Whamcloud - gitweb
LU-4298 utils: do not create file with no striping info
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 # -*- tab-width: 8; indent-tabs-mode: t; -*-
3 #
4 # Run select tests by setting ONLY, or as arguments to the script.
5 # Skip specific tests by setting EXCEPT.
6 #
7 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11 # bug number for skipped test: 13297 2108 9789 3637 9789 3561 12622 5188
12 ALWAYS_EXCEPT="                42a  42b  42c  42d  45   51d   68b   $SANITY_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # with LOD/OSP landing
16 # bug number for skipped tests: LU-2036
17 ALWAYS_EXCEPT="                 76     $ALWAYS_EXCEPT"
18
19 SRCDIR=$(cd $(dirname $0); echo $PWD)
20 export PATH=$PATH:/sbin
21
22 TMP=${TMP:-/tmp}
23
24 CC=${CC:-cc}
25 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
26 CREATETEST=${CREATETEST:-createtest}
27 LFS=${LFS:-lfs}
28 LFIND=${LFIND:-"$LFS find"}
29 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
30 LCTL=${LCTL:-lctl}
31 OPENFILE=${OPENFILE:-openfile}
32 OPENUNLINK=${OPENUNLINK:-openunlink}
33 export MULTIOP=${MULTIOP:-multiop}
34 READS=${READS:-"reads"}
35 MUNLINK=${MUNLINK:-munlink}
36 SOCKETSERVER=${SOCKETSERVER:-socketserver}
37 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
38 MEMHOG=${MEMHOG:-memhog}
39 DIRECTIO=${DIRECTIO:-directio}
40 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
41 UMOUNT=${UMOUNT:-"umount -d"}
42 STRIPES_PER_OBJ=-1
43 CHECK_GRANT=${CHECK_GRANT:-"yes"}
44 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
45 export PARALLEL=${PARALLEL:-"no"}
46
47 export NAME=${NAME:-local}
48
49 SAVE_PWD=$PWD
50
51 CLEANUP=${CLEANUP:-:}
52 SETUP=${SETUP:-:}
53 TRACE=${TRACE:-""}
54 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
55 LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
56 . $LUSTRE/tests/test-framework.sh
57 init_test_env $@
58 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
59 init_logging
60
61 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 27m 64b 68 71 77f 78 115 124b 230d"
62
63 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
64 # bug number for skipped test:        LU-1593 LU-2833 LU-1957 LU-2805
65         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 34h     48a     180     184c"
66
67 FAIL_ON_ERROR=false
68
69 cleanup() {
70         echo -n "cln.."
71         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
72         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
73 }
74 setup() {
75         echo -n "mnt.."
76         load_modules
77         setupall || exit 10
78         echo "done"
79 }
80
81 check_kernel_version() {
82         WANT_VER=$1
83         GOT_VER=$(lctl get_param -n version | awk '/kernel:/ {print $2}')
84         case $GOT_VER in
85         patchless|patchless_client) return 0;;
86         *) [ $GOT_VER -ge $WANT_VER ] && return 0 ;;
87         esac
88         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
89         return 1
90 }
91
92 check_swap_layouts_support()
93 {
94         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
95                 { skip "Does not support layout lock."; return 0; }
96         return 1
97 }
98
99 if [ "$ONLY" == "cleanup" ]; then
100        sh llmountcleanup.sh
101        exit 0
102 fi
103
104 check_and_setup_lustre
105
106 DIR=${DIR:-$MOUNT}
107 assert_DIR
108
109 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
110         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
111 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
112 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
113 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
114 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
115 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
116 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
117
118 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
119 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
120 rm -rf $DIR/[Rdfs][0-9]*
121
122 # $RUNAS_ID may get set incorrectly somewhere else
123 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
124
125 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
126
127 build_test_filter
128
129 if [ "${ONLY}" = "MOUNT" ] ; then
130         echo "Lustre is up, please go on"
131         exit
132 fi
133
134 echo "preparing for tests involving mounts"
135 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
136 touch $EXT2_DEV
137 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
138 echo # add a newline after mke2fs.
139
140 umask 077
141
142 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
143 lctl set_param debug=-1 2> /dev/null || true
144 test_0a() {
145         touch $DIR/$tfile
146         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
147         rm $DIR/$tfile
148         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
149 }
150 run_test 0a "touch; rm ====================="
151
152 test_0b() {
153         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
154         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
155 }
156 run_test 0b "chmod 0755 $DIR ============================="
157
158 test_0c() {
159         $LCTL get_param mdc.*.import | grep "state: FULL" ||
160                 error "import not FULL"
161         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
162                 error "bad target"
163 }
164 run_test 0c "check import proc ============================="
165
166 test_1() {
167         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
168         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
169         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
170         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
171         rmdir $DIR/$tdir/d2
172         rmdir $DIR/$tdir
173         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
174 }
175 run_test 1 "mkdir; remkdir; rmdir =============================="
176
177 test_2() {
178         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
179         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
180         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
181         rm -r $DIR/$tdir
182         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
183 }
184 run_test 2 "mkdir; touch; rmdir; check file ===================="
185
186 test_3() {
187         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
188         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
189         touch $DIR/$tdir/$tfile
190         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
191         rm -r $DIR/$tdir
192         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
193 }
194 run_test 3 "mkdir; touch; rmdir; check dir ====================="
195
196 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
197 test_4() {
198         local MDTIDX=1
199
200         test_mkdir $DIR/$tdir ||
201                 error "Create remote directory failed"
202
203         touch $DIR/$tdir/$tfile ||
204                 error "Create file under remote directory failed"
205
206         rmdir $DIR/$tdir &&
207                 error "Expect error removing in-use dir $DIR/$tdir"
208
209         test -d $DIR/$tdir || error "Remote directory disappeared"
210
211         rm -rf $DIR/$tdir || error "remove remote dir error"
212 }
213 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
214
215 test_5() {
216         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
217         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
218         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
219         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
220         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
221 }
222 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
223
224 test_6a() {
225         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
226         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
227         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
228                 error "$tfile does not have perm 0666 or UID $UID"
229         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
230         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
231                 error "$tfile should be 0666 and owned by UID $UID"
232 }
233 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
234
235 test_6c() {
236         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
237         touch $DIR/$tfile
238         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
239         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
240                 error "$tfile should be owned by UID $RUNAS_ID"
241         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
242         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
243                 error "$tfile should be owned by UID $RUNAS_ID"
244 }
245 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
246
247 test_6e() {
248         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
249         touch $DIR/$tfile
250         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
251         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
252                 error "$tfile should be owned by GID $UID"
253         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
254         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
255                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
256 }
257 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
258
259 test_6g() {
260         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
261         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
262         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
263         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
264         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
265         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
266         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
267                 error "$tdir/d/subdir should be GID $RUNAS_GID"
268 }
269 run_test 6g "Is new dir in sgid dir inheriting group?"
270
271 test_6h() { # bug 7331
272         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
273         touch $DIR/$tfile || error "touch failed"
274         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
275         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
276                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
277         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
278                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
279 }
280 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
281
282 test_7a() {
283         test_mkdir $DIR/$tdir
284         $MCREATE $DIR/$tdir/$tfile
285         chmod 0666 $DIR/$tdir/$tfile
286         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
287                 error "$tdir/$tfile should be mode 0666"
288 }
289 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
290
291 test_7b() {
292         if [ ! -d $DIR/$tdir ]; then
293                 mkdir $DIR/$tdir
294         fi
295         $MCREATE $DIR/$tdir/$tfile
296         echo -n foo > $DIR/$tdir/$tfile
297         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
298         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
299 }
300 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
301
302 test_8() {
303         test_mkdir $DIR/$tdir
304         touch $DIR/$tdir/$tfile
305         chmod 0666 $DIR/$tdir/$tfile
306         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
307                 error "$tfile mode not 0666"
308 }
309 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
310
311 test_9() {
312         test_mkdir $DIR/$tdir
313         test_mkdir $DIR/$tdir/d2
314         test_mkdir $DIR/$tdir/d2/d3
315         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
316 }
317 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
318
319 test_10() {
320         test_mkdir $DIR/$tdir
321         test_mkdir $DIR/$tdir/d2
322         touch $DIR/$tdir/d2/$tfile
323         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
324                 error "$tdir/d2/$tfile not a file"
325 }
326 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
327
328 test_11() {
329         test_mkdir $DIR/$tdir
330         test_mkdir $DIR/$tdir/d2
331         chmod 0666 $DIR/$tdir/d2
332         chmod 0705 $DIR/$tdir/d2
333         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
334                 error "$tdir/d2 mode not 0705"
335 }
336 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
337
338 test_12() {
339         test_mkdir $DIR/$tdir
340         touch $DIR/$tdir/$tfile
341         chmod 0666 $DIR/$tdir/$tfile
342         chmod 0654 $DIR/$tdir/$tfile
343         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
344                 error "$tdir/d2 mode not 0654"
345 }
346 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
347
348 test_13() {
349         test_mkdir $DIR/$tdir
350         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
351         >  $DIR/$tdir/$tfile
352         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
353                 error "$tdir/$tfile size not 0 after truncate"
354 }
355 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
356
357 test_14() {
358         test_mkdir $DIR/$tdir
359         touch $DIR/$tdir/$tfile
360         rm $DIR/$tdir/$tfile
361         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
362 }
363 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
364
365 test_15() {
366         test_mkdir $DIR/$tdir
367         touch $DIR/$tdir/$tfile
368         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
369         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
370                 error "$tdir/${tfile_2} not a file after rename"
371 }
372 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
373
374 test_16() {
375         test_mkdir $DIR/$tdir
376         touch $DIR/$tdir/$tfile
377         rm -rf $DIR/$tdir/$tfile
378         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
379 }
380 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
381
382 test_17a() {
383         test_mkdir -p $DIR/$tdir
384         touch $DIR/$tdir/$tfile
385         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
386         ls -l $DIR/$tdir
387         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
388                 error "$tdir/l-exist not a symlink"
389         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
390                 error "$tdir/l-exist not referencing a file"
391         rm -f $DIR/$tdir/l-exist
392         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
393 }
394 run_test 17a "symlinks: create, remove (real) =================="
395
396 test_17b() {
397         test_mkdir -p $DIR/$tdir
398         ln -s no-such-file $DIR/$tdir/l-dangle
399         ls -l $DIR/$tdir
400         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
401                 error "$tdir/l-dangle not referencing no-such-file"
402         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
403                 error "$tdir/l-dangle not referencing non-existent file"
404         rm -f $DIR/$tdir/l-dangle
405         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
406 }
407 run_test 17b "symlinks: create, remove (dangling) =============="
408
409 test_17c() { # bug 3440 - don't save failed open RPC for replay
410         test_mkdir -p $DIR/$tdir
411         ln -s foo $DIR/$tdir/$tfile
412         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
413 }
414 run_test 17c "symlinks: open dangling (should return error) ===="
415
416 test_17d() {
417         test_mkdir -p $DIR/$tdir
418         ln -s foo $DIR/$tdir/$tfile
419         touch $DIR/$tdir/$tfile || error "creating to new symlink"
420 }
421 run_test 17d "symlinks: create dangling ========================"
422
423 test_17e() {
424         test_mkdir -p $DIR/$tdir
425         local foo=$DIR/$tdir/$tfile
426         ln -s $foo $foo || error "create symlink failed"
427         ls -l $foo || error "ls -l failed"
428         ls $foo && error "ls not failed" || true
429 }
430 run_test 17e "symlinks: create recursive symlink (should return error) ===="
431
432 test_17f() {
433         test_mkdir -p $DIR/$tdir
434         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
435         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
436         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
437         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
438         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
439         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890/aaaaaaaaaa/bbbbbbbbbb/cccccccccc/dddddddddd/eeeeeeeeee/ffffffffff/ $DIR/$tdir/666
440         ls -l  $DIR/$tdir
441 }
442 run_test 17f "symlinks: long and very long symlink name ========================"
443
444 # str_repeat(S, N) generate a string that is string S repeated N times
445 str_repeat() {
446         local s=$1
447         local n=$2
448         local ret=''
449         while [ $((n -= 1)) -ge 0 ]; do
450                 ret=$ret$s
451         done
452         echo $ret
453 }
454
455 # Long symlinks and LU-2241
456 test_17g() {
457         test_mkdir -p $DIR/$tdir
458         local TESTS="59 60 61 4094 4095"
459
460         # Fix for inode size boundary in 2.1.4
461         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
462                 TESTS="4094 4095"
463
464         # Patch not applied to 2.2 or 2.3 branches
465         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
466         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
467                 TESTS="4094 4095"
468
469         # skip long symlink name for rhel6.5.
470         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
471         grep -q '6.5' /etc/redhat-release &>/dev/null &&
472                 TESTS="59 60 61 4062 4063"
473
474         for i in $TESTS; do
475                 local SYMNAME=$(str_repeat 'x' $i)
476                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
477                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
478         done
479 }
480 run_test 17g "symlinks: really long symlink name and inode boundaries"
481
482 test_17h() { #bug 17378
483         remote_mds_nodsh && skip "remote MDS with nodsh" && return
484         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
485         local mdt_idx
486         test_mkdir -p $DIR/$tdir
487         if [[ $MDSCOUNT -gt 1 ]]; then
488                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
489         else
490                 mdt_idx=0
491         fi
492         $SETSTRIPE -c -1 $DIR/$tdir
493 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
494         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
495         touch $DIR/$tdir/$tfile || true
496 }
497 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
498
499 test_17i() { #bug 20018
500         remote_mds_nodsh && skip "remote MDS with nodsh" && return
501         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
502         test_mkdir -c1 $DIR/$tdir
503         local foo=$DIR/$tdir/$tfile
504         local mdt_idx
505         if [[ $MDSCOUNT -gt 1 ]]; then
506                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
507         else
508                 mdt_idx=0
509         fi
510         ln -s $foo $foo || error "create symlink failed"
511 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
512         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
513         ls -l $foo && error "error not detected"
514         return 0
515 }
516 run_test 17i "don't panic on short symlink"
517
518 test_17k() { #bug 22301
519         [[ -z "$(which rsync 2>/dev/null)" ]] &&
520                 skip "no rsync command" && return 0
521         rsync --help | grep -q xattr ||
522                 skip_env "$(rsync --version | head -n1) does not support xattrs"
523         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
524         test_mkdir -p $DIR/$tdir
525         test_mkdir -p $DIR/$tdir.new
526         touch $DIR/$tdir/$tfile
527         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
528         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
529                 error "rsync failed with xattrs enabled"
530 }
531 run_test 17k "symlinks: rsync with xattrs enabled ========================="
532
533 test_17l() { # LU-279
534         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
535                 skip "no getfattr command" && return 0
536         mkdir -p $DIR/$tdir
537         touch $DIR/$tdir/$tfile
538         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
539         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
540                 # -h to not follow symlinks. -m '' to list all the xattrs.
541                 # grep to remove first line: '# file: $path'.
542                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
543                 do
544                         lgetxattr_size_check $path $xattr ||
545                                 error "lgetxattr_size_check $path $xattr failed"
546                 done
547         done
548 }
549 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
550
551 # LU-1540
552 test_17m() {
553         local short_sym="0123456789"
554         local WDIR=$DIR/${tdir}m
555         local mds_index
556         local devname
557         local cmd
558         local i
559         local rc=0
560
561         remote_mds_nodsh && skip "remote MDS with nodsh" && return
562         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
563         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
564                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
565
566         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
567                 skip "only for ldiskfs MDT" && return 0
568
569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
570
571         mkdir -p $WDIR
572         long_sym=$short_sym
573         # create a long symlink file
574         for ((i = 0; i < 4; ++i)); do
575                 long_sym=${long_sym}${long_sym}
576         done
577
578         echo "create 512 short and long symlink files under $WDIR"
579         for ((i = 0; i < 256; ++i)); do
580                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
581                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
582         done
583
584         echo "erase them"
585         rm -f $WDIR/*
586         sync
587         wait_delete_completed
588
589         echo "recreate the 512 symlink files with a shorter string"
590         for ((i = 0; i < 512; ++i)); do
591                 # rewrite the symlink file with a shorter string
592                 ln -sf ${long_sym} $WDIR/long-$i
593                 ln -sf ${short_sym} $WDIR/short-$i
594         done
595
596         mds_index=$($LFS getstripe -M $WDIR)
597         mds_index=$((mds_index+1))
598         devname=$(mdsdevname $mds_index)
599         cmd="$E2FSCK -fnvd $devname"
600
601         echo "stop and checking mds${mds_index}: $cmd"
602         # e2fsck should not return error
603         stop mds${mds_index}
604         do_facet mds${mds_index} $cmd || rc=$?
605
606         start mds${mds_index} $devname $MDS_MOUNT_OPTS || error "start failed"
607         df $MOUNT > /dev/null 2>&1
608         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
609                 "short/long symlink MDT: rc=$rc"
610         return $rc
611 }
612 run_test 17m "run e2fsck against MDT which contains short/long symlink"
613
614 check_fs_consistency_17n() {
615         local mdt_index
616         local devname
617         local cmd
618         local rc=0
619
620         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
621         # so it only check MDT1/MDT2 instead of all of MDTs.
622         for mdt_index in $(seq 1 2); do
623                 devname=$(mdsdevname $mdt_index)
624                 cmd="$E2FSCK -fnvd $devname"
625
626                 echo "stop and checking mds${mdt_index}: $cmd"
627                 # e2fsck should not return error
628                 stop mds${mdt_index}
629                 do_facet mds${mdt_index} $cmd || rc=$?
630
631                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
632                         error "mount mds${mdt_index} failed"
633                 df $MOUNT > /dev/null 2>&1
634                 [ $rc -ne 0 ] && break
635         done
636         return $rc
637 }
638
639 test_17n() {
640         local i
641
642         remote_mds_nodsh && skip "remote MDS with nodsh" && return
643         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
644         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
645                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
646
647         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
648                 skip "only for ldiskfs MDT" && return 0
649
650         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
651
652         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
653
654         mkdir $DIR/$tdir
655         for ((i=0; i<10; i++)); do
656                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
657                         error "create remote dir error $i"
658                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
659                         error "create files under remote dir failed $i"
660         done
661
662         check_fs_consistency_17n ||
663                 error "e2fsck report error after create files under remote dir"
664
665         for ((i=0;i<10;i++)); do
666                 rm -rf $DIR/$tdir/remote_dir_${i} ||
667                         error "destroy remote dir error $i"
668         done
669
670         check_fs_consistency_17n ||
671                 error "e2fsck report error after unlink files under remote dir"
672
673         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
674                 skip "lustre < 2.4.50 does not support migrate mv " && return
675
676         for ((i=0; i<10; i++)); do
677                 mkdir -p $DIR/$tdir/remote_dir_${i}
678                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
679                         error "create files under remote dir failed $i"
680                 $LFS mv -M 1 $DIR/$tdir/remote_dir_${i} ||
681                         error "migrate remote dir error $i"
682         done
683         check_fs_consistency_17n || error "e2fsck report error after migration"
684
685         for ((i=0;i<10;i++)); do
686                 rm -rf $DIR/$tdir/remote_dir_${i} ||
687                         error "destroy remote dir error $i"
688         done
689
690         check_fs_consistency_17n || error "e2fsck report error after unlink"
691 }
692 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
693
694 test_17o() {
695         remote_mds_nodsh && skip "remote MDS with nodsh" && return
696         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
697                 skip "Need MDS version at least 2.3.64" && return
698
699         local WDIR=$DIR/${tdir}o
700         local mdt_index
701         local mdtdevname
702         local rc=0
703
704         mkdir -p $WDIR
705         mdt_index=$($LFS getstripe -M $WDIR)
706         mdt_index=$((mdt_index+1))
707         mdtdevname=$(mdsdevname $mdt_index)
708
709         touch $WDIR/$tfile
710         stop mds${mdt_index}
711         start mds${mdt_index} $mdtdevname $MDS_MOUNT_OPTS ||
712                 error "mount mds${mdt_index} failed"
713
714         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
715         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
716         ls -l $WDIR/$tfile && rc=1
717         do_facet mds${mdt_index} lctl set_param fail_loc=0
718         [[ $rc -ne 0 ]] && error "stat file should fail"
719         true
720 }
721 run_test 17o "stat file with incompat LMA feature"
722
723 test_18() {
724         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
725         ls $DIR || error "Failed to ls $DIR: $?"
726 }
727 run_test 18 "touch .../f ; ls ... =============================="
728
729 test_19a() {
730         touch $DIR/$tfile
731         ls -l $DIR
732         rm $DIR/$tfile
733         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
734 }
735 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
736
737 test_19b() {
738         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
739 }
740 run_test 19b "ls -l .../f19 (should return error) =============="
741
742 test_19c() {
743         [ $RUNAS_ID -eq $UID ] &&
744                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
745         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
746 }
747 run_test 19c "$RUNAS touch .../f19 (should return error) =="
748
749 test_19d() {
750         cat $DIR/f19 && error || true
751 }
752 run_test 19d "cat .../f19 (should return error) =============="
753
754 test_20() {
755         touch $DIR/$tfile
756         rm $DIR/$tfile
757         log "1 done"
758         touch $DIR/$tfile
759         rm $DIR/$tfile
760         log "2 done"
761         touch $DIR/$tfile
762         rm $DIR/$tfile
763         log "3 done"
764         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
765 }
766 run_test 20 "touch .../f ; ls -l ... ==========================="
767
768 test_21() {
769         test_mkdir -p $DIR/$tdir
770         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
771         ln -s dangle $DIR/$tdir/link
772         echo foo >> $DIR/$tdir/link
773         cat $DIR/$tdir/dangle
774         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
775         $CHECKSTAT -f -t file $DIR/$tdir/link ||
776                 error "$tdir/link not linked to a file"
777 }
778 run_test 21 "write to dangling link ============================"
779
780 test_22() {
781         WDIR=$DIR/$tdir
782         test_mkdir -p $DIR/$tdir
783         chown $RUNAS_ID:$RUNAS_GID $WDIR
784         (cd $WDIR || error "cd $WDIR failed";
785         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
786         $RUNAS tar xf -)
787         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
788         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
789         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
790 }
791 run_test 22 "unpack tar archive as non-root user ==============="
792
793 # was test_23
794 test_23a() {
795         test_mkdir -p $DIR/$tdir
796         local file=$DIR/$tdir/$tfile
797
798         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
799         openfile -f O_CREAT:O_EXCL $file &&
800                 error "$file recreate succeeded" || true
801 }
802 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
803
804 test_23b() { # bug 18988
805         test_mkdir -p $DIR/$tdir
806         local file=$DIR/$tdir/$tfile
807
808         rm -f $file
809         echo foo > $file || error "write filed"
810         echo bar >> $file || error "append filed"
811         $CHECKSTAT -s 8 $file || error "wrong size"
812         rm $file
813 }
814 run_test 23b "O_APPEND check =========================="
815
816 # rename sanity
817 test_24a() {
818         echo '-- same directory rename'
819         test_mkdir $DIR/$tdir
820         touch $DIR/$tdir/$tfile.1
821         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
822         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
823 }
824 run_test 24a "rename file to non-existent target"
825
826 test_24b() {
827         test_mkdir $DIR/$tdir
828         touch $DIR/$tdir/$tfile.{1,2}
829         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
830         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
831         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
832 }
833 run_test 24b "rename file to existing target"
834
835 test_24c() {
836         test_mkdir $DIR/$tdir
837         test_mkdir $DIR/$tdir/d$testnum.1
838         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
839         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
840         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
841 }
842 run_test 24c "rename directory to non-existent target"
843
844 test_24d() {
845         test_mkdir -c1 $DIR/$tdir
846         test_mkdir -c1 $DIR/$tdir/d$testnum.1
847         test_mkdir -c1 $DIR/$tdir/d$testnum.2
848         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
849         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
850         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
851 }
852 run_test 24d "rename directory to existing target"
853
854 test_24e() {
855         echo '-- cross directory renames --'
856         test_mkdir $DIR/R5a
857         test_mkdir $DIR/R5b
858         touch $DIR/R5a/f
859         mv $DIR/R5a/f $DIR/R5b/g
860         $CHECKSTAT -a $DIR/R5a/f || error
861         $CHECKSTAT -t file $DIR/R5b/g || error
862 }
863 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
864
865 test_24f() {
866         test_mkdir $DIR/R6a
867         test_mkdir $DIR/R6b
868         touch $DIR/R6a/f $DIR/R6b/g
869         mv $DIR/R6a/f $DIR/R6b/g
870         $CHECKSTAT -a $DIR/R6a/f || error
871         $CHECKSTAT -t file $DIR/R6b/g || error
872 }
873 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
874
875 test_24g() {
876         test_mkdir $DIR/R7a
877         test_mkdir $DIR/R7b
878         test_mkdir $DIR/R7a/d
879         mv $DIR/R7a/d $DIR/R7b/e
880         $CHECKSTAT -a $DIR/R7a/d || error
881         $CHECKSTAT -t dir $DIR/R7b/e || error
882 }
883 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
884
885 test_24h() {
886         test_mkdir -c1 $DIR/R8a
887         test_mkdir -c1 $DIR/R8b
888         test_mkdir -c1 $DIR/R8a/d
889         test_mkdir -c1 $DIR/R8b/e
890         mrename $DIR/R8a/d $DIR/R8b/e
891         $CHECKSTAT -a $DIR/R8a/d || error
892         $CHECKSTAT -t dir $DIR/R8b/e || error
893 }
894 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
895
896 test_24i() {
897         echo "-- rename error cases"
898         test_mkdir $DIR/R9
899         test_mkdir $DIR/R9/a
900         touch $DIR/R9/f
901         mrename $DIR/R9/f $DIR/R9/a
902         $CHECKSTAT -t file $DIR/R9/f || error
903         $CHECKSTAT -t dir  $DIR/R9/a || error
904         $CHECKSTAT -a $DIR/R9/a/f || error
905 }
906 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
907
908 test_24j() {
909         test_mkdir $DIR/R10
910         mrename $DIR/R10/f $DIR/R10/g
911         $CHECKSTAT -t dir $DIR/R10 || error
912         $CHECKSTAT -a $DIR/R10/f || error
913         $CHECKSTAT -a $DIR/R10/g || error
914 }
915 run_test 24j "source does not exist ============================"
916
917 test_24k() {
918         test_mkdir $DIR/R11a
919         test_mkdir $DIR/R11a/d
920         touch $DIR/R11a/f
921         mv $DIR/R11a/f $DIR/R11a/d
922         $CHECKSTAT -a $DIR/R11a/f || error
923         $CHECKSTAT -t file $DIR/R11a/d/f || error
924 }
925 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
926
927 # bug 2429 - rename foo foo foo creates invalid file
928 test_24l() {
929         f="$DIR/f24l"
930         $MULTIOP $f OcNs || error
931 }
932 run_test 24l "Renaming a file to itself ========================"
933
934 test_24m() {
935         f="$DIR/f24m"
936         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
937         # on ext3 this does not remove either the source or target files
938         # though the "expected" operation would be to remove the source
939         $CHECKSTAT -t file ${f} || error "${f} missing"
940         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
941 }
942 run_test 24m "Renaming a file to a hard link to itself ========="
943
944 test_24n() {
945     f="$DIR/f24n"
946     # this stats the old file after it was renamed, so it should fail
947     touch ${f}
948     $CHECKSTAT ${f}
949     mv ${f} ${f}.rename
950     $CHECKSTAT ${f}.rename
951     $CHECKSTAT -a ${f}
952 }
953 run_test 24n "Statting the old file after renaming (Posix rename 2)"
954
955 test_24o() {
956         check_kernel_version 37 || return 0
957         test_mkdir -p $DIR/d24o
958         rename_many -s random -v -n 10 $DIR/d24o
959 }
960 run_test 24o "rename of files during htree split ==============="
961
962 test_24p() {
963         test_mkdir $DIR/R12a
964         test_mkdir $DIR/R12b
965         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
966         mrename $DIR/R12a $DIR/R12b
967         $CHECKSTAT -a $DIR/R12a || error
968         $CHECKSTAT -t dir $DIR/R12b || error
969         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
970         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
971 }
972 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
973
974 cleanup_multiop_pause() {
975         trap 0
976         kill -USR1 $MULTIPID
977 }
978
979 test_24q() {
980         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
981         test_mkdir $DIR/R13a
982         test_mkdir $DIR/R13b
983         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
984         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
985         MULTIPID=$!
986
987         trap cleanup_multiop_pause EXIT
988         mrename $DIR/R13a $DIR/R13b
989         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
990         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
991         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
992         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
993         cleanup_multiop_pause
994         wait $MULTIPID || error "multiop close failed"
995 }
996 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
997
998 test_24r() { #bug 3789
999         test_mkdir $DIR/R14a
1000         test_mkdir $DIR/R14a/b
1001         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1002         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1003         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1004 }
1005 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1006
1007 test_24s() {
1008         test_mkdir $DIR/R15a
1009         test_mkdir $DIR/R15a/b
1010         test_mkdir $DIR/R15a/b/c
1011         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1012         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1013         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1014 }
1015 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1016 test_24t() {
1017         test_mkdir $DIR/R16a
1018         test_mkdir $DIR/R16a/b
1019         test_mkdir $DIR/R16a/b/c
1020         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1021         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1022         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1023 }
1024 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1025
1026 test_24u() { # bug12192
1027         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1028         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1029 }
1030 run_test 24u "create stripe file"
1031
1032 page_size() {
1033         getconf PAGE_SIZE
1034 }
1035
1036 simple_cleanup_common() {
1037         trap 0
1038         rm -rf $DIR/$tdir
1039         wait_delete_completed
1040 }
1041
1042 max_pages_per_rpc() {
1043         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1044 }
1045
1046 test_24v() {
1047         local NRFILES=100000
1048         local FREE_INODES=$(mdt_free_inodes 0)
1049         [[ $FREE_INODES -lt $NRFILES ]] &&
1050                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1051                 return
1052
1053         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1054         trap simple_cleanup_common EXIT
1055
1056         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1057         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1058
1059         mkdir -p $DIR/$tdir
1060         createmany -m $DIR/$tdir/$tfile $NRFILES
1061
1062         cancel_lru_locks mdc
1063         lctl set_param mdc.*.stats clear
1064
1065         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1066
1067         # LU-5 large readdir
1068         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1069         #               8 bytes for name(filename is mostly 5 in this test) +
1070         #               8 bytes for luda_type
1071         # take into account of overhead in lu_dirpage header and end mark in
1072         # each page, plus one in RPC_NUM calculation.
1073         DIRENT_SIZE=48
1074         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1075         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1076         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1077                                 awk '/^mds_readpage/ {print $2}')
1078         [[ $mds_readpage -gt $RPC_NUM ]] &&
1079                 error "large readdir doesn't take effect"
1080
1081         simple_cleanup_common
1082 }
1083 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1084
1085 test_24w() { # bug21506
1086         SZ1=234852
1087         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1088         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1089         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1090         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1091         [[ "$SZ1" -eq "$SZ2" ]] ||
1092                 error "Error reading at the end of the file $tfile"
1093 }
1094 run_test 24w "Reading a file larger than 4Gb"
1095
1096 test_24x() {
1097         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1098         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1099         local MDTIDX=1
1100         local remote_dir=$DIR/$tdir/remote_dir
1101
1102         mkdir -p $DIR/$tdir
1103         $LFS mkdir -i $MDTIDX $remote_dir ||
1104                 error "create remote directory failed"
1105
1106         mkdir -p $DIR/$tdir/src_dir
1107         touch $DIR/$tdir/src_file
1108         mkdir -p $remote_dir/tgt_dir
1109         touch $remote_dir/tgt_file
1110
1111         mrename $remote_dir $DIR/ &&
1112                 error "rename dir cross MDT works!"
1113
1114         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1115                 error "rename dir cross MDT works!"
1116
1117         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1118                 error "rename file cross MDT works!"
1119
1120         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1121                 error "ln file cross MDT should not work!"
1122
1123         rm -rf $DIR/$tdir || error "Can not delete directories"
1124 }
1125 run_test 24x "cross rename/link should be failed"
1126
1127 test_24y() {
1128         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1129         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1130         local MDTIDX=1
1131         local remote_dir=$DIR/$tdir/remote_dir
1132
1133         mkdir -p $DIR/$tdir
1134         $LFS mkdir -i $MDTIDX $remote_dir ||
1135                    error "create remote directory failed"
1136
1137         mkdir -p $remote_dir/src_dir
1138         touch $remote_dir/src_file
1139         mkdir -p $remote_dir/tgt_dir
1140         touch $remote_dir/tgt_file
1141
1142         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1143                 error "rename subdir in the same remote dir failed!"
1144
1145         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1146                 error "rename files in the same remote dir failed!"
1147
1148         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1149                 error "link files in the same remote dir failed!"
1150
1151         rm -rf $DIR/$tdir || error "Can not delete directories"
1152 }
1153 run_test 24y "rename/link on the same dir should succeed"
1154
1155 test_24z() {
1156         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1157         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1158         local MDTIDX=1
1159         local remote_src=$DIR/$tdir/remote_dir
1160         local remote_tgt=$DIR/$tdir/remote_tgt
1161
1162         mkdir -p $DIR/$tdir
1163         $LFS mkdir -i $MDTIDX $remote_src ||
1164                    error "create remote directory failed"
1165
1166         $LFS mkdir -i $MDTIDX $remote_tgt ||
1167                    error "create remote directory failed"
1168
1169         mrename $remote_src $remote_tgt &&
1170                 error "rename remote dirs should not work!"
1171
1172         # If target dir does not exists, it should succeed
1173         rm -rf $remote_tgt
1174         mrename $remote_src $remote_tgt ||
1175                 error "rename remote dirs(tgt dir does not exists) failed!"
1176
1177         rm -rf $DIR/$tdir || error "Can not delete directories"
1178 }
1179 run_test 24z "rename one remote dir to another remote dir should fail"
1180
1181 test_24A() { # LU-3182
1182         local NFILES=5000
1183
1184         rm -rf $DIR/$tdir
1185         mkdir -p $DIR/$tdir
1186         createmany -m $DIR/$tdir/$tfile $NFILES
1187         local t=$(ls $DIR/$tdir | wc -l)
1188         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1189         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1190         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1191                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1192         fi
1193
1194         rm -rf $DIR/$tdir || error "Can not delete directories"
1195 }
1196 run_test 24A "readdir() returns correct number of entries."
1197
1198 test_24B() { # LU-4805
1199         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1200         local count
1201
1202         mkdir $DIR/$tdir
1203         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1204                 error "create striped dir failed"
1205
1206         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1207         [ $count -eq 2 ] || error "Expected 2, got $count"
1208
1209         touch $DIR/$tdir/striped_dir/a
1210
1211         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1212         [ $count -eq 3 ] || error "Expected 3, got $count"
1213
1214         touch $DIR/$tdir/striped_dir/.f
1215
1216         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1217         [ $count -eq 4 ] || error "Expected 4, got $count"
1218
1219         rm -rf $DIR/$tdir || error "Can not delete directories"
1220 }
1221 run_test 24B "readdir for striped dir return correct number of entries"
1222
1223 test_24C() {
1224         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1225
1226         mkdir $DIR/$tdir
1227         mkdir $DIR/$tdir/d0
1228         mkdir $DIR/$tdir/d1
1229
1230         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1231                 error "create striped dir failed"
1232
1233         cd $DIR/$tdir/d0/striped_dir
1234
1235         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1236         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1237         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1238
1239         [ "$d0_ino" = "$parent_ino" ] ||
1240                 error ".. wrong, expect $d0_ino, get $parent_ino"
1241
1242         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1243                 error "mv striped dir failed"
1244
1245         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1246
1247         [ "$d1_ino" = "$parent_ino" ] ||
1248                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1249 }
1250 run_test 24C "check .. in striped dir"
1251
1252 test_25a() {
1253         echo '== symlink sanity ============================================='
1254
1255         test_mkdir $DIR/d25
1256         ln -s d25 $DIR/s25
1257         touch $DIR/s25/foo || error
1258 }
1259 run_test 25a "create file in symlinked directory ==============="
1260
1261 test_25b() {
1262         [ ! -d $DIR/d25 ] && test_25a
1263         $CHECKSTAT -t file $DIR/s25/foo || error
1264 }
1265 run_test 25b "lookup file in symlinked directory ==============="
1266
1267 test_26a() {
1268         test_mkdir $DIR/d26
1269         test_mkdir $DIR/d26/d26-2
1270         ln -s d26/d26-2 $DIR/s26
1271         touch $DIR/s26/foo || error
1272 }
1273 run_test 26a "multiple component symlink ======================="
1274
1275 test_26b() {
1276         test_mkdir -p $DIR/d26b/d26-2
1277         ln -s d26b/d26-2/foo $DIR/s26-2
1278         touch $DIR/s26-2 || error
1279 }
1280 run_test 26b "multiple component symlink at end of lookup ======"
1281
1282 test_26c() {
1283         test_mkdir $DIR/d26.2
1284         touch $DIR/d26.2/foo
1285         ln -s d26.2 $DIR/s26.2-1
1286         ln -s s26.2-1 $DIR/s26.2-2
1287         ln -s s26.2-2 $DIR/s26.2-3
1288         chmod 0666 $DIR/s26.2-3/foo
1289 }
1290 run_test 26c "chain of symlinks ================================"
1291
1292 # recursive symlinks (bug 439)
1293 test_26d() {
1294         ln -s d26-3/foo $DIR/d26-3
1295 }
1296 run_test 26d "create multiple component recursive symlink ======"
1297
1298 test_26e() {
1299         [ ! -h $DIR/d26-3 ] && test_26d
1300         rm $DIR/d26-3
1301 }
1302 run_test 26e "unlink multiple component recursive symlink ======"
1303
1304 # recursive symlinks (bug 7022)
1305 test_26f() {
1306         test_mkdir -p $DIR/$tdir
1307         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1308         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1309         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1310         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1311         cd $tfile                || error "cd $tfile failed"
1312         ln -s .. dotdot          || error "ln dotdot failed"
1313         ln -s dotdot/lndir lndir || error "ln lndir failed"
1314         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1315         output=`ls $tfile/$tfile/lndir/bar1`
1316         [ "$output" = bar1 ] && error "unexpected output"
1317         rm -r $tfile             || error "rm $tfile failed"
1318         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1319 }
1320 run_test 26f "rm -r of a directory which has recursive symlink ="
1321
1322 test_27a() {
1323         echo '== stripe sanity =============================================='
1324         test_mkdir -p $DIR/d27 || error "mkdir failed"
1325         $GETSTRIPE $DIR/d27
1326         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1327         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1328         log "== test_27a: write to one stripe file ========================="
1329         cp /etc/hosts $DIR/d27/f0 || error
1330 }
1331 run_test 27a "one stripe file =================================="
1332
1333 test_27b() {
1334         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1335         test_mkdir -p $DIR/d27
1336         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1337         $GETSTRIPE -c $DIR/d27/f01
1338         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1339                 error "two-stripe file doesn't have two stripes"
1340
1341         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1342 }
1343 run_test 27b "create and write to two stripe file"
1344
1345 test_27d() {
1346         test_mkdir -p $DIR/d27
1347         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1348         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1349         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1350 }
1351 run_test 27d "create file with default settings ================"
1352
1353 test_27e() {
1354         test_mkdir -p $DIR/d27
1355         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1356         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1357         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1358 }
1359 run_test 27e "setstripe existing file (should return error) ======"
1360
1361 test_27f() {
1362         test_mkdir $DIR/$tdir
1363         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1364                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1365         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1366                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1367         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1368         $GETSTRIPE $DIR/$tdir/$tfile || error "$GETSTRIPE failed"
1369 }
1370 run_test 27f "setstripe with bad stripe size (should return error)"
1371
1372 test_27g() {
1373         test_mkdir -p $DIR/d27
1374         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1375         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1376                 error "$DIR/d27/fnone has object"
1377 }
1378 run_test 27g "$GETSTRIPE with no objects"
1379
1380 test_27i() {
1381         touch $DIR/d27/fsome || error "touch failed"
1382         [[ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ]] || error "missing objects"
1383 }
1384 run_test 27i "$GETSTRIPE with some objects"
1385
1386 test_27j() {
1387         test_mkdir -p $DIR/d27
1388         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1389 }
1390 run_test 27j "setstripe with bad stripe offset (should return error)"
1391
1392 test_27k() { # bug 2844
1393         test_mkdir -p $DIR/d27
1394         FILE=$DIR/d27/f27k
1395         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1396         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1397         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1398         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1399         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1400         dd if=/dev/zero of=$FILE bs=4k count=1
1401         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1402         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1403 }
1404 run_test 27k "limit i_blksize for broken user apps ============="
1405
1406 test_27l() {
1407         test_mkdir -p $DIR/d27
1408         mcreate $DIR/f27l || error "creating file"
1409         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1410                 error "setstripe should have failed" || true
1411 }
1412 run_test 27l "check setstripe permissions (should return error)"
1413
1414 test_27m() {
1415         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1416                 return
1417         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1418                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1419                 return
1420         fi
1421         trap simple_cleanup_common EXIT
1422         test_mkdir -p $DIR/$tdir
1423         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1424         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1425                 error "dd should fill OST0"
1426         i=2
1427         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1428                 i=$((i + 1))
1429                 [ $i -gt 256 ] && break
1430         done
1431         i=$((i + 1))
1432         touch $DIR/$tdir/f27m_$i
1433         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1434                 error "OST0 was full but new created file still use it"
1435         i=$((i + 1))
1436         touch $DIR/$tdir/f27m_$i
1437         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1438                 error "OST0 was full but new created file still use it"
1439         simple_cleanup_common
1440 }
1441 run_test 27m "create file while OST0 was full =================="
1442
1443 sleep_maxage() {
1444         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1445         sleep $DELAY
1446 }
1447
1448 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1449 # if the OST isn't full anymore.
1450 reset_enospc() {
1451         local OSTIDX=${1:-""}
1452
1453         local list=$(comma_list $(osts_nodes))
1454         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1455
1456         do_nodes $list lctl set_param fail_loc=0
1457         sync    # initiate all OST_DESTROYs from MDS to OST
1458         sleep_maxage
1459 }
1460
1461 exhaust_precreations() {
1462         local OSTIDX=$1
1463         local FAILLOC=$2
1464         local FAILIDX=${3:-$OSTIDX}
1465
1466         test_mkdir -p $DIR/$tdir
1467         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1468         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1469
1470         local OST=$(ostname_from_index $OSTIDX)
1471         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1472                           sed -e 's/_UUID$//;s/^.*-//')
1473
1474         # on the mdt's osc
1475         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1476         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1477                         osc.$mdtosc_proc1.prealloc_last_id)
1478         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1479                         osc.$mdtosc_proc1.prealloc_next_id)
1480
1481         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1482         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1483
1484         test_mkdir -p $DIR/$tdir/${OST}
1485         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1486 #define OBD_FAIL_OST_ENOSPC              0x215
1487         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1488         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1489         echo "Creating to objid $last_id on ost $OST..."
1490         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1491         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1492         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1493         sleep_maxage
1494 }
1495
1496 exhaust_all_precreations() {
1497         local i
1498         for (( i=0; i < OSTCOUNT; i++ )) ; do
1499                 exhaust_precreations $i $1 -1
1500         done
1501 }
1502
1503 test_27n() {
1504         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1505         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1506         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1507         remote_ost_nodsh && skip "remote OST with nodsh" && return
1508
1509         reset_enospc
1510         rm -f $DIR/$tdir/$tfile
1511         exhaust_precreations 0 0x80000215
1512         $SETSTRIPE -c -1 $DIR/$tdir
1513         touch $DIR/$tdir/$tfile || error
1514         $GETSTRIPE $DIR/$tdir/$tfile
1515         reset_enospc
1516 }
1517 run_test 27n "create file with some full OSTs =================="
1518
1519 test_27o() {
1520         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1521         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1522         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1523         remote_ost_nodsh && skip "remote OST with nodsh" && return
1524
1525         reset_enospc
1526         rm -f $DIR/$tdir/$tfile
1527         exhaust_all_precreations 0x215
1528
1529         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1530
1531         reset_enospc
1532         rm -rf $DIR/$tdir/*
1533 }
1534 run_test 27o "create file with all full OSTs (should error) ===="
1535
1536 test_27p() {
1537         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1538         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1539         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1540         remote_ost_nodsh && skip "remote OST with nodsh" && return
1541
1542         reset_enospc
1543         rm -f $DIR/$tdir/$tfile
1544         test_mkdir -p $DIR/$tdir
1545
1546         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1547         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1548         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1549
1550         exhaust_precreations 0 0x80000215
1551         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1552         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1553         $GETSTRIPE $DIR/$tdir/$tfile
1554
1555         reset_enospc
1556 }
1557 run_test 27p "append to a truncated file with some full OSTs ==="
1558
1559 test_27q() {
1560         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1561         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1562         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1563         remote_ost_nodsh && skip "remote OST with nodsh" && return
1564
1565         reset_enospc
1566         rm -f $DIR/$tdir/$tfile
1567
1568         test_mkdir -p $DIR/$tdir
1569         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1570         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1571         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1572
1573         exhaust_all_precreations 0x215
1574
1575         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1576         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1577
1578         reset_enospc
1579 }
1580 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1581
1582 test_27r() {
1583         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1584         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1585         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1586         remote_ost_nodsh && skip "remote OST with nodsh" && return
1587
1588         reset_enospc
1589         rm -f $DIR/$tdir/$tfile
1590         exhaust_precreations 0 0x80000215
1591
1592         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1593
1594         reset_enospc
1595 }
1596 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1597
1598 test_27s() { # bug 10725
1599         test_mkdir -p $DIR/$tdir
1600         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1601         local stripe_count=0
1602         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1603         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1604                 error "stripe width >= 2^32 succeeded" || true
1605
1606 }
1607 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1608
1609 test_27t() { # bug 10864
1610         WDIR=$(pwd)
1611         WLFS=$(which lfs)
1612         cd $DIR
1613         touch $tfile
1614         $WLFS getstripe $tfile
1615         cd $WDIR
1616 }
1617 run_test 27t "check that utils parse path correctly"
1618
1619 test_27u() { # bug 4900
1620         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1621         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1622         local index
1623         local list=$(comma_list $(mdts_nodes))
1624
1625 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1626         do_nodes $list $LCTL set_param fail_loc=0x139
1627         test_mkdir -p $DIR/$tdir
1628         rm -rf $DIR/$tdir/*
1629         createmany -o $DIR/$tdir/t- 1000
1630         do_nodes $list $LCTL set_param fail_loc=0
1631
1632         TLOG=$DIR/$tfile.getstripe
1633         $GETSTRIPE $DIR/$tdir > $TLOG
1634         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1635         unlinkmany $DIR/$tdir/t- 1000
1636         [[ $OBJS -gt 0 ]] &&
1637                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1638 }
1639 run_test 27u "skip object creation on OSC w/o objects =========="
1640
1641 test_27v() { # bug 4900
1642         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1643         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1644         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1645         remote_ost_nodsh && skip "remote OST with nodsh" && return
1646
1647         exhaust_all_precreations 0x215
1648         reset_enospc
1649
1650         test_mkdir -p $DIR/$tdir
1651         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1652
1653         touch $DIR/$tdir/$tfile
1654         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1655         # all except ost1
1656         for (( i=1; i < OSTCOUNT; i++ )); do
1657                 do_facet ost$i lctl set_param fail_loc=0x705
1658         done
1659         local START=`date +%s`
1660         createmany -o $DIR/$tdir/$tfile 32
1661
1662         local FINISH=`date +%s`
1663         local TIMEOUT=`lctl get_param -n timeout`
1664         local PROCESS=$((FINISH - START))
1665         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1666                error "$FINISH - $START >= $TIMEOUT / 2"
1667         sleep $((TIMEOUT / 2 - PROCESS))
1668         reset_enospc
1669 }
1670 run_test 27v "skip object creation on slow OST ================="
1671
1672 test_27w() { # bug 10997
1673         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1674         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1675         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1676                 error "stripe size $size != 65536" || true
1677         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1678                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1679 }
1680 run_test 27w "check $SETSTRIPE -S option"
1681
1682 test_27wa() {
1683         [[ $OSTCOUNT -lt 2 ]] &&
1684                 skip_env "skipping multiple stripe count/offset test" && return
1685
1686         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1687         for i in $(seq 1 $OSTCOUNT); do
1688                 offset=$((i - 1))
1689                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1690                         error "setstripe -c $i -i $offset failed"
1691                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1692                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1693                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1694                 [ $index -ne $offset ] &&
1695                         error "stripe offset $index != $offset" || true
1696         done
1697 }
1698 run_test 27wa "check $SETSTRIPE -c -i options"
1699
1700 test_27x() {
1701         remote_ost_nodsh && skip "remote OST with nodsh" && return
1702         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1703         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1704         OFFSET=$(($OSTCOUNT - 1))
1705         OSTIDX=0
1706         local OST=$(ostname_from_index $OSTIDX)
1707
1708         test_mkdir -p $DIR/$tdir
1709         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1710         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1711         sleep_maxage
1712         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1713         for i in `seq 0 $OFFSET`; do
1714                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1715                 error "OST0 was degraded but new created file still use it"
1716         done
1717         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1718 }
1719 run_test 27x "create files while OST0 is degraded"
1720
1721 test_27y() {
1722         [[ $OSTCOUNT -lt 2 ]] &&
1723                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1724         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1725         remote_ost_nodsh && skip "remote OST with nodsh" && return
1726         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1727
1728         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1729         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1730             osc.$mdtosc.prealloc_last_id)
1731         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1732             osc.$mdtosc.prealloc_next_id)
1733         local fcount=$((last_id - next_id))
1734         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1735         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1736
1737         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1738                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1739         local OST_DEACTIVE_IDX=-1
1740         local OSC
1741         local OSTIDX
1742         local OST
1743
1744         for OSC in $MDS_OSCS; do
1745                 OST=$(osc_to_ost $OSC)
1746                 OSTIDX=$(index_from_ostuuid $OST)
1747                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1748                         OST_DEACTIVE_IDX=$OSTIDX
1749                 fi
1750                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1751                         echo $OSC "is Deactivated:"
1752                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1753                 fi
1754         done
1755
1756         OSTIDX=$(index_from_ostuuid $OST)
1757         mkdir -p $DIR/$tdir
1758         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1759
1760         for OSC in $MDS_OSCS; do
1761                 OST=$(osc_to_ost $OSC)
1762                 OSTIDX=$(index_from_ostuuid $OST)
1763                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1764                         echo $OST "is degraded:"
1765                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1766                                                 obdfilter.$OST.degraded=1
1767                 fi
1768         done
1769
1770         sleep_maxage
1771         createmany -o $DIR/$tdir/$tfile $fcount
1772
1773         for OSC in $MDS_OSCS; do
1774                 OST=$(osc_to_ost $OSC)
1775                 OSTIDX=$(index_from_ostuuid $OST)
1776                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1777                         echo $OST "is recovered from degraded:"
1778                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1779                                                 obdfilter.$OST.degraded=0
1780                 else
1781                         do_facet $SINGLEMDS lctl --device %$OSC activate
1782                 fi
1783         done
1784
1785         # all osp devices get activated, hence -1 stripe count restored
1786         local stripecnt=0
1787
1788         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1789         # devices get activated.
1790         sleep_maxage
1791         $SETSTRIPE -c -1 $DIR/$tfile
1792         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1793         rm -f $DIR/$tfile
1794         [ $stripecnt -ne $OSTCOUNT ] &&
1795                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1796         return 0
1797 }
1798 run_test 27y "create files while OST0 is degraded and the rest inactive"
1799
1800 check_seq_oid()
1801 {
1802         log "check file $1"
1803
1804         lmm_count=$($GETSTRIPE -c $1)
1805         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1806         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1807
1808         local old_ifs="$IFS"
1809         IFS=$'[:]'
1810         fid=($($LFS path2fid $1))
1811         IFS="$old_ifs"
1812
1813         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1814         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1815
1816         # compare lmm_seq and lu_fid->f_seq
1817         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1818         # compare lmm_object_id and lu_fid->oid
1819         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1820
1821         # check the trusted.fid attribute of the OST objects of the file
1822         local have_obdidx=false
1823         local stripe_nr=0
1824         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1825                 # skip lines up to and including "obdidx"
1826                 [ -z "$obdidx" ] && break
1827                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1828                 $have_obdidx || continue
1829
1830                 local ost=$((obdidx + 1))
1831                 local dev=$(ostdevname $ost)
1832                 local oid_hex
1833
1834                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1835
1836                 seq=$(echo $seq | sed -e "s/^0x//g")
1837                 if [ $seq == 0 ]; then
1838                         oid_hex=$(echo $oid)
1839                 else
1840                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1841                 fi
1842                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1843
1844                 local ff
1845                 #
1846                 # Don't unmount/remount the OSTs if we don't need to do that.
1847                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1848                 # update too, until that use mount/ll_decode_filter_fid/mount.
1849                 # Re-enable when debugfs will understand new filter_fid.
1850                 #
1851                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1852                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1853                                 $dev 2>/dev/null" | grep "parent=")
1854                 else
1855                         stop ost$ost
1856                         mount_fstype ost$ost
1857                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1858                                 $(facet_mntpt ost$ost)/$obj_file)
1859                         unmount_fstype ost$ost
1860                         start ost$ost $dev $OST_MOUNT_OPTS
1861                 fi
1862
1863                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1864
1865                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1866
1867                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1868                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1869                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1870                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1871                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1872                 local ff_pstripe
1873                 if echo $ff_parent | grep -q 'stripe='; then
1874                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1875                 else
1876                         #
1877                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1878                         # into f_ver in this case.  See the comment on
1879                         # ff_parent.
1880                         #
1881                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1882                                 sed -e 's/\]//')
1883                 fi
1884
1885                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1886                 [ $ff_pseq = $lmm_seq ] ||
1887                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1888                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1889                 [ $ff_poid = $lmm_oid ] ||
1890                         error "FF parent OID $ff_poid != $lmm_oid"
1891                 (($ff_pstripe == $stripe_nr)) ||
1892                         error "FF stripe $ff_pstripe != $stripe_nr"
1893
1894                 stripe_nr=$((stripe_nr + 1))
1895         done
1896 }
1897
1898 test_27z() {
1899         remote_ost_nodsh && skip "remote OST with nodsh" && return
1900         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1901         test_mkdir -p $DIR/$tdir
1902
1903         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1904                 { error "setstripe -c -1 failed"; return 1; }
1905         # We need to send a write to every object to get parent FID info set.
1906         # This _should_ also work for setattr, but does not currently.
1907         # touch $DIR/$tdir/$tfile-1 ||
1908         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1909                 { error "dd $tfile-1 failed"; return 2; }
1910         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1911                 { error "setstripe -c -1 failed"; return 3; }
1912         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1913                 { error "dd $tfile-2 failed"; return 4; }
1914
1915         # make sure write RPCs have been sent to OSTs
1916         sync; sleep 5; sync
1917
1918         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1919         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1920 }
1921 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1922
1923 test_27A() { # b=19102
1924         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1925         local restore_size=$($GETSTRIPE -S $MOUNT)
1926         local restore_count=$($GETSTRIPE -c $MOUNT)
1927         local restore_offset=$($GETSTRIPE -i $MOUNT)
1928         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1929         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1930                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1931         local default_size=$($GETSTRIPE -S $MOUNT)
1932         local default_offset=$($GETSTRIPE -i $MOUNT)
1933         local dsize=$((1024 * 1024))
1934         [ $default_size -eq $dsize ] ||
1935                 error "stripe size $default_size != $dsize"
1936         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1937         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1938 }
1939 run_test 27A "check filesystem-wide default LOV EA values"
1940
1941 test_27B() { # LU-2523
1942         test_mkdir -p $DIR/$tdir
1943         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1944         touch $DIR/$tdir/f0
1945         # open f1 with O_LOV_DELAY_CREATE
1946         # rename f0 onto f1
1947         # call setstripe ioctl on open file descriptor for f1
1948         # close
1949         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1950                 $DIR/$tdir/f0
1951
1952         rm -f $DIR/$tdir/f1
1953         # open f1 with O_LOV_DELAY_CREATE
1954         # unlink f1
1955         # call setstripe ioctl on open file descriptor for f1
1956         # close
1957         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1958
1959         # Allow multiop to fail in imitation of NFS's busted semantics.
1960         true
1961 }
1962 run_test 27B "call setstripe on open unlinked file/rename victim"
1963
1964 test_27C() { #LU-2871
1965         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1966
1967         declare -a ost_idx
1968         local index
1969         local found
1970         local i
1971         local j
1972
1973         test_mkdir -p $DIR/$tdir
1974         cd $DIR/$tdir
1975         for i in $(seq 0 $((OSTCOUNT - 1))); do
1976                 # set stripe across all OSTs starting from OST$i
1977                 $SETSTRIPE -i $i -c -1 $tfile$i
1978                 # get striping information
1979                 ost_idx=($($GETSTRIPE $tfile$i |
1980                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1981                 echo ${ost_idx[@]}
1982
1983                 # check the layout
1984                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1985                         error "${#ost_idx[@]} != $OSTCOUNT"
1986
1987                 for index in $(seq 0 $((OSTCOUNT - 1))); do
1988                         found=0
1989                         for j in $(echo ${ost_idx[@]}); do
1990                                 if [ $index -eq $j ]; then
1991                                         found=1
1992                                         break
1993                                 fi
1994                         done
1995                         [ $found = 1 ] ||
1996                                 error "Can not find $index in ${ost_idx[@]}"
1997                 done
1998         done
1999 }
2000 run_test 27C "check full striping across all OSTs"
2001
2002 test_27D() {
2003         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2004         local POOL=${POOL:-testpool}
2005         local first_ost=0
2006         local last_ost=$(($OSTCOUNT - 1))
2007         local ost_step=1
2008         local ost_list=$(seq $first_ost $ost_step $last_ost)
2009         local ost_range="$first_ost $last_ost $ost_step"
2010
2011         mkdir -p $DIR/$tdir
2012         pool_add $POOL || error "pool_add failed"
2013         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2014         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT ||
2015                 error "llapi_layout_test failed"
2016         cleanup_pools || error "cleanup_pools failed"
2017 }
2018 run_test 27D "validate llapi_layout API"
2019
2020 # createtest also checks that device nodes are created and
2021 # then visible correctly (#2091)
2022 test_28() { # bug 2091
2023         test_mkdir $DIR/d28
2024         $CREATETEST $DIR/d28/ct || error
2025 }
2026 run_test 28 "create/mknod/mkdir with bad file types ============"
2027
2028 test_29() {
2029         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2030         cancel_lru_locks mdc
2031         test_mkdir $DIR/d29
2032         touch $DIR/d29/foo
2033         log 'first d29'
2034         ls -l $DIR/d29
2035
2036         declare -i LOCKCOUNTORIG=0
2037         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2038                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2039         done
2040         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
2041
2042         declare -i LOCKUNUSEDCOUNTORIG=0
2043         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2044                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2045         done
2046
2047         log 'second d29'
2048         ls -l $DIR/d29
2049         log 'done'
2050
2051         declare -i LOCKCOUNTCURRENT=0
2052         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2053                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2054         done
2055
2056         declare -i LOCKUNUSEDCOUNTCURRENT=0
2057         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2058                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2059         done
2060
2061         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2062                 $LCTL set_param -n ldlm.dump_namespaces ""
2063                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2064                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2065                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2066                 return 2
2067         fi
2068         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2069                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2070                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2071                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2072                 return 3
2073         fi
2074 }
2075 run_test 29 "IT_GETATTR regression  ============================"
2076
2077 test_30a() { # was test_30
2078         cp $(which ls) $DIR || cp /bin/ls $DIR
2079         $DIR/ls / || error
2080         rm $DIR/ls
2081 }
2082 run_test 30a "execute binary from Lustre (execve) =============="
2083
2084 test_30b() {
2085         cp `which ls` $DIR || cp /bin/ls $DIR
2086         chmod go+rx $DIR/ls
2087         $RUNAS $DIR/ls / || error
2088         rm $DIR/ls
2089 }
2090 run_test 30b "execute binary from Lustre as non-root ==========="
2091
2092 test_30c() { # b=22376
2093         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2094         cp `which ls` $DIR || cp /bin/ls $DIR
2095         chmod a-rw $DIR/ls
2096         cancel_lru_locks mdc
2097         cancel_lru_locks osc
2098         $RUNAS $DIR/ls / || error
2099         rm -f $DIR/ls
2100 }
2101 run_test 30c "execute binary from Lustre without read perms ===="
2102
2103 test_31a() {
2104         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2105         $CHECKSTAT -a $DIR/f31 || error
2106 }
2107 run_test 31a "open-unlink file =================================="
2108
2109 test_31b() {
2110         touch $DIR/f31 || error
2111         ln $DIR/f31 $DIR/f31b || error
2112         $MULTIOP $DIR/f31b Ouc || error
2113         $CHECKSTAT -t file $DIR/f31 || error
2114 }
2115 run_test 31b "unlink file with multiple links while open ======="
2116
2117 test_31c() {
2118         touch $DIR/f31 || error
2119         ln $DIR/f31 $DIR/f31c || error
2120         multiop_bg_pause $DIR/f31 O_uc || return 1
2121         MULTIPID=$!
2122         $MULTIOP $DIR/f31c Ouc
2123         kill -USR1 $MULTIPID
2124         wait $MULTIPID
2125 }
2126 run_test 31c "open-unlink file with multiple links ============="
2127
2128 test_31d() {
2129         opendirunlink $DIR/d31d $DIR/d31d || error
2130         $CHECKSTAT -a $DIR/d31d || error
2131 }
2132 run_test 31d "remove of open directory ========================="
2133
2134 test_31e() { # bug 2904
2135         check_kernel_version 34 || return 0
2136         openfilleddirunlink $DIR/d31e || error
2137 }
2138 run_test 31e "remove of open non-empty directory ==============="
2139
2140 test_31f() { # bug 4554
2141         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2142         set -vx
2143         test_mkdir $DIR/d31f
2144         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2145         cp /etc/hosts $DIR/d31f
2146         ls -l $DIR/d31f
2147         $GETSTRIPE $DIR/d31f/hosts
2148         multiop_bg_pause $DIR/d31f D_c || return 1
2149         MULTIPID=$!
2150
2151         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2152         test_mkdir $DIR/d31f
2153         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2154         cp /etc/hosts $DIR/d31f
2155         ls -l $DIR/d31f
2156         $GETSTRIPE $DIR/d31f/hosts
2157         multiop_bg_pause $DIR/d31f D_c || return 1
2158         MULTIPID2=$!
2159
2160         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2161         wait $MULTIPID || error "first opendir $MULTIPID failed"
2162
2163         sleep 6
2164
2165         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2166         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2167         set +vx
2168 }
2169 run_test 31f "remove of open directory with open-unlink file ==="
2170
2171 test_31g() {
2172         echo "-- cross directory link --"
2173         test_mkdir -c1 $DIR/${tdir}ga
2174         test_mkdir -c1 $DIR/${tdir}gb
2175         touch $DIR/${tdir}ga/f
2176         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2177         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2178         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2179         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2180         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2181 }
2182 run_test 31g "cross directory link==============="
2183
2184 test_31h() {
2185         echo "-- cross directory link --"
2186         test_mkdir -c1 $DIR/${tdir}
2187         test_mkdir -c1 $DIR/${tdir}/dir
2188         touch $DIR/${tdir}/f
2189         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2190         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2191         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2192         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2193         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2194 }
2195 run_test 31h "cross directory link under child==============="
2196
2197 test_31i() {
2198         echo "-- cross directory link --"
2199         test_mkdir -c1 $DIR/$tdir
2200         test_mkdir -c1 $DIR/$tdir/dir
2201         touch $DIR/$tdir/dir/f
2202         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2203         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2204         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2205         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2206         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2207 }
2208 run_test 31i "cross directory link under parent==============="
2209
2210 test_31j() {
2211         test_mkdir -c1 -p $DIR/$tdir
2212         test_mkdir -c1 -p $DIR/$tdir/dir1
2213         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2214         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2215         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2216         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2217         return 0
2218 }
2219 run_test 31j "link for directory==============="
2220
2221 test_31k() {
2222         test_mkdir -c1 -p $DIR/$tdir
2223         touch $DIR/$tdir/s
2224         touch $DIR/$tdir/exist
2225         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2226         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2227         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2228         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2229         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2230         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2231         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2232         return 0
2233 }
2234 run_test 31k "link to file: the same, non-existing, dir==============="
2235
2236 test_31m() {
2237         mkdir $DIR/d31m
2238         touch $DIR/d31m/s
2239         mkdir $DIR/d31m2
2240         touch $DIR/d31m2/exist
2241         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2242         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2243         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2244         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2245         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2246         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2247         return 0
2248 }
2249 run_test 31m "link to file: the same, non-existing, dir==============="
2250
2251 test_31n() {
2252         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2253         nlink=$(stat --format=%h $DIR/$tfile)
2254         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2255         local fd=$(free_fd)
2256         local cmd="exec $fd<$DIR/$tfile"
2257         eval $cmd
2258         cmd="exec $fd<&-"
2259         trap "eval $cmd" EXIT
2260         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2261         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2262         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2263         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2264         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2265         eval $cmd
2266 }
2267 run_test 31n "check link count of unlinked file"
2268
2269 link_one() {
2270         local TEMPNAME=$(mktemp $1_XXXXXX)
2271         mlink $TEMPNAME $1 2> /dev/null &&
2272                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2273         munlink $TEMPNAME
2274 }
2275
2276 test_31o() { # LU-2901
2277         mkdir -p $DIR/$tdir
2278         for LOOP in $(seq 100); do
2279                 rm -f $DIR/$tdir/$tfile*
2280                 for THREAD in $(seq 8); do
2281                         link_one $DIR/$tdir/$tfile.$LOOP &
2282                 done
2283                 wait
2284                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2285                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2286                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2287                         break || true
2288         done
2289 }
2290 run_test 31o "duplicate hard links with same filename"
2291
2292 test_31p() {
2293         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2294
2295         mkdir $DIR/$tdir
2296         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2297         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2298
2299         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2300                 error "open unlink test1 failed"
2301         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2302                 error "open unlink test2 failed"
2303
2304         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2305                 error "test1 still exists"
2306         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2307                 error "test2 still exists"
2308 }
2309 run_test 31p "remove of open striped directory"
2310
2311 cleanup_test32_mount() {
2312         trap 0
2313         $UMOUNT -d $DIR/$tdir/ext2-mountpoint
2314 }
2315
2316 test_32a() {
2317         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2318         echo "== more mountpoints and symlinks ================="
2319         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2320         trap cleanup_test32_mount EXIT
2321         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2322         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2323         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2324         cleanup_test32_mount
2325 }
2326 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2327
2328 test_32b() {
2329         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2330         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2331         trap cleanup_test32_mount EXIT
2332         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2333         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2334         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2335         cleanup_test32_mount
2336 }
2337 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2338
2339 test_32c() {
2340         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2341         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2342         trap cleanup_test32_mount EXIT
2343         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2344         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2345         test_mkdir -p $DIR/$tdir/d2/test_dir
2346         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2347         cleanup_test32_mount
2348 }
2349 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2350
2351 test_32d() {
2352         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2353         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2354         trap cleanup_test32_mount EXIT
2355         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2356         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2357         test_mkdir -p $DIR/$tdir/d2/test_dir
2358         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2359         cleanup_test32_mount
2360 }
2361 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2362
2363 test_32e() {
2364         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2365         test_mkdir -p $DIR/d32e/tmp
2366         TMP_DIR=$DIR/d32e/tmp
2367         ln -s $DIR/d32e $TMP_DIR/symlink11
2368         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2369         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2370         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2371 }
2372 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2373
2374 test_32f() {
2375         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2376         test_mkdir -p $DIR/d32f/tmp
2377         TMP_DIR=$DIR/d32f/tmp
2378         ln -s $DIR/d32f $TMP_DIR/symlink11
2379         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2380         ls $DIR/d32f/tmp/symlink11  || error
2381         ls $DIR/d32f/symlink01 || error
2382 }
2383 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2384
2385 test_32g() {
2386         TMP_DIR=$DIR/$tdir/tmp
2387         test_mkdir -p $DIR/$tdir/tmp
2388         test_mkdir $DIR/${tdir}2
2389         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2390         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2391         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2392         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2393         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2394         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2395 }
2396 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2397
2398 test_32h() {
2399         rm -fr $DIR/$tdir $DIR/${tdir}2
2400         TMP_DIR=$DIR/$tdir/tmp
2401         test_mkdir -p $DIR/$tdir/tmp
2402         test_mkdir $DIR/${tdir}2
2403         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2404         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2405         ls $TMP_DIR/symlink12 || error
2406         ls $DIR/$tdir/symlink02  || error
2407 }
2408 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2409
2410 test_32i() {
2411         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2412         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2413         trap cleanup_test32_mount EXIT
2414         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2415         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2416         touch $DIR/$tdir/test_file
2417         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2418         cleanup_test32_mount
2419 }
2420 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2421
2422 test_32j() {
2423         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2424         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2425         trap cleanup_test32_mount EXIT
2426         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2427         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2428         touch $DIR/$tdir/test_file
2429         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2430         cleanup_test32_mount
2431 }
2432 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2433
2434 test_32k() {
2435         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2436         rm -fr $DIR/$tdir
2437         trap cleanup_test32_mount EXIT
2438         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2439         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2440         test_mkdir -p $DIR/$tdir/d2
2441         touch $DIR/$tdir/d2/test_file || error
2442         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2443         cleanup_test32_mount
2444 }
2445 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2446
2447 test_32l() {
2448         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2449         rm -fr $DIR/$tdir
2450         trap cleanup_test32_mount EXIT
2451         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2452         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2453         test_mkdir -p $DIR/$tdir/d2
2454         touch $DIR/$tdir/d2/test_file
2455         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2456         cleanup_test32_mount
2457 }
2458 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2459
2460 test_32m() {
2461         rm -fr $DIR/d32m
2462         test_mkdir -p $DIR/d32m/tmp
2463         TMP_DIR=$DIR/d32m/tmp
2464         ln -s $DIR $TMP_DIR/symlink11
2465         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2466         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2467         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2468 }
2469 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2470
2471 test_32n() {
2472         rm -fr $DIR/d32n
2473         test_mkdir -p $DIR/d32n/tmp
2474         TMP_DIR=$DIR/d32n/tmp
2475         ln -s $DIR $TMP_DIR/symlink11
2476         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2477         ls -l $DIR/d32n/tmp/symlink11  || error
2478         ls -l $DIR/d32n/symlink01 || error
2479 }
2480 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2481
2482 test_32o() {
2483         touch $DIR/$tfile
2484         test_mkdir -p $DIR/d32o/tmp
2485         TMP_DIR=$DIR/d32o/tmp
2486         ln -s $DIR/$tfile $TMP_DIR/symlink12
2487         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2488         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2489         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2490         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2491         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2492 }
2493 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2494
2495 test_32p() {
2496     log 32p_1
2497         rm -fr $DIR/d32p
2498     log 32p_2
2499         rm -f $DIR/$tfile
2500     log 32p_3
2501         touch $DIR/$tfile
2502     log 32p_4
2503         test_mkdir -p $DIR/d32p/tmp
2504     log 32p_5
2505         TMP_DIR=$DIR/d32p/tmp
2506     log 32p_6
2507         ln -s $DIR/$tfile $TMP_DIR/symlink12
2508     log 32p_7
2509         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2510     log 32p_8
2511         cat $DIR/d32p/tmp/symlink12 || error
2512     log 32p_9
2513         cat $DIR/d32p/symlink02 || error
2514     log 32p_10
2515 }
2516 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2517
2518 cleanup_testdir_mount() {
2519         trap 0
2520         $UMOUNT -d $DIR/$tdir
2521 }
2522
2523 test_32q() {
2524         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2525         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2526         trap cleanup_testdir_mount EXIT
2527         test_mkdir -p $DIR/$tdir
2528         touch $DIR/$tdir/under_the_mount
2529         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2530         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2531         cleanup_testdir_mount
2532 }
2533 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2534
2535 test_32r() {
2536         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2537         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2538         trap cleanup_testdir_mount EXIT
2539         test_mkdir -p $DIR/$tdir
2540         touch $DIR/$tdir/under_the_mount
2541         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2542         ls $DIR/$tdir | grep -q under_the_mount && error || true
2543         cleanup_testdir_mount
2544 }
2545 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2546
2547 test_33aa() {
2548         rm -f $DIR/$tfile
2549         touch $DIR/$tfile
2550         chmod 444 $DIR/$tfile
2551         chown $RUNAS_ID $DIR/$tfile
2552         log 33_1
2553         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2554         log 33_2
2555 }
2556 run_test 33aa "write file with mode 444 (should return error) ===="
2557
2558 test_33a() {
2559         rm -fr $DIR/d33
2560         test_mkdir -p $DIR/d33
2561         chown $RUNAS_ID $DIR/d33
2562         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2563         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2564                 error "open RDWR" || true
2565 }
2566 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2567
2568 test_33b() {
2569         rm -fr $DIR/d33
2570         test_mkdir -p $DIR/d33
2571         chown $RUNAS_ID $DIR/d33
2572         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33
2573 }
2574 run_test 33b "test open file with malformed flags (No panic)"
2575
2576 test_33c() {
2577         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2578         local ostnum
2579         local ostname
2580         local write_bytes
2581         local all_zeros
2582
2583         remote_ost_nodsh && skip "remote OST with nodsh" && return
2584         all_zeros=:
2585         rm -fr $DIR/d33
2586         test_mkdir -p $DIR/d33
2587         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2588
2589         sync
2590         for ostnum in $(seq $OSTCOUNT); do
2591                 # test-framework's OST numbering is one-based, while Lustre's
2592                 # is zero-based
2593                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2594                 # Parsing llobdstat's output sucks; we could grep the /proc
2595                 # path, but that's likely to not be as portable as using the
2596                 # llobdstat utility.  So we parse lctl output instead.
2597                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2598                         obdfilter/$ostname/stats |
2599                         awk '/^write_bytes/ {print $7}' )
2600                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2601                 if (( ${write_bytes:-0} > 0 ))
2602                 then
2603                         all_zeros=false
2604                         break;
2605                 fi
2606         done
2607
2608         $all_zeros || return 0
2609
2610         # Write four bytes
2611         echo foo > $DIR/d33/bar
2612         # Really write them
2613         sync
2614
2615         # Total up write_bytes after writing.  We'd better find non-zeros.
2616         for ostnum in $(seq $OSTCOUNT); do
2617                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2618                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2619                         obdfilter/$ostname/stats |
2620                         awk '/^write_bytes/ {print $7}' )
2621                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2622                 if (( ${write_bytes:-0} > 0 ))
2623                 then
2624                         all_zeros=false
2625                         break;
2626                 fi
2627         done
2628
2629         if $all_zeros
2630         then
2631                 for ostnum in $(seq $OSTCOUNT); do
2632                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2633                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2634                         do_facet ost$ostnum lctl get_param -n \
2635                                 obdfilter/$ostname/stats
2636                 done
2637                 error "OST not keeping write_bytes stats (b22312)"
2638         fi
2639 }
2640 run_test 33c "test llobdstat and write_bytes"
2641
2642 test_33d() {
2643         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2644         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2645         local MDTIDX=1
2646         local remote_dir=$DIR/$tdir/remote_dir
2647
2648         mkdir -p $DIR/$tdir
2649         $LFS mkdir -i $MDTIDX $remote_dir ||
2650                 error "create remote directory failed"
2651
2652         touch $remote_dir/$tfile
2653         chmod 444 $remote_dir/$tfile
2654         chown $RUNAS_ID $remote_dir/$tfile
2655
2656         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2657
2658         chown $RUNAS_ID $remote_dir
2659         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2660                                         error "create" || true
2661         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2662                                     error "open RDWR" || true
2663         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2664                                     error "create" || true
2665 }
2666 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2667
2668 test_33e() {
2669         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2670
2671         mkdir $DIR/$tdir
2672
2673         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2674         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2675         mkdir $DIR/$tdir/local_dir
2676
2677         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2678         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2679         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2680
2681         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2682                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2683
2684         rmdir $DIR/$tdir/* || error "rmdir failed"
2685
2686         umask 777
2687         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2688         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2689         mkdir $DIR/$tdir/local_dir
2690
2691         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2692         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2693         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2694
2695         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2696                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2697
2698         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2699
2700         umask 000
2701         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2702         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2703         mkdir $DIR/$tdir/local_dir
2704
2705         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2706         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2707         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2708
2709         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2710                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2711 }
2712 run_test 33e "mkdir and striped directory should have same mode"
2713
2714 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2715 test_34a() {
2716         rm -f $DIR/f34
2717         $MCREATE $DIR/f34 || error
2718         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2719         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2720         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2721         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2722 }
2723 run_test 34a "truncate file that has not been opened ==========="
2724
2725 test_34b() {
2726         [ ! -f $DIR/f34 ] && test_34a
2727         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2728         $OPENFILE -f O_RDONLY $DIR/f34
2729         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2730         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2731 }
2732 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2733
2734 test_34c() {
2735         [ ! -f $DIR/f34 ] && test_34a
2736         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2737         $OPENFILE -f O_RDWR $DIR/f34
2738         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2739         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2740 }
2741 run_test 34c "O_RDWR opening file-with-size works =============="
2742
2743 test_34d() {
2744         [ ! -f $DIR/f34 ] && test_34a
2745         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2746         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2747         rm $DIR/f34
2748 }
2749 run_test 34d "write to sparse file ============================="
2750
2751 test_34e() {
2752         rm -f $DIR/f34e
2753         $MCREATE $DIR/f34e || error
2754         $TRUNCATE $DIR/f34e 1000 || error
2755         $CHECKSTAT -s 1000 $DIR/f34e || error
2756         $OPENFILE -f O_RDWR $DIR/f34e
2757         $CHECKSTAT -s 1000 $DIR/f34e || error
2758 }
2759 run_test 34e "create objects, some with size and some without =="
2760
2761 test_34f() { # bug 6242, 6243
2762         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2763         SIZE34F=48000
2764         rm -f $DIR/f34f
2765         $MCREATE $DIR/f34f || error
2766         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2767         dd if=$DIR/f34f of=$TMP/f34f
2768         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2769         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2770         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2771         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2772         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2773 }
2774 run_test 34f "read from a file with no objects until EOF ======="
2775
2776 test_34g() {
2777         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2778         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2779         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2780         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2781         cancel_lru_locks osc
2782         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2783                 error "wrong size after lock cancel"
2784
2785         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2786         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2787                 error "expanding truncate failed"
2788         cancel_lru_locks osc
2789         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2790                 error "wrong expanded size after lock cancel"
2791 }
2792 run_test 34g "truncate long file ==============================="
2793
2794 test_34h() {
2795         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2796         local gid=10
2797         local sz=1000
2798
2799         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2800         sync # Flush the cache so that multiop below does not block on cache
2801              # flush when getting the group lock
2802         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2803         MULTIPID=$!
2804
2805         # Since just timed wait is not good enough, let's do a sync write
2806         # that way we are sure enough time for a roundtrip + processing
2807         # passed + 2 seconds of extra margin.
2808         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2809         rm $DIR/${tfile}-1
2810         sleep 2
2811
2812         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2813                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2814                 kill -9 $MULTIPID
2815         fi
2816         wait $MULTIPID
2817         local nsz=`stat -c %s $DIR/$tfile`
2818         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2819 }
2820 run_test 34h "ftruncate file under grouplock should not block"
2821
2822 test_35a() {
2823         cp /bin/sh $DIR/f35a
2824         chmod 444 $DIR/f35a
2825         chown $RUNAS_ID $DIR/f35a
2826         $RUNAS $DIR/f35a && error || true
2827         rm $DIR/f35a
2828 }
2829 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2830
2831 test_36a() {
2832         rm -f $DIR/f36
2833         utime $DIR/f36 || error
2834 }
2835 run_test 36a "MDS utime check (mknod, utime) ==================="
2836
2837 test_36b() {
2838         echo "" > $DIR/f36
2839         utime $DIR/f36 || error
2840 }
2841 run_test 36b "OST utime check (open, utime) ===================="
2842
2843 test_36c() {
2844         rm -f $DIR/d36/f36
2845         test_mkdir $DIR/d36
2846         chown $RUNAS_ID $DIR/d36
2847         $RUNAS utime $DIR/d36/f36 || error
2848 }
2849 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2850
2851 test_36d() {
2852         [ ! -d $DIR/d36 ] && test_36c
2853         echo "" > $DIR/d36/f36
2854         $RUNAS utime $DIR/d36/f36 || error
2855 }
2856 run_test 36d "non-root OST utime check (open, utime) ==========="
2857
2858 test_36e() {
2859         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2860         test_mkdir -p $DIR/$tdir
2861         touch $DIR/$tdir/$tfile
2862         $RUNAS utime $DIR/$tdir/$tfile && \
2863                 error "utime worked, expected failure" || true
2864 }
2865 run_test 36e "utime on non-owned file (should return error) ===="
2866
2867 subr_36fh() {
2868         local fl="$1"
2869         local LANG_SAVE=$LANG
2870         local LC_LANG_SAVE=$LC_LANG
2871         export LANG=C LC_LANG=C # for date language
2872
2873         DATESTR="Dec 20  2000"
2874         test_mkdir -p $DIR/$tdir
2875         lctl set_param fail_loc=$fl
2876         date; date +%s
2877         cp /etc/hosts $DIR/$tdir/$tfile
2878         sync & # write RPC generated with "current" inode timestamp, but delayed
2879         sleep 1
2880         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2881         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2882         cancel_lru_locks osc
2883         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2884         date; date +%s
2885         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2886                 echo "BEFORE: $LS_BEFORE" && \
2887                 echo "AFTER : $LS_AFTER" && \
2888                 echo "WANT  : $DATESTR" && \
2889                 error "$DIR/$tdir/$tfile timestamps changed" || true
2890
2891         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2892 }
2893
2894 test_36f() {
2895         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2896         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2897         subr_36fh "0x80000214"
2898 }
2899 run_test 36f "utime on file racing with OST BRW write =========="
2900
2901 test_36g() {
2902         remote_ost_nodsh && skip "remote OST with nodsh" && return
2903         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2904         local fmd_max_age
2905         local fmd_before
2906         local fmd_after
2907
2908         test_mkdir -p $DIR/$tdir
2909         fmd_max_age=$(do_facet ost1 \
2910                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2911                 head -n 1")
2912
2913         fmd_before=$(do_facet ost1 \
2914                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2915         touch $DIR/$tdir/$tfile
2916         sleep $((fmd_max_age + 12))
2917         fmd_after=$(do_facet ost1 \
2918                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2919
2920         echo "fmd_before: $fmd_before"
2921         echo "fmd_after: $fmd_after"
2922         [[ $fmd_after -gt $fmd_before ]] &&
2923                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
2924                 error "fmd didn't expire after ping" || true
2925 }
2926 run_test 36g "filter mod data cache expiry ====================="
2927
2928 test_36h() {
2929         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2930         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2931         subr_36fh "0x80000227"
2932 }
2933 run_test 36h "utime on file racing with OST BRW write =========="
2934
2935 test_36i() {
2936         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2937
2938         mkdir $DIR/$tdir
2939         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
2940
2941         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
2942         local new_mtime=$((mtime + 200))
2943
2944         #change Modify time of striped dir
2945         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
2946                         error "change mtime failed"
2947
2948         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
2949
2950         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
2951 }
2952 run_test 36i "change mtime on striped directory"
2953
2954 # test_37 - duplicate with tests 32q 32r
2955
2956 test_38() {
2957         local file=$DIR/$tfile
2958         touch $file
2959         openfile -f O_DIRECTORY $file
2960         local RC=$?
2961         local ENOTDIR=20
2962         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2963         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2964 }
2965 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2966
2967 test_39() {
2968         touch $DIR/$tfile
2969         touch $DIR/${tfile}2
2970 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2971 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2972 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2973         sleep 2
2974         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2975         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2976                 echo "mtime"
2977                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2978                 echo "atime"
2979                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2980                 echo "ctime"
2981                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2982                 error "O_TRUNC didn't change timestamps"
2983         fi
2984 }
2985 run_test 39 "mtime changed on create ==========================="
2986
2987 test_39b() {
2988         test_mkdir -p -c1 $DIR/$tdir
2989         cp -p /etc/passwd $DIR/$tdir/fopen
2990         cp -p /etc/passwd $DIR/$tdir/flink
2991         cp -p /etc/passwd $DIR/$tdir/funlink
2992         cp -p /etc/passwd $DIR/$tdir/frename
2993         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2994
2995         sleep 1
2996         echo "aaaaaa" >> $DIR/$tdir/fopen
2997         echo "aaaaaa" >> $DIR/$tdir/flink
2998         echo "aaaaaa" >> $DIR/$tdir/funlink
2999         echo "aaaaaa" >> $DIR/$tdir/frename
3000
3001         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3002         local link_new=`stat -c %Y $DIR/$tdir/flink`
3003         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3004         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3005
3006         cat $DIR/$tdir/fopen > /dev/null
3007         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3008         rm -f $DIR/$tdir/funlink2
3009         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3010
3011         for (( i=0; i < 2; i++ )) ; do
3012                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3013                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3014                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3015                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3016
3017                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3018                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3019                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3020                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3021
3022                 cancel_lru_locks osc
3023                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3024         done
3025 }
3026 run_test 39b "mtime change on open, link, unlink, rename  ======"
3027
3028 # this should be set to past
3029 TEST_39_MTIME=`date -d "1 year ago" +%s`
3030
3031 # bug 11063
3032 test_39c() {
3033         touch $DIR1/$tfile
3034         sleep 2
3035         local mtime0=`stat -c %Y $DIR1/$tfile`
3036
3037         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3038         local mtime1=`stat -c %Y $DIR1/$tfile`
3039         [ "$mtime1" = $TEST_39_MTIME ] || \
3040                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3041
3042         local d1=`date +%s`
3043         echo hello >> $DIR1/$tfile
3044         local d2=`date +%s`
3045         local mtime2=`stat -c %Y $DIR1/$tfile`
3046         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3047                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3048
3049         mv $DIR1/$tfile $DIR1/$tfile-1
3050
3051         for (( i=0; i < 2; i++ )) ; do
3052                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3053                 [ "$mtime2" = "$mtime3" ] || \
3054                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3055
3056                 cancel_lru_locks osc
3057                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3058         done
3059 }
3060 run_test 39c "mtime change on rename ==========================="
3061
3062 # bug 21114
3063 test_39d() {
3064         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3065         touch $DIR1/$tfile
3066
3067         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3068
3069         for (( i=0; i < 2; i++ )) ; do
3070                 local mtime=`stat -c %Y $DIR1/$tfile`
3071                 [ $mtime = $TEST_39_MTIME ] || \
3072                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3073
3074                 cancel_lru_locks osc
3075                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3076         done
3077 }
3078 run_test 39d "create, utime, stat =============================="
3079
3080 # bug 21114
3081 test_39e() {
3082         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3083         touch $DIR1/$tfile
3084         local mtime1=`stat -c %Y $DIR1/$tfile`
3085
3086         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3087
3088         for (( i=0; i < 2; i++ )) ; do
3089                 local mtime2=`stat -c %Y $DIR1/$tfile`
3090                 [ $mtime2 = $TEST_39_MTIME ] || \
3091                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3092
3093                 cancel_lru_locks osc
3094                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3095         done
3096 }
3097 run_test 39e "create, stat, utime, stat ========================"
3098
3099 # bug 21114
3100 test_39f() {
3101         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3102         touch $DIR1/$tfile
3103         mtime1=`stat -c %Y $DIR1/$tfile`
3104
3105         sleep 2
3106         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3107
3108         for (( i=0; i < 2; i++ )) ; do
3109                 local mtime2=`stat -c %Y $DIR1/$tfile`
3110                 [ $mtime2 = $TEST_39_MTIME ] || \
3111                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3112
3113                 cancel_lru_locks osc
3114                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3115         done
3116 }
3117 run_test 39f "create, stat, sleep, utime, stat ================="
3118
3119 # bug 11063
3120 test_39g() {
3121         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3122         echo hello >> $DIR1/$tfile
3123         local mtime1=`stat -c %Y $DIR1/$tfile`
3124
3125         sleep 2
3126         chmod o+r $DIR1/$tfile
3127
3128         for (( i=0; i < 2; i++ )) ; do
3129                 local mtime2=`stat -c %Y $DIR1/$tfile`
3130                 [ "$mtime1" = "$mtime2" ] || \
3131                         error "lost mtime: $mtime2, should be $mtime1"
3132
3133                 cancel_lru_locks osc
3134                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3135         done
3136 }
3137 run_test 39g "write, chmod, stat ==============================="
3138
3139 # bug 11063
3140 test_39h() {
3141         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3142         touch $DIR1/$tfile
3143         sleep 1
3144
3145         local d1=`date`
3146         echo hello >> $DIR1/$tfile
3147         local mtime1=`stat -c %Y $DIR1/$tfile`
3148
3149         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3150         local d2=`date`
3151         if [ "$d1" != "$d2" ]; then
3152                 echo "write and touch not within one second"
3153         else
3154                 for (( i=0; i < 2; i++ )) ; do
3155                         local mtime2=`stat -c %Y $DIR1/$tfile`
3156                         [ "$mtime2" = $TEST_39_MTIME ] || \
3157                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3158
3159                         cancel_lru_locks osc
3160                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3161                 done
3162         fi
3163 }
3164 run_test 39h "write, utime within one second, stat ============="
3165
3166 test_39i() {
3167         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3168         touch $DIR1/$tfile
3169         sleep 1
3170
3171         echo hello >> $DIR1/$tfile
3172         local mtime1=`stat -c %Y $DIR1/$tfile`
3173
3174         mv $DIR1/$tfile $DIR1/$tfile-1
3175
3176         for (( i=0; i < 2; i++ )) ; do
3177                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3178
3179                 [ "$mtime1" = "$mtime2" ] || \
3180                         error "lost mtime: $mtime2, should be $mtime1"
3181
3182                 cancel_lru_locks osc
3183                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3184         done
3185 }
3186 run_test 39i "write, rename, stat =============================="
3187
3188 test_39j() {
3189         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3190         start_full_debug_logging
3191         touch $DIR1/$tfile
3192         sleep 1
3193
3194         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3195         lctl set_param fail_loc=0x80000412
3196         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3197                 error "multiop failed"
3198         local multipid=$!
3199         local mtime1=`stat -c %Y $DIR1/$tfile`
3200
3201         mv $DIR1/$tfile $DIR1/$tfile-1
3202
3203         kill -USR1 $multipid
3204         wait $multipid || error "multiop close failed"
3205
3206         for (( i=0; i < 2; i++ )) ; do
3207                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3208                 [ "$mtime1" = "$mtime2" ] ||
3209                         error "mtime is lost on close: $mtime2, " \
3210                               "should be $mtime1"
3211
3212                 cancel_lru_locks osc
3213                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3214         done
3215         lctl set_param fail_loc=0
3216         stop_full_debug_logging
3217 }
3218 run_test 39j "write, rename, close, stat ======================="
3219
3220 test_39k() {
3221         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3222         touch $DIR1/$tfile
3223         sleep 1
3224
3225         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3226         local multipid=$!
3227         local mtime1=`stat -c %Y $DIR1/$tfile`
3228
3229         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3230
3231         kill -USR1 $multipid
3232         wait $multipid || error "multiop close failed"
3233
3234         for (( i=0; i < 2; i++ )) ; do
3235                 local mtime2=`stat -c %Y $DIR1/$tfile`
3236
3237                 [ "$mtime2" = $TEST_39_MTIME ] || \
3238                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3239
3240                 cancel_lru_locks osc
3241                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3242         done
3243 }
3244 run_test 39k "write, utime, close, stat ========================"
3245
3246 # this should be set to future
3247 TEST_39_ATIME=`date -d "1 year" +%s`
3248
3249 test_39l() {
3250         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3251         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3252         local atime_diff=$(do_facet $SINGLEMDS \
3253                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3254         rm -rf $DIR/$tdir
3255         mkdir -p $DIR/$tdir
3256
3257         # test setting directory atime to future
3258         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3259         local atime=$(stat -c %X $DIR/$tdir)
3260         [ "$atime" = $TEST_39_ATIME ] || \
3261                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3262
3263         # test setting directory atime from future to now
3264         local d1=$(date +%s)
3265         ls $DIR/$tdir
3266         local d2=$(date +%s)
3267
3268         cancel_lru_locks mdc
3269         atime=$(stat -c %X $DIR/$tdir)
3270         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3271                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3272
3273         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3274         sleep 3
3275
3276         # test setting directory atime when now > dir atime + atime_diff
3277         d1=$(date +%s)
3278         ls $DIR/$tdir
3279         d2=$(date +%s)
3280         cancel_lru_locks mdc
3281         atime=$(stat -c %X $DIR/$tdir)
3282         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3283                 error "atime is not updated  : $atime, should be $d2"
3284
3285         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3286         sleep 3
3287
3288         # test not setting directory atime when now < dir atime + atime_diff
3289         ls $DIR/$tdir
3290         cancel_lru_locks mdc
3291         atime=$(stat -c %X $DIR/$tdir)
3292         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3293                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3294
3295         do_facet $SINGLEMDS \
3296                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3297 }
3298 run_test 39l "directory atime update ==========================="
3299
3300 test_39m() {
3301         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3302         touch $DIR1/$tfile
3303         sleep 2
3304         local far_past_mtime=$(date -d "May 29 1953" +%s)
3305         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3306
3307         touch -m -d @$far_past_mtime $DIR1/$tfile
3308         touch -a -d @$far_past_atime $DIR1/$tfile
3309
3310         for (( i=0; i < 2; i++ )) ; do
3311                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3312                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3313                         error "atime or mtime set incorrectly"
3314
3315                 cancel_lru_locks osc
3316                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3317         done
3318 }
3319 run_test 39m "test atime and mtime before 1970"
3320
3321 test_39n() { # LU-3832
3322         local atime_diff=$(do_facet $SINGLEMDS \
3323                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3324         local atime0
3325         local atime1
3326         local atime2
3327
3328         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3329
3330         rm -rf $DIR/$tfile
3331         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3332         atime0=$(stat -c %X $DIR/$tfile)
3333
3334         sleep 5
3335         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3336         atime1=$(stat -c %X $DIR/$tfile)
3337
3338         sleep 5
3339         cancel_lru_locks mdc
3340         cancel_lru_locks osc
3341         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3342         atime2=$(stat -c %X $DIR/$tfile)
3343
3344         do_facet $SINGLEMDS \
3345                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3346
3347         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3348         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3349 }
3350 run_test 39n "check that O_NOATIME is honored"
3351
3352 test_39o() {
3353         TESTDIR=$DIR/$tdir/$tfile
3354         [ -e $TESTDIR ] && rm -rf $TESTDIR
3355         test_mkdir -p $TESTDIR
3356         cd $TESTDIR
3357         links1=2
3358         ls
3359         mkdir a b
3360         ls
3361         links2=$(stat -c %h .)
3362         [ $(($links1 + 2)) != $links2 ] &&
3363                 error "wrong links count $(($links1 + 2)) != $links2"
3364         rmdir b
3365         links3=$(stat -c %h .)
3366         [ $(($links1 + 1)) != $links3 ] &&
3367                 error "wrong links count $links1 != $links3"
3368         return 0
3369 }
3370 run_test 39o "directory cached attributes updated after create ========"
3371
3372 test_39p() {
3373         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3374         local MDTIDX=1
3375         TESTDIR=$DIR/$tdir/$tfile
3376         [ -e $TESTDIR ] && rm -rf $TESTDIR
3377         mkdir -p $TESTDIR
3378         cd $TESTDIR
3379         links1=2
3380         ls
3381         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3382         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3383         ls
3384         links2=$(stat -c %h .)
3385         [ $(($links1 + 2)) != $links2 ] &&
3386                 error "wrong links count $(($links1 + 2)) != $links2"
3387         rmdir remote_dir2
3388         links3=$(stat -c %h .)
3389         [ $(($links1 + 1)) != $links3 ] &&
3390                 error "wrong links count $links1 != $links3"
3391         return 0
3392 }
3393 run_test 39p "remote directory cached attributes updated after create ========"
3394
3395
3396 test_40() {
3397         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3398         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3399                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3400         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3401                 error "$tfile is not 4096 bytes in size"
3402 }
3403 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3404
3405 test_41() {
3406         # bug 1553
3407         small_write $DIR/f41 18
3408 }
3409 run_test 41 "test small file write + fstat ====================="
3410
3411 count_ost_writes() {
3412         lctl get_param -n osc.*.stats |
3413                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3414                         END { printf("%0.0f", writes) }'
3415 }
3416
3417 # decent default
3418 WRITEBACK_SAVE=500
3419 DIRTY_RATIO_SAVE=40
3420 MAX_DIRTY_RATIO=50
3421 BG_DIRTY_RATIO_SAVE=10
3422 MAX_BG_DIRTY_RATIO=25
3423
3424 start_writeback() {
3425         trap 0
3426         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3427         # dirty_ratio, dirty_background_ratio
3428         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3429                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3430                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3431                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3432         else
3433                 # if file not here, we are a 2.4 kernel
3434                 kill -CONT `pidof kupdated`
3435         fi
3436 }
3437
3438 stop_writeback() {
3439         # setup the trap first, so someone cannot exit the test at the
3440         # exact wrong time and mess up a machine
3441         trap start_writeback EXIT
3442         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3443         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3444                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3445                 sysctl -w vm.dirty_writeback_centisecs=0
3446                 sysctl -w vm.dirty_writeback_centisecs=0
3447                 # save and increase /proc/sys/vm/dirty_ratio
3448                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3449                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3450                 # save and increase /proc/sys/vm/dirty_background_ratio
3451                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3452                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3453         else
3454                 # if file not here, we are a 2.4 kernel
3455                 kill -STOP `pidof kupdated`
3456         fi
3457 }
3458
3459 # ensure that all stripes have some grant before we test client-side cache
3460 setup_test42() {
3461         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3462                 dd if=/dev/zero of=$i bs=4k count=1
3463                 rm $i
3464         done
3465 }
3466
3467 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3468 # file truncation, and file removal.
3469 test_42a() {
3470         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3471         setup_test42
3472         cancel_lru_locks osc
3473         stop_writeback
3474         sync; sleep 1; sync # just to be safe
3475         BEFOREWRITES=`count_ost_writes`
3476         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3477         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3478         AFTERWRITES=`count_ost_writes`
3479         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3480                 error "$BEFOREWRITES < $AFTERWRITES"
3481         start_writeback
3482 }
3483 run_test 42a "ensure that we don't flush on close =============="
3484
3485 test_42b() {
3486         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3487         setup_test42
3488         cancel_lru_locks osc
3489         stop_writeback
3490         sync
3491         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3492         BEFOREWRITES=$(count_ost_writes)
3493         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3494         AFTERWRITES=$(count_ost_writes)
3495         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3496                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3497         fi
3498         BEFOREWRITES=$(count_ost_writes)
3499         sync || error "sync: $?"
3500         AFTERWRITES=$(count_ost_writes)
3501         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3502                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3503         fi
3504         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3505         start_writeback
3506         return 0
3507 }
3508 run_test 42b "test destroy of file with cached dirty data ======"
3509
3510 # if these tests just want to test the effect of truncation,
3511 # they have to be very careful.  consider:
3512 # - the first open gets a {0,EOF}PR lock
3513 # - the first write conflicts and gets a {0, count-1}PW
3514 # - the rest of the writes are under {count,EOF}PW
3515 # - the open for truncate tries to match a {0,EOF}PR
3516 #   for the filesize and cancels the PWs.
3517 # any number of fixes (don't get {0,EOF} on open, match
3518 # composite locks, do smarter file size management) fix
3519 # this, but for now we want these tests to verify that
3520 # the cancellation with truncate intent works, so we
3521 # start the file with a full-file pw lock to match against
3522 # until the truncate.
3523 trunc_test() {
3524         test=$1
3525         file=$DIR/$test
3526         offset=$2
3527         cancel_lru_locks osc
3528         stop_writeback
3529         # prime the file with 0,EOF PW to match
3530         touch $file
3531         $TRUNCATE $file 0
3532         sync; sync
3533         # now the real test..
3534         dd if=/dev/zero of=$file bs=1024 count=100
3535         BEFOREWRITES=`count_ost_writes`
3536         $TRUNCATE $file $offset
3537         cancel_lru_locks osc
3538         AFTERWRITES=`count_ost_writes`
3539         start_writeback
3540 }
3541
3542 test_42c() {
3543         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3544         trunc_test 42c 1024
3545         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3546             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3547         rm $file
3548 }
3549 run_test 42c "test partial truncate of file with cached dirty data"
3550
3551 test_42d() {
3552         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3553         trunc_test 42d 0
3554         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3555             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3556         rm $file
3557 }
3558 run_test 42d "test complete truncate of file with cached dirty data"
3559
3560 test_42e() { # bug22074
3561         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3562         local TDIR=$DIR/${tdir}e
3563         local pagesz=$(page_size)
3564         local pages=16 # hardcoded 16 pages, don't change it.
3565         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3566         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3567         local max_dirty_mb
3568         local warmup_files
3569
3570         test_mkdir -p $DIR/${tdir}e
3571         $SETSTRIPE -c 1 $TDIR
3572         createmany -o $TDIR/f $files
3573
3574         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3575
3576         # we assume that with $OSTCOUNT files, at least one of them will
3577         # be allocated on OST0.
3578         warmup_files=$((OSTCOUNT * max_dirty_mb))
3579         createmany -o $TDIR/w $warmup_files
3580
3581         # write a large amount of data into one file and sync, to get good
3582         # avail_grant number from OST.
3583         for ((i=0; i<$warmup_files; i++)); do
3584                 idx=$($GETSTRIPE -i $TDIR/w$i)
3585                 [ $idx -ne 0 ] && continue
3586                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3587                 break
3588         done
3589         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3590         sync
3591         $LCTL get_param $proc_osc0/cur_dirty_bytes
3592         $LCTL get_param $proc_osc0/cur_grant_bytes
3593
3594         # create as much dirty pages as we can while not to trigger the actual
3595         # RPCs directly. but depends on the env, VFS may trigger flush during this
3596         # period, hopefully we are good.
3597         for ((i=0; i<$warmup_files; i++)); do
3598                 idx=$($GETSTRIPE -i $TDIR/w$i)
3599                 [ $idx -ne 0 ] && continue
3600                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3601         done
3602         $LCTL get_param $proc_osc0/cur_dirty_bytes
3603         $LCTL get_param $proc_osc0/cur_grant_bytes
3604
3605         # perform the real test
3606         $LCTL set_param $proc_osc0/rpc_stats 0
3607         for ((;i<$files; i++)); do
3608                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3609                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3610         done
3611         sync
3612         $LCTL get_param $proc_osc0/rpc_stats
3613
3614         local percent=0
3615         local have_ppr=false
3616         $LCTL get_param $proc_osc0/rpc_stats |
3617                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3618                         # skip lines until we are at the RPC histogram data
3619                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3620                         $have_ppr || continue
3621
3622                         # we only want the percent stat for < 16 pages
3623                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3624
3625                         percent=$((percent + WPCT))
3626                         if [[ $percent -gt 15 ]]; then
3627                                 error "less than 16-pages write RPCs" \
3628                                       "$percent% > 15%"
3629                                 break
3630                         fi
3631                 done
3632         rm -rf $TDIR
3633 }
3634 run_test 42e "verify sub-RPC writes are not done synchronously"
3635
3636 test_43() {
3637         test_mkdir -p $DIR/$tdir
3638         cp -p /bin/ls $DIR/$tdir/$tfile
3639         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3640         pid=$!
3641         # give multiop a chance to open
3642         sleep 1
3643
3644         $DIR/$tdir/$tfile && error || true
3645         kill -USR1 $pid
3646 }
3647 run_test 43 "execution of file opened for write should return -ETXTBSY"
3648
3649 test_43a() {
3650         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3651         test_mkdir -p $DIR/$tdir
3652         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3653                         cp -p multiop $DIR/$tdir/multiop
3654         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3655                         return 1
3656         MULTIOP_PID=$!
3657         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3658         kill -USR1 $MULTIOP_PID || return 2
3659         wait $MULTIOP_PID || return 3
3660         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3661 }
3662 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3663
3664 test_43b() {
3665         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3666         test_mkdir -p $DIR/$tdir
3667         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3668                         cp -p multiop $DIR/$tdir/multiop
3669         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3670                         return 1
3671         MULTIOP_PID=$!
3672         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3673         kill -USR1 $MULTIOP_PID || return 2
3674         wait $MULTIOP_PID || return 3
3675         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3676 }
3677 run_test 43b "truncate of file being executed should return -ETXTBSY"
3678
3679 test_43c() {
3680         local testdir="$DIR/$tdir"
3681         test_mkdir -p $DIR/$tdir
3682         cp $SHELL $testdir/
3683         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3684                 ( cd $testdir && md5sum -c)
3685 }
3686 run_test 43c "md5sum of copy into lustre========================"
3687
3688 test_44() {
3689         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3690         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3691         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3692 }
3693 run_test 44 "zero length read from a sparse stripe ============="
3694
3695 test_44a() {
3696         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3697                 awk '{ print $2 }')
3698         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3699         [[ $nstripe -gt $OSTCOUNT ]] &&
3700             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3701             return
3702         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3703                 awk '{ print $2 }')
3704         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3705                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3706                         awk '{ print $2 }')
3707         fi
3708
3709         OFFSETS="0 $((stride/2)) $((stride-1))"
3710         for offset in $OFFSETS; do
3711                 for i in $(seq 0 $((nstripe-1))); do
3712                         local GLOBALOFFSETS=""
3713                         # size in Bytes
3714                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3715                         local myfn=$DIR/d44a-$size
3716                         echo "--------writing $myfn at $size"
3717                         ll_sparseness_write $myfn $size ||
3718                                 error "ll_sparseness_write"
3719                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3720                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3721                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3722
3723                         for j in $(seq 0 $((nstripe-1))); do
3724                                 # size in Bytes
3725                                 size=$((((j + $nstripe )*$stride + $offset)))
3726                                 ll_sparseness_write $myfn $size ||
3727                                         error "ll_sparseness_write"
3728                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3729                         done
3730                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3731                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3732                         rm -f $myfn
3733                 done
3734         done
3735 }
3736 run_test 44a "test sparse pwrite ==============================="
3737
3738 dirty_osc_total() {
3739         tot=0
3740         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3741                 tot=$(($tot + $d))
3742         done
3743         echo $tot
3744 }
3745 do_dirty_record() {
3746         before=`dirty_osc_total`
3747         echo executing "\"$*\""
3748         eval $*
3749         after=`dirty_osc_total`
3750         echo before $before, after $after
3751 }
3752 test_45() {
3753         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3754         f="$DIR/f45"
3755         # Obtain grants from OST if it supports it
3756         echo blah > ${f}_grant
3757         stop_writeback
3758         sync
3759         do_dirty_record "echo blah > $f"
3760         [[ $before -eq $after ]] && error "write wasn't cached"
3761         do_dirty_record "> $f"
3762         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3763         do_dirty_record "echo blah > $f"
3764         [[ $before -eq $after ]] && error "write wasn't cached"
3765         do_dirty_record "sync"
3766         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3767         do_dirty_record "echo blah > $f"
3768         [[ $before -eq $after ]] && error "write wasn't cached"
3769         do_dirty_record "cancel_lru_locks osc"
3770         [[ $before -gt $after ]] ||
3771                 error "lock cancellation didn't lower dirty count"
3772         start_writeback
3773 }
3774 run_test 45 "osc io page accounting ============================"
3775
3776 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3777 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3778 # objects offset and an assert hit when an rpc was built with 1023's mapped
3779 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3780 test_46() {
3781         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3782         f="$DIR/f46"
3783         stop_writeback
3784         sync
3785         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3786         sync
3787         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3788         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3789         sync
3790         start_writeback
3791 }
3792 run_test 46 "dirtying a previously written page ================"
3793
3794 # test_47 is removed "Device nodes check" is moved to test_28
3795
3796 test_48a() { # bug 2399
3797         check_kernel_version 34 || return 0
3798         test_mkdir -p $DIR/$tdir
3799         cd $DIR/$tdir
3800         mv $DIR/$tdir $DIR/d48.new || error "move directory failed"
3801         test_mkdir $DIR/$tdir || error "recreate directory failed"
3802         touch foo || error "'touch foo' failed after recreating cwd"
3803         test_mkdir $DIR/$tdir/bar ||
3804                      error "'mkdir foo' failed after recreating cwd"
3805         if check_kernel_version 44; then
3806                 touch .foo || error "'touch .foo' failed after recreating cwd"
3807                 test_mkdir $DIR/$tdir/.bar ||
3808                               error "'mkdir .foo' failed after recreating cwd"
3809         fi
3810         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3811         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3812         cd . || error "'cd .' failed after recreating cwd"
3813         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3814         rmdir . && error "'rmdir .' worked after recreating cwd"
3815         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3816         cd .. || error "'cd ..' failed after recreating cwd"
3817 }
3818 run_test 48a "Access renamed working dir (should return errors)="
3819
3820 test_48b() { # bug 2399
3821         check_kernel_version 34 || return 0
3822         rm -rf $DIR/$tdir
3823         test_mkdir -p $DIR/$tdir
3824         cd $DIR/$tdir
3825         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3826         touch foo && error "'touch foo' worked after removing cwd"
3827         test_mkdir $DIR/$tdir/foo &&
3828                      error "'mkdir foo' worked after removing cwd"
3829         if check_kernel_version 44; then
3830                 touch .foo && error "'touch .foo' worked after removing cwd"
3831                 test_mkdir $DIR/$tdir/.foo &&
3832                               error "'mkdir .foo' worked after removing cwd"
3833         fi
3834         ls . > /dev/null && error "'ls .' worked after removing cwd"
3835         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3836         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3837         test_mkdir $DIR/$tdir/. && error "'mkdir .' worked after removing cwd"
3838         rmdir . && error "'rmdir .' worked after removing cwd"
3839         ln -s . foo && error "'ln -s .' worked after removing cwd"
3840         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3841 }
3842 run_test 48b "Access removed working dir (should return errors)="
3843
3844 test_48c() { # bug 2350
3845         check_kernel_version 36 || return 0
3846         #lctl set_param debug=-1
3847         #set -vx
3848         rm -rf $DIR/$tdir
3849         test_mkdir -p $DIR/$tdir/dir
3850         cd $DIR/$tdir/dir
3851         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3852         $TRACE touch foo && error "touch foo worked after removing cwd"
3853         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3854         if check_kernel_version 44; then
3855                 touch .foo && error "touch .foo worked after removing cwd"
3856                 test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3857         fi
3858         $TRACE ls . && error "'ls .' worked after removing cwd"
3859         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3860         is_patchless || ( $TRACE cd . &&
3861                         error "'cd .' worked after removing cwd" )
3862         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3863         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3864         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3865         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3866 }
3867 run_test 48c "Access removed working subdir (should return errors)"
3868
3869 test_48d() { # bug 2350
3870         check_kernel_version 36 || return 0
3871         #lctl set_param debug=-1
3872         #set -vx
3873         rm -rf $DIR/$tdir
3874         test_mkdir -p $DIR/$tdir/dir
3875         cd $DIR/$tdir/dir
3876         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3877         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3878         $TRACE touch foo && error "'touch foo' worked after removing parent"
3879         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3880         if check_kernel_version 44; then
3881                 touch .foo && error "'touch .foo' worked after removing parent"
3882                 test_mkdir .foo &&
3883                               error "mkdir .foo worked after removing parent"
3884         fi
3885         $TRACE ls . && error "'ls .' worked after removing parent"
3886         $TRACE ls .. && error "'ls ..' worked after removing parent"
3887         is_patchless || ( $TRACE cd . &&
3888                         error "'cd .' worked after recreate parent" )
3889         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3890         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3891         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3892         is_patchless || ( $TRACE cd .. &&
3893                         error "'cd ..' worked after removing parent" || true )
3894 }
3895 run_test 48d "Access removed parent subdir (should return errors)"
3896
3897 test_48e() { # bug 4134
3898         check_kernel_version 41 || return 0
3899         #lctl set_param debug=-1
3900         #set -vx
3901         rm -rf $DIR/$tdir
3902         test_mkdir -p $DIR/$tdir/dir
3903         cd $DIR/$tdir/dir
3904         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3905         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3906         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3907         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3908         # On a buggy kernel addition of "touch foo" after cd .. will
3909         # produce kernel oops in lookup_hash_it
3910         touch ../foo && error "'cd ..' worked after recreate parent"
3911         cd $DIR
3912         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3913 }
3914 run_test 48e "Access to recreated parent subdir (should return errors)"
3915
3916 test_49() { # LU-1030
3917         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3918         # get ost1 size - lustre-OST0000
3919         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3920                 awk '{ print $4 }')
3921         # write 800M at maximum
3922         [[ $ost1_size -lt 2 ]] && ost1_size=2
3923         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3924
3925         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3926         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3927         local dd_pid=$!
3928
3929         # change max_pages_per_rpc while writing the file
3930         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3931         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3932         # loop until dd process exits
3933         while ps ax -opid | grep -wq $dd_pid; do
3934                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3935                 sleep $((RANDOM % 5 + 1))
3936         done
3937         # restore original max_pages_per_rpc
3938         $LCTL set_param $osc1_mppc=$orig_mppc
3939         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3940 }
3941 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3942
3943 test_50() {
3944         # bug 1485
3945         test_mkdir $DIR/$tdir
3946         cd $DIR/$tdir
3947         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3948 }
3949 run_test 50 "special situations: /proc symlinks  ==============="
3950
3951 test_51a() {    # was test_51
3952         # bug 1516 - create an empty entry right after ".." then split dir
3953         test_mkdir -c1 $DIR/$tdir
3954         touch $DIR/$tdir/foo
3955         $MCREATE $DIR/$tdir/bar
3956         rm $DIR/$tdir/foo
3957         createmany -m $DIR/$tdir/longfile 201
3958         FNUM=202
3959         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
3960                 $MCREATE $DIR/$tdir/longfile$FNUM
3961                 FNUM=$(($FNUM + 1))
3962                 echo -n "+"
3963         done
3964         echo
3965         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
3966 }
3967 run_test 51a "special situations: split htree with empty entry =="
3968
3969 export NUMTEST=70000
3970 test_51b() {
3971         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3972         local BASE=$DIR/d${base}.${TESTSUITE}
3973
3974         # cleanup the directory
3975         rm -fr $BASE
3976
3977         test_mkdir -p -c1 $BASE
3978
3979         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
3980         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
3981         [[ $numfree -lt 21000 ]] && skip "not enough free inodes ($numfree)" &&
3982                 return
3983
3984         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3985                 echo "reduced count to $NUMTEST due to inodes"
3986
3987         # need to check free space for the directories as well
3988         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
3989         numfree=$((blkfree / 4))
3990         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3991                 echo "reduced count to $NUMTEST due to blocks"
3992
3993         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
3994                 echo "failed" > $BASE/fnum
3995 }
3996 run_test 51b "exceed 64k subdirectory nlink limit"
3997
3998 test_51ba() { # LU-993
3999         local BASE=$DIR/d${base}.${TESTSUITE}
4000         # unlink all but 100 subdirectories, then check it still works
4001         local LEFT=100
4002         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
4003
4004         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
4005         local DELETE=$((NUMTEST - LEFT))
4006
4007         # continue on to run this test even if 51b didn't finish,
4008         # just to delete the many subdirectories created.
4009         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
4010
4011         # for ldiskfs the nlink count should be 1, but this is OSD specific
4012         # and so this is listed for informational purposes only
4013         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
4014         unlinkmany -d $BASE/d $DELETE
4015         RC=$?
4016
4017         if [ $RC -ne 0 ]; then
4018                 if [ "$NUMPREV" == "failed" ]; then
4019                         skip "previous setup failed"
4020                         return 0
4021                 else
4022                         error "unlink of first $DELETE subdirs failed"
4023                         return $RC
4024                 fi
4025         fi
4026
4027         echo "nlink between: $(stat -c %h $BASE)"
4028         # trim the first line of ls output
4029         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
4030         [ $FOUND -ne $LEFT ] &&
4031                 error "can't find subdirs: found only $FOUND/$LEFT"
4032
4033         unlinkmany -d $BASE/d $DELETE $LEFT ||
4034                 error "unlink of second $LEFT subdirs failed"
4035         # regardless of whether the backing filesystem tracks nlink accurately
4036         # or not, the nlink count shouldn't be more than "." and ".." here
4037         local AFTER=$(stat -c %h $BASE)
4038         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
4039                 echo "nlink after: $AFTER"
4040 }
4041 run_test 51ba "verify nlink for many subdirectory cleanup"
4042
4043 test_51d() {
4044         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4045         [[ $OSTCOUNT -lt 3 ]] &&
4046                 skip_env "skipping test with few OSTs" && return
4047         test_mkdir -p $DIR/$tdir
4048         createmany -o $DIR/$tdir/t- 1000
4049         $GETSTRIPE $DIR/$tdir > $TMP/files
4050         for N in $(seq 0 $((OSTCOUNT - 1))); do
4051                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4052                         END { printf("%0.0f", objs) }' $TMP/files)
4053                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
4054                         '($1 == '$N') { objs += 1 } \
4055                         END { printf("%0.0f", objs) }')
4056                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4057         done
4058         unlinkmany $DIR/$tdir/t- 1000
4059
4060         NLAST=0
4061         for N in $(seq 1 $((OSTCOUNT - 1))); do
4062                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4063                         error "OST $N has less objects vs OST $NLAST" \
4064                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4065                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4066                         error "OST $N has less objects vs OST $NLAST" \
4067                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4068
4069                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4070                         error "OST $N has less #0 objects vs OST $NLAST" \
4071                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4072                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4073                         error "OST $N has less #0 objects vs OST $NLAST" \
4074                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4075                 NLAST=$N
4076         done
4077 }
4078 run_test 51d "check object distribution ===================="
4079
4080 test_51e() {
4081         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4082                 skip "Only applicable to ldiskfs-based MDTs"
4083                 return
4084         fi
4085
4086         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4087         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4088
4089         touch $DIR/$tdir/d0/foo
4090         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4091                 error "file exceed 65000 nlink limit!"
4092         unlinkmany $DIR/$tdir/d0/f- 65001
4093         return 0
4094 }
4095 run_test 51e "check file nlink limit"
4096
4097 test_52a() {
4098         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4099         test_mkdir -p $DIR/$tdir
4100         touch $DIR/$tdir/foo
4101         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4102         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4103         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4104         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4105         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4106                                         error "link worked"
4107         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4108         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4109         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4110                                                      error "lsattr"
4111         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4112         cp -r $DIR/$tdir /tmp/
4113         rm -fr $DIR/$tdir || error "cleanup rm failed"
4114 }
4115 run_test 52a "append-only flag test (should return errors) ====="
4116
4117 test_52b() {
4118         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4119         test_mkdir -p $DIR/$tdir
4120         touch $DIR/$tdir/foo
4121         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4122         cat test > $DIR/$tdir/foo && error "cat test worked"
4123         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4124         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4125         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4126                                         error "link worked"
4127         echo foo >> $DIR/$tdir/foo && error "echo worked"
4128         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4129         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4130         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4131         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4132                                                         error "lsattr"
4133         chattr -i $DIR/$tdir/foo || error "chattr failed"
4134
4135         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4136 }
4137 run_test 52b "immutable flag test (should return errors) ======="
4138
4139 test_53() {
4140         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4141         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4142         remote_ost_nodsh && skip "remote OST with nodsh" && return
4143
4144         local param
4145         local param_seq
4146         local ostname
4147         local mds_last
4148         local mds_last_seq
4149         local ost_last
4150         local ost_last_seq
4151         local ost_last_id
4152         local ostnum
4153         local node
4154         local found=false
4155         local support_last_seq=true
4156
4157         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4158                 support_last_seq=false
4159
4160         # only test MDT0000
4161         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4162         local value
4163         for value in $(do_facet $SINGLEMDS \
4164                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4165                 param=$(echo ${value[0]} | cut -d "=" -f1)
4166                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4167
4168                 if $support_last_seq; then
4169                         param_seq=$(echo $param |
4170                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4171                         mds_last_seq=$(do_facet $SINGLEMDS \
4172                                        $LCTL get_param -n $param_seq)
4173                 fi
4174                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4175
4176                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4177                 node=$(facet_active_host ost$((ostnum+1)))
4178                 param="obdfilter.$ostname.last_id"
4179                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4180                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4181                         ost_last_id=$ost_last
4182
4183                         if $support_last_seq; then
4184                                 ost_last_id=$(echo $ost_last |
4185                                               awk -F':' '{print $2}' |
4186                                               sed -e "s/^0x//g")
4187                                 ost_last_seq=$(echo $ost_last |
4188                                                awk -F':' '{print $1}')
4189                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4190                         fi
4191
4192                         if [[ $ost_last_id != $mds_last ]]; then
4193                                 error "$ost_last_id != $mds_last"
4194                         else
4195                                 found=true
4196                                 break
4197                         fi
4198                 done
4199         done
4200         $found || error "can not match last_seq/last_id for $mdtosc"
4201         return 0
4202 }
4203 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4204
4205 test_54a() {
4206         $SOCKETSERVER $DIR/socket ||
4207                 error "$SOCKETSERVER $DIR/socket failed: $?"
4208         $SOCKETCLIENT $DIR/socket ||
4209                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4210         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4211 }
4212 run_test 54a "unix domain socket test =========================="
4213
4214 test_54b() {
4215         f="$DIR/f54b"
4216         mknod $f c 1 3
4217         chmod 0666 $f
4218         dd if=/dev/zero of=$f bs=$(page_size) count=1
4219 }
4220 run_test 54b "char device works in lustre ======================"
4221
4222 find_loop_dev() {
4223         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4224         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4225         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4226
4227         for i in $(seq 3 7); do
4228                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4229                 LOOPDEV=$LOOPBASE$i
4230                 LOOPNUM=$i
4231                 break
4232         done
4233 }
4234
4235 cleanup_54c() {
4236         loopdev="$DIR/loop54c"
4237
4238         trap 0
4239         $UMOUNT -d $DIR/$tdir || rc=$?
4240         losetup -d $loopdev || true
4241         losetup -d $LOOPDEV || true
4242         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4243         return $rc
4244 }
4245
4246 test_54c() {
4247         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4248         loopdev="$DIR/loop54c"
4249
4250         find_loop_dev
4251         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4252         trap cleanup_54c EXIT
4253         mknod $loopdev b 7 $LOOPNUM
4254         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4255         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4256         losetup $loopdev $DIR/$tfile ||
4257                 error "can't set up $loopdev for $DIR/$tfile"
4258         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4259         test_mkdir -p $DIR/$tdir
4260         mount -t ext2 $loopdev $DIR/$tdir ||
4261                 error "error mounting $loopdev on $DIR/$tdir"
4262         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4263                 error "dd write"
4264         df $DIR/$tdir
4265         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4266                 error "dd read"
4267         cleanup_54c
4268 }
4269 run_test 54c "block device works in lustre ====================="
4270
4271 test_54d() {
4272         f="$DIR/f54d"
4273         string="aaaaaa"
4274         mknod $f p
4275         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4276 }
4277 run_test 54d "fifo device works in lustre ======================"
4278
4279 test_54e() {
4280         check_kernel_version 46 || return 0
4281         f="$DIR/f54e"
4282         string="aaaaaa"
4283         cp -aL /dev/console $f
4284         echo $string > $f || error "echo $string to $f failed"
4285 }
4286 run_test 54e "console/tty device works in lustre ======================"
4287
4288 #The test_55 used to be iopen test and it was removed by bz#24037.
4289 #run_test 55 "check iopen_connect_dentry() ======================"
4290
4291 test_56a() {    # was test_56
4292         rm -rf $DIR/$tdir
4293         $SETSTRIPE -d $DIR
4294         test_mkdir -p $DIR/$tdir/dir
4295         NUMFILES=3
4296         NUMFILESx2=$(($NUMFILES * 2))
4297         for i in $(seq 1 $NUMFILES); do
4298                 touch $DIR/$tdir/file$i
4299                 touch $DIR/$tdir/dir/file$i
4300         done
4301
4302         # test lfs getstripe with --recursive
4303         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4304         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4305                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4306         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4307         [[ $FILENUM -eq $NUMFILES ]] ||
4308                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4309         echo "$GETSTRIPE --recursive passed."
4310
4311         # test lfs getstripe with file instead of dir
4312         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4313         [[ $FILENUM -eq 1 ]] ||
4314                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4315         echo "$GETSTRIPE file1 passed."
4316
4317         #test lfs getstripe with --verbose
4318         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4319                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4320                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4321         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4322                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4323         echo "$GETSTRIPE --verbose passed."
4324
4325         #test lfs getstripe with --obd
4326         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4327                 grep -q "unknown obduuid" ||
4328                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4329
4330         [[ $OSTCOUNT -lt 2 ]] &&
4331                 skip_env "skipping other $GETSTRIPE --obd test" && return
4332
4333         OSTIDX=1
4334         OBDUUID=$(ostuuid_from_index $OSTIDX)
4335         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4336         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4337         [[ $FOUND -eq $FILENUM ]] ||
4338                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4339         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4340                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4341                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4342                 error "$GETSTRIPE --obd: should not show file on other obd"
4343         echo "$GETSTRIPE --obd passed"
4344 }
4345 run_test 56a "check $GETSTRIPE"
4346
4347 NUMFILES=3
4348 NUMDIRS=3
4349 setup_56() {
4350         local LOCAL_NUMFILES="$1"
4351         local LOCAL_NUMDIRS="$2"
4352         local MKDIR_PARAMS="$3"
4353         local DIR_STRIPE_PARAMS="$4"
4354
4355         if [ ! -d "$TDIR" ] ; then
4356                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4357                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4358                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4359                         touch $TDIR/file$i
4360                 done
4361                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4362                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4363                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4364                                 touch $TDIR/dir$i/file$j
4365                         done
4366                 done
4367         fi
4368 }
4369
4370 setup_56_special() {
4371         LOCAL_NUMFILES=$1
4372         LOCAL_NUMDIRS=$2
4373         setup_56 $1 $2
4374         if [ ! -e "$TDIR/loop1b" ] ; then
4375                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4376                         mknod $TDIR/loop${i}b b 7 $i
4377                         mknod $TDIR/null${i}c c 1 3
4378                         ln -s $TDIR/file1 $TDIR/link${i}l
4379                 done
4380                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4381                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4382                         mknod $TDIR/dir$i/null${i}c c 1 3
4383                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4384                 done
4385         fi
4386 }
4387
4388 test_56g() {
4389         $SETSTRIPE -d $DIR
4390
4391         TDIR=$DIR/${tdir}g
4392         setup_56 $NUMFILES $NUMDIRS
4393
4394         EXPECTED=$(($NUMDIRS + 2))
4395         # test lfs find with -name
4396         for i in $(seq 1 $NUMFILES) ; do
4397                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4398                 [ $NUMS -eq $EXPECTED ] ||
4399                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4400                               "found $NUMS, expected $EXPECTED"
4401         done
4402 }
4403 run_test 56g "check lfs find -name ============================="
4404
4405 test_56h() {
4406         $SETSTRIPE -d $DIR
4407
4408         TDIR=$DIR/${tdir}g
4409         setup_56 $NUMFILES $NUMDIRS
4410
4411         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4412         # test lfs find with ! -name
4413         for i in $(seq 1 $NUMFILES) ; do
4414                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4415                 [ $NUMS -eq $EXPECTED ] ||
4416                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4417                               "found $NUMS, expected $EXPECTED"
4418         done
4419 }
4420 run_test 56h "check lfs find ! -name ============================="
4421
4422 test_56i() {
4423        tdir=${tdir}i
4424        test_mkdir -p $DIR/$tdir
4425        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4426        CMD="$LFIND -ost $UUID $DIR/$tdir"
4427        OUT=$($CMD)
4428        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4429 }
4430 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4431
4432 test_56j() {
4433         TDIR=$DIR/${tdir}g
4434         setup_56_special $NUMFILES $NUMDIRS
4435
4436         EXPECTED=$((NUMDIRS + 1))
4437         CMD="$LFIND -type d $TDIR"
4438         NUMS=$($CMD | wc -l)
4439         [ $NUMS -eq $EXPECTED ] ||
4440                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4441 }
4442 run_test 56j "check lfs find -type d ============================="
4443
4444 test_56k() {
4445         TDIR=$DIR/${tdir}g
4446         setup_56_special $NUMFILES $NUMDIRS
4447
4448         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4449         CMD="$LFIND -type f $TDIR"
4450         NUMS=$($CMD | wc -l)
4451         [ $NUMS -eq $EXPECTED ] ||
4452                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4453 }
4454 run_test 56k "check lfs find -type f ============================="
4455
4456 test_56l() {
4457         TDIR=$DIR/${tdir}g
4458         setup_56_special $NUMFILES $NUMDIRS
4459
4460         EXPECTED=$((NUMDIRS + NUMFILES))
4461         CMD="$LFIND -type b $TDIR"
4462         NUMS=$($CMD | wc -l)
4463         [ $NUMS -eq $EXPECTED ] ||
4464                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4465 }
4466 run_test 56l "check lfs find -type b ============================="
4467
4468 test_56m() {
4469         TDIR=$DIR/${tdir}g
4470         setup_56_special $NUMFILES $NUMDIRS
4471
4472         EXPECTED=$((NUMDIRS + NUMFILES))
4473         CMD="$LFIND -type c $TDIR"
4474         NUMS=$($CMD | wc -l)
4475         [ $NUMS -eq $EXPECTED ] ||
4476                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4477 }
4478 run_test 56m "check lfs find -type c ============================="
4479
4480 test_56n() {
4481         TDIR=$DIR/${tdir}g
4482         setup_56_special $NUMFILES $NUMDIRS
4483
4484         EXPECTED=$((NUMDIRS + NUMFILES))
4485         CMD="$LFIND -type l $TDIR"
4486         NUMS=$($CMD | wc -l)
4487         [ $NUMS -eq $EXPECTED ] ||
4488                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4489 }
4490 run_test 56n "check lfs find -type l ============================="
4491
4492 test_56o() {
4493         TDIR=$DIR/${tdir}o
4494         setup_56 $NUMFILES $NUMDIRS
4495         utime $TDIR/file1 > /dev/null || error "utime (1)"
4496         utime $TDIR/file2 > /dev/null || error "utime (2)"
4497         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4498         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4499         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4500         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4501
4502         EXPECTED=4
4503         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4504         [ $NUMS -eq $EXPECTED ] || \
4505                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4506
4507         EXPECTED=12
4508         CMD="$LFIND -mtime 0 $TDIR"
4509         NUMS=$($CMD | wc -l)
4510         [ $NUMS -eq $EXPECTED ] ||
4511                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4512 }
4513 run_test 56o "check lfs find -mtime for old files =========================="
4514
4515 test_56p() {
4516         [ $RUNAS_ID -eq $UID ] &&
4517                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4518
4519         TDIR=$DIR/${tdir}p
4520         setup_56 $NUMFILES $NUMDIRS
4521
4522         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4523         EXPECTED=$NUMFILES
4524         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4525         NUMS=$($CMD | wc -l)
4526         [ $NUMS -eq $EXPECTED ] || \
4527                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4528
4529         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4530         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4531         NUMS=$($CMD | wc -l)
4532         [ $NUMS -eq $EXPECTED ] || \
4533                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4534 }
4535 run_test 56p "check lfs find -uid and ! -uid ==============================="
4536
4537 test_56q() {
4538         [ $RUNAS_ID -eq $UID ] &&
4539                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4540
4541         TDIR=$DIR/${tdir}q
4542         setup_56 $NUMFILES $NUMDIRS
4543
4544         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4545
4546         EXPECTED=$NUMFILES
4547         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4548         NUMS=$($CMD | wc -l)
4549         [ $NUMS -eq $EXPECTED ] ||
4550                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4551
4552         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4553         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4554         NUMS=$($CMD | wc -l)
4555         [ $NUMS -eq $EXPECTED ] ||
4556                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4557 }
4558 run_test 56q "check lfs find -gid and ! -gid ==============================="
4559
4560 test_56r() {
4561         TDIR=$DIR/${tdir}r
4562         setup_56 $NUMFILES $NUMDIRS
4563
4564         EXPECTED=12
4565         CMD="$LFIND -size 0 -type f $TDIR"
4566         NUMS=$($CMD | wc -l)
4567         [ $NUMS -eq $EXPECTED ] ||
4568                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4569         EXPECTED=0
4570         CMD="$LFIND ! -size 0 -type f $TDIR"
4571         NUMS=$($CMD | wc -l)
4572         [ $NUMS -eq $EXPECTED ] ||
4573                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4574         echo "test" > $TDIR/$tfile
4575         echo "test2" > $TDIR/$tfile.2 && sync
4576         EXPECTED=1
4577         CMD="$LFIND -size 5 -type f $TDIR"
4578         NUMS=$($CMD | wc -l)
4579         [ $NUMS -eq $EXPECTED ] ||
4580                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4581         EXPECTED=1
4582         CMD="$LFIND -size +5 -type f $TDIR"
4583         NUMS=$($CMD | wc -l)
4584         [ $NUMS -eq $EXPECTED ] ||
4585                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4586         EXPECTED=2
4587         CMD="$LFIND -size +0 -type f $TDIR"
4588         NUMS=$($CMD | wc -l)
4589         [ $NUMS -eq $EXPECTED ] ||
4590                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4591         EXPECTED=2
4592         CMD="$LFIND ! -size -5 -type f $TDIR"
4593         NUMS=$($CMD | wc -l)
4594         [ $NUMS -eq $EXPECTED ] ||
4595                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4596         EXPECTED=12
4597         CMD="$LFIND -size -5 -type f $TDIR"
4598         NUMS=$($CMD | wc -l)
4599         [ $NUMS -eq $EXPECTED ] ||
4600                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4601 }
4602 run_test 56r "check lfs find -size works =========================="
4603
4604 test_56s() { # LU-611
4605         TDIR=$DIR/${tdir}s
4606         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4607
4608         if [[ $OSTCOUNT -gt 1 ]]; then
4609                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4610                 ONESTRIPE=4
4611                 EXTRA=4
4612         else
4613                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4614                 EXTRA=0
4615         fi
4616
4617         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4618         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4619         NUMS=$($CMD | wc -l)
4620         [ $NUMS -eq $EXPECTED ] || {
4621                 $GETSTRIPE -R $TDIR
4622                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4623         }
4624
4625         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4626         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4627         NUMS=$($CMD | wc -l)
4628         [ $NUMS -eq $EXPECTED ] || {
4629                 $GETSTRIPE -R $TDIR
4630                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4631         }
4632
4633         EXPECTED=$ONESTRIPE
4634         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4635         NUMS=$($CMD | wc -l)
4636         [ $NUMS -eq $EXPECTED ] || {
4637                 $GETSTRIPE -R $TDIR
4638                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4639         }
4640
4641         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4642         NUMS=$($CMD | wc -l)
4643         [ $NUMS -eq $EXPECTED ] || {
4644                 $GETSTRIPE -R $TDIR
4645                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4646         }
4647
4648         EXPECTED=0
4649         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4650         NUMS=$($CMD | wc -l)
4651         [ $NUMS -eq $EXPECTED ] || {
4652                 $GETSTRIPE -R $TDIR
4653                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4654         }
4655 }
4656 run_test 56s "check lfs find -stripe-count works"
4657
4658 test_56t() { # LU-611
4659         TDIR=$DIR/${tdir}t
4660         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4661
4662         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4663
4664         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4665         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4666         NUMS=$($CMD | wc -l)
4667         [ $NUMS -eq $EXPECTED ] ||
4668                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4669
4670         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4671         NUMS=$($CMD | wc -l)
4672         [ $NUMS -eq $EXPECTED ] ||
4673                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4674
4675         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4676         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4677         NUMS=$($CMD | wc -l)
4678         [ $NUMS -eq $EXPECTED ] ||
4679                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4680
4681         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4682         NUMS=$($CMD | wc -l)
4683         [ $NUMS -eq $EXPECTED ] ||
4684                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4685
4686         EXPECTED=4
4687         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4688         NUMS=$($CMD | wc -l)
4689         [ $NUMS -eq $EXPECTED ] ||
4690                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4691
4692         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4693         NUMS=$($CMD | wc -l)
4694         [ $NUMS -eq $EXPECTED ] ||
4695                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4696
4697         EXPECTED=0
4698         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4699         NUMS=$($CMD | wc -l)
4700         [ $NUMS -eq $EXPECTED ] ||
4701                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4702 }
4703 run_test 56t "check lfs find -stripe-size works"
4704
4705 test_56u() { # LU-611
4706         TDIR=$DIR/${tdir}u
4707         setup_56 $NUMFILES $NUMDIRS "-i 0"
4708
4709         if [[ $OSTCOUNT -gt 1 ]]; then
4710                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4711                 ONESTRIPE=4
4712         else
4713                 ONESTRIPE=0
4714         fi
4715
4716         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4717         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4718         NUMS=$($CMD | wc -l)
4719         [ $NUMS -eq $EXPECTED ] ||
4720                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4721
4722         EXPECTED=$ONESTRIPE
4723         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4724         NUMS=$($CMD | wc -l)
4725         [ $NUMS -eq $EXPECTED ] ||
4726                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4727
4728         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4729         NUMS=$($CMD | wc -l)
4730         [ $NUMS -eq $EXPECTED ] ||
4731                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4732
4733         EXPECTED=0
4734         # This should produce an error and not return any files
4735         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4736         NUMS=$($CMD 2>/dev/null | wc -l)
4737         [ $NUMS -eq $EXPECTED ] ||
4738                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4739
4740         if [[ $OSTCOUNT -gt 1 ]]; then
4741                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4742                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4743                 NUMS=$($CMD | wc -l)
4744                 [ $NUMS -eq $EXPECTED ] ||
4745                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4746         fi
4747 }
4748 run_test 56u "check lfs find -stripe-index works"
4749
4750 test_56v() {
4751     local MDT_IDX=0
4752
4753     TDIR=$DIR/${tdir}v
4754     rm -rf $TDIR
4755     setup_56 $NUMFILES $NUMDIRS
4756
4757     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4758     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4759
4760     for file in $($LFIND -mdt $UUID $TDIR); do
4761         file_mdt_idx=$($GETSTRIPE -M $file)
4762         [ $file_mdt_idx -eq $MDT_IDX ] ||
4763             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4764     done
4765 }
4766 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4767
4768 # Get and check the actual stripe count of one file.
4769 # Usage: check_stripe_count <file> <expected_stripe_count>
4770 check_stripe_count() {
4771     local file=$1
4772     local expected=$2
4773     local actual
4774
4775     [[ -z "$file" || -z "$expected" ]] &&
4776         error "check_stripe_count: invalid argument!"
4777
4778     local cmd="$GETSTRIPE -c $file"
4779     actual=$($cmd) || error "$cmd failed"
4780     actual=${actual%% *}
4781
4782     if [[ $actual -ne $expected ]]; then
4783         [[ $expected -eq -1 ]] ||
4784             error "$cmd wrong: found $actual, expected $expected"
4785         [[ $actual -eq $OSTCOUNT ]] ||
4786             error "$cmd wrong: found $actual, expected $OSTCOUNT"
4787     fi
4788 }
4789
4790 test_56w() {
4791         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4792         TDIR=$DIR/${tdir}w
4793
4794     rm -rf $TDIR || error "remove $TDIR failed"
4795     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4796
4797     local stripe_size
4798     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4799         error "$GETSTRIPE -S -d $TDIR failed"
4800     stripe_size=${stripe_size%% *}
4801
4802     local file_size=$((stripe_size * OSTCOUNT))
4803     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4804     local required_space=$((file_num * file_size))
4805     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4806     [[ $free_space -le $((required_space / 1024)) ]] &&
4807         skip_env "need at least $required_space bytes free space," \
4808                  "have $free_space kbytes" && return
4809
4810     local dd_bs=65536
4811     local dd_count=$((file_size / dd_bs))
4812
4813     # write data into the files
4814     local i
4815     local j
4816     local file
4817     for i in $(seq 1 $NUMFILES); do
4818         file=$TDIR/file$i
4819         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4820             error "write data into $file failed"
4821     done
4822     for i in $(seq 1 $NUMDIRS); do
4823         for j in $(seq 1 $NUMFILES); do
4824             file=$TDIR/dir$i/file$j
4825             yes | dd bs=$dd_bs count=$dd_count of=$file \
4826                 >/dev/null 2>&1 ||
4827                 error "write data into $file failed"
4828         done
4829     done
4830
4831     local expected=-1
4832     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4833
4834     # lfs_migrate file
4835     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4836     echo "$cmd"
4837     eval $cmd || error "$cmd failed"
4838
4839     check_stripe_count $TDIR/file1 $expected
4840
4841     # lfs_migrate dir
4842     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4843     echo "$cmd"
4844     eval $cmd || error "$cmd failed"
4845
4846     for j in $(seq 1 $NUMFILES); do
4847         check_stripe_count $TDIR/dir1/file$j $expected
4848     done
4849
4850     # lfs_migrate works with lfs find
4851     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4852          $LFS_MIGRATE -y -c $expected"
4853     echo "$cmd"
4854     eval $cmd || error "$cmd failed"
4855
4856     for i in $(seq 2 $NUMFILES); do
4857         check_stripe_count $TDIR/file$i $expected
4858     done
4859     for i in $(seq 2 $NUMDIRS); do
4860         for j in $(seq 1 $NUMFILES); do
4861             check_stripe_count $TDIR/dir$i/file$j $expected
4862         done
4863     done
4864 }
4865 run_test 56w "check lfs_migrate -c stripe_count works"
4866
4867 test_56x() {
4868         check_swap_layouts_support && return 0
4869         [[ $OSTCOUNT -lt 2 ]] &&
4870                 skip_env "need 2 OST, skipping test" && return
4871
4872         local dir0=$DIR/$tdir/$testnum
4873         mkdir -p $dir0 || error "creating dir $dir0"
4874
4875         local ref1=/etc/passwd
4876         local file1=$dir0/file1
4877
4878         $SETSTRIPE -c 2 $file1
4879         cp $ref1 $file1
4880         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4881         stripe=$($GETSTRIPE -c $file1)
4882         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4883         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4884
4885         # clean up
4886         rm -f $file1
4887 }
4888 run_test 56x "lfs migration support"
4889
4890 test_56y() {
4891         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4892                 skip "No HSM support on MDS of $(get_lustre_version)," \
4893                          "need 2.4.53 at least" && return
4894         local res=""
4895
4896         local dir0=$DIR/$tdir/$testnum
4897         mkdir -p $dir0 || error "creating dir $dir0"
4898         local f1=$dir0/file1
4899         local f2=$dir0/file2
4900
4901         touch $f1 || error "creating std file $f1"
4902         $MULTIOP $f2 H2c || error "creating released file $f2"
4903
4904         # a directory can be raid0, so ask only for files
4905         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4906         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4907
4908         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4909         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4910
4911         # only files can be released, so no need to force file search
4912         res=$($LFIND $dir0 -L released)
4913         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4914
4915         res=$($LFIND $dir0 \! -L released)
4916         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4917
4918 }
4919 run_test 56y "lfs find -L raid0|released"
4920
4921 test_56z() { # LU-4824
4922         # This checks to make sure 'lfs find' continues after errors
4923         # There are two classes of errors that should be caught:
4924         # - If multiple paths are provided, all should be searched even if one
4925         #   errors out
4926         # - If errors are encountered during the search, it should not terminate
4927         #   early
4928         local i
4929         test_mkdir $DIR/$tdir
4930         for i in d{0..9}; do
4931                 test_mkdir $DIR/$tdir/$i
4932         done
4933         touch $DIR/$tdir/d{0..9}/$tfile
4934         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
4935                 error "$LFS find did not return an error"
4936         # Make a directory unsearchable. This should NOT be the last entry in
4937         # directory order.  Arbitrarily pick the 6th entry
4938         chmod 700 $(lfs find $DIR/$tdir -type d | sed '6!d')
4939         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
4940         # The user should be able to see 10 directories and 9 files
4941         [ $count == 19 ] || error "$LFS find did not continue after error"
4942 }
4943 run_test 56z "lfs find should continue after an error"
4944
4945 test_57a() {
4946         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4947         # note test will not do anything if MDS is not local
4948         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4949                 skip "Only applicable to ldiskfs-based MDTs"
4950                 return
4951         fi
4952
4953         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4954         local MNTDEV="osd*.*MDT*.mntdev"
4955         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
4956         [ -z "$DEV" ] && error "can't access $MNTDEV"
4957         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
4958                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
4959                         error "can't access $DEV"
4960                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
4961                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
4962                 rm $TMP/t57a.dump
4963         done
4964 }
4965 run_test 57a "verify MDS filesystem created with large inodes =="
4966
4967 test_57b() {
4968         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4969         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4970                 skip "Only applicable to ldiskfs-based MDTs"
4971                 return
4972         fi
4973
4974         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4975         local dir=$DIR/d57b
4976
4977         local FILECOUNT=100
4978         local FILE1=$dir/f1
4979         local FILEN=$dir/f$FILECOUNT
4980
4981         rm -rf $dir || error "removing $dir"
4982         test_mkdir -p $dir || error "creating $dir"
4983         local num=$(get_mds_dir $dir)
4984         local mymds=mds$num
4985
4986         echo "mcreating $FILECOUNT files"
4987         createmany -m $dir/f 1 $FILECOUNT || \
4988                 error "creating files in $dir"
4989
4990         # verify that files do not have EAs yet
4991         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
4992         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
4993
4994         sync
4995         sleep 1
4996         df $dir  #make sure we get new statfs data
4997         local MDSFREE=$(do_facet $mymds \
4998                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4999         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
5000         echo "opening files to create objects/EAs"
5001         local FILE
5002         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5003                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5004         done
5005
5006         # verify that files have EAs now
5007         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5008         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5009
5010         sleep 1  #make sure we get new statfs data
5011         df $dir
5012         local MDSFREE2=$(do_facet $mymds \
5013                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
5014         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
5015         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5016                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5017                         error "MDC before $MDCFREE != after $MDCFREE2"
5018                 else
5019                         echo "MDC before $MDCFREE != after $MDCFREE2"
5020                         echo "unable to confirm if MDS has large inodes"
5021                 fi
5022         fi
5023         rm -rf $dir
5024 }
5025 run_test 57b "default LOV EAs are stored inside large inodes ==="
5026
5027 test_58() {
5028         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5029         [ -z "$(which wiretest 2>/dev/null)" ] &&
5030                         skip_env "could not find wiretest" && return
5031         wiretest
5032 }
5033 run_test 58 "verify cross-platform wire constants =============="
5034
5035 test_59() {
5036         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5037         echo "touch 130 files"
5038         createmany -o $DIR/f59- 130
5039         echo "rm 130 files"
5040         unlinkmany $DIR/f59- 130
5041         sync
5042         # wait for commitment of removal
5043         wait_delete_completed
5044 }
5045 run_test 59 "verify cancellation of llog records async ========="
5046
5047 TEST60_HEAD="test_60 run $RANDOM"
5048 test_60a() {
5049         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5050         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5051         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5052                 skip_env "missing subtest run-llog.sh" && return
5053         log "$TEST60_HEAD - from kernel mode"
5054         do_facet mgs sh run-llog.sh
5055 }
5056 run_test 60a "llog sanity tests run from kernel module =========="
5057
5058 test_60b() { # bug 6411
5059         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5060         dmesg > $DIR/$tfile
5061         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
5062                                  /llog.test/ {
5063                                          if (marker)
5064                                                  from_marker++
5065                                          from_begin++
5066                                  }
5067                                  END {
5068                                          if (marker)
5069                                                  print from_marker
5070                                          else
5071                                                  print from_begin
5072                                  }"`
5073         [[ $LLOG_COUNT -gt 50 ]] &&
5074                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5075 }
5076 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5077
5078 test_60c() {
5079         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5080         echo "create 5000 files"
5081         createmany -o $DIR/f60c- 5000
5082 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5083         lctl set_param fail_loc=0x80000137
5084         unlinkmany $DIR/f60c- 5000
5085         lctl set_param fail_loc=0
5086 }
5087 run_test 60c "unlink file when mds full"
5088
5089 test_60d() {
5090         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5091         SAVEPRINTK=$(lctl get_param -n printk)
5092
5093         # verify "lctl mark" is even working"
5094         MESSAGE="test message ID $RANDOM $$"
5095         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5096         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5097
5098         lctl set_param printk=0 || error "set lnet.printk failed"
5099         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5100         MESSAGE="new test message ID $RANDOM $$"
5101         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5102         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5103         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5104
5105         lctl set_param -n printk="$SAVEPRINTK"
5106 }
5107 run_test 60d "test printk console message masking"
5108
5109 test_61() {
5110         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5111         f="$DIR/f61"
5112         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5113         cancel_lru_locks osc
5114         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5115         sync
5116 }
5117 run_test 61 "mmap() writes don't make sync hang ================"
5118
5119 # bug 2330 - insufficient obd_match error checking causes LBUG
5120 test_62() {
5121         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5122         f="$DIR/f62"
5123         echo foo > $f
5124         cancel_lru_locks osc
5125         lctl set_param fail_loc=0x405
5126         cat $f && error "cat succeeded, expect -EIO"
5127         lctl set_param fail_loc=0
5128 }
5129 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5130 # match every page all of the time.
5131 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5132
5133 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5134 # Though this test is irrelevant anymore, it helped to reveal some
5135 # other grant bugs (LU-4482), let's keep it.
5136 test_63a() {   # was test_63
5137         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5138         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5139         for i in `seq 10` ; do
5140                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5141                 sleep 5
5142                 kill $!
5143                 sleep 1
5144         done
5145
5146         rm -f $DIR/f63 || true
5147 }
5148 run_test 63a "Verify oig_wait interruption does not crash ======="
5149
5150 # bug 2248 - async write errors didn't return to application on sync
5151 # bug 3677 - async write errors left page locked
5152 test_63b() {
5153         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5154         debugsave
5155         lctl set_param debug=-1
5156
5157         # ensure we have a grant to do async writes
5158         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5159         rm $DIR/$tfile
5160
5161         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5162         lctl set_param fail_loc=0x80000406
5163         $MULTIOP $DIR/$tfile Owy && \
5164                 error "sync didn't return ENOMEM"
5165         sync; sleep 2; sync     # do a real sync this time to flush page
5166         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5167                 error "locked page left in cache after async error" || true
5168         debugrestore
5169 }
5170 run_test 63b "async write errors should be returned to fsync ==="
5171
5172 test_64a () {
5173         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5174         df $DIR
5175         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5176 }
5177 run_test 64a "verify filter grant calculations (in kernel) ====="
5178
5179 test_64b () {
5180         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5181         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5182 }
5183 run_test 64b "check out-of-space detection on client ==========="
5184
5185 test_64c() {
5186         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5187 }
5188 run_test 64c "verify grant shrink ========================------"
5189
5190 # bug 1414 - set/get directories' stripe info
5191 test_65a() {
5192         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5193         test_mkdir -p $DIR/$tdir
5194         touch $DIR/$tdir/f1
5195         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5196 }
5197 run_test 65a "directory with no stripe info ===================="
5198
5199 test_65b() {
5200         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5201         test_mkdir -p $DIR/$tdir
5202         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5203                                                 error "setstripe"
5204         touch $DIR/$tdir/f2
5205         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5206 }
5207 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
5208
5209 test_65c() {
5210         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5211         if [[ $OSTCOUNT -gt 1 ]]; then
5212                 test_mkdir -p $DIR/$tdir
5213                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5214                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5215                 touch $DIR/$tdir/f3
5216                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5217         fi
5218 }
5219 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
5220
5221 test_65d() {
5222         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5223         test_mkdir -p $DIR/$tdir
5224         if [[ $STRIPECOUNT -le 0 ]]; then
5225                 sc=1
5226         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5227 #LOV_MAX_STRIPE_COUNT is 2000
5228                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5229         else
5230                 sc=$(($STRIPECOUNT - 1))
5231         fi
5232         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5233         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5234         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5235                 error "lverify failed"
5236 }
5237 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
5238
5239 test_65e() {
5240         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5241         test_mkdir -p $DIR/$tdir
5242
5243         $SETSTRIPE $DIR/$tdir || error "setstripe"
5244         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5245                                         error "no stripe info failed"
5246         touch $DIR/$tdir/f6
5247         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5248 }
5249 run_test 65e "directory setstripe defaults ======================="
5250
5251 test_65f() {
5252         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5253         test_mkdir -p $DIR/${tdir}f
5254         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5255 }
5256 run_test 65f "dir setstripe permission (should return error) ==="
5257
5258 test_65g() {
5259         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5260         test_mkdir -p $DIR/$tdir
5261         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5262                                                         error "setstripe"
5263         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5264         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5265                 error "delete default stripe failed"
5266 }
5267 run_test 65g "directory setstripe -d ==========================="
5268
5269 test_65h() {
5270         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5271         test_mkdir -p $DIR/$tdir
5272         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5273                                                         error "setstripe"
5274         test_mkdir -p $DIR/$tdir/dd1
5275         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5276                 error "stripe info inherit failed"
5277 }
5278 run_test 65h "directory stripe info inherit ===================="
5279
5280 test_65i() { # bug6367
5281         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5282         $SETSTRIPE -S 65536 -c -1 $MOUNT
5283 }
5284 run_test 65i "set non-default striping on root directory (bug 6367)="
5285
5286 test_65ia() { # bug12836
5287         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5288         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5289 }
5290 run_test 65ia "getstripe on -1 default directory striping"
5291
5292 test_65ib() { # bug12836
5293         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5294         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5295 }
5296 run_test 65ib "getstripe -v on -1 default directory striping"
5297
5298 test_65ic() { # bug12836
5299         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5300         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5301 }
5302 run_test 65ic "new find on -1 default directory striping"
5303
5304 test_65j() { # bug6367
5305         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5306         sync; sleep 1
5307         # if we aren't already remounting for each test, do so for this test
5308         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5309                 cleanup || error "failed to unmount"
5310                 setup
5311         fi
5312         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5313 }
5314 run_test 65j "set default striping on root directory (bug 6367)="
5315
5316 test_65k() { # bug11679
5317         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5318         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5319         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5320
5321     echo "Check OST status: "
5322     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5323               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5324
5325     for OSC in $MDS_OSCS; do
5326         echo $OSC "is activate"
5327         do_facet $SINGLEMDS lctl --device %$OSC activate
5328     done
5329
5330     mkdir -p $DIR/$tdir
5331     for INACTIVE_OSC in $MDS_OSCS; do
5332         echo "Deactivate: " $INACTIVE_OSC
5333         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5334         for STRIPE_OSC in $MDS_OSCS; do
5335             OST=`osc_to_ost $STRIPE_OSC`
5336             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5337                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5338
5339             [ -f $DIR/$tdir/$IDX ] && continue
5340             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5341             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5342             RC=$?
5343             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5344         done
5345         rm -f $DIR/$tdir/*
5346         echo $INACTIVE_OSC "is Activate."
5347         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5348     done
5349 }
5350 run_test 65k "validate manual striping works properly with deactivated OSCs"
5351
5352 test_65l() { # bug 12836
5353         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5354         test_mkdir -p $DIR/$tdir/test_dir
5355         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5356         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5357 }
5358 run_test 65l "lfs find on -1 stripe dir ========================"
5359
5360 # bug 2543 - update blocks count on client
5361 test_66() {
5362         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5363         COUNT=${COUNT:-8}
5364         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5365         sync; sync_all_data; sync; sync_all_data
5366         cancel_lru_locks osc
5367         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5368         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5369 }
5370 run_test 66 "update inode blocks count on client ==============="
5371
5372 LLOOP=
5373 LLITELOOPLOAD=
5374 cleanup_68() {
5375         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5376         trap 0
5377         if [ ! -z "$LLOOP" ]; then
5378                 if swapon -s | grep -q $LLOOP; then
5379                         swapoff $LLOOP || error "swapoff failed"
5380                 fi
5381
5382                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5383                 rm -f $LLOOP
5384                 unset LLOOP
5385         fi
5386         if [ ! -z "$LLITELOOPLOAD" ]; then
5387                 rmmod llite_lloop
5388                 unset LLITELOOPLOAD
5389         fi
5390         rm -f $DIR/f68*
5391 }
5392
5393 meminfo() {
5394         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5395 }
5396
5397 swap_used() {
5398         swapon -s | awk '($1 == "'$1'") { print $4 }'
5399 }
5400
5401 # test case for lloop driver, basic function
5402 test_68a() {
5403         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5404         [ "$UID" != 0 ] && skip_env "must run as root" && return
5405         llite_lloop_enabled || \
5406                 { skip_env "llite_lloop module disabled" && return; }
5407
5408         trap cleanup_68 EXIT
5409
5410         if ! module_loaded llite_lloop; then
5411                 if load_module llite/llite_lloop; then
5412                         LLITELOOPLOAD=yes
5413                 else
5414                         skip_env "can't find module llite_lloop"
5415                         return
5416                 fi
5417         fi
5418
5419         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5420         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5421         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5422
5423         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5424         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5425
5426         cleanup_68
5427 }
5428 run_test 68a "lloop driver - basic test ========================"
5429
5430 # excercise swapping to lustre by adding a high priority swapfile entry
5431 # and then consuming memory until it is used.
5432 test_68b() {  # was test_68
5433         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5434         [ "$UID" != 0 ] && skip_env "must run as root" && return
5435         lctl get_param -n devices | grep -q obdfilter && \
5436                 skip "local OST" && return
5437
5438         grep -q llite_lloop /proc/modules
5439         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5440
5441         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5442                 skip "can't reliably test swap with TCP" && return
5443
5444         MEMTOTAL=`meminfo MemTotal`
5445         NR_BLOCKS=$((MEMTOTAL>>8))
5446         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5447
5448         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5449         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5450         mkswap $DIR/f68b
5451
5452         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5453
5454         trap cleanup_68 EXIT
5455
5456         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5457
5458         echo "before: `swapon -s | grep $LLOOP`"
5459         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5460         echo "after: `swapon -s | grep $LLOOP`"
5461         SWAPUSED=`swap_used $LLOOP`
5462
5463         cleanup_68
5464
5465         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5466 }
5467 run_test 68b "support swapping to Lustre ========================"
5468
5469 # bug5265, obdfilter oa2dentry return -ENOENT
5470 # #define OBD_FAIL_OST_ENOENT 0x217
5471 test_69() {
5472         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5473         remote_ost_nodsh && skip "remote OST with nodsh" && return
5474
5475         f="$DIR/$tfile"
5476         $SETSTRIPE -c 1 -i 0 $f
5477
5478         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5479
5480         do_facet ost1 lctl set_param fail_loc=0x217
5481         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5482         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5483
5484         do_facet ost1 lctl set_param fail_loc=0
5485         $DIRECTIO write $f 0 2 || error "write error"
5486
5487         cancel_lru_locks osc
5488         $DIRECTIO read $f 0 1 || error "read error"
5489
5490         do_facet ost1 lctl set_param fail_loc=0x217
5491         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5492
5493         do_facet ost1 lctl set_param fail_loc=0
5494         rm -f $f
5495 }
5496 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5497
5498 test_71() {
5499     test_mkdir -p $DIR/$tdir
5500     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5501 }
5502 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5503
5504 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5505         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5506         [ "$RUNAS_ID" = "$UID" ] &&
5507                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5508
5509         # Check that testing environment is properly set up. Skip if not
5510         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5511                 skip_env "User $RUNAS_ID does not exist - skipping"
5512                 return 0
5513         }
5514         touch $DIR/$tfile
5515         chmod 777 $DIR/$tfile
5516         chmod ug+s $DIR/$tfile
5517         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5518                 error "$RUNAS dd $DIR/$tfile failed"
5519         # See if we are still setuid/sgid
5520         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5521                 error "S/gid is not dropped on write"
5522         # Now test that MDS is updated too
5523         cancel_lru_locks mdc
5524         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5525                 error "S/gid is not dropped on MDS"
5526         rm -f $DIR/$tfile
5527 }
5528 run_test 72a "Test that remove suid works properly (bug5695) ===="
5529
5530 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5531         local perm
5532
5533         [ "$RUNAS_ID" = "$UID" ] && \
5534                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5535         [ "$RUNAS_ID" -eq 0 ] && \
5536                 skip_env "RUNAS_ID = 0 -- skipping" && return
5537
5538         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5539         # Check that testing environment is properly set up. Skip if not
5540         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5541                 skip_env "User $RUNAS_ID does not exist - skipping"
5542                 return 0
5543         }
5544         touch $DIR/${tfile}-f{g,u}
5545         test_mkdir $DIR/${tfile}-dg
5546         test_mkdir $DIR/${tfile}-du
5547         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5548         chmod g+s $DIR/${tfile}-{f,d}g
5549         chmod u+s $DIR/${tfile}-{f,d}u
5550         for perm in 777 2777 4777; do
5551                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5552                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5553                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5554                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5555         done
5556         true
5557 }
5558 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5559
5560 # bug 3462 - multiple simultaneous MDC requests
5561 test_73() {
5562         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5563         test_mkdir $DIR/d73-1
5564         test_mkdir $DIR/d73-2
5565         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5566         pid1=$!
5567
5568         lctl set_param fail_loc=0x80000129
5569         $MULTIOP $DIR/d73-1/f73-2 Oc &
5570         sleep 1
5571         lctl set_param fail_loc=0
5572
5573         $MULTIOP $DIR/d73-2/f73-3 Oc &
5574         pid3=$!
5575
5576         kill -USR1 $pid1
5577         wait $pid1 || return 1
5578
5579         sleep 25
5580
5581         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5582         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5583         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5584
5585         rm -rf $DIR/d73-*
5586 }
5587 run_test 73 "multiple MDC requests (should not deadlock)"
5588
5589 test_74a() { # bug 6149, 6184
5590         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5591         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5592         #
5593         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5594         # will spin in a tight reconnection loop
5595         touch $DIR/f74a
5596         $LCTL set_param fail_loc=0x8000030e
5597         # get any lock that won't be difficult - lookup works.
5598         ls $DIR/f74a
5599         $LCTL set_param fail_loc=0
5600         rm -f $DIR/f74a
5601         true
5602 }
5603 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5604
5605 test_74b() { # bug 13310
5606         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5607         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5608         #
5609         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5610         # will spin in a tight reconnection loop
5611         $LCTL set_param fail_loc=0x8000030e
5612         # get a "difficult" lock
5613         touch $DIR/f74b
5614         $LCTL set_param fail_loc=0
5615         rm -f $DIR/f74b
5616         true
5617 }
5618 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5619
5620 test_74c() {
5621         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5622         #define OBD_FAIL_LDLM_NEW_LOCK
5623         $LCTL set_param fail_loc=0x319
5624         touch $DIR/$tfile && error "touch successful"
5625         $LCTL set_param fail_loc=0
5626         true
5627 }
5628 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5629
5630 num_inodes() {
5631         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5632 }
5633
5634 get_inode_slab_tunables() {
5635         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5636 }
5637
5638 set_inode_slab_tunables() {
5639         echo "lustre_inode_cache $1" > /proc/slabinfo
5640 }
5641
5642 test_76() { # Now for bug 20433, added originally in bug 1443
5643         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5644         local SLAB_SETTINGS=`get_inode_slab_tunables`
5645         local CPUS=`getconf _NPROCESSORS_ONLN`
5646         # we cannot set limit below 1 which means 1 inode in each
5647         # per-cpu cache is still allowed
5648         set_inode_slab_tunables "1 1 0"
5649         cancel_lru_locks osc
5650         BEFORE_INODES=$(num_inodes)
5651         echo "before inodes: $BEFORE_INODES"
5652         local COUNT=1000
5653         [ "$SLOW" = "no" ] && COUNT=100
5654         for i in $(seq $COUNT); do
5655                 touch $DIR/$tfile
5656                 rm -f $DIR/$tfile
5657         done
5658         cancel_lru_locks osc
5659         AFTER_INODES=$(num_inodes)
5660         echo "after inodes: $AFTER_INODES"
5661         local wait=0
5662         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5663                 sleep 2
5664                 AFTER_INODES=$(num_inodes)
5665                 wait=$((wait+2))
5666                 echo "wait $wait seconds inodes: $AFTER_INODES"
5667                 if [ $wait -gt 30 ]; then
5668                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5669                 fi
5670         done
5671         set_inode_slab_tunables "$SLAB_SETTINGS"
5672 }
5673 run_test 76 "confirm clients recycle inodes properly ===="
5674
5675
5676 export ORIG_CSUM=""
5677 set_checksums()
5678 {
5679         # Note: in sptlrpc modes which enable its own bulk checksum, the
5680         # original crc32_le bulk checksum will be automatically disabled,
5681         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5682         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5683         # In this case set_checksums() will not be no-op, because sptlrpc
5684         # bulk checksum will be enabled all through the test.
5685
5686         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5687         lctl set_param -n osc.*.checksums $1
5688         return 0
5689 }
5690
5691 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5692                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5693 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5694 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5695 set_checksum_type()
5696 {
5697         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5698         log "set checksum type to $1"
5699         return 0
5700 }
5701 F77_TMP=$TMP/f77-temp
5702 F77SZ=8
5703 setup_f77() {
5704         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5705                 error "error writing to $F77_TMP"
5706 }
5707
5708 test_77a() { # bug 10889
5709         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5710         $GSS && skip "could not run with gss" && return
5711         [ ! -f $F77_TMP ] && setup_f77
5712         set_checksums 1
5713         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5714         set_checksums 0
5715         rm -f $DIR/$tfile
5716 }
5717 run_test 77a "normal checksum read/write operation"
5718
5719 test_77b() { # bug 10889
5720         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5721         $GSS && skip "could not run with gss" && return
5722         [ ! -f $F77_TMP ] && setup_f77
5723         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5724         $LCTL set_param fail_loc=0x80000409
5725         set_checksums 1
5726
5727         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5728                 error "dd error: $?"
5729         $LCTL set_param fail_loc=0
5730
5731         for algo in $CKSUM_TYPES; do
5732                 cancel_lru_locks osc
5733                 set_checksum_type $algo
5734                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5735                 $LCTL set_param fail_loc=0x80000408
5736                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5737                 $LCTL set_param fail_loc=0
5738         done
5739         set_checksums 0
5740         set_checksum_type $ORIG_CSUM_TYPE
5741         rm -f $DIR/$tfile
5742 }
5743 run_test 77b "checksum error on client write, read"
5744
5745 test_77d() { # bug 10889
5746         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5747         $GSS && skip "could not run with gss" && return
5748         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5749         $LCTL set_param fail_loc=0x80000409
5750         set_checksums 1
5751         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5752                 error "direct write: rc=$?"
5753         $LCTL set_param fail_loc=0
5754         set_checksums 0
5755
5756         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5757         $LCTL set_param fail_loc=0x80000408
5758         set_checksums 1
5759         cancel_lru_locks osc
5760         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5761                 error "direct read: rc=$?"
5762         $LCTL set_param fail_loc=0
5763         set_checksums 0
5764 }
5765 run_test 77d "checksum error on OST direct write, read"
5766
5767 test_77f() { # bug 10889
5768         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5769         $GSS && skip "could not run with gss" && return
5770         set_checksums 1
5771         for algo in $CKSUM_TYPES; do
5772                 cancel_lru_locks osc
5773                 set_checksum_type $algo
5774                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5775                 $LCTL set_param fail_loc=0x409
5776                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5777                         error "direct write succeeded"
5778                 $LCTL set_param fail_loc=0
5779         done
5780         set_checksum_type $ORIG_CSUM_TYPE
5781         set_checksums 0
5782 }
5783 run_test 77f "repeat checksum error on write (expect error)"
5784
5785 test_77g() { # bug 10889
5786         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5787         $GSS && skip "could not run with gss" && return
5788         remote_ost_nodsh && skip "remote OST with nodsh" && return
5789
5790         [ ! -f $F77_TMP ] && setup_f77
5791
5792         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5793         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5794         do_facet ost1 lctl set_param fail_loc=0x8000021a
5795         set_checksums 1
5796         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5797                 error "write error: rc=$?"
5798         do_facet ost1 lctl set_param fail_loc=0
5799         set_checksums 0
5800
5801         cancel_lru_locks osc
5802         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5803         do_facet ost1 lctl set_param fail_loc=0x8000021b
5804         set_checksums 1
5805         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5806         do_facet ost1 lctl set_param fail_loc=0
5807         set_checksums 0
5808 }
5809 run_test 77g "checksum error on OST write, read"
5810
5811 test_77i() { # bug 13805
5812         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5813         $GSS && skip "could not run with gss" && return
5814         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5815         lctl set_param fail_loc=0x40b
5816         remount_client $MOUNT
5817         lctl set_param fail_loc=0
5818         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5819                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5820                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5821                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5822         done
5823         remount_client $MOUNT
5824 }
5825 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5826
5827 test_77j() { # bug 13805
5828         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5829         $GSS && skip "could not run with gss" && return
5830         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5831         lctl set_param fail_loc=0x40c
5832         remount_client $MOUNT
5833         lctl set_param fail_loc=0
5834         sleep 2 # wait async osc connect to finish
5835         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5836                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5837                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5838                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5839         done
5840         remount_client $MOUNT
5841 }
5842 run_test 77j "client only supporting ADLER32"
5843
5844 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5845 rm -f $F77_TMP
5846 unset F77_TMP
5847
5848 test_78() { # bug 10901
5849         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5850         remote_ost || { skip_env "local OST" && return; }
5851
5852         NSEQ=5
5853         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5854         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5855         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5856         echo "MemTotal: $MEMTOTAL"
5857
5858         # reserve 256MB of memory for the kernel and other running processes,
5859         # and then take 1/2 of the remaining memory for the read/write buffers.
5860         if [ $MEMTOTAL -gt 512 ] ;then
5861                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5862         else
5863                 # for those poor memory-starved high-end clusters...
5864                 MEMTOTAL=$((MEMTOTAL / 2))
5865         fi
5866         echo "Mem to use for directio: $MEMTOTAL"
5867
5868         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
5869         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
5870         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
5871         SMALLESTOST=$(lfs df $DIR | grep OST | awk '{ print $4 }' | sort -n |
5872                 head -n1)
5873         echo "Smallest OST: $SMALLESTOST"
5874         [[ $SMALLESTOST -lt 10240 ]] &&
5875                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5876
5877         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
5878                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5879
5880         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5881         echo "File size: $F78SIZE"
5882         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5883         for i in $(seq 1 $NSEQ); do
5884                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5885                 echo directIO rdwr round $i of $NSEQ
5886                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5887         done
5888
5889         rm -f $DIR/$tfile
5890 }
5891 run_test 78 "handle large O_DIRECT writes correctly ============"
5892
5893 test_79() { # bug 12743
5894         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5895         wait_delete_completed
5896
5897         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5898         BKFREE=$(calc_osc_kbytes kbytesfree)
5899         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5900
5901         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5902         DFTOTAL=`echo $STRING | cut -d, -f1`
5903         DFUSED=`echo $STRING  | cut -d, -f2`
5904         DFAVAIL=`echo $STRING | cut -d, -f3`
5905         DFFREE=$(($DFTOTAL - $DFUSED))
5906
5907         ALLOWANCE=$((64 * $OSTCOUNT))
5908
5909         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5910            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5911                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5912         fi
5913         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5914            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5915                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5916         fi
5917         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5918            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5919                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5920         fi
5921 }
5922 run_test 79 "df report consistency check ======================="
5923
5924 test_80() { # bug 10718
5925         remote_ost_nodsh && skip "remote OST with nodsh" && return
5926         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5927         # relax strong synchronous semantics for slow backends like ZFS
5928         local soc="obdfilter.*.sync_on_lock_cancel"
5929         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
5930         local hosts=
5931         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
5932                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
5933                           facet_active_host $host; done | sort -u)
5934                 do_nodes $hosts lctl set_param $soc=never
5935         fi
5936
5937         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
5938         sync; sleep 1; sync
5939         local BEFORE=`date +%s`
5940         cancel_lru_locks osc
5941         local AFTER=`date +%s`
5942         local DIFF=$((AFTER-BEFORE))
5943         if [ $DIFF -gt 1 ] ; then
5944                 error "elapsed for 1M@1T = $DIFF"
5945         fi
5946
5947         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
5948
5949         rm -f $DIR/$tfile
5950 }
5951 run_test 80 "Page eviction is equally fast at high offsets too  ===="
5952
5953 test_81a() { # LU-456
5954         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5955         remote_ost_nodsh && skip "remote OST with nodsh" && return
5956         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5957         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
5958         do_facet ost1 lctl set_param fail_loc=0x80000228
5959
5960         # write should trigger a retry and success
5961         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5962         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5963         RC=$?
5964         if [ $RC -ne 0 ] ; then
5965                 error "write should success, but failed for $RC"
5966         fi
5967 }
5968 run_test 81a "OST should retry write when get -ENOSPC ==============="
5969
5970 test_81b() { # LU-456
5971         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5972         remote_ost_nodsh && skip "remote OST with nodsh" && return
5973         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5974         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
5975         do_facet ost1 lctl set_param fail_loc=0x228
5976
5977         # write should retry several times and return -ENOSPC finally
5978         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5979         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5980         RC=$?
5981         ENOSPC=28
5982         if [ $RC -ne $ENOSPC ] ; then
5983                 error "dd should fail for -ENOSPC, but succeed."
5984         fi
5985 }
5986 run_test 81b "OST should return -ENOSPC when retry still fails ======="
5987
5988 test_82() { # LU-1031
5989         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
5990         local gid1=14091995
5991         local gid2=16022000
5992
5993         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
5994         local MULTIPID1=$!
5995         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
5996         local MULTIPID2=$!
5997         kill -USR1 $MULTIPID2
5998         sleep 2
5999         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6000                 error "First grouplock does not block second one"
6001         else
6002                 echo "Second grouplock blocks first one"
6003         fi
6004         kill -USR1 $MULTIPID1
6005         wait $MULTIPID1
6006         wait $MULTIPID2
6007 }
6008 run_test 82 "Basic grouplock test ==============================="
6009
6010 test_99a() {
6011         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6012                 return
6013         test_mkdir -p $DIR/d99cvsroot
6014         chown $RUNAS_ID $DIR/d99cvsroot
6015         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6016         cd $TMP
6017
6018         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6019         cd $oldPWD
6020 }
6021 run_test 99a "cvs init ========================================="
6022
6023 test_99b() {
6024         [ -z "$(which cvs 2>/dev/null)" ] &&
6025                 skip_env "could not find cvs" && return
6026         [ ! -d $DIR/d99cvsroot ] && test_99a
6027         cd /etc/init.d
6028         # some versions of cvs import exit(1) when asked to import links or
6029         # files they can't read.  ignore those files.
6030         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6031                         ! -perm +4 -printf '-I %f\n')
6032         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6033                 d99reposname vtag rtag
6034 }
6035 run_test 99b "cvs import ======================================="
6036
6037 test_99c() {
6038         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6039         [ ! -d $DIR/d99cvsroot ] && test_99b
6040         cd $DIR
6041         test_mkdir -p $DIR/d99reposname
6042         chown $RUNAS_ID $DIR/d99reposname
6043         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6044 }
6045 run_test 99c "cvs checkout ====================================="
6046
6047 test_99d() {
6048         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6049         [ ! -d $DIR/d99cvsroot ] && test_99c
6050         cd $DIR/d99reposname
6051         $RUNAS touch foo99
6052         $RUNAS cvs add -m 'addmsg' foo99
6053 }
6054 run_test 99d "cvs add =========================================="
6055
6056 test_99e() {
6057         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6058         [ ! -d $DIR/d99cvsroot ] && test_99c
6059         cd $DIR/d99reposname
6060         $RUNAS cvs update
6061 }
6062 run_test 99e "cvs update ======================================="
6063
6064 test_99f() {
6065         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6066         [ ! -d $DIR/d99cvsroot ] && test_99d
6067         cd $DIR/d99reposname
6068         $RUNAS cvs commit -m 'nomsg' foo99
6069     rm -fr $DIR/d99cvsroot
6070 }
6071 run_test 99f "cvs commit ======================================="
6072
6073 test_100() {
6074         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6075         [ "$NETTYPE" = tcp ] || \
6076                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
6077                         return ; }
6078
6079         remote_ost_nodsh && skip "remote OST with nodsh" && return
6080         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6081         remote_servers || \
6082                 { skip "useless for local single node setup" && return; }
6083
6084         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6085                 [ "$PROT" != "tcp" ] && continue
6086                 RPORT=$(echo $REMOTE | cut -d: -f2)
6087                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6088
6089                 rc=0
6090                 LPORT=`echo $LOCAL | cut -d: -f2`
6091                 if [ $LPORT -ge 1024 ]; then
6092                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6093                         netstat -tna
6094                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6095                 fi
6096         done
6097         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6098 }
6099 run_test 100 "check local port using privileged port ==========="
6100
6101 function get_named_value()
6102 {
6103     local tag
6104
6105     tag=$1
6106     while read ;do
6107         line=$REPLY
6108         case $line in
6109         $tag*)
6110             echo $line | sed "s/^$tag[ ]*//"
6111             break
6112             ;;
6113         esac
6114     done
6115 }
6116
6117 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6118                    awk '/^max_cached_mb/ { print $2 }')
6119
6120 cleanup_101a() {
6121         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6122         trap 0
6123 }
6124
6125 test_101a() {
6126         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6127         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
6128         local s
6129         local discard
6130         local nreads=10000
6131         local cache_limit=32
6132
6133         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6134         trap cleanup_101a EXIT
6135         $LCTL set_param -n llite.*.read_ahead_stats 0
6136         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6137
6138         #
6139         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6140         #
6141         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6142         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6143
6144         discard=0
6145         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6146                 get_named_value 'read but discarded' | cut -d" " -f1); do
6147                         discard=$(($discard + $s))
6148         done
6149         cleanup_101a
6150
6151         if [[ $(($discard * 10)) -gt $nreads ]]; then
6152                 $LCTL get_param osc.*-osc*.rpc_stats
6153                 $LCTL get_param llite.*.read_ahead_stats
6154                 error "too many ($discard) discarded pages"
6155         fi
6156         rm -f $DIR/$tfile || true
6157 }
6158 run_test 101a "check read-ahead for random reads ================"
6159
6160 setup_test101bc() {
6161         test_mkdir -p $DIR/$tdir
6162         local STRIPE_SIZE=$1
6163         local FILE_LENGTH=$2
6164         STRIPE_OFFSET=0
6165
6166         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6167
6168         local list=$(comma_list $(osts_nodes))
6169         set_osd_param $list '' read_cache_enable 0
6170         set_osd_param $list '' writethrough_cache_enable 0
6171
6172         trap cleanup_test101bc EXIT
6173         # prepare the read-ahead file
6174         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6175
6176         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6177                                 count=$FILE_SIZE_MB 2> /dev/null
6178
6179 }
6180
6181 cleanup_test101bc() {
6182         trap 0
6183         rm -rf $DIR/$tdir
6184         rm -f $DIR/$tfile
6185
6186         local list=$(comma_list $(osts_nodes))
6187         set_osd_param $list '' read_cache_enable 1
6188         set_osd_param $list '' writethrough_cache_enable 1
6189 }
6190
6191 calc_total() {
6192         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6193 }
6194
6195 ra_check_101() {
6196         local READ_SIZE=$1
6197         local STRIPE_SIZE=$2
6198         local FILE_LENGTH=$3
6199         local RA_INC=1048576
6200         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6201         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6202                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6203         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6204                         get_named_value 'read but discarded' |
6205                         cut -d" " -f1 | calc_total)
6206         if [[ $DISCARD -gt $discard_limit ]]; then
6207                 $LCTL get_param llite.*.read_ahead_stats
6208                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6209         else
6210                 echo "Read-ahead success for size ${READ_SIZE}"
6211         fi
6212 }
6213
6214 test_101b() {
6215         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6216         [[ $OSTCOUNT -lt 2 ]] &&
6217                 skip_env "skipping stride IO stride-ahead test" && return
6218         local STRIPE_SIZE=1048576
6219         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6220         if [ $SLOW == "yes" ]; then
6221                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6222         else
6223                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6224         fi
6225
6226         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6227
6228         # prepare the read-ahead file
6229         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6230         cancel_lru_locks osc
6231         for BIDX in 2 4 8 16 32 64 128 256
6232         do
6233                 local BSIZE=$((BIDX*4096))
6234                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6235                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6236                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6237                 $LCTL set_param -n llite.*.read_ahead_stats 0
6238                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6239                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6240                 cancel_lru_locks osc
6241                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6242         done
6243         cleanup_test101bc
6244         true
6245 }
6246 run_test 101b "check stride-io mode read-ahead ================="
6247
6248 test_101c() {
6249         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6250         local STRIPE_SIZE=1048576
6251         local FILE_LENGTH=$((STRIPE_SIZE*100))
6252         local nreads=10000
6253         local osc_rpc_stats
6254
6255         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6256
6257         cancel_lru_locks osc
6258         $LCTL set_param osc.*.rpc_stats 0
6259         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6260         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6261                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6262                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6263                 local size
6264
6265                 if [ $lines -le 20 ]; then
6266                         continue
6267                 fi
6268                 for size in 1 2 4 8; do
6269                         local rpc=$(echo "$stats" |
6270                                     awk '($1 == "'$size':") {print $2; exit; }')
6271                         [ $rpc != 0 ] &&
6272                                 error "Small $((size*4))k read IO $rpc !"
6273                 done
6274                 echo "$osc_rpc_stats check passed!"
6275         done
6276         cleanup_test101bc
6277         true
6278 }
6279 run_test 101c "check stripe_size aligned read-ahead ================="
6280
6281 set_read_ahead() {
6282         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6283         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6284 }
6285
6286 test_101d() {
6287         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6288         local file=$DIR/$tfile
6289         local sz_MB=${FILESIZE_101d:-500}
6290         local ra_MB=${READAHEAD_MB:-40}
6291
6292         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6293         [ $free_MB -lt $sz_MB ] &&
6294                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6295
6296         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6297         $SETSTRIPE -c -1 $file || error "setstripe failed"
6298
6299         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6300         echo Cancel LRU locks on lustre client to flush the client cache
6301         cancel_lru_locks osc
6302
6303         echo Disable read-ahead
6304         local old_READAHEAD=$(set_read_ahead 0)
6305
6306         echo Reading the test file $file with read-ahead disabled
6307         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6308
6309         echo Cancel LRU locks on lustre client to flush the client cache
6310         cancel_lru_locks osc
6311         echo Enable read-ahead with ${ra_MB}MB
6312         set_read_ahead $ra_MB
6313
6314         echo Reading the test file $file with read-ahead enabled
6315         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6316
6317         echo "read-ahead disabled time read $raOFF"
6318         echo "read-ahead enabled  time read $raON"
6319
6320         set_read_ahead $old_READAHEAD
6321         rm -f $file
6322         wait_delete_completed
6323
6324         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6325                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6326 }
6327 run_test 101d "file read with and without read-ahead enabled"
6328
6329 test_101e() {
6330         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6331         local file=$DIR/$tfile
6332         local size_KB=500  #KB
6333         local count=100
6334         local bsize=1024
6335
6336         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6337         local need_KB=$((count * size_KB))
6338         [[ $free_KB -le $need_KB ]] &&
6339                 skip_env "Need free space $need_KB, have $free_KB" && return
6340
6341         echo "Creating $count ${size_KB}K test files"
6342         for ((i = 0; i < $count; i++)); do
6343                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6344         done
6345
6346         echo "Cancel LRU locks on lustre client to flush the client cache"
6347         cancel_lru_locks osc
6348
6349         echo "Reset readahead stats"
6350         $LCTL set_param -n llite.*.read_ahead_stats 0
6351
6352         for ((i = 0; i < $count; i++)); do
6353                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6354         done
6355
6356         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6357                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6358
6359         for ((i = 0; i < $count; i++)); do
6360                 rm -rf $file.$i 2>/dev/null
6361         done
6362
6363         #10000 means 20% reads are missing in readahead
6364         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6365 }
6366 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6367
6368 cleanup_test101f() {
6369     trap 0
6370     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6371     rm -rf $DIR/$tfile 2>/dev/null
6372 }
6373
6374 test_101f() {
6375         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6376     local file=$DIR/$tfile
6377     local nreads=1000
6378
6379     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6380     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6381     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6382     trap cleanup_test101f EXIT
6383
6384     echo Cancel LRU locks on lustre client to flush the client cache
6385     cancel_lru_locks osc
6386
6387     echo Reset readahead stats
6388     $LCTL set_param -n llite.*.read_ahead_stats 0
6389     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6390     # readahead should read in 2M file on second read, so only miss
6391     # 2 pages.
6392     echo Random 4K reads on 2M file for 1000 times
6393     $READS -f $file -s 2097152 -b 4096 -n $nreads
6394
6395     echo checking missing pages
6396     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6397           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6398
6399     [ $miss -lt 3 ] || error "misses too much pages!"
6400     cleanup_test101f
6401 }
6402 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6403
6404 setup_test102() {
6405         test_mkdir -p $DIR/$tdir
6406         chown $RUNAS_ID $DIR/$tdir
6407         STRIPE_SIZE=65536
6408         STRIPE_OFFSET=1
6409         STRIPE_COUNT=$OSTCOUNT
6410         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6411
6412         trap cleanup_test102 EXIT
6413         cd $DIR
6414         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6415         cd $DIR/$tdir
6416         for num in 1 2 3 4; do
6417                 for count in $(seq 1 $STRIPE_COUNT); do
6418                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6419                                 local size=`expr $STRIPE_SIZE \* $num`
6420                                 local file=file"$num-$idx-$count"
6421                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6422                         done
6423                 done
6424         done
6425
6426         cd $DIR
6427         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6428 }
6429
6430 cleanup_test102() {
6431         trap 0
6432         rm -f $TMP/f102.tar
6433         rm -rf $DIR/d0.sanity/d102
6434 }
6435
6436 test_102a() {
6437         local testfile=$DIR/$tfile
6438
6439         touch $testfile
6440
6441         [ "$UID" != 0 ] && skip_env "must run as root" && return
6442         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6443                 skip_env "must have user_xattr" && return
6444
6445         [ -z "$(which setfattr 2>/dev/null)" ] &&
6446                 skip_env "could not find setfattr" && return
6447
6448         echo "set/get xattr..."
6449         setfattr -n trusted.name1 -v value1 $testfile ||
6450                 error "setfattr -n trusted.name1=value1 $testfile failed"
6451         getfattr -n trusted.name1 $testfile 2> /dev/null |
6452           grep "trusted.name1=.value1" ||
6453                 error "$testfile missing trusted.name1=value1"
6454
6455         setfattr -n user.author1 -v author1 $testfile ||
6456                 error "setfattr -n user.author1=author1 $testfile failed"
6457         getfattr -n user.author1 $testfile 2> /dev/null |
6458           grep "user.author1=.author1" ||
6459                 error "$testfile missing trusted.author1=author1"
6460
6461         echo "listxattr..."
6462         setfattr -n trusted.name2 -v value2 $testfile ||
6463                 error "$testfile unable to set trusted.name2"
6464         setfattr -n trusted.name3 -v value3 $testfile ||
6465                 error "$testfile unable to set trusted.name3"
6466         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6467             grep "trusted.name" | wc -l) -eq 3 ] ||
6468                 error "$testfile missing 3 trusted.name xattrs"
6469
6470         setfattr -n user.author2 -v author2 $testfile ||
6471                 error "$testfile unable to set user.author2"
6472         setfattr -n user.author3 -v author3 $testfile ||
6473                 error "$testfile unable to set user.author3"
6474         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6475             grep "user.author" | wc -l) -eq 3 ] ||
6476                 error "$testfile missing 3 user.author xattrs"
6477
6478         echo "remove xattr..."
6479         setfattr -x trusted.name1 $testfile ||
6480                 error "$testfile error deleting trusted.name1"
6481         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6482                 error "$testfile did not delete trusted.name1 xattr"
6483
6484         setfattr -x user.author1 $testfile ||
6485                 error "$testfile error deleting user.author1"
6486         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6487                 error "$testfile did not delete trusted.name1 xattr"
6488
6489         # b10667: setting lustre special xattr be silently discarded
6490         echo "set lustre special xattr ..."
6491         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6492                 error "$testfile allowed setting trusted.lov"
6493 }
6494 run_test 102a "user xattr test =================================="
6495
6496 test_102b() {
6497         [ -z "$(which setfattr 2>/dev/null)" ] &&
6498                 skip_env "could not find setfattr" && return
6499
6500         # b10930: get/set/list trusted.lov xattr
6501         echo "get/set/list trusted.lov xattr ..."
6502         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6503         local testfile=$DIR/$tfile
6504         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6505                 error "setstripe failed"
6506         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6507                 error "getstripe failed"
6508         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6509                 error "can't get trusted.lov from $testfile"
6510
6511         local testfile2=${testfile}2
6512         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6513                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6514
6515         $MCREATE $testfile2
6516         setfattr -n trusted.lov -v $value $testfile2
6517         local stripe_size=$($GETSTRIPE -S $testfile2)
6518         local stripe_count=$($GETSTRIPE -c $testfile2)
6519         [[ $stripe_size -eq 65536 ]] ||
6520                 error "stripe size $stripe_size != 65536"
6521         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6522                 error "stripe count $stripe_count != $STRIPECOUNT"
6523         rm -f $DIR/$tfile
6524 }
6525 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6526
6527 test_102c() {
6528         [ -z "$(which setfattr 2>/dev/null)" ] &&
6529                 skip_env "could not find setfattr" && return
6530
6531         # b10930: get/set/list lustre.lov xattr
6532         echo "get/set/list lustre.lov xattr ..."
6533         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6534         test_mkdir -p $DIR/$tdir
6535         chown $RUNAS_ID $DIR/$tdir
6536         local testfile=$DIR/$tdir/$tfile
6537         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6538                 error "setstripe failed"
6539         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6540                 error "getstripe failed"
6541         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6542         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6543
6544         local testfile2=${testfile}2
6545         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6546                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6547
6548         $RUNAS $MCREATE $testfile2
6549         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6550         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6551         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6552         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6553         [ $stripe_count -eq $STRIPECOUNT ] ||
6554                 error "stripe count $stripe_count != $STRIPECOUNT"
6555 }
6556 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6557
6558 compare_stripe_info1() {
6559         local stripe_index_all_zero=true
6560
6561         for num in 1 2 3 4; do
6562                 for count in $(seq 1 $STRIPE_COUNT); do
6563                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6564                                 local size=$((STRIPE_SIZE * num))
6565                                 local file=file"$num-$offset-$count"
6566                                 stripe_size=$(lfs getstripe -S $PWD/$file)
6567                                 [[ $stripe_size -ne $size ]] &&
6568                                     error "$file: size $stripe_size != $size"
6569                                 stripe_count=$(lfs getstripe -c $PWD/$file)
6570                                 # allow fewer stripes to be created, ORI-601
6571                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6572                                     error "$file: count $stripe_count != $count"
6573                                 stripe_index=$(lfs getstripe -i $PWD/$file)
6574                                 [[ $stripe_index -ne 0 ]] &&
6575                                         stripe_index_all_zero=false
6576                         done
6577                 done
6578         done
6579         $stripe_index_all_zero &&
6580                 error "all files are being extracted starting from OST index 0"
6581         return 0
6582 }
6583
6584 find_lustre_tar() {
6585         [ -n "$(which tar 2>/dev/null)" ] &&
6586                 strings $(which tar) | grep -q "lustre" && echo tar
6587 }
6588
6589 test_102d() {
6590         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6591         # b10930: tar test for trusted.lov xattr
6592         TAR=$(find_lustre_tar)
6593         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6594         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6595         setup_test102
6596         test_mkdir -p $DIR/d102d
6597         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6598         cd $DIR/d102d/$tdir
6599         compare_stripe_info1
6600 }
6601 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6602
6603 test_102f() {
6604         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6605         # b10930: tar test for trusted.lov xattr
6606         TAR=$(find_lustre_tar)
6607         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6608         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6609         setup_test102
6610         test_mkdir -p $DIR/d102f
6611         cd $DIR
6612         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6613         cd $DIR/d102f/$tdir
6614         compare_stripe_info1
6615 }
6616 run_test 102f "tar copy files, not keep osts ==========="
6617
6618 grow_xattr() {
6619         local xsize=${1:-1024}  # in bytes
6620         local file=$DIR/$tfile
6621
6622         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6623                 skip "must have user_xattr" && return 0
6624         [ -z "$(which setfattr 2>/dev/null)" ] &&
6625                 skip_env "could not find setfattr" && return 0
6626         [ -z "$(which getfattr 2>/dev/null)" ] &&
6627                 skip_env "could not find getfattr" && return 0
6628
6629         touch $file
6630
6631         local value="$(generate_string $xsize)"
6632
6633         local xbig=trusted.big
6634         log "save $xbig on $file"
6635         setfattr -n $xbig -v $value $file ||
6636                 error "saving $xbig on $file failed"
6637
6638         local orig=$(get_xattr_value $xbig $file)
6639         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6640
6641         local xsml=trusted.sml
6642         log "save $xsml on $file"
6643         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6644
6645         local new=$(get_xattr_value $xbig $file)
6646         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6647
6648         log "grow $xsml on $file"
6649         setfattr -n $xsml -v "$value" $file ||
6650                 error "growing $xsml on $file failed"
6651
6652         new=$(get_xattr_value $xbig $file)
6653         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6654         log "$xbig still valid after growing $xsml"
6655
6656         rm -f $file
6657 }
6658
6659 test_102h() { # bug 15777
6660         grow_xattr 1024
6661 }
6662 run_test 102h "grow xattr from inside inode to external block"
6663
6664 test_102ha() {
6665         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6666         grow_xattr $(max_xattr_size)
6667 }
6668 run_test 102ha "grow xattr from inside inode to external inode"
6669
6670 test_102i() { # bug 17038
6671         [ -z "$(which getfattr 2>/dev/null)" ] &&
6672                 skip "could not find getfattr" && return
6673         touch $DIR/$tfile
6674         ln -s $DIR/$tfile $DIR/${tfile}link
6675         getfattr -n trusted.lov $DIR/$tfile ||
6676                 error "lgetxattr on $DIR/$tfile failed"
6677         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6678                 grep -i "no such attr" ||
6679                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6680         rm -f $DIR/$tfile $DIR/${tfile}link
6681 }
6682 run_test 102i "lgetxattr test on symbolic link ============"
6683
6684 test_102j() {
6685         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6686         TAR=$(find_lustre_tar)
6687         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6688         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6689         setup_test102 "$RUNAS"
6690         test_mkdir -p $DIR/d102j
6691         chown $RUNAS_ID $DIR/d102j
6692         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6693         cd $DIR/d102j/$tdir
6694         compare_stripe_info1 "$RUNAS"
6695 }
6696 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6697
6698 test_102k() {
6699         [ -z "$(which setfattr 2>/dev/null)" ] &&
6700                 skip "could not find setfattr" && return
6701         touch $DIR/$tfile
6702         # b22187 just check that does not crash for regular file.
6703         setfattr -n trusted.lov $DIR/$tfile
6704         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6705         local test_kdir=$DIR/d102k
6706         test_mkdir $test_kdir
6707         local default_size=`$GETSTRIPE -S $test_kdir`
6708         local default_count=`$GETSTRIPE -c $test_kdir`
6709         local default_offset=`$GETSTRIPE -i $test_kdir`
6710         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6711                 error 'dir setstripe failed'
6712         setfattr -n trusted.lov $test_kdir
6713         local stripe_size=`$GETSTRIPE -S $test_kdir`
6714         local stripe_count=`$GETSTRIPE -c $test_kdir`
6715         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6716         [ $stripe_size -eq $default_size ] ||
6717                 error "stripe size $stripe_size != $default_size"
6718         [ $stripe_count -eq $default_count ] ||
6719                 error "stripe count $stripe_count != $default_count"
6720         [ $stripe_offset -eq $default_offset ] ||
6721                 error "stripe offset $stripe_offset != $default_offset"
6722         rm -rf $DIR/$tfile $test_kdir
6723 }
6724 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6725
6726 test_102l() {
6727         [ -z "$(which getfattr 2>/dev/null)" ] &&
6728                 skip "could not find getfattr" && return
6729
6730         # LU-532 trusted. xattr is invisible to non-root
6731         local testfile=$DIR/$tfile
6732
6733         touch $testfile
6734
6735         echo "listxattr as user..."
6736         chown $RUNAS_ID $testfile
6737         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6738             grep -q "trusted" &&
6739                 error "$testfile trusted xattrs are user visible"
6740
6741         return 0;
6742 }
6743 run_test 102l "listxattr size test =================================="
6744
6745 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6746         local path=$DIR/$tfile
6747         touch $path
6748
6749         listxattr_size_check $path || error "listattr_size_check $path failed"
6750 }
6751 run_test 102m "Ensure listxattr fails on small bufffer ========"
6752
6753 cleanup_test102
6754
6755 getxattr() { # getxattr path name
6756         # Return the base64 encoding of the value of xattr name on path.
6757         local path=$1
6758         local name=$2
6759
6760         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6761         # file: $path
6762         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6763         #
6764         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6765
6766         getfattr --absolute-names --encoding=base64 --name=$name $path |
6767                 awk -F= -v name=$name '$1 == name {
6768                         print substr($0, index($0, "=") + 1);
6769         }'
6770 }
6771
6772 test_102n() { # LU-4101 mdt: protect internal xattrs
6773         local file0=$DIR/$tfile.0
6774         local file1=$DIR/$tfile.1
6775         local xattr0=$TMP/$tfile.0
6776         local xattr1=$TMP/$tfile.1
6777         local name
6778         local value
6779
6780         [ -z "$(which setfattr 2>/dev/null)" ] &&
6781                 skip "could not find setfattr" && return
6782
6783         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6784         then
6785                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6786                 return
6787         fi
6788
6789         rm -rf $file0 $file1 $xattr0 $xattr1
6790         touch $file0 $file1
6791
6792         # Get 'before' xattrs of $file1.
6793         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6794
6795         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6796                 # Try to copy xattr from $file0 to $file1.
6797                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6798
6799                 setfattr --name=trusted.$name --value="$value" $file1 ||
6800                         error "setxattr 'trusted.$name' failed"
6801
6802                 # Try to set a garbage xattr.
6803                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6804
6805                 setfattr --name=trusted.$name --value="$value" $file1 ||
6806                         error "setxattr 'trusted.$name' failed"
6807
6808                 # Try to remove the xattr from $file1. We don't care if this
6809                 # appears to succeed or fail, we just don't want there to be
6810                 # any changes or crashes.
6811                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6812         done
6813
6814         # Get 'after' xattrs of file1.
6815         getfattr --absolute-names --dump --match=- $file1 > $xattr1
6816
6817         if ! diff $xattr0 $xattr1; then
6818                 error "before and after xattrs of '$file1' differ"
6819         fi
6820
6821         rm -rf $file0 $file1 $xattr0 $xattr1
6822
6823         return 0
6824 }
6825 run_test 102n "silently ignore setxattr on internal trusted xattrs"
6826
6827 test_102p() { # LU-4703 setxattr did not check ownership
6828         local testfile=$DIR/$tfile
6829
6830         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
6831                 skip "MDS needs to be at least 2.5.56" && return
6832
6833         touch $testfile
6834
6835         echo "setfacl as user..."
6836         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
6837         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
6838
6839         echo "setfattr as user..."
6840         setfacl -m "u:$RUNAS_ID:---" $testfile
6841         $RUNAS setfattr -x system.posix_acl_access $testfile
6842         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
6843 }
6844 run_test 102p "check setxattr(2) correctly fails without permission"
6845
6846 run_acl_subtest()
6847 {
6848     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6849     return $?
6850 }
6851
6852 test_103a() {
6853         [ "$UID" != 0 ] && skip_env "must run as root" && return
6854         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6855                 skip "must have acl enabled" && return
6856         [ -z "$(which setfacl 2>/dev/null)" ] &&
6857                 skip_env "could not find setfacl" && return
6858         $GSS && skip "could not run under gss" && return
6859
6860         declare -a identity_old
6861
6862         for num in $(seq $MDSCOUNT); do
6863                 switch_identity $num true || identity_old[$num]=$?
6864         done
6865
6866         SAVE_UMASK=$(umask)
6867         umask 0022
6868         cd $DIR
6869
6870         echo "performing cp ..."
6871         run_acl_subtest cp || error "run_acl_subtest cp failed"
6872         echo "performing getfacl-noacl..."
6873         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
6874         echo "performing misc..."
6875         run_acl_subtest misc || error  "misc test failed"
6876         echo "performing permissions..."
6877         run_acl_subtest permissions || error "permissions failed"
6878         echo "performing setfacl..."
6879         run_acl_subtest setfacl || error  "setfacl test failed"
6880
6881         # inheritance test got from HP
6882         echo "performing inheritance..."
6883         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
6884         chmod +x make-tree || error "chmod +x failed"
6885         run_acl_subtest inheritance || error "inheritance test failed"
6886         rm -f make-tree
6887
6888         echo "LU-974 ignore umask when acl is enabled..."
6889         run_acl_subtest 974 || error "LU-974 umask test failed"
6890         if [ $MDSCOUNT -ge 2 ]; then
6891                 run_acl_subtest 974_remote ||
6892                         error "LU-974 umask test failed under remote dir"
6893         fi
6894
6895         echo "LU-2561 newly created file is same size as directory..."
6896         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
6897                 run_acl_subtest 2561 || error "LU-2561 test failed"
6898         else
6899                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
6900         fi
6901
6902         run_acl_subtest 4924 || error "LU-4924 test failed"
6903
6904         cd $SAVE_PWD
6905         umask $SAVE_UMASK
6906
6907         for num in $(seq $MDSCOUNT); do
6908                 if [ "${identity_old[$num]}" = 1 ]; then
6909                         switch_identity $num false || identity_old[$num]=$?
6910                 fi
6911         done
6912 }
6913 run_test 103a "acl test ========================================="
6914
6915 test_103b() {
6916         local noacl=false
6917         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
6918         local mountopts=$MDS_MOUNT_OPTS
6919
6920         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
6921                 noacl=true
6922         else
6923                 # stop the MDT
6924                 stop $SINGLEMDS || error "failed to stop MDT."
6925                 # remount the MDT
6926                 if [ -z "$MDS_MOUNT_OPTS" ]; then
6927                         MDS_MOUNT_OPTS="-o noacl"
6928                 else
6929                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
6930                 fi
6931                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
6932                         error "failed to start MDT."
6933                 MDS_MOUNT_OPTS=$mountopts
6934         fi
6935
6936         touch $DIR/$tfile
6937         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
6938
6939         if ! $noacl; then
6940                 # stop the MDT
6941                 stop $SINGLEMDS || error "failed to stop MDT."
6942                 # remount the MDT
6943                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
6944                         error "failed to start MDT."
6945         fi
6946
6947         true
6948 }
6949 run_test 103b "MDS mount option 'noacl'"
6950
6951 test_103c() {
6952         mkdir -p $DIR/$tdir
6953         cp -rp $DIR/$tdir $DIR/$tdir.bak
6954
6955         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
6956                 error "$DIR/$tdir shouldn't contain default ACL"
6957         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
6958                 error "$DIR/$tdir.bak shouldn't contain default ACL"
6959         true
6960 }
6961 run_test 103c "'cp -rp' won't set empty acl"
6962
6963 test_104a() {
6964         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6965         touch $DIR/$tfile
6966         lfs df || error "lfs df failed"
6967         lfs df -ih || error "lfs df -ih failed"
6968         lfs df -h $DIR || error "lfs df -h $DIR failed"
6969         lfs df -i $DIR || error "lfs df -i $DIR failed"
6970         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
6971         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
6972
6973         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
6974         lctl --device %$OSC deactivate
6975         lfs df || error "lfs df with deactivated OSC failed"
6976         lctl --device %$OSC activate
6977         # wait the osc back to normal
6978         wait_osc_import_state client ost FULL
6979
6980         lfs df || error "lfs df with reactivated OSC failed"
6981         rm -f $DIR/$tfile
6982 }
6983 run_test 104a "lfs df [-ih] [path] test ========================="
6984
6985 test_104b() {
6986         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6987         [ $RUNAS_ID -eq $UID ] &&
6988                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6989         chmod 666 /dev/obd
6990         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
6991                         grep "Permission denied" | wc -l)))
6992         if [ $denied_cnt -ne 0 ]; then
6993                 error "lfs check servers test failed"
6994         fi
6995 }
6996 run_test 104b "$RUNAS lfs check servers test ===================="
6997
6998 test_105a() {
6999         # doesn't work on 2.4 kernels
7000         touch $DIR/$tfile
7001         if $(flock_is_enabled); then
7002                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7003         else
7004                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7005         fi
7006         rm -f $DIR/$tfile
7007 }
7008 run_test 105a "flock when mounted without -o flock test ========"
7009
7010 test_105b() {
7011         touch $DIR/$tfile
7012         if $(flock_is_enabled); then
7013                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7014         else
7015                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7016         fi
7017         rm -f $DIR/$tfile
7018 }
7019 run_test 105b "fcntl when mounted without -o flock test ========"
7020
7021 test_105c() {
7022         touch $DIR/$tfile
7023         if $(flock_is_enabled); then
7024                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7025         else
7026                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7027         fi
7028         rm -f $DIR/$tfile
7029 }
7030 run_test 105c "lockf when mounted without -o flock test ========"
7031
7032 test_105d() { # bug 15924
7033         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7034         test_mkdir -p $DIR/$tdir
7035         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7036         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7037         $LCTL set_param fail_loc=0x80000315
7038         flocks_test 2 $DIR/$tdir
7039 }
7040 run_test 105d "flock race (should not freeze) ========"
7041
7042 test_105e() { # bug 22660 && 22040
7043         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7044         touch $DIR/$tfile
7045         flocks_test 3 $DIR/$tfile
7046 }
7047 run_test 105e "Two conflicting flocks from same process ======="
7048
7049 test_106() { #bug 10921
7050         test_mkdir -p $DIR/$tdir
7051         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7052         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7053 }
7054 run_test 106 "attempt exec of dir followed by chown of that dir"
7055
7056 test_107() {
7057         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7058         CDIR=`pwd`
7059         cd $DIR
7060
7061         local file=core
7062         rm -f $file
7063
7064         local save_pattern=$(sysctl -n kernel.core_pattern)
7065         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7066         sysctl -w kernel.core_pattern=$file
7067         sysctl -w kernel.core_uses_pid=0
7068
7069         ulimit -c unlimited
7070         sleep 60 &
7071         SLEEPPID=$!
7072
7073         sleep 1
7074
7075         kill -s 11 $SLEEPPID
7076         wait $SLEEPPID
7077         if [ -e $file ]; then
7078                 size=`stat -c%s $file`
7079                 [ $size -eq 0 ] && error "Fail to create core file $file"
7080         else
7081                 error "Fail to create core file $file"
7082         fi
7083         rm -f $file
7084         sysctl -w kernel.core_pattern=$save_pattern
7085         sysctl -w kernel.core_uses_pid=$save_uses_pid
7086         cd $CDIR
7087 }
7088 run_test 107 "Coredump on SIG"
7089
7090 test_110() {
7091         test_mkdir -p $DIR/$tdir
7092         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7093                 error "mkdir with 255 char failed"
7094         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7095                 error "mkdir with 256 char should fail, but did not"
7096         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7097                 error "create with 255 char failed"
7098         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7099                 error "create with 256 char should fail, but did not"
7100
7101         ls -l $DIR/$tdir
7102         rm -rf $DIR/$tdir
7103 }
7104 run_test 110 "filename length checking"
7105
7106 test_115() {
7107         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7108         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
7109                 tail -1 | cut -c11-20)
7110         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
7111         echo "Starting with $OSTIO_pre threads"
7112
7113         NUMTEST=20000
7114         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7115         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
7116         echo "$NUMTEST creates/unlinks"
7117         test_mkdir -p $DIR/$tdir
7118         createmany -o $DIR/$tdir/$tfile $NUMTEST
7119         unlinkmany $DIR/$tdir/$tfile $NUMTEST
7120
7121         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
7122                 tail -1 | cut -c11-20)
7123
7124         # don't return an error
7125         [ $OSTIO_post == $OSTIO_pre ] && echo \
7126             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
7127             echo "This may be fine, depending on what ran before this test" &&
7128             echo "and how fast this system is." && return
7129
7130         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
7131 }
7132 run_test 115 "verify dynamic thread creation===================="
7133
7134 free_min_max () {
7135         wait_delete_completed
7136         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7137         echo OST kbytes available: ${AVAIL[@]}
7138         MAXI=0; MAXV=${AVAIL[0]}
7139         MINI=0; MINV=${AVAIL[0]}
7140         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7141                 #echo OST $i: ${AVAIL[i]}kb
7142                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7143                         MAXV=${AVAIL[i]}; MAXI=$i
7144                 fi
7145                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7146                         MINV=${AVAIL[i]}; MINI=$i
7147                 fi
7148         done
7149         echo Min free space: OST $MINI: $MINV
7150         echo Max free space: OST $MAXI: $MAXV
7151 }
7152
7153 test_116a() { # was previously test_116()
7154         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7155         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
7156
7157         echo -n "Free space priority "
7158         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7159                 head -n1
7160         declare -a AVAIL
7161         free_min_max
7162
7163         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7164         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7165                 && return
7166         trap simple_cleanup_common EXIT
7167
7168
7169         # Check if we need to generate uneven OSTs
7170         test_mkdir -p $DIR/$tdir/OST${MINI}
7171         local FILL=$(($MINV / 4))
7172         local DIFF=$(($MAXV - $MINV))
7173         local DIFF2=$(($DIFF * 100 / $MINV))
7174
7175         local threshold=$(do_facet $SINGLEMDS \
7176                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7177         threshold=${threshold%%%}
7178         echo -n "Check for uneven OSTs: "
7179         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7180
7181         if [[ $DIFF2 -gt $threshold ]]; then
7182                 echo "ok"
7183                 echo "Don't need to fill OST$MINI"
7184         else
7185                 # generate uneven OSTs. Write 2% over the QOS threshold value
7186                 echo "no"
7187                 DIFF=$(($threshold - $DIFF2 + 2))
7188                 DIFF2=$(( ($MINV * $DIFF)/100 ))
7189                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
7190                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7191                         error "setstripe failed"
7192                 DIFF=$(($DIFF2 / 2048))
7193                 i=0
7194                 while [ $i -lt $DIFF ]; do
7195                         i=$(($i + 1))
7196                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7197                                 bs=2M count=1 2>/dev/null
7198                         echo -n .
7199                 done
7200                 echo .
7201                 sync
7202                 sleep_maxage
7203                 free_min_max
7204         fi
7205
7206         DIFF=$(($MAXV - $MINV))
7207         DIFF2=$(($DIFF * 100 / $MINV))
7208         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
7209         if [[ $DIFF2 -gt $threshold ]]; then
7210                 echo "ok"
7211         else
7212                 echo "failed - QOS mode won't be used"
7213                 skip "QOS imbalance criteria not met"
7214                 simple_cleanup_common
7215                 return
7216         fi
7217
7218         MINI1=$MINI; MINV1=$MINV
7219         MAXI1=$MAXI; MAXV1=$MAXV
7220
7221         # now fill using QOS
7222         $SETSTRIPE -c 1 $DIR/$tdir
7223         FILL=$(($FILL / 200))
7224         if [ $FILL -gt 600 ]; then
7225                 FILL=600
7226         fi
7227         echo "writing $FILL files to QOS-assigned OSTs"
7228         i=0
7229         while [ $i -lt $FILL ]; do
7230                 i=$((i + 1))
7231                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7232                         count=1 2>/dev/null
7233                 echo -n .
7234         done
7235         echo "wrote $i 200k files"
7236         sync
7237         sleep_maxage
7238
7239         echo "Note: free space may not be updated, so measurements might be off"
7240         free_min_max
7241         DIFF2=$(($MAXV - $MINV))
7242         echo "free space delta: orig $DIFF final $DIFF2"
7243         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7244         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
7245         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7246         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
7247         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7248         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7249         [ $DIFF -gt 0 ] &&
7250                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7251
7252         # Figure out which files were written where
7253         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7254                   awk '/'$MINI1': / {print $2; exit}')
7255         echo $UUID
7256         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7257         echo "$MINC files created on smaller OST $MINI1"
7258         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7259                   awk '/'$MAXI1': / {print $2; exit}')
7260         echo $UUID
7261         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7262         echo "$MAXC files created on larger OST $MAXI1"
7263         FILL=$(($MAXC * 100 / $MINC - 100))
7264         [[ $MINC -gt 0 ]] &&
7265                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7266         [[ $MAXC -gt $MINC ]] ||
7267                 error_ignore LU-9 "stripe QOS didn't balance free space"
7268         simple_cleanup_common
7269 }
7270 run_test 116a "stripe QOS: free space balance ==================="
7271
7272 test_116b() { # LU-2093
7273         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7274         [ -z "$($LCTL get_param -n lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr |
7275                 head -1 2>/dev/null)" ] && skip "no QOS" && return
7276 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7277         local old_rr
7278         old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7279                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7280         do_facet $SINGLEMDS lctl set_param \
7281                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7282         mkdir -p $DIR/$tdir
7283         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7284         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7285         do_facet $SINGLEMDS lctl set_param fail_loc=0
7286         rm -rf $DIR/$tdir
7287         do_facet $SINGLEMDS lctl set_param \
7288                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7289 }
7290 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7291
7292 test_117() # bug 10891
7293 {
7294         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7295         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7296         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7297         lctl set_param fail_loc=0x21e
7298         > $DIR/$tfile || error "truncate failed"
7299         lctl set_param fail_loc=0
7300         echo "Truncate succeeded."
7301         rm -f $DIR/$tfile
7302 }
7303 run_test 117 "verify osd extend =========="
7304
7305 NO_SLOW_RESENDCOUNT=4
7306 export OLD_RESENDCOUNT=""
7307 set_resend_count () {
7308         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7309         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7310         lctl set_param -n $PROC_RESENDCOUNT $1
7311         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7312 }
7313
7314 # for reduce test_118* time (b=14842)
7315 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7316
7317 # Reset async IO behavior after error case
7318 reset_async() {
7319         FILE=$DIR/reset_async
7320
7321         # Ensure all OSCs are cleared
7322         $SETSTRIPE -c -1 $FILE
7323         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7324         sync
7325         rm $FILE
7326 }
7327
7328 test_118a() #bug 11710
7329 {
7330         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7331         reset_async
7332
7333         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7334         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7335         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7336
7337         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7338                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7339                 return 1;
7340         fi
7341         rm -f $DIR/$tfile
7342 }
7343 run_test 118a "verify O_SYNC works =========="
7344
7345 test_118b()
7346 {
7347         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7348         remote_ost_nodsh && skip "remote OST with nodsh" && return
7349
7350         reset_async
7351
7352         #define OBD_FAIL_OST_ENOENT 0x217
7353         set_nodes_failloc "$(osts_nodes)" 0x217
7354         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7355         RC=$?
7356         set_nodes_failloc "$(osts_nodes)" 0
7357         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7358         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7359                     grep -c writeback)
7360
7361         if [[ $RC -eq 0 ]]; then
7362                 error "Must return error due to dropped pages, rc=$RC"
7363                 return 1;
7364         fi
7365
7366         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7367                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7368                 return 1;
7369         fi
7370
7371         echo "Dirty pages not leaked on ENOENT"
7372
7373         # Due to the above error the OSC will issue all RPCs syncronously
7374         # until a subsequent RPC completes successfully without error.
7375         $MULTIOP $DIR/$tfile Ow4096yc
7376         rm -f $DIR/$tfile
7377
7378         return 0
7379 }
7380 run_test 118b "Reclaim dirty pages on fatal error =========="
7381
7382 test_118c()
7383 {
7384         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7385
7386         # for 118c, restore the original resend count, LU-1940
7387         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7388                                 set_resend_count $OLD_RESENDCOUNT
7389         remote_ost_nodsh && skip "remote OST with nodsh" && return
7390
7391         reset_async
7392
7393         #define OBD_FAIL_OST_EROFS               0x216
7394         set_nodes_failloc "$(osts_nodes)" 0x216
7395
7396         # multiop should block due to fsync until pages are written
7397         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7398         MULTIPID=$!
7399         sleep 1
7400
7401         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7402                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7403         fi
7404
7405         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7406                     grep -c writeback)
7407         if [[ $WRITEBACK -eq 0 ]]; then
7408                 error "No page in writeback, writeback=$WRITEBACK"
7409         fi
7410
7411         set_nodes_failloc "$(osts_nodes)" 0
7412         wait $MULTIPID
7413         RC=$?
7414         if [[ $RC -ne 0 ]]; then
7415                 error "Multiop fsync failed, rc=$RC"
7416         fi
7417
7418         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7419         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7420                     grep -c writeback)
7421         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7422                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7423         fi
7424
7425         rm -f $DIR/$tfile
7426         echo "Dirty pages flushed via fsync on EROFS"
7427         return 0
7428 }
7429 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7430
7431 # continue to use small resend count to reduce test_118* time (b=14842)
7432 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7433
7434 test_118d()
7435 {
7436         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7437         remote_ost_nodsh && skip "remote OST with nodsh" && return
7438
7439         reset_async
7440
7441         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7442         set_nodes_failloc "$(osts_nodes)" 0x214
7443         # multiop should block due to fsync until pages are written
7444         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7445         MULTIPID=$!
7446         sleep 1
7447
7448         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7449                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7450         fi
7451
7452         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7453                     grep -c writeback)
7454         if [[ $WRITEBACK -eq 0 ]]; then
7455                 error "No page in writeback, writeback=$WRITEBACK"
7456         fi
7457
7458         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7459         set_nodes_failloc "$(osts_nodes)" 0
7460
7461         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7462         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7463                     grep -c writeback)
7464         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7465                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7466         fi
7467
7468         rm -f $DIR/$tfile
7469         echo "Dirty pages gaurenteed flushed via fsync"
7470         return 0
7471 }
7472 run_test 118d "Fsync validation inject a delay of the bulk =========="
7473
7474 test_118f() {
7475         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7476         reset_async
7477
7478         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7479         lctl set_param fail_loc=0x8000040a
7480
7481         # Should simulate EINVAL error which is fatal
7482         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7483         RC=$?
7484         if [[ $RC -eq 0 ]]; then
7485                 error "Must return error due to dropped pages, rc=$RC"
7486         fi
7487
7488         lctl set_param fail_loc=0x0
7489
7490         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7491         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7492         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7493                     grep -c writeback)
7494         if [[ $LOCKED -ne 0 ]]; then
7495                 error "Locked pages remain in cache, locked=$LOCKED"
7496         fi
7497
7498         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7499                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7500         fi
7501
7502         rm -f $DIR/$tfile
7503         echo "No pages locked after fsync"
7504
7505         reset_async
7506         return 0
7507 }
7508 run_test 118f "Simulate unrecoverable OSC side error =========="
7509
7510 test_118g() {
7511         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7512         reset_async
7513
7514         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7515         lctl set_param fail_loc=0x406
7516
7517         # simulate local -ENOMEM
7518         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7519         RC=$?
7520
7521         lctl set_param fail_loc=0
7522         if [[ $RC -eq 0 ]]; then
7523                 error "Must return error due to dropped pages, rc=$RC"
7524         fi
7525
7526         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7527         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7528         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7529                         grep -c writeback)
7530         if [[ $LOCKED -ne 0 ]]; then
7531                 error "Locked pages remain in cache, locked=$LOCKED"
7532         fi
7533
7534         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7535                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7536         fi
7537
7538         rm -f $DIR/$tfile
7539         echo "No pages locked after fsync"
7540
7541         reset_async
7542         return 0
7543 }
7544 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7545
7546 test_118h() {
7547         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7548         remote_ost_nodsh && skip "remote OST with nodsh" && return
7549
7550         reset_async
7551
7552         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7553         set_nodes_failloc "$(osts_nodes)" 0x20e
7554         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7555         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7556         RC=$?
7557
7558         set_nodes_failloc "$(osts_nodes)" 0
7559         if [[ $RC -eq 0 ]]; then
7560                 error "Must return error due to dropped pages, rc=$RC"
7561         fi
7562
7563         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7564         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7565         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7566                     grep -c writeback)
7567         if [[ $LOCKED -ne 0 ]]; then
7568                 error "Locked pages remain in cache, locked=$LOCKED"
7569         fi
7570
7571         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7572                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7573         fi
7574
7575         rm -f $DIR/$tfile
7576         echo "No pages locked after fsync"
7577
7578         return 0
7579 }
7580 run_test 118h "Verify timeout in handling recoverables errors  =========="
7581
7582 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7583
7584 test_118i() {
7585         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7586         remote_ost_nodsh && skip "remote OST with nodsh" && return
7587
7588         reset_async
7589
7590         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7591         set_nodes_failloc "$(osts_nodes)" 0x20e
7592
7593         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7594         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7595         PID=$!
7596         sleep 5
7597         set_nodes_failloc "$(osts_nodes)" 0
7598
7599         wait $PID
7600         RC=$?
7601         if [[ $RC -ne 0 ]]; then
7602                 error "got error, but should be not, rc=$RC"
7603         fi
7604
7605         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7606         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7607         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7608         if [[ $LOCKED -ne 0 ]]; then
7609                 error "Locked pages remain in cache, locked=$LOCKED"
7610         fi
7611
7612         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7613                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7614         fi
7615
7616         rm -f $DIR/$tfile
7617         echo "No pages locked after fsync"
7618
7619         return 0
7620 }
7621 run_test 118i "Fix error before timeout in recoverable error  =========="
7622
7623 [ "$SLOW" = "no" ] && set_resend_count 4
7624
7625 test_118j() {
7626         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7627         remote_ost_nodsh && skip "remote OST with nodsh" && return
7628
7629         reset_async
7630
7631         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7632         set_nodes_failloc "$(osts_nodes)" 0x220
7633
7634         # return -EIO from OST
7635         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7636         RC=$?
7637         set_nodes_failloc "$(osts_nodes)" 0x0
7638         if [[ $RC -eq 0 ]]; then
7639                 error "Must return error due to dropped pages, rc=$RC"
7640         fi
7641
7642         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7643         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7644         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7645         if [[ $LOCKED -ne 0 ]]; then
7646                 error "Locked pages remain in cache, locked=$LOCKED"
7647         fi
7648
7649         # in recoverable error on OST we want resend and stay until it finished
7650         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7651                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7652         fi
7653
7654         rm -f $DIR/$tfile
7655         echo "No pages locked after fsync"
7656
7657         return 0
7658 }
7659 run_test 118j "Simulate unrecoverable OST side error =========="
7660
7661 test_118k()
7662 {
7663         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7664         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7665
7666         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7667         set_nodes_failloc "$(osts_nodes)" 0x20e
7668         test_mkdir -p $DIR/$tdir
7669
7670         for ((i=0;i<10;i++)); do
7671                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7672                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7673                 SLEEPPID=$!
7674                 sleep 0.500s
7675                 kill $SLEEPPID
7676                 wait $SLEEPPID
7677         done
7678
7679         set_nodes_failloc "$(osts_nodes)" 0
7680         rm -rf $DIR/$tdir
7681 }
7682 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7683
7684 test_118l()
7685 {
7686         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7687         # LU-646
7688         test_mkdir -p $DIR/$tdir
7689         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7690         rm -rf $DIR/$tdir
7691 }
7692 run_test 118l "fsync dir ========="
7693
7694 test_118m() # LU-3066
7695 {
7696         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7697         test_mkdir -p $DIR/$tdir
7698         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7699         rm -rf $DIR/$tdir
7700 }
7701 run_test 118m "fdatasync dir ========="
7702
7703 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7704
7705 test_119a() # bug 11737
7706 {
7707         BSIZE=$((512 * 1024))
7708         directio write $DIR/$tfile 0 1 $BSIZE
7709         # We ask to read two blocks, which is more than a file size.
7710         # directio will indicate an error when requested and actual
7711         # sizes aren't equeal (a normal situation in this case) and
7712         # print actual read amount.
7713         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7714         if [ "$NOB" != "$BSIZE" ]; then
7715                 error "read $NOB bytes instead of $BSIZE"
7716         fi
7717         rm -f $DIR/$tfile
7718 }
7719 run_test 119a "Short directIO read must return actual read amount"
7720
7721 test_119b() # bug 11737
7722 {
7723         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7724
7725         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7726         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7727         sync
7728         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7729                 error "direct read failed"
7730         rm -f $DIR/$tfile
7731 }
7732 run_test 119b "Sparse directIO read must return actual read amount"
7733
7734 test_119c() # bug 13099
7735 {
7736         BSIZE=1048576
7737         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7738         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7739         rm -f $DIR/$tfile
7740 }
7741 run_test 119c "Testing for direct read hitting hole"
7742
7743 test_119d() # bug 15950
7744 {
7745         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7746         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7747         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7748         BSIZE=1048576
7749         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7750         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7751         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7752         lctl set_param fail_loc=0x40d
7753         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7754         pid_dio=$!
7755         sleep 1
7756         cat $DIR/$tfile > /dev/null &
7757         lctl set_param fail_loc=0
7758         pid_reads=$!
7759         wait $pid_dio
7760         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7761         sleep 2
7762         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7763         error "the read rpcs have not completed in 2s"
7764         rm -f $DIR/$tfile
7765         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7766 }
7767 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7768
7769 test_120a() {
7770         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7771         test_mkdir -p $DIR/$tdir
7772         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7773                skip "no early lock cancel on server" && return 0
7774
7775         lru_resize_disable mdc
7776         lru_resize_disable osc
7777         cancel_lru_locks mdc
7778         # asynchronous object destroy at MDT could cause bl ast to client
7779         cancel_lru_locks osc
7780
7781         stat $DIR/$tdir > /dev/null
7782         can1=$(do_facet $SINGLEMDS \
7783                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7784                awk '/ldlm_cancel/ {print $2}')
7785         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7786                awk '/ldlm_bl_callback/ {print $2}')
7787         test_mkdir -c1 $DIR/$tdir/d1
7788         can2=$(do_facet $SINGLEMDS \
7789                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7790                awk '/ldlm_cancel/ {print $2}')
7791         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7792                awk '/ldlm_bl_callback/ {print $2}')
7793         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7794         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7795         lru_resize_enable mdc
7796         lru_resize_enable osc
7797 }
7798 run_test 120a "Early Lock Cancel: mkdir test"
7799
7800 test_120b() {
7801         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7802         test_mkdir $DIR/$tdir
7803         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7804                skip "no early lock cancel on server" && return 0
7805         lru_resize_disable mdc
7806         lru_resize_disable osc
7807         cancel_lru_locks mdc
7808         stat $DIR/$tdir > /dev/null
7809         can1=$(do_facet $SINGLEMDS \
7810                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7811                awk '/ldlm_cancel/ {print $2}')
7812         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7813                awk '/ldlm_bl_callback/ {print $2}')
7814         touch $DIR/$tdir/f1
7815         can2=$(do_facet $SINGLEMDS \
7816                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7817                awk '/ldlm_cancel/ {print $2}')
7818         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7819                awk '/ldlm_bl_callback/ {print $2}')
7820         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7821         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7822         lru_resize_enable mdc
7823         lru_resize_enable osc
7824 }
7825 run_test 120b "Early Lock Cancel: create test"
7826
7827 test_120c() {
7828         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7829         test_mkdir -c1 $DIR/$tdir
7830         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7831                skip "no early lock cancel on server" && return 0
7832         lru_resize_disable mdc
7833         lru_resize_disable osc
7834         test_mkdir -p -c1 $DIR/$tdir/d1
7835         test_mkdir -p -c1 $DIR/$tdir/d2
7836         touch $DIR/$tdir/d1/f1
7837         cancel_lru_locks mdc
7838         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7839         can1=$(do_facet $SINGLEMDS \
7840                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7841                awk '/ldlm_cancel/ {print $2}')
7842         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7843                awk '/ldlm_bl_callback/ {print $2}')
7844         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7845         can2=$(do_facet $SINGLEMDS \
7846                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7847                awk '/ldlm_cancel/ {print $2}')
7848         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7849                awk '/ldlm_bl_callback/ {print $2}')
7850         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7851         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7852         lru_resize_enable mdc
7853         lru_resize_enable osc
7854 }
7855 run_test 120c "Early Lock Cancel: link test"
7856
7857 test_120d() {
7858         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7859         test_mkdir -p -c1 $DIR/$tdir
7860         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7861                skip "no early lock cancel on server" && return 0
7862         lru_resize_disable mdc
7863         lru_resize_disable osc
7864         touch $DIR/$tdir
7865         cancel_lru_locks mdc
7866         stat $DIR/$tdir > /dev/null
7867         can1=$(do_facet $SINGLEMDS \
7868                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7869                awk '/ldlm_cancel/ {print $2}')
7870         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7871                awk '/ldlm_bl_callback/ {print $2}')
7872         chmod a+x $DIR/$tdir
7873         can2=$(do_facet $SINGLEMDS \
7874                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7875                awk '/ldlm_cancel/ {print $2}')
7876         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7877                awk '/ldlm_bl_callback/ {print $2}')
7878         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7879         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7880         lru_resize_enable mdc
7881         lru_resize_enable osc
7882 }
7883 run_test 120d "Early Lock Cancel: setattr test"
7884
7885 test_120e() {
7886         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7887         test_mkdir -p -c1 $DIR/$tdir
7888         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7889                skip "no early lock cancel on server" && return 0
7890         lru_resize_disable mdc
7891         lru_resize_disable osc
7892         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
7893         cancel_lru_locks mdc
7894         cancel_lru_locks osc
7895         dd if=$DIR/$tdir/f1 of=/dev/null
7896         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
7897         # XXX client can not do early lock cancel of OST lock
7898         # during unlink (LU-4206), so cancel osc lock now.
7899         cancel_lru_locks osc
7900         can1=$(do_facet $SINGLEMDS \
7901                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7902                awk '/ldlm_cancel/ {print $2}')
7903         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7904                awk '/ldlm_bl_callback/ {print $2}')
7905         unlink $DIR/$tdir/f1
7906         sleep 5
7907         can2=$(do_facet $SINGLEMDS \
7908                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7909                awk '/ldlm_cancel/ {print $2}')
7910         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7911                awk '/ldlm_bl_callback/ {print $2}')
7912         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7913         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7914         lru_resize_enable mdc
7915         lru_resize_enable osc
7916 }
7917 run_test 120e "Early Lock Cancel: unlink test"
7918
7919 test_120f() {
7920         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7921         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7922                skip "no early lock cancel on server" && return 0
7923         test_mkdir -p -c1 $DIR/$tdir
7924         lru_resize_disable mdc
7925         lru_resize_disable osc
7926         test_mkdir -p -c1 $DIR/$tdir/d1
7927         test_mkdir -p -c1 $DIR/$tdir/d2
7928         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
7929         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
7930         cancel_lru_locks mdc
7931         cancel_lru_locks osc
7932         dd if=$DIR/$tdir/d1/f1 of=/dev/null
7933         dd if=$DIR/$tdir/d2/f2 of=/dev/null
7934         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
7935         # XXX client can not do early lock cancel of OST lock
7936         # during rename (LU-4206), so cancel osc lock now.
7937         cancel_lru_locks osc
7938         can1=$(do_facet $SINGLEMDS \
7939                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7940                awk '/ldlm_cancel/ {print $2}')
7941         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7942                awk '/ldlm_bl_callback/ {print $2}')
7943         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7944         sleep 5
7945         can2=$(do_facet $SINGLEMDS \
7946                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7947                awk '/ldlm_cancel/ {print $2}')
7948         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7949                awk '/ldlm_bl_callback/ {print $2}')
7950         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7951         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7952         lru_resize_enable mdc
7953         lru_resize_enable osc
7954 }
7955 run_test 120f "Early Lock Cancel: rename test"
7956
7957 test_120g() {
7958         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7959         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7960                skip "no early lock cancel on server" && return 0
7961         lru_resize_disable mdc
7962         lru_resize_disable osc
7963         count=10000
7964         echo create $count files
7965         test_mkdir -p $DIR/$tdir
7966         cancel_lru_locks mdc
7967         cancel_lru_locks osc
7968         t0=`date +%s`
7969
7970         can0=$(do_facet $SINGLEMDS \
7971                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7972                awk '/ldlm_cancel/ {print $2}')
7973         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7974                awk '/ldlm_bl_callback/ {print $2}')
7975         createmany -o $DIR/$tdir/f $count
7976         sync
7977         can1=$(do_facet $SINGLEMDS \
7978                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7979                awk '/ldlm_cancel/ {print $2}')
7980         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7981                awk '/ldlm_bl_callback/ {print $2}')
7982         t1=$(date +%s)
7983         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
7984         echo rm $count files
7985         rm -r $DIR/$tdir
7986         sync
7987         can2=$(do_facet $SINGLEMDS \
7988                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7989                awk '/ldlm_cancel/ {print $2}')
7990         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7991                awk '/ldlm_bl_callback/ {print $2}')
7992         t2=$(date +%s)
7993         echo total: $count removes in $((t2-t1))
7994         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
7995         sleep 2
7996         # wait for commitment of removal
7997         lru_resize_enable mdc
7998         lru_resize_enable osc
7999 }
8000 run_test 120g "Early Lock Cancel: performance test"
8001
8002 test_121() { #bug #10589
8003         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8004         rm -rf $DIR/$tfile
8005         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8006 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8007         lctl set_param fail_loc=0x310
8008         cancel_lru_locks osc > /dev/null
8009         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8010         lctl set_param fail_loc=0
8011         [[ $reads -eq $writes ]] ||
8012                 error "read $reads blocks, must be $writes blocks"
8013 }
8014 run_test 121 "read cancel race ========="
8015
8016 test_123a() { # was test 123, statahead(bug 11401)
8017         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8018         SLOWOK=0
8019         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8020             log "testing on UP system. Performance may be not as good as expected."
8021                         SLOWOK=1
8022         fi
8023
8024         rm -rf $DIR/$tdir
8025         test_mkdir -p $DIR/$tdir
8026         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8027         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8028         MULT=10
8029         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8030                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8031
8032                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8033                 lctl set_param -n llite.*.statahead_max 0
8034                 lctl get_param llite.*.statahead_max
8035                 cancel_lru_locks mdc
8036                 cancel_lru_locks osc
8037                 stime=`date +%s`
8038                 time ls -l $DIR/$tdir | wc -l
8039                 etime=`date +%s`
8040                 delta=$((etime - stime))
8041                 log "ls $i files without statahead: $delta sec"
8042                 lctl set_param llite.*.statahead_max=$max
8043
8044                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8045                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8046                 cancel_lru_locks mdc
8047                 cancel_lru_locks osc
8048                 stime=`date +%s`
8049                 time ls -l $DIR/$tdir | wc -l
8050                 etime=`date +%s`
8051                 delta_sa=$((etime - stime))
8052                 log "ls $i files with statahead: $delta_sa sec"
8053                 lctl get_param -n llite.*.statahead_stats
8054                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8055
8056                 [[ $swrong -lt $ewrong ]] &&
8057                         log "statahead was stopped, maybe too many locks held!"
8058                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8059
8060                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8061                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8062                     lctl set_param -n llite.*.statahead_max 0
8063                     lctl get_param llite.*.statahead_max
8064                     cancel_lru_locks mdc
8065                     cancel_lru_locks osc
8066                     stime=`date +%s`
8067                     time ls -l $DIR/$tdir | wc -l
8068                     etime=`date +%s`
8069                     delta=$((etime - stime))
8070                     log "ls $i files again without statahead: $delta sec"
8071                     lctl set_param llite.*.statahead_max=$max
8072                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8073                         if [  $SLOWOK -eq 0 ]; then
8074                                 error "ls $i files is slower with statahead!"
8075                         else
8076                                 log "ls $i files is slower with statahead!"
8077                         fi
8078                         break
8079                     fi
8080                 fi
8081
8082                 [ $delta -gt 20 ] && break
8083                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8084                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8085         done
8086         log "ls done"
8087
8088         stime=`date +%s`
8089         rm -r $DIR/$tdir
8090         sync
8091         etime=`date +%s`
8092         delta=$((etime - stime))
8093         log "rm -r $DIR/$tdir/: $delta seconds"
8094         log "rm done"
8095         lctl get_param -n llite.*.statahead_stats
8096 }
8097 run_test 123a "verify statahead work"
8098
8099 test_123b () { # statahead(bug 15027)
8100         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8101         test_mkdir -p $DIR/$tdir
8102         createmany -o $DIR/$tdir/$tfile-%d 1000
8103
8104         cancel_lru_locks mdc
8105         cancel_lru_locks osc
8106
8107 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8108         lctl set_param fail_loc=0x80000803
8109         ls -lR $DIR/$tdir > /dev/null
8110         log "ls done"
8111         lctl set_param fail_loc=0x0
8112         lctl get_param -n llite.*.statahead_stats
8113         rm -r $DIR/$tdir
8114         sync
8115
8116 }
8117 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8118
8119 test_124a() {
8120         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8121         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8122                 skip "no lru resize on server" && return 0
8123         local NR=2000
8124         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8125
8126         log "create $NR files at $DIR/$tdir"
8127         createmany -o $DIR/$tdir/f $NR ||
8128                 error "failed to create $NR files in $DIR/$tdir"
8129
8130         cancel_lru_locks mdc
8131         ls -l $DIR/$tdir > /dev/null
8132
8133         local NSDIR=""
8134         local LRU_SIZE=0
8135         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8136                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8137                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8138                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8139                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8140                         log "NSDIR=$NSDIR"
8141                         log "NS=$(basename $NSDIR)"
8142                         break
8143                 fi
8144         done
8145
8146         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8147                 skip "Not enough cached locks created!"
8148                 return 0
8149         fi
8150         log "LRU=$LRU_SIZE"
8151
8152         local SLEEP=30
8153
8154         # We know that lru resize allows one client to hold $LIMIT locks
8155         # for 10h. After that locks begin to be killed by client.
8156         local MAX_HRS=10
8157         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8158         log "LIMIT=$LIMIT"
8159
8160         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8161         # killing locks. Some time was spent for creating locks. This means
8162         # that up to the moment of sleep finish we must have killed some of
8163         # them (10-100 locks). This depends on how fast ther were created.
8164         # Many of them were touched in almost the same moment and thus will
8165         # be killed in groups.
8166         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8167
8168         # Use $LRU_SIZE_B here to take into account real number of locks
8169         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8170         local LRU_SIZE_B=$LRU_SIZE
8171         log "LVF=$LVF"
8172         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8173         log "OLD_LVF=$OLD_LVF"
8174         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8175
8176         # Let's make sure that we really have some margin. Client checks
8177         # cached locks every 10 sec.
8178         SLEEP=$((SLEEP+20))
8179         log "Sleep ${SLEEP} sec"
8180         local SEC=0
8181         while ((SEC<$SLEEP)); do
8182                 echo -n "..."
8183                 sleep 5
8184                 SEC=$((SEC+5))
8185                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8186                 echo -n "$LRU_SIZE"
8187         done
8188         echo ""
8189         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8190         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8191
8192         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8193                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8194                 unlinkmany $DIR/$tdir/f $NR
8195                 return
8196         }
8197
8198         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8199         log "unlink $NR files at $DIR/$tdir"
8200         unlinkmany $DIR/$tdir/f $NR
8201 }
8202 run_test 124a "lru resize ======================================="
8203
8204 get_max_pool_limit()
8205 {
8206         local limit=$($LCTL get_param \
8207                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8208         local max=0
8209         for l in $limit; do
8210                 if [[ $l -gt $max ]]; then
8211                         max=$l
8212                 fi
8213         done
8214         echo $max
8215 }
8216
8217 test_124b() {
8218         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8219         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8220                 skip "no lru resize on server" && return 0
8221
8222         LIMIT=$(get_max_pool_limit)
8223
8224         NR=$(($(default_lru_size)*20))
8225         if [[ $NR -gt $LIMIT ]]; then
8226                 log "Limit lock number by $LIMIT locks"
8227                 NR=$LIMIT
8228         fi
8229         lru_resize_disable mdc
8230         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8231                 error "failed to create $DIR/$tdir/disable_lru_resize"
8232
8233         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8234         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8235         cancel_lru_locks mdc
8236         stime=`date +%s`
8237         PID=""
8238         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8239         PID="$PID $!"
8240         sleep 2
8241         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8242         PID="$PID $!"
8243         sleep 2
8244         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8245         PID="$PID $!"
8246         wait $PID
8247         etime=`date +%s`
8248         nolruresize_delta=$((etime-stime))
8249         log "ls -la time: $nolruresize_delta seconds"
8250         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8251         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8252
8253         lru_resize_enable mdc
8254         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8255                 error "failed to create $DIR/$tdir/enable_lru_resize"
8256
8257         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8258         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8259         cancel_lru_locks mdc
8260         stime=`date +%s`
8261         PID=""
8262         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8263         PID="$PID $!"
8264         sleep 2
8265         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8266         PID="$PID $!"
8267         sleep 2
8268         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8269         PID="$PID $!"
8270         wait $PID
8271         etime=`date +%s`
8272         lruresize_delta=$((etime-stime))
8273         log "ls -la time: $lruresize_delta seconds"
8274         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8275
8276         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8277                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8278         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8279                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8280         else
8281                 log "lru resize performs the same with no lru resize"
8282         fi
8283         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8284 }
8285 run_test 124b "lru resize (performance test) ======================="
8286
8287 test_125() { # 13358
8288         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8289         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8290         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8291         test_mkdir -p $DIR/d125 || error "mkdir failed"
8292         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8293         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8294         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8295 }
8296 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8297
8298 test_126() { # bug 12829/13455
8299         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8300         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8301         $GSS && skip "must run as gss disabled" && return
8302
8303         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8304         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8305         rm -f $DIR/$tfile
8306         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8307 }
8308 run_test 126 "check that the fsgid provided by the client is taken into account"
8309
8310 test_127a() { # bug 15521
8311         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8312         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8313         $LCTL set_param osc.*.stats=0
8314         FSIZE=$((2048 * 1024))
8315         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8316         cancel_lru_locks osc
8317         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8318
8319         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8320         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8321                 echo "got $COUNT $NAME"
8322                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8323                 eval $NAME=$COUNT || error "Wrong proc format"
8324
8325                 case $NAME in
8326                         read_bytes|write_bytes)
8327                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8328                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8329                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8330                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8331                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8332                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8333                                 error "sumsquare is too small: $SUMSQ"
8334                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8335                                 error "sumsquare is too big: $SUMSQ"
8336                         ;;
8337                         *) ;;
8338                 esac
8339         done < $DIR/${tfile}.tmp
8340
8341         #check that we actually got some stats
8342         [ "$read_bytes" ] || error "Missing read_bytes stats"
8343         [ "$write_bytes" ] || error "Missing write_bytes stats"
8344         [ "$read_bytes" != 0 ] || error "no read done"
8345         [ "$write_bytes" != 0 ] || error "no write done"
8346 }
8347 run_test 127a "verify the client stats are sane"
8348
8349 test_127b() { # bug LU-333
8350         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8351         $LCTL set_param llite.*.stats=0
8352         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8353         # perform 2 reads and writes so MAX is different from SUM.
8354         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8355         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8356         cancel_lru_locks osc
8357         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8358         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8359
8360         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8361         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8362                 echo "got $COUNT $NAME"
8363                 eval $NAME=$COUNT || error "Wrong proc format"
8364
8365         case $NAME in
8366                 read_bytes)
8367                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8368                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8369                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8370                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8371                         ;;
8372                 write_bytes)
8373                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8374                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8375                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8376                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8377                         ;;
8378                         *) ;;
8379                 esac
8380         done < $TMP/${tfile}.tmp
8381
8382         #check that we actually got some stats
8383         [ "$read_bytes" ] || error "Missing read_bytes stats"
8384         [ "$write_bytes" ] || error "Missing write_bytes stats"
8385         [ "$read_bytes" != 0 ] || error "no read done"
8386         [ "$write_bytes" != 0 ] || error "no write done"
8387 }
8388 run_test 127b "verify the llite client stats are sane"
8389
8390 test_128() { # bug 15212
8391         touch $DIR/$tfile
8392         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8393                 find $DIR/$tfile
8394                 find $DIR/$tfile
8395         EOF
8396
8397         result=$(grep error $TMP/$tfile.log)
8398         rm -f $DIR/$tfile
8399         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8400 }
8401 run_test 128 "interactive lfs for 2 consecutive find's"
8402
8403 set_dir_limits () {
8404         local mntdev
8405         local canondev
8406         local node
8407
8408         local LDPROC=/proc/fs/ldiskfs
8409         local facets=$(get_facets MDS)
8410
8411         for facet in ${facets//,/ }; do
8412                 canondev=$(ldiskfs_canon \
8413                            *.$(convert_facet2label $facet).mntdev $facet)
8414                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8415                                                 LDPROC=/sys/fs/ldiskfs
8416                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8417         done
8418 }
8419
8420 test_129() {
8421         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8422         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8423                 skip "Only applicable to ldiskfs-based MDTs"
8424                 return
8425         fi
8426         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8427         ENOSPC=28
8428         EFBIG=27
8429
8430         rm -rf $DIR/$tdir
8431         test_mkdir -p $DIR/$tdir
8432
8433         # block size of mds1
8434         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8435         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8436         local MAX=$((MDSBLOCKSIZE * 3))
8437         set_dir_limits $MAX
8438         local I=$(stat -c%s "$DIR/$tdir")
8439         local J=0
8440         local STRIPE_COUNT=1
8441         [[ $MDSCOUNT -ge 2 ]] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8442         MAX=$((MAX*STRIPE_COUNT))
8443         while [[ $I -le $MAX ]]; do
8444                 $MULTIOP $DIR/$tdir/$J Oc
8445                 rc=$?
8446                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8447                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8448                 #and EFBIG for previous versions
8449                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8450                         set_dir_limits 0
8451                         echo "return code $rc received as expected"
8452                         multiop $DIR/$tdir/$J Oc ||
8453                                 error_exit "multiop failed w/o dir size limit"
8454
8455                         I=$(stat -c%s "$DIR/$tdir")
8456
8457                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8458                                         $(version_code 2.4.51) ]
8459                         then
8460                                 [[ $I -eq $MAX ]] && return 0
8461                         else
8462                                 [[ $I -gt $MAX ]] && return 0
8463                         fi
8464                         error_exit "current dir size $I, previous limit $MAX"
8465                 elif [ $rc -ne 0 ]; then
8466                         set_dir_limits 0
8467                         error_exit "return code $rc received instead of expected " \
8468                                    "$EFBIG or $ENOSPC, files in dir $I"
8469                 fi
8470                 J=$((J+1))
8471                 I=$(stat -c%s "$DIR/$tdir")
8472         done
8473
8474         set_dir_limits 0
8475         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8476 }
8477 run_test 129 "test directory size limit ========================"
8478
8479 OLDIFS="$IFS"
8480 cleanup_130() {
8481         trap 0
8482         IFS="$OLDIFS"
8483 }
8484
8485 test_130a() {
8486         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8487         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8488                 return
8489
8490         trap cleanup_130 EXIT RETURN
8491
8492         local fm_file=$DIR/$tfile
8493         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8494         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8495                 error "dd failed for $fm_file"
8496
8497         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8498         filefrag -ves $fm_file
8499         RC=$?
8500         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8501                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8502         [ $RC != 0 ] && error "filefrag $fm_file failed"
8503
8504         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8505                       grep -v "ext:" | grep -v "found")
8506         lun=$($GETSTRIPE -i $fm_file)
8507
8508         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8509         IFS=$'\n'
8510         tot_len=0
8511         for line in $filefrag_op
8512         do
8513                 frag_lun=`echo $line | cut -d: -f5`
8514                 ext_len=`echo $line | cut -d: -f4`
8515                 if (( $frag_lun != $lun )); then
8516                         cleanup_130
8517                         error "FIEMAP on 1-stripe file($fm_file) failed"
8518                         return
8519                 fi
8520                 (( tot_len += ext_len ))
8521         done
8522
8523         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8524                 cleanup_130
8525                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8526                 return
8527         fi
8528
8529         cleanup_130
8530
8531         echo "FIEMAP on single striped file succeeded"
8532 }
8533 run_test 130a "FIEMAP (1-stripe file)"
8534
8535 test_130b() {
8536         [ "$OSTCOUNT" -lt "2" ] &&
8537                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8538
8539         [ "$OSTCOUNT" -ge "10" ] &&
8540                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8541
8542         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8543         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8544                 return
8545
8546         trap cleanup_130 EXIT RETURN
8547
8548         local fm_file=$DIR/$tfile
8549         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8550         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8551                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8552
8553         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8554                 error "dd failed on $fm_file"
8555
8556         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8557         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8558                       grep -v "ext:" | grep -v "found")
8559
8560         last_lun=$(echo $filefrag_op | cut -d: -f5)
8561
8562         IFS=$'\n'
8563         tot_len=0
8564         num_luns=1
8565         for line in $filefrag_op
8566         do
8567                 frag_lun=`echo $line | cut -d: -f5`
8568                 ext_len=`echo $line | cut -d: -f4`
8569                 if (( $frag_lun != $last_lun )); then
8570                         if (( tot_len != 1024 )); then
8571                                 cleanup_130
8572                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8573                                 return
8574                         else
8575                                 (( num_luns += 1 ))
8576                                 tot_len=0
8577                         fi
8578                 fi
8579                 (( tot_len += ext_len ))
8580                 last_lun=$frag_lun
8581         done
8582         if (( num_luns != 2 || tot_len != 1024 )); then
8583                 cleanup_130
8584                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8585                 return
8586         fi
8587
8588         cleanup_130
8589
8590         echo "FIEMAP on 2-stripe file succeeded"
8591 }
8592 run_test 130b "FIEMAP (2-stripe file)"
8593
8594 test_130c() {
8595         [ "$OSTCOUNT" -lt "2" ] &&
8596                 skip_env "skipping FIEMAP on 2-stripe file" && return
8597
8598         [ "$OSTCOUNT" -ge "10" ] &&
8599                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8600
8601         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8602         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8603                 return
8604
8605         trap cleanup_130 EXIT RETURN
8606
8607         local fm_file=$DIR/$tfile
8608         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8609         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8610                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8611
8612         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8613
8614         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8615         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8616
8617         last_lun=`echo $filefrag_op | cut -d: -f5`
8618
8619         IFS=$'\n'
8620         tot_len=0
8621         num_luns=1
8622         for line in $filefrag_op
8623         do
8624                 frag_lun=`echo $line | cut -d: -f5`
8625                 ext_len=`echo $line | cut -d: -f4`
8626                 if (( $frag_lun != $last_lun )); then
8627                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8628                         if (( logical != 512 )); then
8629                                 cleanup_130
8630                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8631                                 return
8632                         fi
8633                         if (( tot_len != 512 )); then
8634                                 cleanup_130
8635                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8636                                 return
8637                         else
8638                                 (( num_luns += 1 ))
8639                                 tot_len=0
8640                         fi
8641                 fi
8642                 (( tot_len += ext_len ))
8643                 last_lun=$frag_lun
8644         done
8645         if (( num_luns != 2 || tot_len != 512 )); then
8646                 cleanup_130
8647                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8648                 return
8649         fi
8650
8651         cleanup_130
8652
8653         echo "FIEMAP on 2-stripe file with hole succeeded"
8654 }
8655 run_test 130c "FIEMAP (2-stripe file with hole)"
8656
8657 test_130d() {
8658         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8659
8660         [ "$OSTCOUNT" -ge "10" ] &&
8661                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8662
8663         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8664         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8665
8666         trap cleanup_130 EXIT RETURN
8667
8668         local fm_file=$DIR/$tfile
8669         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8670         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8671                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8672
8673         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8674         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8675                 error "dd failed on $fm_file"
8676
8677         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8678         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8679                 grep -v "ext:" | grep -v "found"`
8680
8681         last_lun=`echo $filefrag_op | cut -d: -f5`
8682
8683         IFS=$'\n'
8684         tot_len=0
8685         num_luns=1
8686         for line in $filefrag_op
8687         do
8688                 frag_lun=`echo $line | cut -d: -f5`
8689                 ext_len=`echo $line | cut -d: -f4`
8690                 if (( $frag_lun != $last_lun )); then
8691                         if (( tot_len != 1024 )); then
8692                                 cleanup_130
8693                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8694                                 return
8695                         else
8696                                 (( num_luns += 1 ))
8697                                 tot_len=0
8698                         fi
8699                 fi
8700                 (( tot_len += ext_len ))
8701                 last_lun=$frag_lun
8702         done
8703         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8704                 cleanup_130
8705                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8706                 return
8707         fi
8708
8709         cleanup_130
8710
8711         echo "FIEMAP on N-stripe file succeeded"
8712 }
8713 run_test 130d "FIEMAP (N-stripe file)"
8714
8715 test_130e() {
8716         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8717
8718         [ "$OSTCOUNT" -ge "10" ] &&
8719                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8720
8721         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8722         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8723
8724         trap cleanup_130 EXIT RETURN
8725
8726         local fm_file=$DIR/$tfile
8727         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8728         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8729                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8730
8731         NUM_BLKS=512
8732         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8733         for ((i = 0; i < $NUM_BLKS; i++))
8734         do
8735                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8736         done
8737
8738         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8739         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8740
8741         last_lun=`echo $filefrag_op | cut -d: -f5`
8742
8743         IFS=$'\n'
8744         tot_len=0
8745         num_luns=1
8746         for line in $filefrag_op
8747         do
8748                 frag_lun=`echo $line | cut -d: -f5`
8749                 ext_len=`echo $line | cut -d: -f4`
8750                 if (( $frag_lun != $last_lun )); then
8751                         if (( tot_len != $EXPECTED_LEN )); then
8752                                 cleanup_130
8753                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8754                                 return
8755                         else
8756                                 (( num_luns += 1 ))
8757                                 tot_len=0
8758                         fi
8759                 fi
8760                 (( tot_len += ext_len ))
8761                 last_lun=$frag_lun
8762         done
8763         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8764                 cleanup_130
8765                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8766                 return
8767         fi
8768
8769         cleanup_130
8770
8771         echo "FIEMAP with continuation calls succeeded"
8772 }
8773 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8774
8775 # Test for writev/readv
8776 test_131a() {
8777         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8778         error "writev test failed"
8779         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8780         error "readv failed"
8781         rm -f $DIR/$tfile
8782 }
8783 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8784
8785 test_131b() {
8786         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8787         error "append writev test failed"
8788         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8789         error "append writev test failed"
8790         rm -f $DIR/$tfile
8791 }
8792 run_test 131b "test append writev"
8793
8794 test_131c() {
8795         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8796         error "NOT PASS"
8797 }
8798 run_test 131c "test read/write on file w/o objects"
8799
8800 test_131d() {
8801         rwv -f $DIR/$tfile -w -n 1 1572864
8802         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8803         if [ "$NOB" != 1572864 ]; then
8804                 error "Short read filed: read $NOB bytes instead of 1572864"
8805         fi
8806         rm -f $DIR/$tfile
8807 }
8808 run_test 131d "test short read"
8809
8810 test_131e() {
8811         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8812         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8813         error "read hitting hole failed"
8814         rm -f $DIR/$tfile
8815 }
8816 run_test 131e "test read hitting hole"
8817
8818 get_ost_param() {
8819         local token=$1
8820         local gl_sum=0
8821         for node in $(osts_nodes); do
8822                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
8823                 [ x$gl = x"" ] && gl=0
8824                 gl_sum=$((gl_sum + gl))
8825         done
8826         echo $gl_sum
8827 }
8828
8829 som_mode_switch() {
8830         local som=$1
8831         local gl1=$2
8832         local gl2=$3
8833
8834         if [ x$som = x"enabled" ]; then
8835                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
8836                 MOUNT_OPTS=`echo $MOUNT_OPTS |
8837                     sed 's/som_preview,\|,som_preview\|som_preview//g'`
8838                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
8839         else
8840                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
8841                 MOUNT_OPTS="${MOUNT_OPTS:+$MOUNT_OPTS,}som_preview"
8842                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
8843         fi
8844
8845         # do remount to make new mount-conf parameters actual
8846         echo remounting...
8847         sync
8848         stopall
8849         setupall
8850 }
8851
8852 test_132() { #1028, SOM
8853         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8854         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8855         local num=$(get_mds_dir $DIR)
8856         local mymds=mds${num}
8857         local MOUNT_OPTS_SAVE=$MOUNT_OPTS
8858
8859         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8860         cancel_lru_locks osc
8861
8862         som1=$(do_facet $mymds "$LCTL get_param -n mdt.*.som" | head -n 1)
8863
8864         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8865         stat $DIR/$tfile >/dev/null
8866         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8867         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
8868         rm $DIR/$tfile
8869         som_mode_switch $som1 $gl1 $gl2
8870
8871         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8872         cancel_lru_locks osc
8873
8874         som2=$(do_facet $mymds "$LCTL get_param -n mdt.*.som" | head -n 1)
8875         if [ $som1 == $som2 ]; then
8876             error "som is still "$som2
8877             if [ x$som2 = x"enabled" ]; then
8878                 som2="disabled"
8879             else
8880                 som2="enabled"
8881             fi
8882         fi
8883
8884         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8885         stat $DIR/$tfile >/dev/null
8886         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8887         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
8888         som_mode_switch $som2 $gl1 $gl2
8889         MOUNT_OPTS=$MOUNT_OPTS_SAVE
8890 }
8891 run_test 132 "som avoids glimpse rpc"
8892
8893 check_stats() {
8894         local res
8895         local count
8896         case $1 in
8897         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8898                  ;;
8899         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8900                  ;;
8901         *) error "Wrong argument $1" ;;
8902         esac
8903         echo $res
8904         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8905         # if the argument $3 is zero, it means any stat increment is ok.
8906         if [[ $3 -gt 0 ]]; then
8907                 count=$(echo $res | awk '{ print $2 }')
8908                 [[ $count -ne $3 ]] &&
8909                         error "The $2 counter on $1 is wrong - expected $3"
8910         fi
8911 }
8912
8913 test_133a() {
8914         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8915         remote_ost_nodsh && skip "remote OST with nodsh" && return
8916         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8917
8918         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8919                 { skip "MDS doesn't support rename stats"; return; }
8920         local testdir=$DIR/${tdir}/stats_testdir
8921         mkdir -p $DIR/${tdir}
8922
8923         # clear stats.
8924         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8925         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8926
8927         # verify mdt stats first.
8928         mkdir ${testdir} || error "mkdir failed"
8929         check_stats $SINGLEMDS "mkdir" 1
8930         touch ${testdir}/${tfile} || "touch failed"
8931         check_stats $SINGLEMDS "open" 1
8932         check_stats $SINGLEMDS "close" 1
8933         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
8934         check_stats $SINGLEMDS "mknod" 1
8935         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
8936         check_stats $SINGLEMDS "unlink" 1
8937         rm -f ${testdir}/${tfile} || error "file remove failed"
8938         check_stats $SINGLEMDS "unlink" 2
8939
8940         # remove working dir and check mdt stats again.
8941         rmdir ${testdir} || error "rmdir failed"
8942         check_stats $SINGLEMDS "rmdir" 1
8943
8944         local testdir1=$DIR/${tdir}/stats_testdir1
8945         mkdir -p ${testdir}
8946         mkdir -p ${testdir1}
8947         touch ${testdir1}/test1
8948         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
8949         check_stats $SINGLEMDS "crossdir_rename" 1
8950
8951         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
8952         check_stats $SINGLEMDS "samedir_rename" 1
8953
8954         rm -rf $DIR/${tdir}
8955 }
8956 run_test 133a "Verifying MDT stats ========================================"
8957
8958 test_133b() {
8959         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8960         remote_ost_nodsh && skip "remote OST with nodsh" && return
8961         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8962         local testdir=$DIR/${tdir}/stats_testdir
8963         mkdir -p ${testdir} || error "mkdir failed"
8964         touch ${testdir}/${tfile} || "touch failed"
8965         cancel_lru_locks mdc
8966
8967         # clear stats.
8968         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8969         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8970
8971         # extra mdt stats verification.
8972         chmod 444 ${testdir}/${tfile} || error "chmod failed"
8973         check_stats $SINGLEMDS "setattr" 1
8974         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8975         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
8976         then            # LU-1740
8977                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
8978                 check_stats $SINGLEMDS "getattr" 1
8979         fi
8980         $LFS df || error "lfs failed"
8981         check_stats $SINGLEMDS "statfs" 1
8982
8983         rm -rf $DIR/${tdir}
8984 }
8985 run_test 133b "Verifying extra MDT stats =================================="
8986
8987 test_133c() {
8988         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8989         remote_ost_nodsh && skip "remote OST with nodsh" && return
8990         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8991         local testdir=$DIR/${tdir}/stats_testdir
8992         test_mkdir -p ${testdir} || error "mkdir failed"
8993
8994         # verify obdfilter stats.
8995         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8996         sync
8997         cancel_lru_locks osc
8998         wait_delete_completed
8999
9000         # clear stats.
9001         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9002         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9003
9004         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
9005         sync
9006         cancel_lru_locks osc
9007         check_stats ost "write" 1
9008
9009         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9010         check_stats ost "read" 1
9011
9012         > ${testdir}/${tfile} || error "truncate failed"
9013         check_stats ost "punch" 1
9014
9015         rm -f ${testdir}/${tfile} || error "file remove failed"
9016         wait_delete_completed
9017         check_stats ost "destroy" 1
9018
9019         rm -rf $DIR/${tdir}
9020 }
9021 run_test 133c "Verifying OST stats ========================================"
9022
9023 order_2() {
9024         local value=$1
9025         local orig=$value
9026         local order=1
9027
9028         while [ $value -ge 2 ]; do
9029                 order=$((order*2))
9030                 value=$((value/2))
9031         done
9032
9033         if [ $orig -gt $order ]; then
9034                 order=$((order*2))
9035         fi
9036         echo $order
9037 }
9038
9039 size_in_KMGT() {
9040     local value=$1
9041     local size=('K' 'M' 'G' 'T');
9042     local i=0
9043     local size_string=$value
9044
9045     while [ $value -ge 1024 ]; do
9046         if [ $i -gt 3 ]; then
9047             #T is the biggest unit we get here, if that is bigger,
9048             #just return XXXT
9049             size_string=${value}T
9050             break
9051         fi
9052         value=$((value >> 10))
9053         if [ $value -lt 1024 ]; then
9054             size_string=${value}${size[$i]}
9055             break
9056         fi
9057         i=$((i + 1))
9058     done
9059
9060     echo $size_string
9061 }
9062
9063 get_rename_size() {
9064     local size=$1
9065     local context=${2:-.}
9066     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9067                 grep -A1 $context |
9068                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9069     echo $sample
9070 }
9071
9072 test_133d() {
9073         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9074         remote_ost_nodsh && skip "remote OST with nodsh" && return
9075         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9076         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9077         { skip "MDS doesn't support rename stats"; return; }
9078
9079         local testdir1=$DIR/${tdir}/stats_testdir1
9080         local testdir2=$DIR/${tdir}/stats_testdir2
9081
9082         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9083
9084         mkdir -p ${testdir1} || error "mkdir failed"
9085         mkdir -p ${testdir2} || error "mkdir failed"
9086
9087         createmany -o $testdir1/test 512 || error "createmany failed"
9088
9089         # check samedir rename size
9090         mv ${testdir1}/test0 ${testdir1}/test_0
9091
9092         local testdir1_size=$(ls -l $DIR/${tdir} |
9093                 awk '/stats_testdir1/ {print $5}')
9094         local testdir2_size=$(ls -l $DIR/${tdir} |
9095                 awk '/stats_testdir2/ {print $5}')
9096
9097         testdir1_size=$(order_2 $testdir1_size)
9098         testdir2_size=$(order_2 $testdir2_size)
9099
9100         testdir1_size=$(size_in_KMGT $testdir1_size)
9101         testdir2_size=$(size_in_KMGT $testdir2_size)
9102
9103         echo "source rename dir size: ${testdir1_size}"
9104         echo "target rename dir size: ${testdir2_size}"
9105
9106         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9107         eval $cmd || error "$cmd failed"
9108         local samedir=$($cmd | grep 'same_dir')
9109         local same_sample=$(get_rename_size $testdir1_size)
9110         [ -z "$samedir" ] && error "samedir_rename_size count error"
9111         [[ $same_sample -eq 1 ]] ||
9112                 error "samedir_rename_size error $same_sample"
9113         echo "Check same dir rename stats success"
9114
9115         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9116
9117         # check crossdir rename size
9118         mv ${testdir1}/test_0 ${testdir2}/test_0
9119
9120         testdir1_size=$(ls -l $DIR/${tdir} |
9121                 awk '/stats_testdir1/ {print $5}')
9122         testdir2_size=$(ls -l $DIR/${tdir} |
9123                 awk '/stats_testdir2/ {print $5}')
9124
9125         testdir1_size=$(order_2 $testdir1_size)
9126         testdir2_size=$(order_2 $testdir2_size)
9127
9128         testdir1_size=$(size_in_KMGT $testdir1_size)
9129         testdir2_size=$(size_in_KMGT $testdir2_size)
9130
9131         echo "source rename dir size: ${testdir1_size}"
9132         echo "target rename dir size: ${testdir2_size}"
9133
9134         eval $cmd || error "$cmd failed"
9135         local crossdir=$($cmd | grep 'crossdir')
9136         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9137         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9138         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9139         [[ $src_sample -eq 1 ]] ||
9140                 error "crossdir_rename_size error $src_sample"
9141         [[ $tgt_sample -eq 1 ]] ||
9142                 error "crossdir_rename_size error $tgt_sample"
9143         echo "Check cross dir rename stats success"
9144         rm -rf $DIR/${tdir}
9145 }
9146 run_test 133d "Verifying rename_stats ========================================"
9147
9148 test_133e() {
9149         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9150         remote_ost_nodsh && skip "remote OST with nodsh" && return
9151         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9152         local testdir=$DIR/${tdir}/stats_testdir
9153         local ctr f0 f1 bs=32768 count=42 sum
9154
9155         mkdir -p ${testdir} || error "mkdir failed"
9156
9157         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9158
9159         for ctr in {write,read}_bytes; do
9160                 sync
9161                 cancel_lru_locks osc
9162
9163                 do_facet ost1 $LCTL set_param -n \
9164                         "obdfilter.*.exports.clear=clear"
9165
9166                 if [ $ctr = write_bytes ]; then
9167                         f0=/dev/zero
9168                         f1=${testdir}/${tfile}
9169                 else
9170                         f0=${testdir}/${tfile}
9171                         f1=/dev/null
9172                 fi
9173
9174                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9175                         error "dd failed"
9176                 sync
9177                 cancel_lru_locks osc
9178
9179                 sum=$(do_facet ost1 $LCTL get_param \
9180                         "obdfilter.*.exports.*.stats" |
9181                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9182                                 $1 == ctr { sum += $7 }
9183                                 END { printf("%0.0f", sum) }')
9184
9185                 if ((sum != bs * count)); then
9186                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9187                 fi
9188         done
9189
9190         rm -rf $DIR/${tdir}
9191 }
9192 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9193
9194 test_133f() {
9195         local proc_dirs
9196
9197         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9198 /sys/fs/lustre/ /sys/fs/lnet/"
9199         local dir
9200         for dir in $dirs; do
9201                 if [ -d $dir ]; then
9202                         proc_dirs="$proc_dirs $dir"
9203                 fi
9204         done
9205
9206         local facet
9207
9208         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9209         remote_ost_nodsh && skip "remote OST with nodsh" && return
9210         # First without trusting modes.
9211         find $proc_dirs -exec cat '{}' \; &> /dev/null
9212
9213         # Second verifying readability.
9214         find $proc_dirs \
9215                 -type f \
9216                 -exec cat '{}' \; &> /dev/null ||
9217                         error "proc file read failed"
9218
9219         for facet in $SINGLEMDS ost1; do
9220                 do_facet $facet find $proc_dirs \
9221                         ! -name req_history \
9222                         -exec cat '{}' \\\; &> /dev/null
9223
9224                 do_facet $facet find $proc_dirs \
9225                         ! -name req_history \
9226                         -type f \
9227                         -exec cat '{}' \\\; &> /dev/null ||
9228                                 error "proc file read failed"
9229         done
9230 }
9231 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9232
9233 test_133g() {
9234         local proc_dirs
9235
9236         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9237 /sys/fs/lustre/ /sys/fs/lnet/"
9238         local dir
9239         for dir in $dirs; do
9240                 if [ -d $dir ]; then
9241                         proc_dirs="$proc_dirs $dir"
9242                 fi
9243         done
9244
9245         local facet
9246
9247         # Second verifying readability.
9248         find $proc_dirs \
9249                 -type f \
9250                 -not -name force_lbug \
9251                 -not -name changelog_mask \
9252                 -exec badarea_io '{}' \; &> /dev/null ||
9253                 error "find $proc_dirs failed"
9254
9255         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
9256                 skip "Too old lustre on MDS"
9257
9258         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
9259                 skip "Too old lustre on ost1"
9260
9261         for facet in $SINGLEMDS ost1; do
9262                 do_facet $facet find $proc_dirs \
9263                         -type f \
9264                         -not -name force_lbug \
9265                         -not -name changelog_mask \
9266                         -exec badarea_io '{}' \\\; &> /dev/null ||
9267                 error "$facet find $proc_dirs failed"
9268
9269         done
9270
9271         # remount the FS in case writes/reads /proc break the FS
9272         cleanup || error "failed to unmount"
9273         setup || error "failed to setup"
9274         true
9275 }
9276 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9277
9278 test_140() { #bug-17379
9279         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9280         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
9281         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
9282         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
9283
9284         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9285         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9286         local i=0
9287         while i=`expr $i + 1`; do
9288                 test_mkdir -p $i || error "Creating dir $i"
9289                 cd $i || error "Changing to $i"
9290                 ln -s ../stat stat || error "Creating stat symlink"
9291                 # Read the symlink until ELOOP present,
9292                 # not LBUGing the system is considered success,
9293                 # we didn't overrun the stack.
9294                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9295                 [ $ret -ne 0 ] && {
9296                         if [ $ret -eq 40 ]; then
9297                                 break  # -ELOOP
9298                         else
9299                                 error "Open stat symlink"
9300                                 return
9301                         fi
9302                 }
9303         done
9304         i=`expr $i - 1`
9305         echo "The symlink depth = $i"
9306         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9307                                         error "Invalid symlink depth"
9308
9309         # Test recursive symlink
9310         ln -s symlink_self symlink_self
9311         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9312         echo "open symlink_self returns $ret"
9313         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9314 }
9315 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9316
9317 test_150() {
9318         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9319         local TF="$TMP/$tfile"
9320
9321         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9322         cp $TF $DIR/$tfile
9323         cancel_lru_locks osc
9324         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9325         remount_client $MOUNT
9326         df -P $MOUNT
9327         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9328
9329         $TRUNCATE $TF 6000
9330         $TRUNCATE $DIR/$tfile 6000
9331         cancel_lru_locks osc
9332         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9333
9334         echo "12345" >>$TF
9335         echo "12345" >>$DIR/$tfile
9336         cancel_lru_locks osc
9337         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9338
9339         echo "12345" >>$TF
9340         echo "12345" >>$DIR/$tfile
9341         cancel_lru_locks osc
9342         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9343
9344         rm -f $TF
9345         true
9346 }
9347 run_test 150 "truncate/append tests"
9348
9349 #LU-2902 roc_hit was not able to read all values from lproc
9350 function roc_hit_init() {
9351         local list=$(comma_list $(osts_nodes))
9352         local dir=$DIR/$tdir-check
9353         local file=$dir/file
9354         local BEFORE
9355         local AFTER
9356         local idx
9357
9358         test_mkdir -p $dir
9359         #use setstripe to do a write to every ost
9360         for i in $(seq 0 $((OSTCOUNT-1))); do
9361                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9362                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9363                 idx=$(printf %04x $i)
9364                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9365                         awk '$1 == "cache_access" {sum += $7}
9366                                 END { printf("%0.0f", sum) }')
9367
9368                 cancel_lru_locks osc
9369                 cat $file >/dev/null
9370
9371                 AFTER=$(get_osd_param $list *OST*$idx stats |
9372                         awk '$1 == "cache_access" {sum += $7}
9373                                 END { printf("%0.0f", sum) }')
9374
9375                 echo BEFORE:$BEFORE AFTER:$AFTER
9376                 if ! let "AFTER - BEFORE == 4"; then
9377                         rm -rf $dir
9378                         error "roc_hit is not safe to use"
9379                 fi
9380                 rm $file
9381         done
9382
9383         rm -rf $dir
9384 }
9385
9386 function roc_hit() {
9387         local list=$(comma_list $(osts_nodes))
9388         echo $(get_osd_param $list '' stats |
9389                 awk '$1 == "cache_hit" {sum += $7}
9390                         END { printf("%0.0f", sum) }')
9391 }
9392
9393 function set_cache() {
9394         local on=1
9395
9396         if [ "$2" == "off" ]; then
9397                 on=0;
9398         fi
9399         local list=$(comma_list $(osts_nodes))
9400         set_osd_param $list '' $1_cache_enable $on
9401
9402         cancel_lru_locks osc
9403 }
9404
9405 test_151() {
9406         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9407         remote_ost_nodsh && skip "remote OST with nodsh" && return
9408
9409         local CPAGES=3
9410         local list=$(comma_list $(osts_nodes))
9411
9412         # check whether obdfilter is cache capable at all
9413         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9414                 echo "not cache-capable obdfilter"
9415                 return 0
9416         fi
9417
9418         # check cache is enabled on all obdfilters
9419         if get_osd_param $list '' read_cache_enable | grep 0; then
9420                 echo "oss cache is disabled"
9421                 return 0
9422         fi
9423
9424         set_osd_param $list '' writethrough_cache_enable 1
9425
9426         # check write cache is enabled on all obdfilters
9427         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9428                 echo "oss write cache is NOT enabled"
9429                 return 0
9430         fi
9431
9432         roc_hit_init
9433
9434         #define OBD_FAIL_OBD_NO_LRU  0x609
9435         do_nodes $list $LCTL set_param fail_loc=0x609
9436
9437         # pages should be in the case right after write
9438         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9439                 error "dd failed"
9440
9441         local BEFORE=$(roc_hit)
9442         cancel_lru_locks osc
9443         cat $DIR/$tfile >/dev/null
9444         local AFTER=$(roc_hit)
9445
9446         do_nodes $list $LCTL set_param fail_loc=0
9447
9448         if ! let "AFTER - BEFORE == CPAGES"; then
9449                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9450         fi
9451
9452         # the following read invalidates the cache
9453         cancel_lru_locks osc
9454         set_osd_param $list '' read_cache_enable 0
9455         cat $DIR/$tfile >/dev/null
9456
9457         # now data shouldn't be found in the cache
9458         BEFORE=$(roc_hit)
9459         cancel_lru_locks osc
9460         cat $DIR/$tfile >/dev/null
9461         AFTER=$(roc_hit)
9462         if let "AFTER - BEFORE != 0"; then
9463                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9464         fi
9465
9466         set_osd_param $list '' read_cache_enable 1
9467         rm -f $DIR/$tfile
9468 }
9469 run_test 151 "test cache on oss and controls ==============================="
9470
9471 test_152() {
9472         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9473         local TF="$TMP/$tfile"
9474
9475         # simulate ENOMEM during write
9476 #define OBD_FAIL_OST_NOMEM      0x226
9477         lctl set_param fail_loc=0x80000226
9478         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9479         cp $TF $DIR/$tfile
9480         sync || error "sync failed"
9481         lctl set_param fail_loc=0
9482
9483         # discard client's cache
9484         cancel_lru_locks osc
9485
9486         # simulate ENOMEM during read
9487         lctl set_param fail_loc=0x80000226
9488         cmp $TF $DIR/$tfile || error "cmp failed"
9489         lctl set_param fail_loc=0
9490
9491         rm -f $TF
9492 }
9493 run_test 152 "test read/write with enomem ============================"
9494
9495 test_153() {
9496         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9497 }
9498 run_test 153 "test if fdatasync does not crash ======================="
9499
9500 dot_lustre_fid_permission_check() {
9501         local fid=$1
9502         local ffid=$MOUNT/.lustre/fid/$fid
9503         local test_dir=$2
9504
9505         echo "stat fid $fid"
9506         stat $ffid > /dev/null || error "stat $ffid failed."
9507         echo "touch fid $fid"
9508         touch $ffid || error "touch $ffid failed."
9509         echo "write to fid $fid"
9510         cat /etc/hosts > $ffid || error "write $ffid failed."
9511         echo "read fid $fid"
9512         diff /etc/hosts $ffid || error "read $ffid failed."
9513         echo "append write to fid $fid"
9514         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9515         echo "rename fid $fid"
9516         mv $ffid $test_dir/$tfile.1 &&
9517                 error "rename $ffid to $tfile.1 should fail."
9518         touch $test_dir/$tfile.1
9519         mv $test_dir/$tfile.1 $ffid &&
9520                 error "rename $tfile.1 to $ffid should fail."
9521         rm -f $test_dir/$tfile.1
9522         echo "truncate fid $fid"
9523         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9524         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9525                 echo "link fid $fid"
9526                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9527         fi
9528         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9529                 echo "setfacl fid $fid"
9530                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9531                 echo "getfacl fid $fid"
9532                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9533         fi
9534         echo "unlink fid $fid"
9535         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9536         echo "mknod fid $fid"
9537         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9538
9539         fid=[0xf00000400:0x1:0x0]
9540         ffid=$MOUNT/.lustre/fid/$fid
9541
9542         echo "stat non-exist fid $fid"
9543         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9544         echo "write to non-exist fid $fid"
9545         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9546         echo "link new fid $fid"
9547         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9548
9549         mkdir -p $test_dir/$tdir
9550         touch $test_dir/$tdir/$tfile
9551         fid=$($LFS path2fid $test_dir/$tdir)
9552         rc=$?
9553         [ $rc -ne 0 ] &&
9554                 error "error: could not get fid for $test_dir/$dir/$tfile."
9555
9556         ffid=$MOUNT/.lustre/fid/$fid
9557
9558         echo "ls $fid"
9559         ls $ffid > /dev/null || error "ls $ffid failed."
9560         echo "touch $fid/$tfile.1"
9561         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9562
9563         echo "touch $MOUNT/.lustre/fid/$tfile"
9564         touch $MOUNT/.lustre/fid/$tfile && \
9565                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9566
9567         echo "setxattr to $MOUNT/.lustre/fid"
9568         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9569
9570         echo "listxattr for $MOUNT/.lustre/fid"
9571         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9572
9573         echo "delxattr from $MOUNT/.lustre/fid"
9574         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9575
9576         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9577         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9578                 error "touch invalid fid should fail."
9579
9580         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9581         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9582                 error "touch non-normal fid should fail."
9583
9584         echo "rename $tdir to $MOUNT/.lustre/fid"
9585         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9586                 error "rename to $MOUNT/.lustre/fid should fail."
9587
9588         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9589         then            # LU-3547
9590                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9591                 local new_obf_mode=777
9592
9593                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9594                 chmod $new_obf_mode $DIR/.lustre/fid ||
9595                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9596
9597                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9598                 [ $obf_mode -eq $new_obf_mode ] ||
9599                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9600
9601                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9602                 chmod $old_obf_mode $DIR/.lustre/fid ||
9603                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9604         fi
9605
9606         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9607         fid=$($LFS path2fid $test_dir/$tfile-2)
9608
9609         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
9610         then # LU-5424
9611                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9612                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
9613                         error "create lov data thru .lustre failed"
9614         fi
9615         echo "cp /etc/passwd $test_dir/$tfile-2"
9616         cp /etc/passwd $test_dir/$tfile-2 ||
9617                 error "copy to $test_dir/$tfile-2 failed."
9618         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9619         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9620                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9621
9622         rm -rf $test_dir/tfile.lnk
9623         rm -rf $test_dir/$tfile-2
9624 }
9625
9626 test_154A() {
9627         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9628                 skip "Need MDS version at least 2.4.1" && return
9629
9630         touch $DIR/$tfile
9631         local FID=$($LFS path2fid $DIR/$tfile)
9632         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9633
9634         # check that we get the same pathname back
9635         local FOUND=$($LFS fid2path $MOUNT $FID)
9636         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9637         [ "$FOUND" != "$DIR/$tfile" ] &&
9638                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9639
9640         rm -rf $DIR/$tfile
9641 }
9642 run_test 154A "lfs path2fid and fid2path basic checks"
9643
9644 test_154a() {
9645         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9646         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9647                 { skip "Need MDS version at least 2.2.51"; return 0; }
9648         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9649
9650         cp /etc/hosts $DIR/$tfile
9651
9652         fid=$($LFS path2fid $DIR/$tfile)
9653         rc=$?
9654         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9655
9656         dot_lustre_fid_permission_check "$fid" $DIR ||
9657                 error "dot lustre permission check $fid failed"
9658
9659         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9660
9661         touch $MOUNT/.lustre/file &&
9662                 error "creation is not allowed under .lustre"
9663
9664         mkdir $MOUNT/.lustre/dir &&
9665                 error "mkdir is not allowed under .lustre"
9666
9667         rm -rf $DIR/$tfile
9668 }
9669 run_test 154a "Open-by-FID"
9670
9671 test_154b() {
9672         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9673         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9674                 { skip "Need MDS version at least 2.2.51"; return 0; }
9675
9676         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9677
9678         local remote_dir=$DIR/$tdir/remote_dir
9679         local MDTIDX=1
9680         local rc=0
9681
9682         mkdir -p $DIR/$tdir
9683         $LFS mkdir -i $MDTIDX $remote_dir ||
9684                 error "create remote directory failed"
9685
9686         cp /etc/hosts $remote_dir/$tfile
9687
9688         fid=$($LFS path2fid $remote_dir/$tfile)
9689         rc=$?
9690         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9691
9692         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9693                 error "dot lustre permission check $fid failed"
9694         rm -rf $DIR/$tdir
9695 }
9696 run_test 154b "Open-by-FID for remote directory"
9697
9698 test_154c() {
9699         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9700                 skip "Need MDS version at least 2.4.1" && return
9701
9702         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9703         local FID1=$($LFS path2fid $DIR/$tfile.1)
9704         local FID2=$($LFS path2fid $DIR/$tfile.2)
9705         local FID3=$($LFS path2fid $DIR/$tfile.3)
9706
9707         local N=1
9708         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9709                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9710                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9711                 local want=FID$N
9712                 [ "$FID" = "${!want}" ] ||
9713                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9714                 N=$((N + 1))
9715         done
9716
9717         $LFS fid2path $MOUNT $FID1 $FID2 $FID3 | while read PATHNAME; do
9718                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
9719                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
9720                 N=$((N + 1))
9721         done
9722 }
9723 run_test 154c "lfs path2fid and fid2path multiple arguments"
9724
9725 test_154d() {
9726         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
9727                 skip "Need MDS version at least 2.5.53" && return
9728
9729         if remote_mds; then
9730                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
9731         else
9732                 nid="0@lo"
9733         fi
9734         local proc_ofile="mdt.*.exports.'$nid'.open_files"
9735         local fd
9736         local cmd
9737
9738         rm -f $DIR/$tfile
9739         touch $DIR/$tfile
9740
9741         fid=$($LFS path2fid $DIR/$tfile)
9742         # Open the file
9743         fd=$(free_fd)
9744         cmd="exec $fd<$DIR/$tfile"
9745         eval $cmd
9746         fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
9747         echo $fid_list | grep $fid
9748         rc=$?
9749
9750         cmd="exec $fd>/dev/null"
9751         eval $cmd
9752         if [ $rc -ne 0 ]; then
9753                 error "FID $fid not found in open files list $fid_list"
9754         fi
9755 }
9756 run_test 154d "Verify open file fid"
9757
9758 test_154e()
9759 {
9760         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
9761                 skip "Need MDS version at least 2.6.50" && return
9762
9763         if ls -a $MOUNT | grep -q '^\.lustre$'; then
9764                 error ".lustre returned by readdir"
9765         fi
9766 }
9767 run_test 154e ".lustre is not returned by readdir"
9768
9769 test_155_small_load() {
9770     local temp=$TMP/$tfile
9771     local file=$DIR/$tfile
9772
9773     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
9774         error "dd of=$temp bs=6096 count=1 failed"
9775     cp $temp $file
9776     cancel_lru_locks osc
9777     cmp $temp $file || error "$temp $file differ"
9778
9779     $TRUNCATE $temp 6000
9780     $TRUNCATE $file 6000
9781     cmp $temp $file || error "$temp $file differ (truncate1)"
9782
9783     echo "12345" >>$temp
9784     echo "12345" >>$file
9785     cmp $temp $file || error "$temp $file differ (append1)"
9786
9787     echo "12345" >>$temp
9788     echo "12345" >>$file
9789     cmp $temp $file || error "$temp $file differ (append2)"
9790
9791     rm -f $temp $file
9792     true
9793 }
9794
9795 test_155_big_load() {
9796     remote_ost_nodsh && skip "remote OST with nodsh" && return
9797     local temp=$TMP/$tfile
9798     local file=$DIR/$tfile
9799
9800     free_min_max
9801     local cache_size=$(do_facet ost$((MAXI+1)) \
9802         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
9803     local large_file_size=$((cache_size * 2))
9804
9805     echo "OSS cache size: $cache_size KB"
9806     echo "Large file size: $large_file_size KB"
9807
9808     [ $MAXV -le $large_file_size ] && \
9809         skip_env "max available OST size needs > $large_file_size KB" && \
9810         return 0
9811
9812     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
9813
9814     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
9815         error "dd of=$temp bs=$large_file_size count=1k failed"
9816     cp $temp $file
9817     ls -lh $temp $file
9818     cancel_lru_locks osc
9819     cmp $temp $file || error "$temp $file differ"
9820
9821     rm -f $temp $file
9822     true
9823 }
9824
9825 test_155a() {
9826         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9827         set_cache read on
9828         set_cache writethrough on
9829         test_155_small_load
9830 }
9831 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
9832
9833 test_155b() {
9834         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9835         set_cache read on
9836         set_cache writethrough off
9837         test_155_small_load
9838 }
9839 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
9840
9841 test_155c() {
9842         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9843         set_cache read off
9844         set_cache writethrough on
9845         test_155_small_load
9846 }
9847 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
9848
9849 test_155d() {
9850         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9851         set_cache read off
9852         set_cache writethrough off
9853         test_155_small_load
9854 }
9855 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
9856
9857 test_155e() {
9858         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9859         set_cache read on
9860         set_cache writethrough on
9861         test_155_big_load
9862 }
9863 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
9864
9865 test_155f() {
9866         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9867         set_cache read on
9868         set_cache writethrough off
9869         test_155_big_load
9870 }
9871 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
9872
9873 test_155g() {
9874         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9875         set_cache read off
9876         set_cache writethrough on
9877         test_155_big_load
9878 }
9879 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
9880
9881 test_155h() {
9882         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9883         set_cache read off
9884         set_cache writethrough off
9885         test_155_big_load
9886 }
9887 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
9888
9889 test_156() {
9890         remote_ost_nodsh && skip "remote OST with nodsh" && return
9891         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9892         local CPAGES=3
9893         local BEFORE
9894         local AFTER
9895         local file="$DIR/$tfile"
9896
9897         [ "$(facet_fstype ost1)" = "zfs" ] &&
9898                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
9899                 return
9900
9901         roc_hit_init
9902
9903     log "Turn on read and write cache"
9904     set_cache read on
9905     set_cache writethrough on
9906
9907     log "Write data and read it back."
9908     log "Read should be satisfied from the cache."
9909     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9910     BEFORE=`roc_hit`
9911     cancel_lru_locks osc
9912     cat $file >/dev/null
9913     AFTER=`roc_hit`
9914     if ! let "AFTER - BEFORE == CPAGES"; then
9915         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9916     else
9917         log "cache hits:: before: $BEFORE, after: $AFTER"
9918     fi
9919
9920     log "Read again; it should be satisfied from the cache."
9921     BEFORE=$AFTER
9922     cancel_lru_locks osc
9923     cat $file >/dev/null
9924     AFTER=`roc_hit`
9925     if ! let "AFTER - BEFORE == CPAGES"; then
9926         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9927     else
9928         log "cache hits:: before: $BEFORE, after: $AFTER"
9929     fi
9930
9931
9932     log "Turn off the read cache and turn on the write cache"
9933     set_cache read off
9934     set_cache writethrough on
9935
9936     log "Read again; it should be satisfied from the cache."
9937     BEFORE=`roc_hit`
9938     cancel_lru_locks osc
9939     cat $file >/dev/null
9940     AFTER=`roc_hit`
9941     if ! let "AFTER - BEFORE == CPAGES"; then
9942         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9943     else
9944         log "cache hits:: before: $BEFORE, after: $AFTER"
9945     fi
9946
9947     log "Read again; it should not be satisfied from the cache."
9948     BEFORE=$AFTER
9949     cancel_lru_locks osc
9950     cat $file >/dev/null
9951     AFTER=`roc_hit`
9952     if ! let "AFTER - BEFORE == 0"; then
9953         error "IN CACHE: before: $BEFORE, after: $AFTER"
9954     else
9955         log "cache hits:: before: $BEFORE, after: $AFTER"
9956     fi
9957
9958     log "Write data and read it back."
9959     log "Read should be satisfied from the cache."
9960     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9961     BEFORE=`roc_hit`
9962     cancel_lru_locks osc
9963     cat $file >/dev/null
9964     AFTER=`roc_hit`
9965     if ! let "AFTER - BEFORE == CPAGES"; then
9966         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9967     else
9968         log "cache hits:: before: $BEFORE, after: $AFTER"
9969     fi
9970
9971     log "Read again; it should not be satisfied from the cache."
9972     BEFORE=$AFTER
9973     cancel_lru_locks osc
9974     cat $file >/dev/null
9975     AFTER=`roc_hit`
9976     if ! let "AFTER - BEFORE == 0"; then
9977         error "IN CACHE: before: $BEFORE, after: $AFTER"
9978     else
9979         log "cache hits:: before: $BEFORE, after: $AFTER"
9980     fi
9981
9982
9983     log "Turn off read and write cache"
9984     set_cache read off
9985     set_cache writethrough off
9986
9987     log "Write data and read it back"
9988     log "It should not be satisfied from the cache."
9989     rm -f $file
9990     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9991     cancel_lru_locks osc
9992     BEFORE=`roc_hit`
9993     cat $file >/dev/null
9994     AFTER=`roc_hit`
9995         if ! let "AFTER - BEFORE == 0"; then
9996                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9997         else
9998                 log "cache hits:: before: $BEFORE, after: $AFTER"
9999         fi
10000
10001     log "Turn on the read cache and turn off the write cache"
10002     set_cache read on
10003     set_cache writethrough off
10004
10005     log "Write data and read it back"
10006     log "It should not be satisfied from the cache."
10007     rm -f $file
10008     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10009     BEFORE=`roc_hit`
10010     cancel_lru_locks osc
10011     cat $file >/dev/null
10012     AFTER=`roc_hit`
10013         if ! let "AFTER - BEFORE == 0"; then
10014                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10015         else
10016                 log "cache hits:: before: $BEFORE, after: $AFTER"
10017         fi
10018
10019     log "Read again; it should be satisfied from the cache."
10020     BEFORE=`roc_hit`
10021     cancel_lru_locks osc
10022     cat $file >/dev/null
10023     AFTER=`roc_hit`
10024     if ! let "AFTER - BEFORE == CPAGES"; then
10025         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10026     else
10027         log "cache hits:: before: $BEFORE, after: $AFTER"
10028     fi
10029
10030     rm -f $file
10031 }
10032 run_test 156 "Verification of tunables ============================"
10033
10034 #Changelogs
10035 err17935 () {
10036         if [[ $MDSCOUNT -gt 1 ]]; then
10037                 error_ignore bz17935 $*
10038         else
10039                 error $*
10040         fi
10041 }
10042
10043 changelog_chmask()
10044 {
10045         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10046
10047         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
10048
10049         if [ $MASK -eq 1 ]; then
10050                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
10051         else
10052                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
10053         fi
10054 }
10055
10056 changelog_extract_field() {
10057         local mdt=$1
10058         local cltype=$2
10059         local file=$3
10060         local identifier=$4
10061
10062         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
10063                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10064                 tail -1
10065 }
10066
10067 test_160a() {
10068         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10069         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10070         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10071                 { skip "Need MDS version at least 2.2.0"; return; }
10072
10073         local CL_USERS="mdd.$MDT0.changelog_users"
10074         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10075         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10076         echo "Registered as changelog user $USER"
10077         $GET_CL_USERS | grep -q $USER ||
10078                 error "User $USER not found in changelog_users"
10079
10080         # change something
10081         test_mkdir -p $DIR/$tdir/pics/2008/zachy
10082         touch $DIR/$tdir/pics/2008/zachy/timestamp
10083         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
10084         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
10085         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
10086         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
10087         rm $DIR/$tdir/pics/desktop.jpg
10088
10089         $LFS changelog $MDT0 | tail -5
10090
10091         echo "verifying changelog mask"
10092         changelog_chmask "MKDIR"
10093         changelog_chmask "CLOSE"
10094
10095         test_mkdir -p $DIR/$tdir/pics/zach/sofia
10096         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10097
10098         changelog_chmask "MKDIR"
10099         changelog_chmask "CLOSE"
10100
10101         test_mkdir -p $DIR/$tdir/pics/2008/sofia
10102         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10103
10104         $LFS changelog $MDT0
10105         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
10106         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
10107         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
10108         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
10109
10110         # verify contents
10111         echo "verifying target fid"
10112         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
10113         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
10114         [ "$fidc" == "$fidf" ] ||
10115                 err17935 "fid in changelog $fidc != file fid $fidf"
10116         echo "verifying parent fid"
10117         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
10118         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
10119         [ "$fidc" == "$fidf" ] ||
10120                 err17935 "pfid in changelog $fidc != dir fid $fidf"
10121
10122         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10123         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
10124         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10125         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
10126         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
10127                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
10128
10129         MIN_REC=$($GET_CL_USERS |
10130                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
10131         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
10132         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
10133         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
10134                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
10135
10136         # LU-3446 changelog index reset on MDT restart
10137         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10138         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10139         $LFS changelog_clear $MDT0 $USER 0
10140         stop $SINGLEMDS || error "Fail to stop MDT."
10141         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10142         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10143         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
10144         [ $CUR_REC1 == $CUR_REC2 ] ||
10145                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
10146
10147         echo "verifying user deregister"
10148         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10149         $GET_CL_USERS | grep -q $USER &&
10150                 error "User $USER still in changelog_users"
10151
10152         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
10153         if [ $USERS -eq 0 ]; then
10154                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10155                 touch $DIR/$tdir/chloe
10156                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10157                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
10158                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
10159         else
10160                 echo "$USERS other changelog users; can't verify off"
10161         fi
10162 }
10163 run_test 160a "changelog sanity"
10164
10165 test_160b() { # LU-3587
10166         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10167         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10168         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10169                 { skip "Need MDS version at least 2.2.0"; return; }
10170
10171         local CL_USERS="mdd.$MDT0.changelog_users"
10172         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10173         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10174         echo "Registered as changelog user $USER"
10175         $GET_CL_USERS | grep -q $USER ||
10176                 error "User $USER not found in changelog_users"
10177
10178         local LONGNAME1=$(str_repeat a 255)
10179         local LONGNAME2=$(str_repeat b 255)
10180
10181         cd $DIR
10182         echo "creating very long named file"
10183         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
10184         echo "moving very long named file"
10185         mv $LONGNAME1 $LONGNAME2
10186
10187         $LFS changelog $MDT0 | grep RENME
10188
10189         echo "deregistering $USER"
10190         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10191
10192         rm -f $LONGNAME2
10193 }
10194 run_test 160b "Verify that very long rename doesn't crash in changelog"
10195
10196 test_160c() {
10197         local rc=0
10198         local server_version=$(lustre_version_code $SINGLEMDS)
10199
10200         [[ $server_version -gt $(version_code 2.5.57) ]] ||
10201                 [[ $server_version -gt $(version_code 2.5.1) &&
10202                    $server_version -lt $(version_code 2.5.50) ]] ||
10203                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
10204         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10205
10206         # Registration step
10207         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10208                 changelog_register -n)
10209
10210         rm -rf $DIR/$tdir
10211         mkdir -p $DIR/$tdir
10212         $MCREATE $DIR/$tdir/foo_160c
10213         changelog_chmask "TRUNC"
10214         $TRUNCATE $DIR/$tdir/foo_160c 200
10215         changelog_chmask "TRUNC"
10216         $TRUNCATE $DIR/$tdir/foo_160c 199
10217         $LFS changelog $MDT0
10218         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
10219         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
10220         $LFS changelog_clear $MDT0 $USER 0
10221
10222         # Deregistration step
10223         echo "deregistering $USER"
10224         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10225 }
10226 run_test 160c "verify that changelog log catch the truncate event"
10227
10228 test_161a() {
10229         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10230         test_mkdir -p -c1 $DIR/$tdir
10231         cp /etc/hosts $DIR/$tdir/$tfile
10232         test_mkdir -c1 $DIR/$tdir/foo1
10233         test_mkdir -c1 $DIR/$tdir/foo2
10234         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
10235         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
10236         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
10237         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
10238         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
10239         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10240                 $LFS fid2path $DIR $FID
10241                 err17935 "bad link ea"
10242         fi
10243     # middle
10244     rm $DIR/$tdir/foo2/zachary
10245     # last
10246     rm $DIR/$tdir/foo2/thor
10247     # first
10248     rm $DIR/$tdir/$tfile
10249     # rename
10250     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
10251     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
10252         then
10253         $LFS fid2path $DIR $FID
10254         err17935 "bad link rename"
10255     fi
10256     rm $DIR/$tdir/foo2/maggie
10257
10258         # overflow the EA
10259         local longname=filename_avg_len_is_thirty_two_
10260         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
10261                 error "failed to hardlink many files"
10262         links=$($LFS fid2path $DIR $FID | wc -l)
10263         echo -n "${links}/1000 links in link EA"
10264         [[ $links -gt 60 ]] ||
10265                 err17935 "expected at least 60 links in link EA"
10266         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
10267                 error "failed to unlink many hardlinks"
10268 }
10269 run_test 161a "link ea sanity"
10270
10271 test_161b() {
10272         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10273         [ $MDSCOUNT -lt 2 ] &&
10274                 skip "skipping remote directory test" && return
10275         local MDTIDX=1
10276         local remote_dir=$DIR/$tdir/remote_dir
10277
10278         mkdir -p $DIR/$tdir
10279         $LFS mkdir -i $MDTIDX $remote_dir ||
10280                 error "create remote directory failed"
10281
10282         cp /etc/hosts $remote_dir/$tfile
10283         mkdir -p $remote_dir/foo1
10284         mkdir -p $remote_dir/foo2
10285         ln $remote_dir/$tfile $remote_dir/foo1/sofia
10286         ln $remote_dir/$tfile $remote_dir/foo2/zachary
10287         ln $remote_dir/$tfile $remote_dir/foo1/luna
10288         ln $remote_dir/$tfile $remote_dir/foo2/thor
10289
10290         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
10291                      tr -d ']')
10292         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10293                 $LFS fid2path $DIR $FID
10294                 err17935 "bad link ea"
10295         fi
10296         # middle
10297         rm $remote_dir/foo2/zachary
10298         # last
10299         rm $remote_dir/foo2/thor
10300         # first
10301         rm $remote_dir/$tfile
10302         # rename
10303         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
10304         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
10305         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
10306                 $LFS fid2path $DIR $FID
10307                 err17935 "bad link rename"
10308         fi
10309         rm $remote_dir/foo2/maggie
10310
10311         # overflow the EA
10312         local longname=filename_avg_len_is_thirty_two_
10313         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10314                 error "failed to hardlink many files"
10315         links=$($LFS fid2path $DIR $FID | wc -l)
10316         echo -n "${links}/1000 links in link EA"
10317         [[ ${links} -gt 60 ]] ||
10318                 err17935 "expected at least 60 links in link EA"
10319         unlinkmany $remote_dir/foo2/$longname 1000 ||
10320         error "failed to unlink many hardlinks"
10321 }
10322 run_test 161b "link ea sanity under remote directory"
10323
10324 test_161c() {
10325         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10326         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10327         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10328                 skip "Need MDS version at least 2.1.5" && return
10329
10330         # define CLF_RENAME_LAST 0x0001
10331         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10332         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10333                 changelog_register -n)
10334         rm -rf $DIR/$tdir
10335         mkdir -p $DIR/$tdir
10336         touch $DIR/$tdir/foo_161c
10337         touch $DIR/$tdir/bar_161c
10338         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10339         $LFS changelog $MDT0 | grep RENME
10340         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10341                 cut -f5 -d' ')
10342         $LFS changelog_clear $MDT0 $USER 0
10343         if [ x$flags != "x0x1" ]; then
10344                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10345                         $USER
10346                 error "flag $flags is not 0x1"
10347         fi
10348         echo "rename overwrite a target having nlink = 1," \
10349                 "changelog record has flags of $flags"
10350
10351         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10352         touch $DIR/$tdir/foo_161c
10353         touch $DIR/$tdir/bar_161c
10354         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10355         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10356         $LFS changelog $MDT0 | grep RENME
10357         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10358         $LFS changelog_clear $MDT0 $USER 0
10359         if [ x$flags != "x0x0" ]; then
10360                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10361                         $USER
10362                 error "flag $flags is not 0x0"
10363         fi
10364         echo "rename overwrite a target having nlink > 1," \
10365                 "changelog record has flags of $flags"
10366
10367         # rename doesn't overwrite a target (changelog flag 0x0)
10368         touch $DIR/$tdir/foo_161c
10369         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10370         $LFS changelog $MDT0 | grep RENME
10371         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10372         $LFS changelog_clear $MDT0 $USER 0
10373         if [ x$flags != "x0x0" ]; then
10374                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10375                         $USER
10376                 error "flag $flags is not 0x0"
10377         fi
10378         echo "rename doesn't overwrite a target," \
10379                 "changelog record has flags of $flags"
10380
10381         # define CLF_UNLINK_LAST 0x0001
10382         # unlink a file having nlink = 1 (changelog flag 0x1)
10383         rm -f $DIR/$tdir/foo2_161c
10384         $LFS changelog $MDT0 | grep UNLNK
10385         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10386         $LFS changelog_clear $MDT0 $USER 0
10387         if [ x$flags != "x0x1" ]; then
10388                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10389                         $USER
10390                 error "flag $flags is not 0x1"
10391         fi
10392         echo "unlink a file having nlink = 1," \
10393                 "changelog record has flags of $flags"
10394
10395         # unlink a file having nlink > 1 (changelog flag 0x0)
10396         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10397         rm -f $DIR/$tdir/foobar_161c
10398         $LFS changelog $MDT0 | grep UNLNK
10399         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10400         $LFS changelog_clear $MDT0 $USER 0
10401         if [ x$flags != "x0x0" ]; then
10402                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10403                         $USER
10404                 error "flag $flags is not 0x0"
10405         fi
10406         echo "unlink a file having nlink > 1," \
10407                 "changelog record has flags of $flags"
10408         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10409 }
10410 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10411
10412 check_path() {
10413     local expected=$1
10414     shift
10415     local fid=$2
10416
10417     local path=$(${LFS} fid2path $*)
10418     RC=$?
10419
10420     if [ $RC -ne 0 ]; then
10421         err17935 "path looked up of $expected failed. Error $RC"
10422         return $RC
10423     elif [ "${path}" != "${expected}" ]; then
10424         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10425         return 2
10426     fi
10427     echo "fid $fid resolves to path $path (expected $expected)"
10428 }
10429
10430 test_162() {
10431         # Make changes to filesystem
10432         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10433         test_mkdir -p -c1 $DIR/$tdir/d2
10434         touch $DIR/$tdir/d2/$tfile
10435         touch $DIR/$tdir/d2/x1
10436         touch $DIR/$tdir/d2/x2
10437         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
10438         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
10439         # regular file
10440         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10441         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
10442                 error "check path $tdir/d2/$tfile failed"
10443
10444         # softlink
10445         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10446         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10447         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
10448                 error "check path $tdir/d2/p/q/r/slink failed"
10449
10450         # softlink to wrong file
10451         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10452         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10453         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
10454                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
10455
10456         # hardlink
10457         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10458         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10459         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10460         # fid2path dir/fsname should both work
10461         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
10462                 error "check path $tdir/d2/a/b/c/new_file failed"
10463         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
10464                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
10465
10466         # hardlink count: check that there are 2 links
10467         # Doesnt work with CMD yet: 17935
10468         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10469                 err17935 "expected 2 links"
10470
10471         # hardlink indexing: remove the first link
10472         rm $DIR/$tdir/d2/p/q/r/hlink
10473         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
10474                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
10475
10476         return 0
10477 }
10478 run_test 162 "path lookup sanity"
10479
10480 test_162b() {
10481         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10482         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10483
10484         mkdir $DIR/$tdir
10485         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
10486                                 error "create striped dir failed"
10487
10488         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
10489                                         tail -n 1 | awk '{print $2}')
10490         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
10491
10492         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
10493         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
10494
10495         # regular file
10496         for ((i=0;i<5;i++)); do
10497                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
10498                         error "get fid for f$i failed"
10499                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
10500                         error "check path $tdir/striped_dir/f$i failed"
10501
10502                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
10503                         error "get fid for d$i failed"
10504                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
10505                         error "check path $tdir/striped_dir/d$i failed"
10506         done
10507
10508         return 0
10509 }
10510 run_test 162b "striped directory path lookup sanity"
10511
10512 test_169() {
10513         # do directio so as not to populate the page cache
10514         log "creating a 10 Mb file"
10515         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10516         log "starting reads"
10517         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10518         log "truncating the file"
10519         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10520         log "killing dd"
10521         kill %+ || true # reads might have finished
10522         echo "wait until dd is finished"
10523         wait
10524         log "removing the temporary file"
10525         rm -rf $DIR/$tfile || error "tmp file removal failed"
10526 }
10527 run_test 169 "parallel read and truncate should not deadlock"
10528
10529 test_170() {
10530         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10531         $LCTL clear     # bug 18514
10532         $LCTL debug_daemon start $TMP/${tfile}_log_good
10533         touch $DIR/$tfile
10534         $LCTL debug_daemon stop
10535         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10536                error "sed failed to read log_good"
10537
10538         $LCTL debug_daemon start $TMP/${tfile}_log_good
10539         rm -rf $DIR/$tfile
10540         $LCTL debug_daemon stop
10541
10542         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10543                error "lctl df log_bad failed"
10544
10545         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10546         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10547
10548         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10549         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10550
10551         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10552                 error "bad_line good_line1 good_line2 are empty"
10553
10554         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10555         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10556         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10557
10558         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10559         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10560         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10561
10562         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
10563                 error "bad_line_new good_line_new are empty"
10564
10565         local expected_good=$((good_line1 + good_line2*2))
10566
10567         rm -f $TMP/${tfile}*
10568         # LU-231, short malformed line may not be counted into bad lines
10569         if [ $bad_line -ne $bad_line_new ] &&
10570                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
10571                 error "expected $bad_line bad lines, but got $bad_line_new"
10572                 return 1
10573         fi
10574
10575         if [ $expected_good -ne $good_line_new ]; then
10576                 error "expected $expected_good good lines, but got $good_line_new"
10577                 return 2
10578         fi
10579         true
10580 }
10581 run_test 170 "test lctl df to handle corrupted log ====================="
10582
10583 test_171() { # bug20592
10584         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10585 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
10586         $LCTL set_param fail_loc=0x50e
10587         $LCTL set_param fail_val=3000
10588         multiop_bg_pause $DIR/$tfile O_s || true
10589         local MULTIPID=$!
10590         kill -USR1 $MULTIPID
10591         # cause log dump
10592         sleep 3
10593         wait $MULTIPID
10594         if dmesg | grep "recursive fault"; then
10595                 error "caught a recursive fault"
10596         fi
10597         $LCTL set_param fail_loc=0
10598         true
10599 }
10600 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
10601
10602 # it would be good to share it with obdfilter-survey/iokit-libecho code
10603 setup_obdecho_osc () {
10604         local rc=0
10605         local ost_nid=$1
10606         local obdfilter_name=$2
10607         echo "Creating new osc for $obdfilter_name on $ost_nid"
10608         # make sure we can find loopback nid
10609         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
10610
10611         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
10612                            ${obdfilter_name}_osc_UUID || rc=2; }
10613         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
10614                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
10615         return $rc
10616 }
10617
10618 cleanup_obdecho_osc () {
10619         local obdfilter_name=$1
10620         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
10621         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
10622         return 0
10623 }
10624
10625 obdecho_test() {
10626         local OBD=$1
10627         local node=$2
10628         local pages=${3:-64}
10629         local rc=0
10630         local id
10631
10632         local count=10
10633         local obd_size=$(get_obd_size $node $OBD)
10634         local page_size=$(get_page_size $node)
10635         if [[ -n "$obd_size" ]]; then
10636                 local new_count=$((obd_size / (pages * page_size / 1024)))
10637                 [[ $new_count -ge $count ]] || count=$new_count
10638         fi
10639
10640         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
10641         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
10642                            rc=2; }
10643         if [ $rc -eq 0 ]; then
10644             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
10645             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
10646         fi
10647         echo "New object id is $id"
10648         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
10649                            rc=4; }
10650         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
10651                            "test_brw $count w v $pages $id" || rc=4; }
10652         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
10653                            rc=4; }
10654         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
10655                                         "cleanup" || rc=5; }
10656         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
10657                                         "detach" || rc=6; }
10658         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
10659         return $rc
10660 }
10661
10662 test_180a() {
10663         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10664         remote_ost_nodsh && skip "remote OST with nodsh" && return
10665         local rc=0
10666         local rmmod_local=0
10667
10668         if ! module_loaded obdecho; then
10669             load_module obdecho/obdecho
10670             rmmod_local=1
10671         fi
10672
10673         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
10674         local host=$(lctl get_param -n osc.$osc.import |
10675                              awk '/current_connection:/ {print $2}' )
10676         local target=$(lctl get_param -n osc.$osc.import |
10677                              awk '/target:/ {print $2}' )
10678         target=${target%_UUID}
10679
10680         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
10681         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
10682         [[ -n $target ]] && cleanup_obdecho_osc $target
10683         [ $rmmod_local -eq 1 ] && rmmod obdecho
10684         return $rc
10685 }
10686 run_test 180a "test obdecho on osc"
10687
10688 test_180b() {
10689         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10690         remote_ost_nodsh && skip "remote OST with nodsh" && return
10691         local rc=0
10692         local rmmod_remote=0
10693
10694         do_facet ost1 "lsmod | grep -q obdecho || "                      \
10695                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
10696                       "modprobe obdecho; }" && rmmod_remote=1
10697         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
10698         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
10699         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
10700         return $rc
10701 }
10702 run_test 180b "test obdecho directly on obdfilter"
10703
10704 test_180c() { # LU-2598
10705         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10706         remote_ost_nodsh && skip "remote OST with nodsh" && return
10707         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
10708                 skip "Need MDS version at least 2.4.0" && return
10709
10710         local rc=0
10711         local rmmod_remote=false
10712         local pages=16384 # 64MB bulk I/O RPC size
10713         local target
10714
10715         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
10716                 rmmod_remote=true || error "failed to load module obdecho"
10717
10718         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
10719                 head -n1)
10720         if [ -n "$target" ]; then
10721                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
10722         else
10723                 echo "there is no obdfilter target on ost1"
10724                 rc=2
10725         fi
10726         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
10727         return $rc
10728 }
10729 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
10730
10731 test_181() { # bug 22177
10732         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10733         # create enough files to index the directory
10734         createmany -o $DIR/$tdir/foobar 4000
10735         # print attributes for debug purpose
10736         lsattr -d .
10737         # open dir
10738         multiop_bg_pause $DIR/$tdir D_Sc || return 1
10739         MULTIPID=$!
10740         # remove the files & current working dir
10741         unlinkmany $DIR/$tdir/foobar 4000
10742         rmdir $DIR/$tdir
10743         kill -USR1 $MULTIPID
10744         wait $MULTIPID
10745         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
10746         return 0
10747 }
10748 run_test 181 "Test open-unlinked dir ========================"
10749
10750 test_182() {
10751         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10752         # disable MDC RPC lock wouldn't crash client
10753         local fcount=1000
10754         local tcount=4
10755
10756         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10757 #define OBD_FAIL_MDC_RPCS_SEM           0x804
10758         $LCTL set_param fail_loc=0x804
10759
10760         for (( i=0; i < $tcount; i++ )) ; do
10761                 mkdir $DIR/$tdir/$i
10762                 createmany -o $DIR/$tdir/$i/f- $fcount &
10763         done
10764         wait
10765
10766         for (( i=0; i < $tcount; i++ )) ; do
10767                 unlinkmany $DIR/$tdir/$i/f- $fcount &
10768         done
10769         wait
10770
10771         rm -rf $DIR/$tdir
10772
10773         $LCTL set_param fail_loc=0
10774 }
10775 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
10776
10777 test_183() { # LU-2275
10778         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10779         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
10780                 skip "Need MDS version at least 2.3.56" && return
10781
10782         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10783         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10784         echo aaa > $DIR/$tdir/$tfile
10785
10786 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
10787         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
10788
10789         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
10790         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
10791
10792         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
10793
10794         # Flush negative dentry cache
10795         touch $DIR/$tdir/$tfile
10796
10797         # We are not checking for any leaked references here, they'll
10798         # become evident next time we do cleanup with module unload.
10799         rm -rf $DIR/$tdir
10800 }
10801 run_test 183 "No crash or request leak in case of strange dispositions ========"
10802
10803 # test suite 184 is for LU-2016, LU-2017
10804 test_184a() {
10805         check_swap_layouts_support && return 0
10806
10807         dir0=$DIR/$tdir/$testnum
10808         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
10809         ref1=/etc/passwd
10810         ref2=/etc/group
10811         file1=$dir0/f1
10812         file2=$dir0/f2
10813         $SETSTRIPE -c1 $file1
10814         cp $ref1 $file1
10815         $SETSTRIPE -c2 $file2
10816         cp $ref2 $file2
10817         gen1=$($GETSTRIPE -g $file1)
10818         gen2=$($GETSTRIPE -g $file2)
10819
10820         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
10821         gen=$($GETSTRIPE -g $file1)
10822         [[ $gen1 != $gen ]] ||
10823                 "Layout generation on $file1 does not change"
10824         gen=$($GETSTRIPE -g $file2)
10825         [[ $gen2 != $gen ]] ||
10826                 "Layout generation on $file2 does not change"
10827
10828         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
10829         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
10830 }
10831 run_test 184a "Basic layout swap"
10832
10833 test_184b() {
10834         check_swap_layouts_support && return 0
10835
10836         dir0=$DIR/$tdir/$testnum
10837         mkdir -p $dir0 || error "creating dir $dir0"
10838         file1=$dir0/f1
10839         file2=$dir0/f2
10840         file3=$dir0/f3
10841         dir1=$dir0/d1
10842         dir2=$dir0/d2
10843         mkdir $dir1 $dir2
10844         $SETSTRIPE -c1 $file1
10845         $SETSTRIPE -c2 $file2
10846         $SETSTRIPE -c1 $file3
10847         chown $RUNAS_ID $file3
10848         gen1=$($GETSTRIPE -g $file1)
10849         gen2=$($GETSTRIPE -g $file2)
10850
10851         $LFS swap_layouts $dir1 $dir2 &&
10852                 error "swap of directories layouts should fail"
10853         $LFS swap_layouts $dir1 $file1 &&
10854                 error "swap of directory and file layouts should fail"
10855         $RUNAS $LFS swap_layouts $file1 $file2 &&
10856                 error "swap of file we cannot write should fail"
10857         $LFS swap_layouts $file1 $file3 &&
10858                 error "swap of file with different owner should fail"
10859         /bin/true # to clear error code
10860 }
10861 run_test 184b "Forbidden layout swap (will generate errors)"
10862
10863 test_184c() {
10864         check_swap_layouts_support && return 0
10865
10866         local dir0=$DIR/$tdir/$testnum
10867         mkdir -p $dir0 || error "creating dir $dir0"
10868
10869         local ref1=$dir0/ref1
10870         local ref2=$dir0/ref2
10871         local file1=$dir0/file1
10872         local file2=$dir0/file2
10873         # create a file large enough for the concurent test
10874         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
10875         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
10876         echo "ref file size: ref1($(stat -c %s $ref1))," \
10877              "ref2($(stat -c %s $ref2))"
10878
10879         cp $ref2 $file2
10880         dd if=$ref1 of=$file1 bs=16k &
10881         local DD_PID=$!
10882
10883         # Make sure dd starts to copy file
10884         while [ ! -f $file1 ]; do sleep 0.1; done
10885
10886         $LFS swap_layouts $file1 $file2
10887         local rc=$?
10888         wait $DD_PID
10889         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
10890         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
10891
10892         # how many bytes copied before swapping layout
10893         local copied=$(stat -c %s $file2)
10894         local remaining=$(stat -c %s $ref1)
10895         remaining=$((remaining - copied))
10896         echo "Copied $copied bytes before swapping layout..."
10897
10898         cmp -n $copied $file1 $ref2 | grep differ &&
10899                 error "Content mismatch [0, $copied) of ref2 and file1"
10900         cmp -n $copied $file2 $ref1 ||
10901                 error "Content mismatch [0, $copied) of ref1 and file2"
10902         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
10903                 error "Content mismatch [$copied, EOF) of ref1 and file1"
10904
10905         # clean up
10906         rm -f $ref1 $ref2 $file1 $file2
10907 }
10908 run_test 184c "Concurrent write and layout swap"
10909
10910 test_184d() {
10911         check_swap_layouts_support && return 0
10912         [ -z "$(which getfattr 2>/dev/null)" ] &&
10913                 skip "no getfattr command" && return 0
10914
10915         local file1=$DIR/$tdir/$tfile-1
10916         local file2=$DIR/$tdir/$tfile-2
10917         local file3=$DIR/$tdir/$tfile-3
10918         local lovea1
10919         local lovea2
10920
10921         mkdir -p $DIR/$tdir
10922         touch $file1 || error "create $file1 failed"
10923         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
10924                 error "create $file2 failed"
10925         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
10926                 error "create $file3 failed"
10927         lovea1=$($LFS getstripe $file1 | sed 1d)
10928
10929         $LFS swap_layouts $file2 $file3 ||
10930                 error "swap $file2 $file3 layouts failed"
10931         $LFS swap_layouts $file1 $file2 ||
10932                 error "swap $file1 $file2 layouts failed"
10933
10934         lovea2=$($LFS getstripe $file2 | sed 1d)
10935         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
10936
10937         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
10938         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
10939 }
10940 run_test 184d "allow stripeless layouts swap"
10941
10942
10943 test_185() { # LU-2441
10944         # LU-3553 - no volatile file support in old servers
10945         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
10946                 { skip "Need MDS version at least 2.3.60"; return 0; }
10947
10948         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10949         touch $DIR/$tdir/spoo
10950         local mtime1=$(stat -c "%Y" $DIR/$tdir)
10951         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
10952                 error "cannot create/write a volatile file"
10953         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
10954                 error "FID is still valid after close"
10955
10956         multiop_bg_pause $DIR/$tdir vVw4096_c
10957         local multi_pid=$!
10958
10959         local OLD_IFS=$IFS
10960         IFS=":"
10961         local fidv=($fid)
10962         IFS=$OLD_IFS
10963         # assume that the next FID for this client is sequential, since stdout
10964         # is unfortunately eaten by multiop_bg_pause
10965         local n=$((${fidv[1]} + 1))
10966         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
10967         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
10968                 error "FID is missing before close"
10969         kill -USR1 $multi_pid
10970         # 1 second delay, so if mtime change we will see it
10971         sleep 1
10972         local mtime2=$(stat -c "%Y" $DIR/$tdir)
10973         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
10974 }
10975 run_test 185 "Volatile file support"
10976
10977 test_187a() {
10978         local dir0=$DIR/$tdir/$testnum
10979         mkdir -p $dir0 || error "creating dir $dir0"
10980
10981         local file=$dir0/file1
10982         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
10983         local dv1=$($LFS data_version $file)
10984         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
10985         local dv2=$($LFS data_version $file)
10986         [[ $dv1 != $dv2 ]] ||
10987                 error "data version did not change on write $dv1 == $dv2"
10988
10989         # clean up
10990         rm -f $file1
10991 }
10992 run_test 187a "Test data version change"
10993
10994 test_187b() {
10995         local dir0=$DIR/$tdir/$testnum
10996         mkdir -p $dir0 || error "creating dir $dir0"
10997
10998         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
10999         [[ ${DV[0]} != ${DV[1]} ]] ||
11000                 error "data version did not change on write"\
11001                       " ${DV[0]} == ${DV[1]}"
11002
11003         # clean up
11004         rm -f $file1
11005 }
11006 run_test 187b "Test data version change on volatile file"
11007
11008 test_200() {
11009         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11010         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11011
11012         local POOL=${POOL:-cea1}
11013         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
11014         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
11015         # Pool OST targets
11016         local first_ost=0
11017         local last_ost=$(($OSTCOUNT - 1))
11018         local ost_step=2
11019         local ost_list=$(seq $first_ost $ost_step $last_ost)
11020         local ost_range="$first_ost $last_ost $ost_step"
11021         local test_path=$POOL_ROOT/$POOL_DIR_NAME
11022         local file_dir=$POOL_ROOT/file_tst
11023
11024         local rc=0
11025         while : ; do
11026                 # former test_200a test_200b
11027                 pool_add $POOL                          || { rc=$? ; break; }
11028                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
11029                 # former test_200c test_200d
11030                 mkdir -p $test_path
11031                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
11032                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
11033                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
11034                                                         || { rc=$? ; break; }
11035                 # former test_200e test_200f
11036                 local files=$((OSTCOUNT*3))
11037                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
11038                                                         || { rc=$? ; break; }
11039                 pool_create_files $POOL $file_dir $files "$ost_list" \
11040                                                         || { rc=$? ; break; }
11041                 # former test_200g test_200h
11042                 pool_lfs_df $POOL                       || { rc=$? ; break; }
11043                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
11044
11045                 # former test_201a test_201b test_201c
11046                 pool_remove_first_target $POOL          || { rc=$? ; break; }
11047
11048                 local f=$test_path/$tfile
11049                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
11050                 pool_remove $POOL $f                    || { rc=$? ; break; }
11051                 break
11052         done
11053
11054         cleanup_pools
11055         return $rc
11056 }
11057 run_test 200 "OST pools"
11058
11059 # usage: default_attr <count | size | offset>
11060 default_attr() {
11061         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
11062 }
11063
11064 # usage: check_default_stripe_attr
11065 check_default_stripe_attr() {
11066         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
11067         case $1 in
11068         --stripe-count|--count)
11069                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
11070         --stripe-size|--size)
11071                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
11072         --stripe-index|--index)
11073                 EXPECTED=-1;;
11074         *)
11075                 error "unknown getstripe attr '$1'"
11076         esac
11077
11078         [ $ACTUAL != $EXPECTED ] &&
11079                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
11080 }
11081
11082 test_204a() {
11083         test_mkdir -p $DIR/$tdir
11084         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
11085
11086         check_default_stripe_attr --stripe-count
11087         check_default_stripe_attr --stripe-size
11088         check_default_stripe_attr --stripe-index
11089
11090         return 0
11091 }
11092 run_test 204a "Print default stripe attributes ================="
11093
11094 test_204b() {
11095         test_mkdir -p $DIR/$tdir
11096         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11097
11098         check_default_stripe_attr --stripe-size
11099         check_default_stripe_attr --stripe-index
11100
11101         return 0
11102 }
11103 run_test 204b "Print default stripe size and offset  ==========="
11104
11105 test_204c() {
11106         test_mkdir -p $DIR/$tdir
11107         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11108
11109         check_default_stripe_attr --stripe-count
11110         check_default_stripe_attr --stripe-index
11111
11112         return 0
11113 }
11114 run_test 204c "Print default stripe count and offset ==========="
11115
11116 test_204d() {
11117         test_mkdir -p $DIR/$tdir
11118         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11119
11120         check_default_stripe_attr --stripe-count
11121         check_default_stripe_attr --stripe-size
11122
11123         return 0
11124 }
11125 run_test 204d "Print default stripe count and size ============="
11126
11127 test_204e() {
11128         test_mkdir -p $DIR/$tdir
11129         $SETSTRIPE -d $DIR/$tdir
11130
11131         check_default_stripe_attr --stripe-count --raw
11132         check_default_stripe_attr --stripe-size --raw
11133         check_default_stripe_attr --stripe-index --raw
11134
11135         return 0
11136 }
11137 run_test 204e "Print raw stripe attributes ================="
11138
11139 test_204f() {
11140         test_mkdir -p $DIR/$tdir
11141         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11142
11143         check_default_stripe_attr --stripe-size --raw
11144         check_default_stripe_attr --stripe-index --raw
11145
11146         return 0
11147 }
11148 run_test 204f "Print raw stripe size and offset  ==========="
11149
11150 test_204g() {
11151         test_mkdir -p $DIR/$tdir
11152         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11153
11154         check_default_stripe_attr --stripe-count --raw
11155         check_default_stripe_attr --stripe-index --raw
11156
11157         return 0
11158 }
11159 run_test 204g "Print raw stripe count and offset ==========="
11160
11161 test_204h() {
11162         test_mkdir -p $DIR/$tdir
11163         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11164
11165         check_default_stripe_attr --stripe-count --raw
11166         check_default_stripe_attr --stripe-size --raw
11167
11168         return 0
11169 }
11170 run_test 204h "Print raw stripe count and size ============="
11171
11172 # Figure out which job scheduler is being used, if any,
11173 # or use a fake one
11174 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11175         JOBENV=SLURM_JOB_ID
11176 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11177         JOBENV=LSB_JOBID
11178 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11179         JOBENV=PBS_JOBID
11180 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11181         JOBENV=LOADL_STEP_ID
11182 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11183         JOBENV=JOB_ID
11184 else
11185         JOBENV=FAKE_JOBID
11186 fi
11187
11188 verify_jobstats() {
11189         local cmd=$1
11190         local target=$2
11191
11192         # clear old jobstats
11193         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
11194         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
11195
11196         # use a new JobID for this test, or we might see an old one
11197         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
11198
11199         JOBVAL=${!JOBENV}
11200         log "Test: $cmd"
11201         log "Using JobID environment variable $JOBENV=$JOBVAL"
11202
11203         if [ $JOBENV = "FAKE_JOBID" ]; then
11204                 FAKE_JOBID=$JOBVAL $cmd
11205         else
11206                 $cmd
11207         fi
11208
11209         if [ "$target" = "mdt" -o "$target" = "both" ]; then
11210                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
11211                 do_facet $FACET lctl get_param mdt.*.job_stats |
11212                         grep $JOBVAL || error "No job stats found on MDT $FACET"
11213         fi
11214         if [ "$target" = "ost" -o "$target" = "both" ]; then
11215                 FACET=ost1
11216                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
11217                         grep $JOBVAL || error "No job stats found on OST $FACET"
11218         fi
11219 }
11220
11221 jobstats_set() {
11222         trap 0
11223         NEW_JOBENV=${1:-$OLD_JOBENV}
11224         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11225         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11226 }
11227
11228 test_205() { # Job stats
11229         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11230         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11231         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11232                 skip "Server doesn't support jobstats" && return 0
11233         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11234
11235         local cmd
11236         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11237         if [ $OLD_JOBENV != $JOBENV ]; then
11238                 jobstats_set $JOBENV
11239                 trap jobstats_set EXIT
11240         fi
11241
11242         # mkdir
11243         cmd="mkdir $DIR/$tfile"
11244         verify_jobstats "$cmd" "mdt"
11245         # rmdir
11246         cmd="rm -fr $DIR/$tfile"
11247         verify_jobstats "$cmd" "mdt"
11248         # mknod
11249         cmd="mknod $DIR/$tfile c 1 3"
11250         verify_jobstats "$cmd" "mdt"
11251         # unlink
11252         cmd="rm -f $DIR/$tfile"
11253         verify_jobstats "$cmd" "mdt"
11254         # open & close
11255         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11256         verify_jobstats "$cmd" "mdt"
11257         # setattr
11258         cmd="touch $DIR/$tfile"
11259         verify_jobstats "$cmd" "both"
11260         # write
11261         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11262         verify_jobstats "$cmd" "ost"
11263         # read
11264         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11265         verify_jobstats "$cmd" "ost"
11266         # truncate
11267         cmd="$TRUNCATE $DIR/$tfile 0"
11268         verify_jobstats "$cmd" "both"
11269         # rename
11270         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
11271         verify_jobstats "$cmd" "mdt"
11272
11273         # cleanup
11274         rm -f $DIR/jobstats_test_rename
11275
11276         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11277 }
11278 run_test 205 "Verify job stats"
11279
11280 # LU-1480, LU-1773 and LU-1657
11281 test_206() {
11282         mkdir -p $DIR/$tdir
11283         $SETSTRIPE -c -1 $DIR/$tdir
11284 #define OBD_FAIL_LOV_INIT 0x1403
11285         $LCTL set_param fail_loc=0xa0001403
11286         $LCTL set_param fail_val=1
11287         touch $DIR/$tdir/$tfile || true
11288 }
11289 run_test 206 "fail lov_init_raid0() doesn't lbug"
11290
11291 test_207a() {
11292         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11293         local fsz=`stat -c %s $DIR/$tfile`
11294         cancel_lru_locks mdc
11295
11296         # do not return layout in getattr intent
11297 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11298         $LCTL set_param fail_loc=0x170
11299         local sz=`stat -c %s $DIR/$tfile`
11300
11301         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11302
11303         rm -rf $DIR/$tfile
11304 }
11305 run_test 207a "can refresh layout at glimpse"
11306
11307 test_207b() {
11308         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11309         local cksum=`md5sum $DIR/$tfile`
11310         local fsz=`stat -c %s $DIR/$tfile`
11311         cancel_lru_locks mdc
11312         cancel_lru_locks osc
11313
11314         # do not return layout in getattr intent
11315 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11316         $LCTL set_param fail_loc=0x171
11317
11318         # it will refresh layout after the file is opened but before read issues
11319         echo checksum is "$cksum"
11320         echo "$cksum" |md5sum -c --quiet || error "file differs"
11321
11322         rm -rf $DIR/$tfile
11323 }
11324 run_test 207b "can refresh layout at open"
11325
11326 test_208() {
11327         # FIXME: in this test suite, only RD lease is used. This is okay
11328         # for now as only exclusive open is supported. After generic lease
11329         # is done, this test suite should be revised. - Jinshan
11330
11331         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11332                 { skip "Need MDS version at least 2.4.52"; return 0; }
11333         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11334
11335         echo "==== test 1: verify get lease work"
11336         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11337
11338         echo "==== test 2: verify lease can be broken by upcoming open"
11339         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11340         local PID=$!
11341         sleep 1
11342
11343         $MULTIOP $DIR/$tfile oO_RDONLY:c
11344         kill -USR1 $PID && wait $PID || error "break lease error"
11345
11346         echo "==== test 3: verify lease can't be granted if an open already exists"
11347         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11348         local PID=$!
11349         sleep 1
11350
11351         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11352         kill -USR1 $PID && wait $PID || error "open file error"
11353
11354         echo "==== test 4: lease can sustain over recovery"
11355         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11356         PID=$!
11357         sleep 1
11358
11359         fail mds1
11360
11361         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11362
11363         echo "==== test 5: lease broken can't be regained by replay"
11364         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11365         PID=$!
11366         sleep 1
11367
11368         # open file to break lease and then recovery
11369         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11370         fail mds1
11371
11372         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11373
11374         rm -f $DIR/$tfile
11375 }
11376 run_test 208 "Exclusive open"
11377
11378 test_209() {
11379         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11380                 skip_env "must have disp_stripe" && return
11381
11382         touch $DIR/$tfile
11383         sync; sleep 5; sync;
11384
11385         echo 3 > /proc/sys/vm/drop_caches
11386         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11387
11388         # open/close 500 times
11389         for i in $(seq 500); do
11390                 cat $DIR/$tfile
11391         done
11392
11393         echo 3 > /proc/sys/vm/drop_caches
11394         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11395
11396         echo "before: $req_before, after: $req_after"
11397         [ $((req_after - req_before)) -ge 300 ] &&
11398                 error "open/close requests are not freed"
11399         return 0
11400 }
11401 run_test 209 "read-only open/close requests should be freed promptly"
11402
11403 test_212() {
11404         size=`date +%s`
11405         size=$((size % 8192 + 1))
11406         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11407         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11408         rm -f $DIR/f212 $DIR/f212.xyz
11409 }
11410 run_test 212 "Sendfile test ============================================"
11411
11412 test_213() {
11413         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11414         cancel_lru_locks osc
11415         lctl set_param fail_loc=0x8000040f
11416         # generate a read lock
11417         cat $DIR/$tfile > /dev/null
11418         # write to the file, it will try to cancel the above read lock.
11419         cat /etc/hosts >> $DIR/$tfile
11420 }
11421 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11422
11423 test_214() { # for bug 20133
11424         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11425         for (( i=0; i < 340; i++ )) ; do
11426                 touch $DIR/$tdir/d214c/a$i
11427         done
11428
11429         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11430         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11431         ls $DIR/d214c || error "ls $DIR/d214c failed"
11432         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11433         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11434 }
11435 run_test 214 "hash-indexed directory test - bug 20133"
11436
11437 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11438 create_lnet_proc_files() {
11439         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
11440         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11441
11442         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11443         rm -f "$TMP/lnet_$1.sys_tmp"
11444 }
11445
11446 # counterpart of create_lnet_proc_files
11447 remove_lnet_proc_files() {
11448         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11449 }
11450
11451 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11452 # 3rd arg as regexp for body
11453 check_lnet_proc_stats() {
11454         local l=$(cat "$TMP/lnet_$1" |wc -l)
11455         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
11456
11457         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
11458 }
11459
11460 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11461 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
11462 # optional and can be regexp for 2nd line (lnet.routes case)
11463 check_lnet_proc_entry() {
11464         local blp=2          # blp stands for 'position of 1st line of body'
11465         [ -z "$5" ] || blp=3 # lnet.routes case
11466
11467         local l=$(cat "$TMP/lnet_$1" |wc -l)
11468         # subtracting one from $blp because the body can be empty
11469         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
11470
11471         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
11472                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
11473
11474         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
11475                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
11476
11477         # bail out if any unexpected line happened
11478         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
11479         [ "$?" != 0 ] || error "$2 misformatted"
11480 }
11481
11482 test_215() { # for bugs 18102, 21079, 21517
11483         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11484         local N='(0|[1-9][0-9]*)'       # non-negative numeric
11485         local P='[1-9][0-9]*'           # positive numeric
11486         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
11487         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
11488         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
11489         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
11490
11491         local L1 # regexp for 1st line
11492         local L2 # regexp for 2nd line (optional)
11493         local BR # regexp for the rest (body)
11494
11495         # lnet.stats should look as 11 space-separated non-negative numerics
11496         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
11497         create_lnet_proc_files "stats"
11498         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
11499         remove_lnet_proc_files "stats"
11500
11501         # lnet.routes should look like this:
11502         # Routing disabled/enabled
11503         # net hops priority state router
11504         # where net is a string like tcp0, hops > 0, priority >= 0,
11505         # state is up/down,
11506         # router is a string like 192.168.1.1@tcp2
11507         L1="^Routing (disabled|enabled)$"
11508         L2="^net +hops +priority +state +router$"
11509         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
11510         create_lnet_proc_files "routes"
11511         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
11512         remove_lnet_proc_files "routes"
11513
11514         # lnet.routers should look like this:
11515         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
11516         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
11517         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
11518         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
11519         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
11520         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
11521         create_lnet_proc_files "routers"
11522         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
11523         remove_lnet_proc_files "routers"
11524
11525         # lnet.peers should look like this:
11526         # nid refs state last max rtr min tx min queue
11527         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
11528         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
11529         # numeric (0 or >0 or <0), queue >= 0.
11530         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
11531         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
11532         create_lnet_proc_files "peers"
11533         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
11534         remove_lnet_proc_files "peers"
11535
11536         # lnet.buffers  should look like this:
11537         # pages count credits min
11538         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
11539         L1="^pages +count +credits +min$"
11540         BR="^ +$N +$N +$I +$I$"
11541         create_lnet_proc_files "buffers"
11542         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
11543         remove_lnet_proc_files "buffers"
11544
11545         # lnet.nis should look like this:
11546         # nid status alive refs peer rtr max tx min
11547         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
11548         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
11549         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
11550         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
11551         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
11552         create_lnet_proc_files "nis"
11553         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
11554         remove_lnet_proc_files "nis"
11555
11556         # can we successfully write to lnet.stats?
11557         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
11558         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
11559 }
11560 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
11561
11562 test_216() { # bug 20317
11563         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11564         remote_ost_nodsh && skip "remote OST with nodsh" && return
11565
11566         local node
11567         local facets=$(get_facets OST)
11568         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11569
11570         save_lustre_params client "osc.*.contention_seconds" > $p
11571         save_lustre_params $facets \
11572                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
11573         save_lustre_params $facets \
11574                 "ldlm.namespaces.filter-*.contended_locks" >> $p
11575         save_lustre_params $facets \
11576                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
11577         clear_osc_stats
11578
11579         # agressive lockless i/o settings
11580         for node in $(osts_nodes); do
11581                 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'
11582         done
11583         lctl set_param -n osc.*.contention_seconds 60
11584
11585         $DIRECTIO write $DIR/$tfile 0 10 4096
11586         $CHECKSTAT -s 40960 $DIR/$tfile
11587
11588         # disable lockless i/o
11589         for node in $(osts_nodes); do
11590                 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'
11591         done
11592         lctl set_param -n osc.*.contention_seconds 0
11593         clear_osc_stats
11594
11595         dd if=/dev/zero of=$DIR/$tfile count=0
11596         $CHECKSTAT -s 0 $DIR/$tfile
11597
11598         restore_lustre_params <$p
11599         rm -f $p
11600         rm $DIR/$tfile
11601 }
11602 run_test 216 "check lockless direct write works and updates file size and kms correctly"
11603
11604 test_217() { # bug 22430
11605         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11606         local node
11607         local nid
11608
11609         for node in $(nodes_list); do
11610                 nid=$(host_nids_address $node $NETTYPE)
11611                 if [[ $nid = *-* ]] ; then
11612                         echo "lctl ping $nid@$NETTYPE"
11613                         lctl ping $nid@$NETTYPE
11614                 else
11615                         echo "skipping $node (no hyphen detected)"
11616                 fi
11617         done
11618 }
11619 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
11620
11621 test_218() {
11622        # do directio so as not to populate the page cache
11623        log "creating a 10 Mb file"
11624        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11625        log "starting reads"
11626        dd if=$DIR/$tfile of=/dev/null bs=4096 &
11627        log "truncating the file"
11628        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11629        log "killing dd"
11630        kill %+ || true # reads might have finished
11631        echo "wait until dd is finished"
11632        wait
11633        log "removing the temporary file"
11634        rm -rf $DIR/$tfile || error "tmp file removal failed"
11635 }
11636 run_test 218 "parallel read and truncate should not deadlock ======================="
11637
11638 test_219() {
11639         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11640         # write one partial page
11641         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
11642         # set no grant so vvp_io_commit_write will do sync write
11643         $LCTL set_param fail_loc=0x411
11644         # write a full page at the end of file
11645         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
11646
11647         $LCTL set_param fail_loc=0
11648         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
11649         $LCTL set_param fail_loc=0x411
11650         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
11651
11652         # LU-4201
11653         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
11654         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
11655 }
11656 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
11657
11658 test_220() { #LU-325
11659         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11660         remote_ost_nodsh && skip "remote OST with nodsh" && return
11661         local OSTIDX=0
11662
11663         test_mkdir -p $DIR/$tdir
11664         local OST=$(lfs osts | grep ${OSTIDX}": " | \
11665                 awk '{print $2}' | sed -e 's/_UUID$//')
11666
11667         # on the mdt's osc
11668         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
11669         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
11670                         osc.$mdtosc_proc1.prealloc_last_id)
11671         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
11672                         osc.$mdtosc_proc1.prealloc_next_id)
11673
11674         $LFS df -i
11675
11676         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
11677         #define OBD_FAIL_OST_ENOINO              0x229
11678         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
11679         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
11680         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
11681
11682         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
11683
11684         MDSOBJS=$((last_id - next_id))
11685         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
11686
11687         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
11688         echo "OST still has $count kbytes free"
11689
11690         echo "create $MDSOBJS files @next_id..."
11691         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
11692
11693         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11694                         osc.$mdtosc_proc1.prealloc_last_id)
11695         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11696                         osc.$mdtosc_proc1.prealloc_next_id)
11697
11698         echo "after creation, last_id=$last_id2, next_id=$next_id2"
11699         $LFS df -i
11700
11701         echo "cleanup..."
11702
11703         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
11704         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
11705
11706         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
11707         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
11708         echo "unlink $MDSOBJS files @$next_id..."
11709         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
11710 }
11711 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
11712
11713 test_221() {
11714         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11715         dd if=`which date` of=$MOUNT/date oflag=sync
11716         chmod +x $MOUNT/date
11717
11718         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
11719         $LCTL set_param fail_loc=0x80001401
11720
11721         $MOUNT/date > /dev/null
11722         rm -f $MOUNT/date
11723 }
11724 run_test 221 "make sure fault and truncate race to not cause OOM"
11725
11726 test_222a () {
11727         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11728        rm -rf $DIR/$tdir
11729        test_mkdir -p $DIR/$tdir
11730        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11731        createmany -o $DIR/$tdir/$tfile 10
11732        cancel_lru_locks mdc
11733        cancel_lru_locks osc
11734        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11735        $LCTL set_param fail_loc=0x31a
11736        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
11737        $LCTL set_param fail_loc=0
11738        rm -r $DIR/$tdir
11739 }
11740 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
11741
11742 test_222b () {
11743         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11744        rm -rf $DIR/$tdir
11745        test_mkdir -p $DIR/$tdir
11746        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11747        createmany -o $DIR/$tdir/$tfile 10
11748        cancel_lru_locks mdc
11749        cancel_lru_locks osc
11750        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11751        $LCTL set_param fail_loc=0x31a
11752        rm -r $DIR/$tdir || "AGL for rmdir failed"
11753        $LCTL set_param fail_loc=0
11754 }
11755 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
11756
11757 test_223 () {
11758         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11759        rm -rf $DIR/$tdir
11760        test_mkdir -p $DIR/$tdir
11761        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11762        createmany -o $DIR/$tdir/$tfile 10
11763        cancel_lru_locks mdc
11764        cancel_lru_locks osc
11765        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
11766        $LCTL set_param fail_loc=0x31b
11767        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
11768        $LCTL set_param fail_loc=0
11769        rm -r $DIR/$tdir
11770 }
11771 run_test 223 "osc reenqueue if without AGL lock granted ======================="
11772
11773 test_224a() { # LU-1039, MRP-303
11774         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11775         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
11776         $LCTL set_param fail_loc=0x508
11777         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
11778         $LCTL set_param fail_loc=0
11779         df $DIR
11780 }
11781 run_test 224a "Don't panic on bulk IO failure"
11782
11783 test_224b() { # LU-1039, MRP-303
11784         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11785         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
11786         cancel_lru_locks osc
11787         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
11788         $LCTL set_param fail_loc=0x515
11789         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
11790         $LCTL set_param fail_loc=0
11791         df $DIR
11792 }
11793 run_test 224b "Don't panic on bulk IO failure"
11794
11795 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
11796 test_225a () {
11797         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11798         if [ -z ${MDSSURVEY} ]; then
11799               skip_env "mds-survey not found" && return
11800         fi
11801
11802         [ $MDSCOUNT -ge 2 ] &&
11803                 skip "skipping now for more than one MDT" && return
11804
11805        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11806             { skip "Need MDS version at least 2.2.51"; return; }
11807
11808        local mds=$(facet_host $SINGLEMDS)
11809        local target=$(do_nodes $mds 'lctl dl' | \
11810                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11811
11812        local cmd1="file_count=1000 thrhi=4"
11813        local cmd2="dir_count=2 layer=mdd stripe_count=0"
11814        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11815        local cmd="$cmd1 $cmd2 $cmd3"
11816
11817        rm -f ${TMP}/mds_survey*
11818        echo + $cmd
11819        eval $cmd || error "mds-survey with zero-stripe failed"
11820        cat ${TMP}/mds_survey*
11821        rm -f ${TMP}/mds_survey*
11822 }
11823 run_test 225a "Metadata survey sanity with zero-stripe"
11824
11825 test_225b () {
11826         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11827
11828         if [ -z ${MDSSURVEY} ]; then
11829               skip_env "mds-survey not found" && return
11830         fi
11831         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11832             { skip "Need MDS version at least 2.2.51"; return; }
11833
11834         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
11835               skip_env "Need to mount OST to test" && return
11836         fi
11837
11838         [ $MDSCOUNT -ge 2 ] &&
11839                 skip "skipping now for more than one MDT" && return
11840        local mds=$(facet_host $SINGLEMDS)
11841        local target=$(do_nodes $mds 'lctl dl' | \
11842                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11843
11844        local cmd1="file_count=1000 thrhi=4"
11845        local cmd2="dir_count=2 layer=mdd stripe_count=1"
11846        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11847        local cmd="$cmd1 $cmd2 $cmd3"
11848
11849        rm -f ${TMP}/mds_survey*
11850        echo + $cmd
11851        eval $cmd || error "mds-survey with stripe_count failed"
11852        cat ${TMP}/mds_survey*
11853        rm -f ${TMP}/mds_survey*
11854 }
11855 run_test 225b "Metadata survey sanity with stripe_count = 1"
11856
11857 mcreate_path2fid () {
11858         local mode=$1
11859         local major=$2
11860         local minor=$3
11861         local name=$4
11862         local desc=$5
11863         local path=$DIR/$tdir/$name
11864         local fid
11865         local rc
11866         local fid_path
11867
11868         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
11869                 error "cannot create $desc"
11870
11871         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
11872         rc=$?
11873         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
11874
11875         fid_path=$($LFS fid2path $MOUNT $fid)
11876         rc=$?
11877         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
11878
11879         [ "$path" == "$fid_path" ] ||
11880                 error "fid2path returned $fid_path, expected $path"
11881
11882         echo "pass with $path and $fid"
11883 }
11884
11885 test_226a () {
11886         rm -rf $DIR/$tdir
11887         mkdir -p $DIR/$tdir
11888
11889         mcreate_path2fid 0010666 0 0 fifo "FIFO"
11890         mcreate_path2fid 0020666 1 3 null "character special file (null)"
11891         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
11892         mcreate_path2fid 0040666 0 0 dir "directory"
11893         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
11894         mcreate_path2fid 0100666 0 0 file "regular file"
11895         mcreate_path2fid 0120666 0 0 link "symbolic link"
11896         mcreate_path2fid 0140666 0 0 sock "socket"
11897 }
11898 run_test 226a "call path2fid and fid2path on files of all type"
11899
11900 test_226b () {
11901         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11902         rm -rf $DIR/$tdir
11903         local MDTIDX=1
11904
11905         mkdir -p $DIR/$tdir
11906         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
11907                 error "create remote directory failed"
11908         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
11909         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
11910                                 "character special file (null)"
11911         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
11912                                 "character special file (no device)"
11913         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
11914         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
11915                                 "block special file (loop)"
11916         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
11917         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
11918         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
11919 }
11920 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
11921
11922 # LU-1299 Executing or running ldd on a truncated executable does not
11923 # cause an out-of-memory condition.
11924 test_227() {
11925         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11926         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
11927         dd if=$(which date) of=$MOUNT/date bs=1k count=1
11928         chmod +x $MOUNT/date
11929
11930         $MOUNT/date > /dev/null
11931         ldd $MOUNT/date > /dev/null
11932         rm -f $MOUNT/date
11933 }
11934 run_test 227 "running truncated executable does not cause OOM"
11935
11936 # LU-1512 try to reuse idle OI blocks
11937 test_228a() {
11938         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11939         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11940         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11941                 skip "non-ldiskfs backend" && return
11942
11943         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11944         local myDIR=$DIR/$tdir
11945
11946         mkdir -p $myDIR
11947         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11948         $LCTL set_param fail_loc=0x80001002
11949         createmany -o $myDIR/t- 10000
11950         $LCTL set_param fail_loc=0
11951         # The guard is current the largest FID holder
11952         touch $myDIR/guard
11953         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11954                     tr -d '[')
11955         local IDX=$(($SEQ % 64))
11956
11957         do_facet $SINGLEMDS sync
11958         # Make sure journal flushed.
11959         sleep 6
11960         local blk1=$(do_facet $SINGLEMDS \
11961                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11962                      grep Blockcount | awk '{print $4}')
11963
11964         # Remove old files, some OI blocks will become idle.
11965         unlinkmany $myDIR/t- 10000
11966         # Create new files, idle OI blocks should be reused.
11967         createmany -o $myDIR/t- 2000
11968         do_facet $SINGLEMDS sync
11969         # Make sure journal flushed.
11970         sleep 6
11971         local blk2=$(do_facet $SINGLEMDS \
11972                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
11973                      grep Blockcount | awk '{print $4}')
11974
11975         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
11976 }
11977 run_test 228a "try to reuse idle OI blocks"
11978
11979 test_228b() {
11980         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11981         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11982         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
11983                 skip "non-ldiskfs backend" && return
11984
11985         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11986         local myDIR=$DIR/$tdir
11987
11988         mkdir -p $myDIR
11989         #define OBD_FAIL_SEQ_EXHAUST             0x1002
11990         $LCTL set_param fail_loc=0x80001002
11991         createmany -o $myDIR/t- 10000
11992         $LCTL set_param fail_loc=0
11993         # The guard is current the largest FID holder
11994         touch $myDIR/guard
11995         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
11996                     tr -d '[')
11997         local IDX=$(($SEQ % 64))
11998
11999         do_facet $SINGLEMDS sync
12000         # Make sure journal flushed.
12001         sleep 6
12002         local blk1=$(do_facet $SINGLEMDS \
12003                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12004                      grep Blockcount | awk '{print $4}')
12005
12006         # Remove old files, some OI blocks will become idle.
12007         unlinkmany $myDIR/t- 10000
12008
12009         # stop the MDT
12010         stop $SINGLEMDS || error "Fail to stop MDT."
12011         # remount the MDT
12012         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
12013
12014         df $MOUNT || error "Fail to df."
12015         # Create new files, idle OI blocks should be reused.
12016         createmany -o $myDIR/t- 2000
12017         do_facet $SINGLEMDS sync
12018         # Make sure journal flushed.
12019         sleep 6
12020         local blk2=$(do_facet $SINGLEMDS \
12021                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12022                      grep Blockcount | awk '{print $4}')
12023
12024         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12025 }
12026 run_test 228b "idle OI blocks can be reused after MDT restart"
12027
12028 #LU-1881
12029 test_228c() {
12030         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12031         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12032         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12033                 skip "non-ldiskfs backend" && return
12034
12035         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12036         local myDIR=$DIR/$tdir
12037
12038         mkdir -p $myDIR
12039         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12040         $LCTL set_param fail_loc=0x80001002
12041         # 20000 files can guarantee there are index nodes in the OI file
12042         createmany -o $myDIR/t- 20000
12043         $LCTL set_param fail_loc=0
12044         # The guard is current the largest FID holder
12045         touch $myDIR/guard
12046         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12047                     tr -d '[')
12048         local IDX=$(($SEQ % 64))
12049
12050         do_facet $SINGLEMDS sync
12051         # Make sure journal flushed.
12052         sleep 6
12053         local blk1=$(do_facet $SINGLEMDS \
12054                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12055                      grep Blockcount | awk '{print $4}')
12056
12057         # Remove old files, some OI blocks will become idle.
12058         unlinkmany $myDIR/t- 20000
12059         rm -f $myDIR/guard
12060         # The OI file should become empty now
12061
12062         # Create new files, idle OI blocks should be reused.
12063         createmany -o $myDIR/t- 2000
12064         do_facet $SINGLEMDS sync
12065         # Make sure journal flushed.
12066         sleep 6
12067         local blk2=$(do_facet $SINGLEMDS \
12068                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12069                      grep Blockcount | awk '{print $4}')
12070
12071         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12072 }
12073 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
12074
12075 test_229() { # LU-2482, LU-3448
12076         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
12077                 skip "No HSM support on MDS of $(get_lustre_version)," \
12078                          "need 2.4.53 at least" && return
12079         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12080         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
12081
12082         rm -f $DIR/$tfile
12083
12084         # Create a file with a released layout and stripe count 2.
12085         $MULTIOP $DIR/$tfile H2c ||
12086                 error "failed to create file with released layout"
12087
12088         $GETSTRIPE -v $DIR/$tfile
12089
12090         local pattern=$($GETSTRIPE -L $DIR/$tfile)
12091         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
12092
12093         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
12094         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
12095         stat $DIR/$tfile || error "failed to stat released file"
12096
12097         chown $RUNAS_ID $DIR/$tfile ||
12098                 error "chown $RUNAS_ID $DIR/$tfile failed"
12099
12100         chgrp $RUNAS_ID $DIR/$tfile ||
12101                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12102
12103         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12104         rm $DIR/$tfile || error "failed to remove released file"
12105 }
12106 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12107
12108 test_230a() {
12109         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12110         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12111         local MDTIDX=1
12112
12113         mkdir -p $DIR/$tdir/test_230_local
12114         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12115         [ $mdt_idx -ne 0 ] &&
12116                 error "create local directory on wrong MDT $mdt_idx"
12117
12118         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12119                         error "create remote directory failed"
12120         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12121         [ $mdt_idx -ne $MDTIDX ] &&
12122                 error "create remote directory on wrong MDT $mdt_idx"
12123
12124         createmany -o $DIR/$tdir/test_230/t- 10 ||
12125                 error "create files on remote directory failed"
12126         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12127         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12128         rm -r $DIR/$tdir || error "unlink remote directory failed"
12129 }
12130 run_test 230a "Create remote directory and files under the remote directory"
12131
12132 test_230b() {
12133         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12134         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12135         local MDTIDX=1
12136         local mdt_index
12137         local i
12138         local file
12139         local pid
12140         local stripe_count
12141         local migrate_dir=$DIR/$tdir/migrate_dir
12142         local other_dir=$DIR/$tdir/other_dir
12143
12144         mkdir -p $migrate_dir
12145         mkdir -p $other_dir
12146         for ((i=0; i<10; i++)); do
12147                 mkdir -p $migrate_dir/dir_${i}
12148                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12149                         error "create files under remote dir failed $i"
12150         done
12151
12152         cp /etc/passwd $migrate_dir/$tfile
12153         cp /etc/passwd $other_dir/$tfile
12154         chattr +SAD $migrate_dir
12155         chattr +SAD $migrate_dir/$tfile
12156
12157         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12158         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12159         local old_dir_mode=$(stat -c%f $migrate_dir)
12160         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
12161
12162         mkdir -p $migrate_dir/dir_default_stripe2
12163         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12164         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12165
12166         mkdir -p $other_dir
12167         ln $migrate_dir/$tfile $other_dir/luna
12168         ln $migrate_dir/$tfile $migrate_dir/sofia
12169         ln $other_dir/$tfile $migrate_dir/david
12170         ln -s $migrate_dir/$tfile $other_dir/zachary
12171         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12172         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12173
12174         $LFS mv -v -M $MDTIDX $migrate_dir ||
12175                         error "migrate remote dir error"
12176
12177         echo "migratate to MDT1, then checking.."
12178         for ((i=0; i<10; i++)); do
12179                 for file in $(find $migrate_dir/dir_${i}); do
12180                         mdt_index=$($LFS getstripe -M $file)
12181                         [ $mdt_index == $MDTIDX ] ||
12182                                 error "$file is not on MDT${MDTIDX}"
12183                 done
12184         done
12185
12186         # the multiple link file should still in MDT0
12187         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12188         [ $mdt_index == 0 ] ||
12189                 error "$file is not on MDT${MDTIDX}"
12190
12191         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12192         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12193                 error " expect $old_dir_flag get $new_dir_flag"
12194
12195         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12196         [ "$old_file_flag" = "$new_file_flag" ] ||
12197                 error " expect $old_file_flag get $new_file_flag"
12198
12199         local new_dir_mode=$(stat -c%f $migrate_dir)
12200         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12201                 error "expect mode $old_dir_mode get $new_dir_mode"
12202
12203         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12204         [ "$old_file_mode" = "$new_file_mode" ] ||
12205                 error "expect mode $old_file_mode get $new_file_mode"
12206
12207         diff /etc/passwd $migrate_dir/$tfile ||
12208                 error "$tfile different after migration"
12209
12210         diff /etc/passwd $other_dir/luna ||
12211                 error "luna different after migration"
12212
12213         diff /etc/passwd $migrate_dir/sofia ||
12214                 error "sofia different after migration"
12215
12216         diff /etc/passwd $migrate_dir/david ||
12217                 error "david different after migration"
12218
12219         diff /etc/passwd $other_dir/zachary ||
12220                 error "zachary different after migration"
12221
12222         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12223                 error "${tfile}_ln different after migration"
12224
12225         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12226                 error "${tfile}_ln_other different after migration"
12227
12228         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12229         [ $stripe_count = 2 ] ||
12230                         error "dir strpe_count $d != 2 after migration."
12231
12232         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12233         [ $stripe_count = 2 ] ||
12234                         error "file strpe_count $d != 2 after migration."
12235
12236         #migrate back to MDT0
12237         MDTIDX=0
12238         $LFS mv -v -M $MDTIDX $migrate_dir ||
12239                         error "migrate remote dir error"
12240
12241         echo "migrate back to MDT0, checking.."
12242         for file in $(find $migrate_dir); do
12243                 mdt_index=$($LFS getstripe -M $file)
12244                 [ $mdt_index == $MDTIDX ] ||
12245                         error "$file is not on MDT${MDTIDX}"
12246         done
12247
12248         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12249         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12250                 error " expect $old_dir_flag get $new_dir_flag"
12251
12252         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12253         [ "$old_file_flag" = "$new_file_flag" ] ||
12254                 error " expect $old_file_flag get $new_file_flag"
12255
12256         local new_dir_mode=$(stat -c%f $migrate_dir)
12257         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12258                 error "expect mode $old_dir_mode get $new_dir_mode"
12259
12260         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12261         [ "$old_file_mode" = "$new_file_mode" ] ||
12262                 error "expect mode $old_file_mode get $new_file_mode"
12263
12264         diff /etc/passwd ${migrate_dir}/$tfile ||
12265                 error "$tfile different after migration"
12266
12267         diff /etc/passwd ${other_dir}/luna ||
12268                 error "luna different after migration"
12269
12270         diff /etc/passwd ${migrate_dir}/sofia ||
12271                 error "sofia different after migration"
12272
12273         diff /etc/passwd ${other_dir}/zachary ||
12274                 error "zachary different after migration"
12275
12276         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12277                 error "${tfile}_ln different after migration"
12278
12279         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12280                 error "${tfile}_ln_other different after migration"
12281
12282         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12283         [ $stripe_count = 2 ] ||
12284                 error "dir strpe_count $d != 2 after migration."
12285
12286         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12287         [ $stripe_count = 2 ] ||
12288                 error "file strpe_count $d != 2 after migration."
12289
12290         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12291 }
12292 run_test 230b "migrate directory"
12293
12294 test_230c() {
12295         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12296         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12297         local MDTIDX=1
12298         local mdt_index
12299         local file
12300
12301         #If migrating directory fails in the middle, all entries of
12302         #the directory is still accessiable.
12303         mkdir -p $DIR/$tdir
12304         stat $DIR/$tdir
12305         createmany -o $DIR/$tdir/f 10 ||
12306                 error "create files under ${tdir} failed"
12307
12308         #failed after migrating 5 entries
12309         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12310         do_facet mds1 lctl set_param fail_loc=0x20001801
12311         do_facet mds1 lctl  set_param fail_val=5
12312         local t=`ls $DIR/$tdir | wc -l`
12313         $LFS mv -M $MDTIDX $DIR/$tdir &&
12314                 error "migrate should failed after 5 entries"
12315         local u=`ls $DIR/$tdir | wc -l`
12316         [ "$u" == "$t" ] || error "$u != $t during migration"
12317
12318         for file in $(find $DIR/$tdir); do
12319                 stat $file || error "stat $file failed"
12320         done
12321
12322         do_facet mds1 lctl set_param fail_loc=0
12323         do_facet mds1 lctl set_param fail_val=0
12324
12325         $LFS mv -M $MDTIDX $DIR/$tdir ||
12326                 error "migrate open files should failed with open files"
12327
12328         echo "Finish migration, then checking.."
12329         for file in $(find $DIR/$tdir); do
12330                 mdt_index=$($LFS getstripe -M $file)
12331                 [ $mdt_index == $MDTIDX ] ||
12332                         error "$file is not on MDT${MDTIDX}"
12333         done
12334
12335         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12336 }
12337 run_test 230c "check directory accessiblity if migration is failed"
12338
12339 test_230d() {
12340         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12341         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12342         local MDTIDX=1
12343         local mdt_index
12344         local i
12345         local j
12346
12347         mkdir -p $DIR/$tdir
12348
12349         for ((i=0; i<100; i++)); do
12350                 mkdir -p $DIR/$tdir/dir_${i}
12351                 createmany -o $DIR/$tdir/dir_${i}/f 100 ||
12352                         error "create files under remote dir failed $i"
12353         done
12354
12355         $LFS mv -M $MDTIDX -v $DIR/$tdir || error "migrate remote dir error"
12356
12357         echo "Finish migration, then checking.."
12358         for file in $(find $DIR/$tdir); do
12359                 mdt_index=$($LFS getstripe -M $file)
12360                 [ $mdt_index == $MDTIDX ] ||
12361                         error "$file is not on MDT${MDTIDX}"
12362         done
12363
12364         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12365 }
12366 run_test 230d "check migrate big directory"
12367
12368 test_231a()
12369 {
12370         # For simplicity this test assumes that max_pages_per_rpc
12371         # is the same across all OSCs
12372         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
12373         local bulk_size=$((max_pages * 4096))
12374
12375         mkdir -p $DIR/$tdir
12376
12377         # clear the OSC stats
12378         $LCTL set_param osc.*.stats=0 &>/dev/null
12379
12380         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
12381         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
12382                 oflag=direct &>/dev/null || error "dd failed"
12383
12384         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
12385         if [ x$nrpcs != "x1" ]; then
12386                 error "found $nrpc ost_write RPCs, not 1 as expected"
12387         fi
12388
12389         # Drop the OSC cache, otherwise we will read from it
12390         cancel_lru_locks osc
12391
12392         # clear the OSC stats
12393         $LCTL set_param osc.*.stats=0 &>/dev/null
12394
12395         # Client reads $bulk_size.
12396         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
12397                 iflag=direct &>/dev/null || error "dd failed"
12398
12399         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
12400         if [ x$nrpcs != "x1" ]; then
12401                 error "found $nrpc ost_read RPCs, not 1 as expected"
12402         fi
12403 }
12404 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
12405
12406 test_231b() {
12407         mkdir -p $DIR/$tdir
12408         local i
12409         for i in {0..1023}; do
12410                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
12411                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
12412                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
12413         done
12414         sync
12415 }
12416 run_test 231b "must not assert on fully utilized OST request buffer"
12417
12418 test_232() {
12419         mkdir -p $DIR/$tdir
12420         #define OBD_FAIL_LDLM_OST_LVB            0x31c
12421         $LCTL set_param fail_loc=0x31c
12422
12423         # ignore dd failure
12424         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
12425
12426         $LCTL set_param fail_loc=0
12427         umount_client $MOUNT || error "umount failed"
12428         mount_client $MOUNT || error "mount failed"
12429 }
12430 run_test 232 "failed lock should not block umount"
12431
12432 test_233a() {
12433         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
12434         { skip "Need MDS version at least 2.3.64"; return; }
12435
12436         local fid=$($LFS path2fid $MOUNT)
12437         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12438                 error "cannot access $MOUNT using its FID '$fid'"
12439 }
12440 run_test 233a "checking that OBF of the FS root succeeds"
12441
12442 test_233b() {
12443         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
12444         { skip "Need MDS version at least 2.5.90"; return; }
12445
12446         local fid=$($LFS path2fid $MOUNT/.lustre)
12447         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12448                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
12449
12450         fid=$($LFS path2fid $MOUNT/.lustre/fid)
12451         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12452                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
12453 }
12454 run_test 233b "checking that OBF of the FS .lustre succeeds"
12455
12456 test_234() {
12457         local p="$TMP/sanityN-$TESTNAME.parameters"
12458         save_lustre_params client "llite.*.xattr_cache" > $p
12459         lctl set_param llite.*.xattr_cache 1 ||
12460                 { skip "xattr cache is not supported"; return 0; }
12461
12462         mkdir -p $DIR/$tdir || error "mkdir failed"
12463         touch $DIR/$tdir/$tfile || error "touch failed"
12464         # OBD_FAIL_LLITE_XATTR_ENOMEM
12465         $LCTL set_param fail_loc=0x1405
12466         # output of the form: attr 2 4 44 3 fc13 x86_64
12467         V=($(IFS=".-" rpm -q attr))
12468         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
12469               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
12470                 # attr pre-2.4.44-7 had a bug with rc
12471                 # LU-3703 - SLES 11 and FC13 clients have older attr
12472                 getfattr -n user.attr $DIR/$tdir/$tfile &&
12473                         error "getfattr should have failed with ENOMEM"
12474         else
12475                 skip "LU-3703: attr version $(getfattr --version) too old"
12476         fi
12477         $LCTL set_param fail_loc=0x0
12478         rm -rf $DIR/$tdir
12479
12480         restore_lustre_params < $p
12481         rm -f $p
12482 }
12483 run_test 234 "xattr cache should not crash on ENOMEM"
12484
12485 test_235() {
12486         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
12487                 skip "Need MDS version at least 2.4.52" && return
12488         flock_deadlock $DIR/$tfile
12489         local RC=$?
12490         case $RC in
12491                 0)
12492                 ;;
12493                 124) error "process hangs on a deadlock"
12494                 ;;
12495                 *) error "error executing flock_deadlock $DIR/$tfile"
12496                 ;;
12497         esac
12498 }
12499 run_test 235 "LU-1715: flock deadlock detection does not work properly"
12500
12501 #LU-2935
12502 test_236() {
12503         check_swap_layouts_support && return 0
12504         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
12505
12506         local ref1=/etc/passwd
12507         local ref2=/etc/group
12508         local file1=$DIR/$tdir/f1
12509         local file2=$DIR/$tdir/f2
12510
12511         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
12512         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
12513         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
12514         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
12515         local fd=$(free_fd)
12516         local cmd="exec $fd<>$file2"
12517         eval $cmd
12518         rm $file2
12519         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
12520                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
12521         cmd="exec $fd>&-"
12522         eval $cmd
12523         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12524
12525         #cleanup
12526         rm -rf $DIR/$tdir
12527 }
12528 run_test 236 "Layout swap on open unlinked file"
12529
12530 # test to verify file handle related system calls
12531 # (name_to_handle_at/open_by_handle_at)
12532 # The new system calls are supported in glibc >= 2.14.
12533
12534 test_237() {
12535         echo "Test file_handle syscalls" > $DIR/$tfile ||
12536                 error "write failed"
12537         check_fhandle_syscalls $DIR/$tfile ||
12538                 error "check_fhandle_syscalls failed"
12539 }
12540 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
12541
12542 # LU-4659 linkea consistency
12543 test_238() {
12544         local server_version=$(lustre_version_code $SINGLEMDS)
12545
12546         [[ $server_version -gt $(version_code 2.5.57) ]] ||
12547                 [[ $server_version -gt $(version_code 2.5.1) &&
12548                    $server_version -lt $(version_code 2.5.50) ]] ||
12549                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
12550
12551         touch $DIR/$tfile
12552         ln $DIR/$tfile $DIR/$tfile.lnk
12553         touch $DIR/$tfile.new
12554         mv $DIR/$tfile.new $DIR/$tfile
12555         local fid1=$(lfs path2fid $DIR/$tfile)
12556         local fid2=$(lfs path2fid $DIR/$tfile.lnk)
12557         local path1=$(lfs fid2path $FSNAME $fid1)
12558         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
12559         local path2=$(lfs fid2path $FSNAME $fid2)
12560         [ $tfile.lnk == $path2 ] ||
12561                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
12562         rm -f $DIR/$tfile*
12563 }
12564 run_test 238 "Verify linkea consistency"
12565
12566 test_239() {
12567         local list=$(comma_list $(mdts_nodes))
12568
12569         mkdir -p $DIR/$tdir
12570         createmany -o $DIR/$tdir/f- 5000
12571         unlinkmany $DIR/$tdir/f- 5000
12572         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
12573         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
12574                         osc.*MDT*.sync_in_flight" | calc_sum)
12575         [ "$changes" -eq 0 ] || error "$changes not synced"
12576 }
12577 run_test 239 "osp_sync test"
12578
12579 test_240() {
12580         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12581
12582         mkdir -p $DIR/$tdir
12583
12584         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
12585                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
12586         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
12587                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
12588
12589         umount_client $MOUNT || error "umount failed"
12590         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
12591         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
12592         mount_client $MOUNT || error "failed to mount client"
12593
12594         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
12595         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
12596 }
12597 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
12598
12599 test_241_bio() {
12600         for LOOP in $(seq $1); do
12601                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
12602                 cancel_lru_locks osc
12603         done
12604 }
12605
12606 test_241_dio() {
12607         for LOOP in $(seq $1); do
12608                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
12609                                                 iflag=direct 2>/dev/null
12610         done
12611 }
12612
12613 test_241() {
12614         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
12615         ls -la $DIR/$tfile
12616         cancel_lru_locks osc
12617         test_241_bio 1000 &
12618         PID=$!
12619         test_241_dio 1000
12620         wait $PID
12621 }
12622 run_test 241 "bio vs dio"
12623
12624 cleanup_test_300() {
12625         trap 0
12626         umask $SAVE_UMASK
12627 }
12628 test_striped_dir() {
12629         local mdt_index=$1
12630         local stripe_count
12631         local stripe_index
12632
12633         mkdir -p $DIR/$tdir
12634
12635         SAVE_UMASK=$(umask)
12636         trap cleanup_test_300 RETURN EXIT
12637
12638         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
12639                                                 $DIR/$tdir/striped_dir ||
12640                 error "set striped dir error"
12641
12642         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
12643         [ "$mode" = "755" ] || error "expect 755 got $mode"
12644
12645         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
12646         if [ "$stripe_count" != "2" ]; then
12647                 error "stripe_count is $stripe_count, expect 2"
12648         fi
12649
12650         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
12651         if [ "$stripe_index" != "$mdt_index" ]; then
12652                 error "stripe_index is $stripe_index, expect $mdt_index"
12653         fi
12654
12655         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12656                 error "nlink error after create striped dir"
12657
12658         mkdir $DIR/$tdir/striped_dir/a
12659         mkdir $DIR/$tdir/striped_dir/b
12660
12661         stat $DIR/$tdir/striped_dir/a ||
12662                 error "create dir under striped dir failed"
12663         stat $DIR/$tdir/striped_dir/b ||
12664                 error "create dir under striped dir failed"
12665
12666         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
12667                 error "nlink error after mkdir"
12668
12669         rmdir $DIR/$tdir/striped_dir/a
12670         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
12671                 error "nlink error after rmdir"
12672
12673         rmdir $DIR/$tdir/striped_dir/b
12674         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12675                 error "nlink error after rmdir"
12676
12677         rmdir $DIR/$tdir/striped_dir ||
12678                 error "rmdir striped dir error"
12679
12680         cleanup_test_300
12681
12682         true
12683 }
12684
12685 test_300a() {
12686         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12687         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12688
12689         test_striped_dir 0 || error "failed on striped dir on MDT0"
12690         test_striped_dir 1 || error "failed on striped dir on MDT0"
12691 }
12692 run_test 300a "basic striped dir sanity test"
12693
12694 test_300b() {
12695         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12696         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12697         local i
12698         local mtime1
12699         local mtime2
12700         local mtime3
12701
12702         test_mkdir $DIR/$tdir || error "mkdir fail"
12703         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12704                 error "set striped dir error"
12705         for ((i=0; i<10; i++)); do
12706                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
12707                 sleep 1
12708                 touch $DIR/$tdir/striped_dir/file_$i ||
12709                                         error "touch error $i"
12710                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
12711                 [ $mtime1 -eq $mtime2 ] &&
12712                         error "mtime not change after create"
12713                 sleep 1
12714                 rm -f $DIR/$tdir/striped_dir/file_$i ||
12715                                         error "unlink error $i"
12716                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
12717                 [ $mtime2 -eq $mtime3 ] &&
12718                         error "mtime did not change after unlink"
12719         done
12720         true
12721 }
12722 run_test 300b "check ctime/mtime for striped dir"
12723
12724 test_300c() {
12725         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12726         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12727         local file_count
12728
12729         mkdir -p $DIR/$tdir
12730         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
12731                 error "set striped dir error"
12732
12733         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
12734                 error "chown striped dir failed"
12735
12736         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
12737                 error "create 5k files failed"
12738
12739         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
12740
12741         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
12742
12743         rm -rf $DIR/$tdir
12744 }
12745 run_test 300c "chown && check ls under striped directory"
12746
12747 test_300d() {
12748         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12749         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12750         local stripe_count
12751         local file
12752
12753         mkdir -p $DIR/$tdir
12754         $SETSTRIPE -c 2 $DIR/$tdir
12755
12756         #local striped directory
12757         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12758                 error "set striped dir error"
12759         createmany -o $DIR/$tdir/striped_dir/f 10 ||
12760                 error "create 10 files failed"
12761
12762         #remote striped directory
12763         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
12764                 error "set striped dir error"
12765         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
12766                 error "create 10 files failed"
12767
12768         for file in $(find $DIR/$tdir); do
12769                 stripe_count=$($GETSTRIPE -c $file)
12770                 [ $stripe_count -eq 2 ] ||
12771                         error "wrong stripe $stripe_count for $file"
12772         done
12773
12774         rm -rf $DIR/$tdir
12775 }
12776 run_test 300d "check default stripe under striped directory"
12777
12778 test_300e() {
12779         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12780         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12781         local stripe_count
12782         local file
12783
12784         mkdir -p $DIR/$tdir
12785
12786         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12787                 error "set striped dir error"
12788
12789         touch $DIR/$tdir/striped_dir/a
12790         touch $DIR/$tdir/striped_dir/b
12791         touch $DIR/$tdir/striped_dir/c
12792
12793         mkdir $DIR/$tdir/striped_dir/dir_a
12794         mkdir $DIR/$tdir/striped_dir/dir_b
12795         mkdir $DIR/$tdir/striped_dir/dir_c
12796
12797         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
12798                 error "set striped dir under striped dir error"
12799
12800         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
12801                 error "set striped dir under striped dir error"
12802
12803         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
12804                 error "set striped dir under striped dir error"
12805
12806         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/b &&
12807                 error "rename file under striped dir should fail"
12808
12809         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b &&
12810                 error "rename dir under striped dir should fail"
12811
12812         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b &&
12813                 error "rename dir under different stripes should fail"
12814
12815         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
12816                 error "rename file under striped dir should succeed"
12817
12818         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_c ||
12819                 error "rename dir under striped dir should succeed"
12820
12821         rm -rf $DIR/$tdir
12822 }
12823 run_test 300e "check rename under striped directory"
12824
12825 test_300f() {
12826         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12827         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12828         local stripe_count
12829         local file
12830
12831         rm -rf $DIR/$tdir
12832         mkdir -p $DIR/$tdir
12833
12834         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12835                 error "set striped dir error"
12836
12837         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
12838                 error "set striped dir error"
12839
12840         touch $DIR/$tdir/striped_dir/a
12841         mkdir $DIR/$tdir/striped_dir/dir_a
12842         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
12843                 error "create striped dir under striped dir fails"
12844
12845         touch $DIR/$tdir/striped_dir1/b
12846         mkdir $DIR/$tdir/striped_dir1/dir_b
12847         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
12848                 error "create striped dir under striped dir fails"
12849
12850         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/b &&
12851                 error "rename file under different striped dir should fail"
12852
12853         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b &&
12854                 error "rename dir under different striped dir should fail"
12855
12856         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b &&
12857                 error "rename striped dir under diff striped dir should fail"
12858
12859         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
12860                 error "rename file under diff striped dirs fails"
12861
12862         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_a ||
12863                 error "rename dir under diff striped dirs fails"
12864
12865         rm -rf $DIR/$tdir
12866 }
12867 run_test 300f "check rename cross striped directory"
12868
12869 test_300g() {
12870         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12871         local stripe_count
12872         local dir
12873
12874         mkdir $DIR/$tdir
12875         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
12876                                         $DIR/$tdir/striped_dir ||
12877                 error "set striped dir error"
12878
12879         $LFS setdirstripe -D -c $MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
12880                 error "set default stripe on striped dir error"
12881
12882         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/striped_dir)
12883         [ $stripe_count -eq $MDSCOUNT ] ||
12884                 error "default stripe wrong expect $MDSCOUNT get $stripe_count"
12885
12886         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12887
12888         for dir in $(find $DIR/$tdir/striped_dir/*); do
12889                 stripe_count=$($LFS getdirstripe -c $dir)
12890                 [ $stripe_count -eq $MDSCOUNT ] ||
12891                         error "expect $MDSCOUNT get $stripe_count for $dir"
12892         done
12893
12894         rmdir $DIR/$tdir/striped_dir/* || error "rmdir1 failed"
12895         #change default stripe count to 2
12896         $LFS setdirstripe -D -c 2 -t all_char $DIR/$tdir/striped_dir ||
12897                 error "set default stripe on striped dir error"
12898
12899         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12900
12901         rmdir $DIR/$tdir/striped_dir/* || error "rmdir2 failed"
12902
12903         #change default stripe count to 1
12904         $LFS setdirstripe -D -c 1 -t all_char $DIR/$tdir/striped_dir ||
12905                 error "set default stripe on striped dir error"
12906
12907         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12908         for dir in $(find $DIR/$tdir/striped_dir/*); do
12909                 stripe_count=$($LFS getdirstripe -c $dir)
12910                 [ $stripe_count -eq 1 ] ||
12911                         error "expect 1 get $stripe_count for $dir"
12912         done
12913         rmdir $DIR/$tdir/striped_dir/* || error "rmdir3 failed"
12914 }
12915 run_test 300g "check default striped directory for striped directory"
12916
12917 test_300h() {
12918         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12919         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12920         local stripe_count
12921         local file
12922
12923         mkdir $DIR/$tdir
12924
12925         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
12926                 error "set striped dir error"
12927
12928         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
12929                 error "create files under striped dir failed"
12930
12931         # unfortunately, we need to umount to clear dir layout cache for now
12932         # once we fully implement dir layout, we can drop this
12933         umount_client $MOUNT || error "umount failed"
12934         mount_client $MOUNT || error "mount failed"
12935
12936         #set the stripe to be unknown hash type
12937         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
12938         $LCTL set_param fail_loc=0x1901
12939         for ((i = 0; i < 10; i++)); do
12940                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
12941                         error "stat f-$i failed"
12942                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
12943         done
12944
12945         touch $DIR/$tdir/striped_dir/f0 &&
12946                 error "create under striped dir with unknown hash should fail"
12947
12948         $LCTL set_param fail_loc=0
12949
12950         umount_client $MOUNT || error "umount failed"
12951         mount_client $MOUNT || error "mount failed"
12952
12953         return 0
12954 }
12955 run_test 300h "client handle unknown hash type striped directory"
12956
12957 test_400a() { # LU-1606, was conf-sanity test_74
12958         local extra_flags=''
12959         local out=$TMP/$tfile
12960         local prefix=/usr/include/lustre
12961         local prog
12962
12963         if ! which $CC > /dev/null 2>&1; then
12964                 skip_env "$CC is not installed"
12965                 return 0
12966         fi
12967
12968         if ! [[ -d $prefix ]]; then
12969                 # Assume we're running in tree and fixup the include path.
12970                 extra_flags+=" -I$LUSTRE/../libcfs/include"
12971                 extra_flags+=" -I$LUSTRE/include"
12972                 extra_flags+=" -L$LUSTRE/utils"
12973         fi
12974
12975         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
12976                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
12977                         error "client api broken"
12978         done
12979 }
12980 run_test 400a "Lustre client api program can compile and link"
12981
12982 test_400b() { # LU-1606, LU-5011
12983         local header
12984         local out=$TMP/$tfile
12985         local prefix=/usr/include/lustre
12986
12987         # We use a hard coded prefix so that this test will not fail
12988         # when run in tree. There are headers in lustre/include/lustre/
12989         # that are not packaged (like lustre_idl.h) and have more
12990         # complicated include dependencies (like config.h and lnet/types.h).
12991         # Since this test about correct packaging we just skip them when
12992         # they don't exist (see below) rather than try to fixup cppflags.
12993
12994         if ! which $CC > /dev/null 2>&1; then
12995                 skip_env "$CC is not installed"
12996                 return 0
12997         fi
12998
12999         for header in $prefix/*.h; do
13000                 if ! [[ -f "$header" ]]; then
13001                         continue
13002                 fi
13003
13004                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
13005                         continue # liblustreapi.h is deprecated.
13006                 fi
13007
13008                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
13009                         error "cannot compile '$header'"
13010         done
13011 }
13012 run_test 400b "packaged headers can be compiled"
13013
13014 #
13015 # tests that do cleanup/setup should be run at the end
13016 #
13017
13018 test_900() {
13019         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13020         local ls
13021         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
13022         $LCTL set_param fail_loc=0x903
13023
13024         cancel_lru_locks MGC
13025
13026         FAIL_ON_ERROR=true cleanup
13027         FAIL_ON_ERROR=true setup
13028 }
13029 run_test 900 "umount should not race with any mgc requeue thread"
13030
13031 complete $SECONDS
13032 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
13033 check_and_cleanup_lustre
13034 if [ "$I_MOUNTED" != "yes" ]; then
13035         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
13036 fi
13037 exit_status