Whamcloud - gitweb
LU-5641 tests: ensure user daemon is in group bin
[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-2833 LU-1957 LU-2805
65         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 34h     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 || error "start failed"
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                         error "mount mds${mdt_index} failed"
633                 df $MOUNT > /dev/null 2>&1
634                 [ $rc -ne 0 ] && break
635         done
636         return $rc
637 }
638
639 test_17n() {
640         local i
641
642         remote_mds_nodsh && skip "remote MDS with nodsh" && return
643         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
644         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
645                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
646
647         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
648                 skip "only for ldiskfs MDT" && return 0
649
650         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
651
652         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
653
654         mkdir $DIR/$tdir
655         for ((i=0; i<10; i++)); do
656                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
657                         error "create remote dir error $i"
658                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
659                         error "create files under remote dir failed $i"
660         done
661
662         check_fs_consistency_17n ||
663                 error "e2fsck report error after create files under remote dir"
664
665         for ((i=0;i<10;i++)); do
666                 rm -rf $DIR/$tdir/remote_dir_${i} ||
667                         error "destroy remote dir error $i"
668         done
669
670         check_fs_consistency_17n ||
671                 error "e2fsck report error after unlink files under remote dir"
672
673         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
674                 skip "lustre < 2.4.50 does not support migrate mv " && return
675
676         for ((i=0; i<10; i++)); do
677                 mkdir -p $DIR/$tdir/remote_dir_${i}
678                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
679                         error "create files under remote dir failed $i"
680                 $LFS mv -M 1 $DIR/$tdir/remote_dir_${i} ||
681                         error "migrate remote dir error $i"
682         done
683         check_fs_consistency_17n || error "e2fsck report error after migration"
684
685         for ((i=0;i<10;i++)); do
686                 rm -rf $DIR/$tdir/remote_dir_${i} ||
687                         error "destroy remote dir error $i"
688         done
689
690         check_fs_consistency_17n || error "e2fsck report error after unlink"
691 }
692 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
693
694 test_17o() {
695         remote_mds_nodsh && skip "remote MDS with nodsh" && return
696         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
697                 skip "Need MDS version at least 2.3.64" && return
698
699         local WDIR=$DIR/${tdir}o
700         local mdt_index
701         local mdtdevname
702         local rc=0
703
704         mkdir -p $WDIR
705         mdt_index=$($LFS getstripe -M $WDIR)
706         mdt_index=$((mdt_index+1))
707         mdtdevname=$(mdsdevname $mdt_index)
708
709         touch $WDIR/$tfile
710         stop mds${mdt_index}
711         start mds${mdt_index} $mdtdevname $MDS_MOUNT_OPTS ||
712                 error "mount mds${mdt_index} failed"
713
714         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
715         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
716         ls -l $WDIR/$tfile && rc=1
717         do_facet mds${mdt_index} lctl set_param fail_loc=0
718         [[ $rc -ne 0 ]] && error "stat file should fail"
719         true
720 }
721 run_test 17o "stat file with incompat LMA feature"
722
723 test_18() {
724         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
725         ls $DIR || error "Failed to ls $DIR: $?"
726 }
727 run_test 18 "touch .../f ; ls ... =============================="
728
729 test_19a() {
730         touch $DIR/$tfile
731         ls -l $DIR
732         rm $DIR/$tfile
733         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
734 }
735 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
736
737 test_19b() {
738         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
739 }
740 run_test 19b "ls -l .../f19 (should return error) =============="
741
742 test_19c() {
743         [ $RUNAS_ID -eq $UID ] &&
744                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
745         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
746 }
747 run_test 19c "$RUNAS touch .../f19 (should return error) =="
748
749 test_19d() {
750         cat $DIR/f19 && error || true
751 }
752 run_test 19d "cat .../f19 (should return error) =============="
753
754 test_20() {
755         touch $DIR/$tfile
756         rm $DIR/$tfile
757         log "1 done"
758         touch $DIR/$tfile
759         rm $DIR/$tfile
760         log "2 done"
761         touch $DIR/$tfile
762         rm $DIR/$tfile
763         log "3 done"
764         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
765 }
766 run_test 20 "touch .../f ; ls -l ... ==========================="
767
768 test_21() {
769         test_mkdir -p $DIR/$tdir
770         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
771         ln -s dangle $DIR/$tdir/link
772         echo foo >> $DIR/$tdir/link
773         cat $DIR/$tdir/dangle
774         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
775         $CHECKSTAT -f -t file $DIR/$tdir/link ||
776                 error "$tdir/link not linked to a file"
777 }
778 run_test 21 "write to dangling link ============================"
779
780 test_22() {
781         WDIR=$DIR/$tdir
782         test_mkdir -p $DIR/$tdir
783         chown $RUNAS_ID:$RUNAS_GID $WDIR
784         (cd $WDIR || error "cd $WDIR failed";
785         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
786         $RUNAS tar xf -)
787         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
788         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
789         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
790 }
791 run_test 22 "unpack tar archive as non-root user ==============="
792
793 # was test_23
794 test_23a() {
795         test_mkdir -p $DIR/$tdir
796         local file=$DIR/$tdir/$tfile
797
798         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
799         openfile -f O_CREAT:O_EXCL $file &&
800                 error "$file recreate succeeded" || true
801 }
802 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
803
804 test_23b() { # bug 18988
805         test_mkdir -p $DIR/$tdir
806         local file=$DIR/$tdir/$tfile
807
808         rm -f $file
809         echo foo > $file || error "write filed"
810         echo bar >> $file || error "append filed"
811         $CHECKSTAT -s 8 $file || error "wrong size"
812         rm $file
813 }
814 run_test 23b "O_APPEND check =========================="
815
816 # rename sanity
817 test_24a() {
818         echo '-- same directory rename'
819         test_mkdir $DIR/$tdir
820         touch $DIR/$tdir/$tfile.1
821         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
822         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
823 }
824 run_test 24a "rename file to non-existent target"
825
826 test_24b() {
827         test_mkdir $DIR/$tdir
828         touch $DIR/$tdir/$tfile.{1,2}
829         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
830         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
831         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
832 }
833 run_test 24b "rename file to existing target"
834
835 test_24c() {
836         test_mkdir $DIR/$tdir
837         test_mkdir $DIR/$tdir/d$testnum.1
838         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
839         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
840         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
841 }
842 run_test 24c "rename directory to non-existent target"
843
844 test_24d() {
845         test_mkdir -c1 $DIR/$tdir
846         test_mkdir -c1 $DIR/$tdir/d$testnum.1
847         test_mkdir -c1 $DIR/$tdir/d$testnum.2
848         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
849         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
850         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
851 }
852 run_test 24d "rename directory to existing target"
853
854 test_24e() {
855         echo '-- cross directory renames --'
856         test_mkdir $DIR/R5a
857         test_mkdir $DIR/R5b
858         touch $DIR/R5a/f
859         mv $DIR/R5a/f $DIR/R5b/g
860         $CHECKSTAT -a $DIR/R5a/f || error
861         $CHECKSTAT -t file $DIR/R5b/g || error
862 }
863 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
864
865 test_24f() {
866         test_mkdir $DIR/R6a
867         test_mkdir $DIR/R6b
868         touch $DIR/R6a/f $DIR/R6b/g
869         mv $DIR/R6a/f $DIR/R6b/g
870         $CHECKSTAT -a $DIR/R6a/f || error
871         $CHECKSTAT -t file $DIR/R6b/g || error
872 }
873 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
874
875 test_24g() {
876         test_mkdir $DIR/R7a
877         test_mkdir $DIR/R7b
878         test_mkdir $DIR/R7a/d
879         mv $DIR/R7a/d $DIR/R7b/e
880         $CHECKSTAT -a $DIR/R7a/d || error
881         $CHECKSTAT -t dir $DIR/R7b/e || error
882 }
883 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
884
885 test_24h() {
886         test_mkdir -c1 $DIR/R8a
887         test_mkdir -c1 $DIR/R8b
888         test_mkdir -c1 $DIR/R8a/d
889         test_mkdir -c1 $DIR/R8b/e
890         mrename $DIR/R8a/d $DIR/R8b/e
891         $CHECKSTAT -a $DIR/R8a/d || error
892         $CHECKSTAT -t dir $DIR/R8b/e || error
893 }
894 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
895
896 test_24i() {
897         echo "-- rename error cases"
898         test_mkdir $DIR/R9
899         test_mkdir $DIR/R9/a
900         touch $DIR/R9/f
901         mrename $DIR/R9/f $DIR/R9/a
902         $CHECKSTAT -t file $DIR/R9/f || error
903         $CHECKSTAT -t dir  $DIR/R9/a || error
904         $CHECKSTAT -a $DIR/R9/a/f || error
905 }
906 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
907
908 test_24j() {
909         test_mkdir $DIR/R10
910         mrename $DIR/R10/f $DIR/R10/g
911         $CHECKSTAT -t dir $DIR/R10 || error
912         $CHECKSTAT -a $DIR/R10/f || error
913         $CHECKSTAT -a $DIR/R10/g || error
914 }
915 run_test 24j "source does not exist ============================"
916
917 test_24k() {
918         test_mkdir $DIR/R11a
919         test_mkdir $DIR/R11a/d
920         touch $DIR/R11a/f
921         mv $DIR/R11a/f $DIR/R11a/d
922         $CHECKSTAT -a $DIR/R11a/f || error
923         $CHECKSTAT -t file $DIR/R11a/d/f || error
924 }
925 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
926
927 # bug 2429 - rename foo foo foo creates invalid file
928 test_24l() {
929         f="$DIR/f24l"
930         $MULTIOP $f OcNs || error
931 }
932 run_test 24l "Renaming a file to itself ========================"
933
934 test_24m() {
935         f="$DIR/f24m"
936         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
937         # on ext3 this does not remove either the source or target files
938         # though the "expected" operation would be to remove the source
939         $CHECKSTAT -t file ${f} || error "${f} missing"
940         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
941 }
942 run_test 24m "Renaming a file to a hard link to itself ========="
943
944 test_24n() {
945     f="$DIR/f24n"
946     # this stats the old file after it was renamed, so it should fail
947     touch ${f}
948     $CHECKSTAT ${f}
949     mv ${f} ${f}.rename
950     $CHECKSTAT ${f}.rename
951     $CHECKSTAT -a ${f}
952 }
953 run_test 24n "Statting the old file after renaming (Posix rename 2)"
954
955 test_24o() {
956         check_kernel_version 37 || return 0
957         test_mkdir -p $DIR/d24o
958         rename_many -s random -v -n 10 $DIR/d24o
959 }
960 run_test 24o "rename of files during htree split ==============="
961
962 test_24p() {
963         test_mkdir $DIR/R12a
964         test_mkdir $DIR/R12b
965         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
966         mrename $DIR/R12a $DIR/R12b
967         $CHECKSTAT -a $DIR/R12a || error
968         $CHECKSTAT -t dir $DIR/R12b || error
969         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
970         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
971 }
972 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
973
974 cleanup_multiop_pause() {
975         trap 0
976         kill -USR1 $MULTIPID
977 }
978
979 test_24q() {
980         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
981         test_mkdir $DIR/R13a
982         test_mkdir $DIR/R13b
983         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
984         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
985         MULTIPID=$!
986
987         trap cleanup_multiop_pause EXIT
988         mrename $DIR/R13a $DIR/R13b
989         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
990         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
991         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
992         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
993         cleanup_multiop_pause
994         wait $MULTIPID || error "multiop close failed"
995 }
996 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
997
998 test_24r() { #bug 3789
999         test_mkdir $DIR/R14a
1000         test_mkdir $DIR/R14a/b
1001         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1002         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1003         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1004 }
1005 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1006
1007 test_24s() {
1008         test_mkdir $DIR/R15a
1009         test_mkdir $DIR/R15a/b
1010         test_mkdir $DIR/R15a/b/c
1011         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1012         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1013         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1014 }
1015 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1016 test_24t() {
1017         test_mkdir $DIR/R16a
1018         test_mkdir $DIR/R16a/b
1019         test_mkdir $DIR/R16a/b/c
1020         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1021         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1022         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1023 }
1024 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1025
1026 test_24u() { # bug12192
1027         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1028         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1029 }
1030 run_test 24u "create stripe file"
1031
1032 page_size() {
1033         getconf PAGE_SIZE
1034 }
1035
1036 simple_cleanup_common() {
1037         trap 0
1038         rm -rf $DIR/$tdir
1039         wait_delete_completed
1040 }
1041
1042 max_pages_per_rpc() {
1043         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1044 }
1045
1046 test_24v() {
1047         local NRFILES=100000
1048         local FREE_INODES=$(mdt_free_inodes 0)
1049         [[ $FREE_INODES -lt $NRFILES ]] &&
1050                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1051                 return
1052
1053         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1054         trap simple_cleanup_common EXIT
1055
1056         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1057         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1058
1059         mkdir -p $DIR/$tdir
1060         createmany -m $DIR/$tdir/$tfile $NRFILES
1061
1062         cancel_lru_locks mdc
1063         lctl set_param mdc.*.stats clear
1064
1065         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1066
1067         # LU-5 large readdir
1068         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1069         #               8 bytes for name(filename is mostly 5 in this test) +
1070         #               8 bytes for luda_type
1071         # take into account of overhead in lu_dirpage header and end mark in
1072         # each page, plus one in RPC_NUM calculation.
1073         DIRENT_SIZE=48
1074         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1075         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1076         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1077                                 awk '/^mds_readpage/ {print $2}')
1078         [[ $mds_readpage -gt $RPC_NUM ]] &&
1079                 error "large readdir doesn't take effect"
1080
1081         simple_cleanup_common
1082 }
1083 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1084
1085 test_24w() { # bug21506
1086         SZ1=234852
1087         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1088         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1089         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1090         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1091         [[ "$SZ1" -eq "$SZ2" ]] ||
1092                 error "Error reading at the end of the file $tfile"
1093 }
1094 run_test 24w "Reading a file larger than 4Gb"
1095
1096 test_24x() {
1097         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1098         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1099         local MDTIDX=1
1100         local remote_dir=$DIR/$tdir/remote_dir
1101
1102         mkdir -p $DIR/$tdir
1103         $LFS mkdir -i $MDTIDX $remote_dir ||
1104                 error "create remote directory failed"
1105
1106         mkdir -p $DIR/$tdir/src_dir
1107         touch $DIR/$tdir/src_file
1108         mkdir -p $remote_dir/tgt_dir
1109         touch $remote_dir/tgt_file
1110
1111         mrename $remote_dir $DIR/ &&
1112                 error "rename dir cross MDT works!"
1113
1114         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1115                 error "rename dir cross MDT works!"
1116
1117         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1118                 error "rename file cross MDT works!"
1119
1120         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1121                 error "ln file cross MDT should not work!"
1122
1123         rm -rf $DIR/$tdir || error "Can not delete directories"
1124 }
1125 run_test 24x "cross rename/link should be failed"
1126
1127 test_24y() {
1128         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1129         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1130         local MDTIDX=1
1131         local remote_dir=$DIR/$tdir/remote_dir
1132
1133         mkdir -p $DIR/$tdir
1134         $LFS mkdir -i $MDTIDX $remote_dir ||
1135                    error "create remote directory failed"
1136
1137         mkdir -p $remote_dir/src_dir
1138         touch $remote_dir/src_file
1139         mkdir -p $remote_dir/tgt_dir
1140         touch $remote_dir/tgt_file
1141
1142         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1143                 error "rename subdir in the same remote dir failed!"
1144
1145         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1146                 error "rename files in the same remote dir failed!"
1147
1148         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1149                 error "link files in the same remote dir failed!"
1150
1151         rm -rf $DIR/$tdir || error "Can not delete directories"
1152 }
1153 run_test 24y "rename/link on the same dir should succeed"
1154
1155 test_24z() {
1156         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1157         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1158         local MDTIDX=1
1159         local remote_src=$DIR/$tdir/remote_dir
1160         local remote_tgt=$DIR/$tdir/remote_tgt
1161
1162         mkdir -p $DIR/$tdir
1163         $LFS mkdir -i $MDTIDX $remote_src ||
1164                    error "create remote directory failed"
1165
1166         $LFS mkdir -i $MDTIDX $remote_tgt ||
1167                    error "create remote directory failed"
1168
1169         mrename $remote_src $remote_tgt &&
1170                 error "rename remote dirs should not work!"
1171
1172         # If target dir does not exists, it should succeed
1173         rm -rf $remote_tgt
1174         mrename $remote_src $remote_tgt ||
1175                 error "rename remote dirs(tgt dir does not exists) failed!"
1176
1177         rm -rf $DIR/$tdir || error "Can not delete directories"
1178 }
1179 run_test 24z "rename one remote dir to another remote dir should fail"
1180
1181 test_24A() { # LU-3182
1182         local NFILES=5000
1183
1184         rm -rf $DIR/$tdir
1185         mkdir -p $DIR/$tdir
1186         createmany -m $DIR/$tdir/$tfile $NFILES
1187         local t=$(ls $DIR/$tdir | wc -l)
1188         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1189         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1190         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1191                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1192         fi
1193
1194         rm -rf $DIR/$tdir || error "Can not delete directories"
1195 }
1196 run_test 24A "readdir() returns correct number of entries."
1197
1198 test_24B() { # LU-4805
1199         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1200         local count
1201
1202         mkdir $DIR/$tdir
1203         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1204                 error "create striped dir failed"
1205
1206         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1207         [ $count -eq 2 ] || error "Expected 2, got $count"
1208
1209         touch $DIR/$tdir/striped_dir/a
1210
1211         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1212         [ $count -eq 3 ] || error "Expected 3, got $count"
1213
1214         touch $DIR/$tdir/striped_dir/.f
1215
1216         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1217         [ $count -eq 4 ] || error "Expected 4, got $count"
1218
1219         rm -rf $DIR/$tdir || error "Can not delete directories"
1220 }
1221 run_test 24B "readdir for striped dir return correct number of entries"
1222
1223 test_24C() {
1224         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1225
1226         mkdir $DIR/$tdir
1227         mkdir $DIR/$tdir/d0
1228         mkdir $DIR/$tdir/d1
1229
1230         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1231                 error "create striped dir failed"
1232
1233         cd $DIR/$tdir/d0/striped_dir
1234
1235         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1236         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1237         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1238
1239         [ "$d0_ino" = "$parent_ino" ] ||
1240                 error ".. wrong, expect $d0_ino, get $parent_ino"
1241
1242         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1243                 error "mv striped dir failed"
1244
1245         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1246
1247         [ "$d1_ino" = "$parent_ino" ] ||
1248                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1249 }
1250 run_test 24C "check .. in striped dir"
1251
1252 test_25a() {
1253         echo '== symlink sanity ============================================='
1254
1255         test_mkdir $DIR/d25
1256         ln -s d25 $DIR/s25
1257         touch $DIR/s25/foo || error
1258 }
1259 run_test 25a "create file in symlinked directory ==============="
1260
1261 test_25b() {
1262         [ ! -d $DIR/d25 ] && test_25a
1263         $CHECKSTAT -t file $DIR/s25/foo || error
1264 }
1265 run_test 25b "lookup file in symlinked directory ==============="
1266
1267 test_26a() {
1268         test_mkdir $DIR/d26
1269         test_mkdir $DIR/d26/d26-2
1270         ln -s d26/d26-2 $DIR/s26
1271         touch $DIR/s26/foo || error
1272 }
1273 run_test 26a "multiple component symlink ======================="
1274
1275 test_26b() {
1276         test_mkdir -p $DIR/d26b/d26-2
1277         ln -s d26b/d26-2/foo $DIR/s26-2
1278         touch $DIR/s26-2 || error
1279 }
1280 run_test 26b "multiple component symlink at end of lookup ======"
1281
1282 test_26c() {
1283         test_mkdir $DIR/d26.2
1284         touch $DIR/d26.2/foo
1285         ln -s d26.2 $DIR/s26.2-1
1286         ln -s s26.2-1 $DIR/s26.2-2
1287         ln -s s26.2-2 $DIR/s26.2-3
1288         chmod 0666 $DIR/s26.2-3/foo
1289 }
1290 run_test 26c "chain of symlinks ================================"
1291
1292 # recursive symlinks (bug 439)
1293 test_26d() {
1294         ln -s d26-3/foo $DIR/d26-3
1295 }
1296 run_test 26d "create multiple component recursive symlink ======"
1297
1298 test_26e() {
1299         [ ! -h $DIR/d26-3 ] && test_26d
1300         rm $DIR/d26-3
1301 }
1302 run_test 26e "unlink multiple component recursive symlink ======"
1303
1304 # recursive symlinks (bug 7022)
1305 test_26f() {
1306         test_mkdir -p $DIR/$tdir
1307         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1308         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1309         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1310         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1311         cd $tfile                || error "cd $tfile failed"
1312         ln -s .. dotdot          || error "ln dotdot failed"
1313         ln -s dotdot/lndir lndir || error "ln lndir failed"
1314         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1315         output=`ls $tfile/$tfile/lndir/bar1`
1316         [ "$output" = bar1 ] && error "unexpected output"
1317         rm -r $tfile             || error "rm $tfile failed"
1318         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1319 }
1320 run_test 26f "rm -r of a directory which has recursive symlink ="
1321
1322 test_27a() {
1323         echo '== stripe sanity =============================================='
1324         test_mkdir -p $DIR/d27 || error "mkdir failed"
1325         $GETSTRIPE $DIR/d27
1326         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1327         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1328         log "== test_27a: write to one stripe file ========================="
1329         cp /etc/hosts $DIR/d27/f0 || error
1330 }
1331 run_test 27a "one stripe file =================================="
1332
1333 test_27b() {
1334         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1335         test_mkdir -p $DIR/d27
1336         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1337         $GETSTRIPE -c $DIR/d27/f01
1338         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1339                 error "two-stripe file doesn't have two stripes"
1340
1341         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1342 }
1343 run_test 27b "create and write to two stripe file"
1344
1345 test_27d() {
1346         test_mkdir -p $DIR/d27
1347         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1348         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1349         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1350 }
1351 run_test 27d "create file with default settings ================"
1352
1353 test_27e() {
1354         test_mkdir -p $DIR/d27
1355         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1356         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1357         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1358 }
1359 run_test 27e "setstripe existing file (should return error) ======"
1360
1361 test_27f() {
1362         test_mkdir $DIR/$tdir
1363         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1364                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1365         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1366                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1367         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1368         $GETSTRIPE $DIR/$tdir/$tfile || error "$GETSTRIPE failed"
1369 }
1370 run_test 27f "setstripe with bad stripe size (should return error)"
1371
1372 test_27g() {
1373         test_mkdir -p $DIR/d27
1374         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1375         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1376                 error "$DIR/d27/fnone has object"
1377 }
1378 run_test 27g "$GETSTRIPE with no objects"
1379
1380 test_27i() {
1381         touch $DIR/d27/fsome || error "touch failed"
1382         [[ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ]] || error "missing objects"
1383 }
1384 run_test 27i "$GETSTRIPE with some objects"
1385
1386 test_27j() {
1387         test_mkdir -p $DIR/d27
1388         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1389 }
1390 run_test 27j "setstripe with bad stripe offset (should return error)"
1391
1392 test_27k() { # bug 2844
1393         test_mkdir -p $DIR/d27
1394         FILE=$DIR/d27/f27k
1395         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1396         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1397         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1398         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1399         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1400         dd if=/dev/zero of=$FILE bs=4k count=1
1401         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1402         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1403 }
1404 run_test 27k "limit i_blksize for broken user apps ============="
1405
1406 test_27l() {
1407         test_mkdir -p $DIR/d27
1408         mcreate $DIR/f27l || error "creating file"
1409         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1410                 error "setstripe should have failed" || true
1411 }
1412 run_test 27l "check setstripe permissions (should return error)"
1413
1414 test_27m() {
1415         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1416                 return
1417         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1418                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1419                 return
1420         fi
1421         trap simple_cleanup_common EXIT
1422         test_mkdir -p $DIR/$tdir
1423         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1424         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1425                 error "dd should fill OST0"
1426         i=2
1427         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1428                 i=$((i + 1))
1429                 [ $i -gt 256 ] && break
1430         done
1431         i=$((i + 1))
1432         touch $DIR/$tdir/f27m_$i
1433         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1434                 error "OST0 was full but new created file still use it"
1435         i=$((i + 1))
1436         touch $DIR/$tdir/f27m_$i
1437         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1438                 error "OST0 was full but new created file still use it"
1439         simple_cleanup_common
1440 }
1441 run_test 27m "create file while OST0 was full =================="
1442
1443 sleep_maxage() {
1444         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1445         sleep $DELAY
1446 }
1447
1448 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1449 # if the OST isn't full anymore.
1450 reset_enospc() {
1451         local OSTIDX=${1:-""}
1452
1453         local list=$(comma_list $(osts_nodes))
1454         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1455
1456         do_nodes $list lctl set_param fail_loc=0
1457         sync    # initiate all OST_DESTROYs from MDS to OST
1458         sleep_maxage
1459 }
1460
1461 exhaust_precreations() {
1462         local OSTIDX=$1
1463         local FAILLOC=$2
1464         local FAILIDX=${3:-$OSTIDX}
1465
1466         test_mkdir -p $DIR/$tdir
1467         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1468         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1469
1470         local OST=$(ostname_from_index $OSTIDX)
1471         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1472                           sed -e 's/_UUID$//;s/^.*-//')
1473
1474         # on the mdt's osc
1475         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1476         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1477                         osc.$mdtosc_proc1.prealloc_last_id)
1478         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1479                         osc.$mdtosc_proc1.prealloc_next_id)
1480
1481         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1482         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1483
1484         test_mkdir -p $DIR/$tdir/${OST}
1485         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1486 #define OBD_FAIL_OST_ENOSPC              0x215
1487         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1488         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1489         echo "Creating to objid $last_id on ost $OST..."
1490         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1491         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1492         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1493         sleep_maxage
1494 }
1495
1496 exhaust_all_precreations() {
1497         local i
1498         for (( i=0; i < OSTCOUNT; i++ )) ; do
1499                 exhaust_precreations $i $1 -1
1500         done
1501 }
1502
1503 test_27n() {
1504         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1505         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1506         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1507         remote_ost_nodsh && skip "remote OST with nodsh" && return
1508
1509         reset_enospc
1510         rm -f $DIR/$tdir/$tfile
1511         exhaust_precreations 0 0x80000215
1512         $SETSTRIPE -c -1 $DIR/$tdir
1513         touch $DIR/$tdir/$tfile || error
1514         $GETSTRIPE $DIR/$tdir/$tfile
1515         reset_enospc
1516 }
1517 run_test 27n "create file with some full OSTs =================="
1518
1519 test_27o() {
1520         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1521         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1522         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1523         remote_ost_nodsh && skip "remote OST with nodsh" && return
1524
1525         reset_enospc
1526         rm -f $DIR/$tdir/$tfile
1527         exhaust_all_precreations 0x215
1528
1529         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1530
1531         reset_enospc
1532         rm -rf $DIR/$tdir/*
1533 }
1534 run_test 27o "create file with all full OSTs (should error) ===="
1535
1536 test_27p() {
1537         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1538         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1539         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1540         remote_ost_nodsh && skip "remote OST with nodsh" && return
1541
1542         reset_enospc
1543         rm -f $DIR/$tdir/$tfile
1544         test_mkdir -p $DIR/$tdir
1545
1546         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1547         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1548         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1549
1550         exhaust_precreations 0 0x80000215
1551         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1552         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1553         $GETSTRIPE $DIR/$tdir/$tfile
1554
1555         reset_enospc
1556 }
1557 run_test 27p "append to a truncated file with some full OSTs ==="
1558
1559 test_27q() {
1560         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1561         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1562         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1563         remote_ost_nodsh && skip "remote OST with nodsh" && return
1564
1565         reset_enospc
1566         rm -f $DIR/$tdir/$tfile
1567
1568         test_mkdir -p $DIR/$tdir
1569         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1570         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1571         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1572
1573         exhaust_all_precreations 0x215
1574
1575         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1576         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1577
1578         reset_enospc
1579 }
1580 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1581
1582 test_27r() {
1583         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1584         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1585         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1586         remote_ost_nodsh && skip "remote OST with nodsh" && return
1587
1588         reset_enospc
1589         rm -f $DIR/$tdir/$tfile
1590         exhaust_precreations 0 0x80000215
1591
1592         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1593
1594         reset_enospc
1595 }
1596 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1597
1598 test_27s() { # bug 10725
1599         test_mkdir -p $DIR/$tdir
1600         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1601         local stripe_count=0
1602         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1603         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1604                 error "stripe width >= 2^32 succeeded" || true
1605
1606 }
1607 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1608
1609 test_27t() { # bug 10864
1610         WDIR=$(pwd)
1611         WLFS=$(which lfs)
1612         cd $DIR
1613         touch $tfile
1614         $WLFS getstripe $tfile
1615         cd $WDIR
1616 }
1617 run_test 27t "check that utils parse path correctly"
1618
1619 test_27u() { # bug 4900
1620         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1621         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1622         local index
1623         local list=$(comma_list $(mdts_nodes))
1624
1625 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1626         do_nodes $list $LCTL set_param fail_loc=0x139
1627         test_mkdir -p $DIR/$tdir
1628         rm -rf $DIR/$tdir/*
1629         createmany -o $DIR/$tdir/t- 1000
1630         do_nodes $list $LCTL set_param fail_loc=0
1631
1632         TLOG=$DIR/$tfile.getstripe
1633         $GETSTRIPE $DIR/$tdir > $TLOG
1634         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1635         unlinkmany $DIR/$tdir/t- 1000
1636         [[ $OBJS -gt 0 ]] &&
1637                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1638 }
1639 run_test 27u "skip object creation on OSC w/o objects =========="
1640
1641 test_27v() { # bug 4900
1642         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1643         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1644         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1645         remote_ost_nodsh && skip "remote OST with nodsh" && return
1646
1647         exhaust_all_precreations 0x215
1648         reset_enospc
1649
1650         test_mkdir -p $DIR/$tdir
1651         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1652
1653         touch $DIR/$tdir/$tfile
1654         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1655         # all except ost1
1656         for (( i=1; i < OSTCOUNT; i++ )); do
1657                 do_facet ost$i lctl set_param fail_loc=0x705
1658         done
1659         local START=`date +%s`
1660         createmany -o $DIR/$tdir/$tfile 32
1661
1662         local FINISH=`date +%s`
1663         local TIMEOUT=`lctl get_param -n timeout`
1664         local PROCESS=$((FINISH - START))
1665         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1666                error "$FINISH - $START >= $TIMEOUT / 2"
1667         sleep $((TIMEOUT / 2 - PROCESS))
1668         reset_enospc
1669 }
1670 run_test 27v "skip object creation on slow OST ================="
1671
1672 test_27w() { # bug 10997
1673         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1674         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1675         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1676                 error "stripe size $size != 65536" || true
1677         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1678                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1679 }
1680 run_test 27w "check $SETSTRIPE -S option"
1681
1682 test_27wa() {
1683         [[ $OSTCOUNT -lt 2 ]] &&
1684                 skip_env "skipping multiple stripe count/offset test" && return
1685
1686         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1687         for i in $(seq 1 $OSTCOUNT); do
1688                 offset=$((i - 1))
1689                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1690                         error "setstripe -c $i -i $offset failed"
1691                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1692                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1693                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1694                 [ $index -ne $offset ] &&
1695                         error "stripe offset $index != $offset" || true
1696         done
1697 }
1698 run_test 27wa "check $SETSTRIPE -c -i options"
1699
1700 test_27x() {
1701         remote_ost_nodsh && skip "remote OST with nodsh" && return
1702         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1703         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1704         OFFSET=$(($OSTCOUNT - 1))
1705         OSTIDX=0
1706         local OST=$(ostname_from_index $OSTIDX)
1707
1708         test_mkdir -p $DIR/$tdir
1709         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1710         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1711         sleep_maxage
1712         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1713         for i in `seq 0 $OFFSET`; do
1714                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1715                 error "OST0 was degraded but new created file still use it"
1716         done
1717         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1718 }
1719 run_test 27x "create files while OST0 is degraded"
1720
1721 test_27y() {
1722         [[ $OSTCOUNT -lt 2 ]] &&
1723                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1724         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1725         remote_ost_nodsh && skip "remote OST with nodsh" && return
1726         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1727
1728         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1729         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1730             osc.$mdtosc.prealloc_last_id)
1731         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1732             osc.$mdtosc.prealloc_next_id)
1733         local fcount=$((last_id - next_id))
1734         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1735         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1736
1737         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1738                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1739         local OST_DEACTIVE_IDX=-1
1740         local OSC
1741         local OSTIDX
1742         local OST
1743
1744         for OSC in $MDS_OSCS; do
1745                 OST=$(osc_to_ost $OSC)
1746                 OSTIDX=$(index_from_ostuuid $OST)
1747                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1748                         OST_DEACTIVE_IDX=$OSTIDX
1749                 fi
1750                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1751                         echo $OSC "is Deactivated:"
1752                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1753                 fi
1754         done
1755
1756         OSTIDX=$(index_from_ostuuid $OST)
1757         mkdir -p $DIR/$tdir
1758         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1759
1760         for OSC in $MDS_OSCS; do
1761                 OST=$(osc_to_ost $OSC)
1762                 OSTIDX=$(index_from_ostuuid $OST)
1763                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1764                         echo $OST "is degraded:"
1765                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1766                                                 obdfilter.$OST.degraded=1
1767                 fi
1768         done
1769
1770         sleep_maxage
1771         createmany -o $DIR/$tdir/$tfile $fcount
1772
1773         for OSC in $MDS_OSCS; do
1774                 OST=$(osc_to_ost $OSC)
1775                 OSTIDX=$(index_from_ostuuid $OST)
1776                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1777                         echo $OST "is recovered from degraded:"
1778                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1779                                                 obdfilter.$OST.degraded=0
1780                 else
1781                         do_facet $SINGLEMDS lctl --device %$OSC activate
1782                 fi
1783         done
1784
1785         # all osp devices get activated, hence -1 stripe count restored
1786         local stripecnt=0
1787
1788         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1789         # devices get activated.
1790         sleep_maxage
1791         $SETSTRIPE -c -1 $DIR/$tfile
1792         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1793         rm -f $DIR/$tfile
1794         [ $stripecnt -ne $OSTCOUNT ] &&
1795                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1796         return 0
1797 }
1798 run_test 27y "create files while OST0 is degraded and the rest inactive"
1799
1800 check_seq_oid()
1801 {
1802         log "check file $1"
1803
1804         lmm_count=$($GETSTRIPE -c $1)
1805         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1806         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1807
1808         local old_ifs="$IFS"
1809         IFS=$'[:]'
1810         fid=($($LFS path2fid $1))
1811         IFS="$old_ifs"
1812
1813         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1814         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1815
1816         # compare lmm_seq and lu_fid->f_seq
1817         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1818         # compare lmm_object_id and lu_fid->oid
1819         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1820
1821         # check the trusted.fid attribute of the OST objects of the file
1822         local have_obdidx=false
1823         local stripe_nr=0
1824         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1825                 # skip lines up to and including "obdidx"
1826                 [ -z "$obdidx" ] && break
1827                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1828                 $have_obdidx || continue
1829
1830                 local ost=$((obdidx + 1))
1831                 local dev=$(ostdevname $ost)
1832                 local oid_hex
1833
1834                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1835
1836                 seq=$(echo $seq | sed -e "s/^0x//g")
1837                 if [ $seq == 0 ]; then
1838                         oid_hex=$(echo $oid)
1839                 else
1840                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1841                 fi
1842                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1843
1844                 local ff
1845                 #
1846                 # Don't unmount/remount the OSTs if we don't need to do that.
1847                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1848                 # update too, until that use mount/ll_decode_filter_fid/mount.
1849                 # Re-enable when debugfs will understand new filter_fid.
1850                 #
1851                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1852                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1853                                 $dev 2>/dev/null" | grep "parent=")
1854                 else
1855                         stop ost$ost
1856                         mount_fstype ost$ost
1857                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1858                                 $(facet_mntpt ost$ost)/$obj_file)
1859                         unmount_fstype ost$ost
1860                         start ost$ost $dev $OST_MOUNT_OPTS
1861                 fi
1862
1863                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1864
1865                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1866
1867                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1868                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1869                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1870                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1871                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1872                 local ff_pstripe
1873                 if echo $ff_parent | grep -q 'stripe='; then
1874                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1875                 else
1876                         #
1877                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1878                         # into f_ver in this case.  See the comment on
1879                         # ff_parent.
1880                         #
1881                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1882                                 sed -e 's/\]//')
1883                 fi
1884
1885                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1886                 [ $ff_pseq = $lmm_seq ] ||
1887                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1888                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1889                 [ $ff_poid = $lmm_oid ] ||
1890                         error "FF parent OID $ff_poid != $lmm_oid"
1891                 (($ff_pstripe == $stripe_nr)) ||
1892                         error "FF stripe $ff_pstripe != $stripe_nr"
1893
1894                 stripe_nr=$((stripe_nr + 1))
1895         done
1896 }
1897
1898 test_27z() {
1899         remote_ost_nodsh && skip "remote OST with nodsh" && return
1900         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1901         test_mkdir -p $DIR/$tdir
1902
1903         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1904                 { error "setstripe -c -1 failed"; return 1; }
1905         # We need to send a write to every object to get parent FID info set.
1906         # This _should_ also work for setattr, but does not currently.
1907         # touch $DIR/$tdir/$tfile-1 ||
1908         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1909                 { error "dd $tfile-1 failed"; return 2; }
1910         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1911                 { error "setstripe -c -1 failed"; return 3; }
1912         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1913                 { error "dd $tfile-2 failed"; return 4; }
1914
1915         # make sure write RPCs have been sent to OSTs
1916         sync; sleep 5; sync
1917
1918         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1919         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1920 }
1921 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1922
1923 test_27A() { # b=19102
1924         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1925         local restore_size=$($GETSTRIPE -S $MOUNT)
1926         local restore_count=$($GETSTRIPE -c $MOUNT)
1927         local restore_offset=$($GETSTRIPE -i $MOUNT)
1928         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1929         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1930                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1931         local default_size=$($GETSTRIPE -S $MOUNT)
1932         local default_offset=$($GETSTRIPE -i $MOUNT)
1933         local dsize=$((1024 * 1024))
1934         [ $default_size -eq $dsize ] ||
1935                 error "stripe size $default_size != $dsize"
1936         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1937         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1938 }
1939 run_test 27A "check filesystem-wide default LOV EA values"
1940
1941 test_27B() { # LU-2523
1942         test_mkdir -p $DIR/$tdir
1943         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1944         touch $DIR/$tdir/f0
1945         # open f1 with O_LOV_DELAY_CREATE
1946         # rename f0 onto f1
1947         # call setstripe ioctl on open file descriptor for f1
1948         # close
1949         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1950                 $DIR/$tdir/f0
1951
1952         rm -f $DIR/$tdir/f1
1953         # open f1 with O_LOV_DELAY_CREATE
1954         # unlink f1
1955         # call setstripe ioctl on open file descriptor for f1
1956         # close
1957         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1958
1959         # Allow multiop to fail in imitation of NFS's busted semantics.
1960         true
1961 }
1962 run_test 27B "call setstripe on open unlinked file/rename victim"
1963
1964 test_27C() { #LU-2871
1965         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1966
1967         declare -a ost_idx
1968         local index
1969         local found
1970         local i
1971         local j
1972
1973         test_mkdir -p $DIR/$tdir
1974         cd $DIR/$tdir
1975         for i in $(seq 0 $((OSTCOUNT - 1))); do
1976                 # set stripe across all OSTs starting from OST$i
1977                 $SETSTRIPE -i $i -c -1 $tfile$i
1978                 # get striping information
1979                 ost_idx=($($GETSTRIPE $tfile$i |
1980                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1981                 echo ${ost_idx[@]}
1982
1983                 # check the layout
1984                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1985                         error "${#ost_idx[@]} != $OSTCOUNT"
1986
1987                 for index in $(seq 0 $((OSTCOUNT - 1))); do
1988                         found=0
1989                         for j in $(echo ${ost_idx[@]}); do
1990                                 if [ $index -eq $j ]; then
1991                                         found=1
1992                                         break
1993                                 fi
1994                         done
1995                         [ $found = 1 ] ||
1996                                 error "Can not find $index in ${ost_idx[@]}"
1997                 done
1998         done
1999 }
2000 run_test 27C "check full striping across all OSTs"
2001
2002 test_27D() {
2003         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2004         local POOL=${POOL:-testpool}
2005         local first_ost=0
2006         local last_ost=$(($OSTCOUNT - 1))
2007         local ost_step=1
2008         local ost_list=$(seq $first_ost $ost_step $last_ost)
2009         local ost_range="$first_ost $last_ost $ost_step"
2010
2011         mkdir -p $DIR/$tdir
2012         pool_add $POOL || error "pool_add failed"
2013         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2014         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT ||
2015                 error "llapi_layout_test failed"
2016         cleanup_pools || error "cleanup_pools failed"
2017 }
2018 run_test 27D "validate llapi_layout API"
2019
2020 # createtest also checks that device nodes are created and
2021 # then visible correctly (#2091)
2022 test_28() { # bug 2091
2023         test_mkdir $DIR/d28
2024         $CREATETEST $DIR/d28/ct || error
2025 }
2026 run_test 28 "create/mknod/mkdir with bad file types ============"
2027
2028 test_29() {
2029         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2030         cancel_lru_locks mdc
2031         test_mkdir $DIR/d29
2032         touch $DIR/d29/foo
2033         log 'first d29'
2034         ls -l $DIR/d29
2035
2036         declare -i LOCKCOUNTORIG=0
2037         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2038                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2039         done
2040         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
2041
2042         declare -i LOCKUNUSEDCOUNTORIG=0
2043         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2044                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2045         done
2046
2047         log 'second d29'
2048         ls -l $DIR/d29
2049         log 'done'
2050
2051         declare -i LOCKCOUNTCURRENT=0
2052         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2053                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2054         done
2055
2056         declare -i LOCKUNUSEDCOUNTCURRENT=0
2057         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2058                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2059         done
2060
2061         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2062                 $LCTL set_param -n ldlm.dump_namespaces ""
2063                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2064                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2065                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2066                 return 2
2067         fi
2068         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2069                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2070                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2071                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2072                 return 3
2073         fi
2074 }
2075 run_test 29 "IT_GETATTR regression  ============================"
2076
2077 test_30a() { # was test_30
2078         cp $(which ls) $DIR || cp /bin/ls $DIR
2079         $DIR/ls / || error
2080         rm $DIR/ls
2081 }
2082 run_test 30a "execute binary from Lustre (execve) =============="
2083
2084 test_30b() {
2085         cp `which ls` $DIR || cp /bin/ls $DIR
2086         chmod go+rx $DIR/ls
2087         $RUNAS $DIR/ls / || error
2088         rm $DIR/ls
2089 }
2090 run_test 30b "execute binary from Lustre as non-root ==========="
2091
2092 test_30c() { # b=22376
2093         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2094         cp `which ls` $DIR || cp /bin/ls $DIR
2095         chmod a-rw $DIR/ls
2096         cancel_lru_locks mdc
2097         cancel_lru_locks osc
2098         $RUNAS $DIR/ls / || error
2099         rm -f $DIR/ls
2100 }
2101 run_test 30c "execute binary from Lustre without read perms ===="
2102
2103 test_31a() {
2104         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2105         $CHECKSTAT -a $DIR/f31 || error
2106 }
2107 run_test 31a "open-unlink file =================================="
2108
2109 test_31b() {
2110         touch $DIR/f31 || error
2111         ln $DIR/f31 $DIR/f31b || error
2112         $MULTIOP $DIR/f31b Ouc || error
2113         $CHECKSTAT -t file $DIR/f31 || error
2114 }
2115 run_test 31b "unlink file with multiple links while open ======="
2116
2117 test_31c() {
2118         touch $DIR/f31 || error
2119         ln $DIR/f31 $DIR/f31c || error
2120         multiop_bg_pause $DIR/f31 O_uc || return 1
2121         MULTIPID=$!
2122         $MULTIOP $DIR/f31c Ouc
2123         kill -USR1 $MULTIPID
2124         wait $MULTIPID
2125 }
2126 run_test 31c "open-unlink file with multiple links ============="
2127
2128 test_31d() {
2129         opendirunlink $DIR/d31d $DIR/d31d || error
2130         $CHECKSTAT -a $DIR/d31d || error
2131 }
2132 run_test 31d "remove of open directory ========================="
2133
2134 test_31e() { # bug 2904
2135         check_kernel_version 34 || return 0
2136         openfilleddirunlink $DIR/d31e || error
2137 }
2138 run_test 31e "remove of open non-empty directory ==============="
2139
2140 test_31f() { # bug 4554
2141         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2142         set -vx
2143         test_mkdir $DIR/d31f
2144         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2145         cp /etc/hosts $DIR/d31f
2146         ls -l $DIR/d31f
2147         $GETSTRIPE $DIR/d31f/hosts
2148         multiop_bg_pause $DIR/d31f D_c || return 1
2149         MULTIPID=$!
2150
2151         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2152         test_mkdir $DIR/d31f
2153         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2154         cp /etc/hosts $DIR/d31f
2155         ls -l $DIR/d31f
2156         $GETSTRIPE $DIR/d31f/hosts
2157         multiop_bg_pause $DIR/d31f D_c || return 1
2158         MULTIPID2=$!
2159
2160         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2161         wait $MULTIPID || error "first opendir $MULTIPID failed"
2162
2163         sleep 6
2164
2165         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2166         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2167         set +vx
2168 }
2169 run_test 31f "remove of open directory with open-unlink file ==="
2170
2171 test_31g() {
2172         echo "-- cross directory link --"
2173         test_mkdir -c1 $DIR/${tdir}ga
2174         test_mkdir -c1 $DIR/${tdir}gb
2175         touch $DIR/${tdir}ga/f
2176         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2177         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2178         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2179         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2180         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2181 }
2182 run_test 31g "cross directory link==============="
2183
2184 test_31h() {
2185         echo "-- cross directory link --"
2186         test_mkdir -c1 $DIR/${tdir}
2187         test_mkdir -c1 $DIR/${tdir}/dir
2188         touch $DIR/${tdir}/f
2189         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2190         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2191         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2192         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2193         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2194 }
2195 run_test 31h "cross directory link under child==============="
2196
2197 test_31i() {
2198         echo "-- cross directory link --"
2199         test_mkdir -c1 $DIR/$tdir
2200         test_mkdir -c1 $DIR/$tdir/dir
2201         touch $DIR/$tdir/dir/f
2202         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2203         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2204         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2205         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2206         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2207 }
2208 run_test 31i "cross directory link under parent==============="
2209
2210 test_31j() {
2211         test_mkdir -c1 -p $DIR/$tdir
2212         test_mkdir -c1 -p $DIR/$tdir/dir1
2213         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2214         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2215         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2216         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2217         return 0
2218 }
2219 run_test 31j "link for directory==============="
2220
2221 test_31k() {
2222         test_mkdir -c1 -p $DIR/$tdir
2223         touch $DIR/$tdir/s
2224         touch $DIR/$tdir/exist
2225         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2226         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2227         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2228         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2229         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2230         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2231         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2232         return 0
2233 }
2234 run_test 31k "link to file: the same, non-existing, dir==============="
2235
2236 test_31m() {
2237         mkdir $DIR/d31m
2238         touch $DIR/d31m/s
2239         mkdir $DIR/d31m2
2240         touch $DIR/d31m2/exist
2241         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2242         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2243         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2244         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2245         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2246         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2247         return 0
2248 }
2249 run_test 31m "link to file: the same, non-existing, dir==============="
2250
2251 test_31n() {
2252         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2253         nlink=$(stat --format=%h $DIR/$tfile)
2254         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2255         local fd=$(free_fd)
2256         local cmd="exec $fd<$DIR/$tfile"
2257         eval $cmd
2258         cmd="exec $fd<&-"
2259         trap "eval $cmd" EXIT
2260         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2261         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2262         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2263         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2264         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2265         eval $cmd
2266 }
2267 run_test 31n "check link count of unlinked file"
2268
2269 link_one() {
2270         local TEMPNAME=$(mktemp $1_XXXXXX)
2271         mlink $TEMPNAME $1 2> /dev/null &&
2272                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2273         munlink $TEMPNAME
2274 }
2275
2276 test_31o() { # LU-2901
2277         mkdir -p $DIR/$tdir
2278         for LOOP in $(seq 100); do
2279                 rm -f $DIR/$tdir/$tfile*
2280                 for THREAD in $(seq 8); do
2281                         link_one $DIR/$tdir/$tfile.$LOOP &
2282                 done
2283                 wait
2284                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2285                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2286                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2287                         break || true
2288         done
2289 }
2290 run_test 31o "duplicate hard links with same filename"
2291
2292 test_31p() {
2293         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2294
2295         mkdir $DIR/$tdir
2296         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2297         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2298
2299         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2300                 error "open unlink test1 failed"
2301         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2302                 error "open unlink test2 failed"
2303
2304         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2305                 error "test1 still exists"
2306         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2307                 error "test2 still exists"
2308 }
2309 run_test 31p "remove of open striped directory"
2310
2311 cleanup_test32_mount() {
2312         trap 0
2313         $UMOUNT -d $DIR/$tdir/ext2-mountpoint
2314 }
2315
2316 test_32a() {
2317         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2318         echo "== more mountpoints and symlinks ================="
2319         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2320         trap cleanup_test32_mount EXIT
2321         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2322         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2323         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2324         cleanup_test32_mount
2325 }
2326 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2327
2328 test_32b() {
2329         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2330         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2331         trap cleanup_test32_mount EXIT
2332         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2333         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2334         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2335         cleanup_test32_mount
2336 }
2337 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2338
2339 test_32c() {
2340         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2341         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2342         trap cleanup_test32_mount EXIT
2343         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2344         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2345         test_mkdir -p $DIR/$tdir/d2/test_dir
2346         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2347         cleanup_test32_mount
2348 }
2349 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2350
2351 test_32d() {
2352         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2353         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2354         trap cleanup_test32_mount EXIT
2355         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2356         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2357         test_mkdir -p $DIR/$tdir/d2/test_dir
2358         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2359         cleanup_test32_mount
2360 }
2361 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2362
2363 test_32e() {
2364         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2365         test_mkdir -p $DIR/d32e/tmp
2366         TMP_DIR=$DIR/d32e/tmp
2367         ln -s $DIR/d32e $TMP_DIR/symlink11
2368         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2369         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2370         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2371 }
2372 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2373
2374 test_32f() {
2375         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2376         test_mkdir -p $DIR/d32f/tmp
2377         TMP_DIR=$DIR/d32f/tmp
2378         ln -s $DIR/d32f $TMP_DIR/symlink11
2379         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2380         ls $DIR/d32f/tmp/symlink11  || error
2381         ls $DIR/d32f/symlink01 || error
2382 }
2383 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2384
2385 test_32g() {
2386         TMP_DIR=$DIR/$tdir/tmp
2387         test_mkdir -p $DIR/$tdir/tmp
2388         test_mkdir $DIR/${tdir}2
2389         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2390         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2391         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2392         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2393         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2394         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2395 }
2396 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2397
2398 test_32h() {
2399         rm -fr $DIR/$tdir $DIR/${tdir}2
2400         TMP_DIR=$DIR/$tdir/tmp
2401         test_mkdir -p $DIR/$tdir/tmp
2402         test_mkdir $DIR/${tdir}2
2403         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2404         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2405         ls $TMP_DIR/symlink12 || error
2406         ls $DIR/$tdir/symlink02  || error
2407 }
2408 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2409
2410 test_32i() {
2411         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2412         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2413         trap cleanup_test32_mount EXIT
2414         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2415         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2416         touch $DIR/$tdir/test_file
2417         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2418         cleanup_test32_mount
2419 }
2420 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2421
2422 test_32j() {
2423         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2424         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2425         trap cleanup_test32_mount EXIT
2426         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2427         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2428         touch $DIR/$tdir/test_file
2429         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2430         cleanup_test32_mount
2431 }
2432 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2433
2434 test_32k() {
2435         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2436         rm -fr $DIR/$tdir
2437         trap cleanup_test32_mount EXIT
2438         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2439         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2440         test_mkdir -p $DIR/$tdir/d2
2441         touch $DIR/$tdir/d2/test_file || error
2442         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2443         cleanup_test32_mount
2444 }
2445 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2446
2447 test_32l() {
2448         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2449         rm -fr $DIR/$tdir
2450         trap cleanup_test32_mount EXIT
2451         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2452         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2453         test_mkdir -p $DIR/$tdir/d2
2454         touch $DIR/$tdir/d2/test_file
2455         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2456         cleanup_test32_mount
2457 }
2458 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2459
2460 test_32m() {
2461         rm -fr $DIR/d32m
2462         test_mkdir -p $DIR/d32m/tmp
2463         TMP_DIR=$DIR/d32m/tmp
2464         ln -s $DIR $TMP_DIR/symlink11
2465         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2466         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2467         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2468 }
2469 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2470
2471 test_32n() {
2472         rm -fr $DIR/d32n
2473         test_mkdir -p $DIR/d32n/tmp
2474         TMP_DIR=$DIR/d32n/tmp
2475         ln -s $DIR $TMP_DIR/symlink11
2476         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2477         ls -l $DIR/d32n/tmp/symlink11  || error
2478         ls -l $DIR/d32n/symlink01 || error
2479 }
2480 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2481
2482 test_32o() {
2483         touch $DIR/$tfile
2484         test_mkdir -p $DIR/d32o/tmp
2485         TMP_DIR=$DIR/d32o/tmp
2486         ln -s $DIR/$tfile $TMP_DIR/symlink12
2487         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2488         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2489         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2490         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2491         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2492 }
2493 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2494
2495 test_32p() {
2496     log 32p_1
2497         rm -fr $DIR/d32p
2498     log 32p_2
2499         rm -f $DIR/$tfile
2500     log 32p_3
2501         touch $DIR/$tfile
2502     log 32p_4
2503         test_mkdir -p $DIR/d32p/tmp
2504     log 32p_5
2505         TMP_DIR=$DIR/d32p/tmp
2506     log 32p_6
2507         ln -s $DIR/$tfile $TMP_DIR/symlink12
2508     log 32p_7
2509         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2510     log 32p_8
2511         cat $DIR/d32p/tmp/symlink12 || error
2512     log 32p_9
2513         cat $DIR/d32p/symlink02 || error
2514     log 32p_10
2515 }
2516 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2517
2518 cleanup_testdir_mount() {
2519         trap 0
2520         $UMOUNT -d $DIR/$tdir
2521 }
2522
2523 test_32q() {
2524         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2525         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2526         trap cleanup_testdir_mount EXIT
2527         test_mkdir -p $DIR/$tdir
2528         touch $DIR/$tdir/under_the_mount
2529         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2530         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2531         cleanup_testdir_mount
2532 }
2533 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2534
2535 test_32r() {
2536         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2537         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2538         trap cleanup_testdir_mount EXIT
2539         test_mkdir -p $DIR/$tdir
2540         touch $DIR/$tdir/under_the_mount
2541         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2542         ls $DIR/$tdir | grep -q under_the_mount && error || true
2543         cleanup_testdir_mount
2544 }
2545 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2546
2547 test_33aa() {
2548         rm -f $DIR/$tfile
2549         touch $DIR/$tfile
2550         chmod 444 $DIR/$tfile
2551         chown $RUNAS_ID $DIR/$tfile
2552         log 33_1
2553         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2554         log 33_2
2555 }
2556 run_test 33aa "write file with mode 444 (should return error) ===="
2557
2558 test_33a() {
2559         rm -fr $DIR/d33
2560         test_mkdir -p $DIR/d33
2561         chown $RUNAS_ID $DIR/d33
2562         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2563         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2564                 error "open RDWR" || true
2565 }
2566 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2567
2568 test_33b() {
2569         rm -fr $DIR/d33
2570         test_mkdir -p $DIR/d33
2571         chown $RUNAS_ID $DIR/d33
2572         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33
2573 }
2574 run_test 33b "test open file with malformed flags (No panic)"
2575
2576 test_33c() {
2577         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2578         local ostnum
2579         local ostname
2580         local write_bytes
2581         local all_zeros
2582
2583         remote_ost_nodsh && skip "remote OST with nodsh" && return
2584         all_zeros=:
2585         rm -fr $DIR/d33
2586         test_mkdir -p $DIR/d33
2587         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2588
2589         sync
2590         for ostnum in $(seq $OSTCOUNT); do
2591                 # test-framework's OST numbering is one-based, while Lustre's
2592                 # is zero-based
2593                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2594                 # Parsing llobdstat's output sucks; we could grep the /proc
2595                 # path, but that's likely to not be as portable as using the
2596                 # llobdstat utility.  So we parse lctl output instead.
2597                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2598                         obdfilter/$ostname/stats |
2599                         awk '/^write_bytes/ {print $7}' )
2600                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2601                 if (( ${write_bytes:-0} > 0 ))
2602                 then
2603                         all_zeros=false
2604                         break;
2605                 fi
2606         done
2607
2608         $all_zeros || return 0
2609
2610         # Write four bytes
2611         echo foo > $DIR/d33/bar
2612         # Really write them
2613         sync
2614
2615         # Total up write_bytes after writing.  We'd better find non-zeros.
2616         for ostnum in $(seq $OSTCOUNT); do
2617                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2618                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2619                         obdfilter/$ostname/stats |
2620                         awk '/^write_bytes/ {print $7}' )
2621                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2622                 if (( ${write_bytes:-0} > 0 ))
2623                 then
2624                         all_zeros=false
2625                         break;
2626                 fi
2627         done
2628
2629         if $all_zeros
2630         then
2631                 for ostnum in $(seq $OSTCOUNT); do
2632                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2633                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2634                         do_facet ost$ostnum lctl get_param -n \
2635                                 obdfilter/$ostname/stats
2636                 done
2637                 error "OST not keeping write_bytes stats (b22312)"
2638         fi
2639 }
2640 run_test 33c "test llobdstat and write_bytes"
2641
2642 test_33d() {
2643         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2644         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2645         local MDTIDX=1
2646         local remote_dir=$DIR/$tdir/remote_dir
2647
2648         mkdir -p $DIR/$tdir
2649         $LFS mkdir -i $MDTIDX $remote_dir ||
2650                 error "create remote directory failed"
2651
2652         touch $remote_dir/$tfile
2653         chmod 444 $remote_dir/$tfile
2654         chown $RUNAS_ID $remote_dir/$tfile
2655
2656         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2657
2658         chown $RUNAS_ID $remote_dir
2659         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2660                                         error "create" || true
2661         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2662                                     error "open RDWR" || true
2663         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2664                                     error "create" || true
2665 }
2666 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2667
2668 test_33e() {
2669         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2670
2671         mkdir $DIR/$tdir
2672
2673         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2674         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2675         mkdir $DIR/$tdir/local_dir
2676
2677         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2678         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2679         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2680
2681         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2682                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2683
2684         rmdir $DIR/$tdir/* || error "rmdir failed"
2685
2686         umask 777
2687         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2688         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2689         mkdir $DIR/$tdir/local_dir
2690
2691         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2692         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2693         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2694
2695         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2696                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2697
2698         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2699
2700         umask 000
2701         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2702         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2703         mkdir $DIR/$tdir/local_dir
2704
2705         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2706         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2707         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2708
2709         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2710                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2711 }
2712 run_test 33e "mkdir and striped directory should have same mode"
2713
2714 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2715 test_34a() {
2716         rm -f $DIR/f34
2717         $MCREATE $DIR/f34 || error
2718         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2719         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2720         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2721         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2722 }
2723 run_test 34a "truncate file that has not been opened ==========="
2724
2725 test_34b() {
2726         [ ! -f $DIR/f34 ] && test_34a
2727         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2728         $OPENFILE -f O_RDONLY $DIR/f34
2729         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2730         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2731 }
2732 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2733
2734 test_34c() {
2735         [ ! -f $DIR/f34 ] && test_34a
2736         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2737         $OPENFILE -f O_RDWR $DIR/f34
2738         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2739         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2740 }
2741 run_test 34c "O_RDWR opening file-with-size works =============="
2742
2743 test_34d() {
2744         [ ! -f $DIR/f34 ] && test_34a
2745         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2746         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2747         rm $DIR/f34
2748 }
2749 run_test 34d "write to sparse file ============================="
2750
2751 test_34e() {
2752         rm -f $DIR/f34e
2753         $MCREATE $DIR/f34e || error
2754         $TRUNCATE $DIR/f34e 1000 || error
2755         $CHECKSTAT -s 1000 $DIR/f34e || error
2756         $OPENFILE -f O_RDWR $DIR/f34e
2757         $CHECKSTAT -s 1000 $DIR/f34e || error
2758 }
2759 run_test 34e "create objects, some with size and some without =="
2760
2761 test_34f() { # bug 6242, 6243
2762         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2763         SIZE34F=48000
2764         rm -f $DIR/f34f
2765         $MCREATE $DIR/f34f || error
2766         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2767         dd if=$DIR/f34f of=$TMP/f34f
2768         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2769         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2770         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2771         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2772         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2773 }
2774 run_test 34f "read from a file with no objects until EOF ======="
2775
2776 test_34g() {
2777         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2778         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2779         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2780         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2781         cancel_lru_locks osc
2782         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2783                 error "wrong size after lock cancel"
2784
2785         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2786         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2787                 error "expanding truncate failed"
2788         cancel_lru_locks osc
2789         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2790                 error "wrong expanded size after lock cancel"
2791 }
2792 run_test 34g "truncate long file ==============================="
2793
2794 test_34h() {
2795         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2796         local gid=10
2797         local sz=1000
2798
2799         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2800         sync # Flush the cache so that multiop below does not block on cache
2801              # flush when getting the group lock
2802         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2803         MULTIPID=$!
2804
2805         # Since just timed wait is not good enough, let's do a sync write
2806         # that way we are sure enough time for a roundtrip + processing
2807         # passed + 2 seconds of extra margin.
2808         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2809         rm $DIR/${tfile}-1
2810         sleep 2
2811
2812         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2813                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2814                 kill -9 $MULTIPID
2815         fi
2816         wait $MULTIPID
2817         local nsz=`stat -c %s $DIR/$tfile`
2818         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2819 }
2820 run_test 34h "ftruncate file under grouplock should not block"
2821
2822 test_35a() {
2823         cp /bin/sh $DIR/f35a
2824         chmod 444 $DIR/f35a
2825         chown $RUNAS_ID $DIR/f35a
2826         $RUNAS $DIR/f35a && error || true
2827         rm $DIR/f35a
2828 }
2829 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2830
2831 test_36a() {
2832         rm -f $DIR/f36
2833         utime $DIR/f36 || error
2834 }
2835 run_test 36a "MDS utime check (mknod, utime) ==================="
2836
2837 test_36b() {
2838         echo "" > $DIR/f36
2839         utime $DIR/f36 || error
2840 }
2841 run_test 36b "OST utime check (open, utime) ===================="
2842
2843 test_36c() {
2844         rm -f $DIR/d36/f36
2845         test_mkdir $DIR/d36
2846         chown $RUNAS_ID $DIR/d36
2847         $RUNAS utime $DIR/d36/f36 || error
2848 }
2849 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2850
2851 test_36d() {
2852         [ ! -d $DIR/d36 ] && test_36c
2853         echo "" > $DIR/d36/f36
2854         $RUNAS utime $DIR/d36/f36 || error
2855 }
2856 run_test 36d "non-root OST utime check (open, utime) ==========="
2857
2858 test_36e() {
2859         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2860         test_mkdir -p $DIR/$tdir
2861         touch $DIR/$tdir/$tfile
2862         $RUNAS utime $DIR/$tdir/$tfile && \
2863                 error "utime worked, expected failure" || true
2864 }
2865 run_test 36e "utime on non-owned file (should return error) ===="
2866
2867 subr_36fh() {
2868         local fl="$1"
2869         local LANG_SAVE=$LANG
2870         local LC_LANG_SAVE=$LC_LANG
2871         export LANG=C LC_LANG=C # for date language
2872
2873         DATESTR="Dec 20  2000"
2874         test_mkdir -p $DIR/$tdir
2875         lctl set_param fail_loc=$fl
2876         date; date +%s
2877         cp /etc/hosts $DIR/$tdir/$tfile
2878         sync & # write RPC generated with "current" inode timestamp, but delayed
2879         sleep 1
2880         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2881         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2882         cancel_lru_locks osc
2883         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2884         date; date +%s
2885         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2886                 echo "BEFORE: $LS_BEFORE" && \
2887                 echo "AFTER : $LS_AFTER" && \
2888                 echo "WANT  : $DATESTR" && \
2889                 error "$DIR/$tdir/$tfile timestamps changed" || true
2890
2891         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2892 }
2893
2894 test_36f() {
2895         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2896         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2897         subr_36fh "0x80000214"
2898 }
2899 run_test 36f "utime on file racing with OST BRW write =========="
2900
2901 test_36g() {
2902         remote_ost_nodsh && skip "remote OST with nodsh" && return
2903         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2904         local fmd_max_age
2905         local fmd_before
2906         local fmd_after
2907
2908         test_mkdir -p $DIR/$tdir
2909         fmd_max_age=$(do_facet ost1 \
2910                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2911                 head -n 1")
2912
2913         fmd_before=$(do_facet ost1 \
2914                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2915         touch $DIR/$tdir/$tfile
2916         sleep $((fmd_max_age + 12))
2917         fmd_after=$(do_facet ost1 \
2918                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2919
2920         echo "fmd_before: $fmd_before"
2921         echo "fmd_after: $fmd_after"
2922         [[ $fmd_after -gt $fmd_before ]] &&
2923                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
2924                 error "fmd didn't expire after ping" || true
2925 }
2926 run_test 36g "filter mod data cache expiry ====================="
2927
2928 test_36h() {
2929         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2930         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2931         subr_36fh "0x80000227"
2932 }
2933 run_test 36h "utime on file racing with OST BRW write =========="
2934
2935 test_36i() {
2936         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2937
2938         mkdir $DIR/$tdir
2939         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
2940
2941         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
2942         local new_mtime=$((mtime + 200))
2943
2944         #change Modify time of striped dir
2945         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
2946                         error "change mtime failed"
2947
2948         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
2949
2950         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
2951 }
2952 run_test 36i "change mtime on striped directory"
2953
2954 # test_37 - duplicate with tests 32q 32r
2955
2956 test_38() {
2957         local file=$DIR/$tfile
2958         touch $file
2959         openfile -f O_DIRECTORY $file
2960         local RC=$?
2961         local ENOTDIR=20
2962         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2963         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2964 }
2965 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2966
2967 test_39() {
2968         touch $DIR/$tfile
2969         touch $DIR/${tfile}2
2970 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2971 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2972 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2973         sleep 2
2974         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2975         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2976                 echo "mtime"
2977                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2978                 echo "atime"
2979                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2980                 echo "ctime"
2981                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2982                 error "O_TRUNC didn't change timestamps"
2983         fi
2984 }
2985 run_test 39 "mtime changed on create ==========================="
2986
2987 test_39b() {
2988         test_mkdir -p -c1 $DIR/$tdir
2989         cp -p /etc/passwd $DIR/$tdir/fopen
2990         cp -p /etc/passwd $DIR/$tdir/flink
2991         cp -p /etc/passwd $DIR/$tdir/funlink
2992         cp -p /etc/passwd $DIR/$tdir/frename
2993         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2994
2995         sleep 1
2996         echo "aaaaaa" >> $DIR/$tdir/fopen
2997         echo "aaaaaa" >> $DIR/$tdir/flink
2998         echo "aaaaaa" >> $DIR/$tdir/funlink
2999         echo "aaaaaa" >> $DIR/$tdir/frename
3000
3001         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3002         local link_new=`stat -c %Y $DIR/$tdir/flink`
3003         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3004         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3005
3006         cat $DIR/$tdir/fopen > /dev/null
3007         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3008         rm -f $DIR/$tdir/funlink2
3009         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3010
3011         for (( i=0; i < 2; i++ )) ; do
3012                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3013                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3014                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3015                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3016
3017                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3018                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3019                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3020                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3021
3022                 cancel_lru_locks osc
3023                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3024         done
3025 }
3026 run_test 39b "mtime change on open, link, unlink, rename  ======"
3027
3028 # this should be set to past
3029 TEST_39_MTIME=`date -d "1 year ago" +%s`
3030
3031 # bug 11063
3032 test_39c() {
3033         touch $DIR1/$tfile
3034         sleep 2
3035         local mtime0=`stat -c %Y $DIR1/$tfile`
3036
3037         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3038         local mtime1=`stat -c %Y $DIR1/$tfile`
3039         [ "$mtime1" = $TEST_39_MTIME ] || \
3040                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3041
3042         local d1=`date +%s`
3043         echo hello >> $DIR1/$tfile
3044         local d2=`date +%s`
3045         local mtime2=`stat -c %Y $DIR1/$tfile`
3046         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3047                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3048
3049         mv $DIR1/$tfile $DIR1/$tfile-1
3050
3051         for (( i=0; i < 2; i++ )) ; do
3052                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3053                 [ "$mtime2" = "$mtime3" ] || \
3054                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3055
3056                 cancel_lru_locks osc
3057                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3058         done
3059 }
3060 run_test 39c "mtime change on rename ==========================="
3061
3062 # bug 21114
3063 test_39d() {
3064         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3065         touch $DIR1/$tfile
3066
3067         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3068
3069         for (( i=0; i < 2; i++ )) ; do
3070                 local mtime=`stat -c %Y $DIR1/$tfile`
3071                 [ $mtime = $TEST_39_MTIME ] || \
3072                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3073
3074                 cancel_lru_locks osc
3075                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3076         done
3077 }
3078 run_test 39d "create, utime, stat =============================="
3079
3080 # bug 21114
3081 test_39e() {
3082         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3083         touch $DIR1/$tfile
3084         local mtime1=`stat -c %Y $DIR1/$tfile`
3085
3086         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3087
3088         for (( i=0; i < 2; i++ )) ; do
3089                 local mtime2=`stat -c %Y $DIR1/$tfile`
3090                 [ $mtime2 = $TEST_39_MTIME ] || \
3091                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3092
3093                 cancel_lru_locks osc
3094                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3095         done
3096 }
3097 run_test 39e "create, stat, utime, stat ========================"
3098
3099 # bug 21114
3100 test_39f() {
3101         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3102         touch $DIR1/$tfile
3103         mtime1=`stat -c %Y $DIR1/$tfile`
3104
3105         sleep 2
3106         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3107
3108         for (( i=0; i < 2; i++ )) ; do
3109                 local mtime2=`stat -c %Y $DIR1/$tfile`
3110                 [ $mtime2 = $TEST_39_MTIME ] || \
3111                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3112
3113                 cancel_lru_locks osc
3114                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3115         done
3116 }
3117 run_test 39f "create, stat, sleep, utime, stat ================="
3118
3119 # bug 11063
3120 test_39g() {
3121         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3122         echo hello >> $DIR1/$tfile
3123         local mtime1=`stat -c %Y $DIR1/$tfile`
3124
3125         sleep 2
3126         chmod o+r $DIR1/$tfile
3127
3128         for (( i=0; i < 2; i++ )) ; do
3129                 local mtime2=`stat -c %Y $DIR1/$tfile`
3130                 [ "$mtime1" = "$mtime2" ] || \
3131                         error "lost mtime: $mtime2, should be $mtime1"
3132
3133                 cancel_lru_locks osc
3134                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3135         done
3136 }
3137 run_test 39g "write, chmod, stat ==============================="
3138
3139 # bug 11063
3140 test_39h() {
3141         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3142         touch $DIR1/$tfile
3143         sleep 1
3144
3145         local d1=`date`
3146         echo hello >> $DIR1/$tfile
3147         local mtime1=`stat -c %Y $DIR1/$tfile`
3148
3149         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3150         local d2=`date`
3151         if [ "$d1" != "$d2" ]; then
3152                 echo "write and touch not within one second"
3153         else
3154                 for (( i=0; i < 2; i++ )) ; do
3155                         local mtime2=`stat -c %Y $DIR1/$tfile`
3156                         [ "$mtime2" = $TEST_39_MTIME ] || \
3157                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3158
3159                         cancel_lru_locks osc
3160                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3161                 done
3162         fi
3163 }
3164 run_test 39h "write, utime within one second, stat ============="
3165
3166 test_39i() {
3167         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3168         touch $DIR1/$tfile
3169         sleep 1
3170
3171         echo hello >> $DIR1/$tfile
3172         local mtime1=`stat -c %Y $DIR1/$tfile`
3173
3174         mv $DIR1/$tfile $DIR1/$tfile-1
3175
3176         for (( i=0; i < 2; i++ )) ; do
3177                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3178
3179                 [ "$mtime1" = "$mtime2" ] || \
3180                         error "lost mtime: $mtime2, should be $mtime1"
3181
3182                 cancel_lru_locks osc
3183                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3184         done
3185 }
3186 run_test 39i "write, rename, stat =============================="
3187
3188 test_39j() {
3189         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3190         start_full_debug_logging
3191         touch $DIR1/$tfile
3192         sleep 1
3193
3194         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3195         lctl set_param fail_loc=0x80000412
3196         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3197                 error "multiop failed"
3198         local multipid=$!
3199         local mtime1=`stat -c %Y $DIR1/$tfile`
3200
3201         mv $DIR1/$tfile $DIR1/$tfile-1
3202
3203         kill -USR1 $multipid
3204         wait $multipid || error "multiop close failed"
3205
3206         for (( i=0; i < 2; i++ )) ; do
3207                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3208                 [ "$mtime1" = "$mtime2" ] ||
3209                         error "mtime is lost on close: $mtime2, " \
3210                               "should be $mtime1"
3211
3212                 cancel_lru_locks osc
3213                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3214         done
3215         lctl set_param fail_loc=0
3216         stop_full_debug_logging
3217 }
3218 run_test 39j "write, rename, close, stat ======================="
3219
3220 test_39k() {
3221         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3222         touch $DIR1/$tfile
3223         sleep 1
3224
3225         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3226         local multipid=$!
3227         local mtime1=`stat -c %Y $DIR1/$tfile`
3228
3229         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3230
3231         kill -USR1 $multipid
3232         wait $multipid || error "multiop close failed"
3233
3234         for (( i=0; i < 2; i++ )) ; do
3235                 local mtime2=`stat -c %Y $DIR1/$tfile`
3236
3237                 [ "$mtime2" = $TEST_39_MTIME ] || \
3238                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3239
3240                 cancel_lru_locks osc
3241                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3242         done
3243 }
3244 run_test 39k "write, utime, close, stat ========================"
3245
3246 # this should be set to future
3247 TEST_39_ATIME=`date -d "1 year" +%s`
3248
3249 test_39l() {
3250         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3251         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3252         local atime_diff=$(do_facet $SINGLEMDS \
3253                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3254         rm -rf $DIR/$tdir
3255         mkdir -p $DIR/$tdir
3256
3257         # test setting directory atime to future
3258         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3259         local atime=$(stat -c %X $DIR/$tdir)
3260         [ "$atime" = $TEST_39_ATIME ] || \
3261                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3262
3263         # test setting directory atime from future to now
3264         local d1=$(date +%s)
3265         ls $DIR/$tdir
3266         local d2=$(date +%s)
3267
3268         cancel_lru_locks mdc
3269         atime=$(stat -c %X $DIR/$tdir)
3270         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3271                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3272
3273         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3274         sleep 3
3275
3276         # test setting directory atime when now > dir atime + atime_diff
3277         d1=$(date +%s)
3278         ls $DIR/$tdir
3279         d2=$(date +%s)
3280         cancel_lru_locks mdc
3281         atime=$(stat -c %X $DIR/$tdir)
3282         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3283                 error "atime is not updated  : $atime, should be $d2"
3284
3285         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3286         sleep 3
3287
3288         # test not setting directory atime when now < dir atime + atime_diff
3289         ls $DIR/$tdir
3290         cancel_lru_locks mdc
3291         atime=$(stat -c %X $DIR/$tdir)
3292         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3293                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3294
3295         do_facet $SINGLEMDS \
3296                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3297 }
3298 run_test 39l "directory atime update ==========================="
3299
3300 test_39m() {
3301         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3302         touch $DIR1/$tfile
3303         sleep 2
3304         local far_past_mtime=$(date -d "May 29 1953" +%s)
3305         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3306
3307         touch -m -d @$far_past_mtime $DIR1/$tfile
3308         touch -a -d @$far_past_atime $DIR1/$tfile
3309
3310         for (( i=0; i < 2; i++ )) ; do
3311                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3312                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3313                         error "atime or mtime set incorrectly"
3314
3315                 cancel_lru_locks osc
3316                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3317         done
3318 }
3319 run_test 39m "test atime and mtime before 1970"
3320
3321 test_39n() { # LU-3832
3322         local atime_diff=$(do_facet $SINGLEMDS \
3323                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3324         local atime0
3325         local atime1
3326         local atime2
3327
3328         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3329
3330         rm -rf $DIR/$tfile
3331         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3332         atime0=$(stat -c %X $DIR/$tfile)
3333
3334         sleep 5
3335         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3336         atime1=$(stat -c %X $DIR/$tfile)
3337
3338         sleep 5
3339         cancel_lru_locks mdc
3340         cancel_lru_locks osc
3341         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3342         atime2=$(stat -c %X $DIR/$tfile)
3343
3344         do_facet $SINGLEMDS \
3345                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3346
3347         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3348         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3349 }
3350 run_test 39n "check that O_NOATIME is honored"
3351
3352 test_39o() {
3353         TESTDIR=$DIR/$tdir/$tfile
3354         [ -e $TESTDIR ] && rm -rf $TESTDIR
3355         test_mkdir -p $TESTDIR
3356         cd $TESTDIR
3357         links1=2
3358         ls
3359         mkdir a b
3360         ls
3361         links2=$(stat -c %h .)
3362         [ $(($links1 + 2)) != $links2 ] &&
3363                 error "wrong links count $(($links1 + 2)) != $links2"
3364         rmdir b
3365         links3=$(stat -c %h .)
3366         [ $(($links1 + 1)) != $links3 ] &&
3367                 error "wrong links count $links1 != $links3"
3368         return 0
3369 }
3370 run_test 39o "directory cached attributes updated after create ========"
3371
3372 test_39p() {
3373         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3374         local MDTIDX=1
3375         TESTDIR=$DIR/$tdir/$tfile
3376         [ -e $TESTDIR ] && rm -rf $TESTDIR
3377         mkdir -p $TESTDIR
3378         cd $TESTDIR
3379         links1=2
3380         ls
3381         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3382         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3383         ls
3384         links2=$(stat -c %h .)
3385         [ $(($links1 + 2)) != $links2 ] &&
3386                 error "wrong links count $(($links1 + 2)) != $links2"
3387         rmdir remote_dir2
3388         links3=$(stat -c %h .)
3389         [ $(($links1 + 1)) != $links3 ] &&
3390                 error "wrong links count $links1 != $links3"
3391         return 0
3392 }
3393 run_test 39p "remote directory cached attributes updated after create ========"
3394
3395
3396 test_40() {
3397         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3398         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3399                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3400         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3401                 error "$tfile is not 4096 bytes in size"
3402 }
3403 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3404
3405 test_41() {
3406         # bug 1553
3407         small_write $DIR/f41 18
3408 }
3409 run_test 41 "test small file write + fstat ====================="
3410
3411 count_ost_writes() {
3412         lctl get_param -n osc.*.stats |
3413                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3414                         END { printf("%0.0f", writes) }'
3415 }
3416
3417 # decent default
3418 WRITEBACK_SAVE=500
3419 DIRTY_RATIO_SAVE=40
3420 MAX_DIRTY_RATIO=50
3421 BG_DIRTY_RATIO_SAVE=10
3422 MAX_BG_DIRTY_RATIO=25
3423
3424 start_writeback() {
3425         trap 0
3426         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3427         # dirty_ratio, dirty_background_ratio
3428         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3429                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3430                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3431                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3432         else
3433                 # if file not here, we are a 2.4 kernel
3434                 kill -CONT `pidof kupdated`
3435         fi
3436 }
3437
3438 stop_writeback() {
3439         # setup the trap first, so someone cannot exit the test at the
3440         # exact wrong time and mess up a machine
3441         trap start_writeback EXIT
3442         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3443         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3444                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3445                 sysctl -w vm.dirty_writeback_centisecs=0
3446                 sysctl -w vm.dirty_writeback_centisecs=0
3447                 # save and increase /proc/sys/vm/dirty_ratio
3448                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3449                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3450                 # save and increase /proc/sys/vm/dirty_background_ratio
3451                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3452                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3453         else
3454                 # if file not here, we are a 2.4 kernel
3455                 kill -STOP `pidof kupdated`
3456         fi
3457 }
3458
3459 # ensure that all stripes have some grant before we test client-side cache
3460 setup_test42() {
3461         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3462                 dd if=/dev/zero of=$i bs=4k count=1
3463                 rm $i
3464         done
3465 }
3466
3467 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3468 # file truncation, and file removal.
3469 test_42a() {
3470         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3471         setup_test42
3472         cancel_lru_locks osc
3473         stop_writeback
3474         sync; sleep 1; sync # just to be safe
3475         BEFOREWRITES=`count_ost_writes`
3476         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3477         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3478         AFTERWRITES=`count_ost_writes`
3479         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3480                 error "$BEFOREWRITES < $AFTERWRITES"
3481         start_writeback
3482 }
3483 run_test 42a "ensure that we don't flush on close =============="
3484
3485 test_42b() {
3486         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3487         setup_test42
3488         cancel_lru_locks osc
3489         stop_writeback
3490         sync
3491         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3492         BEFOREWRITES=$(count_ost_writes)
3493         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3494         AFTERWRITES=$(count_ost_writes)
3495         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3496                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3497         fi
3498         BEFOREWRITES=$(count_ost_writes)
3499         sync || error "sync: $?"
3500         AFTERWRITES=$(count_ost_writes)
3501         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3502                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3503         fi
3504         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3505         start_writeback
3506         return 0
3507 }
3508 run_test 42b "test destroy of file with cached dirty data ======"
3509
3510 # if these tests just want to test the effect of truncation,
3511 # they have to be very careful.  consider:
3512 # - the first open gets a {0,EOF}PR lock
3513 # - the first write conflicts and gets a {0, count-1}PW
3514 # - the rest of the writes are under {count,EOF}PW
3515 # - the open for truncate tries to match a {0,EOF}PR
3516 #   for the filesize and cancels the PWs.
3517 # any number of fixes (don't get {0,EOF} on open, match
3518 # composite locks, do smarter file size management) fix
3519 # this, but for now we want these tests to verify that
3520 # the cancellation with truncate intent works, so we
3521 # start the file with a full-file pw lock to match against
3522 # until the truncate.
3523 trunc_test() {
3524         test=$1
3525         file=$DIR/$test
3526         offset=$2
3527         cancel_lru_locks osc
3528         stop_writeback
3529         # prime the file with 0,EOF PW to match
3530         touch $file
3531         $TRUNCATE $file 0
3532         sync; sync
3533         # now the real test..
3534         dd if=/dev/zero of=$file bs=1024 count=100
3535         BEFOREWRITES=`count_ost_writes`
3536         $TRUNCATE $file $offset
3537         cancel_lru_locks osc
3538         AFTERWRITES=`count_ost_writes`
3539         start_writeback
3540 }
3541
3542 test_42c() {
3543         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3544         trunc_test 42c 1024
3545         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3546             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3547         rm $file
3548 }
3549 run_test 42c "test partial truncate of file with cached dirty data"
3550
3551 test_42d() {
3552         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3553         trunc_test 42d 0
3554         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3555             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3556         rm $file
3557 }
3558 run_test 42d "test complete truncate of file with cached dirty data"
3559
3560 test_42e() { # bug22074
3561         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3562         local TDIR=$DIR/${tdir}e
3563         local pagesz=$(page_size)
3564         local pages=16 # hardcoded 16 pages, don't change it.
3565         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3566         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3567         local max_dirty_mb
3568         local warmup_files
3569
3570         test_mkdir -p $DIR/${tdir}e
3571         $SETSTRIPE -c 1 $TDIR
3572         createmany -o $TDIR/f $files
3573
3574         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3575
3576         # we assume that with $OSTCOUNT files, at least one of them will
3577         # be allocated on OST0.
3578         warmup_files=$((OSTCOUNT * max_dirty_mb))
3579         createmany -o $TDIR/w $warmup_files
3580
3581         # write a large amount of data into one file and sync, to get good
3582         # avail_grant number from OST.
3583         for ((i=0; i<$warmup_files; i++)); do
3584                 idx=$($GETSTRIPE -i $TDIR/w$i)
3585                 [ $idx -ne 0 ] && continue
3586                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3587                 break
3588         done
3589         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3590         sync
3591         $LCTL get_param $proc_osc0/cur_dirty_bytes
3592         $LCTL get_param $proc_osc0/cur_grant_bytes
3593
3594         # create as much dirty pages as we can while not to trigger the actual
3595         # RPCs directly. but depends on the env, VFS may trigger flush during this
3596         # period, hopefully we are good.
3597         for ((i=0; i<$warmup_files; i++)); do
3598                 idx=$($GETSTRIPE -i $TDIR/w$i)
3599                 [ $idx -ne 0 ] && continue
3600                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3601         done
3602         $LCTL get_param $proc_osc0/cur_dirty_bytes
3603         $LCTL get_param $proc_osc0/cur_grant_bytes
3604
3605         # perform the real test
3606         $LCTL set_param $proc_osc0/rpc_stats 0
3607         for ((;i<$files; i++)); do
3608                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3609                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3610         done
3611         sync
3612         $LCTL get_param $proc_osc0/rpc_stats
3613
3614         local percent=0
3615         local have_ppr=false
3616         $LCTL get_param $proc_osc0/rpc_stats |
3617                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3618                         # skip lines until we are at the RPC histogram data
3619                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3620                         $have_ppr || continue
3621
3622                         # we only want the percent stat for < 16 pages
3623                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3624
3625                         percent=$((percent + WPCT))
3626                         if [[ $percent -gt 15 ]]; then
3627                                 error "less than 16-pages write RPCs" \
3628                                       "$percent% > 15%"
3629                                 break
3630                         fi
3631                 done
3632         rm -rf $TDIR
3633 }
3634 run_test 42e "verify sub-RPC writes are not done synchronously"
3635
3636 test_43() {
3637         test_mkdir -p $DIR/$tdir
3638         cp -p /bin/ls $DIR/$tdir/$tfile
3639         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3640         pid=$!
3641         # give multiop a chance to open
3642         sleep 1
3643
3644         $DIR/$tdir/$tfile && error || true
3645         kill -USR1 $pid
3646 }
3647 run_test 43 "execution of file opened for write should return -ETXTBSY"
3648
3649 test_43a() {
3650         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3651         test_mkdir -p $DIR/$tdir
3652         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3653                         cp -p multiop $DIR/$tdir/multiop
3654         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3655                         return 1
3656         MULTIOP_PID=$!
3657         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3658         kill -USR1 $MULTIOP_PID || return 2
3659         wait $MULTIOP_PID || return 3
3660         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3661 }
3662 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3663
3664 test_43b() {
3665         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3666         test_mkdir -p $DIR/$tdir
3667         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3668                         cp -p multiop $DIR/$tdir/multiop
3669         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3670                         return 1
3671         MULTIOP_PID=$!
3672         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3673         kill -USR1 $MULTIOP_PID || return 2
3674         wait $MULTIOP_PID || return 3
3675         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3676 }
3677 run_test 43b "truncate of file being executed should return -ETXTBSY"
3678
3679 test_43c() {
3680         local testdir="$DIR/$tdir"
3681         test_mkdir -p $DIR/$tdir
3682         cp $SHELL $testdir/
3683         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3684                 ( cd $testdir && md5sum -c)
3685 }
3686 run_test 43c "md5sum of copy into lustre========================"
3687
3688 test_44() {
3689         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3690         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3691         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3692 }
3693 run_test 44 "zero length read from a sparse stripe ============="
3694
3695 test_44a() {
3696         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3697                 awk '{ print $2 }')
3698         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3699         [[ $nstripe -gt $OSTCOUNT ]] &&
3700             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3701             return
3702         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3703                 awk '{ print $2 }')
3704         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3705                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3706                         awk '{ print $2 }')
3707         fi
3708
3709         OFFSETS="0 $((stride/2)) $((stride-1))"
3710         for offset in $OFFSETS; do
3711                 for i in $(seq 0 $((nstripe-1))); do
3712                         local GLOBALOFFSETS=""
3713                         # size in Bytes
3714                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3715                         local myfn=$DIR/d44a-$size
3716                         echo "--------writing $myfn at $size"
3717                         ll_sparseness_write $myfn $size ||
3718                                 error "ll_sparseness_write"
3719                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3720                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3721                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3722
3723                         for j in $(seq 0 $((nstripe-1))); do
3724                                 # size in Bytes
3725                                 size=$((((j + $nstripe )*$stride + $offset)))
3726                                 ll_sparseness_write $myfn $size ||
3727                                         error "ll_sparseness_write"
3728                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3729                         done
3730                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3731                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3732                         rm -f $myfn
3733                 done
3734         done
3735 }
3736 run_test 44a "test sparse pwrite ==============================="
3737
3738 dirty_osc_total() {
3739         tot=0
3740         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3741                 tot=$(($tot + $d))
3742         done
3743         echo $tot
3744 }
3745 do_dirty_record() {
3746         before=`dirty_osc_total`
3747         echo executing "\"$*\""
3748         eval $*
3749         after=`dirty_osc_total`
3750         echo before $before, after $after
3751 }
3752 test_45() {
3753         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3754         f="$DIR/f45"
3755         # Obtain grants from OST if it supports it
3756         echo blah > ${f}_grant
3757         stop_writeback
3758         sync
3759         do_dirty_record "echo blah > $f"
3760         [[ $before -eq $after ]] && error "write wasn't cached"
3761         do_dirty_record "> $f"
3762         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3763         do_dirty_record "echo blah > $f"
3764         [[ $before -eq $after ]] && error "write wasn't cached"
3765         do_dirty_record "sync"
3766         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3767         do_dirty_record "echo blah > $f"
3768         [[ $before -eq $after ]] && error "write wasn't cached"
3769         do_dirty_record "cancel_lru_locks osc"
3770         [[ $before -gt $after ]] ||
3771                 error "lock cancellation didn't lower dirty count"
3772         start_writeback
3773 }
3774 run_test 45 "osc io page accounting ============================"
3775
3776 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3777 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3778 # objects offset and an assert hit when an rpc was built with 1023's mapped
3779 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3780 test_46() {
3781         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3782         f="$DIR/f46"
3783         stop_writeback
3784         sync
3785         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3786         sync
3787         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3788         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3789         sync
3790         start_writeback
3791 }
3792 run_test 46 "dirtying a previously written page ================"
3793
3794 # test_47 is removed "Device nodes check" is moved to test_28
3795
3796 test_48a() { # bug 2399
3797         check_kernel_version 34 || return 0
3798         test_mkdir -p $DIR/$tdir
3799         cd $DIR/$tdir
3800         mv $DIR/$tdir $DIR/d48.new || error "move directory failed"
3801         test_mkdir $DIR/$tdir || error "recreate directory failed"
3802         touch foo || error "'touch foo' failed after recreating cwd"
3803         test_mkdir $DIR/$tdir/bar ||
3804                      error "'mkdir foo' failed after recreating cwd"
3805         if check_kernel_version 44; then
3806                 touch .foo || error "'touch .foo' failed after recreating cwd"
3807                 test_mkdir $DIR/$tdir/.bar ||
3808                               error "'mkdir .foo' failed after recreating cwd"
3809         fi
3810         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3811         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3812         cd . || error "'cd .' failed after recreating cwd"
3813         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3814         rmdir . && error "'rmdir .' worked after recreating cwd"
3815         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3816         cd .. || error "'cd ..' failed after recreating cwd"
3817 }
3818 run_test 48a "Access renamed working dir (should return errors)="
3819
3820 test_48b() { # bug 2399
3821         check_kernel_version 34 || return 0
3822         rm -rf $DIR/$tdir
3823         test_mkdir -p $DIR/$tdir
3824         cd $DIR/$tdir
3825         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3826         touch foo && error "'touch foo' worked after removing cwd"
3827         test_mkdir $DIR/$tdir/foo &&
3828                      error "'mkdir foo' worked after removing cwd"
3829         if check_kernel_version 44; then
3830                 touch .foo && error "'touch .foo' worked after removing cwd"
3831                 test_mkdir $DIR/$tdir/.foo &&
3832                               error "'mkdir .foo' worked after removing cwd"
3833         fi
3834         ls . > /dev/null && error "'ls .' worked after removing cwd"
3835         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3836         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3837         test_mkdir $DIR/$tdir/. && error "'mkdir .' worked after removing cwd"
3838         rmdir . && error "'rmdir .' worked after removing cwd"
3839         ln -s . foo && error "'ln -s .' worked after removing cwd"
3840         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3841 }
3842 run_test 48b "Access removed working dir (should return errors)="
3843
3844 test_48c() { # bug 2350
3845         check_kernel_version 36 || return 0
3846         #lctl set_param debug=-1
3847         #set -vx
3848         rm -rf $DIR/$tdir
3849         test_mkdir -p $DIR/$tdir/dir
3850         cd $DIR/$tdir/dir
3851         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3852         $TRACE touch foo && error "touch foo worked after removing cwd"
3853         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3854         if check_kernel_version 44; then
3855                 touch .foo && error "touch .foo worked after removing cwd"
3856                 test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3857         fi
3858         $TRACE ls . && error "'ls .' worked after removing cwd"
3859         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3860         is_patchless || ( $TRACE cd . &&
3861                         error "'cd .' worked after removing cwd" )
3862         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3863         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3864         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3865         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3866 }
3867 run_test 48c "Access removed working subdir (should return errors)"
3868
3869 test_48d() { # bug 2350
3870         check_kernel_version 36 || return 0
3871         #lctl set_param debug=-1
3872         #set -vx
3873         rm -rf $DIR/$tdir
3874         test_mkdir -p $DIR/$tdir/dir
3875         cd $DIR/$tdir/dir
3876         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3877         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3878         $TRACE touch foo && error "'touch foo' worked after removing parent"
3879         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3880         if check_kernel_version 44; then
3881                 touch .foo && error "'touch .foo' worked after removing parent"
3882                 test_mkdir .foo &&
3883                               error "mkdir .foo worked after removing parent"
3884         fi
3885         $TRACE ls . && error "'ls .' worked after removing parent"
3886         $TRACE ls .. && error "'ls ..' worked after removing parent"
3887         is_patchless || ( $TRACE cd . &&
3888                         error "'cd .' worked after recreate parent" )
3889         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3890         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3891         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3892         is_patchless || ( $TRACE cd .. &&
3893                         error "'cd ..' worked after removing parent" || true )
3894 }
3895 run_test 48d "Access removed parent subdir (should return errors)"
3896
3897 test_48e() { # bug 4134
3898         check_kernel_version 41 || return 0
3899         #lctl set_param debug=-1
3900         #set -vx
3901         rm -rf $DIR/$tdir
3902         test_mkdir -p $DIR/$tdir/dir
3903         cd $DIR/$tdir/dir
3904         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3905         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3906         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3907         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3908         # On a buggy kernel addition of "touch foo" after cd .. will
3909         # produce kernel oops in lookup_hash_it
3910         touch ../foo && error "'cd ..' worked after recreate parent"
3911         cd $DIR
3912         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3913 }
3914 run_test 48e "Access to recreated parent subdir (should return errors)"
3915
3916 test_49() { # LU-1030
3917         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3918         # get ost1 size - lustre-OST0000
3919         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3920                 awk '{ print $4 }')
3921         # write 800M at maximum
3922         [[ $ost1_size -lt 2 ]] && ost1_size=2
3923         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3924
3925         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3926         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3927         local dd_pid=$!
3928
3929         # change max_pages_per_rpc while writing the file
3930         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3931         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3932         # loop until dd process exits
3933         while ps ax -opid | grep -wq $dd_pid; do
3934                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3935                 sleep $((RANDOM % 5 + 1))
3936         done
3937         # restore original max_pages_per_rpc
3938         $LCTL set_param $osc1_mppc=$orig_mppc
3939         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3940 }
3941 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3942
3943 test_50() {
3944         # bug 1485
3945         test_mkdir $DIR/$tdir
3946         cd $DIR/$tdir
3947         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3948 }
3949 run_test 50 "special situations: /proc symlinks  ==============="
3950
3951 test_51a() {    # was test_51
3952         # bug 1516 - create an empty entry right after ".." then split dir
3953         test_mkdir -c1 $DIR/$tdir
3954         touch $DIR/$tdir/foo
3955         $MCREATE $DIR/$tdir/bar
3956         rm $DIR/$tdir/foo
3957         createmany -m $DIR/$tdir/longfile 201
3958         FNUM=202
3959         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
3960                 $MCREATE $DIR/$tdir/longfile$FNUM
3961                 FNUM=$(($FNUM + 1))
3962                 echo -n "+"
3963         done
3964         echo
3965         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
3966 }
3967 run_test 51a "special situations: split htree with empty entry =="
3968
3969 export NUMTEST=70000
3970 test_51b() {
3971         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3972         local BASE=$DIR/d${base}.${TESTSUITE}
3973
3974         # cleanup the directory
3975         rm -fr $BASE
3976
3977         test_mkdir -p -c1 $BASE
3978
3979         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
3980         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
3981         [[ $numfree -lt 21000 ]] && skip "not enough free inodes ($numfree)" &&
3982                 return
3983
3984         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3985                 echo "reduced count to $NUMTEST due to inodes"
3986
3987         # need to check free space for the directories as well
3988         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
3989         numfree=$((blkfree / 4))
3990         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3991                 echo "reduced count to $NUMTEST due to blocks"
3992
3993         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
3994                 echo "failed" > $BASE/fnum
3995 }
3996 run_test 51b "exceed 64k subdirectory nlink limit"
3997
3998 test_51ba() { # LU-993
3999         local BASE=$DIR/d${base}.${TESTSUITE}
4000         # unlink all but 100 subdirectories, then check it still works
4001         local LEFT=100
4002         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
4003
4004         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
4005         local DELETE=$((NUMTEST - LEFT))
4006
4007         # continue on to run this test even if 51b didn't finish,
4008         # just to delete the many subdirectories created.
4009         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
4010
4011         # for ldiskfs the nlink count should be 1, but this is OSD specific
4012         # and so this is listed for informational purposes only
4013         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
4014         unlinkmany -d $BASE/d $DELETE
4015         RC=$?
4016
4017         if [ $RC -ne 0 ]; then
4018                 if [ "$NUMPREV" == "failed" ]; then
4019                         skip "previous setup failed"
4020                         return 0
4021                 else
4022                         error "unlink of first $DELETE subdirs failed"
4023                         return $RC
4024                 fi
4025         fi
4026
4027         echo "nlink between: $(stat -c %h $BASE)"
4028         # trim the first line of ls output
4029         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
4030         [ $FOUND -ne $LEFT ] &&
4031                 error "can't find subdirs: found only $FOUND/$LEFT"
4032
4033         unlinkmany -d $BASE/d $DELETE $LEFT ||
4034                 error "unlink of second $LEFT subdirs failed"
4035         # regardless of whether the backing filesystem tracks nlink accurately
4036         # or not, the nlink count shouldn't be more than "." and ".." here
4037         local AFTER=$(stat -c %h $BASE)
4038         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
4039                 echo "nlink after: $AFTER"
4040 }
4041 run_test 51ba "verify nlink for many subdirectory cleanup"
4042
4043 test_51d() {
4044         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4045         [[ $OSTCOUNT -lt 3 ]] &&
4046                 skip_env "skipping test with few OSTs" && return
4047         test_mkdir -p $DIR/$tdir
4048         createmany -o $DIR/$tdir/t- 1000
4049         $GETSTRIPE $DIR/$tdir > $TMP/files
4050         for N in $(seq 0 $((OSTCOUNT - 1))); do
4051                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4052                         END { printf("%0.0f", objs) }' $TMP/files)
4053                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
4054                         '($1 == '$N') { objs += 1 } \
4055                         END { printf("%0.0f", objs) }')
4056                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4057         done
4058         unlinkmany $DIR/$tdir/t- 1000
4059
4060         NLAST=0
4061         for N in $(seq 1 $((OSTCOUNT - 1))); do
4062                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4063                         error "OST $N has less objects vs OST $NLAST" \
4064                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4065                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4066                         error "OST $N has less objects vs OST $NLAST" \
4067                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4068
4069                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4070                         error "OST $N has less #0 objects vs OST $NLAST" \
4071                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4072                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4073                         error "OST $N has less #0 objects vs OST $NLAST" \
4074                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4075                 NLAST=$N
4076         done
4077 }
4078 run_test 51d "check object distribution ===================="
4079
4080 test_51e() {
4081         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4082                 skip "Only applicable to ldiskfs-based MDTs"
4083                 return
4084         fi
4085
4086         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4087         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4088
4089         touch $DIR/$tdir/d0/foo
4090         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4091                 error "file exceed 65000 nlink limit!"
4092         unlinkmany $DIR/$tdir/d0/f- 65001
4093         return 0
4094 }
4095 run_test 51e "check file nlink limit"
4096
4097 test_52a() {
4098         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4099         test_mkdir -p $DIR/$tdir
4100         touch $DIR/$tdir/foo
4101         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4102         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4103         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4104         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4105         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4106                                         error "link worked"
4107         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4108         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4109         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4110                                                      error "lsattr"
4111         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4112         cp -r $DIR/$tdir /tmp/
4113         rm -fr $DIR/$tdir || error "cleanup rm failed"
4114 }
4115 run_test 52a "append-only flag test (should return errors) ====="
4116
4117 test_52b() {
4118         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4119         test_mkdir -p $DIR/$tdir
4120         touch $DIR/$tdir/foo
4121         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4122         cat test > $DIR/$tdir/foo && error "cat test worked"
4123         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4124         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4125         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4126                                         error "link worked"
4127         echo foo >> $DIR/$tdir/foo && error "echo worked"
4128         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4129         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4130         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4131         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4132                                                         error "lsattr"
4133         chattr -i $DIR/$tdir/foo || error "chattr failed"
4134
4135         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4136 }
4137 run_test 52b "immutable flag test (should return errors) ======="
4138
4139 test_53() {
4140         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4141         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4142         remote_ost_nodsh && skip "remote OST with nodsh" && return
4143
4144         local param
4145         local param_seq
4146         local ostname
4147         local mds_last
4148         local mds_last_seq
4149         local ost_last
4150         local ost_last_seq
4151         local ost_last_id
4152         local ostnum
4153         local node
4154         local found=false
4155         local support_last_seq=true
4156
4157         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4158                 support_last_seq=false
4159
4160         # only test MDT0000
4161         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4162         local value
4163         for value in $(do_facet $SINGLEMDS \
4164                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4165                 param=$(echo ${value[0]} | cut -d "=" -f1)
4166                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4167
4168                 if $support_last_seq; then
4169                         param_seq=$(echo $param |
4170                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4171                         mds_last_seq=$(do_facet $SINGLEMDS \
4172                                        $LCTL get_param -n $param_seq)
4173                 fi
4174                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4175
4176                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4177                 node=$(facet_active_host ost$((ostnum+1)))
4178                 param="obdfilter.$ostname.last_id"
4179                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4180                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4181                         ost_last_id=$ost_last
4182
4183                         if $support_last_seq; then
4184                                 ost_last_id=$(echo $ost_last |
4185                                               awk -F':' '{print $2}' |
4186                                               sed -e "s/^0x//g")
4187                                 ost_last_seq=$(echo $ost_last |
4188                                                awk -F':' '{print $1}')
4189                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4190                         fi
4191
4192                         if [[ $ost_last_id != $mds_last ]]; then
4193                                 error "$ost_last_id != $mds_last"
4194                         else
4195                                 found=true
4196                                 break
4197                         fi
4198                 done
4199         done
4200         $found || error "can not match last_seq/last_id for $mdtosc"
4201         return 0
4202 }
4203 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4204
4205 test_54a() {
4206         $SOCKETSERVER $DIR/socket ||
4207                 error "$SOCKETSERVER $DIR/socket failed: $?"
4208         $SOCKETCLIENT $DIR/socket ||
4209                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4210         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4211 }
4212 run_test 54a "unix domain socket test =========================="
4213
4214 test_54b() {
4215         f="$DIR/f54b"
4216         mknod $f c 1 3
4217         chmod 0666 $f
4218         dd if=/dev/zero of=$f bs=$(page_size) count=1
4219 }
4220 run_test 54b "char device works in lustre ======================"
4221
4222 find_loop_dev() {
4223         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4224         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4225         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4226
4227         for i in $(seq 3 7); do
4228                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4229                 LOOPDEV=$LOOPBASE$i
4230                 LOOPNUM=$i
4231                 break
4232         done
4233 }
4234
4235 cleanup_54c() {
4236         loopdev="$DIR/loop54c"
4237
4238         trap 0
4239         $UMOUNT -d $DIR/$tdir || rc=$?
4240         losetup -d $loopdev || true
4241         losetup -d $LOOPDEV || true
4242         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4243         return $rc
4244 }
4245
4246 test_54c() {
4247         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4248         loopdev="$DIR/loop54c"
4249
4250         find_loop_dev
4251         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4252         trap cleanup_54c EXIT
4253         mknod $loopdev b 7 $LOOPNUM
4254         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4255         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4256         losetup $loopdev $DIR/$tfile ||
4257                 error "can't set up $loopdev for $DIR/$tfile"
4258         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4259         test_mkdir -p $DIR/$tdir
4260         mount -t ext2 $loopdev $DIR/$tdir ||
4261                 error "error mounting $loopdev on $DIR/$tdir"
4262         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4263                 error "dd write"
4264         df $DIR/$tdir
4265         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4266                 error "dd read"
4267         cleanup_54c
4268 }
4269 run_test 54c "block device works in lustre ====================="
4270
4271 test_54d() {
4272         f="$DIR/f54d"
4273         string="aaaaaa"
4274         mknod $f p
4275         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4276 }
4277 run_test 54d "fifo device works in lustre ======================"
4278
4279 test_54e() {
4280         check_kernel_version 46 || return 0
4281         f="$DIR/f54e"
4282         string="aaaaaa"
4283         cp -aL /dev/console $f
4284         echo $string > $f || error "echo $string to $f failed"
4285 }
4286 run_test 54e "console/tty device works in lustre ======================"
4287
4288 #The test_55 used to be iopen test and it was removed by bz#24037.
4289 #run_test 55 "check iopen_connect_dentry() ======================"
4290
4291 test_56a() {    # was test_56
4292         rm -rf $DIR/$tdir
4293         $SETSTRIPE -d $DIR
4294         test_mkdir -p $DIR/$tdir/dir
4295         NUMFILES=3
4296         NUMFILESx2=$(($NUMFILES * 2))
4297         for i in $(seq 1 $NUMFILES); do
4298                 touch $DIR/$tdir/file$i
4299                 touch $DIR/$tdir/dir/file$i
4300         done
4301
4302         # test lfs getstripe with --recursive
4303         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4304         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4305                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4306         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4307         [[ $FILENUM -eq $NUMFILES ]] ||
4308                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4309         echo "$GETSTRIPE --recursive passed."
4310
4311         # test lfs getstripe with file instead of dir
4312         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4313         [[ $FILENUM -eq 1 ]] ||
4314                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4315         echo "$GETSTRIPE file1 passed."
4316
4317         #test lfs getstripe with --verbose
4318         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4319                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4320                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4321         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4322                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4323         echo "$GETSTRIPE --verbose passed."
4324
4325         #test lfs getstripe with --obd
4326         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4327                 grep -q "unknown obduuid" ||
4328                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4329
4330         [[ $OSTCOUNT -lt 2 ]] &&
4331                 skip_env "skipping other $GETSTRIPE --obd test" && return
4332
4333         OSTIDX=1
4334         OBDUUID=$(ostuuid_from_index $OSTIDX)
4335         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4336         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4337         [[ $FOUND -eq $FILENUM ]] ||
4338                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4339         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4340                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4341                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4342                 error "$GETSTRIPE --obd: should not show file on other obd"
4343         echo "$GETSTRIPE --obd passed"
4344 }
4345 run_test 56a "check $GETSTRIPE"
4346
4347 NUMFILES=3
4348 NUMDIRS=3
4349 setup_56() {
4350         local LOCAL_NUMFILES="$1"
4351         local LOCAL_NUMDIRS="$2"
4352         local MKDIR_PARAMS="$3"
4353         local DIR_STRIPE_PARAMS="$4"
4354
4355         if [ ! -d "$TDIR" ] ; then
4356                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4357                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4358                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4359                         touch $TDIR/file$i
4360                 done
4361                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4362                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4363                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4364                                 touch $TDIR/dir$i/file$j
4365                         done
4366                 done
4367         fi
4368 }
4369
4370 setup_56_special() {
4371         LOCAL_NUMFILES=$1
4372         LOCAL_NUMDIRS=$2
4373         setup_56 $1 $2
4374         if [ ! -e "$TDIR/loop1b" ] ; then
4375                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4376                         mknod $TDIR/loop${i}b b 7 $i
4377                         mknod $TDIR/null${i}c c 1 3
4378                         ln -s $TDIR/file1 $TDIR/link${i}l
4379                 done
4380                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4381                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4382                         mknod $TDIR/dir$i/null${i}c c 1 3
4383                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4384                 done
4385         fi
4386 }
4387
4388 test_56g() {
4389         $SETSTRIPE -d $DIR
4390
4391         TDIR=$DIR/${tdir}g
4392         setup_56 $NUMFILES $NUMDIRS
4393
4394         EXPECTED=$(($NUMDIRS + 2))
4395         # test lfs find with -name
4396         for i in $(seq 1 $NUMFILES) ; do
4397                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4398                 [ $NUMS -eq $EXPECTED ] ||
4399                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4400                               "found $NUMS, expected $EXPECTED"
4401         done
4402 }
4403 run_test 56g "check lfs find -name ============================="
4404
4405 test_56h() {
4406         $SETSTRIPE -d $DIR
4407
4408         TDIR=$DIR/${tdir}g
4409         setup_56 $NUMFILES $NUMDIRS
4410
4411         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4412         # test lfs find with ! -name
4413         for i in $(seq 1 $NUMFILES) ; do
4414                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4415                 [ $NUMS -eq $EXPECTED ] ||
4416                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4417                               "found $NUMS, expected $EXPECTED"
4418         done
4419 }
4420 run_test 56h "check lfs find ! -name ============================="
4421
4422 test_56i() {
4423        tdir=${tdir}i
4424        test_mkdir -p $DIR/$tdir
4425        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4426        CMD="$LFIND -ost $UUID $DIR/$tdir"
4427        OUT=$($CMD)
4428        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4429 }
4430 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4431
4432 test_56j() {
4433         TDIR=$DIR/${tdir}g
4434         setup_56_special $NUMFILES $NUMDIRS
4435
4436         EXPECTED=$((NUMDIRS + 1))
4437         CMD="$LFIND -type d $TDIR"
4438         NUMS=$($CMD | wc -l)
4439         [ $NUMS -eq $EXPECTED ] ||
4440                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4441 }
4442 run_test 56j "check lfs find -type d ============================="
4443
4444 test_56k() {
4445         TDIR=$DIR/${tdir}g
4446         setup_56_special $NUMFILES $NUMDIRS
4447
4448         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4449         CMD="$LFIND -type f $TDIR"
4450         NUMS=$($CMD | wc -l)
4451         [ $NUMS -eq $EXPECTED ] ||
4452                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4453 }
4454 run_test 56k "check lfs find -type f ============================="
4455
4456 test_56l() {
4457         TDIR=$DIR/${tdir}g
4458         setup_56_special $NUMFILES $NUMDIRS
4459
4460         EXPECTED=$((NUMDIRS + NUMFILES))
4461         CMD="$LFIND -type b $TDIR"
4462         NUMS=$($CMD | wc -l)
4463         [ $NUMS -eq $EXPECTED ] ||
4464                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4465 }
4466 run_test 56l "check lfs find -type b ============================="
4467
4468 test_56m() {
4469         TDIR=$DIR/${tdir}g
4470         setup_56_special $NUMFILES $NUMDIRS
4471
4472         EXPECTED=$((NUMDIRS + NUMFILES))
4473         CMD="$LFIND -type c $TDIR"
4474         NUMS=$($CMD | wc -l)
4475         [ $NUMS -eq $EXPECTED ] ||
4476                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4477 }
4478 run_test 56m "check lfs find -type c ============================="
4479
4480 test_56n() {
4481         TDIR=$DIR/${tdir}g
4482         setup_56_special $NUMFILES $NUMDIRS
4483
4484         EXPECTED=$((NUMDIRS + NUMFILES))
4485         CMD="$LFIND -type l $TDIR"
4486         NUMS=$($CMD | wc -l)
4487         [ $NUMS -eq $EXPECTED ] ||
4488                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4489 }
4490 run_test 56n "check lfs find -type l ============================="
4491
4492 test_56o() {
4493         TDIR=$DIR/${tdir}o
4494         setup_56 $NUMFILES $NUMDIRS
4495         utime $TDIR/file1 > /dev/null || error "utime (1)"
4496         utime $TDIR/file2 > /dev/null || error "utime (2)"
4497         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4498         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4499         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4500         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4501
4502         EXPECTED=4
4503         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4504         [ $NUMS -eq $EXPECTED ] || \
4505                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4506
4507         EXPECTED=12
4508         CMD="$LFIND -mtime 0 $TDIR"
4509         NUMS=$($CMD | wc -l)
4510         [ $NUMS -eq $EXPECTED ] ||
4511                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4512 }
4513 run_test 56o "check lfs find -mtime for old files =========================="
4514
4515 test_56p() {
4516         [ $RUNAS_ID -eq $UID ] &&
4517                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4518
4519         TDIR=$DIR/${tdir}p
4520         setup_56 $NUMFILES $NUMDIRS
4521
4522         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4523         EXPECTED=$NUMFILES
4524         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4525         NUMS=$($CMD | wc -l)
4526         [ $NUMS -eq $EXPECTED ] || \
4527                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4528
4529         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4530         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4531         NUMS=$($CMD | wc -l)
4532         [ $NUMS -eq $EXPECTED ] || \
4533                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4534 }
4535 run_test 56p "check lfs find -uid and ! -uid ==============================="
4536
4537 test_56q() {
4538         [ $RUNAS_ID -eq $UID ] &&
4539                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4540
4541         TDIR=$DIR/${tdir}q
4542         setup_56 $NUMFILES $NUMDIRS
4543
4544         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4545
4546         EXPECTED=$NUMFILES
4547         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4548         NUMS=$($CMD | wc -l)
4549         [ $NUMS -eq $EXPECTED ] ||
4550                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4551
4552         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4553         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4554         NUMS=$($CMD | wc -l)
4555         [ $NUMS -eq $EXPECTED ] ||
4556                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4557 }
4558 run_test 56q "check lfs find -gid and ! -gid ==============================="
4559
4560 test_56r() {
4561         TDIR=$DIR/${tdir}r
4562         setup_56 $NUMFILES $NUMDIRS
4563
4564         EXPECTED=12
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         EXPECTED=0
4570         CMD="$LFIND ! -size 0 -type f $TDIR"
4571         NUMS=$($CMD | wc -l)
4572         [ $NUMS -eq $EXPECTED ] ||
4573                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4574         echo "test" > $TDIR/$tfile
4575         echo "test2" > $TDIR/$tfile.2 && sync
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=1
4582         CMD="$LFIND -size +5 -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 +0 -type f $TDIR"
4588         NUMS=$($CMD | wc -l)
4589         [ $NUMS -eq $EXPECTED ] ||
4590                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4591         EXPECTED=2
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         EXPECTED=12
4597         CMD="$LFIND -size -5 -type f $TDIR"
4598         NUMS=$($CMD | wc -l)
4599         [ $NUMS -eq $EXPECTED ] ||
4600                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4601 }
4602 run_test 56r "check lfs find -size works =========================="
4603
4604 test_56s() { # LU-611
4605         TDIR=$DIR/${tdir}s
4606         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4607
4608         if [[ $OSTCOUNT -gt 1 ]]; then
4609                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4610                 ONESTRIPE=4
4611                 EXTRA=4
4612         else
4613                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4614                 EXTRA=0
4615         fi
4616
4617         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4618         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4619         NUMS=$($CMD | wc -l)
4620         [ $NUMS -eq $EXPECTED ] || {
4621                 $GETSTRIPE -R $TDIR
4622                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4623         }
4624
4625         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4626         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4627         NUMS=$($CMD | wc -l)
4628         [ $NUMS -eq $EXPECTED ] || {
4629                 $GETSTRIPE -R $TDIR
4630                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4631         }
4632
4633         EXPECTED=$ONESTRIPE
4634         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4635         NUMS=$($CMD | wc -l)
4636         [ $NUMS -eq $EXPECTED ] || {
4637                 $GETSTRIPE -R $TDIR
4638                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4639         }
4640
4641         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4642         NUMS=$($CMD | wc -l)
4643         [ $NUMS -eq $EXPECTED ] || {
4644                 $GETSTRIPE -R $TDIR
4645                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4646         }
4647
4648         EXPECTED=0
4649         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4650         NUMS=$($CMD | wc -l)
4651         [ $NUMS -eq $EXPECTED ] || {
4652                 $GETSTRIPE -R $TDIR
4653                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4654         }
4655 }
4656 run_test 56s "check lfs find -stripe-count works"
4657
4658 test_56t() { # LU-611
4659         TDIR=$DIR/${tdir}t
4660         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4661
4662         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4663
4664         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4665         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4666         NUMS=$($CMD | wc -l)
4667         [ $NUMS -eq $EXPECTED ] ||
4668                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4669
4670         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4671         NUMS=$($CMD | wc -l)
4672         [ $NUMS -eq $EXPECTED ] ||
4673                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4674
4675         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4676         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4677         NUMS=$($CMD | wc -l)
4678         [ $NUMS -eq $EXPECTED ] ||
4679                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4680
4681         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4682         NUMS=$($CMD | wc -l)
4683         [ $NUMS -eq $EXPECTED ] ||
4684                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4685
4686         EXPECTED=4
4687         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4688         NUMS=$($CMD | wc -l)
4689         [ $NUMS -eq $EXPECTED ] ||
4690                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4691
4692         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4693         NUMS=$($CMD | wc -l)
4694         [ $NUMS -eq $EXPECTED ] ||
4695                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4696
4697         EXPECTED=0
4698         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4699         NUMS=$($CMD | wc -l)
4700         [ $NUMS -eq $EXPECTED ] ||
4701                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4702 }
4703 run_test 56t "check lfs find -stripe-size works"
4704
4705 test_56u() { # LU-611
4706         TDIR=$DIR/${tdir}u
4707         setup_56 $NUMFILES $NUMDIRS "-i 0"
4708
4709         if [[ $OSTCOUNT -gt 1 ]]; then
4710                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4711                 ONESTRIPE=4
4712         else
4713                 ONESTRIPE=0
4714         fi
4715
4716         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4717         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4718         NUMS=$($CMD | wc -l)
4719         [ $NUMS -eq $EXPECTED ] ||
4720                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4721
4722         EXPECTED=$ONESTRIPE
4723         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4724         NUMS=$($CMD | wc -l)
4725         [ $NUMS -eq $EXPECTED ] ||
4726                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4727
4728         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4729         NUMS=$($CMD | wc -l)
4730         [ $NUMS -eq $EXPECTED ] ||
4731                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4732
4733         EXPECTED=0
4734         # This should produce an error and not return any files
4735         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4736         NUMS=$($CMD 2>/dev/null | wc -l)
4737         [ $NUMS -eq $EXPECTED ] ||
4738                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4739
4740         if [[ $OSTCOUNT -gt 1 ]]; then
4741                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4742                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4743                 NUMS=$($CMD | wc -l)
4744                 [ $NUMS -eq $EXPECTED ] ||
4745                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4746         fi
4747 }
4748 run_test 56u "check lfs find -stripe-index works"
4749
4750 test_56v() {
4751     local MDT_IDX=0
4752
4753     TDIR=$DIR/${tdir}v
4754     rm -rf $TDIR
4755     setup_56 $NUMFILES $NUMDIRS
4756
4757     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4758     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4759
4760     for file in $($LFIND -mdt $UUID $TDIR); do
4761         file_mdt_idx=$($GETSTRIPE -M $file)
4762         [ $file_mdt_idx -eq $MDT_IDX ] ||
4763             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4764     done
4765 }
4766 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4767
4768 # Get and check the actual stripe count of one file.
4769 # Usage: check_stripe_count <file> <expected_stripe_count>
4770 check_stripe_count() {
4771     local file=$1
4772     local expected=$2
4773     local actual
4774
4775     [[ -z "$file" || -z "$expected" ]] &&
4776         error "check_stripe_count: invalid argument!"
4777
4778     local cmd="$GETSTRIPE -c $file"
4779     actual=$($cmd) || error "$cmd failed"
4780     actual=${actual%% *}
4781
4782     if [[ $actual -ne $expected ]]; then
4783         [[ $expected -eq -1 ]] ||
4784             error "$cmd wrong: found $actual, expected $expected"
4785         [[ $actual -eq $OSTCOUNT ]] ||
4786             error "$cmd wrong: found $actual, expected $OSTCOUNT"
4787     fi
4788 }
4789
4790 test_56w() {
4791         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4792         TDIR=$DIR/${tdir}w
4793
4794     rm -rf $TDIR || error "remove $TDIR failed"
4795     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4796
4797     local stripe_size
4798     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4799         error "$GETSTRIPE -S -d $TDIR failed"
4800     stripe_size=${stripe_size%% *}
4801
4802     local file_size=$((stripe_size * OSTCOUNT))
4803     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4804     local required_space=$((file_num * file_size))
4805     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4806     [[ $free_space -le $((required_space / 1024)) ]] &&
4807         skip_env "need at least $required_space bytes free space," \
4808                  "have $free_space kbytes" && return
4809
4810     local dd_bs=65536
4811     local dd_count=$((file_size / dd_bs))
4812
4813     # write data into the files
4814     local i
4815     local j
4816     local file
4817     for i in $(seq 1 $NUMFILES); do
4818         file=$TDIR/file$i
4819         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4820             error "write data into $file failed"
4821     done
4822     for i in $(seq 1 $NUMDIRS); do
4823         for j in $(seq 1 $NUMFILES); do
4824             file=$TDIR/dir$i/file$j
4825             yes | dd bs=$dd_bs count=$dd_count of=$file \
4826                 >/dev/null 2>&1 ||
4827                 error "write data into $file failed"
4828         done
4829     done
4830
4831     local expected=-1
4832     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4833
4834     # lfs_migrate file
4835     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4836     echo "$cmd"
4837     eval $cmd || error "$cmd failed"
4838
4839     check_stripe_count $TDIR/file1 $expected
4840
4841     # lfs_migrate dir
4842     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4843     echo "$cmd"
4844     eval $cmd || error "$cmd failed"
4845
4846     for j in $(seq 1 $NUMFILES); do
4847         check_stripe_count $TDIR/dir1/file$j $expected
4848     done
4849
4850     # lfs_migrate works with lfs find
4851     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4852          $LFS_MIGRATE -y -c $expected"
4853     echo "$cmd"
4854     eval $cmd || error "$cmd failed"
4855
4856     for i in $(seq 2 $NUMFILES); do
4857         check_stripe_count $TDIR/file$i $expected
4858     done
4859     for i in $(seq 2 $NUMDIRS); do
4860         for j in $(seq 1 $NUMFILES); do
4861             check_stripe_count $TDIR/dir$i/file$j $expected
4862         done
4863     done
4864 }
4865 run_test 56w "check lfs_migrate -c stripe_count works"
4866
4867 test_56x() {
4868         check_swap_layouts_support && return 0
4869         [[ $OSTCOUNT -lt 2 ]] &&
4870                 skip_env "need 2 OST, skipping test" && return
4871
4872         local dir0=$DIR/$tdir/$testnum
4873         mkdir -p $dir0 || error "creating dir $dir0"
4874
4875         local ref1=/etc/passwd
4876         local file1=$dir0/file1
4877
4878         $SETSTRIPE -c 2 $file1
4879         cp $ref1 $file1
4880         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4881         stripe=$($GETSTRIPE -c $file1)
4882         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4883         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4884
4885         # clean up
4886         rm -f $file1
4887 }
4888 run_test 56x "lfs migration support"
4889
4890 test_56y() {
4891         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4892                 skip "No HSM support on MDS of $(get_lustre_version)," \
4893                          "need 2.4.53 at least" && return
4894         local res=""
4895
4896         local dir0=$DIR/$tdir/$testnum
4897         mkdir -p $dir0 || error "creating dir $dir0"
4898         local f1=$dir0/file1
4899         local f2=$dir0/file2
4900
4901         touch $f1 || error "creating std file $f1"
4902         $MULTIOP $f2 H2c || error "creating released file $f2"
4903
4904         # a directory can be raid0, so ask only for files
4905         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4906         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4907
4908         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4909         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4910
4911         # only files can be released, so no need to force file search
4912         res=$($LFIND $dir0 -L released)
4913         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4914
4915         res=$($LFIND $dir0 \! -L released)
4916         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4917
4918 }
4919 run_test 56y "lfs find -L raid0|released"
4920
4921 test_56z() { # LU-4824
4922         # This checks to make sure 'lfs find' continues after errors
4923         # There are two classes of errors that should be caught:
4924         # - If multiple paths are provided, all should be searched even if one
4925         #   errors out
4926         # - If errors are encountered during the search, it should not terminate
4927         #   early
4928         local i
4929         test_mkdir $DIR/$tdir
4930         for i in d{0..9}; do
4931                 test_mkdir $DIR/$tdir/$i
4932         done
4933         touch $DIR/$tdir/d{0..9}/$tfile
4934         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
4935                 error "$LFS find did not return an error"
4936         # Make a directory unsearchable. This should NOT be the last entry in
4937         # directory order.  Arbitrarily pick the 6th entry
4938         chmod 700 $(lfs find $DIR/$tdir -type d | sed '6!d')
4939         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
4940         # The user should be able to see 10 directories and 9 files
4941         [ $count == 19 ] || error "$LFS find did not continue after error"
4942 }
4943 run_test 56z "lfs find should continue after an error"
4944
4945 test_57a() {
4946         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4947         # note test will not do anything if MDS is not local
4948         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4949                 skip "Only applicable to ldiskfs-based MDTs"
4950                 return
4951         fi
4952
4953         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4954         local MNTDEV="osd*.*MDT*.mntdev"
4955         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
4956         [ -z "$DEV" ] && error "can't access $MNTDEV"
4957         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
4958                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
4959                         error "can't access $DEV"
4960                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
4961                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
4962                 rm $TMP/t57a.dump
4963         done
4964 }
4965 run_test 57a "verify MDS filesystem created with large inodes =="
4966
4967 test_57b() {
4968         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4969         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4970                 skip "Only applicable to ldiskfs-based MDTs"
4971                 return
4972         fi
4973
4974         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4975         local dir=$DIR/d57b
4976
4977         local FILECOUNT=100
4978         local FILE1=$dir/f1
4979         local FILEN=$dir/f$FILECOUNT
4980
4981         rm -rf $dir || error "removing $dir"
4982         test_mkdir -p $dir || error "creating $dir"
4983         local num=$(get_mds_dir $dir)
4984         local mymds=mds$num
4985
4986         echo "mcreating $FILECOUNT files"
4987         createmany -m $dir/f 1 $FILECOUNT || \
4988                 error "creating files in $dir"
4989
4990         # verify that files do not have EAs yet
4991         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
4992         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
4993
4994         sync
4995         sleep 1
4996         df $dir  #make sure we get new statfs data
4997         local MDSFREE=$(do_facet $mymds \
4998                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4999         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
5000         echo "opening files to create objects/EAs"
5001         local FILE
5002         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5003                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5004         done
5005
5006         # verify that files have EAs now
5007         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5008         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5009
5010         sleep 1  #make sure we get new statfs data
5011         df $dir
5012         local MDSFREE2=$(do_facet $mymds \
5013                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
5014         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
5015         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5016                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5017                         error "MDC before $MDCFREE != after $MDCFREE2"
5018                 else
5019                         echo "MDC before $MDCFREE != after $MDCFREE2"
5020                         echo "unable to confirm if MDS has large inodes"
5021                 fi
5022         fi
5023         rm -rf $dir
5024 }
5025 run_test 57b "default LOV EAs are stored inside large inodes ==="
5026
5027 test_58() {
5028         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5029         [ -z "$(which wiretest 2>/dev/null)" ] &&
5030                         skip_env "could not find wiretest" && return
5031         wiretest
5032 }
5033 run_test 58 "verify cross-platform wire constants =============="
5034
5035 test_59() {
5036         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5037         echo "touch 130 files"
5038         createmany -o $DIR/f59- 130
5039         echo "rm 130 files"
5040         unlinkmany $DIR/f59- 130
5041         sync
5042         # wait for commitment of removal
5043         wait_delete_completed
5044 }
5045 run_test 59 "verify cancellation of llog records async ========="
5046
5047 TEST60_HEAD="test_60 run $RANDOM"
5048 test_60a() {
5049         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5050         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5051         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5052                 skip_env "missing subtest run-llog.sh" && return
5053         log "$TEST60_HEAD - from kernel mode"
5054         do_facet mgs sh run-llog.sh
5055 }
5056 run_test 60a "llog sanity tests run from kernel module =========="
5057
5058 test_60b() { # bug 6411
5059         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5060         dmesg > $DIR/$tfile
5061         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
5062                                  /llog.test/ {
5063                                          if (marker)
5064                                                  from_marker++
5065                                          from_begin++
5066                                  }
5067                                  END {
5068                                          if (marker)
5069                                                  print from_marker
5070                                          else
5071                                                  print from_begin
5072                                  }"`
5073         [[ $LLOG_COUNT -gt 50 ]] &&
5074                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5075 }
5076 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5077
5078 test_60c() {
5079         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5080         echo "create 5000 files"
5081         createmany -o $DIR/f60c- 5000
5082 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5083         lctl set_param fail_loc=0x80000137
5084         unlinkmany $DIR/f60c- 5000
5085         lctl set_param fail_loc=0
5086 }
5087 run_test 60c "unlink file when mds full"
5088
5089 test_60d() {
5090         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5091         SAVEPRINTK=$(lctl get_param -n printk)
5092
5093         # verify "lctl mark" is even working"
5094         MESSAGE="test message ID $RANDOM $$"
5095         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5096         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5097
5098         lctl set_param printk=0 || error "set lnet.printk failed"
5099         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5100         MESSAGE="new test message ID $RANDOM $$"
5101         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5102         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5103         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5104
5105         lctl set_param -n printk="$SAVEPRINTK"
5106 }
5107 run_test 60d "test printk console message masking"
5108
5109 test_61() {
5110         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5111         f="$DIR/f61"
5112         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5113         cancel_lru_locks osc
5114         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5115         sync
5116 }
5117 run_test 61 "mmap() writes don't make sync hang ================"
5118
5119 # bug 2330 - insufficient obd_match error checking causes LBUG
5120 test_62() {
5121         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5122         f="$DIR/f62"
5123         echo foo > $f
5124         cancel_lru_locks osc
5125         lctl set_param fail_loc=0x405
5126         cat $f && error "cat succeeded, expect -EIO"
5127         lctl set_param fail_loc=0
5128 }
5129 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5130 # match every page all of the time.
5131 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5132
5133 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5134 # Though this test is irrelevant anymore, it helped to reveal some
5135 # other grant bugs (LU-4482), let's keep it.
5136 test_63a() {   # was test_63
5137         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5138         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5139         for i in `seq 10` ; do
5140                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5141                 sleep 5
5142                 kill $!
5143                 sleep 1
5144         done
5145
5146         rm -f $DIR/f63 || true
5147 }
5148 run_test 63a "Verify oig_wait interruption does not crash ======="
5149
5150 # bug 2248 - async write errors didn't return to application on sync
5151 # bug 3677 - async write errors left page locked
5152 test_63b() {
5153         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5154         debugsave
5155         lctl set_param debug=-1
5156
5157         # ensure we have a grant to do async writes
5158         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5159         rm $DIR/$tfile
5160
5161         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5162         lctl set_param fail_loc=0x80000406
5163         $MULTIOP $DIR/$tfile Owy && \
5164                 error "sync didn't return ENOMEM"
5165         sync; sleep 2; sync     # do a real sync this time to flush page
5166         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5167                 error "locked page left in cache after async error" || true
5168         debugrestore
5169 }
5170 run_test 63b "async write errors should be returned to fsync ==="
5171
5172 test_64a () {
5173         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5174         df $DIR
5175         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5176 }
5177 run_test 64a "verify filter grant calculations (in kernel) ====="
5178
5179 test_64b () {
5180         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5181         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5182 }
5183 run_test 64b "check out-of-space detection on client ==========="
5184
5185 test_64c() {
5186         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5187 }
5188 run_test 64c "verify grant shrink ========================------"
5189
5190 # bug 1414 - set/get directories' stripe info
5191 test_65a() {
5192         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5193         test_mkdir -p $DIR/$tdir
5194         touch $DIR/$tdir/f1
5195         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5196 }
5197 run_test 65a "directory with no stripe info ===================="
5198
5199 test_65b() {
5200         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5201         test_mkdir -p $DIR/$tdir
5202         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5203                                                 error "setstripe"
5204         touch $DIR/$tdir/f2
5205         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5206 }
5207 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
5208
5209 test_65c() {
5210         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5211         if [[ $OSTCOUNT -gt 1 ]]; then
5212                 test_mkdir -p $DIR/$tdir
5213                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5214                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5215                 touch $DIR/$tdir/f3
5216                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5217         fi
5218 }
5219 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
5220
5221 test_65d() {
5222         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5223         test_mkdir -p $DIR/$tdir
5224         if [[ $STRIPECOUNT -le 0 ]]; then
5225                 sc=1
5226         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5227 #LOV_MAX_STRIPE_COUNT is 2000
5228                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5229         else
5230                 sc=$(($STRIPECOUNT - 1))
5231         fi
5232         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5233         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5234         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5235                 error "lverify failed"
5236 }
5237 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
5238
5239 test_65e() {
5240         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5241         test_mkdir -p $DIR/$tdir
5242
5243         $SETSTRIPE $DIR/$tdir || error "setstripe"
5244         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5245                                         error "no stripe info failed"
5246         touch $DIR/$tdir/f6
5247         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5248 }
5249 run_test 65e "directory setstripe defaults ======================="
5250
5251 test_65f() {
5252         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5253         test_mkdir -p $DIR/${tdir}f
5254         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5255 }
5256 run_test 65f "dir setstripe permission (should return error) ==="
5257
5258 test_65g() {
5259         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5260         test_mkdir -p $DIR/$tdir
5261         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5262                                                         error "setstripe"
5263         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5264         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5265                 error "delete default stripe failed"
5266 }
5267 run_test 65g "directory setstripe -d ==========================="
5268
5269 test_65h() {
5270         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5271         test_mkdir -p $DIR/$tdir
5272         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5273                                                         error "setstripe"
5274         test_mkdir -p $DIR/$tdir/dd1
5275         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5276                 error "stripe info inherit failed"
5277 }
5278 run_test 65h "directory stripe info inherit ===================="
5279
5280 test_65i() { # bug6367
5281         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5282         $SETSTRIPE -S 65536 -c -1 $MOUNT
5283 }
5284 run_test 65i "set non-default striping on root directory (bug 6367)="
5285
5286 test_65ia() { # bug12836
5287         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5288         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5289 }
5290 run_test 65ia "getstripe on -1 default directory striping"
5291
5292 test_65ib() { # bug12836
5293         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5294         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5295 }
5296 run_test 65ib "getstripe -v on -1 default directory striping"
5297
5298 test_65ic() { # bug12836
5299         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5300         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5301 }
5302 run_test 65ic "new find on -1 default directory striping"
5303
5304 test_65j() { # bug6367
5305         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5306         sync; sleep 1
5307         # if we aren't already remounting for each test, do so for this test
5308         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5309                 cleanup || error "failed to unmount"
5310                 setup
5311         fi
5312         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5313 }
5314 run_test 65j "set default striping on root directory (bug 6367)="
5315
5316 test_65k() { # bug11679
5317         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5318         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5319         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5320
5321     echo "Check OST status: "
5322     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5323               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5324
5325     for OSC in $MDS_OSCS; do
5326         echo $OSC "is activate"
5327         do_facet $SINGLEMDS lctl --device %$OSC activate
5328     done
5329
5330     mkdir -p $DIR/$tdir
5331     for INACTIVE_OSC in $MDS_OSCS; do
5332         echo "Deactivate: " $INACTIVE_OSC
5333         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5334         for STRIPE_OSC in $MDS_OSCS; do
5335             OST=`osc_to_ost $STRIPE_OSC`
5336             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5337                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5338
5339             [ -f $DIR/$tdir/$IDX ] && continue
5340             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5341             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5342             RC=$?
5343             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5344         done
5345         rm -f $DIR/$tdir/*
5346         echo $INACTIVE_OSC "is Activate."
5347         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5348     done
5349 }
5350 run_test 65k "validate manual striping works properly with deactivated OSCs"
5351
5352 test_65l() { # bug 12836
5353         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5354         test_mkdir -p $DIR/$tdir/test_dir
5355         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5356         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5357 }
5358 run_test 65l "lfs find on -1 stripe dir ========================"
5359
5360 # bug 2543 - update blocks count on client
5361 test_66() {
5362         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5363         COUNT=${COUNT:-8}
5364         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5365         sync; sync_all_data; sync; sync_all_data
5366         cancel_lru_locks osc
5367         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5368         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5369 }
5370 run_test 66 "update inode blocks count on client ==============="
5371
5372 LLOOP=
5373 LLITELOOPLOAD=
5374 cleanup_68() {
5375         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5376         trap 0
5377         if [ ! -z "$LLOOP" ]; then
5378                 if swapon -s | grep -q $LLOOP; then
5379                         swapoff $LLOOP || error "swapoff failed"
5380                 fi
5381
5382                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5383                 rm -f $LLOOP
5384                 unset LLOOP
5385         fi
5386         if [ ! -z "$LLITELOOPLOAD" ]; then
5387                 rmmod llite_lloop
5388                 unset LLITELOOPLOAD
5389         fi
5390         rm -f $DIR/f68*
5391 }
5392
5393 meminfo() {
5394         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5395 }
5396
5397 swap_used() {
5398         swapon -s | awk '($1 == "'$1'") { print $4 }'
5399 }
5400
5401 # test case for lloop driver, basic function
5402 test_68a() {
5403         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5404         [ "$UID" != 0 ] && skip_env "must run as root" && return
5405         llite_lloop_enabled || \
5406                 { skip_env "llite_lloop module disabled" && return; }
5407
5408         trap cleanup_68 EXIT
5409
5410         if ! module_loaded llite_lloop; then
5411                 if load_module llite/llite_lloop; then
5412                         LLITELOOPLOAD=yes
5413                 else
5414                         skip_env "can't find module llite_lloop"
5415                         return
5416                 fi
5417         fi
5418
5419         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5420         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5421         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5422
5423         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5424         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5425
5426         cleanup_68
5427 }
5428 run_test 68a "lloop driver - basic test ========================"
5429
5430 # excercise swapping to lustre by adding a high priority swapfile entry
5431 # and then consuming memory until it is used.
5432 test_68b() {  # was test_68
5433         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5434         [ "$UID" != 0 ] && skip_env "must run as root" && return
5435         lctl get_param -n devices | grep -q obdfilter && \
5436                 skip "local OST" && return
5437
5438         grep -q llite_lloop /proc/modules
5439         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5440
5441         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5442                 skip "can't reliably test swap with TCP" && return
5443
5444         MEMTOTAL=`meminfo MemTotal`
5445         NR_BLOCKS=$((MEMTOTAL>>8))
5446         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5447
5448         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5449         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5450         mkswap $DIR/f68b
5451
5452         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5453
5454         trap cleanup_68 EXIT
5455
5456         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5457
5458         echo "before: `swapon -s | grep $LLOOP`"
5459         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5460         echo "after: `swapon -s | grep $LLOOP`"
5461         SWAPUSED=`swap_used $LLOOP`
5462
5463         cleanup_68
5464
5465         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5466 }
5467 run_test 68b "support swapping to Lustre ========================"
5468
5469 # bug5265, obdfilter oa2dentry return -ENOENT
5470 # #define OBD_FAIL_OST_ENOENT 0x217
5471 test_69() {
5472         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5473         remote_ost_nodsh && skip "remote OST with nodsh" && return
5474
5475         f="$DIR/$tfile"
5476         $SETSTRIPE -c 1 -i 0 $f
5477
5478         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5479
5480         do_facet ost1 lctl set_param fail_loc=0x217
5481         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5482         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5483
5484         do_facet ost1 lctl set_param fail_loc=0
5485         $DIRECTIO write $f 0 2 || error "write error"
5486
5487         cancel_lru_locks osc
5488         $DIRECTIO read $f 0 1 || error "read error"
5489
5490         do_facet ost1 lctl set_param fail_loc=0x217
5491         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5492
5493         do_facet ost1 lctl set_param fail_loc=0
5494         rm -f $f
5495 }
5496 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5497
5498 test_71() {
5499     test_mkdir -p $DIR/$tdir
5500     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5501 }
5502 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5503
5504 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5505         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5506         [ "$RUNAS_ID" = "$UID" ] &&
5507                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5508
5509         # Check that testing environment is properly set up. Skip if not
5510         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5511                 skip_env "User $RUNAS_ID does not exist - skipping"
5512                 return 0
5513         }
5514         touch $DIR/$tfile
5515         chmod 777 $DIR/$tfile
5516         chmod ug+s $DIR/$tfile
5517         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5518                 error "$RUNAS dd $DIR/$tfile failed"
5519         # See if we are still setuid/sgid
5520         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5521                 error "S/gid is not dropped on write"
5522         # Now test that MDS is updated too
5523         cancel_lru_locks mdc
5524         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5525                 error "S/gid is not dropped on MDS"
5526         rm -f $DIR/$tfile
5527 }
5528 run_test 72a "Test that remove suid works properly (bug5695) ===="
5529
5530 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5531         local perm
5532
5533         [ "$RUNAS_ID" = "$UID" ] && \
5534                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5535         [ "$RUNAS_ID" -eq 0 ] && \
5536                 skip_env "RUNAS_ID = 0 -- skipping" && return
5537
5538         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5539         # Check that testing environment is properly set up. Skip if not
5540         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5541                 skip_env "User $RUNAS_ID does not exist - skipping"
5542                 return 0
5543         }
5544         touch $DIR/${tfile}-f{g,u}
5545         test_mkdir $DIR/${tfile}-dg
5546         test_mkdir $DIR/${tfile}-du
5547         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5548         chmod g+s $DIR/${tfile}-{f,d}g
5549         chmod u+s $DIR/${tfile}-{f,d}u
5550         for perm in 777 2777 4777; do
5551                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5552                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5553                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5554                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5555         done
5556         true
5557 }
5558 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5559
5560 # bug 3462 - multiple simultaneous MDC requests
5561 test_73() {
5562         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5563         test_mkdir $DIR/d73-1
5564         test_mkdir $DIR/d73-2
5565         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5566         pid1=$!
5567
5568         lctl set_param fail_loc=0x80000129
5569         $MULTIOP $DIR/d73-1/f73-2 Oc &
5570         sleep 1
5571         lctl set_param fail_loc=0
5572
5573         $MULTIOP $DIR/d73-2/f73-3 Oc &
5574         pid3=$!
5575
5576         kill -USR1 $pid1
5577         wait $pid1 || return 1
5578
5579         sleep 25
5580
5581         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5582         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5583         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5584
5585         rm -rf $DIR/d73-*
5586 }
5587 run_test 73 "multiple MDC requests (should not deadlock)"
5588
5589 test_74a() { # bug 6149, 6184
5590         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5591         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5592         #
5593         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5594         # will spin in a tight reconnection loop
5595         touch $DIR/f74a
5596         $LCTL set_param fail_loc=0x8000030e
5597         # get any lock that won't be difficult - lookup works.
5598         ls $DIR/f74a
5599         $LCTL set_param fail_loc=0
5600         rm -f $DIR/f74a
5601         true
5602 }
5603 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5604
5605 test_74b() { # bug 13310
5606         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5607         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5608         #
5609         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5610         # will spin in a tight reconnection loop
5611         $LCTL set_param fail_loc=0x8000030e
5612         # get a "difficult" lock
5613         touch $DIR/f74b
5614         $LCTL set_param fail_loc=0
5615         rm -f $DIR/f74b
5616         true
5617 }
5618 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5619
5620 test_74c() {
5621         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5622         #define OBD_FAIL_LDLM_NEW_LOCK
5623         $LCTL set_param fail_loc=0x319
5624         touch $DIR/$tfile && error "touch successful"
5625         $LCTL set_param fail_loc=0
5626         true
5627 }
5628 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5629
5630 num_inodes() {
5631         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5632 }
5633
5634 get_inode_slab_tunables() {
5635         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5636 }
5637
5638 set_inode_slab_tunables() {
5639         echo "lustre_inode_cache $1" > /proc/slabinfo
5640 }
5641
5642 test_76() { # Now for bug 20433, added originally in bug 1443
5643         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5644         local SLAB_SETTINGS=`get_inode_slab_tunables`
5645         local CPUS=`getconf _NPROCESSORS_ONLN`
5646         # we cannot set limit below 1 which means 1 inode in each
5647         # per-cpu cache is still allowed
5648         set_inode_slab_tunables "1 1 0"
5649         cancel_lru_locks osc
5650         BEFORE_INODES=$(num_inodes)
5651         echo "before inodes: $BEFORE_INODES"
5652         local COUNT=1000
5653         [ "$SLOW" = "no" ] && COUNT=100
5654         for i in $(seq $COUNT); do
5655                 touch $DIR/$tfile
5656                 rm -f $DIR/$tfile
5657         done
5658         cancel_lru_locks osc
5659         AFTER_INODES=$(num_inodes)
5660         echo "after inodes: $AFTER_INODES"
5661         local wait=0
5662         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5663                 sleep 2
5664                 AFTER_INODES=$(num_inodes)
5665                 wait=$((wait+2))
5666                 echo "wait $wait seconds inodes: $AFTER_INODES"
5667                 if [ $wait -gt 30 ]; then
5668                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5669                 fi
5670         done
5671         set_inode_slab_tunables "$SLAB_SETTINGS"
5672 }
5673 run_test 76 "confirm clients recycle inodes properly ===="
5674
5675
5676 export ORIG_CSUM=""
5677 set_checksums()
5678 {
5679         # Note: in sptlrpc modes which enable its own bulk checksum, the
5680         # original crc32_le bulk checksum will be automatically disabled,
5681         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5682         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5683         # In this case set_checksums() will not be no-op, because sptlrpc
5684         # bulk checksum will be enabled all through the test.
5685
5686         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5687         lctl set_param -n osc.*.checksums $1
5688         return 0
5689 }
5690
5691 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5692                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5693 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5694 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5695 set_checksum_type()
5696 {
5697         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5698         log "set checksum type to $1"
5699         return 0
5700 }
5701 F77_TMP=$TMP/f77-temp
5702 F77SZ=8
5703 setup_f77() {
5704         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5705                 error "error writing to $F77_TMP"
5706 }
5707
5708 test_77a() { # bug 10889
5709         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5710         $GSS && skip "could not run with gss" && return
5711         [ ! -f $F77_TMP ] && setup_f77
5712         set_checksums 1
5713         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5714         set_checksums 0
5715         rm -f $DIR/$tfile
5716 }
5717 run_test 77a "normal checksum read/write operation"
5718
5719 test_77b() { # bug 10889
5720         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5721         $GSS && skip "could not run with gss" && return
5722         [ ! -f $F77_TMP ] && setup_f77
5723         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5724         $LCTL set_param fail_loc=0x80000409
5725         set_checksums 1
5726
5727         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5728                 error "dd error: $?"
5729         $LCTL set_param fail_loc=0
5730
5731         for algo in $CKSUM_TYPES; do
5732                 cancel_lru_locks osc
5733                 set_checksum_type $algo
5734                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5735                 $LCTL set_param fail_loc=0x80000408
5736                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5737                 $LCTL set_param fail_loc=0
5738         done
5739         set_checksums 0
5740         set_checksum_type $ORIG_CSUM_TYPE
5741         rm -f $DIR/$tfile
5742 }
5743 run_test 77b "checksum error on client write, read"
5744
5745 test_77d() { # bug 10889
5746         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5747         $GSS && skip "could not run with gss" && return
5748         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5749         $LCTL set_param fail_loc=0x80000409
5750         set_checksums 1
5751         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5752                 error "direct write: rc=$?"
5753         $LCTL set_param fail_loc=0
5754         set_checksums 0
5755
5756         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5757         $LCTL set_param fail_loc=0x80000408
5758         set_checksums 1
5759         cancel_lru_locks osc
5760         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5761                 error "direct read: rc=$?"
5762         $LCTL set_param fail_loc=0
5763         set_checksums 0
5764 }
5765 run_test 77d "checksum error on OST direct write, read"
5766
5767 test_77f() { # bug 10889
5768         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5769         $GSS && skip "could not run with gss" && return
5770         set_checksums 1
5771         for algo in $CKSUM_TYPES; do
5772                 cancel_lru_locks osc
5773                 set_checksum_type $algo
5774                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5775                 $LCTL set_param fail_loc=0x409
5776                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5777                         error "direct write succeeded"
5778                 $LCTL set_param fail_loc=0
5779         done
5780         set_checksum_type $ORIG_CSUM_TYPE
5781         set_checksums 0
5782 }
5783 run_test 77f "repeat checksum error on write (expect error)"
5784
5785 test_77g() { # bug 10889
5786         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5787         $GSS && skip "could not run with gss" && return
5788         remote_ost_nodsh && skip "remote OST with nodsh" && return
5789
5790         [ ! -f $F77_TMP ] && setup_f77
5791
5792         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5793         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5794         do_facet ost1 lctl set_param fail_loc=0x8000021a
5795         set_checksums 1
5796         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5797                 error "write error: rc=$?"
5798         do_facet ost1 lctl set_param fail_loc=0
5799         set_checksums 0
5800
5801         cancel_lru_locks osc
5802         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5803         do_facet ost1 lctl set_param fail_loc=0x8000021b
5804         set_checksums 1
5805         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5806         do_facet ost1 lctl set_param fail_loc=0
5807         set_checksums 0
5808 }
5809 run_test 77g "checksum error on OST write, read"
5810
5811 test_77i() { # bug 13805
5812         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5813         $GSS && skip "could not run with gss" && return
5814         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5815         lctl set_param fail_loc=0x40b
5816         remount_client $MOUNT
5817         lctl set_param fail_loc=0
5818         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5819                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5820                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5821                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5822         done
5823         remount_client $MOUNT
5824 }
5825 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5826
5827 test_77j() { # bug 13805
5828         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5829         $GSS && skip "could not run with gss" && return
5830         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5831         lctl set_param fail_loc=0x40c
5832         remount_client $MOUNT
5833         lctl set_param fail_loc=0
5834         sleep 2 # wait async osc connect to finish
5835         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5836                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5837                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5838                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5839         done
5840         remount_client $MOUNT
5841 }
5842 run_test 77j "client only supporting ADLER32"
5843
5844 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5845 rm -f $F77_TMP
5846 unset F77_TMP
5847
5848 test_78() { # bug 10901
5849         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5850         remote_ost || { skip_env "local OST" && return; }
5851
5852         NSEQ=5
5853         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5854         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5855         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5856         echo "MemTotal: $MEMTOTAL"
5857
5858         # reserve 256MB of memory for the kernel and other running processes,
5859         # and then take 1/2 of the remaining memory for the read/write buffers.
5860         if [ $MEMTOTAL -gt 512 ] ;then
5861                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5862         else
5863                 # for those poor memory-starved high-end clusters...
5864                 MEMTOTAL=$((MEMTOTAL / 2))
5865         fi
5866         echo "Mem to use for directio: $MEMTOTAL"
5867
5868         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
5869         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
5870         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
5871         SMALLESTOST=$(lfs df $DIR | grep OST | awk '{ print $4 }' | sort -n |
5872                 head -n1)
5873         echo "Smallest OST: $SMALLESTOST"
5874         [[ $SMALLESTOST -lt 10240 ]] &&
5875                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5876
5877         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
5878                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5879
5880         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5881         echo "File size: $F78SIZE"
5882         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5883         for i in $(seq 1 $NSEQ); do
5884                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5885                 echo directIO rdwr round $i of $NSEQ
5886                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5887         done
5888
5889         rm -f $DIR/$tfile
5890 }
5891 run_test 78 "handle large O_DIRECT writes correctly ============"
5892
5893 test_79() { # bug 12743
5894         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5895         wait_delete_completed
5896
5897         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5898         BKFREE=$(calc_osc_kbytes kbytesfree)
5899         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5900
5901         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5902         DFTOTAL=`echo $STRING | cut -d, -f1`
5903         DFUSED=`echo $STRING  | cut -d, -f2`
5904         DFAVAIL=`echo $STRING | cut -d, -f3`
5905         DFFREE=$(($DFTOTAL - $DFUSED))
5906
5907         ALLOWANCE=$((64 * $OSTCOUNT))
5908
5909         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5910            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5911                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5912         fi
5913         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5914            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5915                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5916         fi
5917         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5918            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5919                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5920         fi
5921 }
5922 run_test 79 "df report consistency check ======================="
5923
5924 test_80() { # bug 10718
5925         remote_ost_nodsh && skip "remote OST with nodsh" && return
5926         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5927         # relax strong synchronous semantics for slow backends like ZFS
5928         local soc="obdfilter.*.sync_on_lock_cancel"
5929         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
5930         local hosts=
5931         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
5932                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
5933                           facet_active_host $host; done | sort -u)
5934                 do_nodes $hosts lctl set_param $soc=never
5935         fi
5936
5937         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
5938         sync; sleep 1; sync
5939         local BEFORE=`date +%s`
5940         cancel_lru_locks osc
5941         local AFTER=`date +%s`
5942         local DIFF=$((AFTER-BEFORE))
5943         if [ $DIFF -gt 1 ] ; then
5944                 error "elapsed for 1M@1T = $DIFF"
5945         fi
5946
5947         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
5948
5949         rm -f $DIR/$tfile
5950 }
5951 run_test 80 "Page eviction is equally fast at high offsets too  ===="
5952
5953 test_81a() { # LU-456
5954         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5955         remote_ost_nodsh && skip "remote OST with nodsh" && return
5956         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5957         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
5958         do_facet ost1 lctl set_param fail_loc=0x80000228
5959
5960         # write should trigger a retry and success
5961         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5962         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5963         RC=$?
5964         if [ $RC -ne 0 ] ; then
5965                 error "write should success, but failed for $RC"
5966         fi
5967 }
5968 run_test 81a "OST should retry write when get -ENOSPC ==============="
5969
5970 test_81b() { # LU-456
5971         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5972         remote_ost_nodsh && skip "remote OST with nodsh" && return
5973         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5974         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
5975         do_facet ost1 lctl set_param fail_loc=0x228
5976
5977         # write should retry several times and return -ENOSPC finally
5978         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5979         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5980         RC=$?
5981         ENOSPC=28
5982         if [ $RC -ne $ENOSPC ] ; then
5983                 error "dd should fail for -ENOSPC, but succeed."
5984         fi
5985 }
5986 run_test 81b "OST should return -ENOSPC when retry still fails ======="
5987
5988 test_82() { # LU-1031
5989         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
5990         local gid1=14091995
5991         local gid2=16022000
5992
5993         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
5994         local MULTIPID1=$!
5995         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
5996         local MULTIPID2=$!
5997         kill -USR1 $MULTIPID2
5998         sleep 2
5999         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6000                 error "First grouplock does not block second one"
6001         else
6002                 echo "Second grouplock blocks first one"
6003         fi
6004         kill -USR1 $MULTIPID1
6005         wait $MULTIPID1
6006         wait $MULTIPID2
6007 }
6008 run_test 82 "Basic grouplock test ==============================="
6009
6010 test_99a() {
6011         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6012                 return
6013         test_mkdir -p $DIR/d99cvsroot
6014         chown $RUNAS_ID $DIR/d99cvsroot
6015         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6016         cd $TMP
6017
6018         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6019         cd $oldPWD
6020 }
6021 run_test 99a "cvs init ========================================="
6022
6023 test_99b() {
6024         [ -z "$(which cvs 2>/dev/null)" ] &&
6025                 skip_env "could not find cvs" && return
6026         [ ! -d $DIR/d99cvsroot ] && test_99a
6027         cd /etc/init.d
6028         # some versions of cvs import exit(1) when asked to import links or
6029         # files they can't read.  ignore those files.
6030         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6031                         ! -perm +4 -printf '-I %f\n')
6032         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6033                 d99reposname vtag rtag
6034 }
6035 run_test 99b "cvs import ======================================="
6036
6037 test_99c() {
6038         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6039         [ ! -d $DIR/d99cvsroot ] && test_99b
6040         cd $DIR
6041         test_mkdir -p $DIR/d99reposname
6042         chown $RUNAS_ID $DIR/d99reposname
6043         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6044 }
6045 run_test 99c "cvs checkout ====================================="
6046
6047 test_99d() {
6048         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6049         [ ! -d $DIR/d99cvsroot ] && test_99c
6050         cd $DIR/d99reposname
6051         $RUNAS touch foo99
6052         $RUNAS cvs add -m 'addmsg' foo99
6053 }
6054 run_test 99d "cvs add =========================================="
6055
6056 test_99e() {
6057         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6058         [ ! -d $DIR/d99cvsroot ] && test_99c
6059         cd $DIR/d99reposname
6060         $RUNAS cvs update
6061 }
6062 run_test 99e "cvs update ======================================="
6063
6064 test_99f() {
6065         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6066         [ ! -d $DIR/d99cvsroot ] && test_99d
6067         cd $DIR/d99reposname
6068         $RUNAS cvs commit -m 'nomsg' foo99
6069     rm -fr $DIR/d99cvsroot
6070 }
6071 run_test 99f "cvs commit ======================================="
6072
6073 test_100() {
6074         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6075         [ "$NETTYPE" = tcp ] || \
6076                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
6077                         return ; }
6078
6079         remote_ost_nodsh && skip "remote OST with nodsh" && return
6080         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6081         remote_servers || \
6082                 { skip "useless for local single node setup" && return; }
6083
6084         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6085                 [ "$PROT" != "tcp" ] && continue
6086                 RPORT=$(echo $REMOTE | cut -d: -f2)
6087                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6088
6089                 rc=0
6090                 LPORT=`echo $LOCAL | cut -d: -f2`
6091                 if [ $LPORT -ge 1024 ]; then
6092                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6093                         netstat -tna
6094                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6095                 fi
6096         done
6097         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6098 }
6099 run_test 100 "check local port using privileged port ==========="
6100
6101 function get_named_value()
6102 {
6103     local tag
6104
6105     tag=$1
6106     while read ;do
6107         line=$REPLY
6108         case $line in
6109         $tag*)
6110             echo $line | sed "s/^$tag[ ]*//"
6111             break
6112             ;;
6113         esac
6114     done
6115 }
6116
6117 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6118                    awk '/^max_cached_mb/ { print $2 }')
6119
6120 cleanup_101a() {
6121         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6122         trap 0
6123 }
6124
6125 test_101a() {
6126         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6127         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
6128         local s
6129         local discard
6130         local nreads=10000
6131         local cache_limit=32
6132
6133         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6134         trap cleanup_101a EXIT
6135         $LCTL set_param -n llite.*.read_ahead_stats 0
6136         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6137
6138         #
6139         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6140         #
6141         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6142         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6143
6144         discard=0
6145         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6146                 get_named_value 'read but discarded' | cut -d" " -f1); do
6147                         discard=$(($discard + $s))
6148         done
6149         cleanup_101a
6150
6151         if [[ $(($discard * 10)) -gt $nreads ]]; then
6152                 $LCTL get_param osc.*-osc*.rpc_stats
6153                 $LCTL get_param llite.*.read_ahead_stats
6154                 error "too many ($discard) discarded pages"
6155         fi
6156         rm -f $DIR/$tfile || true
6157 }
6158 run_test 101a "check read-ahead for random reads ================"
6159
6160 setup_test101bc() {
6161         test_mkdir -p $DIR/$tdir
6162         local STRIPE_SIZE=$1
6163         local FILE_LENGTH=$2
6164         STRIPE_OFFSET=0
6165
6166         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6167
6168         local list=$(comma_list $(osts_nodes))
6169         set_osd_param $list '' read_cache_enable 0
6170         set_osd_param $list '' writethrough_cache_enable 0
6171
6172         trap cleanup_test101bc EXIT
6173         # prepare the read-ahead file
6174         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6175
6176         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6177                                 count=$FILE_SIZE_MB 2> /dev/null
6178
6179 }
6180
6181 cleanup_test101bc() {
6182         trap 0
6183         rm -rf $DIR/$tdir
6184         rm -f $DIR/$tfile
6185
6186         local list=$(comma_list $(osts_nodes))
6187         set_osd_param $list '' read_cache_enable 1
6188         set_osd_param $list '' writethrough_cache_enable 1
6189 }
6190
6191 calc_total() {
6192         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6193 }
6194
6195 ra_check_101() {
6196         local READ_SIZE=$1
6197         local STRIPE_SIZE=$2
6198         local FILE_LENGTH=$3
6199         local RA_INC=1048576
6200         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6201         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6202                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6203         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6204                         get_named_value 'read but discarded' |
6205                         cut -d" " -f1 | calc_total)
6206         if [[ $DISCARD -gt $discard_limit ]]; then
6207                 $LCTL get_param llite.*.read_ahead_stats
6208                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6209         else
6210                 echo "Read-ahead success for size ${READ_SIZE}"
6211         fi
6212 }
6213
6214 test_101b() {
6215         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6216         [[ $OSTCOUNT -lt 2 ]] &&
6217                 skip_env "skipping stride IO stride-ahead test" && return
6218         local STRIPE_SIZE=1048576
6219         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6220         if [ $SLOW == "yes" ]; then
6221                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6222         else
6223                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6224         fi
6225
6226         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6227
6228         # prepare the read-ahead file
6229         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6230         cancel_lru_locks osc
6231         for BIDX in 2 4 8 16 32 64 128 256
6232         do
6233                 local BSIZE=$((BIDX*4096))
6234                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6235                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6236                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6237                 $LCTL set_param -n llite.*.read_ahead_stats 0
6238                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6239                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6240                 cancel_lru_locks osc
6241                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6242         done
6243         cleanup_test101bc
6244         true
6245 }
6246 run_test 101b "check stride-io mode read-ahead ================="
6247
6248 test_101c() {
6249         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6250         local STRIPE_SIZE=1048576
6251         local FILE_LENGTH=$((STRIPE_SIZE*100))
6252         local nreads=10000
6253         local osc_rpc_stats
6254
6255         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6256
6257         cancel_lru_locks osc
6258         $LCTL set_param osc.*.rpc_stats 0
6259         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6260         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6261                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6262                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6263                 local size
6264
6265                 if [ $lines -le 20 ]; then
6266                         continue
6267                 fi
6268                 for size in 1 2 4 8; do
6269                         local rpc=$(echo "$stats" |
6270                                     awk '($1 == "'$size':") {print $2; exit; }')
6271                         [ $rpc != 0 ] &&
6272                                 error "Small $((size*4))k read IO $rpc !"
6273                 done
6274                 echo "$osc_rpc_stats check passed!"
6275         done
6276         cleanup_test101bc
6277         true
6278 }
6279 run_test 101c "check stripe_size aligned read-ahead ================="
6280
6281 set_read_ahead() {
6282         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6283         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6284 }
6285
6286 test_101d() {
6287         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6288         local file=$DIR/$tfile
6289         local sz_MB=${FILESIZE_101d:-500}
6290         local ra_MB=${READAHEAD_MB:-40}
6291
6292         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6293         [ $free_MB -lt $sz_MB ] &&
6294                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6295
6296         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6297         $SETSTRIPE -c -1 $file || error "setstripe failed"
6298
6299         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6300         echo Cancel LRU locks on lustre client to flush the client cache
6301         cancel_lru_locks osc
6302
6303         echo Disable read-ahead
6304         local old_READAHEAD=$(set_read_ahead 0)
6305
6306         echo Reading the test file $file with read-ahead disabled
6307         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6308
6309         echo Cancel LRU locks on lustre client to flush the client cache
6310         cancel_lru_locks osc
6311         echo Enable read-ahead with ${ra_MB}MB
6312         set_read_ahead $ra_MB
6313
6314         echo Reading the test file $file with read-ahead enabled
6315         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6316
6317         echo "read-ahead disabled time read $raOFF"
6318         echo "read-ahead enabled  time read $raON"
6319
6320         set_read_ahead $old_READAHEAD
6321         rm -f $file
6322         wait_delete_completed
6323
6324         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6325                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6326 }
6327 run_test 101d "file read with and without read-ahead enabled"
6328
6329 test_101e() {
6330         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6331         local file=$DIR/$tfile
6332         local size_KB=500  #KB
6333         local count=100
6334         local bsize=1024
6335
6336         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6337         local need_KB=$((count * size_KB))
6338         [[ $free_KB -le $need_KB ]] &&
6339                 skip_env "Need free space $need_KB, have $free_KB" && return
6340
6341         echo "Creating $count ${size_KB}K test files"
6342         for ((i = 0; i < $count; i++)); do
6343                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6344         done
6345
6346         echo "Cancel LRU locks on lustre client to flush the client cache"
6347         cancel_lru_locks osc
6348
6349         echo "Reset readahead stats"
6350         $LCTL set_param -n llite.*.read_ahead_stats 0
6351
6352         for ((i = 0; i < $count; i++)); do
6353                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6354         done
6355
6356         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6357                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6358
6359         for ((i = 0; i < $count; i++)); do
6360                 rm -rf $file.$i 2>/dev/null
6361         done
6362
6363         #10000 means 20% reads are missing in readahead
6364         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6365 }
6366 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6367
6368 cleanup_test101f() {
6369     trap 0
6370     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6371     rm -rf $DIR/$tfile 2>/dev/null
6372 }
6373
6374 test_101f() {
6375         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6376     local file=$DIR/$tfile
6377     local nreads=1000
6378
6379     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6380     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6381     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6382     trap cleanup_test101f EXIT
6383
6384     echo Cancel LRU locks on lustre client to flush the client cache
6385     cancel_lru_locks osc
6386
6387     echo Reset readahead stats
6388     $LCTL set_param -n llite.*.read_ahead_stats 0
6389     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6390     # readahead should read in 2M file on second read, so only miss
6391     # 2 pages.
6392     echo Random 4K reads on 2M file for 1000 times
6393     $READS -f $file -s 2097152 -b 4096 -n $nreads
6394
6395     echo checking missing pages
6396     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6397           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6398
6399     [ $miss -lt 3 ] || error "misses too much pages!"
6400     cleanup_test101f
6401 }
6402 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6403
6404 setup_test102() {
6405         test_mkdir -p $DIR/$tdir
6406         chown $RUNAS_ID $DIR/$tdir
6407         STRIPE_SIZE=65536
6408         STRIPE_OFFSET=1
6409         STRIPE_COUNT=$OSTCOUNT
6410         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6411
6412         trap cleanup_test102 EXIT
6413         cd $DIR
6414         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6415         cd $DIR/$tdir
6416         for num in 1 2 3 4; do
6417                 for count in $(seq 1 $STRIPE_COUNT); do
6418                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6419                                 local size=`expr $STRIPE_SIZE \* $num`
6420                                 local file=file"$num-$idx-$count"
6421                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6422                         done
6423                 done
6424         done
6425
6426         cd $DIR
6427         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6428 }
6429
6430 cleanup_test102() {
6431         trap 0
6432         rm -f $TMP/f102.tar
6433         rm -rf $DIR/d0.sanity/d102
6434 }
6435
6436 test_102a() {
6437         local testfile=$DIR/$tfile
6438
6439         touch $testfile
6440
6441         [ "$UID" != 0 ] && skip_env "must run as root" && return
6442         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6443                 skip_env "must have user_xattr" && return
6444
6445         [ -z "$(which setfattr 2>/dev/null)" ] &&
6446                 skip_env "could not find setfattr" && return
6447
6448         echo "set/get xattr..."
6449         setfattr -n trusted.name1 -v value1 $testfile ||
6450                 error "setfattr -n trusted.name1=value1 $testfile failed"
6451         getfattr -n trusted.name1 $testfile 2> /dev/null |
6452           grep "trusted.name1=.value1" ||
6453                 error "$testfile missing trusted.name1=value1"
6454
6455         setfattr -n user.author1 -v author1 $testfile ||
6456                 error "setfattr -n user.author1=author1 $testfile failed"
6457         getfattr -n user.author1 $testfile 2> /dev/null |
6458           grep "user.author1=.author1" ||
6459                 error "$testfile missing trusted.author1=author1"
6460
6461         echo "listxattr..."
6462         setfattr -n trusted.name2 -v value2 $testfile ||
6463                 error "$testfile unable to set trusted.name2"
6464         setfattr -n trusted.name3 -v value3 $testfile ||
6465                 error "$testfile unable to set trusted.name3"
6466         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6467             grep "trusted.name" | wc -l) -eq 3 ] ||
6468                 error "$testfile missing 3 trusted.name xattrs"
6469
6470         setfattr -n user.author2 -v author2 $testfile ||
6471                 error "$testfile unable to set user.author2"
6472         setfattr -n user.author3 -v author3 $testfile ||
6473                 error "$testfile unable to set user.author3"
6474         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6475             grep "user.author" | wc -l) -eq 3 ] ||
6476                 error "$testfile missing 3 user.author xattrs"
6477
6478         echo "remove xattr..."
6479         setfattr -x trusted.name1 $testfile ||
6480                 error "$testfile error deleting trusted.name1"
6481         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6482                 error "$testfile did not delete trusted.name1 xattr"
6483
6484         setfattr -x user.author1 $testfile ||
6485                 error "$testfile error deleting user.author1"
6486         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6487                 error "$testfile did not delete trusted.name1 xattr"
6488
6489         # b10667: setting lustre special xattr be silently discarded
6490         echo "set lustre special xattr ..."
6491         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6492                 error "$testfile allowed setting trusted.lov"
6493 }
6494 run_test 102a "user xattr test =================================="
6495
6496 test_102b() {
6497         [ -z "$(which setfattr 2>/dev/null)" ] &&
6498                 skip_env "could not find setfattr" && return
6499
6500         # b10930: get/set/list trusted.lov xattr
6501         echo "get/set/list trusted.lov xattr ..."
6502         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6503         local testfile=$DIR/$tfile
6504         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6505                 error "setstripe failed"
6506         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6507                 error "getstripe failed"
6508         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6509                 error "can't get trusted.lov from $testfile"
6510
6511         local testfile2=${testfile}2
6512         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6513                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6514
6515         $MCREATE $testfile2
6516         setfattr -n trusted.lov -v $value $testfile2
6517         local stripe_size=$($GETSTRIPE -S $testfile2)
6518         local stripe_count=$($GETSTRIPE -c $testfile2)
6519         [[ $stripe_size -eq 65536 ]] ||
6520                 error "stripe size $stripe_size != 65536"
6521         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6522                 error "stripe count $stripe_count != $STRIPECOUNT"
6523         rm -f $DIR/$tfile
6524 }
6525 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6526
6527 test_102c() {
6528         [ -z "$(which setfattr 2>/dev/null)" ] &&
6529                 skip_env "could not find setfattr" && return
6530
6531         # b10930: get/set/list lustre.lov xattr
6532         echo "get/set/list lustre.lov xattr ..."
6533         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6534         test_mkdir -p $DIR/$tdir
6535         chown $RUNAS_ID $DIR/$tdir
6536         local testfile=$DIR/$tdir/$tfile
6537         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6538                 error "setstripe failed"
6539         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6540                 error "getstripe failed"
6541         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6542         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6543
6544         local testfile2=${testfile}2
6545         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6546                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6547
6548         $RUNAS $MCREATE $testfile2
6549         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6550         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6551         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6552         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6553         [ $stripe_count -eq $STRIPECOUNT ] ||
6554                 error "stripe count $stripe_count != $STRIPECOUNT"
6555 }
6556 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6557
6558 compare_stripe_info1() {
6559         local stripe_index_all_zero=true
6560
6561         for num in 1 2 3 4; do
6562                 for count in $(seq 1 $STRIPE_COUNT); do
6563                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6564                                 local size=$((STRIPE_SIZE * num))
6565                                 local file=file"$num-$offset-$count"
6566                                 stripe_size=$(lfs getstripe -S $PWD/$file)
6567                                 [[ $stripe_size -ne $size ]] &&
6568                                     error "$file: size $stripe_size != $size"
6569                                 stripe_count=$(lfs getstripe -c $PWD/$file)
6570                                 # allow fewer stripes to be created, ORI-601
6571                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6572                                     error "$file: count $stripe_count != $count"
6573                                 stripe_index=$(lfs getstripe -i $PWD/$file)
6574                                 [[ $stripe_index -ne 0 ]] &&
6575                                         stripe_index_all_zero=false
6576                         done
6577                 done
6578         done
6579         $stripe_index_all_zero &&
6580                 error "all files are being extracted starting from OST index 0"
6581         return 0
6582 }
6583
6584 find_lustre_tar() {
6585         [ -n "$(which tar 2>/dev/null)" ] &&
6586                 strings $(which tar) | grep -q "lustre" && echo tar
6587 }
6588
6589 test_102d() {
6590         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6591         # b10930: tar test for trusted.lov xattr
6592         TAR=$(find_lustre_tar)
6593         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6594         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6595         setup_test102
6596         test_mkdir -p $DIR/d102d
6597         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6598         cd $DIR/d102d/$tdir
6599         compare_stripe_info1
6600 }
6601 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6602
6603 test_102f() {
6604         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6605         # b10930: tar test for trusted.lov xattr
6606         TAR=$(find_lustre_tar)
6607         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6608         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6609         setup_test102
6610         test_mkdir -p $DIR/d102f
6611         cd $DIR
6612         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6613         cd $DIR/d102f/$tdir
6614         compare_stripe_info1
6615 }
6616 run_test 102f "tar copy files, not keep osts ==========="
6617
6618 grow_xattr() {
6619         local xsize=${1:-1024}  # in bytes
6620         local file=$DIR/$tfile
6621
6622         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6623                 skip "must have user_xattr" && return 0
6624         [ -z "$(which setfattr 2>/dev/null)" ] &&
6625                 skip_env "could not find setfattr" && return 0
6626         [ -z "$(which getfattr 2>/dev/null)" ] &&
6627                 skip_env "could not find getfattr" && return 0
6628
6629         touch $file
6630
6631         local value="$(generate_string $xsize)"
6632
6633         local xbig=trusted.big
6634         log "save $xbig on $file"
6635         setfattr -n $xbig -v $value $file ||
6636                 error "saving $xbig on $file failed"
6637
6638         local orig=$(get_xattr_value $xbig $file)
6639         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6640
6641         local xsml=trusted.sml
6642         log "save $xsml on $file"
6643         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6644
6645         local new=$(get_xattr_value $xbig $file)
6646         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6647
6648         log "grow $xsml on $file"
6649         setfattr -n $xsml -v "$value" $file ||
6650                 error "growing $xsml on $file failed"
6651
6652         new=$(get_xattr_value $xbig $file)
6653         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6654         log "$xbig still valid after growing $xsml"
6655
6656         rm -f $file
6657 }
6658
6659 test_102h() { # bug 15777
6660         grow_xattr 1024
6661 }
6662 run_test 102h "grow xattr from inside inode to external block"
6663
6664 test_102ha() {
6665         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6666         grow_xattr $(max_xattr_size)
6667 }
6668 run_test 102ha "grow xattr from inside inode to external inode"
6669
6670 test_102i() { # bug 17038
6671         [ -z "$(which getfattr 2>/dev/null)" ] &&
6672                 skip "could not find getfattr" && return
6673         touch $DIR/$tfile
6674         ln -s $DIR/$tfile $DIR/${tfile}link
6675         getfattr -n trusted.lov $DIR/$tfile ||
6676                 error "lgetxattr on $DIR/$tfile failed"
6677         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6678                 grep -i "no such attr" ||
6679                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6680         rm -f $DIR/$tfile $DIR/${tfile}link
6681 }
6682 run_test 102i "lgetxattr test on symbolic link ============"
6683
6684 test_102j() {
6685         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6686         TAR=$(find_lustre_tar)
6687         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6688         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6689         setup_test102 "$RUNAS"
6690         test_mkdir -p $DIR/d102j
6691         chown $RUNAS_ID $DIR/d102j
6692         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6693         cd $DIR/d102j/$tdir
6694         compare_stripe_info1 "$RUNAS"
6695 }
6696 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6697
6698 test_102k() {
6699         [ -z "$(which setfattr 2>/dev/null)" ] &&
6700                 skip "could not find setfattr" && return
6701         touch $DIR/$tfile
6702         # b22187 just check that does not crash for regular file.
6703         setfattr -n trusted.lov $DIR/$tfile
6704         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6705         local test_kdir=$DIR/d102k
6706         test_mkdir $test_kdir
6707         local default_size=`$GETSTRIPE -S $test_kdir`
6708         local default_count=`$GETSTRIPE -c $test_kdir`
6709         local default_offset=`$GETSTRIPE -i $test_kdir`
6710         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6711                 error 'dir setstripe failed'
6712         setfattr -n trusted.lov $test_kdir
6713         local stripe_size=`$GETSTRIPE -S $test_kdir`
6714         local stripe_count=`$GETSTRIPE -c $test_kdir`
6715         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6716         [ $stripe_size -eq $default_size ] ||
6717                 error "stripe size $stripe_size != $default_size"
6718         [ $stripe_count -eq $default_count ] ||
6719                 error "stripe count $stripe_count != $default_count"
6720         [ $stripe_offset -eq $default_offset ] ||
6721                 error "stripe offset $stripe_offset != $default_offset"
6722         rm -rf $DIR/$tfile $test_kdir
6723 }
6724 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6725
6726 test_102l() {
6727         [ -z "$(which getfattr 2>/dev/null)" ] &&
6728                 skip "could not find getfattr" && return
6729
6730         # LU-532 trusted. xattr is invisible to non-root
6731         local testfile=$DIR/$tfile
6732
6733         touch $testfile
6734
6735         echo "listxattr as user..."
6736         chown $RUNAS_ID $testfile
6737         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6738             grep -q "trusted" &&
6739                 error "$testfile trusted xattrs are user visible"
6740
6741         return 0;
6742 }
6743 run_test 102l "listxattr size test =================================="
6744
6745 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6746         local path=$DIR/$tfile
6747         touch $path
6748
6749         listxattr_size_check $path || error "listattr_size_check $path failed"
6750 }
6751 run_test 102m "Ensure listxattr fails on small bufffer ========"
6752
6753 cleanup_test102
6754
6755 getxattr() { # getxattr path name
6756         # Return the base64 encoding of the value of xattr name on path.
6757         local path=$1
6758         local name=$2
6759
6760         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6761         # file: $path
6762         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6763         #
6764         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6765
6766         getfattr --absolute-names --encoding=base64 --name=$name $path |
6767                 awk -F= -v name=$name '$1 == name {
6768                         print substr($0, index($0, "=") + 1);
6769         }'
6770 }
6771
6772 test_102n() { # LU-4101 mdt: protect internal xattrs
6773         local file0=$DIR/$tfile.0
6774         local file1=$DIR/$tfile.1
6775         local xattr0=$TMP/$tfile.0
6776         local xattr1=$TMP/$tfile.1
6777         local name
6778         local value
6779
6780         [ -z "$(which setfattr 2>/dev/null)" ] &&
6781                 skip "could not find setfattr" && return
6782
6783         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6784         then
6785                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6786                 return
6787         fi
6788
6789         rm -rf $file0 $file1 $xattr0 $xattr1
6790         touch $file0 $file1
6791
6792         # Get 'before' xattrs of $file1.
6793         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6794
6795         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6796                 # Try to copy xattr from $file0 to $file1.
6797                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6798
6799                 setfattr --name=trusted.$name --value="$value" $file1 ||
6800                         error "setxattr 'trusted.$name' failed"
6801
6802                 # Try to set a garbage xattr.
6803                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6804
6805                 setfattr --name=trusted.$name --value="$value" $file1 ||
6806                         error "setxattr 'trusted.$name' failed"
6807
6808                 # Try to remove the xattr from $file1. We don't care if this
6809                 # appears to succeed or fail, we just don't want there to be
6810                 # any changes or crashes.
6811                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6812         done
6813
6814         # Get 'after' xattrs of file1.
6815         getfattr --absolute-names --dump --match=- $file1 > $xattr1
6816
6817         if ! diff $xattr0 $xattr1; then
6818                 error "before and after xattrs of '$file1' differ"
6819         fi
6820
6821         rm -rf $file0 $file1 $xattr0 $xattr1
6822
6823         return 0
6824 }
6825 run_test 102n "silently ignore setxattr on internal trusted xattrs"
6826
6827 test_102p() { # LU-4703 setxattr did not check ownership
6828         local testfile=$DIR/$tfile
6829
6830         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
6831                 skip "MDS needs to be at least 2.5.56" && return
6832
6833         touch $testfile
6834
6835         echo "setfacl as user..."
6836         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
6837         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
6838
6839         echo "setfattr as user..."
6840         setfacl -m "u:$RUNAS_ID:---" $testfile
6841         $RUNAS setfattr -x system.posix_acl_access $testfile
6842         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
6843 }
6844 run_test 102p "check setxattr(2) correctly fails without permission"
6845
6846 run_acl_subtest()
6847 {
6848     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6849     return $?
6850 }
6851
6852 test_103a() {
6853         [ "$UID" != 0 ] && skip_env "must run as root" && return
6854         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6855                 skip "must have acl enabled" && return
6856         [ -z "$(which setfacl 2>/dev/null)" ] &&
6857                 skip_env "could not find setfacl" && return
6858         $GSS && skip "could not run under gss" && return
6859
6860         gpasswd -a daemon bin   # LU-5641
6861
6862         declare -a identity_old
6863
6864         for num in $(seq $MDSCOUNT); do
6865                 switch_identity $num true || identity_old[$num]=$?
6866         done
6867
6868         SAVE_UMASK=$(umask)
6869         umask 0022
6870         cd $DIR
6871
6872         echo "performing cp ..."
6873         run_acl_subtest cp || error "run_acl_subtest cp failed"
6874         echo "performing getfacl-noacl..."
6875         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
6876         echo "performing misc..."
6877         run_acl_subtest misc || error  "misc test failed"
6878         echo "performing permissions..."
6879         run_acl_subtest permissions || error "permissions failed"
6880         echo "performing setfacl..."
6881         run_acl_subtest setfacl || error  "setfacl test failed"
6882
6883         # inheritance test got from HP
6884         echo "performing inheritance..."
6885         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
6886         chmod +x make-tree || error "chmod +x failed"
6887         run_acl_subtest inheritance || error "inheritance test failed"
6888         rm -f make-tree
6889
6890         echo "LU-974 ignore umask when acl is enabled..."
6891         run_acl_subtest 974 || error "LU-974 umask test failed"
6892         if [ $MDSCOUNT -ge 2 ]; then
6893                 run_acl_subtest 974_remote ||
6894                         error "LU-974 umask test failed under remote dir"
6895         fi
6896
6897         echo "LU-2561 newly created file is same size as directory..."
6898         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
6899                 run_acl_subtest 2561 || error "LU-2561 test failed"
6900         else
6901                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
6902         fi
6903
6904         run_acl_subtest 4924 || error "LU-4924 test failed"
6905
6906         cd $SAVE_PWD
6907         umask $SAVE_UMASK
6908
6909         for num in $(seq $MDSCOUNT); do
6910                 if [ "${identity_old[$num]}" = 1 ]; then
6911                         switch_identity $num false || identity_old[$num]=$?
6912                 fi
6913         done
6914 }
6915 run_test 103a "acl test ========================================="
6916
6917 test_103b() {
6918         local noacl=false
6919         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
6920         local mountopts=$MDS_MOUNT_OPTS
6921
6922         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
6923                 noacl=true
6924         else
6925                 # stop the MDT
6926                 stop $SINGLEMDS || error "failed to stop MDT."
6927                 # remount the MDT
6928                 if [ -z "$MDS_MOUNT_OPTS" ]; then
6929                         MDS_MOUNT_OPTS="-o noacl"
6930                 else
6931                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
6932                 fi
6933                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
6934                         error "failed to start MDT."
6935                 MDS_MOUNT_OPTS=$mountopts
6936         fi
6937
6938         touch $DIR/$tfile
6939         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
6940
6941         if ! $noacl; then
6942                 # stop the MDT
6943                 stop $SINGLEMDS || error "failed to stop MDT."
6944                 # remount the MDT
6945                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
6946                         error "failed to start MDT."
6947         fi
6948
6949         true
6950 }
6951 run_test 103b "MDS mount option 'noacl'"
6952
6953 test_103c() {
6954         mkdir -p $DIR/$tdir
6955         cp -rp $DIR/$tdir $DIR/$tdir.bak
6956
6957         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
6958                 error "$DIR/$tdir shouldn't contain default ACL"
6959         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
6960                 error "$DIR/$tdir.bak shouldn't contain default ACL"
6961         true
6962 }
6963 run_test 103c "'cp -rp' won't set empty acl"
6964
6965 test_104a() {
6966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6967         touch $DIR/$tfile
6968         lfs df || error "lfs df failed"
6969         lfs df -ih || error "lfs df -ih failed"
6970         lfs df -h $DIR || error "lfs df -h $DIR failed"
6971         lfs df -i $DIR || error "lfs df -i $DIR failed"
6972         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
6973         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
6974
6975         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
6976         lctl --device %$OSC deactivate
6977         lfs df || error "lfs df with deactivated OSC failed"
6978         lctl --device %$OSC activate
6979         # wait the osc back to normal
6980         wait_osc_import_state client ost FULL
6981
6982         lfs df || error "lfs df with reactivated OSC failed"
6983         rm -f $DIR/$tfile
6984 }
6985 run_test 104a "lfs df [-ih] [path] test ========================="
6986
6987 test_104b() {
6988         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6989         [ $RUNAS_ID -eq $UID ] &&
6990                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6991         chmod 666 /dev/obd
6992         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
6993                         grep "Permission denied" | wc -l)))
6994         if [ $denied_cnt -ne 0 ]; then
6995                 error "lfs check servers test failed"
6996         fi
6997 }
6998 run_test 104b "$RUNAS lfs check servers test ===================="
6999
7000 test_105a() {
7001         # doesn't work on 2.4 kernels
7002         touch $DIR/$tfile
7003         if $(flock_is_enabled); then
7004                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7005         else
7006                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7007         fi
7008         rm -f $DIR/$tfile
7009 }
7010 run_test 105a "flock when mounted without -o flock test ========"
7011
7012 test_105b() {
7013         touch $DIR/$tfile
7014         if $(flock_is_enabled); then
7015                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7016         else
7017                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7018         fi
7019         rm -f $DIR/$tfile
7020 }
7021 run_test 105b "fcntl when mounted without -o flock test ========"
7022
7023 test_105c() {
7024         touch $DIR/$tfile
7025         if $(flock_is_enabled); then
7026                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7027         else
7028                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7029         fi
7030         rm -f $DIR/$tfile
7031 }
7032 run_test 105c "lockf when mounted without -o flock test ========"
7033
7034 test_105d() { # bug 15924
7035         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7036         test_mkdir -p $DIR/$tdir
7037         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7038         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7039         $LCTL set_param fail_loc=0x80000315
7040         flocks_test 2 $DIR/$tdir
7041 }
7042 run_test 105d "flock race (should not freeze) ========"
7043
7044 test_105e() { # bug 22660 && 22040
7045         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7046         touch $DIR/$tfile
7047         flocks_test 3 $DIR/$tfile
7048 }
7049 run_test 105e "Two conflicting flocks from same process ======="
7050
7051 test_106() { #bug 10921
7052         test_mkdir -p $DIR/$tdir
7053         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7054         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7055 }
7056 run_test 106 "attempt exec of dir followed by chown of that dir"
7057
7058 test_107() {
7059         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7060         CDIR=`pwd`
7061         cd $DIR
7062
7063         local file=core
7064         rm -f $file
7065
7066         local save_pattern=$(sysctl -n kernel.core_pattern)
7067         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7068         sysctl -w kernel.core_pattern=$file
7069         sysctl -w kernel.core_uses_pid=0
7070
7071         ulimit -c unlimited
7072         sleep 60 &
7073         SLEEPPID=$!
7074
7075         sleep 1
7076
7077         kill -s 11 $SLEEPPID
7078         wait $SLEEPPID
7079         if [ -e $file ]; then
7080                 size=`stat -c%s $file`
7081                 [ $size -eq 0 ] && error "Fail to create core file $file"
7082         else
7083                 error "Fail to create core file $file"
7084         fi
7085         rm -f $file
7086         sysctl -w kernel.core_pattern=$save_pattern
7087         sysctl -w kernel.core_uses_pid=$save_uses_pid
7088         cd $CDIR
7089 }
7090 run_test 107 "Coredump on SIG"
7091
7092 test_110() {
7093         test_mkdir -p $DIR/$tdir
7094         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7095                 error "mkdir with 255 char failed"
7096         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7097                 error "mkdir with 256 char should fail, but did not"
7098         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7099                 error "create with 255 char failed"
7100         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7101                 error "create with 256 char should fail, but did not"
7102
7103         ls -l $DIR/$tdir
7104         rm -rf $DIR/$tdir
7105 }
7106 run_test 110 "filename length checking"
7107
7108 test_115() {
7109         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7110         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
7111                 tail -1 | cut -c11-20)
7112         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
7113         echo "Starting with $OSTIO_pre threads"
7114
7115         NUMTEST=20000
7116         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7117         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
7118         echo "$NUMTEST creates/unlinks"
7119         test_mkdir -p $DIR/$tdir
7120         createmany -o $DIR/$tdir/$tfile $NUMTEST
7121         unlinkmany $DIR/$tdir/$tfile $NUMTEST
7122
7123         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
7124                 tail -1 | cut -c11-20)
7125
7126         # don't return an error
7127         [ $OSTIO_post == $OSTIO_pre ] && echo \
7128             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
7129             echo "This may be fine, depending on what ran before this test" &&
7130             echo "and how fast this system is." && return
7131
7132         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
7133 }
7134 run_test 115 "verify dynamic thread creation===================="
7135
7136 free_min_max () {
7137         wait_delete_completed
7138         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7139         echo OST kbytes available: ${AVAIL[@]}
7140         MAXI=0; MAXV=${AVAIL[0]}
7141         MINI=0; MINV=${AVAIL[0]}
7142         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7143                 #echo OST $i: ${AVAIL[i]}kb
7144                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7145                         MAXV=${AVAIL[i]}; MAXI=$i
7146                 fi
7147                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7148                         MINV=${AVAIL[i]}; MINI=$i
7149                 fi
7150         done
7151         echo Min free space: OST $MINI: $MINV
7152         echo Max free space: OST $MAXI: $MAXV
7153 }
7154
7155 test_116a() { # was previously test_116()
7156         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7157         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
7158
7159         echo -n "Free space priority "
7160         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7161                 head -n1
7162         declare -a AVAIL
7163         free_min_max
7164
7165         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7166         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7167                 && return
7168         trap simple_cleanup_common EXIT
7169
7170
7171         # Check if we need to generate uneven OSTs
7172         test_mkdir -p $DIR/$tdir/OST${MINI}
7173         local FILL=$(($MINV / 4))
7174         local DIFF=$(($MAXV - $MINV))
7175         local DIFF2=$(($DIFF * 100 / $MINV))
7176
7177         local threshold=$(do_facet $SINGLEMDS \
7178                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7179         threshold=${threshold%%%}
7180         echo -n "Check for uneven OSTs: "
7181         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7182
7183         if [[ $DIFF2 -gt $threshold ]]; then
7184                 echo "ok"
7185                 echo "Don't need to fill OST$MINI"
7186         else
7187                 # generate uneven OSTs. Write 2% over the QOS threshold value
7188                 echo "no"
7189                 DIFF=$(($threshold - $DIFF2 + 2))
7190                 DIFF2=$(( ($MINV * $DIFF)/100 ))
7191                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
7192                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7193                         error "setstripe failed"
7194                 DIFF=$(($DIFF2 / 2048))
7195                 i=0
7196                 while [ $i -lt $DIFF ]; do
7197                         i=$(($i + 1))
7198                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7199                                 bs=2M count=1 2>/dev/null
7200                         echo -n .
7201                 done
7202                 echo .
7203                 sync
7204                 sleep_maxage
7205                 free_min_max
7206         fi
7207
7208         DIFF=$(($MAXV - $MINV))
7209         DIFF2=$(($DIFF * 100 / $MINV))
7210         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
7211         if [[ $DIFF2 -gt $threshold ]]; then
7212                 echo "ok"
7213         else
7214                 echo "failed - QOS mode won't be used"
7215                 skip "QOS imbalance criteria not met"
7216                 simple_cleanup_common
7217                 return
7218         fi
7219
7220         MINI1=$MINI; MINV1=$MINV
7221         MAXI1=$MAXI; MAXV1=$MAXV
7222
7223         # now fill using QOS
7224         $SETSTRIPE -c 1 $DIR/$tdir
7225         FILL=$(($FILL / 200))
7226         if [ $FILL -gt 600 ]; then
7227                 FILL=600
7228         fi
7229         echo "writing $FILL files to QOS-assigned OSTs"
7230         i=0
7231         while [ $i -lt $FILL ]; do
7232                 i=$((i + 1))
7233                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7234                         count=1 2>/dev/null
7235                 echo -n .
7236         done
7237         echo "wrote $i 200k files"
7238         sync
7239         sleep_maxage
7240
7241         echo "Note: free space may not be updated, so measurements might be off"
7242         free_min_max
7243         DIFF2=$(($MAXV - $MINV))
7244         echo "free space delta: orig $DIFF final $DIFF2"
7245         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7246         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
7247         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7248         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
7249         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7250         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7251         [ $DIFF -gt 0 ] &&
7252                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7253
7254         # Figure out which files were written where
7255         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7256                   awk '/'$MINI1': / {print $2; exit}')
7257         echo $UUID
7258         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7259         echo "$MINC files created on smaller OST $MINI1"
7260         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7261                   awk '/'$MAXI1': / {print $2; exit}')
7262         echo $UUID
7263         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7264         echo "$MAXC files created on larger OST $MAXI1"
7265         FILL=$(($MAXC * 100 / $MINC - 100))
7266         [[ $MINC -gt 0 ]] &&
7267                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7268         [[ $MAXC -gt $MINC ]] ||
7269                 error_ignore LU-9 "stripe QOS didn't balance free space"
7270         simple_cleanup_common
7271 }
7272 run_test 116a "stripe QOS: free space balance ==================="
7273
7274 test_116b() { # LU-2093
7275         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7276         [ -z "$($LCTL get_param -n lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr |
7277                 head -1 2>/dev/null)" ] && skip "no QOS" && return
7278 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7279         local old_rr
7280         old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7281                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7282         do_facet $SINGLEMDS lctl set_param \
7283                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7284         mkdir -p $DIR/$tdir
7285         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7286         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7287         do_facet $SINGLEMDS lctl set_param fail_loc=0
7288         rm -rf $DIR/$tdir
7289         do_facet $SINGLEMDS lctl set_param \
7290                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7291 }
7292 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7293
7294 test_117() # bug 10891
7295 {
7296         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7297         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7298         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7299         lctl set_param fail_loc=0x21e
7300         > $DIR/$tfile || error "truncate failed"
7301         lctl set_param fail_loc=0
7302         echo "Truncate succeeded."
7303         rm -f $DIR/$tfile
7304 }
7305 run_test 117 "verify osd extend =========="
7306
7307 NO_SLOW_RESENDCOUNT=4
7308 export OLD_RESENDCOUNT=""
7309 set_resend_count () {
7310         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7311         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7312         lctl set_param -n $PROC_RESENDCOUNT $1
7313         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7314 }
7315
7316 # for reduce test_118* time (b=14842)
7317 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7318
7319 # Reset async IO behavior after error case
7320 reset_async() {
7321         FILE=$DIR/reset_async
7322
7323         # Ensure all OSCs are cleared
7324         $SETSTRIPE -c -1 $FILE
7325         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7326         sync
7327         rm $FILE
7328 }
7329
7330 test_118a() #bug 11710
7331 {
7332         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7333         reset_async
7334
7335         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7336         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7337         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7338
7339         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7340                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7341                 return 1;
7342         fi
7343         rm -f $DIR/$tfile
7344 }
7345 run_test 118a "verify O_SYNC works =========="
7346
7347 test_118b()
7348 {
7349         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7350         remote_ost_nodsh && skip "remote OST with nodsh" && return
7351
7352         reset_async
7353
7354         #define OBD_FAIL_OST_ENOENT 0x217
7355         set_nodes_failloc "$(osts_nodes)" 0x217
7356         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7357         RC=$?
7358         set_nodes_failloc "$(osts_nodes)" 0
7359         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7360         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7361                     grep -c writeback)
7362
7363         if [[ $RC -eq 0 ]]; then
7364                 error "Must return error due to dropped pages, rc=$RC"
7365                 return 1;
7366         fi
7367
7368         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7369                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7370                 return 1;
7371         fi
7372
7373         echo "Dirty pages not leaked on ENOENT"
7374
7375         # Due to the above error the OSC will issue all RPCs syncronously
7376         # until a subsequent RPC completes successfully without error.
7377         $MULTIOP $DIR/$tfile Ow4096yc
7378         rm -f $DIR/$tfile
7379
7380         return 0
7381 }
7382 run_test 118b "Reclaim dirty pages on fatal error =========="
7383
7384 test_118c()
7385 {
7386         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7387
7388         # for 118c, restore the original resend count, LU-1940
7389         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7390                                 set_resend_count $OLD_RESENDCOUNT
7391         remote_ost_nodsh && skip "remote OST with nodsh" && return
7392
7393         reset_async
7394
7395         #define OBD_FAIL_OST_EROFS               0x216
7396         set_nodes_failloc "$(osts_nodes)" 0x216
7397
7398         # multiop should block due to fsync until pages are written
7399         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7400         MULTIPID=$!
7401         sleep 1
7402
7403         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7404                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7405         fi
7406
7407         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7408                     grep -c writeback)
7409         if [[ $WRITEBACK -eq 0 ]]; then
7410                 error "No page in writeback, writeback=$WRITEBACK"
7411         fi
7412
7413         set_nodes_failloc "$(osts_nodes)" 0
7414         wait $MULTIPID
7415         RC=$?
7416         if [[ $RC -ne 0 ]]; then
7417                 error "Multiop fsync failed, rc=$RC"
7418         fi
7419
7420         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7421         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7422                     grep -c writeback)
7423         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7424                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7425         fi
7426
7427         rm -f $DIR/$tfile
7428         echo "Dirty pages flushed via fsync on EROFS"
7429         return 0
7430 }
7431 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7432
7433 # continue to use small resend count to reduce test_118* time (b=14842)
7434 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7435
7436 test_118d()
7437 {
7438         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7439         remote_ost_nodsh && skip "remote OST with nodsh" && return
7440
7441         reset_async
7442
7443         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7444         set_nodes_failloc "$(osts_nodes)" 0x214
7445         # multiop should block due to fsync until pages are written
7446         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7447         MULTIPID=$!
7448         sleep 1
7449
7450         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7451                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7452         fi
7453
7454         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7455                     grep -c writeback)
7456         if [[ $WRITEBACK -eq 0 ]]; then
7457                 error "No page in writeback, writeback=$WRITEBACK"
7458         fi
7459
7460         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7461         set_nodes_failloc "$(osts_nodes)" 0
7462
7463         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7464         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7465                     grep -c writeback)
7466         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7467                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7468         fi
7469
7470         rm -f $DIR/$tfile
7471         echo "Dirty pages gaurenteed flushed via fsync"
7472         return 0
7473 }
7474 run_test 118d "Fsync validation inject a delay of the bulk =========="
7475
7476 test_118f() {
7477         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7478         reset_async
7479
7480         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7481         lctl set_param fail_loc=0x8000040a
7482
7483         # Should simulate EINVAL error which is fatal
7484         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7485         RC=$?
7486         if [[ $RC -eq 0 ]]; then
7487                 error "Must return error due to dropped pages, rc=$RC"
7488         fi
7489
7490         lctl set_param fail_loc=0x0
7491
7492         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7493         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7494         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7495                     grep -c writeback)
7496         if [[ $LOCKED -ne 0 ]]; then
7497                 error "Locked pages remain in cache, locked=$LOCKED"
7498         fi
7499
7500         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7501                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7502         fi
7503
7504         rm -f $DIR/$tfile
7505         echo "No pages locked after fsync"
7506
7507         reset_async
7508         return 0
7509 }
7510 run_test 118f "Simulate unrecoverable OSC side error =========="
7511
7512 test_118g() {
7513         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7514         reset_async
7515
7516         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7517         lctl set_param fail_loc=0x406
7518
7519         # simulate local -ENOMEM
7520         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7521         RC=$?
7522
7523         lctl set_param fail_loc=0
7524         if [[ $RC -eq 0 ]]; then
7525                 error "Must return error due to dropped pages, rc=$RC"
7526         fi
7527
7528         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7529         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7530         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7531                         grep -c writeback)
7532         if [[ $LOCKED -ne 0 ]]; then
7533                 error "Locked pages remain in cache, locked=$LOCKED"
7534         fi
7535
7536         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7537                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7538         fi
7539
7540         rm -f $DIR/$tfile
7541         echo "No pages locked after fsync"
7542
7543         reset_async
7544         return 0
7545 }
7546 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7547
7548 test_118h() {
7549         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7550         remote_ost_nodsh && skip "remote OST with nodsh" && return
7551
7552         reset_async
7553
7554         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7555         set_nodes_failloc "$(osts_nodes)" 0x20e
7556         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7557         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7558         RC=$?
7559
7560         set_nodes_failloc "$(osts_nodes)" 0
7561         if [[ $RC -eq 0 ]]; then
7562                 error "Must return error due to dropped pages, rc=$RC"
7563         fi
7564
7565         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7566         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7567         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7568                     grep -c writeback)
7569         if [[ $LOCKED -ne 0 ]]; then
7570                 error "Locked pages remain in cache, locked=$LOCKED"
7571         fi
7572
7573         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7574                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7575         fi
7576
7577         rm -f $DIR/$tfile
7578         echo "No pages locked after fsync"
7579
7580         return 0
7581 }
7582 run_test 118h "Verify timeout in handling recoverables errors  =========="
7583
7584 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7585
7586 test_118i() {
7587         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7588         remote_ost_nodsh && skip "remote OST with nodsh" && return
7589
7590         reset_async
7591
7592         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7593         set_nodes_failloc "$(osts_nodes)" 0x20e
7594
7595         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7596         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7597         PID=$!
7598         sleep 5
7599         set_nodes_failloc "$(osts_nodes)" 0
7600
7601         wait $PID
7602         RC=$?
7603         if [[ $RC -ne 0 ]]; then
7604                 error "got error, but should be not, rc=$RC"
7605         fi
7606
7607         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7608         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7609         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7610         if [[ $LOCKED -ne 0 ]]; then
7611                 error "Locked pages remain in cache, locked=$LOCKED"
7612         fi
7613
7614         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7615                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7616         fi
7617
7618         rm -f $DIR/$tfile
7619         echo "No pages locked after fsync"
7620
7621         return 0
7622 }
7623 run_test 118i "Fix error before timeout in recoverable error  =========="
7624
7625 [ "$SLOW" = "no" ] && set_resend_count 4
7626
7627 test_118j() {
7628         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7629         remote_ost_nodsh && skip "remote OST with nodsh" && return
7630
7631         reset_async
7632
7633         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7634         set_nodes_failloc "$(osts_nodes)" 0x220
7635
7636         # return -EIO from OST
7637         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7638         RC=$?
7639         set_nodes_failloc "$(osts_nodes)" 0x0
7640         if [[ $RC -eq 0 ]]; then
7641                 error "Must return error due to dropped pages, rc=$RC"
7642         fi
7643
7644         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7645         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7646         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7647         if [[ $LOCKED -ne 0 ]]; then
7648                 error "Locked pages remain in cache, locked=$LOCKED"
7649         fi
7650
7651         # in recoverable error on OST we want resend and stay until it finished
7652         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7653                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7654         fi
7655
7656         rm -f $DIR/$tfile
7657         echo "No pages locked after fsync"
7658
7659         return 0
7660 }
7661 run_test 118j "Simulate unrecoverable OST side error =========="
7662
7663 test_118k()
7664 {
7665         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7666         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7667
7668         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7669         set_nodes_failloc "$(osts_nodes)" 0x20e
7670         test_mkdir -p $DIR/$tdir
7671
7672         for ((i=0;i<10;i++)); do
7673                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7674                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7675                 SLEEPPID=$!
7676                 sleep 0.500s
7677                 kill $SLEEPPID
7678                 wait $SLEEPPID
7679         done
7680
7681         set_nodes_failloc "$(osts_nodes)" 0
7682         rm -rf $DIR/$tdir
7683 }
7684 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7685
7686 test_118l()
7687 {
7688         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7689         # LU-646
7690         test_mkdir -p $DIR/$tdir
7691         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7692         rm -rf $DIR/$tdir
7693 }
7694 run_test 118l "fsync dir ========="
7695
7696 test_118m() # LU-3066
7697 {
7698         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7699         test_mkdir -p $DIR/$tdir
7700         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7701         rm -rf $DIR/$tdir
7702 }
7703 run_test 118m "fdatasync dir ========="
7704
7705 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7706
7707 test_119a() # bug 11737
7708 {
7709         BSIZE=$((512 * 1024))
7710         directio write $DIR/$tfile 0 1 $BSIZE
7711         # We ask to read two blocks, which is more than a file size.
7712         # directio will indicate an error when requested and actual
7713         # sizes aren't equeal (a normal situation in this case) and
7714         # print actual read amount.
7715         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7716         if [ "$NOB" != "$BSIZE" ]; then
7717                 error "read $NOB bytes instead of $BSIZE"
7718         fi
7719         rm -f $DIR/$tfile
7720 }
7721 run_test 119a "Short directIO read must return actual read amount"
7722
7723 test_119b() # bug 11737
7724 {
7725         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7726
7727         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7728         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7729         sync
7730         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7731                 error "direct read failed"
7732         rm -f $DIR/$tfile
7733 }
7734 run_test 119b "Sparse directIO read must return actual read amount"
7735
7736 test_119c() # bug 13099
7737 {
7738         BSIZE=1048576
7739         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7740         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7741         rm -f $DIR/$tfile
7742 }
7743 run_test 119c "Testing for direct read hitting hole"
7744
7745 test_119d() # bug 15950
7746 {
7747         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7748         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7749         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7750         BSIZE=1048576
7751         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7752         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7753         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7754         lctl set_param fail_loc=0x40d
7755         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7756         pid_dio=$!
7757         sleep 1
7758         cat $DIR/$tfile > /dev/null &
7759         lctl set_param fail_loc=0
7760         pid_reads=$!
7761         wait $pid_dio
7762         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7763         sleep 2
7764         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7765         error "the read rpcs have not completed in 2s"
7766         rm -f $DIR/$tfile
7767         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7768 }
7769 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7770
7771 test_120a() {
7772         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7773         test_mkdir -p $DIR/$tdir
7774         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7775                skip "no early lock cancel on server" && return 0
7776
7777         lru_resize_disable mdc
7778         lru_resize_disable osc
7779         cancel_lru_locks mdc
7780         # asynchronous object destroy at MDT could cause bl ast to client
7781         cancel_lru_locks osc
7782
7783         stat $DIR/$tdir > /dev/null
7784         can1=$(do_facet $SINGLEMDS \
7785                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7786                awk '/ldlm_cancel/ {print $2}')
7787         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7788                awk '/ldlm_bl_callback/ {print $2}')
7789         test_mkdir -c1 $DIR/$tdir/d1
7790         can2=$(do_facet $SINGLEMDS \
7791                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7792                awk '/ldlm_cancel/ {print $2}')
7793         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7794                awk '/ldlm_bl_callback/ {print $2}')
7795         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7796         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7797         lru_resize_enable mdc
7798         lru_resize_enable osc
7799 }
7800 run_test 120a "Early Lock Cancel: mkdir test"
7801
7802 test_120b() {
7803         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7804         test_mkdir $DIR/$tdir
7805         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7806                skip "no early lock cancel on server" && return 0
7807         lru_resize_disable mdc
7808         lru_resize_disable osc
7809         cancel_lru_locks mdc
7810         stat $DIR/$tdir > /dev/null
7811         can1=$(do_facet $SINGLEMDS \
7812                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7813                awk '/ldlm_cancel/ {print $2}')
7814         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7815                awk '/ldlm_bl_callback/ {print $2}')
7816         touch $DIR/$tdir/f1
7817         can2=$(do_facet $SINGLEMDS \
7818                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7819                awk '/ldlm_cancel/ {print $2}')
7820         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7821                awk '/ldlm_bl_callback/ {print $2}')
7822         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7823         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7824         lru_resize_enable mdc
7825         lru_resize_enable osc
7826 }
7827 run_test 120b "Early Lock Cancel: create test"
7828
7829 test_120c() {
7830         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7831         test_mkdir -c1 $DIR/$tdir
7832         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7833                skip "no early lock cancel on server" && return 0
7834         lru_resize_disable mdc
7835         lru_resize_disable osc
7836         test_mkdir -p -c1 $DIR/$tdir/d1
7837         test_mkdir -p -c1 $DIR/$tdir/d2
7838         touch $DIR/$tdir/d1/f1
7839         cancel_lru_locks mdc
7840         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7841         can1=$(do_facet $SINGLEMDS \
7842                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7843                awk '/ldlm_cancel/ {print $2}')
7844         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7845                awk '/ldlm_bl_callback/ {print $2}')
7846         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7847         can2=$(do_facet $SINGLEMDS \
7848                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7849                awk '/ldlm_cancel/ {print $2}')
7850         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7851                awk '/ldlm_bl_callback/ {print $2}')
7852         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7853         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7854         lru_resize_enable mdc
7855         lru_resize_enable osc
7856 }
7857 run_test 120c "Early Lock Cancel: link test"
7858
7859 test_120d() {
7860         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7861         test_mkdir -p -c1 $DIR/$tdir
7862         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7863                skip "no early lock cancel on server" && return 0
7864         lru_resize_disable mdc
7865         lru_resize_disable osc
7866         touch $DIR/$tdir
7867         cancel_lru_locks mdc
7868         stat $DIR/$tdir > /dev/null
7869         can1=$(do_facet $SINGLEMDS \
7870                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7871                awk '/ldlm_cancel/ {print $2}')
7872         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7873                awk '/ldlm_bl_callback/ {print $2}')
7874         chmod a+x $DIR/$tdir
7875         can2=$(do_facet $SINGLEMDS \
7876                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7877                awk '/ldlm_cancel/ {print $2}')
7878         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7879                awk '/ldlm_bl_callback/ {print $2}')
7880         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7881         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7882         lru_resize_enable mdc
7883         lru_resize_enable osc
7884 }
7885 run_test 120d "Early Lock Cancel: setattr test"
7886
7887 test_120e() {
7888         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7889         test_mkdir -p -c1 $DIR/$tdir
7890         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7891                skip "no early lock cancel on server" && return 0
7892         lru_resize_disable mdc
7893         lru_resize_disable osc
7894         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
7895         cancel_lru_locks mdc
7896         cancel_lru_locks osc
7897         dd if=$DIR/$tdir/f1 of=/dev/null
7898         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
7899         # XXX client can not do early lock cancel of OST lock
7900         # during unlink (LU-4206), so cancel osc lock now.
7901         cancel_lru_locks osc
7902         can1=$(do_facet $SINGLEMDS \
7903                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7904                awk '/ldlm_cancel/ {print $2}')
7905         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7906                awk '/ldlm_bl_callback/ {print $2}')
7907         unlink $DIR/$tdir/f1
7908         sleep 5
7909         can2=$(do_facet $SINGLEMDS \
7910                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7911                awk '/ldlm_cancel/ {print $2}')
7912         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7913                awk '/ldlm_bl_callback/ {print $2}')
7914         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7915         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7916         lru_resize_enable mdc
7917         lru_resize_enable osc
7918 }
7919 run_test 120e "Early Lock Cancel: unlink test"
7920
7921 test_120f() {
7922         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7923         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7924                skip "no early lock cancel on server" && return 0
7925         test_mkdir -p -c1 $DIR/$tdir
7926         lru_resize_disable mdc
7927         lru_resize_disable osc
7928         test_mkdir -p -c1 $DIR/$tdir/d1
7929         test_mkdir -p -c1 $DIR/$tdir/d2
7930         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
7931         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
7932         cancel_lru_locks mdc
7933         cancel_lru_locks osc
7934         dd if=$DIR/$tdir/d1/f1 of=/dev/null
7935         dd if=$DIR/$tdir/d2/f2 of=/dev/null
7936         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
7937         # XXX client can not do early lock cancel of OST lock
7938         # during rename (LU-4206), so cancel osc lock now.
7939         cancel_lru_locks osc
7940         can1=$(do_facet $SINGLEMDS \
7941                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7942                awk '/ldlm_cancel/ {print $2}')
7943         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7944                awk '/ldlm_bl_callback/ {print $2}')
7945         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7946         sleep 5
7947         can2=$(do_facet $SINGLEMDS \
7948                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7949                awk '/ldlm_cancel/ {print $2}')
7950         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7951                awk '/ldlm_bl_callback/ {print $2}')
7952         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7953         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7954         lru_resize_enable mdc
7955         lru_resize_enable osc
7956 }
7957 run_test 120f "Early Lock Cancel: rename test"
7958
7959 test_120g() {
7960         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7961         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7962                skip "no early lock cancel on server" && return 0
7963         lru_resize_disable mdc
7964         lru_resize_disable osc
7965         count=10000
7966         echo create $count files
7967         test_mkdir -p $DIR/$tdir
7968         cancel_lru_locks mdc
7969         cancel_lru_locks osc
7970         t0=`date +%s`
7971
7972         can0=$(do_facet $SINGLEMDS \
7973                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7974                awk '/ldlm_cancel/ {print $2}')
7975         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7976                awk '/ldlm_bl_callback/ {print $2}')
7977         createmany -o $DIR/$tdir/f $count
7978         sync
7979         can1=$(do_facet $SINGLEMDS \
7980                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7981                awk '/ldlm_cancel/ {print $2}')
7982         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7983                awk '/ldlm_bl_callback/ {print $2}')
7984         t1=$(date +%s)
7985         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
7986         echo rm $count files
7987         rm -r $DIR/$tdir
7988         sync
7989         can2=$(do_facet $SINGLEMDS \
7990                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7991                awk '/ldlm_cancel/ {print $2}')
7992         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7993                awk '/ldlm_bl_callback/ {print $2}')
7994         t2=$(date +%s)
7995         echo total: $count removes in $((t2-t1))
7996         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
7997         sleep 2
7998         # wait for commitment of removal
7999         lru_resize_enable mdc
8000         lru_resize_enable osc
8001 }
8002 run_test 120g "Early Lock Cancel: performance test"
8003
8004 test_121() { #bug #10589
8005         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8006         rm -rf $DIR/$tfile
8007         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8008 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8009         lctl set_param fail_loc=0x310
8010         cancel_lru_locks osc > /dev/null
8011         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8012         lctl set_param fail_loc=0
8013         [[ $reads -eq $writes ]] ||
8014                 error "read $reads blocks, must be $writes blocks"
8015 }
8016 run_test 121 "read cancel race ========="
8017
8018 test_123a() { # was test 123, statahead(bug 11401)
8019         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8020         SLOWOK=0
8021         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8022             log "testing on UP system. Performance may be not as good as expected."
8023                         SLOWOK=1
8024         fi
8025
8026         rm -rf $DIR/$tdir
8027         test_mkdir -p $DIR/$tdir
8028         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8029         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8030         MULT=10
8031         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8032                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8033
8034                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8035                 lctl set_param -n llite.*.statahead_max 0
8036                 lctl get_param llite.*.statahead_max
8037                 cancel_lru_locks mdc
8038                 cancel_lru_locks osc
8039                 stime=`date +%s`
8040                 time ls -l $DIR/$tdir | wc -l
8041                 etime=`date +%s`
8042                 delta=$((etime - stime))
8043                 log "ls $i files without statahead: $delta sec"
8044                 lctl set_param llite.*.statahead_max=$max
8045
8046                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8047                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8048                 cancel_lru_locks mdc
8049                 cancel_lru_locks osc
8050                 stime=`date +%s`
8051                 time ls -l $DIR/$tdir | wc -l
8052                 etime=`date +%s`
8053                 delta_sa=$((etime - stime))
8054                 log "ls $i files with statahead: $delta_sa sec"
8055                 lctl get_param -n llite.*.statahead_stats
8056                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8057
8058                 [[ $swrong -lt $ewrong ]] &&
8059                         log "statahead was stopped, maybe too many locks held!"
8060                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8061
8062                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8063                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8064                     lctl set_param -n llite.*.statahead_max 0
8065                     lctl get_param llite.*.statahead_max
8066                     cancel_lru_locks mdc
8067                     cancel_lru_locks osc
8068                     stime=`date +%s`
8069                     time ls -l $DIR/$tdir | wc -l
8070                     etime=`date +%s`
8071                     delta=$((etime - stime))
8072                     log "ls $i files again without statahead: $delta sec"
8073                     lctl set_param llite.*.statahead_max=$max
8074                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8075                         if [  $SLOWOK -eq 0 ]; then
8076                                 error "ls $i files is slower with statahead!"
8077                         else
8078                                 log "ls $i files is slower with statahead!"
8079                         fi
8080                         break
8081                     fi
8082                 fi
8083
8084                 [ $delta -gt 20 ] && break
8085                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8086                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8087         done
8088         log "ls done"
8089
8090         stime=`date +%s`
8091         rm -r $DIR/$tdir
8092         sync
8093         etime=`date +%s`
8094         delta=$((etime - stime))
8095         log "rm -r $DIR/$tdir/: $delta seconds"
8096         log "rm done"
8097         lctl get_param -n llite.*.statahead_stats
8098 }
8099 run_test 123a "verify statahead work"
8100
8101 test_123b () { # statahead(bug 15027)
8102         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8103         test_mkdir -p $DIR/$tdir
8104         createmany -o $DIR/$tdir/$tfile-%d 1000
8105
8106         cancel_lru_locks mdc
8107         cancel_lru_locks osc
8108
8109 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8110         lctl set_param fail_loc=0x80000803
8111         ls -lR $DIR/$tdir > /dev/null
8112         log "ls done"
8113         lctl set_param fail_loc=0x0
8114         lctl get_param -n llite.*.statahead_stats
8115         rm -r $DIR/$tdir
8116         sync
8117
8118 }
8119 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8120
8121 test_124a() {
8122         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8123         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8124                 skip "no lru resize on server" && return 0
8125         local NR=2000
8126         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8127
8128         log "create $NR files at $DIR/$tdir"
8129         createmany -o $DIR/$tdir/f $NR ||
8130                 error "failed to create $NR files in $DIR/$tdir"
8131
8132         cancel_lru_locks mdc
8133         ls -l $DIR/$tdir > /dev/null
8134
8135         local NSDIR=""
8136         local LRU_SIZE=0
8137         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8138                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8139                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8140                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8141                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8142                         log "NSDIR=$NSDIR"
8143                         log "NS=$(basename $NSDIR)"
8144                         break
8145                 fi
8146         done
8147
8148         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8149                 skip "Not enough cached locks created!"
8150                 return 0
8151         fi
8152         log "LRU=$LRU_SIZE"
8153
8154         local SLEEP=30
8155
8156         # We know that lru resize allows one client to hold $LIMIT locks
8157         # for 10h. After that locks begin to be killed by client.
8158         local MAX_HRS=10
8159         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8160         log "LIMIT=$LIMIT"
8161
8162         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8163         # killing locks. Some time was spent for creating locks. This means
8164         # that up to the moment of sleep finish we must have killed some of
8165         # them (10-100 locks). This depends on how fast ther were created.
8166         # Many of them were touched in almost the same moment and thus will
8167         # be killed in groups.
8168         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8169
8170         # Use $LRU_SIZE_B here to take into account real number of locks
8171         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8172         local LRU_SIZE_B=$LRU_SIZE
8173         log "LVF=$LVF"
8174         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8175         log "OLD_LVF=$OLD_LVF"
8176         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8177
8178         # Let's make sure that we really have some margin. Client checks
8179         # cached locks every 10 sec.
8180         SLEEP=$((SLEEP+20))
8181         log "Sleep ${SLEEP} sec"
8182         local SEC=0
8183         while ((SEC<$SLEEP)); do
8184                 echo -n "..."
8185                 sleep 5
8186                 SEC=$((SEC+5))
8187                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8188                 echo -n "$LRU_SIZE"
8189         done
8190         echo ""
8191         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8192         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8193
8194         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8195                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8196                 unlinkmany $DIR/$tdir/f $NR
8197                 return
8198         }
8199
8200         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8201         log "unlink $NR files at $DIR/$tdir"
8202         unlinkmany $DIR/$tdir/f $NR
8203 }
8204 run_test 124a "lru resize ======================================="
8205
8206 get_max_pool_limit()
8207 {
8208         local limit=$($LCTL get_param \
8209                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8210         local max=0
8211         for l in $limit; do
8212                 if [[ $l -gt $max ]]; then
8213                         max=$l
8214                 fi
8215         done
8216         echo $max
8217 }
8218
8219 test_124b() {
8220         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8221         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8222                 skip "no lru resize on server" && return 0
8223
8224         LIMIT=$(get_max_pool_limit)
8225
8226         NR=$(($(default_lru_size)*20))
8227         if [[ $NR -gt $LIMIT ]]; then
8228                 log "Limit lock number by $LIMIT locks"
8229                 NR=$LIMIT
8230         fi
8231         lru_resize_disable mdc
8232         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8233                 error "failed to create $DIR/$tdir/disable_lru_resize"
8234
8235         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8236         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8237         cancel_lru_locks mdc
8238         stime=`date +%s`
8239         PID=""
8240         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8241         PID="$PID $!"
8242         sleep 2
8243         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8244         PID="$PID $!"
8245         sleep 2
8246         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8247         PID="$PID $!"
8248         wait $PID
8249         etime=`date +%s`
8250         nolruresize_delta=$((etime-stime))
8251         log "ls -la time: $nolruresize_delta seconds"
8252         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8253         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8254
8255         lru_resize_enable mdc
8256         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8257                 error "failed to create $DIR/$tdir/enable_lru_resize"
8258
8259         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8260         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8261         cancel_lru_locks mdc
8262         stime=`date +%s`
8263         PID=""
8264         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8265         PID="$PID $!"
8266         sleep 2
8267         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8268         PID="$PID $!"
8269         sleep 2
8270         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8271         PID="$PID $!"
8272         wait $PID
8273         etime=`date +%s`
8274         lruresize_delta=$((etime-stime))
8275         log "ls -la time: $lruresize_delta seconds"
8276         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8277
8278         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8279                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8280         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8281                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8282         else
8283                 log "lru resize performs the same with no lru resize"
8284         fi
8285         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8286 }
8287 run_test 124b "lru resize (performance test) ======================="
8288
8289 test_125() { # 13358
8290         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8291         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8292         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8293         test_mkdir -p $DIR/d125 || error "mkdir failed"
8294         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8295         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8296         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8297 }
8298 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8299
8300 test_126() { # bug 12829/13455
8301         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8302         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8303         $GSS && skip "must run as gss disabled" && return
8304
8305         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8306         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8307         rm -f $DIR/$tfile
8308         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8309 }
8310 run_test 126 "check that the fsgid provided by the client is taken into account"
8311
8312 test_127a() { # bug 15521
8313         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8314         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8315         $LCTL set_param osc.*.stats=0
8316         FSIZE=$((2048 * 1024))
8317         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8318         cancel_lru_locks osc
8319         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8320
8321         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8322         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8323                 echo "got $COUNT $NAME"
8324                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8325                 eval $NAME=$COUNT || error "Wrong proc format"
8326
8327                 case $NAME in
8328                         read_bytes|write_bytes)
8329                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8330                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8331                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8332                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8333                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8334                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8335                                 error "sumsquare is too small: $SUMSQ"
8336                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8337                                 error "sumsquare is too big: $SUMSQ"
8338                         ;;
8339                         *) ;;
8340                 esac
8341         done < $DIR/${tfile}.tmp
8342
8343         #check that we actually got some stats
8344         [ "$read_bytes" ] || error "Missing read_bytes stats"
8345         [ "$write_bytes" ] || error "Missing write_bytes stats"
8346         [ "$read_bytes" != 0 ] || error "no read done"
8347         [ "$write_bytes" != 0 ] || error "no write done"
8348 }
8349 run_test 127a "verify the client stats are sane"
8350
8351 test_127b() { # bug LU-333
8352         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8353         $LCTL set_param llite.*.stats=0
8354         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8355         # perform 2 reads and writes so MAX is different from SUM.
8356         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8357         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8358         cancel_lru_locks osc
8359         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8360         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8361
8362         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8363         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8364                 echo "got $COUNT $NAME"
8365                 eval $NAME=$COUNT || error "Wrong proc format"
8366
8367         case $NAME in
8368                 read_bytes)
8369                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8370                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8371                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8372                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8373                         ;;
8374                 write_bytes)
8375                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8376                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8377                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8378                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8379                         ;;
8380                         *) ;;
8381                 esac
8382         done < $TMP/${tfile}.tmp
8383
8384         #check that we actually got some stats
8385         [ "$read_bytes" ] || error "Missing read_bytes stats"
8386         [ "$write_bytes" ] || error "Missing write_bytes stats"
8387         [ "$read_bytes" != 0 ] || error "no read done"
8388         [ "$write_bytes" != 0 ] || error "no write done"
8389 }
8390 run_test 127b "verify the llite client stats are sane"
8391
8392 test_128() { # bug 15212
8393         touch $DIR/$tfile
8394         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8395                 find $DIR/$tfile
8396                 find $DIR/$tfile
8397         EOF
8398
8399         result=$(grep error $TMP/$tfile.log)
8400         rm -f $DIR/$tfile
8401         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8402 }
8403 run_test 128 "interactive lfs for 2 consecutive find's"
8404
8405 set_dir_limits () {
8406         local mntdev
8407         local canondev
8408         local node
8409
8410         local LDPROC=/proc/fs/ldiskfs
8411         local facets=$(get_facets MDS)
8412
8413         for facet in ${facets//,/ }; do
8414                 canondev=$(ldiskfs_canon \
8415                            *.$(convert_facet2label $facet).mntdev $facet)
8416                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8417                                                 LDPROC=/sys/fs/ldiskfs
8418                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8419         done
8420 }
8421
8422 test_129() {
8423         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8424         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8425                 skip "Only applicable to ldiskfs-based MDTs"
8426                 return
8427         fi
8428         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8429         ENOSPC=28
8430         EFBIG=27
8431
8432         rm -rf $DIR/$tdir
8433         test_mkdir -p $DIR/$tdir
8434
8435         # block size of mds1
8436         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8437         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8438         local MAX=$((MDSBLOCKSIZE * 3))
8439         set_dir_limits $MAX
8440         local I=$(stat -c%s "$DIR/$tdir")
8441         local J=0
8442         local STRIPE_COUNT=1
8443         [[ $MDSCOUNT -ge 2 ]] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8444         MAX=$((MAX*STRIPE_COUNT))
8445         while [[ $I -le $MAX ]]; do
8446                 $MULTIOP $DIR/$tdir/$J Oc
8447                 rc=$?
8448                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8449                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8450                 #and EFBIG for previous versions
8451                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8452                         set_dir_limits 0
8453                         echo "return code $rc received as expected"
8454                         multiop $DIR/$tdir/$J Oc ||
8455                                 error_exit "multiop failed w/o dir size limit"
8456
8457                         I=$(stat -c%s "$DIR/$tdir")
8458
8459                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8460                                         $(version_code 2.4.51) ]
8461                         then
8462                                 [[ $I -eq $MAX ]] && return 0
8463                         else
8464                                 [[ $I -gt $MAX ]] && return 0
8465                         fi
8466                         error_exit "current dir size $I, previous limit $MAX"
8467                 elif [ $rc -ne 0 ]; then
8468                         set_dir_limits 0
8469                         error_exit "return code $rc received instead of expected " \
8470                                    "$EFBIG or $ENOSPC, files in dir $I"
8471                 fi
8472                 J=$((J+1))
8473                 I=$(stat -c%s "$DIR/$tdir")
8474         done
8475
8476         set_dir_limits 0
8477         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8478 }
8479 run_test 129 "test directory size limit ========================"
8480
8481 OLDIFS="$IFS"
8482 cleanup_130() {
8483         trap 0
8484         IFS="$OLDIFS"
8485 }
8486
8487 test_130a() {
8488         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8489         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8490                 return
8491
8492         trap cleanup_130 EXIT RETURN
8493
8494         local fm_file=$DIR/$tfile
8495         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8496         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8497                 error "dd failed for $fm_file"
8498
8499         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8500         filefrag -ves $fm_file
8501         RC=$?
8502         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8503                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8504         [ $RC != 0 ] && error "filefrag $fm_file failed"
8505
8506         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8507                       grep -v "ext:" | grep -v "found")
8508         lun=$($GETSTRIPE -i $fm_file)
8509
8510         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8511         IFS=$'\n'
8512         tot_len=0
8513         for line in $filefrag_op
8514         do
8515                 frag_lun=`echo $line | cut -d: -f5`
8516                 ext_len=`echo $line | cut -d: -f4`
8517                 if (( $frag_lun != $lun )); then
8518                         cleanup_130
8519                         error "FIEMAP on 1-stripe file($fm_file) failed"
8520                         return
8521                 fi
8522                 (( tot_len += ext_len ))
8523         done
8524
8525         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8526                 cleanup_130
8527                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8528                 return
8529         fi
8530
8531         cleanup_130
8532
8533         echo "FIEMAP on single striped file succeeded"
8534 }
8535 run_test 130a "FIEMAP (1-stripe file)"
8536
8537 test_130b() {
8538         [ "$OSTCOUNT" -lt "2" ] &&
8539                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8540
8541         [ "$OSTCOUNT" -ge "10" ] &&
8542                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8543
8544         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8545         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8546                 return
8547
8548         trap cleanup_130 EXIT RETURN
8549
8550         local fm_file=$DIR/$tfile
8551         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8552         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8553                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8554
8555         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8556                 error "dd failed on $fm_file"
8557
8558         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8559         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8560                       grep -v "ext:" | grep -v "found")
8561
8562         last_lun=$(echo $filefrag_op | cut -d: -f5)
8563
8564         IFS=$'\n'
8565         tot_len=0
8566         num_luns=1
8567         for line in $filefrag_op
8568         do
8569                 frag_lun=`echo $line | cut -d: -f5`
8570                 ext_len=`echo $line | cut -d: -f4`
8571                 if (( $frag_lun != $last_lun )); then
8572                         if (( tot_len != 1024 )); then
8573                                 cleanup_130
8574                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8575                                 return
8576                         else
8577                                 (( num_luns += 1 ))
8578                                 tot_len=0
8579                         fi
8580                 fi
8581                 (( tot_len += ext_len ))
8582                 last_lun=$frag_lun
8583         done
8584         if (( num_luns != 2 || tot_len != 1024 )); then
8585                 cleanup_130
8586                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8587                 return
8588         fi
8589
8590         cleanup_130
8591
8592         echo "FIEMAP on 2-stripe file succeeded"
8593 }
8594 run_test 130b "FIEMAP (2-stripe file)"
8595
8596 test_130c() {
8597         [ "$OSTCOUNT" -lt "2" ] &&
8598                 skip_env "skipping FIEMAP on 2-stripe file" && return
8599
8600         [ "$OSTCOUNT" -ge "10" ] &&
8601                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8602
8603         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8604         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8605                 return
8606
8607         trap cleanup_130 EXIT RETURN
8608
8609         local fm_file=$DIR/$tfile
8610         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8611         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8612                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8613
8614         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8615
8616         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8617         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8618
8619         last_lun=`echo $filefrag_op | cut -d: -f5`
8620
8621         IFS=$'\n'
8622         tot_len=0
8623         num_luns=1
8624         for line in $filefrag_op
8625         do
8626                 frag_lun=`echo $line | cut -d: -f5`
8627                 ext_len=`echo $line | cut -d: -f4`
8628                 if (( $frag_lun != $last_lun )); then
8629                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8630                         if (( logical != 512 )); then
8631                                 cleanup_130
8632                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8633                                 return
8634                         fi
8635                         if (( tot_len != 512 )); then
8636                                 cleanup_130
8637                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8638                                 return
8639                         else
8640                                 (( num_luns += 1 ))
8641                                 tot_len=0
8642                         fi
8643                 fi
8644                 (( tot_len += ext_len ))
8645                 last_lun=$frag_lun
8646         done
8647         if (( num_luns != 2 || tot_len != 512 )); then
8648                 cleanup_130
8649                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8650                 return
8651         fi
8652
8653         cleanup_130
8654
8655         echo "FIEMAP on 2-stripe file with hole succeeded"
8656 }
8657 run_test 130c "FIEMAP (2-stripe file with hole)"
8658
8659 test_130d() {
8660         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8661
8662         [ "$OSTCOUNT" -ge "10" ] &&
8663                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8664
8665         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8666         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8667
8668         trap cleanup_130 EXIT RETURN
8669
8670         local fm_file=$DIR/$tfile
8671         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8672         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8673                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8674
8675         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8676         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8677                 error "dd failed on $fm_file"
8678
8679         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8680         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8681                 grep -v "ext:" | grep -v "found"`
8682
8683         last_lun=`echo $filefrag_op | cut -d: -f5`
8684
8685         IFS=$'\n'
8686         tot_len=0
8687         num_luns=1
8688         for line in $filefrag_op
8689         do
8690                 frag_lun=`echo $line | cut -d: -f5`
8691                 ext_len=`echo $line | cut -d: -f4`
8692                 if (( $frag_lun != $last_lun )); then
8693                         if (( tot_len != 1024 )); then
8694                                 cleanup_130
8695                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8696                                 return
8697                         else
8698                                 (( num_luns += 1 ))
8699                                 tot_len=0
8700                         fi
8701                 fi
8702                 (( tot_len += ext_len ))
8703                 last_lun=$frag_lun
8704         done
8705         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8706                 cleanup_130
8707                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8708                 return
8709         fi
8710
8711         cleanup_130
8712
8713         echo "FIEMAP on N-stripe file succeeded"
8714 }
8715 run_test 130d "FIEMAP (N-stripe file)"
8716
8717 test_130e() {
8718         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8719
8720         [ "$OSTCOUNT" -ge "10" ] &&
8721                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8722
8723         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8724         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8725
8726         trap cleanup_130 EXIT RETURN
8727
8728         local fm_file=$DIR/$tfile
8729         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8730         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8731                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8732
8733         NUM_BLKS=512
8734         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8735         for ((i = 0; i < $NUM_BLKS; i++))
8736         do
8737                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8738         done
8739
8740         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8741         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8742
8743         last_lun=`echo $filefrag_op | cut -d: -f5`
8744
8745         IFS=$'\n'
8746         tot_len=0
8747         num_luns=1
8748         for line in $filefrag_op
8749         do
8750                 frag_lun=`echo $line | cut -d: -f5`
8751                 ext_len=`echo $line | cut -d: -f4`
8752                 if (( $frag_lun != $last_lun )); then
8753                         if (( tot_len != $EXPECTED_LEN )); then
8754                                 cleanup_130
8755                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8756                                 return
8757                         else
8758                                 (( num_luns += 1 ))
8759                                 tot_len=0
8760                         fi
8761                 fi
8762                 (( tot_len += ext_len ))
8763                 last_lun=$frag_lun
8764         done
8765         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8766                 cleanup_130
8767                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8768                 return
8769         fi
8770
8771         cleanup_130
8772
8773         echo "FIEMAP with continuation calls succeeded"
8774 }
8775 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8776
8777 # Test for writev/readv
8778 test_131a() {
8779         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8780         error "writev test failed"
8781         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8782         error "readv failed"
8783         rm -f $DIR/$tfile
8784 }
8785 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8786
8787 test_131b() {
8788         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8789         error "append writev test failed"
8790         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8791         error "append writev test failed"
8792         rm -f $DIR/$tfile
8793 }
8794 run_test 131b "test append writev"
8795
8796 test_131c() {
8797         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8798         error "NOT PASS"
8799 }
8800 run_test 131c "test read/write on file w/o objects"
8801
8802 test_131d() {
8803         rwv -f $DIR/$tfile -w -n 1 1572864
8804         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8805         if [ "$NOB" != 1572864 ]; then
8806                 error "Short read filed: read $NOB bytes instead of 1572864"
8807         fi
8808         rm -f $DIR/$tfile
8809 }
8810 run_test 131d "test short read"
8811
8812 test_131e() {
8813         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8814         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8815         error "read hitting hole failed"
8816         rm -f $DIR/$tfile
8817 }
8818 run_test 131e "test read hitting hole"
8819
8820 get_ost_param() {
8821         local token=$1
8822         local gl_sum=0
8823         for node in $(osts_nodes); do
8824                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
8825                 [ x$gl = x"" ] && gl=0
8826                 gl_sum=$((gl_sum + gl))
8827         done
8828         echo $gl_sum
8829 }
8830
8831 som_mode_switch() {
8832         local som=$1
8833         local gl1=$2
8834         local gl2=$3
8835
8836         if [ x$som = x"enabled" ]; then
8837                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
8838                 MOUNT_OPTS=`echo $MOUNT_OPTS |
8839                     sed 's/som_preview,\|,som_preview\|som_preview//g'`
8840                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
8841         else
8842                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
8843                 MOUNT_OPTS="${MOUNT_OPTS:+$MOUNT_OPTS,}som_preview"
8844                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
8845         fi
8846
8847         # do remount to make new mount-conf parameters actual
8848         echo remounting...
8849         sync
8850         stopall
8851         setupall
8852 }
8853
8854 test_132() { #1028, SOM
8855         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8856         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8857         local num=$(get_mds_dir $DIR)
8858         local mymds=mds${num}
8859         local MOUNT_OPTS_SAVE=$MOUNT_OPTS
8860
8861         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8862         cancel_lru_locks osc
8863
8864         som1=$(do_facet $mymds "$LCTL get_param -n mdt.*.som" | head -n 1)
8865
8866         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8867         stat $DIR/$tfile >/dev/null
8868         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8869         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
8870         rm $DIR/$tfile
8871         som_mode_switch $som1 $gl1 $gl2
8872
8873         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8874         cancel_lru_locks osc
8875
8876         som2=$(do_facet $mymds "$LCTL get_param -n mdt.*.som" | head -n 1)
8877         if [ $som1 == $som2 ]; then
8878             error "som is still "$som2
8879             if [ x$som2 = x"enabled" ]; then
8880                 som2="disabled"
8881             else
8882                 som2="enabled"
8883             fi
8884         fi
8885
8886         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8887         stat $DIR/$tfile >/dev/null
8888         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8889         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
8890         som_mode_switch $som2 $gl1 $gl2
8891         MOUNT_OPTS=$MOUNT_OPTS_SAVE
8892 }
8893 run_test 132 "som avoids glimpse rpc"
8894
8895 check_stats() {
8896         local res
8897         local count
8898         case $1 in
8899         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8900                  ;;
8901         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8902                  ;;
8903         *) error "Wrong argument $1" ;;
8904         esac
8905         echo $res
8906         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8907         # if the argument $3 is zero, it means any stat increment is ok.
8908         if [[ $3 -gt 0 ]]; then
8909                 count=$(echo $res | awk '{ print $2 }')
8910                 [[ $count -ne $3 ]] &&
8911                         error "The $2 counter on $1 is wrong - expected $3"
8912         fi
8913 }
8914
8915 test_133a() {
8916         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8917         remote_ost_nodsh && skip "remote OST with nodsh" && return
8918         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8919
8920         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8921                 { skip "MDS doesn't support rename stats"; return; }
8922         local testdir=$DIR/${tdir}/stats_testdir
8923         mkdir -p $DIR/${tdir}
8924
8925         # clear stats.
8926         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8927         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8928
8929         # verify mdt stats first.
8930         mkdir ${testdir} || error "mkdir failed"
8931         check_stats $SINGLEMDS "mkdir" 1
8932         touch ${testdir}/${tfile} || "touch failed"
8933         check_stats $SINGLEMDS "open" 1
8934         check_stats $SINGLEMDS "close" 1
8935         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
8936         check_stats $SINGLEMDS "mknod" 1
8937         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
8938         check_stats $SINGLEMDS "unlink" 1
8939         rm -f ${testdir}/${tfile} || error "file remove failed"
8940         check_stats $SINGLEMDS "unlink" 2
8941
8942         # remove working dir and check mdt stats again.
8943         rmdir ${testdir} || error "rmdir failed"
8944         check_stats $SINGLEMDS "rmdir" 1
8945
8946         local testdir1=$DIR/${tdir}/stats_testdir1
8947         mkdir -p ${testdir}
8948         mkdir -p ${testdir1}
8949         touch ${testdir1}/test1
8950         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
8951         check_stats $SINGLEMDS "crossdir_rename" 1
8952
8953         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
8954         check_stats $SINGLEMDS "samedir_rename" 1
8955
8956         rm -rf $DIR/${tdir}
8957 }
8958 run_test 133a "Verifying MDT stats ========================================"
8959
8960 test_133b() {
8961         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8962         remote_ost_nodsh && skip "remote OST with nodsh" && return
8963         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8964         local testdir=$DIR/${tdir}/stats_testdir
8965         mkdir -p ${testdir} || error "mkdir failed"
8966         touch ${testdir}/${tfile} || "touch failed"
8967         cancel_lru_locks mdc
8968
8969         # clear stats.
8970         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8971         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8972
8973         # extra mdt stats verification.
8974         chmod 444 ${testdir}/${tfile} || error "chmod failed"
8975         check_stats $SINGLEMDS "setattr" 1
8976         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8977         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
8978         then            # LU-1740
8979                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
8980                 check_stats $SINGLEMDS "getattr" 1
8981         fi
8982         $LFS df || error "lfs failed"
8983         check_stats $SINGLEMDS "statfs" 1
8984
8985         rm -rf $DIR/${tdir}
8986 }
8987 run_test 133b "Verifying extra MDT stats =================================="
8988
8989 test_133c() {
8990         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8991         remote_ost_nodsh && skip "remote OST with nodsh" && return
8992         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8993         local testdir=$DIR/${tdir}/stats_testdir
8994         test_mkdir -p ${testdir} || error "mkdir failed"
8995
8996         # verify obdfilter stats.
8997         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8998         sync
8999         cancel_lru_locks osc
9000         wait_delete_completed
9001
9002         # clear stats.
9003         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9004         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9005
9006         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
9007         sync
9008         cancel_lru_locks osc
9009         check_stats ost "write" 1
9010
9011         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9012         check_stats ost "read" 1
9013
9014         > ${testdir}/${tfile} || error "truncate failed"
9015         check_stats ost "punch" 1
9016
9017         rm -f ${testdir}/${tfile} || error "file remove failed"
9018         wait_delete_completed
9019         check_stats ost "destroy" 1
9020
9021         rm -rf $DIR/${tdir}
9022 }
9023 run_test 133c "Verifying OST stats ========================================"
9024
9025 order_2() {
9026         local value=$1
9027         local orig=$value
9028         local order=1
9029
9030         while [ $value -ge 2 ]; do
9031                 order=$((order*2))
9032                 value=$((value/2))
9033         done
9034
9035         if [ $orig -gt $order ]; then
9036                 order=$((order*2))
9037         fi
9038         echo $order
9039 }
9040
9041 size_in_KMGT() {
9042     local value=$1
9043     local size=('K' 'M' 'G' 'T');
9044     local i=0
9045     local size_string=$value
9046
9047     while [ $value -ge 1024 ]; do
9048         if [ $i -gt 3 ]; then
9049             #T is the biggest unit we get here, if that is bigger,
9050             #just return XXXT
9051             size_string=${value}T
9052             break
9053         fi
9054         value=$((value >> 10))
9055         if [ $value -lt 1024 ]; then
9056             size_string=${value}${size[$i]}
9057             break
9058         fi
9059         i=$((i + 1))
9060     done
9061
9062     echo $size_string
9063 }
9064
9065 get_rename_size() {
9066     local size=$1
9067     local context=${2:-.}
9068     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9069                 grep -A1 $context |
9070                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9071     echo $sample
9072 }
9073
9074 test_133d() {
9075         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9076         remote_ost_nodsh && skip "remote OST with nodsh" && return
9077         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9078         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9079         { skip "MDS doesn't support rename stats"; return; }
9080
9081         local testdir1=$DIR/${tdir}/stats_testdir1
9082         local testdir2=$DIR/${tdir}/stats_testdir2
9083
9084         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9085
9086         mkdir -p ${testdir1} || error "mkdir failed"
9087         mkdir -p ${testdir2} || error "mkdir failed"
9088
9089         createmany -o $testdir1/test 512 || error "createmany failed"
9090
9091         # check samedir rename size
9092         mv ${testdir1}/test0 ${testdir1}/test_0
9093
9094         local testdir1_size=$(ls -l $DIR/${tdir} |
9095                 awk '/stats_testdir1/ {print $5}')
9096         local testdir2_size=$(ls -l $DIR/${tdir} |
9097                 awk '/stats_testdir2/ {print $5}')
9098
9099         testdir1_size=$(order_2 $testdir1_size)
9100         testdir2_size=$(order_2 $testdir2_size)
9101
9102         testdir1_size=$(size_in_KMGT $testdir1_size)
9103         testdir2_size=$(size_in_KMGT $testdir2_size)
9104
9105         echo "source rename dir size: ${testdir1_size}"
9106         echo "target rename dir size: ${testdir2_size}"
9107
9108         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9109         eval $cmd || error "$cmd failed"
9110         local samedir=$($cmd | grep 'same_dir')
9111         local same_sample=$(get_rename_size $testdir1_size)
9112         [ -z "$samedir" ] && error "samedir_rename_size count error"
9113         [[ $same_sample -eq 1 ]] ||
9114                 error "samedir_rename_size error $same_sample"
9115         echo "Check same dir rename stats success"
9116
9117         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9118
9119         # check crossdir rename size
9120         mv ${testdir1}/test_0 ${testdir2}/test_0
9121
9122         testdir1_size=$(ls -l $DIR/${tdir} |
9123                 awk '/stats_testdir1/ {print $5}')
9124         testdir2_size=$(ls -l $DIR/${tdir} |
9125                 awk '/stats_testdir2/ {print $5}')
9126
9127         testdir1_size=$(order_2 $testdir1_size)
9128         testdir2_size=$(order_2 $testdir2_size)
9129
9130         testdir1_size=$(size_in_KMGT $testdir1_size)
9131         testdir2_size=$(size_in_KMGT $testdir2_size)
9132
9133         echo "source rename dir size: ${testdir1_size}"
9134         echo "target rename dir size: ${testdir2_size}"
9135
9136         eval $cmd || error "$cmd failed"
9137         local crossdir=$($cmd | grep 'crossdir')
9138         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9139         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9140         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9141         [[ $src_sample -eq 1 ]] ||
9142                 error "crossdir_rename_size error $src_sample"
9143         [[ $tgt_sample -eq 1 ]] ||
9144                 error "crossdir_rename_size error $tgt_sample"
9145         echo "Check cross dir rename stats success"
9146         rm -rf $DIR/${tdir}
9147 }
9148 run_test 133d "Verifying rename_stats ========================================"
9149
9150 test_133e() {
9151         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9152         remote_ost_nodsh && skip "remote OST with nodsh" && return
9153         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9154         local testdir=$DIR/${tdir}/stats_testdir
9155         local ctr f0 f1 bs=32768 count=42 sum
9156
9157         mkdir -p ${testdir} || error "mkdir failed"
9158
9159         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9160
9161         for ctr in {write,read}_bytes; do
9162                 sync
9163                 cancel_lru_locks osc
9164
9165                 do_facet ost1 $LCTL set_param -n \
9166                         "obdfilter.*.exports.clear=clear"
9167
9168                 if [ $ctr = write_bytes ]; then
9169                         f0=/dev/zero
9170                         f1=${testdir}/${tfile}
9171                 else
9172                         f0=${testdir}/${tfile}
9173                         f1=/dev/null
9174                 fi
9175
9176                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9177                         error "dd failed"
9178                 sync
9179                 cancel_lru_locks osc
9180
9181                 sum=$(do_facet ost1 $LCTL get_param \
9182                         "obdfilter.*.exports.*.stats" |
9183                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9184                                 $1 == ctr { sum += $7 }
9185                                 END { printf("%0.0f", sum) }')
9186
9187                 if ((sum != bs * count)); then
9188                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9189                 fi
9190         done
9191
9192         rm -rf $DIR/${tdir}
9193 }
9194 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9195
9196 test_133f() {
9197         local proc_dirs
9198
9199         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9200 /sys/fs/lustre/ /sys/fs/lnet/"
9201         local dir
9202         for dir in $dirs; do
9203                 if [ -d $dir ]; then
9204                         proc_dirs="$proc_dirs $dir"
9205                 fi
9206         done
9207
9208         local facet
9209
9210         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9211         remote_ost_nodsh && skip "remote OST with nodsh" && return
9212         # First without trusting modes.
9213         find $proc_dirs -exec cat '{}' \; &> /dev/null
9214
9215         # Second verifying readability.
9216         find $proc_dirs \
9217                 -type f \
9218                 -exec cat '{}' \; &> /dev/null ||
9219                         error "proc file read failed"
9220
9221         for facet in $SINGLEMDS ost1; do
9222                 do_facet $facet find $proc_dirs \
9223                         ! -name req_history \
9224                         -exec cat '{}' \\\; &> /dev/null
9225
9226                 do_facet $facet find $proc_dirs \
9227                         ! -name req_history \
9228                         -type f \
9229                         -exec cat '{}' \\\; &> /dev/null ||
9230                                 error "proc file read failed"
9231         done
9232 }
9233 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9234
9235 test_133g() {
9236         local proc_dirs
9237
9238         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9239 /sys/fs/lustre/ /sys/fs/lnet/"
9240         local dir
9241         for dir in $dirs; do
9242                 if [ -d $dir ]; then
9243                         proc_dirs="$proc_dirs $dir"
9244                 fi
9245         done
9246
9247         local facet
9248
9249         # Second verifying readability.
9250         find $proc_dirs \
9251                 -type f \
9252                 -not -name force_lbug \
9253                 -not -name changelog_mask \
9254                 -exec badarea_io '{}' \; &> /dev/null ||
9255                 error "find $proc_dirs failed"
9256
9257         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
9258                 skip "Too old lustre on MDS"
9259
9260         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
9261                 skip "Too old lustre on ost1"
9262
9263         for facet in $SINGLEMDS ost1; do
9264                 do_facet $facet find $proc_dirs \
9265                         -type f \
9266                         -not -name force_lbug \
9267                         -not -name changelog_mask \
9268                         -exec badarea_io '{}' \\\; &> /dev/null ||
9269                 error "$facet find $proc_dirs failed"
9270
9271         done
9272
9273         # remount the FS in case writes/reads /proc break the FS
9274         cleanup || error "failed to unmount"
9275         setup || error "failed to setup"
9276         true
9277 }
9278 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9279
9280 test_140() { #bug-17379
9281         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9282         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
9283         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
9284         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
9285
9286         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9287         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9288         local i=0
9289         while i=`expr $i + 1`; do
9290                 test_mkdir -p $i || error "Creating dir $i"
9291                 cd $i || error "Changing to $i"
9292                 ln -s ../stat stat || error "Creating stat symlink"
9293                 # Read the symlink until ELOOP present,
9294                 # not LBUGing the system is considered success,
9295                 # we didn't overrun the stack.
9296                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9297                 [ $ret -ne 0 ] && {
9298                         if [ $ret -eq 40 ]; then
9299                                 break  # -ELOOP
9300                         else
9301                                 error "Open stat symlink"
9302                                 return
9303                         fi
9304                 }
9305         done
9306         i=`expr $i - 1`
9307         echo "The symlink depth = $i"
9308         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9309                                         error "Invalid symlink depth"
9310
9311         # Test recursive symlink
9312         ln -s symlink_self symlink_self
9313         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9314         echo "open symlink_self returns $ret"
9315         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9316 }
9317 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9318
9319 test_150() {
9320         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9321         local TF="$TMP/$tfile"
9322
9323         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9324         cp $TF $DIR/$tfile
9325         cancel_lru_locks osc
9326         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9327         remount_client $MOUNT
9328         df -P $MOUNT
9329         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9330
9331         $TRUNCATE $TF 6000
9332         $TRUNCATE $DIR/$tfile 6000
9333         cancel_lru_locks osc
9334         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9335
9336         echo "12345" >>$TF
9337         echo "12345" >>$DIR/$tfile
9338         cancel_lru_locks osc
9339         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9340
9341         echo "12345" >>$TF
9342         echo "12345" >>$DIR/$tfile
9343         cancel_lru_locks osc
9344         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9345
9346         rm -f $TF
9347         true
9348 }
9349 run_test 150 "truncate/append tests"
9350
9351 #LU-2902 roc_hit was not able to read all values from lproc
9352 function roc_hit_init() {
9353         local list=$(comma_list $(osts_nodes))
9354         local dir=$DIR/$tdir-check
9355         local file=$dir/file
9356         local BEFORE
9357         local AFTER
9358         local idx
9359
9360         test_mkdir -p $dir
9361         #use setstripe to do a write to every ost
9362         for i in $(seq 0 $((OSTCOUNT-1))); do
9363                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9364                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9365                 idx=$(printf %04x $i)
9366                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9367                         awk '$1 == "cache_access" {sum += $7}
9368                                 END { printf("%0.0f", sum) }')
9369
9370                 cancel_lru_locks osc
9371                 cat $file >/dev/null
9372
9373                 AFTER=$(get_osd_param $list *OST*$idx stats |
9374                         awk '$1 == "cache_access" {sum += $7}
9375                                 END { printf("%0.0f", sum) }')
9376
9377                 echo BEFORE:$BEFORE AFTER:$AFTER
9378                 if ! let "AFTER - BEFORE == 4"; then
9379                         rm -rf $dir
9380                         error "roc_hit is not safe to use"
9381                 fi
9382                 rm $file
9383         done
9384
9385         rm -rf $dir
9386 }
9387
9388 function roc_hit() {
9389         local list=$(comma_list $(osts_nodes))
9390         echo $(get_osd_param $list '' stats |
9391                 awk '$1 == "cache_hit" {sum += $7}
9392                         END { printf("%0.0f", sum) }')
9393 }
9394
9395 function set_cache() {
9396         local on=1
9397
9398         if [ "$2" == "off" ]; then
9399                 on=0;
9400         fi
9401         local list=$(comma_list $(osts_nodes))
9402         set_osd_param $list '' $1_cache_enable $on
9403
9404         cancel_lru_locks osc
9405 }
9406
9407 test_151() {
9408         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9409         remote_ost_nodsh && skip "remote OST with nodsh" && return
9410
9411         local CPAGES=3
9412         local list=$(comma_list $(osts_nodes))
9413
9414         # check whether obdfilter is cache capable at all
9415         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9416                 echo "not cache-capable obdfilter"
9417                 return 0
9418         fi
9419
9420         # check cache is enabled on all obdfilters
9421         if get_osd_param $list '' read_cache_enable | grep 0; then
9422                 echo "oss cache is disabled"
9423                 return 0
9424         fi
9425
9426         set_osd_param $list '' writethrough_cache_enable 1
9427
9428         # check write cache is enabled on all obdfilters
9429         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9430                 echo "oss write cache is NOT enabled"
9431                 return 0
9432         fi
9433
9434         roc_hit_init
9435
9436         #define OBD_FAIL_OBD_NO_LRU  0x609
9437         do_nodes $list $LCTL set_param fail_loc=0x609
9438
9439         # pages should be in the case right after write
9440         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9441                 error "dd failed"
9442
9443         local BEFORE=$(roc_hit)
9444         cancel_lru_locks osc
9445         cat $DIR/$tfile >/dev/null
9446         local AFTER=$(roc_hit)
9447
9448         do_nodes $list $LCTL set_param fail_loc=0
9449
9450         if ! let "AFTER - BEFORE == CPAGES"; then
9451                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9452         fi
9453
9454         # the following read invalidates the cache
9455         cancel_lru_locks osc
9456         set_osd_param $list '' read_cache_enable 0
9457         cat $DIR/$tfile >/dev/null
9458
9459         # now data shouldn't be found in the cache
9460         BEFORE=$(roc_hit)
9461         cancel_lru_locks osc
9462         cat $DIR/$tfile >/dev/null
9463         AFTER=$(roc_hit)
9464         if let "AFTER - BEFORE != 0"; then
9465                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9466         fi
9467
9468         set_osd_param $list '' read_cache_enable 1
9469         rm -f $DIR/$tfile
9470 }
9471 run_test 151 "test cache on oss and controls ==============================="
9472
9473 test_152() {
9474         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9475         local TF="$TMP/$tfile"
9476
9477         # simulate ENOMEM during write
9478 #define OBD_FAIL_OST_NOMEM      0x226
9479         lctl set_param fail_loc=0x80000226
9480         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9481         cp $TF $DIR/$tfile
9482         sync || error "sync failed"
9483         lctl set_param fail_loc=0
9484
9485         # discard client's cache
9486         cancel_lru_locks osc
9487
9488         # simulate ENOMEM during read
9489         lctl set_param fail_loc=0x80000226
9490         cmp $TF $DIR/$tfile || error "cmp failed"
9491         lctl set_param fail_loc=0
9492
9493         rm -f $TF
9494 }
9495 run_test 152 "test read/write with enomem ============================"
9496
9497 test_153() {
9498         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9499 }
9500 run_test 153 "test if fdatasync does not crash ======================="
9501
9502 dot_lustre_fid_permission_check() {
9503         local fid=$1
9504         local ffid=$MOUNT/.lustre/fid/$fid
9505         local test_dir=$2
9506
9507         echo "stat fid $fid"
9508         stat $ffid > /dev/null || error "stat $ffid failed."
9509         echo "touch fid $fid"
9510         touch $ffid || error "touch $ffid failed."
9511         echo "write to fid $fid"
9512         cat /etc/hosts > $ffid || error "write $ffid failed."
9513         echo "read fid $fid"
9514         diff /etc/hosts $ffid || error "read $ffid failed."
9515         echo "append write to fid $fid"
9516         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9517         echo "rename fid $fid"
9518         mv $ffid $test_dir/$tfile.1 &&
9519                 error "rename $ffid to $tfile.1 should fail."
9520         touch $test_dir/$tfile.1
9521         mv $test_dir/$tfile.1 $ffid &&
9522                 error "rename $tfile.1 to $ffid should fail."
9523         rm -f $test_dir/$tfile.1
9524         echo "truncate fid $fid"
9525         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9526         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9527                 echo "link fid $fid"
9528                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9529         fi
9530         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9531                 echo "setfacl fid $fid"
9532                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9533                 echo "getfacl fid $fid"
9534                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9535         fi
9536         echo "unlink fid $fid"
9537         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9538         echo "mknod fid $fid"
9539         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9540
9541         fid=[0xf00000400:0x1:0x0]
9542         ffid=$MOUNT/.lustre/fid/$fid
9543
9544         echo "stat non-exist fid $fid"
9545         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9546         echo "write to non-exist fid $fid"
9547         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9548         echo "link new fid $fid"
9549         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9550
9551         mkdir -p $test_dir/$tdir
9552         touch $test_dir/$tdir/$tfile
9553         fid=$($LFS path2fid $test_dir/$tdir)
9554         rc=$?
9555         [ $rc -ne 0 ] &&
9556                 error "error: could not get fid for $test_dir/$dir/$tfile."
9557
9558         ffid=$MOUNT/.lustre/fid/$fid
9559
9560         echo "ls $fid"
9561         ls $ffid > /dev/null || error "ls $ffid failed."
9562         echo "touch $fid/$tfile.1"
9563         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9564
9565         echo "touch $MOUNT/.lustre/fid/$tfile"
9566         touch $MOUNT/.lustre/fid/$tfile && \
9567                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9568
9569         echo "setxattr to $MOUNT/.lustre/fid"
9570         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9571
9572         echo "listxattr for $MOUNT/.lustre/fid"
9573         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9574
9575         echo "delxattr from $MOUNT/.lustre/fid"
9576         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9577
9578         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9579         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9580                 error "touch invalid fid should fail."
9581
9582         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9583         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9584                 error "touch non-normal fid should fail."
9585
9586         echo "rename $tdir to $MOUNT/.lustre/fid"
9587         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9588                 error "rename to $MOUNT/.lustre/fid should fail."
9589
9590         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9591         then            # LU-3547
9592                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9593                 local new_obf_mode=777
9594
9595                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9596                 chmod $new_obf_mode $DIR/.lustre/fid ||
9597                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9598
9599                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9600                 [ $obf_mode -eq $new_obf_mode ] ||
9601                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9602
9603                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9604                 chmod $old_obf_mode $DIR/.lustre/fid ||
9605                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9606         fi
9607
9608         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9609         fid=$($LFS path2fid $test_dir/$tfile-2)
9610
9611         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
9612         then # LU-5424
9613                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9614                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
9615                         error "create lov data thru .lustre failed"
9616         fi
9617         echo "cp /etc/passwd $test_dir/$tfile-2"
9618         cp /etc/passwd $test_dir/$tfile-2 ||
9619                 error "copy to $test_dir/$tfile-2 failed."
9620         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9621         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9622                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9623
9624         rm -rf $test_dir/tfile.lnk
9625         rm -rf $test_dir/$tfile-2
9626 }
9627
9628 test_154A() {
9629         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9630                 skip "Need MDS version at least 2.4.1" && return
9631
9632         touch $DIR/$tfile
9633         local FID=$($LFS path2fid $DIR/$tfile)
9634         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9635
9636         # check that we get the same pathname back
9637         local FOUND=$($LFS fid2path $MOUNT $FID)
9638         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9639         [ "$FOUND" != "$DIR/$tfile" ] &&
9640                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9641
9642         rm -rf $DIR/$tfile
9643 }
9644 run_test 154A "lfs path2fid and fid2path basic checks"
9645
9646 test_154a() {
9647         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9648         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9649                 { skip "Need MDS version at least 2.2.51"; return 0; }
9650         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9651
9652         cp /etc/hosts $DIR/$tfile
9653
9654         fid=$($LFS path2fid $DIR/$tfile)
9655         rc=$?
9656         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9657
9658         dot_lustre_fid_permission_check "$fid" $DIR ||
9659                 error "dot lustre permission check $fid failed"
9660
9661         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9662
9663         touch $MOUNT/.lustre/file &&
9664                 error "creation is not allowed under .lustre"
9665
9666         mkdir $MOUNT/.lustre/dir &&
9667                 error "mkdir is not allowed under .lustre"
9668
9669         rm -rf $DIR/$tfile
9670 }
9671 run_test 154a "Open-by-FID"
9672
9673 test_154b() {
9674         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9675         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9676                 { skip "Need MDS version at least 2.2.51"; return 0; }
9677
9678         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9679
9680         local remote_dir=$DIR/$tdir/remote_dir
9681         local MDTIDX=1
9682         local rc=0
9683
9684         mkdir -p $DIR/$tdir
9685         $LFS mkdir -i $MDTIDX $remote_dir ||
9686                 error "create remote directory failed"
9687
9688         cp /etc/hosts $remote_dir/$tfile
9689
9690         fid=$($LFS path2fid $remote_dir/$tfile)
9691         rc=$?
9692         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9693
9694         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9695                 error "dot lustre permission check $fid failed"
9696         rm -rf $DIR/$tdir
9697 }
9698 run_test 154b "Open-by-FID for remote directory"
9699
9700 test_154c() {
9701         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9702                 skip "Need MDS version at least 2.4.1" && return
9703
9704         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9705         local FID1=$($LFS path2fid $DIR/$tfile.1)
9706         local FID2=$($LFS path2fid $DIR/$tfile.2)
9707         local FID3=$($LFS path2fid $DIR/$tfile.3)
9708
9709         local N=1
9710         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9711                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9712                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9713                 local want=FID$N
9714                 [ "$FID" = "${!want}" ] ||
9715                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9716                 N=$((N + 1))
9717         done
9718
9719         $LFS fid2path $MOUNT $FID1 $FID2 $FID3 | while read PATHNAME; do
9720                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
9721                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
9722                 N=$((N + 1))
9723         done
9724 }
9725 run_test 154c "lfs path2fid and fid2path multiple arguments"
9726
9727 test_154d() {
9728         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
9729                 skip "Need MDS version at least 2.5.53" && return
9730
9731         if remote_mds; then
9732                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
9733         else
9734                 nid="0@lo"
9735         fi
9736         local proc_ofile="mdt.*.exports.'$nid'.open_files"
9737         local fd
9738         local cmd
9739
9740         rm -f $DIR/$tfile
9741         touch $DIR/$tfile
9742
9743         fid=$($LFS path2fid $DIR/$tfile)
9744         # Open the file
9745         fd=$(free_fd)
9746         cmd="exec $fd<$DIR/$tfile"
9747         eval $cmd
9748         fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
9749         echo $fid_list | grep $fid
9750         rc=$?
9751
9752         cmd="exec $fd>/dev/null"
9753         eval $cmd
9754         if [ $rc -ne 0 ]; then
9755                 error "FID $fid not found in open files list $fid_list"
9756         fi
9757 }
9758 run_test 154d "Verify open file fid"
9759
9760 test_154e()
9761 {
9762         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
9763                 skip "Need MDS version at least 2.6.50" && return
9764
9765         if ls -a $MOUNT | grep -q '^\.lustre$'; then
9766                 error ".lustre returned by readdir"
9767         fi
9768 }
9769 run_test 154e ".lustre is not returned by readdir"
9770
9771 test_155_small_load() {
9772     local temp=$TMP/$tfile
9773     local file=$DIR/$tfile
9774
9775     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
9776         error "dd of=$temp bs=6096 count=1 failed"
9777     cp $temp $file
9778     cancel_lru_locks osc
9779     cmp $temp $file || error "$temp $file differ"
9780
9781     $TRUNCATE $temp 6000
9782     $TRUNCATE $file 6000
9783     cmp $temp $file || error "$temp $file differ (truncate1)"
9784
9785     echo "12345" >>$temp
9786     echo "12345" >>$file
9787     cmp $temp $file || error "$temp $file differ (append1)"
9788
9789     echo "12345" >>$temp
9790     echo "12345" >>$file
9791     cmp $temp $file || error "$temp $file differ (append2)"
9792
9793     rm -f $temp $file
9794     true
9795 }
9796
9797 test_155_big_load() {
9798     remote_ost_nodsh && skip "remote OST with nodsh" && return
9799     local temp=$TMP/$tfile
9800     local file=$DIR/$tfile
9801
9802     free_min_max
9803     local cache_size=$(do_facet ost$((MAXI+1)) \
9804         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
9805     local large_file_size=$((cache_size * 2))
9806
9807     echo "OSS cache size: $cache_size KB"
9808     echo "Large file size: $large_file_size KB"
9809
9810     [ $MAXV -le $large_file_size ] && \
9811         skip_env "max available OST size needs > $large_file_size KB" && \
9812         return 0
9813
9814     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
9815
9816     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
9817         error "dd of=$temp bs=$large_file_size count=1k failed"
9818     cp $temp $file
9819     ls -lh $temp $file
9820     cancel_lru_locks osc
9821     cmp $temp $file || error "$temp $file differ"
9822
9823     rm -f $temp $file
9824     true
9825 }
9826
9827 test_155a() {
9828         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9829         set_cache read on
9830         set_cache writethrough on
9831         test_155_small_load
9832 }
9833 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
9834
9835 test_155b() {
9836         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9837         set_cache read on
9838         set_cache writethrough off
9839         test_155_small_load
9840 }
9841 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
9842
9843 test_155c() {
9844         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9845         set_cache read off
9846         set_cache writethrough on
9847         test_155_small_load
9848 }
9849 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
9850
9851 test_155d() {
9852         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9853         set_cache read off
9854         set_cache writethrough off
9855         test_155_small_load
9856 }
9857 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
9858
9859 test_155e() {
9860         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9861         set_cache read on
9862         set_cache writethrough on
9863         test_155_big_load
9864 }
9865 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
9866
9867 test_155f() {
9868         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9869         set_cache read on
9870         set_cache writethrough off
9871         test_155_big_load
9872 }
9873 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
9874
9875 test_155g() {
9876         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9877         set_cache read off
9878         set_cache writethrough on
9879         test_155_big_load
9880 }
9881 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
9882
9883 test_155h() {
9884         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9885         set_cache read off
9886         set_cache writethrough off
9887         test_155_big_load
9888 }
9889 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
9890
9891 test_156() {
9892         remote_ost_nodsh && skip "remote OST with nodsh" && return
9893         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9894         local CPAGES=3
9895         local BEFORE
9896         local AFTER
9897         local file="$DIR/$tfile"
9898
9899         [ "$(facet_fstype ost1)" = "zfs" ] &&
9900                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
9901                 return
9902
9903         roc_hit_init
9904
9905     log "Turn on read and write cache"
9906     set_cache read on
9907     set_cache writethrough on
9908
9909     log "Write data and read it back."
9910     log "Read should be satisfied from the cache."
9911     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9912     BEFORE=`roc_hit`
9913     cancel_lru_locks osc
9914     cat $file >/dev/null
9915     AFTER=`roc_hit`
9916     if ! let "AFTER - BEFORE == CPAGES"; then
9917         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9918     else
9919         log "cache hits:: before: $BEFORE, after: $AFTER"
9920     fi
9921
9922     log "Read again; it should be satisfied from the cache."
9923     BEFORE=$AFTER
9924     cancel_lru_locks osc
9925     cat $file >/dev/null
9926     AFTER=`roc_hit`
9927     if ! let "AFTER - BEFORE == CPAGES"; then
9928         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9929     else
9930         log "cache hits:: before: $BEFORE, after: $AFTER"
9931     fi
9932
9933
9934     log "Turn off the read cache and turn on the write cache"
9935     set_cache read off
9936     set_cache writethrough on
9937
9938     log "Read again; it should be satisfied from the cache."
9939     BEFORE=`roc_hit`
9940     cancel_lru_locks osc
9941     cat $file >/dev/null
9942     AFTER=`roc_hit`
9943     if ! let "AFTER - BEFORE == CPAGES"; then
9944         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9945     else
9946         log "cache hits:: before: $BEFORE, after: $AFTER"
9947     fi
9948
9949     log "Read again; it should not be satisfied from the cache."
9950     BEFORE=$AFTER
9951     cancel_lru_locks osc
9952     cat $file >/dev/null
9953     AFTER=`roc_hit`
9954     if ! let "AFTER - BEFORE == 0"; then
9955         error "IN CACHE: before: $BEFORE, after: $AFTER"
9956     else
9957         log "cache hits:: before: $BEFORE, after: $AFTER"
9958     fi
9959
9960     log "Write data and read it back."
9961     log "Read should be satisfied from the cache."
9962     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9963     BEFORE=`roc_hit`
9964     cancel_lru_locks osc
9965     cat $file >/dev/null
9966     AFTER=`roc_hit`
9967     if ! let "AFTER - BEFORE == CPAGES"; then
9968         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9969     else
9970         log "cache hits:: before: $BEFORE, after: $AFTER"
9971     fi
9972
9973     log "Read again; it should not be satisfied from the cache."
9974     BEFORE=$AFTER
9975     cancel_lru_locks osc
9976     cat $file >/dev/null
9977     AFTER=`roc_hit`
9978     if ! let "AFTER - BEFORE == 0"; then
9979         error "IN CACHE: before: $BEFORE, after: $AFTER"
9980     else
9981         log "cache hits:: before: $BEFORE, after: $AFTER"
9982     fi
9983
9984
9985     log "Turn off read and write cache"
9986     set_cache read off
9987     set_cache writethrough off
9988
9989     log "Write data and read it back"
9990     log "It should not be satisfied from the cache."
9991     rm -f $file
9992     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9993     cancel_lru_locks osc
9994     BEFORE=`roc_hit`
9995     cat $file >/dev/null
9996     AFTER=`roc_hit`
9997         if ! let "AFTER - BEFORE == 0"; then
9998                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9999         else
10000                 log "cache hits:: before: $BEFORE, after: $AFTER"
10001         fi
10002
10003     log "Turn on the read cache and turn off the write cache"
10004     set_cache read on
10005     set_cache writethrough off
10006
10007     log "Write data and read it back"
10008     log "It should not be satisfied from the cache."
10009     rm -f $file
10010     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10011     BEFORE=`roc_hit`
10012     cancel_lru_locks osc
10013     cat $file >/dev/null
10014     AFTER=`roc_hit`
10015         if ! let "AFTER - BEFORE == 0"; then
10016                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10017         else
10018                 log "cache hits:: before: $BEFORE, after: $AFTER"
10019         fi
10020
10021     log "Read again; it should be satisfied from the cache."
10022     BEFORE=`roc_hit`
10023     cancel_lru_locks osc
10024     cat $file >/dev/null
10025     AFTER=`roc_hit`
10026     if ! let "AFTER - BEFORE == CPAGES"; then
10027         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10028     else
10029         log "cache hits:: before: $BEFORE, after: $AFTER"
10030     fi
10031
10032     rm -f $file
10033 }
10034 run_test 156 "Verification of tunables ============================"
10035
10036 #Changelogs
10037 err17935 () {
10038         if [[ $MDSCOUNT -gt 1 ]]; then
10039                 error_ignore bz17935 $*
10040         else
10041                 error $*
10042         fi
10043 }
10044
10045 changelog_chmask()
10046 {
10047         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10048
10049         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
10050
10051         if [ $MASK -eq 1 ]; then
10052                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
10053         else
10054                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
10055         fi
10056 }
10057
10058 changelog_extract_field() {
10059         local mdt=$1
10060         local cltype=$2
10061         local file=$3
10062         local identifier=$4
10063
10064         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
10065                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10066                 tail -1
10067 }
10068
10069 test_160a() {
10070         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10071         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10072         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10073                 { skip "Need MDS version at least 2.2.0"; return; }
10074
10075         local CL_USERS="mdd.$MDT0.changelog_users"
10076         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10077         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10078         echo "Registered as changelog user $USER"
10079         $GET_CL_USERS | grep -q $USER ||
10080                 error "User $USER not found in changelog_users"
10081
10082         # change something
10083         test_mkdir -p $DIR/$tdir/pics/2008/zachy
10084         touch $DIR/$tdir/pics/2008/zachy/timestamp
10085         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
10086         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
10087         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
10088         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
10089         rm $DIR/$tdir/pics/desktop.jpg
10090
10091         $LFS changelog $MDT0 | tail -5
10092
10093         echo "verifying changelog mask"
10094         changelog_chmask "MKDIR"
10095         changelog_chmask "CLOSE"
10096
10097         test_mkdir -p $DIR/$tdir/pics/zach/sofia
10098         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10099
10100         changelog_chmask "MKDIR"
10101         changelog_chmask "CLOSE"
10102
10103         test_mkdir -p $DIR/$tdir/pics/2008/sofia
10104         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10105
10106         $LFS changelog $MDT0
10107         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
10108         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
10109         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
10110         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
10111
10112         # verify contents
10113         echo "verifying target fid"
10114         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
10115         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
10116         [ "$fidc" == "$fidf" ] ||
10117                 err17935 "fid in changelog $fidc != file fid $fidf"
10118         echo "verifying parent fid"
10119         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
10120         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
10121         [ "$fidc" == "$fidf" ] ||
10122                 err17935 "pfid in changelog $fidc != dir fid $fidf"
10123
10124         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10125         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
10126         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10127         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
10128         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
10129                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
10130
10131         MIN_REC=$($GET_CL_USERS |
10132                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
10133         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
10134         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
10135         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
10136                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
10137
10138         # LU-3446 changelog index reset on MDT restart
10139         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10140         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10141         $LFS changelog_clear $MDT0 $USER 0
10142         stop $SINGLEMDS || error "Fail to stop MDT."
10143         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10144         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10145         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
10146         [ $CUR_REC1 == $CUR_REC2 ] ||
10147                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
10148
10149         echo "verifying user deregister"
10150         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10151         $GET_CL_USERS | grep -q $USER &&
10152                 error "User $USER still in changelog_users"
10153
10154         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
10155         if [ $USERS -eq 0 ]; then
10156                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10157                 touch $DIR/$tdir/chloe
10158                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10159                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
10160                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
10161         else
10162                 echo "$USERS other changelog users; can't verify off"
10163         fi
10164 }
10165 run_test 160a "changelog sanity"
10166
10167 test_160b() { # LU-3587
10168         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10169         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10170         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10171                 { skip "Need MDS version at least 2.2.0"; return; }
10172
10173         local CL_USERS="mdd.$MDT0.changelog_users"
10174         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10175         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10176         echo "Registered as changelog user $USER"
10177         $GET_CL_USERS | grep -q $USER ||
10178                 error "User $USER not found in changelog_users"
10179
10180         local LONGNAME1=$(str_repeat a 255)
10181         local LONGNAME2=$(str_repeat b 255)
10182
10183         cd $DIR
10184         echo "creating very long named file"
10185         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
10186         echo "moving very long named file"
10187         mv $LONGNAME1 $LONGNAME2
10188
10189         $LFS changelog $MDT0 | grep RENME
10190
10191         echo "deregistering $USER"
10192         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10193
10194         rm -f $LONGNAME2
10195 }
10196 run_test 160b "Verify that very long rename doesn't crash in changelog"
10197
10198 test_160c() {
10199         local rc=0
10200         local server_version=$(lustre_version_code $SINGLEMDS)
10201
10202         [[ $server_version -gt $(version_code 2.5.57) ]] ||
10203                 [[ $server_version -gt $(version_code 2.5.1) &&
10204                    $server_version -lt $(version_code 2.5.50) ]] ||
10205                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
10206         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10207
10208         # Registration step
10209         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10210                 changelog_register -n)
10211
10212         rm -rf $DIR/$tdir
10213         mkdir -p $DIR/$tdir
10214         $MCREATE $DIR/$tdir/foo_160c
10215         changelog_chmask "TRUNC"
10216         $TRUNCATE $DIR/$tdir/foo_160c 200
10217         changelog_chmask "TRUNC"
10218         $TRUNCATE $DIR/$tdir/foo_160c 199
10219         $LFS changelog $MDT0
10220         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
10221         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
10222         $LFS changelog_clear $MDT0 $USER 0
10223
10224         # Deregistration step
10225         echo "deregistering $USER"
10226         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10227 }
10228 run_test 160c "verify that changelog log catch the truncate event"
10229
10230 test_161a() {
10231         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10232         test_mkdir -p -c1 $DIR/$tdir
10233         cp /etc/hosts $DIR/$tdir/$tfile
10234         test_mkdir -c1 $DIR/$tdir/foo1
10235         test_mkdir -c1 $DIR/$tdir/foo2
10236         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
10237         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
10238         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
10239         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
10240         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
10241         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10242                 $LFS fid2path $DIR $FID
10243                 err17935 "bad link ea"
10244         fi
10245     # middle
10246     rm $DIR/$tdir/foo2/zachary
10247     # last
10248     rm $DIR/$tdir/foo2/thor
10249     # first
10250     rm $DIR/$tdir/$tfile
10251     # rename
10252     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
10253     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
10254         then
10255         $LFS fid2path $DIR $FID
10256         err17935 "bad link rename"
10257     fi
10258     rm $DIR/$tdir/foo2/maggie
10259
10260         # overflow the EA
10261         local longname=filename_avg_len_is_thirty_two_
10262         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
10263                 error "failed to hardlink many files"
10264         links=$($LFS fid2path $DIR $FID | wc -l)
10265         echo -n "${links}/1000 links in link EA"
10266         [[ $links -gt 60 ]] ||
10267                 err17935 "expected at least 60 links in link EA"
10268         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
10269                 error "failed to unlink many hardlinks"
10270 }
10271 run_test 161a "link ea sanity"
10272
10273 test_161b() {
10274         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10275         [ $MDSCOUNT -lt 2 ] &&
10276                 skip "skipping remote directory test" && return
10277         local MDTIDX=1
10278         local remote_dir=$DIR/$tdir/remote_dir
10279
10280         mkdir -p $DIR/$tdir
10281         $LFS mkdir -i $MDTIDX $remote_dir ||
10282                 error "create remote directory failed"
10283
10284         cp /etc/hosts $remote_dir/$tfile
10285         mkdir -p $remote_dir/foo1
10286         mkdir -p $remote_dir/foo2
10287         ln $remote_dir/$tfile $remote_dir/foo1/sofia
10288         ln $remote_dir/$tfile $remote_dir/foo2/zachary
10289         ln $remote_dir/$tfile $remote_dir/foo1/luna
10290         ln $remote_dir/$tfile $remote_dir/foo2/thor
10291
10292         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
10293                      tr -d ']')
10294         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10295                 $LFS fid2path $DIR $FID
10296                 err17935 "bad link ea"
10297         fi
10298         # middle
10299         rm $remote_dir/foo2/zachary
10300         # last
10301         rm $remote_dir/foo2/thor
10302         # first
10303         rm $remote_dir/$tfile
10304         # rename
10305         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
10306         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
10307         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
10308                 $LFS fid2path $DIR $FID
10309                 err17935 "bad link rename"
10310         fi
10311         rm $remote_dir/foo2/maggie
10312
10313         # overflow the EA
10314         local longname=filename_avg_len_is_thirty_two_
10315         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10316                 error "failed to hardlink many files"
10317         links=$($LFS fid2path $DIR $FID | wc -l)
10318         echo -n "${links}/1000 links in link EA"
10319         [[ ${links} -gt 60 ]] ||
10320                 err17935 "expected at least 60 links in link EA"
10321         unlinkmany $remote_dir/foo2/$longname 1000 ||
10322         error "failed to unlink many hardlinks"
10323 }
10324 run_test 161b "link ea sanity under remote directory"
10325
10326 test_161c() {
10327         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10328         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10329         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10330                 skip "Need MDS version at least 2.1.5" && return
10331
10332         # define CLF_RENAME_LAST 0x0001
10333         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10334         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10335                 changelog_register -n)
10336         rm -rf $DIR/$tdir
10337         mkdir -p $DIR/$tdir
10338         touch $DIR/$tdir/foo_161c
10339         touch $DIR/$tdir/bar_161c
10340         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10341         $LFS changelog $MDT0 | grep RENME
10342         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10343                 cut -f5 -d' ')
10344         $LFS changelog_clear $MDT0 $USER 0
10345         if [ x$flags != "x0x1" ]; then
10346                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10347                         $USER
10348                 error "flag $flags is not 0x1"
10349         fi
10350         echo "rename overwrite a target having nlink = 1," \
10351                 "changelog record has flags of $flags"
10352
10353         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10354         touch $DIR/$tdir/foo_161c
10355         touch $DIR/$tdir/bar_161c
10356         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10357         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10358         $LFS changelog $MDT0 | grep RENME
10359         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10360         $LFS changelog_clear $MDT0 $USER 0
10361         if [ x$flags != "x0x0" ]; then
10362                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10363                         $USER
10364                 error "flag $flags is not 0x0"
10365         fi
10366         echo "rename overwrite a target having nlink > 1," \
10367                 "changelog record has flags of $flags"
10368
10369         # rename doesn't overwrite a target (changelog flag 0x0)
10370         touch $DIR/$tdir/foo_161c
10371         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10372         $LFS changelog $MDT0 | grep RENME
10373         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10374         $LFS changelog_clear $MDT0 $USER 0
10375         if [ x$flags != "x0x0" ]; then
10376                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10377                         $USER
10378                 error "flag $flags is not 0x0"
10379         fi
10380         echo "rename doesn't overwrite a target," \
10381                 "changelog record has flags of $flags"
10382
10383         # define CLF_UNLINK_LAST 0x0001
10384         # unlink a file having nlink = 1 (changelog flag 0x1)
10385         rm -f $DIR/$tdir/foo2_161c
10386         $LFS changelog $MDT0 | grep UNLNK
10387         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10388         $LFS changelog_clear $MDT0 $USER 0
10389         if [ x$flags != "x0x1" ]; then
10390                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10391                         $USER
10392                 error "flag $flags is not 0x1"
10393         fi
10394         echo "unlink a file having nlink = 1," \
10395                 "changelog record has flags of $flags"
10396
10397         # unlink a file having nlink > 1 (changelog flag 0x0)
10398         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10399         rm -f $DIR/$tdir/foobar_161c
10400         $LFS changelog $MDT0 | grep UNLNK
10401         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10402         $LFS changelog_clear $MDT0 $USER 0
10403         if [ x$flags != "x0x0" ]; then
10404                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10405                         $USER
10406                 error "flag $flags is not 0x0"
10407         fi
10408         echo "unlink a file having nlink > 1," \
10409                 "changelog record has flags of $flags"
10410         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10411 }
10412 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10413
10414 check_path() {
10415     local expected=$1
10416     shift
10417     local fid=$2
10418
10419     local path=$(${LFS} fid2path $*)
10420     RC=$?
10421
10422     if [ $RC -ne 0 ]; then
10423         err17935 "path looked up of $expected failed. Error $RC"
10424         return $RC
10425     elif [ "${path}" != "${expected}" ]; then
10426         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10427         return 2
10428     fi
10429     echo "fid $fid resolves to path $path (expected $expected)"
10430 }
10431
10432 test_162() {
10433         # Make changes to filesystem
10434         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10435         test_mkdir -p -c1 $DIR/$tdir/d2
10436         touch $DIR/$tdir/d2/$tfile
10437         touch $DIR/$tdir/d2/x1
10438         touch $DIR/$tdir/d2/x2
10439         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
10440         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
10441         # regular file
10442         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10443         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
10444                 error "check path $tdir/d2/$tfile failed"
10445
10446         # softlink
10447         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10448         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10449         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
10450                 error "check path $tdir/d2/p/q/r/slink failed"
10451
10452         # softlink to wrong file
10453         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10454         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10455         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
10456                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
10457
10458         # hardlink
10459         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10460         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10461         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10462         # fid2path dir/fsname should both work
10463         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
10464                 error "check path $tdir/d2/a/b/c/new_file failed"
10465         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
10466                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
10467
10468         # hardlink count: check that there are 2 links
10469         # Doesnt work with CMD yet: 17935
10470         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10471                 err17935 "expected 2 links"
10472
10473         # hardlink indexing: remove the first link
10474         rm $DIR/$tdir/d2/p/q/r/hlink
10475         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
10476                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
10477
10478         return 0
10479 }
10480 run_test 162 "path lookup sanity"
10481
10482 test_162b() {
10483         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10484         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10485
10486         mkdir $DIR/$tdir
10487         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
10488                                 error "create striped dir failed"
10489
10490         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
10491                                         tail -n 1 | awk '{print $2}')
10492         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
10493
10494         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
10495         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
10496
10497         # regular file
10498         for ((i=0;i<5;i++)); do
10499                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
10500                         error "get fid for f$i failed"
10501                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
10502                         error "check path $tdir/striped_dir/f$i failed"
10503
10504                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
10505                         error "get fid for d$i failed"
10506                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
10507                         error "check path $tdir/striped_dir/d$i failed"
10508         done
10509
10510         return 0
10511 }
10512 run_test 162b "striped directory path lookup sanity"
10513
10514 test_169() {
10515         # do directio so as not to populate the page cache
10516         log "creating a 10 Mb file"
10517         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10518         log "starting reads"
10519         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10520         log "truncating the file"
10521         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10522         log "killing dd"
10523         kill %+ || true # reads might have finished
10524         echo "wait until dd is finished"
10525         wait
10526         log "removing the temporary file"
10527         rm -rf $DIR/$tfile || error "tmp file removal failed"
10528 }
10529 run_test 169 "parallel read and truncate should not deadlock"
10530
10531 test_170() {
10532         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10533         $LCTL clear     # bug 18514
10534         $LCTL debug_daemon start $TMP/${tfile}_log_good
10535         touch $DIR/$tfile
10536         $LCTL debug_daemon stop
10537         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10538                error "sed failed to read log_good"
10539
10540         $LCTL debug_daemon start $TMP/${tfile}_log_good
10541         rm -rf $DIR/$tfile
10542         $LCTL debug_daemon stop
10543
10544         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10545                error "lctl df log_bad failed"
10546
10547         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10548         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10549
10550         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10551         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10552
10553         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10554                 error "bad_line good_line1 good_line2 are empty"
10555
10556         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10557         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10558         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10559
10560         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10561         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10562         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10563
10564         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
10565                 error "bad_line_new good_line_new are empty"
10566
10567         local expected_good=$((good_line1 + good_line2*2))
10568
10569         rm -f $TMP/${tfile}*
10570         # LU-231, short malformed line may not be counted into bad lines
10571         if [ $bad_line -ne $bad_line_new ] &&
10572                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
10573                 error "expected $bad_line bad lines, but got $bad_line_new"
10574                 return 1
10575         fi
10576
10577         if [ $expected_good -ne $good_line_new ]; then
10578                 error "expected $expected_good good lines, but got $good_line_new"
10579                 return 2
10580         fi
10581         true
10582 }
10583 run_test 170 "test lctl df to handle corrupted log ====================="
10584
10585 test_171() { # bug20592
10586         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10587 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
10588         $LCTL set_param fail_loc=0x50e
10589         $LCTL set_param fail_val=3000
10590         multiop_bg_pause $DIR/$tfile O_s || true
10591         local MULTIPID=$!
10592         kill -USR1 $MULTIPID
10593         # cause log dump
10594         sleep 3
10595         wait $MULTIPID
10596         if dmesg | grep "recursive fault"; then
10597                 error "caught a recursive fault"
10598         fi
10599         $LCTL set_param fail_loc=0
10600         true
10601 }
10602 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
10603
10604 # it would be good to share it with obdfilter-survey/iokit-libecho code
10605 setup_obdecho_osc () {
10606         local rc=0
10607         local ost_nid=$1
10608         local obdfilter_name=$2
10609         echo "Creating new osc for $obdfilter_name on $ost_nid"
10610         # make sure we can find loopback nid
10611         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
10612
10613         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
10614                            ${obdfilter_name}_osc_UUID || rc=2; }
10615         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
10616                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
10617         return $rc
10618 }
10619
10620 cleanup_obdecho_osc () {
10621         local obdfilter_name=$1
10622         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
10623         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
10624         return 0
10625 }
10626
10627 obdecho_test() {
10628         local OBD=$1
10629         local node=$2
10630         local pages=${3:-64}
10631         local rc=0
10632         local id
10633
10634         local count=10
10635         local obd_size=$(get_obd_size $node $OBD)
10636         local page_size=$(get_page_size $node)
10637         if [[ -n "$obd_size" ]]; then
10638                 local new_count=$((obd_size / (pages * page_size / 1024)))
10639                 [[ $new_count -ge $count ]] || count=$new_count
10640         fi
10641
10642         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
10643         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
10644                            rc=2; }
10645         if [ $rc -eq 0 ]; then
10646             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
10647             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
10648         fi
10649         echo "New object id is $id"
10650         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
10651                            rc=4; }
10652         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
10653                            "test_brw $count w v $pages $id" || rc=4; }
10654         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
10655                            rc=4; }
10656         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
10657                                         "cleanup" || rc=5; }
10658         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
10659                                         "detach" || rc=6; }
10660         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
10661         return $rc
10662 }
10663
10664 test_180a() {
10665         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10666         remote_ost_nodsh && skip "remote OST with nodsh" && return
10667         local rc=0
10668         local rmmod_local=0
10669
10670         if ! module_loaded obdecho; then
10671             load_module obdecho/obdecho
10672             rmmod_local=1
10673         fi
10674
10675         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
10676         local host=$(lctl get_param -n osc.$osc.import |
10677                              awk '/current_connection:/ {print $2}' )
10678         local target=$(lctl get_param -n osc.$osc.import |
10679                              awk '/target:/ {print $2}' )
10680         target=${target%_UUID}
10681
10682         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
10683         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
10684         [[ -n $target ]] && cleanup_obdecho_osc $target
10685         [ $rmmod_local -eq 1 ] && rmmod obdecho
10686         return $rc
10687 }
10688 run_test 180a "test obdecho on osc"
10689
10690 test_180b() {
10691         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10692         remote_ost_nodsh && skip "remote OST with nodsh" && return
10693         local rc=0
10694         local rmmod_remote=0
10695
10696         do_facet ost1 "lsmod | grep -q obdecho || "                      \
10697                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
10698                       "modprobe obdecho; }" && rmmod_remote=1
10699         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
10700         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
10701         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
10702         return $rc
10703 }
10704 run_test 180b "test obdecho directly on obdfilter"
10705
10706 test_180c() { # LU-2598
10707         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10708         remote_ost_nodsh && skip "remote OST with nodsh" && return
10709         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
10710                 skip "Need MDS version at least 2.4.0" && return
10711
10712         local rc=0
10713         local rmmod_remote=false
10714         local pages=16384 # 64MB bulk I/O RPC size
10715         local target
10716
10717         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
10718                 rmmod_remote=true || error "failed to load module obdecho"
10719
10720         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
10721                 head -n1)
10722         if [ -n "$target" ]; then
10723                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
10724         else
10725                 echo "there is no obdfilter target on ost1"
10726                 rc=2
10727         fi
10728         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
10729         return $rc
10730 }
10731 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
10732
10733 test_181() { # bug 22177
10734         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10735         # create enough files to index the directory
10736         createmany -o $DIR/$tdir/foobar 4000
10737         # print attributes for debug purpose
10738         lsattr -d .
10739         # open dir
10740         multiop_bg_pause $DIR/$tdir D_Sc || return 1
10741         MULTIPID=$!
10742         # remove the files & current working dir
10743         unlinkmany $DIR/$tdir/foobar 4000
10744         rmdir $DIR/$tdir
10745         kill -USR1 $MULTIPID
10746         wait $MULTIPID
10747         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
10748         return 0
10749 }
10750 run_test 181 "Test open-unlinked dir ========================"
10751
10752 test_182() {
10753         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10754         # disable MDC RPC lock wouldn't crash client
10755         local fcount=1000
10756         local tcount=4
10757
10758         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10759 #define OBD_FAIL_MDC_RPCS_SEM           0x804
10760         $LCTL set_param fail_loc=0x804
10761
10762         for (( i=0; i < $tcount; i++ )) ; do
10763                 mkdir $DIR/$tdir/$i
10764                 createmany -o $DIR/$tdir/$i/f- $fcount &
10765         done
10766         wait
10767
10768         for (( i=0; i < $tcount; i++ )) ; do
10769                 unlinkmany $DIR/$tdir/$i/f- $fcount &
10770         done
10771         wait
10772
10773         rm -rf $DIR/$tdir
10774
10775         $LCTL set_param fail_loc=0
10776 }
10777 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
10778
10779 test_183() { # LU-2275
10780         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10781         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
10782                 skip "Need MDS version at least 2.3.56" && return
10783
10784         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10785         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10786         echo aaa > $DIR/$tdir/$tfile
10787
10788 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
10789         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
10790
10791         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
10792         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
10793
10794         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
10795
10796         # Flush negative dentry cache
10797         touch $DIR/$tdir/$tfile
10798
10799         # We are not checking for any leaked references here, they'll
10800         # become evident next time we do cleanup with module unload.
10801         rm -rf $DIR/$tdir
10802 }
10803 run_test 183 "No crash or request leak in case of strange dispositions ========"
10804
10805 # test suite 184 is for LU-2016, LU-2017
10806 test_184a() {
10807         check_swap_layouts_support && return 0
10808
10809         dir0=$DIR/$tdir/$testnum
10810         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
10811         ref1=/etc/passwd
10812         ref2=/etc/group
10813         file1=$dir0/f1
10814         file2=$dir0/f2
10815         $SETSTRIPE -c1 $file1
10816         cp $ref1 $file1
10817         $SETSTRIPE -c2 $file2
10818         cp $ref2 $file2
10819         gen1=$($GETSTRIPE -g $file1)
10820         gen2=$($GETSTRIPE -g $file2)
10821
10822         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
10823         gen=$($GETSTRIPE -g $file1)
10824         [[ $gen1 != $gen ]] ||
10825                 "Layout generation on $file1 does not change"
10826         gen=$($GETSTRIPE -g $file2)
10827         [[ $gen2 != $gen ]] ||
10828                 "Layout generation on $file2 does not change"
10829
10830         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
10831         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
10832 }
10833 run_test 184a "Basic layout swap"
10834
10835 test_184b() {
10836         check_swap_layouts_support && return 0
10837
10838         dir0=$DIR/$tdir/$testnum
10839         mkdir -p $dir0 || error "creating dir $dir0"
10840         file1=$dir0/f1
10841         file2=$dir0/f2
10842         file3=$dir0/f3
10843         dir1=$dir0/d1
10844         dir2=$dir0/d2
10845         mkdir $dir1 $dir2
10846         $SETSTRIPE -c1 $file1
10847         $SETSTRIPE -c2 $file2
10848         $SETSTRIPE -c1 $file3
10849         chown $RUNAS_ID $file3
10850         gen1=$($GETSTRIPE -g $file1)
10851         gen2=$($GETSTRIPE -g $file2)
10852
10853         $LFS swap_layouts $dir1 $dir2 &&
10854                 error "swap of directories layouts should fail"
10855         $LFS swap_layouts $dir1 $file1 &&
10856                 error "swap of directory and file layouts should fail"
10857         $RUNAS $LFS swap_layouts $file1 $file2 &&
10858                 error "swap of file we cannot write should fail"
10859         $LFS swap_layouts $file1 $file3 &&
10860                 error "swap of file with different owner should fail"
10861         /bin/true # to clear error code
10862 }
10863 run_test 184b "Forbidden layout swap (will generate errors)"
10864
10865 test_184c() {
10866         check_swap_layouts_support && return 0
10867
10868         local dir0=$DIR/$tdir/$testnum
10869         mkdir -p $dir0 || error "creating dir $dir0"
10870
10871         local ref1=$dir0/ref1
10872         local ref2=$dir0/ref2
10873         local file1=$dir0/file1
10874         local file2=$dir0/file2
10875         # create a file large enough for the concurent test
10876         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
10877         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
10878         echo "ref file size: ref1($(stat -c %s $ref1))," \
10879              "ref2($(stat -c %s $ref2))"
10880
10881         cp $ref2 $file2
10882         dd if=$ref1 of=$file1 bs=16k &
10883         local DD_PID=$!
10884
10885         # Make sure dd starts to copy file
10886         while [ ! -f $file1 ]; do sleep 0.1; done
10887
10888         $LFS swap_layouts $file1 $file2
10889         local rc=$?
10890         wait $DD_PID
10891         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
10892         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
10893
10894         # how many bytes copied before swapping layout
10895         local copied=$(stat -c %s $file2)
10896         local remaining=$(stat -c %s $ref1)
10897         remaining=$((remaining - copied))
10898         echo "Copied $copied bytes before swapping layout..."
10899
10900         cmp -n $copied $file1 $ref2 | grep differ &&
10901                 error "Content mismatch [0, $copied) of ref2 and file1"
10902         cmp -n $copied $file2 $ref1 ||
10903                 error "Content mismatch [0, $copied) of ref1 and file2"
10904         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
10905                 error "Content mismatch [$copied, EOF) of ref1 and file1"
10906
10907         # clean up
10908         rm -f $ref1 $ref2 $file1 $file2
10909 }
10910 run_test 184c "Concurrent write and layout swap"
10911
10912 test_184d() {
10913         check_swap_layouts_support && return 0
10914         [ -z "$(which getfattr 2>/dev/null)" ] &&
10915                 skip "no getfattr command" && return 0
10916
10917         local file1=$DIR/$tdir/$tfile-1
10918         local file2=$DIR/$tdir/$tfile-2
10919         local file3=$DIR/$tdir/$tfile-3
10920         local lovea1
10921         local lovea2
10922
10923         mkdir -p $DIR/$tdir
10924         touch $file1 || error "create $file1 failed"
10925         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
10926                 error "create $file2 failed"
10927         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
10928                 error "create $file3 failed"
10929         lovea1=$($LFS getstripe $file1 | sed 1d)
10930
10931         $LFS swap_layouts $file2 $file3 ||
10932                 error "swap $file2 $file3 layouts failed"
10933         $LFS swap_layouts $file1 $file2 ||
10934                 error "swap $file1 $file2 layouts failed"
10935
10936         lovea2=$($LFS getstripe $file2 | sed 1d)
10937         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
10938
10939         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
10940         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
10941 }
10942 run_test 184d "allow stripeless layouts swap"
10943
10944
10945 test_185() { # LU-2441
10946         # LU-3553 - no volatile file support in old servers
10947         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
10948                 { skip "Need MDS version at least 2.3.60"; return 0; }
10949
10950         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10951         touch $DIR/$tdir/spoo
10952         local mtime1=$(stat -c "%Y" $DIR/$tdir)
10953         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
10954                 error "cannot create/write a volatile file"
10955         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
10956                 error "FID is still valid after close"
10957
10958         multiop_bg_pause $DIR/$tdir vVw4096_c
10959         local multi_pid=$!
10960
10961         local OLD_IFS=$IFS
10962         IFS=":"
10963         local fidv=($fid)
10964         IFS=$OLD_IFS
10965         # assume that the next FID for this client is sequential, since stdout
10966         # is unfortunately eaten by multiop_bg_pause
10967         local n=$((${fidv[1]} + 1))
10968         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
10969         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
10970                 error "FID is missing before close"
10971         kill -USR1 $multi_pid
10972         # 1 second delay, so if mtime change we will see it
10973         sleep 1
10974         local mtime2=$(stat -c "%Y" $DIR/$tdir)
10975         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
10976 }
10977 run_test 185 "Volatile file support"
10978
10979 test_187a() {
10980         local dir0=$DIR/$tdir/$testnum
10981         mkdir -p $dir0 || error "creating dir $dir0"
10982
10983         local file=$dir0/file1
10984         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
10985         local dv1=$($LFS data_version $file)
10986         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
10987         local dv2=$($LFS data_version $file)
10988         [[ $dv1 != $dv2 ]] ||
10989                 error "data version did not change on write $dv1 == $dv2"
10990
10991         # clean up
10992         rm -f $file1
10993 }
10994 run_test 187a "Test data version change"
10995
10996 test_187b() {
10997         local dir0=$DIR/$tdir/$testnum
10998         mkdir -p $dir0 || error "creating dir $dir0"
10999
11000         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
11001         [[ ${DV[0]} != ${DV[1]} ]] ||
11002                 error "data version did not change on write"\
11003                       " ${DV[0]} == ${DV[1]}"
11004
11005         # clean up
11006         rm -f $file1
11007 }
11008 run_test 187b "Test data version change on volatile file"
11009
11010 test_200() {
11011         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11012         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11013
11014         local POOL=${POOL:-cea1}
11015         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
11016         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
11017         # Pool OST targets
11018         local first_ost=0
11019         local last_ost=$(($OSTCOUNT - 1))
11020         local ost_step=2
11021         local ost_list=$(seq $first_ost $ost_step $last_ost)
11022         local ost_range="$first_ost $last_ost $ost_step"
11023         local test_path=$POOL_ROOT/$POOL_DIR_NAME
11024         local file_dir=$POOL_ROOT/file_tst
11025
11026         local rc=0
11027         while : ; do
11028                 # former test_200a test_200b
11029                 pool_add $POOL                          || { rc=$? ; break; }
11030                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
11031                 # former test_200c test_200d
11032                 mkdir -p $test_path
11033                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
11034                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
11035                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
11036                                                         || { rc=$? ; break; }
11037                 # former test_200e test_200f
11038                 local files=$((OSTCOUNT*3))
11039                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
11040                                                         || { rc=$? ; break; }
11041                 pool_create_files $POOL $file_dir $files "$ost_list" \
11042                                                         || { rc=$? ; break; }
11043                 # former test_200g test_200h
11044                 pool_lfs_df $POOL                       || { rc=$? ; break; }
11045                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
11046
11047                 # former test_201a test_201b test_201c
11048                 pool_remove_first_target $POOL          || { rc=$? ; break; }
11049
11050                 local f=$test_path/$tfile
11051                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
11052                 pool_remove $POOL $f                    || { rc=$? ; break; }
11053                 break
11054         done
11055
11056         cleanup_pools
11057         return $rc
11058 }
11059 run_test 200 "OST pools"
11060
11061 # usage: default_attr <count | size | offset>
11062 default_attr() {
11063         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
11064 }
11065
11066 # usage: check_default_stripe_attr
11067 check_default_stripe_attr() {
11068         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
11069         case $1 in
11070         --stripe-count|--count)
11071                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
11072         --stripe-size|--size)
11073                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
11074         --stripe-index|--index)
11075                 EXPECTED=-1;;
11076         *)
11077                 error "unknown getstripe attr '$1'"
11078         esac
11079
11080         [ $ACTUAL != $EXPECTED ] &&
11081                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
11082 }
11083
11084 test_204a() {
11085         test_mkdir -p $DIR/$tdir
11086         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
11087
11088         check_default_stripe_attr --stripe-count
11089         check_default_stripe_attr --stripe-size
11090         check_default_stripe_attr --stripe-index
11091
11092         return 0
11093 }
11094 run_test 204a "Print default stripe attributes ================="
11095
11096 test_204b() {
11097         test_mkdir -p $DIR/$tdir
11098         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11099
11100         check_default_stripe_attr --stripe-size
11101         check_default_stripe_attr --stripe-index
11102
11103         return 0
11104 }
11105 run_test 204b "Print default stripe size and offset  ==========="
11106
11107 test_204c() {
11108         test_mkdir -p $DIR/$tdir
11109         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11110
11111         check_default_stripe_attr --stripe-count
11112         check_default_stripe_attr --stripe-index
11113
11114         return 0
11115 }
11116 run_test 204c "Print default stripe count and offset ==========="
11117
11118 test_204d() {
11119         test_mkdir -p $DIR/$tdir
11120         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11121
11122         check_default_stripe_attr --stripe-count
11123         check_default_stripe_attr --stripe-size
11124
11125         return 0
11126 }
11127 run_test 204d "Print default stripe count and size ============="
11128
11129 test_204e() {
11130         test_mkdir -p $DIR/$tdir
11131         $SETSTRIPE -d $DIR/$tdir
11132
11133         check_default_stripe_attr --stripe-count --raw
11134         check_default_stripe_attr --stripe-size --raw
11135         check_default_stripe_attr --stripe-index --raw
11136
11137         return 0
11138 }
11139 run_test 204e "Print raw stripe attributes ================="
11140
11141 test_204f() {
11142         test_mkdir -p $DIR/$tdir
11143         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11144
11145         check_default_stripe_attr --stripe-size --raw
11146         check_default_stripe_attr --stripe-index --raw
11147
11148         return 0
11149 }
11150 run_test 204f "Print raw stripe size and offset  ==========="
11151
11152 test_204g() {
11153         test_mkdir -p $DIR/$tdir
11154         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11155
11156         check_default_stripe_attr --stripe-count --raw
11157         check_default_stripe_attr --stripe-index --raw
11158
11159         return 0
11160 }
11161 run_test 204g "Print raw stripe count and offset ==========="
11162
11163 test_204h() {
11164         test_mkdir -p $DIR/$tdir
11165         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11166
11167         check_default_stripe_attr --stripe-count --raw
11168         check_default_stripe_attr --stripe-size --raw
11169
11170         return 0
11171 }
11172 run_test 204h "Print raw stripe count and size ============="
11173
11174 # Figure out which job scheduler is being used, if any,
11175 # or use a fake one
11176 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11177         JOBENV=SLURM_JOB_ID
11178 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11179         JOBENV=LSB_JOBID
11180 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11181         JOBENV=PBS_JOBID
11182 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11183         JOBENV=LOADL_STEP_ID
11184 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11185         JOBENV=JOB_ID
11186 else
11187         JOBENV=FAKE_JOBID
11188 fi
11189
11190 verify_jobstats() {
11191         local cmd=$1
11192         local target=$2
11193
11194         # clear old jobstats
11195         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
11196         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
11197
11198         # use a new JobID for this test, or we might see an old one
11199         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
11200
11201         JOBVAL=${!JOBENV}
11202         log "Test: $cmd"
11203         log "Using JobID environment variable $JOBENV=$JOBVAL"
11204
11205         if [ $JOBENV = "FAKE_JOBID" ]; then
11206                 FAKE_JOBID=$JOBVAL $cmd
11207         else
11208                 $cmd
11209         fi
11210
11211         if [ "$target" = "mdt" -o "$target" = "both" ]; then
11212                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
11213                 do_facet $FACET lctl get_param mdt.*.job_stats |
11214                         grep $JOBVAL || error "No job stats found on MDT $FACET"
11215         fi
11216         if [ "$target" = "ost" -o "$target" = "both" ]; then
11217                 FACET=ost1
11218                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
11219                         grep $JOBVAL || error "No job stats found on OST $FACET"
11220         fi
11221 }
11222
11223 jobstats_set() {
11224         trap 0
11225         NEW_JOBENV=${1:-$OLD_JOBENV}
11226         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11227         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11228 }
11229
11230 test_205() { # Job stats
11231         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11232         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11233         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11234                 skip "Server doesn't support jobstats" && return 0
11235         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11236
11237         local cmd
11238         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11239         if [ $OLD_JOBENV != $JOBENV ]; then
11240                 jobstats_set $JOBENV
11241                 trap jobstats_set EXIT
11242         fi
11243
11244         local user=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11245                      changelog_register -n)
11246         echo "Registered as changelog user $user"
11247
11248         # mkdir
11249         cmd="mkdir $DIR/$tfile"
11250         verify_jobstats "$cmd" "mdt"
11251         # rmdir
11252         cmd="rm -fr $DIR/$tfile"
11253         verify_jobstats "$cmd" "mdt"
11254         # mknod
11255         cmd="mknod $DIR/$tfile c 1 3"
11256         verify_jobstats "$cmd" "mdt"
11257         # unlink
11258         cmd="rm -f $DIR/$tfile"
11259         verify_jobstats "$cmd" "mdt"
11260         # open & close
11261         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11262         verify_jobstats "$cmd" "mdt"
11263         # setattr
11264         cmd="touch $DIR/$tfile"
11265         verify_jobstats "$cmd" "both"
11266         # write
11267         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11268         verify_jobstats "$cmd" "ost"
11269         # read
11270         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11271         verify_jobstats "$cmd" "ost"
11272         # truncate
11273         cmd="$TRUNCATE $DIR/$tfile 0"
11274         verify_jobstats "$cmd" "both"
11275         # rename
11276         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
11277         verify_jobstats "$cmd" "mdt"
11278
11279         # Ensure that jobid are present in changelog (if supported by MDS)
11280         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
11281         then
11282                 $LFS changelog $MDT0 | tail -9
11283                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
11284                 [ $jobids -eq 9 ] ||
11285                         error "Wrong changelog jobid count $jobids != 9"
11286         fi
11287
11288         # cleanup
11289         rm -f $DIR/jobstats_test_rename
11290
11291         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11292 }
11293 run_test 205 "Verify job stats"
11294
11295 # LU-1480, LU-1773 and LU-1657
11296 test_206() {
11297         mkdir -p $DIR/$tdir
11298         $SETSTRIPE -c -1 $DIR/$tdir
11299 #define OBD_FAIL_LOV_INIT 0x1403
11300         $LCTL set_param fail_loc=0xa0001403
11301         $LCTL set_param fail_val=1
11302         touch $DIR/$tdir/$tfile || true
11303 }
11304 run_test 206 "fail lov_init_raid0() doesn't lbug"
11305
11306 test_207a() {
11307         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11308         local fsz=`stat -c %s $DIR/$tfile`
11309         cancel_lru_locks mdc
11310
11311         # do not return layout in getattr intent
11312 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11313         $LCTL set_param fail_loc=0x170
11314         local sz=`stat -c %s $DIR/$tfile`
11315
11316         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11317
11318         rm -rf $DIR/$tfile
11319 }
11320 run_test 207a "can refresh layout at glimpse"
11321
11322 test_207b() {
11323         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11324         local cksum=`md5sum $DIR/$tfile`
11325         local fsz=`stat -c %s $DIR/$tfile`
11326         cancel_lru_locks mdc
11327         cancel_lru_locks osc
11328
11329         # do not return layout in getattr intent
11330 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11331         $LCTL set_param fail_loc=0x171
11332
11333         # it will refresh layout after the file is opened but before read issues
11334         echo checksum is "$cksum"
11335         echo "$cksum" |md5sum -c --quiet || error "file differs"
11336
11337         rm -rf $DIR/$tfile
11338 }
11339 run_test 207b "can refresh layout at open"
11340
11341 test_208() {
11342         # FIXME: in this test suite, only RD lease is used. This is okay
11343         # for now as only exclusive open is supported. After generic lease
11344         # is done, this test suite should be revised. - Jinshan
11345
11346         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11347                 { skip "Need MDS version at least 2.4.52"; return 0; }
11348         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11349
11350         echo "==== test 1: verify get lease work"
11351         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11352
11353         echo "==== test 2: verify lease can be broken by upcoming open"
11354         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11355         local PID=$!
11356         sleep 1
11357
11358         $MULTIOP $DIR/$tfile oO_RDONLY:c
11359         kill -USR1 $PID && wait $PID || error "break lease error"
11360
11361         echo "==== test 3: verify lease can't be granted if an open already exists"
11362         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11363         local PID=$!
11364         sleep 1
11365
11366         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11367         kill -USR1 $PID && wait $PID || error "open file error"
11368
11369         echo "==== test 4: lease can sustain over recovery"
11370         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11371         PID=$!
11372         sleep 1
11373
11374         fail mds1
11375
11376         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11377
11378         echo "==== test 5: lease broken can't be regained by replay"
11379         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11380         PID=$!
11381         sleep 1
11382
11383         # open file to break lease and then recovery
11384         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11385         fail mds1
11386
11387         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11388
11389         rm -f $DIR/$tfile
11390 }
11391 run_test 208 "Exclusive open"
11392
11393 test_209() {
11394         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11395                 skip_env "must have disp_stripe" && return
11396
11397         touch $DIR/$tfile
11398         sync; sleep 5; sync;
11399
11400         echo 3 > /proc/sys/vm/drop_caches
11401         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11402
11403         # open/close 500 times
11404         for i in $(seq 500); do
11405                 cat $DIR/$tfile
11406         done
11407
11408         echo 3 > /proc/sys/vm/drop_caches
11409         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11410
11411         echo "before: $req_before, after: $req_after"
11412         [ $((req_after - req_before)) -ge 300 ] &&
11413                 error "open/close requests are not freed"
11414         return 0
11415 }
11416 run_test 209 "read-only open/close requests should be freed promptly"
11417
11418 test_212() {
11419         size=`date +%s`
11420         size=$((size % 8192 + 1))
11421         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11422         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11423         rm -f $DIR/f212 $DIR/f212.xyz
11424 }
11425 run_test 212 "Sendfile test ============================================"
11426
11427 test_213() {
11428         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11429         cancel_lru_locks osc
11430         lctl set_param fail_loc=0x8000040f
11431         # generate a read lock
11432         cat $DIR/$tfile > /dev/null
11433         # write to the file, it will try to cancel the above read lock.
11434         cat /etc/hosts >> $DIR/$tfile
11435 }
11436 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11437
11438 test_214() { # for bug 20133
11439         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11440         for (( i=0; i < 340; i++ )) ; do
11441                 touch $DIR/$tdir/d214c/a$i
11442         done
11443
11444         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11445         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11446         ls $DIR/d214c || error "ls $DIR/d214c failed"
11447         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11448         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11449 }
11450 run_test 214 "hash-indexed directory test - bug 20133"
11451
11452 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11453 create_lnet_proc_files() {
11454         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
11455         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11456
11457         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11458         rm -f "$TMP/lnet_$1.sys_tmp"
11459 }
11460
11461 # counterpart of create_lnet_proc_files
11462 remove_lnet_proc_files() {
11463         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11464 }
11465
11466 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11467 # 3rd arg as regexp for body
11468 check_lnet_proc_stats() {
11469         local l=$(cat "$TMP/lnet_$1" |wc -l)
11470         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
11471
11472         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
11473 }
11474
11475 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11476 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
11477 # optional and can be regexp for 2nd line (lnet.routes case)
11478 check_lnet_proc_entry() {
11479         local blp=2          # blp stands for 'position of 1st line of body'
11480         [ -z "$5" ] || blp=3 # lnet.routes case
11481
11482         local l=$(cat "$TMP/lnet_$1" |wc -l)
11483         # subtracting one from $blp because the body can be empty
11484         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
11485
11486         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
11487                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
11488
11489         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
11490                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
11491
11492         # bail out if any unexpected line happened
11493         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
11494         [ "$?" != 0 ] || error "$2 misformatted"
11495 }
11496
11497 test_215() { # for bugs 18102, 21079, 21517
11498         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11499         local N='(0|[1-9][0-9]*)'       # non-negative numeric
11500         local P='[1-9][0-9]*'           # positive numeric
11501         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
11502         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
11503         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
11504         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
11505
11506         local L1 # regexp for 1st line
11507         local L2 # regexp for 2nd line (optional)
11508         local BR # regexp for the rest (body)
11509
11510         # lnet.stats should look as 11 space-separated non-negative numerics
11511         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
11512         create_lnet_proc_files "stats"
11513         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
11514         remove_lnet_proc_files "stats"
11515
11516         # lnet.routes should look like this:
11517         # Routing disabled/enabled
11518         # net hops priority state router
11519         # where net is a string like tcp0, hops > 0, priority >= 0,
11520         # state is up/down,
11521         # router is a string like 192.168.1.1@tcp2
11522         L1="^Routing (disabled|enabled)$"
11523         L2="^net +hops +priority +state +router$"
11524         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
11525         create_lnet_proc_files "routes"
11526         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
11527         remove_lnet_proc_files "routes"
11528
11529         # lnet.routers should look like this:
11530         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
11531         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
11532         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
11533         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
11534         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
11535         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
11536         create_lnet_proc_files "routers"
11537         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
11538         remove_lnet_proc_files "routers"
11539
11540         # lnet.peers should look like this:
11541         # nid refs state last max rtr min tx min queue
11542         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
11543         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
11544         # numeric (0 or >0 or <0), queue >= 0.
11545         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
11546         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
11547         create_lnet_proc_files "peers"
11548         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
11549         remove_lnet_proc_files "peers"
11550
11551         # lnet.buffers  should look like this:
11552         # pages count credits min
11553         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
11554         L1="^pages +count +credits +min$"
11555         BR="^ +$N +$N +$I +$I$"
11556         create_lnet_proc_files "buffers"
11557         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
11558         remove_lnet_proc_files "buffers"
11559
11560         # lnet.nis should look like this:
11561         # nid status alive refs peer rtr max tx min
11562         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
11563         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
11564         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
11565         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
11566         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
11567         create_lnet_proc_files "nis"
11568         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
11569         remove_lnet_proc_files "nis"
11570
11571         # can we successfully write to lnet.stats?
11572         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
11573         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
11574 }
11575 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
11576
11577 test_216() { # bug 20317
11578         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11579         remote_ost_nodsh && skip "remote OST with nodsh" && return
11580
11581         local node
11582         local facets=$(get_facets OST)
11583         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11584
11585         save_lustre_params client "osc.*.contention_seconds" > $p
11586         save_lustre_params $facets \
11587                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
11588         save_lustre_params $facets \
11589                 "ldlm.namespaces.filter-*.contended_locks" >> $p
11590         save_lustre_params $facets \
11591                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
11592         clear_osc_stats
11593
11594         # agressive lockless i/o settings
11595         for node in $(osts_nodes); do
11596                 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'
11597         done
11598         lctl set_param -n osc.*.contention_seconds 60
11599
11600         $DIRECTIO write $DIR/$tfile 0 10 4096
11601         $CHECKSTAT -s 40960 $DIR/$tfile
11602
11603         # disable lockless i/o
11604         for node in $(osts_nodes); do
11605                 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'
11606         done
11607         lctl set_param -n osc.*.contention_seconds 0
11608         clear_osc_stats
11609
11610         dd if=/dev/zero of=$DIR/$tfile count=0
11611         $CHECKSTAT -s 0 $DIR/$tfile
11612
11613         restore_lustre_params <$p
11614         rm -f $p
11615         rm $DIR/$tfile
11616 }
11617 run_test 216 "check lockless direct write works and updates file size and kms correctly"
11618
11619 test_217() { # bug 22430
11620         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11621         local node
11622         local nid
11623
11624         for node in $(nodes_list); do
11625                 nid=$(host_nids_address $node $NETTYPE)
11626                 if [[ $nid = *-* ]] ; then
11627                         echo "lctl ping $nid@$NETTYPE"
11628                         lctl ping $nid@$NETTYPE
11629                 else
11630                         echo "skipping $node (no hyphen detected)"
11631                 fi
11632         done
11633 }
11634 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
11635
11636 test_218() {
11637        # do directio so as not to populate the page cache
11638        log "creating a 10 Mb file"
11639        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11640        log "starting reads"
11641        dd if=$DIR/$tfile of=/dev/null bs=4096 &
11642        log "truncating the file"
11643        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11644        log "killing dd"
11645        kill %+ || true # reads might have finished
11646        echo "wait until dd is finished"
11647        wait
11648        log "removing the temporary file"
11649        rm -rf $DIR/$tfile || error "tmp file removal failed"
11650 }
11651 run_test 218 "parallel read and truncate should not deadlock ======================="
11652
11653 test_219() {
11654         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11655         # write one partial page
11656         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
11657         # set no grant so vvp_io_commit_write will do sync write
11658         $LCTL set_param fail_loc=0x411
11659         # write a full page at the end of file
11660         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
11661
11662         $LCTL set_param fail_loc=0
11663         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
11664         $LCTL set_param fail_loc=0x411
11665         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
11666
11667         # LU-4201
11668         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
11669         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
11670 }
11671 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
11672
11673 test_220() { #LU-325
11674         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11675         remote_ost_nodsh && skip "remote OST with nodsh" && return
11676         local OSTIDX=0
11677
11678         test_mkdir -p $DIR/$tdir
11679         local OST=$(lfs osts | grep ${OSTIDX}": " | \
11680                 awk '{print $2}' | sed -e 's/_UUID$//')
11681
11682         # on the mdt's osc
11683         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
11684         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
11685                         osc.$mdtosc_proc1.prealloc_last_id)
11686         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
11687                         osc.$mdtosc_proc1.prealloc_next_id)
11688
11689         $LFS df -i
11690
11691         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
11692         #define OBD_FAIL_OST_ENOINO              0x229
11693         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
11694         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
11695         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
11696
11697         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
11698
11699         MDSOBJS=$((last_id - next_id))
11700         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
11701
11702         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
11703         echo "OST still has $count kbytes free"
11704
11705         echo "create $MDSOBJS files @next_id..."
11706         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
11707
11708         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11709                         osc.$mdtosc_proc1.prealloc_last_id)
11710         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11711                         osc.$mdtosc_proc1.prealloc_next_id)
11712
11713         echo "after creation, last_id=$last_id2, next_id=$next_id2"
11714         $LFS df -i
11715
11716         echo "cleanup..."
11717
11718         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
11719         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
11720
11721         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
11722         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
11723         echo "unlink $MDSOBJS files @$next_id..."
11724         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
11725 }
11726 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
11727
11728 test_221() {
11729         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11730         dd if=`which date` of=$MOUNT/date oflag=sync
11731         chmod +x $MOUNT/date
11732
11733         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
11734         $LCTL set_param fail_loc=0x80001401
11735
11736         $MOUNT/date > /dev/null
11737         rm -f $MOUNT/date
11738 }
11739 run_test 221 "make sure fault and truncate race to not cause OOM"
11740
11741 test_222a () {
11742         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11743        rm -rf $DIR/$tdir
11744        test_mkdir -p $DIR/$tdir
11745        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11746        createmany -o $DIR/$tdir/$tfile 10
11747        cancel_lru_locks mdc
11748        cancel_lru_locks osc
11749        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11750        $LCTL set_param fail_loc=0x31a
11751        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
11752        $LCTL set_param fail_loc=0
11753        rm -r $DIR/$tdir
11754 }
11755 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
11756
11757 test_222b () {
11758         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11759        rm -rf $DIR/$tdir
11760        test_mkdir -p $DIR/$tdir
11761        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11762        createmany -o $DIR/$tdir/$tfile 10
11763        cancel_lru_locks mdc
11764        cancel_lru_locks osc
11765        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11766        $LCTL set_param fail_loc=0x31a
11767        rm -r $DIR/$tdir || "AGL for rmdir failed"
11768        $LCTL set_param fail_loc=0
11769 }
11770 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
11771
11772 test_223 () {
11773         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11774        rm -rf $DIR/$tdir
11775        test_mkdir -p $DIR/$tdir
11776        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11777        createmany -o $DIR/$tdir/$tfile 10
11778        cancel_lru_locks mdc
11779        cancel_lru_locks osc
11780        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
11781        $LCTL set_param fail_loc=0x31b
11782        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
11783        $LCTL set_param fail_loc=0
11784        rm -r $DIR/$tdir
11785 }
11786 run_test 223 "osc reenqueue if without AGL lock granted ======================="
11787
11788 test_224a() { # LU-1039, MRP-303
11789         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11790         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
11791         $LCTL set_param fail_loc=0x508
11792         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
11793         $LCTL set_param fail_loc=0
11794         df $DIR
11795 }
11796 run_test 224a "Don't panic on bulk IO failure"
11797
11798 test_224b() { # LU-1039, MRP-303
11799         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11800         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
11801         cancel_lru_locks osc
11802         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
11803         $LCTL set_param fail_loc=0x515
11804         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
11805         $LCTL set_param fail_loc=0
11806         df $DIR
11807 }
11808 run_test 224b "Don't panic on bulk IO failure"
11809
11810 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
11811 test_225a () {
11812         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11813         if [ -z ${MDSSURVEY} ]; then
11814               skip_env "mds-survey not found" && return
11815         fi
11816
11817         [ $MDSCOUNT -ge 2 ] &&
11818                 skip "skipping now for more than one MDT" && return
11819
11820        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11821             { skip "Need MDS version at least 2.2.51"; return; }
11822
11823        local mds=$(facet_host $SINGLEMDS)
11824        local target=$(do_nodes $mds 'lctl dl' | \
11825                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11826
11827        local cmd1="file_count=1000 thrhi=4"
11828        local cmd2="dir_count=2 layer=mdd stripe_count=0"
11829        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11830        local cmd="$cmd1 $cmd2 $cmd3"
11831
11832        rm -f ${TMP}/mds_survey*
11833        echo + $cmd
11834        eval $cmd || error "mds-survey with zero-stripe failed"
11835        cat ${TMP}/mds_survey*
11836        rm -f ${TMP}/mds_survey*
11837 }
11838 run_test 225a "Metadata survey sanity with zero-stripe"
11839
11840 test_225b () {
11841         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11842
11843         if [ -z ${MDSSURVEY} ]; then
11844               skip_env "mds-survey not found" && return
11845         fi
11846         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11847             { skip "Need MDS version at least 2.2.51"; return; }
11848
11849         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
11850               skip_env "Need to mount OST to test" && return
11851         fi
11852
11853         [ $MDSCOUNT -ge 2 ] &&
11854                 skip "skipping now for more than one MDT" && return
11855        local mds=$(facet_host $SINGLEMDS)
11856        local target=$(do_nodes $mds 'lctl dl' | \
11857                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11858
11859        local cmd1="file_count=1000 thrhi=4"
11860        local cmd2="dir_count=2 layer=mdd stripe_count=1"
11861        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11862        local cmd="$cmd1 $cmd2 $cmd3"
11863
11864        rm -f ${TMP}/mds_survey*
11865        echo + $cmd
11866        eval $cmd || error "mds-survey with stripe_count failed"
11867        cat ${TMP}/mds_survey*
11868        rm -f ${TMP}/mds_survey*
11869 }
11870 run_test 225b "Metadata survey sanity with stripe_count = 1"
11871
11872 mcreate_path2fid () {
11873         local mode=$1
11874         local major=$2
11875         local minor=$3
11876         local name=$4
11877         local desc=$5
11878         local path=$DIR/$tdir/$name
11879         local fid
11880         local rc
11881         local fid_path
11882
11883         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
11884                 error "cannot create $desc"
11885
11886         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
11887         rc=$?
11888         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
11889
11890         fid_path=$($LFS fid2path $MOUNT $fid)
11891         rc=$?
11892         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
11893
11894         [ "$path" == "$fid_path" ] ||
11895                 error "fid2path returned $fid_path, expected $path"
11896
11897         echo "pass with $path and $fid"
11898 }
11899
11900 test_226a () {
11901         rm -rf $DIR/$tdir
11902         mkdir -p $DIR/$tdir
11903
11904         mcreate_path2fid 0010666 0 0 fifo "FIFO"
11905         mcreate_path2fid 0020666 1 3 null "character special file (null)"
11906         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
11907         mcreate_path2fid 0040666 0 0 dir "directory"
11908         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
11909         mcreate_path2fid 0100666 0 0 file "regular file"
11910         mcreate_path2fid 0120666 0 0 link "symbolic link"
11911         mcreate_path2fid 0140666 0 0 sock "socket"
11912 }
11913 run_test 226a "call path2fid and fid2path on files of all type"
11914
11915 test_226b () {
11916         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11917         rm -rf $DIR/$tdir
11918         local MDTIDX=1
11919
11920         mkdir -p $DIR/$tdir
11921         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
11922                 error "create remote directory failed"
11923         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
11924         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
11925                                 "character special file (null)"
11926         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
11927                                 "character special file (no device)"
11928         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
11929         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
11930                                 "block special file (loop)"
11931         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
11932         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
11933         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
11934 }
11935 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
11936
11937 # LU-1299 Executing or running ldd on a truncated executable does not
11938 # cause an out-of-memory condition.
11939 test_227() {
11940         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11941         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
11942         dd if=$(which date) of=$MOUNT/date bs=1k count=1
11943         chmod +x $MOUNT/date
11944
11945         $MOUNT/date > /dev/null
11946         ldd $MOUNT/date > /dev/null
11947         rm -f $MOUNT/date
11948 }
11949 run_test 227 "running truncated executable does not cause OOM"
11950
11951 # LU-1512 try to reuse idle OI blocks
11952 test_228a() {
11953         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11954         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11955         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11956                 skip "non-ldiskfs backend" && return
11957
11958         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11959         local myDIR=$DIR/$tdir
11960
11961         mkdir -p $myDIR
11962         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11963         $LCTL set_param fail_loc=0x80001002
11964         createmany -o $myDIR/t- 10000
11965         $LCTL set_param fail_loc=0
11966         # The guard is current the largest FID holder
11967         touch $myDIR/guard
11968         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11969                     tr -d '[')
11970         local IDX=$(($SEQ % 64))
11971
11972         do_facet $SINGLEMDS sync
11973         # Make sure journal flushed.
11974         sleep 6
11975         local blk1=$(do_facet $SINGLEMDS \
11976                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11977                      grep Blockcount | awk '{print $4}')
11978
11979         # Remove old files, some OI blocks will become idle.
11980         unlinkmany $myDIR/t- 10000
11981         # Create new files, idle OI blocks should be reused.
11982         createmany -o $myDIR/t- 2000
11983         do_facet $SINGLEMDS sync
11984         # Make sure journal flushed.
11985         sleep 6
11986         local blk2=$(do_facet $SINGLEMDS \
11987                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11988                      grep Blockcount | awk '{print $4}')
11989
11990         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11991 }
11992 run_test 228a "try to reuse idle OI blocks"
11993
11994 test_228b() {
11995         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11996         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11997         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11998                 skip "non-ldiskfs backend" && return
11999
12000         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12001         local myDIR=$DIR/$tdir
12002
12003         mkdir -p $myDIR
12004         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12005         $LCTL set_param fail_loc=0x80001002
12006         createmany -o $myDIR/t- 10000
12007         $LCTL set_param fail_loc=0
12008         # The guard is current the largest FID holder
12009         touch $myDIR/guard
12010         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12011                     tr -d '[')
12012         local IDX=$(($SEQ % 64))
12013
12014         do_facet $SINGLEMDS sync
12015         # Make sure journal flushed.
12016         sleep 6
12017         local blk1=$(do_facet $SINGLEMDS \
12018                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12019                      grep Blockcount | awk '{print $4}')
12020
12021         # Remove old files, some OI blocks will become idle.
12022         unlinkmany $myDIR/t- 10000
12023
12024         # stop the MDT
12025         stop $SINGLEMDS || error "Fail to stop MDT."
12026         # remount the MDT
12027         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
12028
12029         df $MOUNT || error "Fail to df."
12030         # Create new files, idle OI blocks should be reused.
12031         createmany -o $myDIR/t- 2000
12032         do_facet $SINGLEMDS sync
12033         # Make sure journal flushed.
12034         sleep 6
12035         local blk2=$(do_facet $SINGLEMDS \
12036                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12037                      grep Blockcount | awk '{print $4}')
12038
12039         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12040 }
12041 run_test 228b "idle OI blocks can be reused after MDT restart"
12042
12043 #LU-1881
12044 test_228c() {
12045         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12046         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12047         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12048                 skip "non-ldiskfs backend" && return
12049
12050         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12051         local myDIR=$DIR/$tdir
12052
12053         mkdir -p $myDIR
12054         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12055         $LCTL set_param fail_loc=0x80001002
12056         # 20000 files can guarantee there are index nodes in the OI file
12057         createmany -o $myDIR/t- 20000
12058         $LCTL set_param fail_loc=0
12059         # The guard is current the largest FID holder
12060         touch $myDIR/guard
12061         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12062                     tr -d '[')
12063         local IDX=$(($SEQ % 64))
12064
12065         do_facet $SINGLEMDS sync
12066         # Make sure journal flushed.
12067         sleep 6
12068         local blk1=$(do_facet $SINGLEMDS \
12069                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12070                      grep Blockcount | awk '{print $4}')
12071
12072         # Remove old files, some OI blocks will become idle.
12073         unlinkmany $myDIR/t- 20000
12074         rm -f $myDIR/guard
12075         # The OI file should become empty now
12076
12077         # Create new files, idle OI blocks should be reused.
12078         createmany -o $myDIR/t- 2000
12079         do_facet $SINGLEMDS sync
12080         # Make sure journal flushed.
12081         sleep 6
12082         local blk2=$(do_facet $SINGLEMDS \
12083                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12084                      grep Blockcount | awk '{print $4}')
12085
12086         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12087 }
12088 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
12089
12090 test_229() { # LU-2482, LU-3448
12091         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
12092                 skip "No HSM support on MDS of $(get_lustre_version)," \
12093                          "need 2.4.53 at least" && return
12094         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12095         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
12096
12097         rm -f $DIR/$tfile
12098
12099         # Create a file with a released layout and stripe count 2.
12100         $MULTIOP $DIR/$tfile H2c ||
12101                 error "failed to create file with released layout"
12102
12103         $GETSTRIPE -v $DIR/$tfile
12104
12105         local pattern=$($GETSTRIPE -L $DIR/$tfile)
12106         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
12107
12108         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
12109         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
12110         stat $DIR/$tfile || error "failed to stat released file"
12111
12112         chown $RUNAS_ID $DIR/$tfile ||
12113                 error "chown $RUNAS_ID $DIR/$tfile failed"
12114
12115         chgrp $RUNAS_ID $DIR/$tfile ||
12116                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12117
12118         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12119         rm $DIR/$tfile || error "failed to remove released file"
12120 }
12121 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12122
12123 test_230a() {
12124         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12125         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12126         local MDTIDX=1
12127
12128         mkdir -p $DIR/$tdir/test_230_local
12129         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12130         [ $mdt_idx -ne 0 ] &&
12131                 error "create local directory on wrong MDT $mdt_idx"
12132
12133         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12134                         error "create remote directory failed"
12135         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12136         [ $mdt_idx -ne $MDTIDX ] &&
12137                 error "create remote directory on wrong MDT $mdt_idx"
12138
12139         createmany -o $DIR/$tdir/test_230/t- 10 ||
12140                 error "create files on remote directory failed"
12141         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12142         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12143         rm -r $DIR/$tdir || error "unlink remote directory failed"
12144 }
12145 run_test 230a "Create remote directory and files under the remote directory"
12146
12147 test_230b() {
12148         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12149         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12150         local MDTIDX=1
12151         local mdt_index
12152         local i
12153         local file
12154         local pid
12155         local stripe_count
12156         local migrate_dir=$DIR/$tdir/migrate_dir
12157         local other_dir=$DIR/$tdir/other_dir
12158
12159         mkdir -p $migrate_dir
12160         mkdir -p $other_dir
12161         for ((i=0; i<10; i++)); do
12162                 mkdir -p $migrate_dir/dir_${i}
12163                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12164                         error "create files under remote dir failed $i"
12165         done
12166
12167         cp /etc/passwd $migrate_dir/$tfile
12168         cp /etc/passwd $other_dir/$tfile
12169         chattr +SAD $migrate_dir
12170         chattr +SAD $migrate_dir/$tfile
12171
12172         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12173         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12174         local old_dir_mode=$(stat -c%f $migrate_dir)
12175         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
12176
12177         mkdir -p $migrate_dir/dir_default_stripe2
12178         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12179         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12180
12181         mkdir -p $other_dir
12182         ln $migrate_dir/$tfile $other_dir/luna
12183         ln $migrate_dir/$tfile $migrate_dir/sofia
12184         ln $other_dir/$tfile $migrate_dir/david
12185         ln -s $migrate_dir/$tfile $other_dir/zachary
12186         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12187         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12188
12189         $LFS mv -v -M $MDTIDX $migrate_dir ||
12190                         error "migrate remote dir error"
12191
12192         echo "migratate to MDT1, then checking.."
12193         for ((i=0; i<10; i++)); do
12194                 for file in $(find $migrate_dir/dir_${i}); do
12195                         mdt_index=$($LFS getstripe -M $file)
12196                         [ $mdt_index == $MDTIDX ] ||
12197                                 error "$file is not on MDT${MDTIDX}"
12198                 done
12199         done
12200
12201         # the multiple link file should still in MDT0
12202         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12203         [ $mdt_index == 0 ] ||
12204                 error "$file is not on MDT${MDTIDX}"
12205
12206         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12207         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12208                 error " expect $old_dir_flag get $new_dir_flag"
12209
12210         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12211         [ "$old_file_flag" = "$new_file_flag" ] ||
12212                 error " expect $old_file_flag get $new_file_flag"
12213
12214         local new_dir_mode=$(stat -c%f $migrate_dir)
12215         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12216                 error "expect mode $old_dir_mode get $new_dir_mode"
12217
12218         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12219         [ "$old_file_mode" = "$new_file_mode" ] ||
12220                 error "expect mode $old_file_mode get $new_file_mode"
12221
12222         diff /etc/passwd $migrate_dir/$tfile ||
12223                 error "$tfile different after migration"
12224
12225         diff /etc/passwd $other_dir/luna ||
12226                 error "luna different after migration"
12227
12228         diff /etc/passwd $migrate_dir/sofia ||
12229                 error "sofia different after migration"
12230
12231         diff /etc/passwd $migrate_dir/david ||
12232                 error "david different after migration"
12233
12234         diff /etc/passwd $other_dir/zachary ||
12235                 error "zachary different after migration"
12236
12237         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12238                 error "${tfile}_ln different after migration"
12239
12240         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12241                 error "${tfile}_ln_other different after migration"
12242
12243         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12244         [ $stripe_count = 2 ] ||
12245                         error "dir strpe_count $d != 2 after migration."
12246
12247         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12248         [ $stripe_count = 2 ] ||
12249                         error "file strpe_count $d != 2 after migration."
12250
12251         #migrate back to MDT0
12252         MDTIDX=0
12253         $LFS mv -v -M $MDTIDX $migrate_dir ||
12254                         error "migrate remote dir error"
12255
12256         echo "migrate back to MDT0, checking.."
12257         for file in $(find $migrate_dir); do
12258                 mdt_index=$($LFS getstripe -M $file)
12259                 [ $mdt_index == $MDTIDX ] ||
12260                         error "$file is not on MDT${MDTIDX}"
12261         done
12262
12263         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12264         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12265                 error " expect $old_dir_flag get $new_dir_flag"
12266
12267         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12268         [ "$old_file_flag" = "$new_file_flag" ] ||
12269                 error " expect $old_file_flag get $new_file_flag"
12270
12271         local new_dir_mode=$(stat -c%f $migrate_dir)
12272         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12273                 error "expect mode $old_dir_mode get $new_dir_mode"
12274
12275         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12276         [ "$old_file_mode" = "$new_file_mode" ] ||
12277                 error "expect mode $old_file_mode get $new_file_mode"
12278
12279         diff /etc/passwd ${migrate_dir}/$tfile ||
12280                 error "$tfile different after migration"
12281
12282         diff /etc/passwd ${other_dir}/luna ||
12283                 error "luna different after migration"
12284
12285         diff /etc/passwd ${migrate_dir}/sofia ||
12286                 error "sofia different after migration"
12287
12288         diff /etc/passwd ${other_dir}/zachary ||
12289                 error "zachary different after migration"
12290
12291         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12292                 error "${tfile}_ln different after migration"
12293
12294         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12295                 error "${tfile}_ln_other different after migration"
12296
12297         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12298         [ $stripe_count = 2 ] ||
12299                 error "dir strpe_count $d != 2 after migration."
12300
12301         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12302         [ $stripe_count = 2 ] ||
12303                 error "file strpe_count $d != 2 after migration."
12304
12305         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12306 }
12307 run_test 230b "migrate directory"
12308
12309 test_230c() {
12310         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12311         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12312         local MDTIDX=1
12313         local mdt_index
12314         local file
12315
12316         #If migrating directory fails in the middle, all entries of
12317         #the directory is still accessiable.
12318         mkdir -p $DIR/$tdir
12319         stat $DIR/$tdir
12320         createmany -o $DIR/$tdir/f 10 ||
12321                 error "create files under ${tdir} failed"
12322
12323         #failed after migrating 5 entries
12324         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12325         do_facet mds1 lctl set_param fail_loc=0x20001801
12326         do_facet mds1 lctl  set_param fail_val=5
12327         local t=`ls $DIR/$tdir | wc -l`
12328         $LFS mv -M $MDTIDX $DIR/$tdir &&
12329                 error "migrate should failed after 5 entries"
12330         local u=`ls $DIR/$tdir | wc -l`
12331         [ "$u" == "$t" ] || error "$u != $t during migration"
12332
12333         for file in $(find $DIR/$tdir); do
12334                 stat $file || error "stat $file failed"
12335         done
12336
12337         do_facet mds1 lctl set_param fail_loc=0
12338         do_facet mds1 lctl set_param fail_val=0
12339
12340         $LFS mv -M $MDTIDX $DIR/$tdir ||
12341                 error "migrate open files should failed with open files"
12342
12343         echo "Finish migration, then checking.."
12344         for file in $(find $DIR/$tdir); do
12345                 mdt_index=$($LFS getstripe -M $file)
12346                 [ $mdt_index == $MDTIDX ] ||
12347                         error "$file is not on MDT${MDTIDX}"
12348         done
12349
12350         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12351 }
12352 run_test 230c "check directory accessiblity if migration is failed"
12353
12354 test_230d() {
12355         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12356         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12357         local MDTIDX=1
12358         local mdt_index
12359         local i
12360         local j
12361
12362         mkdir -p $DIR/$tdir
12363
12364         for ((i=0; i<100; i++)); do
12365                 mkdir -p $DIR/$tdir/dir_${i}
12366                 createmany -o $DIR/$tdir/dir_${i}/f 100 ||
12367                         error "create files under remote dir failed $i"
12368         done
12369
12370         $LFS mv -M $MDTIDX -v $DIR/$tdir || error "migrate remote dir error"
12371
12372         echo "Finish migration, then checking.."
12373         for file in $(find $DIR/$tdir); do
12374                 mdt_index=$($LFS getstripe -M $file)
12375                 [ $mdt_index == $MDTIDX ] ||
12376                         error "$file is not on MDT${MDTIDX}"
12377         done
12378
12379         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12380 }
12381 run_test 230d "check migrate big directory"
12382
12383 test_231a()
12384 {
12385         # For simplicity this test assumes that max_pages_per_rpc
12386         # is the same across all OSCs
12387         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
12388         local bulk_size=$((max_pages * 4096))
12389
12390         mkdir -p $DIR/$tdir
12391
12392         # clear the OSC stats
12393         $LCTL set_param osc.*.stats=0 &>/dev/null
12394
12395         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
12396         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
12397                 oflag=direct &>/dev/null || error "dd failed"
12398
12399         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
12400         if [ x$nrpcs != "x1" ]; then
12401                 error "found $nrpc ost_write RPCs, not 1 as expected"
12402         fi
12403
12404         # Drop the OSC cache, otherwise we will read from it
12405         cancel_lru_locks osc
12406
12407         # clear the OSC stats
12408         $LCTL set_param osc.*.stats=0 &>/dev/null
12409
12410         # Client reads $bulk_size.
12411         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
12412                 iflag=direct &>/dev/null || error "dd failed"
12413
12414         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
12415         if [ x$nrpcs != "x1" ]; then
12416                 error "found $nrpc ost_read RPCs, not 1 as expected"
12417         fi
12418 }
12419 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
12420
12421 test_231b() {
12422         mkdir -p $DIR/$tdir
12423         local i
12424         for i in {0..1023}; do
12425                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
12426                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
12427                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
12428         done
12429         sync
12430 }
12431 run_test 231b "must not assert on fully utilized OST request buffer"
12432
12433 test_232() {
12434         mkdir -p $DIR/$tdir
12435         #define OBD_FAIL_LDLM_OST_LVB            0x31c
12436         $LCTL set_param fail_loc=0x31c
12437
12438         # ignore dd failure
12439         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
12440
12441         $LCTL set_param fail_loc=0
12442         umount_client $MOUNT || error "umount failed"
12443         mount_client $MOUNT || error "mount failed"
12444 }
12445 run_test 232 "failed lock should not block umount"
12446
12447 test_233a() {
12448         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
12449         { skip "Need MDS version at least 2.3.64"; return; }
12450
12451         local fid=$($LFS path2fid $MOUNT)
12452         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12453                 error "cannot access $MOUNT using its FID '$fid'"
12454 }
12455 run_test 233a "checking that OBF of the FS root succeeds"
12456
12457 test_233b() {
12458         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
12459         { skip "Need MDS version at least 2.5.90"; return; }
12460
12461         local fid=$($LFS path2fid $MOUNT/.lustre)
12462         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12463                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
12464
12465         fid=$($LFS path2fid $MOUNT/.lustre/fid)
12466         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12467                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
12468 }
12469 run_test 233b "checking that OBF of the FS .lustre succeeds"
12470
12471 test_234() {
12472         local p="$TMP/sanityN-$TESTNAME.parameters"
12473         save_lustre_params client "llite.*.xattr_cache" > $p
12474         lctl set_param llite.*.xattr_cache 1 ||
12475                 { skip "xattr cache is not supported"; return 0; }
12476
12477         mkdir -p $DIR/$tdir || error "mkdir failed"
12478         touch $DIR/$tdir/$tfile || error "touch failed"
12479         # OBD_FAIL_LLITE_XATTR_ENOMEM
12480         $LCTL set_param fail_loc=0x1405
12481         # output of the form: attr 2 4 44 3 fc13 x86_64
12482         V=($(IFS=".-" rpm -q attr))
12483         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
12484               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
12485                 # attr pre-2.4.44-7 had a bug with rc
12486                 # LU-3703 - SLES 11 and FC13 clients have older attr
12487                 getfattr -n user.attr $DIR/$tdir/$tfile &&
12488                         error "getfattr should have failed with ENOMEM"
12489         else
12490                 skip "LU-3703: attr version $(getfattr --version) too old"
12491         fi
12492         $LCTL set_param fail_loc=0x0
12493         rm -rf $DIR/$tdir
12494
12495         restore_lustre_params < $p
12496         rm -f $p
12497 }
12498 run_test 234 "xattr cache should not crash on ENOMEM"
12499
12500 test_235() {
12501         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
12502                 skip "Need MDS version at least 2.4.52" && return
12503         flock_deadlock $DIR/$tfile
12504         local RC=$?
12505         case $RC in
12506                 0)
12507                 ;;
12508                 124) error "process hangs on a deadlock"
12509                 ;;
12510                 *) error "error executing flock_deadlock $DIR/$tfile"
12511                 ;;
12512         esac
12513 }
12514 run_test 235 "LU-1715: flock deadlock detection does not work properly"
12515
12516 #LU-2935
12517 test_236() {
12518         check_swap_layouts_support && return 0
12519         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
12520
12521         local ref1=/etc/passwd
12522         local ref2=/etc/group
12523         local file1=$DIR/$tdir/f1
12524         local file2=$DIR/$tdir/f2
12525
12526         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
12527         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
12528         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
12529         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
12530         local fd=$(free_fd)
12531         local cmd="exec $fd<>$file2"
12532         eval $cmd
12533         rm $file2
12534         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
12535                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
12536         cmd="exec $fd>&-"
12537         eval $cmd
12538         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12539
12540         #cleanup
12541         rm -rf $DIR/$tdir
12542 }
12543 run_test 236 "Layout swap on open unlinked file"
12544
12545 # test to verify file handle related system calls
12546 # (name_to_handle_at/open_by_handle_at)
12547 # The new system calls are supported in glibc >= 2.14.
12548
12549 test_237() {
12550         echo "Test file_handle syscalls" > $DIR/$tfile ||
12551                 error "write failed"
12552         check_fhandle_syscalls $DIR/$tfile ||
12553                 error "check_fhandle_syscalls failed"
12554 }
12555 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
12556
12557 # LU-4659 linkea consistency
12558 test_238() {
12559         local server_version=$(lustre_version_code $SINGLEMDS)
12560
12561         [[ $server_version -gt $(version_code 2.5.57) ]] ||
12562                 [[ $server_version -gt $(version_code 2.5.1) &&
12563                    $server_version -lt $(version_code 2.5.50) ]] ||
12564                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
12565
12566         touch $DIR/$tfile
12567         ln $DIR/$tfile $DIR/$tfile.lnk
12568         touch $DIR/$tfile.new
12569         mv $DIR/$tfile.new $DIR/$tfile
12570         local fid1=$(lfs path2fid $DIR/$tfile)
12571         local fid2=$(lfs path2fid $DIR/$tfile.lnk)
12572         local path1=$(lfs fid2path $FSNAME $fid1)
12573         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
12574         local path2=$(lfs fid2path $FSNAME $fid2)
12575         [ $tfile.lnk == $path2 ] ||
12576                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
12577         rm -f $DIR/$tfile*
12578 }
12579 run_test 238 "Verify linkea consistency"
12580
12581 test_239() {
12582         local list=$(comma_list $(mdts_nodes))
12583
12584         mkdir -p $DIR/$tdir
12585         createmany -o $DIR/$tdir/f- 5000
12586         unlinkmany $DIR/$tdir/f- 5000
12587         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
12588         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
12589                         osc.*MDT*.sync_in_flight" | calc_sum)
12590         [ "$changes" -eq 0 ] || error "$changes not synced"
12591 }
12592 run_test 239 "osp_sync test"
12593
12594 test_240() {
12595         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12596
12597         mkdir -p $DIR/$tdir
12598
12599         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
12600                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
12601         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
12602                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
12603
12604         umount_client $MOUNT || error "umount failed"
12605         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
12606         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
12607         mount_client $MOUNT || error "failed to mount client"
12608
12609         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
12610         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
12611 }
12612 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
12613
12614 test_241_bio() {
12615         for LOOP in $(seq $1); do
12616                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
12617                 cancel_lru_locks osc
12618         done
12619 }
12620
12621 test_241_dio() {
12622         for LOOP in $(seq $1); do
12623                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
12624                                                 iflag=direct 2>/dev/null
12625         done
12626 }
12627
12628 test_241() {
12629         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
12630         ls -la $DIR/$tfile
12631         cancel_lru_locks osc
12632         test_241_bio 1000 &
12633         PID=$!
12634         test_241_dio 1000
12635         wait $PID
12636 }
12637 run_test 241 "bio vs dio"
12638
12639 cleanup_test_300() {
12640         trap 0
12641         umask $SAVE_UMASK
12642 }
12643 test_striped_dir() {
12644         local mdt_index=$1
12645         local stripe_count
12646         local stripe_index
12647
12648         mkdir -p $DIR/$tdir
12649
12650         SAVE_UMASK=$(umask)
12651         trap cleanup_test_300 RETURN EXIT
12652
12653         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
12654                                                 $DIR/$tdir/striped_dir ||
12655                 error "set striped dir error"
12656
12657         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
12658         [ "$mode" = "755" ] || error "expect 755 got $mode"
12659
12660         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
12661         if [ "$stripe_count" != "2" ]; then
12662                 error "stripe_count is $stripe_count, expect 2"
12663         fi
12664
12665         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
12666         if [ "$stripe_index" != "$mdt_index" ]; then
12667                 error "stripe_index is $stripe_index, expect $mdt_index"
12668         fi
12669
12670         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12671                 error "nlink error after create striped dir"
12672
12673         mkdir $DIR/$tdir/striped_dir/a
12674         mkdir $DIR/$tdir/striped_dir/b
12675
12676         stat $DIR/$tdir/striped_dir/a ||
12677                 error "create dir under striped dir failed"
12678         stat $DIR/$tdir/striped_dir/b ||
12679                 error "create dir under striped dir failed"
12680
12681         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
12682                 error "nlink error after mkdir"
12683
12684         rmdir $DIR/$tdir/striped_dir/a
12685         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
12686                 error "nlink error after rmdir"
12687
12688         rmdir $DIR/$tdir/striped_dir/b
12689         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12690                 error "nlink error after rmdir"
12691
12692         rmdir $DIR/$tdir/striped_dir ||
12693                 error "rmdir striped dir error"
12694
12695         cleanup_test_300
12696
12697         true
12698 }
12699
12700 test_300a() {
12701         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12702         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12703
12704         test_striped_dir 0 || error "failed on striped dir on MDT0"
12705         test_striped_dir 1 || error "failed on striped dir on MDT0"
12706 }
12707 run_test 300a "basic striped dir sanity test"
12708
12709 test_300b() {
12710         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12711         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12712         local i
12713         local mtime1
12714         local mtime2
12715         local mtime3
12716
12717         test_mkdir $DIR/$tdir || error "mkdir fail"
12718         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12719                 error "set striped dir error"
12720         for ((i=0; i<10; i++)); do
12721                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
12722                 sleep 1
12723                 touch $DIR/$tdir/striped_dir/file_$i ||
12724                                         error "touch error $i"
12725                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
12726                 [ $mtime1 -eq $mtime2 ] &&
12727                         error "mtime not change after create"
12728                 sleep 1
12729                 rm -f $DIR/$tdir/striped_dir/file_$i ||
12730                                         error "unlink error $i"
12731                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
12732                 [ $mtime2 -eq $mtime3 ] &&
12733                         error "mtime did not change after unlink"
12734         done
12735         true
12736 }
12737 run_test 300b "check ctime/mtime for striped dir"
12738
12739 test_300c() {
12740         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12741         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12742         local file_count
12743
12744         mkdir -p $DIR/$tdir
12745         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
12746                 error "set striped dir error"
12747
12748         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
12749                 error "chown striped dir failed"
12750
12751         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
12752                 error "create 5k files failed"
12753
12754         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
12755
12756         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
12757
12758         rm -rf $DIR/$tdir
12759 }
12760 run_test 300c "chown && check ls under striped directory"
12761
12762 test_300d() {
12763         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12764         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12765         local stripe_count
12766         local file
12767
12768         mkdir -p $DIR/$tdir
12769         $SETSTRIPE -c 2 $DIR/$tdir
12770
12771         #local striped directory
12772         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12773                 error "set striped dir error"
12774         createmany -o $DIR/$tdir/striped_dir/f 10 ||
12775                 error "create 10 files failed"
12776
12777         #remote striped directory
12778         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
12779                 error "set striped dir error"
12780         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
12781                 error "create 10 files failed"
12782
12783         for file in $(find $DIR/$tdir); do
12784                 stripe_count=$($GETSTRIPE -c $file)
12785                 [ $stripe_count -eq 2 ] ||
12786                         error "wrong stripe $stripe_count for $file"
12787         done
12788
12789         rm -rf $DIR/$tdir
12790 }
12791 run_test 300d "check default stripe under striped directory"
12792
12793 test_300e() {
12794         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12795         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12796         local stripe_count
12797         local file
12798
12799         mkdir -p $DIR/$tdir
12800
12801         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12802                 error "set striped dir error"
12803
12804         touch $DIR/$tdir/striped_dir/a
12805         touch $DIR/$tdir/striped_dir/b
12806         touch $DIR/$tdir/striped_dir/c
12807
12808         mkdir $DIR/$tdir/striped_dir/dir_a
12809         mkdir $DIR/$tdir/striped_dir/dir_b
12810         mkdir $DIR/$tdir/striped_dir/dir_c
12811
12812         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
12813                 error "set striped dir under striped dir error"
12814
12815         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
12816                 error "set striped dir under striped dir error"
12817
12818         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
12819                 error "set striped dir under striped dir error"
12820
12821         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/b &&
12822                 error "rename file under striped dir should fail"
12823
12824         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b &&
12825                 error "rename dir under striped dir should fail"
12826
12827         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b &&
12828                 error "rename dir under different stripes should fail"
12829
12830         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
12831                 error "rename file under striped dir should succeed"
12832
12833         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_c ||
12834                 error "rename dir under striped dir should succeed"
12835
12836         rm -rf $DIR/$tdir
12837 }
12838 run_test 300e "check rename under striped directory"
12839
12840 test_300f() {
12841         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12842         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12843         local stripe_count
12844         local file
12845
12846         rm -rf $DIR/$tdir
12847         mkdir -p $DIR/$tdir
12848
12849         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12850                 error "set striped dir error"
12851
12852         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
12853                 error "set striped dir error"
12854
12855         touch $DIR/$tdir/striped_dir/a
12856         mkdir $DIR/$tdir/striped_dir/dir_a
12857         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
12858                 error "create striped dir under striped dir fails"
12859
12860         touch $DIR/$tdir/striped_dir1/b
12861         mkdir $DIR/$tdir/striped_dir1/dir_b
12862         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
12863                 error "create striped dir under striped dir fails"
12864
12865         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/b &&
12866                 error "rename file under different striped dir should fail"
12867
12868         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b &&
12869                 error "rename dir under different striped dir should fail"
12870
12871         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b &&
12872                 error "rename striped dir under diff striped dir should fail"
12873
12874         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
12875                 error "rename file under diff striped dirs fails"
12876
12877         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_a ||
12878                 error "rename dir under diff striped dirs fails"
12879
12880         rm -rf $DIR/$tdir
12881 }
12882 run_test 300f "check rename cross striped directory"
12883
12884 test_300g() {
12885         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12886         local stripe_count
12887         local dir
12888
12889         mkdir $DIR/$tdir
12890         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
12891                                         $DIR/$tdir/striped_dir ||
12892                 error "set striped dir error"
12893
12894         $LFS setdirstripe -D -c $MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
12895                 error "set default stripe on striped dir error"
12896
12897         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/striped_dir)
12898         [ $stripe_count -eq $MDSCOUNT ] ||
12899                 error "default stripe wrong expect $MDSCOUNT get $stripe_count"
12900
12901         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12902
12903         for dir in $(find $DIR/$tdir/striped_dir/*); do
12904                 stripe_count=$($LFS getdirstripe -c $dir)
12905                 [ $stripe_count -eq $MDSCOUNT ] ||
12906                         error "expect $MDSCOUNT get $stripe_count for $dir"
12907         done
12908
12909         rmdir $DIR/$tdir/striped_dir/* || error "rmdir1 failed"
12910         #change default stripe count to 2
12911         $LFS setdirstripe -D -c 2 -t all_char $DIR/$tdir/striped_dir ||
12912                 error "set default stripe on striped dir error"
12913
12914         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12915
12916         rmdir $DIR/$tdir/striped_dir/* || error "rmdir2 failed"
12917
12918         #change default stripe count to 1
12919         $LFS setdirstripe -D -c 1 -t all_char $DIR/$tdir/striped_dir ||
12920                 error "set default stripe on striped dir error"
12921
12922         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12923         for dir in $(find $DIR/$tdir/striped_dir/*); do
12924                 stripe_count=$($LFS getdirstripe -c $dir)
12925                 [ $stripe_count -eq 1 ] ||
12926                         error "expect 1 get $stripe_count for $dir"
12927         done
12928         rmdir $DIR/$tdir/striped_dir/* || error "rmdir3 failed"
12929 }
12930 run_test 300g "check default striped directory for striped directory"
12931
12932 test_300h() {
12933         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12934         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12935         local stripe_count
12936         local file
12937
12938         mkdir $DIR/$tdir
12939
12940         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
12941                 error "set striped dir error"
12942
12943         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
12944                 error "create files under striped dir failed"
12945
12946         # unfortunately, we need to umount to clear dir layout cache for now
12947         # once we fully implement dir layout, we can drop this
12948         umount_client $MOUNT || error "umount failed"
12949         mount_client $MOUNT || error "mount failed"
12950
12951         #set the stripe to be unknown hash type
12952         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
12953         $LCTL set_param fail_loc=0x1901
12954         for ((i = 0; i < 10; i++)); do
12955                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
12956                         error "stat f-$i failed"
12957                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
12958         done
12959
12960         touch $DIR/$tdir/striped_dir/f0 &&
12961                 error "create under striped dir with unknown hash should fail"
12962
12963         $LCTL set_param fail_loc=0
12964
12965         umount_client $MOUNT || error "umount failed"
12966         mount_client $MOUNT || error "mount failed"
12967
12968         return 0
12969 }
12970 run_test 300h "client handle unknown hash type striped directory"
12971
12972 test_400a() { # LU-1606, was conf-sanity test_74
12973         local extra_flags=''
12974         local out=$TMP/$tfile
12975         local prefix=/usr/include/lustre
12976         local prog
12977
12978         if ! which $CC > /dev/null 2>&1; then
12979                 skip_env "$CC is not installed"
12980                 return 0
12981         fi
12982
12983         if ! [[ -d $prefix ]]; then
12984                 # Assume we're running in tree and fixup the include path.
12985                 extra_flags+=" -I$LUSTRE/../libcfs/include"
12986                 extra_flags+=" -I$LUSTRE/include"
12987                 extra_flags+=" -L$LUSTRE/utils"
12988         fi
12989
12990         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
12991                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
12992                         error "client api broken"
12993         done
12994 }
12995 run_test 400a "Lustre client api program can compile and link"
12996
12997 test_400b() { # LU-1606, LU-5011
12998         local header
12999         local out=$TMP/$tfile
13000         local prefix=/usr/include/lustre
13001
13002         # We use a hard coded prefix so that this test will not fail
13003         # when run in tree. There are headers in lustre/include/lustre/
13004         # that are not packaged (like lustre_idl.h) and have more
13005         # complicated include dependencies (like config.h and lnet/types.h).
13006         # Since this test about correct packaging we just skip them when
13007         # they don't exist (see below) rather than try to fixup cppflags.
13008
13009         if ! which $CC > /dev/null 2>&1; then
13010                 skip_env "$CC is not installed"
13011                 return 0
13012         fi
13013
13014         for header in $prefix/*.h; do
13015                 if ! [[ -f "$header" ]]; then
13016                         continue
13017                 fi
13018
13019                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
13020                         continue # liblustreapi.h is deprecated.
13021                 fi
13022
13023                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
13024                         error "cannot compile '$header'"
13025         done
13026 }
13027 run_test 400b "packaged headers can be compiled"
13028
13029 #
13030 # tests that do cleanup/setup should be run at the end
13031 #
13032
13033 test_900() {
13034         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13035         local ls
13036         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
13037         $LCTL set_param fail_loc=0x903
13038
13039         cancel_lru_locks MGC
13040
13041         FAIL_ON_ERROR=true cleanup
13042         FAIL_ON_ERROR=true setup
13043 }
13044 run_test 900 "umount should not race with any mgc requeue thread"
13045
13046 complete $SECONDS
13047 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
13048 check_and_cleanup_lustre
13049 if [ "$I_MOUNTED" != "yes" ]; then
13050         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
13051 fi
13052 exit_status