Whamcloud - gitweb
ae85f4c97e64d4414fdcf73aa2942aaba7f61ff2
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 # -*- tab-width: 8; 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 SRCDIR=$(cd $(dirname $0); echo $PWD)
20 export PATH=$PATH:/sbin
21
22 TMP=${TMP:-/tmp}
23
24 CC=${CC:-cc}
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 OPENFILE=${OPENFILE:-openfile}
32 OPENUNLINK=${OPENUNLINK:-openunlink}
33 export MULTIOP=${MULTIOP:-multiop}
34 READS=${READS:-"reads"}
35 MUNLINK=${MUNLINK:-munlink}
36 SOCKETSERVER=${SOCKETSERVER:-socketserver}
37 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
38 MEMHOG=${MEMHOG:-memhog}
39 DIRECTIO=${DIRECTIO:-directio}
40 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
41 UMOUNT=${UMOUNT:-"umount -d"}
42 STRIPES_PER_OBJ=-1
43 CHECK_GRANT=${CHECK_GRANT:-"yes"}
44 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
45 export PARALLEL=${PARALLEL:-"no"}
46
47 export NAME=${NAME:-local}
48
49 SAVE_PWD=$PWD
50
51 CLEANUP=${CLEANUP:-:}
52 SETUP=${SETUP:-:}
53 TRACE=${TRACE:-""}
54 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
55 LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
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 230d"
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 -n1)
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 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
197 test_4() {
198         local MDTIDX=1
199
200         test_mkdir $DIR/$tdir ||
201                 error "Create remote directory failed"
202
203         touch $DIR/$tdir/$tfile ||
204                 error "Create file under remote directory failed"
205
206         rmdir $DIR/$tdir &&
207                 error "Expect error removing in-use dir $DIR/$tdir"
208
209         test -d $DIR/$tdir || error "Remote directory disappeared"
210
211         rm -rf $DIR/$tdir || error "remove remote dir error"
212 }
213 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
214
215 test_5() {
216         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
217         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
218         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
219         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
220         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
221 }
222 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
223
224 test_6a() {
225         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
226         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
227         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
228                 error "$tfile does not have perm 0666 or UID $UID"
229         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
230         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
231                 error "$tfile should be 0666 and owned by UID $UID"
232 }
233 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
234
235 test_6c() {
236         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
237         touch $DIR/$tfile
238         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
239         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
240                 error "$tfile should be owned by UID $RUNAS_ID"
241         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
242         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
243                 error "$tfile should be owned by UID $RUNAS_ID"
244 }
245 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
246
247 test_6e() {
248         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
249         touch $DIR/$tfile
250         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
251         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
252                 error "$tfile should be owned by GID $UID"
253         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
254         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
255                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
256 }
257 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
258
259 test_6g() {
260         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
261         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
262         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
263         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
264         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
265         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
266         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
267                 error "$tdir/d/subdir should be GID $RUNAS_GID"
268 }
269 run_test 6g "Is new dir in sgid dir inheriting group?"
270
271 test_6h() { # bug 7331
272         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
273         touch $DIR/$tfile || error "touch failed"
274         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
275         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
276                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
277         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
278                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
279 }
280 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
281
282 test_7a() {
283         test_mkdir $DIR/$tdir
284         $MCREATE $DIR/$tdir/$tfile
285         chmod 0666 $DIR/$tdir/$tfile
286         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
287                 error "$tdir/$tfile should be mode 0666"
288 }
289 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
290
291 test_7b() {
292         if [ ! -d $DIR/$tdir ]; then
293                 mkdir $DIR/$tdir
294         fi
295         $MCREATE $DIR/$tdir/$tfile
296         echo -n foo > $DIR/$tdir/$tfile
297         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
298         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
299 }
300 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
301
302 test_8() {
303         test_mkdir $DIR/$tdir
304         touch $DIR/$tdir/$tfile
305         chmod 0666 $DIR/$tdir/$tfile
306         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
307                 error "$tfile mode not 0666"
308 }
309 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
310
311 test_9() {
312         test_mkdir $DIR/$tdir
313         test_mkdir $DIR/$tdir/d2
314         test_mkdir $DIR/$tdir/d2/d3
315         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
316 }
317 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
318
319 test_10() {
320         test_mkdir $DIR/$tdir
321         test_mkdir $DIR/$tdir/d2
322         touch $DIR/$tdir/d2/$tfile
323         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
324                 error "$tdir/d2/$tfile not a file"
325 }
326 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
327
328 test_11() {
329         test_mkdir $DIR/$tdir
330         test_mkdir $DIR/$tdir/d2
331         chmod 0666 $DIR/$tdir/d2
332         chmod 0705 $DIR/$tdir/d2
333         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
334                 error "$tdir/d2 mode not 0705"
335 }
336 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
337
338 test_12() {
339         test_mkdir $DIR/$tdir
340         touch $DIR/$tdir/$tfile
341         chmod 0666 $DIR/$tdir/$tfile
342         chmod 0654 $DIR/$tdir/$tfile
343         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
344                 error "$tdir/d2 mode not 0654"
345 }
346 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
347
348 test_13() {
349         test_mkdir $DIR/$tdir
350         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
351         >  $DIR/$tdir/$tfile
352         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
353                 error "$tdir/$tfile size not 0 after truncate"
354 }
355 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
356
357 test_14() {
358         test_mkdir $DIR/$tdir
359         touch $DIR/$tdir/$tfile
360         rm $DIR/$tdir/$tfile
361         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
362 }
363 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
364
365 test_15() {
366         test_mkdir $DIR/$tdir
367         touch $DIR/$tdir/$tfile
368         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
369         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
370                 error "$tdir/${tfile_2} not a file after rename"
371 }
372 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
373
374 test_16() {
375         test_mkdir $DIR/$tdir
376         touch $DIR/$tdir/$tfile
377         rm -rf $DIR/$tdir/$tfile
378         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
379 }
380 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
381
382 test_17a() {
383         test_mkdir -p $DIR/$tdir
384         touch $DIR/$tdir/$tfile
385         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
386         ls -l $DIR/$tdir
387         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
388                 error "$tdir/l-exist not a symlink"
389         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
390                 error "$tdir/l-exist not referencing a file"
391         rm -f $DIR/$tdir/l-exist
392         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
393 }
394 run_test 17a "symlinks: create, remove (real) =================="
395
396 test_17b() {
397         test_mkdir -p $DIR/$tdir
398         ln -s no-such-file $DIR/$tdir/l-dangle
399         ls -l $DIR/$tdir
400         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
401                 error "$tdir/l-dangle not referencing no-such-file"
402         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
403                 error "$tdir/l-dangle not referencing non-existent file"
404         rm -f $DIR/$tdir/l-dangle
405         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
406 }
407 run_test 17b "symlinks: create, remove (dangling) =============="
408
409 test_17c() { # bug 3440 - don't save failed open RPC for replay
410         test_mkdir -p $DIR/$tdir
411         ln -s foo $DIR/$tdir/$tfile
412         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
413 }
414 run_test 17c "symlinks: open dangling (should return error) ===="
415
416 test_17d() {
417         test_mkdir -p $DIR/$tdir
418         ln -s foo $DIR/$tdir/$tfile
419         touch $DIR/$tdir/$tfile || error "creating to new symlink"
420 }
421 run_test 17d "symlinks: create dangling ========================"
422
423 test_17e() {
424         test_mkdir -p $DIR/$tdir
425         local foo=$DIR/$tdir/$tfile
426         ln -s $foo $foo || error "create symlink failed"
427         ls -l $foo || error "ls -l failed"
428         ls $foo && error "ls not failed" || true
429 }
430 run_test 17e "symlinks: create recursive symlink (should return error) ===="
431
432 test_17f() {
433         test_mkdir -p $DIR/$tdir
434         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
435         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
436         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
437         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
438         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
439         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890/aaaaaaaaaa/bbbbbbbbbb/cccccccccc/dddddddddd/eeeeeeeeee/ffffffffff/ $DIR/$tdir/666
440         ls -l  $DIR/$tdir
441 }
442 run_test 17f "symlinks: long and very long symlink name ========================"
443
444 # str_repeat(S, N) generate a string that is string S repeated N times
445 str_repeat() {
446         local s=$1
447         local n=$2
448         local ret=''
449         while [ $((n -= 1)) -ge 0 ]; do
450                 ret=$ret$s
451         done
452         echo $ret
453 }
454
455 # Long symlinks and LU-2241
456 test_17g() {
457         test_mkdir -p $DIR/$tdir
458         local TESTS="59 60 61 4094 4095"
459
460         # Fix for inode size boundary in 2.1.4
461         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
462                 TESTS="4094 4095"
463
464         # Patch not applied to 2.2 or 2.3 branches
465         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
466         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
467                 TESTS="4094 4095"
468
469         # skip long symlink name for rhel6.5.
470         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
471         grep -q '6.5' /etc/redhat-release &>/dev/null &&
472                 TESTS="59 60 61 4062 4063"
473
474         for i in $TESTS; do
475                 local SYMNAME=$(str_repeat 'x' $i)
476                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
477                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
478         done
479 }
480 run_test 17g "symlinks: really long symlink name and inode boundaries"
481
482 test_17h() { #bug 17378
483         remote_mds_nodsh && skip "remote MDS with nodsh" && return
484         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
485         local mdt_idx
486         test_mkdir -p $DIR/$tdir
487         if [[ $MDSCOUNT -gt 1 ]]; then
488                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
489         else
490                 mdt_idx=0
491         fi
492         $SETSTRIPE -c -1 $DIR/$tdir
493 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
494         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
495         touch $DIR/$tdir/$tfile || true
496 }
497 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
498
499 test_17i() { #bug 20018
500         remote_mds_nodsh && skip "remote MDS with nodsh" && return
501         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
502         test_mkdir -c1 $DIR/$tdir
503         local foo=$DIR/$tdir/$tfile
504         local mdt_idx
505         if [[ $MDSCOUNT -gt 1 ]]; then
506                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
507         else
508                 mdt_idx=0
509         fi
510         ln -s $foo $foo || error "create symlink failed"
511 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
512         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
513         ls -l $foo && error "error not detected"
514         return 0
515 }
516 run_test 17i "don't panic on short symlink"
517
518 test_17k() { #bug 22301
519         [[ -z "$(which rsync 2>/dev/null)" ]] &&
520                 skip "no rsync command" && return 0
521         rsync --help | grep -q xattr ||
522                 skip_env "$(rsync --version | head -n1) does not support xattrs"
523         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
524         test_mkdir -p $DIR/$tdir
525         test_mkdir -p $DIR/$tdir.new
526         touch $DIR/$tdir/$tfile
527         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
528         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
529                 error "rsync failed with xattrs enabled"
530 }
531 run_test 17k "symlinks: rsync with xattrs enabled ========================="
532
533 test_17l() { # LU-279
534         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
535                 skip "no getfattr command" && return 0
536         mkdir -p $DIR/$tdir
537         touch $DIR/$tdir/$tfile
538         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
539         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
540                 # -h to not follow symlinks. -m '' to list all the xattrs.
541                 # grep to remove first line: '# file: $path'.
542                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
543                 do
544                         lgetxattr_size_check $path $xattr ||
545                                 error "lgetxattr_size_check $path $xattr failed"
546                 done
547         done
548 }
549 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
550
551 # LU-1540
552 test_17m() {
553         local short_sym="0123456789"
554         local WDIR=$DIR/${tdir}m
555         local mds_index
556         local devname
557         local cmd
558         local i
559         local rc=0
560
561         remote_mds_nodsh && skip "remote MDS with nodsh" && return
562         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
563         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
564                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
565
566         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
567                 skip "only for ldiskfs MDT" && return 0
568
569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
570
571         mkdir -p $WDIR
572         long_sym=$short_sym
573         # create a long symlink file
574         for ((i = 0; i < 4; ++i)); do
575                 long_sym=${long_sym}${long_sym}
576         done
577
578         echo "create 512 short and long symlink files under $WDIR"
579         for ((i = 0; i < 256; ++i)); do
580                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
581                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
582         done
583
584         echo "erase them"
585         rm -f $WDIR/*
586         sync
587         wait_delete_completed
588
589         echo "recreate the 512 symlink files with a shorter string"
590         for ((i = 0; i < 512; ++i)); do
591                 # rewrite the symlink file with a shorter string
592                 ln -sf ${long_sym} $WDIR/long-$i
593                 ln -sf ${short_sym} $WDIR/short-$i
594         done
595
596         mds_index=$($LFS getstripe -M $WDIR)
597         mds_index=$((mds_index+1))
598         devname=$(mdsdevname $mds_index)
599         cmd="$E2FSCK -fnvd $devname"
600
601         echo "stop and checking mds${mds_index}: $cmd"
602         # e2fsck should not return error
603         stop mds${mds_index}
604         do_facet mds${mds_index} $cmd || rc=$?
605
606         start mds${mds_index} $devname $MDS_MOUNT_OPTS
607         df $MOUNT > /dev/null 2>&1
608         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
609                 "short/long symlink MDT: rc=$rc"
610         return $rc
611 }
612 run_test 17m "run e2fsck against MDT which contains short/long symlink"
613
614 check_fs_consistency_17n() {
615         local mdt_index
616         local devname
617         local cmd
618         local rc=0
619
620         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
621         # so it only check MDT1/MDT2 instead of all of MDTs.
622         for mdt_index in $(seq 1 2); do
623                 devname=$(mdsdevname $mdt_index)
624                 cmd="$E2FSCK -fnvd $devname"
625
626                 echo "stop and checking mds${mdt_index}: $cmd"
627                 # e2fsck should not return error
628                 stop mds${mdt_index}
629                 do_facet mds${mdt_index} $cmd || rc=$?
630
631                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS
632                 df $MOUNT > /dev/null 2>&1
633                 [ $rc -ne 0 ] && break
634         done
635         return $rc
636 }
637
638 test_17n() {
639         local i
640
641         remote_mds_nodsh && skip "remote MDS with nodsh" && return
642         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
643         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
644                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
645
646         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
647                 skip "only for ldiskfs MDT" && return 0
648
649         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
650
651         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
652
653         mkdir $DIR/$tdir
654         for ((i=0; i<10; i++)); do
655                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
656                         error "create remote dir error $i"
657                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
658                         error "create files under remote dir failed $i"
659         done
660
661         check_fs_consistency_17n ||
662                 error "e2fsck report error after create files under remote dir"
663
664         for ((i=0;i<10;i++)); do
665                 rm -rf $DIR/$tdir/remote_dir_${i} ||
666                         error "destroy remote dir error $i"
667         done
668
669         check_fs_consistency_17n ||
670                 error "e2fsck report error after unlink files under remote dir"
671
672         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
673                 skip "lustre < 2.4.50 does not support migrate mv " && return
674
675         for ((i=0; i<10; i++)); do
676                 mkdir -p $DIR/$tdir/remote_dir_${i}
677                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
678                         error "create files under remote dir failed $i"
679                 $LFS mv -M 1 $DIR/$tdir/remote_dir_${i} ||
680                         error "migrate remote dir error $i"
681         done
682         check_fs_consistency_17n || error "e2fsck report error after migration"
683
684         for ((i=0;i<10;i++)); do
685                 rm -rf $DIR/$tdir/remote_dir_${i} ||
686                         error "destroy remote dir error $i"
687         done
688
689         check_fs_consistency_17n || error "e2fsck report error after unlink"
690 }
691 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
692
693 test_17o() {
694         remote_mds_nodsh && skip "remote MDS with nodsh" && return
695         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
696                 skip "Need MDS version at least 2.3.64" && return
697
698         local WDIR=$DIR/${tdir}o
699         local mdt_index
700         local mdtdevname
701         local rc=0
702
703         mkdir -p $WDIR
704         mdt_index=$($LFS getstripe -M $WDIR)
705         mdt_index=$((mdt_index+1))
706         mdtdevname=$(mdsdevname $mdt_index)
707
708         touch $WDIR/$tfile
709         stop mds${mdt_index}
710         start mds${mdt_index} $mdtdevname $MDS_MOUNT_OPTS
711
712         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
713         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
714         ls -l $WDIR/$tfile && rc=1
715         do_facet mds${mdt_index} lctl set_param fail_loc=0
716         [[ $rc -ne 0 ]] && error "stat file should fail"
717         true
718 }
719 run_test 17o "stat file with incompat LMA feature"
720
721 test_18() {
722         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
723         ls $DIR || error "Failed to ls $DIR: $?"
724 }
725 run_test 18 "touch .../f ; ls ... =============================="
726
727 test_19a() {
728         touch $DIR/$tfile
729         ls -l $DIR
730         rm $DIR/$tfile
731         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
732 }
733 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
734
735 test_19b() {
736         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
737 }
738 run_test 19b "ls -l .../f19 (should return error) =============="
739
740 test_19c() {
741         [ $RUNAS_ID -eq $UID ] &&
742                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
743         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
744 }
745 run_test 19c "$RUNAS touch .../f19 (should return error) =="
746
747 test_19d() {
748         cat $DIR/f19 && error || true
749 }
750 run_test 19d "cat .../f19 (should return error) =============="
751
752 test_20() {
753         touch $DIR/$tfile
754         rm $DIR/$tfile
755         log "1 done"
756         touch $DIR/$tfile
757         rm $DIR/$tfile
758         log "2 done"
759         touch $DIR/$tfile
760         rm $DIR/$tfile
761         log "3 done"
762         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
763 }
764 run_test 20 "touch .../f ; ls -l ... ==========================="
765
766 test_21() {
767         test_mkdir -p $DIR/$tdir
768         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
769         ln -s dangle $DIR/$tdir/link
770         echo foo >> $DIR/$tdir/link
771         cat $DIR/$tdir/dangle
772         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
773         $CHECKSTAT -f -t file $DIR/$tdir/link ||
774                 error "$tdir/link not linked to a file"
775 }
776 run_test 21 "write to dangling link ============================"
777
778 test_22() {
779         WDIR=$DIR/$tdir
780         test_mkdir -p $DIR/$tdir
781         chown $RUNAS_ID:$RUNAS_GID $WDIR
782         (cd $WDIR || error "cd $WDIR failed";
783         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
784         $RUNAS tar xf -)
785         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
786         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
787         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
788 }
789 run_test 22 "unpack tar archive as non-root user ==============="
790
791 # was test_23
792 test_23a() {
793         test_mkdir -p $DIR/$tdir
794         local file=$DIR/$tdir/$tfile
795
796         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
797         openfile -f O_CREAT:O_EXCL $file &&
798                 error "$file recreate succeeded" || true
799 }
800 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
801
802 test_23b() { # bug 18988
803         test_mkdir -p $DIR/$tdir
804         local file=$DIR/$tdir/$tfile
805
806         rm -f $file
807         echo foo > $file || error "write filed"
808         echo bar >> $file || error "append filed"
809         $CHECKSTAT -s 8 $file || error "wrong size"
810         rm $file
811 }
812 run_test 23b "O_APPEND check =========================="
813
814 # rename sanity
815 test_24a() {
816         echo '-- same directory rename'
817         test_mkdir $DIR/$tdir
818         touch $DIR/$tdir/$tfile.1
819         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
820         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
821 }
822 run_test 24a "rename file to non-existent target"
823
824 test_24b() {
825         test_mkdir $DIR/$tdir
826         touch $DIR/$tdir/$tfile.{1,2}
827         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
828         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
829         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
830 }
831 run_test 24b "rename file to existing target"
832
833 test_24c() {
834         test_mkdir $DIR/$tdir
835         test_mkdir $DIR/$tdir/d$testnum.1
836         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
837         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
838         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
839 }
840 run_test 24c "rename directory to non-existent target"
841
842 test_24d() {
843         test_mkdir -c1 $DIR/$tdir
844         test_mkdir -c1 $DIR/$tdir/d$testnum.1
845         test_mkdir -c1 $DIR/$tdir/d$testnum.2
846         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
847         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
848         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
849 }
850 run_test 24d "rename directory to existing target"
851
852 test_24e() {
853         echo '-- cross directory renames --'
854         test_mkdir $DIR/R5a
855         test_mkdir $DIR/R5b
856         touch $DIR/R5a/f
857         mv $DIR/R5a/f $DIR/R5b/g
858         $CHECKSTAT -a $DIR/R5a/f || error
859         $CHECKSTAT -t file $DIR/R5b/g || error
860 }
861 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
862
863 test_24f() {
864         test_mkdir $DIR/R6a
865         test_mkdir $DIR/R6b
866         touch $DIR/R6a/f $DIR/R6b/g
867         mv $DIR/R6a/f $DIR/R6b/g
868         $CHECKSTAT -a $DIR/R6a/f || error
869         $CHECKSTAT -t file $DIR/R6b/g || error
870 }
871 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
872
873 test_24g() {
874         test_mkdir $DIR/R7a
875         test_mkdir $DIR/R7b
876         test_mkdir $DIR/R7a/d
877         mv $DIR/R7a/d $DIR/R7b/e
878         $CHECKSTAT -a $DIR/R7a/d || error
879         $CHECKSTAT -t dir $DIR/R7b/e || error
880 }
881 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
882
883 test_24h() {
884         test_mkdir -c1 $DIR/R8a
885         test_mkdir -c1 $DIR/R8b
886         test_mkdir -c1 $DIR/R8a/d
887         test_mkdir -c1 $DIR/R8b/e
888         mrename $DIR/R8a/d $DIR/R8b/e
889         $CHECKSTAT -a $DIR/R8a/d || error
890         $CHECKSTAT -t dir $DIR/R8b/e || error
891 }
892 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
893
894 test_24i() {
895         echo "-- rename error cases"
896         test_mkdir $DIR/R9
897         test_mkdir $DIR/R9/a
898         touch $DIR/R9/f
899         mrename $DIR/R9/f $DIR/R9/a
900         $CHECKSTAT -t file $DIR/R9/f || error
901         $CHECKSTAT -t dir  $DIR/R9/a || error
902         $CHECKSTAT -a $DIR/R9/a/f || error
903 }
904 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
905
906 test_24j() {
907         test_mkdir $DIR/R10
908         mrename $DIR/R10/f $DIR/R10/g
909         $CHECKSTAT -t dir $DIR/R10 || error
910         $CHECKSTAT -a $DIR/R10/f || error
911         $CHECKSTAT -a $DIR/R10/g || error
912 }
913 run_test 24j "source does not exist ============================"
914
915 test_24k() {
916         test_mkdir $DIR/R11a
917         test_mkdir $DIR/R11a/d
918         touch $DIR/R11a/f
919         mv $DIR/R11a/f $DIR/R11a/d
920         $CHECKSTAT -a $DIR/R11a/f || error
921         $CHECKSTAT -t file $DIR/R11a/d/f || error
922 }
923 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
924
925 # bug 2429 - rename foo foo foo creates invalid file
926 test_24l() {
927         f="$DIR/f24l"
928         $MULTIOP $f OcNs || error
929 }
930 run_test 24l "Renaming a file to itself ========================"
931
932 test_24m() {
933         f="$DIR/f24m"
934         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
935         # on ext3 this does not remove either the source or target files
936         # though the "expected" operation would be to remove the source
937         $CHECKSTAT -t file ${f} || error "${f} missing"
938         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
939 }
940 run_test 24m "Renaming a file to a hard link to itself ========="
941
942 test_24n() {
943     f="$DIR/f24n"
944     # this stats the old file after it was renamed, so it should fail
945     touch ${f}
946     $CHECKSTAT ${f}
947     mv ${f} ${f}.rename
948     $CHECKSTAT ${f}.rename
949     $CHECKSTAT -a ${f}
950 }
951 run_test 24n "Statting the old file after renaming (Posix rename 2)"
952
953 test_24o() {
954         check_kernel_version 37 || return 0
955         test_mkdir -p $DIR/d24o
956         rename_many -s random -v -n 10 $DIR/d24o
957 }
958 run_test 24o "rename of files during htree split ==============="
959
960 test_24p() {
961         test_mkdir $DIR/R12a
962         test_mkdir $DIR/R12b
963         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
964         mrename $DIR/R12a $DIR/R12b
965         $CHECKSTAT -a $DIR/R12a || error
966         $CHECKSTAT -t dir $DIR/R12b || error
967         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
968         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
969 }
970 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
971
972 cleanup_multiop_pause() {
973         trap 0
974         kill -USR1 $MULTIPID
975 }
976
977 test_24q() {
978         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
979         test_mkdir $DIR/R13a
980         test_mkdir $DIR/R13b
981         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
982         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
983         MULTIPID=$!
984
985         trap cleanup_multiop_pause EXIT
986         mrename $DIR/R13a $DIR/R13b
987         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
988         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
989         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
990         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
991         cleanup_multiop_pause
992         wait $MULTIPID || error "multiop close failed"
993 }
994 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
995
996 test_24r() { #bug 3789
997         test_mkdir $DIR/R14a
998         test_mkdir $DIR/R14a/b
999         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1000         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1001         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1002 }
1003 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1004
1005 test_24s() {
1006         test_mkdir $DIR/R15a
1007         test_mkdir $DIR/R15a/b
1008         test_mkdir $DIR/R15a/b/c
1009         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1010         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1011         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1012 }
1013 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1014 test_24t() {
1015         test_mkdir $DIR/R16a
1016         test_mkdir $DIR/R16a/b
1017         test_mkdir $DIR/R16a/b/c
1018         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1019         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1020         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1021 }
1022 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1023
1024 test_24u() { # bug12192
1025         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1026         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1027 }
1028 run_test 24u "create stripe file"
1029
1030 page_size() {
1031         getconf PAGE_SIZE
1032 }
1033
1034 simple_cleanup_common() {
1035         trap 0
1036         rm -rf $DIR/$tdir
1037         wait_delete_completed
1038 }
1039
1040 max_pages_per_rpc() {
1041         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1042 }
1043
1044 test_24v() {
1045         local NRFILES=100000
1046         local FREE_INODES=$(mdt_free_inodes 0)
1047         [[ $FREE_INODES -lt $NRFILES ]] &&
1048                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1049                 return
1050
1051         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1052         trap simple_cleanup_common EXIT
1053
1054         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1055         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1056
1057         mkdir -p $DIR/$tdir
1058         createmany -m $DIR/$tdir/$tfile $NRFILES
1059
1060         cancel_lru_locks mdc
1061         lctl set_param mdc.*.stats clear
1062
1063         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1064
1065         # LU-5 large readdir
1066         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1067         #               8 bytes for name(filename is mostly 5 in this test) +
1068         #               8 bytes for luda_type
1069         # take into account of overhead in lu_dirpage header and end mark in
1070         # each page, plus one in RPC_NUM calculation.
1071         DIRENT_SIZE=48
1072         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1073         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1074         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1075                                 awk '/^mds_readpage/ {print $2}')
1076         [[ $mds_readpage -gt $RPC_NUM ]] &&
1077                 error "large readdir doesn't take effect"
1078
1079         simple_cleanup_common
1080 }
1081 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1082
1083 test_24w() { # bug21506
1084         SZ1=234852
1085         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1086         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1087         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1088         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1089         [[ "$SZ1" -eq "$SZ2" ]] ||
1090                 error "Error reading at the end of the file $tfile"
1091 }
1092 run_test 24w "Reading a file larger than 4Gb"
1093
1094 test_24x() {
1095         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1096         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1097         local MDTIDX=1
1098         local remote_dir=$DIR/$tdir/remote_dir
1099
1100         mkdir -p $DIR/$tdir
1101         $LFS mkdir -i $MDTIDX $remote_dir ||
1102                 error "create remote directory failed"
1103
1104         mkdir -p $DIR/$tdir/src_dir
1105         touch $DIR/$tdir/src_file
1106         mkdir -p $remote_dir/tgt_dir
1107         touch $remote_dir/tgt_file
1108
1109         mrename $remote_dir $DIR/ &&
1110                 error "rename dir cross MDT works!"
1111
1112         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1113                 error "rename dir cross MDT works!"
1114
1115         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1116                 error "rename file cross MDT works!"
1117
1118         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1119                 error "ln file cross MDT should not work!"
1120
1121         rm -rf $DIR/$tdir || error "Can not delete directories"
1122 }
1123 run_test 24x "cross rename/link should be failed"
1124
1125 test_24y() {
1126         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1127         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1128         local MDTIDX=1
1129         local remote_dir=$DIR/$tdir/remote_dir
1130
1131         mkdir -p $DIR/$tdir
1132         $LFS mkdir -i $MDTIDX $remote_dir ||
1133                    error "create remote directory failed"
1134
1135         mkdir -p $remote_dir/src_dir
1136         touch $remote_dir/src_file
1137         mkdir -p $remote_dir/tgt_dir
1138         touch $remote_dir/tgt_file
1139
1140         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1141                 error "rename subdir in the same remote dir failed!"
1142
1143         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1144                 error "rename files in the same remote dir failed!"
1145
1146         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1147                 error "link files in the same remote dir failed!"
1148
1149         rm -rf $DIR/$tdir || error "Can not delete directories"
1150 }
1151 run_test 24y "rename/link on the same dir should succeed"
1152
1153 test_24z() {
1154         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1155         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1156         local MDTIDX=1
1157         local remote_src=$DIR/$tdir/remote_dir
1158         local remote_tgt=$DIR/$tdir/remote_tgt
1159
1160         mkdir -p $DIR/$tdir
1161         $LFS mkdir -i $MDTIDX $remote_src ||
1162                    error "create remote directory failed"
1163
1164         $LFS mkdir -i $MDTIDX $remote_tgt ||
1165                    error "create remote directory failed"
1166
1167         mrename $remote_src $remote_tgt &&
1168                 error "rename remote dirs should not work!"
1169
1170         # If target dir does not exists, it should succeed
1171         rm -rf $remote_tgt
1172         mrename $remote_src $remote_tgt ||
1173                 error "rename remote dirs(tgt dir does not exists) failed!"
1174
1175         rm -rf $DIR/$tdir || error "Can not delete directories"
1176 }
1177 run_test 24z "rename one remote dir to another remote dir should fail"
1178
1179 test_24A() { # LU-3182
1180         local NFILES=5000
1181
1182         rm -rf $DIR/$tdir
1183         mkdir -p $DIR/$tdir
1184         createmany -m $DIR/$tdir/$tfile $NFILES
1185         local t=$(ls $DIR/$tdir | wc -l)
1186         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1187         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1188         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1189                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1190         fi
1191
1192         rm -rf $DIR/$tdir || error "Can not delete directories"
1193 }
1194 run_test 24A "readdir() returns correct number of entries."
1195
1196 test_24B() { # LU-4805
1197         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1198         local count
1199
1200         mkdir $DIR/$tdir
1201         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1202                 error "create striped dir failed"
1203
1204         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1205         [ $count -eq 2 ] || error "Expected 2, got $count"
1206
1207         touch $DIR/$tdir/striped_dir/a
1208
1209         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1210         [ $count -eq 3 ] || error "Expected 3, got $count"
1211
1212         touch $DIR/$tdir/striped_dir/.f
1213
1214         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1215         [ $count -eq 4 ] || error "Expected 4, got $count"
1216
1217         rm -rf $DIR/$tdir || error "Can not delete directories"
1218 }
1219 run_test 24B "readdir for striped dir return correct number of entries"
1220
1221 test_24C() {
1222         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1223
1224         mkdir $DIR/$tdir
1225         mkdir $DIR/$tdir/d0
1226         mkdir $DIR/$tdir/d1
1227
1228         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1229                 error "create striped dir failed"
1230
1231         cd $DIR/$tdir/d0/striped_dir
1232
1233         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1234         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1235         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1236
1237         [ "$d0_ino" = "$parent_ino" ] ||
1238                 error ".. wrong, expect $d0_ino, get $parent_ino"
1239
1240         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1241                 error "mv striped dir failed"
1242
1243         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1244
1245         [ "$d1_ino" = "$parent_ino" ] ||
1246                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1247 }
1248 run_test 24C "check .. in striped dir"
1249
1250 test_25a() {
1251         echo '== symlink sanity ============================================='
1252
1253         test_mkdir $DIR/d25
1254         ln -s d25 $DIR/s25
1255         touch $DIR/s25/foo || error
1256 }
1257 run_test 25a "create file in symlinked directory ==============="
1258
1259 test_25b() {
1260         [ ! -d $DIR/d25 ] && test_25a
1261         $CHECKSTAT -t file $DIR/s25/foo || error
1262 }
1263 run_test 25b "lookup file in symlinked directory ==============="
1264
1265 test_26a() {
1266         test_mkdir $DIR/d26
1267         test_mkdir $DIR/d26/d26-2
1268         ln -s d26/d26-2 $DIR/s26
1269         touch $DIR/s26/foo || error
1270 }
1271 run_test 26a "multiple component symlink ======================="
1272
1273 test_26b() {
1274         test_mkdir -p $DIR/d26b/d26-2
1275         ln -s d26b/d26-2/foo $DIR/s26-2
1276         touch $DIR/s26-2 || error
1277 }
1278 run_test 26b "multiple component symlink at end of lookup ======"
1279
1280 test_26c() {
1281         test_mkdir $DIR/d26.2
1282         touch $DIR/d26.2/foo
1283         ln -s d26.2 $DIR/s26.2-1
1284         ln -s s26.2-1 $DIR/s26.2-2
1285         ln -s s26.2-2 $DIR/s26.2-3
1286         chmod 0666 $DIR/s26.2-3/foo
1287 }
1288 run_test 26c "chain of symlinks ================================"
1289
1290 # recursive symlinks (bug 439)
1291 test_26d() {
1292         ln -s d26-3/foo $DIR/d26-3
1293 }
1294 run_test 26d "create multiple component recursive symlink ======"
1295
1296 test_26e() {
1297         [ ! -h $DIR/d26-3 ] && test_26d
1298         rm $DIR/d26-3
1299 }
1300 run_test 26e "unlink multiple component recursive symlink ======"
1301
1302 # recursive symlinks (bug 7022)
1303 test_26f() {
1304         test_mkdir -p $DIR/$tdir
1305         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1306         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1307         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1308         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1309         cd $tfile                || error "cd $tfile failed"
1310         ln -s .. dotdot          || error "ln dotdot failed"
1311         ln -s dotdot/lndir lndir || error "ln lndir failed"
1312         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1313         output=`ls $tfile/$tfile/lndir/bar1`
1314         [ "$output" = bar1 ] && error "unexpected output"
1315         rm -r $tfile             || error "rm $tfile failed"
1316         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1317 }
1318 run_test 26f "rm -r of a directory which has recursive symlink ="
1319
1320 test_27a() {
1321         echo '== stripe sanity =============================================='
1322         test_mkdir -p $DIR/d27 || error "mkdir failed"
1323         $GETSTRIPE $DIR/d27
1324         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1325         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1326         log "== test_27a: write to one stripe file ========================="
1327         cp /etc/hosts $DIR/d27/f0 || error
1328 }
1329 run_test 27a "one stripe file =================================="
1330
1331 test_27b() {
1332         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1333         test_mkdir -p $DIR/d27
1334         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1335         $GETSTRIPE -c $DIR/d27/f01
1336         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1337                 error "two-stripe file doesn't have two stripes"
1338
1339         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1340 }
1341 run_test 27b "create and write to two stripe file"
1342
1343 test_27d() {
1344         test_mkdir -p $DIR/d27
1345         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1346         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1347         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1348 }
1349 run_test 27d "create file with default settings ================"
1350
1351 test_27e() {
1352         test_mkdir -p $DIR/d27
1353         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1354         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1355         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1356 }
1357 run_test 27e "setstripe existing file (should return error) ======"
1358
1359 test_27f() {
1360         test_mkdir -p $DIR/d27
1361         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/d27/fbad && error "setstripe failed"
1362         dd if=/dev/zero of=$DIR/d27/fbad bs=4k count=4 || error "dd failed"
1363         $GETSTRIPE $DIR/d27/fbad || error "$GETSTRIPE failed"
1364 }
1365 run_test 27f "setstripe with bad stripe size (should return error)"
1366
1367 test_27g() {
1368         test_mkdir -p $DIR/d27
1369         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1370         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1371                 error "$DIR/d27/fnone has object"
1372 }
1373 run_test 27g "$GETSTRIPE with no objects"
1374
1375 test_27i() {
1376         touch $DIR/d27/fsome || error "touch failed"
1377         [[ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ]] || error "missing objects"
1378 }
1379 run_test 27i "$GETSTRIPE with some objects"
1380
1381 test_27j() {
1382         test_mkdir -p $DIR/d27
1383         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1384 }
1385 run_test 27j "setstripe with bad stripe offset (should return error)"
1386
1387 test_27k() { # bug 2844
1388         test_mkdir -p $DIR/d27
1389         FILE=$DIR/d27/f27k
1390         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1391         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1392         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1393         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1394         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1395         dd if=/dev/zero of=$FILE bs=4k count=1
1396         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1397         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1398 }
1399 run_test 27k "limit i_blksize for broken user apps ============="
1400
1401 test_27l() {
1402         test_mkdir -p $DIR/d27
1403         mcreate $DIR/f27l || error "creating file"
1404         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1405                 error "setstripe should have failed" || true
1406 }
1407 run_test 27l "check setstripe permissions (should return error)"
1408
1409 test_27m() {
1410         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1411                 return
1412         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1413                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1414                 return
1415         fi
1416         trap simple_cleanup_common EXIT
1417         test_mkdir -p $DIR/$tdir
1418         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1419         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1420                 error "dd should fill OST0"
1421         i=2
1422         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1423                 i=$((i + 1))
1424                 [ $i -gt 256 ] && break
1425         done
1426         i=$((i + 1))
1427         touch $DIR/$tdir/f27m_$i
1428         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1429                 error "OST0 was full but new created file still use it"
1430         i=$((i + 1))
1431         touch $DIR/$tdir/f27m_$i
1432         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1433                 error "OST0 was full but new created file still use it"
1434         simple_cleanup_common
1435 }
1436 run_test 27m "create file while OST0 was full =================="
1437
1438 sleep_maxage() {
1439         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1440         sleep $DELAY
1441 }
1442
1443 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1444 # if the OST isn't full anymore.
1445 reset_enospc() {
1446         local OSTIDX=${1:-""}
1447
1448         local list=$(comma_list $(osts_nodes))
1449         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1450
1451         do_nodes $list lctl set_param fail_loc=0
1452         sync    # initiate all OST_DESTROYs from MDS to OST
1453         sleep_maxage
1454 }
1455
1456 exhaust_precreations() {
1457         local OSTIDX=$1
1458         local FAILLOC=$2
1459         local FAILIDX=${3:-$OSTIDX}
1460
1461         test_mkdir -p $DIR/$tdir
1462         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1463         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1464
1465         local OST=$(ostname_from_index $OSTIDX)
1466         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1467                           sed -e 's/_UUID$//;s/^.*-//')
1468
1469         # on the mdt's osc
1470         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1471         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1472                         osc.$mdtosc_proc1.prealloc_last_id)
1473         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1474                         osc.$mdtosc_proc1.prealloc_next_id)
1475
1476         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1477         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1478
1479         test_mkdir -p $DIR/$tdir/${OST}
1480         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1481 #define OBD_FAIL_OST_ENOSPC              0x215
1482         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1483         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1484         echo "Creating to objid $last_id on ost $OST..."
1485         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1486         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1487         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1488         sleep_maxage
1489 }
1490
1491 exhaust_all_precreations() {
1492         local i
1493         for (( i=0; i < OSTCOUNT; i++ )) ; do
1494                 exhaust_precreations $i $1 -1
1495         done
1496 }
1497
1498 test_27n() {
1499         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1500         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1501         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1502         remote_ost_nodsh && skip "remote OST with nodsh" && return
1503
1504         reset_enospc
1505         rm -f $DIR/$tdir/$tfile
1506         exhaust_precreations 0 0x80000215
1507         $SETSTRIPE -c -1 $DIR/$tdir
1508         touch $DIR/$tdir/$tfile || error
1509         $GETSTRIPE $DIR/$tdir/$tfile
1510         reset_enospc
1511 }
1512 run_test 27n "create file with some full OSTs =================="
1513
1514 test_27o() {
1515         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1516         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1517         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1518         remote_ost_nodsh && skip "remote OST with nodsh" && return
1519
1520         reset_enospc
1521         rm -f $DIR/$tdir/$tfile
1522         exhaust_all_precreations 0x215
1523
1524         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1525
1526         reset_enospc
1527         rm -rf $DIR/$tdir/*
1528 }
1529 run_test 27o "create file with all full OSTs (should error) ===="
1530
1531 test_27p() {
1532         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1533         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1534         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1535         remote_ost_nodsh && skip "remote OST with nodsh" && return
1536
1537         reset_enospc
1538         rm -f $DIR/$tdir/$tfile
1539         test_mkdir -p $DIR/$tdir
1540
1541         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1542         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1543         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1544
1545         exhaust_precreations 0 0x80000215
1546         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1547         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1548         $GETSTRIPE $DIR/$tdir/$tfile
1549
1550         reset_enospc
1551 }
1552 run_test 27p "append to a truncated file with some full OSTs ==="
1553
1554 test_27q() {
1555         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1556         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1557         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1558         remote_ost_nodsh && skip "remote OST with nodsh" && return
1559
1560         reset_enospc
1561         rm -f $DIR/$tdir/$tfile
1562
1563         test_mkdir -p $DIR/$tdir
1564         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1565         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1566         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1567
1568         exhaust_all_precreations 0x215
1569
1570         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1571         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1572
1573         reset_enospc
1574 }
1575 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1576
1577 test_27r() {
1578         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1579         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1580         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1581         remote_ost_nodsh && skip "remote OST with nodsh" && return
1582
1583         reset_enospc
1584         rm -f $DIR/$tdir/$tfile
1585         exhaust_precreations 0 0x80000215
1586
1587         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1588
1589         reset_enospc
1590 }
1591 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1592
1593 test_27s() { # bug 10725
1594         test_mkdir -p $DIR/$tdir
1595         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1596         local stripe_count=0
1597         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1598         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1599                 error "stripe width >= 2^32 succeeded" || true
1600
1601 }
1602 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1603
1604 test_27t() { # bug 10864
1605         WDIR=$(pwd)
1606         WLFS=$(which lfs)
1607         cd $DIR
1608         touch $tfile
1609         $WLFS getstripe $tfile
1610         cd $WDIR
1611 }
1612 run_test 27t "check that utils parse path correctly"
1613
1614 test_27u() { # bug 4900
1615         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1616         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1617         local index
1618         local list=$(comma_list $(mdts_nodes))
1619
1620 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1621         do_nodes $list $LCTL set_param fail_loc=0x139
1622         test_mkdir -p $DIR/$tdir
1623         rm -rf $DIR/$tdir/*
1624         createmany -o $DIR/$tdir/t- 1000
1625         do_nodes $list $LCTL set_param fail_loc=0
1626
1627         TLOG=$DIR/$tfile.getstripe
1628         $GETSTRIPE $DIR/$tdir > $TLOG
1629         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1630         unlinkmany $DIR/$tdir/t- 1000
1631         [[ $OBJS -gt 0 ]] &&
1632                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1633 }
1634 run_test 27u "skip object creation on OSC w/o objects =========="
1635
1636 test_27v() { # bug 4900
1637         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1638         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1639         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1640         remote_ost_nodsh && skip "remote OST with nodsh" && return
1641
1642         exhaust_all_precreations 0x215
1643         reset_enospc
1644
1645         test_mkdir -p $DIR/$tdir
1646         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1647
1648         touch $DIR/$tdir/$tfile
1649         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1650         # all except ost1
1651         for (( i=1; i < OSTCOUNT; i++ )); do
1652                 do_facet ost$i lctl set_param fail_loc=0x705
1653         done
1654         local START=`date +%s`
1655         createmany -o $DIR/$tdir/$tfile 32
1656
1657         local FINISH=`date +%s`
1658         local TIMEOUT=`lctl get_param -n timeout`
1659         local PROCESS=$((FINISH - START))
1660         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1661                error "$FINISH - $START >= $TIMEOUT / 2"
1662         sleep $((TIMEOUT / 2 - PROCESS))
1663         reset_enospc
1664 }
1665 run_test 27v "skip object creation on slow OST ================="
1666
1667 test_27w() { # bug 10997
1668         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1669         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1670         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1671                 error "stripe size $size != 65536" || true
1672         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1673                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1674 }
1675 run_test 27w "check $SETSTRIPE -S option"
1676
1677 test_27wa() {
1678         [[ $OSTCOUNT -lt 2 ]] &&
1679                 skip_env "skipping multiple stripe count/offset test" && return
1680
1681         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1682         for i in $(seq 1 $OSTCOUNT); do
1683                 offset=$((i - 1))
1684                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1685                         error "setstripe -c $i -i $offset failed"
1686                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1687                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1688                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1689                 [ $index -ne $offset ] &&
1690                         error "stripe offset $index != $offset" || true
1691         done
1692 }
1693 run_test 27wa "check $SETSTRIPE -c -i options"
1694
1695 test_27x() {
1696         remote_ost_nodsh && skip "remote OST with nodsh" && return
1697         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1698         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1699         OFFSET=$(($OSTCOUNT - 1))
1700         OSTIDX=0
1701         local OST=$(ostname_from_index $OSTIDX)
1702
1703         test_mkdir -p $DIR/$tdir
1704         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1705         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1706         sleep_maxage
1707         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1708         for i in `seq 0 $OFFSET`; do
1709                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1710                 error "OST0 was degraded but new created file still use it"
1711         done
1712         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1713 }
1714 run_test 27x "create files while OST0 is degraded"
1715
1716 test_27y() {
1717         [[ $OSTCOUNT -lt 2 ]] &&
1718                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1719         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1720         remote_ost_nodsh && skip "remote OST with nodsh" && return
1721         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1722
1723         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1724         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1725             osc.$mdtosc.prealloc_last_id)
1726         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1727             osc.$mdtosc.prealloc_next_id)
1728         local fcount=$((last_id - next_id))
1729         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1730         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1731
1732         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1733                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1734         local OST_DEACTIVE_IDX=-1
1735         local OSC
1736         local OSTIDX
1737         local OST
1738
1739         for OSC in $MDS_OSCS; do
1740                 OST=$(osc_to_ost $OSC)
1741                 OSTIDX=$(index_from_ostuuid $OST)
1742                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1743                         OST_DEACTIVE_IDX=$OSTIDX
1744                 fi
1745                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1746                         echo $OSC "is Deactivated:"
1747                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1748                 fi
1749         done
1750
1751         OSTIDX=$(index_from_ostuuid $OST)
1752         mkdir -p $DIR/$tdir
1753         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1754
1755         for OSC in $MDS_OSCS; do
1756                 OST=$(osc_to_ost $OSC)
1757                 OSTIDX=$(index_from_ostuuid $OST)
1758                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1759                         echo $OST "is degraded:"
1760                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1761                                                 obdfilter.$OST.degraded=1
1762                 fi
1763         done
1764
1765         sleep_maxage
1766         createmany -o $DIR/$tdir/$tfile $fcount
1767
1768         for OSC in $MDS_OSCS; do
1769                 OST=$(osc_to_ost $OSC)
1770                 OSTIDX=$(index_from_ostuuid $OST)
1771                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1772                         echo $OST "is recovered from degraded:"
1773                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1774                                                 obdfilter.$OST.degraded=0
1775                 else
1776                         do_facet $SINGLEMDS lctl --device %$OSC activate
1777                 fi
1778         done
1779
1780         # all osp devices get activated, hence -1 stripe count restored
1781         local stripecnt=0
1782
1783         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1784         # devices get activated.
1785         sleep_maxage
1786         $SETSTRIPE -c -1 $DIR/$tfile
1787         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1788         rm -f $DIR/$tfile
1789         [ $stripecnt -ne $OSTCOUNT ] &&
1790                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1791         return 0
1792 }
1793 run_test 27y "create files while OST0 is degraded and the rest inactive"
1794
1795 check_seq_oid()
1796 {
1797         log "check file $1"
1798
1799         lmm_count=$($GETSTRIPE -c $1)
1800         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1801         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1802
1803         local old_ifs="$IFS"
1804         IFS=$'[:]'
1805         fid=($($LFS path2fid $1))
1806         IFS="$old_ifs"
1807
1808         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1809         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1810
1811         # compare lmm_seq and lu_fid->f_seq
1812         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1813         # compare lmm_object_id and lu_fid->oid
1814         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1815
1816         # check the trusted.fid attribute of the OST objects of the file
1817         local have_obdidx=false
1818         local stripe_nr=0
1819         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1820                 # skip lines up to and including "obdidx"
1821                 [ -z "$obdidx" ] && break
1822                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1823                 $have_obdidx || continue
1824
1825                 local ost=$((obdidx + 1))
1826                 local dev=$(ostdevname $ost)
1827                 local oid_hex
1828
1829                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1830
1831                 seq=$(echo $seq | sed -e "s/^0x//g")
1832                 if [ $seq == 0 ]; then
1833                         oid_hex=$(echo $oid)
1834                 else
1835                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1836                 fi
1837                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1838
1839                 local ff
1840                 #
1841                 # Don't unmount/remount the OSTs if we don't need to do that.
1842                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1843                 # update too, until that use mount/ll_decode_filter_fid/mount.
1844                 # Re-enable when debugfs will understand new filter_fid.
1845                 #
1846                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1847                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1848                                 $dev 2>/dev/null" | grep "parent=")
1849                 else
1850                         stop ost$ost
1851                         mount_fstype ost$ost
1852                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1853                                 $(facet_mntpt ost$ost)/$obj_file)
1854                         unmount_fstype ost$ost
1855                         start ost$ost $dev $OST_MOUNT_OPTS
1856                 fi
1857
1858                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1859
1860                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1861
1862                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1863                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1864                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1865                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1866                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1867                 local ff_pstripe
1868                 if echo $ff_parent | grep -q 'stripe='; then
1869                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1870                 else
1871                         #
1872                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1873                         # into f_ver in this case.  See the comment on
1874                         # ff_parent.
1875                         #
1876                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1877                                 sed -e 's/\]//')
1878                 fi
1879
1880                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1881                 [ $ff_pseq = $lmm_seq ] ||
1882                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1883                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1884                 [ $ff_poid = $lmm_oid ] ||
1885                         error "FF parent OID $ff_poid != $lmm_oid"
1886                 (($ff_pstripe == $stripe_nr)) ||
1887                         error "FF stripe $ff_pstripe != $stripe_nr"
1888
1889                 stripe_nr=$((stripe_nr + 1))
1890         done
1891 }
1892
1893 test_27z() {
1894         remote_ost_nodsh && skip "remote OST with nodsh" && return
1895         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1896         test_mkdir -p $DIR/$tdir
1897
1898         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1899                 { error "setstripe -c -1 failed"; return 1; }
1900         # We need to send a write to every object to get parent FID info set.
1901         # This _should_ also work for setattr, but does not currently.
1902         # touch $DIR/$tdir/$tfile-1 ||
1903         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1904                 { error "dd $tfile-1 failed"; return 2; }
1905         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1906                 { error "setstripe -c -1 failed"; return 3; }
1907         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1908                 { error "dd $tfile-2 failed"; return 4; }
1909
1910         # make sure write RPCs have been sent to OSTs
1911         sync; sleep 5; sync
1912
1913         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1914         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1915 }
1916 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1917
1918 test_27A() { # b=19102
1919         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1920         local restore_size=$($GETSTRIPE -S $MOUNT)
1921         local restore_count=$($GETSTRIPE -c $MOUNT)
1922         local restore_offset=$($GETSTRIPE -i $MOUNT)
1923         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1924         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1925                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1926         local default_size=$($GETSTRIPE -S $MOUNT)
1927         local default_offset=$($GETSTRIPE -i $MOUNT)
1928         local dsize=$((1024 * 1024))
1929         [ $default_size -eq $dsize ] ||
1930                 error "stripe size $default_size != $dsize"
1931         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1932         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1933 }
1934 run_test 27A "check filesystem-wide default LOV EA values"
1935
1936 test_27B() { # LU-2523
1937         test_mkdir -p $DIR/$tdir
1938         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1939         touch $DIR/$tdir/f0
1940         # open f1 with O_LOV_DELAY_CREATE
1941         # rename f0 onto f1
1942         # call setstripe ioctl on open file descriptor for f1
1943         # close
1944         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1945                 $DIR/$tdir/f0
1946
1947         rm -f $DIR/$tdir/f1
1948         # open f1 with O_LOV_DELAY_CREATE
1949         # unlink f1
1950         # call setstripe ioctl on open file descriptor for f1
1951         # close
1952         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1953
1954         # Allow multiop to fail in imitation of NFS's busted semantics.
1955         true
1956 }
1957 run_test 27B "call setstripe on open unlinked file/rename victim"
1958
1959 test_27C() { #LU-2871
1960         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1961
1962         declare -a ost_idx
1963         local index
1964         local found
1965         local i
1966         local j
1967
1968         test_mkdir -p $DIR/$tdir
1969         cd $DIR/$tdir
1970         for i in $(seq 0 $((OSTCOUNT - 1))); do
1971                 # set stripe across all OSTs starting from OST$i
1972                 $SETSTRIPE -i $i -c -1 $tfile$i
1973                 # get striping information
1974                 ost_idx=($($GETSTRIPE $tfile$i |
1975                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1976                 echo ${ost_idx[@]}
1977
1978                 # check the layout
1979                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1980                         error "${#ost_idx[@]} != $OSTCOUNT"
1981
1982                 for index in $(seq 0 $((OSTCOUNT - 1))); do
1983                         found=0
1984                         for j in $(echo ${ost_idx[@]}); do
1985                                 if [ $index -eq $j ]; then
1986                                         found=1
1987                                         break
1988                                 fi
1989                         done
1990                         [ $found = 1 ] ||
1991                                 error "Can not find $index in ${ost_idx[@]}"
1992                 done
1993         done
1994 }
1995 run_test 27C "check full striping across all OSTs"
1996
1997 test_27D() {
1998         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
1999         local POOL=${POOL:-testpool}
2000         local first_ost=0
2001         local last_ost=$(($OSTCOUNT - 1))
2002         local ost_step=1
2003         local ost_list=$(seq $first_ost $ost_step $last_ost)
2004         local ost_range="$first_ost $last_ost $ost_step"
2005
2006         mkdir -p $DIR/$tdir
2007         pool_add $POOL || error "pool_add failed"
2008         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2009         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT ||
2010                 error "llapi_layout_test failed"
2011         cleanup_pools || error "cleanup_pools failed"
2012 }
2013 run_test 27D "validate llapi_layout API"
2014
2015 # createtest also checks that device nodes are created and
2016 # then visible correctly (#2091)
2017 test_28() { # bug 2091
2018         test_mkdir $DIR/d28
2019         $CREATETEST $DIR/d28/ct || error
2020 }
2021 run_test 28 "create/mknod/mkdir with bad file types ============"
2022
2023 test_29() {
2024         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2025         cancel_lru_locks mdc
2026         test_mkdir $DIR/d29
2027         touch $DIR/d29/foo
2028         log 'first d29'
2029         ls -l $DIR/d29
2030
2031         declare -i LOCKCOUNTORIG=0
2032         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2033                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2034         done
2035         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
2036
2037         declare -i LOCKUNUSEDCOUNTORIG=0
2038         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2039                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2040         done
2041
2042         log 'second d29'
2043         ls -l $DIR/d29
2044         log 'done'
2045
2046         declare -i LOCKCOUNTCURRENT=0
2047         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2048                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2049         done
2050
2051         declare -i LOCKUNUSEDCOUNTCURRENT=0
2052         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2053                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2054         done
2055
2056         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2057                 $LCTL set_param -n ldlm.dump_namespaces ""
2058                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2059                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2060                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2061                 return 2
2062         fi
2063         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2064                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2065                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2066                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2067                 return 3
2068         fi
2069 }
2070 run_test 29 "IT_GETATTR regression  ============================"
2071
2072 test_30a() { # was test_30
2073         cp $(which ls) $DIR || cp /bin/ls $DIR
2074         $DIR/ls / || error
2075         rm $DIR/ls
2076 }
2077 run_test 30a "execute binary from Lustre (execve) =============="
2078
2079 test_30b() {
2080         cp `which ls` $DIR || cp /bin/ls $DIR
2081         chmod go+rx $DIR/ls
2082         $RUNAS $DIR/ls / || error
2083         rm $DIR/ls
2084 }
2085 run_test 30b "execute binary from Lustre as non-root ==========="
2086
2087 test_30c() { # b=22376
2088         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2089         cp `which ls` $DIR || cp /bin/ls $DIR
2090         chmod a-rw $DIR/ls
2091         cancel_lru_locks mdc
2092         cancel_lru_locks osc
2093         $RUNAS $DIR/ls / || error
2094         rm -f $DIR/ls
2095 }
2096 run_test 30c "execute binary from Lustre without read perms ===="
2097
2098 test_31a() {
2099         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2100         $CHECKSTAT -a $DIR/f31 || error
2101 }
2102 run_test 31a "open-unlink file =================================="
2103
2104 test_31b() {
2105         touch $DIR/f31 || error
2106         ln $DIR/f31 $DIR/f31b || error
2107         $MULTIOP $DIR/f31b Ouc || error
2108         $CHECKSTAT -t file $DIR/f31 || error
2109 }
2110 run_test 31b "unlink file with multiple links while open ======="
2111
2112 test_31c() {
2113         touch $DIR/f31 || error
2114         ln $DIR/f31 $DIR/f31c || error
2115         multiop_bg_pause $DIR/f31 O_uc || return 1
2116         MULTIPID=$!
2117         $MULTIOP $DIR/f31c Ouc
2118         kill -USR1 $MULTIPID
2119         wait $MULTIPID
2120 }
2121 run_test 31c "open-unlink file with multiple links ============="
2122
2123 test_31d() {
2124         opendirunlink $DIR/d31d $DIR/d31d || error
2125         $CHECKSTAT -a $DIR/d31d || error
2126 }
2127 run_test 31d "remove of open directory ========================="
2128
2129 test_31e() { # bug 2904
2130         check_kernel_version 34 || return 0
2131         openfilleddirunlink $DIR/d31e || error
2132 }
2133 run_test 31e "remove of open non-empty directory ==============="
2134
2135 test_31f() { # bug 4554
2136         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2137         set -vx
2138         test_mkdir $DIR/d31f
2139         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2140         cp /etc/hosts $DIR/d31f
2141         ls -l $DIR/d31f
2142         $GETSTRIPE $DIR/d31f/hosts
2143         multiop_bg_pause $DIR/d31f D_c || return 1
2144         MULTIPID=$!
2145
2146         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2147         test_mkdir $DIR/d31f
2148         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2149         cp /etc/hosts $DIR/d31f
2150         ls -l $DIR/d31f
2151         $GETSTRIPE $DIR/d31f/hosts
2152         multiop_bg_pause $DIR/d31f D_c || return 1
2153         MULTIPID2=$!
2154
2155         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2156         wait $MULTIPID || error "first opendir $MULTIPID failed"
2157
2158         sleep 6
2159
2160         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2161         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2162         set +vx
2163 }
2164 run_test 31f "remove of open directory with open-unlink file ==="
2165
2166 test_31g() {
2167         echo "-- cross directory link --"
2168         test_mkdir -c1 $DIR/${tdir}ga
2169         test_mkdir -c1 $DIR/${tdir}gb
2170         touch $DIR/${tdir}ga/f
2171         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2172         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2173         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2174         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2175         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2176 }
2177 run_test 31g "cross directory link==============="
2178
2179 test_31h() {
2180         echo "-- cross directory link --"
2181         test_mkdir -c1 $DIR/${tdir}
2182         test_mkdir -c1 $DIR/${tdir}/dir
2183         touch $DIR/${tdir}/f
2184         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2185         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2186         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2187         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2188         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2189 }
2190 run_test 31h "cross directory link under child==============="
2191
2192 test_31i() {
2193         echo "-- cross directory link --"
2194         test_mkdir -c1 $DIR/$tdir
2195         test_mkdir -c1 $DIR/$tdir/dir
2196         touch $DIR/$tdir/dir/f
2197         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2198         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2199         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2200         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2201         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2202 }
2203 run_test 31i "cross directory link under parent==============="
2204
2205 test_31j() {
2206         test_mkdir -c1 -p $DIR/$tdir
2207         test_mkdir -c1 -p $DIR/$tdir/dir1
2208         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2209         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2210         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2211         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2212         return 0
2213 }
2214 run_test 31j "link for directory==============="
2215
2216 test_31k() {
2217         test_mkdir -c1 -p $DIR/$tdir
2218         touch $DIR/$tdir/s
2219         touch $DIR/$tdir/exist
2220         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2221         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2222         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2223         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2224         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2225         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2226         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2227         return 0
2228 }
2229 run_test 31k "link to file: the same, non-existing, dir==============="
2230
2231 test_31m() {
2232         mkdir $DIR/d31m
2233         touch $DIR/d31m/s
2234         mkdir $DIR/d31m2
2235         touch $DIR/d31m2/exist
2236         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2237         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2238         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2239         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2240         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2241         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2242         return 0
2243 }
2244 run_test 31m "link to file: the same, non-existing, dir==============="
2245
2246 test_31n() {
2247         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2248         nlink=$(stat --format=%h $DIR/$tfile)
2249         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2250         local fd=$(free_fd)
2251         local cmd="exec $fd<$DIR/$tfile"
2252         eval $cmd
2253         cmd="exec $fd<&-"
2254         trap "eval $cmd" EXIT
2255         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2256         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2257         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2258         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2259         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2260         eval $cmd
2261 }
2262 run_test 31n "check link count of unlinked file"
2263
2264 link_one() {
2265         local TEMPNAME=$(mktemp $1_XXXXXX)
2266         mlink $TEMPNAME $1 2> /dev/null &&
2267                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2268         munlink $TEMPNAME
2269 }
2270
2271 test_31o() { # LU-2901
2272         mkdir -p $DIR/$tdir
2273         for LOOP in $(seq 100); do
2274                 rm -f $DIR/$tdir/$tfile*
2275                 for THREAD in $(seq 8); do
2276                         link_one $DIR/$tdir/$tfile.$LOOP &
2277                 done
2278                 wait
2279                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2280                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2281                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2282                         break || true
2283         done
2284 }
2285 run_test 31o "duplicate hard links with same filename"
2286
2287 test_31p() {
2288         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2289
2290         mkdir $DIR/$tdir
2291         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2292         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2293
2294         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2295                 error "open unlink test1 failed"
2296         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2297                 error "open unlink test2 failed"
2298
2299         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2300                 error "test1 still exists"
2301         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2302                 error "test2 still exists"
2303 }
2304 run_test 31p "remove of open striped directory"
2305
2306 cleanup_test32_mount() {
2307         trap 0
2308         $UMOUNT -d $DIR/$tdir/ext2-mountpoint
2309 }
2310
2311 test_32a() {
2312         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2313         echo "== more mountpoints and symlinks ================="
2314         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2315         trap cleanup_test32_mount EXIT
2316         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2317         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2318         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2319         cleanup_test32_mount
2320 }
2321 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2322
2323 test_32b() {
2324         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2325         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2326         trap cleanup_test32_mount EXIT
2327         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2328         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2329         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2330         cleanup_test32_mount
2331 }
2332 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2333
2334 test_32c() {
2335         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2336         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2337         trap cleanup_test32_mount EXIT
2338         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2339         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2340         test_mkdir -p $DIR/$tdir/d2/test_dir
2341         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2342         cleanup_test32_mount
2343 }
2344 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2345
2346 test_32d() {
2347         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2348         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2349         trap cleanup_test32_mount EXIT
2350         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2351         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2352         test_mkdir -p $DIR/$tdir/d2/test_dir
2353         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2354         cleanup_test32_mount
2355 }
2356 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2357
2358 test_32e() {
2359         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2360         test_mkdir -p $DIR/d32e/tmp
2361         TMP_DIR=$DIR/d32e/tmp
2362         ln -s $DIR/d32e $TMP_DIR/symlink11
2363         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2364         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2365         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2366 }
2367 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2368
2369 test_32f() {
2370         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2371         test_mkdir -p $DIR/d32f/tmp
2372         TMP_DIR=$DIR/d32f/tmp
2373         ln -s $DIR/d32f $TMP_DIR/symlink11
2374         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2375         ls $DIR/d32f/tmp/symlink11  || error
2376         ls $DIR/d32f/symlink01 || error
2377 }
2378 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2379
2380 test_32g() {
2381         TMP_DIR=$DIR/$tdir/tmp
2382         test_mkdir -p $DIR/$tdir/tmp
2383         test_mkdir $DIR/${tdir}2
2384         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2385         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2386         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2387         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2388         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2389         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2390 }
2391 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2392
2393 test_32h() {
2394         rm -fr $DIR/$tdir $DIR/${tdir}2
2395         TMP_DIR=$DIR/$tdir/tmp
2396         test_mkdir -p $DIR/$tdir/tmp
2397         test_mkdir $DIR/${tdir}2
2398         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2399         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2400         ls $TMP_DIR/symlink12 || error
2401         ls $DIR/$tdir/symlink02  || error
2402 }
2403 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2404
2405 test_32i() {
2406         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2407         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2408         trap cleanup_test32_mount EXIT
2409         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2410         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2411         touch $DIR/$tdir/test_file
2412         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2413         cleanup_test32_mount
2414 }
2415 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2416
2417 test_32j() {
2418         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2419         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2420         trap cleanup_test32_mount EXIT
2421         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2422         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2423         touch $DIR/$tdir/test_file
2424         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2425         cleanup_test32_mount
2426 }
2427 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2428
2429 test_32k() {
2430         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2431         rm -fr $DIR/$tdir
2432         trap cleanup_test32_mount EXIT
2433         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2434         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2435         test_mkdir -p $DIR/$tdir/d2
2436         touch $DIR/$tdir/d2/test_file || error
2437         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2438         cleanup_test32_mount
2439 }
2440 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2441
2442 test_32l() {
2443         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2444         rm -fr $DIR/$tdir
2445         trap cleanup_test32_mount EXIT
2446         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2447         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2448         test_mkdir -p $DIR/$tdir/d2
2449         touch $DIR/$tdir/d2/test_file
2450         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2451         cleanup_test32_mount
2452 }
2453 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2454
2455 test_32m() {
2456         rm -fr $DIR/d32m
2457         test_mkdir -p $DIR/d32m/tmp
2458         TMP_DIR=$DIR/d32m/tmp
2459         ln -s $DIR $TMP_DIR/symlink11
2460         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2461         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2462         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2463 }
2464 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2465
2466 test_32n() {
2467         rm -fr $DIR/d32n
2468         test_mkdir -p $DIR/d32n/tmp
2469         TMP_DIR=$DIR/d32n/tmp
2470         ln -s $DIR $TMP_DIR/symlink11
2471         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2472         ls -l $DIR/d32n/tmp/symlink11  || error
2473         ls -l $DIR/d32n/symlink01 || error
2474 }
2475 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2476
2477 test_32o() {
2478         touch $DIR/$tfile
2479         test_mkdir -p $DIR/d32o/tmp
2480         TMP_DIR=$DIR/d32o/tmp
2481         ln -s $DIR/$tfile $TMP_DIR/symlink12
2482         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2483         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2484         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2485         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2486         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2487 }
2488 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2489
2490 test_32p() {
2491     log 32p_1
2492         rm -fr $DIR/d32p
2493     log 32p_2
2494         rm -f $DIR/$tfile
2495     log 32p_3
2496         touch $DIR/$tfile
2497     log 32p_4
2498         test_mkdir -p $DIR/d32p/tmp
2499     log 32p_5
2500         TMP_DIR=$DIR/d32p/tmp
2501     log 32p_6
2502         ln -s $DIR/$tfile $TMP_DIR/symlink12
2503     log 32p_7
2504         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2505     log 32p_8
2506         cat $DIR/d32p/tmp/symlink12 || error
2507     log 32p_9
2508         cat $DIR/d32p/symlink02 || error
2509     log 32p_10
2510 }
2511 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2512
2513 cleanup_testdir_mount() {
2514         trap 0
2515         $UMOUNT -d $DIR/$tdir
2516 }
2517
2518 test_32q() {
2519         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2520         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2521         trap cleanup_testdir_mount EXIT
2522         test_mkdir -p $DIR/$tdir
2523         touch $DIR/$tdir/under_the_mount
2524         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2525         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2526         cleanup_testdir_mount
2527 }
2528 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2529
2530 test_32r() {
2531         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2532         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2533         trap cleanup_testdir_mount EXIT
2534         test_mkdir -p $DIR/$tdir
2535         touch $DIR/$tdir/under_the_mount
2536         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2537         ls $DIR/$tdir | grep -q under_the_mount && error || true
2538         cleanup_testdir_mount
2539 }
2540 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2541
2542 test_33aa() {
2543         rm -f $DIR/$tfile
2544         touch $DIR/$tfile
2545         chmod 444 $DIR/$tfile
2546         chown $RUNAS_ID $DIR/$tfile
2547         log 33_1
2548         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2549         log 33_2
2550 }
2551 run_test 33aa "write file with mode 444 (should return error) ===="
2552
2553 test_33a() {
2554         rm -fr $DIR/d33
2555         test_mkdir -p $DIR/d33
2556         chown $RUNAS_ID $DIR/d33
2557         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2558         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2559                 error "open RDWR" || true
2560 }
2561 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2562
2563 test_33b() {
2564         rm -fr $DIR/d33
2565         test_mkdir -p $DIR/d33
2566         chown $RUNAS_ID $DIR/d33
2567         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33
2568 }
2569 run_test 33b "test open file with malformed flags (No panic)"
2570
2571 test_33c() {
2572         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2573         local ostnum
2574         local ostname
2575         local write_bytes
2576         local all_zeros
2577
2578         remote_ost_nodsh && skip "remote OST with nodsh" && return
2579         all_zeros=:
2580         rm -fr $DIR/d33
2581         test_mkdir -p $DIR/d33
2582         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2583
2584         sync
2585         for ostnum in $(seq $OSTCOUNT); do
2586                 # test-framework's OST numbering is one-based, while Lustre's
2587                 # is zero-based
2588                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2589                 # Parsing llobdstat's output sucks; we could grep the /proc
2590                 # path, but that's likely to not be as portable as using the
2591                 # llobdstat utility.  So we parse lctl output instead.
2592                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2593                         obdfilter/$ostname/stats |
2594                         awk '/^write_bytes/ {print $7}' )
2595                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2596                 if (( ${write_bytes:-0} > 0 ))
2597                 then
2598                         all_zeros=false
2599                         break;
2600                 fi
2601         done
2602
2603         $all_zeros || return 0
2604
2605         # Write four bytes
2606         echo foo > $DIR/d33/bar
2607         # Really write them
2608         sync
2609
2610         # Total up write_bytes after writing.  We'd better find non-zeros.
2611         for ostnum in $(seq $OSTCOUNT); do
2612                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2613                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2614                         obdfilter/$ostname/stats |
2615                         awk '/^write_bytes/ {print $7}' )
2616                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2617                 if (( ${write_bytes:-0} > 0 ))
2618                 then
2619                         all_zeros=false
2620                         break;
2621                 fi
2622         done
2623
2624         if $all_zeros
2625         then
2626                 for ostnum in $(seq $OSTCOUNT); do
2627                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2628                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2629                         do_facet ost$ostnum lctl get_param -n \
2630                                 obdfilter/$ostname/stats
2631                 done
2632                 error "OST not keeping write_bytes stats (b22312)"
2633         fi
2634 }
2635 run_test 33c "test llobdstat and write_bytes"
2636
2637 test_33d() {
2638         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2639         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2640         local MDTIDX=1
2641         local remote_dir=$DIR/$tdir/remote_dir
2642
2643         mkdir -p $DIR/$tdir
2644         $LFS mkdir -i $MDTIDX $remote_dir ||
2645                 error "create remote directory failed"
2646
2647         touch $remote_dir/$tfile
2648         chmod 444 $remote_dir/$tfile
2649         chown $RUNAS_ID $remote_dir/$tfile
2650
2651         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2652
2653         chown $RUNAS_ID $remote_dir
2654         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2655                                         error "create" || true
2656         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2657                                     error "open RDWR" || true
2658         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2659                                     error "create" || true
2660 }
2661 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2662
2663 test_33e() {
2664         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2665
2666         mkdir $DIR/$tdir
2667
2668         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2669         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2670         mkdir $DIR/$tdir/local_dir
2671
2672         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2673         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2674         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2675
2676         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2677                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2678
2679         rmdir $DIR/$tdir/* || error "rmdir failed"
2680
2681         umask 777
2682         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2683         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2684         mkdir $DIR/$tdir/local_dir
2685
2686         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2687         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2688         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2689
2690         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2691                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2692
2693         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2694
2695         umask 000
2696         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2697         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2698         mkdir $DIR/$tdir/local_dir
2699
2700         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2701         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2702         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2703
2704         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2705                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2706 }
2707 run_test 33e "mkdir and striped directory should have same mode"
2708
2709 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2710 test_34a() {
2711         rm -f $DIR/f34
2712         $MCREATE $DIR/f34 || error
2713         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2714         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2715         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2716         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2717 }
2718 run_test 34a "truncate file that has not been opened ==========="
2719
2720 test_34b() {
2721         [ ! -f $DIR/f34 ] && test_34a
2722         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2723         $OPENFILE -f O_RDONLY $DIR/f34
2724         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2725         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2726 }
2727 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2728
2729 test_34c() {
2730         [ ! -f $DIR/f34 ] && test_34a
2731         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2732         $OPENFILE -f O_RDWR $DIR/f34
2733         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2734         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2735 }
2736 run_test 34c "O_RDWR opening file-with-size works =============="
2737
2738 test_34d() {
2739         [ ! -f $DIR/f34 ] && test_34a
2740         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2741         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2742         rm $DIR/f34
2743 }
2744 run_test 34d "write to sparse file ============================="
2745
2746 test_34e() {
2747         rm -f $DIR/f34e
2748         $MCREATE $DIR/f34e || error
2749         $TRUNCATE $DIR/f34e 1000 || error
2750         $CHECKSTAT -s 1000 $DIR/f34e || error
2751         $OPENFILE -f O_RDWR $DIR/f34e
2752         $CHECKSTAT -s 1000 $DIR/f34e || error
2753 }
2754 run_test 34e "create objects, some with size and some without =="
2755
2756 test_34f() { # bug 6242, 6243
2757         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2758         SIZE34F=48000
2759         rm -f $DIR/f34f
2760         $MCREATE $DIR/f34f || error
2761         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2762         dd if=$DIR/f34f of=$TMP/f34f
2763         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2764         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2765         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2766         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2767         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2768 }
2769 run_test 34f "read from a file with no objects until EOF ======="
2770
2771 test_34g() {
2772         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2773         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2774         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2775         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2776         cancel_lru_locks osc
2777         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2778                 error "wrong size after lock cancel"
2779
2780         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2781         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2782                 error "expanding truncate failed"
2783         cancel_lru_locks osc
2784         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2785                 error "wrong expanded size after lock cancel"
2786 }
2787 run_test 34g "truncate long file ==============================="
2788
2789 test_34h() {
2790         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2791         local gid=10
2792         local sz=1000
2793
2794         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2795         sync # Flush the cache so that multiop below does not block on cache
2796              # flush when getting the group lock
2797         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2798         MULTIPID=$!
2799
2800         # Since just timed wait is not good enough, let's do a sync write
2801         # that way we are sure enough time for a roundtrip + processing
2802         # passed + 2 seconds of extra margin.
2803         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2804         rm $DIR/${tfile}-1
2805         sleep 2
2806
2807         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2808                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2809                 kill -9 $MULTIPID
2810         fi
2811         wait $MULTIPID
2812         local nsz=`stat -c %s $DIR/$tfile`
2813         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2814 }
2815 run_test 34h "ftruncate file under grouplock should not block"
2816
2817 test_35a() {
2818         cp /bin/sh $DIR/f35a
2819         chmod 444 $DIR/f35a
2820         chown $RUNAS_ID $DIR/f35a
2821         $RUNAS $DIR/f35a && error || true
2822         rm $DIR/f35a
2823 }
2824 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2825
2826 test_36a() {
2827         rm -f $DIR/f36
2828         utime $DIR/f36 || error
2829 }
2830 run_test 36a "MDS utime check (mknod, utime) ==================="
2831
2832 test_36b() {
2833         echo "" > $DIR/f36
2834         utime $DIR/f36 || error
2835 }
2836 run_test 36b "OST utime check (open, utime) ===================="
2837
2838 test_36c() {
2839         rm -f $DIR/d36/f36
2840         test_mkdir $DIR/d36
2841         chown $RUNAS_ID $DIR/d36
2842         $RUNAS utime $DIR/d36/f36 || error
2843 }
2844 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2845
2846 test_36d() {
2847         [ ! -d $DIR/d36 ] && test_36c
2848         echo "" > $DIR/d36/f36
2849         $RUNAS utime $DIR/d36/f36 || error
2850 }
2851 run_test 36d "non-root OST utime check (open, utime) ==========="
2852
2853 test_36e() {
2854         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2855         test_mkdir -p $DIR/$tdir
2856         touch $DIR/$tdir/$tfile
2857         $RUNAS utime $DIR/$tdir/$tfile && \
2858                 error "utime worked, expected failure" || true
2859 }
2860 run_test 36e "utime on non-owned file (should return error) ===="
2861
2862 subr_36fh() {
2863         local fl="$1"
2864         local LANG_SAVE=$LANG
2865         local LC_LANG_SAVE=$LC_LANG
2866         export LANG=C LC_LANG=C # for date language
2867
2868         DATESTR="Dec 20  2000"
2869         test_mkdir -p $DIR/$tdir
2870         lctl set_param fail_loc=$fl
2871         date; date +%s
2872         cp /etc/hosts $DIR/$tdir/$tfile
2873         sync & # write RPC generated with "current" inode timestamp, but delayed
2874         sleep 1
2875         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2876         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2877         cancel_lru_locks osc
2878         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2879         date; date +%s
2880         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2881                 echo "BEFORE: $LS_BEFORE" && \
2882                 echo "AFTER : $LS_AFTER" && \
2883                 echo "WANT  : $DATESTR" && \
2884                 error "$DIR/$tdir/$tfile timestamps changed" || true
2885
2886         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2887 }
2888
2889 test_36f() {
2890         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2891         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2892         subr_36fh "0x80000214"
2893 }
2894 run_test 36f "utime on file racing with OST BRW write =========="
2895
2896 test_36g() {
2897         remote_ost_nodsh && skip "remote OST with nodsh" && return
2898         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2899         local fmd_max_age
2900         local fmd_before
2901         local fmd_after
2902
2903         test_mkdir -p $DIR/$tdir
2904         fmd_max_age=$(do_facet ost1 \
2905                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2906                 head -n 1")
2907
2908         fmd_before=$(do_facet ost1 \
2909                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2910         touch $DIR/$tdir/$tfile
2911         sleep $((fmd_max_age + 12))
2912         fmd_after=$(do_facet ost1 \
2913                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2914
2915         echo "fmd_before: $fmd_before"
2916         echo "fmd_after: $fmd_after"
2917         [[ $fmd_after -gt $fmd_before ]] &&
2918                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
2919                 error "fmd didn't expire after ping" || true
2920 }
2921 run_test 36g "filter mod data cache expiry ====================="
2922
2923 test_36h() {
2924         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2925         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2926         subr_36fh "0x80000227"
2927 }
2928 run_test 36h "utime on file racing with OST BRW write =========="
2929
2930 test_36i() {
2931         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2932
2933         mkdir $DIR/$tdir
2934         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
2935
2936         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
2937         local new_mtime=$((mtime + 200))
2938
2939         #change Modify time of striped dir
2940         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
2941                         error "change mtime failed"
2942
2943         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
2944
2945         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
2946 }
2947 run_test 36i "change mtime on striped directory"
2948
2949 # test_37 - duplicate with tests 32q 32r
2950
2951 test_38() {
2952         local file=$DIR/$tfile
2953         touch $file
2954         openfile -f O_DIRECTORY $file
2955         local RC=$?
2956         local ENOTDIR=20
2957         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2958         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2959 }
2960 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2961
2962 test_39() {
2963         touch $DIR/$tfile
2964         touch $DIR/${tfile}2
2965 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2966 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2967 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2968         sleep 2
2969         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2970         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2971                 echo "mtime"
2972                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2973                 echo "atime"
2974                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2975                 echo "ctime"
2976                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2977                 error "O_TRUNC didn't change timestamps"
2978         fi
2979 }
2980 run_test 39 "mtime changed on create ==========================="
2981
2982 test_39b() {
2983         test_mkdir -p -c1 $DIR/$tdir
2984         cp -p /etc/passwd $DIR/$tdir/fopen
2985         cp -p /etc/passwd $DIR/$tdir/flink
2986         cp -p /etc/passwd $DIR/$tdir/funlink
2987         cp -p /etc/passwd $DIR/$tdir/frename
2988         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2989
2990         sleep 1
2991         echo "aaaaaa" >> $DIR/$tdir/fopen
2992         echo "aaaaaa" >> $DIR/$tdir/flink
2993         echo "aaaaaa" >> $DIR/$tdir/funlink
2994         echo "aaaaaa" >> $DIR/$tdir/frename
2995
2996         local open_new=`stat -c %Y $DIR/$tdir/fopen`
2997         local link_new=`stat -c %Y $DIR/$tdir/flink`
2998         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
2999         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3000
3001         cat $DIR/$tdir/fopen > /dev/null
3002         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3003         rm -f $DIR/$tdir/funlink2
3004         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3005
3006         for (( i=0; i < 2; i++ )) ; do
3007                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3008                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3009                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3010                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3011
3012                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3013                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3014                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3015                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3016
3017                 cancel_lru_locks osc
3018                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3019         done
3020 }
3021 run_test 39b "mtime change on open, link, unlink, rename  ======"
3022
3023 # this should be set to past
3024 TEST_39_MTIME=`date -d "1 year ago" +%s`
3025
3026 # bug 11063
3027 test_39c() {
3028         touch $DIR1/$tfile
3029         sleep 2
3030         local mtime0=`stat -c %Y $DIR1/$tfile`
3031
3032         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3033         local mtime1=`stat -c %Y $DIR1/$tfile`
3034         [ "$mtime1" = $TEST_39_MTIME ] || \
3035                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3036
3037         local d1=`date +%s`
3038         echo hello >> $DIR1/$tfile
3039         local d2=`date +%s`
3040         local mtime2=`stat -c %Y $DIR1/$tfile`
3041         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3042                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3043
3044         mv $DIR1/$tfile $DIR1/$tfile-1
3045
3046         for (( i=0; i < 2; i++ )) ; do
3047                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3048                 [ "$mtime2" = "$mtime3" ] || \
3049                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3050
3051                 cancel_lru_locks osc
3052                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3053         done
3054 }
3055 run_test 39c "mtime change on rename ==========================="
3056
3057 # bug 21114
3058 test_39d() {
3059         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3060         touch $DIR1/$tfile
3061
3062         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3063
3064         for (( i=0; i < 2; i++ )) ; do
3065                 local mtime=`stat -c %Y $DIR1/$tfile`
3066                 [ $mtime = $TEST_39_MTIME ] || \
3067                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3068
3069                 cancel_lru_locks osc
3070                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3071         done
3072 }
3073 run_test 39d "create, utime, stat =============================="
3074
3075 # bug 21114
3076 test_39e() {
3077         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3078         touch $DIR1/$tfile
3079         local mtime1=`stat -c %Y $DIR1/$tfile`
3080
3081         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3082
3083         for (( i=0; i < 2; i++ )) ; do
3084                 local mtime2=`stat -c %Y $DIR1/$tfile`
3085                 [ $mtime2 = $TEST_39_MTIME ] || \
3086                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3087
3088                 cancel_lru_locks osc
3089                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3090         done
3091 }
3092 run_test 39e "create, stat, utime, stat ========================"
3093
3094 # bug 21114
3095 test_39f() {
3096         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3097         touch $DIR1/$tfile
3098         mtime1=`stat -c %Y $DIR1/$tfile`
3099
3100         sleep 2
3101         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3102
3103         for (( i=0; i < 2; i++ )) ; do
3104                 local mtime2=`stat -c %Y $DIR1/$tfile`
3105                 [ $mtime2 = $TEST_39_MTIME ] || \
3106                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3107
3108                 cancel_lru_locks osc
3109                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3110         done
3111 }
3112 run_test 39f "create, stat, sleep, utime, stat ================="
3113
3114 # bug 11063
3115 test_39g() {
3116         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3117         echo hello >> $DIR1/$tfile
3118         local mtime1=`stat -c %Y $DIR1/$tfile`
3119
3120         sleep 2
3121         chmod o+r $DIR1/$tfile
3122
3123         for (( i=0; i < 2; i++ )) ; do
3124                 local mtime2=`stat -c %Y $DIR1/$tfile`
3125                 [ "$mtime1" = "$mtime2" ] || \
3126                         error "lost mtime: $mtime2, should be $mtime1"
3127
3128                 cancel_lru_locks osc
3129                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3130         done
3131 }
3132 run_test 39g "write, chmod, stat ==============================="
3133
3134 # bug 11063
3135 test_39h() {
3136         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3137         touch $DIR1/$tfile
3138         sleep 1
3139
3140         local d1=`date`
3141         echo hello >> $DIR1/$tfile
3142         local mtime1=`stat -c %Y $DIR1/$tfile`
3143
3144         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3145         local d2=`date`
3146         if [ "$d1" != "$d2" ]; then
3147                 echo "write and touch not within one second"
3148         else
3149                 for (( i=0; i < 2; i++ )) ; do
3150                         local mtime2=`stat -c %Y $DIR1/$tfile`
3151                         [ "$mtime2" = $TEST_39_MTIME ] || \
3152                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3153
3154                         cancel_lru_locks osc
3155                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3156                 done
3157         fi
3158 }
3159 run_test 39h "write, utime within one second, stat ============="
3160
3161 test_39i() {
3162         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3163         touch $DIR1/$tfile
3164         sleep 1
3165
3166         echo hello >> $DIR1/$tfile
3167         local mtime1=`stat -c %Y $DIR1/$tfile`
3168
3169         mv $DIR1/$tfile $DIR1/$tfile-1
3170
3171         for (( i=0; i < 2; i++ )) ; do
3172                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3173
3174                 [ "$mtime1" = "$mtime2" ] || \
3175                         error "lost mtime: $mtime2, should be $mtime1"
3176
3177                 cancel_lru_locks osc
3178                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3179         done
3180 }
3181 run_test 39i "write, rename, stat =============================="
3182
3183 test_39j() {
3184         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3185         start_full_debug_logging
3186         touch $DIR1/$tfile
3187         sleep 1
3188
3189         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3190         lctl set_param fail_loc=0x80000412
3191         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3192                 error "multiop failed"
3193         local multipid=$!
3194         local mtime1=`stat -c %Y $DIR1/$tfile`
3195
3196         mv $DIR1/$tfile $DIR1/$tfile-1
3197
3198         kill -USR1 $multipid
3199         wait $multipid || error "multiop close failed"
3200
3201         for (( i=0; i < 2; i++ )) ; do
3202                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3203                 [ "$mtime1" = "$mtime2" ] ||
3204                         error "mtime is lost on close: $mtime2, " \
3205                               "should be $mtime1"
3206
3207                 cancel_lru_locks osc
3208                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3209         done
3210         lctl set_param fail_loc=0
3211         stop_full_debug_logging
3212 }
3213 run_test 39j "write, rename, close, stat ======================="
3214
3215 test_39k() {
3216         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3217         touch $DIR1/$tfile
3218         sleep 1
3219
3220         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3221         local multipid=$!
3222         local mtime1=`stat -c %Y $DIR1/$tfile`
3223
3224         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3225
3226         kill -USR1 $multipid
3227         wait $multipid || error "multiop close failed"
3228
3229         for (( i=0; i < 2; i++ )) ; do
3230                 local mtime2=`stat -c %Y $DIR1/$tfile`
3231
3232                 [ "$mtime2" = $TEST_39_MTIME ] || \
3233                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3234
3235                 cancel_lru_locks osc
3236                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3237         done
3238 }
3239 run_test 39k "write, utime, close, stat ========================"
3240
3241 # this should be set to future
3242 TEST_39_ATIME=`date -d "1 year" +%s`
3243
3244 test_39l() {
3245         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3246         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3247         local atime_diff=$(do_facet $SINGLEMDS \
3248                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3249         rm -rf $DIR/$tdir
3250         mkdir -p $DIR/$tdir
3251
3252         # test setting directory atime to future
3253         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3254         local atime=$(stat -c %X $DIR/$tdir)
3255         [ "$atime" = $TEST_39_ATIME ] || \
3256                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3257
3258         # test setting directory atime from future to now
3259         local d1=$(date +%s)
3260         ls $DIR/$tdir
3261         local d2=$(date +%s)
3262
3263         cancel_lru_locks mdc
3264         atime=$(stat -c %X $DIR/$tdir)
3265         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3266                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3267
3268         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3269         sleep 3
3270
3271         # test setting directory atime when now > dir atime + atime_diff
3272         d1=$(date +%s)
3273         ls $DIR/$tdir
3274         d2=$(date +%s)
3275         cancel_lru_locks mdc
3276         atime=$(stat -c %X $DIR/$tdir)
3277         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3278                 error "atime is not updated  : $atime, should be $d2"
3279
3280         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3281         sleep 3
3282
3283         # test not setting directory atime when now < dir atime + atime_diff
3284         ls $DIR/$tdir
3285         cancel_lru_locks mdc
3286         atime=$(stat -c %X $DIR/$tdir)
3287         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3288                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3289
3290         do_facet $SINGLEMDS \
3291                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3292 }
3293 run_test 39l "directory atime update ==========================="
3294
3295 test_39m() {
3296         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3297         touch $DIR1/$tfile
3298         sleep 2
3299         local far_past_mtime=$(date -d "May 29 1953" +%s)
3300         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3301
3302         touch -m -d @$far_past_mtime $DIR1/$tfile
3303         touch -a -d @$far_past_atime $DIR1/$tfile
3304
3305         for (( i=0; i < 2; i++ )) ; do
3306                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3307                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3308                         error "atime or mtime set incorrectly"
3309
3310                 cancel_lru_locks osc
3311                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3312         done
3313 }
3314 run_test 39m "test atime and mtime before 1970"
3315
3316 test_39n() { # LU-3832
3317         local atime_diff=$(do_facet $SINGLEMDS \
3318                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3319         local atime0
3320         local atime1
3321         local atime2
3322
3323         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3324
3325         rm -rf $DIR/$tfile
3326         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3327         atime0=$(stat -c %X $DIR/$tfile)
3328
3329         sleep 5
3330         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3331         atime1=$(stat -c %X $DIR/$tfile)
3332
3333         sleep 5
3334         cancel_lru_locks mdc
3335         cancel_lru_locks osc
3336         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3337         atime2=$(stat -c %X $DIR/$tfile)
3338
3339         do_facet $SINGLEMDS \
3340                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3341
3342         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3343         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3344 }
3345 run_test 39n "check that O_NOATIME is honored"
3346
3347 test_39o() {
3348         TESTDIR=$DIR/$tdir/$tfile
3349         [ -e $TESTDIR ] && rm -rf $TESTDIR
3350         test_mkdir -p $TESTDIR
3351         cd $TESTDIR
3352         links1=2
3353         ls
3354         mkdir a b
3355         ls
3356         links2=$(stat -c %h .)
3357         [ $(($links1 + 2)) != $links2 ] &&
3358                 error "wrong links count $(($links1 + 2)) != $links2"
3359         rmdir b
3360         links3=$(stat -c %h .)
3361         [ $(($links1 + 1)) != $links3 ] &&
3362                 error "wrong links count $links1 != $links3"
3363         return 0
3364 }
3365 run_test 39o "directory cached attributes updated after create ========"
3366
3367 test_39p() {
3368         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3369         local MDTIDX=1
3370         TESTDIR=$DIR/$tdir/$tfile
3371         [ -e $TESTDIR ] && rm -rf $TESTDIR
3372         mkdir -p $TESTDIR
3373         cd $TESTDIR
3374         links1=2
3375         ls
3376         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3377         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3378         ls
3379         links2=$(stat -c %h .)
3380         [ $(($links1 + 2)) != $links2 ] &&
3381                 error "wrong links count $(($links1 + 2)) != $links2"
3382         rmdir remote_dir2
3383         links3=$(stat -c %h .)
3384         [ $(($links1 + 1)) != $links3 ] &&
3385                 error "wrong links count $links1 != $links3"
3386         return 0
3387 }
3388 run_test 39p "remote directory cached attributes updated after create ========"
3389
3390
3391 test_40() {
3392         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3393         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3394                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3395         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3396                 error "$tfile is not 4096 bytes in size"
3397 }
3398 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3399
3400 test_41() {
3401         # bug 1553
3402         small_write $DIR/f41 18
3403 }
3404 run_test 41 "test small file write + fstat ====================="
3405
3406 count_ost_writes() {
3407         lctl get_param -n osc.*.stats |
3408                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3409                         END { printf("%0.0f", writes) }'
3410 }
3411
3412 # decent default
3413 WRITEBACK_SAVE=500
3414 DIRTY_RATIO_SAVE=40
3415 MAX_DIRTY_RATIO=50
3416 BG_DIRTY_RATIO_SAVE=10
3417 MAX_BG_DIRTY_RATIO=25
3418
3419 start_writeback() {
3420         trap 0
3421         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3422         # dirty_ratio, dirty_background_ratio
3423         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3424                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3425                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3426                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3427         else
3428                 # if file not here, we are a 2.4 kernel
3429                 kill -CONT `pidof kupdated`
3430         fi
3431 }
3432
3433 stop_writeback() {
3434         # setup the trap first, so someone cannot exit the test at the
3435         # exact wrong time and mess up a machine
3436         trap start_writeback EXIT
3437         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3438         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3439                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3440                 sysctl -w vm.dirty_writeback_centisecs=0
3441                 sysctl -w vm.dirty_writeback_centisecs=0
3442                 # save and increase /proc/sys/vm/dirty_ratio
3443                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3444                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3445                 # save and increase /proc/sys/vm/dirty_background_ratio
3446                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3447                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3448         else
3449                 # if file not here, we are a 2.4 kernel
3450                 kill -STOP `pidof kupdated`
3451         fi
3452 }
3453
3454 # ensure that all stripes have some grant before we test client-side cache
3455 setup_test42() {
3456         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3457                 dd if=/dev/zero of=$i bs=4k count=1
3458                 rm $i
3459         done
3460 }
3461
3462 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3463 # file truncation, and file removal.
3464 test_42a() {
3465         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3466         setup_test42
3467         cancel_lru_locks osc
3468         stop_writeback
3469         sync; sleep 1; sync # just to be safe
3470         BEFOREWRITES=`count_ost_writes`
3471         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3472         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3473         AFTERWRITES=`count_ost_writes`
3474         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3475                 error "$BEFOREWRITES < $AFTERWRITES"
3476         start_writeback
3477 }
3478 run_test 42a "ensure that we don't flush on close =============="
3479
3480 test_42b() {
3481         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3482         setup_test42
3483         cancel_lru_locks osc
3484         stop_writeback
3485         sync
3486         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3487         BEFOREWRITES=$(count_ost_writes)
3488         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3489         AFTERWRITES=$(count_ost_writes)
3490         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3491                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3492         fi
3493         BEFOREWRITES=$(count_ost_writes)
3494         sync || error "sync: $?"
3495         AFTERWRITES=$(count_ost_writes)
3496         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3497                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3498         fi
3499         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3500         start_writeback
3501         return 0
3502 }
3503 run_test 42b "test destroy of file with cached dirty data ======"
3504
3505 # if these tests just want to test the effect of truncation,
3506 # they have to be very careful.  consider:
3507 # - the first open gets a {0,EOF}PR lock
3508 # - the first write conflicts and gets a {0, count-1}PW
3509 # - the rest of the writes are under {count,EOF}PW
3510 # - the open for truncate tries to match a {0,EOF}PR
3511 #   for the filesize and cancels the PWs.
3512 # any number of fixes (don't get {0,EOF} on open, match
3513 # composite locks, do smarter file size management) fix
3514 # this, but for now we want these tests to verify that
3515 # the cancellation with truncate intent works, so we
3516 # start the file with a full-file pw lock to match against
3517 # until the truncate.
3518 trunc_test() {
3519         test=$1
3520         file=$DIR/$test
3521         offset=$2
3522         cancel_lru_locks osc
3523         stop_writeback
3524         # prime the file with 0,EOF PW to match
3525         touch $file
3526         $TRUNCATE $file 0
3527         sync; sync
3528         # now the real test..
3529         dd if=/dev/zero of=$file bs=1024 count=100
3530         BEFOREWRITES=`count_ost_writes`
3531         $TRUNCATE $file $offset
3532         cancel_lru_locks osc
3533         AFTERWRITES=`count_ost_writes`
3534         start_writeback
3535 }
3536
3537 test_42c() {
3538         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3539         trunc_test 42c 1024
3540         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3541             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3542         rm $file
3543 }
3544 run_test 42c "test partial truncate of file with cached dirty data"
3545
3546 test_42d() {
3547         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3548         trunc_test 42d 0
3549         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3550             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3551         rm $file
3552 }
3553 run_test 42d "test complete truncate of file with cached dirty data"
3554
3555 test_42e() { # bug22074
3556         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3557         local TDIR=$DIR/${tdir}e
3558         local pagesz=$(page_size)
3559         local pages=16 # hardcoded 16 pages, don't change it.
3560         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3561         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3562         local max_dirty_mb
3563         local warmup_files
3564
3565         test_mkdir -p $DIR/${tdir}e
3566         $SETSTRIPE -c 1 $TDIR
3567         createmany -o $TDIR/f $files
3568
3569         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3570
3571         # we assume that with $OSTCOUNT files, at least one of them will
3572         # be allocated on OST0.
3573         warmup_files=$((OSTCOUNT * max_dirty_mb))
3574         createmany -o $TDIR/w $warmup_files
3575
3576         # write a large amount of data into one file and sync, to get good
3577         # avail_grant number from OST.
3578         for ((i=0; i<$warmup_files; i++)); do
3579                 idx=$($GETSTRIPE -i $TDIR/w$i)
3580                 [ $idx -ne 0 ] && continue
3581                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3582                 break
3583         done
3584         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3585         sync
3586         $LCTL get_param $proc_osc0/cur_dirty_bytes
3587         $LCTL get_param $proc_osc0/cur_grant_bytes
3588
3589         # create as much dirty pages as we can while not to trigger the actual
3590         # RPCs directly. but depends on the env, VFS may trigger flush during this
3591         # period, hopefully we are good.
3592         for ((i=0; i<$warmup_files; i++)); do
3593                 idx=$($GETSTRIPE -i $TDIR/w$i)
3594                 [ $idx -ne 0 ] && continue
3595                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3596         done
3597         $LCTL get_param $proc_osc0/cur_dirty_bytes
3598         $LCTL get_param $proc_osc0/cur_grant_bytes
3599
3600         # perform the real test
3601         $LCTL set_param $proc_osc0/rpc_stats 0
3602         for ((;i<$files; i++)); do
3603                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3604                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3605         done
3606         sync
3607         $LCTL get_param $proc_osc0/rpc_stats
3608
3609         local percent=0
3610         local have_ppr=false
3611         $LCTL get_param $proc_osc0/rpc_stats |
3612                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3613                         # skip lines until we are at the RPC histogram data
3614                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3615                         $have_ppr || continue
3616
3617                         # we only want the percent stat for < 16 pages
3618                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3619
3620                         percent=$((percent + WPCT))
3621                         if [[ $percent -gt 15 ]]; then
3622                                 error "less than 16-pages write RPCs" \
3623                                       "$percent% > 15%"
3624                                 break
3625                         fi
3626                 done
3627         rm -rf $TDIR
3628 }
3629 run_test 42e "verify sub-RPC writes are not done synchronously"
3630
3631 test_43() {
3632         test_mkdir -p $DIR/$tdir
3633         cp -p /bin/ls $DIR/$tdir/$tfile
3634         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3635         pid=$!
3636         # give multiop a chance to open
3637         sleep 1
3638
3639         $DIR/$tdir/$tfile && error || true
3640         kill -USR1 $pid
3641 }
3642 run_test 43 "execution of file opened for write should return -ETXTBSY"
3643
3644 test_43a() {
3645         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3646         test_mkdir -p $DIR/$tdir
3647         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3648                         cp -p multiop $DIR/$tdir/multiop
3649         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3650                         return 1
3651         MULTIOP_PID=$!
3652         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3653         kill -USR1 $MULTIOP_PID || return 2
3654         wait $MULTIOP_PID || return 3
3655         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3656 }
3657 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3658
3659 test_43b() {
3660         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3661         test_mkdir -p $DIR/$tdir
3662         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3663                         cp -p multiop $DIR/$tdir/multiop
3664         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3665                         return 1
3666         MULTIOP_PID=$!
3667         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3668         kill -USR1 $MULTIOP_PID || return 2
3669         wait $MULTIOP_PID || return 3
3670         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3671 }
3672 run_test 43b "truncate of file being executed should return -ETXTBSY"
3673
3674 test_43c() {
3675         local testdir="$DIR/$tdir"
3676         test_mkdir -p $DIR/$tdir
3677         cp $SHELL $testdir/
3678         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3679                 ( cd $testdir && md5sum -c)
3680 }
3681 run_test 43c "md5sum of copy into lustre========================"
3682
3683 test_44() {
3684         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3685         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3686         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3687 }
3688 run_test 44 "zero length read from a sparse stripe ============="
3689
3690 test_44a() {
3691         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3692                 awk '{ print $2 }')
3693         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3694         [[ $nstripe -gt $OSTCOUNT ]] &&
3695             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3696             return
3697         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3698                 awk '{ print $2 }')
3699         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3700                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3701                         awk '{ print $2 }')
3702         fi
3703
3704         OFFSETS="0 $((stride/2)) $((stride-1))"
3705         for offset in $OFFSETS; do
3706                 for i in $(seq 0 $((nstripe-1))); do
3707                         local GLOBALOFFSETS=""
3708                         # size in Bytes
3709                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3710                         local myfn=$DIR/d44a-$size
3711                         echo "--------writing $myfn at $size"
3712                         ll_sparseness_write $myfn $size ||
3713                                 error "ll_sparseness_write"
3714                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3715                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3716                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3717
3718                         for j in $(seq 0 $((nstripe-1))); do
3719                                 # size in Bytes
3720                                 size=$((((j + $nstripe )*$stride + $offset)))
3721                                 ll_sparseness_write $myfn $size ||
3722                                         error "ll_sparseness_write"
3723                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3724                         done
3725                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3726                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3727                         rm -f $myfn
3728                 done
3729         done
3730 }
3731 run_test 44a "test sparse pwrite ==============================="
3732
3733 dirty_osc_total() {
3734         tot=0
3735         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3736                 tot=$(($tot + $d))
3737         done
3738         echo $tot
3739 }
3740 do_dirty_record() {
3741         before=`dirty_osc_total`
3742         echo executing "\"$*\""
3743         eval $*
3744         after=`dirty_osc_total`
3745         echo before $before, after $after
3746 }
3747 test_45() {
3748         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3749         f="$DIR/f45"
3750         # Obtain grants from OST if it supports it
3751         echo blah > ${f}_grant
3752         stop_writeback
3753         sync
3754         do_dirty_record "echo blah > $f"
3755         [[ $before -eq $after ]] && error "write wasn't cached"
3756         do_dirty_record "> $f"
3757         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3758         do_dirty_record "echo blah > $f"
3759         [[ $before -eq $after ]] && error "write wasn't cached"
3760         do_dirty_record "sync"
3761         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3762         do_dirty_record "echo blah > $f"
3763         [[ $before -eq $after ]] && error "write wasn't cached"
3764         do_dirty_record "cancel_lru_locks osc"
3765         [[ $before -gt $after ]] ||
3766                 error "lock cancellation didn't lower dirty count"
3767         start_writeback
3768 }
3769 run_test 45 "osc io page accounting ============================"
3770
3771 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3772 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3773 # objects offset and an assert hit when an rpc was built with 1023's mapped
3774 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3775 test_46() {
3776         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3777         f="$DIR/f46"
3778         stop_writeback
3779         sync
3780         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3781         sync
3782         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3783         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3784         sync
3785         start_writeback
3786 }
3787 run_test 46 "dirtying a previously written page ================"
3788
3789 # test_47 is removed "Device nodes check" is moved to test_28
3790
3791 test_48a() { # bug 2399
3792         check_kernel_version 34 || return 0
3793         test_mkdir -p $DIR/$tdir
3794         cd $DIR/$tdir
3795         mv $DIR/$tdir $DIR/d48.new || error "move directory failed"
3796         test_mkdir $DIR/$tdir || error "recreate directory failed"
3797         touch foo || error "'touch foo' failed after recreating cwd"
3798         test_mkdir $DIR/$tdir/bar ||
3799                      error "'mkdir foo' failed after recreating cwd"
3800         if check_kernel_version 44; then
3801                 touch .foo || error "'touch .foo' failed after recreating cwd"
3802                 test_mkdir $DIR/$tdir/.bar ||
3803                               error "'mkdir .foo' failed after recreating cwd"
3804         fi
3805         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3806         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3807         cd . || error "'cd .' failed after recreating cwd"
3808         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3809         rmdir . && error "'rmdir .' worked after recreating cwd"
3810         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3811         cd .. || error "'cd ..' failed after recreating cwd"
3812 }
3813 run_test 48a "Access renamed working dir (should return errors)="
3814
3815 test_48b() { # bug 2399
3816         check_kernel_version 34 || return 0
3817         rm -rf $DIR/$tdir
3818         test_mkdir -p $DIR/$tdir
3819         cd $DIR/$tdir
3820         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3821         touch foo && error "'touch foo' worked after removing cwd"
3822         test_mkdir $DIR/$tdir/foo &&
3823                      error "'mkdir foo' worked after removing cwd"
3824         if check_kernel_version 44; then
3825                 touch .foo && error "'touch .foo' worked after removing cwd"
3826                 test_mkdir $DIR/$tdir/.foo &&
3827                               error "'mkdir .foo' worked after removing cwd"
3828         fi
3829         ls . > /dev/null && error "'ls .' worked after removing cwd"
3830         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3831         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3832         test_mkdir $DIR/$tdir/. && error "'mkdir .' worked after removing cwd"
3833         rmdir . && error "'rmdir .' worked after removing cwd"
3834         ln -s . foo && error "'ln -s .' worked after removing cwd"
3835         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3836 }
3837 run_test 48b "Access removed working dir (should return errors)="
3838
3839 test_48c() { # bug 2350
3840         check_kernel_version 36 || return 0
3841         #lctl set_param debug=-1
3842         #set -vx
3843         rm -rf $DIR/$tdir
3844         test_mkdir -p $DIR/$tdir/dir
3845         cd $DIR/$tdir/dir
3846         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3847         $TRACE touch foo && error "touch foo worked after removing cwd"
3848         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3849         if check_kernel_version 44; then
3850                 touch .foo && error "touch .foo worked after removing cwd"
3851                 test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3852         fi
3853         $TRACE ls . && error "'ls .' worked after removing cwd"
3854         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3855         is_patchless || ( $TRACE cd . &&
3856                         error "'cd .' worked after removing cwd" )
3857         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3858         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3859         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3860         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3861 }
3862 run_test 48c "Access removed working subdir (should return errors)"
3863
3864 test_48d() { # bug 2350
3865         check_kernel_version 36 || return 0
3866         #lctl set_param debug=-1
3867         #set -vx
3868         rm -rf $DIR/$tdir
3869         test_mkdir -p $DIR/$tdir/dir
3870         cd $DIR/$tdir/dir
3871         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3872         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3873         $TRACE touch foo && error "'touch foo' worked after removing parent"
3874         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3875         if check_kernel_version 44; then
3876                 touch .foo && error "'touch .foo' worked after removing parent"
3877                 test_mkdir .foo &&
3878                               error "mkdir .foo worked after removing parent"
3879         fi
3880         $TRACE ls . && error "'ls .' worked after removing parent"
3881         $TRACE ls .. && error "'ls ..' worked after removing parent"
3882         is_patchless || ( $TRACE cd . &&
3883                         error "'cd .' worked after recreate parent" )
3884         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3885         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3886         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3887         is_patchless || ( $TRACE cd .. &&
3888                         error "'cd ..' worked after removing parent" || true )
3889 }
3890 run_test 48d "Access removed parent subdir (should return errors)"
3891
3892 test_48e() { # bug 4134
3893         check_kernel_version 41 || return 0
3894         #lctl set_param debug=-1
3895         #set -vx
3896         rm -rf $DIR/$tdir
3897         test_mkdir -p $DIR/$tdir/dir
3898         cd $DIR/$tdir/dir
3899         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3900         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3901         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3902         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3903         # On a buggy kernel addition of "touch foo" after cd .. will
3904         # produce kernel oops in lookup_hash_it
3905         touch ../foo && error "'cd ..' worked after recreate parent"
3906         cd $DIR
3907         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3908 }
3909 run_test 48e "Access to recreated parent subdir (should return errors)"
3910
3911 test_49() { # LU-1030
3912         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3913         # get ost1 size - lustre-OST0000
3914         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3915                 awk '{ print $4 }')
3916         # write 800M at maximum
3917         [[ $ost1_size -lt 2 ]] && ost1_size=2
3918         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3919
3920         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3921         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3922         local dd_pid=$!
3923
3924         # change max_pages_per_rpc while writing the file
3925         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3926         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3927         # loop until dd process exits
3928         while ps ax -opid | grep -wq $dd_pid; do
3929                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3930                 sleep $((RANDOM % 5 + 1))
3931         done
3932         # restore original max_pages_per_rpc
3933         $LCTL set_param $osc1_mppc=$orig_mppc
3934         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3935 }
3936 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3937
3938 test_50() {
3939         # bug 1485
3940         test_mkdir $DIR/$tdir
3941         cd $DIR/$tdir
3942         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3943 }
3944 run_test 50 "special situations: /proc symlinks  ==============="
3945
3946 test_51a() {    # was test_51
3947         # bug 1516 - create an empty entry right after ".." then split dir
3948         test_mkdir -c1 $DIR/$tdir
3949         touch $DIR/$tdir/foo
3950         $MCREATE $DIR/$tdir/bar
3951         rm $DIR/$tdir/foo
3952         createmany -m $DIR/$tdir/longfile 201
3953         FNUM=202
3954         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
3955                 $MCREATE $DIR/$tdir/longfile$FNUM
3956                 FNUM=$(($FNUM + 1))
3957                 echo -n "+"
3958         done
3959         echo
3960         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
3961 }
3962 run_test 51a "special situations: split htree with empty entry =="
3963
3964 export NUMTEST=70000
3965 test_51b() {
3966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3967         local BASE=$DIR/d${base}.${TESTSUITE}
3968
3969         # cleanup the directory
3970         rm -fr $BASE
3971
3972         test_mkdir -p -c1 $BASE
3973
3974         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
3975         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
3976         [[ $numfree -lt 21000 ]] && skip "not enough free inodes ($numfree)" &&
3977                 return
3978
3979         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3980                 echo "reduced count to $NUMTEST due to inodes"
3981
3982         # need to check free space for the directories as well
3983         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
3984         numfree=$((blkfree / 4))
3985         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3986                 echo "reduced count to $NUMTEST due to blocks"
3987
3988         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
3989                 echo "failed" > $BASE/fnum
3990 }
3991 run_test 51b "exceed 64k subdirectory nlink limit"
3992
3993 test_51ba() { # LU-993
3994         local BASE=$DIR/d${base}.${TESTSUITE}
3995         # unlink all but 100 subdirectories, then check it still works
3996         local LEFT=100
3997         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
3998
3999         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
4000         local DELETE=$((NUMTEST - LEFT))
4001
4002         # continue on to run this test even if 51b didn't finish,
4003         # just to delete the many subdirectories created.
4004         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
4005
4006         # for ldiskfs the nlink count should be 1, but this is OSD specific
4007         # and so this is listed for informational purposes only
4008         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
4009         unlinkmany -d $BASE/d $DELETE
4010         RC=$?
4011
4012         if [ $RC -ne 0 ]; then
4013                 if [ "$NUMPREV" == "failed" ]; then
4014                         skip "previous setup failed"
4015                         return 0
4016                 else
4017                         error "unlink of first $DELETE subdirs failed"
4018                         return $RC
4019                 fi
4020         fi
4021
4022         echo "nlink between: $(stat -c %h $BASE)"
4023         # trim the first line of ls output
4024         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
4025         [ $FOUND -ne $LEFT ] &&
4026                 error "can't find subdirs: found only $FOUND/$LEFT"
4027
4028         unlinkmany -d $BASE/d $DELETE $LEFT ||
4029                 error "unlink of second $LEFT subdirs failed"
4030         # regardless of whether the backing filesystem tracks nlink accurately
4031         # or not, the nlink count shouldn't be more than "." and ".." here
4032         local AFTER=$(stat -c %h $BASE)
4033         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
4034                 echo "nlink after: $AFTER"
4035 }
4036 run_test 51ba "verify nlink for many subdirectory cleanup"
4037
4038 test_51d() {
4039         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4040         [[ $OSTCOUNT -lt 3 ]] &&
4041                 skip_env "skipping test with few OSTs" && return
4042         test_mkdir -p $DIR/$tdir
4043         createmany -o $DIR/$tdir/t- 1000
4044         $GETSTRIPE $DIR/$tdir > $TMP/files
4045         for N in $(seq 0 $((OSTCOUNT - 1))); do
4046                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4047                         END { printf("%0.0f", objs) }' $TMP/files)
4048                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
4049                         '($1 == '$N') { objs += 1 } \
4050                         END { printf("%0.0f", objs) }')
4051                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4052         done
4053         unlinkmany $DIR/$tdir/t- 1000
4054
4055         NLAST=0
4056         for N in $(seq 1 $((OSTCOUNT - 1))); do
4057                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4058                         error "OST $N has less objects vs OST $NLAST" \
4059                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4060                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4061                         error "OST $N has less objects vs OST $NLAST" \
4062                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4063
4064                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4065                         error "OST $N has less #0 objects vs OST $NLAST" \
4066                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4067                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4068                         error "OST $N has less #0 objects vs OST $NLAST" \
4069                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4070                 NLAST=$N
4071         done
4072 }
4073 run_test 51d "check object distribution ===================="
4074
4075 test_51e() {
4076         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4077                 skip "Only applicable to ldiskfs-based MDTs"
4078                 return
4079         fi
4080
4081         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4082         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4083
4084         touch $DIR/$tdir/d0/foo
4085         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4086                 error "file exceed 65000 nlink limit!"
4087         unlinkmany $DIR/$tdir/d0/f- 65001
4088         return 0
4089 }
4090 run_test 51e "check file nlink limit"
4091
4092 test_52a() {
4093         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4094         test_mkdir -p $DIR/$tdir
4095         touch $DIR/$tdir/foo
4096         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4097         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4098         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4099         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4100         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4101                                         error "link worked"
4102         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4103         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4104         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4105                                                      error "lsattr"
4106         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4107         cp -r $DIR/$tdir /tmp/
4108         rm -fr $DIR/$tdir || error "cleanup rm failed"
4109 }
4110 run_test 52a "append-only flag test (should return errors) ====="
4111
4112 test_52b() {
4113         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4114         test_mkdir -p $DIR/$tdir
4115         touch $DIR/$tdir/foo
4116         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4117         cat test > $DIR/$tdir/foo && error "cat test worked"
4118         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4119         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4120         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4121                                         error "link worked"
4122         echo foo >> $DIR/$tdir/foo && error "echo worked"
4123         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4124         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4125         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4126         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4127                                                         error "lsattr"
4128         chattr -i $DIR/$tdir/foo || error "chattr failed"
4129
4130         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4131 }
4132 run_test 52b "immutable flag test (should return errors) ======="
4133
4134 test_53() {
4135         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4136         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4137         remote_ost_nodsh && skip "remote OST with nodsh" && return
4138
4139         local param
4140         local param_seq
4141         local ostname
4142         local mds_last
4143         local mds_last_seq
4144         local ost_last
4145         local ost_last_seq
4146         local ost_last_id
4147         local ostnum
4148         local node
4149         local found=false
4150         local support_last_seq=true
4151
4152         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4153                 support_last_seq=false
4154
4155         # only test MDT0000
4156         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4157         local value
4158         for value in $(do_facet $SINGLEMDS \
4159                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4160                 param=$(echo ${value[0]} | cut -d "=" -f1)
4161                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4162
4163                 if $support_last_seq; then
4164                         param_seq=$(echo $param |
4165                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4166                         mds_last_seq=$(do_facet $SINGLEMDS \
4167                                        $LCTL get_param -n $param_seq)
4168                 fi
4169                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4170
4171                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4172                 node=$(facet_active_host ost$((ostnum+1)))
4173                 param="obdfilter.$ostname.last_id"
4174                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4175                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4176                         ost_last_id=$ost_last
4177
4178                         if $support_last_seq; then
4179                                 ost_last_id=$(echo $ost_last |
4180                                               awk -F':' '{print $2}' |
4181                                               sed -e "s/^0x//g")
4182                                 ost_last_seq=$(echo $ost_last |
4183                                                awk -F':' '{print $1}')
4184                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4185                         fi
4186
4187                         if [[ $ost_last_id != $mds_last ]]; then
4188                                 error "$ost_last_id != $mds_last"
4189                         else
4190                                 found=true
4191                                 break
4192                         fi
4193                 done
4194         done
4195         $found || error "can not match last_seq/last_id for $mdtosc"
4196         return 0
4197 }
4198 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4199
4200 test_54a() {
4201         $SOCKETSERVER $DIR/socket ||
4202                 error "$SOCKETSERVER $DIR/socket failed: $?"
4203         $SOCKETCLIENT $DIR/socket ||
4204                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4205         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4206 }
4207 run_test 54a "unix domain socket test =========================="
4208
4209 test_54b() {
4210         f="$DIR/f54b"
4211         mknod $f c 1 3
4212         chmod 0666 $f
4213         dd if=/dev/zero of=$f bs=$(page_size) count=1
4214 }
4215 run_test 54b "char device works in lustre ======================"
4216
4217 find_loop_dev() {
4218         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4219         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4220         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4221
4222         for i in $(seq 3 7); do
4223                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4224                 LOOPDEV=$LOOPBASE$i
4225                 LOOPNUM=$i
4226                 break
4227         done
4228 }
4229
4230 cleanup_54c() {
4231         loopdev="$DIR/loop54c"
4232
4233         trap 0
4234         $UMOUNT -d $DIR/$tdir || rc=$?
4235         losetup -d $loopdev || true
4236         losetup -d $LOOPDEV || true
4237         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4238         return $rc
4239 }
4240
4241 test_54c() {
4242         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4243         loopdev="$DIR/loop54c"
4244
4245         find_loop_dev
4246         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4247         trap cleanup_54c EXIT
4248         mknod $loopdev b 7 $LOOPNUM
4249         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4250         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4251         losetup $loopdev $DIR/$tfile ||
4252                 error "can't set up $loopdev for $DIR/$tfile"
4253         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4254         test_mkdir -p $DIR/$tdir
4255         mount -t ext2 $loopdev $DIR/$tdir ||
4256                 error "error mounting $loopdev on $DIR/$tdir"
4257         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4258                 error "dd write"
4259         df $DIR/$tdir
4260         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4261                 error "dd read"
4262         cleanup_54c
4263 }
4264 run_test 54c "block device works in lustre ====================="
4265
4266 test_54d() {
4267         f="$DIR/f54d"
4268         string="aaaaaa"
4269         mknod $f p
4270         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4271 }
4272 run_test 54d "fifo device works in lustre ======================"
4273
4274 test_54e() {
4275         check_kernel_version 46 || return 0
4276         f="$DIR/f54e"
4277         string="aaaaaa"
4278         cp -aL /dev/console $f
4279         echo $string > $f || error "echo $string to $f failed"
4280 }
4281 run_test 54e "console/tty device works in lustre ======================"
4282
4283 #The test_55 used to be iopen test and it was removed by bz#24037.
4284 #run_test 55 "check iopen_connect_dentry() ======================"
4285
4286 test_56a() {    # was test_56
4287         rm -rf $DIR/$tdir
4288         $SETSTRIPE -d $DIR
4289         test_mkdir -p $DIR/$tdir/dir
4290         NUMFILES=3
4291         NUMFILESx2=$(($NUMFILES * 2))
4292         for i in $(seq 1 $NUMFILES); do
4293                 touch $DIR/$tdir/file$i
4294                 touch $DIR/$tdir/dir/file$i
4295         done
4296
4297         # test lfs getstripe with --recursive
4298         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4299         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4300                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4301         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4302         [[ $FILENUM -eq $NUMFILES ]] ||
4303                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4304         echo "$GETSTRIPE --recursive passed."
4305
4306         # test lfs getstripe with file instead of dir
4307         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4308         [[ $FILENUM -eq 1 ]] ||
4309                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4310         echo "$GETSTRIPE file1 passed."
4311
4312         #test lfs getstripe with --verbose
4313         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4314                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4315                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4316         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4317                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4318         echo "$GETSTRIPE --verbose passed."
4319
4320         #test lfs getstripe with --obd
4321         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4322                 grep -q "unknown obduuid" ||
4323                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4324
4325         [[ $OSTCOUNT -lt 2 ]] &&
4326                 skip_env "skipping other $GETSTRIPE --obd test" && return
4327
4328         OSTIDX=1
4329         OBDUUID=$(ostuuid_from_index $OSTIDX)
4330         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4331         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4332         [[ $FOUND -eq $FILENUM ]] ||
4333                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4334         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4335                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4336                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4337                 error "$GETSTRIPE --obd: should not show file on other obd"
4338         echo "$GETSTRIPE --obd passed"
4339 }
4340 run_test 56a "check $GETSTRIPE"
4341
4342 NUMFILES=3
4343 NUMDIRS=3
4344 setup_56() {
4345         local LOCAL_NUMFILES="$1"
4346         local LOCAL_NUMDIRS="$2"
4347         local MKDIR_PARAMS="$3"
4348         local DIR_STRIPE_PARAMS="$4"
4349
4350         if [ ! -d "$TDIR" ] ; then
4351                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4352                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4353                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4354                         touch $TDIR/file$i
4355                 done
4356                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4357                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4358                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4359                                 touch $TDIR/dir$i/file$j
4360                         done
4361                 done
4362         fi
4363 }
4364
4365 setup_56_special() {
4366         LOCAL_NUMFILES=$1
4367         LOCAL_NUMDIRS=$2
4368         setup_56 $1 $2
4369         if [ ! -e "$TDIR/loop1b" ] ; then
4370                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4371                         mknod $TDIR/loop${i}b b 7 $i
4372                         mknod $TDIR/null${i}c c 1 3
4373                         ln -s $TDIR/file1 $TDIR/link${i}l
4374                 done
4375                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4376                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4377                         mknod $TDIR/dir$i/null${i}c c 1 3
4378                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4379                 done
4380         fi
4381 }
4382
4383 test_56g() {
4384         $SETSTRIPE -d $DIR
4385
4386         TDIR=$DIR/${tdir}g
4387         setup_56 $NUMFILES $NUMDIRS
4388
4389         EXPECTED=$(($NUMDIRS + 2))
4390         # test lfs find with -name
4391         for i in $(seq 1 $NUMFILES) ; do
4392                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4393                 [ $NUMS -eq $EXPECTED ] ||
4394                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4395                               "found $NUMS, expected $EXPECTED"
4396         done
4397 }
4398 run_test 56g "check lfs find -name ============================="
4399
4400 test_56h() {
4401         $SETSTRIPE -d $DIR
4402
4403         TDIR=$DIR/${tdir}g
4404         setup_56 $NUMFILES $NUMDIRS
4405
4406         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4407         # test lfs find with ! -name
4408         for i in $(seq 1 $NUMFILES) ; do
4409                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4410                 [ $NUMS -eq $EXPECTED ] ||
4411                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4412                               "found $NUMS, expected $EXPECTED"
4413         done
4414 }
4415 run_test 56h "check lfs find ! -name ============================="
4416
4417 test_56i() {
4418        tdir=${tdir}i
4419        test_mkdir -p $DIR/$tdir
4420        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4421        CMD="$LFIND -ost $UUID $DIR/$tdir"
4422        OUT=$($CMD)
4423        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4424 }
4425 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4426
4427 test_56j() {
4428         TDIR=$DIR/${tdir}g
4429         setup_56_special $NUMFILES $NUMDIRS
4430
4431         EXPECTED=$((NUMDIRS + 1))
4432         CMD="$LFIND -type d $TDIR"
4433         NUMS=$($CMD | wc -l)
4434         [ $NUMS -eq $EXPECTED ] ||
4435                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4436 }
4437 run_test 56j "check lfs find -type d ============================="
4438
4439 test_56k() {
4440         TDIR=$DIR/${tdir}g
4441         setup_56_special $NUMFILES $NUMDIRS
4442
4443         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4444         CMD="$LFIND -type f $TDIR"
4445         NUMS=$($CMD | wc -l)
4446         [ $NUMS -eq $EXPECTED ] ||
4447                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4448 }
4449 run_test 56k "check lfs find -type f ============================="
4450
4451 test_56l() {
4452         TDIR=$DIR/${tdir}g
4453         setup_56_special $NUMFILES $NUMDIRS
4454
4455         EXPECTED=$((NUMDIRS + NUMFILES))
4456         CMD="$LFIND -type b $TDIR"
4457         NUMS=$($CMD | wc -l)
4458         [ $NUMS -eq $EXPECTED ] ||
4459                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4460 }
4461 run_test 56l "check lfs find -type b ============================="
4462
4463 test_56m() {
4464         TDIR=$DIR/${tdir}g
4465         setup_56_special $NUMFILES $NUMDIRS
4466
4467         EXPECTED=$((NUMDIRS + NUMFILES))
4468         CMD="$LFIND -type c $TDIR"
4469         NUMS=$($CMD | wc -l)
4470         [ $NUMS -eq $EXPECTED ] ||
4471                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4472 }
4473 run_test 56m "check lfs find -type c ============================="
4474
4475 test_56n() {
4476         TDIR=$DIR/${tdir}g
4477         setup_56_special $NUMFILES $NUMDIRS
4478
4479         EXPECTED=$((NUMDIRS + NUMFILES))
4480         CMD="$LFIND -type l $TDIR"
4481         NUMS=$($CMD | wc -l)
4482         [ $NUMS -eq $EXPECTED ] ||
4483                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4484 }
4485 run_test 56n "check lfs find -type l ============================="
4486
4487 test_56o() {
4488         TDIR=$DIR/${tdir}o
4489         setup_56 $NUMFILES $NUMDIRS
4490         utime $TDIR/file1 > /dev/null || error "utime (1)"
4491         utime $TDIR/file2 > /dev/null || error "utime (2)"
4492         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4493         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4494         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4495         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4496
4497         EXPECTED=4
4498         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4499         [ $NUMS -eq $EXPECTED ] || \
4500                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4501
4502         EXPECTED=12
4503         CMD="$LFIND -mtime 0 $TDIR"
4504         NUMS=$($CMD | wc -l)
4505         [ $NUMS -eq $EXPECTED ] ||
4506                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4507 }
4508 run_test 56o "check lfs find -mtime for old files =========================="
4509
4510 test_56p() {
4511         [ $RUNAS_ID -eq $UID ] &&
4512                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4513
4514         TDIR=$DIR/${tdir}p
4515         setup_56 $NUMFILES $NUMDIRS
4516
4517         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4518         EXPECTED=$NUMFILES
4519         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4520         NUMS=$($CMD | wc -l)
4521         [ $NUMS -eq $EXPECTED ] || \
4522                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4523
4524         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4525         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4526         NUMS=$($CMD | wc -l)
4527         [ $NUMS -eq $EXPECTED ] || \
4528                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4529 }
4530 run_test 56p "check lfs find -uid and ! -uid ==============================="
4531
4532 test_56q() {
4533         [ $RUNAS_ID -eq $UID ] &&
4534                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4535
4536         TDIR=$DIR/${tdir}q
4537         setup_56 $NUMFILES $NUMDIRS
4538
4539         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4540
4541         EXPECTED=$NUMFILES
4542         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4543         NUMS=$($CMD | wc -l)
4544         [ $NUMS -eq $EXPECTED ] ||
4545                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4546
4547         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4548         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4549         NUMS=$($CMD | wc -l)
4550         [ $NUMS -eq $EXPECTED ] ||
4551                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4552 }
4553 run_test 56q "check lfs find -gid and ! -gid ==============================="
4554
4555 test_56r() {
4556         TDIR=$DIR/${tdir}r
4557         setup_56 $NUMFILES $NUMDIRS
4558
4559         EXPECTED=12
4560         CMD="$LFIND -size 0 -type f $TDIR"
4561         NUMS=$($CMD | wc -l)
4562         [ $NUMS -eq $EXPECTED ] ||
4563                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4564         EXPECTED=0
4565         CMD="$LFIND ! -size 0 -type f $TDIR"
4566         NUMS=$($CMD | wc -l)
4567         [ $NUMS -eq $EXPECTED ] ||
4568                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4569         echo "test" > $TDIR/$tfile
4570         echo "test2" > $TDIR/$tfile.2 && sync
4571         EXPECTED=1
4572         CMD="$LFIND -size 5 -type f $TDIR"
4573         NUMS=$($CMD | wc -l)
4574         [ $NUMS -eq $EXPECTED ] ||
4575                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4576         EXPECTED=1
4577         CMD="$LFIND -size +5 -type f $TDIR"
4578         NUMS=$($CMD | wc -l)
4579         [ $NUMS -eq $EXPECTED ] ||
4580                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4581         EXPECTED=2
4582         CMD="$LFIND -size +0 -type f $TDIR"
4583         NUMS=$($CMD | wc -l)
4584         [ $NUMS -eq $EXPECTED ] ||
4585                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4586         EXPECTED=2
4587         CMD="$LFIND ! -size -5 -type f $TDIR"
4588         NUMS=$($CMD | wc -l)
4589         [ $NUMS -eq $EXPECTED ] ||
4590                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4591         EXPECTED=12
4592         CMD="$LFIND -size -5 -type f $TDIR"
4593         NUMS=$($CMD | wc -l)
4594         [ $NUMS -eq $EXPECTED ] ||
4595                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4596 }
4597 run_test 56r "check lfs find -size works =========================="
4598
4599 test_56s() { # LU-611
4600         TDIR=$DIR/${tdir}s
4601         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4602
4603         if [[ $OSTCOUNT -gt 1 ]]; then
4604                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4605                 ONESTRIPE=4
4606                 EXTRA=4
4607         else
4608                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4609                 EXTRA=0
4610         fi
4611
4612         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4613         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4614         NUMS=$($CMD | wc -l)
4615         [ $NUMS -eq $EXPECTED ] || {
4616                 $GETSTRIPE -R $TDIR
4617                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4618         }
4619
4620         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4621         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4622         NUMS=$($CMD | wc -l)
4623         [ $NUMS -eq $EXPECTED ] || {
4624                 $GETSTRIPE -R $TDIR
4625                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4626         }
4627
4628         EXPECTED=$ONESTRIPE
4629         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4630         NUMS=$($CMD | wc -l)
4631         [ $NUMS -eq $EXPECTED ] || {
4632                 $GETSTRIPE -R $TDIR
4633                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4634         }
4635
4636         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4637         NUMS=$($CMD | wc -l)
4638         [ $NUMS -eq $EXPECTED ] || {
4639                 $GETSTRIPE -R $TDIR
4640                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4641         }
4642
4643         EXPECTED=0
4644         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4645         NUMS=$($CMD | wc -l)
4646         [ $NUMS -eq $EXPECTED ] || {
4647                 $GETSTRIPE -R $TDIR
4648                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4649         }
4650 }
4651 run_test 56s "check lfs find -stripe-count works"
4652
4653 test_56t() { # LU-611
4654         TDIR=$DIR/${tdir}t
4655         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4656
4657         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4658
4659         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4660         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4661         NUMS=$($CMD | wc -l)
4662         [ $NUMS -eq $EXPECTED ] ||
4663                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4664
4665         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4666         NUMS=$($CMD | wc -l)
4667         [ $NUMS -eq $EXPECTED ] ||
4668                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4669
4670         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4671         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4672         NUMS=$($CMD | wc -l)
4673         [ $NUMS -eq $EXPECTED ] ||
4674                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4675
4676         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4677         NUMS=$($CMD | wc -l)
4678         [ $NUMS -eq $EXPECTED ] ||
4679                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4680
4681         EXPECTED=4
4682         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4683         NUMS=$($CMD | wc -l)
4684         [ $NUMS -eq $EXPECTED ] ||
4685                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4686
4687         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4688         NUMS=$($CMD | wc -l)
4689         [ $NUMS -eq $EXPECTED ] ||
4690                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4691
4692         EXPECTED=0
4693         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4694         NUMS=$($CMD | wc -l)
4695         [ $NUMS -eq $EXPECTED ] ||
4696                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4697 }
4698 run_test 56t "check lfs find -stripe-size works"
4699
4700 test_56u() { # LU-611
4701         TDIR=$DIR/${tdir}u
4702         setup_56 $NUMFILES $NUMDIRS "-i 0"
4703
4704         if [[ $OSTCOUNT -gt 1 ]]; then
4705                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4706                 ONESTRIPE=4
4707         else
4708                 ONESTRIPE=0
4709         fi
4710
4711         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4712         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4713         NUMS=$($CMD | wc -l)
4714         [ $NUMS -eq $EXPECTED ] ||
4715                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4716
4717         EXPECTED=$ONESTRIPE
4718         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4719         NUMS=$($CMD | wc -l)
4720         [ $NUMS -eq $EXPECTED ] ||
4721                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4722
4723         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4724         NUMS=$($CMD | wc -l)
4725         [ $NUMS -eq $EXPECTED ] ||
4726                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4727
4728         EXPECTED=0
4729         # This should produce an error and not return any files
4730         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4731         NUMS=$($CMD 2>/dev/null | wc -l)
4732         [ $NUMS -eq $EXPECTED ] ||
4733                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4734
4735         if [[ $OSTCOUNT -gt 1 ]]; then
4736                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4737                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4738                 NUMS=$($CMD | wc -l)
4739                 [ $NUMS -eq $EXPECTED ] ||
4740                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4741         fi
4742 }
4743 run_test 56u "check lfs find -stripe-index works"
4744
4745 test_56v() {
4746     local MDT_IDX=0
4747
4748     TDIR=$DIR/${tdir}v
4749     rm -rf $TDIR
4750     setup_56 $NUMFILES $NUMDIRS
4751
4752     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4753     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4754
4755     for file in $($LFIND -mdt $UUID $TDIR); do
4756         file_mdt_idx=$($GETSTRIPE -M $file)
4757         [ $file_mdt_idx -eq $MDT_IDX ] ||
4758             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4759     done
4760 }
4761 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4762
4763 # Get and check the actual stripe count of one file.
4764 # Usage: check_stripe_count <file> <expected_stripe_count>
4765 check_stripe_count() {
4766     local file=$1
4767     local expected=$2
4768     local actual
4769
4770     [[ -z "$file" || -z "$expected" ]] &&
4771         error "check_stripe_count: invalid argument!"
4772
4773     local cmd="$GETSTRIPE -c $file"
4774     actual=$($cmd) || error "$cmd failed"
4775     actual=${actual%% *}
4776
4777     if [[ $actual -ne $expected ]]; then
4778         [[ $expected -eq -1 ]] ||
4779             error "$cmd wrong: found $actual, expected $expected"
4780         [[ $actual -eq $OSTCOUNT ]] ||
4781             error "$cmd wrong: found $actual, expected $OSTCOUNT"
4782     fi
4783 }
4784
4785 test_56w() {
4786         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4787         TDIR=$DIR/${tdir}w
4788
4789     rm -rf $TDIR || error "remove $TDIR failed"
4790     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4791
4792     local stripe_size
4793     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4794         error "$GETSTRIPE -S -d $TDIR failed"
4795     stripe_size=${stripe_size%% *}
4796
4797     local file_size=$((stripe_size * OSTCOUNT))
4798     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4799     local required_space=$((file_num * file_size))
4800     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4801     [[ $free_space -le $((required_space / 1024)) ]] &&
4802         skip_env "need at least $required_space bytes free space," \
4803                  "have $free_space kbytes" && return
4804
4805     local dd_bs=65536
4806     local dd_count=$((file_size / dd_bs))
4807
4808     # write data into the files
4809     local i
4810     local j
4811     local file
4812     for i in $(seq 1 $NUMFILES); do
4813         file=$TDIR/file$i
4814         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4815             error "write data into $file failed"
4816     done
4817     for i in $(seq 1 $NUMDIRS); do
4818         for j in $(seq 1 $NUMFILES); do
4819             file=$TDIR/dir$i/file$j
4820             yes | dd bs=$dd_bs count=$dd_count of=$file \
4821                 >/dev/null 2>&1 ||
4822                 error "write data into $file failed"
4823         done
4824     done
4825
4826     local expected=-1
4827     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4828
4829     # lfs_migrate file
4830     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4831     echo "$cmd"
4832     eval $cmd || error "$cmd failed"
4833
4834     check_stripe_count $TDIR/file1 $expected
4835
4836     # lfs_migrate dir
4837     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4838     echo "$cmd"
4839     eval $cmd || error "$cmd failed"
4840
4841     for j in $(seq 1 $NUMFILES); do
4842         check_stripe_count $TDIR/dir1/file$j $expected
4843     done
4844
4845     # lfs_migrate works with lfs find
4846     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4847          $LFS_MIGRATE -y -c $expected"
4848     echo "$cmd"
4849     eval $cmd || error "$cmd failed"
4850
4851     for i in $(seq 2 $NUMFILES); do
4852         check_stripe_count $TDIR/file$i $expected
4853     done
4854     for i in $(seq 2 $NUMDIRS); do
4855         for j in $(seq 1 $NUMFILES); do
4856             check_stripe_count $TDIR/dir$i/file$j $expected
4857         done
4858     done
4859 }
4860 run_test 56w "check lfs_migrate -c stripe_count works"
4861
4862 test_56x() {
4863         check_swap_layouts_support && return 0
4864         [[ $OSTCOUNT -lt 2 ]] &&
4865                 skip_env "need 2 OST, skipping test" && return
4866
4867         local dir0=$DIR/$tdir/$testnum
4868         mkdir -p $dir0 || error "creating dir $dir0"
4869
4870         local ref1=/etc/passwd
4871         local file1=$dir0/file1
4872
4873         $SETSTRIPE -c 2 $file1
4874         cp $ref1 $file1
4875         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4876         stripe=$($GETSTRIPE -c $file1)
4877         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4878         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4879
4880         # clean up
4881         rm -f $file1
4882 }
4883 run_test 56x "lfs migration support"
4884
4885 test_56y() {
4886         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4887                 skip "No HSM support on MDS of $(get_lustre_version)," \
4888                          "need 2.4.53 at least" && return
4889         local res=""
4890
4891         local dir0=$DIR/$tdir/$testnum
4892         mkdir -p $dir0 || error "creating dir $dir0"
4893         local f1=$dir0/file1
4894         local f2=$dir0/file2
4895
4896         touch $f1 || error "creating std file $f1"
4897         $MULTIOP $f2 H2c || error "creating released file $f2"
4898
4899         # a directory can be raid0, so ask only for files
4900         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4901         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4902
4903         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4904         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4905
4906         # only files can be released, so no need to force file search
4907         res=$($LFIND $dir0 -L released)
4908         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4909
4910         res=$($LFIND $dir0 \! -L released)
4911         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4912
4913 }
4914 run_test 56y "lfs find -L raid0|released"
4915
4916 test_56z() { # LU-4824
4917         # This checks to make sure 'lfs find' continues after errors
4918         # There are two classes of errors that should be caught:
4919         # - If multiple paths are provided, all should be searched even if one
4920         #   errors out
4921         # - If errors are encountered during the search, it should not terminate
4922         #   early
4923         local i
4924         test_mkdir $DIR/$tdir
4925         for i in d{0..9}; do
4926                 test_mkdir $DIR/$tdir/$i
4927         done
4928         touch $DIR/$tdir/d{0..9}/$tfile
4929         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
4930                 error "$LFS find did not return an error"
4931         # Make a directory unsearchable. This should NOT be the last entry in
4932         # directory order.  Arbitrarily pick the 6th entry
4933         chmod 700 $(lfs find $DIR/$tdir -type d | sed '6!d')
4934         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
4935         # The user should be able to see 10 directories and 9 files
4936         [ $count == 19 ] || error "$LFS find did not continue after error"
4937 }
4938 run_test 56z "lfs find should continue after an error"
4939
4940 test_57a() {
4941         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4942         # note test will not do anything if MDS is not local
4943         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4944                 skip "Only applicable to ldiskfs-based MDTs"
4945                 return
4946         fi
4947
4948         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4949         local MNTDEV="osd*.*MDT*.mntdev"
4950         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
4951         [ -z "$DEV" ] && error "can't access $MNTDEV"
4952         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
4953                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
4954                         error "can't access $DEV"
4955                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
4956                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
4957                 rm $TMP/t57a.dump
4958         done
4959 }
4960 run_test 57a "verify MDS filesystem created with large inodes =="
4961
4962 test_57b() {
4963         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4964         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4965                 skip "Only applicable to ldiskfs-based MDTs"
4966                 return
4967         fi
4968
4969         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4970         local dir=$DIR/d57b
4971
4972         local FILECOUNT=100
4973         local FILE1=$dir/f1
4974         local FILEN=$dir/f$FILECOUNT
4975
4976         rm -rf $dir || error "removing $dir"
4977         test_mkdir -p $dir || error "creating $dir"
4978         local num=$(get_mds_dir $dir)
4979         local mymds=mds$num
4980
4981         echo "mcreating $FILECOUNT files"
4982         createmany -m $dir/f 1 $FILECOUNT || \
4983                 error "creating files in $dir"
4984
4985         # verify that files do not have EAs yet
4986         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
4987         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
4988
4989         sync
4990         sleep 1
4991         df $dir  #make sure we get new statfs data
4992         local MDSFREE=$(do_facet $mymds \
4993                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4994         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4995         echo "opening files to create objects/EAs"
4996         local FILE
4997         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
4998                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
4999         done
5000
5001         # verify that files have EAs now
5002         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5003         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5004
5005         sleep 1  #make sure we get new statfs data
5006         df $dir
5007         local MDSFREE2=$(do_facet $mymds \
5008                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
5009         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
5010         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5011                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5012                         error "MDC before $MDCFREE != after $MDCFREE2"
5013                 else
5014                         echo "MDC before $MDCFREE != after $MDCFREE2"
5015                         echo "unable to confirm if MDS has large inodes"
5016                 fi
5017         fi
5018         rm -rf $dir
5019 }
5020 run_test 57b "default LOV EAs are stored inside large inodes ==="
5021
5022 test_58() {
5023         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5024         [ -z "$(which wiretest 2>/dev/null)" ] &&
5025                         skip_env "could not find wiretest" && return
5026         wiretest
5027 }
5028 run_test 58 "verify cross-platform wire constants =============="
5029
5030 test_59() {
5031         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5032         echo "touch 130 files"
5033         createmany -o $DIR/f59- 130
5034         echo "rm 130 files"
5035         unlinkmany $DIR/f59- 130
5036         sync
5037         # wait for commitment of removal
5038         wait_delete_completed
5039 }
5040 run_test 59 "verify cancellation of llog records async ========="
5041
5042 TEST60_HEAD="test_60 run $RANDOM"
5043 test_60a() {
5044         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5045         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5046         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5047                 skip_env "missing subtest run-llog.sh" && return
5048         log "$TEST60_HEAD - from kernel mode"
5049         do_facet mgs sh run-llog.sh
5050 }
5051 run_test 60a "llog sanity tests run from kernel module =========="
5052
5053 test_60b() { # bug 6411
5054         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5055         dmesg > $DIR/$tfile
5056         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
5057                                  /llog.test/ {
5058                                          if (marker)
5059                                                  from_marker++
5060                                          from_begin++
5061                                  }
5062                                  END {
5063                                          if (marker)
5064                                                  print from_marker
5065                                          else
5066                                                  print from_begin
5067                                  }"`
5068         [[ $LLOG_COUNT -gt 50 ]] &&
5069                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5070 }
5071 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5072
5073 test_60c() {
5074         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5075         echo "create 5000 files"
5076         createmany -o $DIR/f60c- 5000
5077 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5078         lctl set_param fail_loc=0x80000137
5079         unlinkmany $DIR/f60c- 5000
5080         lctl set_param fail_loc=0
5081 }
5082 run_test 60c "unlink file when mds full"
5083
5084 test_60d() {
5085         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5086         SAVEPRINTK=$(lctl get_param -n printk)
5087
5088         # verify "lctl mark" is even working"
5089         MESSAGE="test message ID $RANDOM $$"
5090         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5091         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5092
5093         lctl set_param printk=0 || error "set lnet.printk failed"
5094         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5095         MESSAGE="new test message ID $RANDOM $$"
5096         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5097         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5098         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5099
5100         lctl set_param -n printk="$SAVEPRINTK"
5101 }
5102 run_test 60d "test printk console message masking"
5103
5104 test_61() {
5105         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5106         f="$DIR/f61"
5107         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5108         cancel_lru_locks osc
5109         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5110         sync
5111 }
5112 run_test 61 "mmap() writes don't make sync hang ================"
5113
5114 # bug 2330 - insufficient obd_match error checking causes LBUG
5115 test_62() {
5116         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5117         f="$DIR/f62"
5118         echo foo > $f
5119         cancel_lru_locks osc
5120         lctl set_param fail_loc=0x405
5121         cat $f && error "cat succeeded, expect -EIO"
5122         lctl set_param fail_loc=0
5123 }
5124 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5125 # match every page all of the time.
5126 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5127
5128 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5129 # Though this test is irrelevant anymore, it helped to reveal some
5130 # other grant bugs (LU-4482), let's keep it.
5131 test_63a() {   # was test_63
5132         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5133         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5134         for i in `seq 10` ; do
5135                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5136                 sleep 5
5137                 kill $!
5138                 sleep 1
5139         done
5140
5141         rm -f $DIR/f63 || true
5142 }
5143 run_test 63a "Verify oig_wait interruption does not crash ======="
5144
5145 # bug 2248 - async write errors didn't return to application on sync
5146 # bug 3677 - async write errors left page locked
5147 test_63b() {
5148         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5149         debugsave
5150         lctl set_param debug=-1
5151
5152         # ensure we have a grant to do async writes
5153         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5154         rm $DIR/$tfile
5155
5156         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5157         lctl set_param fail_loc=0x80000406
5158         $MULTIOP $DIR/$tfile Owy && \
5159                 error "sync didn't return ENOMEM"
5160         sync; sleep 2; sync     # do a real sync this time to flush page
5161         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5162                 error "locked page left in cache after async error" || true
5163         debugrestore
5164 }
5165 run_test 63b "async write errors should be returned to fsync ==="
5166
5167 test_64a () {
5168         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5169         df $DIR
5170         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5171 }
5172 run_test 64a "verify filter grant calculations (in kernel) ====="
5173
5174 test_64b () {
5175         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5176         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5177 }
5178 run_test 64b "check out-of-space detection on client ==========="
5179
5180 test_64c() {
5181         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5182 }
5183 run_test 64c "verify grant shrink ========================------"
5184
5185 # bug 1414 - set/get directories' stripe info
5186 test_65a() {
5187         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5188         test_mkdir -p $DIR/$tdir
5189         touch $DIR/$tdir/f1
5190         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5191 }
5192 run_test 65a "directory with no stripe info ===================="
5193
5194 test_65b() {
5195         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5196         test_mkdir -p $DIR/$tdir
5197         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5198                                                 error "setstripe"
5199         touch $DIR/$tdir/f2
5200         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5201 }
5202 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
5203
5204 test_65c() {
5205         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5206         if [[ $OSTCOUNT -gt 1 ]]; then
5207                 test_mkdir -p $DIR/$tdir
5208                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5209                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5210                 touch $DIR/$tdir/f3
5211                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5212         fi
5213 }
5214 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
5215
5216 test_65d() {
5217         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5218         test_mkdir -p $DIR/$tdir
5219         if [[ $STRIPECOUNT -le 0 ]]; then
5220                 sc=1
5221         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5222 #LOV_MAX_STRIPE_COUNT is 2000
5223                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5224         else
5225                 sc=$(($STRIPECOUNT - 1))
5226         fi
5227         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5228         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5229         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5230                 error "lverify failed"
5231 }
5232 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
5233
5234 test_65e() {
5235         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5236         test_mkdir -p $DIR/$tdir
5237
5238         $SETSTRIPE $DIR/$tdir || error "setstripe"
5239         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5240                                         error "no stripe info failed"
5241         touch $DIR/$tdir/f6
5242         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5243 }
5244 run_test 65e "directory setstripe defaults ======================="
5245
5246 test_65f() {
5247         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5248         test_mkdir -p $DIR/${tdir}f
5249         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5250 }
5251 run_test 65f "dir setstripe permission (should return error) ==="
5252
5253 test_65g() {
5254         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5255         test_mkdir -p $DIR/$tdir
5256         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5257                                                         error "setstripe"
5258         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5259         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5260                 error "delete default stripe failed"
5261 }
5262 run_test 65g "directory setstripe -d ==========================="
5263
5264 test_65h() {
5265         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5266         test_mkdir -p $DIR/$tdir
5267         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5268                                                         error "setstripe"
5269         test_mkdir -p $DIR/$tdir/dd1
5270         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5271                 error "stripe info inherit failed"
5272 }
5273 run_test 65h "directory stripe info inherit ===================="
5274
5275 test_65i() { # bug6367
5276         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5277         $SETSTRIPE -S 65536 -c -1 $MOUNT
5278 }
5279 run_test 65i "set non-default striping on root directory (bug 6367)="
5280
5281 test_65ia() { # bug12836
5282         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5283         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5284 }
5285 run_test 65ia "getstripe on -1 default directory striping"
5286
5287 test_65ib() { # bug12836
5288         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5289         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5290 }
5291 run_test 65ib "getstripe -v on -1 default directory striping"
5292
5293 test_65ic() { # bug12836
5294         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5295         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5296 }
5297 run_test 65ic "new find on -1 default directory striping"
5298
5299 test_65j() { # bug6367
5300         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5301         sync; sleep 1
5302         # if we aren't already remounting for each test, do so for this test
5303         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5304                 cleanup || error "failed to unmount"
5305                 setup
5306         fi
5307         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5308 }
5309 run_test 65j "set default striping on root directory (bug 6367)="
5310
5311 test_65k() { # bug11679
5312         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5313         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5314         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5315
5316     echo "Check OST status: "
5317     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5318               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5319
5320     for OSC in $MDS_OSCS; do
5321         echo $OSC "is activate"
5322         do_facet $SINGLEMDS lctl --device %$OSC activate
5323     done
5324
5325     mkdir -p $DIR/$tdir
5326     for INACTIVE_OSC in $MDS_OSCS; do
5327         echo "Deactivate: " $INACTIVE_OSC
5328         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5329         for STRIPE_OSC in $MDS_OSCS; do
5330             OST=`osc_to_ost $STRIPE_OSC`
5331             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5332                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5333
5334             [ -f $DIR/$tdir/$IDX ] && continue
5335             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5336             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5337             RC=$?
5338             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5339         done
5340         rm -f $DIR/$tdir/*
5341         echo $INACTIVE_OSC "is Activate."
5342         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5343     done
5344 }
5345 run_test 65k "validate manual striping works properly with deactivated OSCs"
5346
5347 test_65l() { # bug 12836
5348         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5349         test_mkdir -p $DIR/$tdir/test_dir
5350         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5351         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5352 }
5353 run_test 65l "lfs find on -1 stripe dir ========================"
5354
5355 # bug 2543 - update blocks count on client
5356 test_66() {
5357         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5358         COUNT=${COUNT:-8}
5359         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5360         sync; sync_all_data; sync; sync_all_data
5361         cancel_lru_locks osc
5362         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5363         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5364 }
5365 run_test 66 "update inode blocks count on client ==============="
5366
5367 LLOOP=
5368 LLITELOOPLOAD=
5369 cleanup_68() {
5370         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5371         trap 0
5372         if [ ! -z "$LLOOP" ]; then
5373                 if swapon -s | grep -q $LLOOP; then
5374                         swapoff $LLOOP || error "swapoff failed"
5375                 fi
5376
5377                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5378                 rm -f $LLOOP
5379                 unset LLOOP
5380         fi
5381         if [ ! -z "$LLITELOOPLOAD" ]; then
5382                 rmmod llite_lloop
5383                 unset LLITELOOPLOAD
5384         fi
5385         rm -f $DIR/f68*
5386 }
5387
5388 meminfo() {
5389         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5390 }
5391
5392 swap_used() {
5393         swapon -s | awk '($1 == "'$1'") { print $4 }'
5394 }
5395
5396 # test case for lloop driver, basic function
5397 test_68a() {
5398         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5399         [ "$UID" != 0 ] && skip_env "must run as root" && return
5400         llite_lloop_enabled || \
5401                 { skip_env "llite_lloop module disabled" && return; }
5402
5403         trap cleanup_68 EXIT
5404
5405         if ! module_loaded llite_lloop; then
5406                 if load_module llite/llite_lloop; then
5407                         LLITELOOPLOAD=yes
5408                 else
5409                         skip_env "can't find module llite_lloop"
5410                         return
5411                 fi
5412         fi
5413
5414         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5415         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5416         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5417
5418         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5419         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5420
5421         cleanup_68
5422 }
5423 run_test 68a "lloop driver - basic test ========================"
5424
5425 # excercise swapping to lustre by adding a high priority swapfile entry
5426 # and then consuming memory until it is used.
5427 test_68b() {  # was test_68
5428         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5429         [ "$UID" != 0 ] && skip_env "must run as root" && return
5430         lctl get_param -n devices | grep -q obdfilter && \
5431                 skip "local OST" && return
5432
5433         grep -q llite_lloop /proc/modules
5434         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5435
5436         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5437                 skip "can't reliably test swap with TCP" && return
5438
5439         MEMTOTAL=`meminfo MemTotal`
5440         NR_BLOCKS=$((MEMTOTAL>>8))
5441         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5442
5443         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5444         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5445         mkswap $DIR/f68b
5446
5447         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5448
5449         trap cleanup_68 EXIT
5450
5451         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5452
5453         echo "before: `swapon -s | grep $LLOOP`"
5454         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5455         echo "after: `swapon -s | grep $LLOOP`"
5456         SWAPUSED=`swap_used $LLOOP`
5457
5458         cleanup_68
5459
5460         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5461 }
5462 run_test 68b "support swapping to Lustre ========================"
5463
5464 # bug5265, obdfilter oa2dentry return -ENOENT
5465 # #define OBD_FAIL_OST_ENOENT 0x217
5466 test_69() {
5467         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5468         remote_ost_nodsh && skip "remote OST with nodsh" && return
5469
5470         f="$DIR/$tfile"
5471         $SETSTRIPE -c 1 -i 0 $f
5472
5473         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5474
5475         do_facet ost1 lctl set_param fail_loc=0x217
5476         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5477         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5478
5479         do_facet ost1 lctl set_param fail_loc=0
5480         $DIRECTIO write $f 0 2 || error "write error"
5481
5482         cancel_lru_locks osc
5483         $DIRECTIO read $f 0 1 || error "read error"
5484
5485         do_facet ost1 lctl set_param fail_loc=0x217
5486         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5487
5488         do_facet ost1 lctl set_param fail_loc=0
5489         rm -f $f
5490 }
5491 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5492
5493 test_71() {
5494     test_mkdir -p $DIR/$tdir
5495     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5496 }
5497 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5498
5499 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5500         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5501         [ "$RUNAS_ID" = "$UID" ] &&
5502                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5503
5504         # Check that testing environment is properly set up. Skip if not
5505         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5506                 skip_env "User $RUNAS_ID does not exist - skipping"
5507                 return 0
5508         }
5509         touch $DIR/$tfile
5510         chmod 777 $DIR/$tfile
5511         chmod ug+s $DIR/$tfile
5512         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5513                 error "$RUNAS dd $DIR/$tfile failed"
5514         # See if we are still setuid/sgid
5515         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5516                 error "S/gid is not dropped on write"
5517         # Now test that MDS is updated too
5518         cancel_lru_locks mdc
5519         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5520                 error "S/gid is not dropped on MDS"
5521         rm -f $DIR/$tfile
5522 }
5523 run_test 72a "Test that remove suid works properly (bug5695) ===="
5524
5525 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5526         local perm
5527
5528         [ "$RUNAS_ID" = "$UID" ] && \
5529                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5530         [ "$RUNAS_ID" -eq 0 ] && \
5531                 skip_env "RUNAS_ID = 0 -- skipping" && return
5532
5533         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5534         # Check that testing environment is properly set up. Skip if not
5535         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5536                 skip_env "User $RUNAS_ID does not exist - skipping"
5537                 return 0
5538         }
5539         touch $DIR/${tfile}-f{g,u}
5540         test_mkdir $DIR/${tfile}-dg
5541         test_mkdir $DIR/${tfile}-du
5542         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5543         chmod g+s $DIR/${tfile}-{f,d}g
5544         chmod u+s $DIR/${tfile}-{f,d}u
5545         for perm in 777 2777 4777; do
5546                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5547                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5548                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5549                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5550         done
5551         true
5552 }
5553 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5554
5555 # bug 3462 - multiple simultaneous MDC requests
5556 test_73() {
5557         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5558         test_mkdir $DIR/d73-1
5559         test_mkdir $DIR/d73-2
5560         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5561         pid1=$!
5562
5563         lctl set_param fail_loc=0x80000129
5564         $MULTIOP $DIR/d73-1/f73-2 Oc &
5565         sleep 1
5566         lctl set_param fail_loc=0
5567
5568         $MULTIOP $DIR/d73-2/f73-3 Oc &
5569         pid3=$!
5570
5571         kill -USR1 $pid1
5572         wait $pid1 || return 1
5573
5574         sleep 25
5575
5576         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5577         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5578         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5579
5580         rm -rf $DIR/d73-*
5581 }
5582 run_test 73 "multiple MDC requests (should not deadlock)"
5583
5584 test_74a() { # bug 6149, 6184
5585         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5586         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5587         #
5588         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5589         # will spin in a tight reconnection loop
5590         touch $DIR/f74a
5591         $LCTL set_param fail_loc=0x8000030e
5592         # get any lock that won't be difficult - lookup works.
5593         ls $DIR/f74a
5594         $LCTL set_param fail_loc=0
5595         rm -f $DIR/f74a
5596         true
5597 }
5598 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5599
5600 test_74b() { # bug 13310
5601         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5602         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5603         #
5604         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5605         # will spin in a tight reconnection loop
5606         $LCTL set_param fail_loc=0x8000030e
5607         # get a "difficult" lock
5608         touch $DIR/f74b
5609         $LCTL set_param fail_loc=0
5610         rm -f $DIR/f74b
5611         true
5612 }
5613 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5614
5615 test_74c() {
5616         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5617         #define OBD_FAIL_LDLM_NEW_LOCK
5618         $LCTL set_param fail_loc=0x319
5619         touch $DIR/$tfile && error "touch successful"
5620         $LCTL set_param fail_loc=0
5621         true
5622 }
5623 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5624
5625 num_inodes() {
5626         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5627 }
5628
5629 get_inode_slab_tunables() {
5630         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5631 }
5632
5633 set_inode_slab_tunables() {
5634         echo "lustre_inode_cache $1" > /proc/slabinfo
5635 }
5636
5637 test_76() { # Now for bug 20433, added originally in bug 1443
5638         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5639         local SLAB_SETTINGS=`get_inode_slab_tunables`
5640         local CPUS=`getconf _NPROCESSORS_ONLN`
5641         # we cannot set limit below 1 which means 1 inode in each
5642         # per-cpu cache is still allowed
5643         set_inode_slab_tunables "1 1 0"
5644         cancel_lru_locks osc
5645         BEFORE_INODES=$(num_inodes)
5646         echo "before inodes: $BEFORE_INODES"
5647         local COUNT=1000
5648         [ "$SLOW" = "no" ] && COUNT=100
5649         for i in $(seq $COUNT); do
5650                 touch $DIR/$tfile
5651                 rm -f $DIR/$tfile
5652         done
5653         cancel_lru_locks osc
5654         AFTER_INODES=$(num_inodes)
5655         echo "after inodes: $AFTER_INODES"
5656         local wait=0
5657         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5658                 sleep 2
5659                 AFTER_INODES=$(num_inodes)
5660                 wait=$((wait+2))
5661                 echo "wait $wait seconds inodes: $AFTER_INODES"
5662                 if [ $wait -gt 30 ]; then
5663                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5664                 fi
5665         done
5666         set_inode_slab_tunables "$SLAB_SETTINGS"
5667 }
5668 run_test 76 "confirm clients recycle inodes properly ===="
5669
5670
5671 export ORIG_CSUM=""
5672 set_checksums()
5673 {
5674         # Note: in sptlrpc modes which enable its own bulk checksum, the
5675         # original crc32_le bulk checksum will be automatically disabled,
5676         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5677         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5678         # In this case set_checksums() will not be no-op, because sptlrpc
5679         # bulk checksum will be enabled all through the test.
5680
5681         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5682         lctl set_param -n osc.*.checksums $1
5683         return 0
5684 }
5685
5686 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5687                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5688 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5689 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5690 set_checksum_type()
5691 {
5692         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5693         log "set checksum type to $1"
5694         return 0
5695 }
5696 F77_TMP=$TMP/f77-temp
5697 F77SZ=8
5698 setup_f77() {
5699         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5700                 error "error writing to $F77_TMP"
5701 }
5702
5703 test_77a() { # bug 10889
5704         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5705         $GSS && skip "could not run with gss" && return
5706         [ ! -f $F77_TMP ] && setup_f77
5707         set_checksums 1
5708         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5709         set_checksums 0
5710         rm -f $DIR/$tfile
5711 }
5712 run_test 77a "normal checksum read/write operation"
5713
5714 test_77b() { # bug 10889
5715         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5716         $GSS && skip "could not run with gss" && return
5717         [ ! -f $F77_TMP ] && setup_f77
5718         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5719         $LCTL set_param fail_loc=0x80000409
5720         set_checksums 1
5721
5722         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5723                 error "dd error: $?"
5724         $LCTL set_param fail_loc=0
5725
5726         for algo in $CKSUM_TYPES; do
5727                 cancel_lru_locks osc
5728                 set_checksum_type $algo
5729                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5730                 $LCTL set_param fail_loc=0x80000408
5731                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5732                 $LCTL set_param fail_loc=0
5733         done
5734         set_checksums 0
5735         set_checksum_type $ORIG_CSUM_TYPE
5736         rm -f $DIR/$tfile
5737 }
5738 run_test 77b "checksum error on client write, read"
5739
5740 test_77d() { # bug 10889
5741         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5742         $GSS && skip "could not run with gss" && return
5743         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5744         $LCTL set_param fail_loc=0x80000409
5745         set_checksums 1
5746         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5747                 error "direct write: rc=$?"
5748         $LCTL set_param fail_loc=0
5749         set_checksums 0
5750
5751         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5752         $LCTL set_param fail_loc=0x80000408
5753         set_checksums 1
5754         cancel_lru_locks osc
5755         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5756                 error "direct read: rc=$?"
5757         $LCTL set_param fail_loc=0
5758         set_checksums 0
5759 }
5760 run_test 77d "checksum error on OST direct write, read"
5761
5762 test_77f() { # bug 10889
5763         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5764         $GSS && skip "could not run with gss" && return
5765         set_checksums 1
5766         for algo in $CKSUM_TYPES; do
5767                 cancel_lru_locks osc
5768                 set_checksum_type $algo
5769                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5770                 $LCTL set_param fail_loc=0x409
5771                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5772                         error "direct write succeeded"
5773                 $LCTL set_param fail_loc=0
5774         done
5775         set_checksum_type $ORIG_CSUM_TYPE
5776         set_checksums 0
5777 }
5778 run_test 77f "repeat checksum error on write (expect error)"
5779
5780 test_77g() { # bug 10889
5781         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5782         $GSS && skip "could not run with gss" && return
5783         remote_ost_nodsh && skip "remote OST with nodsh" && return
5784
5785         [ ! -f $F77_TMP ] && setup_f77
5786
5787         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5788         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5789         do_facet ost1 lctl set_param fail_loc=0x8000021a
5790         set_checksums 1
5791         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5792                 error "write error: rc=$?"
5793         do_facet ost1 lctl set_param fail_loc=0
5794         set_checksums 0
5795
5796         cancel_lru_locks osc
5797         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5798         do_facet ost1 lctl set_param fail_loc=0x8000021b
5799         set_checksums 1
5800         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5801         do_facet ost1 lctl set_param fail_loc=0
5802         set_checksums 0
5803 }
5804 run_test 77g "checksum error on OST write, read"
5805
5806 test_77i() { # bug 13805
5807         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5808         $GSS && skip "could not run with gss" && return
5809         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5810         lctl set_param fail_loc=0x40b
5811         remount_client $MOUNT
5812         lctl set_param fail_loc=0
5813         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5814                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5815                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5816                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5817         done
5818         remount_client $MOUNT
5819 }
5820 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5821
5822 test_77j() { # bug 13805
5823         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5824         $GSS && skip "could not run with gss" && return
5825         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5826         lctl set_param fail_loc=0x40c
5827         remount_client $MOUNT
5828         lctl set_param fail_loc=0
5829         sleep 2 # wait async osc connect to finish
5830         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5831                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5832                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5833                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5834         done
5835         remount_client $MOUNT
5836 }
5837 run_test 77j "client only supporting ADLER32"
5838
5839 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5840 rm -f $F77_TMP
5841 unset F77_TMP
5842
5843 test_78() { # bug 10901
5844         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5845         remote_ost || { skip_env "local OST" && return; }
5846
5847         NSEQ=5
5848         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5849         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5850         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5851         echo "MemTotal: $MEMTOTAL"
5852
5853         # reserve 256MB of memory for the kernel and other running processes,
5854         # and then take 1/2 of the remaining memory for the read/write buffers.
5855         if [ $MEMTOTAL -gt 512 ] ;then
5856                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5857         else
5858                 # for those poor memory-starved high-end clusters...
5859                 MEMTOTAL=$((MEMTOTAL / 2))
5860         fi
5861         echo "Mem to use for directio: $MEMTOTAL"
5862
5863         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
5864         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
5865         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
5866         SMALLESTOST=$(lfs df $DIR | grep OST | awk '{ print $4 }' | sort -n |
5867                 head -n1)
5868         echo "Smallest OST: $SMALLESTOST"
5869         [[ $SMALLESTOST -lt 10240 ]] &&
5870                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5871
5872         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
5873                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5874
5875         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5876         echo "File size: $F78SIZE"
5877         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5878         for i in $(seq 1 $NSEQ); do
5879                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5880                 echo directIO rdwr round $i of $NSEQ
5881                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5882         done
5883
5884         rm -f $DIR/$tfile
5885 }
5886 run_test 78 "handle large O_DIRECT writes correctly ============"
5887
5888 test_79() { # bug 12743
5889         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5890         wait_delete_completed
5891
5892         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5893         BKFREE=$(calc_osc_kbytes kbytesfree)
5894         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5895
5896         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5897         DFTOTAL=`echo $STRING | cut -d, -f1`
5898         DFUSED=`echo $STRING  | cut -d, -f2`
5899         DFAVAIL=`echo $STRING | cut -d, -f3`
5900         DFFREE=$(($DFTOTAL - $DFUSED))
5901
5902         ALLOWANCE=$((64 * $OSTCOUNT))
5903
5904         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5905            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5906                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5907         fi
5908         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5909            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5910                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5911         fi
5912         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5913            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5914                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5915         fi
5916 }
5917 run_test 79 "df report consistency check ======================="
5918
5919 test_80() { # bug 10718
5920         remote_ost_nodsh && skip "remote OST with nodsh" && return
5921         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5922         # relax strong synchronous semantics for slow backends like ZFS
5923         local soc="obdfilter.*.sync_on_lock_cancel"
5924         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
5925         local hosts=
5926         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
5927                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
5928                           facet_active_host $host; done | sort -u)
5929                 do_nodes $hosts lctl set_param $soc=never
5930         fi
5931
5932         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
5933         sync; sleep 1; sync
5934         local BEFORE=`date +%s`
5935         cancel_lru_locks osc
5936         local AFTER=`date +%s`
5937         local DIFF=$((AFTER-BEFORE))
5938         if [ $DIFF -gt 1 ] ; then
5939                 error "elapsed for 1M@1T = $DIFF"
5940         fi
5941
5942         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
5943
5944         rm -f $DIR/$tfile
5945 }
5946 run_test 80 "Page eviction is equally fast at high offsets too  ===="
5947
5948 test_81a() { # LU-456
5949         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5950         remote_ost_nodsh && skip "remote OST with nodsh" && return
5951         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5952         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
5953         do_facet ost1 lctl set_param fail_loc=0x80000228
5954
5955         # write should trigger a retry and success
5956         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5957         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5958         RC=$?
5959         if [ $RC -ne 0 ] ; then
5960                 error "write should success, but failed for $RC"
5961         fi
5962 }
5963 run_test 81a "OST should retry write when get -ENOSPC ==============="
5964
5965 test_81b() { # LU-456
5966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5967         remote_ost_nodsh && skip "remote OST with nodsh" && return
5968         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5969         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
5970         do_facet ost1 lctl set_param fail_loc=0x228
5971
5972         # write should retry several times and return -ENOSPC finally
5973         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5974         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5975         RC=$?
5976         ENOSPC=28
5977         if [ $RC -ne $ENOSPC ] ; then
5978                 error "dd should fail for -ENOSPC, but succeed."
5979         fi
5980 }
5981 run_test 81b "OST should return -ENOSPC when retry still fails ======="
5982
5983 test_82() { # LU-1031
5984         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
5985         local gid1=14091995
5986         local gid2=16022000
5987
5988         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
5989         local MULTIPID1=$!
5990         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
5991         local MULTIPID2=$!
5992         kill -USR1 $MULTIPID2
5993         sleep 2
5994         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
5995                 error "First grouplock does not block second one"
5996         else
5997                 echo "Second grouplock blocks first one"
5998         fi
5999         kill -USR1 $MULTIPID1
6000         wait $MULTIPID1
6001         wait $MULTIPID2
6002 }
6003 run_test 82 "Basic grouplock test ==============================="
6004
6005 test_99a() {
6006         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6007                 return
6008         test_mkdir -p $DIR/d99cvsroot
6009         chown $RUNAS_ID $DIR/d99cvsroot
6010         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6011         cd $TMP
6012
6013         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6014         cd $oldPWD
6015 }
6016 run_test 99a "cvs init ========================================="
6017
6018 test_99b() {
6019         [ -z "$(which cvs 2>/dev/null)" ] &&
6020                 skip_env "could not find cvs" && return
6021         [ ! -d $DIR/d99cvsroot ] && test_99a
6022         cd /etc/init.d
6023         # some versions of cvs import exit(1) when asked to import links or
6024         # files they can't read.  ignore those files.
6025         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6026                         ! -perm +4 -printf '-I %f\n')
6027         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6028                 d99reposname vtag rtag
6029 }
6030 run_test 99b "cvs import ======================================="
6031
6032 test_99c() {
6033         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6034         [ ! -d $DIR/d99cvsroot ] && test_99b
6035         cd $DIR
6036         test_mkdir -p $DIR/d99reposname
6037         chown $RUNAS_ID $DIR/d99reposname
6038         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6039 }
6040 run_test 99c "cvs checkout ====================================="
6041
6042 test_99d() {
6043         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6044         [ ! -d $DIR/d99cvsroot ] && test_99c
6045         cd $DIR/d99reposname
6046         $RUNAS touch foo99
6047         $RUNAS cvs add -m 'addmsg' foo99
6048 }
6049 run_test 99d "cvs add =========================================="
6050
6051 test_99e() {
6052         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6053         [ ! -d $DIR/d99cvsroot ] && test_99c
6054         cd $DIR/d99reposname
6055         $RUNAS cvs update
6056 }
6057 run_test 99e "cvs update ======================================="
6058
6059 test_99f() {
6060         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6061         [ ! -d $DIR/d99cvsroot ] && test_99d
6062         cd $DIR/d99reposname
6063         $RUNAS cvs commit -m 'nomsg' foo99
6064     rm -fr $DIR/d99cvsroot
6065 }
6066 run_test 99f "cvs commit ======================================="
6067
6068 test_100() {
6069         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6070         [ "$NETTYPE" = tcp ] || \
6071                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
6072                         return ; }
6073
6074         remote_ost_nodsh && skip "remote OST with nodsh" && return
6075         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6076         remote_servers || \
6077                 { skip "useless for local single node setup" && return; }
6078
6079         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6080                 [ "$PROT" != "tcp" ] && continue
6081                 RPORT=$(echo $REMOTE | cut -d: -f2)
6082                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6083
6084                 rc=0
6085                 LPORT=`echo $LOCAL | cut -d: -f2`
6086                 if [ $LPORT -ge 1024 ]; then
6087                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6088                         netstat -tna
6089                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6090                 fi
6091         done
6092         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6093 }
6094 run_test 100 "check local port using privileged port ==========="
6095
6096 function get_named_value()
6097 {
6098     local tag
6099
6100     tag=$1
6101     while read ;do
6102         line=$REPLY
6103         case $line in
6104         $tag*)
6105             echo $line | sed "s/^$tag[ ]*//"
6106             break
6107             ;;
6108         esac
6109     done
6110 }
6111
6112 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6113                    awk '/^max_cached_mb/ { print $2 }')
6114
6115 cleanup_101a() {
6116         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6117         trap 0
6118 }
6119
6120 test_101a() {
6121         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6122         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
6123         local s
6124         local discard
6125         local nreads=10000
6126         local cache_limit=32
6127
6128         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6129         trap cleanup_101a EXIT
6130         $LCTL set_param -n llite.*.read_ahead_stats 0
6131         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6132
6133         #
6134         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6135         #
6136         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6137         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6138
6139         discard=0
6140         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6141                 get_named_value 'read but discarded' | cut -d" " -f1); do
6142                         discard=$(($discard + $s))
6143         done
6144         cleanup_101a
6145
6146         if [[ $(($discard * 10)) -gt $nreads ]]; then
6147                 $LCTL get_param osc.*-osc*.rpc_stats
6148                 $LCTL get_param llite.*.read_ahead_stats
6149                 error "too many ($discard) discarded pages"
6150         fi
6151         rm -f $DIR/$tfile || true
6152 }
6153 run_test 101a "check read-ahead for random reads ================"
6154
6155 setup_test101bc() {
6156         test_mkdir -p $DIR/$tdir
6157         local STRIPE_SIZE=$1
6158         local FILE_LENGTH=$2
6159         STRIPE_OFFSET=0
6160
6161         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6162
6163         local list=$(comma_list $(osts_nodes))
6164         set_osd_param $list '' read_cache_enable 0
6165         set_osd_param $list '' writethrough_cache_enable 0
6166
6167         trap cleanup_test101bc EXIT
6168         # prepare the read-ahead file
6169         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6170
6171         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6172                                 count=$FILE_SIZE_MB 2> /dev/null
6173
6174 }
6175
6176 cleanup_test101bc() {
6177         trap 0
6178         rm -rf $DIR/$tdir
6179         rm -f $DIR/$tfile
6180
6181         local list=$(comma_list $(osts_nodes))
6182         set_osd_param $list '' read_cache_enable 1
6183         set_osd_param $list '' writethrough_cache_enable 1
6184 }
6185
6186 calc_total() {
6187         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6188 }
6189
6190 ra_check_101() {
6191         local READ_SIZE=$1
6192         local STRIPE_SIZE=$2
6193         local FILE_LENGTH=$3
6194         local RA_INC=1048576
6195         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6196         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6197                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6198         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6199                         get_named_value 'read but discarded' |
6200                         cut -d" " -f1 | calc_total)
6201         if [[ $DISCARD -gt $discard_limit ]]; then
6202                 $LCTL get_param llite.*.read_ahead_stats
6203                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6204         else
6205                 echo "Read-ahead success for size ${READ_SIZE}"
6206         fi
6207 }
6208
6209 test_101b() {
6210         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6211         [[ $OSTCOUNT -lt 2 ]] &&
6212                 skip_env "skipping stride IO stride-ahead test" && return
6213         local STRIPE_SIZE=1048576
6214         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6215         if [ $SLOW == "yes" ]; then
6216                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6217         else
6218                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6219         fi
6220
6221         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6222
6223         # prepare the read-ahead file
6224         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6225         cancel_lru_locks osc
6226         for BIDX in 2 4 8 16 32 64 128 256
6227         do
6228                 local BSIZE=$((BIDX*4096))
6229                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6230                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6231                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6232                 $LCTL set_param -n llite.*.read_ahead_stats 0
6233                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6234                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6235                 cancel_lru_locks osc
6236                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6237         done
6238         cleanup_test101bc
6239         true
6240 }
6241 run_test 101b "check stride-io mode read-ahead ================="
6242
6243 test_101c() {
6244         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6245         local STRIPE_SIZE=1048576
6246         local FILE_LENGTH=$((STRIPE_SIZE*100))
6247         local nreads=10000
6248         local osc_rpc_stats
6249
6250         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6251
6252         cancel_lru_locks osc
6253         $LCTL set_param osc.*.rpc_stats 0
6254         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6255         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6256                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6257                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6258                 local size
6259
6260                 if [ $lines -le 20 ]; then
6261                         continue
6262                 fi
6263                 for size in 1 2 4 8; do
6264                         local rpc=$(echo "$stats" |
6265                                     awk '($1 == "'$size':") {print $2; exit; }')
6266                         [ $rpc != 0 ] &&
6267                                 error "Small $((size*4))k read IO $rpc !"
6268                 done
6269                 echo "$osc_rpc_stats check passed!"
6270         done
6271         cleanup_test101bc
6272         true
6273 }
6274 run_test 101c "check stripe_size aligned read-ahead ================="
6275
6276 set_read_ahead() {
6277         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6278         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6279 }
6280
6281 test_101d() {
6282         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6283         local file=$DIR/$tfile
6284         local sz_MB=${FILESIZE_101d:-500}
6285         local ra_MB=${READAHEAD_MB:-40}
6286
6287         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6288         [ $free_MB -lt $sz_MB ] &&
6289                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6290
6291         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6292         $SETSTRIPE -c -1 $file || error "setstripe failed"
6293
6294         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6295         echo Cancel LRU locks on lustre client to flush the client cache
6296         cancel_lru_locks osc
6297
6298         echo Disable read-ahead
6299         local old_READAHEAD=$(set_read_ahead 0)
6300
6301         echo Reading the test file $file with read-ahead disabled
6302         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6303
6304         echo Cancel LRU locks on lustre client to flush the client cache
6305         cancel_lru_locks osc
6306         echo Enable read-ahead with ${ra_MB}MB
6307         set_read_ahead $ra_MB
6308
6309         echo Reading the test file $file with read-ahead enabled
6310         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6311
6312         echo "read-ahead disabled time read $raOFF"
6313         echo "read-ahead enabled  time read $raON"
6314
6315         set_read_ahead $old_READAHEAD
6316         rm -f $file
6317         wait_delete_completed
6318
6319         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6320                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6321 }
6322 run_test 101d "file read with and without read-ahead enabled"
6323
6324 test_101e() {
6325         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6326         local file=$DIR/$tfile
6327         local size_KB=500  #KB
6328         local count=100
6329         local bsize=1024
6330
6331         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6332         local need_KB=$((count * size_KB))
6333         [[ $free_KB -le $need_KB ]] &&
6334                 skip_env "Need free space $need_KB, have $free_KB" && return
6335
6336         echo "Creating $count ${size_KB}K test files"
6337         for ((i = 0; i < $count; i++)); do
6338                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6339         done
6340
6341         echo "Cancel LRU locks on lustre client to flush the client cache"
6342         cancel_lru_locks osc
6343
6344         echo "Reset readahead stats"
6345         $LCTL set_param -n llite.*.read_ahead_stats 0
6346
6347         for ((i = 0; i < $count; i++)); do
6348                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6349         done
6350
6351         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6352                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6353
6354         for ((i = 0; i < $count; i++)); do
6355                 rm -rf $file.$i 2>/dev/null
6356         done
6357
6358         #10000 means 20% reads are missing in readahead
6359         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6360 }
6361 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6362
6363 cleanup_test101f() {
6364     trap 0
6365     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6366     rm -rf $DIR/$tfile 2>/dev/null
6367 }
6368
6369 test_101f() {
6370         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6371     local file=$DIR/$tfile
6372     local nreads=1000
6373
6374     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6375     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6376     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6377     trap cleanup_test101f EXIT
6378
6379     echo Cancel LRU locks on lustre client to flush the client cache
6380     cancel_lru_locks osc
6381
6382     echo Reset readahead stats
6383     $LCTL set_param -n llite.*.read_ahead_stats 0
6384     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6385     # readahead should read in 2M file on second read, so only miss
6386     # 2 pages.
6387     echo Random 4K reads on 2M file for 1000 times
6388     $READS -f $file -s 2097152 -b 4096 -n $nreads
6389
6390     echo checking missing pages
6391     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6392           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6393
6394     [ $miss -lt 3 ] || error "misses too much pages!"
6395     cleanup_test101f
6396 }
6397 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6398
6399 setup_test102() {
6400         test_mkdir -p $DIR/$tdir
6401         chown $RUNAS_ID $DIR/$tdir
6402         STRIPE_SIZE=65536
6403         STRIPE_OFFSET=1
6404         STRIPE_COUNT=$OSTCOUNT
6405         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6406
6407         trap cleanup_test102 EXIT
6408         cd $DIR
6409         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6410         cd $DIR/$tdir
6411         for num in 1 2 3 4; do
6412                 for count in $(seq 1 $STRIPE_COUNT); do
6413                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6414                                 local size=`expr $STRIPE_SIZE \* $num`
6415                                 local file=file"$num-$idx-$count"
6416                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6417                         done
6418                 done
6419         done
6420
6421         cd $DIR
6422         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6423 }
6424
6425 cleanup_test102() {
6426         trap 0
6427         rm -f $TMP/f102.tar
6428         rm -rf $DIR/d0.sanity/d102
6429 }
6430
6431 test_102a() {
6432         local testfile=$DIR/$tfile
6433
6434         touch $testfile
6435
6436         [ "$UID" != 0 ] && skip_env "must run as root" && return
6437         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6438                 skip_env "must have user_xattr" && return
6439
6440         [ -z "$(which setfattr 2>/dev/null)" ] &&
6441                 skip_env "could not find setfattr" && return
6442
6443         echo "set/get xattr..."
6444         setfattr -n trusted.name1 -v value1 $testfile ||
6445                 error "setfattr -n trusted.name1=value1 $testfile failed"
6446         getfattr -n trusted.name1 $testfile 2> /dev/null |
6447           grep "trusted.name1=.value1" ||
6448                 error "$testfile missing trusted.name1=value1"
6449
6450         setfattr -n user.author1 -v author1 $testfile ||
6451                 error "setfattr -n user.author1=author1 $testfile failed"
6452         getfattr -n user.author1 $testfile 2> /dev/null |
6453           grep "user.author1=.author1" ||
6454                 error "$testfile missing trusted.author1=author1"
6455
6456         echo "listxattr..."
6457         setfattr -n trusted.name2 -v value2 $testfile ||
6458                 error "$testfile unable to set trusted.name2"
6459         setfattr -n trusted.name3 -v value3 $testfile ||
6460                 error "$testfile unable to set trusted.name3"
6461         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6462             grep "trusted.name" | wc -l) -eq 3 ] ||
6463                 error "$testfile missing 3 trusted.name xattrs"
6464
6465         setfattr -n user.author2 -v author2 $testfile ||
6466                 error "$testfile unable to set user.author2"
6467         setfattr -n user.author3 -v author3 $testfile ||
6468                 error "$testfile unable to set user.author3"
6469         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6470             grep "user.author" | wc -l) -eq 3 ] ||
6471                 error "$testfile missing 3 user.author xattrs"
6472
6473         echo "remove xattr..."
6474         setfattr -x trusted.name1 $testfile ||
6475                 error "$testfile error deleting trusted.name1"
6476         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6477                 error "$testfile did not delete trusted.name1 xattr"
6478
6479         setfattr -x user.author1 $testfile ||
6480                 error "$testfile error deleting user.author1"
6481         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6482                 error "$testfile did not delete trusted.name1 xattr"
6483
6484         # b10667: setting lustre special xattr be silently discarded
6485         echo "set lustre special xattr ..."
6486         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6487                 error "$testfile allowed setting trusted.lov"
6488 }
6489 run_test 102a "user xattr test =================================="
6490
6491 test_102b() {
6492         [ -z "$(which setfattr 2>/dev/null)" ] &&
6493                 skip_env "could not find setfattr" && return
6494
6495         # b10930: get/set/list trusted.lov xattr
6496         echo "get/set/list trusted.lov xattr ..."
6497         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6498         local testfile=$DIR/$tfile
6499         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6500                 error "setstripe failed"
6501         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6502                 error "getstripe failed"
6503         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6504                 error "can't get trusted.lov from $testfile"
6505
6506         local testfile2=${testfile}2
6507         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6508                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6509
6510         $MCREATE $testfile2
6511         setfattr -n trusted.lov -v $value $testfile2
6512         local stripe_size=$($GETSTRIPE -S $testfile2)
6513         local stripe_count=$($GETSTRIPE -c $testfile2)
6514         [[ $stripe_size -eq 65536 ]] ||
6515                 error "stripe size $stripe_size != 65536"
6516         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6517                 error "stripe count $stripe_count != $STRIPECOUNT"
6518         rm -f $DIR/$tfile
6519 }
6520 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6521
6522 test_102c() {
6523         [ -z "$(which setfattr 2>/dev/null)" ] &&
6524                 skip_env "could not find setfattr" && return
6525
6526         # b10930: get/set/list lustre.lov xattr
6527         echo "get/set/list lustre.lov xattr ..."
6528         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6529         test_mkdir -p $DIR/$tdir
6530         chown $RUNAS_ID $DIR/$tdir
6531         local testfile=$DIR/$tdir/$tfile
6532         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6533                 error "setstripe failed"
6534         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6535                 error "getstripe failed"
6536         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6537         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6538
6539         local testfile2=${testfile}2
6540         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6541                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6542
6543         $RUNAS $MCREATE $testfile2
6544         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6545         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6546         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6547         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6548         [ $stripe_count -eq $STRIPECOUNT ] ||
6549                 error "stripe count $stripe_count != $STRIPECOUNT"
6550 }
6551 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6552
6553 compare_stripe_info1() {
6554         local stripe_index_all_zero=true
6555
6556         for num in 1 2 3 4; do
6557                 for count in $(seq 1 $STRIPE_COUNT); do
6558                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6559                                 local size=$((STRIPE_SIZE * num))
6560                                 local file=file"$num-$offset-$count"
6561                                 stripe_size=$(lfs getstripe -S $PWD/$file)
6562                                 [[ $stripe_size -ne $size ]] &&
6563                                     error "$file: size $stripe_size != $size"
6564                                 stripe_count=$(lfs getstripe -c $PWD/$file)
6565                                 # allow fewer stripes to be created, ORI-601
6566                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6567                                     error "$file: count $stripe_count != $count"
6568                                 stripe_index=$(lfs getstripe -i $PWD/$file)
6569                                 [[ $stripe_index -ne 0 ]] &&
6570                                         stripe_index_all_zero=false
6571                         done
6572                 done
6573         done
6574         $stripe_index_all_zero &&
6575                 error "all files are being extracted starting from OST index 0"
6576         return 0
6577 }
6578
6579 find_lustre_tar() {
6580         [ -n "$(which tar 2>/dev/null)" ] &&
6581                 strings $(which tar) | grep -q "lustre" && echo tar
6582 }
6583
6584 test_102d() {
6585         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6586         # b10930: tar test for trusted.lov xattr
6587         TAR=$(find_lustre_tar)
6588         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6589         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6590         setup_test102
6591         test_mkdir -p $DIR/d102d
6592         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6593         cd $DIR/d102d/$tdir
6594         compare_stripe_info1
6595 }
6596 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6597
6598 test_102f() {
6599         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6600         # b10930: tar test for trusted.lov xattr
6601         TAR=$(find_lustre_tar)
6602         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6603         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6604         setup_test102
6605         test_mkdir -p $DIR/d102f
6606         cd $DIR
6607         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6608         cd $DIR/d102f/$tdir
6609         compare_stripe_info1
6610 }
6611 run_test 102f "tar copy files, not keep osts ==========="
6612
6613 grow_xattr() {
6614         local xsize=${1:-1024}  # in bytes
6615         local file=$DIR/$tfile
6616
6617         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6618                 skip "must have user_xattr" && return 0
6619         [ -z "$(which setfattr 2>/dev/null)" ] &&
6620                 skip_env "could not find setfattr" && return 0
6621         [ -z "$(which getfattr 2>/dev/null)" ] &&
6622                 skip_env "could not find getfattr" && return 0
6623
6624         touch $file
6625
6626         local value="$(generate_string $xsize)"
6627
6628         local xbig=trusted.big
6629         log "save $xbig on $file"
6630         setfattr -n $xbig -v $value $file ||
6631                 error "saving $xbig on $file failed"
6632
6633         local orig=$(get_xattr_value $xbig $file)
6634         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6635
6636         local xsml=trusted.sml
6637         log "save $xsml on $file"
6638         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6639
6640         local new=$(get_xattr_value $xbig $file)
6641         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6642
6643         log "grow $xsml on $file"
6644         setfattr -n $xsml -v "$value" $file ||
6645                 error "growing $xsml on $file failed"
6646
6647         new=$(get_xattr_value $xbig $file)
6648         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6649         log "$xbig still valid after growing $xsml"
6650
6651         rm -f $file
6652 }
6653
6654 test_102h() { # bug 15777
6655         grow_xattr 1024
6656 }
6657 run_test 102h "grow xattr from inside inode to external block"
6658
6659 test_102ha() {
6660         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6661         grow_xattr $(max_xattr_size)
6662 }
6663 run_test 102ha "grow xattr from inside inode to external inode"
6664
6665 test_102i() { # bug 17038
6666         [ -z "$(which getfattr 2>/dev/null)" ] &&
6667                 skip "could not find getfattr" && return
6668         touch $DIR/$tfile
6669         ln -s $DIR/$tfile $DIR/${tfile}link
6670         getfattr -n trusted.lov $DIR/$tfile ||
6671                 error "lgetxattr on $DIR/$tfile failed"
6672         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6673                 grep -i "no such attr" ||
6674                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6675         rm -f $DIR/$tfile $DIR/${tfile}link
6676 }
6677 run_test 102i "lgetxattr test on symbolic link ============"
6678
6679 test_102j() {
6680         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6681         TAR=$(find_lustre_tar)
6682         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6683         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6684         setup_test102 "$RUNAS"
6685         test_mkdir -p $DIR/d102j
6686         chown $RUNAS_ID $DIR/d102j
6687         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6688         cd $DIR/d102j/$tdir
6689         compare_stripe_info1 "$RUNAS"
6690 }
6691 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6692
6693 test_102k() {
6694         [ -z "$(which setfattr 2>/dev/null)" ] &&
6695                 skip "could not find setfattr" && return
6696         touch $DIR/$tfile
6697         # b22187 just check that does not crash for regular file.
6698         setfattr -n trusted.lov $DIR/$tfile
6699         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6700         local test_kdir=$DIR/d102k
6701         test_mkdir $test_kdir
6702         local default_size=`$GETSTRIPE -S $test_kdir`
6703         local default_count=`$GETSTRIPE -c $test_kdir`
6704         local default_offset=`$GETSTRIPE -i $test_kdir`
6705         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6706                 error 'dir setstripe failed'
6707         setfattr -n trusted.lov $test_kdir
6708         local stripe_size=`$GETSTRIPE -S $test_kdir`
6709         local stripe_count=`$GETSTRIPE -c $test_kdir`
6710         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6711         [ $stripe_size -eq $default_size ] ||
6712                 error "stripe size $stripe_size != $default_size"
6713         [ $stripe_count -eq $default_count ] ||
6714                 error "stripe count $stripe_count != $default_count"
6715         [ $stripe_offset -eq $default_offset ] ||
6716                 error "stripe offset $stripe_offset != $default_offset"
6717         rm -rf $DIR/$tfile $test_kdir
6718 }
6719 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6720
6721 test_102l() {
6722         [ -z "$(which getfattr 2>/dev/null)" ] &&
6723                 skip "could not find getfattr" && return
6724
6725         # LU-532 trusted. xattr is invisible to non-root
6726         local testfile=$DIR/$tfile
6727
6728         touch $testfile
6729
6730         echo "listxattr as user..."
6731         chown $RUNAS_ID $testfile
6732         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6733             grep -q "trusted" &&
6734                 error "$testfile trusted xattrs are user visible"
6735
6736         return 0;
6737 }
6738 run_test 102l "listxattr size test =================================="
6739
6740 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6741         local path=$DIR/$tfile
6742         touch $path
6743
6744         listxattr_size_check $path || error "listattr_size_check $path failed"
6745 }
6746 run_test 102m "Ensure listxattr fails on small bufffer ========"
6747
6748 cleanup_test102
6749
6750 getxattr() { # getxattr path name
6751         # Return the base64 encoding of the value of xattr name on path.
6752         local path=$1
6753         local name=$2
6754
6755         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6756         # file: $path
6757         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6758         #
6759         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6760
6761         getfattr --absolute-names --encoding=base64 --name=$name $path |
6762                 awk -F= -v name=$name '$1 == name {
6763                         print substr($0, index($0, "=") + 1);
6764         }'
6765 }
6766
6767 test_102n() { # LU-4101 mdt: protect internal xattrs
6768         local file0=$DIR/$tfile.0
6769         local file1=$DIR/$tfile.1
6770         local xattr0=$TMP/$tfile.0
6771         local xattr1=$TMP/$tfile.1
6772         local name
6773         local value
6774
6775         [ -z "$(which setfattr 2>/dev/null)" ] &&
6776                 skip "could not find setfattr" && return
6777
6778         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6779         then
6780                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6781                 return
6782         fi
6783
6784         rm -rf $file0 $file1 $xattr0 $xattr1
6785         touch $file0 $file1
6786
6787         # Get 'before' xattrs of $file1.
6788         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6789
6790         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6791                 # Try to copy xattr from $file0 to $file1.
6792                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6793
6794                 setfattr --name=trusted.$name --value="$value" $file1 ||
6795                         error "setxattr 'trusted.$name' failed"
6796
6797                 # Try to set a garbage xattr.
6798                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6799
6800                 setfattr --name=trusted.$name --value="$value" $file1 ||
6801                         error "setxattr 'trusted.$name' failed"
6802
6803                 # Try to remove the xattr from $file1. We don't care if this
6804                 # appears to succeed or fail, we just don't want there to be
6805                 # any changes or crashes.
6806                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6807         done
6808
6809         # Get 'after' xattrs of file1.
6810         getfattr --absolute-names --dump --match=- $file1 > $xattr1
6811
6812         if ! diff $xattr0 $xattr1; then
6813                 error "before and after xattrs of '$file1' differ"
6814         fi
6815
6816         rm -rf $file0 $file1 $xattr0 $xattr1
6817
6818         return 0
6819 }
6820 run_test 102n "silently ignore setxattr on internal trusted xattrs"
6821
6822 test_102p() { # LU-4703 setxattr did not check ownership
6823         local testfile=$DIR/$tfile
6824
6825         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
6826                 skip "MDS needs to be at least 2.5.56" && return
6827
6828         touch $testfile
6829
6830         echo "setfacl as user..."
6831         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
6832         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
6833
6834         echo "setfattr as user..."
6835         setfacl -m "u:$RUNAS_ID:---" $testfile
6836         $RUNAS setfattr -x system.posix_acl_access $testfile
6837         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
6838 }
6839 run_test 102p "check setxattr(2) correctly fails without permission"
6840
6841 run_acl_subtest()
6842 {
6843     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6844     return $?
6845 }
6846
6847 test_103a() {
6848         [ "$UID" != 0 ] && skip_env "must run as root" && return
6849         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6850                 skip "must have acl enabled" && return
6851         [ -z "$(which setfacl 2>/dev/null)" ] &&
6852                 skip_env "could not find setfacl" && return
6853         $GSS && skip "could not run under gss" && return
6854
6855         declare -a identity_old
6856
6857         for num in $(seq $MDSCOUNT); do
6858                 switch_identity $num true || identity_old[$num]=$?
6859         done
6860
6861         SAVE_UMASK=$(umask)
6862         umask 0022
6863         cd $DIR
6864
6865         echo "performing cp ..."
6866         run_acl_subtest cp || error "run_acl_subtest cp failed"
6867         echo "performing getfacl-noacl..."
6868         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
6869         echo "performing misc..."
6870         run_acl_subtest misc || error  "misc test failed"
6871         echo "performing permissions..."
6872         run_acl_subtest permissions || error "permissions failed"
6873         echo "performing setfacl..."
6874         run_acl_subtest setfacl || error  "setfacl test failed"
6875
6876         # inheritance test got from HP
6877         echo "performing inheritance..."
6878         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
6879         chmod +x make-tree || error "chmod +x failed"
6880         run_acl_subtest inheritance || error "inheritance test failed"
6881         rm -f make-tree
6882
6883         echo "LU-974 ignore umask when acl is enabled..."
6884         run_acl_subtest 974 || error "LU-974 umask test failed"
6885         if [ $MDSCOUNT -ge 2 ]; then
6886                 run_acl_subtest 974_remote ||
6887                         error "LU-974 umask test failed under remote dir"
6888         fi
6889
6890         echo "LU-2561 newly created file is same size as directory..."
6891         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
6892                 run_acl_subtest 2561 || error "LU-2561 test failed"
6893         else
6894                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
6895         fi
6896
6897         run_acl_subtest 4924 || error "LU-4924 test failed"
6898
6899         cd $SAVE_PWD
6900         umask $SAVE_UMASK
6901
6902         for num in $(seq $MDSCOUNT); do
6903                 if [ "${identity_old[$num]}" = 1 ]; then
6904                         switch_identity $num false || identity_old[$num]=$?
6905                 fi
6906         done
6907 }
6908 run_test 103a "acl test ========================================="
6909
6910 test_103b() {
6911         local noacl=false
6912         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
6913         local mountopts=$MDS_MOUNT_OPTS
6914
6915         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
6916                 noacl=true
6917         else
6918                 # stop the MDT
6919                 stop $SINGLEMDS || error "failed to stop MDT."
6920                 # remount the MDT
6921                 if [ -z "$MDS_MOUNT_OPTS" ]; then
6922                         MDS_MOUNT_OPTS="-o noacl"
6923                 else
6924                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
6925                 fi
6926                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
6927                         error "failed to start MDT."
6928                 MDS_MOUNT_OPTS=$mountopts
6929         fi
6930
6931         touch $DIR/$tfile
6932         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
6933
6934         if ! $noacl; then
6935                 # stop the MDT
6936                 stop $SINGLEMDS || error "failed to stop MDT."
6937                 # remount the MDT
6938                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
6939                         error "failed to start MDT."
6940         fi
6941
6942         true
6943 }
6944 run_test 103b "MDS mount option 'noacl'"
6945
6946 test_103c() {
6947         mkdir -p $DIR/$tdir
6948         cp -rp $DIR/$tdir $DIR/$tdir.bak
6949
6950         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
6951                 error "$DIR/$tdir shouldn't contain default ACL"
6952         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
6953                 error "$DIR/$tdir.bak shouldn't contain default ACL"
6954         true
6955 }
6956 run_test 103c "'cp -rp' won't set empty acl"
6957
6958 test_104a() {
6959         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6960         touch $DIR/$tfile
6961         lfs df || error "lfs df failed"
6962         lfs df -ih || error "lfs df -ih failed"
6963         lfs df -h $DIR || error "lfs df -h $DIR failed"
6964         lfs df -i $DIR || error "lfs df -i $DIR failed"
6965         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
6966         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
6967
6968         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
6969         lctl --device %$OSC deactivate
6970         lfs df || error "lfs df with deactivated OSC failed"
6971         lctl --device %$OSC activate
6972         # wait the osc back to normal
6973         wait_osc_import_state client ost FULL
6974
6975         lfs df || error "lfs df with reactivated OSC failed"
6976         rm -f $DIR/$tfile
6977 }
6978 run_test 104a "lfs df [-ih] [path] test ========================="
6979
6980 test_104b() {
6981         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6982         [ $RUNAS_ID -eq $UID ] &&
6983                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6984         chmod 666 /dev/obd
6985         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
6986                         grep "Permission denied" | wc -l)))
6987         if [ $denied_cnt -ne 0 ]; then
6988                 error "lfs check servers test failed"
6989         fi
6990 }
6991 run_test 104b "$RUNAS lfs check servers test ===================="
6992
6993 test_105a() {
6994         # doesn't work on 2.4 kernels
6995         touch $DIR/$tfile
6996         if $(flock_is_enabled); then
6997                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
6998         else
6999                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7000         fi
7001         rm -f $DIR/$tfile
7002 }
7003 run_test 105a "flock when mounted without -o flock test ========"
7004
7005 test_105b() {
7006         touch $DIR/$tfile
7007         if $(flock_is_enabled); then
7008                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7009         else
7010                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7011         fi
7012         rm -f $DIR/$tfile
7013 }
7014 run_test 105b "fcntl when mounted without -o flock test ========"
7015
7016 test_105c() {
7017         touch $DIR/$tfile
7018         if $(flock_is_enabled); then
7019                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7020         else
7021                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7022         fi
7023         rm -f $DIR/$tfile
7024 }
7025 run_test 105c "lockf when mounted without -o flock test ========"
7026
7027 test_105d() { # bug 15924
7028         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7029         test_mkdir -p $DIR/$tdir
7030         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7031         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7032         $LCTL set_param fail_loc=0x80000315
7033         flocks_test 2 $DIR/$tdir
7034 }
7035 run_test 105d "flock race (should not freeze) ========"
7036
7037 test_105e() { # bug 22660 && 22040
7038         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7039         touch $DIR/$tfile
7040         flocks_test 3 $DIR/$tfile
7041 }
7042 run_test 105e "Two conflicting flocks from same process ======="
7043
7044 test_106() { #bug 10921
7045         test_mkdir -p $DIR/$tdir
7046         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7047         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7048 }
7049 run_test 106 "attempt exec of dir followed by chown of that dir"
7050
7051 test_107() {
7052         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7053         CDIR=`pwd`
7054         cd $DIR
7055
7056         local file=core
7057         rm -f $file
7058
7059         local save_pattern=$(sysctl -n kernel.core_pattern)
7060         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7061         sysctl -w kernel.core_pattern=$file
7062         sysctl -w kernel.core_uses_pid=0
7063
7064         ulimit -c unlimited
7065         sleep 60 &
7066         SLEEPPID=$!
7067
7068         sleep 1
7069
7070         kill -s 11 $SLEEPPID
7071         wait $SLEEPPID
7072         if [ -e $file ]; then
7073                 size=`stat -c%s $file`
7074                 [ $size -eq 0 ] && error "Fail to create core file $file"
7075         else
7076                 error "Fail to create core file $file"
7077         fi
7078         rm -f $file
7079         sysctl -w kernel.core_pattern=$save_pattern
7080         sysctl -w kernel.core_uses_pid=$save_uses_pid
7081         cd $CDIR
7082 }
7083 run_test 107 "Coredump on SIG"
7084
7085 test_110() {
7086         test_mkdir -p $DIR/$tdir
7087         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7088                 error "mkdir with 255 char failed"
7089         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7090                 error "mkdir with 256 char should fail, but did not"
7091         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7092                 error "create with 255 char failed"
7093         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7094                 error "create with 256 char should fail, but did not"
7095
7096         ls -l $DIR/$tdir
7097         rm -rf $DIR/$tdir
7098 }
7099 run_test 110 "filename length checking"
7100
7101 test_115() {
7102         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7103         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
7104                 tail -1 | cut -c11-20)
7105         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
7106         echo "Starting with $OSTIO_pre threads"
7107
7108         NUMTEST=20000
7109         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7110         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
7111         echo "$NUMTEST creates/unlinks"
7112         test_mkdir -p $DIR/$tdir
7113         createmany -o $DIR/$tdir/$tfile $NUMTEST
7114         unlinkmany $DIR/$tdir/$tfile $NUMTEST
7115
7116         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
7117                 tail -1 | cut -c11-20)
7118
7119         # don't return an error
7120         [ $OSTIO_post == $OSTIO_pre ] && echo \
7121             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
7122             echo "This may be fine, depending on what ran before this test" &&
7123             echo "and how fast this system is." && return
7124
7125         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
7126 }
7127 run_test 115 "verify dynamic thread creation===================="
7128
7129 free_min_max () {
7130         wait_delete_completed
7131         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7132         echo OST kbytes available: ${AVAIL[@]}
7133         MAXI=0; MAXV=${AVAIL[0]}
7134         MINI=0; MINV=${AVAIL[0]}
7135         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7136                 #echo OST $i: ${AVAIL[i]}kb
7137                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7138                         MAXV=${AVAIL[i]}; MAXI=$i
7139                 fi
7140                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7141                         MINV=${AVAIL[i]}; MINI=$i
7142                 fi
7143         done
7144         echo Min free space: OST $MINI: $MINV
7145         echo Max free space: OST $MAXI: $MAXV
7146 }
7147
7148 test_116a() { # was previously test_116()
7149         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7150         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
7151
7152         echo -n "Free space priority "
7153         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7154                 head -n1
7155         declare -a AVAIL
7156         free_min_max
7157
7158         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7159         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7160                 && return
7161         trap simple_cleanup_common EXIT
7162
7163
7164         # Check if we need to generate uneven OSTs
7165         test_mkdir -p $DIR/$tdir/OST${MINI}
7166         local FILL=$(($MINV / 4))
7167         local DIFF=$(($MAXV - $MINV))
7168         local DIFF2=$(($DIFF * 100 / $MINV))
7169
7170         local threshold=$(do_facet $SINGLEMDS \
7171                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7172         threshold=${threshold%%%}
7173         echo -n "Check for uneven OSTs: "
7174         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7175
7176         if [[ $DIFF2 -gt $threshold ]]; then
7177                 echo "ok"
7178                 echo "Don't need to fill OST$MINI"
7179         else
7180                 # generate uneven OSTs. Write 2% over the QOS threshold value
7181                 echo "no"
7182                 DIFF=$(($threshold - $DIFF2 + 2))
7183                 DIFF2=$(( ($MINV * $DIFF)/100 ))
7184                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
7185                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7186                         error "setstripe failed"
7187                 DIFF=$(($DIFF2 / 2048))
7188                 i=0
7189                 while [ $i -lt $DIFF ]; do
7190                         i=$(($i + 1))
7191                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7192                                 bs=2M count=1 2>/dev/null
7193                         echo -n .
7194                 done
7195                 echo .
7196                 sync
7197                 sleep_maxage
7198                 free_min_max
7199         fi
7200
7201         DIFF=$(($MAXV - $MINV))
7202         DIFF2=$(($DIFF * 100 / $MINV))
7203         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
7204         if [[ $DIFF2 -gt $threshold ]]; then
7205                 echo "ok"
7206         else
7207                 echo "failed - QOS mode won't be used"
7208                 skip "QOS imbalance criteria not met"
7209                 simple_cleanup_common
7210                 return
7211         fi
7212
7213         MINI1=$MINI; MINV1=$MINV
7214         MAXI1=$MAXI; MAXV1=$MAXV
7215
7216         # now fill using QOS
7217         $SETSTRIPE -c 1 $DIR/$tdir
7218         FILL=$(($FILL / 200))
7219         if [ $FILL -gt 600 ]; then
7220                 FILL=600
7221         fi
7222         echo "writing $FILL files to QOS-assigned OSTs"
7223         i=0
7224         while [ $i -lt $FILL ]; do
7225                 i=$((i + 1))
7226                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7227                         count=1 2>/dev/null
7228                 echo -n .
7229         done
7230         echo "wrote $i 200k files"
7231         sync
7232         sleep_maxage
7233
7234         echo "Note: free space may not be updated, so measurements might be off"
7235         free_min_max
7236         DIFF2=$(($MAXV - $MINV))
7237         echo "free space delta: orig $DIFF final $DIFF2"
7238         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7239         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
7240         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7241         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
7242         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7243         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7244         [ $DIFF -gt 0 ] &&
7245                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7246
7247         # Figure out which files were written where
7248         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7249                   awk '/'$MINI1': / {print $2; exit}')
7250         echo $UUID
7251         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7252         echo "$MINC files created on smaller OST $MINI1"
7253         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7254                   awk '/'$MAXI1': / {print $2; exit}')
7255         echo $UUID
7256         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7257         echo "$MAXC files created on larger OST $MAXI1"
7258         FILL=$(($MAXC * 100 / $MINC - 100))
7259         [[ $MINC -gt 0 ]] &&
7260                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7261         [[ $MAXC -gt $MINC ]] ||
7262                 error_ignore LU-9 "stripe QOS didn't balance free space"
7263         simple_cleanup_common
7264 }
7265 run_test 116a "stripe QOS: free space balance ==================="
7266
7267 test_116b() { # LU-2093
7268         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7269         [ -z "$($LCTL get_param -n lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr |
7270                 head -1 2>/dev/null)" ] && skip "no QOS" && return
7271 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7272         local old_rr
7273         old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7274                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7275         do_facet $SINGLEMDS lctl set_param \
7276                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7277         mkdir -p $DIR/$tdir
7278         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7279         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7280         do_facet $SINGLEMDS lctl set_param fail_loc=0
7281         rm -rf $DIR/$tdir
7282         do_facet $SINGLEMDS lctl set_param \
7283                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7284 }
7285 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7286
7287 test_117() # bug 10891
7288 {
7289         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7290         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7291         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7292         lctl set_param fail_loc=0x21e
7293         > $DIR/$tfile || error "truncate failed"
7294         lctl set_param fail_loc=0
7295         echo "Truncate succeeded."
7296         rm -f $DIR/$tfile
7297 }
7298 run_test 117 "verify osd extend =========="
7299
7300 NO_SLOW_RESENDCOUNT=4
7301 export OLD_RESENDCOUNT=""
7302 set_resend_count () {
7303         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7304         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7305         lctl set_param -n $PROC_RESENDCOUNT $1
7306         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7307 }
7308
7309 # for reduce test_118* time (b=14842)
7310 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7311
7312 # Reset async IO behavior after error case
7313 reset_async() {
7314         FILE=$DIR/reset_async
7315
7316         # Ensure all OSCs are cleared
7317         $SETSTRIPE -c -1 $FILE
7318         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7319         sync
7320         rm $FILE
7321 }
7322
7323 test_118a() #bug 11710
7324 {
7325         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7326         reset_async
7327
7328         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7329         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7330         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7331
7332         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7333                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7334                 return 1;
7335         fi
7336         rm -f $DIR/$tfile
7337 }
7338 run_test 118a "verify O_SYNC works =========="
7339
7340 test_118b()
7341 {
7342         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7343         remote_ost_nodsh && skip "remote OST with nodsh" && return
7344
7345         reset_async
7346
7347         #define OBD_FAIL_OST_ENOENT 0x217
7348         set_nodes_failloc "$(osts_nodes)" 0x217
7349         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7350         RC=$?
7351         set_nodes_failloc "$(osts_nodes)" 0
7352         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7353         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7354                     grep -c writeback)
7355
7356         if [[ $RC -eq 0 ]]; then
7357                 error "Must return error due to dropped pages, rc=$RC"
7358                 return 1;
7359         fi
7360
7361         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7362                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7363                 return 1;
7364         fi
7365
7366         echo "Dirty pages not leaked on ENOENT"
7367
7368         # Due to the above error the OSC will issue all RPCs syncronously
7369         # until a subsequent RPC completes successfully without error.
7370         $MULTIOP $DIR/$tfile Ow4096yc
7371         rm -f $DIR/$tfile
7372
7373         return 0
7374 }
7375 run_test 118b "Reclaim dirty pages on fatal error =========="
7376
7377 test_118c()
7378 {
7379         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7380
7381         # for 118c, restore the original resend count, LU-1940
7382         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7383                                 set_resend_count $OLD_RESENDCOUNT
7384         remote_ost_nodsh && skip "remote OST with nodsh" && return
7385
7386         reset_async
7387
7388         #define OBD_FAIL_OST_EROFS               0x216
7389         set_nodes_failloc "$(osts_nodes)" 0x216
7390
7391         # multiop should block due to fsync until pages are written
7392         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7393         MULTIPID=$!
7394         sleep 1
7395
7396         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7397                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7398         fi
7399
7400         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7401                     grep -c writeback)
7402         if [[ $WRITEBACK -eq 0 ]]; then
7403                 error "No page in writeback, writeback=$WRITEBACK"
7404         fi
7405
7406         set_nodes_failloc "$(osts_nodes)" 0
7407         wait $MULTIPID
7408         RC=$?
7409         if [[ $RC -ne 0 ]]; then
7410                 error "Multiop fsync failed, rc=$RC"
7411         fi
7412
7413         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7414         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7415                     grep -c writeback)
7416         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7417                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7418         fi
7419
7420         rm -f $DIR/$tfile
7421         echo "Dirty pages flushed via fsync on EROFS"
7422         return 0
7423 }
7424 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7425
7426 # continue to use small resend count to reduce test_118* time (b=14842)
7427 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7428
7429 test_118d()
7430 {
7431         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7432         remote_ost_nodsh && skip "remote OST with nodsh" && return
7433
7434         reset_async
7435
7436         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7437         set_nodes_failloc "$(osts_nodes)" 0x214
7438         # multiop should block due to fsync until pages are written
7439         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7440         MULTIPID=$!
7441         sleep 1
7442
7443         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7444                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7445         fi
7446
7447         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7448                     grep -c writeback)
7449         if [[ $WRITEBACK -eq 0 ]]; then
7450                 error "No page in writeback, writeback=$WRITEBACK"
7451         fi
7452
7453         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7454         set_nodes_failloc "$(osts_nodes)" 0
7455
7456         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7457         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7458                     grep -c writeback)
7459         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7460                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7461         fi
7462
7463         rm -f $DIR/$tfile
7464         echo "Dirty pages gaurenteed flushed via fsync"
7465         return 0
7466 }
7467 run_test 118d "Fsync validation inject a delay of the bulk =========="
7468
7469 test_118f() {
7470         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7471         reset_async
7472
7473         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7474         lctl set_param fail_loc=0x8000040a
7475
7476         # Should simulate EINVAL error which is fatal
7477         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7478         RC=$?
7479         if [[ $RC -eq 0 ]]; then
7480                 error "Must return error due to dropped pages, rc=$RC"
7481         fi
7482
7483         lctl set_param fail_loc=0x0
7484
7485         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7486         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7487         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7488                     grep -c writeback)
7489         if [[ $LOCKED -ne 0 ]]; then
7490                 error "Locked pages remain in cache, locked=$LOCKED"
7491         fi
7492
7493         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7494                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7495         fi
7496
7497         rm -f $DIR/$tfile
7498         echo "No pages locked after fsync"
7499
7500         reset_async
7501         return 0
7502 }
7503 run_test 118f "Simulate unrecoverable OSC side error =========="
7504
7505 test_118g() {
7506         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7507         reset_async
7508
7509         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7510         lctl set_param fail_loc=0x406
7511
7512         # simulate local -ENOMEM
7513         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7514         RC=$?
7515
7516         lctl set_param fail_loc=0
7517         if [[ $RC -eq 0 ]]; then
7518                 error "Must return error due to dropped pages, rc=$RC"
7519         fi
7520
7521         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7522         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7523         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7524                         grep -c writeback)
7525         if [[ $LOCKED -ne 0 ]]; then
7526                 error "Locked pages remain in cache, locked=$LOCKED"
7527         fi
7528
7529         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7530                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7531         fi
7532
7533         rm -f $DIR/$tfile
7534         echo "No pages locked after fsync"
7535
7536         reset_async
7537         return 0
7538 }
7539 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7540
7541 test_118h() {
7542         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7543         remote_ost_nodsh && skip "remote OST with nodsh" && return
7544
7545         reset_async
7546
7547         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7548         set_nodes_failloc "$(osts_nodes)" 0x20e
7549         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7550         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7551         RC=$?
7552
7553         set_nodes_failloc "$(osts_nodes)" 0
7554         if [[ $RC -eq 0 ]]; then
7555                 error "Must return error due to dropped pages, rc=$RC"
7556         fi
7557
7558         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7559         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7560         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7561                     grep -c writeback)
7562         if [[ $LOCKED -ne 0 ]]; then
7563                 error "Locked pages remain in cache, locked=$LOCKED"
7564         fi
7565
7566         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7567                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7568         fi
7569
7570         rm -f $DIR/$tfile
7571         echo "No pages locked after fsync"
7572
7573         return 0
7574 }
7575 run_test 118h "Verify timeout in handling recoverables errors  =========="
7576
7577 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7578
7579 test_118i() {
7580         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7581         remote_ost_nodsh && skip "remote OST with nodsh" && return
7582
7583         reset_async
7584
7585         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7586         set_nodes_failloc "$(osts_nodes)" 0x20e
7587
7588         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7589         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7590         PID=$!
7591         sleep 5
7592         set_nodes_failloc "$(osts_nodes)" 0
7593
7594         wait $PID
7595         RC=$?
7596         if [[ $RC -ne 0 ]]; then
7597                 error "got error, but should be not, rc=$RC"
7598         fi
7599
7600         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7601         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7602         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7603         if [[ $LOCKED -ne 0 ]]; then
7604                 error "Locked pages remain in cache, locked=$LOCKED"
7605         fi
7606
7607         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7608                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7609         fi
7610
7611         rm -f $DIR/$tfile
7612         echo "No pages locked after fsync"
7613
7614         return 0
7615 }
7616 run_test 118i "Fix error before timeout in recoverable error  =========="
7617
7618 [ "$SLOW" = "no" ] && set_resend_count 4
7619
7620 test_118j() {
7621         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7622         remote_ost_nodsh && skip "remote OST with nodsh" && return
7623
7624         reset_async
7625
7626         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7627         set_nodes_failloc "$(osts_nodes)" 0x220
7628
7629         # return -EIO from OST
7630         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7631         RC=$?
7632         set_nodes_failloc "$(osts_nodes)" 0x0
7633         if [[ $RC -eq 0 ]]; then
7634                 error "Must return error due to dropped pages, rc=$RC"
7635         fi
7636
7637         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7638         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7639         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7640         if [[ $LOCKED -ne 0 ]]; then
7641                 error "Locked pages remain in cache, locked=$LOCKED"
7642         fi
7643
7644         # in recoverable error on OST we want resend and stay until it finished
7645         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7646                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7647         fi
7648
7649         rm -f $DIR/$tfile
7650         echo "No pages locked after fsync"
7651
7652         return 0
7653 }
7654 run_test 118j "Simulate unrecoverable OST side error =========="
7655
7656 test_118k()
7657 {
7658         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7659         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7660
7661         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7662         set_nodes_failloc "$(osts_nodes)" 0x20e
7663         test_mkdir -p $DIR/$tdir
7664
7665         for ((i=0;i<10;i++)); do
7666                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7667                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7668                 SLEEPPID=$!
7669                 sleep 0.500s
7670                 kill $SLEEPPID
7671                 wait $SLEEPPID
7672         done
7673
7674         set_nodes_failloc "$(osts_nodes)" 0
7675         rm -rf $DIR/$tdir
7676 }
7677 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7678
7679 test_118l()
7680 {
7681         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7682         # LU-646
7683         test_mkdir -p $DIR/$tdir
7684         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7685         rm -rf $DIR/$tdir
7686 }
7687 run_test 118l "fsync dir ========="
7688
7689 test_118m() # LU-3066
7690 {
7691         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7692         test_mkdir -p $DIR/$tdir
7693         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7694         rm -rf $DIR/$tdir
7695 }
7696 run_test 118m "fdatasync dir ========="
7697
7698 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7699
7700 test_119a() # bug 11737
7701 {
7702         BSIZE=$((512 * 1024))
7703         directio write $DIR/$tfile 0 1 $BSIZE
7704         # We ask to read two blocks, which is more than a file size.
7705         # directio will indicate an error when requested and actual
7706         # sizes aren't equeal (a normal situation in this case) and
7707         # print actual read amount.
7708         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7709         if [ "$NOB" != "$BSIZE" ]; then
7710                 error "read $NOB bytes instead of $BSIZE"
7711         fi
7712         rm -f $DIR/$tfile
7713 }
7714 run_test 119a "Short directIO read must return actual read amount"
7715
7716 test_119b() # bug 11737
7717 {
7718         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7719
7720         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7721         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7722         sync
7723         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7724                 error "direct read failed"
7725         rm -f $DIR/$tfile
7726 }
7727 run_test 119b "Sparse directIO read must return actual read amount"
7728
7729 test_119c() # bug 13099
7730 {
7731         BSIZE=1048576
7732         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7733         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7734         rm -f $DIR/$tfile
7735 }
7736 run_test 119c "Testing for direct read hitting hole"
7737
7738 test_119d() # bug 15950
7739 {
7740         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7741         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7742         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7743         BSIZE=1048576
7744         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7745         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7746         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7747         lctl set_param fail_loc=0x40d
7748         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7749         pid_dio=$!
7750         sleep 1
7751         cat $DIR/$tfile > /dev/null &
7752         lctl set_param fail_loc=0
7753         pid_reads=$!
7754         wait $pid_dio
7755         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7756         sleep 2
7757         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7758         error "the read rpcs have not completed in 2s"
7759         rm -f $DIR/$tfile
7760         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7761 }
7762 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7763
7764 test_120a() {
7765         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7766         test_mkdir -p $DIR/$tdir
7767         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7768                skip "no early lock cancel on server" && return 0
7769
7770         lru_resize_disable mdc
7771         lru_resize_disable osc
7772         cancel_lru_locks mdc
7773         # asynchronous object destroy at MDT could cause bl ast to client
7774         cancel_lru_locks osc
7775
7776         stat $DIR/$tdir > /dev/null
7777         can1=$(do_facet $SINGLEMDS \
7778                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7779                awk '/ldlm_cancel/ {print $2}')
7780         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7781                awk '/ldlm_bl_callback/ {print $2}')
7782         test_mkdir -c1 $DIR/$tdir/d1
7783         can2=$(do_facet $SINGLEMDS \
7784                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7785                awk '/ldlm_cancel/ {print $2}')
7786         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7787                awk '/ldlm_bl_callback/ {print $2}')
7788         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7789         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7790         lru_resize_enable mdc
7791         lru_resize_enable osc
7792 }
7793 run_test 120a "Early Lock Cancel: mkdir test"
7794
7795 test_120b() {
7796         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7797         test_mkdir $DIR/$tdir
7798         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7799                skip "no early lock cancel on server" && return 0
7800         lru_resize_disable mdc
7801         lru_resize_disable osc
7802         cancel_lru_locks mdc
7803         stat $DIR/$tdir > /dev/null
7804         can1=$(do_facet $SINGLEMDS \
7805                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7806                awk '/ldlm_cancel/ {print $2}')
7807         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7808                awk '/ldlm_bl_callback/ {print $2}')
7809         touch $DIR/$tdir/f1
7810         can2=$(do_facet $SINGLEMDS \
7811                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7812                awk '/ldlm_cancel/ {print $2}')
7813         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7814                awk '/ldlm_bl_callback/ {print $2}')
7815         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7816         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7817         lru_resize_enable mdc
7818         lru_resize_enable osc
7819 }
7820 run_test 120b "Early Lock Cancel: create test"
7821
7822 test_120c() {
7823         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7824         test_mkdir -c1 $DIR/$tdir
7825         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7826                skip "no early lock cancel on server" && return 0
7827         lru_resize_disable mdc
7828         lru_resize_disable osc
7829         test_mkdir -p -c1 $DIR/$tdir/d1
7830         test_mkdir -p -c1 $DIR/$tdir/d2
7831         touch $DIR/$tdir/d1/f1
7832         cancel_lru_locks mdc
7833         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7834         can1=$(do_facet $SINGLEMDS \
7835                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7836                awk '/ldlm_cancel/ {print $2}')
7837         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7838                awk '/ldlm_bl_callback/ {print $2}')
7839         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7840         can2=$(do_facet $SINGLEMDS \
7841                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7842                awk '/ldlm_cancel/ {print $2}')
7843         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7844                awk '/ldlm_bl_callback/ {print $2}')
7845         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7846         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7847         lru_resize_enable mdc
7848         lru_resize_enable osc
7849 }
7850 run_test 120c "Early Lock Cancel: link test"
7851
7852 test_120d() {
7853         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7854         test_mkdir -p -c1 $DIR/$tdir
7855         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7856                skip "no early lock cancel on server" && return 0
7857         lru_resize_disable mdc
7858         lru_resize_disable osc
7859         touch $DIR/$tdir
7860         cancel_lru_locks mdc
7861         stat $DIR/$tdir > /dev/null
7862         can1=$(do_facet $SINGLEMDS \
7863                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7864                awk '/ldlm_cancel/ {print $2}')
7865         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7866                awk '/ldlm_bl_callback/ {print $2}')
7867         chmod a+x $DIR/$tdir
7868         can2=$(do_facet $SINGLEMDS \
7869                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7870                awk '/ldlm_cancel/ {print $2}')
7871         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7872                awk '/ldlm_bl_callback/ {print $2}')
7873         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7874         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7875         lru_resize_enable mdc
7876         lru_resize_enable osc
7877 }
7878 run_test 120d "Early Lock Cancel: setattr test"
7879
7880 test_120e() {
7881         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7882         test_mkdir -p -c1 $DIR/$tdir
7883         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7884                skip "no early lock cancel on server" && return 0
7885         lru_resize_disable mdc
7886         lru_resize_disable osc
7887         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
7888         cancel_lru_locks mdc
7889         cancel_lru_locks osc
7890         dd if=$DIR/$tdir/f1 of=/dev/null
7891         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
7892         # XXX client can not do early lock cancel of OST lock
7893         # during unlink (LU-4206), so cancel osc lock now.
7894         cancel_lru_locks osc
7895         can1=$(do_facet $SINGLEMDS \
7896                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7897                awk '/ldlm_cancel/ {print $2}')
7898         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7899                awk '/ldlm_bl_callback/ {print $2}')
7900         unlink $DIR/$tdir/f1
7901         sleep 5
7902         can2=$(do_facet $SINGLEMDS \
7903                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7904                awk '/ldlm_cancel/ {print $2}')
7905         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7906                awk '/ldlm_bl_callback/ {print $2}')
7907         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7908         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7909         lru_resize_enable mdc
7910         lru_resize_enable osc
7911 }
7912 run_test 120e "Early Lock Cancel: unlink test"
7913
7914 test_120f() {
7915         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7916         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7917                skip "no early lock cancel on server" && return 0
7918         test_mkdir -p -c1 $DIR/$tdir
7919         lru_resize_disable mdc
7920         lru_resize_disable osc
7921         test_mkdir -p -c1 $DIR/$tdir/d1
7922         test_mkdir -p -c1 $DIR/$tdir/d2
7923         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
7924         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
7925         cancel_lru_locks mdc
7926         cancel_lru_locks osc
7927         dd if=$DIR/$tdir/d1/f1 of=/dev/null
7928         dd if=$DIR/$tdir/d2/f2 of=/dev/null
7929         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
7930         # XXX client can not do early lock cancel of OST lock
7931         # during rename (LU-4206), so cancel osc lock now.
7932         cancel_lru_locks osc
7933         can1=$(do_facet $SINGLEMDS \
7934                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7935                awk '/ldlm_cancel/ {print $2}')
7936         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7937                awk '/ldlm_bl_callback/ {print $2}')
7938         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7939         sleep 5
7940         can2=$(do_facet $SINGLEMDS \
7941                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7942                awk '/ldlm_cancel/ {print $2}')
7943         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7944                awk '/ldlm_bl_callback/ {print $2}')
7945         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7946         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7947         lru_resize_enable mdc
7948         lru_resize_enable osc
7949 }
7950 run_test 120f "Early Lock Cancel: rename test"
7951
7952 test_120g() {
7953         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7954         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7955                skip "no early lock cancel on server" && return 0
7956         lru_resize_disable mdc
7957         lru_resize_disable osc
7958         count=10000
7959         echo create $count files
7960         test_mkdir -p $DIR/$tdir
7961         cancel_lru_locks mdc
7962         cancel_lru_locks osc
7963         t0=`date +%s`
7964
7965         can0=$(do_facet $SINGLEMDS \
7966                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7967                awk '/ldlm_cancel/ {print $2}')
7968         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7969                awk '/ldlm_bl_callback/ {print $2}')
7970         createmany -o $DIR/$tdir/f $count
7971         sync
7972         can1=$(do_facet $SINGLEMDS \
7973                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7974                awk '/ldlm_cancel/ {print $2}')
7975         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7976                awk '/ldlm_bl_callback/ {print $2}')
7977         t1=$(date +%s)
7978         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
7979         echo rm $count files
7980         rm -r $DIR/$tdir
7981         sync
7982         can2=$(do_facet $SINGLEMDS \
7983                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7984                awk '/ldlm_cancel/ {print $2}')
7985         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7986                awk '/ldlm_bl_callback/ {print $2}')
7987         t2=$(date +%s)
7988         echo total: $count removes in $((t2-t1))
7989         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
7990         sleep 2
7991         # wait for commitment of removal
7992         lru_resize_enable mdc
7993         lru_resize_enable osc
7994 }
7995 run_test 120g "Early Lock Cancel: performance test"
7996
7997 test_121() { #bug #10589
7998         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7999         rm -rf $DIR/$tfile
8000         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8001 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8002         lctl set_param fail_loc=0x310
8003         cancel_lru_locks osc > /dev/null
8004         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8005         lctl set_param fail_loc=0
8006         [[ $reads -eq $writes ]] ||
8007                 error "read $reads blocks, must be $writes blocks"
8008 }
8009 run_test 121 "read cancel race ========="
8010
8011 test_123a() { # was test 123, statahead(bug 11401)
8012         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8013         SLOWOK=0
8014         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8015             log "testing on UP system. Performance may be not as good as expected."
8016                         SLOWOK=1
8017         fi
8018
8019         rm -rf $DIR/$tdir
8020         test_mkdir -p $DIR/$tdir
8021         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8022         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8023         MULT=10
8024         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8025                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8026
8027                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8028                 lctl set_param -n llite.*.statahead_max 0
8029                 lctl get_param llite.*.statahead_max
8030                 cancel_lru_locks mdc
8031                 cancel_lru_locks osc
8032                 stime=`date +%s`
8033                 time ls -l $DIR/$tdir | wc -l
8034                 etime=`date +%s`
8035                 delta=$((etime - stime))
8036                 log "ls $i files without statahead: $delta sec"
8037                 lctl set_param llite.*.statahead_max=$max
8038
8039                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8040                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8041                 cancel_lru_locks mdc
8042                 cancel_lru_locks osc
8043                 stime=`date +%s`
8044                 time ls -l $DIR/$tdir | wc -l
8045                 etime=`date +%s`
8046                 delta_sa=$((etime - stime))
8047                 log "ls $i files with statahead: $delta_sa sec"
8048                 lctl get_param -n llite.*.statahead_stats
8049                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8050
8051                 [[ $swrong -lt $ewrong ]] &&
8052                         log "statahead was stopped, maybe too many locks held!"
8053                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8054
8055                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8056                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8057                     lctl set_param -n llite.*.statahead_max 0
8058                     lctl get_param llite.*.statahead_max
8059                     cancel_lru_locks mdc
8060                     cancel_lru_locks osc
8061                     stime=`date +%s`
8062                     time ls -l $DIR/$tdir | wc -l
8063                     etime=`date +%s`
8064                     delta=$((etime - stime))
8065                     log "ls $i files again without statahead: $delta sec"
8066                     lctl set_param llite.*.statahead_max=$max
8067                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8068                         if [  $SLOWOK -eq 0 ]; then
8069                                 error "ls $i files is slower with statahead!"
8070                         else
8071                                 log "ls $i files is slower with statahead!"
8072                         fi
8073                         break
8074                     fi
8075                 fi
8076
8077                 [ $delta -gt 20 ] && break
8078                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8079                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8080         done
8081         log "ls done"
8082
8083         stime=`date +%s`
8084         rm -r $DIR/$tdir
8085         sync
8086         etime=`date +%s`
8087         delta=$((etime - stime))
8088         log "rm -r $DIR/$tdir/: $delta seconds"
8089         log "rm done"
8090         lctl get_param -n llite.*.statahead_stats
8091 }
8092 run_test 123a "verify statahead work"
8093
8094 test_123b () { # statahead(bug 15027)
8095         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8096         test_mkdir -p $DIR/$tdir
8097         createmany -o $DIR/$tdir/$tfile-%d 1000
8098
8099         cancel_lru_locks mdc
8100         cancel_lru_locks osc
8101
8102 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8103         lctl set_param fail_loc=0x80000803
8104         ls -lR $DIR/$tdir > /dev/null
8105         log "ls done"
8106         lctl set_param fail_loc=0x0
8107         lctl get_param -n llite.*.statahead_stats
8108         rm -r $DIR/$tdir
8109         sync
8110
8111 }
8112 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8113
8114 test_124a() {
8115         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8116         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8117                 skip "no lru resize on server" && return 0
8118         local NR=2000
8119         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8120
8121         log "create $NR files at $DIR/$tdir"
8122         createmany -o $DIR/$tdir/f $NR ||
8123                 error "failed to create $NR files in $DIR/$tdir"
8124
8125         cancel_lru_locks mdc
8126         ls -l $DIR/$tdir > /dev/null
8127
8128         local NSDIR=""
8129         local LRU_SIZE=0
8130         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8131                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8132                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8133                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8134                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8135                         log "NSDIR=$NSDIR"
8136                         log "NS=$(basename $NSDIR)"
8137                         break
8138                 fi
8139         done
8140
8141         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8142                 skip "Not enough cached locks created!"
8143                 return 0
8144         fi
8145         log "LRU=$LRU_SIZE"
8146
8147         local SLEEP=30
8148
8149         # We know that lru resize allows one client to hold $LIMIT locks
8150         # for 10h. After that locks begin to be killed by client.
8151         local MAX_HRS=10
8152         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8153         log "LIMIT=$LIMIT"
8154
8155         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8156         # killing locks. Some time was spent for creating locks. This means
8157         # that up to the moment of sleep finish we must have killed some of
8158         # them (10-100 locks). This depends on how fast ther were created.
8159         # Many of them were touched in almost the same moment and thus will
8160         # be killed in groups.
8161         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8162
8163         # Use $LRU_SIZE_B here to take into account real number of locks
8164         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8165         local LRU_SIZE_B=$LRU_SIZE
8166         log "LVF=$LVF"
8167         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8168         log "OLD_LVF=$OLD_LVF"
8169         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8170
8171         # Let's make sure that we really have some margin. Client checks
8172         # cached locks every 10 sec.
8173         SLEEP=$((SLEEP+20))
8174         log "Sleep ${SLEEP} sec"
8175         local SEC=0
8176         while ((SEC<$SLEEP)); do
8177                 echo -n "..."
8178                 sleep 5
8179                 SEC=$((SEC+5))
8180                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8181                 echo -n "$LRU_SIZE"
8182         done
8183         echo ""
8184         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8185         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8186
8187         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8188                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8189                 unlinkmany $DIR/$tdir/f $NR
8190                 return
8191         }
8192
8193         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8194         log "unlink $NR files at $DIR/$tdir"
8195         unlinkmany $DIR/$tdir/f $NR
8196 }
8197 run_test 124a "lru resize ======================================="
8198
8199 get_max_pool_limit()
8200 {
8201         local limit=$($LCTL get_param \
8202                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8203         local max=0
8204         for l in $limit; do
8205                 if [[ $l -gt $max ]]; then
8206                         max=$l
8207                 fi
8208         done
8209         echo $max
8210 }
8211
8212 test_124b() {
8213         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8214         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8215                 skip "no lru resize on server" && return 0
8216
8217         LIMIT=$(get_max_pool_limit)
8218
8219         NR=$(($(default_lru_size)*20))
8220         if [[ $NR -gt $LIMIT ]]; then
8221                 log "Limit lock number by $LIMIT locks"
8222                 NR=$LIMIT
8223         fi
8224         lru_resize_disable mdc
8225         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8226                 error "failed to create $DIR/$tdir/disable_lru_resize"
8227
8228         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8229         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8230         cancel_lru_locks mdc
8231         stime=`date +%s`
8232         PID=""
8233         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8234         PID="$PID $!"
8235         sleep 2
8236         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8237         PID="$PID $!"
8238         sleep 2
8239         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8240         PID="$PID $!"
8241         wait $PID
8242         etime=`date +%s`
8243         nolruresize_delta=$((etime-stime))
8244         log "ls -la time: $nolruresize_delta seconds"
8245         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8246         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8247
8248         lru_resize_enable mdc
8249         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8250                 error "failed to create $DIR/$tdir/enable_lru_resize"
8251
8252         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8253         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8254         cancel_lru_locks mdc
8255         stime=`date +%s`
8256         PID=""
8257         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8258         PID="$PID $!"
8259         sleep 2
8260         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8261         PID="$PID $!"
8262         sleep 2
8263         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8264         PID="$PID $!"
8265         wait $PID
8266         etime=`date +%s`
8267         lruresize_delta=$((etime-stime))
8268         log "ls -la time: $lruresize_delta seconds"
8269         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8270
8271         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8272                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8273         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8274                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8275         else
8276                 log "lru resize performs the same with no lru resize"
8277         fi
8278         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8279 }
8280 run_test 124b "lru resize (performance test) ======================="
8281
8282 test_125() { # 13358
8283         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8284         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8285         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8286         test_mkdir -p $DIR/d125 || error "mkdir failed"
8287         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8288         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8289         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8290 }
8291 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8292
8293 test_126() { # bug 12829/13455
8294         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8295         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8296         $GSS && skip "must run as gss disabled" && return
8297
8298         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8299         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8300         rm -f $DIR/$tfile
8301         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8302 }
8303 run_test 126 "check that the fsgid provided by the client is taken into account"
8304
8305 test_127a() { # bug 15521
8306         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8307         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8308         $LCTL set_param osc.*.stats=0
8309         FSIZE=$((2048 * 1024))
8310         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8311         cancel_lru_locks osc
8312         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8313
8314         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8315         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8316                 echo "got $COUNT $NAME"
8317                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8318                 eval $NAME=$COUNT || error "Wrong proc format"
8319
8320                 case $NAME in
8321                         read_bytes|write_bytes)
8322                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8323                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8324                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8325                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8326                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8327                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8328                                 error "sumsquare is too small: $SUMSQ"
8329                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8330                                 error "sumsquare is too big: $SUMSQ"
8331                         ;;
8332                         *) ;;
8333                 esac
8334         done < $DIR/${tfile}.tmp
8335
8336         #check that we actually got some stats
8337         [ "$read_bytes" ] || error "Missing read_bytes stats"
8338         [ "$write_bytes" ] || error "Missing write_bytes stats"
8339         [ "$read_bytes" != 0 ] || error "no read done"
8340         [ "$write_bytes" != 0 ] || error "no write done"
8341 }
8342 run_test 127a "verify the client stats are sane"
8343
8344 test_127b() { # bug LU-333
8345         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8346         $LCTL set_param llite.*.stats=0
8347         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8348         # perform 2 reads and writes so MAX is different from SUM.
8349         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8350         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8351         cancel_lru_locks osc
8352         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8353         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8354
8355         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8356         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8357                 echo "got $COUNT $NAME"
8358                 eval $NAME=$COUNT || error "Wrong proc format"
8359
8360         case $NAME in
8361                 read_bytes)
8362                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8363                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8364                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8365                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8366                         ;;
8367                 write_bytes)
8368                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8369                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8370                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8371                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8372                         ;;
8373                         *) ;;
8374                 esac
8375         done < $TMP/${tfile}.tmp
8376
8377         #check that we actually got some stats
8378         [ "$read_bytes" ] || error "Missing read_bytes stats"
8379         [ "$write_bytes" ] || error "Missing write_bytes stats"
8380         [ "$read_bytes" != 0 ] || error "no read done"
8381         [ "$write_bytes" != 0 ] || error "no write done"
8382 }
8383 run_test 127b "verify the llite client stats are sane"
8384
8385 test_128() { # bug 15212
8386         touch $DIR/$tfile
8387         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8388                 find $DIR/$tfile
8389                 find $DIR/$tfile
8390         EOF
8391
8392         result=$(grep error $TMP/$tfile.log)
8393         rm -f $DIR/$tfile
8394         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8395 }
8396 run_test 128 "interactive lfs for 2 consecutive find's"
8397
8398 set_dir_limits () {
8399         local mntdev
8400         local canondev
8401         local node
8402
8403         local LDPROC=/proc/fs/ldiskfs
8404         local facets=$(get_facets MDS)
8405
8406         for facet in ${facets//,/ }; do
8407                 canondev=$(ldiskfs_canon \
8408                            *.$(convert_facet2label $facet).mntdev $facet)
8409                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8410                                                 LDPROC=/sys/fs/ldiskfs
8411                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8412         done
8413 }
8414
8415 test_129() {
8416         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8417         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8418                 skip "Only applicable to ldiskfs-based MDTs"
8419                 return
8420         fi
8421         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8422         ENOSPC=28
8423         EFBIG=27
8424
8425         rm -rf $DIR/$tdir
8426         test_mkdir -p $DIR/$tdir
8427
8428         # block size of mds1
8429         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8430         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8431         local MAX=$((MDSBLOCKSIZE * 3))
8432         set_dir_limits $MAX
8433         local I=$(stat -c%s "$DIR/$tdir")
8434         local J=0
8435         local STRIPE_COUNT=1
8436         [[ $MDSCOUNT -ge 2 ]] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8437         MAX=$((MAX*STRIPE_COUNT))
8438         while [[ $I -le $MAX ]]; do
8439                 $MULTIOP $DIR/$tdir/$J Oc
8440                 rc=$?
8441                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8442                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8443                 #and EFBIG for previous versions
8444                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8445                         set_dir_limits 0
8446                         echo "return code $rc received as expected"
8447                         multiop $DIR/$tdir/$J Oc ||
8448                                 error_exit "multiop failed w/o dir size limit"
8449
8450                         I=$(stat -c%s "$DIR/$tdir")
8451
8452                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8453                                         $(version_code 2.4.51) ]
8454                         then
8455                                 [[ $I -eq $MAX ]] && return 0
8456                         else
8457                                 [[ $I -gt $MAX ]] && return 0
8458                         fi
8459                         error_exit "current dir size $I, previous limit $MAX"
8460                 elif [ $rc -ne 0 ]; then
8461                         set_dir_limits 0
8462                         error_exit "return code $rc received instead of expected " \
8463                                    "$EFBIG or $ENOSPC, files in dir $I"
8464                 fi
8465                 J=$((J+1))
8466                 I=$(stat -c%s "$DIR/$tdir")
8467         done
8468
8469         set_dir_limits 0
8470         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8471 }
8472 run_test 129 "test directory size limit ========================"
8473
8474 OLDIFS="$IFS"
8475 cleanup_130() {
8476         trap 0
8477         IFS="$OLDIFS"
8478 }
8479
8480 test_130a() {
8481         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8482         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8483                 return
8484
8485         trap cleanup_130 EXIT RETURN
8486
8487         local fm_file=$DIR/$tfile
8488         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8489         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8490                 error "dd failed for $fm_file"
8491
8492         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8493         filefrag -ves $fm_file
8494         RC=$?
8495         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8496                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8497         [ $RC != 0 ] && error "filefrag $fm_file failed"
8498
8499         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8500                       grep -v "ext:" | grep -v "found")
8501         lun=$($GETSTRIPE -i $fm_file)
8502
8503         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8504         IFS=$'\n'
8505         tot_len=0
8506         for line in $filefrag_op
8507         do
8508                 frag_lun=`echo $line | cut -d: -f5`
8509                 ext_len=`echo $line | cut -d: -f4`
8510                 if (( $frag_lun != $lun )); then
8511                         cleanup_130
8512                         error "FIEMAP on 1-stripe file($fm_file) failed"
8513                         return
8514                 fi
8515                 (( tot_len += ext_len ))
8516         done
8517
8518         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8519                 cleanup_130
8520                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8521                 return
8522         fi
8523
8524         cleanup_130
8525
8526         echo "FIEMAP on single striped file succeeded"
8527 }
8528 run_test 130a "FIEMAP (1-stripe file)"
8529
8530 test_130b() {
8531         [ "$OSTCOUNT" -lt "2" ] &&
8532                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8533
8534         [ "$OSTCOUNT" -ge "10" ] &&
8535                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8536
8537         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8538         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8539                 return
8540
8541         trap cleanup_130 EXIT RETURN
8542
8543         local fm_file=$DIR/$tfile
8544         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8545         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8546                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8547
8548         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8549                 error "dd failed on $fm_file"
8550
8551         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8552         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8553                       grep -v "ext:" | grep -v "found")
8554
8555         last_lun=$(echo $filefrag_op | cut -d: -f5)
8556
8557         IFS=$'\n'
8558         tot_len=0
8559         num_luns=1
8560         for line in $filefrag_op
8561         do
8562                 frag_lun=`echo $line | cut -d: -f5`
8563                 ext_len=`echo $line | cut -d: -f4`
8564                 if (( $frag_lun != $last_lun )); then
8565                         if (( tot_len != 1024 )); then
8566                                 cleanup_130
8567                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8568                                 return
8569                         else
8570                                 (( num_luns += 1 ))
8571                                 tot_len=0
8572                         fi
8573                 fi
8574                 (( tot_len += ext_len ))
8575                 last_lun=$frag_lun
8576         done
8577         if (( num_luns != 2 || tot_len != 1024 )); then
8578                 cleanup_130
8579                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8580                 return
8581         fi
8582
8583         cleanup_130
8584
8585         echo "FIEMAP on 2-stripe file succeeded"
8586 }
8587 run_test 130b "FIEMAP (2-stripe file)"
8588
8589 test_130c() {
8590         [ "$OSTCOUNT" -lt "2" ] &&
8591                 skip_env "skipping FIEMAP on 2-stripe file" && return
8592
8593         [ "$OSTCOUNT" -ge "10" ] &&
8594                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8595
8596         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8597         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8598                 return
8599
8600         trap cleanup_130 EXIT RETURN
8601
8602         local fm_file=$DIR/$tfile
8603         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8604         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8605                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8606
8607         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8608
8609         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8610         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8611
8612         last_lun=`echo $filefrag_op | cut -d: -f5`
8613
8614         IFS=$'\n'
8615         tot_len=0
8616         num_luns=1
8617         for line in $filefrag_op
8618         do
8619                 frag_lun=`echo $line | cut -d: -f5`
8620                 ext_len=`echo $line | cut -d: -f4`
8621                 if (( $frag_lun != $last_lun )); then
8622                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8623                         if (( logical != 512 )); then
8624                                 cleanup_130
8625                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8626                                 return
8627                         fi
8628                         if (( tot_len != 512 )); then
8629                                 cleanup_130
8630                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8631                                 return
8632                         else
8633                                 (( num_luns += 1 ))
8634                                 tot_len=0
8635                         fi
8636                 fi
8637                 (( tot_len += ext_len ))
8638                 last_lun=$frag_lun
8639         done
8640         if (( num_luns != 2 || tot_len != 512 )); then
8641                 cleanup_130
8642                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8643                 return
8644         fi
8645
8646         cleanup_130
8647
8648         echo "FIEMAP on 2-stripe file with hole succeeded"
8649 }
8650 run_test 130c "FIEMAP (2-stripe file with hole)"
8651
8652 test_130d() {
8653         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8654
8655         [ "$OSTCOUNT" -ge "10" ] &&
8656                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8657
8658         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8659         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8660
8661         trap cleanup_130 EXIT RETURN
8662
8663         local fm_file=$DIR/$tfile
8664         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8665         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8666                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8667
8668         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8669         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8670                 error "dd failed on $fm_file"
8671
8672         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8673         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8674                 grep -v "ext:" | grep -v "found"`
8675
8676         last_lun=`echo $filefrag_op | cut -d: -f5`
8677
8678         IFS=$'\n'
8679         tot_len=0
8680         num_luns=1
8681         for line in $filefrag_op
8682         do
8683                 frag_lun=`echo $line | cut -d: -f5`
8684                 ext_len=`echo $line | cut -d: -f4`
8685                 if (( $frag_lun != $last_lun )); then
8686                         if (( tot_len != 1024 )); then
8687                                 cleanup_130
8688                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8689                                 return
8690                         else
8691                                 (( num_luns += 1 ))
8692                                 tot_len=0
8693                         fi
8694                 fi
8695                 (( tot_len += ext_len ))
8696                 last_lun=$frag_lun
8697         done
8698         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8699                 cleanup_130
8700                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8701                 return
8702         fi
8703
8704         cleanup_130
8705
8706         echo "FIEMAP on N-stripe file succeeded"
8707 }
8708 run_test 130d "FIEMAP (N-stripe file)"
8709
8710 test_130e() {
8711         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8712
8713         [ "$OSTCOUNT" -ge "10" ] &&
8714                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8715
8716         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8717         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8718
8719         trap cleanup_130 EXIT RETURN
8720
8721         local fm_file=$DIR/$tfile
8722         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8723         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8724                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8725
8726         NUM_BLKS=512
8727         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8728         for ((i = 0; i < $NUM_BLKS; i++))
8729         do
8730                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8731         done
8732
8733         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8734         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8735
8736         last_lun=`echo $filefrag_op | cut -d: -f5`
8737
8738         IFS=$'\n'
8739         tot_len=0
8740         num_luns=1
8741         for line in $filefrag_op
8742         do
8743                 frag_lun=`echo $line | cut -d: -f5`
8744                 ext_len=`echo $line | cut -d: -f4`
8745                 if (( $frag_lun != $last_lun )); then
8746                         if (( tot_len != $EXPECTED_LEN )); then
8747                                 cleanup_130
8748                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8749                                 return
8750                         else
8751                                 (( num_luns += 1 ))
8752                                 tot_len=0
8753                         fi
8754                 fi
8755                 (( tot_len += ext_len ))
8756                 last_lun=$frag_lun
8757         done
8758         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8759                 cleanup_130
8760                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8761                 return
8762         fi
8763
8764         cleanup_130
8765
8766         echo "FIEMAP with continuation calls succeeded"
8767 }
8768 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8769
8770 # Test for writev/readv
8771 test_131a() {
8772         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8773         error "writev test failed"
8774         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8775         error "readv failed"
8776         rm -f $DIR/$tfile
8777 }
8778 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8779
8780 test_131b() {
8781         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8782         error "append writev test failed"
8783         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8784         error "append writev test failed"
8785         rm -f $DIR/$tfile
8786 }
8787 run_test 131b "test append writev"
8788
8789 test_131c() {
8790         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8791         error "NOT PASS"
8792 }
8793 run_test 131c "test read/write on file w/o objects"
8794
8795 test_131d() {
8796         rwv -f $DIR/$tfile -w -n 1 1572864
8797         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8798         if [ "$NOB" != 1572864 ]; then
8799                 error "Short read filed: read $NOB bytes instead of 1572864"
8800         fi
8801         rm -f $DIR/$tfile
8802 }
8803 run_test 131d "test short read"
8804
8805 test_131e() {
8806         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8807         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8808         error "read hitting hole failed"
8809         rm -f $DIR/$tfile
8810 }
8811 run_test 131e "test read hitting hole"
8812
8813 get_ost_param() {
8814         local token=$1
8815         local gl_sum=0
8816         for node in $(osts_nodes); do
8817                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
8818                 [ x$gl = x"" ] && gl=0
8819                 gl_sum=$((gl_sum + gl))
8820         done
8821         echo $gl_sum
8822 }
8823
8824 som_mode_switch() {
8825         local som=$1
8826         local gl1=$2
8827         local gl2=$3
8828
8829         if [ x$som = x"enabled" ]; then
8830                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
8831                 MOUNT_OPTS=`echo $MOUNT_OPTS |
8832                     sed 's/som_preview,\|,som_preview\|som_preview//g'`
8833                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
8834         else
8835                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
8836                 MOUNT_OPTS="${MOUNT_OPTS:+$MOUNT_OPTS,}som_preview"
8837                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
8838         fi
8839
8840         # do remount to make new mount-conf parameters actual
8841         echo remounting...
8842         sync
8843         stopall
8844         setupall
8845 }
8846
8847 test_132() { #1028, SOM
8848         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8849         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8850         local num=$(get_mds_dir $DIR)
8851         local mymds=mds${num}
8852         local MOUNT_OPTS_SAVE=$MOUNT_OPTS
8853
8854         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8855         cancel_lru_locks osc
8856
8857         som1=$(do_facet $mymds "$LCTL get_param -n mdt.*.som" | head -n 1)
8858
8859         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8860         stat $DIR/$tfile >/dev/null
8861         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8862         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
8863         rm $DIR/$tfile
8864         som_mode_switch $som1 $gl1 $gl2
8865
8866         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8867         cancel_lru_locks osc
8868
8869         som2=$(do_facet $mymds "$LCTL get_param -n mdt.*.som" | head -n 1)
8870         if [ $som1 == $som2 ]; then
8871             error "som is still "$som2
8872             if [ x$som2 = x"enabled" ]; then
8873                 som2="disabled"
8874             else
8875                 som2="enabled"
8876             fi
8877         fi
8878
8879         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8880         stat $DIR/$tfile >/dev/null
8881         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8882         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
8883         som_mode_switch $som2 $gl1 $gl2
8884         MOUNT_OPTS=$MOUNT_OPTS_SAVE
8885 }
8886 run_test 132 "som avoids glimpse rpc"
8887
8888 check_stats() {
8889         local res
8890         local count
8891         case $1 in
8892         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8893                  ;;
8894         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8895                  ;;
8896         *) error "Wrong argument $1" ;;
8897         esac
8898         echo $res
8899         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8900         # if the argument $3 is zero, it means any stat increment is ok.
8901         if [[ $3 -gt 0 ]]; then
8902                 count=$(echo $res | awk '{ print $2 }')
8903                 [[ $count -ne $3 ]] &&
8904                         error "The $2 counter on $1 is wrong - expected $3"
8905         fi
8906 }
8907
8908 test_133a() {
8909         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8910         remote_ost_nodsh && skip "remote OST with nodsh" && return
8911         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8912
8913         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8914                 { skip "MDS doesn't support rename stats"; return; }
8915         local testdir=$DIR/${tdir}/stats_testdir
8916         mkdir -p $DIR/${tdir}
8917
8918         # clear stats.
8919         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8920         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8921
8922         # verify mdt stats first.
8923         mkdir ${testdir} || error "mkdir failed"
8924         check_stats $SINGLEMDS "mkdir" 1
8925         touch ${testdir}/${tfile} || "touch failed"
8926         check_stats $SINGLEMDS "open" 1
8927         check_stats $SINGLEMDS "close" 1
8928         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
8929         check_stats $SINGLEMDS "mknod" 1
8930         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
8931         check_stats $SINGLEMDS "unlink" 1
8932         rm -f ${testdir}/${tfile} || error "file remove failed"
8933         check_stats $SINGLEMDS "unlink" 2
8934
8935         # remove working dir and check mdt stats again.
8936         rmdir ${testdir} || error "rmdir failed"
8937         check_stats $SINGLEMDS "rmdir" 1
8938
8939         local testdir1=$DIR/${tdir}/stats_testdir1
8940         mkdir -p ${testdir}
8941         mkdir -p ${testdir1}
8942         touch ${testdir1}/test1
8943         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
8944         check_stats $SINGLEMDS "crossdir_rename" 1
8945
8946         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
8947         check_stats $SINGLEMDS "samedir_rename" 1
8948
8949         rm -rf $DIR/${tdir}
8950 }
8951 run_test 133a "Verifying MDT stats ========================================"
8952
8953 test_133b() {
8954         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8955         remote_ost_nodsh && skip "remote OST with nodsh" && return
8956         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8957         local testdir=$DIR/${tdir}/stats_testdir
8958         mkdir -p ${testdir} || error "mkdir failed"
8959         touch ${testdir}/${tfile} || "touch failed"
8960         cancel_lru_locks mdc
8961
8962         # clear stats.
8963         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8964         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8965
8966         # extra mdt stats verification.
8967         chmod 444 ${testdir}/${tfile} || error "chmod failed"
8968         check_stats $SINGLEMDS "setattr" 1
8969         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8970         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
8971         then            # LU-1740
8972                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
8973                 check_stats $SINGLEMDS "getattr" 1
8974         fi
8975         $LFS df || error "lfs failed"
8976         check_stats $SINGLEMDS "statfs" 1
8977
8978         rm -rf $DIR/${tdir}
8979 }
8980 run_test 133b "Verifying extra MDT stats =================================="
8981
8982 test_133c() {
8983         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8984         remote_ost_nodsh && skip "remote OST with nodsh" && return
8985         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8986         local testdir=$DIR/${tdir}/stats_testdir
8987         test_mkdir -p ${testdir} || error "mkdir failed"
8988
8989         # verify obdfilter stats.
8990         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8991         sync
8992         cancel_lru_locks osc
8993         wait_delete_completed
8994
8995         # clear stats.
8996         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8997         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8998
8999         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
9000         sync
9001         cancel_lru_locks osc
9002         check_stats ost "write" 1
9003
9004         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9005         check_stats ost "read" 1
9006
9007         > ${testdir}/${tfile} || error "truncate failed"
9008         check_stats ost "punch" 1
9009
9010         rm -f ${testdir}/${tfile} || error "file remove failed"
9011         wait_delete_completed
9012         check_stats ost "destroy" 1
9013
9014         rm -rf $DIR/${tdir}
9015 }
9016 run_test 133c "Verifying OST stats ========================================"
9017
9018 order_2() {
9019         local value=$1
9020         local orig=$value
9021         local order=1
9022
9023         while [ $value -ge 2 ]; do
9024                 order=$((order*2))
9025                 value=$((value/2))
9026         done
9027
9028         if [ $orig -gt $order ]; then
9029                 order=$((order*2))
9030         fi
9031         echo $order
9032 }
9033
9034 size_in_KMGT() {
9035     local value=$1
9036     local size=('K' 'M' 'G' 'T');
9037     local i=0
9038     local size_string=$value
9039
9040     while [ $value -ge 1024 ]; do
9041         if [ $i -gt 3 ]; then
9042             #T is the biggest unit we get here, if that is bigger,
9043             #just return XXXT
9044             size_string=${value}T
9045             break
9046         fi
9047         value=$((value >> 10))
9048         if [ $value -lt 1024 ]; then
9049             size_string=${value}${size[$i]}
9050             break
9051         fi
9052         i=$((i + 1))
9053     done
9054
9055     echo $size_string
9056 }
9057
9058 get_rename_size() {
9059     local size=$1
9060     local context=${2:-.}
9061     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9062                 grep -A1 $context |
9063                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9064     echo $sample
9065 }
9066
9067 test_133d() {
9068         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9069         remote_ost_nodsh && skip "remote OST with nodsh" && return
9070         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9071         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9072         { skip "MDS doesn't support rename stats"; return; }
9073
9074         local testdir1=$DIR/${tdir}/stats_testdir1
9075         local testdir2=$DIR/${tdir}/stats_testdir2
9076
9077         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9078
9079         mkdir -p ${testdir1} || error "mkdir failed"
9080         mkdir -p ${testdir2} || error "mkdir failed"
9081
9082         createmany -o $testdir1/test 512 || error "createmany failed"
9083
9084         # check samedir rename size
9085         mv ${testdir1}/test0 ${testdir1}/test_0
9086
9087         local testdir1_size=$(ls -l $DIR/${tdir} |
9088                 awk '/stats_testdir1/ {print $5}')
9089         local testdir2_size=$(ls -l $DIR/${tdir} |
9090                 awk '/stats_testdir2/ {print $5}')
9091
9092         testdir1_size=$(order_2 $testdir1_size)
9093         testdir2_size=$(order_2 $testdir2_size)
9094
9095         testdir1_size=$(size_in_KMGT $testdir1_size)
9096         testdir2_size=$(size_in_KMGT $testdir2_size)
9097
9098         echo "source rename dir size: ${testdir1_size}"
9099         echo "target rename dir size: ${testdir2_size}"
9100
9101         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9102         eval $cmd || error "$cmd failed"
9103         local samedir=$($cmd | grep 'same_dir')
9104         local same_sample=$(get_rename_size $testdir1_size)
9105         [ -z "$samedir" ] && error "samedir_rename_size count error"
9106         [[ $same_sample -eq 1 ]] ||
9107                 error "samedir_rename_size error $same_sample"
9108         echo "Check same dir rename stats success"
9109
9110         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9111
9112         # check crossdir rename size
9113         mv ${testdir1}/test_0 ${testdir2}/test_0
9114
9115         testdir1_size=$(ls -l $DIR/${tdir} |
9116                 awk '/stats_testdir1/ {print $5}')
9117         testdir2_size=$(ls -l $DIR/${tdir} |
9118                 awk '/stats_testdir2/ {print $5}')
9119
9120         testdir1_size=$(order_2 $testdir1_size)
9121         testdir2_size=$(order_2 $testdir2_size)
9122
9123         testdir1_size=$(size_in_KMGT $testdir1_size)
9124         testdir2_size=$(size_in_KMGT $testdir2_size)
9125
9126         echo "source rename dir size: ${testdir1_size}"
9127         echo "target rename dir size: ${testdir2_size}"
9128
9129         eval $cmd || error "$cmd failed"
9130         local crossdir=$($cmd | grep 'crossdir')
9131         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9132         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9133         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9134         [[ $src_sample -eq 1 ]] ||
9135                 error "crossdir_rename_size error $src_sample"
9136         [[ $tgt_sample -eq 1 ]] ||
9137                 error "crossdir_rename_size error $tgt_sample"
9138         echo "Check cross dir rename stats success"
9139         rm -rf $DIR/${tdir}
9140 }
9141 run_test 133d "Verifying rename_stats ========================================"
9142
9143 test_133e() {
9144         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9145         remote_ost_nodsh && skip "remote OST with nodsh" && return
9146         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9147         local testdir=$DIR/${tdir}/stats_testdir
9148         local ctr f0 f1 bs=32768 count=42 sum
9149
9150         mkdir -p ${testdir} || error "mkdir failed"
9151
9152         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9153
9154         for ctr in {write,read}_bytes; do
9155                 sync
9156                 cancel_lru_locks osc
9157
9158                 do_facet ost1 $LCTL set_param -n \
9159                         "obdfilter.*.exports.clear=clear"
9160
9161                 if [ $ctr = write_bytes ]; then
9162                         f0=/dev/zero
9163                         f1=${testdir}/${tfile}
9164                 else
9165                         f0=${testdir}/${tfile}
9166                         f1=/dev/null
9167                 fi
9168
9169                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9170                         error "dd failed"
9171                 sync
9172                 cancel_lru_locks osc
9173
9174                 sum=$(do_facet ost1 $LCTL get_param \
9175                         "obdfilter.*.exports.*.stats" |
9176                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9177                                 $1 == ctr { sum += $7 }
9178                                 END { printf("%0.0f", sum) }')
9179
9180                 if ((sum != bs * count)); then
9181                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9182                 fi
9183         done
9184
9185         rm -rf $DIR/${tdir}
9186 }
9187 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9188
9189 test_133f() {
9190         local proc_dirs
9191
9192         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9193 /sys/fs/lustre/ /sys/fs/lnet/"
9194         local dir
9195         for dir in $dirs; do
9196                 if [ -d $dir ]; then
9197                         proc_dirs="$proc_dirs $dir"
9198                 fi
9199         done
9200
9201         local facet
9202
9203         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9204         remote_ost_nodsh && skip "remote OST with nodsh" && return
9205         # First without trusting modes.
9206         find $proc_dirs -exec cat '{}' \; &> /dev/null
9207
9208         # Second verifying readability.
9209         find $proc_dirs \
9210                 -type f \
9211                 -exec cat '{}' \; &> /dev/null ||
9212                         error "proc file read failed"
9213
9214         for facet in $SINGLEMDS ost1; do
9215                 do_facet $facet find $proc_dirs \
9216                         ! -name req_history \
9217                         -exec cat '{}' \\\; &> /dev/null
9218
9219                 do_facet $facet find $proc_dirs \
9220                         ! -name req_history \
9221                         -type f \
9222                         -exec cat '{}' \\\; &> /dev/null ||
9223                                 error "proc file read failed"
9224         done
9225 }
9226 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9227
9228 test_133g() {
9229         local proc_dirs
9230
9231         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9232 /sys/fs/lustre/ /sys/fs/lnet/"
9233         local dir
9234         for dir in $dirs; do
9235                 if [ -d $dir ]; then
9236                         proc_dirs="$proc_dirs $dir"
9237                 fi
9238         done
9239
9240         local facet
9241
9242         # Second verifying readability.
9243         find $proc_dirs \
9244                 -type f \
9245                 -not -name force_lbug \
9246                 -not -name changelog_mask \
9247                 -exec badarea_io '{}' \; &> /dev/null ||
9248                 error "find $proc_dirs failed"
9249
9250         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
9251                 skip "Too old lustre on MDS"
9252
9253         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
9254                 skip "Too old lustre on ost1"
9255
9256         for facet in $SINGLEMDS ost1; do
9257                 do_facet $facet find $proc_dirs \
9258                         -type f \
9259                         -not -name force_lbug \
9260                         -not -name changelog_mask \
9261                         -exec badarea_io '{}' \\\; &> /dev/null ||
9262                 error "$facet find $proc_dirs failed"
9263
9264         done
9265
9266         # remount the FS in case writes/reads /proc break the FS
9267         cleanup || error "failed to unmount"
9268         setup || error "failed to setup"
9269         true
9270 }
9271 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9272
9273 test_140() { #bug-17379
9274         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9275         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
9276         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
9277         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
9278
9279         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9280         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9281         local i=0
9282         while i=`expr $i + 1`; do
9283                 test_mkdir -p $i || error "Creating dir $i"
9284                 cd $i || error "Changing to $i"
9285                 ln -s ../stat stat || error "Creating stat symlink"
9286                 # Read the symlink until ELOOP present,
9287                 # not LBUGing the system is considered success,
9288                 # we didn't overrun the stack.
9289                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9290                 [ $ret -ne 0 ] && {
9291                         if [ $ret -eq 40 ]; then
9292                                 break  # -ELOOP
9293                         else
9294                                 error "Open stat symlink"
9295                                 return
9296                         fi
9297                 }
9298         done
9299         i=`expr $i - 1`
9300         echo "The symlink depth = $i"
9301         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9302                                         error "Invalid symlink depth"
9303
9304         # Test recursive symlink
9305         ln -s symlink_self symlink_self
9306         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9307         echo "open symlink_self returns $ret"
9308         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9309 }
9310 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9311
9312 test_150() {
9313         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9314         local TF="$TMP/$tfile"
9315
9316         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9317         cp $TF $DIR/$tfile
9318         cancel_lru_locks osc
9319         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9320         remount_client $MOUNT
9321         df -P $MOUNT
9322         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9323
9324         $TRUNCATE $TF 6000
9325         $TRUNCATE $DIR/$tfile 6000
9326         cancel_lru_locks osc
9327         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9328
9329         echo "12345" >>$TF
9330         echo "12345" >>$DIR/$tfile
9331         cancel_lru_locks osc
9332         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9333
9334         echo "12345" >>$TF
9335         echo "12345" >>$DIR/$tfile
9336         cancel_lru_locks osc
9337         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9338
9339         rm -f $TF
9340         true
9341 }
9342 run_test 150 "truncate/append tests"
9343
9344 #LU-2902 roc_hit was not able to read all values from lproc
9345 function roc_hit_init() {
9346         local list=$(comma_list $(osts_nodes))
9347         local dir=$DIR/$tdir-check
9348         local file=$dir/file
9349         local BEFORE
9350         local AFTER
9351         local idx
9352
9353         test_mkdir -p $dir
9354         #use setstripe to do a write to every ost
9355         for i in $(seq 0 $((OSTCOUNT-1))); do
9356                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9357                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9358                 idx=$(printf %04x $i)
9359                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9360                         awk '$1 == "cache_access" {sum += $7}
9361                                 END { printf("%0.0f", sum) }')
9362
9363                 cancel_lru_locks osc
9364                 cat $file >/dev/null
9365
9366                 AFTER=$(get_osd_param $list *OST*$idx stats |
9367                         awk '$1 == "cache_access" {sum += $7}
9368                                 END { printf("%0.0f", sum) }')
9369
9370                 echo BEFORE:$BEFORE AFTER:$AFTER
9371                 if ! let "AFTER - BEFORE == 4"; then
9372                         rm -rf $dir
9373                         error "roc_hit is not safe to use"
9374                 fi
9375                 rm $file
9376         done
9377
9378         rm -rf $dir
9379 }
9380
9381 function roc_hit() {
9382         local list=$(comma_list $(osts_nodes))
9383         echo $(get_osd_param $list '' stats |
9384                 awk '$1 == "cache_hit" {sum += $7}
9385                         END { printf("%0.0f", sum) }')
9386 }
9387
9388 function set_cache() {
9389         local on=1
9390
9391         if [ "$2" == "off" ]; then
9392                 on=0;
9393         fi
9394         local list=$(comma_list $(osts_nodes))
9395         set_osd_param $list '' $1_cache_enable $on
9396
9397         cancel_lru_locks osc
9398 }
9399
9400 test_151() {
9401         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9402         remote_ost_nodsh && skip "remote OST with nodsh" && return
9403
9404         local CPAGES=3
9405         local list=$(comma_list $(osts_nodes))
9406
9407         # check whether obdfilter is cache capable at all
9408         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9409                 echo "not cache-capable obdfilter"
9410                 return 0
9411         fi
9412
9413         # check cache is enabled on all obdfilters
9414         if get_osd_param $list '' read_cache_enable | grep 0; then
9415                 echo "oss cache is disabled"
9416                 return 0
9417         fi
9418
9419         set_osd_param $list '' writethrough_cache_enable 1
9420
9421         # check write cache is enabled on all obdfilters
9422         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9423                 echo "oss write cache is NOT enabled"
9424                 return 0
9425         fi
9426
9427         roc_hit_init
9428
9429         #define OBD_FAIL_OBD_NO_LRU  0x609
9430         do_nodes $list $LCTL set_param fail_loc=0x609
9431
9432         # pages should be in the case right after write
9433         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9434                 error "dd failed"
9435
9436         local BEFORE=$(roc_hit)
9437         cancel_lru_locks osc
9438         cat $DIR/$tfile >/dev/null
9439         local AFTER=$(roc_hit)
9440
9441         do_nodes $list $LCTL set_param fail_loc=0
9442
9443         if ! let "AFTER - BEFORE == CPAGES"; then
9444                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9445         fi
9446
9447         # the following read invalidates the cache
9448         cancel_lru_locks osc
9449         set_osd_param $list '' read_cache_enable 0
9450         cat $DIR/$tfile >/dev/null
9451
9452         # now data shouldn't be found in the cache
9453         BEFORE=$(roc_hit)
9454         cancel_lru_locks osc
9455         cat $DIR/$tfile >/dev/null
9456         AFTER=$(roc_hit)
9457         if let "AFTER - BEFORE != 0"; then
9458                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9459         fi
9460
9461         set_osd_param $list '' read_cache_enable 1
9462         rm -f $DIR/$tfile
9463 }
9464 run_test 151 "test cache on oss and controls ==============================="
9465
9466 test_152() {
9467         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9468         local TF="$TMP/$tfile"
9469
9470         # simulate ENOMEM during write
9471 #define OBD_FAIL_OST_NOMEM      0x226
9472         lctl set_param fail_loc=0x80000226
9473         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9474         cp $TF $DIR/$tfile
9475         sync || error "sync failed"
9476         lctl set_param fail_loc=0
9477
9478         # discard client's cache
9479         cancel_lru_locks osc
9480
9481         # simulate ENOMEM during read
9482         lctl set_param fail_loc=0x80000226
9483         cmp $TF $DIR/$tfile || error "cmp failed"
9484         lctl set_param fail_loc=0
9485
9486         rm -f $TF
9487 }
9488 run_test 152 "test read/write with enomem ============================"
9489
9490 test_153() {
9491         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9492 }
9493 run_test 153 "test if fdatasync does not crash ======================="
9494
9495 dot_lustre_fid_permission_check() {
9496         local fid=$1
9497         local ffid=$MOUNT/.lustre/fid/$fid
9498         local test_dir=$2
9499
9500         echo "stat fid $fid"
9501         stat $ffid > /dev/null || error "stat $ffid failed."
9502         echo "touch fid $fid"
9503         touch $ffid || error "touch $ffid failed."
9504         echo "write to fid $fid"
9505         cat /etc/hosts > $ffid || error "write $ffid failed."
9506         echo "read fid $fid"
9507         diff /etc/hosts $ffid || error "read $ffid failed."
9508         echo "append write to fid $fid"
9509         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9510         echo "rename fid $fid"
9511         mv $ffid $test_dir/$tfile.1 &&
9512                 error "rename $ffid to $tfile.1 should fail."
9513         touch $test_dir/$tfile.1
9514         mv $test_dir/$tfile.1 $ffid &&
9515                 error "rename $tfile.1 to $ffid should fail."
9516         rm -f $test_dir/$tfile.1
9517         echo "truncate fid $fid"
9518         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9519         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9520                 echo "link fid $fid"
9521                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9522         fi
9523         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9524                 echo "setfacl fid $fid"
9525                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9526                 echo "getfacl fid $fid"
9527                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9528         fi
9529         echo "unlink fid $fid"
9530         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9531         echo "mknod fid $fid"
9532         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9533
9534         fid=[0xf00000400:0x1:0x0]
9535         ffid=$MOUNT/.lustre/fid/$fid
9536
9537         echo "stat non-exist fid $fid"
9538         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9539         echo "write to non-exist fid $fid"
9540         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9541         echo "link new fid $fid"
9542         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9543
9544         mkdir -p $test_dir/$tdir
9545         touch $test_dir/$tdir/$tfile
9546         fid=$($LFS path2fid $test_dir/$tdir)
9547         rc=$?
9548         [ $rc -ne 0 ] &&
9549                 error "error: could not get fid for $test_dir/$dir/$tfile."
9550
9551         ffid=$MOUNT/.lustre/fid/$fid
9552
9553         echo "ls $fid"
9554         ls $ffid > /dev/null || error "ls $ffid failed."
9555         echo "touch $fid/$tfile.1"
9556         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9557
9558         echo "touch $MOUNT/.lustre/fid/$tfile"
9559         touch $MOUNT/.lustre/fid/$tfile && \
9560                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9561
9562         echo "setxattr to $MOUNT/.lustre/fid"
9563         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9564
9565         echo "listxattr for $MOUNT/.lustre/fid"
9566         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9567
9568         echo "delxattr from $MOUNT/.lustre/fid"
9569         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9570
9571         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9572         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9573                 error "touch invalid fid should fail."
9574
9575         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9576         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9577                 error "touch non-normal fid should fail."
9578
9579         echo "rename $tdir to $MOUNT/.lustre/fid"
9580         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9581                 error "rename to $MOUNT/.lustre/fid should fail."
9582
9583         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9584         then            # LU-3547
9585                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9586                 local new_obf_mode=777
9587
9588                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9589                 chmod $new_obf_mode $DIR/.lustre/fid ||
9590                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9591
9592                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9593                 [ $obf_mode -eq $new_obf_mode ] ||
9594                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9595
9596                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9597                 chmod $old_obf_mode $DIR/.lustre/fid ||
9598                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9599         fi
9600
9601         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9602         fid=$($LFS path2fid $test_dir/$tfile-2)
9603
9604         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
9605         then # LU-5424
9606                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9607                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
9608                         error "create lov data thru .lustre failed"
9609         fi
9610         echo "cp /etc/passwd $test_dir/$tfile-2"
9611         cp /etc/passwd $test_dir/$tfile-2 ||
9612                 error "copy to $test_dir/$tfile-2 failed."
9613         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9614         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9615                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9616
9617         rm -rf $test_dir/tfile.lnk
9618         rm -rf $test_dir/$tfile-2
9619 }
9620
9621 test_154A() {
9622         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9623                 skip "Need MDS version at least 2.4.1" && return
9624
9625         touch $DIR/$tfile
9626         local FID=$($LFS path2fid $DIR/$tfile)
9627         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9628
9629         # check that we get the same pathname back
9630         local FOUND=$($LFS fid2path $MOUNT $FID)
9631         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9632         [ "$FOUND" != "$DIR/$tfile" ] &&
9633                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9634
9635         rm -rf $DIR/$tfile
9636 }
9637 run_test 154A "lfs path2fid and fid2path basic checks"
9638
9639 test_154a() {
9640         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9641         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9642                 { skip "Need MDS version at least 2.2.51"; return 0; }
9643         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9644
9645         cp /etc/hosts $DIR/$tfile
9646
9647         fid=$($LFS path2fid $DIR/$tfile)
9648         rc=$?
9649         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9650
9651         dot_lustre_fid_permission_check "$fid" $DIR ||
9652                 error "dot lustre permission check $fid failed"
9653
9654         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9655
9656         touch $MOUNT/.lustre/file &&
9657                 error "creation is not allowed under .lustre"
9658
9659         mkdir $MOUNT/.lustre/dir &&
9660                 error "mkdir is not allowed under .lustre"
9661
9662         rm -rf $DIR/$tfile
9663 }
9664 run_test 154a "Open-by-FID"
9665
9666 test_154b() {
9667         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9668         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9669                 { skip "Need MDS version at least 2.2.51"; return 0; }
9670
9671         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9672
9673         local remote_dir=$DIR/$tdir/remote_dir
9674         local MDTIDX=1
9675         local rc=0
9676
9677         mkdir -p $DIR/$tdir
9678         $LFS mkdir -i $MDTIDX $remote_dir ||
9679                 error "create remote directory failed"
9680
9681         cp /etc/hosts $remote_dir/$tfile
9682
9683         fid=$($LFS path2fid $remote_dir/$tfile)
9684         rc=$?
9685         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9686
9687         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9688                 error "dot lustre permission check $fid failed"
9689         rm -rf $DIR/$tdir
9690 }
9691 run_test 154b "Open-by-FID for remote directory"
9692
9693 test_154c() {
9694         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9695                 skip "Need MDS version at least 2.4.1" && return
9696
9697         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9698         local FID1=$($LFS path2fid $DIR/$tfile.1)
9699         local FID2=$($LFS path2fid $DIR/$tfile.2)
9700         local FID3=$($LFS path2fid $DIR/$tfile.3)
9701
9702         local N=1
9703         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9704                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9705                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9706                 local want=FID$N
9707                 [ "$FID" = "${!want}" ] ||
9708                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9709                 N=$((N + 1))
9710         done
9711
9712         $LFS fid2path $MOUNT $FID1 $FID2 $FID3 | while read PATHNAME; do
9713                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
9714                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
9715                 N=$((N + 1))
9716         done
9717 }
9718 run_test 154c "lfs path2fid and fid2path multiple arguments"
9719
9720 test_154d() {
9721         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
9722                 skip "Need MDS version at least 2.5.53" && return
9723
9724         if remote_mds; then
9725                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
9726         else
9727                 nid="0@lo"
9728         fi
9729         local proc_ofile="mdt.*.exports.'$nid'.open_files"
9730         local fd
9731         local cmd
9732
9733         rm -f $DIR/$tfile
9734         touch $DIR/$tfile
9735
9736         fid=$($LFS path2fid $DIR/$tfile)
9737         # Open the file
9738         fd=$(free_fd)
9739         cmd="exec $fd<$DIR/$tfile"
9740         eval $cmd
9741         fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
9742         echo $fid_list | grep $fid
9743         rc=$?
9744
9745         cmd="exec $fd>/dev/null"
9746         eval $cmd
9747         if [ $rc -ne 0 ]; then
9748                 error "FID $fid not found in open files list $fid_list"
9749         fi
9750 }
9751 run_test 154d "Verify open file fid"
9752
9753 test_154e()
9754 {
9755         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
9756                 skip "Need MDS version at least 2.6.50" && return
9757
9758         if ls -a $MOUNT | grep -q '^\.lustre$'; then
9759                 error ".lustre returned by readdir"
9760         fi
9761 }
9762 run_test 154e ".lustre is not returned by readdir"
9763
9764 test_155_small_load() {
9765     local temp=$TMP/$tfile
9766     local file=$DIR/$tfile
9767
9768     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
9769         error "dd of=$temp bs=6096 count=1 failed"
9770     cp $temp $file
9771     cancel_lru_locks osc
9772     cmp $temp $file || error "$temp $file differ"
9773
9774     $TRUNCATE $temp 6000
9775     $TRUNCATE $file 6000
9776     cmp $temp $file || error "$temp $file differ (truncate1)"
9777
9778     echo "12345" >>$temp
9779     echo "12345" >>$file
9780     cmp $temp $file || error "$temp $file differ (append1)"
9781
9782     echo "12345" >>$temp
9783     echo "12345" >>$file
9784     cmp $temp $file || error "$temp $file differ (append2)"
9785
9786     rm -f $temp $file
9787     true
9788 }
9789
9790 test_155_big_load() {
9791     remote_ost_nodsh && skip "remote OST with nodsh" && return
9792     local temp=$TMP/$tfile
9793     local file=$DIR/$tfile
9794
9795     free_min_max
9796     local cache_size=$(do_facet ost$((MAXI+1)) \
9797         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
9798     local large_file_size=$((cache_size * 2))
9799
9800     echo "OSS cache size: $cache_size KB"
9801     echo "Large file size: $large_file_size KB"
9802
9803     [ $MAXV -le $large_file_size ] && \
9804         skip_env "max available OST size needs > $large_file_size KB" && \
9805         return 0
9806
9807     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
9808
9809     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
9810         error "dd of=$temp bs=$large_file_size count=1k failed"
9811     cp $temp $file
9812     ls -lh $temp $file
9813     cancel_lru_locks osc
9814     cmp $temp $file || error "$temp $file differ"
9815
9816     rm -f $temp $file
9817     true
9818 }
9819
9820 test_155a() {
9821         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9822         set_cache read on
9823         set_cache writethrough on
9824         test_155_small_load
9825 }
9826 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
9827
9828 test_155b() {
9829         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9830         set_cache read on
9831         set_cache writethrough off
9832         test_155_small_load
9833 }
9834 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
9835
9836 test_155c() {
9837         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9838         set_cache read off
9839         set_cache writethrough on
9840         test_155_small_load
9841 }
9842 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
9843
9844 test_155d() {
9845         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9846         set_cache read off
9847         set_cache writethrough off
9848         test_155_small_load
9849 }
9850 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
9851
9852 test_155e() {
9853         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9854         set_cache read on
9855         set_cache writethrough on
9856         test_155_big_load
9857 }
9858 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
9859
9860 test_155f() {
9861         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9862         set_cache read on
9863         set_cache writethrough off
9864         test_155_big_load
9865 }
9866 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
9867
9868 test_155g() {
9869         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9870         set_cache read off
9871         set_cache writethrough on
9872         test_155_big_load
9873 }
9874 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
9875
9876 test_155h() {
9877         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9878         set_cache read off
9879         set_cache writethrough off
9880         test_155_big_load
9881 }
9882 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
9883
9884 test_156() {
9885         remote_ost_nodsh && skip "remote OST with nodsh" && return
9886         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9887         local CPAGES=3
9888         local BEFORE
9889         local AFTER
9890         local file="$DIR/$tfile"
9891
9892         [ "$(facet_fstype ost1)" = "zfs" ] &&
9893                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
9894                 return
9895
9896         roc_hit_init
9897
9898     log "Turn on read and write cache"
9899     set_cache read on
9900     set_cache writethrough on
9901
9902     log "Write data and read it back."
9903     log "Read should be satisfied from the cache."
9904     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9905     BEFORE=`roc_hit`
9906     cancel_lru_locks osc
9907     cat $file >/dev/null
9908     AFTER=`roc_hit`
9909     if ! let "AFTER - BEFORE == CPAGES"; then
9910         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9911     else
9912         log "cache hits:: before: $BEFORE, after: $AFTER"
9913     fi
9914
9915     log "Read again; it should be satisfied from the cache."
9916     BEFORE=$AFTER
9917     cancel_lru_locks osc
9918     cat $file >/dev/null
9919     AFTER=`roc_hit`
9920     if ! let "AFTER - BEFORE == CPAGES"; then
9921         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9922     else
9923         log "cache hits:: before: $BEFORE, after: $AFTER"
9924     fi
9925
9926
9927     log "Turn off the read cache and turn on the write cache"
9928     set_cache read off
9929     set_cache writethrough on
9930
9931     log "Read again; it should be satisfied from the cache."
9932     BEFORE=`roc_hit`
9933     cancel_lru_locks osc
9934     cat $file >/dev/null
9935     AFTER=`roc_hit`
9936     if ! let "AFTER - BEFORE == CPAGES"; then
9937         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9938     else
9939         log "cache hits:: before: $BEFORE, after: $AFTER"
9940     fi
9941
9942     log "Read again; it should not be satisfied from the cache."
9943     BEFORE=$AFTER
9944     cancel_lru_locks osc
9945     cat $file >/dev/null
9946     AFTER=`roc_hit`
9947     if ! let "AFTER - BEFORE == 0"; then
9948         error "IN CACHE: before: $BEFORE, after: $AFTER"
9949     else
9950         log "cache hits:: before: $BEFORE, after: $AFTER"
9951     fi
9952
9953     log "Write data and read it back."
9954     log "Read should be satisfied from the cache."
9955     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9956     BEFORE=`roc_hit`
9957     cancel_lru_locks osc
9958     cat $file >/dev/null
9959     AFTER=`roc_hit`
9960     if ! let "AFTER - BEFORE == CPAGES"; then
9961         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9962     else
9963         log "cache hits:: before: $BEFORE, after: $AFTER"
9964     fi
9965
9966     log "Read again; it should not be satisfied from the cache."
9967     BEFORE=$AFTER
9968     cancel_lru_locks osc
9969     cat $file >/dev/null
9970     AFTER=`roc_hit`
9971     if ! let "AFTER - BEFORE == 0"; then
9972         error "IN CACHE: before: $BEFORE, after: $AFTER"
9973     else
9974         log "cache hits:: before: $BEFORE, after: $AFTER"
9975     fi
9976
9977
9978     log "Turn off read and write cache"
9979     set_cache read off
9980     set_cache writethrough off
9981
9982     log "Write data and read it back"
9983     log "It should not be satisfied from the cache."
9984     rm -f $file
9985     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9986     cancel_lru_locks osc
9987     BEFORE=`roc_hit`
9988     cat $file >/dev/null
9989     AFTER=`roc_hit`
9990         if ! let "AFTER - BEFORE == 0"; then
9991                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9992         else
9993                 log "cache hits:: before: $BEFORE, after: $AFTER"
9994         fi
9995
9996     log "Turn on the read cache and turn off the write cache"
9997     set_cache read on
9998     set_cache writethrough off
9999
10000     log "Write data and read it back"
10001     log "It should not be satisfied from the cache."
10002     rm -f $file
10003     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10004     BEFORE=`roc_hit`
10005     cancel_lru_locks osc
10006     cat $file >/dev/null
10007     AFTER=`roc_hit`
10008         if ! let "AFTER - BEFORE == 0"; then
10009                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10010         else
10011                 log "cache hits:: before: $BEFORE, after: $AFTER"
10012         fi
10013
10014     log "Read again; it should be satisfied from the cache."
10015     BEFORE=`roc_hit`
10016     cancel_lru_locks osc
10017     cat $file >/dev/null
10018     AFTER=`roc_hit`
10019     if ! let "AFTER - BEFORE == CPAGES"; then
10020         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10021     else
10022         log "cache hits:: before: $BEFORE, after: $AFTER"
10023     fi
10024
10025     rm -f $file
10026 }
10027 run_test 156 "Verification of tunables ============================"
10028
10029 #Changelogs
10030 err17935 () {
10031         if [[ $MDSCOUNT -gt 1 ]]; then
10032                 error_ignore bz17935 $*
10033         else
10034                 error $*
10035         fi
10036 }
10037
10038 changelog_chmask()
10039 {
10040         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10041
10042         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
10043
10044         if [ $MASK -eq 1 ]; then
10045                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
10046         else
10047                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
10048         fi
10049 }
10050
10051 changelog_extract_field() {
10052         local mdt=$1
10053         local cltype=$2
10054         local file=$3
10055         local identifier=$4
10056
10057         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
10058                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10059                 tail -1
10060 }
10061
10062 test_160a() {
10063         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10064         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10065         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10066                 { skip "Need MDS version at least 2.2.0"; return; }
10067
10068         local CL_USERS="mdd.$MDT0.changelog_users"
10069         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10070         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10071         echo "Registered as changelog user $USER"
10072         $GET_CL_USERS | grep -q $USER ||
10073                 error "User $USER not found in changelog_users"
10074
10075         # change something
10076         test_mkdir -p $DIR/$tdir/pics/2008/zachy
10077         touch $DIR/$tdir/pics/2008/zachy/timestamp
10078         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
10079         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
10080         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
10081         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
10082         rm $DIR/$tdir/pics/desktop.jpg
10083
10084         $LFS changelog $MDT0 | tail -5
10085
10086         echo "verifying changelog mask"
10087         changelog_chmask "MKDIR"
10088         changelog_chmask "CLOSE"
10089
10090         test_mkdir -p $DIR/$tdir/pics/zach/sofia
10091         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10092
10093         changelog_chmask "MKDIR"
10094         changelog_chmask "CLOSE"
10095
10096         test_mkdir -p $DIR/$tdir/pics/2008/sofia
10097         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10098
10099         $LFS changelog $MDT0
10100         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
10101         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
10102         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
10103         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
10104
10105         # verify contents
10106         echo "verifying target fid"
10107         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
10108         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
10109         [ "$fidc" == "$fidf" ] ||
10110                 err17935 "fid in changelog $fidc != file fid $fidf"
10111         echo "verifying parent fid"
10112         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
10113         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
10114         [ "$fidc" == "$fidf" ] ||
10115                 err17935 "pfid in changelog $fidc != dir fid $fidf"
10116
10117         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10118         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
10119         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10120         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
10121         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
10122                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
10123
10124         MIN_REC=$($GET_CL_USERS |
10125                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
10126         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
10127         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
10128         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
10129                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
10130
10131         # LU-3446 changelog index reset on MDT restart
10132         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10133         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10134         $LFS changelog_clear $MDT0 $USER 0
10135         stop $SINGLEMDS || error "Fail to stop MDT."
10136         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10137         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10138         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
10139         [ $CUR_REC1 == $CUR_REC2 ] ||
10140                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
10141
10142         echo "verifying user deregister"
10143         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10144         $GET_CL_USERS | grep -q $USER &&
10145                 error "User $USER still in changelog_users"
10146
10147         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
10148         if [ $USERS -eq 0 ]; then
10149                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10150                 touch $DIR/$tdir/chloe
10151                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10152                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
10153                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
10154         else
10155                 echo "$USERS other changelog users; can't verify off"
10156         fi
10157 }
10158 run_test 160a "changelog sanity"
10159
10160 test_160b() { # LU-3587
10161         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10162         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10163         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10164                 { skip "Need MDS version at least 2.2.0"; return; }
10165
10166         local CL_USERS="mdd.$MDT0.changelog_users"
10167         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10168         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10169         echo "Registered as changelog user $USER"
10170         $GET_CL_USERS | grep -q $USER ||
10171                 error "User $USER not found in changelog_users"
10172
10173         local LONGNAME1=$(str_repeat a 255)
10174         local LONGNAME2=$(str_repeat b 255)
10175
10176         cd $DIR
10177         echo "creating very long named file"
10178         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
10179         echo "moving very long named file"
10180         mv $LONGNAME1 $LONGNAME2
10181
10182         $LFS changelog $MDT0 | grep RENME
10183
10184         echo "deregistering $USER"
10185         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10186
10187         rm -f $LONGNAME2
10188 }
10189 run_test 160b "Verify that very long rename doesn't crash in changelog"
10190
10191 test_160c() {
10192         local rc=0
10193         local server_version=$(lustre_version_code $SINGLEMDS)
10194
10195         [[ $server_version -gt $(version_code 2.5.57) ]] ||
10196                 [[ $server_version -gt $(version_code 2.5.1) &&
10197                    $server_version -lt $(version_code 2.5.50) ]] ||
10198                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
10199         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10200
10201         # Registration step
10202         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10203                 changelog_register -n)
10204
10205         rm -rf $DIR/$tdir
10206         mkdir -p $DIR/$tdir
10207         $MCREATE $DIR/$tdir/foo_160c
10208         changelog_chmask "TRUNC"
10209         $TRUNCATE $DIR/$tdir/foo_160c 200
10210         changelog_chmask "TRUNC"
10211         $TRUNCATE $DIR/$tdir/foo_160c 199
10212         $LFS changelog $MDT0
10213         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
10214         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
10215         $LFS changelog_clear $MDT0 $USER 0
10216
10217         # Deregistration step
10218         echo "deregistering $USER"
10219         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10220 }
10221 run_test 160c "verify that changelog log catch the truncate event"
10222
10223 test_161a() {
10224         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10225         test_mkdir -p -c1 $DIR/$tdir
10226         cp /etc/hosts $DIR/$tdir/$tfile
10227         test_mkdir -c1 $DIR/$tdir/foo1
10228         test_mkdir -c1 $DIR/$tdir/foo2
10229         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
10230         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
10231         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
10232         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
10233         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
10234         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10235                 $LFS fid2path $DIR $FID
10236                 err17935 "bad link ea"
10237         fi
10238     # middle
10239     rm $DIR/$tdir/foo2/zachary
10240     # last
10241     rm $DIR/$tdir/foo2/thor
10242     # first
10243     rm $DIR/$tdir/$tfile
10244     # rename
10245     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
10246     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
10247         then
10248         $LFS fid2path $DIR $FID
10249         err17935 "bad link rename"
10250     fi
10251     rm $DIR/$tdir/foo2/maggie
10252
10253         # overflow the EA
10254         local longname=filename_avg_len_is_thirty_two_
10255         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
10256                 error "failed to hardlink many files"
10257         links=$($LFS fid2path $DIR $FID | wc -l)
10258         echo -n "${links}/1000 links in link EA"
10259         [[ $links -gt 60 ]] ||
10260                 err17935 "expected at least 60 links in link EA"
10261         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
10262                 error "failed to unlink many hardlinks"
10263 }
10264 run_test 161a "link ea sanity"
10265
10266 test_161b() {
10267         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10268         [ $MDSCOUNT -lt 2 ] &&
10269                 skip "skipping remote directory test" && return
10270         local MDTIDX=1
10271         local remote_dir=$DIR/$tdir/remote_dir
10272
10273         mkdir -p $DIR/$tdir
10274         $LFS mkdir -i $MDTIDX $remote_dir ||
10275                 error "create remote directory failed"
10276
10277         cp /etc/hosts $remote_dir/$tfile
10278         mkdir -p $remote_dir/foo1
10279         mkdir -p $remote_dir/foo2
10280         ln $remote_dir/$tfile $remote_dir/foo1/sofia
10281         ln $remote_dir/$tfile $remote_dir/foo2/zachary
10282         ln $remote_dir/$tfile $remote_dir/foo1/luna
10283         ln $remote_dir/$tfile $remote_dir/foo2/thor
10284
10285         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
10286                      tr -d ']')
10287         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10288                 $LFS fid2path $DIR $FID
10289                 err17935 "bad link ea"
10290         fi
10291         # middle
10292         rm $remote_dir/foo2/zachary
10293         # last
10294         rm $remote_dir/foo2/thor
10295         # first
10296         rm $remote_dir/$tfile
10297         # rename
10298         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
10299         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
10300         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
10301                 $LFS fid2path $DIR $FID
10302                 err17935 "bad link rename"
10303         fi
10304         rm $remote_dir/foo2/maggie
10305
10306         # overflow the EA
10307         local longname=filename_avg_len_is_thirty_two_
10308         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10309                 error "failed to hardlink many files"
10310         links=$($LFS fid2path $DIR $FID | wc -l)
10311         echo -n "${links}/1000 links in link EA"
10312         [[ ${links} -gt 60 ]] ||
10313                 err17935 "expected at least 60 links in link EA"
10314         unlinkmany $remote_dir/foo2/$longname 1000 ||
10315         error "failed to unlink many hardlinks"
10316 }
10317 run_test 161b "link ea sanity under remote directory"
10318
10319 test_161c() {
10320         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10321         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10322         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10323                 skip "Need MDS version at least 2.1.5" && return
10324
10325         # define CLF_RENAME_LAST 0x0001
10326         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10327         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10328                 changelog_register -n)
10329         rm -rf $DIR/$tdir
10330         mkdir -p $DIR/$tdir
10331         touch $DIR/$tdir/foo_161c
10332         touch $DIR/$tdir/bar_161c
10333         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10334         $LFS changelog $MDT0 | grep RENME
10335         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10336                 cut -f5 -d' ')
10337         $LFS changelog_clear $MDT0 $USER 0
10338         if [ x$flags != "x0x1" ]; then
10339                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10340                         $USER
10341                 error "flag $flags is not 0x1"
10342         fi
10343         echo "rename overwrite a target having nlink = 1," \
10344                 "changelog record has flags of $flags"
10345
10346         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10347         touch $DIR/$tdir/foo_161c
10348         touch $DIR/$tdir/bar_161c
10349         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10350         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10351         $LFS changelog $MDT0 | grep RENME
10352         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10353         $LFS changelog_clear $MDT0 $USER 0
10354         if [ x$flags != "x0x0" ]; then
10355                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10356                         $USER
10357                 error "flag $flags is not 0x0"
10358         fi
10359         echo "rename overwrite a target having nlink > 1," \
10360                 "changelog record has flags of $flags"
10361
10362         # rename doesn't overwrite a target (changelog flag 0x0)
10363         touch $DIR/$tdir/foo_161c
10364         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10365         $LFS changelog $MDT0 | grep RENME
10366         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10367         $LFS changelog_clear $MDT0 $USER 0
10368         if [ x$flags != "x0x0" ]; then
10369                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10370                         $USER
10371                 error "flag $flags is not 0x0"
10372         fi
10373         echo "rename doesn't overwrite a target," \
10374                 "changelog record has flags of $flags"
10375
10376         # define CLF_UNLINK_LAST 0x0001
10377         # unlink a file having nlink = 1 (changelog flag 0x1)
10378         rm -f $DIR/$tdir/foo2_161c
10379         $LFS changelog $MDT0 | grep UNLNK
10380         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10381         $LFS changelog_clear $MDT0 $USER 0
10382         if [ x$flags != "x0x1" ]; then
10383                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10384                         $USER
10385                 error "flag $flags is not 0x1"
10386         fi
10387         echo "unlink a file having nlink = 1," \
10388                 "changelog record has flags of $flags"
10389
10390         # unlink a file having nlink > 1 (changelog flag 0x0)
10391         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10392         rm -f $DIR/$tdir/foobar_161c
10393         $LFS changelog $MDT0 | grep UNLNK
10394         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10395         $LFS changelog_clear $MDT0 $USER 0
10396         if [ x$flags != "x0x0" ]; then
10397                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10398                         $USER
10399                 error "flag $flags is not 0x0"
10400         fi
10401         echo "unlink a file having nlink > 1," \
10402                 "changelog record has flags of $flags"
10403         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10404 }
10405 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10406
10407 check_path() {
10408     local expected=$1
10409     shift
10410     local fid=$2
10411
10412     local path=$(${LFS} fid2path $*)
10413     RC=$?
10414
10415     if [ $RC -ne 0 ]; then
10416         err17935 "path looked up of $expected failed. Error $RC"
10417         return $RC
10418     elif [ "${path}" != "${expected}" ]; then
10419         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10420         return 2
10421     fi
10422     echo "fid $fid resolves to path $path (expected $expected)"
10423 }
10424
10425 test_162() {
10426         # Make changes to filesystem
10427         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10428         test_mkdir -p -c1 $DIR/$tdir/d2
10429         touch $DIR/$tdir/d2/$tfile
10430         touch $DIR/$tdir/d2/x1
10431         touch $DIR/$tdir/d2/x2
10432         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
10433         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
10434         # regular file
10435         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10436         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
10437                 error "check path $tdir/d2/$tfile failed"
10438
10439         # softlink
10440         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10441         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10442         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
10443                 error "check path $tdir/d2/p/q/r/slink failed"
10444
10445         # softlink to wrong file
10446         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10447         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10448         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
10449                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
10450
10451         # hardlink
10452         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10453         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10454         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10455         # fid2path dir/fsname should both work
10456         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
10457                 error "check path $tdir/d2/a/b/c/new_file failed"
10458         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
10459                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
10460
10461         # hardlink count: check that there are 2 links
10462         # Doesnt work with CMD yet: 17935
10463         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10464                 err17935 "expected 2 links"
10465
10466         # hardlink indexing: remove the first link
10467         rm $DIR/$tdir/d2/p/q/r/hlink
10468         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
10469                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
10470
10471         return 0
10472 }
10473 run_test 162 "path lookup sanity"
10474
10475 test_162b() {
10476         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10477         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10478
10479         mkdir $DIR/$tdir
10480         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
10481                                 error "create striped dir failed"
10482
10483         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
10484                                         tail -n 1 | awk '{print $2}')
10485         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
10486
10487         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
10488         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
10489
10490         # regular file
10491         for ((i=0;i<5;i++)); do
10492                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
10493                         error "get fid for f$i failed"
10494                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
10495                         error "check path $tdir/striped_dir/f$i failed"
10496
10497                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
10498                         error "get fid for d$i failed"
10499                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
10500                         error "check path $tdir/striped_dir/d$i failed"
10501         done
10502
10503         return 0
10504 }
10505 run_test 162b "striped directory path lookup sanity"
10506
10507 test_169() {
10508         # do directio so as not to populate the page cache
10509         log "creating a 10 Mb file"
10510         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10511         log "starting reads"
10512         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10513         log "truncating the file"
10514         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10515         log "killing dd"
10516         kill %+ || true # reads might have finished
10517         echo "wait until dd is finished"
10518         wait
10519         log "removing the temporary file"
10520         rm -rf $DIR/$tfile || error "tmp file removal failed"
10521 }
10522 run_test 169 "parallel read and truncate should not deadlock"
10523
10524 test_170() {
10525         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10526         $LCTL clear     # bug 18514
10527         $LCTL debug_daemon start $TMP/${tfile}_log_good
10528         touch $DIR/$tfile
10529         $LCTL debug_daemon stop
10530         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10531                error "sed failed to read log_good"
10532
10533         $LCTL debug_daemon start $TMP/${tfile}_log_good
10534         rm -rf $DIR/$tfile
10535         $LCTL debug_daemon stop
10536
10537         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10538                error "lctl df log_bad failed"
10539
10540         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10541         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10542
10543         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10544         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10545
10546         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10547                 error "bad_line good_line1 good_line2 are empty"
10548
10549         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10550         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10551         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10552
10553         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10554         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10555         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10556
10557         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
10558                 error "bad_line_new good_line_new are empty"
10559
10560         local expected_good=$((good_line1 + good_line2*2))
10561
10562         rm -f $TMP/${tfile}*
10563         # LU-231, short malformed line may not be counted into bad lines
10564         if [ $bad_line -ne $bad_line_new ] &&
10565                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
10566                 error "expected $bad_line bad lines, but got $bad_line_new"
10567                 return 1
10568         fi
10569
10570         if [ $expected_good -ne $good_line_new ]; then
10571                 error "expected $expected_good good lines, but got $good_line_new"
10572                 return 2
10573         fi
10574         true
10575 }
10576 run_test 170 "test lctl df to handle corrupted log ====================="
10577
10578 test_171() { # bug20592
10579         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10580 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
10581         $LCTL set_param fail_loc=0x50e
10582         $LCTL set_param fail_val=3000
10583         multiop_bg_pause $DIR/$tfile O_s || true
10584         local MULTIPID=$!
10585         kill -USR1 $MULTIPID
10586         # cause log dump
10587         sleep 3
10588         wait $MULTIPID
10589         if dmesg | grep "recursive fault"; then
10590                 error "caught a recursive fault"
10591         fi
10592         $LCTL set_param fail_loc=0
10593         true
10594 }
10595 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
10596
10597 # it would be good to share it with obdfilter-survey/iokit-libecho code
10598 setup_obdecho_osc () {
10599         local rc=0
10600         local ost_nid=$1
10601         local obdfilter_name=$2
10602         echo "Creating new osc for $obdfilter_name on $ost_nid"
10603         # make sure we can find loopback nid
10604         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
10605
10606         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
10607                            ${obdfilter_name}_osc_UUID || rc=2; }
10608         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
10609                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
10610         return $rc
10611 }
10612
10613 cleanup_obdecho_osc () {
10614         local obdfilter_name=$1
10615         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
10616         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
10617         return 0
10618 }
10619
10620 obdecho_test() {
10621         local OBD=$1
10622         local node=$2
10623         local pages=${3:-64}
10624         local rc=0
10625         local id
10626
10627         local count=10
10628         local obd_size=$(get_obd_size $node $OBD)
10629         local page_size=$(get_page_size $node)
10630         if [[ -n "$obd_size" ]]; then
10631                 local new_count=$((obd_size / (pages * page_size / 1024)))
10632                 [[ $new_count -ge $count ]] || count=$new_count
10633         fi
10634
10635         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
10636         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
10637                            rc=2; }
10638         if [ $rc -eq 0 ]; then
10639             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
10640             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
10641         fi
10642         echo "New object id is $id"
10643         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
10644                            rc=4; }
10645         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
10646                            "test_brw $count w v $pages $id" || rc=4; }
10647         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
10648                            rc=4; }
10649         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
10650                                         "cleanup" || rc=5; }
10651         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
10652                                         "detach" || rc=6; }
10653         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
10654         return $rc
10655 }
10656
10657 test_180a() {
10658         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10659         remote_ost_nodsh && skip "remote OST with nodsh" && return
10660         local rc=0
10661         local rmmod_local=0
10662
10663         if ! module_loaded obdecho; then
10664             load_module obdecho/obdecho
10665             rmmod_local=1
10666         fi
10667
10668         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
10669         local host=$(lctl get_param -n osc.$osc.import |
10670                              awk '/current_connection:/ {print $2}' )
10671         local target=$(lctl get_param -n osc.$osc.import |
10672                              awk '/target:/ {print $2}' )
10673         target=${target%_UUID}
10674
10675         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
10676         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
10677         [[ -n $target ]] && cleanup_obdecho_osc $target
10678         [ $rmmod_local -eq 1 ] && rmmod obdecho
10679         return $rc
10680 }
10681 run_test 180a "test obdecho on osc"
10682
10683 test_180b() {
10684         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10685         remote_ost_nodsh && skip "remote OST with nodsh" && return
10686         local rc=0
10687         local rmmod_remote=0
10688
10689         do_facet ost1 "lsmod | grep -q obdecho || "                      \
10690                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
10691                       "modprobe obdecho; }" && rmmod_remote=1
10692         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
10693         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
10694         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
10695         return $rc
10696 }
10697 run_test 180b "test obdecho directly on obdfilter"
10698
10699 test_180c() { # LU-2598
10700         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10701         remote_ost_nodsh && skip "remote OST with nodsh" && return
10702         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
10703                 skip "Need MDS version at least 2.4.0" && return
10704
10705         local rc=0
10706         local rmmod_remote=false
10707         local pages=16384 # 64MB bulk I/O RPC size
10708         local target
10709
10710         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
10711                 rmmod_remote=true || error "failed to load module obdecho"
10712
10713         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
10714                 head -n1)
10715         if [ -n "$target" ]; then
10716                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
10717         else
10718                 echo "there is no obdfilter target on ost1"
10719                 rc=2
10720         fi
10721         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
10722         return $rc
10723 }
10724 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
10725
10726 test_181() { # bug 22177
10727         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10728         # create enough files to index the directory
10729         createmany -o $DIR/$tdir/foobar 4000
10730         # print attributes for debug purpose
10731         lsattr -d .
10732         # open dir
10733         multiop_bg_pause $DIR/$tdir D_Sc || return 1
10734         MULTIPID=$!
10735         # remove the files & current working dir
10736         unlinkmany $DIR/$tdir/foobar 4000
10737         rmdir $DIR/$tdir
10738         kill -USR1 $MULTIPID
10739         wait $MULTIPID
10740         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
10741         return 0
10742 }
10743 run_test 181 "Test open-unlinked dir ========================"
10744
10745 test_182() {
10746         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10747         # disable MDC RPC lock wouldn't crash client
10748         local fcount=1000
10749         local tcount=4
10750
10751         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10752 #define OBD_FAIL_MDC_RPCS_SEM           0x804
10753         $LCTL set_param fail_loc=0x804
10754
10755         for (( i=0; i < $tcount; i++ )) ; do
10756                 mkdir $DIR/$tdir/$i
10757                 createmany -o $DIR/$tdir/$i/f- $fcount &
10758         done
10759         wait
10760
10761         for (( i=0; i < $tcount; i++ )) ; do
10762                 unlinkmany $DIR/$tdir/$i/f- $fcount &
10763         done
10764         wait
10765
10766         rm -rf $DIR/$tdir
10767
10768         $LCTL set_param fail_loc=0
10769 }
10770 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
10771
10772 test_183() { # LU-2275
10773         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10774         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
10775                 skip "Need MDS version at least 2.3.56" && return
10776
10777         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10778         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10779         echo aaa > $DIR/$tdir/$tfile
10780
10781 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
10782         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
10783
10784         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
10785         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
10786
10787         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
10788
10789         # Flush negative dentry cache
10790         touch $DIR/$tdir/$tfile
10791
10792         # We are not checking for any leaked references here, they'll
10793         # become evident next time we do cleanup with module unload.
10794         rm -rf $DIR/$tdir
10795 }
10796 run_test 183 "No crash or request leak in case of strange dispositions ========"
10797
10798 # test suite 184 is for LU-2016, LU-2017
10799 test_184a() {
10800         check_swap_layouts_support && return 0
10801
10802         dir0=$DIR/$tdir/$testnum
10803         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
10804         ref1=/etc/passwd
10805         ref2=/etc/group
10806         file1=$dir0/f1
10807         file2=$dir0/f2
10808         $SETSTRIPE -c1 $file1
10809         cp $ref1 $file1
10810         $SETSTRIPE -c2 $file2
10811         cp $ref2 $file2
10812         gen1=$($GETSTRIPE -g $file1)
10813         gen2=$($GETSTRIPE -g $file2)
10814
10815         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
10816         gen=$($GETSTRIPE -g $file1)
10817         [[ $gen1 != $gen ]] ||
10818                 "Layout generation on $file1 does not change"
10819         gen=$($GETSTRIPE -g $file2)
10820         [[ $gen2 != $gen ]] ||
10821                 "Layout generation on $file2 does not change"
10822
10823         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
10824         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
10825 }
10826 run_test 184a "Basic layout swap"
10827
10828 test_184b() {
10829         check_swap_layouts_support && return 0
10830
10831         dir0=$DIR/$tdir/$testnum
10832         mkdir -p $dir0 || error "creating dir $dir0"
10833         file1=$dir0/f1
10834         file2=$dir0/f2
10835         file3=$dir0/f3
10836         dir1=$dir0/d1
10837         dir2=$dir0/d2
10838         mkdir $dir1 $dir2
10839         $SETSTRIPE -c1 $file1
10840         $SETSTRIPE -c2 $file2
10841         $SETSTRIPE -c1 $file3
10842         chown $RUNAS_ID $file3
10843         gen1=$($GETSTRIPE -g $file1)
10844         gen2=$($GETSTRIPE -g $file2)
10845
10846         $LFS swap_layouts $dir1 $dir2 &&
10847                 error "swap of directories layouts should fail"
10848         $LFS swap_layouts $dir1 $file1 &&
10849                 error "swap of directory and file layouts should fail"
10850         $RUNAS $LFS swap_layouts $file1 $file2 &&
10851                 error "swap of file we cannot write should fail"
10852         $LFS swap_layouts $file1 $file3 &&
10853                 error "swap of file with different owner should fail"
10854         /bin/true # to clear error code
10855 }
10856 run_test 184b "Forbidden layout swap (will generate errors)"
10857
10858 test_184c() {
10859         check_swap_layouts_support && return 0
10860
10861         local dir0=$DIR/$tdir/$testnum
10862         mkdir -p $dir0 || error "creating dir $dir0"
10863
10864         local ref1=$dir0/ref1
10865         local ref2=$dir0/ref2
10866         local file1=$dir0/file1
10867         local file2=$dir0/file2
10868         # create a file large enough for the concurent test
10869         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
10870         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
10871         echo "ref file size: ref1($(stat -c %s $ref1))," \
10872              "ref2($(stat -c %s $ref2))"
10873
10874         cp $ref2 $file2
10875         dd if=$ref1 of=$file1 bs=16k &
10876         local DD_PID=$!
10877
10878         # Make sure dd starts to copy file
10879         while [ ! -f $file1 ]; do sleep 0.1; done
10880
10881         $LFS swap_layouts $file1 $file2
10882         local rc=$?
10883         wait $DD_PID
10884         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
10885         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
10886
10887         # how many bytes copied before swapping layout
10888         local copied=$(stat -c %s $file2)
10889         local remaining=$(stat -c %s $ref1)
10890         remaining=$((remaining - copied))
10891         echo "Copied $copied bytes before swapping layout..."
10892
10893         cmp -n $copied $file1 $ref2 | grep differ &&
10894                 error "Content mismatch [0, $copied) of ref2 and file1"
10895         cmp -n $copied $file2 $ref1 ||
10896                 error "Content mismatch [0, $copied) of ref1 and file2"
10897         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
10898                 error "Content mismatch [$copied, EOF) of ref1 and file1"
10899
10900         # clean up
10901         rm -f $ref1 $ref2 $file1 $file2
10902 }
10903 run_test 184c "Concurrent write and layout swap"
10904
10905 test_184d() {
10906         check_swap_layouts_support && return 0
10907         [ -z "$(which getfattr 2>/dev/null)" ] &&
10908                 skip "no getfattr command" && return 0
10909
10910         local file1=$DIR/$tdir/$tfile-1
10911         local file2=$DIR/$tdir/$tfile-2
10912         local file3=$DIR/$tdir/$tfile-3
10913         local lovea1
10914         local lovea2
10915
10916         mkdir -p $DIR/$tdir
10917         touch $file1 || error "create $file1 failed"
10918         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
10919                 error "create $file2 failed"
10920         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
10921                 error "create $file3 failed"
10922         lovea1=$($LFS getstripe $file1 | sed 1d)
10923
10924         $LFS swap_layouts $file2 $file3 ||
10925                 error "swap $file2 $file3 layouts failed"
10926         $LFS swap_layouts $file1 $file2 ||
10927                 error "swap $file1 $file2 layouts failed"
10928
10929         lovea2=$($LFS getstripe $file2 | sed 1d)
10930         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
10931
10932         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
10933         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
10934 }
10935 run_test 184d "allow stripeless layouts swap"
10936
10937
10938 test_185() { # LU-2441
10939         # LU-3553 - no volatile file support in old servers
10940         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
10941                 { skip "Need MDS version at least 2.3.60"; return 0; }
10942
10943         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10944         touch $DIR/$tdir/spoo
10945         local mtime1=$(stat -c "%Y" $DIR/$tdir)
10946         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
10947                 error "cannot create/write a volatile file"
10948         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
10949                 error "FID is still valid after close"
10950
10951         multiop_bg_pause $DIR/$tdir vVw4096_c
10952         local multi_pid=$!
10953
10954         local OLD_IFS=$IFS
10955         IFS=":"
10956         local fidv=($fid)
10957         IFS=$OLD_IFS
10958         # assume that the next FID for this client is sequential, since stdout
10959         # is unfortunately eaten by multiop_bg_pause
10960         local n=$((${fidv[1]} + 1))
10961         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
10962         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
10963                 error "FID is missing before close"
10964         kill -USR1 $multi_pid
10965         # 1 second delay, so if mtime change we will see it
10966         sleep 1
10967         local mtime2=$(stat -c "%Y" $DIR/$tdir)
10968         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
10969 }
10970 run_test 185 "Volatile file support"
10971
10972 test_187a() {
10973         local dir0=$DIR/$tdir/$testnum
10974         mkdir -p $dir0 || error "creating dir $dir0"
10975
10976         local file=$dir0/file1
10977         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
10978         local dv1=$($LFS data_version $file)
10979         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
10980         local dv2=$($LFS data_version $file)
10981         [[ $dv1 != $dv2 ]] ||
10982                 error "data version did not change on write $dv1 == $dv2"
10983
10984         # clean up
10985         rm -f $file1
10986 }
10987 run_test 187a "Test data version change"
10988
10989 test_187b() {
10990         local dir0=$DIR/$tdir/$testnum
10991         mkdir -p $dir0 || error "creating dir $dir0"
10992
10993         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
10994         [[ ${DV[0]} != ${DV[1]} ]] ||
10995                 error "data version did not change on write"\
10996                       " ${DV[0]} == ${DV[1]}"
10997
10998         # clean up
10999         rm -f $file1
11000 }
11001 run_test 187b "Test data version change on volatile file"
11002
11003 test_200() {
11004         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11005         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11006
11007         local POOL=${POOL:-cea1}
11008         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
11009         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
11010         # Pool OST targets
11011         local first_ost=0
11012         local last_ost=$(($OSTCOUNT - 1))
11013         local ost_step=2
11014         local ost_list=$(seq $first_ost $ost_step $last_ost)
11015         local ost_range="$first_ost $last_ost $ost_step"
11016         local test_path=$POOL_ROOT/$POOL_DIR_NAME
11017         local file_dir=$POOL_ROOT/file_tst
11018
11019         local rc=0
11020         while : ; do
11021                 # former test_200a test_200b
11022                 pool_add $POOL                          || { rc=$? ; break; }
11023                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
11024                 # former test_200c test_200d
11025                 mkdir -p $test_path
11026                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
11027                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
11028                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
11029                                                         || { rc=$? ; break; }
11030                 # former test_200e test_200f
11031                 local files=$((OSTCOUNT*3))
11032                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
11033                                                         || { rc=$? ; break; }
11034                 pool_create_files $POOL $file_dir $files "$ost_list" \
11035                                                         || { rc=$? ; break; }
11036                 # former test_200g test_200h
11037                 pool_lfs_df $POOL                       || { rc=$? ; break; }
11038                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
11039
11040                 # former test_201a test_201b test_201c
11041                 pool_remove_first_target $POOL          || { rc=$? ; break; }
11042
11043                 local f=$test_path/$tfile
11044                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
11045                 pool_remove $POOL $f                    || { rc=$? ; break; }
11046                 break
11047         done
11048
11049         cleanup_pools
11050         return $rc
11051 }
11052 run_test 200 "OST pools"
11053
11054 # usage: default_attr <count | size | offset>
11055 default_attr() {
11056         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
11057 }
11058
11059 # usage: check_default_stripe_attr
11060 check_default_stripe_attr() {
11061         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
11062         case $1 in
11063         --stripe-count|--count)
11064                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
11065         --stripe-size|--size)
11066                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
11067         --stripe-index|--index)
11068                 EXPECTED=-1;;
11069         *)
11070                 error "unknown getstripe attr '$1'"
11071         esac
11072
11073         [ $ACTUAL != $EXPECTED ] &&
11074                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
11075 }
11076
11077 test_204a() {
11078         test_mkdir -p $DIR/$tdir
11079         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
11080
11081         check_default_stripe_attr --stripe-count
11082         check_default_stripe_attr --stripe-size
11083         check_default_stripe_attr --stripe-index
11084
11085         return 0
11086 }
11087 run_test 204a "Print default stripe attributes ================="
11088
11089 test_204b() {
11090         test_mkdir -p $DIR/$tdir
11091         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11092
11093         check_default_stripe_attr --stripe-size
11094         check_default_stripe_attr --stripe-index
11095
11096         return 0
11097 }
11098 run_test 204b "Print default stripe size and offset  ==========="
11099
11100 test_204c() {
11101         test_mkdir -p $DIR/$tdir
11102         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11103
11104         check_default_stripe_attr --stripe-count
11105         check_default_stripe_attr --stripe-index
11106
11107         return 0
11108 }
11109 run_test 204c "Print default stripe count and offset ==========="
11110
11111 test_204d() {
11112         test_mkdir -p $DIR/$tdir
11113         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11114
11115         check_default_stripe_attr --stripe-count
11116         check_default_stripe_attr --stripe-size
11117
11118         return 0
11119 }
11120 run_test 204d "Print default stripe count and size ============="
11121
11122 test_204e() {
11123         test_mkdir -p $DIR/$tdir
11124         $SETSTRIPE -d $DIR/$tdir
11125
11126         check_default_stripe_attr --stripe-count --raw
11127         check_default_stripe_attr --stripe-size --raw
11128         check_default_stripe_attr --stripe-index --raw
11129
11130         return 0
11131 }
11132 run_test 204e "Print raw stripe attributes ================="
11133
11134 test_204f() {
11135         test_mkdir -p $DIR/$tdir
11136         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11137
11138         check_default_stripe_attr --stripe-size --raw
11139         check_default_stripe_attr --stripe-index --raw
11140
11141         return 0
11142 }
11143 run_test 204f "Print raw stripe size and offset  ==========="
11144
11145 test_204g() {
11146         test_mkdir -p $DIR/$tdir
11147         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11148
11149         check_default_stripe_attr --stripe-count --raw
11150         check_default_stripe_attr --stripe-index --raw
11151
11152         return 0
11153 }
11154 run_test 204g "Print raw stripe count and offset ==========="
11155
11156 test_204h() {
11157         test_mkdir -p $DIR/$tdir
11158         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11159
11160         check_default_stripe_attr --stripe-count --raw
11161         check_default_stripe_attr --stripe-size --raw
11162
11163         return 0
11164 }
11165 run_test 204h "Print raw stripe count and size ============="
11166
11167 # Figure out which job scheduler is being used, if any,
11168 # or use a fake one
11169 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11170         JOBENV=SLURM_JOB_ID
11171 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11172         JOBENV=LSB_JOBID
11173 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11174         JOBENV=PBS_JOBID
11175 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11176         JOBENV=LOADL_STEP_ID
11177 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11178         JOBENV=JOB_ID
11179 else
11180         JOBENV=FAKE_JOBID
11181 fi
11182
11183 verify_jobstats() {
11184         local cmd=$1
11185         local target=$2
11186
11187         # clear old jobstats
11188         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
11189         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
11190
11191         # use a new JobID for this test, or we might see an old one
11192         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
11193
11194         JOBVAL=${!JOBENV}
11195         log "Test: $cmd"
11196         log "Using JobID environment variable $JOBENV=$JOBVAL"
11197
11198         if [ $JOBENV = "FAKE_JOBID" ]; then
11199                 FAKE_JOBID=$JOBVAL $cmd
11200         else
11201                 $cmd
11202         fi
11203
11204         if [ "$target" = "mdt" -o "$target" = "both" ]; then
11205                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
11206                 do_facet $FACET lctl get_param mdt.*.job_stats |
11207                         grep $JOBVAL || error "No job stats found on MDT $FACET"
11208         fi
11209         if [ "$target" = "ost" -o "$target" = "both" ]; then
11210                 FACET=ost1
11211                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
11212                         grep $JOBVAL || error "No job stats found on OST $FACET"
11213         fi
11214 }
11215
11216 jobstats_set() {
11217         trap 0
11218         NEW_JOBENV=${1:-$OLD_JOBENV}
11219         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11220         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11221 }
11222
11223 test_205() { # Job stats
11224         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11225         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11226         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11227                 skip "Server doesn't support jobstats" && return 0
11228         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11229
11230         local cmd
11231         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11232         if [ $OLD_JOBENV != $JOBENV ]; then
11233                 jobstats_set $JOBENV
11234                 trap jobstats_set EXIT
11235         fi
11236
11237         # mkdir
11238         cmd="mkdir $DIR/$tfile"
11239         verify_jobstats "$cmd" "mdt"
11240         # rmdir
11241         cmd="rm -fr $DIR/$tfile"
11242         verify_jobstats "$cmd" "mdt"
11243         # mknod
11244         cmd="mknod $DIR/$tfile c 1 3"
11245         verify_jobstats "$cmd" "mdt"
11246         # unlink
11247         cmd="rm -f $DIR/$tfile"
11248         verify_jobstats "$cmd" "mdt"
11249         # open & close
11250         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11251         verify_jobstats "$cmd" "mdt"
11252         # setattr
11253         cmd="touch $DIR/$tfile"
11254         verify_jobstats "$cmd" "both"
11255         # write
11256         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11257         verify_jobstats "$cmd" "ost"
11258         # read
11259         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11260         verify_jobstats "$cmd" "ost"
11261         # truncate
11262         cmd="$TRUNCATE $DIR/$tfile 0"
11263         verify_jobstats "$cmd" "both"
11264         # rename
11265         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
11266         verify_jobstats "$cmd" "mdt"
11267
11268         # cleanup
11269         rm -f $DIR/jobstats_test_rename
11270
11271         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11272 }
11273 run_test 205 "Verify job stats"
11274
11275 # LU-1480, LU-1773 and LU-1657
11276 test_206() {
11277         mkdir -p $DIR/$tdir
11278         $SETSTRIPE -c -1 $DIR/$tdir
11279 #define OBD_FAIL_LOV_INIT 0x1403
11280         $LCTL set_param fail_loc=0xa0001403
11281         $LCTL set_param fail_val=1
11282         touch $DIR/$tdir/$tfile || true
11283 }
11284 run_test 206 "fail lov_init_raid0() doesn't lbug"
11285
11286 test_207a() {
11287         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11288         local fsz=`stat -c %s $DIR/$tfile`
11289         cancel_lru_locks mdc
11290
11291         # do not return layout in getattr intent
11292 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11293         $LCTL set_param fail_loc=0x170
11294         local sz=`stat -c %s $DIR/$tfile`
11295
11296         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11297
11298         rm -rf $DIR/$tfile
11299 }
11300 run_test 207a "can refresh layout at glimpse"
11301
11302 test_207b() {
11303         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11304         local cksum=`md5sum $DIR/$tfile`
11305         local fsz=`stat -c %s $DIR/$tfile`
11306         cancel_lru_locks mdc
11307         cancel_lru_locks osc
11308
11309         # do not return layout in getattr intent
11310 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11311         $LCTL set_param fail_loc=0x171
11312
11313         # it will refresh layout after the file is opened but before read issues
11314         echo checksum is "$cksum"
11315         echo "$cksum" |md5sum -c --quiet || error "file differs"
11316
11317         rm -rf $DIR/$tfile
11318 }
11319 run_test 207b "can refresh layout at open"
11320
11321 test_208() {
11322         # FIXME: in this test suite, only RD lease is used. This is okay
11323         # for now as only exclusive open is supported. After generic lease
11324         # is done, this test suite should be revised. - Jinshan
11325
11326         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11327                 { skip "Need MDS version at least 2.4.52"; return 0; }
11328         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11329
11330         echo "==== test 1: verify get lease work"
11331         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11332
11333         echo "==== test 2: verify lease can be broken by upcoming open"
11334         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11335         local PID=$!
11336         sleep 1
11337
11338         $MULTIOP $DIR/$tfile oO_RDONLY:c
11339         kill -USR1 $PID && wait $PID || error "break lease error"
11340
11341         echo "==== test 3: verify lease can't be granted if an open already exists"
11342         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11343         local PID=$!
11344         sleep 1
11345
11346         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11347         kill -USR1 $PID && wait $PID || error "open file error"
11348
11349         echo "==== test 4: lease can sustain over recovery"
11350         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11351         PID=$!
11352         sleep 1
11353
11354         fail mds1
11355
11356         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11357
11358         echo "==== test 5: lease broken can't be regained by replay"
11359         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11360         PID=$!
11361         sleep 1
11362
11363         # open file to break lease and then recovery
11364         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11365         fail mds1
11366
11367         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11368
11369         rm -f $DIR/$tfile
11370 }
11371 run_test 208 "Exclusive open"
11372
11373 test_209() {
11374         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11375                 skip_env "must have disp_stripe" && return
11376
11377         touch $DIR/$tfile
11378         sync; sleep 5; sync;
11379
11380         echo 3 > /proc/sys/vm/drop_caches
11381         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11382
11383         # open/close 500 times
11384         for i in $(seq 500); do
11385                 cat $DIR/$tfile
11386         done
11387
11388         echo 3 > /proc/sys/vm/drop_caches
11389         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11390
11391         echo "before: $req_before, after: $req_after"
11392         [ $((req_after - req_before)) -ge 300 ] &&
11393                 error "open/close requests are not freed"
11394         return 0
11395 }
11396 run_test 209 "read-only open/close requests should be freed promptly"
11397
11398 test_212() {
11399         size=`date +%s`
11400         size=$((size % 8192 + 1))
11401         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11402         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11403         rm -f $DIR/f212 $DIR/f212.xyz
11404 }
11405 run_test 212 "Sendfile test ============================================"
11406
11407 test_213() {
11408         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11409         cancel_lru_locks osc
11410         lctl set_param fail_loc=0x8000040f
11411         # generate a read lock
11412         cat $DIR/$tfile > /dev/null
11413         # write to the file, it will try to cancel the above read lock.
11414         cat /etc/hosts >> $DIR/$tfile
11415 }
11416 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11417
11418 test_214() { # for bug 20133
11419         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11420         for (( i=0; i < 340; i++ )) ; do
11421                 touch $DIR/$tdir/d214c/a$i
11422         done
11423
11424         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11425         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11426         ls $DIR/d214c || error "ls $DIR/d214c failed"
11427         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11428         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11429 }
11430 run_test 214 "hash-indexed directory test - bug 20133"
11431
11432 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11433 create_lnet_proc_files() {
11434         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
11435         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11436
11437         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11438         rm -f "$TMP/lnet_$1.sys_tmp"
11439 }
11440
11441 # counterpart of create_lnet_proc_files
11442 remove_lnet_proc_files() {
11443         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11444 }
11445
11446 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11447 # 3rd arg as regexp for body
11448 check_lnet_proc_stats() {
11449         local l=$(cat "$TMP/lnet_$1" |wc -l)
11450         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
11451
11452         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
11453 }
11454
11455 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11456 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
11457 # optional and can be regexp for 2nd line (lnet.routes case)
11458 check_lnet_proc_entry() {
11459         local blp=2          # blp stands for 'position of 1st line of body'
11460         [ -z "$5" ] || blp=3 # lnet.routes case
11461
11462         local l=$(cat "$TMP/lnet_$1" |wc -l)
11463         # subtracting one from $blp because the body can be empty
11464         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
11465
11466         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
11467                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
11468
11469         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
11470                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
11471
11472         # bail out if any unexpected line happened
11473         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
11474         [ "$?" != 0 ] || error "$2 misformatted"
11475 }
11476
11477 test_215() { # for bugs 18102, 21079, 21517
11478         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11479         local N='(0|[1-9][0-9]*)'       # non-negative numeric
11480         local P='[1-9][0-9]*'           # positive numeric
11481         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
11482         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
11483         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
11484         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
11485
11486         local L1 # regexp for 1st line
11487         local L2 # regexp for 2nd line (optional)
11488         local BR # regexp for the rest (body)
11489
11490         # lnet.stats should look as 11 space-separated non-negative numerics
11491         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
11492         create_lnet_proc_files "stats"
11493         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
11494         remove_lnet_proc_files "stats"
11495
11496         # lnet.routes should look like this:
11497         # Routing disabled/enabled
11498         # net hops priority state router
11499         # where net is a string like tcp0, hops > 0, priority >= 0,
11500         # state is up/down,
11501         # router is a string like 192.168.1.1@tcp2
11502         L1="^Routing (disabled|enabled)$"
11503         L2="^net +hops +priority +state +router$"
11504         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
11505         create_lnet_proc_files "routes"
11506         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
11507         remove_lnet_proc_files "routes"
11508
11509         # lnet.routers should look like this:
11510         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
11511         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
11512         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
11513         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
11514         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
11515         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
11516         create_lnet_proc_files "routers"
11517         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
11518         remove_lnet_proc_files "routers"
11519
11520         # lnet.peers should look like this:
11521         # nid refs state last max rtr min tx min queue
11522         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
11523         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
11524         # numeric (0 or >0 or <0), queue >= 0.
11525         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
11526         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
11527         create_lnet_proc_files "peers"
11528         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
11529         remove_lnet_proc_files "peers"
11530
11531         # lnet.buffers  should look like this:
11532         # pages count credits min
11533         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
11534         L1="^pages +count +credits +min$"
11535         BR="^ +$N +$N +$I +$I$"
11536         create_lnet_proc_files "buffers"
11537         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
11538         remove_lnet_proc_files "buffers"
11539
11540         # lnet.nis should look like this:
11541         # nid status alive refs peer rtr max tx min
11542         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
11543         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
11544         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
11545         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
11546         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
11547         create_lnet_proc_files "nis"
11548         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
11549         remove_lnet_proc_files "nis"
11550
11551         # can we successfully write to lnet.stats?
11552         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
11553         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
11554 }
11555 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
11556
11557 test_216() { # bug 20317
11558         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11559         remote_ost_nodsh && skip "remote OST with nodsh" && return
11560
11561         local node
11562         local facets=$(get_facets OST)
11563         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11564
11565         save_lustre_params client "osc.*.contention_seconds" > $p
11566         save_lustre_params $facets \
11567                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
11568         save_lustre_params $facets \
11569                 "ldlm.namespaces.filter-*.contended_locks" >> $p
11570         save_lustre_params $facets \
11571                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
11572         clear_osc_stats
11573
11574         # agressive lockless i/o settings
11575         for node in $(osts_nodes); do
11576                 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'
11577         done
11578         lctl set_param -n osc.*.contention_seconds 60
11579
11580         $DIRECTIO write $DIR/$tfile 0 10 4096
11581         $CHECKSTAT -s 40960 $DIR/$tfile
11582
11583         # disable lockless i/o
11584         for node in $(osts_nodes); do
11585                 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'
11586         done
11587         lctl set_param -n osc.*.contention_seconds 0
11588         clear_osc_stats
11589
11590         dd if=/dev/zero of=$DIR/$tfile count=0
11591         $CHECKSTAT -s 0 $DIR/$tfile
11592
11593         restore_lustre_params <$p
11594         rm -f $p
11595         rm $DIR/$tfile
11596 }
11597 run_test 216 "check lockless direct write works and updates file size and kms correctly"
11598
11599 test_217() { # bug 22430
11600         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11601         local node
11602         local nid
11603
11604         for node in $(nodes_list); do
11605                 nid=$(host_nids_address $node $NETTYPE)
11606                 if [[ $nid = *-* ]] ; then
11607                         echo "lctl ping $nid@$NETTYPE"
11608                         lctl ping $nid@$NETTYPE
11609                 else
11610                         echo "skipping $node (no hyphen detected)"
11611                 fi
11612         done
11613 }
11614 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
11615
11616 test_218() {
11617        # do directio so as not to populate the page cache
11618        log "creating a 10 Mb file"
11619        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11620        log "starting reads"
11621        dd if=$DIR/$tfile of=/dev/null bs=4096 &
11622        log "truncating the file"
11623        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11624        log "killing dd"
11625        kill %+ || true # reads might have finished
11626        echo "wait until dd is finished"
11627        wait
11628        log "removing the temporary file"
11629        rm -rf $DIR/$tfile || error "tmp file removal failed"
11630 }
11631 run_test 218 "parallel read and truncate should not deadlock ======================="
11632
11633 test_219() {
11634         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11635         # write one partial page
11636         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
11637         # set no grant so vvp_io_commit_write will do sync write
11638         $LCTL set_param fail_loc=0x411
11639         # write a full page at the end of file
11640         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
11641
11642         $LCTL set_param fail_loc=0
11643         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
11644         $LCTL set_param fail_loc=0x411
11645         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
11646
11647         # LU-4201
11648         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
11649         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
11650 }
11651 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
11652
11653 test_220() { #LU-325
11654         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11655         remote_ost_nodsh && skip "remote OST with nodsh" && return
11656         local OSTIDX=0
11657
11658         test_mkdir -p $DIR/$tdir
11659         local OST=$(lfs osts | grep ${OSTIDX}": " | \
11660                 awk '{print $2}' | sed -e 's/_UUID$//')
11661
11662         # on the mdt's osc
11663         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
11664         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
11665                         osc.$mdtosc_proc1.prealloc_last_id)
11666         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
11667                         osc.$mdtosc_proc1.prealloc_next_id)
11668
11669         $LFS df -i
11670
11671         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
11672         #define OBD_FAIL_OST_ENOINO              0x229
11673         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
11674         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
11675         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
11676
11677         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
11678
11679         MDSOBJS=$((last_id - next_id))
11680         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
11681
11682         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
11683         echo "OST still has $count kbytes free"
11684
11685         echo "create $MDSOBJS files @next_id..."
11686         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
11687
11688         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11689                         osc.$mdtosc_proc1.prealloc_last_id)
11690         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11691                         osc.$mdtosc_proc1.prealloc_next_id)
11692
11693         echo "after creation, last_id=$last_id2, next_id=$next_id2"
11694         $LFS df -i
11695
11696         echo "cleanup..."
11697
11698         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
11699         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
11700
11701         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
11702         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
11703         echo "unlink $MDSOBJS files @$next_id..."
11704         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
11705 }
11706 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
11707
11708 test_221() {
11709         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11710         dd if=`which date` of=$MOUNT/date oflag=sync
11711         chmod +x $MOUNT/date
11712
11713         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
11714         $LCTL set_param fail_loc=0x80001401
11715
11716         $MOUNT/date > /dev/null
11717         rm -f $MOUNT/date
11718 }
11719 run_test 221 "make sure fault and truncate race to not cause OOM"
11720
11721 test_222a () {
11722         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11723        rm -rf $DIR/$tdir
11724        test_mkdir -p $DIR/$tdir
11725        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11726        createmany -o $DIR/$tdir/$tfile 10
11727        cancel_lru_locks mdc
11728        cancel_lru_locks osc
11729        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11730        $LCTL set_param fail_loc=0x31a
11731        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
11732        $LCTL set_param fail_loc=0
11733        rm -r $DIR/$tdir
11734 }
11735 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
11736
11737 test_222b () {
11738         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11739        rm -rf $DIR/$tdir
11740        test_mkdir -p $DIR/$tdir
11741        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11742        createmany -o $DIR/$tdir/$tfile 10
11743        cancel_lru_locks mdc
11744        cancel_lru_locks osc
11745        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11746        $LCTL set_param fail_loc=0x31a
11747        rm -r $DIR/$tdir || "AGL for rmdir failed"
11748        $LCTL set_param fail_loc=0
11749 }
11750 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
11751
11752 test_223 () {
11753         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11754        rm -rf $DIR/$tdir
11755        test_mkdir -p $DIR/$tdir
11756        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11757        createmany -o $DIR/$tdir/$tfile 10
11758        cancel_lru_locks mdc
11759        cancel_lru_locks osc
11760        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
11761        $LCTL set_param fail_loc=0x31b
11762        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
11763        $LCTL set_param fail_loc=0
11764        rm -r $DIR/$tdir
11765 }
11766 run_test 223 "osc reenqueue if without AGL lock granted ======================="
11767
11768 test_224a() { # LU-1039, MRP-303
11769         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11770         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
11771         $LCTL set_param fail_loc=0x508
11772         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
11773         $LCTL set_param fail_loc=0
11774         df $DIR
11775 }
11776 run_test 224a "Don't panic on bulk IO failure"
11777
11778 test_224b() { # LU-1039, MRP-303
11779         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11780         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
11781         cancel_lru_locks osc
11782         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
11783         $LCTL set_param fail_loc=0x515
11784         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
11785         $LCTL set_param fail_loc=0
11786         df $DIR
11787 }
11788 run_test 224b "Don't panic on bulk IO failure"
11789
11790 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
11791 test_225a () {
11792         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11793         if [ -z ${MDSSURVEY} ]; then
11794               skip_env "mds-survey not found" && return
11795         fi
11796
11797         [ $MDSCOUNT -ge 2 ] &&
11798                 skip "skipping now for more than one MDT" && return
11799
11800        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11801             { skip "Need MDS version at least 2.2.51"; return; }
11802
11803        local mds=$(facet_host $SINGLEMDS)
11804        local target=$(do_nodes $mds 'lctl dl' | \
11805                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11806
11807        local cmd1="file_count=1000 thrhi=4"
11808        local cmd2="dir_count=2 layer=mdd stripe_count=0"
11809        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11810        local cmd="$cmd1 $cmd2 $cmd3"
11811
11812        rm -f ${TMP}/mds_survey*
11813        echo + $cmd
11814        eval $cmd || error "mds-survey with zero-stripe failed"
11815        cat ${TMP}/mds_survey*
11816        rm -f ${TMP}/mds_survey*
11817 }
11818 run_test 225a "Metadata survey sanity with zero-stripe"
11819
11820 test_225b () {
11821         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11822
11823         if [ -z ${MDSSURVEY} ]; then
11824               skip_env "mds-survey not found" && return
11825         fi
11826         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11827             { skip "Need MDS version at least 2.2.51"; return; }
11828
11829         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
11830               skip_env "Need to mount OST to test" && return
11831         fi
11832
11833         [ $MDSCOUNT -ge 2 ] &&
11834                 skip "skipping now for more than one MDT" && return
11835        local mds=$(facet_host $SINGLEMDS)
11836        local target=$(do_nodes $mds 'lctl dl' | \
11837                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11838
11839        local cmd1="file_count=1000 thrhi=4"
11840        local cmd2="dir_count=2 layer=mdd stripe_count=1"
11841        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11842        local cmd="$cmd1 $cmd2 $cmd3"
11843
11844        rm -f ${TMP}/mds_survey*
11845        echo + $cmd
11846        eval $cmd || error "mds-survey with stripe_count failed"
11847        cat ${TMP}/mds_survey*
11848        rm -f ${TMP}/mds_survey*
11849 }
11850 run_test 225b "Metadata survey sanity with stripe_count = 1"
11851
11852 mcreate_path2fid () {
11853         local mode=$1
11854         local major=$2
11855         local minor=$3
11856         local name=$4
11857         local desc=$5
11858         local path=$DIR/$tdir/$name
11859         local fid
11860         local rc
11861         local fid_path
11862
11863         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
11864                 error "cannot create $desc"
11865
11866         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
11867         rc=$?
11868         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
11869
11870         fid_path=$($LFS fid2path $MOUNT $fid)
11871         rc=$?
11872         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
11873
11874         [ "$path" == "$fid_path" ] ||
11875                 error "fid2path returned $fid_path, expected $path"
11876
11877         echo "pass with $path and $fid"
11878 }
11879
11880 test_226a () {
11881         rm -rf $DIR/$tdir
11882         mkdir -p $DIR/$tdir
11883
11884         mcreate_path2fid 0010666 0 0 fifo "FIFO"
11885         mcreate_path2fid 0020666 1 3 null "character special file (null)"
11886         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
11887         mcreate_path2fid 0040666 0 0 dir "directory"
11888         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
11889         mcreate_path2fid 0100666 0 0 file "regular file"
11890         mcreate_path2fid 0120666 0 0 link "symbolic link"
11891         mcreate_path2fid 0140666 0 0 sock "socket"
11892 }
11893 run_test 226a "call path2fid and fid2path on files of all type"
11894
11895 test_226b () {
11896         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11897         rm -rf $DIR/$tdir
11898         local MDTIDX=1
11899
11900         mkdir -p $DIR/$tdir
11901         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
11902                 error "create remote directory failed"
11903         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
11904         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
11905                                 "character special file (null)"
11906         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
11907                                 "character special file (no device)"
11908         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
11909         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
11910                                 "block special file (loop)"
11911         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
11912         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
11913         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
11914 }
11915 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
11916
11917 # LU-1299 Executing or running ldd on a truncated executable does not
11918 # cause an out-of-memory condition.
11919 test_227() {
11920         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11921         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
11922         dd if=$(which date) of=$MOUNT/date bs=1k count=1
11923         chmod +x $MOUNT/date
11924
11925         $MOUNT/date > /dev/null
11926         ldd $MOUNT/date > /dev/null
11927         rm -f $MOUNT/date
11928 }
11929 run_test 227 "running truncated executable does not cause OOM"
11930
11931 # LU-1512 try to reuse idle OI blocks
11932 test_228a() {
11933         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11934         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11935         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11936                 skip "non-ldiskfs backend" && return
11937
11938         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11939         local myDIR=$DIR/$tdir
11940
11941         mkdir -p $myDIR
11942         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11943         $LCTL set_param fail_loc=0x80001002
11944         createmany -o $myDIR/t- 10000
11945         $LCTL set_param fail_loc=0
11946         # The guard is current the largest FID holder
11947         touch $myDIR/guard
11948         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11949                     tr -d '[')
11950         local IDX=$(($SEQ % 64))
11951
11952         do_facet $SINGLEMDS sync
11953         # Make sure journal flushed.
11954         sleep 6
11955         local blk1=$(do_facet $SINGLEMDS \
11956                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11957                      grep Blockcount | awk '{print $4}')
11958
11959         # Remove old files, some OI blocks will become idle.
11960         unlinkmany $myDIR/t- 10000
11961         # Create new files, idle OI blocks should be reused.
11962         createmany -o $myDIR/t- 2000
11963         do_facet $SINGLEMDS sync
11964         # Make sure journal flushed.
11965         sleep 6
11966         local blk2=$(do_facet $SINGLEMDS \
11967                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11968                      grep Blockcount | awk '{print $4}')
11969
11970         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11971 }
11972 run_test 228a "try to reuse idle OI blocks"
11973
11974 test_228b() {
11975         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11976         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11977         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11978                 skip "non-ldiskfs backend" && return
11979
11980         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11981         local myDIR=$DIR/$tdir
11982
11983         mkdir -p $myDIR
11984         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11985         $LCTL set_param fail_loc=0x80001002
11986         createmany -o $myDIR/t- 10000
11987         $LCTL set_param fail_loc=0
11988         # The guard is current the largest FID holder
11989         touch $myDIR/guard
11990         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11991                     tr -d '[')
11992         local IDX=$(($SEQ % 64))
11993
11994         do_facet $SINGLEMDS sync
11995         # Make sure journal flushed.
11996         sleep 6
11997         local blk1=$(do_facet $SINGLEMDS \
11998                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11999                      grep Blockcount | awk '{print $4}')
12000
12001         # Remove old files, some OI blocks will become idle.
12002         unlinkmany $myDIR/t- 10000
12003
12004         # stop the MDT
12005         stop $SINGLEMDS || error "Fail to stop MDT."
12006         # remount the MDT
12007         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
12008
12009         df $MOUNT || error "Fail to df."
12010         # Create new files, idle OI blocks should be reused.
12011         createmany -o $myDIR/t- 2000
12012         do_facet $SINGLEMDS sync
12013         # Make sure journal flushed.
12014         sleep 6
12015         local blk2=$(do_facet $SINGLEMDS \
12016                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12017                      grep Blockcount | awk '{print $4}')
12018
12019         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12020 }
12021 run_test 228b "idle OI blocks can be reused after MDT restart"
12022
12023 #LU-1881
12024 test_228c() {
12025         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12026         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12027         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12028                 skip "non-ldiskfs backend" && return
12029
12030         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12031         local myDIR=$DIR/$tdir
12032
12033         mkdir -p $myDIR
12034         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12035         $LCTL set_param fail_loc=0x80001002
12036         # 20000 files can guarantee there are index nodes in the OI file
12037         createmany -o $myDIR/t- 20000
12038         $LCTL set_param fail_loc=0
12039         # The guard is current the largest FID holder
12040         touch $myDIR/guard
12041         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12042                     tr -d '[')
12043         local IDX=$(($SEQ % 64))
12044
12045         do_facet $SINGLEMDS sync
12046         # Make sure journal flushed.
12047         sleep 6
12048         local blk1=$(do_facet $SINGLEMDS \
12049                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12050                      grep Blockcount | awk '{print $4}')
12051
12052         # Remove old files, some OI blocks will become idle.
12053         unlinkmany $myDIR/t- 20000
12054         rm -f $myDIR/guard
12055         # The OI file should become empty now
12056
12057         # Create new files, idle OI blocks should be reused.
12058         createmany -o $myDIR/t- 2000
12059         do_facet $SINGLEMDS sync
12060         # Make sure journal flushed.
12061         sleep 6
12062         local blk2=$(do_facet $SINGLEMDS \
12063                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12064                      grep Blockcount | awk '{print $4}')
12065
12066         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12067 }
12068 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
12069
12070 test_229() { # LU-2482, LU-3448
12071         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
12072                 skip "No HSM support on MDS of $(get_lustre_version)," \
12073                          "need 2.4.53 at least" && return
12074         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12075         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
12076
12077         rm -f $DIR/$tfile
12078
12079         # Create a file with a released layout and stripe count 2.
12080         $MULTIOP $DIR/$tfile H2c ||
12081                 error "failed to create file with released layout"
12082
12083         $GETSTRIPE -v $DIR/$tfile
12084
12085         local pattern=$($GETSTRIPE -L $DIR/$tfile)
12086         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
12087
12088         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
12089         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
12090         stat $DIR/$tfile || error "failed to stat released file"
12091
12092         chown $RUNAS_ID $DIR/$tfile ||
12093                 error "chown $RUNAS_ID $DIR/$tfile failed"
12094
12095         chgrp $RUNAS_ID $DIR/$tfile ||
12096                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12097
12098         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12099         rm $DIR/$tfile || error "failed to remove released file"
12100 }
12101 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12102
12103 test_230a() {
12104         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12105         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12106         local MDTIDX=1
12107
12108         mkdir -p $DIR/$tdir/test_230_local
12109         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12110         [ $mdt_idx -ne 0 ] &&
12111                 error "create local directory on wrong MDT $mdt_idx"
12112
12113         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12114                         error "create remote directory failed"
12115         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12116         [ $mdt_idx -ne $MDTIDX ] &&
12117                 error "create remote directory on wrong MDT $mdt_idx"
12118
12119         createmany -o $DIR/$tdir/test_230/t- 10 ||
12120                 error "create files on remote directory failed"
12121         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12122         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12123         rm -r $DIR/$tdir || error "unlink remote directory failed"
12124 }
12125 run_test 230a "Create remote directory and files under the remote directory"
12126
12127 test_230b() {
12128         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12129         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12130         local MDTIDX=1
12131         local mdt_index
12132         local i
12133         local file
12134         local pid
12135         local stripe_count
12136         local migrate_dir=$DIR/$tdir/migrate_dir
12137         local other_dir=$DIR/$tdir/other_dir
12138
12139         mkdir -p $migrate_dir
12140         mkdir -p $other_dir
12141         for ((i=0; i<10; i++)); do
12142                 mkdir -p $migrate_dir/dir_${i}
12143                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12144                         error "create files under remote dir failed $i"
12145         done
12146
12147         cp /etc/passwd $migrate_dir/$tfile
12148         cp /etc/passwd $other_dir/$tfile
12149         chattr +SAD $migrate_dir
12150         chattr +SAD $migrate_dir/$tfile
12151
12152         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12153         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12154         local old_dir_mode=$(stat -c%f $migrate_dir)
12155         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
12156
12157         mkdir -p $migrate_dir/dir_default_stripe2
12158         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12159         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12160
12161         mkdir -p $other_dir
12162         ln $migrate_dir/$tfile $other_dir/luna
12163         ln $migrate_dir/$tfile $migrate_dir/sofia
12164         ln $other_dir/$tfile $migrate_dir/david
12165         ln -s $migrate_dir/$tfile $other_dir/zachary
12166         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12167         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12168
12169         $LFS mv -v -M $MDTIDX $migrate_dir ||
12170                         error "migrate remote dir error"
12171
12172         echo "migratate to MDT1, then checking.."
12173         for ((i=0; i<10; i++)); do
12174                 for file in $(find $migrate_dir/dir_${i}); do
12175                         mdt_index=$($LFS getstripe -M $file)
12176                         [ $mdt_index == $MDTIDX ] ||
12177                                 error "$file is not on MDT${MDTIDX}"
12178                 done
12179         done
12180
12181         # the multiple link file should still in MDT0
12182         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12183         [ $mdt_index == 0 ] ||
12184                 error "$file is not on MDT${MDTIDX}"
12185
12186         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12187         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12188                 error " expect $old_dir_flag get $new_dir_flag"
12189
12190         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12191         [ "$old_file_flag" = "$new_file_flag" ] ||
12192                 error " expect $old_file_flag get $new_file_flag"
12193
12194         local new_dir_mode=$(stat -c%f $migrate_dir)
12195         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12196                 error "expect mode $old_dir_mode get $new_dir_mode"
12197
12198         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12199         [ "$old_file_mode" = "$new_file_mode" ] ||
12200                 error "expect mode $old_file_mode get $new_file_mode"
12201
12202         diff /etc/passwd $migrate_dir/$tfile ||
12203                 error "$tfile different after migration"
12204
12205         diff /etc/passwd $other_dir/luna ||
12206                 error "luna different after migration"
12207
12208         diff /etc/passwd $migrate_dir/sofia ||
12209                 error "sofia different after migration"
12210
12211         diff /etc/passwd $migrate_dir/david ||
12212                 error "david different after migration"
12213
12214         diff /etc/passwd $other_dir/zachary ||
12215                 error "zachary different after migration"
12216
12217         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12218                 error "${tfile}_ln different after migration"
12219
12220         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12221                 error "${tfile}_ln_other different after migration"
12222
12223         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12224         [ $stripe_count = 2 ] ||
12225                         error "dir strpe_count $d != 2 after migration."
12226
12227         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12228         [ $stripe_count = 2 ] ||
12229                         error "file strpe_count $d != 2 after migration."
12230
12231         #migrate back to MDT0
12232         MDTIDX=0
12233         $LFS mv -v -M $MDTIDX $migrate_dir ||
12234                         error "migrate remote dir error"
12235
12236         echo "migrate back to MDT0, checking.."
12237         for file in $(find $migrate_dir); do
12238                 mdt_index=$($LFS getstripe -M $file)
12239                 [ $mdt_index == $MDTIDX ] ||
12240                         error "$file is not on MDT${MDTIDX}"
12241         done
12242
12243         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12244         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12245                 error " expect $old_dir_flag get $new_dir_flag"
12246
12247         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12248         [ "$old_file_flag" = "$new_file_flag" ] ||
12249                 error " expect $old_file_flag get $new_file_flag"
12250
12251         local new_dir_mode=$(stat -c%f $migrate_dir)
12252         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12253                 error "expect mode $old_dir_mode get $new_dir_mode"
12254
12255         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12256         [ "$old_file_mode" = "$new_file_mode" ] ||
12257                 error "expect mode $old_file_mode get $new_file_mode"
12258
12259         diff /etc/passwd ${migrate_dir}/$tfile ||
12260                 error "$tfile different after migration"
12261
12262         diff /etc/passwd ${other_dir}/luna ||
12263                 error "luna different after migration"
12264
12265         diff /etc/passwd ${migrate_dir}/sofia ||
12266                 error "sofia different after migration"
12267
12268         diff /etc/passwd ${other_dir}/zachary ||
12269                 error "zachary different after migration"
12270
12271         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12272                 error "${tfile}_ln different after migration"
12273
12274         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12275                 error "${tfile}_ln_other different after migration"
12276
12277         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12278         [ $stripe_count = 2 ] ||
12279                 error "dir strpe_count $d != 2 after migration."
12280
12281         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12282         [ $stripe_count = 2 ] ||
12283                 error "file strpe_count $d != 2 after migration."
12284
12285         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12286 }
12287 run_test 230b "migrate directory"
12288
12289 test_230c() {
12290         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12291         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12292         local MDTIDX=1
12293         local mdt_index
12294         local file
12295
12296         #If migrating directory fails in the middle, all entries of
12297         #the directory is still accessiable.
12298         mkdir -p $DIR/$tdir
12299         stat $DIR/$tdir
12300         createmany -o $DIR/$tdir/f 10 ||
12301                 error "create files under ${tdir} failed"
12302
12303         #failed after migrating 5 entries
12304         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12305         do_facet mds1 lctl set_param fail_loc=0x20001801
12306         do_facet mds1 lctl  set_param fail_val=5
12307         local t=`ls $DIR/$tdir | wc -l`
12308         $LFS mv -M $MDTIDX $DIR/$tdir &&
12309                 error "migrate should failed after 5 entries"
12310         local u=`ls $DIR/$tdir | wc -l`
12311         [ "$u" == "$t" ] || error "$u != $t during migration"
12312
12313         for file in $(find $DIR/$tdir); do
12314                 stat $file || error "stat $file failed"
12315         done
12316
12317         do_facet mds1 lctl set_param fail_loc=0
12318         do_facet mds1 lctl set_param fail_val=0
12319
12320         $LFS mv -M $MDTIDX $DIR/$tdir ||
12321                 error "migrate open files should failed with open files"
12322
12323         echo "Finish migration, then checking.."
12324         for file in $(find $DIR/$tdir); do
12325                 mdt_index=$($LFS getstripe -M $file)
12326                 [ $mdt_index == $MDTIDX ] ||
12327                         error "$file is not on MDT${MDTIDX}"
12328         done
12329
12330         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12331 }
12332 run_test 230c "check directory accessiblity if migration is failed"
12333
12334 test_230d() {
12335         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12336         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12337         local MDTIDX=1
12338         local mdt_index
12339         local i
12340         local j
12341
12342         mkdir -p $DIR/$tdir
12343
12344         for ((i=0; i<100; i++)); do
12345                 mkdir -p $DIR/$tdir/dir_${i}
12346                 createmany -o $DIR/$tdir/dir_${i}/f 100 ||
12347                         error "create files under remote dir failed $i"
12348         done
12349
12350         $LFS mv -M $MDTIDX -v $DIR/$tdir || error "migrate remote dir error"
12351
12352         echo "Finish migration, then checking.."
12353         for file in $(find $DIR/$tdir); do
12354                 mdt_index=$($LFS getstripe -M $file)
12355                 [ $mdt_index == $MDTIDX ] ||
12356                         error "$file is not on MDT${MDTIDX}"
12357         done
12358
12359         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12360 }
12361 run_test 230d "check migrate big directory"
12362
12363 test_231a()
12364 {
12365         # For simplicity this test assumes that max_pages_per_rpc
12366         # is the same across all OSCs
12367         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
12368         local bulk_size=$((max_pages * 4096))
12369
12370         mkdir -p $DIR/$tdir
12371
12372         # clear the OSC stats
12373         $LCTL set_param osc.*.stats=0 &>/dev/null
12374
12375         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
12376         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
12377                 oflag=direct &>/dev/null || error "dd failed"
12378
12379         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
12380         if [ x$nrpcs != "x1" ]; then
12381                 error "found $nrpc ost_write RPCs, not 1 as expected"
12382         fi
12383
12384         # Drop the OSC cache, otherwise we will read from it
12385         cancel_lru_locks osc
12386
12387         # clear the OSC stats
12388         $LCTL set_param osc.*.stats=0 &>/dev/null
12389
12390         # Client reads $bulk_size.
12391         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
12392                 iflag=direct &>/dev/null || error "dd failed"
12393
12394         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
12395         if [ x$nrpcs != "x1" ]; then
12396                 error "found $nrpc ost_read RPCs, not 1 as expected"
12397         fi
12398 }
12399 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
12400
12401 test_231b() {
12402         mkdir -p $DIR/$tdir
12403         local i
12404         for i in {0..1023}; do
12405                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
12406                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
12407                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
12408         done
12409         sync
12410 }
12411 run_test 231b "must not assert on fully utilized OST request buffer"
12412
12413 test_232() {
12414         mkdir -p $DIR/$tdir
12415         #define OBD_FAIL_LDLM_OST_LVB            0x31c
12416         $LCTL set_param fail_loc=0x31c
12417
12418         # ignore dd failure
12419         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
12420
12421         $LCTL set_param fail_loc=0
12422         umount_client $MOUNT || error "umount failed"
12423         mount_client $MOUNT || error "mount failed"
12424 }
12425 run_test 232 "failed lock should not block umount"
12426
12427 test_233a() {
12428         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
12429         { skip "Need MDS version at least 2.3.64"; return; }
12430
12431         local fid=$($LFS path2fid $MOUNT)
12432         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12433                 error "cannot access $MOUNT using its FID '$fid'"
12434 }
12435 run_test 233a "checking that OBF of the FS root succeeds"
12436
12437 test_233b() {
12438         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
12439         { skip "Need MDS version at least 2.5.90"; return; }
12440
12441         local fid=$($LFS path2fid $MOUNT/.lustre)
12442         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12443                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
12444
12445         fid=$($LFS path2fid $MOUNT/.lustre/fid)
12446         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12447                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
12448 }
12449 run_test 233b "checking that OBF of the FS .lustre succeeds"
12450
12451 test_234() {
12452         local p="$TMP/sanityN-$TESTNAME.parameters"
12453         save_lustre_params client "llite.*.xattr_cache" > $p
12454         lctl set_param llite.*.xattr_cache 1 ||
12455                 { skip "xattr cache is not supported"; return 0; }
12456
12457         mkdir -p $DIR/$tdir || error "mkdir failed"
12458         touch $DIR/$tdir/$tfile || error "touch failed"
12459         # OBD_FAIL_LLITE_XATTR_ENOMEM
12460         $LCTL set_param fail_loc=0x1405
12461         if [ ! -f /etc/SuSE-release ]; then
12462                 # attr pre-2.4.44-7 had a bug with rc
12463                 # LU-3703 - SLES clients have older attr
12464                 getfattr -n user.attr $DIR/$tdir/$tfile &&
12465                         error "getfattr should have failed with ENOMEM"
12466         fi
12467         $LCTL set_param fail_loc=0x0
12468         rm -rf $DIR/$tdir
12469
12470         restore_lustre_params < $p
12471         rm -f $p
12472 }
12473 run_test 234 "xattr cache should not crash on ENOMEM"
12474
12475 test_235() {
12476         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
12477                 skip "Need MDS version at least 2.4.52" && return
12478         flock_deadlock $DIR/$tfile
12479         local RC=$?
12480         case $RC in
12481                 0)
12482                 ;;
12483                 124) error "process hangs on a deadlock"
12484                 ;;
12485                 *) error "error executing flock_deadlock $DIR/$tfile"
12486                 ;;
12487         esac
12488 }
12489 run_test 235 "LU-1715: flock deadlock detection does not work properly"
12490
12491 #LU-2935
12492 test_236() {
12493         check_swap_layouts_support && return 0
12494         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
12495
12496         local ref1=/etc/passwd
12497         local ref2=/etc/group
12498         local file1=$DIR/$tdir/f1
12499         local file2=$DIR/$tdir/f2
12500
12501         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
12502         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
12503         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
12504         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
12505         local fd=$(free_fd)
12506         local cmd="exec $fd<>$file2"
12507         eval $cmd
12508         rm $file2
12509         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
12510                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
12511         cmd="exec $fd>&-"
12512         eval $cmd
12513         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12514
12515         #cleanup
12516         rm -rf $DIR/$tdir
12517 }
12518 run_test 236 "Layout swap on open unlinked file"
12519
12520 # test to verify file handle related system calls
12521 # (name_to_handle_at/open_by_handle_at)
12522 # The new system calls are supported in glibc >= 2.14.
12523
12524 test_237() {
12525         echo "Test file_handle syscalls" > $DIR/$tfile ||
12526                 error "write failed"
12527         check_fhandle_syscalls $DIR/$tfile ||
12528                 error "check_fhandle_syscalls failed"
12529 }
12530 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
12531
12532 # LU-4659 linkea consistency
12533 test_238() {
12534         local server_version=$(lustre_version_code $SINGLEMDS)
12535
12536         [[ $server_version -gt $(version_code 2.5.57) ]] ||
12537                 [[ $server_version -gt $(version_code 2.5.1) &&
12538                    $server_version -lt $(version_code 2.5.50) ]] ||
12539                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
12540
12541         touch $DIR/$tfile
12542         ln $DIR/$tfile $DIR/$tfile.lnk
12543         touch $DIR/$tfile.new
12544         mv $DIR/$tfile.new $DIR/$tfile
12545         local fid1=$(lfs path2fid $DIR/$tfile)
12546         local fid2=$(lfs path2fid $DIR/$tfile.lnk)
12547         local path1=$(lfs fid2path $FSNAME $fid1)
12548         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
12549         local path2=$(lfs fid2path $FSNAME $fid2)
12550         [ $tfile.lnk == $path2 ] ||
12551                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
12552         rm -f $DIR/$tfile*
12553 }
12554 run_test 238 "Verify linkea consistency"
12555
12556 test_239() {
12557         local list=$(comma_list $(mdts_nodes))
12558
12559         mkdir -p $DIR/$tdir
12560         createmany -o $DIR/$tdir/f- 5000
12561         unlinkmany $DIR/$tdir/f- 5000
12562         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
12563         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
12564                         osc.*MDT*.sync_in_flight" | calc_sum)
12565         [ "$changes" -eq 0 ] || error "$changes not synced"
12566 }
12567 run_test 239 "osp_sync test"
12568
12569 test_240() {
12570         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12571
12572         mkdir -p $DIR/$tdir
12573
12574         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
12575                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
12576         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
12577                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
12578
12579         umount_client $MOUNT || error "umount failed"
12580         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
12581         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
12582         mount_client $MOUNT || error "failed to mount client"
12583
12584         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
12585         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
12586 }
12587 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
12588
12589 test_241_bio() {
12590         for LOOP in $(seq $1); do
12591                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
12592                 cancel_lru_locks osc
12593         done
12594 }
12595
12596 test_241_dio() {
12597         for LOOP in $(seq $1); do
12598                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
12599                                                 iflag=direct 2>/dev/null
12600         done
12601 }
12602
12603 test_241() {
12604         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
12605         ls -la $DIR/$tfile
12606         cancel_lru_locks osc
12607         test_241_bio 1000 &
12608         PID=$!
12609         test_241_dio 1000
12610         wait $PID
12611 }
12612 run_test 241 "bio vs dio"
12613
12614 cleanup_test_300() {
12615         trap 0
12616         umask $SAVE_UMASK
12617 }
12618 test_striped_dir() {
12619         local mdt_index=$1
12620         local stripe_count
12621         local stripe_index
12622
12623         mkdir -p $DIR/$tdir
12624
12625         SAVE_UMASK=$(umask)
12626         trap cleanup_test_300 RETURN EXIT
12627
12628         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
12629                                                 $DIR/$tdir/striped_dir ||
12630                 error "set striped dir error"
12631
12632         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
12633         [ "$mode" = "755" ] || error "expect 755 got $mode"
12634
12635         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
12636         if [ "$stripe_count" != "2" ]; then
12637                 error "stripe_count is $stripe_count, expect 2"
12638         fi
12639
12640         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
12641         if [ "$stripe_index" != "$mdt_index" ]; then
12642                 error "stripe_index is $stripe_index, expect $mdt_index"
12643         fi
12644
12645         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12646                 error "nlink error after create striped dir"
12647
12648         mkdir $DIR/$tdir/striped_dir/a
12649         mkdir $DIR/$tdir/striped_dir/b
12650
12651         stat $DIR/$tdir/striped_dir/a ||
12652                 error "create dir under striped dir failed"
12653         stat $DIR/$tdir/striped_dir/b ||
12654                 error "create dir under striped dir failed"
12655
12656         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
12657                 error "nlink error after mkdir"
12658
12659         rmdir $DIR/$tdir/striped_dir/a
12660         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
12661                 error "nlink error after rmdir"
12662
12663         rmdir $DIR/$tdir/striped_dir/b
12664         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12665                 error "nlink error after rmdir"
12666
12667         rmdir $DIR/$tdir/striped_dir ||
12668                 error "rmdir striped dir error"
12669
12670         cleanup_test_300
12671
12672         true
12673 }
12674
12675 test_300a() {
12676         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12677         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12678
12679         test_striped_dir 0 || error "failed on striped dir on MDT0"
12680         test_striped_dir 1 || error "failed on striped dir on MDT0"
12681 }
12682 run_test 300a "basic striped dir sanity test"
12683
12684 test_300b() {
12685         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12686         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12687         local i
12688         local mtime1
12689         local mtime2
12690         local mtime3
12691
12692         test_mkdir $DIR/$tdir || error "mkdir fail"
12693         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12694                 error "set striped dir error"
12695         for ((i=0; i<10; i++)); do
12696                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
12697                 sleep 1
12698                 touch $DIR/$tdir/striped_dir/file_$i ||
12699                                         error "touch error $i"
12700                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
12701                 [ $mtime1 -eq $mtime2 ] &&
12702                         error "mtime not change after create"
12703                 sleep 1
12704                 rm -f $DIR/$tdir/striped_dir/file_$i ||
12705                                         error "unlink error $i"
12706                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
12707                 [ $mtime2 -eq $mtime3 ] &&
12708                         error "mtime did not change after unlink"
12709         done
12710         true
12711 }
12712 run_test 300b "check ctime/mtime for striped dir"
12713
12714 test_300c() {
12715         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12716         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12717         local file_count
12718
12719         mkdir -p $DIR/$tdir
12720         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
12721                 error "set striped dir error"
12722
12723         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
12724                 error "chown striped dir failed"
12725
12726         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
12727                 error "create 5k files failed"
12728
12729         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
12730
12731         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
12732
12733         rm -rf $DIR/$tdir
12734 }
12735 run_test 300c "chown && check ls under striped directory"
12736
12737 test_300d() {
12738         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12739         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12740         local stripe_count
12741         local file
12742
12743         mkdir -p $DIR/$tdir
12744         $SETSTRIPE -c 2 $DIR/$tdir
12745
12746         #local striped directory
12747         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12748                 error "set striped dir error"
12749         createmany -o $DIR/$tdir/striped_dir/f 10 ||
12750                 error "create 10 files failed"
12751
12752         #remote striped directory
12753         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
12754                 error "set striped dir error"
12755         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
12756                 error "create 10 files failed"
12757
12758         for file in $(find $DIR/$tdir); do
12759                 stripe_count=$($GETSTRIPE -c $file)
12760                 [ $stripe_count -eq 2 ] ||
12761                         error "wrong stripe $stripe_count for $file"
12762         done
12763
12764         rm -rf $DIR/$tdir
12765 }
12766 run_test 300d "check default stripe under striped directory"
12767
12768 test_300e() {
12769         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12770         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12771         local stripe_count
12772         local file
12773
12774         mkdir -p $DIR/$tdir
12775
12776         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12777                 error "set striped dir error"
12778
12779         touch $DIR/$tdir/striped_dir/a
12780         touch $DIR/$tdir/striped_dir/b
12781         touch $DIR/$tdir/striped_dir/c
12782
12783         mkdir $DIR/$tdir/striped_dir/dir_a
12784         mkdir $DIR/$tdir/striped_dir/dir_b
12785         mkdir $DIR/$tdir/striped_dir/dir_c
12786
12787         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
12788                 error "set striped dir under striped dir error"
12789
12790         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
12791                 error "set striped dir under striped dir error"
12792
12793         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
12794                 error "set striped dir under striped dir error"
12795
12796         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/b &&
12797                 error "rename file under striped dir should fail"
12798
12799         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b &&
12800                 error "rename dir under striped dir should fail"
12801
12802         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b &&
12803                 error "rename dir under different stripes should fail"
12804
12805         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
12806                 error "rename file under striped dir should succeed"
12807
12808         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_c ||
12809                 error "rename dir under striped dir should succeed"
12810
12811         rm -rf $DIR/$tdir
12812 }
12813 run_test 300e "check rename under striped directory"
12814
12815 test_300f() {
12816         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12817         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12818         local stripe_count
12819         local file
12820
12821         rm -rf $DIR/$tdir
12822         mkdir -p $DIR/$tdir
12823
12824         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12825                 error "set striped dir error"
12826
12827         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
12828                 error "set striped dir error"
12829
12830         touch $DIR/$tdir/striped_dir/a
12831         mkdir $DIR/$tdir/striped_dir/dir_a
12832         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
12833                 error "create striped dir under striped dir fails"
12834
12835         touch $DIR/$tdir/striped_dir1/b
12836         mkdir $DIR/$tdir/striped_dir1/dir_b
12837         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
12838                 error "create striped dir under striped dir fails"
12839
12840         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/b &&
12841                 error "rename file under different striped dir should fail"
12842
12843         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b &&
12844                 error "rename dir under different striped dir should fail"
12845
12846         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b &&
12847                 error "rename striped dir under diff striped dir should fail"
12848
12849         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
12850                 error "rename file under diff striped dirs fails"
12851
12852         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_a ||
12853                 error "rename dir under diff striped dirs fails"
12854
12855         rm -rf $DIR/$tdir
12856 }
12857 run_test 300f "check rename cross striped directory"
12858
12859 test_300g() {
12860         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12861         local stripe_count
12862         local dir
12863
12864         mkdir $DIR/$tdir
12865         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
12866                                         $DIR/$tdir/striped_dir ||
12867                 error "set striped dir error"
12868
12869         $LFS setdirstripe -D -c $MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
12870                 error "set default stripe on striped dir error"
12871
12872         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/striped_dir)
12873         [ $stripe_count -eq $MDSCOUNT ] ||
12874                 error "default stripe wrong expect $MDSCOUNT get $stripe_count"
12875
12876         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12877
12878         for dir in $(find $DIR/$tdir/striped_dir/*); do
12879                 stripe_count=$($LFS getdirstripe -c $dir)
12880                 [ $stripe_count -eq $MDSCOUNT ] ||
12881                         error "expect $MDSCOUNT get $stripe_count for $dir"
12882         done
12883
12884         rmdir $DIR/$tdir/striped_dir/* || error "rmdir1 failed"
12885         #change default stripe count to 2
12886         $LFS setdirstripe -D -c 2 -t all_char $DIR/$tdir/striped_dir ||
12887                 error "set default stripe on striped dir error"
12888
12889         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12890
12891         rmdir $DIR/$tdir/striped_dir/* || error "rmdir2 failed"
12892
12893         #change default stripe count to 1
12894         $LFS setdirstripe -D -c 1 -t all_char $DIR/$tdir/striped_dir ||
12895                 error "set default stripe on striped dir error"
12896
12897         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12898         for dir in $(find $DIR/$tdir/striped_dir/*); do
12899                 stripe_count=$($LFS getdirstripe -c $dir)
12900                 [ $stripe_count -eq 1 ] ||
12901                         error "expect 1 get $stripe_count for $dir"
12902         done
12903         rmdir $DIR/$tdir/striped_dir/* || error "rmdir3 failed"
12904 }
12905 run_test 300g "check default striped directory for striped directory"
12906
12907 test_300h() {
12908         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12909         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12910         local stripe_count
12911         local file
12912
12913         mkdir $DIR/$tdir
12914
12915         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
12916                 error "set striped dir error"
12917
12918         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
12919                 error "create files under striped dir failed"
12920
12921         # unfortunately, we need to umount to clear dir layout cache for now
12922         # once we fully implement dir layout, we can drop this
12923         umount_client $MOUNT || error "umount failed"
12924         mount_client $MOUNT || error "mount failed"
12925
12926         #set the stripe to be unknown hash type
12927         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
12928         $LCTL set_param fail_loc=0x1901
12929         for ((i = 0; i < 10; i++)); do
12930                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
12931                         error "stat f-$i failed"
12932                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
12933         done
12934
12935         touch $DIR/$tdir/striped_dir/f0 &&
12936                 error "create under striped dir with unknown hash should fail"
12937
12938         $LCTL set_param fail_loc=0
12939
12940         umount_client $MOUNT || error "umount failed"
12941         mount_client $MOUNT || error "mount failed"
12942
12943         return 0
12944 }
12945 run_test 300h "client handle unknown hash type striped directory"
12946
12947 test_400a() { # LU-1606, was conf-sanity test_74
12948         local extra_flags=''
12949         local out=$TMP/$tfile
12950         local prefix=/usr/include/lustre
12951         local prog
12952
12953         if ! which $CC > /dev/null 2>&1; then
12954                 skip_env "$CC is not installed"
12955                 return 0
12956         fi
12957
12958         if ! [[ -d $prefix ]]; then
12959                 # Assume we're running in tree and fixup the include path.
12960                 extra_flags+=" -I$LUSTRE/../libcfs/include"
12961                 extra_flags+=" -I$LUSTRE/include"
12962                 extra_flags+=" -L$LUSTRE/utils"
12963         fi
12964
12965         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
12966                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
12967                         error "client api broken"
12968         done
12969 }
12970 run_test 400a "Lustre client api program can compile and link"
12971
12972 test_400b() { # LU-1606, LU-5011
12973         local header
12974         local out=$TMP/$tfile
12975         local prefix=/usr/include/lustre
12976
12977         # We use a hard coded prefix so that this test will not fail
12978         # when run in tree. There are headers in lustre/include/lustre/
12979         # that are not packaged (like lustre_idl.h) and have more
12980         # complicated include dependencies (like config.h and lnet/types.h).
12981         # Since this test about correct packaging we just skip them when
12982         # they don't exist (see below) rather than try to fixup cppflags.
12983
12984         if ! which $CC > /dev/null 2>&1; then
12985                 skip_env "$CC is not installed"
12986                 return 0
12987         fi
12988
12989         for header in $prefix/*.h; do
12990                 if ! [[ -f "$header" ]]; then
12991                         continue
12992                 fi
12993
12994                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
12995                         continue # liblustreapi.h is deprecated.
12996                 fi
12997
12998                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
12999                         error "cannot compile '$header'"
13000         done
13001 }
13002 run_test 400b "packaged headers can be compiled"
13003
13004 #
13005 # tests that do cleanup/setup should be run at the end
13006 #
13007
13008 test_900() {
13009         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13010         local ls
13011         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
13012         $LCTL set_param fail_loc=0x903
13013
13014         cancel_lru_locks MGC
13015
13016         FAIL_ON_ERROR=true cleanup
13017         FAIL_ON_ERROR=true setup
13018 }
13019 run_test 900 "umount should not race with any mgc requeue thread"
13020
13021 complete $SECONDS
13022 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
13023 check_and_cleanup_lustre
13024 if [ "$I_MOUNTED" != "yes" ]; then
13025         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
13026 fi
13027 exit_status