Whamcloud - gitweb
LU-4819 tests: Lustre Sanity test_101b hangs for large OSTCOUNTs
[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
20 SRCDIR=$(cd $(dirname $0); echo $PWD)
21 export PATH=$PATH:/sbin
22
23 TMP=${TMP:-/tmp}
24
25 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
26 CREATETEST=${CREATETEST:-createtest}
27 LFS=${LFS:-lfs}
28 LFIND=${LFIND:-"$LFS find"}
29 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
30 LCTL=${LCTL:-lctl}
31 MCREATE=${MCREATE:-mcreate}
32 OPENFILE=${OPENFILE:-openfile}
33 OPENUNLINK=${OPENUNLINK:-openunlink}
34 export MULTIOP=${MULTIOP:-multiop}
35 READS=${READS:-"reads"}
36 MUNLINK=${MUNLINK:-munlink}
37 SOCKETSERVER=${SOCKETSERVER:-socketserver}
38 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
39 MEMHOG=${MEMHOG:-memhog}
40 DIRECTIO=${DIRECTIO:-directio}
41 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
42 UMOUNT=${UMOUNT:-"umount -d"}
43 STRIPES_PER_OBJ=-1
44 CHECK_GRANT=${CHECK_GRANT:-"yes"}
45 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
46 export PARALLEL=${PARALLEL:-"no"}
47
48 export NAME=${NAME:-local}
49
50 SAVE_PWD=$PWD
51
52 CLEANUP=${CLEANUP:-:}
53 SETUP=${SETUP:-:}
54 TRACE=${TRACE:-""}
55 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
56 . $LUSTRE/tests/test-framework.sh
57 init_test_env $@
58 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
59 init_logging
60
61 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 27m 64b 68 71 77f 78 115 124b 230d"
62
63 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
64 # bug number for skipped test:        LU-1593 LU-2610 LU-2833 LU-1957 LU-2805
65         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 34h     40      48a     180     184c"
66
67 FAIL_ON_ERROR=false
68
69 cleanup() {
70         echo -n "cln.."
71         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
72         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
73 }
74 setup() {
75         echo -n "mnt.."
76         load_modules
77         setupall || exit 10
78         echo "done"
79 }
80
81 check_kernel_version() {
82         WANT_VER=$1
83         GOT_VER=$(lctl get_param -n version | awk '/kernel:/ {print $2}')
84         case $GOT_VER in
85         patchless|patchless_client) return 0;;
86         *) [ $GOT_VER -ge $WANT_VER ] && return 0 ;;
87         esac
88         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
89         return 1
90 }
91
92 check_swap_layouts_support()
93 {
94         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
95                 { skip "Does not support layout lock."; return 0; }
96         return 1
97 }
98
99 if [ "$ONLY" == "cleanup" ]; then
100        sh llmountcleanup.sh
101        exit 0
102 fi
103
104 check_and_setup_lustre
105
106 DIR=${DIR:-$MOUNT}
107 assert_DIR
108
109 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
110         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
111 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
112 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
113 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
114 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
115 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
116 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
117
118 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
119 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
120 rm -rf $DIR/[Rdfs][0-9]*
121
122 # $RUNAS_ID may get set incorrectly somewhere else
123 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
124
125 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
126
127 build_test_filter
128
129 if [ "${ONLY}" = "MOUNT" ] ; then
130         echo "Lustre is up, please go on"
131         exit
132 fi
133
134 echo "preparing for tests involving mounts"
135 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
136 touch $EXT2_DEV
137 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
138 echo # add a newline after mke2fs.
139
140 umask 077
141
142 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
143 lctl set_param debug=-1 2> /dev/null || true
144 test_0a() {
145         touch $DIR/$tfile
146         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
147         rm $DIR/$tfile
148         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
149 }
150 run_test 0a "touch; rm ====================="
151
152 test_0b() {
153         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
154         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
155 }
156 run_test 0b "chmod 0755 $DIR ============================="
157
158 test_0c() {
159         $LCTL get_param mdc.*.import | grep "state: FULL" ||
160                 error "import not FULL"
161         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
162                 error "bad target"
163 }
164 run_test 0c "check import proc ============================="
165
166 test_1() {
167         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
168         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
169         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
170         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
171         rmdir $DIR/$tdir/d2
172         rmdir $DIR/$tdir
173         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
174 }
175 run_test 1 "mkdir; remkdir; rmdir =============================="
176
177 test_2() {
178         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
179         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
180         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
181         rm -r $DIR/$tdir
182         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
183 }
184 run_test 2 "mkdir; touch; rmdir; check file ===================="
185
186 test_3() {
187         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
188         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
189         touch $DIR/$tdir/$tfile
190         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
191         rm -r $DIR/$tdir
192         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
193 }
194 run_test 3 "mkdir; touch; rmdir; check dir ====================="
195
196 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
197 test_4() {
198         local MDTIDX=1
199         local remote_dir=remote_dir
200
201         [ $MDSCOUNT -ge 2 ] && skip "skip now for LU-4690" && return #LU-4690
202         test_mkdir $DIR/$remote_dir ||
203                 error "Create remote directory failed"
204
205         touch $DIR/$remote_dir/$tfile ||
206                 error "Create file under remote directory failed"
207
208         rmdir $DIR/$remote_dir &&
209                 error "Expect error removing in-use dir $DIR/$remote_dir"
210
211         test -d $DIR/$remote_dir || error "Remote directory disappeared"
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/d17f
434         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/d17f/111
435         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/d17f/222
436         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/d17f/333
437         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/d17f/444
438         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/d17f/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/d17f/666
440         ls -l  $DIR/d17f
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 && TESTS="59 60 61 4062 4063"
472
473         for i in $TESTS; do
474                 local SYMNAME=$(str_repeat 'x' $i)
475                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
476                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
477         done
478 }
479 run_test 17g "symlinks: really long symlink name and inode boundaries"
480
481 test_17h() { #bug 17378
482         remote_mds_nodsh && skip "remote MDS with nodsh" && return
483         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
484         local mdt_idx
485         test_mkdir -p $DIR/$tdir
486         if [ $MDSCOUNT -gt 1 ]; then
487                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
488         else
489                 mdt_idx=0
490         fi
491         $SETSTRIPE -c -1 $DIR/$tdir
492 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
493         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
494         touch $DIR/$tdir/$tfile || true
495 }
496 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
497
498 test_17i() { #bug 20018
499         remote_mds_nodsh && skip "remote MDS with nodsh" && return
500         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
501         test_mkdir -p $DIR/$tdir
502         local foo=$DIR/$tdir/$tfile
503         local mdt_idx
504         if [ $MDSCOUNT -gt 1 ]; then
505                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
506         else
507                 mdt_idx=0
508         fi
509         ln -s $foo $foo || error "create symlink failed"
510 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
511         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
512         ls -l $foo && error "error not detected"
513         return 0
514 }
515 run_test 17i "don't panic on short symlink"
516
517 test_17k() { #bug 22301
518         rsync --help | grep -q xattr ||
519                 skip_env "$(rsync --version | head -n1) does not support xattrs"
520         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
521         test_mkdir -p $DIR/$tdir
522         test_mkdir -p $DIR/$tdir.new
523         touch $DIR/$tdir/$tfile
524         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
525         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
526                 error "rsync failed with xattrs enabled"
527 }
528 run_test 17k "symlinks: rsync with xattrs enabled ========================="
529
530 test_17l() { # LU-279
531         mkdir -p $DIR/$tdir
532         touch $DIR/$tdir/$tfile
533         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
534         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
535                 # -h to not follow symlinks. -m '' to list all the xattrs.
536                 # grep to remove first line: '# file: $path'.
537                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
538                 do
539                         lgetxattr_size_check $path $xattr ||
540                                 error "lgetxattr_size_check $path $xattr failed"
541                 done
542         done
543 }
544 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
545
546 # LU-1540
547 test_17m() {
548         local short_sym="0123456789"
549         local WDIR=$DIR/${tdir}m
550         local mds_index
551         local devname
552         local cmd
553         local i
554         local rc=0
555
556         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
557         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
558                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
559
560         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
561                 skip "only for ldiskfs MDT" && return 0
562
563         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
564
565         mkdir -p $WDIR
566         long_sym=$short_sym
567         # create a long symlink file
568         for ((i = 0; i < 4; ++i)); do
569                 long_sym=${long_sym}${long_sym}
570         done
571
572         echo "create 512 short and long symlink files under $WDIR"
573         for ((i = 0; i < 256; ++i)); do
574                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
575                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
576         done
577
578         echo "erase them"
579         rm -f $WDIR/*
580         sync
581         wait_delete_completed
582
583         echo "recreate the 512 symlink files with a shorter string"
584         for ((i = 0; i < 512; ++i)); do
585                 # rewrite the symlink file with a shorter string
586                 ln -sf ${long_sym} $WDIR/long-$i
587                 ln -sf ${short_sym} $WDIR/short-$i
588         done
589
590         mds_index=$($LFS getstripe -M $WDIR)
591         mds_index=$((mds_index+1))
592         devname=$(mdsdevname $mds_index)
593         cmd="$E2FSCK -fnvd $devname"
594
595         echo "stop and checking mds${mds_index}: $cmd"
596         # e2fsck should not return error
597         stop mds${mds_index}
598         do_facet mds${mds_index} $cmd || rc=$?
599
600         start mds${mds_index} $devname $MDS_MOUNT_OPTS
601         df $MOUNT > /dev/null 2>&1
602         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
603                 "short/long symlink MDT: rc=$rc"
604         return $rc
605 }
606 run_test 17m "run e2fsck against MDT which contains short/long symlink"
607
608 check_fs_consistency_17n() {
609         local mdt_index
610         local devname
611         local cmd
612         local rc=0
613
614         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
615         # so it only check MDT1/MDT2 instead of all of MDTs.
616         for mdt_index in $(seq 1 2); do
617                 devname=$(mdsdevname $mdt_index)
618                 cmd="$E2FSCK -fnvd $devname"
619
620                 echo "stop and checking mds${mdt_index}: $cmd"
621                 # e2fsck should not return error
622                 stop mds${mdt_index}
623                 do_facet mds${mdt_index} $cmd || rc=$?
624
625                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS
626                 df $MOUNT > /dev/null 2>&1
627                 [ $rc -ne 0 ] && break
628         done
629         return $rc
630 }
631
632 test_17n() {
633         local i
634
635         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
636         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
637                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
638
639         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
640                 skip "only for ldiskfs MDT" && return 0
641
642         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
643
644         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
645
646         mkdir -p $DIR/$tdir
647         for ((i=0; i<10; i++)); do
648                 $LFS mkdir -i 1 $DIR/$tdir/remote_dir_${i} ||
649                         error "create remote dir error $i"
650                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
651                         error "create files under remote dir failed $i"
652         done
653
654         check_fs_consistency_17n ||
655                 error "e2fsck report error after create files under remote dir"
656
657         for ((i=0;i<10;i++)); do
658                 rm -rf $DIR/$tdir/remote_dir_${i} ||
659                         error "destroy remote dir error $i"
660         done
661
662         check_fs_consistency_17n ||
663                 error "e2fsck report error after unlink files under remote dir"
664
665         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
666                 skip "lustre < 2.4.50 does not support migrate mv " && return
667
668         for ((i=0; i<10; i++)); do
669                 mkdir -p $DIR/$tdir/remote_dir_${i}
670                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
671                         error "create files under remote dir failed $i"
672                 $LFS mv -M 1 $DIR/$tdir/remote_dir_${i} ||
673                         error "migrate remote dir error $i"
674         done
675         check_fs_consistency_17n || error "e2fsck report error after migration"
676
677         for ((i=0;i<10;i++)); do
678                 rm -rf $DIR/$tdir/remote_dir_${i} ||
679                         error "destroy remote dir error $i"
680         done
681
682         check_fs_consistency_17n || error "e2fsck report error after unlink"
683 }
684 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
685
686 test_17o() {
687         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ]] &&
688                 skip "Need MDS version at least 2.3.64" && return
689
690         local WDIR=$DIR/${tdir}o
691         local mdt_index
692         local mdtdevname
693         local rc=0
694
695         mkdir -p $WDIR
696         mdt_index=$($LFS getstripe -M $WDIR)
697         mdt_index=$((mdt_index+1))
698         mdtdevname=$(mdsdevname $mdt_index)
699
700         touch $WDIR/$tfile
701         stop mds${mdt_index}
702         start mds${mdt_index} $mdtdevname $MDS_MOUNT_OPTS
703
704         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
705         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
706         ls -l $WDIR/$tfile && rc=1
707         do_facet mds${mdt_index} lctl set_param fail_loc=0
708         [[ $rc -ne 0 ]] && error "stat file should fail"
709         true
710 }
711 run_test 17o "stat file with incompat LMA feature"
712
713 test_18() {
714         touch $DIR/f || error "Failed to touch $DIR/f: $?"
715         ls $DIR || error "Failed to ls $DIR: $?"
716 }
717 run_test 18 "touch .../f ; ls ... =============================="
718
719 test_19a() {
720         touch $DIR/$tfile
721         ls -l $DIR
722         rm $DIR/$tfile
723         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
724 }
725 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
726
727 test_19b() {
728         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
729 }
730 run_test 19b "ls -l .../f19 (should return error) =============="
731
732 test_19c() {
733         [ $RUNAS_ID -eq $UID ] &&
734                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
735         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
736 }
737 run_test 19c "$RUNAS touch .../f19 (should return error) =="
738
739 test_19d() {
740         cat $DIR/f19 && error || true
741 }
742 run_test 19d "cat .../f19 (should return error) =============="
743
744 test_20() {
745         touch $DIR/$tfile
746         rm $DIR/$tfile
747         log "1 done"
748         touch $DIR/$tfile
749         rm $DIR/$tfile
750         log "2 done"
751         touch $DIR/$tfile
752         rm $DIR/$tfile
753         log "3 done"
754         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
755 }
756 run_test 20 "touch .../f ; ls -l ... ==========================="
757
758 test_21() {
759         test_mkdir -p $DIR/$tdir
760         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
761         ln -s dangle $DIR/$tdir/link
762         echo foo >> $DIR/$tdir/link
763         cat $DIR/$tdir/dangle
764         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
765         $CHECKSTAT -f -t file $DIR/$tdir/link ||
766                 error "$tdir/link not linked to a file"
767 }
768 run_test 21 "write to dangling link ============================"
769
770 test_22() {
771         WDIR=$DIR/$tdir
772         test_mkdir -p $DIR/$tdir
773         chown $RUNAS_ID:$RUNAS_GID $WDIR
774         (cd $WDIR || error "cd $WDIR failed";
775         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
776         $RUNAS tar xf -)
777         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
778         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
779         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
780 }
781 run_test 22 "unpack tar archive as non-root user ==============="
782
783 # was test_23
784 test_23a() {
785         test_mkdir -p $DIR/$tdir
786         local file=$DIR/$tdir/$tfile
787
788         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
789         openfile -f O_CREAT:O_EXCL $file &&
790                 error "$file recreate succeeded" || true
791 }
792 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
793
794 test_23b() { # bug 18988
795         test_mkdir -p $DIR/$tdir
796         local file=$DIR/$tdir/$tfile
797
798         rm -f $file
799         echo foo > $file || error "write filed"
800         echo bar >> $file || error "append filed"
801         $CHECKSTAT -s 8 $file || error "wrong size"
802         rm $file
803 }
804 run_test 23b "O_APPEND check =========================="
805
806 # rename sanity
807 test_24a() {
808         echo '-- same directory rename'
809         test_mkdir $DIR/$tdir
810         touch $DIR/$tdir/$tfile.1
811         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
812         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
813 }
814 run_test 24a "rename file to non-existent target"
815
816 test_24b() {
817         test_mkdir $DIR/$tdir
818         touch $DIR/$tdir/$tfile.{1,2}
819         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
820         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
821         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
822 }
823 run_test 24b "rename file to existing target"
824
825 test_24c() {
826         test_mkdir $DIR/$tdir
827         test_mkdir $DIR/$tdir/d$testnum.1
828         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
829         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
830         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
831 }
832 run_test 24c "rename directory to non-existent target"
833
834 test_24d() {
835         test_mkdir -c1 $DIR/$tdir
836         test_mkdir -c1 $DIR/$tdir/d$testnum.1
837         test_mkdir -c1 $DIR/$tdir/d$testnum.2
838         mrename $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 24d "rename directory to existing target"
843
844 test_24e() {
845         echo '-- cross directory renames --'
846         test_mkdir $DIR/R5a
847         test_mkdir $DIR/R5b
848         touch $DIR/R5a/f
849         mv $DIR/R5a/f $DIR/R5b/g
850         $CHECKSTAT -a $DIR/R5a/f || error
851         $CHECKSTAT -t file $DIR/R5b/g || error
852 }
853 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
854
855 test_24f() {
856         test_mkdir $DIR/R6a
857         test_mkdir $DIR/R6b
858         touch $DIR/R6a/f $DIR/R6b/g
859         mv $DIR/R6a/f $DIR/R6b/g
860         $CHECKSTAT -a $DIR/R6a/f || error
861         $CHECKSTAT -t file $DIR/R6b/g || error
862 }
863 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
864
865 test_24g() {
866         test_mkdir $DIR/R7a
867         test_mkdir $DIR/R7b
868         test_mkdir $DIR/R7a/d
869         mv $DIR/R7a/d $DIR/R7b/e
870         $CHECKSTAT -a $DIR/R7a/d || error
871         $CHECKSTAT -t dir $DIR/R7b/e || error
872 }
873 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
874
875 test_24h() {
876         test_mkdir -c1 $DIR/R8a
877         test_mkdir -c1 $DIR/R8b
878         test_mkdir -c1 $DIR/R8a/d
879         test_mkdir -c1 $DIR/R8b/e
880         mrename $DIR/R8a/d $DIR/R8b/e
881         $CHECKSTAT -a $DIR/R8a/d || error
882         $CHECKSTAT -t dir $DIR/R8b/e || error
883 }
884 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
885
886 test_24i() {
887         echo "-- rename error cases"
888         test_mkdir $DIR/R9
889         test_mkdir $DIR/R9/a
890         touch $DIR/R9/f
891         mrename $DIR/R9/f $DIR/R9/a
892         $CHECKSTAT -t file $DIR/R9/f || error
893         $CHECKSTAT -t dir  $DIR/R9/a || error
894         $CHECKSTAT -a $DIR/R9/a/f || error
895 }
896 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
897
898 test_24j() {
899         test_mkdir $DIR/R10
900         mrename $DIR/R10/f $DIR/R10/g
901         $CHECKSTAT -t dir $DIR/R10 || error
902         $CHECKSTAT -a $DIR/R10/f || error
903         $CHECKSTAT -a $DIR/R10/g || error
904 }
905 run_test 24j "source does not exist ============================"
906
907 test_24k() {
908         test_mkdir $DIR/R11a
909         test_mkdir $DIR/R11a/d
910         touch $DIR/R11a/f
911         mv $DIR/R11a/f $DIR/R11a/d
912         $CHECKSTAT -a $DIR/R11a/f || error
913         $CHECKSTAT -t file $DIR/R11a/d/f || error
914 }
915 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
916
917 # bug 2429 - rename foo foo foo creates invalid file
918 test_24l() {
919         f="$DIR/f24l"
920         $MULTIOP $f OcNs || error
921 }
922 run_test 24l "Renaming a file to itself ========================"
923
924 test_24m() {
925         f="$DIR/f24m"
926         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
927         # on ext3 this does not remove either the source or target files
928         # though the "expected" operation would be to remove the source
929         $CHECKSTAT -t file ${f} || error "${f} missing"
930         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
931 }
932 run_test 24m "Renaming a file to a hard link to itself ========="
933
934 test_24n() {
935     f="$DIR/f24n"
936     # this stats the old file after it was renamed, so it should fail
937     touch ${f}
938     $CHECKSTAT ${f}
939     mv ${f} ${f}.rename
940     $CHECKSTAT ${f}.rename
941     $CHECKSTAT -a ${f}
942 }
943 run_test 24n "Statting the old file after renaming (Posix rename 2)"
944
945 test_24o() {
946         check_kernel_version 37 || return 0
947         test_mkdir -p $DIR/d24o
948         rename_many -s random -v -n 10 $DIR/d24o
949 }
950 run_test 24o "rename of files during htree split ==============="
951
952 test_24p() {
953         test_mkdir $DIR/R12a
954         test_mkdir $DIR/R12b
955         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
956         mrename $DIR/R12a $DIR/R12b
957         $CHECKSTAT -a $DIR/R12a || error
958         $CHECKSTAT -t dir $DIR/R12b || error
959         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
960         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
961 }
962 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
963
964 cleanup_multiop_pause() {
965         trap 0
966         kill -USR1 $MULTIPID
967 }
968
969 test_24q() {
970         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
971         test_mkdir $DIR/R13a
972         test_mkdir $DIR/R13b
973         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
974         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
975         MULTIPID=$!
976
977         trap cleanup_multiop_pause EXIT
978         mrename $DIR/R13a $DIR/R13b
979         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
980         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
981         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
982         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
983         cleanup_multiop_pause
984         wait $MULTIPID || error "multiop close failed"
985 }
986 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
987
988 test_24r() { #bug 3789
989         test_mkdir $DIR/R14a
990         test_mkdir $DIR/R14a/b
991         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
992         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
993         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
994 }
995 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
996
997 test_24s() {
998         test_mkdir $DIR/R15a
999         test_mkdir $DIR/R15a/b
1000         test_mkdir $DIR/R15a/b/c
1001         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1002         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1003         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1004 }
1005 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1006 test_24t() {
1007         test_mkdir $DIR/R16a
1008         test_mkdir $DIR/R16a/b
1009         test_mkdir $DIR/R16a/b/c
1010         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1011         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1012         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1013 }
1014 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1015
1016 test_24u() { # bug12192
1017         rm -rf $DIR/$tfile
1018         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1019         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1020 }
1021 run_test 24u "create stripe file"
1022
1023 page_size() {
1024         getconf PAGE_SIZE
1025 }
1026
1027 simple_cleanup_common() {
1028         trap 0
1029         rm -rf $DIR/$tdir
1030         wait_delete_completed
1031 }
1032
1033 max_pages_per_rpc() {
1034         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1035 }
1036
1037 test_24v() {
1038         local NRFILES=100000
1039         local FREE_INODES=$(mdt_free_inodes 0)
1040         [ $FREE_INODES -lt $NRFILES ] && \
1041                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1042                 return
1043
1044         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1045         trap simple_cleanup_common EXIT
1046
1047         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1048         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1049
1050         mkdir -p $DIR/$tdir
1051         createmany -m $DIR/$tdir/$tfile $NRFILES
1052
1053         cancel_lru_locks mdc
1054         lctl set_param mdc.*.stats clear
1055
1056         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1057
1058         # LU-5 large readdir
1059         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1060         #               8 bytes for name(filename is mostly 5 in this test) +
1061         #               8 bytes for luda_type
1062         # take into account of overhead in lu_dirpage header and end mark in
1063         # each page, plus one in RPC_NUM calculation.
1064         DIRENT_SIZE=48
1065         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1066         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1067         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats | \
1068                                 awk '/^mds_readpage/ {print $2}')
1069         [ $mds_readpage -gt $RPC_NUM ] && \
1070                 error "large readdir doesn't take effect"
1071
1072         simple_cleanup_common
1073 }
1074 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1075
1076 test_24w() { # bug21506
1077         SZ1=234852
1078         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1079         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1080         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1081         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1082         [ "$SZ1" = "$SZ2" ] || \
1083                 error "Error reading at the end of the file $tfile"
1084 }
1085 run_test 24w "Reading a file larger than 4Gb"
1086
1087 test_24x() {
1088         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1089         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1090         local MDTIDX=1
1091         local remote_dir=$DIR/$tdir/remote_dir
1092
1093         mkdir -p $DIR/$tdir
1094         $LFS mkdir -i $MDTIDX $remote_dir ||
1095                 error "create remote directory failed"
1096
1097         mkdir -p $DIR/$tdir/src_dir
1098         touch $DIR/$tdir/src_file
1099         mkdir -p $remote_dir/tgt_dir
1100         touch $remote_dir/tgt_file
1101
1102         mrename $remote_dir $DIR/ &&
1103                 error "rename dir cross MDT works!"
1104
1105         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1106                 error "rename dir cross MDT works!"
1107
1108         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1109                 error "rename file cross MDT works!"
1110
1111         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1112                 error "ln file cross MDT should not work!"
1113
1114         rm -rf $DIR/$tdir || error "Can not delete directories"
1115 }
1116 run_test 24x "cross rename/link should be failed"
1117
1118 test_24y() {
1119         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1120         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1121         local MDTIDX=1
1122         local remote_dir=$DIR/$tdir/remote_dir
1123
1124         mkdir -p $DIR/$tdir
1125         $LFS mkdir -i $MDTIDX $remote_dir ||
1126                    error "create remote directory failed"
1127
1128         mkdir -p $remote_dir/src_dir
1129         touch $remote_dir/src_file
1130         mkdir -p $remote_dir/tgt_dir
1131         touch $remote_dir/tgt_file
1132
1133         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1134                 error "rename subdir in the same remote dir failed!"
1135
1136         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1137                 error "rename files in the same remote dir failed!"
1138
1139         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1140                 error "link files in the same remote dir failed!"
1141
1142         rm -rf $DIR/$tdir || error "Can not delete directories"
1143 }
1144 run_test 24y "rename/link on the same dir should succeed"
1145
1146 test_24z() {
1147         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1148         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1149         local MDTIDX=1
1150         local remote_src=$DIR/$tdir/remote_dir
1151         local remote_tgt=$DIR/$tdir/remote_tgt
1152
1153         mkdir -p $DIR/$tdir
1154         $LFS mkdir -i $MDTIDX $remote_src ||
1155                    error "create remote directory failed"
1156
1157         $LFS mkdir -i $MDTIDX $remote_tgt ||
1158                    error "create remote directory failed"
1159
1160         mrename $remote_src $remote_tgt &&
1161                 error "rename remote dirs should not work!"
1162
1163         # If target dir does not exists, it should succeed
1164         rm -rf $remote_tgt
1165         mrename $remote_src $remote_tgt ||
1166                 error "rename remote dirs(tgt dir does not exists) failed!"
1167
1168         rm -rf $DIR/$tdir || error "Can not delete directories"
1169 }
1170 run_test 24z "rename one remote dir to another remote dir should fail"
1171
1172 test_24A() { # LU-3182
1173         local NFILES=5000
1174
1175         rm -rf $DIR/$tdir
1176         mkdir -p $DIR/$tdir
1177         createmany -m $DIR/$tdir/$tfile $NFILES
1178         local t=`ls $DIR/$tdir | wc -l`
1179         local u=`ls $DIR/$tdir | sort -u | wc -l`
1180         if [ $t -ne $NFILES -o $u -ne $NFILES ] ; then
1181                 error "Expected $NFILES files, got $t ($u unique)"
1182         fi
1183
1184         rm -rf $DIR/$tdir || error "Can not delete directories"
1185 }
1186 run_test 24A "readdir() returns correct number of entries."
1187
1188 test_25a() {
1189         echo '== symlink sanity ============================================='
1190
1191         test_mkdir $DIR/d25
1192         ln -s d25 $DIR/s25
1193         touch $DIR/s25/foo || error
1194 }
1195 run_test 25a "create file in symlinked directory ==============="
1196
1197 test_25b() {
1198         [ ! -d $DIR/d25 ] && test_25a
1199         $CHECKSTAT -t file $DIR/s25/foo || error
1200 }
1201 run_test 25b "lookup file in symlinked directory ==============="
1202
1203 test_26a() {
1204         test_mkdir $DIR/d26
1205         test_mkdir $DIR/d26/d26-2
1206         ln -s d26/d26-2 $DIR/s26
1207         touch $DIR/s26/foo || error
1208 }
1209 run_test 26a "multiple component symlink ======================="
1210
1211 test_26b() {
1212         test_mkdir -p $DIR/d26b/d26-2
1213         ln -s d26b/d26-2/foo $DIR/s26-2
1214         touch $DIR/s26-2 || error
1215 }
1216 run_test 26b "multiple component symlink at end of lookup ======"
1217
1218 test_26c() {
1219         test_mkdir $DIR/d26.2
1220         touch $DIR/d26.2/foo
1221         ln -s d26.2 $DIR/s26.2-1
1222         ln -s s26.2-1 $DIR/s26.2-2
1223         ln -s s26.2-2 $DIR/s26.2-3
1224         chmod 0666 $DIR/s26.2-3/foo
1225 }
1226 run_test 26c "chain of symlinks ================================"
1227
1228 # recursive symlinks (bug 439)
1229 test_26d() {
1230         ln -s d26-3/foo $DIR/d26-3
1231 }
1232 run_test 26d "create multiple component recursive symlink ======"
1233
1234 test_26e() {
1235         [ ! -h $DIR/d26-3 ] && test_26d
1236         rm $DIR/d26-3
1237 }
1238 run_test 26e "unlink multiple component recursive symlink ======"
1239
1240 # recursive symlinks (bug 7022)
1241 test_26f() {
1242         test_mkdir -p $DIR/$tdir
1243         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1244         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1245         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1246         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1247         cd $tfile                || error "cd $tfile failed"
1248         ln -s .. dotdot          || error "ln dotdot failed"
1249         ln -s dotdot/lndir lndir || error "ln lndir failed"
1250         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1251         output=`ls $tfile/$tfile/lndir/bar1`
1252         [ "$output" = bar1 ] && error "unexpected output"
1253         rm -r $tfile             || error "rm $tfile failed"
1254         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1255 }
1256 run_test 26f "rm -r of a directory which has recursive symlink ="
1257
1258 test_27a() {
1259         echo '== stripe sanity =============================================='
1260         test_mkdir -p $DIR/d27 || error "mkdir failed"
1261         $GETSTRIPE $DIR/d27
1262         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1263         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1264         pass
1265         log "== test_27a: write to one stripe file ========================="
1266         cp /etc/hosts $DIR/d27/f0 || error
1267 }
1268 run_test 27a "one stripe file =================================="
1269
1270 test_27b() {
1271         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1272         test_mkdir -p $DIR/d27
1273         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1274         $GETSTRIPE -c $DIR/d27/f01
1275         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1276                 error "two-stripe file doesn't have two stripes"
1277
1278         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1279 }
1280 run_test 27b "create and write to two stripe file"
1281
1282 test_27d() {
1283         test_mkdir -p $DIR/d27
1284         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1285         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1286         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1287 }
1288 run_test 27d "create file with default settings ================"
1289
1290 test_27e() {
1291         test_mkdir -p $DIR/d27
1292         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1293         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1294         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1295 }
1296 run_test 27e "setstripe existing file (should return error) ======"
1297
1298 test_27f() {
1299         test_mkdir -p $DIR/d27
1300         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/d27/fbad && error "setstripe failed"
1301         dd if=/dev/zero of=$DIR/d27/fbad bs=4k count=4 || error "dd failed"
1302         $GETSTRIPE $DIR/d27/fbad || error "$GETSTRIPE failed"
1303 }
1304 run_test 27f "setstripe with bad stripe size (should return error)"
1305
1306 test_27g() {
1307         test_mkdir -p $DIR/d27
1308         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1309         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1310                 error "$DIR/d27/fnone has object"
1311 }
1312 run_test 27g "$GETSTRIPE with no objects"
1313
1314 test_27i() {
1315         touch $DIR/d27/fsome || error "touch failed"
1316         [ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ] || error "missing objects"
1317 }
1318 run_test 27i "$GETSTRIPE with some objects"
1319
1320 test_27j() {
1321         test_mkdir -p $DIR/d27
1322         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1323 }
1324 run_test 27j "setstripe with bad stripe offset (should return error)"
1325
1326 test_27k() { # bug 2844
1327         test_mkdir -p $DIR/d27
1328         FILE=$DIR/d27/f27k
1329         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1330         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1331         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1332         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1333         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1334         dd if=/dev/zero of=$FILE bs=4k count=1
1335         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1336         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1337 }
1338 run_test 27k "limit i_blksize for broken user apps ============="
1339
1340 test_27l() {
1341         test_mkdir -p $DIR/d27
1342         mcreate $DIR/f27l || error "creating file"
1343         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1344                 error "setstripe should have failed" || true
1345 }
1346 run_test 27l "check setstripe permissions (should return error)"
1347
1348 test_27m() {
1349         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1350                 return
1351         if [ $ORIGFREE -gt $MAXFREE ]; then
1352                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1353                 return
1354         fi
1355         trap simple_cleanup_common EXIT
1356         test_mkdir -p $DIR/$tdir
1357         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1358         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1359                 error "dd should fill OST0"
1360         i=2
1361         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1362                 i=`expr $i + 1`
1363                 [ $i -gt 256 ] && break
1364         done
1365         i=`expr $i + 1`
1366         touch $DIR/$tdir/f27m_$i
1367         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1368                 error "OST0 was full but new created file still use it"
1369         i=`expr $i + 1`
1370         touch $DIR/$tdir/f27m_$i
1371         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1372                 error "OST0 was full but new created file still use it"
1373         simple_cleanup_common
1374 }
1375 run_test 27m "create file while OST0 was full =================="
1376
1377 sleep_maxage() {
1378         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1379         sleep $DELAY
1380 }
1381
1382 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1383 # if the OST isn't full anymore.
1384 reset_enospc() {
1385         local OSTIDX=${1:-""}
1386
1387         local list=$(comma_list $(osts_nodes))
1388         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1389
1390         do_nodes $list lctl set_param fail_loc=0
1391         sync    # initiate all OST_DESTROYs from MDS to OST
1392         sleep_maxage
1393 }
1394
1395 exhaust_precreations() {
1396         local OSTIDX=$1
1397         local FAILLOC=$2
1398         local FAILIDX=${3:-$OSTIDX}
1399
1400         test_mkdir -p $DIR/$tdir
1401         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1402         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1403
1404         local OST=$(ostname_from_index $OSTIDX)
1405         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1406                           sed -e 's/_UUID$//;s/^.*-//')
1407
1408         # on the mdt's osc
1409         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1410         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1411                         osc.$mdtosc_proc1.prealloc_last_id)
1412         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1413                         osc.$mdtosc_proc1.prealloc_next_id)
1414
1415         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1416         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1417
1418         test_mkdir -p $DIR/$tdir/${OST}
1419         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1420 #define OBD_FAIL_OST_ENOSPC              0x215
1421         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1422         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1423         echo "Creating to objid $last_id on ost $OST..."
1424         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1425         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1426         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1427         sleep_maxage
1428 }
1429
1430 exhaust_all_precreations() {
1431         local i
1432         for (( i=0; i < OSTCOUNT; i++ )) ; do
1433                 exhaust_precreations $i $1 -1
1434         done
1435 }
1436
1437 test_27n() {
1438         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1439         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1440         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1441         remote_ost_nodsh && skip "remote OST with nodsh" && return
1442
1443         reset_enospc
1444         rm -f $DIR/$tdir/$tfile
1445         exhaust_precreations 0 0x80000215
1446         $SETSTRIPE -c -1 $DIR/$tdir
1447         touch $DIR/$tdir/$tfile || error
1448         $GETSTRIPE $DIR/$tdir/$tfile
1449         reset_enospc
1450 }
1451 run_test 27n "create file with some full OSTs =================="
1452
1453 test_27o() {
1454         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1455         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1456         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1457         remote_ost_nodsh && skip "remote OST with nodsh" && return
1458
1459         reset_enospc
1460         rm -f $DIR/$tdir/$tfile
1461         exhaust_all_precreations 0x215
1462
1463         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1464
1465         reset_enospc
1466         rm -rf $DIR/$tdir/*
1467 }
1468 run_test 27o "create file with all full OSTs (should error) ===="
1469
1470 test_27p() {
1471         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1472         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1473         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1474         remote_ost_nodsh && skip "remote OST with nodsh" && return
1475
1476         reset_enospc
1477         rm -f $DIR/$tdir/$tfile
1478         test_mkdir -p $DIR/$tdir
1479
1480         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1481         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1482         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1483
1484         exhaust_precreations 0 0x80000215
1485         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1486         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1487         $GETSTRIPE $DIR/$tdir/$tfile
1488
1489         reset_enospc
1490 }
1491 run_test 27p "append to a truncated file with some full OSTs ==="
1492
1493 test_27q() {
1494         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1495         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1496         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1497         remote_ost_nodsh && skip "remote OST with nodsh" && return
1498
1499         reset_enospc
1500         rm -f $DIR/$tdir/$tfile
1501
1502         test_mkdir -p $DIR/$tdir
1503         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1504         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1505         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1506
1507         exhaust_all_precreations 0x215
1508
1509         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1510         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1511
1512         reset_enospc
1513 }
1514 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1515
1516 test_27r() {
1517         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1518         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1519         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1520         remote_ost_nodsh && skip "remote OST with nodsh" && return
1521
1522         reset_enospc
1523         rm -f $DIR/$tdir/$tfile
1524         exhaust_precreations 0 0x80000215
1525
1526         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1527
1528         reset_enospc
1529 }
1530 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1531
1532 test_27s() { # bug 10725
1533         test_mkdir -p $DIR/$tdir
1534         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1535         local stripe_count=0
1536         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1537         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1538                 error "stripe width >= 2^32 succeeded" || true
1539
1540 }
1541 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1542
1543 test_27t() { # bug 10864
1544         WDIR=`pwd`
1545         WLFS=`which lfs`
1546         cd $DIR
1547         touch $tfile
1548         $WLFS getstripe $tfile
1549         cd $WDIR
1550 }
1551 run_test 27t "check that utils parse path correctly"
1552
1553 test_27u() { # bug 4900
1554         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1555         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1556         local index
1557         local list=$(comma_list $(mdts_nodes))
1558
1559 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1560         do_nodes $list $LCTL set_param fail_loc=0x139
1561         test_mkdir -p $DIR/$tdir
1562         rm -rf $DIR/$tdir/*
1563         createmany -o $DIR/$tdir/t- 1000
1564         do_nodes $list $LCTL set_param fail_loc=0
1565
1566         TLOG=$DIR/$tfile.getstripe
1567         $GETSTRIPE $DIR/$tdir > $TLOG
1568         OBJS=`awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj;}' $TLOG`
1569         unlinkmany $DIR/$tdir/t- 1000
1570         [ $OBJS -gt 0 ] && \
1571                 error "$OBJS objects created on OST-0.  See $TLOG" || pass
1572 }
1573 run_test 27u "skip object creation on OSC w/o objects =========="
1574
1575 test_27v() { # bug 4900
1576         [ "$OSTCOUNT" -lt "2" ] && skip_env "too few OSTs" && return
1577         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1578         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1579         remote_ost_nodsh && skip "remote OST with nodsh" && return
1580
1581         exhaust_all_precreations 0x215
1582         reset_enospc
1583
1584         test_mkdir -p $DIR/$tdir
1585         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1586
1587         touch $DIR/$tdir/$tfile
1588         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1589         # all except ost1
1590         for (( i=1; i < OSTCOUNT; i++ )); do
1591                 do_facet ost$i lctl set_param fail_loc=0x705
1592         done
1593         local START=`date +%s`
1594         createmany -o $DIR/$tdir/$tfile 32
1595
1596         local FINISH=`date +%s`
1597         local TIMEOUT=`lctl get_param -n timeout`
1598         local PROCESS=$((FINISH - START))
1599         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1600                error "$FINISH - $START >= $TIMEOUT / 2"
1601         sleep $((TIMEOUT / 2 - PROCESS))
1602         reset_enospc
1603 }
1604 run_test 27v "skip object creation on slow OST ================="
1605
1606 test_27w() { # bug 10997
1607         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1608         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1609         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1610                 error "stripe size $size != 65536" || true
1611         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1612                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1613 }
1614 run_test 27w "check $SETSTRIPE -S option"
1615
1616 test_27wa() {
1617         [ "$OSTCOUNT" -lt "2" ] &&
1618                 skip_env "skipping multiple stripe count/offset test" && return
1619
1620         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1621         for i in $(seq 1 $OSTCOUNT); do
1622                 offset=$((i - 1))
1623                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1624                         error "setstripe -c $i -i $offset failed"
1625                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1626                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1627                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1628                 [ $index -ne $offset ] &&
1629                         error "stripe offset $index != $offset" || true
1630         done
1631 }
1632 run_test 27wa "check $SETSTRIPE -c -i options"
1633
1634 test_27x() {
1635         remote_ost_nodsh && skip "remote OST with nodsh" && return
1636         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
1637         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1638         OFFSET=$(($OSTCOUNT - 1))
1639         OSTIDX=0
1640         local OST=$(ostname_from_index $OSTIDX)
1641
1642         test_mkdir -p $DIR/$tdir
1643         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1644         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1645         sleep_maxage
1646         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1647         for i in `seq 0 $OFFSET`; do
1648                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1649                 error "OST0 was degraded but new created file still use it"
1650         done
1651         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1652 }
1653 run_test 27x "create files while OST0 is degraded"
1654
1655 test_27y() {
1656         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1657         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1658         remote_ost_nodsh && skip "remote OST with nodsh" && return
1659         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1660
1661         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1662         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1663             osc.$mdtosc.prealloc_last_id)
1664         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1665             osc.$mdtosc.prealloc_next_id)
1666         local fcount=$((last_id - next_id))
1667         [ $fcount -eq 0 ] && skip "not enough space on OST0" && return
1668         [ $fcount -gt $OSTCOUNT ] && fcount=$OSTCOUNT
1669
1670         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1671                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1672         local OST_DEACTIVE_IDX=-1
1673         local OSC
1674         local OSTIDX
1675         local OST
1676
1677         for OSC in $MDS_OSCS; do
1678                 OST=$(osc_to_ost $OSC)
1679                 OSTIDX=$(index_from_ostuuid $OST)
1680                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1681                         OST_DEACTIVE_IDX=$OSTIDX
1682                 fi
1683                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1684                         echo $OSC "is Deactivated:"
1685                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1686                 fi
1687         done
1688
1689         OSTIDX=$(index_from_ostuuid $OST)
1690         mkdir -p $DIR/$tdir
1691         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1692
1693         for OSC in $MDS_OSCS; do
1694                 OST=$(osc_to_ost $OSC)
1695                 OSTIDX=$(index_from_ostuuid $OST)
1696                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1697                         echo $OST "is degraded:"
1698                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1699                                                 obdfilter.$OST.degraded=1
1700                 fi
1701         done
1702
1703         sleep_maxage
1704         createmany -o $DIR/$tdir/$tfile $fcount
1705
1706         for OSC in $MDS_OSCS; do
1707                 OST=$(osc_to_ost $OSC)
1708                 OSTIDX=$(index_from_ostuuid $OST)
1709                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1710                         echo $OST "is recovered from degraded:"
1711                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1712                                                 obdfilter.$OST.degraded=0
1713                 else
1714                         do_facet $SINGLEMDS lctl --device %$OSC activate
1715                 fi
1716         done
1717
1718         # all osp devices get activated, hence -1 stripe count restored
1719         local stripecnt=0
1720
1721         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1722         # devices get activated.
1723         sleep_maxage
1724         $SETSTRIPE -c -1 $DIR/$tfile
1725         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1726         rm -f $DIR/$tfile
1727         [ $stripecnt -ne $OSTCOUNT ] &&
1728                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1729         return 0
1730 }
1731 run_test 27y "create files while OST0 is degraded and the rest inactive"
1732
1733 check_seq_oid()
1734 {
1735         log "check file $1"
1736
1737         lmm_count=$($GETSTRIPE -c $1)
1738         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1739         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1740
1741         local old_ifs="$IFS"
1742         IFS=$'[:]'
1743         fid=($($LFS path2fid $1))
1744         IFS="$old_ifs"
1745
1746         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1747         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1748
1749         # compare lmm_seq and lu_fid->f_seq
1750         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1751         # compare lmm_object_id and lu_fid->oid
1752         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1753
1754         # check the trusted.fid attribute of the OST objects of the file
1755         local have_obdidx=false
1756         local stripe_nr=0
1757         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1758                 # skip lines up to and including "obdidx"
1759                 [ -z "$obdidx" ] && break
1760                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1761                 $have_obdidx || continue
1762
1763                 local ost=$((obdidx + 1))
1764                 local dev=$(ostdevname $ost)
1765                 local oid_hex
1766
1767                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1768
1769                 seq=$(echo $seq | sed -e "s/^0x//g")
1770                 if [ $seq == 0 ]; then
1771                         oid_hex=$(echo $oid)
1772                 else
1773                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1774                 fi
1775                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1776
1777                 local ff
1778                 #
1779                 # Don't unmount/remount the OSTs if we don't need to do that.
1780                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1781                 # update too, until that use mount/ll_decode_filter_fid/mount.
1782                 # Re-enable when debugfs will understand new filter_fid.
1783                 #
1784                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1785                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1786                                 $dev 2>/dev/null" | grep "parent=")
1787                 else
1788                         stop ost$ost
1789                         mount_fstype ost$ost
1790                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1791                                 $(facet_mntpt ost$ost)/$obj_file)
1792                         unmount_fstype ost$ost
1793                         start ost$ost $dev $OST_MOUNT_OPTS
1794                 fi
1795
1796                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1797
1798                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1799
1800                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1801                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1802                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1803                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1804                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1805                 local ff_pstripe
1806                 if echo $ff_parent | grep -q 'stripe='; then
1807                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1808                 else
1809                         #
1810                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1811                         # into f_ver in this case.  See the comment on
1812                         # ff_parent.
1813                         #
1814                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1815                                 sed -e 's/\]//')
1816                 fi
1817
1818                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1819                 [ $ff_pseq = $lmm_seq ] ||
1820                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1821                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1822                 [ $ff_poid = $lmm_oid ] ||
1823                         error "FF parent OID $ff_poid != $lmm_oid"
1824                 (($ff_pstripe == $stripe_nr)) ||
1825                         error "FF stripe $ff_pstripe != $stripe_nr"
1826
1827                 stripe_nr=$((stripe_nr + 1))
1828         done
1829 }
1830
1831 test_27z() {
1832         remote_ost_nodsh && skip "remote OST with nodsh" && return
1833         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1834         test_mkdir -p $DIR/$tdir
1835
1836         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1837                 { error "setstripe -c -1 failed"; return 1; }
1838         # We need to send a write to every object to get parent FID info set.
1839         # This _should_ also work for setattr, but does not currently.
1840         # touch $DIR/$tdir/$tfile-1 ||
1841         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1842                 { error "dd $tfile-1 failed"; return 2; }
1843         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1844                 { error "setstripe -c -1 failed"; return 3; }
1845         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1846                 { error "dd $tfile-2 failed"; return 4; }
1847
1848         # make sure write RPCs have been sent to OSTs
1849         sync; sleep 5; sync
1850
1851         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1852         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1853 }
1854 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1855
1856 test_27A() { # b=19102
1857         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1858         local restore_size=$($GETSTRIPE -S $MOUNT)
1859         local restore_count=$($GETSTRIPE -c $MOUNT)
1860         local restore_offset=$($GETSTRIPE -i $MOUNT)
1861         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1862         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1863                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1864         local default_size=$($GETSTRIPE -S $MOUNT)
1865         local default_offset=$($GETSTRIPE -i $MOUNT)
1866         local dsize=$((1024 * 1024))
1867         [ $default_size -eq $dsize ] ||
1868                 error "stripe size $default_size != $dsize"
1869         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1870         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1871 }
1872 run_test 27A "check filesystem-wide default LOV EA values"
1873
1874 test_27B() { # LU-2523
1875         test_mkdir -p $DIR/$tdir
1876         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1877         touch $DIR/$tdir/f0
1878         # open f1 with O_LOV_DELAY_CREATE
1879         # rename f0 onto f1
1880         # call setstripe ioctl on open file descriptor for f1
1881         # close
1882         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1883                 $DIR/$tdir/f0
1884
1885         rm -f $DIR/$tdir/f1
1886         # open f1 with O_LOV_DELAY_CREATE
1887         # unlink f1
1888         # call setstripe ioctl on open file descriptor for f1
1889         # close
1890         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1891
1892         # Allow multiop to fail in imitation of NFS's busted semantics.
1893         true
1894 }
1895 run_test 27B "call setstripe on open unlinked file/rename victim"
1896
1897 test_27C() { #LU-2871
1898         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
1899
1900         declare -a ost_idx
1901         local index
1902         local found
1903         local i
1904         local j
1905
1906         test_mkdir -p $DIR/$tdir
1907         cd $DIR/$tdir
1908         for i in $(seq 0 $((OSTCOUNT - 1))); do
1909                 # set stripe across all OSTs starting from OST$i
1910                 $SETSTRIPE -i $i -c -1 $tfile$i
1911                 # get striping information
1912                 ost_idx=($($GETSTRIPE $tfile$i |
1913                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1914                 echo ${ost_idx[@]}
1915
1916                 # check the layout
1917                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1918                         error "${#ost_idx[@]} != $OSTCOUNT"
1919
1920                 for index in $(seq 0 $((OSTCOUNT - 1))); do
1921                         found=0
1922                         for j in $(echo ${ost_idx[@]}); do
1923                                 if [ $index -eq $j ]; then
1924                                         found=1
1925                                         break
1926                                 fi
1927                         done
1928                         [ $found = 1 ] ||
1929                                 error "Can not find $index in ${ost_idx[@]}"
1930                 done
1931         done
1932 }
1933 run_test 27C "check full striping across all OSTs"
1934
1935 # createtest also checks that device nodes are created and
1936 # then visible correctly (#2091)
1937 test_28() { # bug 2091
1938         test_mkdir $DIR/d28
1939         $CREATETEST $DIR/d28/ct || error
1940 }
1941 run_test 28 "create/mknod/mkdir with bad file types ============"
1942
1943 test_29() {
1944         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1945         cancel_lru_locks mdc
1946         test_mkdir $DIR/d29
1947         touch $DIR/d29/foo
1948         log 'first d29'
1949         ls -l $DIR/d29
1950
1951         declare -i LOCKCOUNTORIG=0
1952         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1953                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
1954         done
1955         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
1956
1957         declare -i LOCKUNUSEDCOUNTORIG=0
1958         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1959                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
1960         done
1961
1962         log 'second d29'
1963         ls -l $DIR/d29
1964         log 'done'
1965
1966         declare -i LOCKCOUNTCURRENT=0
1967         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
1968                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
1969         done
1970
1971         declare -i LOCKUNUSEDCOUNTCURRENT=0
1972         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
1973                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
1974         done
1975
1976         if [ "$LOCKCOUNTCURRENT" -gt "$LOCKCOUNTORIG" ]; then
1977                 lctl set_param -n ldlm.dump_namespaces ""
1978                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
1979                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1980                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1981                 return 2
1982         fi
1983         if [ "$LOCKUNUSEDCOUNTCURRENT" -gt "$LOCKUNUSEDCOUNTORIG" ]; then
1984                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
1985                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
1986                 log "dumped log to $TMP/test_29.dk (bug 5793)"
1987                 return 3
1988         fi
1989 }
1990 run_test 29 "IT_GETATTR regression  ============================"
1991
1992 test_30a() { # was test_30
1993         cp `which ls` $DIR || cp /bin/ls $DIR
1994         $DIR/ls / || error
1995         rm $DIR/ls
1996 }
1997 run_test 30a "execute binary from Lustre (execve) =============="
1998
1999 test_30b() {
2000         cp `which ls` $DIR || cp /bin/ls $DIR
2001         chmod go+rx $DIR/ls
2002         $RUNAS $DIR/ls / || error
2003         rm $DIR/ls
2004 }
2005 run_test 30b "execute binary from Lustre as non-root ==========="
2006
2007 test_30c() { # b=22376
2008         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2009         cp `which ls` $DIR || cp /bin/ls $DIR
2010         chmod a-rw $DIR/ls
2011         cancel_lru_locks mdc
2012         cancel_lru_locks osc
2013         $RUNAS $DIR/ls / || error
2014         rm -f $DIR/ls
2015 }
2016 run_test 30c "execute binary from Lustre without read perms ===="
2017
2018 test_31a() {
2019         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2020         $CHECKSTAT -a $DIR/f31 || error
2021 }
2022 run_test 31a "open-unlink file =================================="
2023
2024 test_31b() {
2025         touch $DIR/f31 || error
2026         ln $DIR/f31 $DIR/f31b || error
2027         $MULTIOP $DIR/f31b Ouc || error
2028         $CHECKSTAT -t file $DIR/f31 || error
2029 }
2030 run_test 31b "unlink file with multiple links while open ======="
2031
2032 test_31c() {
2033         touch $DIR/f31 || error
2034         ln $DIR/f31 $DIR/f31c || error
2035         multiop_bg_pause $DIR/f31 O_uc || return 1
2036         MULTIPID=$!
2037         $MULTIOP $DIR/f31c Ouc
2038         kill -USR1 $MULTIPID
2039         wait $MULTIPID
2040 }
2041 run_test 31c "open-unlink file with multiple links ============="
2042
2043 test_31d() {
2044         opendirunlink $DIR/d31d $DIR/d31d || error
2045         $CHECKSTAT -a $DIR/d31d || error
2046 }
2047 run_test 31d "remove of open directory ========================="
2048
2049 test_31e() { # bug 2904
2050         check_kernel_version 34 || return 0
2051         openfilleddirunlink $DIR/d31e || error
2052 }
2053 run_test 31e "remove of open non-empty directory ==============="
2054
2055 test_31f() { # bug 4554
2056         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2057         set -vx
2058         test_mkdir $DIR/d31f
2059         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2060         cp /etc/hosts $DIR/d31f
2061         ls -l $DIR/d31f
2062         $GETSTRIPE $DIR/d31f/hosts
2063         multiop_bg_pause $DIR/d31f D_c || return 1
2064         MULTIPID=$!
2065
2066         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2067         test_mkdir $DIR/d31f
2068         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2069         cp /etc/hosts $DIR/d31f
2070         ls -l $DIR/d31f
2071         $GETSTRIPE $DIR/d31f/hosts
2072         multiop_bg_pause $DIR/d31f D_c || return 1
2073         MULTIPID2=$!
2074
2075         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2076         wait $MULTIPID || error "first opendir $MULTIPID failed"
2077
2078         sleep 6
2079
2080         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2081         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2082         set +vx
2083 }
2084 run_test 31f "remove of open directory with open-unlink file ==="
2085
2086 test_31g() {
2087         echo "-- cross directory link --"
2088         test_mkdir -c1 $DIR/${tdir}ga
2089         test_mkdir -c1 $DIR/${tdir}gb
2090         touch $DIR/${tdir}ga/f
2091         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2092         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2093         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2094         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2095         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2096 }
2097 run_test 31g "cross directory link==============="
2098
2099 test_31h() {
2100         echo "-- cross directory link --"
2101         test_mkdir -c1 $DIR/${tdir}
2102         test_mkdir -c1 $DIR/${tdir}/dir
2103         touch $DIR/${tdir}/f
2104         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2105         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2106         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2107         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2108         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2109 }
2110 run_test 31h "cross directory link under child==============="
2111
2112 test_31i() {
2113         echo "-- cross directory link --"
2114         test_mkdir -c1 $DIR/$tdir
2115         test_mkdir -c1 $DIR/$tdir/dir
2116         touch $DIR/$tdir/dir/f
2117         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2118         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2119         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2120         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2121         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2122 }
2123 run_test 31i "cross directory link under parent==============="
2124
2125 test_31j() {
2126         test_mkdir -c1 -p $DIR/$tdir
2127         test_mkdir -c1 -p $DIR/$tdir/dir1
2128         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2129         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2130         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2131         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2132         return 0
2133 }
2134 run_test 31j "link for directory==============="
2135
2136 test_31k() {
2137         test_mkdir -c1 -p $DIR/$tdir
2138         touch $DIR/$tdir/s
2139         touch $DIR/$tdir/exist
2140         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2141         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2142         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2143         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2144         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2145         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2146         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2147         return 0
2148 }
2149 run_test 31k "link to file: the same, non-existing, dir==============="
2150
2151 test_31m() {
2152         mkdir $DIR/d31m
2153         touch $DIR/d31m/s
2154         mkdir $DIR/d31m2
2155         touch $DIR/d31m2/exist
2156         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2157         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2158         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2159         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2160         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2161         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2162         return 0
2163 }
2164 run_test 31m "link to file: the same, non-existing, dir==============="
2165
2166 test_31n() {
2167         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2168         nlink=$(stat --format=%h $DIR/$tfile)
2169         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2170         local fd=$(free_fd)
2171         local cmd="exec $fd<$DIR/$tfile"
2172         eval $cmd
2173         cmd="exec $fd<&-"
2174         trap "eval $cmd" EXIT
2175         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2176         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2177         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2178         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2179         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2180         eval $cmd
2181 }
2182 run_test 31n "check link count of unlinked file"
2183
2184 link_one() {
2185         local TEMPNAME=$(mktemp $1_XXXXXX)
2186         mlink $TEMPNAME $1 2> /dev/null &&
2187                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2188         munlink $TEMPNAME
2189 }
2190
2191 test_31o() { # LU-2901
2192         mkdir -p $DIR/$tdir
2193         for LOOP in $(seq 100); do
2194                 rm -f $DIR/$tdir/$tfile*
2195                 for THREAD in $(seq 8); do
2196                         link_one $DIR/$tdir/$tfile.$LOOP &
2197                 done
2198                 wait
2199                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2200                 [ $LINKS -gt 1 ] && ls $DIR/$tdir &&
2201                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2202                         break || true
2203         done
2204 }
2205 run_test 31o "duplicate hard links with same filename"
2206
2207 cleanup_test32_mount() {
2208         trap 0
2209         $UMOUNT -d $DIR/$tdir/ext2-mountpoint
2210 }
2211
2212 test_32a() {
2213         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2214         echo "== more mountpoints and symlinks ================="
2215         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2216         trap cleanup_test32_mount EXIT
2217         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2218         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2219         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2220         cleanup_test32_mount
2221 }
2222 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2223
2224 test_32b() {
2225         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2226         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2227         trap cleanup_test32_mount EXIT
2228         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2229         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2230         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2231         cleanup_test32_mount
2232 }
2233 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2234
2235 test_32c() {
2236         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2237         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2238         trap cleanup_test32_mount EXIT
2239         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2240         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2241         test_mkdir -p $DIR/$tdir/d2/test_dir
2242         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2243         cleanup_test32_mount
2244 }
2245 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2246
2247 test_32d() {
2248         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2249         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2250         trap cleanup_test32_mount EXIT
2251         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2252         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2253         test_mkdir -p $DIR/$tdir/d2/test_dir
2254         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2255         cleanup_test32_mount
2256 }
2257 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2258
2259 test_32e() {
2260         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2261         test_mkdir -p $DIR/d32e/tmp
2262         TMP_DIR=$DIR/d32e/tmp
2263         ln -s $DIR/d32e $TMP_DIR/symlink11
2264         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2265         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2266         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2267 }
2268 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2269
2270 test_32f() {
2271         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2272         test_mkdir -p $DIR/d32f/tmp
2273         TMP_DIR=$DIR/d32f/tmp
2274         ln -s $DIR/d32f $TMP_DIR/symlink11
2275         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2276         ls $DIR/d32f/tmp/symlink11  || error
2277         ls $DIR/d32f/symlink01 || error
2278 }
2279 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2280
2281 test_32g() {
2282         TMP_DIR=$DIR/$tdir/tmp
2283         test_mkdir -p $DIR/$tdir/tmp
2284         test_mkdir $DIR/${tdir}2
2285         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2286         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2287         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2288         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2289         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2290         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2291 }
2292 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2293
2294 test_32h() {
2295         rm -fr $DIR/$tdir $DIR/${tdir}2
2296         TMP_DIR=$DIR/$tdir/tmp
2297         test_mkdir -p $DIR/$tdir/tmp
2298         test_mkdir $DIR/${tdir}2
2299         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2300         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2301         ls $TMP_DIR/symlink12 || error
2302         ls $DIR/$tdir/symlink02  || error
2303 }
2304 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2305
2306 test_32i() {
2307         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2308         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2309         trap cleanup_test32_mount EXIT
2310         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2311         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2312         touch $DIR/$tdir/test_file
2313         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2314         cleanup_test32_mount
2315 }
2316 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2317
2318 test_32j() {
2319         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2320         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2321         trap cleanup_test32_mount EXIT
2322         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2323         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2324         touch $DIR/$tdir/test_file
2325         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2326         cleanup_test32_mount
2327 }
2328 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2329
2330 test_32k() {
2331         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2332         rm -fr $DIR/$tdir
2333         trap cleanup_test32_mount EXIT
2334         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2335         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2336         test_mkdir -p $DIR/$tdir/d2
2337         touch $DIR/$tdir/d2/test_file || error
2338         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2339         cleanup_test32_mount
2340 }
2341 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2342
2343 test_32l() {
2344         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2345         rm -fr $DIR/$tdir
2346         trap cleanup_test32_mount EXIT
2347         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2348         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2349         test_mkdir -p $DIR/$tdir/d2
2350         touch $DIR/$tdir/d2/test_file
2351         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2352         cleanup_test32_mount
2353 }
2354 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2355
2356 test_32m() {
2357         rm -fr $DIR/d32m
2358         test_mkdir -p $DIR/d32m/tmp
2359         TMP_DIR=$DIR/d32m/tmp
2360         ln -s $DIR $TMP_DIR/symlink11
2361         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2362         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2363         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2364 }
2365 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2366
2367 test_32n() {
2368         rm -fr $DIR/d32n
2369         test_mkdir -p $DIR/d32n/tmp
2370         TMP_DIR=$DIR/d32n/tmp
2371         ln -s $DIR $TMP_DIR/symlink11
2372         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2373         ls -l $DIR/d32n/tmp/symlink11  || error
2374         ls -l $DIR/d32n/symlink01 || error
2375 }
2376 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2377
2378 test_32o() {
2379         rm -fr $DIR/d32o $DIR/$tfile
2380         touch $DIR/$tfile
2381         test_mkdir -p $DIR/d32o/tmp
2382         TMP_DIR=$DIR/d32o/tmp
2383         ln -s $DIR/$tfile $TMP_DIR/symlink12
2384         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2385         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2386         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2387         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2388         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2389 }
2390 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2391
2392 test_32p() {
2393     log 32p_1
2394         rm -fr $DIR/d32p
2395     log 32p_2
2396         rm -f $DIR/$tfile
2397     log 32p_3
2398         touch $DIR/$tfile
2399     log 32p_4
2400         test_mkdir -p $DIR/d32p/tmp
2401     log 32p_5
2402         TMP_DIR=$DIR/d32p/tmp
2403     log 32p_6
2404         ln -s $DIR/$tfile $TMP_DIR/symlink12
2405     log 32p_7
2406         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2407     log 32p_8
2408         cat $DIR/d32p/tmp/symlink12 || error
2409     log 32p_9
2410         cat $DIR/d32p/symlink02 || error
2411     log 32p_10
2412 }
2413 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2414
2415 cleanup_testdir_mount() {
2416         trap 0
2417         $UMOUNT -d $DIR/$tdir
2418 }
2419
2420 test_32q() {
2421         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2422         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2423         trap cleanup_testdir_mount EXIT
2424         test_mkdir -p $DIR/$tdir
2425         touch $DIR/$tdir/under_the_mount
2426         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2427         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2428         cleanup_testdir_mount
2429 }
2430 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2431
2432 test_32r() {
2433         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2434         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2435         trap cleanup_testdir_mount EXIT
2436         test_mkdir -p $DIR/$tdir
2437         touch $DIR/$tdir/under_the_mount
2438         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2439         ls $DIR/$tdir | grep -q under_the_mount && error || true
2440         cleanup_testdir_mount
2441 }
2442 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2443
2444 test_33aa() {
2445         rm -f $DIR/$tfile
2446         touch $DIR/$tfile
2447         chmod 444 $DIR/$tfile
2448         chown $RUNAS_ID $DIR/$tfile
2449         log 33_1
2450         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2451         log 33_2
2452 }
2453 run_test 33aa "write file with mode 444 (should return error) ===="
2454
2455 test_33a() {
2456         rm -fr $DIR/d33
2457         test_mkdir -p $DIR/d33
2458         chown $RUNAS_ID $DIR/d33
2459         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2460         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2461                 error "open RDWR" || true
2462 }
2463 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2464
2465 test_33b() {
2466         rm -fr $DIR/d33
2467         test_mkdir -p $DIR/d33
2468         chown $RUNAS_ID $DIR/d33
2469         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 && error "create" || true
2470 }
2471 run_test 33b "test open file with malformed flags (No panic and return error)"
2472
2473 test_33c() {
2474         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2475         local ostnum
2476         local ostname
2477         local write_bytes
2478         local all_zeros
2479
2480         remote_ost_nodsh && skip "remote OST with nodsh" && return
2481         all_zeros=:
2482         rm -fr $DIR/d33
2483         test_mkdir -p $DIR/d33
2484         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2485
2486         sync
2487         for ostnum in $(seq $OSTCOUNT); do
2488                 # test-framework's OST numbering is one-based, while Lustre's
2489                 # is zero-based
2490                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2491                 # Parsing llobdstat's output sucks; we could grep the /proc
2492                 # path, but that's likely to not be as portable as using the
2493                 # llobdstat utility.  So we parse lctl output instead.
2494                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2495                         obdfilter/$ostname/stats |
2496                         awk '/^write_bytes/ {print $7}' )
2497                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2498                 if (( ${write_bytes:-0} > 0 ))
2499                 then
2500                         all_zeros=false
2501                         break;
2502                 fi
2503         done
2504
2505         $all_zeros || return 0
2506
2507         # Write four bytes
2508         echo foo > $DIR/d33/bar
2509         # Really write them
2510         sync
2511
2512         # Total up write_bytes after writing.  We'd better find non-zeros.
2513         for ostnum in $(seq $OSTCOUNT); do
2514                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2515                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2516                         obdfilter/$ostname/stats |
2517                         awk '/^write_bytes/ {print $7}' )
2518                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2519                 if (( ${write_bytes:-0} > 0 ))
2520                 then
2521                         all_zeros=false
2522                         break;
2523                 fi
2524         done
2525
2526         if $all_zeros
2527         then
2528                 for ostnum in $(seq $OSTCOUNT); do
2529                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2530                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2531                         do_facet ost$ostnum lctl get_param -n \
2532                                 obdfilter/$ostname/stats
2533                 done
2534                 error "OST not keeping write_bytes stats (b22312)"
2535         fi
2536 }
2537 run_test 33c "test llobdstat and write_bytes"
2538
2539 test_33d() {
2540         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2541         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2542         local MDTIDX=1
2543         local remote_dir=$DIR/$tdir/remote_dir
2544
2545         mkdir -p $DIR/$tdir
2546         $LFS mkdir -i $MDTIDX $remote_dir ||
2547                 error "create remote directory failed"
2548
2549         touch $remote_dir/$tfile
2550         chmod 444 $remote_dir/$tfile
2551         chown $RUNAS_ID $remote_dir/$tfile
2552
2553         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2554
2555         chown $RUNAS_ID $remote_dir
2556         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2557                                         error "create" || true
2558         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2559                                     error "open RDWR" || true
2560         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2561                                     error "create" || true
2562 }
2563 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2564
2565 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2566 test_34a() {
2567         rm -f $DIR/f34
2568         $MCREATE $DIR/f34 || error
2569         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2570         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2571         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2572         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2573 }
2574 run_test 34a "truncate file that has not been opened ==========="
2575
2576 test_34b() {
2577         [ ! -f $DIR/f34 ] && test_34a
2578         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2579         $OPENFILE -f O_RDONLY $DIR/f34
2580         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2581         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2582 }
2583 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2584
2585 test_34c() {
2586         [ ! -f $DIR/f34 ] && test_34a
2587         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2588         $OPENFILE -f O_RDWR $DIR/f34
2589         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2590         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2591 }
2592 run_test 34c "O_RDWR opening file-with-size works =============="
2593
2594 test_34d() {
2595         [ ! -f $DIR/f34 ] && test_34a
2596         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2597         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2598         rm $DIR/f34
2599 }
2600 run_test 34d "write to sparse file ============================="
2601
2602 test_34e() {
2603         rm -f $DIR/f34e
2604         $MCREATE $DIR/f34e || error
2605         $TRUNCATE $DIR/f34e 1000 || error
2606         $CHECKSTAT -s 1000 $DIR/f34e || error
2607         $OPENFILE -f O_RDWR $DIR/f34e
2608         $CHECKSTAT -s 1000 $DIR/f34e || error
2609 }
2610 run_test 34e "create objects, some with size and some without =="
2611
2612 test_34f() { # bug 6242, 6243
2613         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2614         SIZE34F=48000
2615         rm -f $DIR/f34f
2616         $MCREATE $DIR/f34f || error
2617         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2618         dd if=$DIR/f34f of=$TMP/f34f
2619         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2620         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2621         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2622         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2623         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2624 }
2625 run_test 34f "read from a file with no objects until EOF ======="
2626
2627 test_34g() {
2628         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2629         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2630         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2631         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2632         cancel_lru_locks osc
2633         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2634                 error "wrong size after lock cancel"
2635
2636         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2637         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2638                 error "expanding truncate failed"
2639         cancel_lru_locks osc
2640         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2641                 error "wrong expanded size after lock cancel"
2642 }
2643 run_test 34g "truncate long file ==============================="
2644
2645 test_34h() {
2646         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2647         local gid=10
2648         local sz=1000
2649
2650         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2651         sync # Flush the cache so that multiop below does not block on cache
2652              # flush when getting the group lock
2653         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2654         MULTIPID=$!
2655
2656         # Since just timed wait is not good enough, let's do a sync write
2657         # that way we are sure enough time for a roundtrip + processing
2658         # passed + 2 seconds of extra margin.
2659         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2660         rm $DIR/${tfile}-1
2661         sleep 2
2662
2663         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2664                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2665                 kill -9 $MULTIPID
2666         fi
2667         wait $MULTIPID
2668         local nsz=`stat -c %s $DIR/$tfile`
2669         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2670 }
2671 run_test 34h "ftruncate file under grouplock should not block"
2672
2673 test_35a() {
2674         cp /bin/sh $DIR/f35a
2675         chmod 444 $DIR/f35a
2676         chown $RUNAS_ID $DIR/f35a
2677         $RUNAS $DIR/f35a && error || true
2678         rm $DIR/f35a
2679 }
2680 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2681
2682 test_36a() {
2683         rm -f $DIR/f36
2684         utime $DIR/f36 || error
2685 }
2686 run_test 36a "MDS utime check (mknod, utime) ==================="
2687
2688 test_36b() {
2689         echo "" > $DIR/f36
2690         utime $DIR/f36 || error
2691 }
2692 run_test 36b "OST utime check (open, utime) ===================="
2693
2694 test_36c() {
2695         rm -f $DIR/d36/f36
2696         test_mkdir $DIR/d36
2697         chown $RUNAS_ID $DIR/d36
2698         $RUNAS utime $DIR/d36/f36 || error
2699 }
2700 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2701
2702 test_36d() {
2703         [ ! -d $DIR/d36 ] && test_36c
2704         echo "" > $DIR/d36/f36
2705         $RUNAS utime $DIR/d36/f36 || error
2706 }
2707 run_test 36d "non-root OST utime check (open, utime) ==========="
2708
2709 test_36e() {
2710         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2711         test_mkdir -p $DIR/$tdir
2712         touch $DIR/$tdir/$tfile
2713         $RUNAS utime $DIR/$tdir/$tfile && \
2714                 error "utime worked, expected failure" || true
2715 }
2716 run_test 36e "utime on non-owned file (should return error) ===="
2717
2718 subr_36fh() {
2719         local fl="$1"
2720         local LANG_SAVE=$LANG
2721         local LC_LANG_SAVE=$LC_LANG
2722         export LANG=C LC_LANG=C # for date language
2723
2724         DATESTR="Dec 20  2000"
2725         test_mkdir -p $DIR/$tdir
2726         lctl set_param fail_loc=$fl
2727         date; date +%s
2728         cp /etc/hosts $DIR/$tdir/$tfile
2729         sync & # write RPC generated with "current" inode timestamp, but delayed
2730         sleep 1
2731         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2732         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2733         cancel_lru_locks osc
2734         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2735         date; date +%s
2736         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2737                 echo "BEFORE: $LS_BEFORE" && \
2738                 echo "AFTER : $LS_AFTER" && \
2739                 echo "WANT  : $DATESTR" && \
2740                 error "$DIR/$tdir/$tfile timestamps changed" || true
2741
2742         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2743 }
2744
2745 test_36f() {
2746         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2747         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2748         subr_36fh "0x80000214"
2749 }
2750 run_test 36f "utime on file racing with OST BRW write =========="
2751
2752 test_36g() {
2753         remote_ost_nodsh && skip "remote OST with nodsh" && return
2754         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2755         local fmd_max_age
2756         local fmd_before
2757         local fmd_after
2758
2759         test_mkdir -p $DIR/$tdir
2760         fmd_max_age=$(do_facet ost1 \
2761                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2762                 head -n 1")
2763
2764         fmd_before=$(do_facet ost1 \
2765                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2766         touch $DIR/$tdir/$tfile
2767         sleep $((fmd_max_age + 12))
2768         fmd_after=$(do_facet ost1 \
2769                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2770
2771         echo "fmd_before: $fmd_before"
2772         echo "fmd_after: $fmd_after"
2773         [ "$fmd_after" -gt "$fmd_before" ] && \
2774                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" && \
2775                 error "fmd didn't expire after ping" || true
2776 }
2777 run_test 36g "filter mod data cache expiry ====================="
2778
2779 test_36h() {
2780         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2781         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2782         subr_36fh "0x80000227"
2783 }
2784 run_test 36h "utime on file racing with OST BRW write =========="
2785
2786 # test_37 - duplicate with tests 32q 32r
2787
2788 test_38() {
2789         local file=$DIR/$tfile
2790         touch $file
2791         openfile -f O_DIRECTORY $file
2792         local RC=$?
2793         local ENOTDIR=20
2794         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2795         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2796 }
2797 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2798
2799 test_39() {
2800         touch $DIR/$tfile
2801         touch $DIR/${tfile}2
2802 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2803 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2804 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2805         sleep 2
2806         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2807         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2808                 echo "mtime"
2809                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2810                 echo "atime"
2811                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2812                 echo "ctime"
2813                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2814                 error "O_TRUNC didn't change timestamps"
2815         fi
2816 }
2817 run_test 39 "mtime changed on create ==========================="
2818
2819 test_39b() {
2820         test_mkdir -p $DIR/$tdir
2821         cp -p /etc/passwd $DIR/$tdir/fopen
2822         cp -p /etc/passwd $DIR/$tdir/flink
2823         cp -p /etc/passwd $DIR/$tdir/funlink
2824         cp -p /etc/passwd $DIR/$tdir/frename
2825         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2826
2827         sleep 1
2828         echo "aaaaaa" >> $DIR/$tdir/fopen
2829         echo "aaaaaa" >> $DIR/$tdir/flink
2830         echo "aaaaaa" >> $DIR/$tdir/funlink
2831         echo "aaaaaa" >> $DIR/$tdir/frename
2832
2833         local open_new=`stat -c %Y $DIR/$tdir/fopen`
2834         local link_new=`stat -c %Y $DIR/$tdir/flink`
2835         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
2836         local rename_new=`stat -c %Y $DIR/$tdir/frename`
2837
2838         cat $DIR/$tdir/fopen > /dev/null
2839         ln $DIR/$tdir/flink $DIR/$tdir/flink2
2840         rm -f $DIR/$tdir/funlink2
2841         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
2842
2843         for (( i=0; i < 2; i++ )) ; do
2844                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
2845                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
2846                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
2847                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
2848
2849                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
2850                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
2851                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
2852                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
2853
2854                 cancel_lru_locks osc
2855                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2856         done
2857 }
2858 run_test 39b "mtime change on open, link, unlink, rename  ======"
2859
2860 # this should be set to past
2861 TEST_39_MTIME=`date -d "1 year ago" +%s`
2862
2863 # bug 11063
2864 test_39c() {
2865         touch $DIR1/$tfile
2866         sleep 2
2867         local mtime0=`stat -c %Y $DIR1/$tfile`
2868
2869         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2870         local mtime1=`stat -c %Y $DIR1/$tfile`
2871         [ "$mtime1" = $TEST_39_MTIME ] || \
2872                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
2873
2874         local d1=`date +%s`
2875         echo hello >> $DIR1/$tfile
2876         local d2=`date +%s`
2877         local mtime2=`stat -c %Y $DIR1/$tfile`
2878         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
2879                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
2880
2881         mv $DIR1/$tfile $DIR1/$tfile-1
2882
2883         for (( i=0; i < 2; i++ )) ; do
2884                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
2885                 [ "$mtime2" = "$mtime3" ] || \
2886                         error "mtime ($mtime2) changed (to $mtime3) on rename"
2887
2888                 cancel_lru_locks osc
2889                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2890         done
2891 }
2892 run_test 39c "mtime change on rename ==========================="
2893
2894 # bug 21114
2895 test_39d() {
2896         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2897         touch $DIR1/$tfile
2898
2899         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2900
2901         for (( i=0; i < 2; i++ )) ; do
2902                 local mtime=`stat -c %Y $DIR1/$tfile`
2903                 [ $mtime = $TEST_39_MTIME ] || \
2904                         error "mtime($mtime) is not set to $TEST_39_MTIME"
2905
2906                 cancel_lru_locks osc
2907                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2908         done
2909 }
2910 run_test 39d "create, utime, stat =============================="
2911
2912 # bug 21114
2913 test_39e() {
2914         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2915         touch $DIR1/$tfile
2916         local mtime1=`stat -c %Y $DIR1/$tfile`
2917
2918         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2919
2920         for (( i=0; i < 2; i++ )) ; do
2921                 local mtime2=`stat -c %Y $DIR1/$tfile`
2922                 [ $mtime2 = $TEST_39_MTIME ] || \
2923                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2924
2925                 cancel_lru_locks osc
2926                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2927         done
2928 }
2929 run_test 39e "create, stat, utime, stat ========================"
2930
2931 # bug 21114
2932 test_39f() {
2933         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2934         touch $DIR1/$tfile
2935         mtime1=`stat -c %Y $DIR1/$tfile`
2936
2937         sleep 2
2938         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2939
2940         for (( i=0; i < 2; i++ )) ; do
2941                 local mtime2=`stat -c %Y $DIR1/$tfile`
2942                 [ $mtime2 = $TEST_39_MTIME ] || \
2943                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
2944
2945                 cancel_lru_locks osc
2946                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2947         done
2948 }
2949 run_test 39f "create, stat, sleep, utime, stat ================="
2950
2951 # bug 11063
2952 test_39g() {
2953         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2954         echo hello >> $DIR1/$tfile
2955         local mtime1=`stat -c %Y $DIR1/$tfile`
2956
2957         sleep 2
2958         chmod o+r $DIR1/$tfile
2959
2960         for (( i=0; i < 2; i++ )) ; do
2961                 local mtime2=`stat -c %Y $DIR1/$tfile`
2962                 [ "$mtime1" = "$mtime2" ] || \
2963                         error "lost mtime: $mtime2, should be $mtime1"
2964
2965                 cancel_lru_locks osc
2966                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2967         done
2968 }
2969 run_test 39g "write, chmod, stat ==============================="
2970
2971 # bug 11063
2972 test_39h() {
2973         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2974         touch $DIR1/$tfile
2975         sleep 1
2976
2977         local d1=`date`
2978         echo hello >> $DIR1/$tfile
2979         local mtime1=`stat -c %Y $DIR1/$tfile`
2980
2981         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
2982         local d2=`date`
2983         if [ "$d1" != "$d2" ]; then
2984                 echo "write and touch not within one second"
2985         else
2986                 for (( i=0; i < 2; i++ )) ; do
2987                         local mtime2=`stat -c %Y $DIR1/$tfile`
2988                         [ "$mtime2" = $TEST_39_MTIME ] || \
2989                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
2990
2991                         cancel_lru_locks osc
2992                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
2993                 done
2994         fi
2995 }
2996 run_test 39h "write, utime within one second, stat ============="
2997
2998 test_39i() {
2999         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3000         touch $DIR1/$tfile
3001         sleep 1
3002
3003         echo hello >> $DIR1/$tfile
3004         local mtime1=`stat -c %Y $DIR1/$tfile`
3005
3006         mv $DIR1/$tfile $DIR1/$tfile-1
3007
3008         for (( i=0; i < 2; i++ )) ; do
3009                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3010
3011                 [ "$mtime1" = "$mtime2" ] || \
3012                         error "lost mtime: $mtime2, should be $mtime1"
3013
3014                 cancel_lru_locks osc
3015                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3016         done
3017 }
3018 run_test 39i "write, rename, stat =============================="
3019
3020 test_39j() {
3021         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3022         start_full_debug_logging
3023         touch $DIR1/$tfile
3024         sleep 1
3025
3026         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3027         lctl set_param fail_loc=0x80000412
3028         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3029                 error "multiop failed"
3030         local multipid=$!
3031         local mtime1=`stat -c %Y $DIR1/$tfile`
3032
3033         mv $DIR1/$tfile $DIR1/$tfile-1
3034
3035         kill -USR1 $multipid
3036         wait $multipid || error "multiop close failed"
3037
3038         for (( i=0; i < 2; i++ )) ; do
3039                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3040                 [ "$mtime1" = "$mtime2" ] ||
3041                         error "mtime is lost on close: $mtime2, " \
3042                               "should be $mtime1"
3043
3044                 cancel_lru_locks osc
3045                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3046         done
3047         lctl set_param fail_loc=0
3048         stop_full_debug_logging
3049 }
3050 run_test 39j "write, rename, close, stat ======================="
3051
3052 test_39k() {
3053         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3054         touch $DIR1/$tfile
3055         sleep 1
3056
3057         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3058         local multipid=$!
3059         local mtime1=`stat -c %Y $DIR1/$tfile`
3060
3061         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3062
3063         kill -USR1 $multipid
3064         wait $multipid || error "multiop close failed"
3065
3066         for (( i=0; i < 2; i++ )) ; do
3067                 local mtime2=`stat -c %Y $DIR1/$tfile`
3068
3069                 [ "$mtime2" = $TEST_39_MTIME ] || \
3070                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3071
3072                 cancel_lru_locks osc
3073                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3074         done
3075 }
3076 run_test 39k "write, utime, close, stat ========================"
3077
3078 # this should be set to future
3079 TEST_39_ATIME=`date -d "1 year" +%s`
3080
3081 test_39l() {
3082         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3083         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3084         local atime_diff=$(do_facet $SINGLEMDS \
3085                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3086         rm -rf $DIR/$tdir
3087         mkdir -p $DIR/$tdir
3088
3089         # test setting directory atime to future
3090         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3091         local atime=$(stat -c %X $DIR/$tdir)
3092         [ "$atime" = $TEST_39_ATIME ] || \
3093                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3094
3095         # test setting directory atime from future to now
3096         local d1=$(date +%s)
3097         ls $DIR/$tdir
3098         local d2=$(date +%s)
3099
3100         cancel_lru_locks mdc
3101         atime=$(stat -c %X $DIR/$tdir)
3102         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3103                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3104
3105         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3106         sleep 3
3107
3108         # test setting directory atime when now > dir atime + atime_diff
3109         d1=$(date +%s)
3110         ls $DIR/$tdir
3111         d2=$(date +%s)
3112         cancel_lru_locks mdc
3113         atime=$(stat -c %X $DIR/$tdir)
3114         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3115                 error "atime is not updated  : $atime, should be $d2"
3116
3117         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3118         sleep 3
3119
3120         # test not setting directory atime when now < dir atime + atime_diff
3121         ls $DIR/$tdir
3122         cancel_lru_locks mdc
3123         atime=$(stat -c %X $DIR/$tdir)
3124         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3125                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3126
3127         do_facet $SINGLEMDS \
3128                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3129 }
3130 run_test 39l "directory atime update ==========================="
3131
3132 test_39m() {
3133         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3134         touch $DIR1/$tfile
3135         sleep 2
3136         local far_past_mtime=$(date -d "May 29 1953" +%s)
3137         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3138
3139         touch -m -d @$far_past_mtime $DIR1/$tfile
3140         touch -a -d @$far_past_atime $DIR1/$tfile
3141
3142         for (( i=0; i < 2; i++ )) ; do
3143                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3144                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3145                         error "atime or mtime set incorrectly"
3146
3147                 cancel_lru_locks osc
3148                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3149         done
3150 }
3151 run_test 39m "test atime and mtime before 1970"
3152
3153 test_39n() { # LU-3832
3154         local atime_diff=$(do_facet $SINGLEMDS \
3155                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3156         local atime0
3157         local atime1
3158         local atime2
3159
3160         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3161
3162         rm -rf $DIR/$tfile
3163         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3164         atime0=$(stat -c %X $DIR/$tfile)
3165
3166         sleep 5
3167         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3168         atime1=$(stat -c %X $DIR/$tfile)
3169
3170         sleep 5
3171         cancel_lru_locks mdc
3172         cancel_lru_locks osc
3173         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3174         atime2=$(stat -c %X $DIR/$tfile)
3175
3176         do_facet $SINGLEMDS \
3177                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3178
3179         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3180         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3181 }
3182 run_test 39n "check that O_NOATIME is honored"
3183
3184 test_39o() {
3185         TESTDIR=$DIR/$tdir/$tfile
3186         [ -e $TESTDIR ] && rm -rf $TESTDIR
3187         test_mkdir -p $TESTDIR
3188         cd $TESTDIR
3189         links1=2
3190         ls
3191         mkdir a b
3192         ls
3193         links2=$(stat -c %h .)
3194         [ $(($links1 + 2)) != $links2 ] &&
3195                 error "wrong links count $(($links1 + 2)) != $links2"
3196         rmdir b
3197         links3=$(stat -c %h .)
3198         [ $(($links1 + 1)) != $links3 ] &&
3199                 error "wrong links count $links1 != $links3"
3200         return 0
3201 }
3202 run_test 39o "directory cached attributes updated after create ========"
3203
3204 test_39p() {
3205         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3206         local MDTIDX=1
3207         TESTDIR=$DIR/$tdir/$tfile
3208         [ -e $TESTDIR ] && rm -rf $TESTDIR
3209         mkdir -p $TESTDIR
3210         cd $TESTDIR
3211         links1=2
3212         ls
3213         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3214         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3215         ls
3216         links2=$(stat -c %h .)
3217         [ $(($links1 + 2)) != $links2 ] &&
3218                 error "wrong links count $(($links1 + 2)) != $links2"
3219         rmdir remote_dir2
3220         links3=$(stat -c %h .)
3221         [ $(($links1 + 1)) != $links3 ] &&
3222                 error "wrong links count $links1 != $links3"
3223         return 0
3224 }
3225 run_test 39p "remote directory cached attributes updated after create ========"
3226
3227
3228 test_40() {
3229         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3230         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3231                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3232         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3233                 error "$tfile is not 4096 bytes in size"
3234 }
3235 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3236
3237 test_41() {
3238         # bug 1553
3239         small_write $DIR/f41 18
3240 }
3241 run_test 41 "test small file write + fstat ====================="
3242
3243 count_ost_writes() {
3244         lctl get_param -n osc.*.stats |
3245             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
3246 }
3247
3248 # decent default
3249 WRITEBACK_SAVE=500
3250 DIRTY_RATIO_SAVE=40
3251 MAX_DIRTY_RATIO=50
3252 BG_DIRTY_RATIO_SAVE=10
3253 MAX_BG_DIRTY_RATIO=25
3254
3255 start_writeback() {
3256         trap 0
3257         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3258         # dirty_ratio, dirty_background_ratio
3259         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3260                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3261                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3262                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3263         else
3264                 # if file not here, we are a 2.4 kernel
3265                 kill -CONT `pidof kupdated`
3266         fi
3267 }
3268
3269 stop_writeback() {
3270         # setup the trap first, so someone cannot exit the test at the
3271         # exact wrong time and mess up a machine
3272         trap start_writeback EXIT
3273         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3274         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3275                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3276                 sysctl -w vm.dirty_writeback_centisecs=0
3277                 sysctl -w vm.dirty_writeback_centisecs=0
3278                 # save and increase /proc/sys/vm/dirty_ratio
3279                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3280                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3281                 # save and increase /proc/sys/vm/dirty_background_ratio
3282                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3283                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3284         else
3285                 # if file not here, we are a 2.4 kernel
3286                 kill -STOP `pidof kupdated`
3287         fi
3288 }
3289
3290 # ensure that all stripes have some grant before we test client-side cache
3291 setup_test42() {
3292         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3293                 dd if=/dev/zero of=$i bs=4k count=1
3294                 rm $i
3295         done
3296 }
3297
3298 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3299 # file truncation, and file removal.
3300 test_42a() {
3301         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3302         setup_test42
3303         cancel_lru_locks osc
3304         stop_writeback
3305         sync; sleep 1; sync # just to be safe
3306         BEFOREWRITES=`count_ost_writes`
3307         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3308         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3309         AFTERWRITES=`count_ost_writes`
3310         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3311                 error "$BEFOREWRITES < $AFTERWRITES"
3312         start_writeback
3313 }
3314 run_test 42a "ensure that we don't flush on close =============="
3315
3316 test_42b() {
3317         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3318         setup_test42
3319         cancel_lru_locks osc
3320         stop_writeback
3321         sync
3322         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3323         BEFOREWRITES=`count_ost_writes`
3324         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3325         AFTERWRITES=`count_ost_writes`
3326         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
3327                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3328         fi
3329         BEFOREWRITES=`count_ost_writes`
3330         sync || error "sync: $?"
3331         AFTERWRITES=`count_ost_writes`
3332         if [ $BEFOREWRITES -lt $AFTERWRITES ]; then
3333                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3334         fi
3335         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3336         start_writeback
3337         return 0
3338 }
3339 run_test 42b "test destroy of file with cached dirty data ======"
3340
3341 # if these tests just want to test the effect of truncation,
3342 # they have to be very careful.  consider:
3343 # - the first open gets a {0,EOF}PR lock
3344 # - the first write conflicts and gets a {0, count-1}PW
3345 # - the rest of the writes are under {count,EOF}PW
3346 # - the open for truncate tries to match a {0,EOF}PR
3347 #   for the filesize and cancels the PWs.
3348 # any number of fixes (don't get {0,EOF} on open, match
3349 # composite locks, do smarter file size management) fix
3350 # this, but for now we want these tests to verify that
3351 # the cancellation with truncate intent works, so we
3352 # start the file with a full-file pw lock to match against
3353 # until the truncate.
3354 trunc_test() {
3355         test=$1
3356         file=$DIR/$test
3357         offset=$2
3358         cancel_lru_locks osc
3359         stop_writeback
3360         # prime the file with 0,EOF PW to match
3361         touch $file
3362         $TRUNCATE $file 0
3363         sync; sync
3364         # now the real test..
3365         dd if=/dev/zero of=$file bs=1024 count=100
3366         BEFOREWRITES=`count_ost_writes`
3367         $TRUNCATE $file $offset
3368         cancel_lru_locks osc
3369         AFTERWRITES=`count_ost_writes`
3370         start_writeback
3371 }
3372
3373 test_42c() {
3374         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3375         trunc_test 42c 1024
3376         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3377             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3378         rm $file
3379 }
3380 run_test 42c "test partial truncate of file with cached dirty data"
3381
3382 test_42d() {
3383         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3384         trunc_test 42d 0
3385         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3386             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3387         rm $file
3388 }
3389 run_test 42d "test complete truncate of file with cached dirty data"
3390
3391 test_42e() { # bug22074
3392         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3393         local TDIR=$DIR/${tdir}e
3394         local pagesz=$(page_size)
3395         local pages=16 # hardcoded 16 pages, don't change it.
3396         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3397         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3398         local max_dirty_mb
3399         local warmup_files
3400
3401         test_mkdir -p $DIR/${tdir}e
3402         $SETSTRIPE -c 1 $TDIR
3403         createmany -o $TDIR/f $files
3404
3405         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3406
3407         # we assume that with $OSTCOUNT files, at least one of them will
3408         # be allocated on OST0.
3409         warmup_files=$((OSTCOUNT * max_dirty_mb))
3410         createmany -o $TDIR/w $warmup_files
3411
3412         # write a large amount of data into one file and sync, to get good
3413         # avail_grant number from OST.
3414         for ((i=0; i<$warmup_files; i++)); do
3415                 idx=$($GETSTRIPE -i $TDIR/w$i)
3416                 [ $idx -ne 0 ] && continue
3417                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3418                 break
3419         done
3420         [ $i -gt $warmup_files ] && error "OST0 is still cold"
3421         sync
3422         $LCTL get_param $proc_osc0/cur_dirty_bytes
3423         $LCTL get_param $proc_osc0/cur_grant_bytes
3424
3425         # create as much dirty pages as we can while not to trigger the actual
3426         # RPCs directly. but depends on the env, VFS may trigger flush during this
3427         # period, hopefully we are good.
3428         for ((i=0; i<$warmup_files; i++)); do
3429                 idx=$($GETSTRIPE -i $TDIR/w$i)
3430                 [ $idx -ne 0 ] && continue
3431                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3432         done
3433         $LCTL get_param $proc_osc0/cur_dirty_bytes
3434         $LCTL get_param $proc_osc0/cur_grant_bytes
3435
3436         # perform the real test
3437         $LCTL set_param $proc_osc0/rpc_stats 0
3438         for ((;i<$files; i++)); do
3439                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3440                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3441         done
3442         sync
3443         $LCTL get_param $proc_osc0/rpc_stats
3444
3445         local percent=0
3446         local have_ppr=false
3447         $LCTL get_param $proc_osc0/rpc_stats |
3448                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3449                         # skip lines until we are at the RPC histogram data
3450                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3451                         $have_ppr || continue
3452
3453                         # we only want the percent stat for < 16 pages
3454                         [ $(echo $PPR | tr -d ':') -ge $pages ] && break
3455
3456                         percent=$((percent + WPCT))
3457                         if [ $percent -gt 15 ]; then
3458                                 error "less than 16-pages write RPCs" \
3459                                       "$percent% > 15%"
3460                                 break
3461                         fi
3462                 done
3463         rm -rf $TDIR
3464 }
3465 run_test 42e "verify sub-RPC writes are not done synchronously"
3466
3467 test_43() {
3468         test_mkdir -p $DIR/$tdir
3469         cp -p /bin/ls $DIR/$tdir/$tfile
3470         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3471         pid=$!
3472         # give multiop a chance to open
3473         sleep 1
3474
3475         $DIR/$tdir/$tfile && error || true
3476         kill -USR1 $pid
3477 }
3478 run_test 43 "execution of file opened for write should return -ETXTBSY"
3479
3480 test_43a() {
3481         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3482         test_mkdir -p $DIR/$tdir
3483         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3484                         cp -p multiop $DIR/$tdir/multiop
3485         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3486                         return 1
3487         MULTIOP_PID=$!
3488         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3489         kill -USR1 $MULTIOP_PID || return 2
3490         wait $MULTIOP_PID || return 3
3491         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3492 }
3493 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3494
3495 test_43b() {
3496         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3497         test_mkdir -p $DIR/$tdir
3498         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3499                         cp -p multiop $DIR/$tdir/multiop
3500         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3501                         return 1
3502         MULTIOP_PID=$!
3503         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3504         kill -USR1 $MULTIOP_PID || return 2
3505         wait $MULTIOP_PID || return 3
3506         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3507 }
3508 run_test 43b "truncate of file being executed should return -ETXTBSY"
3509
3510 test_43c() {
3511         local testdir="$DIR/$tdir"
3512         test_mkdir -p $DIR/$tdir
3513         cp $SHELL $testdir/
3514         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3515                 ( cd $testdir && md5sum -c)
3516 }
3517 run_test 43c "md5sum of copy into lustre========================"
3518
3519 test_44() {
3520         [  "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
3521         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3522         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3523 }
3524 run_test 44 "zero length read from a sparse stripe ============="
3525
3526 test_44a() {
3527     local nstripe=`$LCTL lov_getconfig $DIR | grep default_stripe_count: | \
3528                          awk '{print $2}'`
3529     [ -z "$nstripe" ] && skip "can't get stripe info" && return
3530     [ "$nstripe" -gt "$OSTCOUNT" ] && skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" && return
3531     local stride=`$LCTL lov_getconfig $DIR | grep default_stripe_size: | \
3532                       awk '{print $2}'`
3533     if [ $nstripe -eq 0 -o $nstripe -eq -1 ] ; then
3534         nstripe=`$LCTL lov_getconfig $DIR | grep obd_count: | awk '{print $2}'`
3535     fi
3536
3537     OFFSETS="0 $((stride/2)) $((stride-1))"
3538     for offset in $OFFSETS ; do
3539       for i in `seq 0 $((nstripe-1))`; do
3540         local GLOBALOFFSETS=""
3541         local size=$((((i + 2 * $nstripe )*$stride + $offset)))  # Bytes
3542         local myfn=$DIR/d44a-$size
3543         echo "--------writing $myfn at $size"
3544         ll_sparseness_write $myfn $size  || error "ll_sparseness_write"
3545         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3546         ll_sparseness_verify $myfn $GLOBALOFFSETS \
3547                             || error "ll_sparseness_verify $GLOBALOFFSETS"
3548
3549         for j in `seq 0 $((nstripe-1))`; do
3550             size=$((((j + $nstripe )*$stride + $offset)))  # Bytes
3551             ll_sparseness_write $myfn $size || error "ll_sparseness_write"
3552             GLOBALOFFSETS="$GLOBALOFFSETS $size"
3553         done
3554         ll_sparseness_verify $myfn $GLOBALOFFSETS \
3555                             || error "ll_sparseness_verify $GLOBALOFFSETS"
3556         rm -f $myfn
3557       done
3558     done
3559 }
3560 run_test 44a "test sparse pwrite ==============================="
3561
3562 dirty_osc_total() {
3563         tot=0
3564         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3565                 tot=$(($tot + $d))
3566         done
3567         echo $tot
3568 }
3569 do_dirty_record() {
3570         before=`dirty_osc_total`
3571         echo executing "\"$*\""
3572         eval $*
3573         after=`dirty_osc_total`
3574         echo before $before, after $after
3575 }
3576 test_45() {
3577         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3578         f="$DIR/f45"
3579         # Obtain grants from OST if it supports it
3580         echo blah > ${f}_grant
3581         stop_writeback
3582         sync
3583         do_dirty_record "echo blah > $f"
3584         [ $before -eq $after ] && error "write wasn't cached"
3585         do_dirty_record "> $f"
3586         [ $before -gt $after ] || error "truncate didn't lower dirty count"
3587         do_dirty_record "echo blah > $f"
3588         [ $before -eq $after ] && error "write wasn't cached"
3589         do_dirty_record "sync"
3590         [ $before -gt $after ] || error "writeback didn't lower dirty count"
3591         do_dirty_record "echo blah > $f"
3592         [ $before -eq $after ] && error "write wasn't cached"
3593         do_dirty_record "cancel_lru_locks osc"
3594         [ $before -gt $after ] || error "lock cancellation didn't lower dirty count"
3595         start_writeback
3596 }
3597 run_test 45 "osc io page accounting ============================"
3598
3599 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3600 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3601 # objects offset and an assert hit when an rpc was built with 1023's mapped
3602 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3603 test_46() {
3604         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3605         f="$DIR/f46"
3606         stop_writeback
3607         sync
3608         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3609         sync
3610         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3611         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3612         sync
3613         start_writeback
3614 }
3615 run_test 46 "dirtying a previously written page ================"
3616
3617 # test_47 is removed "Device nodes check" is moved to test_28
3618
3619 test_48a() { # bug 2399
3620         check_kernel_version 34 || return 0
3621         test_mkdir -p $DIR/$tdir
3622         cd $DIR/$tdir
3623         mv $DIR/$tdir $DIR/d48.new || error "move directory failed"
3624         test_mkdir $DIR/$tdir || error "recreate directory failed"
3625         touch foo || error "'touch foo' failed after recreating cwd"
3626         test_mkdir $DIR/$tdir/bar ||
3627                      error "'mkdir foo' failed after recreating cwd"
3628         if check_kernel_version 44; then
3629                 touch .foo || error "'touch .foo' failed after recreating cwd"
3630                 test_mkdir $DIR/$tdir/.bar ||
3631                               error "'mkdir .foo' failed after recreating cwd"
3632         fi
3633         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3634         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3635         cd . || error "'cd .' failed after recreating cwd"
3636         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3637         rmdir . && error "'rmdir .' worked after recreating cwd"
3638         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3639         cd .. || error "'cd ..' failed after recreating cwd"
3640 }
3641 run_test 48a "Access renamed working dir (should return errors)="
3642
3643 test_48b() { # bug 2399
3644         check_kernel_version 34 || return 0
3645         rm -rf $DIR/$tdir
3646         test_mkdir -p $DIR/$tdir
3647         cd $DIR/$tdir
3648         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3649         touch foo && error "'touch foo' worked after removing cwd"
3650         test_mkdir $DIR/$tdir/foo &&
3651                      error "'mkdir foo' worked after removing cwd"
3652         if check_kernel_version 44; then
3653                 touch .foo && error "'touch .foo' worked after removing cwd"
3654                 test_mkdir $DIR/$tdir/.foo &&
3655                               error "'mkdir .foo' worked after removing cwd"
3656         fi
3657         ls . > /dev/null && error "'ls .' worked after removing cwd"
3658         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3659         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3660         test_mkdir $DIR/$tdir/. && error "'mkdir .' worked after removing cwd"
3661         rmdir . && error "'rmdir .' worked after removing cwd"
3662         ln -s . foo && error "'ln -s .' worked after removing cwd"
3663         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3664 }
3665 run_test 48b "Access removed working dir (should return errors)="
3666
3667 test_48c() { # bug 2350
3668         check_kernel_version 36 || return 0
3669         #lctl set_param debug=-1
3670         #set -vx
3671         rm -rf $DIR/$tdir
3672         test_mkdir -p $DIR/$tdir/dir
3673         cd $DIR/$tdir/dir
3674         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3675         $TRACE touch foo && error "touch foo worked after removing cwd"
3676         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3677         if check_kernel_version 44; then
3678                 touch .foo && error "touch .foo worked after removing cwd"
3679                 test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3680         fi
3681         $TRACE ls . && error "'ls .' worked after removing cwd"
3682         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3683         is_patchless || ( $TRACE cd . &&
3684                         error "'cd .' worked after removing cwd" )
3685         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3686         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3687         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3688         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3689 }
3690 run_test 48c "Access removed working subdir (should return errors)"
3691
3692 test_48d() { # bug 2350
3693         check_kernel_version 36 || return 0
3694         #lctl set_param debug=-1
3695         #set -vx
3696         rm -rf $DIR/$tdir
3697         test_mkdir -p $DIR/$tdir/dir
3698         cd $DIR/$tdir/dir
3699         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3700         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3701         $TRACE touch foo && error "'touch foo' worked after removing parent"
3702         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3703         if check_kernel_version 44; then
3704                 touch .foo && error "'touch .foo' worked after removing parent"
3705                 test_mkdir .foo &&
3706                               error "mkdir .foo worked after removing parent"
3707         fi
3708         $TRACE ls . && error "'ls .' worked after removing parent"
3709         $TRACE ls .. && error "'ls ..' worked after removing parent"
3710         is_patchless || ( $TRACE cd . &&
3711                         error "'cd .' worked after recreate parent" )
3712         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3713         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3714         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3715         is_patchless || ( $TRACE cd .. &&
3716                         error "'cd ..' worked after removing parent" || true )
3717 }
3718 run_test 48d "Access removed parent subdir (should return errors)"
3719
3720 test_48e() { # bug 4134
3721         check_kernel_version 41 || return 0
3722         #lctl set_param debug=-1
3723         #set -vx
3724         rm -rf $DIR/$tdir
3725         test_mkdir -p $DIR/$tdir/dir
3726         cd $DIR/$tdir/dir
3727         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3728         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3729         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3730         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3731         # On a buggy kernel addition of "touch foo" after cd .. will
3732         # produce kernel oops in lookup_hash_it
3733         touch ../foo && error "'cd ..' worked after recreate parent"
3734         cd $DIR
3735         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3736 }
3737 run_test 48e "Access to recreated parent subdir (should return errors)"
3738
3739 test_49() { # LU-1030
3740         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3741         # get ost1 size - lustre-OST0000
3742         ost1_size=$(do_facet ost1 lfs df |grep ${ost1_svc} |awk '{print $4}')
3743         # write 800M at maximum
3744         [ $ost1_size -gt 819200 ] && ost1_size=819200
3745
3746         lfs setstripe -c 1 -i 0 $DIR/$tfile
3747         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3748         local dd_pid=$!
3749
3750         # change max_pages_per_rpc while writing the file
3751         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3752         local orig_mppc=`$LCTL get_param -n $osc1_mppc`
3753         # loop until dd process exits
3754         while ps ax -opid | grep -wq $dd_pid; do
3755                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3756                 sleep $((RANDOM % 5 + 1))
3757         done
3758         # restore original max_pages_per_rpc
3759         $LCTL set_param $osc1_mppc=$orig_mppc
3760         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3761 }
3762 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3763
3764 test_50() {
3765         # bug 1485
3766         test_mkdir $DIR/$tdir
3767         cd $DIR/$tdir
3768         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3769 }
3770 run_test 50 "special situations: /proc symlinks  ==============="
3771
3772 test_51a() {    # was test_51
3773         # bug 1516 - create an empty entry right after ".." then split dir
3774         test_mkdir -p $DIR/$tdir
3775         touch $DIR/$tdir/foo
3776         $MCREATE $DIR/$tdir/bar
3777         rm $DIR/$tdir/foo
3778         createmany -m $DIR/$tdir/longfile 201
3779         FNUM=202
3780         while [ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]; do
3781                 $MCREATE $DIR/$tdir/longfile$FNUM
3782                 FNUM=$(($FNUM + 1))
3783                 echo -n "+"
3784         done
3785         echo
3786         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
3787 }
3788 run_test 51a "special situations: split htree with empty entry =="
3789
3790 export NUMTEST=70000
3791 test_51b() {
3792         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3793         local BASE=$DIR/d${base}.${TESTSUITE}
3794
3795         # cleanup the directory
3796         rm -fr $BASE
3797
3798         test_mkdir -p $BASE
3799
3800         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
3801         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
3802         [ $numfree -lt 21000 ] && skip "not enough free inodes ($numfree)" &&
3803                 return
3804
3805         [ $numfree -lt $NUMTEST ] && NUMTEST=$(($numfree - 50)) &&
3806                 echo "reduced count to $NUMTEST due to inodes"
3807
3808         # need to check free space for the directories as well
3809         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
3810         numfree=$((blkfree / 4))
3811         [ $numfree -lt $NUMTEST ] && NUMTEST=$(($numfree - 50)) &&
3812                 echo "reduced count to $NUMTEST due to blocks"
3813
3814         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
3815                 echo "failed" > $BASE/fnum
3816 }
3817 run_test 51b "exceed 64k subdirectory nlink limit"
3818
3819 test_51ba() { # LU-993
3820         local BASE=$DIR/d${base}.${TESTSUITE}
3821         # unlink all but 100 subdirectories, then check it still works
3822         local LEFT=100
3823         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
3824
3825         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
3826         local DELETE=$((NUMTEST - LEFT))
3827
3828         # continue on to run this test even if 51b didn't finish,
3829         # just to delete the many subdirectories created.
3830         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
3831
3832         # for ldiskfs the nlink count should be 1, but this is OSD specific
3833         # and so this is listed for informational purposes only
3834         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
3835         unlinkmany -d $BASE/d $DELETE
3836         RC=$?
3837
3838         if [ $RC -ne 0 ]; then
3839                 if [ "$NUMPREV" == "failed" ]; then
3840                         skip "previous setup failed"
3841                         return 0
3842                 else
3843                         error "unlink of first $DELETE subdirs failed"
3844                         return $RC
3845                 fi
3846         fi
3847
3848         echo "nlink between: $(stat -c %h $BASE)"
3849         # trim the first line of ls output
3850         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
3851         [ $FOUND -ne $LEFT ] &&
3852                 error "can't find subdirs: found only $FOUND/$LEFT"
3853
3854         unlinkmany -d $BASE/d $DELETE $LEFT ||
3855                 error "unlink of second $LEFT subdirs failed"
3856         # regardless of whether the backing filesystem tracks nlink accurately
3857         # or not, the nlink count shouldn't be more than "." and ".." here
3858         local AFTER=$(stat -c %h $BASE)
3859         [ $AFTER -gt 2 ] && error "nlink after: $AFTER > 2" ||
3860                 echo "nlink after: $AFTER"
3861 }
3862 run_test 51ba "verify nlink for many subdirectory cleanup"
3863
3864 test_51d() {
3865         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3866         [  "$OSTCOUNT" -lt "3" ] && skip_env "skipping test with few OSTs" && return
3867         test_mkdir -p $DIR/$tdir
3868         createmany -o $DIR/$tdir/t- 1000
3869         $GETSTRIPE $DIR/$tdir > $TMP/files
3870         for N in `seq 0 $((OSTCOUNT - 1))`; do
3871             OBJS[$N]=`awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}' $TMP/files`
3872             OBJS0[$N]=`grep -A 1 idx $TMP/files | awk -vobjs=0 '($1 == '$N') { objs += 1 } END { print objs;}'`
3873             log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
3874         done
3875         unlinkmany $DIR/$tdir/t- 1000
3876
3877         NLAST=0
3878         for N in `seq 1 $((OSTCOUNT - 1))`; do
3879             [ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ] && \
3880                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3881             [ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ] && \
3882                 error "OST $N has less objects vs OST $NLAST (${OBJS[$N]} < ${OBJS[$NLAST]}"
3883
3884             [ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ] && \
3885                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3886             [ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ] && \
3887                 error "OST $N has less #0 objects vs OST $NLAST (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
3888             NLAST=$N
3889         done
3890 }
3891 run_test 51d "check object distribution ===================="
3892
3893 test_52a() {
3894         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
3895         test_mkdir -p $DIR/$tdir
3896         touch $DIR/$tdir/foo
3897         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
3898         echo bar >> $DIR/$tdir/foo || error "append bar failed"
3899         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
3900         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
3901         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
3902                                         error "link worked"
3903         echo foo >> $DIR/$tdir/foo || error "append foo failed"
3904         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
3905         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
3906                                                      error "lsattr"
3907         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
3908         cp -r $DIR/$tdir /tmp/
3909         rm -fr $DIR/$tdir || error "cleanup rm failed"
3910 }
3911 run_test 52a "append-only flag test (should return errors) ====="
3912
3913 test_52b() {
3914         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
3915         test_mkdir -p $DIR/$tdir
3916         touch $DIR/$tdir/foo
3917         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
3918         cat test > $DIR/$tdir/foo && error "cat test worked"
3919         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
3920         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
3921         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
3922                                         error "link worked"
3923         echo foo >> $DIR/$tdir/foo && error "echo worked"
3924         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
3925         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
3926         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
3927         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
3928                                                         error "lsattr"
3929         chattr -i $DIR/$tdir/foo || error "chattr failed"
3930
3931         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
3932 }
3933 run_test 52b "immutable flag test (should return errors) ======="
3934
3935 test_53() {
3936         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3937         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3938         remote_ost_nodsh && skip "remote OST with nodsh" && return
3939
3940         local param
3941         local param_seq
3942         local ostname
3943         local mds_last
3944         local mds_last_seq
3945         local ost_last
3946         local ost_last_seq
3947         local ost_last_id
3948         local ostnum
3949         local node
3950         local found=false
3951         local support_last_seq=true
3952
3953         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
3954                 support_last_seq=false
3955
3956         # only test MDT0000
3957         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
3958         local value
3959         for value in $(do_facet $SINGLEMDS \
3960                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
3961                 param=$(echo ${value[0]} | cut -d "=" -f1)
3962                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
3963
3964                 if $support_last_seq; then
3965                         param_seq=$(echo $param |
3966                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
3967                         mds_last_seq=$(do_facet $SINGLEMDS \
3968                                        $LCTL get_param -n $param_seq)
3969                 fi
3970                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
3971
3972                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
3973                 node=$(facet_active_host ost$((ostnum+1)))
3974                 param="obdfilter.$ostname.last_id"
3975                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
3976                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
3977                         ost_last_id=$ost_last
3978
3979                         if $support_last_seq; then
3980                                 ost_last_id=$(echo $ost_last |
3981                                               awk -F':' '{print $2}' |
3982                                               sed -e "s/^0x//g")
3983                                 ost_last_seq=$(echo $ost_last |
3984                                                awk -F':' '{print $1}')
3985                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
3986                         fi
3987
3988                         if [[ $ost_last_id != $mds_last ]]; then
3989                                 error "$ost_last_id != $mds_last"
3990                         else
3991                                 found=true
3992                                 break
3993                         fi
3994                 done
3995         done
3996         $found || error "can not match last_seq/last_id for $mdtosc"
3997         return 0
3998 }
3999 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4000
4001 test_54a() {
4002         $SOCKETSERVER $DIR/socket ||
4003                 error "$SOCKETSERVER $DIR/socket failed: $?"
4004         $SOCKETCLIENT $DIR/socket ||
4005                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4006         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4007 }
4008 run_test 54a "unix domain socket test =========================="
4009
4010 test_54b() {
4011         f="$DIR/f54b"
4012         mknod $f c 1 3
4013         chmod 0666 $f
4014         dd if=/dev/zero of=$f bs=$(page_size) count=1
4015 }
4016 run_test 54b "char device works in lustre ======================"
4017
4018 find_loop_dev() {
4019         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4020         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4021         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4022
4023         for i in $(seq 3 7); do
4024                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4025                 LOOPDEV=$LOOPBASE$i
4026                 LOOPNUM=$i
4027                 break
4028         done
4029 }
4030
4031 cleanup_54c() {
4032         loopdev="$DIR/loop54c"
4033
4034         trap 0
4035         $UMOUNT -d $tdir || rc=$?
4036         losetup -d $loopdev || true
4037         rm $loopdev
4038         return $rc
4039 }
4040
4041 test_54c() {
4042         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4043         tfile="$DIR/f54c"
4044         tdir="$DIR/d54c"
4045         loopdev="$DIR/loop54c"
4046
4047         find_loop_dev
4048         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4049         mknod $loopdev b 7 $LOOPNUM
4050         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
4051         dd if=/dev/zero of=$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4052         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
4053         trap cleanup_54c EXIT
4054         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4055         test_mkdir -p $tdir
4056         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
4057         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
4058         df $tdir
4059         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
4060         cleanup_54c
4061 }
4062 run_test 54c "block device works in lustre ====================="
4063
4064 test_54d() {
4065         f="$DIR/f54d"
4066         string="aaaaaa"
4067         mknod $f p
4068         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4069 }
4070 run_test 54d "fifo device works in lustre ======================"
4071
4072 test_54e() {
4073         check_kernel_version 46 || return 0
4074         f="$DIR/f54e"
4075         string="aaaaaa"
4076         cp -aL /dev/console $f
4077         echo $string > $f || error "echo $string to $f failed"
4078 }
4079 run_test 54e "console/tty device works in lustre ======================"
4080
4081 #The test_55 used to be iopen test and it was removed by bz#24037.
4082 #run_test 55 "check iopen_connect_dentry() ======================"
4083
4084 test_56a() {    # was test_56
4085         rm -rf $DIR/$tdir
4086         $SETSTRIPE -d $DIR
4087         test_mkdir -p $DIR/$tdir/dir
4088         NUMFILES=3
4089         NUMFILESx2=$(($NUMFILES * 2))
4090         for i in `seq 1 $NUMFILES` ; do
4091                 touch $DIR/$tdir/file$i
4092                 touch $DIR/$tdir/dir/file$i
4093         done
4094
4095         # test lfs getstripe with --recursive
4096         FILENUM=`$GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx`
4097         [ $FILENUM -eq $NUMFILESx2 ] ||
4098                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4099         FILENUM=`$GETSTRIPE $DIR/$tdir | grep -c obdidx`
4100         [ $FILENUM -eq $NUMFILES ] ||
4101                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4102         echo "$GETSTRIPE --recursive passed."
4103
4104         # test lfs getstripe with file instead of dir
4105         FILENUM=`$GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx`
4106         [ $FILENUM  -eq 1 ] || error \
4107                  "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4108         echo "$GETSTRIPE file1 passed."
4109
4110         #test lfs getstripe with --verbose
4111         [ `$GETSTRIPE --verbose $DIR/$tdir |
4112                         grep -c lmm_magic` -eq $NUMFILES ] ||
4113                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4114         [ `$GETSTRIPE $DIR/$tdir | grep -c lmm_magic` -eq 0 ] ||
4115             error "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4116         echo "$GETSTRIPE --verbose passed."
4117
4118         #test lfs getstripe with --obd
4119         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4120                                         grep -q "unknown obduuid" ||
4121                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4122
4123         [  "$OSTCOUNT" -lt 2 ] &&
4124                 skip_env "skipping other $GETSTRIPE --obd test" && return
4125
4126         OSTIDX=1
4127         OBDUUID=$(ostuuid_from_index $OSTIDX)
4128         FILENUM=`$GETSTRIPE -ir $DIR/$tdir | grep -x $OSTIDX | wc -l`
4129         FOUND=`$GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l`
4130         [ $FOUND -eq $FILENUM ] ||
4131                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4132         [ `$GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4133                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4134                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l` -eq 0 ] ||
4135                 error "$GETSTRIPE --obd: should not show file on other obd"
4136         echo "$GETSTRIPE --obd passed"
4137 }
4138 run_test 56a "check $GETSTRIPE"
4139
4140 NUMFILES=3
4141 NUMDIRS=3
4142 setup_56() {
4143         local LOCAL_NUMFILES="$1"
4144         local LOCAL_NUMDIRS="$2"
4145         local MKDIR_PARAMS="$3"
4146         local DIR_STRIPE_PARAMS="$4"
4147
4148         if [ ! -d "$TDIR" ] ; then
4149                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4150                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4151                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4152                         touch $TDIR/file$i
4153                 done
4154                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4155                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4156                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4157                                 touch $TDIR/dir$i/file$j
4158                         done
4159                 done
4160         fi
4161 }
4162
4163 setup_56_special() {
4164         LOCAL_NUMFILES=$1
4165         LOCAL_NUMDIRS=$2
4166         setup_56 $1 $2
4167         if [ ! -e "$TDIR/loop1b" ] ; then
4168                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4169                         mknod $TDIR/loop${i}b b 7 $i
4170                         mknod $TDIR/null${i}c c 1 3
4171                         ln -s $TDIR/file1 $TDIR/link${i}l
4172                 done
4173                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4174                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4175                         mknod $TDIR/dir$i/null${i}c c 1 3
4176                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4177                 done
4178         fi
4179 }
4180
4181 test_56g() {
4182         $SETSTRIPE -d $DIR
4183
4184         TDIR=$DIR/${tdir}g
4185         setup_56 $NUMFILES $NUMDIRS
4186
4187         EXPECTED=$(($NUMDIRS + 2))
4188         # test lfs find with -name
4189         for i in $(seq 1 $NUMFILES) ; do
4190                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4191                 [ $NUMS -eq $EXPECTED ] ||
4192                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4193                               "found $NUMS, expected $EXPECTED"
4194         done
4195 }
4196 run_test 56g "check lfs find -name ============================="
4197
4198 test_56h() {
4199         $SETSTRIPE -d $DIR
4200
4201         TDIR=$DIR/${tdir}g
4202         setup_56 $NUMFILES $NUMDIRS
4203
4204         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4205         # test lfs find with ! -name
4206         for i in $(seq 1 $NUMFILES) ; do
4207                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4208                 [ $NUMS -eq $EXPECTED ] ||
4209                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4210                               "found $NUMS, expected $EXPECTED"
4211         done
4212 }
4213 run_test 56h "check lfs find ! -name ============================="
4214
4215 test_56i() {
4216        tdir=${tdir}i
4217        test_mkdir -p $DIR/$tdir
4218        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4219        CMD="$LFIND -ost $UUID $DIR/$tdir"
4220        OUT=$($CMD)
4221        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4222 }
4223 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4224
4225 test_56j() {
4226         TDIR=$DIR/${tdir}g
4227         setup_56_special $NUMFILES $NUMDIRS
4228
4229         EXPECTED=$((NUMDIRS + 1))
4230         CMD="$LFIND -type d $TDIR"
4231         NUMS=$($CMD | wc -l)
4232         [ $NUMS -eq $EXPECTED ] ||
4233                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4234 }
4235 run_test 56j "check lfs find -type d ============================="
4236
4237 test_56k() {
4238         TDIR=$DIR/${tdir}g
4239         setup_56_special $NUMFILES $NUMDIRS
4240
4241         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4242         CMD="$LFIND -type f $TDIR"
4243         NUMS=$($CMD | wc -l)
4244         [ $NUMS -eq $EXPECTED ] ||
4245                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4246 }
4247 run_test 56k "check lfs find -type f ============================="
4248
4249 test_56l() {
4250         TDIR=$DIR/${tdir}g
4251         setup_56_special $NUMFILES $NUMDIRS
4252
4253         EXPECTED=$((NUMDIRS + NUMFILES))
4254         CMD="$LFIND -type b $TDIR"
4255         NUMS=$($CMD | wc -l)
4256         [ $NUMS -eq $EXPECTED ] ||
4257                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4258 }
4259 run_test 56l "check lfs find -type b ============================="
4260
4261 test_56m() {
4262         TDIR=$DIR/${tdir}g
4263         setup_56_special $NUMFILES $NUMDIRS
4264
4265         EXPECTED=$((NUMDIRS + NUMFILES))
4266         CMD="$LFIND -type c $TDIR"
4267         NUMS=$($CMD | wc -l)
4268         [ $NUMS -eq $EXPECTED ] ||
4269                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4270 }
4271 run_test 56m "check lfs find -type c ============================="
4272
4273 test_56n() {
4274         TDIR=$DIR/${tdir}g
4275         setup_56_special $NUMFILES $NUMDIRS
4276
4277         EXPECTED=$((NUMDIRS + NUMFILES))
4278         CMD="$LFIND -type l $TDIR"
4279         NUMS=$($CMD | wc -l)
4280         [ $NUMS -eq $EXPECTED ] ||
4281                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4282 }
4283 run_test 56n "check lfs find -type l ============================="
4284
4285 test_56o() {
4286         TDIR=$DIR/${tdir}o
4287         setup_56 $NUMFILES $NUMDIRS
4288         utime $TDIR/file1 > /dev/null || error "utime (1)"
4289         utime $TDIR/file2 > /dev/null || error "utime (2)"
4290         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4291         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4292         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4293         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4294
4295         EXPECTED=4
4296         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4297         [ $NUMS -eq $EXPECTED ] || \
4298                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4299
4300         EXPECTED=12
4301         CMD="$LFIND -mtime 0 $TDIR"
4302         NUMS=$($CMD | wc -l)
4303         [ $NUMS -eq $EXPECTED ] ||
4304                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4305 }
4306 run_test 56o "check lfs find -mtime for old files =========================="
4307
4308 test_56p() {
4309         [ $RUNAS_ID -eq $UID ] &&
4310                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4311
4312         TDIR=$DIR/${tdir}p
4313         setup_56 $NUMFILES $NUMDIRS
4314
4315         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4316         EXPECTED=$NUMFILES
4317         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4318         NUMS=$($CMD | wc -l)
4319         [ $NUMS -eq $EXPECTED ] || \
4320                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4321
4322         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4323         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4324         NUMS=$($CMD | wc -l)
4325         [ $NUMS -eq $EXPECTED ] || \
4326                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4327 }
4328 run_test 56p "check lfs find -uid and ! -uid ==============================="
4329
4330 test_56q() {
4331         [ $RUNAS_ID -eq $UID ] &&
4332                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4333
4334         TDIR=$DIR/${tdir}q
4335         setup_56 $NUMFILES $NUMDIRS
4336
4337         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4338
4339         EXPECTED=$NUMFILES
4340         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4341         NUMS=$($CMD | wc -l)
4342         [ $NUMS -eq $EXPECTED ] ||
4343                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4344
4345         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4346         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4347         NUMS=$($CMD | wc -l)
4348         [ $NUMS -eq $EXPECTED ] ||
4349                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4350 }
4351 run_test 56q "check lfs find -gid and ! -gid ==============================="
4352
4353 test_56r() {
4354         TDIR=$DIR/${tdir}r
4355         setup_56 $NUMFILES $NUMDIRS
4356
4357         EXPECTED=12
4358         CMD="$LFIND -size 0 -type f $TDIR"
4359         NUMS=$($CMD | wc -l)
4360         [ $NUMS -eq $EXPECTED ] ||
4361                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4362         EXPECTED=0
4363         CMD="$LFIND ! -size 0 -type f $TDIR"
4364         NUMS=$($CMD | wc -l)
4365         [ $NUMS -eq $EXPECTED ] ||
4366                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4367         echo "test" > $TDIR/$tfile
4368         echo "test2" > $TDIR/$tfile.2 && sync
4369         EXPECTED=1
4370         CMD="$LFIND -size 5 -type f $TDIR"
4371         NUMS=$($CMD | wc -l)
4372         [ $NUMS -eq $EXPECTED ] ||
4373                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4374         EXPECTED=1
4375         CMD="$LFIND -size +5 -type f $TDIR"
4376         NUMS=$($CMD | wc -l)
4377         [ $NUMS -eq $EXPECTED ] ||
4378                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4379         EXPECTED=2
4380         CMD="$LFIND -size +0 -type f $TDIR"
4381         NUMS=$($CMD | wc -l)
4382         [ $NUMS -eq $EXPECTED ] ||
4383                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4384         EXPECTED=2
4385         CMD="$LFIND ! -size -5 -type f $TDIR"
4386         NUMS=$($CMD | wc -l)
4387         [ $NUMS -eq $EXPECTED ] ||
4388                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4389         EXPECTED=12
4390         CMD="$LFIND -size -5 -type f $TDIR"
4391         NUMS=$($CMD | wc -l)
4392         [ $NUMS -eq $EXPECTED ] ||
4393                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4394 }
4395 run_test 56r "check lfs find -size works =========================="
4396
4397 test_56s() { # LU-611
4398         TDIR=$DIR/${tdir}s
4399         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4400
4401         if [ $OSTCOUNT -gt 1 ]; then
4402                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4403                 ONESTRIPE=4
4404                 EXTRA=4
4405         else
4406                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4407                 EXTRA=0
4408         fi
4409
4410         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4411         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4412         NUMS=$($CMD | wc -l)
4413         [ $NUMS -eq $EXPECTED ] ||
4414                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4415
4416         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4417         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4418         NUMS=$($CMD | wc -l)
4419         [ $NUMS -eq $EXPECTED ] ||
4420                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4421
4422         EXPECTED=$ONESTRIPE
4423         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4424         NUMS=$($CMD | wc -l)
4425         [ $NUMS -eq $EXPECTED ] ||
4426                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4427
4428         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4429         NUMS=$($CMD | wc -l)
4430         [ $NUMS -eq $EXPECTED ] ||
4431                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4432
4433         EXPECTED=0
4434         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4435         NUMS=$($CMD | wc -l)
4436         [ $NUMS -eq $EXPECTED ] ||
4437                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4438 }
4439 run_test 56s "check lfs find -stripe-count works"
4440
4441 test_56t() { # LU-611
4442         TDIR=$DIR/${tdir}t
4443         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4444
4445         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4446
4447         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4448         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4449         NUMS=$($CMD | wc -l)
4450         [ $NUMS -eq $EXPECTED ] ||
4451                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4452
4453         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4454         NUMS=$($CMD | wc -l)
4455         [ $NUMS -eq $EXPECTED ] ||
4456                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4457
4458         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4459         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4460         NUMS=$($CMD | wc -l)
4461         [ $NUMS -eq $EXPECTED ] ||
4462                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4463
4464         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4465         NUMS=$($CMD | wc -l)
4466         [ $NUMS -eq $EXPECTED ] ||
4467                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4468
4469         EXPECTED=4
4470         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4471         NUMS=$($CMD | wc -l)
4472         [ $NUMS -eq $EXPECTED ] ||
4473                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4474
4475         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4476         NUMS=$($CMD | wc -l)
4477         [ $NUMS -eq $EXPECTED ] ||
4478                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4479
4480         EXPECTED=0
4481         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4482         NUMS=$($CMD | wc -l)
4483         [ $NUMS -eq $EXPECTED ] ||
4484                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4485 }
4486 run_test 56t "check lfs find -stripe-size works"
4487
4488 test_56u() { # LU-611
4489         TDIR=$DIR/${tdir}u
4490         setup_56 $NUMFILES $NUMDIRS "-i 0"
4491
4492         if [ $OSTCOUNT -gt 1 ]; then
4493                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4494                 ONESTRIPE=4
4495         else
4496                 ONESTRIPE=0
4497         fi
4498
4499         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4500         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4501         NUMS=$($CMD | wc -l)
4502         [ $NUMS -eq $EXPECTED ] ||
4503                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4504
4505         EXPECTED=$ONESTRIPE
4506         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4507         NUMS=$($CMD | wc -l)
4508         [ $NUMS -eq $EXPECTED ] ||
4509                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4510
4511         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4512         NUMS=$($CMD | wc -l)
4513         [ $NUMS -eq $EXPECTED ] ||
4514                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4515
4516         EXPECTED=0
4517         # This should produce an error and not return any files
4518         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4519         NUMS=$($CMD 2>/dev/null | wc -l)
4520         [ $NUMS -eq $EXPECTED ] ||
4521                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4522
4523         if [ $OSTCOUNT -gt 1 ]; then
4524                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4525                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4526                 NUMS=$($CMD | wc -l)
4527                 [ $NUMS -eq $EXPECTED ] ||
4528                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4529         fi
4530 }
4531 run_test 56u "check lfs find -stripe-index works"
4532
4533 test_56v() {
4534     local MDT_IDX=0
4535
4536     TDIR=$DIR/${tdir}v
4537     rm -rf $TDIR
4538     setup_56 $NUMFILES $NUMDIRS
4539
4540     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4541     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4542
4543     for file in $($LFIND -mdt $UUID $TDIR); do
4544         file_mdt_idx=$($GETSTRIPE -M $file)
4545         [ $file_mdt_idx -eq $MDT_IDX ] ||
4546             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4547     done
4548 }
4549 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4550
4551 # Get and check the actual stripe count of one file.
4552 # Usage: check_stripe_count <file> <expected_stripe_count>
4553 check_stripe_count() {
4554     local file=$1
4555     local expected=$2
4556     local actual
4557
4558     [[ -z "$file" || -z "$expected" ]] &&
4559         error "check_stripe_count: invalid argument!"
4560
4561     local cmd="$GETSTRIPE -c $file"
4562     actual=$($cmd) || error "$cmd failed"
4563     actual=${actual%% *}
4564
4565     if [[ $actual -ne $expected ]]; then
4566         [[ $expected -eq -1 ]] ||
4567             error "$cmd wrong: found $actual, expected $expected"
4568         [[ $actual -eq $OSTCOUNT ]] ||
4569             error "$cmd wrong: found $actual, expected $OSTCOUNT"
4570     fi
4571 }
4572
4573 test_56w() {
4574         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4575         TDIR=$DIR/${tdir}w
4576
4577     rm -rf $TDIR || error "remove $TDIR failed"
4578     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4579
4580     local stripe_size
4581     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4582         error "$GETSTRIPE -S -d $TDIR failed"
4583     stripe_size=${stripe_size%% *}
4584
4585     local file_size=$((stripe_size * OSTCOUNT))
4586     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4587     local required_space=$((file_num * file_size))
4588     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4589     [[ $free_space -le $((required_space / 1024)) ]] &&
4590         skip_env "need at least $required_space bytes free space," \
4591                  "have $free_space kbytes" && return
4592
4593     local dd_bs=65536
4594     local dd_count=$((file_size / dd_bs))
4595
4596     # write data into the files
4597     local i
4598     local j
4599     local file
4600     for i in $(seq 1 $NUMFILES); do
4601         file=$TDIR/file$i
4602         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4603             error "write data into $file failed"
4604     done
4605     for i in $(seq 1 $NUMDIRS); do
4606         for j in $(seq 1 $NUMFILES); do
4607             file=$TDIR/dir$i/file$j
4608             yes | dd bs=$dd_bs count=$dd_count of=$file \
4609                 >/dev/null 2>&1 ||
4610                 error "write data into $file failed"
4611         done
4612     done
4613
4614     local expected=-1
4615     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4616
4617     # lfs_migrate file
4618     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4619     echo "$cmd"
4620     eval $cmd || error "$cmd failed"
4621
4622     check_stripe_count $TDIR/file1 $expected
4623
4624     # lfs_migrate dir
4625     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4626     echo "$cmd"
4627     eval $cmd || error "$cmd failed"
4628
4629     for j in $(seq 1 $NUMFILES); do
4630         check_stripe_count $TDIR/dir1/file$j $expected
4631     done
4632
4633     # lfs_migrate works with lfs find
4634     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4635          $LFS_MIGRATE -y -c $expected"
4636     echo "$cmd"
4637     eval $cmd || error "$cmd failed"
4638
4639     for i in $(seq 2 $NUMFILES); do
4640         check_stripe_count $TDIR/file$i $expected
4641     done
4642     for i in $(seq 2 $NUMDIRS); do
4643         for j in $(seq 1 $NUMFILES); do
4644             check_stripe_count $TDIR/dir$i/file$j $expected
4645         done
4646     done
4647 }
4648 run_test 56w "check lfs_migrate -c stripe_count works"
4649
4650 test_56x() {
4651         check_swap_layouts_support && return 0
4652         [ "$OSTCOUNT" -lt "2" ] &&
4653                 skip_env "need 2 OST, skipping test" && return
4654
4655         local dir0=$DIR/$tdir/$testnum
4656         mkdir -p $dir0 || error "creating dir $dir0"
4657
4658         local ref1=/etc/passwd
4659         local file1=$dir0/file1
4660
4661         $SETSTRIPE -c 2 $file1
4662         cp $ref1 $file1
4663         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4664         stripe=$($GETSTRIPE -c $file1)
4665         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4666         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4667
4668         # clean up
4669         rm -f $file1
4670 }
4671 run_test 56x "lfs migration support"
4672
4673 test_56y() {
4674         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4675                 skip "No HSM support on MDS of $(get_lustre_version)," \
4676                          "need 2.4.53 at least" && return
4677         local res=""
4678
4679         local dir0=$DIR/$tdir/$testnum
4680         mkdir -p $dir0 || error "creating dir $dir0"
4681         local f1=$dir0/file1
4682         local f2=$dir0/file2
4683
4684         touch $f1 || error "creating std file $f1"
4685         $MULTIOP $f2 H2c || error "creating released file $f2"
4686
4687         # a directory can be raid0, so ask only for files
4688         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4689         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4690
4691         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4692         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4693
4694         # only files can be released, so no need to force file search
4695         res=$($LFIND $dir0 -L released)
4696         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4697
4698         res=$($LFIND $dir0 \! -L released)
4699         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4700
4701 }
4702 run_test 56y "lfs find -L raid0|released"
4703
4704 test_57a() {
4705         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4706         # note test will not do anything if MDS is not local
4707         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4708                 skip "Only applicable to ldiskfs-based MDTs"
4709                 return
4710         fi
4711
4712         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4713         local MNTDEV="osd*.*MDT*.mntdev"
4714         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
4715         [ -z "$DEV" ] && error "can't access $MNTDEV"
4716         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
4717                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
4718                         error "can't access $DEV"
4719                 DEVISIZE=`awk '/Inode size:/ { print $3 }' $TMP/t57a.dump`
4720                 [ "$DEVISIZE" -gt 128 ] || error "inode size $DEVISIZE"
4721                 rm $TMP/t57a.dump
4722         done
4723 }
4724 run_test 57a "verify MDS filesystem created with large inodes =="
4725
4726 test_57b() {
4727         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4728         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4729                 skip "Only applicable to ldiskfs-based MDTs"
4730                 return
4731         fi
4732
4733         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4734         local dir=$DIR/d57b
4735
4736         local FILECOUNT=100
4737         local FILE1=$dir/f1
4738         local FILEN=$dir/f$FILECOUNT
4739
4740         rm -rf $dir || error "removing $dir"
4741         test_mkdir -p $dir || error "creating $dir"
4742         local num=$(get_mds_dir $dir)
4743         local mymds=mds$num
4744
4745         echo "mcreating $FILECOUNT files"
4746         createmany -m $dir/f 1 $FILECOUNT || \
4747                 error "creating files in $dir"
4748
4749         # verify that files do not have EAs yet
4750         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
4751         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
4752
4753         sync
4754         sleep 1
4755         df $dir  #make sure we get new statfs data
4756         local MDSFREE=$(do_facet $mymds \
4757                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4758         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4759         echo "opening files to create objects/EAs"
4760         local FILE
4761         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
4762                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
4763         done
4764
4765         # verify that files have EAs now
4766         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
4767         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
4768
4769         sleep 1  #make sure we get new statfs data
4770         df $dir
4771         local MDSFREE2=$(do_facet $mymds \
4772                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4773         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4774         if [ "$MDCFREE2" -lt "$((MDCFREE - 16))" ]; then
4775                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
4776                         error "MDC before $MDCFREE != after $MDCFREE2"
4777                 else
4778                         echo "MDC before $MDCFREE != after $MDCFREE2"
4779                         echo "unable to confirm if MDS has large inodes"
4780                 fi
4781         fi
4782         rm -rf $dir
4783 }
4784 run_test 57b "default LOV EAs are stored inside large inodes ==="
4785
4786 test_58() {
4787         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4788         [ -z "$(which wiretest 2>/dev/null)" ] &&
4789                         skip_env "could not find wiretest" && return
4790         wiretest
4791 }
4792 run_test 58 "verify cross-platform wire constants =============="
4793
4794 test_59() {
4795         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4796         echo "touch 130 files"
4797         createmany -o $DIR/f59- 130
4798         echo "rm 130 files"
4799         unlinkmany $DIR/f59- 130
4800         sync
4801         # wait for commitment of removal
4802         wait_delete_completed
4803 }
4804 run_test 59 "verify cancellation of llog records async ========="
4805
4806 TEST60_HEAD="test_60 run $RANDOM"
4807 test_60a() {
4808         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4809         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
4810         do_facet mgs "! which run-llog.sh &> /dev/null" &&
4811                 skip_env "missing subtest run-llog.sh" && return
4812         log "$TEST60_HEAD - from kernel mode"
4813         do_facet mgs sh run-llog.sh
4814 }
4815 run_test 60a "llog sanity tests run from kernel module =========="
4816
4817 test_60b() { # bug 6411
4818         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4819         dmesg > $DIR/$tfile
4820         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
4821                                  /llog.test/ {
4822                                          if (marker)
4823                                                  from_marker++
4824                                          from_begin++
4825                                  }
4826                                  END {
4827                                          if (marker)
4828                                                  print from_marker
4829                                          else
4830                                                  print from_begin
4831                                  }"`
4832         [ $LLOG_COUNT -gt 50 ] && error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)"|| true
4833 }
4834 run_test 60b "limit repeated messages from CERROR/CWARN ========"
4835
4836 test_60c() {
4837         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4838         echo "create 5000 files"
4839         createmany -o $DIR/f60c- 5000
4840 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
4841         lctl set_param fail_loc=0x80000137
4842         unlinkmany $DIR/f60c- 5000
4843         lctl set_param fail_loc=0
4844 }
4845 run_test 60c "unlink file when mds full"
4846
4847 test_60d() {
4848         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4849         SAVEPRINTK=$(lctl get_param -n printk)
4850
4851         # verify "lctl mark" is even working"
4852         MESSAGE="test message ID $RANDOM $$"
4853         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4854         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
4855
4856         lctl set_param printk=0 || error "set lnet.printk failed"
4857         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
4858         MESSAGE="new test message ID $RANDOM $$"
4859         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
4860         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
4861         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
4862
4863         lctl set_param -n printk="$SAVEPRINTK"
4864 }
4865 run_test 60d "test printk console message masking"
4866
4867 test_61() {
4868         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4869         f="$DIR/f61"
4870         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
4871         cancel_lru_locks osc
4872         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
4873         sync
4874 }
4875 run_test 61 "mmap() writes don't make sync hang ================"
4876
4877 # bug 2330 - insufficient obd_match error checking causes LBUG
4878 test_62() {
4879         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4880         f="$DIR/f62"
4881         echo foo > $f
4882         cancel_lru_locks osc
4883         lctl set_param fail_loc=0x405
4884         cat $f && error "cat succeeded, expect -EIO"
4885         lctl set_param fail_loc=0
4886 }
4887 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
4888 # match every page all of the time.
4889 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
4890
4891 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
4892 # Though this test is irrelevant anymore, it helped to reveal some
4893 # other grant bugs (LU-4482), let's keep it.
4894 test_63a() {   # was test_63
4895         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4896         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
4897         for i in `seq 10` ; do
4898                 dd if=/dev/zero of=$DIR/f63 bs=8k &
4899                 sleep 5
4900                 kill $!
4901                 sleep 1
4902         done
4903
4904         rm -f $DIR/f63 || true
4905 }
4906 run_test 63a "Verify oig_wait interruption does not crash ======="
4907
4908 # bug 2248 - async write errors didn't return to application on sync
4909 # bug 3677 - async write errors left page locked
4910 test_63b() {
4911         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4912         debugsave
4913         lctl set_param debug=-1
4914
4915         # ensure we have a grant to do async writes
4916         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
4917         rm $DIR/$tfile
4918
4919         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
4920         lctl set_param fail_loc=0x80000406
4921         $MULTIOP $DIR/$tfile Owy && \
4922                 error "sync didn't return ENOMEM"
4923         sync; sleep 2; sync     # do a real sync this time to flush page
4924         lctl get_param -n llite.*.dump_page_cache | grep locked && \
4925                 error "locked page left in cache after async error" || true
4926         debugrestore
4927 }
4928 run_test 63b "async write errors should be returned to fsync ==="
4929
4930 test_64a () {
4931         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4932         df $DIR
4933         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
4934 }
4935 run_test 64a "verify filter grant calculations (in kernel) ====="
4936
4937 test_64b () {
4938         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4939         sh oos.sh $MOUNT || error "oos.sh failed: $?"
4940 }
4941 run_test 64b "check out-of-space detection on client ==========="
4942
4943 test_64c() {
4944         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
4945 }
4946 run_test 64c "verify grant shrink ========================------"
4947
4948 # bug 1414 - set/get directories' stripe info
4949 test_65a() {
4950         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4951         test_mkdir -p $DIR/$tdir
4952         touch $DIR/$tdir/f1
4953         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
4954 }
4955 run_test 65a "directory with no stripe info ===================="
4956
4957 test_65b() {
4958         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4959         test_mkdir -p $DIR/$tdir
4960         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
4961                                                 error "setstripe"
4962         touch $DIR/$tdir/f2
4963         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
4964 }
4965 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
4966
4967 test_65c() {
4968         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4969         if [ $OSTCOUNT -gt 1 ]; then
4970                 test_mkdir -p $DIR/$tdir
4971                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
4972                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
4973                 touch $DIR/$tdir/f3
4974                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
4975         fi
4976 }
4977 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
4978
4979 test_65d() {
4980         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4981         test_mkdir -p $DIR/$tdir
4982         if [ $STRIPECOUNT -le 0 ]; then
4983                 sc=1
4984         elif [ $STRIPECOUNT -gt 2000 ]; then
4985 #LOV_MAX_STRIPE_COUNT is 2000
4986                 [ $OSTCOUNT -gt 2000 ] && sc=2000 || sc=$(($OSTCOUNT - 1))
4987         else
4988                 sc=$(($STRIPECOUNT - 1))
4989         fi
4990         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
4991         touch $DIR/$tdir/f4 $DIR/$tdir/f5
4992         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
4993                                                 error "lverify failed"
4994 }
4995 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
4996
4997 test_65e() {
4998         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4999         test_mkdir -p $DIR/$tdir
5000
5001         $SETSTRIPE $DIR/$tdir || error "setstripe"
5002         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5003                                         error "no stripe info failed"
5004         touch $DIR/$tdir/f6
5005         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5006 }
5007 run_test 65e "directory setstripe defaults ======================="
5008
5009 test_65f() {
5010         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5011         test_mkdir -p $DIR/${tdir}f
5012         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5013 }
5014 run_test 65f "dir setstripe permission (should return error) ==="
5015
5016 test_65g() {
5017         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5018         test_mkdir -p $DIR/$tdir
5019         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5020                                                         error "setstripe"
5021         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5022         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5023                 error "delete default stripe failed"
5024 }
5025 run_test 65g "directory setstripe -d ==========================="
5026
5027 test_65h() {
5028         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5029         test_mkdir -p $DIR/$tdir
5030         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5031                                                         error "setstripe"
5032         test_mkdir -p $DIR/$tdir/dd1
5033         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5034                 error "stripe info inherit failed"
5035 }
5036 run_test 65h "directory stripe info inherit ===================="
5037
5038 test_65i() { # bug6367
5039         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5040         $SETSTRIPE -S 65536 -c -1 $MOUNT
5041 }
5042 run_test 65i "set non-default striping on root directory (bug 6367)="
5043
5044 test_65ia() { # bug12836
5045         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5046         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5047 }
5048 run_test 65ia "getstripe on -1 default directory striping"
5049
5050 test_65ib() { # bug12836
5051         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5052         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5053 }
5054 run_test 65ib "getstripe -v on -1 default directory striping"
5055
5056 test_65ic() { # bug12836
5057         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5058         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5059 }
5060 run_test 65ic "new find on -1 default directory striping"
5061
5062 test_65j() { # bug6367
5063         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5064         sync; sleep 1
5065         # if we aren't already remounting for each test, do so for this test
5066         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5067                 cleanup || error "failed to unmount"
5068                 setup
5069         fi
5070         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5071 }
5072 run_test 65j "set default striping on root directory (bug 6367)="
5073
5074 test_65k() { # bug11679
5075         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5076         [ "$OSTCOUNT" -lt 2 ] && skip_env "too few OSTs" && return
5077         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5078
5079     echo "Check OST status: "
5080     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5081               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5082
5083     for OSC in $MDS_OSCS; do
5084         echo $OSC "is activate"
5085         do_facet $SINGLEMDS lctl --device %$OSC activate
5086     done
5087
5088     mkdir -p $DIR/$tdir
5089     for INACTIVE_OSC in $MDS_OSCS; do
5090         echo "Deactivate: " $INACTIVE_OSC
5091         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5092         for STRIPE_OSC in $MDS_OSCS; do
5093             OST=`osc_to_ost $STRIPE_OSC`
5094             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5095                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5096
5097             [ -f $DIR/$tdir/$IDX ] && continue
5098             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5099             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5100             RC=$?
5101             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5102         done
5103         rm -f $DIR/$tdir/*
5104         echo $INACTIVE_OSC "is Activate."
5105         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5106     done
5107 }
5108 run_test 65k "validate manual striping works properly with deactivated OSCs"
5109
5110 test_65l() { # bug 12836
5111         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5112         test_mkdir -p $DIR/$tdir/test_dir
5113         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5114         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5115 }
5116 run_test 65l "lfs find on -1 stripe dir ========================"
5117
5118 # bug 2543 - update blocks count on client
5119 test_66() {
5120         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5121         COUNT=${COUNT:-8}
5122         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5123         sync; sync_all_data; sync; sync_all_data
5124         cancel_lru_locks osc
5125         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5126         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5127 }
5128 run_test 66 "update inode blocks count on client ==============="
5129
5130 LLOOP=
5131 LLITELOOPLOAD=
5132 cleanup_68() {
5133         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5134         trap 0
5135         if [ ! -z "$LLOOP" ]; then
5136                 if swapon -s | grep -q $LLOOP; then
5137                         swapoff $LLOOP || error "swapoff failed"
5138                 fi
5139
5140                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5141                 rm -f $LLOOP
5142                 unset LLOOP
5143         fi
5144         if [ ! -z "$LLITELOOPLOAD" ]; then
5145                 rmmod llite_lloop
5146                 unset LLITELOOPLOAD
5147         fi
5148         rm -f $DIR/f68*
5149 }
5150
5151 meminfo() {
5152         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5153 }
5154
5155 swap_used() {
5156         swapon -s | awk '($1 == "'$1'") { print $4 }'
5157 }
5158
5159 # test case for lloop driver, basic function
5160 test_68a() {
5161         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5162         [ "$UID" != 0 ] && skip_env "must run as root" && return
5163         llite_lloop_enabled || \
5164                 { skip_env "llite_lloop module disabled" && return; }
5165
5166         trap cleanup_68 EXIT
5167
5168         if ! module_loaded llite_lloop; then
5169                 if load_module llite/llite_lloop; then
5170                         LLITELOOPLOAD=yes
5171                 else
5172                         skip_env "can't find module llite_lloop"
5173                         return
5174                 fi
5175         fi
5176
5177         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5178         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5179         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5180
5181         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5182         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5183
5184         cleanup_68
5185 }
5186 run_test 68a "lloop driver - basic test ========================"
5187
5188 # excercise swapping to lustre by adding a high priority swapfile entry
5189 # and then consuming memory until it is used.
5190 test_68b() {  # was test_68
5191         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5192         [ "$UID" != 0 ] && skip_env "must run as root" && return
5193         lctl get_param -n devices | grep -q obdfilter && \
5194                 skip "local OST" && return
5195
5196         grep -q llite_lloop /proc/modules
5197         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5198
5199         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5200                 skip "can't reliably test swap with TCP" && return
5201
5202         MEMTOTAL=`meminfo MemTotal`
5203         NR_BLOCKS=$((MEMTOTAL>>8))
5204         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5205
5206         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5207         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5208         mkswap $DIR/f68b
5209
5210         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5211
5212         trap cleanup_68 EXIT
5213
5214         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5215
5216         echo "before: `swapon -s | grep $LLOOP`"
5217         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5218         echo "after: `swapon -s | grep $LLOOP`"
5219         SWAPUSED=`swap_used $LLOOP`
5220
5221         cleanup_68
5222
5223         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5224 }
5225 run_test 68b "support swapping to Lustre ========================"
5226
5227 # bug5265, obdfilter oa2dentry return -ENOENT
5228 # #define OBD_FAIL_OST_ENOENT 0x217
5229 test_69() {
5230         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5231         remote_ost_nodsh && skip "remote OST with nodsh" && return
5232
5233         f="$DIR/$tfile"
5234         $SETSTRIPE -c 1 -i 0 $f
5235
5236         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5237
5238         do_facet ost1 lctl set_param fail_loc=0x217
5239         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5240         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5241
5242         do_facet ost1 lctl set_param fail_loc=0
5243         $DIRECTIO write $f 0 2 || error "write error"
5244
5245         cancel_lru_locks osc
5246         $DIRECTIO read $f 0 1 || error "read error"
5247
5248         do_facet ost1 lctl set_param fail_loc=0x217
5249         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5250
5251         do_facet ost1 lctl set_param fail_loc=0
5252         rm -f $f
5253 }
5254 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5255
5256 test_71() {
5257     test_mkdir -p $DIR/$tdir
5258     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5259 }
5260 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5261
5262 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5263         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5264         [ "$RUNAS_ID" = "$UID" ] &&
5265                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5266
5267         # Check that testing environment is properly set up. Skip if not
5268         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5269                 skip_env "User $RUNAS_ID does not exist - skipping"
5270                 return 0
5271         }
5272         # We had better clear the $DIR to get enough space for dd
5273         rm -rf $DIR/*
5274         touch $DIR/$tfile
5275         chmod 777 $DIR/$tfile
5276         chmod ug+s $DIR/$tfile
5277         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5278                 error "$RUNAS dd $DIR/$tfile failed"
5279         # See if we are still setuid/sgid
5280         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5281                 error "S/gid is not dropped on write"
5282         # Now test that MDS is updated too
5283         cancel_lru_locks mdc
5284         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5285                 error "S/gid is not dropped on MDS"
5286         rm -f $DIR/$tfile
5287 }
5288 run_test 72a "Test that remove suid works properly (bug5695) ===="
5289
5290 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5291         local perm
5292
5293         [ "$RUNAS_ID" = "$UID" ] && \
5294                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5295         [ "$RUNAS_ID" -eq 0 ] && \
5296                 skip_env "RUNAS_ID = 0 -- skipping" && return
5297
5298         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5299         # Check that testing environment is properly set up. Skip if not
5300         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5301                 skip_env "User $RUNAS_ID does not exist - skipping"
5302                 return 0
5303         }
5304         touch $DIR/${tfile}-f{g,u}
5305         test_mkdir $DIR/${tfile}-dg
5306         test_mkdir $DIR/${tfile}-du
5307         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5308         chmod g+s $DIR/${tfile}-{f,d}g
5309         chmod u+s $DIR/${tfile}-{f,d}u
5310         for perm in 777 2777 4777; do
5311                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5312                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5313                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5314                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5315         done
5316         true
5317 }
5318 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5319
5320 # bug 3462 - multiple simultaneous MDC requests
5321 test_73() {
5322         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5323         test_mkdir $DIR/d73-1
5324         test_mkdir $DIR/d73-2
5325         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5326         pid1=$!
5327
5328         lctl set_param fail_loc=0x80000129
5329         $MULTIOP $DIR/d73-1/f73-2 Oc &
5330         sleep 1
5331         lctl set_param fail_loc=0
5332
5333         $MULTIOP $DIR/d73-2/f73-3 Oc &
5334         pid3=$!
5335
5336         kill -USR1 $pid1
5337         wait $pid1 || return 1
5338
5339         sleep 25
5340
5341         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5342         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5343         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5344
5345         rm -rf $DIR/d73-*
5346 }
5347 run_test 73 "multiple MDC requests (should not deadlock)"
5348
5349 test_74a() { # bug 6149, 6184
5350         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5351         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5352         #
5353         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5354         # will spin in a tight reconnection loop
5355         touch $DIR/f74a
5356         lctl set_param fail_loc=0x8000030e
5357         # get any lock that won't be difficult - lookup works.
5358         ls $DIR/f74a
5359         lctl set_param fail_loc=0
5360         true
5361         rm -f $DIR/f74a
5362 }
5363 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5364
5365 test_74b() { # bug 13310
5366         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5367         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5368         #
5369         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5370         # will spin in a tight reconnection loop
5371         lctl set_param fail_loc=0x8000030e
5372         # get a "difficult" lock
5373         touch $DIR/f74b
5374         lctl set_param fail_loc=0
5375         true
5376         rm -f $DIR/f74b
5377 }
5378 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5379
5380 test_74c() {
5381         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5382 #define OBD_FAIL_LDLM_NEW_LOCK
5383         lctl set_param fail_loc=0x80000319
5384         touch $DIR/$tfile && error "Touch successful"
5385         true
5386 }
5387 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5388
5389 num_inodes() {
5390         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5391 }
5392
5393 get_inode_slab_tunables() {
5394         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5395 }
5396
5397 set_inode_slab_tunables() {
5398         echo "lustre_inode_cache $1" > /proc/slabinfo
5399 }
5400
5401 test_76() { # Now for bug 20433, added originally in bug 1443
5402         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5403         local SLAB_SETTINGS=`get_inode_slab_tunables`
5404         local CPUS=`getconf _NPROCESSORS_ONLN`
5405         # we cannot set limit below 1 which means 1 inode in each
5406         # per-cpu cache is still allowed
5407         set_inode_slab_tunables "1 1 0"
5408         cancel_lru_locks osc
5409         BEFORE_INODES=`num_inodes`
5410         echo "before inodes: $BEFORE_INODES"
5411         local COUNT=1000
5412         [ "$SLOW" = "no" ] && COUNT=100
5413         for i in `seq $COUNT`; do
5414                 touch $DIR/$tfile
5415                 rm -f $DIR/$tfile
5416         done
5417         cancel_lru_locks osc
5418         AFTER_INODES=`num_inodes`
5419         echo "after inodes: $AFTER_INODES"
5420         local wait=0
5421         while [ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]; do
5422                 sleep 2
5423                 AFTER_INODES=`num_inodes`
5424                 wait=$((wait+2))
5425                 echo "wait $wait seconds inodes: $AFTER_INODES"
5426                 if [ $wait -gt 30 ]; then
5427                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5428                 fi
5429         done
5430         set_inode_slab_tunables "$SLAB_SETTINGS"
5431 }
5432 run_test 76 "confirm clients recycle inodes properly ===="
5433
5434
5435 export ORIG_CSUM=""
5436 set_checksums()
5437 {
5438         # Note: in sptlrpc modes which enable its own bulk checksum, the
5439         # original crc32_le bulk checksum will be automatically disabled,
5440         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5441         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5442         # In this case set_checksums() will not be no-op, because sptlrpc
5443         # bulk checksum will be enabled all through the test.
5444
5445         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5446         lctl set_param -n osc.*.checksums $1
5447         return 0
5448 }
5449
5450 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5451                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5452 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5453 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5454 set_checksum_type()
5455 {
5456         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5457         log "set checksum type to $1"
5458         return 0
5459 }
5460 F77_TMP=$TMP/f77-temp
5461 F77SZ=8
5462 setup_f77() {
5463         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5464                 error "error writing to $F77_TMP"
5465 }
5466
5467 test_77a() { # bug 10889
5468         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5469         $GSS && skip "could not run with gss" && return
5470         [ ! -f $F77_TMP ] && setup_f77
5471         set_checksums 1
5472         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5473         set_checksums 0
5474         rm -f $DIR/$tfile
5475 }
5476 run_test 77a "normal checksum read/write operation"
5477
5478 test_77b() { # bug 10889
5479         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5480         $GSS && skip "could not run with gss" && return
5481         [ ! -f $F77_TMP ] && setup_f77
5482         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5483         $LCTL set_param fail_loc=0x80000409
5484         set_checksums 1
5485
5486         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5487                 error "dd error: $?"
5488         $LCTL set_param fail_loc=0
5489
5490         for algo in $CKSUM_TYPES; do
5491                 cancel_lru_locks osc
5492                 set_checksum_type $algo
5493                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5494                 $LCTL set_param fail_loc=0x80000408
5495                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5496                 $LCTL set_param fail_loc=0
5497         done
5498         set_checksums 0
5499         set_checksum_type $ORIG_CSUM_TYPE
5500         rm -f $DIR/$tfile
5501 }
5502 run_test 77b "checksum error on client write, read"
5503
5504 test_77d() { # bug 10889
5505         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5506         $GSS && skip "could not run with gss" && return
5507         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5508         $LCTL set_param fail_loc=0x80000409
5509         set_checksums 1
5510         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5511                 error "direct write: rc=$?"
5512         $LCTL set_param fail_loc=0
5513         set_checksums 0
5514
5515         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5516         $LCTL set_param fail_loc=0x80000408
5517         set_checksums 1
5518         cancel_lru_locks osc
5519         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5520                 error "direct read: rc=$?"
5521         $LCTL set_param fail_loc=0
5522         set_checksums 0
5523 }
5524 run_test 77d "checksum error on OST direct write, read"
5525
5526 test_77f() { # bug 10889
5527         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5528         $GSS && skip "could not run with gss" && return
5529         set_checksums 1
5530         for algo in $CKSUM_TYPES; do
5531                 cancel_lru_locks osc
5532                 set_checksum_type $algo
5533                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5534                 $LCTL set_param fail_loc=0x409
5535                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5536                         error "direct write succeeded"
5537                 $LCTL set_param fail_loc=0
5538         done
5539         set_checksum_type $ORIG_CSUM_TYPE
5540         set_checksums 0
5541 }
5542 run_test 77f "repeat checksum error on write (expect error)"
5543
5544 test_77g() { # bug 10889
5545         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5546         $GSS && skip "could not run with gss" && return
5547         remote_ost_nodsh && skip "remote OST with nodsh" && return
5548
5549         [ ! -f $F77_TMP ] && setup_f77
5550
5551         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5552         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5553         do_facet ost1 lctl set_param fail_loc=0x8000021a
5554         set_checksums 1
5555         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5556                 error "write error: rc=$?"
5557         do_facet ost1 lctl set_param fail_loc=0
5558         set_checksums 0
5559
5560         cancel_lru_locks osc
5561         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5562         do_facet ost1 lctl set_param fail_loc=0x8000021b
5563         set_checksums 1
5564         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5565         do_facet ost1 lctl set_param fail_loc=0
5566         set_checksums 0
5567 }
5568 run_test 77g "checksum error on OST write, read"
5569
5570 test_77i() { # bug 13805
5571         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5572         $GSS && skip "could not run with gss" && return
5573         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5574         lctl set_param fail_loc=0x40b
5575         remount_client $MOUNT
5576         lctl set_param fail_loc=0
5577         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5578                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5579                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5580                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5581         done
5582         remount_client $MOUNT
5583 }
5584 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5585
5586 test_77j() { # bug 13805
5587         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5588         $GSS && skip "could not run with gss" && return
5589         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5590         lctl set_param fail_loc=0x40c
5591         remount_client $MOUNT
5592         lctl set_param fail_loc=0
5593         sleep 2 # wait async osc connect to finish
5594         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5595                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5596                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5597                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5598         done
5599         remount_client $MOUNT
5600 }
5601 run_test 77j "client only supporting ADLER32"
5602
5603 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5604 rm -f $F77_TMP
5605 unset F77_TMP
5606
5607 test_78() { # bug 10901
5608         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5609         remote_ost || { skip_env "local OST" && return; }
5610
5611         NSEQ=5
5612         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5613         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5614         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5615         echo "MemTotal: $MEMTOTAL"
5616 # reserve 256MB of memory for the kernel and other running processes,
5617 # and then take 1/2 of the remaining memory for the read/write buffers.
5618     if [ $MEMTOTAL -gt 512 ] ;then
5619         MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5620     else
5621         # for those poor memory-starved high-end clusters...
5622         MEMTOTAL=$((MEMTOTAL / 2))
5623     fi
5624         echo "Mem to use for directio: $MEMTOTAL"
5625         [ $F78SIZE -gt $MEMTOTAL ] && F78SIZE=$MEMTOTAL
5626         [ $F78SIZE -gt 512 ] && F78SIZE=512
5627         [ $F78SIZE -gt $((MAXFREE / 1024)) ] && F78SIZE=$((MAXFREE / 1024))
5628         SMALLESTOST=$(lfs df $DIR | grep OST | awk '{ print $4 }' | sort -n |
5629                 head -n1)
5630         echo "Smallest OST: $SMALLESTOST"
5631         [ $SMALLESTOST -lt 10240 ] && \
5632                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5633
5634         [ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ] && \
5635                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5636
5637         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5638         echo "File size: $F78SIZE"
5639         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5640         for i in `seq 1 $NSEQ`
5641         do
5642                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5643                 echo directIO rdwr round $i of $NSEQ
5644                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5645         done
5646
5647         rm -f $DIR/$tfile
5648 }
5649 run_test 78 "handle large O_DIRECT writes correctly ============"
5650
5651 test_79() { # bug 12743
5652         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5653         wait_delete_completed
5654
5655         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5656         BKFREE=$(calc_osc_kbytes kbytesfree)
5657         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5658
5659         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5660         DFTOTAL=`echo $STRING | cut -d, -f1`
5661         DFUSED=`echo $STRING  | cut -d, -f2`
5662         DFAVAIL=`echo $STRING | cut -d, -f3`
5663         DFFREE=$(($DFTOTAL - $DFUSED))
5664
5665         ALLOWANCE=$((64 * $OSTCOUNT))
5666
5667         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5668            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5669                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5670         fi
5671         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5672            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5673                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5674         fi
5675         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5676            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5677                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5678         fi
5679 }
5680 run_test 79 "df report consistency check ======================="
5681
5682 test_80() { # bug 10718
5683         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5684         # relax strong synchronous semantics for slow backends like ZFS
5685         local soc="obdfilter.*.sync_on_lock_cancel"
5686         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
5687         local hosts=
5688         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
5689                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
5690                           facet_active_host $host; done | sort -u)
5691                 do_nodes $hosts lctl set_param $soc=never
5692         fi
5693
5694         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
5695         sync; sleep 1; sync
5696         local BEFORE=`date +%s`
5697         cancel_lru_locks osc
5698         local AFTER=`date +%s`
5699         local DIFF=$((AFTER-BEFORE))
5700         if [ $DIFF -gt 1 ] ; then
5701                 error "elapsed for 1M@1T = $DIFF"
5702         fi
5703
5704         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
5705
5706         rm -f $DIR/$tfile
5707 }
5708 run_test 80 "Page eviction is equally fast at high offsets too  ===="
5709
5710 test_81a() { # LU-456
5711         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5712         remote_ost_nodsh && skip "remote OST with nodsh" && return
5713         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5714         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
5715         do_facet ost1 lctl set_param fail_loc=0x80000228
5716
5717         # write should trigger a retry and success
5718         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5719         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5720         RC=$?
5721         if [ $RC -ne 0 ] ; then
5722                 error "write should success, but failed for $RC"
5723         fi
5724 }
5725 run_test 81a "OST should retry write when get -ENOSPC ==============="
5726
5727 test_81b() { # LU-456
5728         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5729         remote_ost_nodsh && skip "remote OST with nodsh" && return
5730         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5731         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
5732         do_facet ost1 lctl set_param fail_loc=0x228
5733
5734         # write should retry several times and return -ENOSPC finally
5735         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5736         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5737         RC=$?
5738         ENOSPC=28
5739         if [ $RC -ne $ENOSPC ] ; then
5740                 error "dd should fail for -ENOSPC, but succeed."
5741         fi
5742 }
5743 run_test 81b "OST should return -ENOSPC when retry still fails ======="
5744
5745 test_82() { # LU-1031
5746         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
5747         local gid1=14091995
5748         local gid2=16022000
5749
5750         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
5751         local MULTIPID1=$!
5752         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
5753         local MULTIPID2=$!
5754         kill -USR1 $MULTIPID2
5755         sleep 2
5756         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
5757                 error "First grouplock does not block second one"
5758         else
5759                 echo "Second grouplock blocks first one"
5760         fi
5761         kill -USR1 $MULTIPID1
5762         wait $MULTIPID1
5763         wait $MULTIPID2
5764 }
5765 run_test 82 "Basic grouplock test ==============================="
5766
5767 test_99a() {
5768         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
5769                 return
5770         test_mkdir -p $DIR/d99cvsroot
5771         chown $RUNAS_ID $DIR/d99cvsroot
5772         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
5773         cd $TMP
5774
5775         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
5776         cd $oldPWD
5777 }
5778 run_test 99a "cvs init ========================================="
5779
5780 test_99b() {
5781         [ -z "$(which cvs 2>/dev/null)" ] &&
5782                 skip_env "could not find cvs" && return
5783         [ ! -d $DIR/d99cvsroot ] && test_99a
5784         cd /etc/init.d
5785         # some versions of cvs import exit(1) when asked to import links or
5786         # files they can't read.  ignore those files.
5787         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
5788                         ! -perm +4 -printf '-I %f\n')
5789         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
5790                 d99reposname vtag rtag
5791 }
5792 run_test 99b "cvs import ======================================="
5793
5794 test_99c() {
5795         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5796         [ ! -d $DIR/d99cvsroot ] && test_99b
5797         cd $DIR
5798         test_mkdir -p $DIR/d99reposname
5799         chown $RUNAS_ID $DIR/d99reposname
5800         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
5801 }
5802 run_test 99c "cvs checkout ====================================="
5803
5804 test_99d() {
5805         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5806         [ ! -d $DIR/d99cvsroot ] && test_99c
5807         cd $DIR/d99reposname
5808         $RUNAS touch foo99
5809         $RUNAS cvs add -m 'addmsg' foo99
5810 }
5811 run_test 99d "cvs add =========================================="
5812
5813 test_99e() {
5814         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5815         [ ! -d $DIR/d99cvsroot ] && test_99c
5816         cd $DIR/d99reposname
5817         $RUNAS cvs update
5818 }
5819 run_test 99e "cvs update ======================================="
5820
5821 test_99f() {
5822         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5823         [ ! -d $DIR/d99cvsroot ] && test_99d
5824         cd $DIR/d99reposname
5825         $RUNAS cvs commit -m 'nomsg' foo99
5826     rm -fr $DIR/d99cvsroot
5827 }
5828 run_test 99f "cvs commit ======================================="
5829
5830 test_100() {
5831         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5832         [ "$NETTYPE" = tcp ] || \
5833                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
5834                         return ; }
5835
5836         remote_ost_nodsh && skip "remote OST with nodsh" && return
5837         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5838         remote_servers || \
5839                 { skip "useless for local single node setup" && return; }
5840
5841         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
5842                 [ "$PROT" != "tcp" ] && continue
5843                 RPORT=$(echo $REMOTE | cut -d: -f2)
5844                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
5845
5846                 rc=0
5847                 LPORT=`echo $LOCAL | cut -d: -f2`
5848                 if [ $LPORT -ge 1024 ]; then
5849                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
5850                         netstat -tna
5851                         error_exit "local: $LPORT > 1024, remote: $RPORT"
5852                 fi
5853         done
5854         [ "$rc" = 0 ] || error_exit "privileged port not found" )
5855 }
5856 run_test 100 "check local port using privileged port ==========="
5857
5858 function get_named_value()
5859 {
5860     local tag
5861
5862     tag=$1
5863     while read ;do
5864         line=$REPLY
5865         case $line in
5866         $tag*)
5867             echo $line | sed "s/^$tag[ ]*//"
5868             break
5869             ;;
5870         esac
5871     done
5872 }
5873
5874 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
5875                    awk '/^max_cached_mb/ { print $2 }')
5876
5877 cleanup_101a() {
5878         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
5879         trap 0
5880 }
5881
5882 test_101a() {
5883         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5884         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
5885         local s
5886         local discard
5887         local nreads=10000
5888         local cache_limit=32
5889
5890         $LCTL set_param -n osc.*-osc*.rpc_stats 0
5891         trap cleanup_101a EXIT
5892         $LCTL set_param -n llite.*.read_ahead_stats 0
5893         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
5894
5895         #
5896         # randomly read 10000 of 64K chunks from file 3x 32MB in size
5897         #
5898         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
5899         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
5900
5901         discard=0
5902         for s in `$LCTL get_param -n llite.*.read_ahead_stats | \
5903                 get_named_value 'read but discarded' | cut -d" " -f1`; do
5904                         discard=$(($discard + $s))
5905         done
5906         cleanup_101a
5907
5908         if [ $(($discard * 10)) -gt $nreads ] ;then
5909                 $LCTL get_param osc.*-osc*.rpc_stats
5910                 $LCTL get_param llite.*.read_ahead_stats
5911                 error "too many ($discard) discarded pages"
5912         fi
5913         rm -f $DIR/$tfile || true
5914 }
5915 run_test 101a "check read-ahead for random reads ================"
5916
5917 setup_test101bc() {
5918         test_mkdir -p $DIR/$tdir
5919         local STRIPE_SIZE=$1
5920         local FILE_LENGTH=$2
5921         STRIPE_OFFSET=0
5922
5923         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
5924
5925         local list=$(comma_list $(osts_nodes))
5926         set_osd_param $list '' read_cache_enable 0
5927         set_osd_param $list '' writethrough_cache_enable 0
5928
5929         trap cleanup_test101bc EXIT
5930         # prepare the read-ahead file
5931         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
5932
5933         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
5934                                 count=$FILE_SIZE_MB 2> /dev/null
5935
5936 }
5937
5938 cleanup_test101bc() {
5939         trap 0
5940         rm -rf $DIR/$tdir
5941         rm -f $DIR/$tfile
5942
5943         local list=$(comma_list $(osts_nodes))
5944         set_osd_param $list '' read_cache_enable 1
5945         set_osd_param $list '' writethrough_cache_enable 1
5946 }
5947
5948 calc_total() {
5949         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
5950 }
5951
5952 ra_check_101() {
5953         local READ_SIZE=$1
5954         local STRIPE_SIZE=$2
5955         local FILE_LENGTH=$3
5956         local RA_INC=1048576
5957         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
5958         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
5959                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
5960         DISCARD=`$LCTL get_param -n llite.*.read_ahead_stats | \
5961                         get_named_value 'read but discarded' | \
5962                         cut -d" " -f1 | calc_total`
5963         if [ $DISCARD -gt $discard_limit ]; then
5964                 $LCTL get_param llite.*.read_ahead_stats
5965                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
5966         else
5967                 echo "Read-ahead success for size ${READ_SIZE}"
5968         fi
5969 }
5970
5971 test_101b() {
5972         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5973         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping stride IO stride-ahead test" && return
5974         local STRIPE_SIZE=1048576
5975         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
5976         if [ $SLOW == "yes" ]; then
5977                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
5978         else
5979                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
5980         fi
5981
5982         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
5983
5984         # prepare the read-ahead file
5985         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
5986         cancel_lru_locks osc
5987         for BIDX in 2 4 8 16 32 64 128 256
5988         do
5989                 local BSIZE=$((BIDX*4096))
5990                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
5991                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
5992                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
5993                 $LCTL set_param -n llite.*.read_ahead_stats 0
5994                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
5995                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
5996                 cancel_lru_locks osc
5997                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
5998         done
5999         cleanup_test101bc
6000         true
6001 }
6002 run_test 101b "check stride-io mode read-ahead ================="
6003
6004 test_101c() {
6005         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6006         local STRIPE_SIZE=1048576
6007         local FILE_LENGTH=$((STRIPE_SIZE*100))
6008         local nreads=10000
6009         local osc_rpc_stats
6010
6011         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6012
6013         cancel_lru_locks osc
6014         $LCTL set_param osc.*.rpc_stats 0
6015         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6016         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6017                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6018                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6019                 local size
6020
6021                 if [ $lines -le 20 ]; then
6022                         continue
6023                 fi
6024                 for size in 1 2 4 8; do
6025                         local rpc=$(echo "$stats" |
6026                                     awk '($1 == "'$size':") {print $2; exit; }')
6027                         [ $rpc != 0 ] &&
6028                                 error "Small $((size*4))k read IO $rpc !"
6029                 done
6030                 echo "$osc_rpc_stats check passed!"
6031         done
6032         cleanup_test101bc
6033         true
6034 }
6035 run_test 101c "check stripe_size aligned read-ahead ================="
6036
6037 set_read_ahead() {
6038         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6039         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6040 }
6041
6042 test_101d() {
6043         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6044         local file=$DIR/$tfile
6045         local sz_MB=${FILESIZE_101d:-500}
6046         local ra_MB=${READAHEAD_MB:-40}
6047
6048         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6049         [ $free_MB -lt $sz_MB ] &&
6050                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6051
6052         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6053         $SETSTRIPE -c -1 $file || error "setstripe failed"
6054
6055         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6056         echo Cancel LRU locks on lustre client to flush the client cache
6057         cancel_lru_locks osc
6058
6059         echo Disable read-ahead
6060         local old_READAHEAD=$(set_read_ahead 0)
6061
6062         echo Reading the test file $file with read-ahead disabled
6063         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6064
6065         echo Cancel LRU locks on lustre client to flush the client cache
6066         cancel_lru_locks osc
6067         echo Enable read-ahead with ${ra_MB}MB
6068         set_read_ahead $ra_MB
6069
6070         echo Reading the test file $file with read-ahead enabled
6071         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6072
6073         echo "read-ahead disabled time read $raOFF"
6074         echo "read-ahead enabled  time read $raON"
6075
6076         set_read_ahead $old_READAHEAD
6077         rm -f $file
6078         wait_delete_completed
6079
6080         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6081                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6082 }
6083 run_test 101d "file read with and without read-ahead enabled"
6084
6085 test_101e() {
6086         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6087         local file=$DIR/$tfile
6088         local size_KB=500  #KB
6089         local count=100
6090         local bsize=1024
6091
6092         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6093         local need_KB=$((count * size_KB))
6094         [ $free_KB -le $need_KB ] &&
6095                 skip_env "Need free space $need_KB, have $free_KB" && return
6096
6097         echo "Creating $count ${size_KB}K test files"
6098         for ((i = 0; i < $count; i++)); do
6099                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6100         done
6101
6102         echo "Cancel LRU locks on lustre client to flush the client cache"
6103         cancel_lru_locks osc
6104
6105         echo "Reset readahead stats"
6106         $LCTL set_param -n llite.*.read_ahead_stats 0
6107
6108         for ((i = 0; i < $count; i++)); do
6109                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6110         done
6111
6112         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6113                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6114
6115         for ((i = 0; i < $count; i++)); do
6116                 rm -rf $file.$i 2>/dev/null
6117         done
6118
6119         #10000 means 20% reads are missing in readahead
6120         [ $miss -lt 10000 ] ||  error "misses too much for small reads"
6121 }
6122 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6123
6124 cleanup_test101f() {
6125     trap 0
6126     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6127     rm -rf $DIR/$tfile 2>/dev/null
6128 }
6129
6130 test_101f() {
6131         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6132     local file=$DIR/$tfile
6133     local nreads=1000
6134
6135     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6136     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6137     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6138     trap cleanup_test101f EXIT
6139
6140     echo Cancel LRU locks on lustre client to flush the client cache
6141     cancel_lru_locks osc
6142
6143     echo Reset readahead stats
6144     $LCTL set_param -n llite.*.read_ahead_stats 0
6145     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6146     # readahead should read in 2M file on second read, so only miss
6147     # 2 pages.
6148     echo Random 4K reads on 2M file for 1000 times
6149     $READS -f $file -s 2097152 -b 4096 -n $nreads
6150
6151     echo checking missing pages
6152     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6153           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6154
6155     [ $miss -lt 3 ] || error "misses too much pages!"
6156     cleanup_test101f
6157 }
6158 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6159
6160 setup_test102() {
6161         test_mkdir -p $DIR/$tdir
6162         chown $RUNAS_ID $DIR/$tdir
6163         STRIPE_SIZE=65536
6164         STRIPE_OFFSET=1
6165         STRIPE_COUNT=$OSTCOUNT
6166         [ $OSTCOUNT -gt 4 ] && STRIPE_COUNT=4
6167
6168         trap cleanup_test102 EXIT
6169         cd $DIR
6170         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6171         cd $DIR/$tdir
6172         for num in 1 2 3 4; do
6173                 for count in $(seq 1 $STRIPE_COUNT); do
6174                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6175                                 local size=`expr $STRIPE_SIZE \* $num`
6176                                 local file=file"$num-$idx-$count"
6177                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6178                         done
6179                 done
6180         done
6181
6182         cd $DIR
6183         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6184 }
6185
6186 cleanup_test102() {
6187         trap 0
6188         rm -f $TMP/f102.tar
6189         rm -rf $DIR/d0.sanity/d102
6190 }
6191
6192 test_102a() {
6193         local testfile=$DIR/xattr_testfile
6194
6195         touch $testfile
6196
6197         [ "$UID" != 0 ] && skip_env "must run as root" && return
6198         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6199                 skip_env "must have user_xattr" && return
6200
6201         [ -z "$(which setfattr 2>/dev/null)" ] &&
6202                 skip_env "could not find setfattr" && return
6203
6204         echo "set/get xattr..."
6205         setfattr -n trusted.name1 -v value1 $testfile ||
6206                 error "setfattr -n trusted.name1=value1 $testfile failed"
6207         getfattr -n trusted.name1 $testfile 2> /dev/null |
6208           grep "trusted.name1=.value1" ||
6209                 error "$testfile missing trusted.name1=value1"
6210
6211         setfattr -n user.author1 -v author1 $testfile ||
6212                 error "setfattr -n user.author1=author1 $testfile failed"
6213         getfattr -n user.author1 $testfile 2> /dev/null |
6214           grep "user.author1=.author1" ||
6215                 error "$testfile missing trusted.author1=author1"
6216
6217         echo "listxattr..."
6218         setfattr -n trusted.name2 -v value2 $testfile ||
6219                 error "$testfile unable to set trusted.name2"
6220         setfattr -n trusted.name3 -v value3 $testfile ||
6221                 error "$testfile unable to set trusted.name3"
6222         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6223             grep "trusted.name" | wc -l) -eq 3 ] ||
6224                 error "$testfile missing 3 trusted.name xattrs"
6225
6226         setfattr -n user.author2 -v author2 $testfile ||
6227                 error "$testfile unable to set user.author2"
6228         setfattr -n user.author3 -v author3 $testfile ||
6229                 error "$testfile unable to set user.author3"
6230         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6231             grep "user.author" | wc -l) -eq 3 ] ||
6232                 error "$testfile missing 3 user.author xattrs"
6233
6234         echo "remove xattr..."
6235         setfattr -x trusted.name1 $testfile ||
6236                 error "$testfile error deleting trusted.name1"
6237         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6238                 error "$testfile did not delete trusted.name1 xattr"
6239
6240         setfattr -x user.author1 $testfile ||
6241                 error "$testfile error deleting user.author1"
6242         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6243                 error "$testfile did not delete trusted.name1 xattr"
6244
6245         # b10667: setting lustre special xattr be silently discarded
6246         echo "set lustre special xattr ..."
6247         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6248                 error "$testfile allowed setting trusted.lov"
6249 }
6250 run_test 102a "user xattr test =================================="
6251
6252 test_102b() {
6253         # b10930: get/set/list trusted.lov xattr
6254         echo "get/set/list trusted.lov xattr ..."
6255         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
6256         local testfile=$DIR/$tfile
6257         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6258                 error "setstripe failed"
6259         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6260                 error "getstripe failed"
6261         getfattr -d -m "^trusted" $testfile 2> /dev/null | \
6262         grep "trusted.lov" || error "can't get trusted.lov from $testfile"
6263
6264         local testfile2=${testfile}2
6265         local value=`getfattr -n trusted.lov $testfile 2> /dev/null | \
6266                      grep "trusted.lov" |sed -e 's/[^=]\+=//'`
6267
6268         $MCREATE $testfile2
6269         setfattr -n trusted.lov -v $value $testfile2
6270         local stripe_size=$($GETSTRIPE -S $testfile2)
6271         local stripe_count=$($GETSTRIPE -c $testfile2)
6272         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6273         [ $stripe_count -eq $STRIPECOUNT ] ||
6274                 error "stripe count $stripe_count != $STRIPECOUNT"
6275         rm -f $DIR/$tfile
6276 }
6277 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6278
6279 test_102c() {
6280         # b10930: get/set/list lustre.lov xattr
6281         echo "get/set/list lustre.lov xattr ..."
6282         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
6283         test_mkdir -p $DIR/$tdir
6284         chown $RUNAS_ID $DIR/$tdir
6285         local testfile=$DIR/$tdir/$tfile
6286         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6287                 error "setstripe failed"
6288         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6289                 error "getstripe failed"
6290         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6291         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6292
6293         local testfile2=${testfile}2
6294         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6295                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6296
6297         $RUNAS $MCREATE $testfile2
6298         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6299         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6300         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6301         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6302         [ $stripe_count -eq $STRIPECOUNT ] ||
6303                 error "stripe count $stripe_count != $STRIPECOUNT"
6304 }
6305 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6306
6307 compare_stripe_info1() {
6308         local stripe_index_all_zero=true
6309
6310         for num in 1 2 3 4; do
6311                 for count in $(seq 1 $STRIPE_COUNT); do
6312                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6313                                 local size=$((STRIPE_SIZE * num))
6314                                 local file=file"$num-$offset-$count"
6315                                 stripe_size=$(lfs getstripe -S $PWD/$file)
6316                                 [ $stripe_size -ne $size ] &&
6317                                     error "$file: size $stripe_size != $size"
6318                                 stripe_count=$(lfs getstripe -c $PWD/$file)
6319                                 # allow fewer stripes to be created, ORI-601
6320                                 [ $stripe_count -lt $(((3 * count + 3) / 4)) ]&&
6321                                     error "$file: count $stripe_count != $count"
6322                                 stripe_index=$(lfs getstripe -i $PWD/$file)
6323                                 [ $stripe_index -ne 0 ] &&
6324                                         stripe_index_all_zero=false
6325                         done
6326                 done
6327         done
6328         $stripe_index_all_zero &&
6329                 error "all files are being extracted starting from OST index 0"
6330         return 0
6331 }
6332
6333 find_lustre_tar() {
6334         [ -n "$(which tar 2>/dev/null)" ] &&
6335                 strings $(which tar) | grep -q "lustre" && echo tar
6336 }
6337
6338 test_102d() {
6339         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6340         # b10930: tar test for trusted.lov xattr
6341         TAR=$(find_lustre_tar)
6342         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6343         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
6344         setup_test102
6345         test_mkdir -p $DIR/d102d
6346         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6347         cd $DIR/d102d/$tdir
6348         compare_stripe_info1
6349 }
6350 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6351
6352 test_102f() {
6353         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6354         # b10930: tar test for trusted.lov xattr
6355         TAR=$(find_lustre_tar)
6356         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6357         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
6358         setup_test102
6359         test_mkdir -p $DIR/d102f
6360         cd $DIR
6361         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6362         cd $DIR/d102f/$tdir
6363         compare_stripe_info1
6364 }
6365 run_test 102f "tar copy files, not keep osts ==========="
6366
6367 grow_xattr() {
6368         local xsize=${1:-1024}  # in bytes
6369         local file=$DIR/$tfile
6370
6371         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6372                 skip "must have user_xattr" && return 0
6373         [ -z "$(which setfattr 2>/dev/null)" ] &&
6374                 skip_env "could not find setfattr" && return 0
6375         [ -z "$(which getfattr 2>/dev/null)" ] &&
6376                 skip_env "could not find getfattr" && return 0
6377
6378         touch $file
6379
6380         local value="$(generate_string $xsize)"
6381
6382         local xbig=trusted.big
6383         log "save $xbig on $file"
6384         setfattr -n $xbig -v $value $file ||
6385                 error "saving $xbig on $file failed"
6386
6387         local orig=$(get_xattr_value $xbig $file)
6388         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6389
6390         local xsml=trusted.sml
6391         log "save $xsml on $file"
6392         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6393
6394         local new=$(get_xattr_value $xbig $file)
6395         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6396
6397         log "grow $xsml on $file"
6398         setfattr -n $xsml -v "$value" $file ||
6399                 error "growing $xsml on $file failed"
6400
6401         new=$(get_xattr_value $xbig $file)
6402         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6403         log "$xbig still valid after growing $xsml"
6404
6405         rm -f $file
6406 }
6407
6408 test_102h() { # bug 15777
6409         grow_xattr 1024
6410 }
6411 run_test 102h "grow xattr from inside inode to external block"
6412
6413 test_102ha() {
6414         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6415         grow_xattr $(max_xattr_size)
6416 }
6417 run_test 102ha "grow xattr from inside inode to external inode"
6418
6419 test_102i() { # bug 17038
6420         touch $DIR/$tfile
6421         ln -s $DIR/$tfile $DIR/${tfile}link
6422         getfattr -n trusted.lov $DIR/$tfile || error "lgetxattr on $DIR/$tfile failed"
6423         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 | grep -i "no such attr" || error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6424         rm -f $DIR/$tfile $DIR/${tfile}link
6425 }
6426 run_test 102i "lgetxattr test on symbolic link ============"
6427
6428 test_102j() {
6429         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6430         TAR=$(find_lustre_tar)
6431         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6432         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping N-stripe test" && return
6433         setup_test102 "$RUNAS"
6434         test_mkdir -p $DIR/d102j
6435         chown $RUNAS_ID $DIR/d102j
6436         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6437         cd $DIR/d102j/$tdir
6438         compare_stripe_info1 "$RUNAS"
6439 }
6440 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6441
6442 test_102k() {
6443         touch $DIR/$tfile
6444         # b22187 just check that does not crash for regular file.
6445         setfattr -n trusted.lov $DIR/$tfile
6446         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6447         local test_kdir=$DIR/d102k
6448         test_mkdir $test_kdir
6449         local default_size=`$GETSTRIPE -S $test_kdir`
6450         local default_count=`$GETSTRIPE -c $test_kdir`
6451         local default_offset=`$GETSTRIPE -i $test_kdir`
6452         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6453                 error 'dir setstripe failed'
6454         setfattr -n trusted.lov $test_kdir
6455         local stripe_size=`$GETSTRIPE -S $test_kdir`
6456         local stripe_count=`$GETSTRIPE -c $test_kdir`
6457         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6458         [ $stripe_size -eq $default_size ] ||
6459                 error "stripe size $stripe_size != $default_size"
6460         [ $stripe_count -eq $default_count ] ||
6461                 error "stripe count $stripe_count != $default_count"
6462         [ $stripe_offset -eq $default_offset ] ||
6463                 error "stripe offset $stripe_offset != $default_offset"
6464         rm -rf $DIR/$tfile $test_kdir
6465 }
6466 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6467
6468 test_102l() {
6469         # LU-532 trusted. xattr is invisible to non-root
6470         local testfile=$DIR/$tfile
6471
6472         touch $testfile
6473
6474         echo "listxattr as user..."
6475         chown $RUNAS_ID $testfile
6476         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6477             grep -q "trusted" &&
6478                 error "$testfile trusted xattrs are user visible"
6479
6480         return 0;
6481 }
6482 run_test 102l "listxattr size test =================================="
6483
6484 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6485         local path=$DIR/$tfile
6486         touch $path
6487
6488         listxattr_size_check $path || error "listattr_size_check $path failed"
6489 }
6490 run_test 102m "Ensure listxattr fails on small bufffer ========"
6491
6492 cleanup_test102
6493
6494 getxattr() { # getxattr path name
6495         # Return the base64 encoding of the value of xattr name on path.
6496         local path=$1
6497         local name=$2
6498
6499         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6500         # file: $path
6501         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6502         #
6503         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6504
6505         getfattr --absolute-names --encoding=base64 --name=$name $path |
6506                 awk -F= -v name=$name '$1 == name {
6507                         print substr($0, index($0, "=") + 1);
6508         }'
6509 }
6510
6511 test_102n() { # LU-4101 mdt: protect internal xattrs
6512         local file0=$DIR/$tfile.0
6513         local file1=$DIR/$tfile.1
6514         local xattr0=$TMP/$tfile.0
6515         local xattr1=$TMP/$tfile.1
6516         local name
6517         local value
6518
6519         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6520         then
6521                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6522                 return
6523         fi
6524
6525         rm -rf $file0 $file1 $xattr0 $xattr1
6526         touch $file0 $file1
6527
6528         # Get 'before' xattrs of $file1.
6529         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6530
6531         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6532                 # Try to copy xattr from $file0 to $file1.
6533                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6534
6535                 setfattr --name=trusted.$name --value="$value" $file1 ||
6536                         error "setxattr 'trusted.$name' failed"
6537
6538                 # Try to set a garbage xattr.
6539                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6540
6541                 setfattr --name=trusted.$name --value="$value" $file1 ||
6542                         error "setxattr 'trusted.$name' failed"
6543
6544                 # Try to remove the xattr from $file1. We don't care if this
6545                 # appears to succeed or fail, we just don't want there to be
6546                 # any changes or crashes.
6547                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6548         done
6549
6550         # Get 'after' xattrs of file1.
6551         getfattr --absolute-names --dump --match=- $file1 > $xattr1
6552
6553         if ! diff $xattr0 $xattr1; then
6554                 error "before and after xattrs of '$file1' differ"
6555         fi
6556
6557         rm -rf $file0 $file1 $xattr0 $xattr1
6558
6559         return 0
6560 }
6561 run_test 102n "silently ignore setxattr on internal trusted xattrs"
6562
6563 test_102p() { # LU-4703 setxattr did not check ownership
6564         local testfile=$DIR/$tfile
6565
6566         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
6567                 skip "MDS needs to be at least 2.5.56" && return
6568
6569         touch $testfile
6570
6571         echo "setfacl as user..."
6572         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
6573         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
6574
6575         echo "setfattr as user..."
6576         setfacl -m "u:$RUNAS_ID:---" $testfile
6577         $RUNAS setfattr -x system.posix_acl_access $testfile
6578         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
6579 }
6580 run_test 102p "check setxattr(2) correctly fails without permission"
6581
6582 run_acl_subtest()
6583 {
6584     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6585     return $?
6586 }
6587
6588 test_103 () {
6589         [ "$UID" != 0 ] && skip_env "must run as root" && return
6590         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6591                 skip "must have acl enabled" && return
6592         [ -z "$(which setfacl 2>/dev/null)" ] &&
6593                 skip_env "could not find setfacl" && return
6594         $GSS && skip "could not run under gss" && return
6595
6596         declare -a identity_old
6597
6598         for num in $(seq $MDSCOUNT); do
6599                 switch_identity $num true || identity_old[$num]=$?
6600         done
6601
6602         SAVE_UMASK=$(umask)
6603         umask 0022
6604         cd $DIR
6605
6606         echo "performing cp ..."
6607         run_acl_subtest cp || error "run_acl_subtest cp failed"
6608         echo "performing getfacl-noacl..."
6609         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
6610         echo "performing misc..."
6611         run_acl_subtest misc || error  "misc test failed"
6612         echo "performing permissions..."
6613         run_acl_subtest permissions || error "permissions failed"
6614         echo "performing setfacl..."
6615         run_acl_subtest setfacl || error  "setfacl test failed"
6616
6617         # inheritance test got from HP
6618         echo "performing inheritance..."
6619         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
6620         chmod +x make-tree || error "chmod +x failed"
6621         run_acl_subtest inheritance || error "inheritance test failed"
6622         rm -f make-tree
6623
6624         echo "LU-974 ignore umask when acl is enabled..."
6625         run_acl_subtest 974 || error "LU-974 umask test failed"
6626         if [ $MDSCOUNT -ge 2 ]; then
6627                 run_acl_subtest 974_remote ||
6628                         error "LU-974 umask test failed under remote dir"
6629         fi
6630
6631         echo "LU-2561 newly created file is same size as directory..."
6632         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
6633                 run_acl_subtest 2561 || error "LU-2561 test failed"
6634         else
6635                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
6636         fi
6637
6638         cd $SAVE_PWD
6639         umask $SAVE_UMASK
6640
6641         for num in $(seq $MDSCOUNT); do
6642                 if [ "${identity_old[$num]}" = 1 ]; then
6643                         switch_identity $num false || identity_old[$num]=$?
6644                 fi
6645         done
6646 }
6647 run_test 103 "acl test ========================================="
6648
6649 test_104a() {
6650         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6651         touch $DIR/$tfile
6652         lfs df || error "lfs df failed"
6653         lfs df -ih || error "lfs df -ih failed"
6654         lfs df -h $DIR || error "lfs df -h $DIR failed"
6655         lfs df -i $DIR || error "lfs df -i $DIR failed"
6656         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
6657         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
6658
6659         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
6660         lctl --device %$OSC deactivate
6661         lfs df || error "lfs df with deactivated OSC failed"
6662         lctl --device %$OSC activate
6663         # wait the osc back to normal
6664         wait_osc_import_state client ost FULL
6665
6666         lfs df || error "lfs df with reactivated OSC failed"
6667         rm -f $DIR/$tfile
6668 }
6669 run_test 104a "lfs df [-ih] [path] test ========================="
6670
6671 test_104b() {
6672         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6673         [ $RUNAS_ID -eq $UID ] &&
6674                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6675         chmod 666 /dev/obd
6676         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
6677                         grep "Permission denied" | wc -l)))
6678         if [ $denied_cnt -ne 0 ]; then
6679                 error "lfs check servers test failed"
6680         fi
6681 }
6682 run_test 104b "$RUNAS lfs check servers test ===================="
6683
6684 test_105a() {
6685         # doesn't work on 2.4 kernels
6686         touch $DIR/$tfile
6687         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6688                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
6689         else
6690                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
6691         fi
6692         rm -f $DIR/$tfile
6693 }
6694 run_test 105a "flock when mounted without -o flock test ========"
6695
6696 test_105b() {
6697         touch $DIR/$tfile
6698         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6699                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
6700         else
6701                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
6702         fi
6703         rm -f $DIR/$tfile
6704 }
6705 run_test 105b "fcntl when mounted without -o flock test ========"
6706
6707 test_105c() {
6708         touch $DIR/$tfile
6709         if [ -n "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ]; then
6710                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
6711         else
6712                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
6713         fi
6714         rm -f $DIR/$tfile
6715 }
6716 run_test 105c "lockf when mounted without -o flock test ========"
6717
6718 test_105d() { # bug 15924
6719         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6720         test_mkdir -p $DIR/$tdir
6721         [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] &&
6722                 skip "mount w/o flock enabled" && return
6723         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
6724         $LCTL set_param fail_loc=0x80000315
6725         flocks_test 2 $DIR/$tdir
6726 }
6727 run_test 105d "flock race (should not freeze) ========"
6728
6729 test_105e() { # bug 22660 && 22040
6730         [ -z "$(mount | grep "$MOUNT.*flock" | grep -v noflock)" ] &&
6731                 skip "mount w/o flock enabled" && return
6732         touch $DIR/$tfile
6733         flocks_test 3 $DIR/$tfile
6734 }
6735 run_test 105e "Two conflicting flocks from same process ======="
6736
6737 test_106() { #bug 10921
6738         test_mkdir -p $DIR/$tdir
6739         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
6740         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
6741 }
6742 run_test 106 "attempt exec of dir followed by chown of that dir"
6743
6744 test_107() {
6745         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6746         CDIR=`pwd`
6747         cd $DIR
6748
6749         local file=core
6750         rm -f $file
6751
6752         local save_pattern=$(sysctl -n kernel.core_pattern)
6753         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
6754         sysctl -w kernel.core_pattern=$file
6755         sysctl -w kernel.core_uses_pid=0
6756
6757         ulimit -c unlimited
6758         sleep 60 &
6759         SLEEPPID=$!
6760
6761         sleep 1
6762
6763         kill -s 11 $SLEEPPID
6764         wait $SLEEPPID
6765         if [ -e $file ]; then
6766                 size=`stat -c%s $file`
6767                 [ $size -eq 0 ] && error "Fail to create core file $file"
6768         else
6769                 error "Fail to create core file $file"
6770         fi
6771         rm -f $file
6772         sysctl -w kernel.core_pattern=$save_pattern
6773         sysctl -w kernel.core_uses_pid=$save_uses_pid
6774         cd $CDIR
6775 }
6776 run_test 107 "Coredump on SIG"
6777
6778 test_110() {
6779         test_mkdir -p $DIR/$tdir
6780         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
6781                 error "mkdir with 255 char failed"
6782         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
6783                 error "mkdir with 256 char should fail, but did not"
6784         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
6785                 error "create with 255 char failed"
6786         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
6787                 error "create with 256 char should fail, but did not"
6788
6789         ls -l $DIR/$tdir
6790         rm -rf $DIR/$tdir
6791 }
6792 run_test 110 "filename length checking"
6793
6794 test_115() {
6795         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6796         OSTIO_pre=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
6797             cut -c11-20)
6798         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && \
6799             return
6800         echo "Starting with $OSTIO_pre threads"
6801
6802         NUMTEST=20000
6803         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
6804         [ $NUMFREE -lt $NUMTEST ] && NUMTEST=$(($NUMFREE - 1000))
6805         echo "$NUMTEST creates/unlinks"
6806         test_mkdir -p $DIR/$tdir
6807         createmany -o $DIR/$tdir/$tfile $NUMTEST
6808         unlinkmany $DIR/$tdir/$tfile $NUMTEST
6809
6810         OSTIO_post=$(ps -e|grep ll_ost_io|awk '{print $4}'|sort -n|tail -1|\
6811             cut -c11-20)
6812
6813         # don't return an error
6814         [ $OSTIO_post == $OSTIO_pre ] && echo \
6815             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
6816             echo "This may be fine, depending on what ran before this test" &&
6817             echo "and how fast this system is." && return
6818
6819         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
6820 }
6821 run_test 115 "verify dynamic thread creation===================="
6822
6823 free_min_max () {
6824         wait_delete_completed
6825         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
6826         echo OST kbytes available: ${AVAIL[@]}
6827         MAXI=0; MAXV=${AVAIL[0]}
6828         MINI=0; MINV=${AVAIL[0]}
6829         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
6830             #echo OST $i: ${AVAIL[i]}kb
6831             if [ ${AVAIL[i]} -gt $MAXV ]; then
6832                 MAXV=${AVAIL[i]}; MAXI=$i
6833             fi
6834             if [ ${AVAIL[i]} -lt $MINV ]; then
6835                 MINV=${AVAIL[i]}; MINI=$i
6836             fi
6837         done
6838         echo Min free space: OST $MINI: $MINV
6839         echo Max free space: OST $MAXI: $MAXV
6840 }
6841
6842 test_116a() { # was previously test_116()
6843         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6844         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs" && return
6845
6846         echo -n "Free space priority "
6847         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
6848                 head -n1
6849         declare -a AVAIL
6850         free_min_max
6851
6852         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
6853         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
6854                 && return
6855         trap simple_cleanup_common EXIT
6856
6857
6858         # Check if we need to generate uneven OSTs
6859         test_mkdir -p $DIR/$tdir/OST${MINI}
6860         local FILL=$(($MINV / 4))
6861         local DIFF=$(($MAXV - $MINV))
6862         local DIFF2=$(($DIFF * 100 / $MINV))
6863
6864         local threshold=$(do_facet $SINGLEMDS \
6865                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
6866         threshold=${threshold%%%}
6867         echo -n "Check for uneven OSTs: "
6868         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
6869
6870         if [ $DIFF2 -gt $threshold ]; then
6871                 echo "ok"
6872                 echo "Don't need to fill OST$MINI"
6873         else
6874                 # generate uneven OSTs. Write 2% over the QOS threshold value
6875                 echo "no"
6876                 DIFF=$(($threshold - $DIFF2 + 2))
6877                 DIFF2=$(( ($MINV * $DIFF)/100 ))
6878                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
6879                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
6880                         error "setstripe failed"
6881                 DIFF=$(($DIFF2 / 2048))
6882                 i=0
6883                 while [ $i -lt $DIFF ]; do
6884                         i=$(($i + 1))
6885                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
6886                                 bs=2M count=1 2>/dev/null
6887                         echo -n .
6888                 done
6889                 echo .
6890                 sync
6891                 sleep_maxage
6892                 free_min_max
6893         fi
6894
6895         DIFF=$(($MAXV - $MINV))
6896         DIFF2=$(($DIFF * 100 / $MINV))
6897         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
6898         if [ $DIFF2 -gt $threshold ]; then
6899                 echo "ok"
6900         else
6901                 echo "failed - QOS mode won't be used"
6902                 skip "QOS imbalance criteria not met"
6903                 simple_cleanup_common
6904                 return
6905         fi
6906
6907         MINI1=$MINI; MINV1=$MINV
6908         MAXI1=$MAXI; MAXV1=$MAXV
6909
6910         # now fill using QOS
6911         $SETSTRIPE -c 1 $DIR/$tdir
6912         FILL=$(($FILL / 200))
6913         if [ $FILL -gt 600 ]; then
6914                 FILL=600
6915         fi
6916         echo "writing $FILL files to QOS-assigned OSTs"
6917         i=0
6918         while [ $i -lt $FILL ]; do
6919                 i=$(($i + 1))
6920                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
6921                         count=1 2>/dev/null
6922                 echo -n .
6923         done
6924         echo "wrote $i 200k files"
6925         sync
6926         sleep_maxage
6927
6928         echo "Note: free space may not be updated, so measurements might be off"
6929         free_min_max
6930         DIFF2=$(($MAXV - $MINV))
6931         echo "free space delta: orig $DIFF final $DIFF2"
6932         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
6933         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
6934         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
6935         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
6936         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
6937         FILL=$(($DIFF2 * 100 / $DIFF - 100))
6938         [ $DIFF -gt 0 ] &&
6939                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
6940
6941         # Figure out which files were written where
6942         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
6943                   awk '/'$MINI1': / {print $2; exit}')
6944         echo $UUID
6945         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
6946         echo "$MINC files created on smaller OST $MINI1"
6947         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
6948                   awk '/'$MAXI1': / {print $2; exit}')
6949         echo $UUID
6950         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
6951         echo "$MAXC files created on larger OST $MAXI1"
6952         FILL=$(($MAXC * 100 / $MINC - 100))
6953         [ $MINC -gt 0 ] &&
6954                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
6955         [ $MAXC -gt $MINC ] ||
6956                 error_ignore LU-9 "stripe QOS didn't balance free space"
6957         simple_cleanup_common
6958 }
6959 run_test 116a "stripe QOS: free space balance ==================="
6960
6961 test_116b() { # LU-2093
6962         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6963 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
6964         local old_rr
6965         old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
6966                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
6967         do_facet $SINGLEMDS lctl set_param \
6968                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
6969         mkdir -p $DIR/$tdir
6970         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
6971         createmany -o $DIR/$tdir/f- 20 || error "can't create"
6972         do_facet $SINGLEMDS lctl set_param fail_loc=0
6973         rm -rf $DIR/$tdir
6974         do_facet $SINGLEMDS lctl set_param \
6975                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
6976 }
6977 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
6978
6979 test_117() # bug 10891
6980 {
6981         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6982         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
6983         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
6984         lctl set_param fail_loc=0x21e
6985         > $DIR/$tfile || error "truncate failed"
6986         lctl set_param fail_loc=0
6987         echo "Truncate succeeded."
6988         rm -f $DIR/$tfile
6989 }
6990 run_test 117 "verify osd extend =========="
6991
6992 NO_SLOW_RESENDCOUNT=4
6993 export OLD_RESENDCOUNT=""
6994 set_resend_count () {
6995         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
6996         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
6997         lctl set_param -n $PROC_RESENDCOUNT $1
6998         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
6999 }
7000
7001 # for reduce test_118* time (b=14842)
7002 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7003
7004 # Reset async IO behavior after error case
7005 reset_async() {
7006         FILE=$DIR/reset_async
7007
7008         # Ensure all OSCs are cleared
7009         $SETSTRIPE -c -1 $FILE
7010         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7011         sync
7012         rm $FILE
7013 }
7014
7015 test_118a() #bug 11710
7016 {
7017         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7018         reset_async
7019
7020         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7021         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7022         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7023
7024         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7025                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7026                 return 1;
7027         fi
7028         rm -f $DIR/$tfile
7029 }
7030 run_test 118a "verify O_SYNC works =========="
7031
7032 test_118b()
7033 {
7034         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7035         remote_ost_nodsh && skip "remote OST with nodsh" && return
7036
7037         reset_async
7038
7039         #define OBD_FAIL_OST_ENOENT 0x217
7040         set_nodes_failloc "$(osts_nodes)" 0x217
7041         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7042         RC=$?
7043         set_nodes_failloc "$(osts_nodes)" 0
7044         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7045         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7046                     grep -c writeback)
7047
7048         if [[ $RC -eq 0 ]]; then
7049                 error "Must return error due to dropped pages, rc=$RC"
7050                 return 1;
7051         fi
7052
7053         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7054                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7055                 return 1;
7056         fi
7057
7058         echo "Dirty pages not leaked on ENOENT"
7059
7060         # Due to the above error the OSC will issue all RPCs syncronously
7061         # until a subsequent RPC completes successfully without error.
7062         $MULTIOP $DIR/$tfile Ow4096yc
7063         rm -f $DIR/$tfile
7064
7065         return 0
7066 }
7067 run_test 118b "Reclaim dirty pages on fatal error =========="
7068
7069 test_118c()
7070 {
7071         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7072
7073         # for 118c, restore the original resend count, LU-1940
7074         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7075                                 set_resend_count $OLD_RESENDCOUNT
7076         remote_ost_nodsh && skip "remote OST with nodsh" && return
7077
7078         reset_async
7079
7080         #define OBD_FAIL_OST_EROFS               0x216
7081         set_nodes_failloc "$(osts_nodes)" 0x216
7082
7083         # multiop should block due to fsync until pages are written
7084         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7085         MULTIPID=$!
7086         sleep 1
7087
7088         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7089                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7090         fi
7091
7092         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7093                     grep -c writeback)
7094         if [[ $WRITEBACK -eq 0 ]]; then
7095                 error "No page in writeback, writeback=$WRITEBACK"
7096         fi
7097
7098         set_nodes_failloc "$(osts_nodes)" 0
7099         wait $MULTIPID
7100         RC=$?
7101         if [[ $RC -ne 0 ]]; then
7102                 error "Multiop fsync failed, rc=$RC"
7103         fi
7104
7105         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7106         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7107                     grep -c writeback)
7108         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7109                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7110         fi
7111
7112         rm -f $DIR/$tfile
7113         echo "Dirty pages flushed via fsync on EROFS"
7114         return 0
7115 }
7116 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7117
7118 # continue to use small resend count to reduce test_118* time (b=14842)
7119 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7120
7121 test_118d()
7122 {
7123         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7124         remote_ost_nodsh && skip "remote OST with nodsh" && return
7125
7126         reset_async
7127
7128         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7129         set_nodes_failloc "$(osts_nodes)" 0x214
7130         # multiop should block due to fsync until pages are written
7131         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7132         MULTIPID=$!
7133         sleep 1
7134
7135         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7136                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7137         fi
7138
7139         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7140                     grep -c writeback)
7141         if [[ $WRITEBACK -eq 0 ]]; then
7142                 error "No page in writeback, writeback=$WRITEBACK"
7143         fi
7144
7145         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7146         set_nodes_failloc "$(osts_nodes)" 0
7147
7148         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7149         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7150                     grep -c writeback)
7151         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7152                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7153         fi
7154
7155         rm -f $DIR/$tfile
7156         echo "Dirty pages gaurenteed flushed via fsync"
7157         return 0
7158 }
7159 run_test 118d "Fsync validation inject a delay of the bulk =========="
7160
7161 test_118f() {
7162         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7163         reset_async
7164
7165         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7166         lctl set_param fail_loc=0x8000040a
7167
7168         # Should simulate EINVAL error which is fatal
7169         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7170         RC=$?
7171         if [[ $RC -eq 0 ]]; then
7172                 error "Must return error due to dropped pages, rc=$RC"
7173         fi
7174
7175         lctl set_param fail_loc=0x0
7176
7177         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7178         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7179         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7180                     grep -c writeback)
7181         if [[ $LOCKED -ne 0 ]]; then
7182                 error "Locked pages remain in cache, locked=$LOCKED"
7183         fi
7184
7185         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7186                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7187         fi
7188
7189         rm -f $DIR/$tfile
7190         echo "No pages locked after fsync"
7191
7192         reset_async
7193         return 0
7194 }
7195 run_test 118f "Simulate unrecoverable OSC side error =========="
7196
7197 test_118g() {
7198         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7199         reset_async
7200
7201         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7202         lctl set_param fail_loc=0x406
7203
7204         # simulate local -ENOMEM
7205         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7206         RC=$?
7207
7208         lctl set_param fail_loc=0
7209         if [[ $RC -eq 0 ]]; then
7210                 error "Must return error due to dropped pages, rc=$RC"
7211         fi
7212
7213         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7214         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7215         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7216                         grep -c writeback)
7217         if [[ $LOCKED -ne 0 ]]; then
7218                 error "Locked pages remain in cache, locked=$LOCKED"
7219         fi
7220
7221         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7222                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7223         fi
7224
7225         rm -f $DIR/$tfile
7226         echo "No pages locked after fsync"
7227
7228         reset_async
7229         return 0
7230 }
7231 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7232
7233 test_118h() {
7234         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7235         remote_ost_nodsh && skip "remote OST with nodsh" && return
7236
7237         reset_async
7238
7239         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7240         set_nodes_failloc "$(osts_nodes)" 0x20e
7241         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7242         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7243         RC=$?
7244
7245         set_nodes_failloc "$(osts_nodes)" 0
7246         if [[ $RC -eq 0 ]]; then
7247                 error "Must return error due to dropped pages, rc=$RC"
7248         fi
7249
7250         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7251         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7252         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7253                     grep -c writeback)
7254         if [[ $LOCKED -ne 0 ]]; then
7255                 error "Locked pages remain in cache, locked=$LOCKED"
7256         fi
7257
7258         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7259                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7260         fi
7261
7262         rm -f $DIR/$tfile
7263         echo "No pages locked after fsync"
7264
7265         return 0
7266 }
7267 run_test 118h "Verify timeout in handling recoverables errors  =========="
7268
7269 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7270
7271 test_118i() {
7272         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7273         remote_ost_nodsh && skip "remote OST with nodsh" && return
7274
7275         reset_async
7276
7277         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7278         set_nodes_failloc "$(osts_nodes)" 0x20e
7279
7280         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7281         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7282         PID=$!
7283         sleep 5
7284         set_nodes_failloc "$(osts_nodes)" 0
7285
7286         wait $PID
7287         RC=$?
7288         if [[ $RC -ne 0 ]]; then
7289                 error "got error, but should be not, rc=$RC"
7290         fi
7291
7292         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7293         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7294         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7295         if [[ $LOCKED -ne 0 ]]; then
7296                 error "Locked pages remain in cache, locked=$LOCKED"
7297         fi
7298
7299         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7300                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7301         fi
7302
7303         rm -f $DIR/$tfile
7304         echo "No pages locked after fsync"
7305
7306         return 0
7307 }
7308 run_test 118i "Fix error before timeout in recoverable error  =========="
7309
7310 [ "$SLOW" = "no" ] && set_resend_count 4
7311
7312 test_118j() {
7313         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7314         remote_ost_nodsh && skip "remote OST with nodsh" && return
7315
7316         reset_async
7317
7318         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7319         set_nodes_failloc "$(osts_nodes)" 0x220
7320
7321         # return -EIO from OST
7322         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7323         RC=$?
7324         set_nodes_failloc "$(osts_nodes)" 0x0
7325         if [[ $RC -eq 0 ]]; then
7326                 error "Must return error due to dropped pages, rc=$RC"
7327         fi
7328
7329         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7330         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7331         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7332         if [[ $LOCKED -ne 0 ]]; then
7333                 error "Locked pages remain in cache, locked=$LOCKED"
7334         fi
7335
7336         # in recoverable error on OST we want resend and stay until it finished
7337         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7338                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7339         fi
7340
7341         rm -f $DIR/$tfile
7342         echo "No pages locked after fsync"
7343
7344         return 0
7345 }
7346 run_test 118j "Simulate unrecoverable OST side error =========="
7347
7348 test_118k()
7349 {
7350         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7351         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7352
7353         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7354         set_nodes_failloc "$(osts_nodes)" 0x20e
7355         test_mkdir -p $DIR/$tdir
7356
7357         for ((i=0;i<10;i++)); do
7358                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7359                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7360                 SLEEPPID=$!
7361                 sleep 0.500s
7362                 kill $SLEEPPID
7363                 wait $SLEEPPID
7364         done
7365
7366         set_nodes_failloc "$(osts_nodes)" 0
7367         rm -rf $DIR/$tdir
7368 }
7369 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7370
7371 test_118l()
7372 {
7373         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7374         # LU-646
7375         test_mkdir -p $DIR/$tdir
7376         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7377         rm -rf $DIR/$tdir
7378 }
7379 run_test 118l "fsync dir ========="
7380
7381 test_118m() # LU-3066
7382 {
7383         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7384         test_mkdir -p $DIR/$tdir
7385         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7386         rm -rf $DIR/$tdir
7387 }
7388 run_test 118m "fdatasync dir ========="
7389
7390 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7391
7392 test_119a() # bug 11737
7393 {
7394         BSIZE=$((512 * 1024))
7395         directio write $DIR/$tfile 0 1 $BSIZE
7396         # We ask to read two blocks, which is more than a file size.
7397         # directio will indicate an error when requested and actual
7398         # sizes aren't equeal (a normal situation in this case) and
7399         # print actual read amount.
7400         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7401         if [ "$NOB" != "$BSIZE" ]; then
7402                 error "read $NOB bytes instead of $BSIZE"
7403         fi
7404         rm -f $DIR/$tfile
7405 }
7406 run_test 119a "Short directIO read must return actual read amount"
7407
7408 test_119b() # bug 11737
7409 {
7410         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7411
7412         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7413         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7414         sync
7415         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7416                 error "direct read failed"
7417         rm -f $DIR/$tfile
7418 }
7419 run_test 119b "Sparse directIO read must return actual read amount"
7420
7421 test_119c() # bug 13099
7422 {
7423         BSIZE=1048576
7424         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7425         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7426         rm -f $DIR/$tfile
7427 }
7428 run_test 119c "Testing for direct read hitting hole"
7429
7430 test_119d() # bug 15950
7431 {
7432         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7433         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7434         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7435         BSIZE=1048576
7436         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7437         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7438         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7439         lctl set_param fail_loc=0x40d
7440         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7441         pid_dio=$!
7442         sleep 1
7443         cat $DIR/$tfile > /dev/null &
7444         lctl set_param fail_loc=0
7445         pid_reads=$!
7446         wait $pid_dio
7447         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7448         sleep 2
7449         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7450         error "the read rpcs have not completed in 2s"
7451         rm -f $DIR/$tfile
7452         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7453 }
7454 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7455
7456 test_120a() {
7457         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7458         test_mkdir -p $DIR/$tdir
7459         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7460                skip "no early lock cancel on server" && return 0
7461
7462         lru_resize_disable mdc
7463         lru_resize_disable osc
7464         cancel_lru_locks mdc
7465         # asynchronous object destroy at MDT could cause bl ast to client
7466         cancel_lru_locks osc
7467
7468         stat $DIR/$tdir > /dev/null
7469         can1=$(do_facet $SINGLEMDS \
7470                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7471                awk '/ldlm_cancel/ {print $2}')
7472         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7473                awk '/ldlm_bl_callback/ {print $2}')
7474         test_mkdir -c1 $DIR/$tdir/d1
7475         can2=$(do_facet $SINGLEMDS \
7476                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7477                awk '/ldlm_cancel/ {print $2}')
7478         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7479                awk '/ldlm_bl_callback/ {print $2}')
7480         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7481         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7482         lru_resize_enable mdc
7483         lru_resize_enable osc
7484 }
7485 run_test 120a "Early Lock Cancel: mkdir test"
7486
7487 test_120b() {
7488         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7489         test_mkdir $DIR/$tdir
7490         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7491                skip "no early lock cancel on server" && return 0
7492         lru_resize_disable mdc
7493         lru_resize_disable osc
7494         cancel_lru_locks mdc
7495         stat $DIR/$tdir > /dev/null
7496         can1=$(do_facet $SINGLEMDS \
7497                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7498                awk '/ldlm_cancel/ {print $2}')
7499         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7500                awk '/ldlm_bl_callback/ {print $2}')
7501         touch $DIR/$tdir/f1
7502         can2=$(do_facet $SINGLEMDS \
7503                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7504                awk '/ldlm_cancel/ {print $2}')
7505         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7506                awk '/ldlm_bl_callback/ {print $2}')
7507         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7508         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7509         lru_resize_enable mdc
7510         lru_resize_enable osc
7511 }
7512 run_test 120b "Early Lock Cancel: create test"
7513
7514 test_120c() {
7515         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7516         test_mkdir -c1 $DIR/$tdir
7517         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7518                skip "no early lock cancel on server" && return 0
7519         lru_resize_disable mdc
7520         lru_resize_disable osc
7521         test_mkdir -p -c1 $DIR/$tdir/d1
7522         test_mkdir -p -c1 $DIR/$tdir/d2
7523         touch $DIR/$tdir/d1/f1
7524         cancel_lru_locks mdc
7525         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7526         can1=$(do_facet $SINGLEMDS \
7527                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7528                awk '/ldlm_cancel/ {print $2}')
7529         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7530                awk '/ldlm_bl_callback/ {print $2}')
7531         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7532         can2=$(do_facet $SINGLEMDS \
7533                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7534                awk '/ldlm_cancel/ {print $2}')
7535         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7536                awk '/ldlm_bl_callback/ {print $2}')
7537         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7538         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7539         lru_resize_enable mdc
7540         lru_resize_enable osc
7541 }
7542 run_test 120c "Early Lock Cancel: link test"
7543
7544 test_120d() {
7545         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7546         test_mkdir -p -c1 $DIR/$tdir
7547         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7548                skip "no early lock cancel on server" && return 0
7549         lru_resize_disable mdc
7550         lru_resize_disable osc
7551         touch $DIR/$tdir
7552         cancel_lru_locks mdc
7553         stat $DIR/$tdir > /dev/null
7554         can1=$(do_facet $SINGLEMDS \
7555                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7556                awk '/ldlm_cancel/ {print $2}')
7557         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7558                awk '/ldlm_bl_callback/ {print $2}')
7559         chmod a+x $DIR/$tdir
7560         can2=$(do_facet $SINGLEMDS \
7561                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7562                awk '/ldlm_cancel/ {print $2}')
7563         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7564                awk '/ldlm_bl_callback/ {print $2}')
7565         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7566         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7567         lru_resize_enable mdc
7568         lru_resize_enable osc
7569 }
7570 run_test 120d "Early Lock Cancel: setattr test"
7571
7572 test_120e() {
7573         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7574         test_mkdir -p -c1 $DIR/$tdir
7575         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7576                skip "no early lock cancel on server" && return 0
7577         lru_resize_disable mdc
7578         lru_resize_disable osc
7579         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
7580         cancel_lru_locks mdc
7581         cancel_lru_locks osc
7582         dd if=$DIR/$tdir/f1 of=/dev/null
7583         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
7584         can1=$(do_facet $SINGLEMDS \
7585                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7586                awk '/ldlm_cancel/ {print $2}')
7587         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7588                awk '/ldlm_bl_callback/ {print $2}')
7589         unlink $DIR/$tdir/f1
7590         can2=$(do_facet $SINGLEMDS \
7591                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7592                awk '/ldlm_cancel/ {print $2}')
7593         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7594                awk '/ldlm_bl_callback/ {print $2}')
7595         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7596         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7597         lru_resize_enable mdc
7598         lru_resize_enable osc
7599 }
7600 run_test 120e "Early Lock Cancel: unlink test"
7601
7602 test_120f() {
7603         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7604         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7605                skip "no early lock cancel on server" && return 0
7606         test_mkdir -p -c1 $DIR/$tdir
7607         lru_resize_disable mdc
7608         lru_resize_disable osc
7609         test_mkdir -p -c1 $DIR/$tdir/d1
7610         test_mkdir -p -c1 $DIR/$tdir/d2
7611         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
7612         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
7613         cancel_lru_locks mdc
7614         cancel_lru_locks osc
7615         dd if=$DIR/$tdir/d1/f1 of=/dev/null
7616         dd if=$DIR/$tdir/d2/f2 of=/dev/null
7617         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
7618         can1=$(do_facet $SINGLEMDS \
7619                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7620                awk '/ldlm_cancel/ {print $2}')
7621         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7622                awk '/ldlm_bl_callback/ {print $2}')
7623         mv $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7624         can2=$(do_facet $SINGLEMDS \
7625                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7626                awk '/ldlm_cancel/ {print $2}')
7627         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7628                awk '/ldlm_bl_callback/ {print $2}')
7629         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7630         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7631         lru_resize_enable mdc
7632         lru_resize_enable osc
7633 }
7634 run_test 120f "Early Lock Cancel: rename test"
7635
7636 test_120g() {
7637         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7638         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7639                skip "no early lock cancel on server" && return 0
7640         lru_resize_disable mdc
7641         lru_resize_disable osc
7642         count=10000
7643         echo create $count files
7644         test_mkdir -p $DIR/$tdir
7645         cancel_lru_locks mdc
7646         cancel_lru_locks osc
7647         t0=`date +%s`
7648
7649         can0=$(do_facet $SINGLEMDS \
7650                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7651                awk '/ldlm_cancel/ {print $2}')
7652         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7653                awk '/ldlm_bl_callback/ {print $2}')
7654         createmany -o $DIR/$tdir/f $count
7655         sync
7656         can1=$(do_facet $SINGLEMDS \
7657                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7658                awk '/ldlm_cancel/ {print $2}')
7659         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7660                awk '/ldlm_bl_callback/ {print $2}')
7661         t1=$(date +%s)
7662         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
7663         echo rm $count files
7664         rm -r $DIR/$tdir
7665         sync
7666         can2=$(do_facet $SINGLEMDS \
7667                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7668                awk '/ldlm_cancel/ {print $2}')
7669         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7670                awk '/ldlm_bl_callback/ {print $2}')
7671         t2=$(date +%s)
7672         echo total: $count removes in $((t2-t1))
7673         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
7674         sleep 2
7675         # wait for commitment of removal
7676         lru_resize_enable mdc
7677         lru_resize_enable osc
7678 }
7679 run_test 120g "Early Lock Cancel: performance test"
7680
7681 test_121() { #bug #10589
7682         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7683         rm -rf $DIR/$tfile
7684         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
7685 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
7686         lctl set_param fail_loc=0x310
7687         cancel_lru_locks osc > /dev/null
7688         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
7689         lctl set_param fail_loc=0
7690         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
7691 }
7692 run_test 121 "read cancel race ========="
7693
7694 test_123a() { # was test 123, statahead(bug 11401)
7695         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7696         SLOWOK=0
7697         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
7698             log "testing on UP system. Performance may be not as good as expected."
7699                         SLOWOK=1
7700         fi
7701
7702         rm -rf $DIR/$tdir
7703         test_mkdir -p $DIR/$tdir
7704         NUMFREE=`df -i -P $DIR | tail -n 1 | awk '{ print $4 }'`
7705         [ $NUMFREE -gt 100000 ] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
7706         MULT=10
7707         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
7708                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
7709
7710                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7711                 lctl set_param -n llite.*.statahead_max 0
7712                 lctl get_param llite.*.statahead_max
7713                 cancel_lru_locks mdc
7714                 cancel_lru_locks osc
7715                 stime=`date +%s`
7716                 time ls -l $DIR/$tdir | wc -l
7717                 etime=`date +%s`
7718                 delta=$((etime - stime))
7719                 log "ls $i files without statahead: $delta sec"
7720                 lctl set_param llite.*.statahead_max=$max
7721
7722                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7723                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
7724                 cancel_lru_locks mdc
7725                 cancel_lru_locks osc
7726                 stime=`date +%s`
7727                 time ls -l $DIR/$tdir | wc -l
7728                 etime=`date +%s`
7729                 delta_sa=$((etime - stime))
7730                 log "ls $i files with statahead: $delta_sa sec"
7731                 lctl get_param -n llite.*.statahead_stats
7732                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7733
7734                 [ $swrong -lt $ewrong ] && log "statahead was stopped, maybe too many locks held!"
7735                 [ $delta -eq 0 -o $delta_sa -eq 0 ] && continue
7736
7737                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7738                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7739                     lctl set_param -n llite.*.statahead_max 0
7740                     lctl get_param llite.*.statahead_max
7741                     cancel_lru_locks mdc
7742                     cancel_lru_locks osc
7743                     stime=`date +%s`
7744                     time ls -l $DIR/$tdir | wc -l
7745                     etime=`date +%s`
7746                     delta=$((etime - stime))
7747                     log "ls $i files again without statahead: $delta sec"
7748                     lctl set_param llite.*.statahead_max=$max
7749                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7750                         if [  $SLOWOK -eq 0 ]; then
7751                                 error "ls $i files is slower with statahead!"
7752                         else
7753                                 log "ls $i files is slower with statahead!"
7754                         fi
7755                         break
7756                     fi
7757                 fi
7758
7759                 [ $delta -gt 20 ] && break
7760                 [ $delta -gt 8 ] && MULT=$((50 / delta))
7761                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
7762         done
7763         log "ls done"
7764
7765         stime=`date +%s`
7766         rm -r $DIR/$tdir
7767         sync
7768         etime=`date +%s`
7769         delta=$((etime - stime))
7770         log "rm -r $DIR/$tdir/: $delta seconds"
7771         log "rm done"
7772         lctl get_param -n llite.*.statahead_stats
7773 }
7774 run_test 123a "verify statahead work"
7775
7776 test_123b () { # statahead(bug 15027)
7777         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7778         test_mkdir -p $DIR/$tdir
7779         createmany -o $DIR/$tdir/$tfile-%d 1000
7780
7781         cancel_lru_locks mdc
7782         cancel_lru_locks osc
7783
7784 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
7785         lctl set_param fail_loc=0x80000803
7786         ls -lR $DIR/$tdir > /dev/null
7787         log "ls done"
7788         lctl set_param fail_loc=0x0
7789         lctl get_param -n llite.*.statahead_stats
7790         rm -r $DIR/$tdir
7791         sync
7792
7793 }
7794 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
7795
7796 test_124a() {
7797         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7798         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
7799                skip "no lru resize on server" && return 0
7800         local NR=2000
7801         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
7802
7803         log "create $NR files at $DIR/$tdir"
7804         createmany -o $DIR/$tdir/f $NR ||
7805                 error "failed to create $NR files in $DIR/$tdir"
7806
7807         cancel_lru_locks mdc
7808         ls -l $DIR/$tdir > /dev/null
7809
7810         local NSDIR=""
7811         local LRU_SIZE=0
7812         for VALUE in `lctl get_param ldlm.namespaces.*mdc-*.lru_size`; do
7813                 local PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
7814                 LRU_SIZE=$(lctl get_param -n $PARAM)
7815                 if [ $LRU_SIZE -gt $(default_lru_size) ]; then
7816                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
7817                                                 log "NSDIR=$NSDIR"
7818                         log "NS=$(basename $NSDIR)"
7819                         break
7820                 fi
7821         done
7822
7823         if [ -z "$NSDIR" -o $LRU_SIZE -lt $(default_lru_size) ]; then
7824                 skip "Not enough cached locks created!"
7825                 return 0
7826         fi
7827         log "LRU=$LRU_SIZE"
7828
7829         local SLEEP=30
7830
7831         # We know that lru resize allows one client to hold $LIMIT locks
7832         # for 10h. After that locks begin to be killed by client.
7833         local MAX_HRS=10
7834         local LIMIT=`lctl get_param -n $NSDIR.pool.limit`
7835                 log "LIMIT=$LIMIT"
7836
7837         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
7838         # killing locks. Some time was spent for creating locks. This means
7839         # that up to the moment of sleep finish we must have killed some of
7840         # them (10-100 locks). This depends on how fast ther were created.
7841         # Many of them were touched in almost the same moment and thus will
7842         # be killed in groups.
7843         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
7844
7845         # Use $LRU_SIZE_B here to take into account real number of locks
7846         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
7847         local LRU_SIZE_B=$LRU_SIZE
7848         log "LVF=$LVF"
7849         local OLD_LVF=`lctl get_param -n $NSDIR.pool.lock_volume_factor`
7850                 log "OLD_LVF=$OLD_LVF"
7851         lctl set_param -n $NSDIR.pool.lock_volume_factor $LVF
7852
7853         # Let's make sure that we really have some margin. Client checks
7854         # cached locks every 10 sec.
7855         SLEEP=$((SLEEP+20))
7856         log "Sleep ${SLEEP} sec"
7857         local SEC=0
7858         while ((SEC<$SLEEP)); do
7859                 echo -n "..."
7860                 sleep 5
7861                 SEC=$((SEC+5))
7862                 LRU_SIZE=`lctl get_param -n $NSDIR/lru_size`
7863                 echo -n "$LRU_SIZE"
7864         done
7865         echo ""
7866         lctl set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
7867         local LRU_SIZE_A=`lctl get_param -n $NSDIR.lru_size`
7868
7869         [ $LRU_SIZE_B -gt $LRU_SIZE_A ] || {
7870                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
7871                 unlinkmany $DIR/$tdir/f $NR
7872                 return
7873         }
7874
7875         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
7876         log "unlink $NR files at $DIR/$tdir"
7877         unlinkmany $DIR/$tdir/f $NR
7878 }
7879 run_test 124a "lru resize ======================================="
7880
7881 get_max_pool_limit()
7882 {
7883         local limit=`lctl get_param -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit`
7884         local max=0
7885         for l in $limit; do
7886                 if test $l -gt $max; then
7887                         max=$l
7888                 fi
7889         done
7890         echo $max
7891 }
7892
7893 test_124b() {
7894         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7895         [ -z "`lctl get_param -n mdc.*.connect_flags | grep lru_resize`" ] && \
7896                skip "no lru resize on server" && return 0
7897
7898         LIMIT=`get_max_pool_limit`
7899
7900         NR=$(($(default_lru_size)*20))
7901         if [ $NR -gt $LIMIT ]; then
7902                 log "Limit lock number by $LIMIT locks"
7903                 NR=$LIMIT
7904         fi
7905         lru_resize_disable mdc
7906         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
7907                 error "failed to create $DIR/$tdir/disable_lru_resize"
7908
7909         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
7910         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
7911         cancel_lru_locks mdc
7912         stime=`date +%s`
7913         PID=""
7914         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7915         PID="$PID $!"
7916         sleep 2
7917         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7918         PID="$PID $!"
7919         sleep 2
7920         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
7921         PID="$PID $!"
7922         wait $PID
7923         etime=`date +%s`
7924         nolruresize_delta=$((etime-stime))
7925         log "ls -la time: $nolruresize_delta seconds"
7926         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
7927         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
7928
7929         lru_resize_enable mdc
7930         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
7931                 error "failed to create $DIR/$tdir/enable_lru_resize"
7932
7933         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
7934         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
7935         cancel_lru_locks mdc
7936         stime=`date +%s`
7937         PID=""
7938         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7939         PID="$PID $!"
7940         sleep 2
7941         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7942         PID="$PID $!"
7943         sleep 2
7944         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
7945         PID="$PID $!"
7946         wait $PID
7947         etime=`date +%s`
7948         lruresize_delta=$((etime-stime))
7949         log "ls -la time: $lruresize_delta seconds"
7950         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
7951
7952         if [ $lruresize_delta -gt $nolruresize_delta ]; then
7953                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
7954         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
7955                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
7956         else
7957                 log "lru resize performs the same with no lru resize"
7958         fi
7959         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
7960 }
7961 run_test 124b "lru resize (performance test) ======================="
7962
7963 test_125() { # 13358
7964         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
7965         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
7966         test_mkdir -p $DIR/d125 || error "mkdir failed"
7967         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
7968         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
7969         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
7970 }
7971 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
7972
7973 test_126() { # bug 12829/13455
7974         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
7975         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
7976         $GSS && skip "must run as gss disabled" && return
7977
7978         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
7979         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
7980         rm -f $DIR/$tfile
7981         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
7982 }
7983 run_test 126 "check that the fsgid provided by the client is taken into account"
7984
7985 test_127a() { # bug 15521
7986         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7987         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
7988         $LCTL set_param osc.*.stats=0
7989         FSIZE=$((2048 * 1024))
7990         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
7991         cancel_lru_locks osc
7992         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
7993
7994         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
7995         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
7996                 echo "got $COUNT $NAME"
7997                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
7998                 eval $NAME=$COUNT || error "Wrong proc format"
7999
8000                 case $NAME in
8001                         read_bytes|write_bytes)
8002                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8003                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8004                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8005                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8006                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8007                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8008                                 error "sumsquare is too small: $SUMSQ"
8009                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8010                                 error "sumsquare is too big: $SUMSQ"
8011                         ;;
8012                         *) ;;
8013                 esac
8014         done < $DIR/${tfile}.tmp
8015
8016         #check that we actually got some stats
8017         [ "$read_bytes" ] || error "Missing read_bytes stats"
8018         [ "$write_bytes" ] || error "Missing write_bytes stats"
8019         [ "$read_bytes" != 0 ] || error "no read done"
8020         [ "$write_bytes" != 0 ] || error "no write done"
8021 }
8022 run_test 127a "verify the client stats are sane"
8023
8024 test_127b() { # bug LU-333
8025         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8026         $LCTL set_param llite.*.stats=0
8027         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8028         # perform 2 reads and writes so MAX is different from SUM.
8029         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8030         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8031         cancel_lru_locks osc
8032         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8033         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8034
8035         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8036         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8037                 echo "got $COUNT $NAME"
8038                 eval $NAME=$COUNT || error "Wrong proc format"
8039
8040         case $NAME in
8041                 read_bytes)
8042                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8043                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8044                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8045                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8046                         ;;
8047                 write_bytes)
8048                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8049                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8050                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8051                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8052                         ;;
8053                         *) ;;
8054                 esac
8055         done < $TMP/${tfile}.tmp
8056
8057         #check that we actually got some stats
8058         [ "$read_bytes" ] || error "Missing read_bytes stats"
8059         [ "$write_bytes" ] || error "Missing write_bytes stats"
8060         [ "$read_bytes" != 0 ] || error "no read done"
8061         [ "$write_bytes" != 0 ] || error "no write done"
8062 }
8063 run_test 127b "verify the llite client stats are sane"
8064
8065 test_128() { # bug 15212
8066         touch $DIR/$tfile
8067         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8068                 find $DIR/$tfile
8069                 find $DIR/$tfile
8070         EOF
8071
8072         result=$(grep error $TMP/$tfile.log)
8073         rm -f $DIR/$tfile
8074         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8075 }
8076 run_test 128 "interactive lfs for 2 consecutive find's"
8077
8078 set_dir_limits () {
8079         local mntdev
8080         local canondev
8081         local node
8082
8083         local LDPROC=/proc/fs/ldiskfs
8084         local facets=$(get_facets MDS)
8085
8086         for facet in ${facets//,/ }; do
8087                 canondev=$(ldiskfs_canon \
8088                            *.$(convert_facet2label $facet).mntdev $facet)
8089                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8090                                                 LDPROC=/sys/fs/ldiskfs
8091                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8092         done
8093 }
8094
8095 test_129() {
8096         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8097         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8098                 skip "Only applicable to ldiskfs-based MDTs"
8099                 return
8100         fi
8101         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8102         ENOSPC=28
8103         EFBIG=27
8104
8105         rm -rf $DIR/$tdir
8106         test_mkdir -p $DIR/$tdir
8107
8108         # block size of mds1
8109         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8110         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8111         local MAX=$((MDSBLOCKSIZE * 3))
8112         set_dir_limits $MAX
8113         local I=$(stat -c%s "$DIR/$tdir")
8114         local J=0
8115         local STRIPE_COUNT=1
8116         [ $MDSCOUNT -ge 2 ] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8117         MAX=$((MAX*STRIPE_COUNT))
8118         while [ ! $I -gt $MAX ]; do
8119                 $MULTIOP $DIR/$tdir/$J Oc
8120                 rc=$?
8121                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8122                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8123                 #and EFBIG for previous versions
8124                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8125                         set_dir_limits 0
8126                         echo "return code $rc received as expected"
8127                         multiop $DIR/$tdir/$J Oc ||
8128                                 error_exit "multiop failed w/o dir size limit"
8129
8130                         I=$(stat -c%s "$DIR/$tdir")
8131
8132                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8133                                         $(version_code 2.4.51) ]
8134                         then
8135                                 [ $I -eq $MAX ] && return 0
8136                         else
8137                                 [ $I -gt $MAX ] && return 0
8138                         fi
8139                         error_exit "current dir size $I, previous limit $MAX"
8140                 elif [ $rc -ne 0 ]; then
8141                         set_dir_limits 0
8142                         error_exit "return code $rc received instead of expected " \
8143                                    "$EFBIG or $ENOSPC, files in dir $I"
8144                 fi
8145                 J=$((J+1))
8146                 I=$(stat -c%s "$DIR/$tdir")
8147         done
8148
8149         set_dir_limits 0
8150         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8151 }
8152 run_test 129 "test directory size limit ========================"
8153
8154 OLDIFS="$IFS"
8155 cleanup_130() {
8156         trap 0
8157         IFS="$OLDIFS"
8158 }
8159
8160 test_130a() {
8161         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8162         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8163                 return
8164
8165         trap cleanup_130 EXIT RETURN
8166
8167         local fm_file=$DIR/$tfile
8168         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8169         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8170                 error "dd failed for $fm_file"
8171
8172         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8173         filefrag -ves $fm_file
8174         RC=$?
8175         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8176                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8177         [ $RC != 0 ] && error "filefrag $fm_file failed"
8178
8179         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8180                       grep -v "ext:" | grep -v "found")
8181         lun=$($GETSTRIPE -i $fm_file)
8182
8183         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8184         IFS=$'\n'
8185         tot_len=0
8186         for line in $filefrag_op
8187         do
8188                 frag_lun=`echo $line | cut -d: -f5`
8189                 ext_len=`echo $line | cut -d: -f4`
8190                 if (( $frag_lun != $lun )); then
8191                         cleanup_130
8192                         error "FIEMAP on 1-stripe file($fm_file) failed"
8193                         return
8194                 fi
8195                 (( tot_len += ext_len ))
8196         done
8197
8198         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8199                 cleanup_130
8200                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8201                 return
8202         fi
8203
8204         cleanup_130
8205
8206         echo "FIEMAP on single striped file succeeded"
8207 }
8208 run_test 130a "FIEMAP (1-stripe file)"
8209
8210 test_130b() {
8211         [ "$OSTCOUNT" -lt "2" ] &&
8212                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8213
8214         [ "$OSTCOUNT" -ge "10" ] &&
8215                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8216
8217         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8218         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8219                 return
8220
8221         trap cleanup_130 EXIT RETURN
8222
8223         local fm_file=$DIR/$tfile
8224         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8225         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8226                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8227
8228         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8229                 error "dd failed on $fm_file"
8230
8231         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8232         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8233                       grep -v "ext:" | grep -v "found")
8234
8235         last_lun=$(echo $filefrag_op | cut -d: -f5)
8236
8237         IFS=$'\n'
8238         tot_len=0
8239         num_luns=1
8240         for line in $filefrag_op
8241         do
8242                 frag_lun=`echo $line | cut -d: -f5`
8243                 ext_len=`echo $line | cut -d: -f4`
8244                 if (( $frag_lun != $last_lun )); then
8245                         if (( tot_len != 1024 )); then
8246                                 cleanup_130
8247                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8248                                 return
8249                         else
8250                                 (( num_luns += 1 ))
8251                                 tot_len=0
8252                         fi
8253                 fi
8254                 (( tot_len += ext_len ))
8255                 last_lun=$frag_lun
8256         done
8257         if (( num_luns != 2 || tot_len != 1024 )); then
8258                 cleanup_130
8259                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8260                 return
8261         fi
8262
8263         cleanup_130
8264
8265         echo "FIEMAP on 2-stripe file succeeded"
8266 }
8267 run_test 130b "FIEMAP (2-stripe file)"
8268
8269 test_130c() {
8270         [ "$OSTCOUNT" -lt "2" ] &&
8271                 skip_env "skipping FIEMAP on 2-stripe file" && return
8272
8273         [ "$OSTCOUNT" -ge "10" ] &&
8274                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8275
8276         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8277         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8278                 return
8279
8280         trap cleanup_130 EXIT RETURN
8281
8282         local fm_file=$DIR/$tfile
8283         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8284         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8285                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8286
8287         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8288
8289         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8290         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8291
8292         last_lun=`echo $filefrag_op | cut -d: -f5`
8293
8294         IFS=$'\n'
8295         tot_len=0
8296         num_luns=1
8297         for line in $filefrag_op
8298         do
8299                 frag_lun=`echo $line | cut -d: -f5`
8300                 ext_len=`echo $line | cut -d: -f4`
8301                 if (( $frag_lun != $last_lun )); then
8302                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8303                         if (( logical != 512 )); then
8304                                 cleanup_130
8305                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8306                                 return
8307                         fi
8308                         if (( tot_len != 512 )); then
8309                                 cleanup_130
8310                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8311                                 return
8312                         else
8313                                 (( num_luns += 1 ))
8314                                 tot_len=0
8315                         fi
8316                 fi
8317                 (( tot_len += ext_len ))
8318                 last_lun=$frag_lun
8319         done
8320         if (( num_luns != 2 || tot_len != 512 )); then
8321                 cleanup_130
8322                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8323                 return
8324         fi
8325
8326         cleanup_130
8327
8328         echo "FIEMAP on 2-stripe file with hole succeeded"
8329 }
8330 run_test 130c "FIEMAP (2-stripe file with hole)"
8331
8332 test_130d() {
8333         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8334
8335         [ "$OSTCOUNT" -ge "10" ] &&
8336                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8337
8338         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8339         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8340
8341         trap cleanup_130 EXIT RETURN
8342
8343         local fm_file=$DIR/$tfile
8344         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8345         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8346                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8347
8348         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8349         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8350                 error "dd failed on $fm_file"
8351
8352         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8353         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8354                 grep -v "ext:" | grep -v "found"`
8355
8356         last_lun=`echo $filefrag_op | cut -d: -f5`
8357
8358         IFS=$'\n'
8359         tot_len=0
8360         num_luns=1
8361         for line in $filefrag_op
8362         do
8363                 frag_lun=`echo $line | cut -d: -f5`
8364                 ext_len=`echo $line | cut -d: -f4`
8365                 if (( $frag_lun != $last_lun )); then
8366                         if (( tot_len != 1024 )); then
8367                                 cleanup_130
8368                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8369                                 return
8370                         else
8371                                 (( num_luns += 1 ))
8372                                 tot_len=0
8373                         fi
8374                 fi
8375                 (( tot_len += ext_len ))
8376                 last_lun=$frag_lun
8377         done
8378         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8379                 cleanup_130
8380                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8381                 return
8382         fi
8383
8384         cleanup_130
8385
8386         echo "FIEMAP on N-stripe file succeeded"
8387 }
8388 run_test 130d "FIEMAP (N-stripe file)"
8389
8390 test_130e() {
8391         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8392
8393         [ "$OSTCOUNT" -ge "10" ] &&
8394                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8395
8396         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8397         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8398
8399         trap cleanup_130 EXIT RETURN
8400
8401         local fm_file=$DIR/$tfile
8402         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8403         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8404                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8405
8406         NUM_BLKS=512
8407         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8408         for ((i = 0; i < $NUM_BLKS; i++))
8409         do
8410                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8411         done
8412
8413         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8414         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8415
8416         last_lun=`echo $filefrag_op | cut -d: -f5`
8417
8418         IFS=$'\n'
8419         tot_len=0
8420         num_luns=1
8421         for line in $filefrag_op
8422         do
8423                 frag_lun=`echo $line | cut -d: -f5`
8424                 ext_len=`echo $line | cut -d: -f4`
8425                 if (( $frag_lun != $last_lun )); then
8426                         if (( tot_len != $EXPECTED_LEN )); then
8427                                 cleanup_130
8428                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8429                                 return
8430                         else
8431                                 (( num_luns += 1 ))
8432                                 tot_len=0
8433                         fi
8434                 fi
8435                 (( tot_len += ext_len ))
8436                 last_lun=$frag_lun
8437         done
8438         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8439                 cleanup_130
8440                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8441                 return
8442         fi
8443
8444         cleanup_130
8445
8446         echo "FIEMAP with continuation calls succeeded"
8447 }
8448 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8449
8450 # Test for writev/readv
8451 test_131a() {
8452         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8453         error "writev test failed"
8454         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8455         error "readv failed"
8456         rm -f $DIR/$tfile
8457 }
8458 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8459
8460 test_131b() {
8461         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8462         error "append writev test failed"
8463         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8464         error "append writev test failed"
8465         rm -f $DIR/$tfile
8466 }
8467 run_test 131b "test append writev"
8468
8469 test_131c() {
8470         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8471         error "NOT PASS"
8472 }
8473 run_test 131c "test read/write on file w/o objects"
8474
8475 test_131d() {
8476         rwv -f $DIR/$tfile -w -n 1 1572864
8477         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8478         if [ "$NOB" != 1572864 ]; then
8479                 error "Short read filed: read $NOB bytes instead of 1572864"
8480         fi
8481         rm -f $DIR/$tfile
8482 }
8483 run_test 131d "test short read"
8484
8485 test_131e() {
8486         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8487         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8488         error "read hitting hole failed"
8489         rm -f $DIR/$tfile
8490 }
8491 run_test 131e "test read hitting hole"
8492
8493 get_ost_param() {
8494         local token=$1
8495         local gl_sum=0
8496         for node in $(osts_nodes); do
8497                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
8498                 [ x$gl = x"" ] && gl=0
8499                 gl_sum=$((gl_sum + gl))
8500         done
8501         echo $gl_sum
8502 }
8503
8504 som_mode_switch() {
8505         local som=$1
8506         local gl1=$2
8507         local gl2=$3
8508
8509         if [ x$som = x"enabled" ]; then
8510                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
8511                 MOUNTOPT=`echo $MOUNTOPT | sed 's/som_preview//g'`
8512                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
8513         else
8514                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
8515                 MOUNTOPT="$MOUNTOPT,som_preview"
8516                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
8517         fi
8518
8519         # do remount to make new mount-conf parameters actual
8520         echo remounting...
8521         sync
8522         stopall
8523         setupall
8524 }
8525
8526 test_132() { #1028, SOM
8527         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8528         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8529         local num=$(get_mds_dir $DIR)
8530         local mymds=mds${num}
8531         local MOUNTOPT_SAVE=$MOUNTOPT
8532
8533         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8534         cancel_lru_locks osc
8535
8536         som1=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8537
8538         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8539         stat $DIR/$tfile >/dev/null
8540         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8541         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
8542         rm $DIR/$tfile
8543         som_mode_switch $som1 $gl1 $gl2
8544
8545         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8546         cancel_lru_locks osc
8547
8548         som2=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8549         if [ $som1 == $som2 ]; then
8550             error "som is still "$som2
8551             if [ x$som2 = x"enabled" ]; then
8552                 som2="disabled"
8553             else
8554                 som2="enabled"
8555             fi
8556         fi
8557
8558         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8559         stat $DIR/$tfile >/dev/null
8560         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8561         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
8562         som_mode_switch $som2 $gl1 $gl2
8563         MOUNTOPT=$MOUNTOPT_SAVE
8564 }
8565 run_test 132 "som avoids glimpse rpc"
8566
8567 check_stats() {
8568         local res
8569         local count
8570         case $1 in
8571         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8572                  ;;
8573         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8574                  ;;
8575         *) error "Wrong argument $1" ;;
8576         esac
8577         echo $res
8578         count=`echo $res | awk '{print $2}'`
8579         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8580         # if the argument $3 is zero, it means any stat increment is ok.
8581         if [ $3 -gt 0 ] ; then
8582                 [ $count -ne $3 ] && error "The $2 counter on $1 is wrong - expected $3"
8583         fi
8584 }
8585
8586 test_133a() {
8587         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8588         remote_ost_nodsh && skip "remote OST with nodsh" && return
8589         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8590
8591         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8592                 { skip "MDS doesn't support rename stats"; return; }
8593         local testdir=$DIR/${tdir}/stats_testdir
8594         mkdir -p $DIR/${tdir}
8595
8596         # clear stats.
8597         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8598         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8599
8600         # verify mdt stats first.
8601         mkdir ${testdir} || error "mkdir failed"
8602         check_stats $SINGLEMDS "mkdir" 1
8603         touch ${testdir}/${tfile} || "touch failed"
8604         check_stats $SINGLEMDS "open" 1
8605         check_stats $SINGLEMDS "close" 1
8606         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
8607         check_stats $SINGLEMDS "mknod" 1
8608         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
8609         check_stats $SINGLEMDS "unlink" 1
8610         rm -f ${testdir}/${tfile} || error "file remove failed"
8611         check_stats $SINGLEMDS "unlink" 2
8612
8613         # remove working dir and check mdt stats again.
8614         rmdir ${testdir} || error "rmdir failed"
8615         check_stats $SINGLEMDS "rmdir" 1
8616
8617         local testdir1=$DIR/${tdir}/stats_testdir1
8618         mkdir -p ${testdir}
8619         mkdir -p ${testdir1}
8620         touch ${testdir1}/test1
8621         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
8622         check_stats $SINGLEMDS "crossdir_rename" 1
8623
8624         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
8625         check_stats $SINGLEMDS "samedir_rename" 1
8626
8627         rm -rf $DIR/${tdir}
8628 }
8629 run_test 133a "Verifying MDT stats ========================================"
8630
8631 test_133b() {
8632         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8633         remote_ost_nodsh && skip "remote OST with nodsh" && return
8634         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8635         local testdir=$DIR/${tdir}/stats_testdir
8636         mkdir -p ${testdir} || error "mkdir failed"
8637         touch ${testdir}/${tfile} || "touch failed"
8638         cancel_lru_locks mdc
8639
8640         # clear stats.
8641         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8642         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8643
8644         # extra mdt stats verification.
8645         chmod 444 ${testdir}/${tfile} || error "chmod failed"
8646         check_stats $SINGLEMDS "setattr" 1
8647         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8648         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
8649         then            # LU-1740
8650                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
8651                 check_stats $SINGLEMDS "getattr" 1
8652         fi
8653         $LFS df || error "lfs failed"
8654         check_stats $SINGLEMDS "statfs" 1
8655
8656         rm -rf $DIR/${tdir}
8657 }
8658 run_test 133b "Verifying extra MDT stats =================================="
8659
8660 test_133c() {
8661         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8662         remote_ost_nodsh && skip "remote OST with nodsh" && return
8663         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8664         local testdir=$DIR/${tdir}/stats_testdir
8665         test_mkdir -p ${testdir} || error "mkdir failed"
8666
8667         # verify obdfilter stats.
8668         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8669         sync
8670         cancel_lru_locks osc
8671         wait_delete_completed
8672
8673         # clear stats.
8674         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8675         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8676
8677         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
8678         sync
8679         cancel_lru_locks osc
8680         check_stats ost "write" 1
8681
8682         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
8683         check_stats ost "read" 1
8684
8685         > ${testdir}/${tfile} || error "truncate failed"
8686         check_stats ost "punch" 1
8687
8688         rm -f ${testdir}/${tfile} || error "file remove failed"
8689         wait_delete_completed
8690         check_stats ost "destroy" 1
8691
8692         rm -rf $DIR/${tdir}
8693 }
8694 run_test 133c "Verifying OST stats ========================================"
8695
8696 order_2() {
8697     local value=$1
8698     local orig=$value
8699     local order=1
8700
8701     while [ $value -ge 2 ]; do
8702         order=$((order*2))
8703         value=$((value/2))
8704     done
8705
8706     if [ $orig -gt $order ]; then
8707         order=$((order*2))
8708     fi
8709     echo $order
8710 }
8711
8712 size_in_KMGT() {
8713     local value=$1
8714     local size=('K' 'M' 'G' 'T');
8715     local i=0
8716     local size_string=$value
8717
8718     while [ $value -ge 1024 ]; do
8719         if [ $i -gt 3 ]; then
8720             #T is the biggest unit we get here, if that is bigger,
8721             #just return XXXT
8722             size_string=${value}T
8723             break
8724         fi
8725         value=$((value >> 10))
8726         if [ $value -lt 1024 ]; then
8727             size_string=${value}${size[$i]}
8728             break
8729         fi
8730         i=$((i + 1))
8731     done
8732
8733     echo $size_string
8734 }
8735
8736 get_rename_size() {
8737     local size=$1
8738     local context=${2:-.}
8739     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
8740                 grep -A1 $context |
8741                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
8742     echo $sample
8743 }
8744
8745 test_133d() {
8746         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8747         remote_ost_nodsh && skip "remote OST with nodsh" && return
8748         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8749         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8750         { skip "MDS doesn't support rename stats"; return; }
8751
8752         local testdir1=$DIR/${tdir}/stats_testdir1
8753         local testdir2=$DIR/${tdir}/stats_testdir2
8754
8755         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
8756
8757         mkdir -p ${testdir1} || error "mkdir failed"
8758         mkdir -p ${testdir2} || error "mkdir failed"
8759
8760         createmany -o $testdir1/test 512 || error "createmany failed"
8761
8762         # check samedir rename size
8763         mv ${testdir1}/test0 ${testdir1}/test_0
8764
8765         local testdir1_size=$(ls -l $DIR/${tdir} |
8766                 awk '/stats_testdir1/ {print $5}')
8767         local testdir2_size=$(ls -l $DIR/${tdir} |
8768                 awk '/stats_testdir2/ {print $5}')
8769
8770         testdir1_size=$(order_2 $testdir1_size)
8771         testdir2_size=$(order_2 $testdir2_size)
8772
8773         testdir1_size=$(size_in_KMGT $testdir1_size)
8774         testdir2_size=$(size_in_KMGT $testdir2_size)
8775
8776         echo "source rename dir size: ${testdir1_size}"
8777         echo "target rename dir size: ${testdir2_size}"
8778
8779         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
8780         eval $cmd || error "$cmd failed"
8781         local samedir=$($cmd | grep 'same_dir')
8782         local same_sample=$(get_rename_size $testdir1_size)
8783         [ -z "$samedir" ] && error "samedir_rename_size count error"
8784         [ "$same_sample" -eq 1 ] || error "samedir_rename_size error $same_sample"
8785         echo "Check same dir rename stats success"
8786
8787         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
8788
8789         # check crossdir rename size
8790         mv ${testdir1}/test_0 ${testdir2}/test_0
8791
8792         testdir1_size=$(ls -l $DIR/${tdir} |
8793                 awk '/stats_testdir1/ {print $5}')
8794         testdir2_size=$(ls -l $DIR/${tdir} |
8795                 awk '/stats_testdir2/ {print $5}')
8796
8797         testdir1_size=$(order_2 $testdir1_size)
8798         testdir2_size=$(order_2 $testdir2_size)
8799
8800         testdir1_size=$(size_in_KMGT $testdir1_size)
8801         testdir2_size=$(size_in_KMGT $testdir2_size)
8802
8803         echo "source rename dir size: ${testdir1_size}"
8804         echo "target rename dir size: ${testdir2_size}"
8805
8806         eval $cmd || error "$cmd failed"
8807         local crossdir=$($cmd | grep 'crossdir')
8808         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
8809         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
8810         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
8811         [ "$src_sample" -eq 1 ] || error "crossdir_rename_size error $src_sample"
8812         [ "$tgt_sample" -eq 1 ] || error "crossdir_rename_size error $tgt_sample"
8813         echo "Check cross dir rename stats success"
8814         rm -rf $DIR/${tdir}
8815 }
8816 run_test 133d "Verifying rename_stats ========================================"
8817
8818 test_133e() {
8819         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8820         local testdir=$DIR/${tdir}/stats_testdir
8821         local ctr f0 f1 bs=32768 count=42 sum
8822
8823         remote_ost_nodsh && skip "remote OST with nodsh" && return
8824         mkdir -p ${testdir} || error "mkdir failed"
8825
8826         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8827
8828         for ctr in {write,read}_bytes; do
8829                 sync
8830                 cancel_lru_locks osc
8831
8832                 do_facet ost1 $LCTL set_param -n \
8833                         "obdfilter.*.exports.clear=clear"
8834
8835                 if [ $ctr = write_bytes ]; then
8836                         f0=/dev/zero
8837                         f1=${testdir}/${tfile}
8838                 else
8839                         f0=${testdir}/${tfile}
8840                         f1=/dev/null
8841                 fi
8842
8843                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
8844                         error "dd failed"
8845                 sync
8846                 cancel_lru_locks osc
8847
8848                 sum=$(do_facet ost1 $LCTL get_param \
8849                                 "obdfilter.*.exports.*.stats" | \
8850                           awk -v ctr=$ctr '\
8851                                 BEGIN { sum = 0 }
8852                                 $1 == ctr { sum += $7 }
8853                                 END { print sum }')
8854
8855                 if ((sum != bs * count)); then
8856                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
8857                 fi
8858         done
8859
8860         rm -rf $DIR/${tdir}
8861 }
8862 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
8863
8864 test_133f() {
8865         local proc_dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/"
8866         local facet
8867
8868         # First without trusting modes.
8869         find $proc_dirs \
8870                 -exec cat '{}' \; &> /dev/null
8871
8872         # Second verifying readability.
8873         find $proc_dirs \
8874                 -type f \
8875                 -readable \
8876                 -exec cat '{}' \; > /dev/null ||
8877                         error "proc file read failed"
8878
8879         for facet in $SINGLEMDS ost1; do
8880                 do_facet $facet find $proc_dirs \
8881                         -not -name req_history \
8882                         -exec cat '{}' \\\; &> /dev/null
8883
8884             do_facet $facet     find $proc_dirs \
8885                         -not -name req_history \
8886                         -type f \
8887                         -readable \
8888                         -exec cat '{}' \\\; > /dev/null ||
8889                                 error "proc file read failed"
8890         done
8891 }
8892 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
8893
8894 test_140() { #bug-17379
8895         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8896         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
8897         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
8898         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
8899
8900         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
8901         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
8902         local i=0
8903         while i=`expr $i + 1`; do
8904                 test_mkdir -p $i || error "Creating dir $i"
8905                 cd $i || error "Changing to $i"
8906                 ln -s ../stat stat || error "Creating stat symlink"
8907                 # Read the symlink until ELOOP present,
8908                 # not LBUGing the system is considered success,
8909                 # we didn't overrun the stack.
8910                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
8911                 [ $ret -ne 0 ] && {
8912                         if [ $ret -eq 40 ]; then
8913                                 break  # -ELOOP
8914                         else
8915                                 error "Open stat symlink"
8916                                 return
8917                         fi
8918                 }
8919         done
8920         i=`expr $i - 1`
8921         echo "The symlink depth = $i"
8922         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
8923                                         error "Invalid symlink depth"
8924
8925         # Test recursive symlink
8926         ln -s symlink_self symlink_self
8927         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
8928         echo "open symlink_self returns $ret"
8929         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
8930 }
8931 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
8932
8933 test_150() {
8934         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8935         local TF="$TMP/$tfile"
8936
8937         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
8938         cp $TF $DIR/$tfile
8939         cancel_lru_locks osc
8940         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
8941         remount_client $MOUNT
8942         df -P $MOUNT
8943         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
8944
8945         $TRUNCATE $TF 6000
8946         $TRUNCATE $DIR/$tfile 6000
8947         cancel_lru_locks osc
8948         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
8949
8950         echo "12345" >>$TF
8951         echo "12345" >>$DIR/$tfile
8952         cancel_lru_locks osc
8953         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
8954
8955         echo "12345" >>$TF
8956         echo "12345" >>$DIR/$tfile
8957         cancel_lru_locks osc
8958         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
8959
8960         rm -f $TF
8961         true
8962 }
8963 run_test 150 "truncate/append tests"
8964
8965 #LU-2902 roc_hit was not able to read all values from lproc
8966 function roc_hit_init() {
8967         local list=$(comma_list $(osts_nodes))
8968         local dir=$DIR/$tdir-check
8969         local file=$dir/file
8970         local BEFORE
8971         local AFTER
8972         local idx
8973
8974         test_mkdir -p $dir
8975         #use setstripe to do a write to every ost
8976         for i in $(seq 0 $((OSTCOUNT-1))); do
8977                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
8978                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
8979                 idx=$(printf %04x $i)
8980                 BEFORE=$(get_osd_param $list *OST*$idx stats |
8981                     awk '$1 == "cache_access" {sum += $2} END { print sum }')
8982                 if [ -z "$BEFORE" ]; then
8983                         BEFORE=0
8984                 fi
8985
8986                 cancel_lru_locks osc
8987                 cat $file >/dev/null
8988
8989                 AFTER=$(get_osd_param $list *OST*$idx stats |
8990                     awk '$1 == "cache_access" {sum += $2} END { print sum }')
8991
8992                 echo BEFORE:$BEFORE AFTER:$AFTER
8993                 if ! let "AFTER - BEFORE == 4"; then
8994                         rm -rf $dir
8995                         error "roc_hit is not safe to use"
8996                 fi
8997                 rm $file
8998         done
8999
9000         rm -rf $dir
9001 }
9002
9003 function roc_hit() {
9004         local list=$(comma_list $(osts_nodes))
9005         echo $(get_osd_param $list '' stats |
9006                 awk '$1 == "cache_hit" {sum += $2} END { print sum }')
9007 }
9008
9009 function set_cache() {
9010         local on=1
9011
9012         if [ "$2" == "off" ]; then
9013                 on=0;
9014         fi
9015         local list=$(comma_list $(osts_nodes))
9016         set_osd_param $list '' $1_cache_enable $on
9017
9018         cancel_lru_locks osc
9019 }
9020
9021 test_151() {
9022         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9023         remote_ost_nodsh && skip "remote OST with nodsh" && return
9024
9025         local CPAGES=3
9026         local list=$(comma_list $(osts_nodes))
9027
9028         # check whether obdfilter is cache capable at all
9029         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9030                 echo "not cache-capable obdfilter"
9031                 return 0
9032         fi
9033
9034         # check cache is enabled on all obdfilters
9035         if get_osd_param $list '' read_cache_enable | grep 0; then
9036                 echo "oss cache is disabled"
9037                 return 0
9038         fi
9039
9040         set_osd_param $list '' writethrough_cache_enable 1
9041
9042         # check write cache is enabled on all obdfilters
9043         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9044                 echo "oss write cache is NOT enabled"
9045                 return 0
9046         fi
9047
9048         roc_hit_init
9049
9050         #define OBD_FAIL_OBD_NO_LRU  0x609
9051         do_nodes $list $LCTL set_param fail_loc=0x609
9052
9053         # pages should be in the case right after write
9054         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9055                 error "dd failed"
9056
9057         local BEFORE=$(roc_hit)
9058         cancel_lru_locks osc
9059         cat $DIR/$tfile >/dev/null
9060         local AFTER=$(roc_hit)
9061
9062         do_nodes $list $LCTL set_param fail_loc=0
9063
9064         if ! let "AFTER - BEFORE == CPAGES"; then
9065                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9066         fi
9067
9068         # the following read invalidates the cache
9069         cancel_lru_locks osc
9070         set_osd_param $list '' read_cache_enable 0
9071         cat $DIR/$tfile >/dev/null
9072
9073         # now data shouldn't be found in the cache
9074         BEFORE=$(roc_hit)
9075         cancel_lru_locks osc
9076         cat $DIR/$tfile >/dev/null
9077         AFTER=$(roc_hit)
9078         if let "AFTER - BEFORE != 0"; then
9079                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9080         fi
9081
9082         set_osd_param $list '' read_cache_enable 1
9083         rm -f $DIR/$tfile
9084 }
9085 run_test 151 "test cache on oss and controls ==============================="
9086
9087 test_152() {
9088         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9089         local TF="$TMP/$tfile"
9090
9091         # simulate ENOMEM during write
9092 #define OBD_FAIL_OST_NOMEM      0x226
9093         lctl set_param fail_loc=0x80000226
9094         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9095         cp $TF $DIR/$tfile
9096         sync || error "sync failed"
9097         lctl set_param fail_loc=0
9098
9099         # discard client's cache
9100         cancel_lru_locks osc
9101
9102         # simulate ENOMEM during read
9103         lctl set_param fail_loc=0x80000226
9104         cmp $TF $DIR/$tfile || error "cmp failed"
9105         lctl set_param fail_loc=0
9106
9107         rm -f $TF
9108 }
9109 run_test 152 "test read/write with enomem ============================"
9110
9111 test_153() {
9112         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9113 }
9114 run_test 153 "test if fdatasync does not crash ======================="
9115
9116 dot_lustre_fid_permission_check() {
9117         local fid=$1
9118         local ffid=$MOUNT/.lustre/fid/$fid
9119         local test_dir=$2
9120
9121         echo "stat fid $fid"
9122         stat $ffid > /dev/null || error "stat $ffid failed."
9123         echo "touch fid $fid"
9124         touch $ffid || error "touch $ffid failed."
9125         echo "write to fid $fid"
9126         cat /etc/hosts > $ffid || error "write $ffid failed."
9127         echo "read fid $fid"
9128         diff /etc/hosts $ffid || error "read $ffid failed."
9129         echo "append write to fid $fid"
9130         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9131         echo "rename fid $fid"
9132         mv $ffid $test_dir/$tfile.1 &&
9133                 error "rename $ffid to $tfile.1 should fail."
9134         touch $test_dir/$tfile.1
9135         mv $test_dir/$tfile.1 $ffid &&
9136                 error "rename $tfile.1 to $ffid should fail."
9137         rm -f $test_dir/$tfile.1
9138         echo "truncate fid $fid"
9139         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9140         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9141                 echo "link fid $fid"
9142                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9143         fi
9144         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9145                 echo "setfacl fid $fid"
9146                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9147                 echo "getfacl fid $fid"
9148                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9149         fi
9150         echo "unlink fid $fid"
9151         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9152         echo "mknod fid $fid"
9153         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9154
9155         fid=[0xf00000400:0x1:0x0]
9156         ffid=$MOUNT/.lustre/fid/$fid
9157
9158         echo "stat non-exist fid $fid"
9159         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9160         echo "write to non-exist fid $fid"
9161         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9162         echo "link new fid $fid"
9163         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9164
9165         mkdir -p $test_dir/$tdir
9166         touch $test_dir/$tdir/$tfile
9167         fid=$($LFS path2fid $test_dir/$tdir)
9168         rc=$?
9169         [ $rc -ne 0 ] &&
9170                 error "error: could not get fid for $test_dir/$dir/$tfile."
9171
9172         ffid=$MOUNT/.lustre/fid/$fid
9173
9174         echo "ls $fid"
9175         ls $ffid > /dev/null || error "ls $ffid failed."
9176         echo "touch $fid/$tfile.1"
9177         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9178
9179         echo "touch $MOUNT/.lustre/fid/$tfile"
9180         touch $MOUNT/.lustre/fid/$tfile && \
9181                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9182
9183         echo "setxattr to $MOUNT/.lustre/fid"
9184         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9185
9186         echo "listxattr for $MOUNT/.lustre/fid"
9187         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9188
9189         echo "delxattr from $MOUNT/.lustre/fid"
9190         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9191
9192         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9193         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9194                 error "touch invalid fid should fail."
9195
9196         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9197         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9198                 error "touch non-normal fid should fail."
9199
9200         echo "rename $tdir to $MOUNT/.lustre/fid"
9201         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9202                 error "rename to $MOUNT/.lustre/fid should fail."
9203
9204         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9205         then            # LU-3547
9206                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9207                 local new_obf_mode=777
9208
9209                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9210                 chmod $new_obf_mode $DIR/.lustre/fid ||
9211                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9212
9213                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9214                 [ $obf_mode -eq $new_obf_mode ] ||
9215                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9216
9217                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9218                 chmod $old_obf_mode $DIR/.lustre/fid ||
9219                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9220         fi
9221
9222         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9223         fid=$($LFS path2fid $test_dir/$tfile-2)
9224         echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9225         cp /etc/passwd $MOUNT/.lustre/fid/$fid &&
9226                 error "create lov data thru .lustre should fail."
9227         echo "cp /etc/passwd $test_dir/$tfile-2"
9228         cp /etc/passwd $test_dir/$tfile-2 ||
9229                 error "copy to $test_dir/$tfile-2 failed."
9230         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9231         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9232                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9233
9234         rm -rf $test_dir/tfile.lnk
9235         rm -rf $test_dir/$tfile-2
9236 }
9237
9238 test_154A() {
9239         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9240                 skip "Need MDS version at least 2.4.1" && return
9241
9242         touch $DIR/$tfile
9243         local FID=$($LFS path2fid $DIR/$tfile)
9244         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9245
9246         # check that we get the same pathname back
9247         local FOUND=$($LFS fid2path $MOUNT $FID)
9248         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9249         [ "$FOUND" != "$DIR/$tfile" ] &&
9250                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9251
9252         rm -rf $DIR/$tfile
9253 }
9254 run_test 154A "lfs path2fid and fid2path basic checks"
9255
9256 test_154a() {
9257         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9258         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9259                 { skip "Need MDS version at least 2.2.51"; return 0; }
9260
9261         cp /etc/hosts $DIR/$tfile
9262
9263         fid=$($LFS path2fid $DIR/$tfile)
9264         rc=$?
9265         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9266
9267         dot_lustre_fid_permission_check "$fid" $DIR ||
9268                 error "dot lustre permission check $fid failed"
9269
9270         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9271
9272         touch $MOUNT/.lustre/file &&
9273                 error "creation is not allowed under .lustre"
9274
9275         mkdir $MOUNT/.lustre/dir &&
9276                 error "mkdir is not allowed under .lustre"
9277
9278         rm -rf $DIR/$tfile
9279 }
9280 run_test 154a "Open-by-FID"
9281
9282 test_154b() {
9283         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9284         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9285                 { skip "Need MDS version at least 2.2.51"; return 0; }
9286
9287         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9288
9289         local remote_dir=$DIR/$tdir/remote_dir
9290         local MDTIDX=1
9291         local rc=0
9292
9293         mkdir -p $DIR/$tdir
9294         $LFS mkdir -i $MDTIDX -c $MDSCOUNT $remote_dir ||
9295                 error "create remote directory failed"
9296
9297         cp /etc/hosts $remote_dir/$tfile
9298
9299         fid=$($LFS path2fid $remote_dir/$tfile)
9300         rc=$?
9301         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9302
9303         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9304                 error "dot lustre permission check $fid failed"
9305         rm -rf $DIR/$tdir
9306 }
9307 run_test 154b "Open-by-FID for remote directory"
9308
9309 test_154c() {
9310         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9311                 skip "Need MDS version at least 2.4.1" && return
9312
9313         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9314         local FID1=$($LFS path2fid $DIR/$tfile.1)
9315         local FID2=$($LFS path2fid $DIR/$tfile.2)
9316         local FID3=$($LFS path2fid $DIR/$tfile.3)
9317
9318         local N=1
9319         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9320                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9321                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9322                 local want=FID$N
9323                 [ "$FID" = "${!want}" ] ||
9324                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9325                 N=$((N + 1))
9326         done
9327
9328         $LFS fid2path $MOUNT $FID1 $FID2 $FID3 | while read PATHNAME; do
9329                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
9330                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
9331                 N=$((N + 1))
9332         done
9333 }
9334 run_test 154c "lfs path2fid and fid2path multiple arguments"
9335
9336 test_154d() {
9337         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
9338                 skip "Need MDS version at least 2.5.53" && return
9339
9340         if remote_mds; then
9341                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
9342         else
9343                 nid="0@lo"
9344         fi
9345         local proc_ofile="mdt.*.exports.'$nid'.open_files"
9346         local fd
9347         local cmd
9348
9349         rm -f $DIR/$tfile
9350         touch $DIR/$tfile
9351
9352         fid=$($LFS path2fid $DIR/$tfile)
9353         # Open the file
9354         fd=$(free_fd)
9355         cmd="exec $fd<$DIR/$tfile"
9356         eval $cmd
9357         fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
9358         echo $fid_list | grep $fid
9359         rc=$?
9360
9361         cmd="exec $fd>/dev/null"
9362         eval $cmd
9363         if [ $rc -ne 0 ]; then
9364                 error "FID $fid not found in open files list $fid_list"
9365         fi
9366 }
9367 run_test 154d "Verify open file fid"
9368
9369 test_155_small_load() {
9370     local temp=$TMP/$tfile
9371     local file=$DIR/$tfile
9372
9373     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
9374         error "dd of=$temp bs=6096 count=1 failed"
9375     cp $temp $file
9376     cancel_lru_locks osc
9377     cmp $temp $file || error "$temp $file differ"
9378
9379     $TRUNCATE $temp 6000
9380     $TRUNCATE $file 6000
9381     cmp $temp $file || error "$temp $file differ (truncate1)"
9382
9383     echo "12345" >>$temp
9384     echo "12345" >>$file
9385     cmp $temp $file || error "$temp $file differ (append1)"
9386
9387     echo "12345" >>$temp
9388     echo "12345" >>$file
9389     cmp $temp $file || error "$temp $file differ (append2)"
9390
9391     rm -f $temp $file
9392     true
9393 }
9394
9395 test_155_big_load() {
9396     remote_ost_nodsh && skip "remote OST with nodsh" && return
9397     local temp=$TMP/$tfile
9398     local file=$DIR/$tfile
9399
9400     free_min_max
9401     local cache_size=$(do_facet ost$((MAXI+1)) \
9402         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
9403     local large_file_size=$((cache_size * 2))
9404
9405     echo "OSS cache size: $cache_size KB"
9406     echo "Large file size: $large_file_size KB"
9407
9408     [ $MAXV -le $large_file_size ] && \
9409         skip_env "max available OST size needs > $large_file_size KB" && \
9410         return 0
9411
9412     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
9413
9414     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
9415         error "dd of=$temp bs=$large_file_size count=1k failed"
9416     cp $temp $file
9417     ls -lh $temp $file
9418     cancel_lru_locks osc
9419     cmp $temp $file || error "$temp $file differ"
9420
9421     rm -f $temp $file
9422     true
9423 }
9424
9425 test_155a() {
9426         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9427         set_cache read on
9428         set_cache writethrough on
9429         test_155_small_load
9430 }
9431 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
9432
9433 test_155b() {
9434         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9435         set_cache read on
9436         set_cache writethrough off
9437         test_155_small_load
9438 }
9439 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
9440
9441 test_155c() {
9442         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9443         set_cache read off
9444         set_cache writethrough on
9445         test_155_small_load
9446 }
9447 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
9448
9449 test_155d() {
9450         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9451         set_cache read off
9452         set_cache writethrough off
9453         test_155_small_load
9454 }
9455 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
9456
9457 test_155e() {
9458         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9459         set_cache read on
9460         set_cache writethrough on
9461         test_155_big_load
9462 }
9463 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
9464
9465 test_155f() {
9466         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9467         set_cache read on
9468         set_cache writethrough off
9469         test_155_big_load
9470 }
9471 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
9472
9473 test_155g() {
9474         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9475         set_cache read off
9476         set_cache writethrough on
9477         test_155_big_load
9478 }
9479 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
9480
9481 test_155h() {
9482         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9483         set_cache read off
9484         set_cache writethrough off
9485         test_155_big_load
9486 }
9487 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
9488
9489 test_156() {
9490         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9491         local CPAGES=3
9492         local BEFORE
9493         local AFTER
9494         local file="$DIR/$tfile"
9495
9496         [ "$(facet_fstype ost1)" = "zfs" ] &&
9497                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
9498                 return
9499
9500         roc_hit_init
9501
9502     log "Turn on read and write cache"
9503     set_cache read on
9504     set_cache writethrough on
9505
9506     log "Write data and read it back."
9507     log "Read should be satisfied from the cache."
9508     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9509     BEFORE=`roc_hit`
9510     cancel_lru_locks osc
9511     cat $file >/dev/null
9512     AFTER=`roc_hit`
9513     if ! let "AFTER - BEFORE == CPAGES"; then
9514         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9515     else
9516         log "cache hits:: before: $BEFORE, after: $AFTER"
9517     fi
9518
9519     log "Read again; it should be satisfied from the cache."
9520     BEFORE=$AFTER
9521     cancel_lru_locks osc
9522     cat $file >/dev/null
9523     AFTER=`roc_hit`
9524     if ! let "AFTER - BEFORE == CPAGES"; then
9525         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9526     else
9527         log "cache hits:: before: $BEFORE, after: $AFTER"
9528     fi
9529
9530
9531     log "Turn off the read cache and turn on the write cache"
9532     set_cache read off
9533     set_cache writethrough on
9534
9535     log "Read again; it should be satisfied from the cache."
9536     BEFORE=`roc_hit`
9537     cancel_lru_locks osc
9538     cat $file >/dev/null
9539     AFTER=`roc_hit`
9540     if ! let "AFTER - BEFORE == CPAGES"; then
9541         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9542     else
9543         log "cache hits:: before: $BEFORE, after: $AFTER"
9544     fi
9545
9546     log "Read again; it should not be satisfied from the cache."
9547     BEFORE=$AFTER
9548     cancel_lru_locks osc
9549     cat $file >/dev/null
9550     AFTER=`roc_hit`
9551     if ! let "AFTER - BEFORE == 0"; then
9552         error "IN CACHE: before: $BEFORE, after: $AFTER"
9553     else
9554         log "cache hits:: before: $BEFORE, after: $AFTER"
9555     fi
9556
9557     log "Write data and read it back."
9558     log "Read should be satisfied from the cache."
9559     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9560     BEFORE=`roc_hit`
9561     cancel_lru_locks osc
9562     cat $file >/dev/null
9563     AFTER=`roc_hit`
9564     if ! let "AFTER - BEFORE == CPAGES"; then
9565         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9566     else
9567         log "cache hits:: before: $BEFORE, after: $AFTER"
9568     fi
9569
9570     log "Read again; it should not be satisfied from the cache."
9571     BEFORE=$AFTER
9572     cancel_lru_locks osc
9573     cat $file >/dev/null
9574     AFTER=`roc_hit`
9575     if ! let "AFTER - BEFORE == 0"; then
9576         error "IN CACHE: before: $BEFORE, after: $AFTER"
9577     else
9578         log "cache hits:: before: $BEFORE, after: $AFTER"
9579     fi
9580
9581
9582     log "Turn off read and write cache"
9583     set_cache read off
9584     set_cache writethrough off
9585
9586     log "Write data and read it back"
9587     log "It should not be satisfied from the cache."
9588     rm -f $file
9589     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9590     cancel_lru_locks osc
9591     BEFORE=`roc_hit`
9592     cat $file >/dev/null
9593     AFTER=`roc_hit`
9594         if ! let "AFTER - BEFORE == 0"; then
9595                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9596         else
9597                 log "cache hits:: before: $BEFORE, after: $AFTER"
9598         fi
9599
9600     log "Turn on the read cache and turn off the write cache"
9601     set_cache read on
9602     set_cache writethrough off
9603
9604     log "Write data and read it back"
9605     log "It should not be satisfied from the cache."
9606     rm -f $file
9607     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9608     BEFORE=`roc_hit`
9609     cancel_lru_locks osc
9610     cat $file >/dev/null
9611     AFTER=`roc_hit`
9612         if ! let "AFTER - BEFORE == 0"; then
9613                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9614         else
9615                 log "cache hits:: before: $BEFORE, after: $AFTER"
9616         fi
9617
9618     log "Read again; it should be satisfied from the cache."
9619     BEFORE=`roc_hit`
9620     cancel_lru_locks osc
9621     cat $file >/dev/null
9622     AFTER=`roc_hit`
9623     if ! let "AFTER - BEFORE == CPAGES"; then
9624         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9625     else
9626         log "cache hits:: before: $BEFORE, after: $AFTER"
9627     fi
9628
9629     rm -f $file
9630 }
9631 run_test 156 "Verification of tunables ============================"
9632
9633 #Changelogs
9634 err17935 () {
9635         if [ $MDSCOUNT -gt 1 ]; then
9636                 error_ignore bz17935 $*
9637         else
9638                 error $*
9639         fi
9640 }
9641
9642 changelog_chmask()
9643 {
9644         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
9645
9646         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
9647
9648         if [ $MASK -eq 1 ]; then
9649                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
9650         else
9651                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
9652         fi
9653 }
9654
9655 changelog_extract_field() {
9656         local mdt=$1
9657         local cltype=$2
9658         local file=$3
9659         local identifier=$4
9660
9661         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
9662                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
9663                 tail -1
9664 }
9665
9666 test_160a() {
9667         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9668         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9669         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
9670                 { skip "Need MDS version at least 2.2.0"; return; }
9671
9672         local CL_USERS="mdd.$MDT0.changelog_users"
9673         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
9674         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
9675         echo "Registered as changelog user $USER"
9676         $GET_CL_USERS | grep -q $USER ||
9677                 error "User $USER not found in changelog_users"
9678
9679         # change something
9680         test_mkdir -p $DIR/$tdir/pics/2008/zachy
9681         touch $DIR/$tdir/pics/2008/zachy/timestamp
9682         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
9683         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
9684         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
9685         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
9686         rm $DIR/$tdir/pics/desktop.jpg
9687
9688         $LFS changelog $MDT0 | tail -5
9689
9690         echo "verifying changelog mask"
9691         changelog_chmask "MKDIR"
9692         changelog_chmask "CLOSE"
9693
9694         test_mkdir -p $DIR/$tdir/pics/zach/sofia
9695         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9696
9697         changelog_chmask "MKDIR"
9698         changelog_chmask "CLOSE"
9699
9700         test_mkdir -p $DIR/$tdir/pics/2008/sofia
9701         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9702
9703         $LFS changelog $MDT0
9704         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
9705         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
9706         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
9707         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
9708
9709         # verify contents
9710         echo "verifying target fid"
9711         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
9712         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
9713         [ "$fidc" == "$fidf" ] ||
9714                 err17935 "fid in changelog $fidc != file fid $fidf"
9715         echo "verifying parent fid"
9716         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
9717         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
9718         [ "$fidc" == "$fidf" ] ||
9719                 err17935 "pfid in changelog $fidc != dir fid $fidf"
9720
9721         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
9722         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
9723         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
9724         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
9725         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
9726                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
9727
9728         MIN_REC=$($GET_CL_USERS |
9729                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
9730         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
9731         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
9732         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
9733                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
9734
9735         # LU-3446 changelog index reset on MDT restart
9736         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
9737         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9738         $LFS changelog_clear $MDT0 $USER 0
9739         stop $SINGLEMDS || error "Fail to stop MDT."
9740         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
9741         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9742         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
9743         [ $CUR_REC1 == $CUR_REC2 ] ||
9744                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
9745
9746         echo "verifying user deregister"
9747         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9748         $GET_CL_USERS | grep -q $USER &&
9749                 error "User $USER still in changelog_users"
9750
9751         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
9752         if [ $USERS -eq 0 ]; then
9753                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9754                 touch $DIR/$tdir/chloe
9755                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
9756                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
9757                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
9758         else
9759                 echo "$USERS other changelog users; can't verify off"
9760         fi
9761 }
9762 run_test 160a "changelog sanity"
9763
9764 test_160b() { # LU-3587
9765         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9766         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9767         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
9768                 { skip "Need MDS version at least 2.2.0"; return; }
9769
9770         local CL_USERS="mdd.$MDT0.changelog_users"
9771         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
9772         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
9773         echo "Registered as changelog user $USER"
9774         $GET_CL_USERS | grep -q $USER ||
9775                 error "User $USER not found in changelog_users"
9776
9777         local LONGNAME1=$(str_repeat a 255)
9778         local LONGNAME2=$(str_repeat b 255)
9779
9780         cd $DIR
9781         echo "creating very long named file"
9782         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
9783         echo "moving very long named file"
9784         mv $LONGNAME1 $LONGNAME2
9785
9786         $LFS changelog $MDT0 | grep RENME
9787
9788         echo "deregistering $USER"
9789         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9790
9791         rm -f $LONGNAME2
9792 }
9793 run_test 160b "Verify that very long rename doesn't crash in changelog"
9794
9795 test_160c() {
9796         local rc=0
9797         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9798
9799         # Registration step
9800         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
9801                 changelog_register -n)
9802
9803         rm -rf $DIR/$tdir
9804         mkdir -p $DIR/$tdir
9805         $MCREATE $DIR/$tdir/foo_160c
9806         changelog_chmask "TRUNC"
9807         $TRUNCATE $DIR/$tdir/foo_160c 200
9808         changelog_chmask "TRUNC"
9809         $TRUNCATE $DIR/$tdir/foo_160c 199
9810         $LFS changelog $MDT0
9811         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
9812         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
9813         $LFS changelog_clear $MDT0 $USER 0
9814
9815         # Deregistration step
9816         echo "deregistering $USER"
9817         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9818 }
9819 run_test 160c "verify that changelog log catch the truncate event"
9820
9821 test_161a() {
9822         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9823         test_mkdir -p -c1 $DIR/$tdir
9824         cp /etc/hosts $DIR/$tdir/$tfile
9825         test_mkdir -c1 $DIR/$tdir/foo1
9826         test_mkdir -c1 $DIR/$tdir/foo2
9827         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
9828         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
9829         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
9830         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
9831         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
9832         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
9833                 $LFS fid2path $DIR $FID
9834                 err17935 "bad link ea"
9835         fi
9836     # middle
9837     rm $DIR/$tdir/foo2/zachary
9838     # last
9839     rm $DIR/$tdir/foo2/thor
9840     # first
9841     rm $DIR/$tdir/$tfile
9842     # rename
9843     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
9844     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
9845         then
9846         $LFS fid2path $DIR $FID
9847         err17935 "bad link rename"
9848     fi
9849     rm $DIR/$tdir/foo2/maggie
9850
9851     # overflow the EA
9852     local longname=filename_avg_len_is_thirty_two_
9853     createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 || \
9854         error "failed to hardlink many files"
9855     links=$($LFS fid2path $DIR $FID | wc -l)
9856     echo -n "${links}/1000 links in link EA"
9857     [ ${links} -gt 60 ] || err17935 "expected at least 60 links in link EA"
9858     unlinkmany $DIR/$tdir/foo2/$longname 1000 || \
9859         error "failed to unlink many hardlinks"
9860 }
9861 run_test 161a "link ea sanity"
9862
9863 test_161b() {
9864         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9865         [ $MDSCOUNT -lt 2 ] &&
9866                 skip "skipping remote directory test" && return
9867         local MDTIDX=1
9868         local remote_dir=$DIR/$tdir/remote_dir
9869
9870         mkdir -p $DIR/$tdir
9871         $LFS mkdir -i $MDTIDX $remote_dir ||
9872                 error "create remote directory failed"
9873
9874         cp /etc/hosts $remote_dir/$tfile
9875         mkdir -p $remote_dir/foo1
9876         mkdir -p $remote_dir/foo2
9877         ln $remote_dir/$tfile $remote_dir/foo1/sofia
9878         ln $remote_dir/$tfile $remote_dir/foo2/zachary
9879         ln $remote_dir/$tfile $remote_dir/foo1/luna
9880         ln $remote_dir/$tfile $remote_dir/foo2/thor
9881
9882         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
9883                      tr -d ']')
9884         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
9885                 $LFS fid2path $DIR $FID
9886                 err17935 "bad link ea"
9887         fi
9888         # middle
9889         rm $remote_dir/foo2/zachary
9890         # last
9891         rm $remote_dir/foo2/thor
9892         # first
9893         rm $remote_dir/$tfile
9894         # rename
9895         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
9896         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
9897         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
9898                 $LFS fid2path $DIR $FID
9899                 err17935 "bad link rename"
9900         fi
9901         rm $remote_dir/foo2/maggie
9902
9903         # overflow the EA
9904         local longname=filename_avg_len_is_thirty_two_
9905         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
9906                 error "failed to hardlink many files"
9907         links=$($LFS fid2path $DIR $FID | wc -l)
9908         echo -n "${links}/1000 links in link EA"
9909         [ ${links} -gt 60 ] || err17935 "expected at least 60 links in link EA"
9910         unlinkmany $remote_dir/foo2/$longname 1000 ||
9911         error "failed to unlink many hardlinks"
9912 }
9913 run_test 161b "link ea sanity under remote directory"
9914
9915 test_161c() {
9916         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9917         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
9918                 skip "Need MDS version at least 2.1.5" && return
9919
9920         # define CLF_RENAME_LAST 0x0001
9921         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
9922         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
9923                 changelog_register -n)
9924         rm -rf $DIR/$tdir
9925         mkdir -p $DIR/$tdir
9926         touch $DIR/$tdir/foo_161c
9927         touch $DIR/$tdir/bar_161c
9928         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
9929         $LFS changelog $MDT0 | grep RENME
9930         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
9931                 cut -f5 -d' ')
9932         $LFS changelog_clear $MDT0 $USER 0
9933         if [ x$flags != "x0x1" ]; then
9934                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9935                         $USER
9936                 error "flag $flags is not 0x1"
9937         fi
9938         echo "rename overwrite a target having nlink = 1," \
9939                 "changelog record has flags of $flags"
9940
9941         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
9942         touch $DIR/$tdir/foo_161c
9943         touch $DIR/$tdir/bar_161c
9944         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
9945         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
9946         $LFS changelog $MDT0 | grep RENME
9947         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
9948         $LFS changelog_clear $MDT0 $USER 0
9949         if [ x$flags != "x0x0" ]; then
9950                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9951                         $USER
9952                 error "flag $flags is not 0x0"
9953         fi
9954         echo "rename overwrite a target having nlink > 1," \
9955                 "changelog record has flags of $flags"
9956
9957         # rename doesn't overwrite a target (changelog flag 0x0)
9958         touch $DIR/$tdir/foo_161c
9959         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
9960         $LFS changelog $MDT0 | grep RENME
9961         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
9962         $LFS changelog_clear $MDT0 $USER 0
9963         if [ x$flags != "x0x0" ]; then
9964                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9965                         $USER
9966                 error "flag $flags is not 0x0"
9967         fi
9968         echo "rename doesn't overwrite a target," \
9969                 "changelog record has flags of $flags"
9970
9971         # define CLF_UNLINK_LAST 0x0001
9972         # unlink a file having nlink = 1 (changelog flag 0x1)
9973         rm -f $DIR/$tdir/foo2_161c
9974         $LFS changelog $MDT0 | grep UNLNK
9975         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
9976         $LFS changelog_clear $MDT0 $USER 0
9977         if [ x$flags != "x0x1" ]; then
9978                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9979                         $USER
9980                 error "flag $flags is not 0x1"
9981         fi
9982         echo "unlink a file having nlink = 1," \
9983                 "changelog record has flags of $flags"
9984
9985         # unlink a file having nlink > 1 (changelog flag 0x0)
9986         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
9987         rm -f $DIR/$tdir/foobar_161c
9988         $LFS changelog $MDT0 | grep UNLNK
9989         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
9990         $LFS changelog_clear $MDT0 $USER 0
9991         if [ x$flags != "x0x0" ]; then
9992                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
9993                         $USER
9994                 error "flag $flags is not 0x0"
9995         fi
9996         echo "unlink a file having nlink > 1," \
9997                 "changelog record has flags of $flags"
9998         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
9999 }
10000 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10001
10002 check_path() {
10003     local expected=$1
10004     shift
10005     local fid=$2
10006
10007     local path=$(${LFS} fid2path $*)
10008     RC=$?
10009
10010     if [ $RC -ne 0 ]; then
10011         err17935 "path looked up of $expected failed. Error $RC"
10012         return $RC
10013     elif [ "${path}" != "${expected}" ]; then
10014         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10015         return 2
10016     fi
10017     echo "fid $fid resolves to path $path (expected $expected)"
10018 }
10019
10020 test_162() {
10021         # Make changes to filesystem
10022         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10023         test_mkdir -p $DIR/$tdir/d2
10024         touch $DIR/$tdir/d2/$tfile
10025         touch $DIR/$tdir/d2/x1
10026         touch $DIR/$tdir/d2/x2
10027         test_mkdir -p $DIR/$tdir/d2/a/b/c
10028         test_mkdir -p $DIR/$tdir/d2/p/q/r
10029         # regular file
10030         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10031         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0
10032
10033         # softlink
10034         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10035         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10036         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0
10037
10038         # softlink to wrong file
10039         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10040         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10041         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0
10042
10043         # hardlink
10044         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10045         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10046         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10047         # fid2path dir/fsname should both work
10048         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1
10049         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0
10050
10051         # hardlink count: check that there are 2 links
10052         # Doesnt work with CMD yet: 17935
10053         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10054                 err17935 "expected 2 links"
10055
10056         # hardlink indexing: remove the first link
10057         rm $DIR/$tdir/d2/p/q/r/hlink
10058         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0
10059
10060         return 0
10061 }
10062 run_test 162 "path lookup sanity"
10063
10064 test_169() {
10065         # do directio so as not to populate the page cache
10066         log "creating a 10 Mb file"
10067         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10068         log "starting reads"
10069         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10070         log "truncating the file"
10071         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10072         log "killing dd"
10073         kill %+ || true # reads might have finished
10074         echo "wait until dd is finished"
10075         wait
10076         log "removing the temporary file"
10077         rm -rf $DIR/$tfile || error "tmp file removal failed"
10078 }
10079 run_test 169 "parallel read and truncate should not deadlock"
10080
10081 test_170() {
10082         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10083         $LCTL clear     # bug 18514
10084         $LCTL debug_daemon start $TMP/${tfile}_log_good
10085         touch $DIR/$tfile
10086         $LCTL debug_daemon stop
10087         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10088                error "sed failed to read log_good"
10089
10090         $LCTL debug_daemon start $TMP/${tfile}_log_good
10091         rm -rf $DIR/$tfile
10092         $LCTL debug_daemon stop
10093
10094         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10095                error "lctl df log_bad failed"
10096
10097         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10098         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10099
10100         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10101         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10102
10103         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10104                 error "bad_line good_line1 good_line2 are empty"
10105
10106         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10107         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10108         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10109
10110         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10111         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10112         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10113
10114         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
10115                 error "bad_line_new good_line_new are empty"
10116
10117         local expected_good=$((good_line1 + good_line2*2))
10118
10119         rm -f $TMP/${tfile}*
10120         # LU-231, short malformed line may not be counted into bad lines
10121         if [ $bad_line -ne $bad_line_new ] &&
10122                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
10123                 error "expected $bad_line bad lines, but got $bad_line_new"
10124                 return 1
10125         fi
10126
10127         if [ $expected_good -ne $good_line_new ]; then
10128                 error "expected $expected_good good lines, but got $good_line_new"
10129                 return 2
10130         fi
10131         true
10132 }
10133 run_test 170 "test lctl df to handle corrupted log ====================="
10134
10135 test_171() { # bug20592
10136         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10137 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
10138         $LCTL set_param fail_loc=0x50e
10139         $LCTL set_param fail_val=3000
10140         multiop_bg_pause $DIR/$tfile O_s || true
10141         local MULTIPID=$!
10142         kill -USR1 $MULTIPID
10143         # cause log dump
10144         sleep 3
10145         wait $MULTIPID
10146         if dmesg | grep "recursive fault"; then
10147                 error "caught a recursive fault"
10148         fi
10149         $LCTL set_param fail_loc=0
10150         true
10151 }
10152 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
10153
10154 # it would be good to share it with obdfilter-survey/libecho code
10155 setup_obdecho_osc () {
10156         local rc=0
10157         local ost_nid=$1
10158         local obdfilter_name=$2
10159         echo "Creating new osc for $obdfilter_name on $ost_nid"
10160         # make sure we can find loopback nid
10161         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
10162
10163         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
10164                            ${obdfilter_name}_osc_UUID || rc=2; }
10165         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
10166                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
10167         return $rc
10168 }
10169
10170 cleanup_obdecho_osc () {
10171         local obdfilter_name=$1
10172         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
10173         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
10174         return 0
10175 }
10176
10177 obdecho_test() {
10178         local OBD=$1
10179         local node=$2
10180         local pages=${3:-64}
10181         local rc=0
10182         local id
10183
10184         local count=10
10185         local obd_size=$(get_obd_size $node $OBD)
10186         local page_size=$(get_page_size $node)
10187         if [[ -n "$obd_size" ]]; then
10188                 local new_count=$((obd_size / (pages * page_size / 1024)))
10189                 [[ $new_count -ge $count ]] || count=$new_count
10190         fi
10191
10192         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
10193         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
10194                            rc=2; }
10195         if [ $rc -eq 0 ]; then
10196             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
10197             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
10198         fi
10199         echo "New object id is $id"
10200         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
10201                            rc=4; }
10202         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
10203                            "test_brw $count w v $pages $id" || rc=4; }
10204         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
10205                            rc=4; }
10206         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
10207                                         "cleanup" || rc=5; }
10208         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
10209                                         "detach" || rc=6; }
10210         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
10211         return $rc
10212 }
10213
10214 test_180a() {
10215         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10216         remote_ost_nodsh && skip "remote OST with nodsh" && return
10217         local rc=0
10218         local rmmod_local=0
10219
10220         if ! module_loaded obdecho; then
10221             load_module obdecho/obdecho
10222             rmmod_local=1
10223         fi
10224
10225         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
10226         local host=$(lctl get_param -n osc.$osc.import |
10227                              awk '/current_connection:/ {print $2}' )
10228         local target=$(lctl get_param -n osc.$osc.import |
10229                              awk '/target:/ {print $2}' )
10230         target=${target%_UUID}
10231
10232         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
10233         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
10234         [[ -n $target ]] && cleanup_obdecho_osc $target
10235         [ $rmmod_local -eq 1 ] && rmmod obdecho
10236         return $rc
10237 }
10238 run_test 180a "test obdecho on osc"
10239
10240 test_180b() {
10241         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10242         remote_ost_nodsh && skip "remote OST with nodsh" && return
10243         local rc=0
10244         local rmmod_remote=0
10245
10246         do_facet ost1 "lsmod | grep -q obdecho || "                      \
10247                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
10248                       "modprobe obdecho; }" && rmmod_remote=1
10249         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
10250         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
10251         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
10252         return $rc
10253 }
10254 run_test 180b "test obdecho directly on obdfilter"
10255
10256 test_180c() { # LU-2598
10257         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10258         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
10259                 skip "Need MDS version at least 2.4.0" && return
10260
10261         local rc=0
10262         local rmmod_remote=false
10263         local pages=16384 # 64MB bulk I/O RPC size
10264         local target
10265
10266         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
10267                 rmmod_remote=true || error "failed to load module obdecho"
10268
10269         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
10270                 head -n1)
10271         if [[ -n $target ]]; then
10272                 obdecho_test "$target" ost1 "$pages" ||
10273                         rc=${PIPESTATUS[0]}
10274         else
10275                 echo "there is no obdfilter target on ost1"
10276                 rc=2
10277         fi
10278         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
10279         return $rc
10280 }
10281 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
10282
10283 test_181() { # bug 22177
10284         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10285         # create enough files to index the directory
10286         createmany -o $DIR/$tdir/foobar 4000
10287         # print attributes for debug purpose
10288         lsattr -d .
10289         # open dir
10290         multiop_bg_pause $DIR/$tdir D_Sc || return 1
10291         MULTIPID=$!
10292         # remove the files & current working dir
10293         unlinkmany $DIR/$tdir/foobar 4000
10294         rmdir $DIR/$tdir
10295         kill -USR1 $MULTIPID
10296         wait $MULTIPID
10297         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
10298         return 0
10299 }
10300 run_test 181 "Test open-unlinked dir ========================"
10301
10302 test_182() {
10303         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10304         # disable MDC RPC lock wouldn't crash client
10305         local fcount=1000
10306         local tcount=4
10307
10308         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10309 #define OBD_FAIL_MDC_RPCS_SEM           0x804
10310         $LCTL set_param fail_loc=0x804
10311
10312         for (( i=0; i < $tcount; i++ )) ; do
10313                 mkdir $DIR/$tdir/$i
10314                 createmany -o $DIR/$tdir/$i/f- $fcount &
10315         done
10316         wait
10317
10318         for (( i=0; i < $tcount; i++ )) ; do
10319                 unlinkmany $DIR/$tdir/$i/f- $fcount &
10320         done
10321         wait
10322
10323         rm -rf $DIR/$tdir
10324
10325         $LCTL set_param fail_loc=0
10326 }
10327 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
10328
10329 test_183() { # LU-2275
10330         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
10331                 skip "Need MDS version at least 2.3.56" && return
10332
10333         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10334         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10335         echo aaa > $DIR/$tdir/$tfile
10336
10337 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
10338         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
10339
10340         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
10341         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
10342
10343         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
10344
10345         # Flush negative dentry cache
10346         touch $DIR/$tdir/$tfile
10347
10348         # We are not checking for any leaked references here, they'll
10349         # become evident next time we do cleanup with module unload.
10350         rm -rf $DIR/$tdir
10351 }
10352 run_test 183 "No crash or request leak in case of strange dispositions ========"
10353
10354 # test suite 184 is for LU-2016, LU-2017
10355 test_184a() {
10356         check_swap_layouts_support && return 0
10357
10358         dir0=$DIR/$tdir/$testnum
10359         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
10360         ref1=/etc/passwd
10361         ref2=/etc/group
10362         file1=$dir0/f1
10363         file2=$dir0/f2
10364         $SETSTRIPE -c1 $file1
10365         cp $ref1 $file1
10366         $SETSTRIPE -c2 $file2
10367         cp $ref2 $file2
10368         gen1=$($GETSTRIPE -g $file1)
10369         gen2=$($GETSTRIPE -g $file2)
10370
10371         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
10372         gen=$($GETSTRIPE -g $file1)
10373         [[ $gen1 != $gen ]] ||
10374                 "Layout generation on $file1 does not change"
10375         gen=$($GETSTRIPE -g $file2)
10376         [[ $gen2 != $gen ]] ||
10377                 "Layout generation on $file2 does not change"
10378
10379         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
10380         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
10381 }
10382 run_test 184a "Basic layout swap"
10383
10384 test_184b() {
10385         check_swap_layouts_support && return 0
10386
10387         dir0=$DIR/$tdir/$testnum
10388         mkdir -p $dir0 || error "creating dir $dir0"
10389         file1=$dir0/f1
10390         file2=$dir0/f2
10391         file3=$dir0/f3
10392         dir1=$dir0/d1
10393         dir2=$dir0/d2
10394         mkdir $dir1 $dir2
10395         $SETSTRIPE -c1 $file1
10396         $SETSTRIPE -c2 $file2
10397         $SETSTRIPE -c1 $file3
10398         chown $RUNAS_ID $file3
10399         gen1=$($GETSTRIPE -g $file1)
10400         gen2=$($GETSTRIPE -g $file2)
10401
10402         $LFS swap_layouts $dir1 $dir2 &&
10403                 error "swap of directories layouts should fail"
10404         $LFS swap_layouts $dir1 $file1 &&
10405                 error "swap of directory and file layouts should fail"
10406         $RUNAS $LFS swap_layouts $file1 $file2 &&
10407                 error "swap of file we cannot write should fail"
10408         $LFS swap_layouts $file1 $file3 &&
10409                 error "swap of file with different owner should fail"
10410         /bin/true # to clear error code
10411 }
10412 run_test 184b "Forbidden layout swap (will generate errors)"
10413
10414 test_184c() {
10415         check_swap_layouts_support && return 0
10416
10417         local dir0=$DIR/$tdir/$testnum
10418         mkdir -p $dir0 || error "creating dir $dir0"
10419
10420         local ref1=$dir0/ref1
10421         local ref2=$dir0/ref2
10422         local file1=$dir0/file1
10423         local file2=$dir0/file2
10424         # create a file large enough for the concurent test
10425         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
10426         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
10427         echo "ref file size: ref1(`stat -c %s $ref1`), ref2(`stat -c %s $ref2`)"
10428
10429         cp $ref2 $file2
10430         dd if=$ref1 of=$file1 bs=16k &
10431         local DD_PID=$!
10432
10433         # Make sure dd starts to copy file
10434         while [ ! -f $file1 ]; do sleep 0.1; done
10435
10436         $LFS swap_layouts $file1 $file2
10437         local rc=$?
10438         wait $DD_PID
10439         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
10440         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
10441
10442         # how many bytes copied before swapping layout
10443         local copied=`stat -c %s $file2`
10444         local remaining=`stat -c %s $ref1`
10445         remaining=$((remaining - copied))
10446         echo "Copied $copied bytes before swapping layout..."
10447
10448         cmp -n $copied $file1 $ref2 | grep differ &&
10449                 error "Content mismatch [0, $copied) of ref2 and file1"
10450         cmp -n $copied $file2 $ref1 ||
10451                 error "Content mismatch [0, $copied) of ref1 and file2"
10452         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
10453                 error "Content mismatch [$copied, EOF) of ref1 and file1"
10454
10455         # clean up
10456         rm -f $ref1 $ref2 $file1 $file2
10457 }
10458 run_test 184c "Concurrent write and layout swap"
10459
10460 test_184d() {
10461         check_swap_layouts_support && return 0
10462
10463         local file1=$DIR/$tdir/$tfile-1
10464         local file2=$DIR/$tdir/$tfile-2
10465         local file3=$DIR/$tdir/$tfile-3
10466         local lovea1
10467         local lovea2
10468
10469         mkdir -p $DIR/$tdir
10470         touch $file1 || error "create $file1 failed"
10471         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
10472                 error "create $file2 failed"
10473         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
10474                 error "create $file3 failed"
10475         lovea1=$($LFS getstripe $file1 | sed 1d)
10476
10477         $LFS swap_layouts $file2 $file3 ||
10478                 error "swap $file2 $file3 layouts failed"
10479         $LFS swap_layouts $file1 $file2 ||
10480                 error "swap $file1 $file2 layouts failed"
10481
10482         lovea2=$($LFS getstripe $file2 | sed 1d)
10483         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
10484
10485         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
10486         [ -z $lovea1 ] || error "$file1 shouldn't have lovea"
10487 }
10488 run_test 184d "allow stripeless layouts swap"
10489
10490
10491 test_185() { # LU-2441
10492         # LU-3553 - no volatile file support in old servers
10493         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
10494                 { skip "Need MDS version at least 2.3.60"; return 0; }
10495
10496         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10497         touch $DIR/$tdir/spoo
10498         local mtime1=$(stat -c "%Y" $DIR/$tdir)
10499         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
10500                 error "cannot create/write a volatile file"
10501         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
10502                 error "FID is still valid after close"
10503
10504         multiop_bg_pause $DIR/$tdir vVw4096_c
10505         local multi_pid=$!
10506
10507         local OLD_IFS=$IFS
10508         IFS=":"
10509         local fidv=($fid)
10510         IFS=$OLD_IFS
10511         # assume that the next FID for this client is sequential, since stdout
10512         # is unfortunately eaten by multiop_bg_pause
10513         local n=$((${fidv[1]} + 1))
10514         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
10515         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
10516                 error "FID is missing before close"
10517         kill -USR1 $multi_pid
10518         # 1 second delay, so if mtime change we will see it
10519         sleep 1
10520         local mtime2=$(stat -c "%Y" $DIR/$tdir)
10521         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
10522 }
10523 run_test 185 "Volatile file support"
10524
10525 test_187a() {
10526         local dir0=$DIR/$tdir/$testnum
10527         mkdir -p $dir0 || error "creating dir $dir0"
10528
10529         local file=$dir0/file1
10530         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
10531         local dv1=$($LFS data_version $file)
10532         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
10533         local dv2=$($LFS data_version $file)
10534         [[ $dv1 != $dv2 ]] ||
10535                 error "data version did not change on write $dv1 == $dv2"
10536
10537         # clean up
10538         rm -f $file1
10539 }
10540 run_test 187a "Test data version change"
10541
10542 test_187b() {
10543         local dir0=$DIR/$tdir/$testnum
10544         mkdir -p $dir0 || error "creating dir $dir0"
10545
10546         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
10547         [[ ${DV[0]} != ${DV[1]} ]] ||
10548                 error "data version did not change on write"\
10549                       " ${DV[0]} == ${DV[1]}"
10550
10551         # clean up
10552         rm -f $file1
10553 }
10554 run_test 187b "Test data version change on volatile file"
10555
10556 # OST pools tests
10557 check_file_in_pool()
10558 {
10559         local file=$1
10560         local pool=$2
10561         local tlist="$3"
10562         local res=$($GETSTRIPE $file | grep 0x | cut -f2)
10563         for i in $res
10564         do
10565                 for t in $tlist ; do
10566                         [ "$i" -eq "$t" ] && continue 2
10567                 done
10568
10569                 echo "pool list: $tlist"
10570                 echo "striping: $res"
10571                 error_noexit "$file not allocated in $pool"
10572                 return 1
10573         done
10574         return 0
10575 }
10576
10577 pool_add() {
10578         echo "Creating new pool"
10579         local pool=$1
10580
10581         create_pool $FSNAME.$pool ||
10582                 { error_noexit "No pool created, result code $?"; return 1; }
10583         [ $($LFS pool_list $FSNAME | grep -c $pool) -eq 1 ] ||
10584                 { error_noexit "$pool not in lfs pool_list"; return 2; }
10585 }
10586
10587 pool_add_targets() {
10588         echo "Adding targets to pool"
10589         local pool=$1
10590         local first=$2
10591         local last=$3
10592         local step=${4:-1}
10593
10594         local list=$(seq $first $step $last)
10595
10596         local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
10597         do_facet mgs $LCTL pool_add \
10598                         $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
10599         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
10600                         | sort -u | tr '\n' ' ' " "$t" || { 
10601                 error_noexit "Add to pool failed"
10602                 return 1
10603         }
10604         local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
10605         local addcount=$(((last - first) / step + 1))
10606         [ $lfscount -eq $addcount ] || {
10607                 error_noexit "lfs pool_list bad ost count" \
10608                                                 "$lfscount != $addcount"
10609                 return 2
10610         }
10611 }
10612
10613 pool_set_dir() {
10614         local pool=$1
10615         local tdir=$2
10616         echo "Setting pool on directory $tdir"
10617
10618         $SETSTRIPE -c 2 -p $pool $tdir && return 0
10619
10620         error_noexit "Cannot set pool $pool to $tdir"
10621         return 1
10622 }
10623
10624 pool_check_dir() {
10625         local pool=$1
10626         local tdir=$2
10627         echo "Checking pool on directory $tdir"
10628
10629         local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
10630         [ "$res" = "$pool" ] && return 0
10631
10632         error_noexit "Pool on '$tdir' is '$res', not '$pool'"
10633         return 1
10634 }
10635
10636 pool_dir_rel_path() {
10637         echo "Testing relative path works well"
10638         local pool=$1
10639         local tdir=$2
10640         local root=$3
10641
10642         mkdir -p $root/$tdir/$tdir
10643         cd $root/$tdir
10644         pool_set_dir $pool $tdir          || return 1
10645         pool_set_dir $pool ./$tdir        || return 2
10646         pool_set_dir $pool ../$tdir       || return 3
10647         pool_set_dir $pool ../$tdir/$tdir || return 4
10648         rm -rf $tdir; cd - > /dev/null
10649 }
10650
10651 pool_alloc_files() {
10652         echo "Checking files allocation from directory pool"
10653         local pool=$1
10654         local tdir=$2
10655         local count=$3
10656         local tlist="$4"
10657
10658         local failed=0
10659         for i in $(seq -w 1 $count)
10660         do
10661                 local file=$tdir/file-$i
10662                 touch $file
10663                 check_file_in_pool $file $pool "$tlist" || \
10664                         failed=$((failed + 1))
10665         done
10666         [ "$failed" = 0 ] && return 0
10667
10668         error_noexit "$failed files not allocated in $pool"
10669         return 1
10670 }
10671
10672 pool_create_files() {
10673         echo "Creating files in pool"
10674         local pool=$1
10675         local tdir=$2
10676         local count=$3
10677         local tlist="$4"
10678
10679         mkdir -p $tdir
10680         local failed=0
10681         for i in $(seq -w 1 $count)
10682         do
10683                 local file=$tdir/spoo-$i
10684                 $SETSTRIPE -p $pool $file
10685                 check_file_in_pool $file $pool "$tlist" || \
10686                         failed=$((failed + 1))
10687         done
10688         [ "$failed" = 0 ] && return 0
10689
10690         error_noexit "$failed files not allocated in $pool"
10691         return 1
10692 }
10693
10694 pool_lfs_df() {
10695         echo "Checking 'lfs df' output"
10696         local pool=$1
10697
10698         local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
10699                         tr '\n' ' ')
10700         local res=$($LFS df --pool $FSNAME.$pool |
10701                         awk '{print $1}' |
10702                         grep "$FSNAME-OST" |
10703                         tr '\n' ' ')
10704         [ "$res" = "$t" ] && return 0
10705
10706         error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
10707         return 1
10708 }
10709
10710 pool_file_rel_path() {
10711         echo "Creating files in a pool with relative pathname"
10712         local pool=$1
10713         local tdir=$2
10714
10715         mkdir -p $tdir ||
10716                 { error_noexit "unable to create $tdir"; return 1 ; }
10717         local file="/..$tdir/$tfile-1"
10718         $SETSTRIPE -p $pool $file ||
10719                 { error_noexit "unable to create $file" ; return 2 ; }
10720
10721         cd $tdir
10722         $SETSTRIPE -p $pool $tfile-2 || {
10723                 error_noexit "unable to create $tfile-2 in $tdir"
10724                 return 3
10725         }
10726 }
10727
10728 pool_remove_first_target() {
10729         echo "Removing first target from a pool"
10730         local pool=$1
10731
10732         local pname="lov.$FSNAME-*.pools.$pool"
10733         local t=$($LCTL get_param -n $pname | head -n1)
10734         do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10735         wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
10736                 error_noexit "$t not removed from $FSNAME.$pool"
10737                 return 1
10738         }
10739 }
10740
10741 pool_remove_all_targets() {
10742         echo "Removing all targets from pool"
10743         local pool=$1
10744         local file=$2
10745         local pname="lov.$FSNAME-*.pools.$pool"
10746         for t in $($LCTL get_param -n $pname | sort -u)
10747         do
10748                 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
10749         done
10750         wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
10751                 error_noexit "Pool $FSNAME.$pool cannot be drained"
10752                 return 1
10753         }
10754         # striping on an empty/nonexistant pool should fall back
10755         # to "pool of everything"
10756         touch $file || {
10757                 error_noexit "failed to use fallback striping for empty pool"
10758                 return 2
10759         }
10760         # setstripe on an empty pool should fail
10761         $SETSTRIPE -p $pool $file 2>/dev/null && {
10762                 error_noexit "expected failure when creating file" \
10763                                                         "with empty pool"
10764                 return 3
10765         }
10766         return 0
10767 }
10768
10769 pool_remove() {
10770         echo "Destroying pool"
10771         local pool=$1
10772         local file=$2
10773
10774         do_facet mgs $LCTL pool_destroy $FSNAME.$pool
10775
10776         sleep 2
10777         # striping on an empty/nonexistant pool should fall back 
10778         # to "pool of everything"
10779         touch $file || {
10780                 error_noexit "failed to use fallback striping for missing pool"
10781                 return 1
10782         }
10783         # setstripe on an empty pool should fail
10784         $SETSTRIPE -p $pool $file 2>/dev/null && {
10785                 error_noexit "expected failure when creating file" \
10786                                                         "with missing pool"
10787                 return 2
10788         }
10789
10790         # get param should return err once pool is gone
10791         if wait_update $HOSTNAME "lctl get_param -n \
10792                 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
10793         then
10794                 remove_pool_from_list $FSNAME.$pool
10795                 return 0
10796         fi
10797         error_noexit "Pool $FSNAME.$pool is not destroyed"
10798         return 3
10799 }
10800
10801 test_200() {
10802         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10803         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
10804
10805         local POOL=${POOL:-cea1}
10806         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
10807         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
10808         # Pool OST targets
10809         local first_ost=0
10810         local last_ost=$(($OSTCOUNT - 1))
10811         local ost_step=2
10812         local ost_list=$(seq $first_ost $ost_step $last_ost)
10813         local ost_range="$first_ost $last_ost $ost_step"
10814         local test_path=$POOL_ROOT/$POOL_DIR_NAME
10815         local file_dir=$POOL_ROOT/file_tst
10816
10817         local rc=0
10818         while : ; do
10819                 # former test_200a test_200b
10820                 pool_add $POOL                          || { rc=$? ; break; }
10821                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
10822                 # former test_200c test_200d
10823                 mkdir -p $test_path
10824                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
10825                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
10826                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
10827                                                         || { rc=$? ; break; }
10828                 # former test_200e test_200f
10829                 local files=$((OSTCOUNT*3))
10830                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
10831                                                         || { rc=$? ; break; }
10832                 pool_create_files $POOL $file_dir $files "$ost_list" \
10833                                                         || { rc=$? ; break; }
10834                 # former test_200g test_200h
10835                 pool_lfs_df $POOL                       || { rc=$? ; break; }
10836                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
10837
10838                 # former test_201a test_201b test_201c
10839                 pool_remove_first_target $POOL          || { rc=$? ; break; }
10840
10841                 local f=$test_path/$tfile
10842                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
10843                 pool_remove $POOL $f                    || { rc=$? ; break; }
10844                 break
10845         done
10846
10847         cleanup_pools
10848         return $rc
10849 }
10850 run_test 200 "OST pools"
10851
10852 # usage: default_attr <count | size | offset>
10853 default_attr() {
10854         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
10855 }
10856
10857 # usage: check_default_stripe_attr
10858 check_default_stripe_attr() {
10859         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
10860         case $1 in
10861         --stripe-count|--count)
10862                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
10863         --stripe-size|--size)
10864                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
10865         --stripe-index|--index)
10866                 EXPECTED=-1;;
10867         *)
10868                 error "unknown getstripe attr '$1'"
10869         esac
10870
10871         [ $ACTUAL != $EXPECTED ] &&
10872                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
10873 }
10874
10875 test_204a() {
10876         test_mkdir -p $DIR/$tdir
10877         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
10878
10879         check_default_stripe_attr --stripe-count
10880         check_default_stripe_attr --stripe-size
10881         check_default_stripe_attr --stripe-index
10882
10883         return 0
10884 }
10885 run_test 204a "Print default stripe attributes ================="
10886
10887 test_204b() {
10888         test_mkdir -p $DIR/$tdir
10889         $SETSTRIPE --stripe-count 1 $DIR/$tdir
10890
10891         check_default_stripe_attr --stripe-size
10892         check_default_stripe_attr --stripe-index
10893
10894         return 0
10895 }
10896 run_test 204b "Print default stripe size and offset  ==========="
10897
10898 test_204c() {
10899         test_mkdir -p $DIR/$tdir
10900         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
10901
10902         check_default_stripe_attr --stripe-count
10903         check_default_stripe_attr --stripe-index
10904
10905         return 0
10906 }
10907 run_test 204c "Print default stripe count and offset ==========="
10908
10909 test_204d() {
10910         test_mkdir -p $DIR/$tdir
10911         $SETSTRIPE --stripe-index 0 $DIR/$tdir
10912
10913         check_default_stripe_attr --stripe-count
10914         check_default_stripe_attr --stripe-size
10915
10916         return 0
10917 }
10918 run_test 204d "Print default stripe count and size ============="
10919
10920 test_204e() {
10921         test_mkdir -p $DIR/$tdir
10922         $SETSTRIPE -d $DIR/$tdir
10923
10924         check_default_stripe_attr --stripe-count --raw
10925         check_default_stripe_attr --stripe-size --raw
10926         check_default_stripe_attr --stripe-index --raw
10927
10928         return 0
10929 }
10930 run_test 204e "Print raw stripe attributes ================="
10931
10932 test_204f() {
10933         test_mkdir -p $DIR/$tdir
10934         $SETSTRIPE --stripe-count 1 $DIR/$tdir
10935
10936         check_default_stripe_attr --stripe-size --raw
10937         check_default_stripe_attr --stripe-index --raw
10938
10939         return 0
10940 }
10941 run_test 204f "Print raw stripe size and offset  ==========="
10942
10943 test_204g() {
10944         test_mkdir -p $DIR/$tdir
10945         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
10946
10947         check_default_stripe_attr --stripe-count --raw
10948         check_default_stripe_attr --stripe-index --raw
10949
10950         return 0
10951 }
10952 run_test 204g "Print raw stripe count and offset ==========="
10953
10954 test_204h() {
10955         test_mkdir -p $DIR/$tdir
10956         $SETSTRIPE --stripe-index 0 $DIR/$tdir
10957
10958         check_default_stripe_attr --stripe-count --raw
10959         check_default_stripe_attr --stripe-size --raw
10960
10961         return 0
10962 }
10963 run_test 204h "Print raw stripe count and size ============="
10964
10965 # Figure out which job scheduler is being used, if any,
10966 # or use a fake one
10967 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
10968         JOBENV=SLURM_JOB_ID
10969 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
10970         JOBENV=LSB_JOBID
10971 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
10972         JOBENV=PBS_JOBID
10973 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
10974         JOBENV=LOADL_STEP_ID
10975 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
10976         JOBENV=JOB_ID
10977 else
10978         JOBENV=FAKE_JOBID
10979 fi
10980
10981 verify_jobstats() {
10982         local cmd=$1
10983         local target=$2
10984
10985         # clear old jobstats
10986         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
10987         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
10988
10989         # use a new JobID for this test, or we might see an old one
10990         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
10991
10992         JOBVAL=${!JOBENV}
10993         log "Test: $cmd"
10994         log "Using JobID environment variable $JOBENV=$JOBVAL"
10995
10996         if [ $JOBENV = "FAKE_JOBID" ]; then
10997                 FAKE_JOBID=$JOBVAL $cmd
10998         else
10999                 $cmd
11000         fi
11001
11002         if [ "$target" = "mdt" -o "$target" = "both" ]; then
11003                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
11004                 do_facet $FACET lctl get_param mdt.*.job_stats |
11005                         grep $JOBVAL || error "No job stats found on MDT $FACET"
11006         fi
11007         if [ "$target" = "ost" -o "$target" = "both" ]; then
11008                 FACET=ost1
11009                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
11010                         grep $JOBVAL || error "No job stats found on OST $FACET"
11011         fi
11012 }
11013
11014 jobstats_set() {
11015         trap 0
11016         NEW_JOBENV=${1:-$OLD_JOBENV}
11017         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11018         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11019 }
11020
11021 test_205() { # Job stats
11022         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11023         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11024                 skip "Server doesn't support jobstats" && return 0
11025
11026         local cmd
11027         OLD_JOBENV=`$LCTL get_param -n jobid_var`
11028         if [ $OLD_JOBENV != $JOBENV ]; then
11029                 jobstats_set $JOBENV
11030                 trap jobstats_set EXIT
11031         fi
11032
11033         # mkdir
11034         cmd="mkdir $DIR/$tfile"
11035         verify_jobstats "$cmd" "mdt"
11036         # rmdir
11037         cmd="rm -fr $DIR/$tfile"
11038         verify_jobstats "$cmd" "mdt"
11039         # mknod
11040         cmd="mknod $DIR/$tfile c 1 3"
11041         verify_jobstats "$cmd" "mdt"
11042         # unlink
11043         cmd="rm -f $DIR/$tfile"
11044         verify_jobstats "$cmd" "mdt"
11045         # open & close
11046         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11047         verify_jobstats "$cmd" "mdt"
11048         # setattr
11049         cmd="touch $DIR/$tfile"
11050         verify_jobstats "$cmd" "both"
11051         # write
11052         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11053         verify_jobstats "$cmd" "ost"
11054         # read
11055         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11056         verify_jobstats "$cmd" "ost"
11057         # truncate
11058         cmd="$TRUNCATE $DIR/$tfile 0"
11059         verify_jobstats "$cmd" "both"
11060         # rename
11061         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
11062         verify_jobstats "$cmd" "mdt"
11063
11064         # cleanup
11065         rm -f $DIR/jobstats_test_rename
11066
11067         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11068 }
11069 run_test 205 "Verify job stats"
11070
11071 # LU-1480, LU-1773 and LU-1657
11072 test_206() {
11073         mkdir -p $DIR/$tdir
11074         lfs setstripe -c -1 $DIR/$tdir
11075 #define OBD_FAIL_LOV_INIT 0x1403
11076         $LCTL set_param fail_loc=0xa0001403
11077         $LCTL set_param fail_val=1
11078         touch $DIR/$tdir/$tfile || true
11079 }
11080 run_test 206 "fail lov_init_raid0() doesn't lbug"
11081
11082 test_207a() {
11083         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11084         local fsz=`stat -c %s $DIR/$tfile`
11085         cancel_lru_locks mdc
11086
11087         # do not return layout in getattr intent
11088 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11089         $LCTL set_param fail_loc=0x170
11090         local sz=`stat -c %s $DIR/$tfile`
11091
11092         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11093
11094         rm -rf $DIR/$tfile
11095 }
11096 run_test 207a "can refresh layout at glimpse"
11097
11098 test_207b() {
11099         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11100         local cksum=`md5sum $DIR/$tfile`
11101         local fsz=`stat -c %s $DIR/$tfile`
11102         cancel_lru_locks mdc
11103         cancel_lru_locks osc
11104
11105         # do not return layout in getattr intent
11106 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11107         $LCTL set_param fail_loc=0x171
11108
11109         # it will refresh layout after the file is opened but before read issues
11110         echo checksum is "$cksum"
11111         echo "$cksum" |md5sum -c --quiet || error "file differs"
11112
11113         rm -rf $DIR/$tfile
11114 }
11115 run_test 207b "can refresh layout at open"
11116
11117 test_208() {
11118         # FIXME: in this test suite, only RD lease is used. This is okay
11119         # for now as only exclusive open is supported. After generic lease
11120         # is done, this test suite should be revised. - Jinshan
11121
11122         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11123                 { skip "Need MDS version at least 2.4.52"; return 0; }
11124
11125         echo "==== test 1: verify get lease work"
11126         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11127
11128         echo "==== test 2: verify lease can be broken by upcoming open"
11129         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11130         local PID=$!
11131         sleep 1
11132
11133         $MULTIOP $DIR/$tfile oO_RDONLY:c
11134         kill -USR1 $PID && wait $PID || error "break lease error"
11135
11136         echo "==== test 3: verify lease can't be granted if an open already exists"
11137         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11138         local PID=$!
11139         sleep 1
11140
11141         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11142         kill -USR1 $PID && wait $PID || error "open file error"
11143
11144         echo "==== test 4: lease can sustain over recovery"
11145         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11146         PID=$!
11147         sleep 1
11148
11149         fail mds1
11150
11151         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11152
11153         echo "==== test 5: lease broken can't be regained by replay"
11154         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11155         PID=$!
11156         sleep 1
11157
11158         # open file to break lease and then recovery
11159         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11160         fail mds1
11161
11162         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11163
11164         rm -f $DIR/$tfile
11165 }
11166 run_test 208 "Exclusive open"
11167
11168 test_209() {
11169         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11170                 skip_env "must have disp_stripe" && return
11171
11172         touch $DIR/$tfile
11173         sync; sleep 5; sync;
11174
11175         echo 3 > /proc/sys/vm/drop_caches
11176         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11177
11178         # open/close 500 times
11179         for i in $(seq 500); do
11180                 cat $DIR/$tfile
11181         done
11182
11183         echo 3 > /proc/sys/vm/drop_caches
11184         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11185
11186         echo "before: $req_before, after: $req_after"
11187         [ $((req_after - req_before)) -ge 300 ] &&
11188                 error "open/close requests are not freed"
11189         return 0
11190 }
11191 run_test 209 "read-only open/close requests should be freed promptly"
11192
11193 test_212() {
11194         size=`date +%s`
11195         size=$((size % 8192 + 1))
11196         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11197         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11198         rm -f $DIR/f212 $DIR/f212.xyz
11199 }
11200 run_test 212 "Sendfile test ============================================"
11201
11202 test_213() {
11203         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11204         cancel_lru_locks osc
11205         lctl set_param fail_loc=0x8000040f
11206         # generate a read lock
11207         cat $DIR/$tfile > /dev/null
11208         # write to the file, it will try to cancel the above read lock.
11209         cat /etc/hosts >> $DIR/$tfile
11210 }
11211 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11212
11213 test_214() { # for bug 20133
11214         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11215         for (( i=0; i < 340; i++ )) ; do
11216                 touch $DIR/$tdir/d214c/a$i
11217         done
11218
11219         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11220         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11221         ls $DIR/d214c || error "ls $DIR/d214c failed"
11222         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11223         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11224 }
11225 run_test 214 "hash-indexed directory test - bug 20133"
11226
11227 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11228 create_lnet_proc_files() {
11229         cat /proc/sys/lnet/$1 >$TMP/lnet_$1.out || error "cannot read /proc/sys/lnet/$1"
11230         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11231
11232         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11233         rm -f "$TMP/lnet_$1.sys_tmp"
11234 }
11235
11236 # counterpart of create_lnet_proc_files
11237 remove_lnet_proc_files() {
11238         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11239 }
11240
11241 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11242 # 3rd arg as regexp for body
11243 check_lnet_proc_stats() {
11244         local l=$(cat "$TMP/lnet_$1" |wc -l)
11245         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
11246
11247         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
11248 }
11249
11250 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11251 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
11252 # optional and can be regexp for 2nd line (lnet.routes case)
11253 check_lnet_proc_entry() {
11254         local blp=2            # blp stands for 'position of 1st line of body'
11255         [ "$5" = "" ] || blp=3 # lnet.routes case
11256
11257         local l=$(cat "$TMP/lnet_$1" |wc -l)
11258         # subtracting one from $blp because the body can be empty
11259         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
11260
11261         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
11262                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
11263
11264         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
11265                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
11266
11267         # bail out if any unexpected line happened
11268         sed -n "$blp~1 p" "$TMP/lnet_$1" |grep -Ev "$3"
11269         [ "$?" != 0 ] || error "$2 misformatted"
11270 }
11271
11272 test_215() { # for bugs 18102, 21079, 21517
11273         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11274         local N='(0|[1-9][0-9]*)'       # non-negative numeric
11275         local P='[1-9][0-9]*'           # positive numeric
11276         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
11277         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
11278         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
11279         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
11280
11281         local L1 # regexp for 1st line
11282         local L2 # regexp for 2nd line (optional)
11283         local BR # regexp for the rest (body)
11284
11285         # /proc/sys/lnet/stats should look as 11 space-separated non-negative numerics
11286         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
11287         create_lnet_proc_files "stats"
11288         check_lnet_proc_stats "stats.out" "/proc/sys/lnet/stats" "$BR"
11289         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
11290         remove_lnet_proc_files "stats"
11291
11292         # /proc/sys/lnet/routes should look like this:
11293         # Routing disabled/enabled
11294         # net hops priority state router
11295         # where net is a string like tcp0, hops > 0, priority >= 0,
11296         # state is up/down,
11297         # router is a string like 192.168.1.1@tcp2
11298         L1="^Routing (disabled|enabled)$"
11299         L2="^net +hops +priority +state +router$"
11300         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
11301         create_lnet_proc_files "routes"
11302         check_lnet_proc_entry "routes.out" "/proc/sys/lnet/routes" "$BR" "$L1" "$L2"
11303         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
11304         remove_lnet_proc_files "routes"
11305
11306         # /proc/sys/lnet/routers should look like this:
11307         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
11308         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
11309         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
11310         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
11311         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
11312         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
11313         create_lnet_proc_files "routers"
11314         check_lnet_proc_entry "routers.out" "/proc/sys/lnet/routers" "$BR" "$L1"
11315         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
11316         remove_lnet_proc_files "routers"
11317
11318         # /proc/sys/lnet/peers should look like this:
11319         # nid refs state last max rtr min tx min queue
11320         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
11321         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
11322         # numeric (0 or >0 or <0), queue >= 0.
11323         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
11324         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
11325         create_lnet_proc_files "peers"
11326         check_lnet_proc_entry "peers.out" "/proc/sys/lnet/peers" "$BR" "$L1"
11327         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
11328         remove_lnet_proc_files "peers"
11329
11330         # /proc/sys/lnet/buffers  should look like this:
11331         # pages count credits min
11332         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
11333         L1="^pages +count +credits +min$"
11334         BR="^ +$N +$N +$I +$I$"
11335         create_lnet_proc_files "buffers"
11336         check_lnet_proc_entry "buffers.out" "/proc/sys/lnet/buffers" "$BR" "$L1"
11337         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
11338         remove_lnet_proc_files "buffers"
11339
11340         # /proc/sys/lnet/nis should look like this:
11341         # nid status alive refs peer rtr max tx min
11342         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
11343         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
11344         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
11345         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
11346         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
11347         create_lnet_proc_files "nis"
11348         check_lnet_proc_entry "nis.out" "/proc/sys/lnet/nis" "$BR" "$L1"
11349         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
11350         remove_lnet_proc_files "nis"
11351
11352         # can we successfully write to /proc/sys/lnet/stats?
11353         echo "0" >/proc/sys/lnet/stats || error "cannot write to /proc/sys/lnet/stats"
11354         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
11355 }
11356 run_test 215 "/proc/sys/lnet exists and has proper content - bugs 18102, 21079, 21517"
11357
11358 test_216() { # bug 20317
11359         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11360         remote_ost_nodsh && skip "remote OST with nodsh" && return
11361
11362         local node
11363         local facets=$(get_facets OST)
11364         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11365
11366         save_lustre_params client "osc.*.contention_seconds" > $p
11367         save_lustre_params $facets \
11368                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
11369         save_lustre_params $facets \
11370                 "ldlm.namespaces.filter-*.contended_locks" >> $p
11371         save_lustre_params $facets \
11372                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
11373         clear_osc_stats
11374
11375         # agressive lockless i/o settings
11376         for node in $(osts_nodes); do
11377                 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'
11378         done
11379         lctl set_param -n osc.*.contention_seconds 60
11380
11381         $DIRECTIO write $DIR/$tfile 0 10 4096
11382         $CHECKSTAT -s 40960 $DIR/$tfile
11383
11384         # disable lockless i/o
11385         for node in $(osts_nodes); do
11386                 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'
11387         done
11388         lctl set_param -n osc.*.contention_seconds 0
11389         clear_osc_stats
11390
11391         dd if=/dev/zero of=$DIR/$tfile count=0
11392         $CHECKSTAT -s 0 $DIR/$tfile
11393
11394         restore_lustre_params <$p
11395         rm -f $p
11396         rm $DIR/$tfile
11397 }
11398 run_test 216 "check lockless direct write works and updates file size and kms correctly"
11399
11400 test_217() { # bug 22430
11401         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11402         local node
11403         local nid
11404
11405         for node in $(nodes_list); do
11406                 nid=$(host_nids_address $node $NETTYPE)
11407                 if [[ $nid = *-* ]] ; then
11408                         echo "lctl ping $nid@$NETTYPE"
11409                         lctl ping $nid@$NETTYPE
11410                 else
11411                         echo "skipping $node (no hyphen detected)"
11412                 fi
11413         done
11414 }
11415 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
11416
11417 test_218() {
11418        # do directio so as not to populate the page cache
11419        log "creating a 10 Mb file"
11420        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11421        log "starting reads"
11422        dd if=$DIR/$tfile of=/dev/null bs=4096 &
11423        log "truncating the file"
11424        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11425        log "killing dd"
11426        kill %+ || true # reads might have finished
11427        echo "wait until dd is finished"
11428        wait
11429        log "removing the temporary file"
11430        rm -rf $DIR/$tfile || error "tmp file removal failed"
11431 }
11432 run_test 218 "parallel read and truncate should not deadlock ======================="
11433
11434 test_219() {
11435         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11436         # write one partial page
11437         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
11438         # set no grant so vvp_io_commit_write will do sync write
11439         $LCTL set_param fail_loc=0x411
11440         # write a full page at the end of file
11441         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
11442
11443         $LCTL set_param fail_loc=0
11444         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
11445         $LCTL set_param fail_loc=0x411
11446         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
11447
11448         # LU-4201
11449         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
11450         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
11451 }
11452 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
11453
11454 test_220() { #LU-325
11455         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11456         remote_ost_nodsh && skip "remote OST with nodsh" && return
11457         local OSTIDX=0
11458
11459         test_mkdir -p $DIR/$tdir
11460         local OST=$(lfs osts | grep ${OSTIDX}": " | \
11461                 awk '{print $2}' | sed -e 's/_UUID$//')
11462
11463         # on the mdt's osc
11464         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
11465         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
11466                         osc.$mdtosc_proc1.prealloc_last_id)
11467         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
11468                         osc.$mdtosc_proc1.prealloc_next_id)
11469
11470         $LFS df -i
11471
11472         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
11473         #define OBD_FAIL_OST_ENOINO              0x229
11474         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
11475         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
11476         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
11477
11478         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
11479
11480         MDSOBJS=$((last_id - next_id))
11481         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
11482
11483         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
11484         echo "OST still has $count kbytes free"
11485
11486         echo "create $MDSOBJS files @next_id..."
11487         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
11488
11489         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11490                         osc.$mdtosc_proc1.prealloc_last_id)
11491         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11492                         osc.$mdtosc_proc1.prealloc_next_id)
11493
11494         echo "after creation, last_id=$last_id2, next_id=$next_id2"
11495         $LFS df -i
11496
11497         echo "cleanup..."
11498
11499         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
11500         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
11501
11502         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
11503         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
11504         echo "unlink $MDSOBJS files @$next_id..."
11505         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
11506 }
11507 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
11508
11509 test_221() {
11510         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11511         dd if=`which date` of=$MOUNT/date oflag=sync
11512         chmod +x $MOUNT/date
11513
11514         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
11515         $LCTL set_param fail_loc=0x80001401
11516
11517         $MOUNT/date > /dev/null
11518         rm -f $MOUNT/date
11519 }
11520 run_test 221 "make sure fault and truncate race to not cause OOM"
11521
11522 test_222a () {
11523         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11524        rm -rf $DIR/$tdir
11525        test_mkdir -p $DIR/$tdir
11526        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11527        createmany -o $DIR/$tdir/$tfile 10
11528        cancel_lru_locks mdc
11529        cancel_lru_locks osc
11530        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11531        $LCTL set_param fail_loc=0x31a
11532        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
11533        $LCTL set_param fail_loc=0
11534        rm -r $DIR/$tdir
11535 }
11536 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
11537
11538 test_222b () {
11539         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11540        rm -rf $DIR/$tdir
11541        test_mkdir -p $DIR/$tdir
11542        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11543        createmany -o $DIR/$tdir/$tfile 10
11544        cancel_lru_locks mdc
11545        cancel_lru_locks osc
11546        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11547        $LCTL set_param fail_loc=0x31a
11548        rm -r $DIR/$tdir || "AGL for rmdir failed"
11549        $LCTL set_param fail_loc=0
11550 }
11551 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
11552
11553 test_223 () {
11554         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11555        rm -rf $DIR/$tdir
11556        test_mkdir -p $DIR/$tdir
11557        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11558        createmany -o $DIR/$tdir/$tfile 10
11559        cancel_lru_locks mdc
11560        cancel_lru_locks osc
11561        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
11562        $LCTL set_param fail_loc=0x31b
11563        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
11564        $LCTL set_param fail_loc=0
11565        rm -r $DIR/$tdir
11566 }
11567 run_test 223 "osc reenqueue if without AGL lock granted ======================="
11568
11569 test_224a() { # LU-1039, MRP-303
11570         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11571         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
11572         $LCTL set_param fail_loc=0x508
11573         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
11574         $LCTL set_param fail_loc=0
11575         df $DIR
11576 }
11577 run_test 224a "Don't panic on bulk IO failure"
11578
11579 test_224b() { # LU-1039, MRP-303
11580         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11581         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
11582         cancel_lru_locks osc
11583         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
11584         $LCTL set_param fail_loc=0x515
11585         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
11586         $LCTL set_param fail_loc=0
11587         df $DIR
11588 }
11589 run_test 224b "Don't panic on bulk IO failure"
11590
11591 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
11592 test_225a () {
11593         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11594         if [ -z ${MDSSURVEY} ]; then
11595               skip_env "mds-survey not found" && return
11596         fi
11597
11598         [ $MDSCOUNT -ge 2 ] &&
11599                 skip "skipping now for more than one MDT" && return
11600
11601        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11602             { skip "Need MDS version at least 2.2.51"; return; }
11603
11604        local mds=$(facet_host $SINGLEMDS)
11605        local target=$(do_nodes $mds 'lctl dl' | \
11606                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11607
11608        local cmd1="file_count=1000 thrhi=4"
11609        local cmd2="dir_count=2 layer=mdd stripe_count=0"
11610        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11611        local cmd="$cmd1 $cmd2 $cmd3"
11612
11613        rm -f ${TMP}/mds_survey*
11614        echo + $cmd
11615        eval $cmd || error "mds-survey with zero-stripe failed"
11616        cat ${TMP}/mds_survey*
11617        rm -f ${TMP}/mds_survey*
11618 }
11619 run_test 225a "Metadata survey sanity with zero-stripe"
11620
11621 test_225b () {
11622         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11623
11624         if [ -z ${MDSSURVEY} ]; then
11625               skip_env "mds-survey not found" && return
11626         fi
11627         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11628             { skip "Need MDS version at least 2.2.51"; return; }
11629
11630         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
11631               skip_env "Need to mount OST to test" && return
11632         fi
11633
11634         [ $MDSCOUNT -ge 2 ] &&
11635                 skip "skipping now for more than one MDT" && return
11636        local mds=$(facet_host $SINGLEMDS)
11637        local target=$(do_nodes $mds 'lctl dl' | \
11638                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11639
11640        local cmd1="file_count=1000 thrhi=4"
11641        local cmd2="dir_count=2 layer=mdd stripe_count=1"
11642        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11643        local cmd="$cmd1 $cmd2 $cmd3"
11644
11645        rm -f ${TMP}/mds_survey*
11646        echo + $cmd
11647        eval $cmd || error "mds-survey with stripe_count failed"
11648        cat ${TMP}/mds_survey*
11649        rm -f ${TMP}/mds_survey*
11650 }
11651 run_test 225b "Metadata survey sanity with stripe_count = 1"
11652
11653 mcreate_path2fid () {
11654         local mode=$1
11655         local major=$2
11656         local minor=$3
11657         local name=$4
11658         local desc=$5
11659         local path=$DIR/$tdir/$name
11660         local fid
11661         local rc
11662         local fid_path
11663
11664         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
11665                 error "cannot create $desc"
11666
11667         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
11668         rc=$?
11669         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
11670
11671         fid_path=$($LFS fid2path $MOUNT $fid)
11672         rc=$?
11673         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
11674
11675         [ "$path" == "$fid_path" ] ||
11676                 error "fid2path returned $fid_path, expected $path"
11677
11678         echo "pass with $path and $fid"
11679 }
11680
11681 test_226a () {
11682         rm -rf $DIR/$tdir
11683         mkdir -p $DIR/$tdir
11684
11685         mcreate_path2fid 0010666 0 0 fifo "FIFO"
11686         mcreate_path2fid 0020666 1 3 null "character special file (null)"
11687         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
11688         mcreate_path2fid 0040666 0 0 dir "directory"
11689         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
11690         mcreate_path2fid 0100666 0 0 file "regular file"
11691         mcreate_path2fid 0120666 0 0 link "symbolic link"
11692         mcreate_path2fid 0140666 0 0 sock "socket"
11693 }
11694 run_test 226a "call path2fid and fid2path on files of all type"
11695
11696 test_226b () {
11697         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11698         rm -rf $DIR/$tdir
11699         local MDTIDX=1
11700
11701         mkdir -p $DIR/$tdir
11702         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
11703                 error "create remote directory failed"
11704         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
11705         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
11706                                 "character special file (null)"
11707         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
11708                                 "character special file (no device)"
11709         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
11710         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
11711                                 "block special file (loop)"
11712         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
11713         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
11714         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
11715 }
11716 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
11717
11718 # LU-1299 Executing or running ldd on a truncated executable does not
11719 # cause an out-of-memory condition.
11720 test_227() {
11721         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11722         dd if=`which date` of=$MOUNT/date bs=1k count=1
11723         chmod +x $MOUNT/date
11724
11725         $MOUNT/date > /dev/null
11726         ldd $MOUNT/date > /dev/null
11727         rm -f $MOUNT/date
11728 }
11729 run_test 227 "running truncated executable does not cause OOM"
11730
11731 # LU-1512 try to reuse idle OI blocks
11732 test_228a() {
11733         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11734         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11735                 skip "non-ldiskfs backend" && return
11736
11737         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11738         local myDIR=$DIR/$tdir
11739
11740         mkdir -p $myDIR
11741         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11742         $LCTL set_param fail_loc=0x80001002
11743         createmany -o $myDIR/t- 10000
11744         $LCTL set_param fail_loc=0
11745         # The guard is current the largest FID holder
11746         touch $myDIR/guard
11747         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11748                     tr -d '[')
11749         local IDX=$(($SEQ % 64))
11750
11751         do_facet $SINGLEMDS sync
11752         # Make sure journal flushed.
11753         sleep 6
11754         local blk1=$(do_facet $SINGLEMDS \
11755                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11756                      grep Blockcount | awk '{print $4}')
11757
11758         # Remove old files, some OI blocks will become idle.
11759         unlinkmany $myDIR/t- 10000
11760         # Create new files, idle OI blocks should be reused.
11761         createmany -o $myDIR/t- 2000
11762         do_facet $SINGLEMDS sync
11763         # Make sure journal flushed.
11764         sleep 6
11765         local blk2=$(do_facet $SINGLEMDS \
11766                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11767                      grep Blockcount | awk '{print $4}')
11768
11769         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11770 }
11771 run_test 228a "try to reuse idle OI blocks"
11772
11773 test_228b() {
11774         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11775         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11776                 skip "non-ldiskfs backend" && return
11777
11778         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11779         local myDIR=$DIR/$tdir
11780
11781         mkdir -p $myDIR
11782         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11783         $LCTL set_param fail_loc=0x80001002
11784         createmany -o $myDIR/t- 10000
11785         $LCTL set_param fail_loc=0
11786         # The guard is current the largest FID holder
11787         touch $myDIR/guard
11788         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11789                     tr -d '[')
11790         local IDX=$(($SEQ % 64))
11791
11792         do_facet $SINGLEMDS sync
11793         # Make sure journal flushed.
11794         sleep 6
11795         local blk1=$(do_facet $SINGLEMDS \
11796                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11797                      grep Blockcount | awk '{print $4}')
11798
11799         # Remove old files, some OI blocks will become idle.
11800         unlinkmany $myDIR/t- 10000
11801
11802         # stop the MDT
11803         stop $SINGLEMDS || error "Fail to stop MDT."
11804         # remount the MDT
11805         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
11806
11807         df $MOUNT || error "Fail to df."
11808         # Create new files, idle OI blocks should be reused.
11809         createmany -o $myDIR/t- 2000
11810         do_facet $SINGLEMDS sync
11811         # Make sure journal flushed.
11812         sleep 6
11813         local blk2=$(do_facet $SINGLEMDS \
11814                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11815                      grep Blockcount | awk '{print $4}')
11816
11817         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11818 }
11819 run_test 228b "idle OI blocks can be reused after MDT restart"
11820
11821 #LU-1881
11822 test_228c() {
11823         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11824         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11825                 skip "non-ldiskfs backend" && return
11826
11827         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11828         local myDIR=$DIR/$tdir
11829
11830         mkdir -p $myDIR
11831         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11832         $LCTL set_param fail_loc=0x80001002
11833         # 20000 files can guarantee there are index nodes in the OI file
11834         createmany -o $myDIR/t- 20000
11835         $LCTL set_param fail_loc=0
11836         # The guard is current the largest FID holder
11837         touch $myDIR/guard
11838         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11839                     tr -d '[')
11840         local IDX=$(($SEQ % 64))
11841
11842         do_facet $SINGLEMDS sync
11843         # Make sure journal flushed.
11844         sleep 6
11845         local blk1=$(do_facet $SINGLEMDS \
11846                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11847                      grep Blockcount | awk '{print $4}')
11848
11849         # Remove old files, some OI blocks will become idle.
11850         unlinkmany $myDIR/t- 20000
11851         rm -f $myDIR/guard
11852         # The OI file should become empty now
11853
11854         # Create new files, idle OI blocks should be reused.
11855         createmany -o $myDIR/t- 2000
11856         do_facet $SINGLEMDS sync
11857         # Make sure journal flushed.
11858         sleep 6
11859         local blk2=$(do_facet $SINGLEMDS \
11860                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11861                      grep Blockcount | awk '{print $4}')
11862
11863         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11864 }
11865 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
11866
11867 test_229() { # LU-2482, LU-3448
11868         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
11869                 skip "No HSM support on MDS of $(get_lustre_version)," \
11870                          "need 2.4.53 at least" && return
11871         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11872         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
11873
11874         rm -f $DIR/$tfile
11875
11876         # Create a file with a released layout and stripe count 2.
11877         $MULTIOP $DIR/$tfile H2c ||
11878                 error "failed to create file with released layout"
11879
11880         $GETSTRIPE -v $DIR/$tfile
11881
11882         local pattern=$($GETSTRIPE -L $DIR/$tfile)
11883         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
11884
11885         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
11886         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
11887         stat $DIR/$tfile || error "failed to stat released file"
11888
11889         chown $RUNAS_ID $DIR/$tfile ||
11890                 error "chown $RUNAS_ID $DIR/$tfile failed"
11891
11892         chgrp $RUNAS_ID $DIR/$tfile ||
11893                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
11894
11895         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
11896         rm $DIR/$tfile || error "failed to remove released file"
11897 }
11898 run_test 229 "getstripe/stat/rm/attr changes work on released files"
11899
11900 test_230a() {
11901         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11902         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11903         local MDTIDX=1
11904
11905         mkdir -p $DIR/$tdir/test_230_local
11906         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
11907         [ $mdt_idx -ne 0 ] &&
11908                 error "create local directory on wrong MDT $mdt_idx"
11909
11910         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
11911                         error "create remote directory failed"
11912         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
11913         [ $mdt_idx -ne $MDTIDX ] &&
11914                 error "create remote directory on wrong MDT $mdt_idx"
11915
11916         createmany -o $DIR/$tdir/test_230/t- 10 ||
11917                 error "create files on remote directory failed"
11918         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
11919         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
11920         rm -r $DIR/$tdir || error "unlink remote directory failed"
11921 }
11922 run_test 230a "Create remote directory and files under the remote directory"
11923
11924 test_230b() {
11925         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11926         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11927         local MDTIDX=1
11928         local mdt_index
11929         local i
11930         local file
11931         local pid
11932         local stripe_count
11933         local migrate_dir=$DIR/$tdir/migrate_dir
11934         local other_dir=$DIR/$tdir/other_dir
11935
11936         mkdir -p $migrate_dir
11937         mkdir -p $other_dir
11938         for ((i=0; i<10; i++)); do
11939                 mkdir -p $migrate_dir/dir_${i}
11940                 createmany -o $migrate_dir/dir_${i}/f 10 ||
11941                         error "create files under remote dir failed $i"
11942         done
11943
11944         cp /etc/passwd $migrate_dir/$tfile
11945         cp /etc/passwd $other_dir/$tfile
11946         mkdir -p $migrate_dir/dir_default_stripe2
11947         $LFS setstripe -c 2 $migrate_dir/dir_default_stripe2
11948         $LFS setstripe -c 2 $migrate_dir/${tfile}_stripe2
11949
11950         mkdir -p $other_dir
11951         ln $migrate_dir/$tfile $other_dir/luna
11952         ln $migrate_dir/$tfile $migrate_dir/sofia
11953         ln $other_dir/$tfile $migrate_dir/david
11954         ln -s $migrate_dir/$tfile $other_dir/zachary
11955         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
11956         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
11957
11958         $LFS mv -v -M $MDTIDX $migrate_dir ||
11959                         error "migrate remote dir error"
11960
11961         echo "migratate to MDT1, then checking.."
11962         for ((i=0; i<10; i++)); do
11963                 for file in $(find $migrate_dir/dir_${i}); do
11964                         mdt_index=$($LFS getstripe -M $file)
11965                         [ $mdt_index == $MDTIDX ] ||
11966                                 error "$file is not on MDT${MDTIDX}"
11967                 done
11968         done
11969
11970         # the multiple link file should still in MDT0
11971         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
11972         [ $mdt_index == 0 ] ||
11973                 error "$file is not on MDT${MDTIDX}"
11974
11975         diff /etc/passwd $migrate_dir/$tfile ||
11976                 error "$tfile different after migration"
11977
11978         diff /etc/passwd $other_dir/luna ||
11979                 error "luna different after migration"
11980
11981         diff /etc/passwd $migrate_dir/sofia ||
11982                 error "sofia different after migration"
11983
11984         diff /etc/passwd $migrate_dir/david ||
11985                 error "david different after migration"
11986
11987         diff /etc/passwd $other_dir/zachary ||
11988                 error "zachary different after migration"
11989
11990         diff /etc/passwd $migrate_dir/${tfile}_ln ||
11991                 error "${tfile}_ln different after migration"
11992
11993         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
11994                 error "${tfile}_ln_other different after migration"
11995
11996         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
11997         [ $stripe_count = 2 ] ||
11998                         error "dir strpe_count $d != 2 after migration."
11999
12000         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12001         [ $stripe_count = 2 ] ||
12002                         error "file strpe_count $d != 2 after migration."
12003
12004         #migrate back to MDT0
12005         MDTIDX=0
12006         $LFS mv -v -M $MDTIDX $migrate_dir ||
12007                         error "migrate remote dir error"
12008
12009         echo "migrate back to MDT0, checking.."
12010         for file in $(find $migrate_dir); do
12011                 mdt_index=$($LFS getstripe -M $file)
12012                 [ $mdt_index == $MDTIDX ] ||
12013                         error "$file is not on MDT${MDTIDX}"
12014         done
12015
12016         diff /etc/passwd ${migrate_dir}/$tfile ||
12017                 error "$tfile different after migration"
12018
12019         diff /etc/passwd ${other_dir}/luna ||
12020                 error "luna different after migration"
12021
12022         diff /etc/passwd ${migrate_dir}/sofia ||
12023                 error "sofia different after migration"
12024
12025         diff /etc/passwd ${other_dir}/zachary ||
12026                 error "zachary different after migration"
12027
12028         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12029                 error "${tfile}_ln different after migration"
12030
12031         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12032                 error "${tfile}_ln_other different after migration"
12033
12034         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12035         [ $stripe_count = 2 ] ||
12036                 error "dir strpe_count $d != 2 after migration."
12037
12038         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12039         [ $stripe_count = 2 ] ||
12040                 error "file strpe_count $d != 2 after migration."
12041
12042         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12043 }
12044 run_test 230b "migrate directory"
12045
12046 test_230c() {
12047         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12048         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12049         local MDTIDX=1
12050         local mdt_index
12051         local file
12052
12053         #If migrating directory fails in the middle, all entries of
12054         #the directory is still accessiable.
12055         mkdir -p $DIR/$tdir
12056         stat $DIR/$tdir
12057         createmany -o $DIR/$tdir/f 10 ||
12058                 error "create files under ${tdir} failed"
12059
12060         #failed after migrating 5 entries
12061         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12062         do_facet mds1 lctl set_param fail_loc=0x20001801
12063         do_facet mds1 lctl  set_param fail_val=5
12064         local t=`ls $DIR/$tdir | wc -l`
12065         $LFS mv -M $MDTIDX $DIR/$tdir &&
12066                 error "migrate should failed after 5 entries"
12067         local u=`ls $DIR/$tdir | wc -l`
12068         [ "$u" == "$t" ] || error "$u != $t during migration"
12069
12070         for file in $(find $DIR/$tdir); do
12071                 stat $file || error "stat $file failed"
12072         done
12073
12074         do_facet mds1 lctl set_param fail_loc=0
12075         do_facet mds1 lctl set_param fail_val=0
12076
12077         $LFS mv -M $MDTIDX $DIR/$tdir ||
12078                 error "migrate open files should failed with open files"
12079
12080         echo "Finish migration, then checking.."
12081         for file in $(find $DIR/$tdir); do
12082                 mdt_index=$($LFS getstripe -M $file)
12083                 [ $mdt_index == $MDTIDX ] ||
12084                         error "$file is not on MDT${MDTIDX}"
12085         done
12086
12087         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12088 }
12089 run_test 230c "check directory accessiblity if migration is failed"
12090
12091 test_230d() {
12092         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12093         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12094         local MDTIDX=1
12095         local mdt_index
12096         local i
12097         local j
12098
12099         mkdir -p $DIR/$tdir
12100
12101         for ((i=0; i<100; i++)); do
12102                 mkdir -p $DIR/$tdir/dir_${i}
12103                 createmany -o $DIR/$tdir/dir_${i}/f 100 ||
12104                         error "create files under remote dir failed $i"
12105         done
12106
12107         $LFS mv -M $MDTIDX -v $DIR/$tdir || error "migrate remote dir error"
12108
12109         echo "Finish migration, then checking.."
12110         for file in $(find $DIR/$tdir); do
12111                 mdt_index=$($LFS getstripe -M $file)
12112                 [ $mdt_index == $MDTIDX ] ||
12113                         error "$file is not on MDT${MDTIDX}"
12114         done
12115
12116         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12117 }
12118 run_test 230d "check migrate big directory"
12119
12120 test_231a()
12121 {
12122         # For simplicity this test assumes that max_pages_per_rpc
12123         # is the same across all OSCs
12124         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
12125         local bulk_size=$((max_pages * 4096))
12126
12127         mkdir -p $DIR/$tdir
12128
12129         # clear the OSC stats
12130         $LCTL set_param osc.*.stats=0 &>/dev/null
12131
12132         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
12133         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
12134                 oflag=direct &>/dev/null || error "dd failed"
12135
12136         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
12137         if [ x$nrpcs != "x1" ]; then
12138                 error "found $nrpc ost_write RPCs, not 1 as expected"
12139         fi
12140
12141         # Drop the OSC cache, otherwise we will read from it
12142         cancel_lru_locks osc
12143
12144         # clear the OSC stats
12145         $LCTL set_param osc.*.stats=0 &>/dev/null
12146
12147         # Client reads $bulk_size.
12148         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
12149                 iflag=direct &>/dev/null || error "dd failed"
12150
12151         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
12152         if [ x$nrpcs != "x1" ]; then
12153                 error "found $nrpc ost_read RPCs, not 1 as expected"
12154         fi
12155 }
12156 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
12157
12158 test_231b() {
12159         mkdir -p $DIR/$tdir
12160         local i
12161         for i in {0..1023}; do
12162                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
12163                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
12164                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
12165         done
12166         sync
12167 }
12168 run_test 231b "must not assert on fully utilized OST request buffer"
12169
12170 test_232() {
12171         mkdir -p $DIR/$tdir
12172         #define OBD_FAIL_LDLM_OST_LVB            0x31c
12173         $LCTL set_param fail_loc=0x31c
12174
12175         # ignore dd failure
12176         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
12177
12178         $LCTL set_param fail_loc=0
12179         umount_client $MOUNT || error "umount failed"
12180         mount_client $MOUNT || error "mount failed"
12181 }
12182 run_test 232 "failed lock should not block umount"
12183
12184 test_233a() {
12185         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
12186         { skip "Need MDS version at least 2.3.64"; return; }
12187
12188         local fid=$($LFS path2fid $MOUNT)
12189         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12190                 error "cannot access $MOUNT using its FID '$fid'"
12191 }
12192 run_test 233a "checking that OBF of the FS root succeeds"
12193
12194 test_233b() {
12195         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
12196         { skip "Need MDS version at least 2.5.90"; return; }
12197
12198         local fid=$($LFS path2fid $MOUNT/.lustre)
12199         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12200                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
12201
12202         fid=$($LFS path2fid $MOUNT/.lustre/fid)
12203         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12204                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
12205 }
12206 run_test 233b "checking that OBF of the FS .lustre succeeds"
12207
12208 test_234() {
12209         local p="$TMP/sanityN-$TESTNAME.parameters"
12210         save_lustre_params client "llite.*.xattr_cache" > $p
12211         lctl set_param llite.*.xattr_cache 1 ||
12212                 { skip "xattr cache is not supported"; return 0; }
12213
12214         mkdir -p $DIR/$tdir || error "mkdir failed"
12215         touch $DIR/$tdir/$tfile || error "touch failed"
12216         # OBD_FAIL_LLITE_XATTR_ENOMEM
12217         $LCTL set_param fail_loc=0x1405
12218         if [ ! -f /etc/SuSE-release ]; then
12219                 # attr pre-2.4.44-7 had a bug with rc
12220                 # LU-3703 - SLES clients have older attr
12221                 getfattr -n user.attr $DIR/$tdir/$tfile &&
12222                         error "getfattr should have failed with ENOMEM"
12223         fi
12224         $LCTL set_param fail_loc=0x0
12225         rm -rf $DIR/$tdir
12226
12227         restore_lustre_params < $p
12228         rm -f $p
12229 }
12230 run_test 234 "xattr cache should not crash on ENOMEM"
12231
12232 test_235() {
12233          [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
12234                 skip "Need MDS version at least 2.4.52" && return
12235         flock_deadlock $DIR/$tfile
12236         local RC=$?
12237         case $RC in
12238                 0)
12239                 ;;
12240                 124) error "process hangs on a deadlock"
12241                 ;;
12242                 *) error "error executing flock_deadlock $DIR/$tfile"
12243                 ;;
12244         esac
12245 }
12246 run_test 235 "LU-1715: flock deadlock detection does not work properly"
12247
12248 #LU-2935
12249 test_236() {
12250         check_swap_layouts_support && return 0
12251         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
12252
12253         local ref1=/etc/passwd
12254         local ref2=/etc/group
12255         local file1=$DIR/$tdir/f1
12256         local file2=$DIR/$tdir/f2
12257
12258         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
12259         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
12260         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
12261         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
12262         local fd=$(free_fd)
12263         local cmd="exec $fd<>$file2"
12264         eval $cmd
12265         rm $file2
12266         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
12267                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
12268         cmd="exec $fd>&-"
12269         eval $cmd
12270         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12271
12272         #cleanup
12273         rm -rf $DIR/$tdir
12274 }
12275 run_test 236 "Layout swap on open unlinked file"
12276
12277 # test to verify file handle related system calls
12278 # (name_to_handle_at/open_by_handle_at)
12279 # The new system calls are supported in glibc >= 2.14.
12280
12281 test_237() {
12282         echo "Test file_handle syscalls" > $DIR/$tfile
12283         check_fhandle_syscalls $DIR/$tfile ||
12284                 error "check_fhandle_syscalls failed"
12285 }
12286 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
12287
12288 # LU-4659 linkea consistency
12289 test_238() {
12290         touch $DIR/$tfile
12291         ln $DIR/$tfile $DIR/$tfile.lnk
12292         touch $DIR/$tfile.new
12293         mv $DIR/$tfile.new $DIR/$tfile
12294         local fid1=$(lfs path2fid $DIR/$tfile)
12295         local fid2=$(lfs path2fid $DIR/$tfile.lnk)
12296         local path1=$(lfs fid2path $FSNAME $fid1)
12297         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
12298         local path2=$(lfs fid2path $FSNAME $fid2)
12299         [ $tfile.lnk == $path2 ] ||
12300                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
12301         rm -f $DIR/$tfile*
12302 }
12303 run_test 238 "Verify linkea consistency"
12304
12305 test_striped_dir() {
12306         local mdt_index=$1
12307         local stripe_count
12308         local stripe_index
12309
12310         mkdir -p $DIR/$tdir
12311         $LFS setdirstripe -i $mdt_index -c 2 -t all_char $DIR/$tdir/striped_dir ||
12312                 error "set striped dir error"
12313
12314         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
12315         if [ "$stripe_count" != "2" ]; then
12316                 error "stripe_count is $stripe_count, expect 2"
12317         fi
12318
12319         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
12320         if [ "$stripe_index" != "$mdt_index" ]; then
12321                 error "stripe_index is $stripe_index, expect $mdt_index"
12322         fi
12323
12324         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12325                 error "nlink error after create striped dir"
12326
12327         mkdir $DIR/$tdir/striped_dir/a
12328         mkdir $DIR/$tdir/striped_dir/b
12329
12330         stat $DIR/$tdir/striped_dir/a ||
12331                 error "create dir under striped dir failed"
12332         stat $DIR/$tdir/striped_dir/b ||
12333                 error "create dir under striped dir failed"
12334
12335         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
12336                 error "nlink error after mkdir"
12337
12338         rmdir $DIR/$tdir/striped_dir/a
12339         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
12340                 error "nlink error after rmdir"
12341
12342         rmdir $DIR/$tdir/striped_dir/b
12343         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12344                 error "nlink error after rmdir"
12345
12346         rmdir $DIR/$tdir/striped_dir ||
12347                 error "rmdir striped dir error"
12348         true
12349 }
12350
12351 test_300a() {
12352         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12353         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12354
12355         test_striped_dir 0 || error "failed on striped dir on MDT0"
12356         test_striped_dir 1 || error "failed on striped dir on MDT0"
12357 }
12358 run_test 300a "basic striped dir sanity test"
12359
12360 test_300b() {
12361         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12362         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12363         local i
12364         local mtime1
12365         local mtime2
12366         local mtime3
12367
12368         test_mkdir $DIR/$tdir || error "mkdir fail"
12369         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12370                 error "set striped dir error"
12371         for ((i=0; i<10; i++)); do
12372                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
12373                 sleep 1
12374                 touch $DIR/$tdir/striped_dir/file_$i ||
12375                                         error "touch error $i"
12376                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
12377                 [ $mtime1 -eq $mtime2 ] &&
12378                         error "mtime not change after create"
12379                 sleep 1
12380                 rm -f $DIR/$tdir/striped_dir/file_$i ||
12381                                         error "unlink error $i"
12382                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
12383                 [ $mtime2 -eq $mtime3 ] &&
12384                         error "mtime did not change after unlink"
12385         done
12386         true
12387 }
12388 run_test 300b "check ctime/mtime for striped dir"
12389
12390 test_300c() {
12391         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12392         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12393         local file_count
12394
12395         mkdir -p $DIR/$tdir
12396         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
12397                 error "set striped dir error"
12398
12399         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
12400                 error "chown striped dir failed"
12401
12402         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
12403                 error "create 5k files failed"
12404
12405         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
12406
12407         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
12408
12409         rm -rf $DIR/$tdir
12410 }
12411 run_test 300c "chown && check ls under striped directory"
12412
12413 test_300d() {
12414         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12415         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12416         local stripe_count
12417         local file
12418
12419         mkdir -p $DIR/$tdir
12420         $SETSTRIPE -c 2 $DIR/$tdir
12421
12422         #local striped directory
12423         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12424                 error "set striped dir error"
12425         createmany -o $DIR/$tdir/striped_dir/f 10 ||
12426                 error "create 10 files failed"
12427
12428         #remote striped directory
12429         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
12430                 error "set striped dir error"
12431         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
12432                 error "create 10 files failed"
12433
12434         for file in $(find $DIR/$tdir); do
12435                 stripe_count=$($GETSTRIPE -c $file)
12436                 [ $stripe_count -eq 2 ] ||
12437                         error "wrong stripe $stripe_count for $file"
12438         done
12439
12440         rm -rf $DIR/$tdir
12441 }
12442 run_test 300d "check default stripe under striped directory"
12443
12444 test_300e() {
12445         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12446         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12447         local stripe_count
12448         local file
12449
12450         mkdir -p $DIR/$tdir
12451
12452         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12453                 error "set striped dir error"
12454
12455         touch $DIR/$tdir/striped_dir/a
12456         touch $DIR/$tdir/striped_dir/b
12457         touch $DIR/$tdir/striped_dir/c
12458
12459         mkdir $DIR/$tdir/striped_dir/dir_a
12460         mkdir $DIR/$tdir/striped_dir/dir_b
12461         mkdir $DIR/$tdir/striped_dir/dir_c
12462
12463         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
12464                 error "set striped dir under striped dir error"
12465
12466         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
12467                 error "set striped dir under striped dir error"
12468
12469         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
12470                 error "set striped dir under striped dir error"
12471
12472         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/b &&
12473                 error "rename file under striped dir should fail"
12474
12475         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b &&
12476                 error "rename dir under striped dir should fail"
12477
12478         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b &&
12479                 error "rename dir under different stripes should fail"
12480
12481         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
12482                 error "rename file under striped dir should succeed"
12483
12484         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_c ||
12485                 error "rename dir under striped dir should succeed"
12486
12487         rm -rf $DIR/$tdir
12488 }
12489 run_test 300e "check rename under striped directory"
12490
12491 test_300f() {
12492         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12493         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12494         local stripe_count
12495         local file
12496
12497         rm -rf $DIR/$tdir
12498         mkdir -p $DIR/$tdir
12499
12500         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12501                 error "set striped dir error"
12502
12503         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
12504                 error "set striped dir error"
12505
12506         touch $DIR/$tdir/striped_dir/a
12507         mkdir $DIR/$tdir/striped_dir/dir_a
12508         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
12509                 error "create striped dir under striped dir fails"
12510
12511         touch $DIR/$tdir/striped_dir1/b
12512         mkdir $DIR/$tdir/striped_dir1/dir_b
12513         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
12514                 error "create striped dir under striped dir fails"
12515
12516         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/b &&
12517                 error "rename file under different striped dir should fail"
12518
12519         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b &&
12520                 error "rename dir under different striped dir should fail"
12521
12522         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b &&
12523                 error "rename striped dir under diff striped dir should fail"
12524
12525         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
12526                 error "rename file under diff striped dirs fails"
12527
12528         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_a ||
12529                 error "rename dir under diff striped dirs fails"
12530
12531         rm -rf $DIR/$tdir
12532 }
12533 run_test 300f "check rename cross striped directory"
12534
12535 #
12536 # tests that do cleanup/setup should be run at the end
12537 #
12538
12539 test_900() {
12540         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12541         local ls
12542         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
12543         $LCTL set_param fail_loc=0x903
12544         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
12545         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
12546                 echo "clear" > $ls
12547         done
12548         FAIL_ON_ERROR=true cleanup
12549         FAIL_ON_ERROR=true setup
12550 }
12551 run_test 900 "umount should not race with any mgc requeue thread"
12552
12553 complete $SECONDS
12554 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
12555 check_and_cleanup_lustre
12556 if [ "$I_MOUNTED" != "yes" ]; then
12557         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
12558 fi
12559 exit_status