Whamcloud - gitweb
LU-3540 lod: update recovery thread
[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 24D 27m 64b 68 71 77f 78 115 124b 230d"
62
63 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
64         # bug number for skipped test: LU-4536 LU-1957 LU-2805
65         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  65ic    180     184c"
66         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b 51ba"
67 fi
68
69 FAIL_ON_ERROR=false
70
71 cleanup() {
72         echo -n "cln.."
73         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
74         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
75 }
76 setup() {
77         echo -n "mnt.."
78         load_modules
79         setupall || exit 10
80         echo "done"
81 }
82
83 check_swap_layouts_support()
84 {
85         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
86                 { skip "Does not support layout lock."; return 0; }
87         return 1
88 }
89
90 check_and_setup_lustre
91
92 DIR=${DIR:-$MOUNT}
93 assert_DIR
94
95 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
96         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
97 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
98 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
99 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
100 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
101 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
102 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
103
104 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
105 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
106 rm -rf $DIR/[Rdfs][0-9]*
107
108 # $RUNAS_ID may get set incorrectly somewhere else
109 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
110
111 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
112
113 build_test_filter
114
115 if [ "${ONLY}" = "MOUNT" ] ; then
116         echo "Lustre is up, please go on"
117         exit
118 fi
119
120 echo "preparing for tests involving mounts"
121 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
122 touch $EXT2_DEV
123 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
124 echo # add a newline after mke2fs.
125
126 umask 077
127
128 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
129 lctl set_param debug=-1 2> /dev/null || true
130 test_0a() {
131         touch $DIR/$tfile
132         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
133         rm $DIR/$tfile
134         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
135 }
136 run_test 0a "touch; rm ====================="
137
138 test_0b() {
139         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
140         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
141 }
142 run_test 0b "chmod 0755 $DIR ============================="
143
144 test_0c() {
145         $LCTL get_param mdc.*.import | grep "state: FULL" ||
146                 error "import not FULL"
147         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
148                 error "bad target"
149 }
150 run_test 0c "check import proc ============================="
151
152 test_1() {
153         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
154         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
155         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
156         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
157         rmdir $DIR/$tdir/d2
158         rmdir $DIR/$tdir
159         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
160 }
161 run_test 1 "mkdir; remkdir; rmdir =============================="
162
163 test_2() {
164         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
165         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
166         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
167         rm -r $DIR/$tdir
168         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
169 }
170 run_test 2 "mkdir; touch; rmdir; check file ===================="
171
172 test_3() {
173         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
174         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
175         touch $DIR/$tdir/$tfile
176         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
177         rm -r $DIR/$tdir
178         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
179 }
180 run_test 3 "mkdir; touch; rmdir; check dir ====================="
181
182 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
183 test_4() {
184         local MDTIDX=1
185
186         test_mkdir $DIR/$tdir ||
187                 error "Create remote directory failed"
188
189         touch $DIR/$tdir/$tfile ||
190                 error "Create file under remote directory failed"
191
192         rmdir $DIR/$tdir &&
193                 error "Expect error removing in-use dir $DIR/$tdir"
194
195         test -d $DIR/$tdir || error "Remote directory disappeared"
196
197         rm -rf $DIR/$tdir || error "remove remote dir error"
198 }
199 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
200
201 test_5() {
202         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
203         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
204         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
205         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
206         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
207 }
208 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
209
210 test_6a() {
211         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
212         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
213         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
214                 error "$tfile does not have perm 0666 or UID $UID"
215         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
216         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
217                 error "$tfile should be 0666 and owned by UID $UID"
218 }
219 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
220
221 test_6c() {
222         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
223         touch $DIR/$tfile
224         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
225         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
226                 error "$tfile should be owned by UID $RUNAS_ID"
227         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
228         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
229                 error "$tfile should be owned by UID $RUNAS_ID"
230 }
231 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
232
233 test_6e() {
234         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
235         touch $DIR/$tfile
236         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
237         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
238                 error "$tfile should be owned by GID $UID"
239         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
240         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
241                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
242 }
243 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
244
245 test_6g() {
246         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
247         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
248         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
249         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
250         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
251         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
252         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
253                 error "$tdir/d/subdir should be GID $RUNAS_GID"
254 }
255 run_test 6g "Is new dir in sgid dir inheriting group?"
256
257 test_6h() { # bug 7331
258         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
259         touch $DIR/$tfile || error "touch failed"
260         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
261         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
262                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
263         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
264                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
265 }
266 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
267
268 test_7a() {
269         test_mkdir $DIR/$tdir
270         $MCREATE $DIR/$tdir/$tfile
271         chmod 0666 $DIR/$tdir/$tfile
272         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
273                 error "$tdir/$tfile should be mode 0666"
274 }
275 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
276
277 test_7b() {
278         if [ ! -d $DIR/$tdir ]; then
279                 mkdir $DIR/$tdir
280         fi
281         $MCREATE $DIR/$tdir/$tfile
282         echo -n foo > $DIR/$tdir/$tfile
283         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
284         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
285 }
286 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
287
288 test_8() {
289         test_mkdir $DIR/$tdir
290         touch $DIR/$tdir/$tfile
291         chmod 0666 $DIR/$tdir/$tfile
292         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
293                 error "$tfile mode not 0666"
294 }
295 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
296
297 test_9() {
298         test_mkdir $DIR/$tdir
299         test_mkdir $DIR/$tdir/d2
300         test_mkdir $DIR/$tdir/d2/d3
301         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
302 }
303 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
304
305 test_10() {
306         test_mkdir $DIR/$tdir
307         test_mkdir $DIR/$tdir/d2
308         touch $DIR/$tdir/d2/$tfile
309         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
310                 error "$tdir/d2/$tfile not a file"
311 }
312 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
313
314 test_11() {
315         test_mkdir $DIR/$tdir
316         test_mkdir $DIR/$tdir/d2
317         chmod 0666 $DIR/$tdir/d2
318         chmod 0705 $DIR/$tdir/d2
319         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
320                 error "$tdir/d2 mode not 0705"
321 }
322 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
323
324 test_12() {
325         test_mkdir $DIR/$tdir
326         touch $DIR/$tdir/$tfile
327         chmod 0666 $DIR/$tdir/$tfile
328         chmod 0654 $DIR/$tdir/$tfile
329         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
330                 error "$tdir/d2 mode not 0654"
331 }
332 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
333
334 test_13() {
335         test_mkdir $DIR/$tdir
336         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
337         >  $DIR/$tdir/$tfile
338         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
339                 error "$tdir/$tfile size not 0 after truncate"
340 }
341 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
342
343 test_14() {
344         test_mkdir $DIR/$tdir
345         touch $DIR/$tdir/$tfile
346         rm $DIR/$tdir/$tfile
347         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
348 }
349 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
350
351 test_15() {
352         test_mkdir $DIR/$tdir
353         touch $DIR/$tdir/$tfile
354         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
355         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
356                 error "$tdir/${tfile_2} not a file after rename"
357 }
358 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
359
360 test_16() {
361         test_mkdir $DIR/$tdir
362         touch $DIR/$tdir/$tfile
363         rm -rf $DIR/$tdir/$tfile
364         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
365 }
366 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
367
368 test_17a() {
369         test_mkdir -p $DIR/$tdir
370         touch $DIR/$tdir/$tfile
371         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
372         ls -l $DIR/$tdir
373         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
374                 error "$tdir/l-exist not a symlink"
375         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
376                 error "$tdir/l-exist not referencing a file"
377         rm -f $DIR/$tdir/l-exist
378         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
379 }
380 run_test 17a "symlinks: create, remove (real) =================="
381
382 test_17b() {
383         test_mkdir -p $DIR/$tdir
384         ln -s no-such-file $DIR/$tdir/l-dangle
385         ls -l $DIR/$tdir
386         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
387                 error "$tdir/l-dangle not referencing no-such-file"
388         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
389                 error "$tdir/l-dangle not referencing non-existent file"
390         rm -f $DIR/$tdir/l-dangle
391         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
392 }
393 run_test 17b "symlinks: create, remove (dangling) =============="
394
395 test_17c() { # bug 3440 - don't save failed open RPC for replay
396         test_mkdir -p $DIR/$tdir
397         ln -s foo $DIR/$tdir/$tfile
398         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
399 }
400 run_test 17c "symlinks: open dangling (should return error) ===="
401
402 test_17d() {
403         test_mkdir -p $DIR/$tdir
404         ln -s foo $DIR/$tdir/$tfile
405         touch $DIR/$tdir/$tfile || error "creating to new symlink"
406 }
407 run_test 17d "symlinks: create dangling ========================"
408
409 test_17e() {
410         test_mkdir -p $DIR/$tdir
411         local foo=$DIR/$tdir/$tfile
412         ln -s $foo $foo || error "create symlink failed"
413         ls -l $foo || error "ls -l failed"
414         ls $foo && error "ls not failed" || true
415 }
416 run_test 17e "symlinks: create recursive symlink (should return error) ===="
417
418 test_17f() {
419         test_mkdir -p $DIR/$tdir
420         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
421         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
422         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
423         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
424         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
425         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
426         ls -l  $DIR/$tdir
427 }
428 run_test 17f "symlinks: long and very long symlink name ========================"
429
430 # str_repeat(S, N) generate a string that is string S repeated N times
431 str_repeat() {
432         local s=$1
433         local n=$2
434         local ret=''
435         while [ $((n -= 1)) -ge 0 ]; do
436                 ret=$ret$s
437         done
438         echo $ret
439 }
440
441 # Long symlinks and LU-2241
442 test_17g() {
443         test_mkdir -p $DIR/$tdir
444         local TESTS="59 60 61 4094 4095"
445
446         # Fix for inode size boundary in 2.1.4
447         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
448                 TESTS="4094 4095"
449
450         # Patch not applied to 2.2 or 2.3 branches
451         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
452         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
453                 TESTS="4094 4095"
454
455         # skip long symlink name for rhel6.5.
456         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
457         grep -q '6.5' /etc/redhat-release &>/dev/null &&
458                 TESTS="59 60 61 4062 4063"
459
460         for i in $TESTS; do
461                 local SYMNAME=$(str_repeat 'x' $i)
462                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
463                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
464         done
465 }
466 run_test 17g "symlinks: really long symlink name and inode boundaries"
467
468 test_17h() { #bug 17378
469         remote_mds_nodsh && skip "remote MDS with nodsh" && return
470         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
471         local mdt_idx
472         test_mkdir -p $DIR/$tdir
473         if [[ $MDSCOUNT -gt 1 ]]; then
474                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
475         else
476                 mdt_idx=0
477         fi
478         $SETSTRIPE -c -1 $DIR/$tdir
479 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
480         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
481         touch $DIR/$tdir/$tfile || true
482 }
483 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
484
485 test_17i() { #bug 20018
486         remote_mds_nodsh && skip "remote MDS with nodsh" && return
487         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
488         test_mkdir -c1 $DIR/$tdir
489         local foo=$DIR/$tdir/$tfile
490         local mdt_idx
491         if [[ $MDSCOUNT -gt 1 ]]; then
492                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
493         else
494                 mdt_idx=0
495         fi
496         ln -s $foo $foo || error "create symlink failed"
497 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
498         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
499         ls -l $foo && error "error not detected"
500         return 0
501 }
502 run_test 17i "don't panic on short symlink"
503
504 test_17k() { #bug 22301
505         [[ -z "$(which rsync 2>/dev/null)" ]] &&
506                 skip "no rsync command" && return 0
507         rsync --help | grep -q xattr ||
508                 skip_env "$(rsync --version | head -n1) does not support xattrs"
509         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
510         test_mkdir -p $DIR/$tdir
511         test_mkdir -p $DIR/$tdir.new
512         touch $DIR/$tdir/$tfile
513         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
514         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
515                 error "rsync failed with xattrs enabled"
516 }
517 run_test 17k "symlinks: rsync with xattrs enabled ========================="
518
519 test_17l() { # LU-279
520         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
521                 skip "no getfattr command" && return 0
522         mkdir -p $DIR/$tdir
523         touch $DIR/$tdir/$tfile
524         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
525         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
526                 # -h to not follow symlinks. -m '' to list all the xattrs.
527                 # grep to remove first line: '# file: $path'.
528                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
529                 do
530                         lgetxattr_size_check $path $xattr ||
531                                 error "lgetxattr_size_check $path $xattr failed"
532                 done
533         done
534 }
535 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
536
537 # LU-1540
538 test_17m() {
539         local short_sym="0123456789"
540         local WDIR=$DIR/${tdir}m
541         local mds_index
542         local devname
543         local cmd
544         local i
545         local rc=0
546
547         remote_mds_nodsh && skip "remote MDS with nodsh" && return
548         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
549         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
550                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
551
552         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
553                 skip "only for ldiskfs MDT" && return 0
554
555         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
556
557         mkdir -p $WDIR
558         long_sym=$short_sym
559         # create a long symlink file
560         for ((i = 0; i < 4; ++i)); do
561                 long_sym=${long_sym}${long_sym}
562         done
563
564         echo "create 512 short and long symlink files under $WDIR"
565         for ((i = 0; i < 256; ++i)); do
566                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
567                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
568         done
569
570         echo "erase them"
571         rm -f $WDIR/*
572         sync
573         wait_delete_completed
574
575         echo "recreate the 512 symlink files with a shorter string"
576         for ((i = 0; i < 512; ++i)); do
577                 # rewrite the symlink file with a shorter string
578                 ln -sf ${long_sym} $WDIR/long-$i
579                 ln -sf ${short_sym} $WDIR/short-$i
580         done
581
582         mds_index=$($LFS getstripe -M $WDIR)
583         mds_index=$((mds_index+1))
584         devname=$(mdsdevname $mds_index)
585         cmd="$E2FSCK -fnvd $devname"
586
587         echo "stop and checking mds${mds_index}: $cmd"
588         # e2fsck should not return error
589         stop mds${mds_index}
590         do_facet mds${mds_index} $cmd || rc=$?
591
592         start mds${mds_index} $devname $MDS_MOUNT_OPTS || error "start failed"
593         df $MOUNT > /dev/null 2>&1
594         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
595                 "short/long symlink MDT: rc=$rc"
596         return $rc
597 }
598 run_test 17m "run e2fsck against MDT which contains short/long symlink"
599
600 check_fs_consistency_17n() {
601         local mdt_index
602         local devname
603         local cmd
604         local rc=0
605
606         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
607         # so it only check MDT1/MDT2 instead of all of MDTs.
608         for mdt_index in $(seq 1 2); do
609                 devname=$(mdsdevname $mdt_index)
610                 cmd="$E2FSCK -fnvd $devname"
611
612                 echo "stop and checking mds${mdt_index}: $cmd"
613                 # e2fsck should not return error
614                 stop mds${mdt_index}
615                 do_facet mds${mdt_index} $cmd || rc=$?
616
617                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
618                         error "mount mds${mdt_index} failed"
619                 df $MOUNT > /dev/null 2>&1
620                 [ $rc -ne 0 ] && break
621         done
622         return $rc
623 }
624
625 test_17n() {
626         local i
627
628         remote_mds_nodsh && skip "remote MDS with nodsh" && return
629         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
630         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
631                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
632
633         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
634                 skip "only for ldiskfs MDT" && return 0
635
636         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
637
638         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
639
640         mkdir $DIR/$tdir
641         for ((i=0; i<10; i++)); do
642                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
643                         error "create remote dir error $i"
644                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
645                         error "create files under remote dir failed $i"
646         done
647
648         check_fs_consistency_17n ||
649                 error "e2fsck report error after create files under remote dir"
650
651         for ((i = 0; i < 10; i++)); do
652                 rm -rf $DIR/$tdir/remote_dir_${i} ||
653                         error "destroy remote dir error $i"
654         done
655
656         check_fs_consistency_17n ||
657                 error "e2fsck report error after unlink files under remote dir"
658
659         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
660                 skip "lustre < 2.4.50 does not support migrate mv " && return
661
662         for ((i = 0; i < 10; i++)); do
663                 mkdir -p $DIR/$tdir/remote_dir_${i}
664                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
665                         error "create files under remote dir failed $i"
666                 $LFS mv --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
667                         error "migrate remote dir error $i"
668         done
669         check_fs_consistency_17n || error "e2fsck report error after migration"
670
671         for ((i = 0; i < 10; i++)); do
672                 rm -rf $DIR/$tdir/remote_dir_${i} ||
673                         error "destroy remote dir error $i"
674         done
675
676         check_fs_consistency_17n || error "e2fsck report error after unlink"
677 }
678 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
679
680 test_17o() {
681         remote_mds_nodsh && skip "remote MDS with nodsh" && return
682         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
683                 skip "Need MDS version at least 2.3.64" && return
684
685         local WDIR=$DIR/${tdir}o
686         local mdt_index
687         local rc=0
688
689         mkdir -p $WDIR
690         mdt_index=$($LFS getstripe -M $WDIR)
691         mdt_index=$((mdt_index+1))
692
693         touch $WDIR/$tfile
694
695         #fail mds will wait the failover finish then set
696         #following fail_loc to avoid interfer the recovery process.
697         fail mds${mdt_index}
698
699         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
700         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
701         ls -l $WDIR/$tfile && rc=1
702         do_facet mds${mdt_index} lctl set_param fail_loc=0
703         [[ $rc -ne 0 ]] && error "stat file should fail"
704         true
705 }
706 run_test 17o "stat file with incompat LMA feature"
707
708 test_18() {
709         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
710         ls $DIR || error "Failed to ls $DIR: $?"
711 }
712 run_test 18 "touch .../f ; ls ... =============================="
713
714 test_19a() {
715         touch $DIR/$tfile
716         ls -l $DIR
717         rm $DIR/$tfile
718         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
719 }
720 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
721
722 test_19b() {
723         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
724 }
725 run_test 19b "ls -l .../f19 (should return error) =============="
726
727 test_19c() {
728         [ $RUNAS_ID -eq $UID ] &&
729                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
730         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
731 }
732 run_test 19c "$RUNAS touch .../f19 (should return error) =="
733
734 test_19d() {
735         cat $DIR/f19 && error || true
736 }
737 run_test 19d "cat .../f19 (should return error) =============="
738
739 test_20() {
740         touch $DIR/$tfile
741         rm $DIR/$tfile
742         log "1 done"
743         touch $DIR/$tfile
744         rm $DIR/$tfile
745         log "2 done"
746         touch $DIR/$tfile
747         rm $DIR/$tfile
748         log "3 done"
749         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
750 }
751 run_test 20 "touch .../f ; ls -l ... ==========================="
752
753 test_21() {
754         test_mkdir -p $DIR/$tdir
755         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
756         ln -s dangle $DIR/$tdir/link
757         echo foo >> $DIR/$tdir/link
758         cat $DIR/$tdir/dangle
759         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
760         $CHECKSTAT -f -t file $DIR/$tdir/link ||
761                 error "$tdir/link not linked to a file"
762 }
763 run_test 21 "write to dangling link ============================"
764
765 test_22() {
766         WDIR=$DIR/$tdir
767         test_mkdir -p $DIR/$tdir
768         chown $RUNAS_ID:$RUNAS_GID $WDIR
769         (cd $WDIR || error "cd $WDIR failed";
770         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
771         $RUNAS tar xf -)
772         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
773         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
774         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
775 }
776 run_test 22 "unpack tar archive as non-root user ==============="
777
778 # was test_23
779 test_23a() {
780         test_mkdir -p $DIR/$tdir
781         local file=$DIR/$tdir/$tfile
782
783         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
784         openfile -f O_CREAT:O_EXCL $file &&
785                 error "$file recreate succeeded" || true
786 }
787 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
788
789 test_23b() { # bug 18988
790         test_mkdir -p $DIR/$tdir
791         local file=$DIR/$tdir/$tfile
792
793         rm -f $file
794         echo foo > $file || error "write filed"
795         echo bar >> $file || error "append filed"
796         $CHECKSTAT -s 8 $file || error "wrong size"
797         rm $file
798 }
799 run_test 23b "O_APPEND check =========================="
800
801 # rename sanity
802 test_24a() {
803         echo '-- same directory rename'
804         test_mkdir $DIR/$tdir
805         touch $DIR/$tdir/$tfile.1
806         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
807         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
808 }
809 run_test 24a "rename file to non-existent target"
810
811 test_24b() {
812         test_mkdir $DIR/$tdir
813         touch $DIR/$tdir/$tfile.{1,2}
814         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
815         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
816         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
817 }
818 run_test 24b "rename file to existing target"
819
820 test_24c() {
821         test_mkdir $DIR/$tdir
822         test_mkdir $DIR/$tdir/d$testnum.1
823         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
824         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
825         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
826 }
827 run_test 24c "rename directory to non-existent target"
828
829 test_24d() {
830         test_mkdir -c1 $DIR/$tdir
831         test_mkdir -c1 $DIR/$tdir/d$testnum.1
832         test_mkdir -c1 $DIR/$tdir/d$testnum.2
833         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
834         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
835         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
836 }
837 run_test 24d "rename directory to existing target"
838
839 test_24e() {
840         echo '-- cross directory renames --'
841         test_mkdir $DIR/R5a
842         test_mkdir $DIR/R5b
843         touch $DIR/R5a/f
844         mv $DIR/R5a/f $DIR/R5b/g
845         $CHECKSTAT -a $DIR/R5a/f || error
846         $CHECKSTAT -t file $DIR/R5b/g || error
847 }
848 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
849
850 test_24f() {
851         test_mkdir $DIR/R6a
852         test_mkdir $DIR/R6b
853         touch $DIR/R6a/f $DIR/R6b/g
854         mv $DIR/R6a/f $DIR/R6b/g
855         $CHECKSTAT -a $DIR/R6a/f || error
856         $CHECKSTAT -t file $DIR/R6b/g || error
857 }
858 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
859
860 test_24g() {
861         test_mkdir $DIR/R7a
862         test_mkdir $DIR/R7b
863         test_mkdir $DIR/R7a/d
864         mv $DIR/R7a/d $DIR/R7b/e
865         $CHECKSTAT -a $DIR/R7a/d || error
866         $CHECKSTAT -t dir $DIR/R7b/e || error
867 }
868 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
869
870 test_24h() {
871         test_mkdir -c1 $DIR/R8a
872         test_mkdir -c1 $DIR/R8b
873         test_mkdir -c1 $DIR/R8a/d
874         test_mkdir -c1 $DIR/R8b/e
875         mrename $DIR/R8a/d $DIR/R8b/e
876         $CHECKSTAT -a $DIR/R8a/d || error
877         $CHECKSTAT -t dir $DIR/R8b/e || error
878 }
879 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
880
881 test_24i() {
882         echo "-- rename error cases"
883         test_mkdir $DIR/R9
884         test_mkdir $DIR/R9/a
885         touch $DIR/R9/f
886         mrename $DIR/R9/f $DIR/R9/a
887         $CHECKSTAT -t file $DIR/R9/f || error
888         $CHECKSTAT -t dir  $DIR/R9/a || error
889         $CHECKSTAT -a $DIR/R9/a/f || error
890 }
891 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
892
893 test_24j() {
894         test_mkdir $DIR/R10
895         mrename $DIR/R10/f $DIR/R10/g
896         $CHECKSTAT -t dir $DIR/R10 || error
897         $CHECKSTAT -a $DIR/R10/f || error
898         $CHECKSTAT -a $DIR/R10/g || error
899 }
900 run_test 24j "source does not exist ============================"
901
902 test_24k() {
903         test_mkdir $DIR/R11a
904         test_mkdir $DIR/R11a/d
905         touch $DIR/R11a/f
906         mv $DIR/R11a/f $DIR/R11a/d
907         $CHECKSTAT -a $DIR/R11a/f || error
908         $CHECKSTAT -t file $DIR/R11a/d/f || error
909 }
910 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
911
912 # bug 2429 - rename foo foo foo creates invalid file
913 test_24l() {
914         f="$DIR/f24l"
915         $MULTIOP $f OcNs || error
916 }
917 run_test 24l "Renaming a file to itself ========================"
918
919 test_24m() {
920         f="$DIR/f24m"
921         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
922         # on ext3 this does not remove either the source or target files
923         # though the "expected" operation would be to remove the source
924         $CHECKSTAT -t file ${f} || error "${f} missing"
925         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
926 }
927 run_test 24m "Renaming a file to a hard link to itself ========="
928
929 test_24n() {
930     f="$DIR/f24n"
931     # this stats the old file after it was renamed, so it should fail
932     touch ${f}
933     $CHECKSTAT ${f}
934     mv ${f} ${f}.rename
935     $CHECKSTAT ${f}.rename
936     $CHECKSTAT -a ${f}
937 }
938 run_test 24n "Statting the old file after renaming (Posix rename 2)"
939
940 test_24o() {
941         test_mkdir -p $DIR/d24o
942         rename_many -s random -v -n 10 $DIR/d24o
943 }
944 run_test 24o "rename of files during htree split ==============="
945
946 test_24p() {
947         test_mkdir $DIR/R12a
948         test_mkdir $DIR/R12b
949         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
950         mrename $DIR/R12a $DIR/R12b
951         $CHECKSTAT -a $DIR/R12a || error
952         $CHECKSTAT -t dir $DIR/R12b || error
953         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
954         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
955 }
956 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
957
958 cleanup_multiop_pause() {
959         trap 0
960         kill -USR1 $MULTIPID
961 }
962
963 test_24q() {
964         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
965         test_mkdir $DIR/R13a
966         test_mkdir $DIR/R13b
967         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
968         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
969         MULTIPID=$!
970
971         trap cleanup_multiop_pause EXIT
972         mrename $DIR/R13a $DIR/R13b
973         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
974         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
975         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
976         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
977         cleanup_multiop_pause
978         wait $MULTIPID || error "multiop close failed"
979 }
980 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
981
982 test_24r() { #bug 3789
983         test_mkdir $DIR/R14a
984         test_mkdir $DIR/R14a/b
985         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
986         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
987         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
988 }
989 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
990
991 test_24s() {
992         test_mkdir $DIR/R15a
993         test_mkdir $DIR/R15a/b
994         test_mkdir $DIR/R15a/b/c
995         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
996         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
997         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
998 }
999 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1000 test_24t() {
1001         test_mkdir $DIR/R16a
1002         test_mkdir $DIR/R16a/b
1003         test_mkdir $DIR/R16a/b/c
1004         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1005         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1006         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1007 }
1008 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1009
1010 test_24u() { # bug12192
1011         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1012         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1013 }
1014 run_test 24u "create stripe file"
1015
1016 page_size() {
1017         getconf PAGE_SIZE
1018 }
1019
1020 simple_cleanup_common() {
1021         trap 0
1022         rm -rf $DIR/$tdir
1023         wait_delete_completed
1024 }
1025
1026 max_pages_per_rpc() {
1027         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1028 }
1029
1030 test_24v() {
1031         local NRFILES=100000
1032         local FREE_INODES=$(mdt_free_inodes 0)
1033         [[ $FREE_INODES -lt $NRFILES ]] &&
1034                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1035                 return
1036
1037         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1038         trap simple_cleanup_common EXIT
1039
1040         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1041         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1042
1043         mkdir -p $DIR/$tdir
1044         createmany -m $DIR/$tdir/$tfile $NRFILES
1045
1046         cancel_lru_locks mdc
1047         lctl set_param mdc.*.stats clear
1048
1049         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1050
1051         # LU-5 large readdir
1052         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1053         #               8 bytes for name(filename is mostly 5 in this test) +
1054         #               8 bytes for luda_type
1055         # take into account of overhead in lu_dirpage header and end mark in
1056         # each page, plus one in RPC_NUM calculation.
1057         DIRENT_SIZE=48
1058         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1059         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1060         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1061                                 awk '/^mds_readpage/ {print $2}')
1062         [[ $mds_readpage -gt $RPC_NUM ]] &&
1063                 error "large readdir doesn't take effect"
1064
1065         simple_cleanup_common
1066 }
1067 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1068
1069 test_24w() { # bug21506
1070         SZ1=234852
1071         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1072         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1073         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1074         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1075         [[ "$SZ1" -eq "$SZ2" ]] ||
1076                 error "Error reading at the end of the file $tfile"
1077 }
1078 run_test 24w "Reading a file larger than 4Gb"
1079
1080 test_24x() {
1081         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1082         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1083         local MDTIDX=1
1084         local remote_dir=$DIR/$tdir/remote_dir
1085
1086         mkdir -p $DIR/$tdir
1087         $LFS mkdir -i $MDTIDX $remote_dir ||
1088                 error "create remote directory failed"
1089
1090         mkdir -p $DIR/$tdir/src_dir
1091         touch $DIR/$tdir/src_file
1092         mkdir -p $remote_dir/tgt_dir
1093         touch $remote_dir/tgt_file
1094
1095         mrename $remote_dir $DIR/ &&
1096                 error "rename dir cross MDT works!"
1097
1098         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1099                 error "rename dir cross MDT works!"
1100
1101         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1102                 error "rename file cross MDT works!"
1103
1104         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1105                 error "ln file cross MDT should not work!"
1106
1107         rm -rf $DIR/$tdir || error "Can not delete directories"
1108 }
1109 run_test 24x "cross rename/link should be failed"
1110
1111 test_24y() {
1112         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1113         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1114         local MDTIDX=1
1115         local remote_dir=$DIR/$tdir/remote_dir
1116
1117         mkdir -p $DIR/$tdir
1118         $LFS mkdir -i $MDTIDX $remote_dir ||
1119                    error "create remote directory failed"
1120
1121         mkdir -p $remote_dir/src_dir
1122         touch $remote_dir/src_file
1123         mkdir -p $remote_dir/tgt_dir
1124         touch $remote_dir/tgt_file
1125
1126         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1127                 error "rename subdir in the same remote dir failed!"
1128
1129         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1130                 error "rename files in the same remote dir failed!"
1131
1132         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1133                 error "link files in the same remote dir failed!"
1134
1135         rm -rf $DIR/$tdir || error "Can not delete directories"
1136 }
1137 run_test 24y "rename/link on the same dir should succeed"
1138
1139 test_24z() {
1140         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1141         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1142         local MDTIDX=1
1143         local remote_src=$DIR/$tdir/remote_dir
1144         local remote_tgt=$DIR/$tdir/remote_tgt
1145
1146         mkdir -p $DIR/$tdir
1147         $LFS mkdir -i $MDTIDX $remote_src ||
1148                    error "create remote directory failed"
1149
1150         $LFS mkdir -i $MDTIDX $remote_tgt ||
1151                    error "create remote directory failed"
1152
1153         mrename $remote_src $remote_tgt &&
1154                 error "rename remote dirs should not work!"
1155
1156         # If target dir does not exists, it should succeed
1157         rm -rf $remote_tgt
1158         mrename $remote_src $remote_tgt ||
1159                 error "rename remote dirs(tgt dir does not exists) failed!"
1160
1161         rm -rf $DIR/$tdir || error "Can not delete directories"
1162 }
1163 run_test 24z "rename one remote dir to another remote dir should fail"
1164
1165 test_24A() { # LU-3182
1166         local NFILES=5000
1167
1168         rm -rf $DIR/$tdir
1169         mkdir -p $DIR/$tdir
1170         createmany -m $DIR/$tdir/$tfile $NFILES
1171         local t=$(ls $DIR/$tdir | wc -l)
1172         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1173         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1174         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1175                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1176         fi
1177
1178         rm -rf $DIR/$tdir || error "Can not delete directories"
1179 }
1180 run_test 24A "readdir() returns correct number of entries."
1181
1182 test_24B() { # LU-4805
1183         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1184         local count
1185
1186         mkdir $DIR/$tdir
1187         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1188                 error "create striped dir failed"
1189
1190         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1191         [ $count -eq 2 ] || error "Expected 2, got $count"
1192
1193         touch $DIR/$tdir/striped_dir/a
1194
1195         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1196         [ $count -eq 3 ] || error "Expected 3, got $count"
1197
1198         touch $DIR/$tdir/striped_dir/.f
1199
1200         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1201         [ $count -eq 4 ] || error "Expected 4, got $count"
1202
1203         rm -rf $DIR/$tdir || error "Can not delete directories"
1204 }
1205 run_test 24B "readdir for striped dir return correct number of entries"
1206
1207 test_24C() {
1208         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1209
1210         mkdir $DIR/$tdir
1211         mkdir $DIR/$tdir/d0
1212         mkdir $DIR/$tdir/d1
1213
1214         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1215                 error "create striped dir failed"
1216
1217         cd $DIR/$tdir/d0/striped_dir
1218
1219         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1220         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1221         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1222
1223         [ "$d0_ino" = "$parent_ino" ] ||
1224                 error ".. wrong, expect $d0_ino, get $parent_ino"
1225
1226         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1227                 error "mv striped dir failed"
1228
1229         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1230
1231         [ "$d1_ino" = "$parent_ino" ] ||
1232                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1233 }
1234 run_test 24C "check .. in striped dir"
1235
1236 test_24D() { # LU-6101
1237         local NFILES=50000
1238
1239         rm -rf $DIR/$tdir
1240         mkdir -p $DIR/$tdir
1241         createmany -m $DIR/$tdir/$tfile $NFILES
1242         local t=$(ls $DIR/$tdir | wc -l)
1243         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1244         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1245         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1246                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1247         fi
1248
1249         rm -rf $DIR/$tdir || error "Can not delete directories"
1250 }
1251 run_test 24D "readdir() returns correct number of entries after cursor reload"
1252
1253 test_25a() {
1254         echo '== symlink sanity ============================================='
1255
1256         test_mkdir $DIR/d25
1257         ln -s d25 $DIR/s25
1258         touch $DIR/s25/foo || error
1259 }
1260 run_test 25a "create file in symlinked directory ==============="
1261
1262 test_25b() {
1263         [ ! -d $DIR/d25 ] && test_25a
1264         $CHECKSTAT -t file $DIR/s25/foo || error
1265 }
1266 run_test 25b "lookup file in symlinked directory ==============="
1267
1268 test_26a() {
1269         test_mkdir $DIR/d26
1270         test_mkdir $DIR/d26/d26-2
1271         ln -s d26/d26-2 $DIR/s26
1272         touch $DIR/s26/foo || error
1273 }
1274 run_test 26a "multiple component symlink ======================="
1275
1276 test_26b() {
1277         test_mkdir -p $DIR/d26b/d26-2
1278         ln -s d26b/d26-2/foo $DIR/s26-2
1279         touch $DIR/s26-2 || error
1280 }
1281 run_test 26b "multiple component symlink at end of lookup ======"
1282
1283 test_26c() {
1284         test_mkdir $DIR/d26.2
1285         touch $DIR/d26.2/foo
1286         ln -s d26.2 $DIR/s26.2-1
1287         ln -s s26.2-1 $DIR/s26.2-2
1288         ln -s s26.2-2 $DIR/s26.2-3
1289         chmod 0666 $DIR/s26.2-3/foo
1290 }
1291 run_test 26c "chain of symlinks ================================"
1292
1293 # recursive symlinks (bug 439)
1294 test_26d() {
1295         ln -s d26-3/foo $DIR/d26-3
1296 }
1297 run_test 26d "create multiple component recursive symlink ======"
1298
1299 test_26e() {
1300         [ ! -h $DIR/d26-3 ] && test_26d
1301         rm $DIR/d26-3
1302 }
1303 run_test 26e "unlink multiple component recursive symlink ======"
1304
1305 # recursive symlinks (bug 7022)
1306 test_26f() {
1307         test_mkdir -p $DIR/$tdir
1308         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1309         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1310         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1311         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1312         cd $tfile                || error "cd $tfile failed"
1313         ln -s .. dotdot          || error "ln dotdot failed"
1314         ln -s dotdot/lndir lndir || error "ln lndir failed"
1315         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1316         output=`ls $tfile/$tfile/lndir/bar1`
1317         [ "$output" = bar1 ] && error "unexpected output"
1318         rm -r $tfile             || error "rm $tfile failed"
1319         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1320 }
1321 run_test 26f "rm -r of a directory which has recursive symlink ="
1322
1323 test_27a() {
1324         echo '== stripe sanity =============================================='
1325         test_mkdir -p $DIR/d27 || error "mkdir failed"
1326         $GETSTRIPE $DIR/d27
1327         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1328         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1329         log "== test_27a: write to one stripe file ========================="
1330         cp /etc/hosts $DIR/d27/f0 || error
1331 }
1332 run_test 27a "one stripe file =================================="
1333
1334 test_27b() {
1335         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1336         test_mkdir -p $DIR/d27
1337         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1338         $GETSTRIPE -c $DIR/d27/f01
1339         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1340                 error "two-stripe file doesn't have two stripes"
1341
1342         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1343 }
1344 run_test 27b "create and write to two stripe file"
1345
1346 test_27d() {
1347         test_mkdir -p $DIR/d27
1348         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1349         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1350         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1351 }
1352 run_test 27d "create file with default settings ================"
1353
1354 test_27e() {
1355         test_mkdir -p $DIR/d27
1356         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1357         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1358         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1359 }
1360 run_test 27e "setstripe existing file (should return error) ======"
1361
1362 test_27f() {
1363         test_mkdir $DIR/$tdir
1364         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1365                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1366         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1367                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1368         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1369         $GETSTRIPE $DIR/$tdir/$tfile || error "$GETSTRIPE failed"
1370 }
1371 run_test 27f "setstripe with bad stripe size (should return error)"
1372
1373 test_27g() {
1374         test_mkdir -p $DIR/d27
1375         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1376         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1377                 error "$DIR/d27/fnone has object"
1378 }
1379 run_test 27g "$GETSTRIPE with no objects"
1380
1381 test_27i() {
1382         test_mkdir $DIR/$tdir
1383         touch $DIR/$tdir/$tfile || error "touch failed"
1384         [[ $($GETSTRIPE -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1385                 error "missing objects"
1386 }
1387 run_test 27i "$GETSTRIPE with some objects"
1388
1389 test_27j() {
1390         test_mkdir -p $DIR/d27
1391         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1392 }
1393 run_test 27j "setstripe with bad stripe offset (should return error)"
1394
1395 test_27k() { # bug 2844
1396         test_mkdir -p $DIR/d27
1397         FILE=$DIR/d27/f27k
1398         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1399         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1400         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1401         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1402         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1403         dd if=/dev/zero of=$FILE bs=4k count=1
1404         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1405         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1406 }
1407 run_test 27k "limit i_blksize for broken user apps ============="
1408
1409 test_27l() {
1410         test_mkdir -p $DIR/d27
1411         mcreate $DIR/f27l || error "creating file"
1412         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1413                 error "setstripe should have failed" || true
1414 }
1415 run_test 27l "check setstripe permissions (should return error)"
1416
1417 test_27m() {
1418         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1419                 return
1420         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1421                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1422                 return
1423         fi
1424         trap simple_cleanup_common EXIT
1425         test_mkdir -p $DIR/$tdir
1426         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1427         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1428                 error "dd should fill OST0"
1429         i=2
1430         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1431                 i=$((i + 1))
1432                 [ $i -gt 256 ] && break
1433         done
1434         i=$((i + 1))
1435         touch $DIR/$tdir/f27m_$i
1436         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1437                 error "OST0 was full but new created file still use it"
1438         i=$((i + 1))
1439         touch $DIR/$tdir/f27m_$i
1440         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1441                 error "OST0 was full but new created file still use it"
1442         simple_cleanup_common
1443 }
1444 run_test 27m "create file while OST0 was full =================="
1445
1446 sleep_maxage() {
1447         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1448         sleep $DELAY
1449 }
1450
1451 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1452 # if the OST isn't full anymore.
1453 reset_enospc() {
1454         local OSTIDX=${1:-""}
1455
1456         local list=$(comma_list $(osts_nodes))
1457         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1458
1459         do_nodes $list lctl set_param fail_loc=0
1460         sync    # initiate all OST_DESTROYs from MDS to OST
1461         sleep_maxage
1462 }
1463
1464 exhaust_precreations() {
1465         local OSTIDX=$1
1466         local FAILLOC=$2
1467         local FAILIDX=${3:-$OSTIDX}
1468         local ofacet=ost$((OSTIDX + 1))
1469
1470         test_mkdir -p -c1 $DIR/$tdir
1471         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
1472         local mfacet=mds$((mdtidx + 1))
1473         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1474
1475         local OST=$(ostname_from_index $OSTIDX)
1476
1477         # on the mdt's osc
1478         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1479         local last_id=$(do_facet $mfacet lctl get_param -n \
1480                         osc.$mdtosc_proc1.prealloc_last_id)
1481         local next_id=$(do_facet $mfacet lctl get_param -n \
1482                         osc.$mdtosc_proc1.prealloc_next_id)
1483
1484         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1485         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1486
1487         test_mkdir -p $DIR/$tdir/${OST}
1488         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1489 #define OBD_FAIL_OST_ENOSPC              0x215
1490         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1491         echo "Creating to objid $last_id on ost $OST..."
1492         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1493         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1494         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1495         sleep_maxage
1496 }
1497
1498 exhaust_all_precreations() {
1499         local i
1500         for (( i=0; i < OSTCOUNT; i++ )) ; do
1501                 exhaust_precreations $i $1 -1
1502         done
1503 }
1504
1505 test_27n() {
1506         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1507         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1508         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1509         remote_ost_nodsh && skip "remote OST with nodsh" && return
1510
1511         reset_enospc
1512         rm -f $DIR/$tdir/$tfile
1513         exhaust_precreations 0 0x80000215
1514         $SETSTRIPE -c -1 $DIR/$tdir
1515         touch $DIR/$tdir/$tfile || error
1516         $GETSTRIPE $DIR/$tdir/$tfile
1517         reset_enospc
1518 }
1519 run_test 27n "create file with some full OSTs =================="
1520
1521 test_27o() {
1522         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1523         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1524         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1525         remote_ost_nodsh && skip "remote OST with nodsh" && return
1526
1527         reset_enospc
1528         rm -f $DIR/$tdir/$tfile
1529         exhaust_all_precreations 0x215
1530
1531         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1532
1533         reset_enospc
1534         rm -rf $DIR/$tdir/*
1535 }
1536 run_test 27o "create file with all full OSTs (should error) ===="
1537
1538 test_27p() {
1539         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1540         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1541         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1542         remote_ost_nodsh && skip "remote OST with nodsh" && return
1543
1544         reset_enospc
1545         rm -f $DIR/$tdir/$tfile
1546         test_mkdir -p $DIR/$tdir
1547
1548         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1549         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1550         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1551
1552         exhaust_precreations 0 0x80000215
1553         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1554         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1555         $GETSTRIPE $DIR/$tdir/$tfile
1556
1557         reset_enospc
1558 }
1559 run_test 27p "append to a truncated file with some full OSTs ==="
1560
1561 test_27q() {
1562         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1563         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1564         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1565         remote_ost_nodsh && skip "remote OST with nodsh" && return
1566
1567         reset_enospc
1568         rm -f $DIR/$tdir/$tfile
1569
1570         test_mkdir -p $DIR/$tdir
1571         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1572         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1573         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1574
1575         exhaust_all_precreations 0x215
1576
1577         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1578         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1579
1580         reset_enospc
1581 }
1582 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1583
1584 test_27r() {
1585         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1586         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1587         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1588         remote_ost_nodsh && skip "remote OST with nodsh" && return
1589
1590         reset_enospc
1591         rm -f $DIR/$tdir/$tfile
1592         exhaust_precreations 0 0x80000215
1593
1594         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1595
1596         reset_enospc
1597 }
1598 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1599
1600 test_27s() { # bug 10725
1601         test_mkdir -p $DIR/$tdir
1602         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1603         local stripe_count=0
1604         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1605         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1606                 error "stripe width >= 2^32 succeeded" || true
1607
1608 }
1609 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1610
1611 test_27t() { # bug 10864
1612         WDIR=$(pwd)
1613         WLFS=$(which lfs)
1614         cd $DIR
1615         touch $tfile
1616         $WLFS getstripe $tfile
1617         cd $WDIR
1618 }
1619 run_test 27t "check that utils parse path correctly"
1620
1621 test_27u() { # bug 4900
1622         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1623         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1624         local index
1625         local list=$(comma_list $(mdts_nodes))
1626
1627 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1628         do_nodes $list $LCTL set_param fail_loc=0x139
1629         test_mkdir -p $DIR/$tdir
1630         rm -rf $DIR/$tdir/*
1631         createmany -o $DIR/$tdir/t- 1000
1632         do_nodes $list $LCTL set_param fail_loc=0
1633
1634         TLOG=$DIR/$tfile.getstripe
1635         $GETSTRIPE $DIR/$tdir > $TLOG
1636         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1637         unlinkmany $DIR/$tdir/t- 1000
1638         [[ $OBJS -gt 0 ]] &&
1639                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1640 }
1641 run_test 27u "skip object creation on OSC w/o objects =========="
1642
1643 test_27v() { # bug 4900
1644         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1645         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1646         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1647         remote_ost_nodsh && skip "remote OST with nodsh" && return
1648
1649         exhaust_all_precreations 0x215
1650         reset_enospc
1651
1652         test_mkdir -p $DIR/$tdir
1653         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1654
1655         touch $DIR/$tdir/$tfile
1656         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1657         # all except ost1
1658         for (( i=1; i < OSTCOUNT; i++ )); do
1659                 do_facet ost$i lctl set_param fail_loc=0x705
1660         done
1661         local START=`date +%s`
1662         createmany -o $DIR/$tdir/$tfile 32
1663
1664         local FINISH=`date +%s`
1665         local TIMEOUT=`lctl get_param -n timeout`
1666         local PROCESS=$((FINISH - START))
1667         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1668                error "$FINISH - $START >= $TIMEOUT / 2"
1669         sleep $((TIMEOUT / 2 - PROCESS))
1670         reset_enospc
1671 }
1672 run_test 27v "skip object creation on slow OST ================="
1673
1674 test_27w() { # bug 10997
1675         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1676         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1677         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1678                 error "stripe size $size != 65536" || true
1679         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1680                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1681 }
1682 run_test 27w "check $SETSTRIPE -S option"
1683
1684 test_27wa() {
1685         [[ $OSTCOUNT -lt 2 ]] &&
1686                 skip_env "skipping multiple stripe count/offset test" && return
1687
1688         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1689         for i in $(seq 1 $OSTCOUNT); do
1690                 offset=$((i - 1))
1691                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1692                         error "setstripe -c $i -i $offset failed"
1693                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1694                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1695                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1696                 [ $index -ne $offset ] &&
1697                         error "stripe offset $index != $offset" || true
1698         done
1699 }
1700 run_test 27wa "check $SETSTRIPE -c -i options"
1701
1702 test_27x() {
1703         remote_ost_nodsh && skip "remote OST with nodsh" && return
1704         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1705         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1706         OFFSET=$(($OSTCOUNT - 1))
1707         OSTIDX=0
1708         local OST=$(ostname_from_index $OSTIDX)
1709
1710         test_mkdir -p $DIR/$tdir
1711         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1712         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1713         sleep_maxage
1714         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1715         for i in `seq 0 $OFFSET`; do
1716                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1717                 error "OST0 was degraded but new created file still use it"
1718         done
1719         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1720 }
1721 run_test 27x "create files while OST0 is degraded"
1722
1723 test_27y() {
1724         [[ $OSTCOUNT -lt 2 ]] &&
1725                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1726         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1727         remote_ost_nodsh && skip "remote OST with nodsh" && return
1728         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1729
1730         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1731         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1732             osc.$mdtosc.prealloc_last_id)
1733         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1734             osc.$mdtosc.prealloc_next_id)
1735         local fcount=$((last_id - next_id))
1736         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1737         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1738
1739         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1740                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1741         local OST_DEACTIVE_IDX=-1
1742         local OSC
1743         local OSTIDX
1744         local OST
1745
1746         for OSC in $MDS_OSCS; do
1747                 OST=$(osc_to_ost $OSC)
1748                 OSTIDX=$(index_from_ostuuid $OST)
1749                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1750                         OST_DEACTIVE_IDX=$OSTIDX
1751                 fi
1752                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1753                         echo $OSC "is Deactivated:"
1754                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1755                 fi
1756         done
1757
1758         OSTIDX=$(index_from_ostuuid $OST)
1759         mkdir -p $DIR/$tdir
1760         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1761
1762         for OSC in $MDS_OSCS; do
1763                 OST=$(osc_to_ost $OSC)
1764                 OSTIDX=$(index_from_ostuuid $OST)
1765                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1766                         echo $OST "is degraded:"
1767                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1768                                                 obdfilter.$OST.degraded=1
1769                 fi
1770         done
1771
1772         sleep_maxage
1773         createmany -o $DIR/$tdir/$tfile $fcount
1774
1775         for OSC in $MDS_OSCS; do
1776                 OST=$(osc_to_ost $OSC)
1777                 OSTIDX=$(index_from_ostuuid $OST)
1778                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1779                         echo $OST "is recovered from degraded:"
1780                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1781                                                 obdfilter.$OST.degraded=0
1782                 else
1783                         do_facet $SINGLEMDS lctl --device %$OSC activate
1784                 fi
1785         done
1786
1787         # all osp devices get activated, hence -1 stripe count restored
1788         local stripecnt=0
1789
1790         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1791         # devices get activated.
1792         sleep_maxage
1793         $SETSTRIPE -c -1 $DIR/$tfile
1794         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1795         rm -f $DIR/$tfile
1796         [ $stripecnt -ne $OSTCOUNT ] &&
1797                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1798         return 0
1799 }
1800 run_test 27y "create files while OST0 is degraded and the rest inactive"
1801
1802 check_seq_oid()
1803 {
1804         log "check file $1"
1805
1806         lmm_count=$($GETSTRIPE -c $1)
1807         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1808         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1809
1810         local old_ifs="$IFS"
1811         IFS=$'[:]'
1812         fid=($($LFS path2fid $1))
1813         IFS="$old_ifs"
1814
1815         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1816         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1817
1818         # compare lmm_seq and lu_fid->f_seq
1819         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1820         # compare lmm_object_id and lu_fid->oid
1821         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1822
1823         # check the trusted.fid attribute of the OST objects of the file
1824         local have_obdidx=false
1825         local stripe_nr=0
1826         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1827                 # skip lines up to and including "obdidx"
1828                 [ -z "$obdidx" ] && break
1829                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1830                 $have_obdidx || continue
1831
1832                 local ost=$((obdidx + 1))
1833                 local dev=$(ostdevname $ost)
1834                 local oid_hex
1835
1836                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1837
1838                 seq=$(echo $seq | sed -e "s/^0x//g")
1839                 if [ $seq == 0 ]; then
1840                         oid_hex=$(echo $oid)
1841                 else
1842                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1843                 fi
1844                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1845
1846                 local ff
1847                 #
1848                 # Don't unmount/remount the OSTs if we don't need to do that.
1849                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1850                 # update too, until that use mount/ll_decode_filter_fid/mount.
1851                 # Re-enable when debugfs will understand new filter_fid.
1852                 #
1853                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1854                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1855                                 $dev 2>/dev/null" | grep "parent=")
1856                 else
1857                         stop ost$ost
1858                         mount_fstype ost$ost
1859                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1860                                 $(facet_mntpt ost$ost)/$obj_file)
1861                         unmount_fstype ost$ost
1862                         start ost$ost $dev $OST_MOUNT_OPTS
1863                 fi
1864
1865                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1866
1867                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1868
1869                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1870                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1871                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1872                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1873                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1874                 local ff_pstripe
1875                 if echo $ff_parent | grep -q 'stripe='; then
1876                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1877                 else
1878                         #
1879                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1880                         # into f_ver in this case.  See the comment on
1881                         # ff_parent.
1882                         #
1883                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1884                                 sed -e 's/\]//')
1885                 fi
1886
1887                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1888                 [ $ff_pseq = $lmm_seq ] ||
1889                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1890                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1891                 [ $ff_poid = $lmm_oid ] ||
1892                         error "FF parent OID $ff_poid != $lmm_oid"
1893                 (($ff_pstripe == $stripe_nr)) ||
1894                         error "FF stripe $ff_pstripe != $stripe_nr"
1895
1896                 stripe_nr=$((stripe_nr + 1))
1897         done
1898 }
1899
1900 test_27z() {
1901         remote_ost_nodsh && skip "remote OST with nodsh" && return
1902         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1903         test_mkdir -p $DIR/$tdir
1904
1905         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1906                 { error "setstripe -c -1 failed"; return 1; }
1907         # We need to send a write to every object to get parent FID info set.
1908         # This _should_ also work for setattr, but does not currently.
1909         # touch $DIR/$tdir/$tfile-1 ||
1910         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1911                 { error "dd $tfile-1 failed"; return 2; }
1912         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1913                 { error "setstripe -c -1 failed"; return 3; }
1914         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1915                 { error "dd $tfile-2 failed"; return 4; }
1916
1917         # make sure write RPCs have been sent to OSTs
1918         sync; sleep 5; sync
1919
1920         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1921         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1922 }
1923 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1924
1925 test_27A() { # b=19102
1926         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1927         local restore_size=$($GETSTRIPE -S $MOUNT)
1928         local restore_count=$($GETSTRIPE -c $MOUNT)
1929         local restore_offset=$($GETSTRIPE -i $MOUNT)
1930         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1931         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1932                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1933         local default_size=$($GETSTRIPE -S $MOUNT)
1934         local default_offset=$($GETSTRIPE -i $MOUNT)
1935         local dsize=$((1024 * 1024))
1936         [ $default_size -eq $dsize ] ||
1937                 error "stripe size $default_size != $dsize"
1938         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1939         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1940 }
1941 run_test 27A "check filesystem-wide default LOV EA values"
1942
1943 test_27B() { # LU-2523
1944         test_mkdir -p $DIR/$tdir
1945         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1946         touch $DIR/$tdir/f0
1947         # open f1 with O_LOV_DELAY_CREATE
1948         # rename f0 onto f1
1949         # call setstripe ioctl on open file descriptor for f1
1950         # close
1951         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1952                 $DIR/$tdir/f0
1953
1954         rm -f $DIR/$tdir/f1
1955         # open f1 with O_LOV_DELAY_CREATE
1956         # unlink f1
1957         # call setstripe ioctl on open file descriptor for f1
1958         # close
1959         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1960
1961         # Allow multiop to fail in imitation of NFS's busted semantics.
1962         true
1963 }
1964 run_test 27B "call setstripe on open unlinked file/rename victim"
1965
1966 test_27C() { #LU-2871
1967         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1968
1969         declare -a ost_idx
1970         local index
1971         local found
1972         local i
1973         local j
1974
1975         test_mkdir -p $DIR/$tdir
1976         cd $DIR/$tdir
1977         for i in $(seq 0 $((OSTCOUNT - 1))); do
1978                 # set stripe across all OSTs starting from OST$i
1979                 $SETSTRIPE -i $i -c -1 $tfile$i
1980                 # get striping information
1981                 ost_idx=($($GETSTRIPE $tfile$i |
1982                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1983                 echo ${ost_idx[@]}
1984
1985                 # check the layout
1986                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1987                         error "${#ost_idx[@]} != $OSTCOUNT"
1988
1989                 for index in $(seq 0 $((OSTCOUNT - 1))); do
1990                         found=0
1991                         for j in $(echo ${ost_idx[@]}); do
1992                                 if [ $index -eq $j ]; then
1993                                         found=1
1994                                         break
1995                                 fi
1996                         done
1997                         [ $found = 1 ] ||
1998                                 error "Can not find $index in ${ost_idx[@]}"
1999                 done
2000         done
2001 }
2002 run_test 27C "check full striping across all OSTs"
2003
2004 test_27D() {
2005         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2006         local POOL=${POOL:-testpool}
2007         local first_ost=0
2008         local last_ost=$(($OSTCOUNT - 1))
2009         local ost_step=1
2010         local ost_list=$(seq $first_ost $ost_step $last_ost)
2011         local ost_range="$first_ost $last_ost $ost_step"
2012
2013         mkdir -p $DIR/$tdir
2014         pool_add $POOL || error "pool_add failed"
2015         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2016         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT ||
2017                 error "llapi_layout_test failed"
2018         cleanup_pools || error "cleanup_pools failed"
2019 }
2020 run_test 27D "validate llapi_layout API"
2021
2022 # Verify that default_easize is increased from its initial value after
2023 # accessing a widely striped file.
2024 test_27E() {
2025         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2026
2027         # 72 bytes is the minimum space required to store striping
2028         # information for a file striped across one OST:
2029         # (sizeof(struct lov_user_md_v3) +
2030         #  sizeof(struct lov_user_ost_data_v1))
2031         local min_easize=72
2032         $LCTL set_param -n llite.*.default_easize $min_easize ||
2033                 error "lctl set_param failed"
2034         local easize=$($LCTL get_param -n llite.*.default_easize)
2035
2036         [ $easize -eq $min_easize ] ||
2037                 error "failed to set default_easize"
2038
2039         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2040                 error "setstripe failed"
2041         cat $DIR/$tfile
2042         rm $DIR/$tfile
2043
2044         easize=$($LCTL get_param -n llite.*.default_easize)
2045
2046         [ $easize -gt $min_easize ] ||
2047                 error "default_easize not updated"
2048 }
2049 run_test 27E "check that default extended attribute size properly increases"
2050
2051 # createtest also checks that device nodes are created and
2052 # then visible correctly (#2091)
2053 test_28() { # bug 2091
2054         test_mkdir $DIR/d28
2055         $CREATETEST $DIR/d28/ct || error
2056 }
2057 run_test 28 "create/mknod/mkdir with bad file types ============"
2058
2059 test_29() {
2060         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2061         cancel_lru_locks mdc
2062         test_mkdir $DIR/d29
2063         touch $DIR/d29/foo
2064         log 'first d29'
2065         ls -l $DIR/d29
2066
2067         declare -i LOCKCOUNTORIG=0
2068         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2069                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2070         done
2071         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
2072
2073         declare -i LOCKUNUSEDCOUNTORIG=0
2074         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2075                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2076         done
2077
2078         log 'second d29'
2079         ls -l $DIR/d29
2080         log 'done'
2081
2082         declare -i LOCKCOUNTCURRENT=0
2083         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2084                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2085         done
2086
2087         declare -i LOCKUNUSEDCOUNTCURRENT=0
2088         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2089                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2090         done
2091
2092         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2093                 $LCTL set_param -n ldlm.dump_namespaces ""
2094                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2095                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2096                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2097                 return 2
2098         fi
2099         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2100                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2101                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2102                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2103                 return 3
2104         fi
2105 }
2106 run_test 29 "IT_GETATTR regression  ============================"
2107
2108 test_30a() { # was test_30
2109         cp $(which ls) $DIR || cp /bin/ls $DIR
2110         $DIR/ls / || error
2111         rm $DIR/ls
2112 }
2113 run_test 30a "execute binary from Lustre (execve) =============="
2114
2115 test_30b() {
2116         cp `which ls` $DIR || cp /bin/ls $DIR
2117         chmod go+rx $DIR/ls
2118         $RUNAS $DIR/ls / || error
2119         rm $DIR/ls
2120 }
2121 run_test 30b "execute binary from Lustre as non-root ==========="
2122
2123 test_30c() { # b=22376
2124         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2125         cp `which ls` $DIR || cp /bin/ls $DIR
2126         chmod a-rw $DIR/ls
2127         cancel_lru_locks mdc
2128         cancel_lru_locks osc
2129         $RUNAS $DIR/ls / || error
2130         rm -f $DIR/ls
2131 }
2132 run_test 30c "execute binary from Lustre without read perms ===="
2133
2134 test_31a() {
2135         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2136         $CHECKSTAT -a $DIR/f31 || error
2137 }
2138 run_test 31a "open-unlink file =================================="
2139
2140 test_31b() {
2141         touch $DIR/f31 || error
2142         ln $DIR/f31 $DIR/f31b || error
2143         $MULTIOP $DIR/f31b Ouc || error
2144         $CHECKSTAT -t file $DIR/f31 || error
2145 }
2146 run_test 31b "unlink file with multiple links while open ======="
2147
2148 test_31c() {
2149         touch $DIR/f31 || error
2150         ln $DIR/f31 $DIR/f31c || error
2151         multiop_bg_pause $DIR/f31 O_uc || return 1
2152         MULTIPID=$!
2153         $MULTIOP $DIR/f31c Ouc
2154         kill -USR1 $MULTIPID
2155         wait $MULTIPID
2156 }
2157 run_test 31c "open-unlink file with multiple links ============="
2158
2159 test_31d() {
2160         opendirunlink $DIR/d31d $DIR/d31d || error
2161         $CHECKSTAT -a $DIR/d31d || error
2162 }
2163 run_test 31d "remove of open directory ========================="
2164
2165 test_31e() { # bug 2904
2166         openfilleddirunlink $DIR/d31e || error
2167 }
2168 run_test 31e "remove of open non-empty directory ==============="
2169
2170 test_31f() { # bug 4554
2171         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2172         set -vx
2173         test_mkdir $DIR/d31f
2174         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2175         cp /etc/hosts $DIR/d31f
2176         ls -l $DIR/d31f
2177         $GETSTRIPE $DIR/d31f/hosts
2178         multiop_bg_pause $DIR/d31f D_c || return 1
2179         MULTIPID=$!
2180
2181         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2182         test_mkdir $DIR/d31f
2183         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2184         cp /etc/hosts $DIR/d31f
2185         ls -l $DIR/d31f
2186         $GETSTRIPE $DIR/d31f/hosts
2187         multiop_bg_pause $DIR/d31f D_c || return 1
2188         MULTIPID2=$!
2189
2190         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2191         wait $MULTIPID || error "first opendir $MULTIPID failed"
2192
2193         sleep 6
2194
2195         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2196         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2197         set +vx
2198 }
2199 run_test 31f "remove of open directory with open-unlink file ==="
2200
2201 test_31g() {
2202         echo "-- cross directory link --"
2203         test_mkdir -c1 $DIR/${tdir}ga
2204         test_mkdir -c1 $DIR/${tdir}gb
2205         touch $DIR/${tdir}ga/f
2206         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2207         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2208         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2209         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2210         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2211 }
2212 run_test 31g "cross directory link==============="
2213
2214 test_31h() {
2215         echo "-- cross directory link --"
2216         test_mkdir -c1 $DIR/${tdir}
2217         test_mkdir -c1 $DIR/${tdir}/dir
2218         touch $DIR/${tdir}/f
2219         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2220         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2221         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2222         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2223         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2224 }
2225 run_test 31h "cross directory link under child==============="
2226
2227 test_31i() {
2228         echo "-- cross directory link --"
2229         test_mkdir -c1 $DIR/$tdir
2230         test_mkdir -c1 $DIR/$tdir/dir
2231         touch $DIR/$tdir/dir/f
2232         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2233         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2234         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2235         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2236         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2237 }
2238 run_test 31i "cross directory link under parent==============="
2239
2240 test_31j() {
2241         test_mkdir -c1 -p $DIR/$tdir
2242         test_mkdir -c1 -p $DIR/$tdir/dir1
2243         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2244         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2245         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2246         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2247         return 0
2248 }
2249 run_test 31j "link for directory==============="
2250
2251 test_31k() {
2252         test_mkdir -c1 -p $DIR/$tdir
2253         touch $DIR/$tdir/s
2254         touch $DIR/$tdir/exist
2255         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2256         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2257         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2258         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2259         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2260         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2261         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2262         return 0
2263 }
2264 run_test 31k "link to file: the same, non-existing, dir==============="
2265
2266 test_31m() {
2267         mkdir $DIR/d31m
2268         touch $DIR/d31m/s
2269         mkdir $DIR/d31m2
2270         touch $DIR/d31m2/exist
2271         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2272         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2273         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2274         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2275         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2276         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2277         return 0
2278 }
2279 run_test 31m "link to file: the same, non-existing, dir==============="
2280
2281 test_31n() {
2282         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2283         nlink=$(stat --format=%h $DIR/$tfile)
2284         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2285         local fd=$(free_fd)
2286         local cmd="exec $fd<$DIR/$tfile"
2287         eval $cmd
2288         cmd="exec $fd<&-"
2289         trap "eval $cmd" EXIT
2290         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2291         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2292         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2293         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2294         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2295         eval $cmd
2296 }
2297 run_test 31n "check link count of unlinked file"
2298
2299 link_one() {
2300         local TEMPNAME=$(mktemp $1_XXXXXX)
2301         mlink $TEMPNAME $1 2> /dev/null &&
2302                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2303         munlink $TEMPNAME
2304 }
2305
2306 test_31o() { # LU-2901
2307         mkdir -p $DIR/$tdir
2308         for LOOP in $(seq 100); do
2309                 rm -f $DIR/$tdir/$tfile*
2310                 for THREAD in $(seq 8); do
2311                         link_one $DIR/$tdir/$tfile.$LOOP &
2312                 done
2313                 wait
2314                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2315                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2316                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2317                         break || true
2318         done
2319 }
2320 run_test 31o "duplicate hard links with same filename"
2321
2322 test_31p() {
2323         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2324
2325         mkdir $DIR/$tdir
2326         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2327         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2328
2329         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2330                 error "open unlink test1 failed"
2331         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2332                 error "open unlink test2 failed"
2333
2334         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2335                 error "test1 still exists"
2336         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2337                 error "test2 still exists"
2338 }
2339 run_test 31p "remove of open striped directory"
2340
2341 cleanup_test32_mount() {
2342         trap 0
2343         $UMOUNT -d $DIR/$tdir/ext2-mountpoint
2344 }
2345
2346 test_32a() {
2347         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2348         echo "== more mountpoints and symlinks ================="
2349         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2350         trap cleanup_test32_mount EXIT
2351         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2352         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2353         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2354         cleanup_test32_mount
2355 }
2356 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2357
2358 test_32b() {
2359         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2360         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2361         trap cleanup_test32_mount EXIT
2362         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2363         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2364         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2365         cleanup_test32_mount
2366 }
2367 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2368
2369 test_32c() {
2370         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2371         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2372         trap cleanup_test32_mount EXIT
2373         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2374         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2375         test_mkdir -p $DIR/$tdir/d2/test_dir
2376         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2377         cleanup_test32_mount
2378 }
2379 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2380
2381 test_32d() {
2382         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2383         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2384         trap cleanup_test32_mount EXIT
2385         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2386         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2387         test_mkdir -p $DIR/$tdir/d2/test_dir
2388         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2389         cleanup_test32_mount
2390 }
2391 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2392
2393 test_32e() {
2394         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2395         test_mkdir -p $DIR/d32e/tmp
2396         TMP_DIR=$DIR/d32e/tmp
2397         ln -s $DIR/d32e $TMP_DIR/symlink11
2398         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2399         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2400         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2401 }
2402 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2403
2404 test_32f() {
2405         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2406         test_mkdir -p $DIR/d32f/tmp
2407         TMP_DIR=$DIR/d32f/tmp
2408         ln -s $DIR/d32f $TMP_DIR/symlink11
2409         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2410         ls $DIR/d32f/tmp/symlink11  || error
2411         ls $DIR/d32f/symlink01 || error
2412 }
2413 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2414
2415 test_32g() {
2416         TMP_DIR=$DIR/$tdir/tmp
2417         test_mkdir -p $DIR/$tdir/tmp
2418         test_mkdir $DIR/${tdir}2
2419         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2420         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2421         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2422         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2423         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2424         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2425 }
2426 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2427
2428 test_32h() {
2429         rm -fr $DIR/$tdir $DIR/${tdir}2
2430         TMP_DIR=$DIR/$tdir/tmp
2431         test_mkdir -p $DIR/$tdir/tmp
2432         test_mkdir $DIR/${tdir}2
2433         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2434         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2435         ls $TMP_DIR/symlink12 || error
2436         ls $DIR/$tdir/symlink02  || error
2437 }
2438 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2439
2440 test_32i() {
2441         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2442         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2443         trap cleanup_test32_mount EXIT
2444         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2445         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2446         touch $DIR/$tdir/test_file
2447         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2448         cleanup_test32_mount
2449 }
2450 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2451
2452 test_32j() {
2453         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2454         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2455         trap cleanup_test32_mount EXIT
2456         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2457         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2458         touch $DIR/$tdir/test_file
2459         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2460         cleanup_test32_mount
2461 }
2462 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2463
2464 test_32k() {
2465         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2466         rm -fr $DIR/$tdir
2467         trap cleanup_test32_mount EXIT
2468         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2469         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2470         test_mkdir -p $DIR/$tdir/d2
2471         touch $DIR/$tdir/d2/test_file || error
2472         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2473         cleanup_test32_mount
2474 }
2475 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2476
2477 test_32l() {
2478         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2479         rm -fr $DIR/$tdir
2480         trap cleanup_test32_mount EXIT
2481         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2482         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2483         test_mkdir -p $DIR/$tdir/d2
2484         touch $DIR/$tdir/d2/test_file
2485         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2486         cleanup_test32_mount
2487 }
2488 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2489
2490 test_32m() {
2491         rm -fr $DIR/d32m
2492         test_mkdir -p $DIR/d32m/tmp
2493         TMP_DIR=$DIR/d32m/tmp
2494         ln -s $DIR $TMP_DIR/symlink11
2495         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2496         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2497         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2498 }
2499 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2500
2501 test_32n() {
2502         rm -fr $DIR/d32n
2503         test_mkdir -p $DIR/d32n/tmp
2504         TMP_DIR=$DIR/d32n/tmp
2505         ln -s $DIR $TMP_DIR/symlink11
2506         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2507         ls -l $DIR/d32n/tmp/symlink11  || error
2508         ls -l $DIR/d32n/symlink01 || error
2509 }
2510 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2511
2512 test_32o() {
2513         touch $DIR/$tfile
2514         test_mkdir -p $DIR/d32o/tmp
2515         TMP_DIR=$DIR/d32o/tmp
2516         ln -s $DIR/$tfile $TMP_DIR/symlink12
2517         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2518         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2519         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2520         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2521         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2522 }
2523 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2524
2525 test_32p() {
2526     log 32p_1
2527         rm -fr $DIR/d32p
2528     log 32p_2
2529         rm -f $DIR/$tfile
2530     log 32p_3
2531         touch $DIR/$tfile
2532     log 32p_4
2533         test_mkdir -p $DIR/d32p/tmp
2534     log 32p_5
2535         TMP_DIR=$DIR/d32p/tmp
2536     log 32p_6
2537         ln -s $DIR/$tfile $TMP_DIR/symlink12
2538     log 32p_7
2539         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2540     log 32p_8
2541         cat $DIR/d32p/tmp/symlink12 || error
2542     log 32p_9
2543         cat $DIR/d32p/symlink02 || error
2544     log 32p_10
2545 }
2546 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2547
2548 cleanup_testdir_mount() {
2549         trap 0
2550         $UMOUNT -d $DIR/$tdir
2551 }
2552
2553 test_32q() {
2554         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2555         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2556         trap cleanup_testdir_mount EXIT
2557         test_mkdir -p $DIR/$tdir
2558         touch $DIR/$tdir/under_the_mount
2559         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2560         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2561         cleanup_testdir_mount
2562 }
2563 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2564
2565 test_32r() {
2566         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2567         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2568         trap cleanup_testdir_mount EXIT
2569         test_mkdir -p $DIR/$tdir
2570         touch $DIR/$tdir/under_the_mount
2571         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2572         ls $DIR/$tdir | grep -q under_the_mount && error || true
2573         cleanup_testdir_mount
2574 }
2575 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2576
2577 test_33aa() {
2578         rm -f $DIR/$tfile
2579         touch $DIR/$tfile
2580         chmod 444 $DIR/$tfile
2581         chown $RUNAS_ID $DIR/$tfile
2582         log 33_1
2583         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2584         log 33_2
2585 }
2586 run_test 33aa "write file with mode 444 (should return error) ===="
2587
2588 test_33a() {
2589         rm -fr $DIR/d33
2590         test_mkdir -p $DIR/d33
2591         chown $RUNAS_ID $DIR/d33
2592         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2593         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2594                 error "open RDWR" || true
2595 }
2596 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2597
2598 test_33b() {
2599         rm -fr $DIR/d33
2600         test_mkdir -p $DIR/d33
2601         chown $RUNAS_ID $DIR/d33
2602         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 || true
2603 }
2604 run_test 33b "test open file with malformed flags (No panic)"
2605
2606 test_33c() {
2607         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2608         local ostnum
2609         local ostname
2610         local write_bytes
2611         local all_zeros
2612
2613         remote_ost_nodsh && skip "remote OST with nodsh" && return
2614         all_zeros=:
2615         rm -fr $DIR/d33
2616         test_mkdir -p $DIR/d33
2617         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2618
2619         sync
2620         for ostnum in $(seq $OSTCOUNT); do
2621                 # test-framework's OST numbering is one-based, while Lustre's
2622                 # is zero-based
2623                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2624                 # Parsing llobdstat's output sucks; we could grep the /proc
2625                 # path, but that's likely to not be as portable as using the
2626                 # llobdstat utility.  So we parse lctl output instead.
2627                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2628                         obdfilter/$ostname/stats |
2629                         awk '/^write_bytes/ {print $7}' )
2630                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2631                 if (( ${write_bytes:-0} > 0 ))
2632                 then
2633                         all_zeros=false
2634                         break;
2635                 fi
2636         done
2637
2638         $all_zeros || return 0
2639
2640         # Write four bytes
2641         echo foo > $DIR/d33/bar
2642         # Really write them
2643         sync
2644
2645         # Total up write_bytes after writing.  We'd better find non-zeros.
2646         for ostnum in $(seq $OSTCOUNT); do
2647                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2648                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2649                         obdfilter/$ostname/stats |
2650                         awk '/^write_bytes/ {print $7}' )
2651                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2652                 if (( ${write_bytes:-0} > 0 ))
2653                 then
2654                         all_zeros=false
2655                         break;
2656                 fi
2657         done
2658
2659         if $all_zeros
2660         then
2661                 for ostnum in $(seq $OSTCOUNT); do
2662                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2663                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2664                         do_facet ost$ostnum lctl get_param -n \
2665                                 obdfilter/$ostname/stats
2666                 done
2667                 error "OST not keeping write_bytes stats (b22312)"
2668         fi
2669 }
2670 run_test 33c "test llobdstat and write_bytes"
2671
2672 test_33d() {
2673         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2674         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2675         local MDTIDX=1
2676         local remote_dir=$DIR/$tdir/remote_dir
2677
2678         mkdir -p $DIR/$tdir
2679         $LFS mkdir -i $MDTIDX $remote_dir ||
2680                 error "create remote directory failed"
2681
2682         touch $remote_dir/$tfile
2683         chmod 444 $remote_dir/$tfile
2684         chown $RUNAS_ID $remote_dir/$tfile
2685
2686         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2687
2688         chown $RUNAS_ID $remote_dir
2689         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2690                                         error "create" || true
2691         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2692                                     error "open RDWR" || true
2693         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2694                                     error "create" || true
2695 }
2696 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2697
2698 test_33e() {
2699         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2700
2701         mkdir $DIR/$tdir
2702
2703         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2704         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2705         mkdir $DIR/$tdir/local_dir
2706
2707         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2708         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2709         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2710
2711         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2712                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2713
2714         rmdir $DIR/$tdir/* || error "rmdir failed"
2715
2716         umask 777
2717         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2718         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2719         mkdir $DIR/$tdir/local_dir
2720
2721         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2722         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2723         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2724
2725         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2726                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2727
2728         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2729
2730         umask 000
2731         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2732         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2733         mkdir $DIR/$tdir/local_dir
2734
2735         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2736         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2737         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2738
2739         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2740                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2741 }
2742 run_test 33e "mkdir and striped directory should have same mode"
2743
2744 cleanup_33f() {
2745         trap 0
2746         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
2747 }
2748
2749 test_33f() {
2750         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2751
2752         mkdir $DIR/$tdir
2753         chmod go+rwx $DIR/$tdir
2754         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
2755         trap cleanup_33f EXIT
2756
2757         $RUNAS lfs mkdir -c$MDSCOUNT $DIR/$tdir/striped_dir ||
2758                 error "cannot create striped directory"
2759
2760         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
2761                 error "cannot create files in striped directory"
2762
2763         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
2764                 error "cannot remove files in striped directory"
2765
2766         $RUNAS rmdir $DIR/$tdir/striped_dir ||
2767                 error "cannot remove striped directory"
2768
2769         cleanup_33f
2770 }
2771 run_test 33f "nonroot user can create, access, and remove a striped directory"
2772
2773 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2774 test_34a() {
2775         rm -f $DIR/f34
2776         $MCREATE $DIR/f34 || error
2777         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2778         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2779         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2780         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2781 }
2782 run_test 34a "truncate file that has not been opened ==========="
2783
2784 test_34b() {
2785         [ ! -f $DIR/f34 ] && test_34a
2786         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2787         $OPENFILE -f O_RDONLY $DIR/f34
2788         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2789         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2790 }
2791 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2792
2793 test_34c() {
2794         [ ! -f $DIR/f34 ] && test_34a
2795         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2796         $OPENFILE -f O_RDWR $DIR/f34
2797         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2798         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2799 }
2800 run_test 34c "O_RDWR opening file-with-size works =============="
2801
2802 test_34d() {
2803         [ ! -f $DIR/f34 ] && test_34a
2804         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2805         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2806         rm $DIR/f34
2807 }
2808 run_test 34d "write to sparse file ============================="
2809
2810 test_34e() {
2811         rm -f $DIR/f34e
2812         $MCREATE $DIR/f34e || error
2813         $TRUNCATE $DIR/f34e 1000 || error
2814         $CHECKSTAT -s 1000 $DIR/f34e || error
2815         $OPENFILE -f O_RDWR $DIR/f34e
2816         $CHECKSTAT -s 1000 $DIR/f34e || error
2817 }
2818 run_test 34e "create objects, some with size and some without =="
2819
2820 test_34f() { # bug 6242, 6243
2821         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2822         SIZE34F=48000
2823         rm -f $DIR/f34f
2824         $MCREATE $DIR/f34f || error
2825         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2826         dd if=$DIR/f34f of=$TMP/f34f
2827         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2828         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2829         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2830         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2831         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2832 }
2833 run_test 34f "read from a file with no objects until EOF ======="
2834
2835 test_34g() {
2836         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2837         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2838         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2839         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2840         cancel_lru_locks osc
2841         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2842                 error "wrong size after lock cancel"
2843
2844         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2845         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2846                 error "expanding truncate failed"
2847         cancel_lru_locks osc
2848         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2849                 error "wrong expanded size after lock cancel"
2850 }
2851 run_test 34g "truncate long file ==============================="
2852
2853 test_34h() {
2854         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2855         local gid=10
2856         local sz=1000
2857
2858         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2859         sync # Flush the cache so that multiop below does not block on cache
2860              # flush when getting the group lock
2861         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2862         MULTIPID=$!
2863
2864         # Since just timed wait is not good enough, let's do a sync write
2865         # that way we are sure enough time for a roundtrip + processing
2866         # passed + 2 seconds of extra margin.
2867         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2868         rm $DIR/${tfile}-1
2869         sleep 2
2870
2871         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2872                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2873                 kill -9 $MULTIPID
2874         fi
2875         wait $MULTIPID
2876         local nsz=`stat -c %s $DIR/$tfile`
2877         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2878 }
2879 run_test 34h "ftruncate file under grouplock should not block"
2880
2881 test_35a() {
2882         cp /bin/sh $DIR/f35a
2883         chmod 444 $DIR/f35a
2884         chown $RUNAS_ID $DIR/f35a
2885         $RUNAS $DIR/f35a && error || true
2886         rm $DIR/f35a
2887 }
2888 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2889
2890 test_36a() {
2891         rm -f $DIR/f36
2892         utime $DIR/f36 || error
2893 }
2894 run_test 36a "MDS utime check (mknod, utime) ==================="
2895
2896 test_36b() {
2897         echo "" > $DIR/f36
2898         utime $DIR/f36 || error
2899 }
2900 run_test 36b "OST utime check (open, utime) ===================="
2901
2902 test_36c() {
2903         rm -f $DIR/d36/f36
2904         test_mkdir $DIR/d36
2905         chown $RUNAS_ID $DIR/d36
2906         $RUNAS utime $DIR/d36/f36 || error
2907 }
2908 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2909
2910 test_36d() {
2911         [ ! -d $DIR/d36 ] && test_36c
2912         echo "" > $DIR/d36/f36
2913         $RUNAS utime $DIR/d36/f36 || error
2914 }
2915 run_test 36d "non-root OST utime check (open, utime) ==========="
2916
2917 test_36e() {
2918         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2919         test_mkdir -p $DIR/$tdir
2920         touch $DIR/$tdir/$tfile
2921         $RUNAS utime $DIR/$tdir/$tfile && \
2922                 error "utime worked, expected failure" || true
2923 }
2924 run_test 36e "utime on non-owned file (should return error) ===="
2925
2926 subr_36fh() {
2927         local fl="$1"
2928         local LANG_SAVE=$LANG
2929         local LC_LANG_SAVE=$LC_LANG
2930         export LANG=C LC_LANG=C # for date language
2931
2932         DATESTR="Dec 20  2000"
2933         test_mkdir -p $DIR/$tdir
2934         lctl set_param fail_loc=$fl
2935         date; date +%s
2936         cp /etc/hosts $DIR/$tdir/$tfile
2937         sync & # write RPC generated with "current" inode timestamp, but delayed
2938         sleep 1
2939         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2940         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2941         cancel_lru_locks osc
2942         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2943         date; date +%s
2944         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2945                 echo "BEFORE: $LS_BEFORE" && \
2946                 echo "AFTER : $LS_AFTER" && \
2947                 echo "WANT  : $DATESTR" && \
2948                 error "$DIR/$tdir/$tfile timestamps changed" || true
2949
2950         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2951 }
2952
2953 test_36f() {
2954         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2955         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2956         subr_36fh "0x80000214"
2957 }
2958 run_test 36f "utime on file racing with OST BRW write =========="
2959
2960 test_36g() {
2961         remote_ost_nodsh && skip "remote OST with nodsh" && return
2962         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2963         local fmd_max_age
2964         local fmd_before
2965         local fmd_after
2966
2967         test_mkdir -p $DIR/$tdir
2968         fmd_max_age=$(do_facet ost1 \
2969                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2970                 head -n 1")
2971
2972         fmd_before=$(do_facet ost1 \
2973                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2974         touch $DIR/$tdir/$tfile
2975         sleep $((fmd_max_age + 12))
2976         fmd_after=$(do_facet ost1 \
2977                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2978
2979         echo "fmd_before: $fmd_before"
2980         echo "fmd_after: $fmd_after"
2981         [[ $fmd_after -gt $fmd_before ]] &&
2982                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
2983                 error "fmd didn't expire after ping" || true
2984 }
2985 run_test 36g "filter mod data cache expiry ====================="
2986
2987 test_36h() {
2988         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2989         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2990         subr_36fh "0x80000227"
2991 }
2992 run_test 36h "utime on file racing with OST BRW write =========="
2993
2994 test_36i() {
2995         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2996
2997         mkdir $DIR/$tdir
2998         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
2999
3000         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3001         local new_mtime=$((mtime + 200))
3002
3003         #change Modify time of striped dir
3004         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3005                         error "change mtime failed"
3006
3007         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3008
3009         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3010 }
3011 run_test 36i "change mtime on striped directory"
3012
3013 # test_37 - duplicate with tests 32q 32r
3014
3015 test_38() {
3016         local file=$DIR/$tfile
3017         touch $file
3018         openfile -f O_DIRECTORY $file
3019         local RC=$?
3020         local ENOTDIR=20
3021         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3022         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3023 }
3024 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3025
3026 test_39() {
3027         touch $DIR/$tfile
3028         touch $DIR/${tfile}2
3029 #       ls -l  $DIR/$tfile $DIR/${tfile}2
3030 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
3031 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
3032         sleep 2
3033         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3034         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3035                 echo "mtime"
3036                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3037                 echo "atime"
3038                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3039                 echo "ctime"
3040                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3041                 error "O_TRUNC didn't change timestamps"
3042         fi
3043 }
3044 run_test 39 "mtime changed on create ==========================="
3045
3046 test_39b() {
3047         test_mkdir -p -c1 $DIR/$tdir
3048         cp -p /etc/passwd $DIR/$tdir/fopen
3049         cp -p /etc/passwd $DIR/$tdir/flink
3050         cp -p /etc/passwd $DIR/$tdir/funlink
3051         cp -p /etc/passwd $DIR/$tdir/frename
3052         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3053
3054         sleep 1
3055         echo "aaaaaa" >> $DIR/$tdir/fopen
3056         echo "aaaaaa" >> $DIR/$tdir/flink
3057         echo "aaaaaa" >> $DIR/$tdir/funlink
3058         echo "aaaaaa" >> $DIR/$tdir/frename
3059
3060         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3061         local link_new=`stat -c %Y $DIR/$tdir/flink`
3062         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3063         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3064
3065         cat $DIR/$tdir/fopen > /dev/null
3066         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3067         rm -f $DIR/$tdir/funlink2
3068         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3069
3070         for (( i=0; i < 2; i++ )) ; do
3071                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3072                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3073                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3074                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3075
3076                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3077                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3078                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3079                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3080
3081                 cancel_lru_locks osc
3082                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3083         done
3084 }
3085 run_test 39b "mtime change on open, link, unlink, rename  ======"
3086
3087 # this should be set to past
3088 TEST_39_MTIME=`date -d "1 year ago" +%s`
3089
3090 # bug 11063
3091 test_39c() {
3092         touch $DIR1/$tfile
3093         sleep 2
3094         local mtime0=`stat -c %Y $DIR1/$tfile`
3095
3096         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3097         local mtime1=`stat -c %Y $DIR1/$tfile`
3098         [ "$mtime1" = $TEST_39_MTIME ] || \
3099                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3100
3101         local d1=`date +%s`
3102         echo hello >> $DIR1/$tfile
3103         local d2=`date +%s`
3104         local mtime2=`stat -c %Y $DIR1/$tfile`
3105         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3106                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3107
3108         mv $DIR1/$tfile $DIR1/$tfile-1
3109
3110         for (( i=0; i < 2; i++ )) ; do
3111                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3112                 [ "$mtime2" = "$mtime3" ] || \
3113                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3114
3115                 cancel_lru_locks osc
3116                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3117         done
3118 }
3119 run_test 39c "mtime change on rename ==========================="
3120
3121 # bug 21114
3122 test_39d() {
3123         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3124         touch $DIR1/$tfile
3125
3126         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3127
3128         for (( i=0; i < 2; i++ )) ; do
3129                 local mtime=`stat -c %Y $DIR1/$tfile`
3130                 [ $mtime = $TEST_39_MTIME ] || \
3131                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3132
3133                 cancel_lru_locks osc
3134                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3135         done
3136 }
3137 run_test 39d "create, utime, stat =============================="
3138
3139 # bug 21114
3140 test_39e() {
3141         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3142         touch $DIR1/$tfile
3143         local mtime1=`stat -c %Y $DIR1/$tfile`
3144
3145         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3146
3147         for (( i=0; i < 2; i++ )) ; do
3148                 local mtime2=`stat -c %Y $DIR1/$tfile`
3149                 [ $mtime2 = $TEST_39_MTIME ] || \
3150                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3151
3152                 cancel_lru_locks osc
3153                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3154         done
3155 }
3156 run_test 39e "create, stat, utime, stat ========================"
3157
3158 # bug 21114
3159 test_39f() {
3160         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3161         touch $DIR1/$tfile
3162         mtime1=`stat -c %Y $DIR1/$tfile`
3163
3164         sleep 2
3165         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3166
3167         for (( i=0; i < 2; i++ )) ; do
3168                 local mtime2=`stat -c %Y $DIR1/$tfile`
3169                 [ $mtime2 = $TEST_39_MTIME ] || \
3170                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3171
3172                 cancel_lru_locks osc
3173                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3174         done
3175 }
3176 run_test 39f "create, stat, sleep, utime, stat ================="
3177
3178 # bug 11063
3179 test_39g() {
3180         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3181         echo hello >> $DIR1/$tfile
3182         local mtime1=`stat -c %Y $DIR1/$tfile`
3183
3184         sleep 2
3185         chmod o+r $DIR1/$tfile
3186
3187         for (( i=0; i < 2; i++ )) ; do
3188                 local mtime2=`stat -c %Y $DIR1/$tfile`
3189                 [ "$mtime1" = "$mtime2" ] || \
3190                         error "lost mtime: $mtime2, should be $mtime1"
3191
3192                 cancel_lru_locks osc
3193                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3194         done
3195 }
3196 run_test 39g "write, chmod, stat ==============================="
3197
3198 # bug 11063
3199 test_39h() {
3200         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3201         touch $DIR1/$tfile
3202         sleep 1
3203
3204         local d1=`date`
3205         echo hello >> $DIR1/$tfile
3206         local mtime1=`stat -c %Y $DIR1/$tfile`
3207
3208         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3209         local d2=`date`
3210         if [ "$d1" != "$d2" ]; then
3211                 echo "write and touch not within one second"
3212         else
3213                 for (( i=0; i < 2; i++ )) ; do
3214                         local mtime2=`stat -c %Y $DIR1/$tfile`
3215                         [ "$mtime2" = $TEST_39_MTIME ] || \
3216                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3217
3218                         cancel_lru_locks osc
3219                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3220                 done
3221         fi
3222 }
3223 run_test 39h "write, utime within one second, stat ============="
3224
3225 test_39i() {
3226         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3227         touch $DIR1/$tfile
3228         sleep 1
3229
3230         echo hello >> $DIR1/$tfile
3231         local mtime1=`stat -c %Y $DIR1/$tfile`
3232
3233         mv $DIR1/$tfile $DIR1/$tfile-1
3234
3235         for (( i=0; i < 2; i++ )) ; do
3236                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3237
3238                 [ "$mtime1" = "$mtime2" ] || \
3239                         error "lost mtime: $mtime2, should be $mtime1"
3240
3241                 cancel_lru_locks osc
3242                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3243         done
3244 }
3245 run_test 39i "write, rename, stat =============================="
3246
3247 test_39j() {
3248         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3249         start_full_debug_logging
3250         touch $DIR1/$tfile
3251         sleep 1
3252
3253         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3254         lctl set_param fail_loc=0x80000412
3255         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3256                 error "multiop failed"
3257         local multipid=$!
3258         local mtime1=`stat -c %Y $DIR1/$tfile`
3259
3260         mv $DIR1/$tfile $DIR1/$tfile-1
3261
3262         kill -USR1 $multipid
3263         wait $multipid || error "multiop close failed"
3264
3265         for (( i=0; i < 2; i++ )) ; do
3266                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3267                 [ "$mtime1" = "$mtime2" ] ||
3268                         error "mtime is lost on close: $mtime2, " \
3269                               "should be $mtime1"
3270
3271                 cancel_lru_locks osc
3272                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3273         done
3274         lctl set_param fail_loc=0
3275         stop_full_debug_logging
3276 }
3277 run_test 39j "write, rename, close, stat ======================="
3278
3279 test_39k() {
3280         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3281         touch $DIR1/$tfile
3282         sleep 1
3283
3284         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3285         local multipid=$!
3286         local mtime1=`stat -c %Y $DIR1/$tfile`
3287
3288         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3289
3290         kill -USR1 $multipid
3291         wait $multipid || error "multiop close failed"
3292
3293         for (( i=0; i < 2; i++ )) ; do
3294                 local mtime2=`stat -c %Y $DIR1/$tfile`
3295
3296                 [ "$mtime2" = $TEST_39_MTIME ] || \
3297                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3298
3299                 cancel_lru_locks osc
3300                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3301         done
3302 }
3303 run_test 39k "write, utime, close, stat ========================"
3304
3305 # this should be set to future
3306 TEST_39_ATIME=`date -d "1 year" +%s`
3307
3308 test_39l() {
3309         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3310         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3311         local atime_diff=$(do_facet $SINGLEMDS \
3312                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3313         rm -rf $DIR/$tdir
3314         mkdir -p $DIR/$tdir
3315
3316         # test setting directory atime to future
3317         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3318         local atime=$(stat -c %X $DIR/$tdir)
3319         [ "$atime" = $TEST_39_ATIME ] || \
3320                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3321
3322         # test setting directory atime from future to now
3323         local d1=$(date +%s)
3324         ls $DIR/$tdir
3325         local d2=$(date +%s)
3326
3327         cancel_lru_locks mdc
3328         atime=$(stat -c %X $DIR/$tdir)
3329         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3330                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3331
3332         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3333         sleep 3
3334
3335         # test setting directory atime when now > dir atime + atime_diff
3336         d1=$(date +%s)
3337         ls $DIR/$tdir
3338         d2=$(date +%s)
3339         cancel_lru_locks mdc
3340         atime=$(stat -c %X $DIR/$tdir)
3341         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3342                 error "atime is not updated  : $atime, should be $d2"
3343
3344         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3345         sleep 3
3346
3347         # test not setting directory atime when now < dir atime + atime_diff
3348         ls $DIR/$tdir
3349         cancel_lru_locks mdc
3350         atime=$(stat -c %X $DIR/$tdir)
3351         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3352                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3353
3354         do_facet $SINGLEMDS \
3355                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3356 }
3357 run_test 39l "directory atime update ==========================="
3358
3359 test_39m() {
3360         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3361         touch $DIR1/$tfile
3362         sleep 2
3363         local far_past_mtime=$(date -d "May 29 1953" +%s)
3364         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3365
3366         touch -m -d @$far_past_mtime $DIR1/$tfile
3367         touch -a -d @$far_past_atime $DIR1/$tfile
3368
3369         for (( i=0; i < 2; i++ )) ; do
3370                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3371                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3372                         error "atime or mtime set incorrectly"
3373
3374                 cancel_lru_locks osc
3375                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3376         done
3377 }
3378 run_test 39m "test atime and mtime before 1970"
3379
3380 test_39n() { # LU-3832
3381         local atime_diff=$(do_facet $SINGLEMDS \
3382                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3383         local atime0
3384         local atime1
3385         local atime2
3386
3387         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3388
3389         rm -rf $DIR/$tfile
3390         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3391         atime0=$(stat -c %X $DIR/$tfile)
3392
3393         sleep 5
3394         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3395         atime1=$(stat -c %X $DIR/$tfile)
3396
3397         sleep 5
3398         cancel_lru_locks mdc
3399         cancel_lru_locks osc
3400         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3401         atime2=$(stat -c %X $DIR/$tfile)
3402
3403         do_facet $SINGLEMDS \
3404                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3405
3406         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3407         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3408 }
3409 run_test 39n "check that O_NOATIME is honored"
3410
3411 test_39o() {
3412         TESTDIR=$DIR/$tdir/$tfile
3413         [ -e $TESTDIR ] && rm -rf $TESTDIR
3414         test_mkdir -p $TESTDIR
3415         cd $TESTDIR
3416         links1=2
3417         ls
3418         mkdir a b
3419         ls
3420         links2=$(stat -c %h .)
3421         [ $(($links1 + 2)) != $links2 ] &&
3422                 error "wrong links count $(($links1 + 2)) != $links2"
3423         rmdir b
3424         links3=$(stat -c %h .)
3425         [ $(($links1 + 1)) != $links3 ] &&
3426                 error "wrong links count $links1 != $links3"
3427         return 0
3428 }
3429 run_test 39o "directory cached attributes updated after create ========"
3430
3431 test_39p() {
3432         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3433         local MDTIDX=1
3434         TESTDIR=$DIR/$tdir/$tfile
3435         [ -e $TESTDIR ] && rm -rf $TESTDIR
3436         mkdir -p $TESTDIR
3437         cd $TESTDIR
3438         links1=2
3439         ls
3440         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3441         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3442         ls
3443         links2=$(stat -c %h .)
3444         [ $(($links1 + 2)) != $links2 ] &&
3445                 error "wrong links count $(($links1 + 2)) != $links2"
3446         rmdir remote_dir2
3447         links3=$(stat -c %h .)
3448         [ $(($links1 + 1)) != $links3 ] &&
3449                 error "wrong links count $links1 != $links3"
3450         return 0
3451 }
3452 run_test 39p "remote directory cached attributes updated after create ========"
3453
3454
3455 test_40() {
3456         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3457         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3458                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3459         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3460                 error "$tfile is not 4096 bytes in size"
3461 }
3462 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3463
3464 test_41() {
3465         # bug 1553
3466         small_write $DIR/f41 18
3467 }
3468 run_test 41 "test small file write + fstat ====================="
3469
3470 count_ost_writes() {
3471         lctl get_param -n osc.*.stats |
3472                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3473                         END { printf("%0.0f", writes) }'
3474 }
3475
3476 # decent default
3477 WRITEBACK_SAVE=500
3478 DIRTY_RATIO_SAVE=40
3479 MAX_DIRTY_RATIO=50
3480 BG_DIRTY_RATIO_SAVE=10
3481 MAX_BG_DIRTY_RATIO=25
3482
3483 start_writeback() {
3484         trap 0
3485         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3486         # dirty_ratio, dirty_background_ratio
3487         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3488                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3489                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3490                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3491         else
3492                 # if file not here, we are a 2.4 kernel
3493                 kill -CONT `pidof kupdated`
3494         fi
3495 }
3496
3497 stop_writeback() {
3498         # setup the trap first, so someone cannot exit the test at the
3499         # exact wrong time and mess up a machine
3500         trap start_writeback EXIT
3501         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3502         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3503                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3504                 sysctl -w vm.dirty_writeback_centisecs=0
3505                 sysctl -w vm.dirty_writeback_centisecs=0
3506                 # save and increase /proc/sys/vm/dirty_ratio
3507                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3508                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3509                 # save and increase /proc/sys/vm/dirty_background_ratio
3510                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3511                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3512         else
3513                 # if file not here, we are a 2.4 kernel
3514                 kill -STOP `pidof kupdated`
3515         fi
3516 }
3517
3518 # ensure that all stripes have some grant before we test client-side cache
3519 setup_test42() {
3520         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3521                 dd if=/dev/zero of=$i bs=4k count=1
3522                 rm $i
3523         done
3524 }
3525
3526 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3527 # file truncation, and file removal.
3528 test_42a() {
3529         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3530         setup_test42
3531         cancel_lru_locks osc
3532         stop_writeback
3533         sync; sleep 1; sync # just to be safe
3534         BEFOREWRITES=`count_ost_writes`
3535         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3536         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3537         AFTERWRITES=`count_ost_writes`
3538         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3539                 error "$BEFOREWRITES < $AFTERWRITES"
3540         start_writeback
3541 }
3542 run_test 42a "ensure that we don't flush on close =============="
3543
3544 test_42b() {
3545         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3546         setup_test42
3547         cancel_lru_locks osc
3548         stop_writeback
3549         sync
3550         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3551         BEFOREWRITES=$(count_ost_writes)
3552         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3553         AFTERWRITES=$(count_ost_writes)
3554         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3555                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3556         fi
3557         BEFOREWRITES=$(count_ost_writes)
3558         sync || error "sync: $?"
3559         AFTERWRITES=$(count_ost_writes)
3560         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3561                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3562         fi
3563         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3564         start_writeback
3565         return 0
3566 }
3567 run_test 42b "test destroy of file with cached dirty data ======"
3568
3569 # if these tests just want to test the effect of truncation,
3570 # they have to be very careful.  consider:
3571 # - the first open gets a {0,EOF}PR lock
3572 # - the first write conflicts and gets a {0, count-1}PW
3573 # - the rest of the writes are under {count,EOF}PW
3574 # - the open for truncate tries to match a {0,EOF}PR
3575 #   for the filesize and cancels the PWs.
3576 # any number of fixes (don't get {0,EOF} on open, match
3577 # composite locks, do smarter file size management) fix
3578 # this, but for now we want these tests to verify that
3579 # the cancellation with truncate intent works, so we
3580 # start the file with a full-file pw lock to match against
3581 # until the truncate.
3582 trunc_test() {
3583         test=$1
3584         file=$DIR/$test
3585         offset=$2
3586         cancel_lru_locks osc
3587         stop_writeback
3588         # prime the file with 0,EOF PW to match
3589         touch $file
3590         $TRUNCATE $file 0
3591         sync; sync
3592         # now the real test..
3593         dd if=/dev/zero of=$file bs=1024 count=100
3594         BEFOREWRITES=`count_ost_writes`
3595         $TRUNCATE $file $offset
3596         cancel_lru_locks osc
3597         AFTERWRITES=`count_ost_writes`
3598         start_writeback
3599 }
3600
3601 test_42c() {
3602         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3603         trunc_test 42c 1024
3604         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3605             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3606         rm $file
3607 }
3608 run_test 42c "test partial truncate of file with cached dirty data"
3609
3610 test_42d() {
3611         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3612         trunc_test 42d 0
3613         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3614             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3615         rm $file
3616 }
3617 run_test 42d "test complete truncate of file with cached dirty data"
3618
3619 test_42e() { # bug22074
3620         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3621         local TDIR=$DIR/${tdir}e
3622         local pagesz=$(page_size)
3623         local pages=16 # hardcoded 16 pages, don't change it.
3624         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3625         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3626         local max_dirty_mb
3627         local warmup_files
3628
3629         test_mkdir -p $DIR/${tdir}e
3630         $SETSTRIPE -c 1 $TDIR
3631         createmany -o $TDIR/f $files
3632
3633         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3634
3635         # we assume that with $OSTCOUNT files, at least one of them will
3636         # be allocated on OST0.
3637         warmup_files=$((OSTCOUNT * max_dirty_mb))
3638         createmany -o $TDIR/w $warmup_files
3639
3640         # write a large amount of data into one file and sync, to get good
3641         # avail_grant number from OST.
3642         for ((i=0; i<$warmup_files; i++)); do
3643                 idx=$($GETSTRIPE -i $TDIR/w$i)
3644                 [ $idx -ne 0 ] && continue
3645                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3646                 break
3647         done
3648         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3649         sync
3650         $LCTL get_param $proc_osc0/cur_dirty_bytes
3651         $LCTL get_param $proc_osc0/cur_grant_bytes
3652
3653         # create as much dirty pages as we can while not to trigger the actual
3654         # RPCs directly. but depends on the env, VFS may trigger flush during this
3655         # period, hopefully we are good.
3656         for ((i=0; i<$warmup_files; i++)); do
3657                 idx=$($GETSTRIPE -i $TDIR/w$i)
3658                 [ $idx -ne 0 ] && continue
3659                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3660         done
3661         $LCTL get_param $proc_osc0/cur_dirty_bytes
3662         $LCTL get_param $proc_osc0/cur_grant_bytes
3663
3664         # perform the real test
3665         $LCTL set_param $proc_osc0/rpc_stats 0
3666         for ((;i<$files; i++)); do
3667                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3668                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3669         done
3670         sync
3671         $LCTL get_param $proc_osc0/rpc_stats
3672
3673         local percent=0
3674         local have_ppr=false
3675         $LCTL get_param $proc_osc0/rpc_stats |
3676                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3677                         # skip lines until we are at the RPC histogram data
3678                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3679                         $have_ppr || continue
3680
3681                         # we only want the percent stat for < 16 pages
3682                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3683
3684                         percent=$((percent + WPCT))
3685                         if [[ $percent -gt 15 ]]; then
3686                                 error "less than 16-pages write RPCs" \
3687                                       "$percent% > 15%"
3688                                 break
3689                         fi
3690                 done
3691         rm -rf $TDIR
3692 }
3693 run_test 42e "verify sub-RPC writes are not done synchronously"
3694
3695 test_43() {
3696         test_mkdir -p $DIR/$tdir
3697         cp -p /bin/ls $DIR/$tdir/$tfile
3698         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3699         pid=$!
3700         # give multiop a chance to open
3701         sleep 1
3702
3703         $DIR/$tdir/$tfile && error || true
3704         kill -USR1 $pid
3705 }
3706 run_test 43 "execution of file opened for write should return -ETXTBSY"
3707
3708 test_43a() {
3709         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3710         test_mkdir -p $DIR/$tdir
3711         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3712                         cp -p multiop $DIR/$tdir/multiop
3713         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3714                         return 1
3715         MULTIOP_PID=$!
3716         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3717         kill -USR1 $MULTIOP_PID || return 2
3718         wait $MULTIOP_PID || return 3
3719         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3720 }
3721 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3722
3723 test_43b() {
3724         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3725         test_mkdir -p $DIR/$tdir
3726         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3727                         cp -p multiop $DIR/$tdir/multiop
3728         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3729                         return 1
3730         MULTIOP_PID=$!
3731         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3732         kill -USR1 $MULTIOP_PID || return 2
3733         wait $MULTIOP_PID || return 3
3734         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3735 }
3736 run_test 43b "truncate of file being executed should return -ETXTBSY"
3737
3738 test_43c() {
3739         local testdir="$DIR/$tdir"
3740         test_mkdir -p $DIR/$tdir
3741         cp $SHELL $testdir/
3742         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3743                 ( cd $testdir && md5sum -c)
3744 }
3745 run_test 43c "md5sum of copy into lustre========================"
3746
3747 test_44() {
3748         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3749         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3750         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3751 }
3752 run_test 44 "zero length read from a sparse stripe ============="
3753
3754 test_44a() {
3755         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3756                 awk '{ print $2 }')
3757         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3758         [[ $nstripe -gt $OSTCOUNT ]] &&
3759             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3760             return
3761         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3762                 awk '{ print $2 }')
3763         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3764                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3765                         awk '{ print $2 }')
3766         fi
3767
3768         OFFSETS="0 $((stride/2)) $((stride-1))"
3769         for offset in $OFFSETS; do
3770                 for i in $(seq 0 $((nstripe-1))); do
3771                         local GLOBALOFFSETS=""
3772                         # size in Bytes
3773                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3774                         local myfn=$DIR/d44a-$size
3775                         echo "--------writing $myfn at $size"
3776                         ll_sparseness_write $myfn $size ||
3777                                 error "ll_sparseness_write"
3778                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3779                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3780                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3781
3782                         for j in $(seq 0 $((nstripe-1))); do
3783                                 # size in Bytes
3784                                 size=$((((j + $nstripe )*$stride + $offset)))
3785                                 ll_sparseness_write $myfn $size ||
3786                                         error "ll_sparseness_write"
3787                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3788                         done
3789                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3790                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3791                         rm -f $myfn
3792                 done
3793         done
3794 }
3795 run_test 44a "test sparse pwrite ==============================="
3796
3797 dirty_osc_total() {
3798         tot=0
3799         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3800                 tot=$(($tot + $d))
3801         done
3802         echo $tot
3803 }
3804 do_dirty_record() {
3805         before=`dirty_osc_total`
3806         echo executing "\"$*\""
3807         eval $*
3808         after=`dirty_osc_total`
3809         echo before $before, after $after
3810 }
3811 test_45() {
3812         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3813         f="$DIR/f45"
3814         # Obtain grants from OST if it supports it
3815         echo blah > ${f}_grant
3816         stop_writeback
3817         sync
3818         do_dirty_record "echo blah > $f"
3819         [[ $before -eq $after ]] && error "write wasn't cached"
3820         do_dirty_record "> $f"
3821         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3822         do_dirty_record "echo blah > $f"
3823         [[ $before -eq $after ]] && error "write wasn't cached"
3824         do_dirty_record "sync"
3825         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3826         do_dirty_record "echo blah > $f"
3827         [[ $before -eq $after ]] && error "write wasn't cached"
3828         do_dirty_record "cancel_lru_locks osc"
3829         [[ $before -gt $after ]] ||
3830                 error "lock cancellation didn't lower dirty count"
3831         start_writeback
3832 }
3833 run_test 45 "osc io page accounting ============================"
3834
3835 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3836 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3837 # objects offset and an assert hit when an rpc was built with 1023's mapped
3838 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3839 test_46() {
3840         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3841         f="$DIR/f46"
3842         stop_writeback
3843         sync
3844         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3845         sync
3846         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3847         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3848         sync
3849         start_writeback
3850 }
3851 run_test 46 "dirtying a previously written page ================"
3852
3853 # test_47 is removed "Device nodes check" is moved to test_28
3854
3855 test_48a() { # bug 2399
3856         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
3857         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
3858                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly" &&
3859                 return
3860         test_mkdir $DIR/$tdir
3861         cd $DIR/$tdir
3862         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
3863         test_mkdir $DIR/$tdir || error "recreate directory failed"
3864         touch foo || error "'touch foo' failed after recreating cwd"
3865         test_mkdir bar || error "'mkdir foo' failed after recreating cwd"
3866         touch .foo || error "'touch .foo' failed after recreating cwd"
3867         test_mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
3868         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3869         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3870         cd . || error "'cd .' failed after recreating cwd"
3871         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3872         rmdir . && error "'rmdir .' worked after recreating cwd"
3873         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3874         cd .. || error "'cd ..' failed after recreating cwd"
3875 }
3876 run_test 48a "Access renamed working dir (should return errors)="
3877
3878 test_48b() { # bug 2399
3879         rm -rf $DIR/$tdir
3880         test_mkdir $DIR/$tdir
3881         cd $DIR/$tdir
3882         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3883         touch foo && error "'touch foo' worked after removing cwd"
3884         test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3885         touch .foo && error "'touch .foo' worked after removing cwd"
3886         test_mkdir .foo && error "'mkdir .foo' worked after removing cwd"
3887         ls . > /dev/null && error "'ls .' worked after removing cwd"
3888         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3889         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3890         test_mkdir . && error "'mkdir .' worked after removing cwd"
3891         rmdir . && error "'rmdir .' worked after removing cwd"
3892         ln -s . foo && error "'ln -s .' worked after removing cwd"
3893         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3894 }
3895 run_test 48b "Access removed working dir (should return errors)="
3896
3897 test_48c() { # bug 2350
3898         #lctl set_param debug=-1
3899         #set -vx
3900         rm -rf $DIR/$tdir
3901         test_mkdir -p $DIR/$tdir/dir
3902         cd $DIR/$tdir/dir
3903         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3904         $TRACE touch foo && error "touch foo worked after removing cwd"
3905         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3906         touch .foo && error "touch .foo worked after removing cwd"
3907         test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3908         $TRACE ls . && error "'ls .' worked after removing cwd"
3909         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3910         is_patchless || ( $TRACE cd . &&
3911                         error "'cd .' worked after removing cwd" )
3912         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3913         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3914         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3915         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3916 }
3917 run_test 48c "Access removed working subdir (should return errors)"
3918
3919 test_48d() { # bug 2350
3920         #lctl set_param debug=-1
3921         #set -vx
3922         rm -rf $DIR/$tdir
3923         test_mkdir -p $DIR/$tdir/dir
3924         cd $DIR/$tdir/dir
3925         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3926         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3927         $TRACE touch foo && error "'touch foo' worked after removing parent"
3928         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3929         touch .foo && error "'touch .foo' worked after removing parent"
3930         test_mkdir .foo && error "mkdir .foo worked after removing parent"
3931         $TRACE ls . && error "'ls .' worked after removing parent"
3932         $TRACE ls .. && error "'ls ..' worked after removing parent"
3933         is_patchless || ( $TRACE cd . &&
3934                         error "'cd .' worked after recreate parent" )
3935         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3936         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3937         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3938         is_patchless || ( $TRACE cd .. &&
3939                         error "'cd ..' worked after removing parent" || true )
3940 }
3941 run_test 48d "Access removed parent subdir (should return errors)"
3942
3943 test_48e() { # bug 4134
3944         #lctl set_param debug=-1
3945         #set -vx
3946         rm -rf $DIR/$tdir
3947         test_mkdir -p $DIR/$tdir/dir
3948         cd $DIR/$tdir/dir
3949         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3950         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3951         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3952         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3953         # On a buggy kernel addition of "touch foo" after cd .. will
3954         # produce kernel oops in lookup_hash_it
3955         touch ../foo && error "'cd ..' worked after recreate parent"
3956         cd $DIR
3957         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3958 }
3959 run_test 48e "Access to recreated parent subdir (should return errors)"
3960
3961 test_49() { # LU-1030
3962         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3963         # get ost1 size - lustre-OST0000
3964         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3965                 awk '{ print $4 }')
3966         # write 800M at maximum
3967         [[ $ost1_size -lt 2 ]] && ost1_size=2
3968         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3969
3970         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3971         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3972         local dd_pid=$!
3973
3974         # change max_pages_per_rpc while writing the file
3975         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3976         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3977         # loop until dd process exits
3978         while ps ax -opid | grep -wq $dd_pid; do
3979                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3980                 sleep $((RANDOM % 5 + 1))
3981         done
3982         # restore original max_pages_per_rpc
3983         $LCTL set_param $osc1_mppc=$orig_mppc
3984         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3985 }
3986 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3987
3988 test_50() {
3989         # bug 1485
3990         test_mkdir $DIR/$tdir
3991         cd $DIR/$tdir
3992         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3993 }
3994 run_test 50 "special situations: /proc symlinks  ==============="
3995
3996 test_51a() {    # was test_51
3997         # bug 1516 - create an empty entry right after ".." then split dir
3998         test_mkdir -c1 $DIR/$tdir
3999         touch $DIR/$tdir/foo
4000         $MCREATE $DIR/$tdir/bar
4001         rm $DIR/$tdir/foo
4002         createmany -m $DIR/$tdir/longfile 201
4003         FNUM=202
4004         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
4005                 $MCREATE $DIR/$tdir/longfile$FNUM
4006                 FNUM=$(($FNUM + 1))
4007                 echo -n "+"
4008         done
4009         echo
4010         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
4011 }
4012 run_test 51a "special situations: split htree with empty entry =="
4013
4014 export NUMTEST=70000
4015 test_51b() {
4016         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4017         local BASE=$DIR/d${base}.${TESTSUITE}
4018
4019         # cleanup the directory
4020         rm -fr $BASE
4021
4022         test_mkdir -p -c1 $BASE
4023
4024         $LFS df
4025         $LFS df -i
4026         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
4027         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
4028         [[ $numfree -lt 21000 ]] &&
4029                 skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
4030                 return
4031
4032         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
4033                 echo "reduced count to $NUMTEST due to inodes on MDT$mdtidx"
4034
4035         # need to check free space for the directories as well
4036         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
4037         numfree=$((blkfree / 4))
4038         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$((numfree - 50)) &&
4039                 echo "reduced count to $NUMTEST due to blocks on MDT$mdtidx"
4040
4041         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
4042         {
4043                 $LFS df
4044                 $LFS df -i
4045                 echo "failed" > $BASE/fnum
4046                 error "failed to create $NUMTEST subdirs in MDT$mdtidx:$BASE"
4047         }
4048 }
4049 run_test 51b "exceed 64k subdirectory nlink limit"
4050
4051 test_51ba() { # LU-993
4052         local BASE=$DIR/d${base}.${TESTSUITE}
4053         # unlink all but 100 subdirectories, then check it still works
4054         local LEFT=100
4055         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
4056
4057         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
4058         local DELETE=$((NUMTEST - LEFT))
4059
4060         # continue on to run this test even if 51b didn't finish,
4061         # just to delete the many subdirectories created.
4062         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
4063
4064         # for ldiskfs the nlink count should be 1, but this is OSD specific
4065         # and so this is listed for informational purposes only
4066         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
4067         unlinkmany -d $BASE/d $DELETE
4068         RC=$?
4069
4070         if [ $RC -ne 0 ]; then
4071                 if [ "$NUMPREV" == "failed" ]; then
4072                         skip "previous setup failed"
4073                         return 0
4074                 else
4075                         error "unlink of first $DELETE subdirs failed"
4076                         return $RC
4077                 fi
4078         fi
4079
4080         echo "nlink between: $(stat -c %h $BASE)"
4081         # trim the first line of ls output
4082         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
4083         [ $FOUND -ne $LEFT ] &&
4084                 error "can't find subdirs: found only $FOUND/$LEFT"
4085
4086         unlinkmany -d $BASE/d $DELETE $LEFT ||
4087                 error "unlink of second $LEFT subdirs failed"
4088         # regardless of whether the backing filesystem tracks nlink accurately
4089         # or not, the nlink count shouldn't be more than "." and ".." here
4090         local AFTER=$(stat -c %h $BASE)
4091         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
4092                 echo "nlink after: $AFTER"
4093 }
4094 run_test 51ba "verify nlink for many subdirectory cleanup"
4095
4096 test_51d() {
4097         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4098         [[ $OSTCOUNT -lt 3 ]] &&
4099                 skip_env "skipping test with few OSTs" && return
4100         test_mkdir -p $DIR/$tdir
4101         createmany -o $DIR/$tdir/t- 1000
4102         $GETSTRIPE $DIR/$tdir > $TMP/files
4103         for N in $(seq 0 $((OSTCOUNT - 1))); do
4104                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4105                         END { printf("%0.0f", objs) }' $TMP/files)
4106                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
4107                         '($1 == '$N') { objs += 1 } \
4108                         END { printf("%0.0f", objs) }')
4109                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4110         done
4111         unlinkmany $DIR/$tdir/t- 1000
4112
4113         NLAST=0
4114         for N in $(seq 1 $((OSTCOUNT - 1))); do
4115                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4116                         error "OST $N has less objects vs OST $NLAST" \
4117                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4118                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4119                         error "OST $N has less objects vs OST $NLAST" \
4120                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4121
4122                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4123                         error "OST $N has less #0 objects vs OST $NLAST" \
4124                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4125                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4126                         error "OST $N has less #0 objects vs OST $NLAST" \
4127                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4128                 NLAST=$N
4129         done
4130 }
4131 run_test 51d "check object distribution ===================="
4132
4133 test_51e() {
4134         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4135                 skip "Only applicable to ldiskfs-based MDTs"
4136                 return
4137         fi
4138
4139         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4140         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4141
4142         touch $DIR/$tdir/d0/foo
4143         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4144                 error "file exceed 65000 nlink limit!"
4145         unlinkmany $DIR/$tdir/d0/f- 65001
4146         return 0
4147 }
4148 run_test 51e "check file nlink limit"
4149
4150 test_52a() {
4151         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4152         test_mkdir -p $DIR/$tdir
4153         touch $DIR/$tdir/foo
4154         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4155         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4156         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4157         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4158         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4159                                         error "link worked"
4160         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4161         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4162         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4163                                                      error "lsattr"
4164         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4165         cp -r $DIR/$tdir /tmp/
4166         rm -fr $DIR/$tdir || error "cleanup rm failed"
4167 }
4168 run_test 52a "append-only flag test (should return errors) ====="
4169
4170 test_52b() {
4171         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4172         test_mkdir -p $DIR/$tdir
4173         touch $DIR/$tdir/foo
4174         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4175         cat test > $DIR/$tdir/foo && error "cat test worked"
4176         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4177         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4178         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4179                                         error "link worked"
4180         echo foo >> $DIR/$tdir/foo && error "echo worked"
4181         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4182         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4183         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4184         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4185                                                         error "lsattr"
4186         chattr -i $DIR/$tdir/foo || error "chattr failed"
4187
4188         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4189 }
4190 run_test 52b "immutable flag test (should return errors) ======="
4191
4192 test_53() {
4193         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4194         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4195         remote_ost_nodsh && skip "remote OST with nodsh" && return
4196
4197         local param
4198         local param_seq
4199         local ostname
4200         local mds_last
4201         local mds_last_seq
4202         local ost_last
4203         local ost_last_seq
4204         local ost_last_id
4205         local ostnum
4206         local node
4207         local found=false
4208         local support_last_seq=true
4209
4210         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4211                 support_last_seq=false
4212
4213         # only test MDT0000
4214         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4215         local value
4216         for value in $(do_facet $SINGLEMDS \
4217                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4218                 param=$(echo ${value[0]} | cut -d "=" -f1)
4219                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4220
4221                 if $support_last_seq; then
4222                         param_seq=$(echo $param |
4223                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4224                         mds_last_seq=$(do_facet $SINGLEMDS \
4225                                        $LCTL get_param -n $param_seq)
4226                 fi
4227                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4228
4229                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4230                 node=$(facet_active_host ost$((ostnum+1)))
4231                 param="obdfilter.$ostname.last_id"
4232                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4233                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4234                         ost_last_id=$ost_last
4235
4236                         if $support_last_seq; then
4237                                 ost_last_id=$(echo $ost_last |
4238                                               awk -F':' '{print $2}' |
4239                                               sed -e "s/^0x//g")
4240                                 ost_last_seq=$(echo $ost_last |
4241                                                awk -F':' '{print $1}')
4242                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4243                         fi
4244
4245                         if [[ $ost_last_id != $mds_last ]]; then
4246                                 error "$ost_last_id != $mds_last"
4247                         else
4248                                 found=true
4249                                 break
4250                         fi
4251                 done
4252         done
4253         $found || error "can not match last_seq/last_id for $mdtosc"
4254         return 0
4255 }
4256 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4257
4258 test_54a() {
4259         $SOCKETSERVER $DIR/socket ||
4260                 error "$SOCKETSERVER $DIR/socket failed: $?"
4261         $SOCKETCLIENT $DIR/socket ||
4262                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4263         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4264 }
4265 run_test 54a "unix domain socket test =========================="
4266
4267 test_54b() {
4268         f="$DIR/f54b"
4269         mknod $f c 1 3
4270         chmod 0666 $f
4271         dd if=/dev/zero of=$f bs=$(page_size) count=1
4272 }
4273 run_test 54b "char device works in lustre ======================"
4274
4275 find_loop_dev() {
4276         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4277         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4278         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4279
4280         for i in $(seq 3 7); do
4281                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4282                 LOOPDEV=$LOOPBASE$i
4283                 LOOPNUM=$i
4284                 break
4285         done
4286 }
4287
4288 cleanup_54c() {
4289         loopdev="$DIR/loop54c"
4290
4291         trap 0
4292         $UMOUNT -d $DIR/$tdir || rc=$?
4293         losetup -d $loopdev || true
4294         losetup -d $LOOPDEV || true
4295         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4296         return $rc
4297 }
4298
4299 test_54c() {
4300         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4301         loopdev="$DIR/loop54c"
4302
4303         find_loop_dev
4304         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4305         trap cleanup_54c EXIT
4306         mknod $loopdev b 7 $LOOPNUM
4307         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4308         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4309         losetup $loopdev $DIR/$tfile ||
4310                 error "can't set up $loopdev for $DIR/$tfile"
4311         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4312         test_mkdir -p $DIR/$tdir
4313         mount -t ext2 $loopdev $DIR/$tdir ||
4314                 error "error mounting $loopdev on $DIR/$tdir"
4315         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4316                 error "dd write"
4317         df $DIR/$tdir
4318         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4319                 error "dd read"
4320         cleanup_54c
4321 }
4322 run_test 54c "block device works in lustre ====================="
4323
4324 test_54d() {
4325         f="$DIR/f54d"
4326         string="aaaaaa"
4327         mknod $f p
4328         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4329 }
4330 run_test 54d "fifo device works in lustre ======================"
4331
4332 test_54e() {
4333         f="$DIR/f54e"
4334         string="aaaaaa"
4335         cp -aL /dev/console $f
4336         echo $string > $f || error "echo $string to $f failed"
4337 }
4338 run_test 54e "console/tty device works in lustre ======================"
4339
4340 #The test_55 used to be iopen test and it was removed by bz#24037.
4341 #run_test 55 "check iopen_connect_dentry() ======================"
4342
4343 test_56a() {    # was test_56
4344         rm -rf $DIR/$tdir
4345         $SETSTRIPE -d $DIR
4346         test_mkdir -p $DIR/$tdir/dir
4347         NUMFILES=3
4348         NUMFILESx2=$(($NUMFILES * 2))
4349         for i in $(seq 1 $NUMFILES); do
4350                 touch $DIR/$tdir/file$i
4351                 touch $DIR/$tdir/dir/file$i
4352         done
4353
4354         # test lfs getstripe with --recursive
4355         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4356         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4357                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4358         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4359         [[ $FILENUM -eq $NUMFILES ]] ||
4360                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4361         echo "$GETSTRIPE --recursive passed."
4362
4363         # test lfs getstripe with file instead of dir
4364         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4365         [[ $FILENUM -eq 1 ]] ||
4366                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4367         echo "$GETSTRIPE file1 passed."
4368
4369         #test lfs getstripe with --verbose
4370         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4371                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4372                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4373         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4374                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4375         echo "$GETSTRIPE --verbose passed."
4376
4377         #test lfs getstripe with --obd
4378         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4379                 grep -q "unknown obduuid" ||
4380                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4381
4382         [[ $OSTCOUNT -lt 2 ]] &&
4383                 skip_env "skipping other $GETSTRIPE --obd test" && return
4384
4385         OSTIDX=1
4386         OBDUUID=$(ostuuid_from_index $OSTIDX)
4387         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4388         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4389         [[ $FOUND -eq $FILENUM ]] ||
4390                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4391         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4392                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4393                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4394                 error "$GETSTRIPE --obd: should not show file on other obd"
4395         echo "$GETSTRIPE --obd passed"
4396 }
4397 run_test 56a "check $GETSTRIPE"
4398
4399 NUMFILES=3
4400 NUMDIRS=3
4401 setup_56() {
4402         local LOCAL_NUMFILES="$1"
4403         local LOCAL_NUMDIRS="$2"
4404         local MKDIR_PARAMS="$3"
4405         local DIR_STRIPE_PARAMS="$4"
4406
4407         if [ ! -d "$TDIR" ] ; then
4408                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4409                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4410                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4411                         touch $TDIR/file$i
4412                 done
4413                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4414                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4415                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4416                                 touch $TDIR/dir$i/file$j
4417                         done
4418                 done
4419         fi
4420 }
4421
4422 setup_56_special() {
4423         LOCAL_NUMFILES=$1
4424         LOCAL_NUMDIRS=$2
4425         setup_56 $1 $2
4426         if [ ! -e "$TDIR/loop1b" ] ; then
4427                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4428                         mknod $TDIR/loop${i}b b 7 $i
4429                         mknod $TDIR/null${i}c c 1 3
4430                         ln -s $TDIR/file1 $TDIR/link${i}l
4431                 done
4432                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4433                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4434                         mknod $TDIR/dir$i/null${i}c c 1 3
4435                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4436                 done
4437         fi
4438 }
4439
4440 test_56g() {
4441         $SETSTRIPE -d $DIR
4442
4443         TDIR=$DIR/${tdir}g
4444         setup_56 $NUMFILES $NUMDIRS
4445
4446         EXPECTED=$(($NUMDIRS + 2))
4447         # test lfs find with -name
4448         for i in $(seq 1 $NUMFILES) ; do
4449                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4450                 [ $NUMS -eq $EXPECTED ] ||
4451                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4452                               "found $NUMS, expected $EXPECTED"
4453         done
4454 }
4455 run_test 56g "check lfs find -name ============================="
4456
4457 test_56h() {
4458         $SETSTRIPE -d $DIR
4459
4460         TDIR=$DIR/${tdir}g
4461         setup_56 $NUMFILES $NUMDIRS
4462
4463         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4464         # test lfs find with ! -name
4465         for i in $(seq 1 $NUMFILES) ; do
4466                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4467                 [ $NUMS -eq $EXPECTED ] ||
4468                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4469                               "found $NUMS, expected $EXPECTED"
4470         done
4471 }
4472 run_test 56h "check lfs find ! -name ============================="
4473
4474 test_56i() {
4475        tdir=${tdir}i
4476        test_mkdir -p $DIR/$tdir
4477        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4478        CMD="$LFIND -ost $UUID $DIR/$tdir"
4479        OUT=$($CMD)
4480        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4481 }
4482 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4483
4484 test_56j() {
4485         TDIR=$DIR/${tdir}g
4486         setup_56_special $NUMFILES $NUMDIRS
4487
4488         EXPECTED=$((NUMDIRS + 1))
4489         CMD="$LFIND -type d $TDIR"
4490         NUMS=$($CMD | wc -l)
4491         [ $NUMS -eq $EXPECTED ] ||
4492                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4493 }
4494 run_test 56j "check lfs find -type d ============================="
4495
4496 test_56k() {
4497         TDIR=$DIR/${tdir}g
4498         setup_56_special $NUMFILES $NUMDIRS
4499
4500         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4501         CMD="$LFIND -type f $TDIR"
4502         NUMS=$($CMD | wc -l)
4503         [ $NUMS -eq $EXPECTED ] ||
4504                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4505 }
4506 run_test 56k "check lfs find -type f ============================="
4507
4508 test_56l() {
4509         TDIR=$DIR/${tdir}g
4510         setup_56_special $NUMFILES $NUMDIRS
4511
4512         EXPECTED=$((NUMDIRS + NUMFILES))
4513         CMD="$LFIND -type b $TDIR"
4514         NUMS=$($CMD | wc -l)
4515         [ $NUMS -eq $EXPECTED ] ||
4516                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4517 }
4518 run_test 56l "check lfs find -type b ============================="
4519
4520 test_56m() {
4521         TDIR=$DIR/${tdir}g
4522         setup_56_special $NUMFILES $NUMDIRS
4523
4524         EXPECTED=$((NUMDIRS + NUMFILES))
4525         CMD="$LFIND -type c $TDIR"
4526         NUMS=$($CMD | wc -l)
4527         [ $NUMS -eq $EXPECTED ] ||
4528                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4529 }
4530 run_test 56m "check lfs find -type c ============================="
4531
4532 test_56n() {
4533         TDIR=$DIR/${tdir}g
4534         setup_56_special $NUMFILES $NUMDIRS
4535
4536         EXPECTED=$((NUMDIRS + NUMFILES))
4537         CMD="$LFIND -type l $TDIR"
4538         NUMS=$($CMD | wc -l)
4539         [ $NUMS -eq $EXPECTED ] ||
4540                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4541 }
4542 run_test 56n "check lfs find -type l ============================="
4543
4544 test_56o() {
4545         TDIR=$DIR/${tdir}o
4546         setup_56 $NUMFILES $NUMDIRS
4547         utime $TDIR/file1 > /dev/null || error "utime (1)"
4548         utime $TDIR/file2 > /dev/null || error "utime (2)"
4549         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4550         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4551         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4552         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4553
4554         EXPECTED=4
4555         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4556         [ $NUMS -eq $EXPECTED ] || \
4557                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4558
4559         EXPECTED=12
4560         CMD="$LFIND -mtime 0 $TDIR"
4561         NUMS=$($CMD | wc -l)
4562         [ $NUMS -eq $EXPECTED ] ||
4563                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4564 }
4565 run_test 56o "check lfs find -mtime for old files =========================="
4566
4567 test_56p() {
4568         [ $RUNAS_ID -eq $UID ] &&
4569                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4570
4571         TDIR=$DIR/${tdir}p
4572         setup_56 $NUMFILES $NUMDIRS
4573
4574         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4575         EXPECTED=$NUMFILES
4576         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4577         NUMS=$($CMD | wc -l)
4578         [ $NUMS -eq $EXPECTED ] || \
4579                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4580
4581         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4582         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4583         NUMS=$($CMD | wc -l)
4584         [ $NUMS -eq $EXPECTED ] || \
4585                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4586 }
4587 run_test 56p "check lfs find -uid and ! -uid ==============================="
4588
4589 test_56q() {
4590         [ $RUNAS_ID -eq $UID ] &&
4591                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4592
4593         TDIR=$DIR/${tdir}q
4594         setup_56 $NUMFILES $NUMDIRS
4595
4596         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4597
4598         EXPECTED=$NUMFILES
4599         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4600         NUMS=$($CMD | wc -l)
4601         [ $NUMS -eq $EXPECTED ] ||
4602                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4603
4604         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4605         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4606         NUMS=$($CMD | wc -l)
4607         [ $NUMS -eq $EXPECTED ] ||
4608                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4609 }
4610 run_test 56q "check lfs find -gid and ! -gid ==============================="
4611
4612 test_56r() {
4613         TDIR=$DIR/${tdir}r
4614         setup_56 $NUMFILES $NUMDIRS
4615
4616         EXPECTED=12
4617         CMD="$LFIND -size 0 -type f $TDIR"
4618         NUMS=$($CMD | wc -l)
4619         [ $NUMS -eq $EXPECTED ] ||
4620                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4621         EXPECTED=0
4622         CMD="$LFIND ! -size 0 -type f $TDIR"
4623         NUMS=$($CMD | wc -l)
4624         [ $NUMS -eq $EXPECTED ] ||
4625                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4626         echo "test" > $TDIR/$tfile
4627         echo "test2" > $TDIR/$tfile.2 && sync
4628         EXPECTED=1
4629         CMD="$LFIND -size 5 -type f $TDIR"
4630         NUMS=$($CMD | wc -l)
4631         [ $NUMS -eq $EXPECTED ] ||
4632                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4633         EXPECTED=1
4634         CMD="$LFIND -size +5 -type f $TDIR"
4635         NUMS=$($CMD | wc -l)
4636         [ $NUMS -eq $EXPECTED ] ||
4637                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4638         EXPECTED=2
4639         CMD="$LFIND -size +0 -type f $TDIR"
4640         NUMS=$($CMD | wc -l)
4641         [ $NUMS -eq $EXPECTED ] ||
4642                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4643         EXPECTED=2
4644         CMD="$LFIND ! -size -5 -type f $TDIR"
4645         NUMS=$($CMD | wc -l)
4646         [ $NUMS -eq $EXPECTED ] ||
4647                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4648         EXPECTED=12
4649         CMD="$LFIND -size -5 -type f $TDIR"
4650         NUMS=$($CMD | wc -l)
4651         [ $NUMS -eq $EXPECTED ] ||
4652                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4653 }
4654 run_test 56r "check lfs find -size works =========================="
4655
4656 test_56s() { # LU-611
4657         TDIR=$DIR/${tdir}s
4658         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4659
4660         if [[ $OSTCOUNT -gt 1 ]]; then
4661                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4662                 ONESTRIPE=4
4663                 EXTRA=4
4664         else
4665                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4666                 EXTRA=0
4667         fi
4668
4669         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4670         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4671         NUMS=$($CMD | wc -l)
4672         [ $NUMS -eq $EXPECTED ] || {
4673                 $GETSTRIPE -R $TDIR
4674                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4675         }
4676
4677         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4678         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4679         NUMS=$($CMD | wc -l)
4680         [ $NUMS -eq $EXPECTED ] || {
4681                 $GETSTRIPE -R $TDIR
4682                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4683         }
4684
4685         EXPECTED=$ONESTRIPE
4686         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4687         NUMS=$($CMD | wc -l)
4688         [ $NUMS -eq $EXPECTED ] || {
4689                 $GETSTRIPE -R $TDIR
4690                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4691         }
4692
4693         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4694         NUMS=$($CMD | wc -l)
4695         [ $NUMS -eq $EXPECTED ] || {
4696                 $GETSTRIPE -R $TDIR
4697                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4698         }
4699
4700         EXPECTED=0
4701         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4702         NUMS=$($CMD | wc -l)
4703         [ $NUMS -eq $EXPECTED ] || {
4704                 $GETSTRIPE -R $TDIR
4705                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4706         }
4707 }
4708 run_test 56s "check lfs find -stripe-count works"
4709
4710 test_56t() { # LU-611
4711         TDIR=$DIR/${tdir}t
4712         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4713
4714         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4715
4716         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4717         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4718         NUMS=$($CMD | wc -l)
4719         [ $NUMS -eq $EXPECTED ] ||
4720                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4721
4722         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4723         NUMS=$($CMD | wc -l)
4724         [ $NUMS -eq $EXPECTED ] ||
4725                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4726
4727         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4728         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4729         NUMS=$($CMD | wc -l)
4730         [ $NUMS -eq $EXPECTED ] ||
4731                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4732
4733         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4734         NUMS=$($CMD | wc -l)
4735         [ $NUMS -eq $EXPECTED ] ||
4736                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4737
4738         EXPECTED=4
4739         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4740         NUMS=$($CMD | wc -l)
4741         [ $NUMS -eq $EXPECTED ] ||
4742                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4743
4744         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4745         NUMS=$($CMD | wc -l)
4746         [ $NUMS -eq $EXPECTED ] ||
4747                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4748
4749         EXPECTED=0
4750         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4751         NUMS=$($CMD | wc -l)
4752         [ $NUMS -eq $EXPECTED ] ||
4753                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4754 }
4755 run_test 56t "check lfs find -stripe-size works"
4756
4757 test_56u() { # LU-611
4758         TDIR=$DIR/${tdir}u
4759         setup_56 $NUMFILES $NUMDIRS "-i 0"
4760
4761         if [[ $OSTCOUNT -gt 1 ]]; then
4762                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4763                 ONESTRIPE=4
4764         else
4765                 ONESTRIPE=0
4766         fi
4767
4768         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4769         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4770         NUMS=$($CMD | wc -l)
4771         [ $NUMS -eq $EXPECTED ] ||
4772                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4773
4774         EXPECTED=$ONESTRIPE
4775         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4776         NUMS=$($CMD | wc -l)
4777         [ $NUMS -eq $EXPECTED ] ||
4778                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4779
4780         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4781         NUMS=$($CMD | wc -l)
4782         [ $NUMS -eq $EXPECTED ] ||
4783                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4784
4785         EXPECTED=0
4786         # This should produce an error and not return any files
4787         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4788         NUMS=$($CMD 2>/dev/null | wc -l)
4789         [ $NUMS -eq $EXPECTED ] ||
4790                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4791
4792         if [[ $OSTCOUNT -gt 1 ]]; then
4793                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4794                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4795                 NUMS=$($CMD | wc -l)
4796                 [ $NUMS -eq $EXPECTED ] ||
4797                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4798         fi
4799 }
4800 run_test 56u "check lfs find -stripe-index works"
4801
4802 test_56v() {
4803     local MDT_IDX=0
4804
4805     TDIR=$DIR/${tdir}v
4806     rm -rf $TDIR
4807     setup_56 $NUMFILES $NUMDIRS
4808
4809     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4810     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4811
4812     for file in $($LFIND -mdt $UUID $TDIR); do
4813         file_mdt_idx=$($GETSTRIPE -M $file)
4814         [ $file_mdt_idx -eq $MDT_IDX ] ||
4815             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4816     done
4817 }
4818 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4819
4820 test_56w() {
4821         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
4822                 return
4823         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4824         TDIR=$DIR/${tdir}w
4825
4826     rm -rf $TDIR || error "remove $TDIR failed"
4827     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4828
4829     local stripe_size
4830     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4831         error "$GETSTRIPE -S -d $TDIR failed"
4832     stripe_size=${stripe_size%% *}
4833
4834     local file_size=$((stripe_size * OSTCOUNT))
4835     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4836     local required_space=$((file_num * file_size))
4837     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4838     [[ $free_space -le $((required_space / 1024)) ]] &&
4839         skip_env "need at least $required_space bytes free space," \
4840                  "have $free_space kbytes" && return
4841
4842     local dd_bs=65536
4843     local dd_count=$((file_size / dd_bs))
4844
4845     # write data into the files
4846     local i
4847     local j
4848     local file
4849     for i in $(seq 1 $NUMFILES); do
4850         file=$TDIR/file$i
4851         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4852             error "write data into $file failed"
4853     done
4854     for i in $(seq 1 $NUMDIRS); do
4855         for j in $(seq 1 $NUMFILES); do
4856             file=$TDIR/dir$i/file$j
4857             yes | dd bs=$dd_bs count=$dd_count of=$file \
4858                 >/dev/null 2>&1 ||
4859                 error "write data into $file failed"
4860         done
4861     done
4862
4863     local expected=-1
4864     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4865
4866     # lfs_migrate file
4867     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4868     echo "$cmd"
4869     eval $cmd || error "$cmd failed"
4870
4871     check_stripe_count $TDIR/file1 $expected
4872
4873         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
4874         then
4875                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
4876                 # OST 1 if it is on OST 0. This file is small enough to
4877                 # be on only one stripe.
4878                 file=$TDIR/migr_1_ost
4879                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
4880                         error "write data into $file failed"
4881                 local obdidx=$($LFS getstripe -i $file)
4882                 local oldmd5=$(md5sum $file)
4883                 local newobdidx=0
4884                 [[ $obdidx -eq 0 ]] && newobdidx=1
4885                 cmd="$LFS migrate -i $newobdidx $file"
4886                 echo $cmd
4887                 eval $cmd || error "$cmd failed"
4888                 local realobdix=$($LFS getstripe -i $file)
4889                 local newmd5=$(md5sum $file)
4890                 [[ $newobdidx -ne $realobdix ]] &&
4891                         error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
4892                 [[ "$oldmd5" != "$newmd5" ]] &&
4893                         error "md5sum differ: $oldmd5, $newmd5"
4894         fi
4895
4896     # lfs_migrate dir
4897     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4898     echo "$cmd"
4899     eval $cmd || error "$cmd failed"
4900
4901     for j in $(seq 1 $NUMFILES); do
4902         check_stripe_count $TDIR/dir1/file$j $expected
4903     done
4904
4905     # lfs_migrate works with lfs find
4906     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4907          $LFS_MIGRATE -y -c $expected"
4908     echo "$cmd"
4909     eval $cmd || error "$cmd failed"
4910
4911     for i in $(seq 2 $NUMFILES); do
4912         check_stripe_count $TDIR/file$i $expected
4913     done
4914     for i in $(seq 2 $NUMDIRS); do
4915         for j in $(seq 1 $NUMFILES); do
4916             check_stripe_count $TDIR/dir$i/file$j $expected
4917         done
4918     done
4919 }
4920 run_test 56w "check lfs_migrate -c stripe_count works"
4921
4922 test_56x() {
4923         check_swap_layouts_support && return 0
4924         [[ $OSTCOUNT -lt 2 ]] &&
4925                 skip_env "need 2 OST, skipping test" && return
4926
4927         local dir0=$DIR/$tdir/$testnum
4928         mkdir -p $dir0 || error "creating dir $dir0"
4929
4930         local ref1=/etc/passwd
4931         local file1=$dir0/file1
4932
4933         $SETSTRIPE -c 2 $file1
4934         cp $ref1 $file1
4935         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4936         stripe=$($GETSTRIPE -c $file1)
4937         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4938         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4939
4940         # clean up
4941         rm -f $file1
4942 }
4943 run_test 56x "lfs migration support"
4944
4945 test_56y() {
4946         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4947                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
4948                 return
4949
4950         local res=""
4951         local dir0=$DIR/$tdir/$testnum
4952         mkdir -p $dir0 || error "creating dir $dir0"
4953         local f1=$dir0/file1
4954         local f2=$dir0/file2
4955
4956         touch $f1 || error "creating std file $f1"
4957         $MULTIOP $f2 H2c || error "creating released file $f2"
4958
4959         # a directory can be raid0, so ask only for files
4960         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4961         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4962
4963         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4964         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4965
4966         # only files can be released, so no need to force file search
4967         res=$($LFIND $dir0 -L released)
4968         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4969
4970         res=$($LFIND $dir0 \! -L released)
4971         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4972
4973 }
4974 run_test 56y "lfs find -L raid0|released"
4975
4976 test_56z() { # LU-4824
4977         # This checks to make sure 'lfs find' continues after errors
4978         # There are two classes of errors that should be caught:
4979         # - If multiple paths are provided, all should be searched even if one
4980         #   errors out
4981         # - If errors are encountered during the search, it should not terminate
4982         #   early
4983         local i
4984         test_mkdir $DIR/$tdir
4985         for i in d{0..9}; do
4986                 test_mkdir $DIR/$tdir/$i
4987         done
4988         touch $DIR/$tdir/d{0..9}/$tfile
4989         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
4990                 error "$LFS find did not return an error"
4991         # Make a directory unsearchable. This should NOT be the last entry in
4992         # directory order.  Arbitrarily pick the 6th entry
4993         chmod 700 $($LFS find $DIR/$tdir -type d | sed '6!d')
4994         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
4995         # The user should be able to see 10 directories and 9 files
4996         [ $count == 19 ] || error "$LFS find did not continue after error"
4997 }
4998 run_test 56z "lfs find should continue after an error"
4999
5000 test_56aa() { # LU-5937
5001         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5002
5003         mkdir $DIR/$tdir
5004         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
5005
5006         createmany -o $DIR/$tdir/striped_dir/${tfile}- 1024
5007         local dirs=$(lfs find --size +8k $DIR/$tdir/)
5008
5009         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5010 }
5011 run_test 56aa "lfs find --size under striped dir"
5012
5013 test_57a() {
5014         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5015         # note test will not do anything if MDS is not local
5016         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5017                 skip "Only applicable to ldiskfs-based MDTs"
5018                 return
5019         fi
5020
5021         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5022         local MNTDEV="osd*.*MDT*.mntdev"
5023         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
5024         [ -z "$DEV" ] && error "can't access $MNTDEV"
5025         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
5026                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
5027                         error "can't access $DEV"
5028                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
5029                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
5030                 rm $TMP/t57a.dump
5031         done
5032 }
5033 run_test 57a "verify MDS filesystem created with large inodes =="
5034
5035 test_57b() {
5036         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5037         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5038                 skip "Only applicable to ldiskfs-based MDTs"
5039                 return
5040         fi
5041
5042         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5043         local dir=$DIR/$tdir
5044
5045         local FILECOUNT=100
5046         local FILE1=$dir/f1
5047         local FILEN=$dir/f$FILECOUNT
5048
5049         rm -rf $dir || error "removing $dir"
5050         test_mkdir -p -c1 $dir || error "creating $dir"
5051         local mdtidx=$($LFS getstripe -M $dir)
5052         local mdtname=MDT$(printf %04x $mdtidx)
5053         local facet=mds$((mdtidx + 1))
5054
5055         echo "mcreating $FILECOUNT files"
5056         createmany -m $dir/f 1 $FILECOUNT || \
5057                 error "creating files in $dir"
5058
5059         # verify that files do not have EAs yet
5060         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5061         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5062
5063         sync
5064         sleep 1
5065         df $dir  #make sure we get new statfs data
5066         local MDSFREE=$(do_facet $facet \
5067                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5068         local MDCFREE=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5069         echo "opening files to create objects/EAs"
5070         local FILE
5071         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5072                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5073         done
5074
5075         # verify that files have EAs now
5076         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5077         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5078
5079         sleep 1  #make sure we get new statfs data
5080         df $dir
5081         local MDSFREE2=$(do_facet $facet \
5082                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5083         local MDCFREE2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5084         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5085                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5086                         error "MDC before $MDCFREE != after $MDCFREE2"
5087                 else
5088                         echo "MDC before $MDCFREE != after $MDCFREE2"
5089                         echo "unable to confirm if MDS has large inodes"
5090                 fi
5091         fi
5092         rm -rf $dir
5093 }
5094 run_test 57b "default LOV EAs are stored inside large inodes ==="
5095
5096 test_58() {
5097         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5098         [ -z "$(which wiretest 2>/dev/null)" ] &&
5099                         skip_env "could not find wiretest" && return
5100         wiretest
5101 }
5102 run_test 58 "verify cross-platform wire constants =============="
5103
5104 test_59() {
5105         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5106         echo "touch 130 files"
5107         createmany -o $DIR/f59- 130
5108         echo "rm 130 files"
5109         unlinkmany $DIR/f59- 130
5110         sync
5111         # wait for commitment of removal
5112         wait_delete_completed
5113 }
5114 run_test 59 "verify cancellation of llog records async ========="
5115
5116 TEST60_HEAD="test_60 run $RANDOM"
5117 test_60a() {
5118         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5119         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5120         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5121                 skip_env "missing subtest run-llog.sh" && return
5122         log "$TEST60_HEAD - from kernel mode"
5123         do_facet mgs sh run-llog.sh
5124 }
5125 run_test 60a "llog sanity tests run from kernel module =========="
5126
5127 test_60b() { # bug 6411
5128         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5129         dmesg > $DIR/$tfile
5130         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
5131                                  /llog.test/ {
5132                                          if (marker)
5133                                                  from_marker++
5134                                          from_begin++
5135                                  }
5136                                  END {
5137                                          if (marker)
5138                                                  print from_marker
5139                                          else
5140                                                  print from_begin
5141                                  }"`
5142         [[ $LLOG_COUNT -gt 50 ]] &&
5143                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5144 }
5145 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5146
5147 test_60c() {
5148         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5149         echo "create 5000 files"
5150         createmany -o $DIR/f60c- 5000
5151 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5152         lctl set_param fail_loc=0x80000137
5153         unlinkmany $DIR/f60c- 5000
5154         lctl set_param fail_loc=0
5155 }
5156 run_test 60c "unlink file when mds full"
5157
5158 test_60d() {
5159         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5160         SAVEPRINTK=$(lctl get_param -n printk)
5161
5162         # verify "lctl mark" is even working"
5163         MESSAGE="test message ID $RANDOM $$"
5164         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5165         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5166
5167         lctl set_param printk=0 || error "set lnet.printk failed"
5168         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5169         MESSAGE="new test message ID $RANDOM $$"
5170         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5171         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5172         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5173
5174         lctl set_param -n printk="$SAVEPRINTK"
5175 }
5176 run_test 60d "test printk console message masking"
5177
5178 test_61() {
5179         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5180         f="$DIR/f61"
5181         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5182         cancel_lru_locks osc
5183         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5184         sync
5185 }
5186 run_test 61 "mmap() writes don't make sync hang ================"
5187
5188 # bug 2330 - insufficient obd_match error checking causes LBUG
5189 test_62() {
5190         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5191         f="$DIR/f62"
5192         echo foo > $f
5193         cancel_lru_locks osc
5194         lctl set_param fail_loc=0x405
5195         cat $f && error "cat succeeded, expect -EIO"
5196         lctl set_param fail_loc=0
5197 }
5198 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5199 # match every page all of the time.
5200 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5201
5202 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5203 # Though this test is irrelevant anymore, it helped to reveal some
5204 # other grant bugs (LU-4482), let's keep it.
5205 test_63a() {   # was test_63
5206         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5207         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5208         for i in `seq 10` ; do
5209                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5210                 sleep 5
5211                 kill $!
5212                 sleep 1
5213         done
5214
5215         rm -f $DIR/f63 || true
5216 }
5217 run_test 63a "Verify oig_wait interruption does not crash ======="
5218
5219 # bug 2248 - async write errors didn't return to application on sync
5220 # bug 3677 - async write errors left page locked
5221 test_63b() {
5222         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5223         debugsave
5224         lctl set_param debug=-1
5225
5226         # ensure we have a grant to do async writes
5227         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5228         rm $DIR/$tfile
5229
5230         sync    # sync lest earlier test intercept the fail_loc
5231
5232         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5233         lctl set_param fail_loc=0x80000406
5234         $MULTIOP $DIR/$tfile Owy && \
5235                 error "sync didn't return ENOMEM"
5236         sync; sleep 2; sync     # do a real sync this time to flush page
5237         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5238                 error "locked page left in cache after async error" || true
5239         debugrestore
5240 }
5241 run_test 63b "async write errors should be returned to fsync ==="
5242
5243 test_64a () {
5244         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5245         df $DIR
5246         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5247 }
5248 run_test 64a "verify filter grant calculations (in kernel) ====="
5249
5250 test_64b () {
5251         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5252         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5253 }
5254 run_test 64b "check out-of-space detection on client ==========="
5255
5256 test_64c() {
5257         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5258 }
5259 run_test 64c "verify grant shrink ========================------"
5260
5261 # bug 1414 - set/get directories' stripe info
5262 test_65a() {
5263         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5264         test_mkdir -p $DIR/$tdir
5265         touch $DIR/$tdir/f1
5266         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5267 }
5268 run_test 65a "directory with no stripe info ===================="
5269
5270 test_65b() {
5271         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5272         test_mkdir -p $DIR/$tdir
5273         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5274                                                 error "setstripe"
5275         touch $DIR/$tdir/f2
5276         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5277 }
5278 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
5279
5280 test_65c() {
5281         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5282         if [[ $OSTCOUNT -gt 1 ]]; then
5283                 test_mkdir -p $DIR/$tdir
5284                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5285                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5286                 touch $DIR/$tdir/f3
5287                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5288         fi
5289 }
5290 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
5291
5292 test_65d() {
5293         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5294         test_mkdir -p $DIR/$tdir
5295         if [[ $STRIPECOUNT -le 0 ]]; then
5296                 sc=1
5297         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5298 #LOV_MAX_STRIPE_COUNT is 2000
5299                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5300         else
5301                 sc=$(($STRIPECOUNT - 1))
5302         fi
5303         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5304         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5305         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5306                 error "lverify failed"
5307 }
5308 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
5309
5310 test_65e() {
5311         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5312         test_mkdir -p $DIR/$tdir
5313
5314         $SETSTRIPE $DIR/$tdir || error "setstripe"
5315         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5316                                         error "no stripe info failed"
5317         touch $DIR/$tdir/f6
5318         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5319 }
5320 run_test 65e "directory setstripe defaults ======================="
5321
5322 test_65f() {
5323         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5324         test_mkdir -p $DIR/${tdir}f
5325         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5326 }
5327 run_test 65f "dir setstripe permission (should return error) ==="
5328
5329 test_65g() {
5330         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5331         test_mkdir -p $DIR/$tdir
5332         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5333                                                         error "setstripe"
5334         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5335         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5336                 error "delete default stripe failed"
5337 }
5338 run_test 65g "directory setstripe -d ==========================="
5339
5340 test_65h() {
5341         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5342         test_mkdir -p $DIR/$tdir
5343         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5344                                                         error "setstripe"
5345         test_mkdir -p $DIR/$tdir/dd1
5346         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5347                 error "stripe info inherit failed"
5348 }
5349 run_test 65h "directory stripe info inherit ===================="
5350
5351 test_65i() { # bug6367
5352         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5353         $SETSTRIPE -S 65536 -c -1 $MOUNT
5354 }
5355 run_test 65i "set non-default striping on root directory (bug 6367)="
5356
5357 test_65ia() { # bug12836
5358         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5359         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5360 }
5361 run_test 65ia "getstripe on -1 default directory striping"
5362
5363 test_65ib() { # bug12836
5364         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5365         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5366 }
5367 run_test 65ib "getstripe -v on -1 default directory striping"
5368
5369 test_65ic() { # bug12836
5370         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5371         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5372 }
5373 run_test 65ic "new find on -1 default directory striping"
5374
5375 test_65j() { # bug6367
5376         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5377         sync; sleep 1
5378         # if we aren't already remounting for each test, do so for this test
5379         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5380                 cleanup || error "failed to unmount"
5381                 setup
5382         fi
5383         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5384 }
5385 run_test 65j "set default striping on root directory (bug 6367)="
5386
5387 test_65k() { # bug11679
5388         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5389         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5390         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5391
5392     echo "Check OST status: "
5393     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5394               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5395
5396     for OSC in $MDS_OSCS; do
5397         echo $OSC "is activate"
5398         do_facet $SINGLEMDS lctl --device %$OSC activate
5399     done
5400
5401     mkdir -p $DIR/$tdir
5402     for INACTIVE_OSC in $MDS_OSCS; do
5403         echo "Deactivate: " $INACTIVE_OSC
5404         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5405         for STRIPE_OSC in $MDS_OSCS; do
5406             OST=`osc_to_ost $STRIPE_OSC`
5407             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5408                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5409
5410             [ -f $DIR/$tdir/$IDX ] && continue
5411             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5412             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5413             RC=$?
5414             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5415         done
5416         rm -f $DIR/$tdir/*
5417         echo $INACTIVE_OSC "is Activate."
5418         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5419     done
5420 }
5421 run_test 65k "validate manual striping works properly with deactivated OSCs"
5422
5423 test_65l() { # bug 12836
5424         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5425         test_mkdir -p $DIR/$tdir/test_dir
5426         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5427         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5428 }
5429 run_test 65l "lfs find on -1 stripe dir ========================"
5430
5431 # bug 2543 - update blocks count on client
5432 test_66() {
5433         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5434         COUNT=${COUNT:-8}
5435         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5436         sync; sync_all_data; sync; sync_all_data
5437         cancel_lru_locks osc
5438         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5439         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5440 }
5441 run_test 66 "update inode blocks count on client ==============="
5442
5443 LLOOP=
5444 LLITELOOPLOAD=
5445 cleanup_68() {
5446         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5447         trap 0
5448         if [ ! -z "$LLOOP" ]; then
5449                 if swapon -s | grep -q $LLOOP; then
5450                         swapoff $LLOOP || error "swapoff failed"
5451                 fi
5452
5453                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5454                 rm -f $LLOOP
5455                 unset LLOOP
5456         fi
5457         if [ ! -z "$LLITELOOPLOAD" ]; then
5458                 rmmod llite_lloop
5459                 unset LLITELOOPLOAD
5460         fi
5461         rm -f $DIR/f68*
5462 }
5463
5464 meminfo() {
5465         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5466 }
5467
5468 swap_used() {
5469         swapon -s | awk '($1 == "'$1'") { print $4 }'
5470 }
5471
5472 # test case for lloop driver, basic function
5473 test_68a() {
5474         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5475         [ "$UID" != 0 ] && skip_env "must run as root" && return
5476         llite_lloop_enabled || \
5477                 { skip_env "llite_lloop module disabled" && return; }
5478
5479         trap cleanup_68 EXIT
5480
5481         if ! module_loaded llite_lloop; then
5482                 if load_module llite/llite_lloop; then
5483                         LLITELOOPLOAD=yes
5484                 else
5485                         skip_env "can't find module llite_lloop"
5486                         return
5487                 fi
5488         fi
5489
5490         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5491         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5492         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5493
5494         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5495         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5496
5497         cleanup_68
5498 }
5499 run_test 68a "lloop driver - basic test ========================"
5500
5501 # excercise swapping to lustre by adding a high priority swapfile entry
5502 # and then consuming memory until it is used.
5503 test_68b() {  # was test_68
5504         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5505         [ "$UID" != 0 ] && skip_env "must run as root" && return
5506         lctl get_param -n devices | grep -q obdfilter && \
5507                 skip "local OST" && return
5508
5509         grep -q llite_lloop /proc/modules
5510         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5511
5512         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5513                 skip "can't reliably test swap with TCP" && return
5514
5515         MEMTOTAL=`meminfo MemTotal`
5516         NR_BLOCKS=$((MEMTOTAL>>8))
5517         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5518
5519         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5520         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5521         mkswap $DIR/f68b
5522
5523         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5524
5525         trap cleanup_68 EXIT
5526
5527         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5528
5529         echo "before: `swapon -s | grep $LLOOP`"
5530         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5531         echo "after: `swapon -s | grep $LLOOP`"
5532         SWAPUSED=`swap_used $LLOOP`
5533
5534         cleanup_68
5535
5536         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5537 }
5538 run_test 68b "support swapping to Lustre ========================"
5539
5540 # bug5265, obdfilter oa2dentry return -ENOENT
5541 # #define OBD_FAIL_OST_ENOENT 0x217
5542 test_69() {
5543         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5544         remote_ost_nodsh && skip "remote OST with nodsh" && return
5545
5546         f="$DIR/$tfile"
5547         $SETSTRIPE -c 1 -i 0 $f
5548
5549         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5550
5551         do_facet ost1 lctl set_param fail_loc=0x217
5552         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5553         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5554
5555         do_facet ost1 lctl set_param fail_loc=0
5556         $DIRECTIO write $f 0 2 || error "write error"
5557
5558         cancel_lru_locks osc
5559         $DIRECTIO read $f 0 1 || error "read error"
5560
5561         do_facet ost1 lctl set_param fail_loc=0x217
5562         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5563
5564         do_facet ost1 lctl set_param fail_loc=0
5565         rm -f $f
5566 }
5567 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5568
5569 test_71() {
5570     test_mkdir -p $DIR/$tdir
5571     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5572 }
5573 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5574
5575 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5576         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5577         [ "$RUNAS_ID" = "$UID" ] &&
5578                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5579
5580         # Check that testing environment is properly set up. Skip if not
5581         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5582                 skip_env "User $RUNAS_ID does not exist - skipping"
5583                 return 0
5584         }
5585         touch $DIR/$tfile
5586         chmod 777 $DIR/$tfile
5587         chmod ug+s $DIR/$tfile
5588         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5589                 error "$RUNAS dd $DIR/$tfile failed"
5590         # See if we are still setuid/sgid
5591         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5592                 error "S/gid is not dropped on write"
5593         # Now test that MDS is updated too
5594         cancel_lru_locks mdc
5595         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5596                 error "S/gid is not dropped on MDS"
5597         rm -f $DIR/$tfile
5598 }
5599 run_test 72a "Test that remove suid works properly (bug5695) ===="
5600
5601 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5602         local perm
5603
5604         [ "$RUNAS_ID" = "$UID" ] && \
5605                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5606         [ "$RUNAS_ID" -eq 0 ] && \
5607                 skip_env "RUNAS_ID = 0 -- skipping" && return
5608
5609         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5610         # Check that testing environment is properly set up. Skip if not
5611         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5612                 skip_env "User $RUNAS_ID does not exist - skipping"
5613                 return 0
5614         }
5615         touch $DIR/${tfile}-f{g,u}
5616         test_mkdir $DIR/${tfile}-dg
5617         test_mkdir $DIR/${tfile}-du
5618         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5619         chmod g+s $DIR/${tfile}-{f,d}g
5620         chmod u+s $DIR/${tfile}-{f,d}u
5621         for perm in 777 2777 4777; do
5622                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5623                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5624                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5625                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5626         done
5627         true
5628 }
5629 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5630
5631 # bug 3462 - multiple simultaneous MDC requests
5632 test_73() {
5633         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5634         test_mkdir $DIR/d73-1
5635         test_mkdir $DIR/d73-2
5636         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5637         pid1=$!
5638
5639         lctl set_param fail_loc=0x80000129
5640         $MULTIOP $DIR/d73-1/f73-2 Oc &
5641         sleep 1
5642         lctl set_param fail_loc=0
5643
5644         $MULTIOP $DIR/d73-2/f73-3 Oc &
5645         pid3=$!
5646
5647         kill -USR1 $pid1
5648         wait $pid1 || return 1
5649
5650         sleep 25
5651
5652         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5653         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5654         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5655
5656         rm -rf $DIR/d73-*
5657 }
5658 run_test 73 "multiple MDC requests (should not deadlock)"
5659
5660 test_74a() { # bug 6149, 6184
5661         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5662         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5663         #
5664         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5665         # will spin in a tight reconnection loop
5666         touch $DIR/f74a
5667         $LCTL set_param fail_loc=0x8000030e
5668         # get any lock that won't be difficult - lookup works.
5669         ls $DIR/f74a
5670         $LCTL set_param fail_loc=0
5671         rm -f $DIR/f74a
5672         true
5673 }
5674 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5675
5676 test_74b() { # bug 13310
5677         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5678         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5679         #
5680         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5681         # will spin in a tight reconnection loop
5682         $LCTL set_param fail_loc=0x8000030e
5683         # get a "difficult" lock
5684         touch $DIR/f74b
5685         $LCTL set_param fail_loc=0
5686         rm -f $DIR/f74b
5687         true
5688 }
5689 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5690
5691 test_74c() {
5692         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5693         #define OBD_FAIL_LDLM_NEW_LOCK
5694         $LCTL set_param fail_loc=0x319
5695         touch $DIR/$tfile && error "touch successful"
5696         $LCTL set_param fail_loc=0
5697         true
5698 }
5699 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5700
5701 num_inodes() {
5702         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5703 }
5704
5705 get_inode_slab_tunables() {
5706         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5707 }
5708
5709 set_inode_slab_tunables() {
5710         echo "lustre_inode_cache $1" > /proc/slabinfo
5711 }
5712
5713 test_76() { # Now for bug 20433, added originally in bug 1443
5714         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5715         local SLAB_SETTINGS=`get_inode_slab_tunables`
5716         local CPUS=`getconf _NPROCESSORS_ONLN`
5717         # we cannot set limit below 1 which means 1 inode in each
5718         # per-cpu cache is still allowed
5719         set_inode_slab_tunables "1 1 0"
5720         cancel_lru_locks osc
5721         BEFORE_INODES=$(num_inodes)
5722         echo "before inodes: $BEFORE_INODES"
5723         local COUNT=1000
5724         [ "$SLOW" = "no" ] && COUNT=100
5725         for i in $(seq $COUNT); do
5726                 touch $DIR/$tfile
5727                 rm -f $DIR/$tfile
5728         done
5729         cancel_lru_locks osc
5730         AFTER_INODES=$(num_inodes)
5731         echo "after inodes: $AFTER_INODES"
5732         local wait=0
5733         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5734                 sleep 2
5735                 AFTER_INODES=$(num_inodes)
5736                 wait=$((wait+2))
5737                 echo "wait $wait seconds inodes: $AFTER_INODES"
5738                 if [ $wait -gt 30 ]; then
5739                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5740                 fi
5741         done
5742         set_inode_slab_tunables "$SLAB_SETTINGS"
5743 }
5744 run_test 76 "confirm clients recycle inodes properly ===="
5745
5746
5747 export ORIG_CSUM=""
5748 set_checksums()
5749 {
5750         # Note: in sptlrpc modes which enable its own bulk checksum, the
5751         # original crc32_le bulk checksum will be automatically disabled,
5752         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5753         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5754         # In this case set_checksums() will not be no-op, because sptlrpc
5755         # bulk checksum will be enabled all through the test.
5756
5757         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5758         lctl set_param -n osc.*.checksums $1
5759         return 0
5760 }
5761
5762 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5763                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5764 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5765 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5766 set_checksum_type()
5767 {
5768         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5769         log "set checksum type to $1"
5770         return 0
5771 }
5772 F77_TMP=$TMP/f77-temp
5773 F77SZ=8
5774 setup_f77() {
5775         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5776                 error "error writing to $F77_TMP"
5777 }
5778
5779 test_77a() { # bug 10889
5780         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5781         $GSS && skip "could not run with gss" && return
5782         [ ! -f $F77_TMP ] && setup_f77
5783         set_checksums 1
5784         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5785         set_checksums 0
5786         rm -f $DIR/$tfile
5787 }
5788 run_test 77a "normal checksum read/write operation"
5789
5790 test_77b() { # bug 10889
5791         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5792         $GSS && skip "could not run with gss" && return
5793         [ ! -f $F77_TMP ] && setup_f77
5794         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5795         $LCTL set_param fail_loc=0x80000409
5796         set_checksums 1
5797
5798         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5799                 error "dd error: $?"
5800         $LCTL set_param fail_loc=0
5801
5802         for algo in $CKSUM_TYPES; do
5803                 cancel_lru_locks osc
5804                 set_checksum_type $algo
5805                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5806                 $LCTL set_param fail_loc=0x80000408
5807                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5808                 $LCTL set_param fail_loc=0
5809         done
5810         set_checksums 0
5811         set_checksum_type $ORIG_CSUM_TYPE
5812         rm -f $DIR/$tfile
5813 }
5814 run_test 77b "checksum error on client write, read"
5815
5816 test_77d() { # bug 10889
5817         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5818         $GSS && skip "could not run with gss" && return
5819         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5820         $LCTL set_param fail_loc=0x80000409
5821         set_checksums 1
5822         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5823                 error "direct write: rc=$?"
5824         $LCTL set_param fail_loc=0
5825         set_checksums 0
5826
5827         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5828         $LCTL set_param fail_loc=0x80000408
5829         set_checksums 1
5830         cancel_lru_locks osc
5831         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5832                 error "direct read: rc=$?"
5833         $LCTL set_param fail_loc=0
5834         set_checksums 0
5835 }
5836 run_test 77d "checksum error on OST direct write, read"
5837
5838 test_77f() { # bug 10889
5839         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5840         $GSS && skip "could not run with gss" && return
5841         set_checksums 1
5842         for algo in $CKSUM_TYPES; do
5843                 cancel_lru_locks osc
5844                 set_checksum_type $algo
5845                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5846                 $LCTL set_param fail_loc=0x409
5847                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5848                         error "direct write succeeded"
5849                 $LCTL set_param fail_loc=0
5850         done
5851         set_checksum_type $ORIG_CSUM_TYPE
5852         set_checksums 0
5853 }
5854 run_test 77f "repeat checksum error on write (expect error)"
5855
5856 test_77g() { # bug 10889
5857         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5858         $GSS && skip "could not run with gss" && return
5859         remote_ost_nodsh && skip "remote OST with nodsh" && return
5860
5861         [ ! -f $F77_TMP ] && setup_f77
5862
5863         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5864         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5865         do_facet ost1 lctl set_param fail_loc=0x8000021a
5866         set_checksums 1
5867         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5868                 error "write error: rc=$?"
5869         do_facet ost1 lctl set_param fail_loc=0
5870         set_checksums 0
5871
5872         cancel_lru_locks osc
5873         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5874         do_facet ost1 lctl set_param fail_loc=0x8000021b
5875         set_checksums 1
5876         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5877         do_facet ost1 lctl set_param fail_loc=0
5878         set_checksums 0
5879 }
5880 run_test 77g "checksum error on OST write, read"
5881
5882 test_77i() { # bug 13805
5883         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5884         $GSS && skip "could not run with gss" && return
5885         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5886         lctl set_param fail_loc=0x40b
5887         remount_client $MOUNT
5888         lctl set_param fail_loc=0
5889         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5890                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5891                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5892                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5893         done
5894         remount_client $MOUNT
5895 }
5896 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5897
5898 test_77j() { # bug 13805
5899         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5900         $GSS && skip "could not run with gss" && return
5901         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5902         lctl set_param fail_loc=0x40c
5903         remount_client $MOUNT
5904         lctl set_param fail_loc=0
5905         sleep 2 # wait async osc connect to finish
5906         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5907                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5908                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5909                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5910         done
5911         remount_client $MOUNT
5912 }
5913 run_test 77j "client only supporting ADLER32"
5914
5915 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5916 rm -f $F77_TMP
5917 unset F77_TMP
5918
5919 test_78() { # bug 10901
5920         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5921         remote_ost || { skip_env "local OST" && return; }
5922
5923         NSEQ=5
5924         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5925         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5926         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5927         echo "MemTotal: $MEMTOTAL"
5928
5929         # reserve 256MB of memory for the kernel and other running processes,
5930         # and then take 1/2 of the remaining memory for the read/write buffers.
5931         if [ $MEMTOTAL -gt 512 ] ;then
5932                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5933         else
5934                 # for those poor memory-starved high-end clusters...
5935                 MEMTOTAL=$((MEMTOTAL / 2))
5936         fi
5937         echo "Mem to use for directio: $MEMTOTAL"
5938
5939         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
5940         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
5941         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
5942         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
5943                 head -n1)
5944         echo "Smallest OST: $SMALLESTOST"
5945         [[ $SMALLESTOST -lt 10240 ]] &&
5946                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5947
5948         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
5949                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5950
5951         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5952         echo "File size: $F78SIZE"
5953         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5954         for i in $(seq 1 $NSEQ); do
5955                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5956                 echo directIO rdwr round $i of $NSEQ
5957                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5958         done
5959
5960         rm -f $DIR/$tfile
5961 }
5962 run_test 78 "handle large O_DIRECT writes correctly ============"
5963
5964 test_79() { # bug 12743
5965         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5966         wait_delete_completed
5967
5968         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5969         BKFREE=$(calc_osc_kbytes kbytesfree)
5970         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5971
5972         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5973         DFTOTAL=`echo $STRING | cut -d, -f1`
5974         DFUSED=`echo $STRING  | cut -d, -f2`
5975         DFAVAIL=`echo $STRING | cut -d, -f3`
5976         DFFREE=$(($DFTOTAL - $DFUSED))
5977
5978         ALLOWANCE=$((64 * $OSTCOUNT))
5979
5980         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5981            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5982                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5983         fi
5984         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5985            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5986                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5987         fi
5988         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5989            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5990                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5991         fi
5992 }
5993 run_test 79 "df report consistency check ======================="
5994
5995 test_80() { # bug 10718
5996         remote_ost_nodsh && skip "remote OST with nodsh" && return
5997         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5998         # relax strong synchronous semantics for slow backends like ZFS
5999         local soc="obdfilter.*.sync_on_lock_cancel"
6000         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
6001         local hosts=
6002         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
6003                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
6004                           facet_active_host $host; done | sort -u)
6005                 do_nodes $hosts lctl set_param $soc=never
6006         fi
6007
6008         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
6009         sync; sleep 1; sync
6010         local BEFORE=`date +%s`
6011         cancel_lru_locks osc
6012         local AFTER=`date +%s`
6013         local DIFF=$((AFTER-BEFORE))
6014         if [ $DIFF -gt 1 ] ; then
6015                 error "elapsed for 1M@1T = $DIFF"
6016         fi
6017
6018         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
6019
6020         rm -f $DIR/$tfile
6021 }
6022 run_test 80 "Page eviction is equally fast at high offsets too  ===="
6023
6024 test_81a() { # LU-456
6025         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6026         remote_ost_nodsh && skip "remote OST with nodsh" && return
6027         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6028         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
6029         do_facet ost1 lctl set_param fail_loc=0x80000228
6030
6031         # write should trigger a retry and success
6032         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6033         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6034         RC=$?
6035         if [ $RC -ne 0 ] ; then
6036                 error "write should success, but failed for $RC"
6037         fi
6038 }
6039 run_test 81a "OST should retry write when get -ENOSPC ==============="
6040
6041 test_81b() { # LU-456
6042         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6043         remote_ost_nodsh && skip "remote OST with nodsh" && return
6044         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6045         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
6046         do_facet ost1 lctl set_param fail_loc=0x228
6047
6048         # write should retry several times and return -ENOSPC finally
6049         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6050         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6051         RC=$?
6052         ENOSPC=28
6053         if [ $RC -ne $ENOSPC ] ; then
6054                 error "dd should fail for -ENOSPC, but succeed."
6055         fi
6056 }
6057 run_test 81b "OST should return -ENOSPC when retry still fails ======="
6058
6059 test_82() { # LU-1031
6060         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
6061         local gid1=14091995
6062         local gid2=16022000
6063
6064         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
6065         local MULTIPID1=$!
6066         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
6067         local MULTIPID2=$!
6068         kill -USR1 $MULTIPID2
6069         sleep 2
6070         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6071                 error "First grouplock does not block second one"
6072         else
6073                 echo "Second grouplock blocks first one"
6074         fi
6075         kill -USR1 $MULTIPID1
6076         wait $MULTIPID1
6077         wait $MULTIPID2
6078 }
6079 run_test 82 "Basic grouplock test ==============================="
6080
6081 test_99a() {
6082         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6083                 return
6084         test_mkdir -p $DIR/d99cvsroot
6085         chown $RUNAS_ID $DIR/d99cvsroot
6086         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6087         cd $TMP
6088
6089         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6090         cd $oldPWD
6091 }
6092 run_test 99a "cvs init ========================================="
6093
6094 test_99b() {
6095         [ -z "$(which cvs 2>/dev/null)" ] &&
6096                 skip_env "could not find cvs" && return
6097         [ ! -d $DIR/d99cvsroot ] && test_99a
6098         cd /etc/init.d
6099         # some versions of cvs import exit(1) when asked to import links or
6100         # files they can't read.  ignore those files.
6101         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6102                         ! -perm +4 -printf '-I %f\n')
6103         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6104                 d99reposname vtag rtag
6105 }
6106 run_test 99b "cvs import ======================================="
6107
6108 test_99c() {
6109         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6110         [ ! -d $DIR/d99cvsroot ] && test_99b
6111         cd $DIR
6112         test_mkdir -p $DIR/d99reposname
6113         chown $RUNAS_ID $DIR/d99reposname
6114         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6115 }
6116 run_test 99c "cvs checkout ====================================="
6117
6118 test_99d() {
6119         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6120         [ ! -d $DIR/d99cvsroot ] && test_99c
6121         cd $DIR/d99reposname
6122         $RUNAS touch foo99
6123         $RUNAS cvs add -m 'addmsg' foo99
6124 }
6125 run_test 99d "cvs add =========================================="
6126
6127 test_99e() {
6128         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6129         [ ! -d $DIR/d99cvsroot ] && test_99c
6130         cd $DIR/d99reposname
6131         $RUNAS cvs update
6132 }
6133 run_test 99e "cvs update ======================================="
6134
6135 test_99f() {
6136         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6137         [ ! -d $DIR/d99cvsroot ] && test_99d
6138         cd $DIR/d99reposname
6139         $RUNAS cvs commit -m 'nomsg' foo99
6140     rm -fr $DIR/d99cvsroot
6141 }
6142 run_test 99f "cvs commit ======================================="
6143
6144 test_100() {
6145         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6146         [ "$NETTYPE" = tcp ] || \
6147                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
6148                         return ; }
6149
6150         remote_ost_nodsh && skip "remote OST with nodsh" && return
6151         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6152         remote_servers || \
6153                 { skip "useless for local single node setup" && return; }
6154
6155         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6156                 [ "$PROT" != "tcp" ] && continue
6157                 RPORT=$(echo $REMOTE | cut -d: -f2)
6158                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6159
6160                 rc=0
6161                 LPORT=`echo $LOCAL | cut -d: -f2`
6162                 if [ $LPORT -ge 1024 ]; then
6163                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6164                         netstat -tna
6165                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6166                 fi
6167         done
6168         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6169 }
6170 run_test 100 "check local port using privileged port ==========="
6171
6172 function get_named_value()
6173 {
6174     local tag
6175
6176     tag=$1
6177     while read ;do
6178         line=$REPLY
6179         case $line in
6180         $tag*)
6181             echo $line | sed "s/^$tag[ ]*//"
6182             break
6183             ;;
6184         esac
6185     done
6186 }
6187
6188 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6189                    awk '/^max_cached_mb/ { print $2 }')
6190
6191 cleanup_101a() {
6192         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6193         trap 0
6194 }
6195
6196 test_101a() {
6197         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6198         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
6199         local s
6200         local discard
6201         local nreads=10000
6202         local cache_limit=32
6203
6204         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6205         trap cleanup_101a EXIT
6206         $LCTL set_param -n llite.*.read_ahead_stats 0
6207         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6208
6209         #
6210         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6211         #
6212         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6213         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6214
6215         discard=0
6216         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6217                 get_named_value 'read but discarded' | cut -d" " -f1); do
6218                         discard=$(($discard + $s))
6219         done
6220         cleanup_101a
6221
6222         if [[ $(($discard * 10)) -gt $nreads ]]; then
6223                 $LCTL get_param osc.*-osc*.rpc_stats
6224                 $LCTL get_param llite.*.read_ahead_stats
6225                 error "too many ($discard) discarded pages"
6226         fi
6227         rm -f $DIR/$tfile || true
6228 }
6229 run_test 101a "check read-ahead for random reads ================"
6230
6231 setup_test101bc() {
6232         test_mkdir -p $DIR/$tdir
6233         local STRIPE_SIZE=$1
6234         local FILE_LENGTH=$2
6235         STRIPE_OFFSET=0
6236
6237         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6238
6239         local list=$(comma_list $(osts_nodes))
6240         set_osd_param $list '' read_cache_enable 0
6241         set_osd_param $list '' writethrough_cache_enable 0
6242
6243         trap cleanup_test101bc EXIT
6244         # prepare the read-ahead file
6245         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6246
6247         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6248                                 count=$FILE_SIZE_MB 2> /dev/null
6249
6250 }
6251
6252 cleanup_test101bc() {
6253         trap 0
6254         rm -rf $DIR/$tdir
6255         rm -f $DIR/$tfile
6256
6257         local list=$(comma_list $(osts_nodes))
6258         set_osd_param $list '' read_cache_enable 1
6259         set_osd_param $list '' writethrough_cache_enable 1
6260 }
6261
6262 calc_total() {
6263         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6264 }
6265
6266 ra_check_101() {
6267         local READ_SIZE=$1
6268         local STRIPE_SIZE=$2
6269         local FILE_LENGTH=$3
6270         local RA_INC=1048576
6271         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6272         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6273                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6274         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6275                         get_named_value 'read but discarded' |
6276                         cut -d" " -f1 | calc_total)
6277         if [[ $DISCARD -gt $discard_limit ]]; then
6278                 $LCTL get_param llite.*.read_ahead_stats
6279                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6280         else
6281                 echo "Read-ahead success for size ${READ_SIZE}"
6282         fi
6283 }
6284
6285 test_101b() {
6286         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6287         [[ $OSTCOUNT -lt 2 ]] &&
6288                 skip_env "skipping stride IO stride-ahead test" && return
6289         local STRIPE_SIZE=1048576
6290         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6291         if [ $SLOW == "yes" ]; then
6292                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6293         else
6294                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6295         fi
6296
6297         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6298
6299         # prepare the read-ahead file
6300         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6301         cancel_lru_locks osc
6302         for BIDX in 2 4 8 16 32 64 128 256
6303         do
6304                 local BSIZE=$((BIDX*4096))
6305                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6306                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6307                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6308                 $LCTL set_param -n llite.*.read_ahead_stats 0
6309                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6310                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6311                 cancel_lru_locks osc
6312                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6313         done
6314         cleanup_test101bc
6315         true
6316 }
6317 run_test 101b "check stride-io mode read-ahead ================="
6318
6319 test_101c() {
6320         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6321         local STRIPE_SIZE=1048576
6322         local FILE_LENGTH=$((STRIPE_SIZE*100))
6323         local nreads=10000
6324         local osc_rpc_stats
6325
6326         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6327
6328         cancel_lru_locks osc
6329         $LCTL set_param osc.*.rpc_stats 0
6330         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6331         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6332                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6333                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6334                 local size
6335
6336                 if [ $lines -le 20 ]; then
6337                         continue
6338                 fi
6339                 for size in 1 2 4 8; do
6340                         local rpc=$(echo "$stats" |
6341                                     awk '($1 == "'$size':") {print $2; exit; }')
6342                         [ $rpc != 0 ] &&
6343                                 error "Small $((size*4))k read IO $rpc !"
6344                 done
6345                 echo "$osc_rpc_stats check passed!"
6346         done
6347         cleanup_test101bc
6348         true
6349 }
6350 run_test 101c "check stripe_size aligned read-ahead ================="
6351
6352 set_read_ahead() {
6353         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6354         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6355 }
6356
6357 test_101d() {
6358         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6359         local file=$DIR/$tfile
6360         local sz_MB=${FILESIZE_101d:-500}
6361         local ra_MB=${READAHEAD_MB:-40}
6362
6363         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6364         [ $free_MB -lt $sz_MB ] &&
6365                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6366
6367         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6368         $SETSTRIPE -c -1 $file || error "setstripe failed"
6369
6370         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6371         echo Cancel LRU locks on lustre client to flush the client cache
6372         cancel_lru_locks osc
6373
6374         echo Disable read-ahead
6375         local old_READAHEAD=$(set_read_ahead 0)
6376
6377         echo Reading the test file $file with read-ahead disabled
6378         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6379
6380         echo Cancel LRU locks on lustre client to flush the client cache
6381         cancel_lru_locks osc
6382         echo Enable read-ahead with ${ra_MB}MB
6383         set_read_ahead $ra_MB
6384
6385         echo Reading the test file $file with read-ahead enabled
6386         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6387
6388         echo "read-ahead disabled time read $raOFF"
6389         echo "read-ahead enabled  time read $raON"
6390
6391         set_read_ahead $old_READAHEAD
6392         rm -f $file
6393         wait_delete_completed
6394
6395         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6396                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6397 }
6398 run_test 101d "file read with and without read-ahead enabled"
6399
6400 test_101e() {
6401         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6402         local file=$DIR/$tfile
6403         local size_KB=500  #KB
6404         local count=100
6405         local bsize=1024
6406
6407         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6408         local need_KB=$((count * size_KB))
6409         [[ $free_KB -le $need_KB ]] &&
6410                 skip_env "Need free space $need_KB, have $free_KB" && return
6411
6412         echo "Creating $count ${size_KB}K test files"
6413         for ((i = 0; i < $count; i++)); do
6414                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6415         done
6416
6417         echo "Cancel LRU locks on lustre client to flush the client cache"
6418         cancel_lru_locks osc
6419
6420         echo "Reset readahead stats"
6421         $LCTL set_param -n llite.*.read_ahead_stats 0
6422
6423         for ((i = 0; i < $count; i++)); do
6424                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6425         done
6426
6427         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6428                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6429
6430         for ((i = 0; i < $count; i++)); do
6431                 rm -rf $file.$i 2>/dev/null
6432         done
6433
6434         #10000 means 20% reads are missing in readahead
6435         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6436 }
6437 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6438
6439 cleanup_test101f() {
6440     trap 0
6441     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6442     rm -rf $DIR/$tfile 2>/dev/null
6443 }
6444
6445 test_101f() {
6446         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6447     local file=$DIR/$tfile
6448     local nreads=1000
6449
6450     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6451     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6452     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6453     trap cleanup_test101f EXIT
6454
6455     echo Cancel LRU locks on lustre client to flush the client cache
6456     cancel_lru_locks osc
6457
6458     echo Reset readahead stats
6459     $LCTL set_param -n llite.*.read_ahead_stats 0
6460     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6461     # readahead should read in 2M file on second read, so only miss
6462     # 2 pages.
6463     echo Random 4K reads on 2M file for 1000 times
6464     $READS -f $file -s 2097152 -b 4096 -n $nreads
6465
6466     echo checking missing pages
6467     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6468           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6469
6470     [ $miss -lt 3 ] || error "misses too much pages!"
6471     cleanup_test101f
6472 }
6473 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6474
6475 setup_test102() {
6476         test_mkdir -p $DIR/$tdir
6477         chown $RUNAS_ID $DIR/$tdir
6478         STRIPE_SIZE=65536
6479         STRIPE_OFFSET=1
6480         STRIPE_COUNT=$OSTCOUNT
6481         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6482
6483         trap cleanup_test102 EXIT
6484         cd $DIR
6485         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6486         cd $DIR/$tdir
6487         for num in 1 2 3 4; do
6488                 for count in $(seq 1 $STRIPE_COUNT); do
6489                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6490                                 local size=`expr $STRIPE_SIZE \* $num`
6491                                 local file=file"$num-$idx-$count"
6492                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6493                         done
6494                 done
6495         done
6496
6497         cd $DIR
6498         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6499 }
6500
6501 cleanup_test102() {
6502         trap 0
6503         rm -f $TMP/f102.tar
6504         rm -rf $DIR/d0.sanity/d102
6505 }
6506
6507 test_102a() {
6508         local testfile=$DIR/$tfile
6509
6510         touch $testfile
6511
6512         [ "$UID" != 0 ] && skip_env "must run as root" && return
6513         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6514                 skip_env "must have user_xattr" && return
6515
6516         [ -z "$(which setfattr 2>/dev/null)" ] &&
6517                 skip_env "could not find setfattr" && return
6518
6519         echo "set/get xattr..."
6520         setfattr -n trusted.name1 -v value1 $testfile ||
6521                 error "setfattr -n trusted.name1=value1 $testfile failed"
6522         getfattr -n trusted.name1 $testfile 2> /dev/null |
6523           grep "trusted.name1=.value1" ||
6524                 error "$testfile missing trusted.name1=value1"
6525
6526         setfattr -n user.author1 -v author1 $testfile ||
6527                 error "setfattr -n user.author1=author1 $testfile failed"
6528         getfattr -n user.author1 $testfile 2> /dev/null |
6529           grep "user.author1=.author1" ||
6530                 error "$testfile missing trusted.author1=author1"
6531
6532         echo "listxattr..."
6533         setfattr -n trusted.name2 -v value2 $testfile ||
6534                 error "$testfile unable to set trusted.name2"
6535         setfattr -n trusted.name3 -v value3 $testfile ||
6536                 error "$testfile unable to set trusted.name3"
6537         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6538             grep "trusted.name" | wc -l) -eq 3 ] ||
6539                 error "$testfile missing 3 trusted.name xattrs"
6540
6541         setfattr -n user.author2 -v author2 $testfile ||
6542                 error "$testfile unable to set user.author2"
6543         setfattr -n user.author3 -v author3 $testfile ||
6544                 error "$testfile unable to set user.author3"
6545         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6546             grep "user.author" | wc -l) -eq 3 ] ||
6547                 error "$testfile missing 3 user.author xattrs"
6548
6549         echo "remove xattr..."
6550         setfattr -x trusted.name1 $testfile ||
6551                 error "$testfile error deleting trusted.name1"
6552         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6553                 error "$testfile did not delete trusted.name1 xattr"
6554
6555         setfattr -x user.author1 $testfile ||
6556                 error "$testfile error deleting user.author1"
6557         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6558                 error "$testfile did not delete trusted.name1 xattr"
6559
6560         # b10667: setting lustre special xattr be silently discarded
6561         echo "set lustre special xattr ..."
6562         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6563                 error "$testfile allowed setting trusted.lov"
6564 }
6565 run_test 102a "user xattr test =================================="
6566
6567 test_102b() {
6568         [ -z "$(which setfattr 2>/dev/null)" ] &&
6569                 skip_env "could not find setfattr" && return
6570
6571         # b10930: get/set/list trusted.lov xattr
6572         echo "get/set/list trusted.lov xattr ..."
6573         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6574         local testfile=$DIR/$tfile
6575         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6576                 error "setstripe failed"
6577         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6578                 error "getstripe failed"
6579         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6580                 error "can't get trusted.lov from $testfile"
6581
6582         local testfile2=${testfile}2
6583         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6584                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6585
6586         $MCREATE $testfile2
6587         setfattr -n trusted.lov -v $value $testfile2
6588         local stripe_size=$($GETSTRIPE -S $testfile2)
6589         local stripe_count=$($GETSTRIPE -c $testfile2)
6590         [[ $stripe_size -eq 65536 ]] ||
6591                 error "stripe size $stripe_size != 65536"
6592         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6593                 error "stripe count $stripe_count != $STRIPECOUNT"
6594         rm -f $DIR/$tfile
6595 }
6596 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6597
6598 test_102c() {
6599         [ -z "$(which setfattr 2>/dev/null)" ] &&
6600                 skip_env "could not find setfattr" && return
6601
6602         # b10930: get/set/list lustre.lov xattr
6603         echo "get/set/list lustre.lov xattr ..."
6604         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6605         test_mkdir -p $DIR/$tdir
6606         chown $RUNAS_ID $DIR/$tdir
6607         local testfile=$DIR/$tdir/$tfile
6608         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6609                 error "setstripe failed"
6610         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6611                 error "getstripe failed"
6612         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6613         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6614
6615         local testfile2=${testfile}2
6616         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6617                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6618
6619         $RUNAS $MCREATE $testfile2
6620         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6621         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6622         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6623         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6624         [ $stripe_count -eq $STRIPECOUNT ] ||
6625                 error "stripe count $stripe_count != $STRIPECOUNT"
6626 }
6627 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6628
6629 compare_stripe_info1() {
6630         local stripe_index_all_zero=true
6631
6632         for num in 1 2 3 4; do
6633                 for count in $(seq 1 $STRIPE_COUNT); do
6634                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6635                                 local size=$((STRIPE_SIZE * num))
6636                                 local file=file"$num-$offset-$count"
6637                                 stripe_size=$($LFS getstripe -S $PWD/$file)
6638                                 [[ $stripe_size -ne $size ]] &&
6639                                     error "$file: size $stripe_size != $size"
6640                                 stripe_count=$($LFS getstripe -c $PWD/$file)
6641                                 # allow fewer stripes to be created, ORI-601
6642                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6643                                     error "$file: count $stripe_count != $count"
6644                                 stripe_index=$($LFS getstripe -i $PWD/$file)
6645                                 [[ $stripe_index -ne 0 ]] &&
6646                                         stripe_index_all_zero=false
6647                         done
6648                 done
6649         done
6650         $stripe_index_all_zero &&
6651                 error "all files are being extracted starting from OST index 0"
6652         return 0
6653 }
6654
6655 find_lustre_tar() {
6656         [ -n "$(which tar 2>/dev/null)" ] &&
6657                 strings $(which tar) | grep -q "lustre" && echo tar
6658 }
6659
6660 test_102d() {
6661         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6662         # b10930: tar test for trusted.lov xattr
6663         TAR=$(find_lustre_tar)
6664         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6665         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6666         setup_test102
6667         test_mkdir -p $DIR/d102d
6668         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6669         cd $DIR/d102d/$tdir
6670         compare_stripe_info1
6671 }
6672 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6673
6674 test_102f() {
6675         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6676         # b10930: tar test for trusted.lov xattr
6677         TAR=$(find_lustre_tar)
6678         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6679         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6680         setup_test102
6681         test_mkdir -p $DIR/d102f
6682         cd $DIR
6683         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6684         cd $DIR/d102f/$tdir
6685         compare_stripe_info1
6686 }
6687 run_test 102f "tar copy files, not keep osts ==========="
6688
6689 grow_xattr() {
6690         local xsize=${1:-1024}  # in bytes
6691         local file=$DIR/$tfile
6692
6693         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6694                 skip "must have user_xattr" && return 0
6695         [ -z "$(which setfattr 2>/dev/null)" ] &&
6696                 skip_env "could not find setfattr" && return 0
6697         [ -z "$(which getfattr 2>/dev/null)" ] &&
6698                 skip_env "could not find getfattr" && return 0
6699
6700         touch $file
6701
6702         local value="$(generate_string $xsize)"
6703
6704         local xbig=trusted.big
6705         log "save $xbig on $file"
6706         setfattr -n $xbig -v $value $file ||
6707                 error "saving $xbig on $file failed"
6708
6709         local orig=$(get_xattr_value $xbig $file)
6710         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6711
6712         local xsml=trusted.sml
6713         log "save $xsml on $file"
6714         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6715
6716         local new=$(get_xattr_value $xbig $file)
6717         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6718
6719         log "grow $xsml on $file"
6720         setfattr -n $xsml -v "$value" $file ||
6721                 error "growing $xsml on $file failed"
6722
6723         new=$(get_xattr_value $xbig $file)
6724         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6725         log "$xbig still valid after growing $xsml"
6726
6727         rm -f $file
6728 }
6729
6730 test_102h() { # bug 15777
6731         grow_xattr 1024
6732 }
6733 run_test 102h "grow xattr from inside inode to external block"
6734
6735 test_102ha() {
6736         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6737         grow_xattr $(max_xattr_size)
6738 }
6739 run_test 102ha "grow xattr from inside inode to external inode"
6740
6741 test_102i() { # bug 17038
6742         [ -z "$(which getfattr 2>/dev/null)" ] &&
6743                 skip "could not find getfattr" && return
6744         touch $DIR/$tfile
6745         ln -s $DIR/$tfile $DIR/${tfile}link
6746         getfattr -n trusted.lov $DIR/$tfile ||
6747                 error "lgetxattr on $DIR/$tfile failed"
6748         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6749                 grep -i "no such attr" ||
6750                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6751         rm -f $DIR/$tfile $DIR/${tfile}link
6752 }
6753 run_test 102i "lgetxattr test on symbolic link ============"
6754
6755 test_102j() {
6756         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6757         TAR=$(find_lustre_tar)
6758         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6759         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6760         setup_test102 "$RUNAS"
6761         test_mkdir -p $DIR/d102j
6762         chown $RUNAS_ID $DIR/d102j
6763         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6764         cd $DIR/d102j/$tdir
6765         compare_stripe_info1 "$RUNAS"
6766 }
6767 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6768
6769 test_102k() {
6770         [ -z "$(which setfattr 2>/dev/null)" ] &&
6771                 skip "could not find setfattr" && return
6772         touch $DIR/$tfile
6773         # b22187 just check that does not crash for regular file.
6774         setfattr -n trusted.lov $DIR/$tfile
6775         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6776         local test_kdir=$DIR/d102k
6777         test_mkdir $test_kdir
6778         local default_size=`$GETSTRIPE -S $test_kdir`
6779         local default_count=`$GETSTRIPE -c $test_kdir`
6780         local default_offset=`$GETSTRIPE -i $test_kdir`
6781         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6782                 error 'dir setstripe failed'
6783         setfattr -n trusted.lov $test_kdir
6784         local stripe_size=`$GETSTRIPE -S $test_kdir`
6785         local stripe_count=`$GETSTRIPE -c $test_kdir`
6786         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6787         [ $stripe_size -eq $default_size ] ||
6788                 error "stripe size $stripe_size != $default_size"
6789         [ $stripe_count -eq $default_count ] ||
6790                 error "stripe count $stripe_count != $default_count"
6791         [ $stripe_offset -eq $default_offset ] ||
6792                 error "stripe offset $stripe_offset != $default_offset"
6793         rm -rf $DIR/$tfile $test_kdir
6794 }
6795 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6796
6797 test_102l() {
6798         [ -z "$(which getfattr 2>/dev/null)" ] &&
6799                 skip "could not find getfattr" && return
6800
6801         # LU-532 trusted. xattr is invisible to non-root
6802         local testfile=$DIR/$tfile
6803
6804         touch $testfile
6805
6806         echo "listxattr as user..."
6807         chown $RUNAS_ID $testfile
6808         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6809             grep -q "trusted" &&
6810                 error "$testfile trusted xattrs are user visible"
6811
6812         return 0;
6813 }
6814 run_test 102l "listxattr size test =================================="
6815
6816 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6817         local path=$DIR/$tfile
6818         touch $path
6819
6820         listxattr_size_check $path || error "listattr_size_check $path failed"
6821 }
6822 run_test 102m "Ensure listxattr fails on small bufffer ========"
6823
6824 cleanup_test102
6825
6826 getxattr() { # getxattr path name
6827         # Return the base64 encoding of the value of xattr name on path.
6828         local path=$1
6829         local name=$2
6830
6831         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6832         # file: $path
6833         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6834         #
6835         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6836
6837         getfattr --absolute-names --encoding=base64 --name=$name $path |
6838                 awk -F= -v name=$name '$1 == name {
6839                         print substr($0, index($0, "=") + 1);
6840         }'
6841 }
6842
6843 test_102n() { # LU-4101 mdt: protect internal xattrs
6844         local file0=$DIR/$tfile.0
6845         local file1=$DIR/$tfile.1
6846         local xattr0=$TMP/$tfile.0
6847         local xattr1=$TMP/$tfile.1
6848         local name
6849         local value
6850
6851         [ -z "$(which setfattr 2>/dev/null)" ] &&
6852                 skip "could not find setfattr" && return
6853
6854         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6855         then
6856                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6857                 return
6858         fi
6859
6860         rm -rf $file0 $file1 $xattr0 $xattr1
6861         touch $file0 $file1
6862
6863         # Get 'before' xattrs of $file1.
6864         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6865
6866         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6867                 # Try to copy xattr from $file0 to $file1.
6868                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6869
6870                 setfattr --name=trusted.$name --value="$value" $file1 ||
6871                         error "setxattr 'trusted.$name' failed"
6872
6873                 # Try to set a garbage xattr.
6874                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6875
6876                 setfattr --name=trusted.$name --value="$value" $file1 ||
6877                         error "setxattr 'trusted.$name' failed"
6878
6879                 # Try to remove the xattr from $file1. We don't care if this
6880                 # appears to succeed or fail, we just don't want there to be
6881                 # any changes or crashes.
6882                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6883         done
6884
6885         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
6886         then
6887                 name="lfsck_ns"
6888                 # Try to copy xattr from $file0 to $file1.
6889                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6890
6891                 setfattr --name=trusted.$name --value="$value" $file1 ||
6892                         error "setxattr 'trusted.$name' failed"
6893
6894                 # Try to set a garbage xattr.
6895                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6896
6897                 setfattr --name=trusted.$name --value="$value" $file1 ||
6898                         error "setxattr 'trusted.$name' failed"
6899
6900                 # Try to remove the xattr from $file1. We don't care if this
6901                 # appears to succeed or fail, we just don't want there to be
6902                 # any changes or crashes.
6903                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6904         fi
6905
6906         # Get 'after' xattrs of file1.
6907         getfattr --absolute-names --dump --match=- $file1 > $xattr1
6908
6909         if ! diff $xattr0 $xattr1; then
6910                 error "before and after xattrs of '$file1' differ"
6911         fi
6912
6913         rm -rf $file0 $file1 $xattr0 $xattr1
6914
6915         return 0
6916 }
6917 run_test 102n "silently ignore setxattr on internal trusted xattrs"
6918
6919 test_102p() { # LU-4703 setxattr did not check ownership
6920         local testfile=$DIR/$tfile
6921
6922         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
6923                 skip "MDS needs to be at least 2.5.56" && return
6924
6925         touch $testfile
6926
6927         echo "setfacl as user..."
6928         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
6929         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
6930
6931         echo "setfattr as user..."
6932         setfacl -m "u:$RUNAS_ID:---" $testfile
6933         $RUNAS setfattr -x system.posix_acl_access $testfile
6934         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
6935 }
6936 run_test 102p "check setxattr(2) correctly fails without permission"
6937
6938 test_102q() {
6939         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
6940                 skip "MDS needs to be at least 2.6.92" && return
6941         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
6942 }
6943 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
6944
6945 test_102r() {
6946         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
6947                 skip "MDS needs to be at least 2.6.93" && return
6948         touch $DIR/$tfile || error "touch"
6949         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
6950         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
6951         rm $DIR/$tfile || error "rm"
6952
6953         #normal directory
6954         mkdir -p $DIR/$tdir || error "mkdir"
6955         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
6956         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
6957         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
6958                 error "$testfile error deleting user.author1"
6959         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
6960                 grep "user.$(basename $tdir)" &&
6961                 error "$tdir did not delete user.$(basename $tdir)"
6962         rmdir $DIR/$tdir || error "rmdir"
6963
6964         #striped directory
6965         test_mkdir -p $DIR/$tdir || error "make striped dir"
6966         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
6967         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
6968         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
6969                 error "$testfile error deleting user.author1"
6970         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
6971                 grep "user.$(basename $tdir)" &&
6972                 error "$tdir did not delete user.$(basename $tdir)"
6973         rmdir $DIR/$tdir || error "rm striped dir"
6974 }
6975 run_test 102r "set EAs with empty values"
6976
6977 run_acl_subtest()
6978 {
6979     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6980     return $?
6981 }
6982
6983 test_103a() {
6984         [ "$UID" != 0 ] && skip_env "must run as root" && return
6985         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6986                 skip "must have acl enabled" && return
6987         [ -z "$(which setfacl 2>/dev/null)" ] &&
6988                 skip_env "could not find setfacl" && return
6989         $GSS && skip "could not run under gss" && return
6990
6991         gpasswd -a daemon bin                           # LU-5641
6992         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
6993
6994         declare -a identity_old
6995
6996         for num in $(seq $MDSCOUNT); do
6997                 switch_identity $num true || identity_old[$num]=$?
6998         done
6999
7000         SAVE_UMASK=$(umask)
7001         umask 0022
7002         cd $DIR
7003
7004         echo "performing cp ..."
7005         run_acl_subtest cp || error "run_acl_subtest cp failed"
7006         echo "performing getfacl-noacl..."
7007         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
7008         echo "performing misc..."
7009         run_acl_subtest misc || error  "misc test failed"
7010         echo "performing permissions..."
7011         run_acl_subtest permissions || error "permissions failed"
7012         echo "performing setfacl..."
7013         run_acl_subtest setfacl || error  "setfacl test failed"
7014
7015         # inheritance test got from HP
7016         echo "performing inheritance..."
7017         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
7018         chmod +x make-tree || error "chmod +x failed"
7019         run_acl_subtest inheritance || error "inheritance test failed"
7020         rm -f make-tree
7021
7022         echo "LU-974 ignore umask when acl is enabled..."
7023         run_acl_subtest 974 || error "LU-974 umask test failed"
7024         if [ $MDSCOUNT -ge 2 ]; then
7025                 run_acl_subtest 974_remote ||
7026                         error "LU-974 umask test failed under remote dir"
7027         fi
7028
7029         echo "LU-2561 newly created file is same size as directory..."
7030         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
7031                 run_acl_subtest 2561 || error "LU-2561 test failed"
7032         else
7033                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
7034         fi
7035
7036         run_acl_subtest 4924 || error "LU-4924 test failed"
7037
7038         cd $SAVE_PWD
7039         umask $SAVE_UMASK
7040
7041         for num in $(seq $MDSCOUNT); do
7042                 if [ "${identity_old[$num]}" = 1 ]; then
7043                         switch_identity $num false || identity_old[$num]=$?
7044                 fi
7045         done
7046 }
7047 run_test 103a "acl test ========================================="
7048
7049 test_103b() {
7050         local noacl=false
7051         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
7052         local mountopts=$MDS_MOUNT_OPTS
7053
7054         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
7055                 noacl=true
7056         else
7057                 # stop the MDT
7058                 stop $SINGLEMDS || error "failed to stop MDT."
7059                 # remount the MDT
7060                 if [ -z "$MDS_MOUNT_OPTS" ]; then
7061                         MDS_MOUNT_OPTS="-o noacl"
7062                 else
7063                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
7064                 fi
7065                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7066                         error "failed to start MDT."
7067                 MDS_MOUNT_OPTS=$mountopts
7068         fi
7069
7070         touch $DIR/$tfile
7071         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
7072
7073         if ! $noacl; then
7074                 # stop the MDT
7075                 stop $SINGLEMDS || error "failed to stop MDT."
7076                 # remount the MDT
7077                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7078                         error "failed to start MDT."
7079         fi
7080
7081         true
7082 }
7083 run_test 103b "MDS mount option 'noacl'"
7084
7085 test_103c() {
7086         mkdir -p $DIR/$tdir
7087         cp -rp $DIR/$tdir $DIR/$tdir.bak
7088
7089         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
7090                 error "$DIR/$tdir shouldn't contain default ACL"
7091         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
7092                 error "$DIR/$tdir.bak shouldn't contain default ACL"
7093         true
7094 }
7095 run_test 103c "'cp -rp' won't set empty acl"
7096
7097 test_104a() {
7098         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7099         touch $DIR/$tfile
7100         lfs df || error "lfs df failed"
7101         lfs df -ih || error "lfs df -ih failed"
7102         lfs df -h $DIR || error "lfs df -h $DIR failed"
7103         lfs df -i $DIR || error "lfs df -i $DIR failed"
7104         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
7105         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
7106
7107         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
7108         lctl --device %$OSC deactivate
7109         lfs df || error "lfs df with deactivated OSC failed"
7110         lctl --device %$OSC activate
7111         # wait the osc back to normal
7112         wait_osc_import_state client ost FULL
7113
7114         lfs df || error "lfs df with reactivated OSC failed"
7115         rm -f $DIR/$tfile
7116 }
7117 run_test 104a "lfs df [-ih] [path] test ========================="
7118
7119 test_104b() {
7120         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7121         [ $RUNAS_ID -eq $UID ] &&
7122                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
7123         chmod 666 /dev/obd
7124         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
7125                         grep "Permission denied" | wc -l)))
7126         if [ $denied_cnt -ne 0 ]; then
7127                 error "lfs check servers test failed"
7128         fi
7129 }
7130 run_test 104b "$RUNAS lfs check servers test ===================="
7131
7132 test_105a() {
7133         # doesn't work on 2.4 kernels
7134         touch $DIR/$tfile
7135         if $(flock_is_enabled); then
7136                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7137         else
7138                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7139         fi
7140         rm -f $DIR/$tfile
7141 }
7142 run_test 105a "flock when mounted without -o flock test ========"
7143
7144 test_105b() {
7145         touch $DIR/$tfile
7146         if $(flock_is_enabled); then
7147                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7148         else
7149                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7150         fi
7151         rm -f $DIR/$tfile
7152 }
7153 run_test 105b "fcntl when mounted without -o flock test ========"
7154
7155 test_105c() {
7156         touch $DIR/$tfile
7157         if $(flock_is_enabled); then
7158                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7159         else
7160                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7161         fi
7162         rm -f $DIR/$tfile
7163 }
7164 run_test 105c "lockf when mounted without -o flock test ========"
7165
7166 test_105d() { # bug 15924
7167         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7168         test_mkdir -p $DIR/$tdir
7169         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7170         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7171         $LCTL set_param fail_loc=0x80000315
7172         flocks_test 2 $DIR/$tdir
7173 }
7174 run_test 105d "flock race (should not freeze) ========"
7175
7176 test_105e() { # bug 22660 && 22040
7177         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7178         touch $DIR/$tfile
7179         flocks_test 3 $DIR/$tfile
7180 }
7181 run_test 105e "Two conflicting flocks from same process ======="
7182
7183 test_106() { #bug 10921
7184         test_mkdir -p $DIR/$tdir
7185         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7186         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7187 }
7188 run_test 106 "attempt exec of dir followed by chown of that dir"
7189
7190 test_107() {
7191         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7192         CDIR=`pwd`
7193         cd $DIR
7194
7195         local file=core
7196         rm -f $file
7197
7198         local save_pattern=$(sysctl -n kernel.core_pattern)
7199         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7200         sysctl -w kernel.core_pattern=$file
7201         sysctl -w kernel.core_uses_pid=0
7202
7203         ulimit -c unlimited
7204         sleep 60 &
7205         SLEEPPID=$!
7206
7207         sleep 1
7208
7209         kill -s 11 $SLEEPPID
7210         wait $SLEEPPID
7211         if [ -e $file ]; then
7212                 size=`stat -c%s $file`
7213                 [ $size -eq 0 ] && error "Fail to create core file $file"
7214         else
7215                 error "Fail to create core file $file"
7216         fi
7217         rm -f $file
7218         sysctl -w kernel.core_pattern=$save_pattern
7219         sysctl -w kernel.core_uses_pid=$save_uses_pid
7220         cd $CDIR
7221 }
7222 run_test 107 "Coredump on SIG"
7223
7224 test_110() {
7225         test_mkdir -p $DIR/$tdir
7226         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7227                 error "mkdir with 255 char failed"
7228         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7229                 error "mkdir with 256 char should fail, but did not"
7230         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7231                 error "create with 255 char failed"
7232         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7233                 error "create with 256 char should fail, but did not"
7234
7235         ls -l $DIR/$tdir
7236         rm -rf $DIR/$tdir
7237 }
7238 run_test 110 "filename length checking"
7239
7240 test_115() {
7241         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7242         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
7243                 tail -1 | cut -c11-20)
7244         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
7245         echo "Starting with $OSTIO_pre threads"
7246
7247         NUMTEST=20000
7248         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7249         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
7250         echo "$NUMTEST creates/unlinks"
7251         test_mkdir -p $DIR/$tdir
7252         createmany -o $DIR/$tdir/$tfile $NUMTEST
7253         unlinkmany $DIR/$tdir/$tfile $NUMTEST
7254
7255         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
7256                 tail -1 | cut -c11-20)
7257
7258         # don't return an error
7259         [ $OSTIO_post == $OSTIO_pre ] && echo \
7260             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
7261             echo "This may be fine, depending on what ran before this test" &&
7262             echo "and how fast this system is." && return
7263
7264         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
7265 }
7266 run_test 115 "verify dynamic thread creation===================="
7267
7268 free_min_max () {
7269         wait_delete_completed
7270         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7271         echo OST kbytes available: ${AVAIL[@]}
7272         MAXI=0; MAXV=${AVAIL[0]}
7273         MINI=0; MINV=${AVAIL[0]}
7274         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7275                 #echo OST $i: ${AVAIL[i]}kb
7276                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7277                         MAXV=${AVAIL[i]}; MAXI=$i
7278                 fi
7279                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7280                         MINV=${AVAIL[i]}; MINI=$i
7281                 fi
7282         done
7283         echo Min free space: OST $MINI: $MINV
7284         echo Max free space: OST $MAXI: $MAXV
7285 }
7286
7287 test_116a() { # was previously test_116()
7288         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7289         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
7290
7291         echo -n "Free space priority "
7292         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7293                 head -n1
7294         declare -a AVAIL
7295         free_min_max
7296
7297         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7298         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7299                 && return
7300         trap simple_cleanup_common EXIT
7301
7302
7303         # Check if we need to generate uneven OSTs
7304         test_mkdir -p $DIR/$tdir/OST${MINI}
7305         local FILL=$(($MINV / 4))
7306         local DIFF=$(($MAXV - $MINV))
7307         local DIFF2=$(($DIFF * 100 / $MINV))
7308
7309         local threshold=$(do_facet $SINGLEMDS \
7310                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7311         threshold=${threshold%%%}
7312         echo -n "Check for uneven OSTs: "
7313         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7314
7315         if [[ $DIFF2 -gt $threshold ]]; then
7316                 echo "ok"
7317                 echo "Don't need to fill OST$MINI"
7318         else
7319                 # generate uneven OSTs. Write 2% over the QOS threshold value
7320                 echo "no"
7321                 DIFF=$(($threshold - $DIFF2 + 2))
7322                 DIFF2=$(( ($MINV * $DIFF)/100 ))
7323                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
7324                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7325                         error "setstripe failed"
7326                 DIFF=$(($DIFF2 / 2048))
7327                 i=0
7328                 while [ $i -lt $DIFF ]; do
7329                         i=$(($i + 1))
7330                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7331                                 bs=2M count=1 2>/dev/null
7332                         echo -n .
7333                 done
7334                 echo .
7335                 sync
7336                 sleep_maxage
7337                 free_min_max
7338         fi
7339
7340         DIFF=$(($MAXV - $MINV))
7341         DIFF2=$(($DIFF * 100 / $MINV))
7342         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
7343         if [[ $DIFF2 -gt $threshold ]]; then
7344                 echo "ok"
7345         else
7346                 echo "failed - QOS mode won't be used"
7347                 skip "QOS imbalance criteria not met"
7348                 simple_cleanup_common
7349                 return
7350         fi
7351
7352         MINI1=$MINI; MINV1=$MINV
7353         MAXI1=$MAXI; MAXV1=$MAXV
7354
7355         # now fill using QOS
7356         $SETSTRIPE -c 1 $DIR/$tdir
7357         FILL=$(($FILL / 200))
7358         if [ $FILL -gt 600 ]; then
7359                 FILL=600
7360         fi
7361         echo "writing $FILL files to QOS-assigned OSTs"
7362         i=0
7363         while [ $i -lt $FILL ]; do
7364                 i=$((i + 1))
7365                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7366                         count=1 2>/dev/null
7367                 echo -n .
7368         done
7369         echo "wrote $i 200k files"
7370         sync
7371         sleep_maxage
7372
7373         echo "Note: free space may not be updated, so measurements might be off"
7374         free_min_max
7375         DIFF2=$(($MAXV - $MINV))
7376         echo "free space delta: orig $DIFF final $DIFF2"
7377         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7378         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
7379         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7380         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
7381         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7382         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7383         [ $DIFF -gt 0 ] &&
7384                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7385
7386         # Figure out which files were written where
7387         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7388                   awk '/'$MINI1': / {print $2; exit}')
7389         echo $UUID
7390         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7391         echo "$MINC files created on smaller OST $MINI1"
7392         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7393                   awk '/'$MAXI1': / {print $2; exit}')
7394         echo $UUID
7395         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7396         echo "$MAXC files created on larger OST $MAXI1"
7397         FILL=$(($MAXC * 100 / $MINC - 100))
7398         [[ $MINC -gt 0 ]] &&
7399                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7400         [[ $MAXC -gt $MINC ]] ||
7401                 error_ignore LU-9 "stripe QOS didn't balance free space"
7402         simple_cleanup_common
7403 }
7404 run_test 116a "stripe QOS: free space balance ==================="
7405
7406 test_116b() { # LU-2093
7407         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7408 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7409         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7410                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7411         [ -z "$old_rr" ] && skip "no QOS" && return 0
7412         do_facet $SINGLEMDS lctl set_param \
7413                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7414         mkdir -p $DIR/$tdir
7415         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7416         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7417         do_facet $SINGLEMDS lctl set_param fail_loc=0
7418         rm -rf $DIR/$tdir
7419         do_facet $SINGLEMDS lctl set_param \
7420                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7421 }
7422 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7423
7424 test_117() # bug 10891
7425 {
7426         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7427         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7428         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7429         lctl set_param fail_loc=0x21e
7430         > $DIR/$tfile || error "truncate failed"
7431         lctl set_param fail_loc=0
7432         echo "Truncate succeeded."
7433         rm -f $DIR/$tfile
7434 }
7435 run_test 117 "verify osd extend =========="
7436
7437 NO_SLOW_RESENDCOUNT=4
7438 export OLD_RESENDCOUNT=""
7439 set_resend_count () {
7440         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7441         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7442         lctl set_param -n $PROC_RESENDCOUNT $1
7443         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7444 }
7445
7446 # for reduce test_118* time (b=14842)
7447 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7448
7449 # Reset async IO behavior after error case
7450 reset_async() {
7451         FILE=$DIR/reset_async
7452
7453         # Ensure all OSCs are cleared
7454         $SETSTRIPE -c -1 $FILE
7455         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7456         sync
7457         rm $FILE
7458 }
7459
7460 test_118a() #bug 11710
7461 {
7462         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7463         reset_async
7464
7465         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7466         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7467         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7468
7469         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7470                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7471                 return 1;
7472         fi
7473         rm -f $DIR/$tfile
7474 }
7475 run_test 118a "verify O_SYNC works =========="
7476
7477 test_118b()
7478 {
7479         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7480         remote_ost_nodsh && skip "remote OST with nodsh" && return
7481
7482         reset_async
7483
7484         #define OBD_FAIL_OST_ENOENT 0x217
7485         set_nodes_failloc "$(osts_nodes)" 0x217
7486         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7487         RC=$?
7488         set_nodes_failloc "$(osts_nodes)" 0
7489         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7490         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7491                     grep -c writeback)
7492
7493         if [[ $RC -eq 0 ]]; then
7494                 error "Must return error due to dropped pages, rc=$RC"
7495                 return 1;
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                 return 1;
7501         fi
7502
7503         echo "Dirty pages not leaked on ENOENT"
7504
7505         # Due to the above error the OSC will issue all RPCs syncronously
7506         # until a subsequent RPC completes successfully without error.
7507         $MULTIOP $DIR/$tfile Ow4096yc
7508         rm -f $DIR/$tfile
7509
7510         return 0
7511 }
7512 run_test 118b "Reclaim dirty pages on fatal error =========="
7513
7514 test_118c()
7515 {
7516         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7517
7518         # for 118c, restore the original resend count, LU-1940
7519         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7520                                 set_resend_count $OLD_RESENDCOUNT
7521         remote_ost_nodsh && skip "remote OST with nodsh" && return
7522
7523         reset_async
7524
7525         #define OBD_FAIL_OST_EROFS               0x216
7526         set_nodes_failloc "$(osts_nodes)" 0x216
7527
7528         # multiop should block due to fsync until pages are written
7529         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7530         MULTIPID=$!
7531         sleep 1
7532
7533         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7534                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7535         fi
7536
7537         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7538                     grep -c writeback)
7539         if [[ $WRITEBACK -eq 0 ]]; then
7540                 error "No page in writeback, writeback=$WRITEBACK"
7541         fi
7542
7543         set_nodes_failloc "$(osts_nodes)" 0
7544         wait $MULTIPID
7545         RC=$?
7546         if [[ $RC -ne 0 ]]; then
7547                 error "Multiop fsync failed, rc=$RC"
7548         fi
7549
7550         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7551         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7552                     grep -c writeback)
7553         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7554                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7555         fi
7556
7557         rm -f $DIR/$tfile
7558         echo "Dirty pages flushed via fsync on EROFS"
7559         return 0
7560 }
7561 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7562
7563 # continue to use small resend count to reduce test_118* time (b=14842)
7564 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7565
7566 test_118d()
7567 {
7568         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7569         remote_ost_nodsh && skip "remote OST with nodsh" && return
7570
7571         reset_async
7572
7573         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7574         set_nodes_failloc "$(osts_nodes)" 0x214
7575         # multiop should block due to fsync until pages are written
7576         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7577         MULTIPID=$!
7578         sleep 1
7579
7580         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7581                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7582         fi
7583
7584         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7585                     grep -c writeback)
7586         if [[ $WRITEBACK -eq 0 ]]; then
7587                 error "No page in writeback, writeback=$WRITEBACK"
7588         fi
7589
7590         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7591         set_nodes_failloc "$(osts_nodes)" 0
7592
7593         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7594         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7595                     grep -c writeback)
7596         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7597                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7598         fi
7599
7600         rm -f $DIR/$tfile
7601         echo "Dirty pages gaurenteed flushed via fsync"
7602         return 0
7603 }
7604 run_test 118d "Fsync validation inject a delay of the bulk =========="
7605
7606 test_118f() {
7607         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7608         reset_async
7609
7610         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7611         lctl set_param fail_loc=0x8000040a
7612
7613         # Should simulate EINVAL error which is fatal
7614         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7615         RC=$?
7616         if [[ $RC -eq 0 ]]; then
7617                 error "Must return error due to dropped pages, rc=$RC"
7618         fi
7619
7620         lctl set_param fail_loc=0x0
7621
7622         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7623         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7624         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7625                     grep -c writeback)
7626         if [[ $LOCKED -ne 0 ]]; then
7627                 error "Locked pages remain in cache, locked=$LOCKED"
7628         fi
7629
7630         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7631                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7632         fi
7633
7634         rm -f $DIR/$tfile
7635         echo "No pages locked after fsync"
7636
7637         reset_async
7638         return 0
7639 }
7640 run_test 118f "Simulate unrecoverable OSC side error =========="
7641
7642 test_118g() {
7643         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7644         reset_async
7645
7646         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7647         lctl set_param fail_loc=0x406
7648
7649         # simulate local -ENOMEM
7650         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7651         RC=$?
7652
7653         lctl set_param fail_loc=0
7654         if [[ $RC -eq 0 ]]; then
7655                 error "Must return error due to dropped pages, rc=$RC"
7656         fi
7657
7658         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7659         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7660         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7661                         grep -c writeback)
7662         if [[ $LOCKED -ne 0 ]]; then
7663                 error "Locked pages remain in cache, locked=$LOCKED"
7664         fi
7665
7666         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7667                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7668         fi
7669
7670         rm -f $DIR/$tfile
7671         echo "No pages locked after fsync"
7672
7673         reset_async
7674         return 0
7675 }
7676 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7677
7678 test_118h() {
7679         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7680         remote_ost_nodsh && skip "remote OST with nodsh" && return
7681
7682         reset_async
7683
7684         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7685         set_nodes_failloc "$(osts_nodes)" 0x20e
7686         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7687         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7688         RC=$?
7689
7690         set_nodes_failloc "$(osts_nodes)" 0
7691         if [[ $RC -eq 0 ]]; then
7692                 error "Must return error due to dropped pages, rc=$RC"
7693         fi
7694
7695         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7696         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7697         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7698                     grep -c writeback)
7699         if [[ $LOCKED -ne 0 ]]; then
7700                 error "Locked pages remain in cache, locked=$LOCKED"
7701         fi
7702
7703         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7704                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7705         fi
7706
7707         rm -f $DIR/$tfile
7708         echo "No pages locked after fsync"
7709
7710         return 0
7711 }
7712 run_test 118h "Verify timeout in handling recoverables errors  =========="
7713
7714 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7715
7716 test_118i() {
7717         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7718         remote_ost_nodsh && skip "remote OST with nodsh" && return
7719
7720         reset_async
7721
7722         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7723         set_nodes_failloc "$(osts_nodes)" 0x20e
7724
7725         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7726         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7727         PID=$!
7728         sleep 5
7729         set_nodes_failloc "$(osts_nodes)" 0
7730
7731         wait $PID
7732         RC=$?
7733         if [[ $RC -ne 0 ]]; then
7734                 error "got error, but should be not, rc=$RC"
7735         fi
7736
7737         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7738         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7739         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7740         if [[ $LOCKED -ne 0 ]]; then
7741                 error "Locked pages remain in cache, locked=$LOCKED"
7742         fi
7743
7744         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7745                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7746         fi
7747
7748         rm -f $DIR/$tfile
7749         echo "No pages locked after fsync"
7750
7751         return 0
7752 }
7753 run_test 118i "Fix error before timeout in recoverable error  =========="
7754
7755 [ "$SLOW" = "no" ] && set_resend_count 4
7756
7757 test_118j() {
7758         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7759         remote_ost_nodsh && skip "remote OST with nodsh" && return
7760
7761         reset_async
7762
7763         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7764         set_nodes_failloc "$(osts_nodes)" 0x220
7765
7766         # return -EIO from OST
7767         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7768         RC=$?
7769         set_nodes_failloc "$(osts_nodes)" 0x0
7770         if [[ $RC -eq 0 ]]; then
7771                 error "Must return error due to dropped pages, rc=$RC"
7772         fi
7773
7774         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7775         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7776         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7777         if [[ $LOCKED -ne 0 ]]; then
7778                 error "Locked pages remain in cache, locked=$LOCKED"
7779         fi
7780
7781         # in recoverable error on OST we want resend and stay until it finished
7782         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7783                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7784         fi
7785
7786         rm -f $DIR/$tfile
7787         echo "No pages locked after fsync"
7788
7789         return 0
7790 }
7791 run_test 118j "Simulate unrecoverable OST side error =========="
7792
7793 test_118k()
7794 {
7795         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7796         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7797
7798         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7799         set_nodes_failloc "$(osts_nodes)" 0x20e
7800         test_mkdir -p $DIR/$tdir
7801
7802         for ((i=0;i<10;i++)); do
7803                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7804                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7805                 SLEEPPID=$!
7806                 sleep 0.500s
7807                 kill $SLEEPPID
7808                 wait $SLEEPPID
7809         done
7810
7811         set_nodes_failloc "$(osts_nodes)" 0
7812         rm -rf $DIR/$tdir
7813 }
7814 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7815
7816 test_118l()
7817 {
7818         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7819         # LU-646
7820         test_mkdir -p $DIR/$tdir
7821         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7822         rm -rf $DIR/$tdir
7823 }
7824 run_test 118l "fsync dir ========="
7825
7826 test_118m() # LU-3066
7827 {
7828         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7829         test_mkdir -p $DIR/$tdir
7830         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7831         rm -rf $DIR/$tdir
7832 }
7833 run_test 118m "fdatasync dir ========="
7834
7835 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7836
7837 test_119a() # bug 11737
7838 {
7839         BSIZE=$((512 * 1024))
7840         directio write $DIR/$tfile 0 1 $BSIZE
7841         # We ask to read two blocks, which is more than a file size.
7842         # directio will indicate an error when requested and actual
7843         # sizes aren't equeal (a normal situation in this case) and
7844         # print actual read amount.
7845         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7846         if [ "$NOB" != "$BSIZE" ]; then
7847                 error "read $NOB bytes instead of $BSIZE"
7848         fi
7849         rm -f $DIR/$tfile
7850 }
7851 run_test 119a "Short directIO read must return actual read amount"
7852
7853 test_119b() # bug 11737
7854 {
7855         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7856
7857         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7858         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7859         sync
7860         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7861                 error "direct read failed"
7862         rm -f $DIR/$tfile
7863 }
7864 run_test 119b "Sparse directIO read must return actual read amount"
7865
7866 test_119c() # bug 13099
7867 {
7868         BSIZE=1048576
7869         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7870         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7871         rm -f $DIR/$tfile
7872 }
7873 run_test 119c "Testing for direct read hitting hole"
7874
7875 test_119d() # bug 15950
7876 {
7877         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7878         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7879         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7880         BSIZE=1048576
7881         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7882         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7883         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7884         lctl set_param fail_loc=0x40d
7885         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7886         pid_dio=$!
7887         sleep 1
7888         cat $DIR/$tfile > /dev/null &
7889         lctl set_param fail_loc=0
7890         pid_reads=$!
7891         wait $pid_dio
7892         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7893         sleep 2
7894         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7895         error "the read rpcs have not completed in 2s"
7896         rm -f $DIR/$tfile
7897         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7898 }
7899 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7900
7901 test_120a() {
7902         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7903         test_mkdir -p $DIR/$tdir
7904         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7905                skip "no early lock cancel on server" && return 0
7906
7907         lru_resize_disable mdc
7908         lru_resize_disable osc
7909         cancel_lru_locks mdc
7910         # asynchronous object destroy at MDT could cause bl ast to client
7911         cancel_lru_locks osc
7912
7913         stat $DIR/$tdir > /dev/null
7914         can1=$(do_facet $SINGLEMDS \
7915                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7916                awk '/ldlm_cancel/ {print $2}')
7917         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7918                awk '/ldlm_bl_callback/ {print $2}')
7919         test_mkdir -c1 $DIR/$tdir/d1
7920         can2=$(do_facet $SINGLEMDS \
7921                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7922                awk '/ldlm_cancel/ {print $2}')
7923         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7924                awk '/ldlm_bl_callback/ {print $2}')
7925         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7926         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7927         lru_resize_enable mdc
7928         lru_resize_enable osc
7929 }
7930 run_test 120a "Early Lock Cancel: mkdir test"
7931
7932 test_120b() {
7933         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7934         test_mkdir $DIR/$tdir
7935         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7936                skip "no early lock cancel on server" && return 0
7937         lru_resize_disable mdc
7938         lru_resize_disable osc
7939         cancel_lru_locks mdc
7940         stat $DIR/$tdir > /dev/null
7941         can1=$(do_facet $SINGLEMDS \
7942                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7943                awk '/ldlm_cancel/ {print $2}')
7944         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7945                awk '/ldlm_bl_callback/ {print $2}')
7946         touch $DIR/$tdir/f1
7947         can2=$(do_facet $SINGLEMDS \
7948                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7949                awk '/ldlm_cancel/ {print $2}')
7950         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7951                awk '/ldlm_bl_callback/ {print $2}')
7952         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7953         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7954         lru_resize_enable mdc
7955         lru_resize_enable osc
7956 }
7957 run_test 120b "Early Lock Cancel: create test"
7958
7959 test_120c() {
7960         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7961         test_mkdir -c1 $DIR/$tdir
7962         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7963                skip "no early lock cancel on server" && return 0
7964         lru_resize_disable mdc
7965         lru_resize_disable osc
7966         test_mkdir -p -c1 $DIR/$tdir/d1
7967         test_mkdir -p -c1 $DIR/$tdir/d2
7968         touch $DIR/$tdir/d1/f1
7969         cancel_lru_locks mdc
7970         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7971         can1=$(do_facet $SINGLEMDS \
7972                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7973                awk '/ldlm_cancel/ {print $2}')
7974         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7975                awk '/ldlm_bl_callback/ {print $2}')
7976         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7977         can2=$(do_facet $SINGLEMDS \
7978                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7979                awk '/ldlm_cancel/ {print $2}')
7980         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7981                awk '/ldlm_bl_callback/ {print $2}')
7982         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7983         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7984         lru_resize_enable mdc
7985         lru_resize_enable osc
7986 }
7987 run_test 120c "Early Lock Cancel: link test"
7988
7989 test_120d() {
7990         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7991         test_mkdir -p -c1 $DIR/$tdir
7992         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7993                skip "no early lock cancel on server" && return 0
7994         lru_resize_disable mdc
7995         lru_resize_disable osc
7996         touch $DIR/$tdir
7997         cancel_lru_locks mdc
7998         stat $DIR/$tdir > /dev/null
7999         can1=$(do_facet $SINGLEMDS \
8000                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8001                awk '/ldlm_cancel/ {print $2}')
8002         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8003                awk '/ldlm_bl_callback/ {print $2}')
8004         chmod a+x $DIR/$tdir
8005         can2=$(do_facet $SINGLEMDS \
8006                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8007                awk '/ldlm_cancel/ {print $2}')
8008         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8009                awk '/ldlm_bl_callback/ {print $2}')
8010         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8011         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8012         lru_resize_enable mdc
8013         lru_resize_enable osc
8014 }
8015 run_test 120d "Early Lock Cancel: setattr test"
8016
8017 test_120e() {
8018         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8019         test_mkdir -p -c1 $DIR/$tdir
8020         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8021                skip "no early lock cancel on server" && return 0
8022         lru_resize_disable mdc
8023         lru_resize_disable osc
8024         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
8025         cancel_lru_locks mdc
8026         cancel_lru_locks osc
8027         dd if=$DIR/$tdir/f1 of=/dev/null
8028         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
8029         # XXX client can not do early lock cancel of OST lock
8030         # during unlink (LU-4206), so cancel osc lock now.
8031         cancel_lru_locks osc
8032         can1=$(do_facet $SINGLEMDS \
8033                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8034                awk '/ldlm_cancel/ {print $2}')
8035         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8036                awk '/ldlm_bl_callback/ {print $2}')
8037         unlink $DIR/$tdir/f1
8038         sleep 5
8039         can2=$(do_facet $SINGLEMDS \
8040                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8041                awk '/ldlm_cancel/ {print $2}')
8042         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8043                awk '/ldlm_bl_callback/ {print $2}')
8044         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8045         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8046         lru_resize_enable mdc
8047         lru_resize_enable osc
8048 }
8049 run_test 120e "Early Lock Cancel: unlink test"
8050
8051 test_120f() {
8052         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8053         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8054                skip "no early lock cancel on server" && return 0
8055         test_mkdir -p -c1 $DIR/$tdir
8056         lru_resize_disable mdc
8057         lru_resize_disable osc
8058         test_mkdir -p -c1 $DIR/$tdir/d1
8059         test_mkdir -p -c1 $DIR/$tdir/d2
8060         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
8061         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
8062         cancel_lru_locks mdc
8063         cancel_lru_locks osc
8064         dd if=$DIR/$tdir/d1/f1 of=/dev/null
8065         dd if=$DIR/$tdir/d2/f2 of=/dev/null
8066         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
8067         # XXX client can not do early lock cancel of OST lock
8068         # during rename (LU-4206), so cancel osc lock now.
8069         cancel_lru_locks osc
8070         can1=$(do_facet $SINGLEMDS \
8071                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8072                awk '/ldlm_cancel/ {print $2}')
8073         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8074                awk '/ldlm_bl_callback/ {print $2}')
8075         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8076         sleep 5
8077         can2=$(do_facet $SINGLEMDS \
8078                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8079                awk '/ldlm_cancel/ {print $2}')
8080         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8081                awk '/ldlm_bl_callback/ {print $2}')
8082         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8083         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8084         lru_resize_enable mdc
8085         lru_resize_enable osc
8086 }
8087 run_test 120f "Early Lock Cancel: rename test"
8088
8089 test_120g() {
8090         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8091         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8092                skip "no early lock cancel on server" && return 0
8093         lru_resize_disable mdc
8094         lru_resize_disable osc
8095         count=10000
8096         echo create $count files
8097         test_mkdir -p $DIR/$tdir
8098         cancel_lru_locks mdc
8099         cancel_lru_locks osc
8100         t0=`date +%s`
8101
8102         can0=$(do_facet $SINGLEMDS \
8103                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8104                awk '/ldlm_cancel/ {print $2}')
8105         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8106                awk '/ldlm_bl_callback/ {print $2}')
8107         createmany -o $DIR/$tdir/f $count
8108         sync
8109         can1=$(do_facet $SINGLEMDS \
8110                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8111                awk '/ldlm_cancel/ {print $2}')
8112         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8113                awk '/ldlm_bl_callback/ {print $2}')
8114         t1=$(date +%s)
8115         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
8116         echo rm $count files
8117         rm -r $DIR/$tdir
8118         sync
8119         can2=$(do_facet $SINGLEMDS \
8120                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8121                awk '/ldlm_cancel/ {print $2}')
8122         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8123                awk '/ldlm_bl_callback/ {print $2}')
8124         t2=$(date +%s)
8125         echo total: $count removes in $((t2-t1))
8126         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
8127         sleep 2
8128         # wait for commitment of removal
8129         lru_resize_enable mdc
8130         lru_resize_enable osc
8131 }
8132 run_test 120g "Early Lock Cancel: performance test"
8133
8134 test_121() { #bug #10589
8135         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8136         rm -rf $DIR/$tfile
8137         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8138 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8139         lctl set_param fail_loc=0x310
8140         cancel_lru_locks osc > /dev/null
8141         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8142         lctl set_param fail_loc=0
8143         [[ $reads -eq $writes ]] ||
8144                 error "read $reads blocks, must be $writes blocks"
8145 }
8146 run_test 121 "read cancel race ========="
8147
8148 test_123a() { # was test 123, statahead(bug 11401)
8149         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8150         SLOWOK=0
8151         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8152             log "testing on UP system. Performance may be not as good as expected."
8153                         SLOWOK=1
8154         fi
8155
8156         rm -rf $DIR/$tdir
8157         test_mkdir -p $DIR/$tdir
8158         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8159         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8160         MULT=10
8161         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8162                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8163
8164                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8165                 lctl set_param -n llite.*.statahead_max 0
8166                 lctl get_param llite.*.statahead_max
8167                 cancel_lru_locks mdc
8168                 cancel_lru_locks osc
8169                 stime=`date +%s`
8170                 time ls -l $DIR/$tdir | wc -l
8171                 etime=`date +%s`
8172                 delta=$((etime - stime))
8173                 log "ls $i files without statahead: $delta sec"
8174                 lctl set_param llite.*.statahead_max=$max
8175
8176                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8177                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8178                 cancel_lru_locks mdc
8179                 cancel_lru_locks osc
8180                 stime=`date +%s`
8181                 time ls -l $DIR/$tdir | wc -l
8182                 etime=`date +%s`
8183                 delta_sa=$((etime - stime))
8184                 log "ls $i files with statahead: $delta_sa sec"
8185                 lctl get_param -n llite.*.statahead_stats
8186                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8187
8188                 [[ $swrong -lt $ewrong ]] &&
8189                         log "statahead was stopped, maybe too many locks held!"
8190                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8191
8192                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8193                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8194                     lctl set_param -n llite.*.statahead_max 0
8195                     lctl get_param llite.*.statahead_max
8196                     cancel_lru_locks mdc
8197                     cancel_lru_locks osc
8198                     stime=`date +%s`
8199                     time ls -l $DIR/$tdir | wc -l
8200                     etime=`date +%s`
8201                     delta=$((etime - stime))
8202                     log "ls $i files again without statahead: $delta sec"
8203                     lctl set_param llite.*.statahead_max=$max
8204                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8205                         if [  $SLOWOK -eq 0 ]; then
8206                                 error "ls $i files is slower with statahead!"
8207                         else
8208                                 log "ls $i files is slower with statahead!"
8209                         fi
8210                         break
8211                     fi
8212                 fi
8213
8214                 [ $delta -gt 20 ] && break
8215                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8216                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8217         done
8218         log "ls done"
8219
8220         stime=`date +%s`
8221         rm -r $DIR/$tdir
8222         sync
8223         etime=`date +%s`
8224         delta=$((etime - stime))
8225         log "rm -r $DIR/$tdir/: $delta seconds"
8226         log "rm done"
8227         lctl get_param -n llite.*.statahead_stats
8228 }
8229 run_test 123a "verify statahead work"
8230
8231 test_123b () { # statahead(bug 15027)
8232         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8233         test_mkdir -p $DIR/$tdir
8234         createmany -o $DIR/$tdir/$tfile-%d 1000
8235
8236         cancel_lru_locks mdc
8237         cancel_lru_locks osc
8238
8239 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8240         lctl set_param fail_loc=0x80000803
8241         ls -lR $DIR/$tdir > /dev/null
8242         log "ls done"
8243         lctl set_param fail_loc=0x0
8244         lctl get_param -n llite.*.statahead_stats
8245         rm -r $DIR/$tdir
8246         sync
8247
8248 }
8249 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8250
8251 test_124a() {
8252         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8253         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8254                 skip "no lru resize on server" && return 0
8255         local NR=2000
8256         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8257
8258         log "create $NR files at $DIR/$tdir"
8259         createmany -o $DIR/$tdir/f $NR ||
8260                 error "failed to create $NR files in $DIR/$tdir"
8261
8262         cancel_lru_locks mdc
8263         ls -l $DIR/$tdir > /dev/null
8264
8265         local NSDIR=""
8266         local LRU_SIZE=0
8267         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8268                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8269                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8270                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8271                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8272                         log "NSDIR=$NSDIR"
8273                         log "NS=$(basename $NSDIR)"
8274                         break
8275                 fi
8276         done
8277
8278         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8279                 skip "Not enough cached locks created!"
8280                 return 0
8281         fi
8282         log "LRU=$LRU_SIZE"
8283
8284         local SLEEP=30
8285
8286         # We know that lru resize allows one client to hold $LIMIT locks
8287         # for 10h. After that locks begin to be killed by client.
8288         local MAX_HRS=10
8289         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8290         log "LIMIT=$LIMIT"
8291         if [ $LIMIT -lt $LRU_SIZE ]; then
8292             skip "Limit is too small $LIMIT"
8293             return 0
8294         fi
8295
8296         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8297         # killing locks. Some time was spent for creating locks. This means
8298         # that up to the moment of sleep finish we must have killed some of
8299         # them (10-100 locks). This depends on how fast ther were created.
8300         # Many of them were touched in almost the same moment and thus will
8301         # be killed in groups.
8302         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8303
8304         # Use $LRU_SIZE_B here to take into account real number of locks
8305         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8306         local LRU_SIZE_B=$LRU_SIZE
8307         log "LVF=$LVF"
8308         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8309         log "OLD_LVF=$OLD_LVF"
8310         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8311
8312         # Let's make sure that we really have some margin. Client checks
8313         # cached locks every 10 sec.
8314         SLEEP=$((SLEEP+20))
8315         log "Sleep ${SLEEP} sec"
8316         local SEC=0
8317         while ((SEC<$SLEEP)); do
8318                 echo -n "..."
8319                 sleep 5
8320                 SEC=$((SEC+5))
8321                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8322                 echo -n "$LRU_SIZE"
8323         done
8324         echo ""
8325         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8326         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8327
8328         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8329                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8330                 unlinkmany $DIR/$tdir/f $NR
8331                 return
8332         }
8333
8334         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8335         log "unlink $NR files at $DIR/$tdir"
8336         unlinkmany $DIR/$tdir/f $NR
8337 }
8338 run_test 124a "lru resize ======================================="
8339
8340 get_max_pool_limit()
8341 {
8342         local limit=$($LCTL get_param \
8343                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8344         local max=0
8345         for l in $limit; do
8346                 if [[ $l -gt $max ]]; then
8347                         max=$l
8348                 fi
8349         done
8350         echo $max
8351 }
8352
8353 test_124b() {
8354         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8355         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8356                 skip "no lru resize on server" && return 0
8357
8358         LIMIT=$(get_max_pool_limit)
8359
8360         NR=$(($(default_lru_size)*20))
8361         if [[ $NR -gt $LIMIT ]]; then
8362                 log "Limit lock number by $LIMIT locks"
8363                 NR=$LIMIT
8364         fi
8365         lru_resize_disable mdc
8366         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8367                 error "failed to create $DIR/$tdir/disable_lru_resize"
8368
8369         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8370         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8371         cancel_lru_locks mdc
8372         stime=`date +%s`
8373         PID=""
8374         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8375         PID="$PID $!"
8376         sleep 2
8377         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8378         PID="$PID $!"
8379         sleep 2
8380         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8381         PID="$PID $!"
8382         wait $PID
8383         etime=`date +%s`
8384         nolruresize_delta=$((etime-stime))
8385         log "ls -la time: $nolruresize_delta seconds"
8386         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8387         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8388
8389         lru_resize_enable mdc
8390         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8391                 error "failed to create $DIR/$tdir/enable_lru_resize"
8392
8393         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8394         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8395         cancel_lru_locks mdc
8396         stime=`date +%s`
8397         PID=""
8398         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8399         PID="$PID $!"
8400         sleep 2
8401         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8402         PID="$PID $!"
8403         sleep 2
8404         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8405         PID="$PID $!"
8406         wait $PID
8407         etime=`date +%s`
8408         lruresize_delta=$((etime-stime))
8409         log "ls -la time: $lruresize_delta seconds"
8410         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8411
8412         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8413                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8414         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8415                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8416         else
8417                 log "lru resize performs the same with no lru resize"
8418         fi
8419         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8420 }
8421 run_test 124b "lru resize (performance test) ======================="
8422
8423 test_124c() {
8424         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8425         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8426                 skip "no lru resize on server" && return 0
8427
8428         # cache ununsed locks on client
8429         local nr=100
8430         cancel_lru_locks mdc
8431         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8432         createmany -o $DIR/$tdir/f $nr ||
8433                 error "failed to create $nr files in $DIR/$tdir"
8434         ls -l $DIR/$tdir > /dev/null
8435
8436         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
8437         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
8438         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
8439         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
8440         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
8441
8442         # set lru_max_age to 1 sec
8443         $LCTL set_param $nsdir.lru_max_age=1000 # jiffies
8444         echo "sleep $((recalc_p * 2)) seconds..."
8445         sleep $((recalc_p * 2))
8446
8447         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
8448         # restore lru_max_age
8449         $LCTL set_param -n $nsdir.lru_max_age $max_age
8450         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
8451         unlinkmany $DIR/$tdir/f $nr
8452 }
8453 run_test 124c "LRUR cancel very aged locks"
8454
8455 test_125() { # 13358
8456         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8457         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8458         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8459         test_mkdir -p $DIR/d125 || error "mkdir failed"
8460         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8461         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8462         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8463 }
8464 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8465
8466 test_126() { # bug 12829/13455
8467         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8468         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8469         $GSS && skip "must run as gss disabled" && return
8470
8471         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8472         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8473         rm -f $DIR/$tfile
8474         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8475 }
8476 run_test 126 "check that the fsgid provided by the client is taken into account"
8477
8478 test_127a() { # bug 15521
8479         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8480         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8481         $LCTL set_param osc.*.stats=0
8482         FSIZE=$((2048 * 1024))
8483         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8484         cancel_lru_locks osc
8485         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8486
8487         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8488         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8489                 echo "got $COUNT $NAME"
8490                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8491                 eval $NAME=$COUNT || error "Wrong proc format"
8492
8493                 case $NAME in
8494                         read_bytes|write_bytes)
8495                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8496                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8497                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8498                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8499                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8500                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8501                                 error "sumsquare is too small: $SUMSQ"
8502                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8503                                 error "sumsquare is too big: $SUMSQ"
8504                         ;;
8505                         *) ;;
8506                 esac
8507         done < $DIR/${tfile}.tmp
8508
8509         #check that we actually got some stats
8510         [ "$read_bytes" ] || error "Missing read_bytes stats"
8511         [ "$write_bytes" ] || error "Missing write_bytes stats"
8512         [ "$read_bytes" != 0 ] || error "no read done"
8513         [ "$write_bytes" != 0 ] || error "no write done"
8514 }
8515 run_test 127a "verify the client stats are sane"
8516
8517 test_127b() { # bug LU-333
8518         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8519         $LCTL set_param llite.*.stats=0
8520         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8521         # perform 2 reads and writes so MAX is different from SUM.
8522         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8523         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8524         cancel_lru_locks osc
8525         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8526         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8527
8528         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8529         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8530                 echo "got $COUNT $NAME"
8531                 eval $NAME=$COUNT || error "Wrong proc format"
8532
8533         case $NAME in
8534                 read_bytes)
8535                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8536                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8537                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8538                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8539                         ;;
8540                 write_bytes)
8541                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8542                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8543                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8544                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8545                         ;;
8546                         *) ;;
8547                 esac
8548         done < $TMP/${tfile}.tmp
8549
8550         #check that we actually got some stats
8551         [ "$read_bytes" ] || error "Missing read_bytes stats"
8552         [ "$write_bytes" ] || error "Missing write_bytes stats"
8553         [ "$read_bytes" != 0 ] || error "no read done"
8554         [ "$write_bytes" != 0 ] || error "no write done"
8555 }
8556 run_test 127b "verify the llite client stats are sane"
8557
8558 test_128() { # bug 15212
8559         touch $DIR/$tfile
8560         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8561                 find $DIR/$tfile
8562                 find $DIR/$tfile
8563         EOF
8564
8565         result=$(grep error $TMP/$tfile.log)
8566         rm -f $DIR/$tfile
8567         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8568 }
8569 run_test 128 "interactive lfs for 2 consecutive find's"
8570
8571 set_dir_limits () {
8572         local mntdev
8573         local canondev
8574         local node
8575
8576         local LDPROC=/proc/fs/ldiskfs
8577         local facets=$(get_facets MDS)
8578
8579         for facet in ${facets//,/ }; do
8580                 canondev=$(ldiskfs_canon \
8581                            *.$(convert_facet2label $facet).mntdev $facet)
8582                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8583                                                 LDPROC=/sys/fs/ldiskfs
8584                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8585         done
8586 }
8587
8588 test_129() {
8589         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8590         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8591                 skip "Only applicable to ldiskfs-based MDTs"
8592                 return
8593         fi
8594         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8595         ENOSPC=28
8596         EFBIG=27
8597
8598         rm -rf $DIR/$tdir
8599         test_mkdir -p $DIR/$tdir
8600
8601         # block size of mds1
8602         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8603         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8604         local MAX=$((MDSBLOCKSIZE * 3))
8605         set_dir_limits $MAX
8606         local I=$(stat -c%s "$DIR/$tdir")
8607         local J=0
8608         local STRIPE_COUNT=1
8609         [[ $MDSCOUNT -ge 2 ]] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8610         MAX=$((MAX*STRIPE_COUNT))
8611         while [[ $I -le $MAX ]]; do
8612                 $MULTIOP $DIR/$tdir/$J Oc
8613                 rc=$?
8614                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8615                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8616                 #and EFBIG for previous versions
8617                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8618                         set_dir_limits 0
8619                         echo "return code $rc received as expected"
8620                         multiop $DIR/$tdir/$J Oc ||
8621                                 error_exit "multiop failed w/o dir size limit"
8622
8623                         I=$(stat -c%s "$DIR/$tdir")
8624
8625                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8626                                         $(version_code 2.4.51) ]
8627                         then
8628                                 [[ $I -eq $MAX ]] && return 0
8629                         else
8630                                 [[ $I -gt $MAX ]] && return 0
8631                         fi
8632                         error_exit "current dir size $I, previous limit $MAX"
8633                 elif [ $rc -ne 0 ]; then
8634                         set_dir_limits 0
8635                         error_exit "return code $rc received instead of expected " \
8636                                    "$EFBIG or $ENOSPC, files in dir $I"
8637                 fi
8638                 J=$((J+1))
8639                 I=$(stat -c%s "$DIR/$tdir")
8640         done
8641
8642         set_dir_limits 0
8643         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8644 }
8645 run_test 129 "test directory size limit ========================"
8646
8647 OLDIFS="$IFS"
8648 cleanup_130() {
8649         trap 0
8650         IFS="$OLDIFS"
8651 }
8652
8653 test_130a() {
8654         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8655         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8656                 return
8657
8658         trap cleanup_130 EXIT RETURN
8659
8660         local fm_file=$DIR/$tfile
8661         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8662         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8663                 error "dd failed for $fm_file"
8664
8665         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8666         filefrag -ves $fm_file
8667         RC=$?
8668         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8669                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8670         [ $RC != 0 ] && error "filefrag $fm_file failed"
8671
8672         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8673                       grep -v "ext:" | grep -v "found")
8674         lun=$($GETSTRIPE -i $fm_file)
8675
8676         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8677         IFS=$'\n'
8678         tot_len=0
8679         for line in $filefrag_op
8680         do
8681                 frag_lun=`echo $line | cut -d: -f5`
8682                 ext_len=`echo $line | cut -d: -f4`
8683                 if (( $frag_lun != $lun )); then
8684                         cleanup_130
8685                         error "FIEMAP on 1-stripe file($fm_file) failed"
8686                         return
8687                 fi
8688                 (( tot_len += ext_len ))
8689         done
8690
8691         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8692                 cleanup_130
8693                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8694                 return
8695         fi
8696
8697         cleanup_130
8698
8699         echo "FIEMAP on single striped file succeeded"
8700 }
8701 run_test 130a "FIEMAP (1-stripe file)"
8702
8703 test_130b() {
8704         [ "$OSTCOUNT" -lt "2" ] &&
8705                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8706
8707         [ "$OSTCOUNT" -ge "10" ] &&
8708                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8709
8710         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8711         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8712                 return
8713
8714         trap cleanup_130 EXIT RETURN
8715
8716         local fm_file=$DIR/$tfile
8717         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8718         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8719                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8720
8721         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8722                 error "dd failed on $fm_file"
8723
8724         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8725         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8726                       grep -v "ext:" | grep -v "found")
8727
8728         last_lun=$(echo $filefrag_op | cut -d: -f5)
8729
8730         IFS=$'\n'
8731         tot_len=0
8732         num_luns=1
8733         for line in $filefrag_op
8734         do
8735                 frag_lun=`echo $line | cut -d: -f5`
8736                 ext_len=`echo $line | cut -d: -f4`
8737                 if (( $frag_lun != $last_lun )); then
8738                         if (( tot_len != 1024 )); then
8739                                 cleanup_130
8740                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8741                                 return
8742                         else
8743                                 (( num_luns += 1 ))
8744                                 tot_len=0
8745                         fi
8746                 fi
8747                 (( tot_len += ext_len ))
8748                 last_lun=$frag_lun
8749         done
8750         if (( num_luns != 2 || tot_len != 1024 )); then
8751                 cleanup_130
8752                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8753                 return
8754         fi
8755
8756         cleanup_130
8757
8758         echo "FIEMAP on 2-stripe file succeeded"
8759 }
8760 run_test 130b "FIEMAP (2-stripe file)"
8761
8762 test_130c() {
8763         [ "$OSTCOUNT" -lt "2" ] &&
8764                 skip_env "skipping FIEMAP on 2-stripe file" && return
8765
8766         [ "$OSTCOUNT" -ge "10" ] &&
8767                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8768
8769         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8770         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8771                 return
8772
8773         trap cleanup_130 EXIT RETURN
8774
8775         local fm_file=$DIR/$tfile
8776         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8777         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8778                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8779
8780         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8781
8782         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8783         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8784
8785         last_lun=`echo $filefrag_op | cut -d: -f5`
8786
8787         IFS=$'\n'
8788         tot_len=0
8789         num_luns=1
8790         for line in $filefrag_op
8791         do
8792                 frag_lun=`echo $line | cut -d: -f5`
8793                 ext_len=`echo $line | cut -d: -f4`
8794                 if (( $frag_lun != $last_lun )); then
8795                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8796                         if (( logical != 512 )); then
8797                                 cleanup_130
8798                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8799                                 return
8800                         fi
8801                         if (( tot_len != 512 )); then
8802                                 cleanup_130
8803                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8804                                 return
8805                         else
8806                                 (( num_luns += 1 ))
8807                                 tot_len=0
8808                         fi
8809                 fi
8810                 (( tot_len += ext_len ))
8811                 last_lun=$frag_lun
8812         done
8813         if (( num_luns != 2 || tot_len != 512 )); then
8814                 cleanup_130
8815                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8816                 return
8817         fi
8818
8819         cleanup_130
8820
8821         echo "FIEMAP on 2-stripe file with hole succeeded"
8822 }
8823 run_test 130c "FIEMAP (2-stripe file with hole)"
8824
8825 test_130d() {
8826         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8827
8828         [ "$OSTCOUNT" -ge "10" ] &&
8829                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8830
8831         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8832         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8833
8834         trap cleanup_130 EXIT RETURN
8835
8836         local fm_file=$DIR/$tfile
8837         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8838         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8839                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8840
8841         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8842         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8843                 error "dd failed on $fm_file"
8844
8845         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8846         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8847                 grep -v "ext:" | grep -v "found"`
8848
8849         last_lun=`echo $filefrag_op | cut -d: -f5`
8850
8851         IFS=$'\n'
8852         tot_len=0
8853         num_luns=1
8854         for line in $filefrag_op
8855         do
8856                 frag_lun=`echo $line | cut -d: -f5`
8857                 ext_len=`echo $line | cut -d: -f4`
8858                 if (( $frag_lun != $last_lun )); then
8859                         if (( tot_len != 1024 )); then
8860                                 cleanup_130
8861                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8862                                 return
8863                         else
8864                                 (( num_luns += 1 ))
8865                                 tot_len=0
8866                         fi
8867                 fi
8868                 (( tot_len += ext_len ))
8869                 last_lun=$frag_lun
8870         done
8871         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8872                 cleanup_130
8873                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8874                 return
8875         fi
8876
8877         cleanup_130
8878
8879         echo "FIEMAP on N-stripe file succeeded"
8880 }
8881 run_test 130d "FIEMAP (N-stripe file)"
8882
8883 test_130e() {
8884         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8885
8886         [ "$OSTCOUNT" -ge "10" ] &&
8887                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8888
8889         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8890         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8891
8892         trap cleanup_130 EXIT RETURN
8893
8894         local fm_file=$DIR/$tfile
8895         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8896         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8897                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8898
8899         NUM_BLKS=512
8900         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8901         for ((i = 0; i < $NUM_BLKS; i++))
8902         do
8903                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8904         done
8905
8906         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8907         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8908
8909         last_lun=`echo $filefrag_op | cut -d: -f5`
8910
8911         IFS=$'\n'
8912         tot_len=0
8913         num_luns=1
8914         for line in $filefrag_op
8915         do
8916                 frag_lun=`echo $line | cut -d: -f5`
8917                 ext_len=`echo $line | cut -d: -f4`
8918                 if (( $frag_lun != $last_lun )); then
8919                         if (( tot_len != $EXPECTED_LEN )); then
8920                                 cleanup_130
8921                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8922                                 return
8923                         else
8924                                 (( num_luns += 1 ))
8925                                 tot_len=0
8926                         fi
8927                 fi
8928                 (( tot_len += ext_len ))
8929                 last_lun=$frag_lun
8930         done
8931         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8932                 cleanup_130
8933                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8934                 return
8935         fi
8936
8937         cleanup_130
8938
8939         echo "FIEMAP with continuation calls succeeded"
8940 }
8941 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8942
8943 # Test for writev/readv
8944 test_131a() {
8945         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8946         error "writev test failed"
8947         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8948         error "readv failed"
8949         rm -f $DIR/$tfile
8950 }
8951 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8952
8953 test_131b() {
8954         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8955         error "append writev test failed"
8956         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8957         error "append writev test failed"
8958         rm -f $DIR/$tfile
8959 }
8960 run_test 131b "test append writev"
8961
8962 test_131c() {
8963         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8964         error "NOT PASS"
8965 }
8966 run_test 131c "test read/write on file w/o objects"
8967
8968 test_131d() {
8969         rwv -f $DIR/$tfile -w -n 1 1572864
8970         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8971         if [ "$NOB" != 1572864 ]; then
8972                 error "Short read filed: read $NOB bytes instead of 1572864"
8973         fi
8974         rm -f $DIR/$tfile
8975 }
8976 run_test 131d "test short read"
8977
8978 test_131e() {
8979         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8980         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8981         error "read hitting hole failed"
8982         rm -f $DIR/$tfile
8983 }
8984 run_test 131e "test read hitting hole"
8985
8986 check_stats() {
8987         local res
8988         local count
8989         case $1 in
8990         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8991                  ;;
8992         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8993                  ;;
8994         *) error "Wrong argument $1" ;;
8995         esac
8996         echo $res
8997         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8998         # if the argument $3 is zero, it means any stat increment is ok.
8999         if [[ $3 -gt 0 ]]; then
9000                 count=$(echo $res | awk '{ print $2 }')
9001                 [[ $count -ne $3 ]] &&
9002                         error "The $2 counter on $1 is wrong - expected $3"
9003         fi
9004 }
9005
9006 test_133a() {
9007         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9008         remote_ost_nodsh && skip "remote OST with nodsh" && return
9009         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9010
9011         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9012                 { skip "MDS doesn't support rename stats"; return; }
9013         local testdir=$DIR/${tdir}/stats_testdir
9014         mkdir -p $DIR/${tdir}
9015
9016         # clear stats.
9017         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9018         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9019
9020         # verify mdt stats first.
9021         mkdir ${testdir} || error "mkdir failed"
9022         check_stats $SINGLEMDS "mkdir" 1
9023         touch ${testdir}/${tfile} || "touch failed"
9024         check_stats $SINGLEMDS "open" 1
9025         check_stats $SINGLEMDS "close" 1
9026         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
9027         check_stats $SINGLEMDS "mknod" 1
9028         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
9029         check_stats $SINGLEMDS "unlink" 1
9030         rm -f ${testdir}/${tfile} || error "file remove failed"
9031         check_stats $SINGLEMDS "unlink" 2
9032
9033         # remove working dir and check mdt stats again.
9034         rmdir ${testdir} || error "rmdir failed"
9035         check_stats $SINGLEMDS "rmdir" 1
9036
9037         local testdir1=$DIR/${tdir}/stats_testdir1
9038         mkdir -p ${testdir}
9039         mkdir -p ${testdir1}
9040         touch ${testdir1}/test1
9041         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
9042         check_stats $SINGLEMDS "crossdir_rename" 1
9043
9044         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
9045         check_stats $SINGLEMDS "samedir_rename" 1
9046
9047         rm -rf $DIR/${tdir}
9048 }
9049 run_test 133a "Verifying MDT stats ========================================"
9050
9051 test_133b() {
9052         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9053         remote_ost_nodsh && skip "remote OST with nodsh" && return
9054         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9055         local testdir=$DIR/${tdir}/stats_testdir
9056         mkdir -p ${testdir} || error "mkdir failed"
9057         touch ${testdir}/${tfile} || "touch failed"
9058         cancel_lru_locks mdc
9059
9060         # clear stats.
9061         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9062         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9063
9064         # extra mdt stats verification.
9065         chmod 444 ${testdir}/${tfile} || error "chmod failed"
9066         check_stats $SINGLEMDS "setattr" 1
9067         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9068         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
9069         then            # LU-1740
9070                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
9071                 check_stats $SINGLEMDS "getattr" 1
9072         fi
9073         $LFS df || error "lfs failed"
9074         check_stats $SINGLEMDS "statfs" 1
9075
9076         rm -rf $DIR/${tdir}
9077 }
9078 run_test 133b "Verifying extra MDT stats =================================="
9079
9080 test_133c() {
9081         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9082         remote_ost_nodsh && skip "remote OST with nodsh" && return
9083         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9084         local testdir=$DIR/${tdir}/stats_testdir
9085         test_mkdir -p ${testdir} || error "mkdir failed"
9086
9087         # verify obdfilter stats.
9088         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9089         sync
9090         cancel_lru_locks osc
9091         wait_delete_completed
9092
9093         # clear stats.
9094         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9095         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9096
9097         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
9098         sync
9099         cancel_lru_locks osc
9100         check_stats ost "write" 1
9101
9102         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9103         check_stats ost "read" 1
9104
9105         > ${testdir}/${tfile} || error "truncate failed"
9106         check_stats ost "punch" 1
9107
9108         rm -f ${testdir}/${tfile} || error "file remove failed"
9109         wait_delete_completed
9110         check_stats ost "destroy" 1
9111
9112         rm -rf $DIR/${tdir}
9113 }
9114 run_test 133c "Verifying OST stats ========================================"
9115
9116 order_2() {
9117         local value=$1
9118         local orig=$value
9119         local order=1
9120
9121         while [ $value -ge 2 ]; do
9122                 order=$((order*2))
9123                 value=$((value/2))
9124         done
9125
9126         if [ $orig -gt $order ]; then
9127                 order=$((order*2))
9128         fi
9129         echo $order
9130 }
9131
9132 size_in_KMGT() {
9133     local value=$1
9134     local size=('K' 'M' 'G' 'T');
9135     local i=0
9136     local size_string=$value
9137
9138     while [ $value -ge 1024 ]; do
9139         if [ $i -gt 3 ]; then
9140             #T is the biggest unit we get here, if that is bigger,
9141             #just return XXXT
9142             size_string=${value}T
9143             break
9144         fi
9145         value=$((value >> 10))
9146         if [ $value -lt 1024 ]; then
9147             size_string=${value}${size[$i]}
9148             break
9149         fi
9150         i=$((i + 1))
9151     done
9152
9153     echo $size_string
9154 }
9155
9156 get_rename_size() {
9157     local size=$1
9158     local context=${2:-.}
9159     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9160                 grep -A1 $context |
9161                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9162     echo $sample
9163 }
9164
9165 test_133d() {
9166         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9167         remote_ost_nodsh && skip "remote OST with nodsh" && return
9168         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9169         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9170         { skip "MDS doesn't support rename stats"; return; }
9171
9172         local testdir1=$DIR/${tdir}/stats_testdir1
9173         local testdir2=$DIR/${tdir}/stats_testdir2
9174
9175         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9176
9177         mkdir -p ${testdir1} || error "mkdir failed"
9178         mkdir -p ${testdir2} || error "mkdir failed"
9179
9180         createmany -o $testdir1/test 512 || error "createmany failed"
9181
9182         # check samedir rename size
9183         mv ${testdir1}/test0 ${testdir1}/test_0
9184
9185         local testdir1_size=$(ls -l $DIR/${tdir} |
9186                 awk '/stats_testdir1/ {print $5}')
9187         local testdir2_size=$(ls -l $DIR/${tdir} |
9188                 awk '/stats_testdir2/ {print $5}')
9189
9190         testdir1_size=$(order_2 $testdir1_size)
9191         testdir2_size=$(order_2 $testdir2_size)
9192
9193         testdir1_size=$(size_in_KMGT $testdir1_size)
9194         testdir2_size=$(size_in_KMGT $testdir2_size)
9195
9196         echo "source rename dir size: ${testdir1_size}"
9197         echo "target rename dir size: ${testdir2_size}"
9198
9199         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9200         eval $cmd || error "$cmd failed"
9201         local samedir=$($cmd | grep 'same_dir')
9202         local same_sample=$(get_rename_size $testdir1_size)
9203         [ -z "$samedir" ] && error "samedir_rename_size count error"
9204         [[ $same_sample -eq 1 ]] ||
9205                 error "samedir_rename_size error $same_sample"
9206         echo "Check same dir rename stats success"
9207
9208         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9209
9210         # check crossdir rename size
9211         mv ${testdir1}/test_0 ${testdir2}/test_0
9212
9213         testdir1_size=$(ls -l $DIR/${tdir} |
9214                 awk '/stats_testdir1/ {print $5}')
9215         testdir2_size=$(ls -l $DIR/${tdir} |
9216                 awk '/stats_testdir2/ {print $5}')
9217
9218         testdir1_size=$(order_2 $testdir1_size)
9219         testdir2_size=$(order_2 $testdir2_size)
9220
9221         testdir1_size=$(size_in_KMGT $testdir1_size)
9222         testdir2_size=$(size_in_KMGT $testdir2_size)
9223
9224         echo "source rename dir size: ${testdir1_size}"
9225         echo "target rename dir size: ${testdir2_size}"
9226
9227         eval $cmd || error "$cmd failed"
9228         local crossdir=$($cmd | grep 'crossdir')
9229         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9230         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9231         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9232         [[ $src_sample -eq 1 ]] ||
9233                 error "crossdir_rename_size error $src_sample"
9234         [[ $tgt_sample -eq 1 ]] ||
9235                 error "crossdir_rename_size error $tgt_sample"
9236         echo "Check cross dir rename stats success"
9237         rm -rf $DIR/${tdir}
9238 }
9239 run_test 133d "Verifying rename_stats ========================================"
9240
9241 test_133e() {
9242         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9243         remote_ost_nodsh && skip "remote OST with nodsh" && return
9244         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9245         local testdir=$DIR/${tdir}/stats_testdir
9246         local ctr f0 f1 bs=32768 count=42 sum
9247
9248         mkdir -p ${testdir} || error "mkdir failed"
9249
9250         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9251
9252         for ctr in {write,read}_bytes; do
9253                 sync
9254                 cancel_lru_locks osc
9255
9256                 do_facet ost1 $LCTL set_param -n \
9257                         "obdfilter.*.exports.clear=clear"
9258
9259                 if [ $ctr = write_bytes ]; then
9260                         f0=/dev/zero
9261                         f1=${testdir}/${tfile}
9262                 else
9263                         f0=${testdir}/${tfile}
9264                         f1=/dev/null
9265                 fi
9266
9267                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9268                         error "dd failed"
9269                 sync
9270                 cancel_lru_locks osc
9271
9272                 sum=$(do_facet ost1 $LCTL get_param \
9273                         "obdfilter.*.exports.*.stats" |
9274                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9275                                 $1 == ctr { sum += $7 }
9276                                 END { printf("%0.0f", sum) }')
9277
9278                 if ((sum != bs * count)); then
9279                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9280                 fi
9281         done
9282
9283         rm -rf $DIR/${tdir}
9284 }
9285 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9286
9287 test_133f() {
9288         local proc_dirs
9289
9290         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9291 /sys/fs/lustre/ /sys/fs/lnet/"
9292         local dir
9293         for dir in $dirs; do
9294                 if [ -d $dir ]; then
9295                         proc_dirs="$proc_dirs $dir"
9296                 fi
9297         done
9298
9299         local facet
9300
9301         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9302         remote_ost_nodsh && skip "remote OST with nodsh" && return
9303         # First without trusting modes.
9304         find $proc_dirs -exec cat '{}' \; &> /dev/null
9305
9306         # Second verifying readability.
9307         find $proc_dirs \
9308                 -type f \
9309                 -exec cat '{}' \; &> /dev/null ||
9310                         error "proc file read failed"
9311
9312         for facet in $SINGLEMDS ost1; do
9313                 do_facet $facet find $proc_dirs \
9314                         ! -name req_history \
9315                         -exec cat '{}' \\\; &> /dev/null
9316
9317                 do_facet $facet find $proc_dirs \
9318                         ! -name req_history \
9319                         -type f \
9320                         -exec cat '{}' \\\; &> /dev/null ||
9321                                 error "proc file read failed"
9322         done
9323 }
9324 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9325
9326 test_133g() {
9327         local proc_dirs
9328
9329         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9330 /sys/fs/lustre/ /sys/fs/lnet/"
9331         local dir
9332         for dir in $dirs; do
9333                 if [ -d $dir ]; then
9334                         proc_dirs="$proc_dirs $dir"
9335                 fi
9336         done
9337
9338         local facet
9339
9340         # Second verifying readability.
9341         find $proc_dirs \
9342                 -type f \
9343                 -not -name force_lbug \
9344                 -not -name changelog_mask \
9345                 -exec badarea_io '{}' \; &> /dev/null ||
9346                 error "find $proc_dirs failed"
9347
9348         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
9349                 skip "Too old lustre on MDS" && return
9350
9351         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
9352                 skip "Too old lustre on ost1" && return
9353
9354         for facet in $SINGLEMDS ost1; do
9355                 do_facet $facet find $proc_dirs \
9356                         -type f \
9357                         -not -name force_lbug \
9358                         -not -name changelog_mask \
9359                         -exec badarea_io '{}' \\\; &> /dev/null ||
9360                 error "$facet find $proc_dirs failed"
9361
9362         done
9363
9364         # remount the FS in case writes/reads /proc break the FS
9365         cleanup || error "failed to unmount"
9366         setup || error "failed to setup"
9367         true
9368 }
9369 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9370
9371 test_140() { #bug-17379
9372         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9373         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
9374         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
9375         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
9376
9377         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9378         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9379         local i=0
9380         while i=`expr $i + 1`; do
9381                 test_mkdir -p $i || error "Creating dir $i"
9382                 cd $i || error "Changing to $i"
9383                 ln -s ../stat stat || error "Creating stat symlink"
9384                 # Read the symlink until ELOOP present,
9385                 # not LBUGing the system is considered success,
9386                 # we didn't overrun the stack.
9387                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9388                 [ $ret -ne 0 ] && {
9389                         if [ $ret -eq 40 ]; then
9390                                 break  # -ELOOP
9391                         else
9392                                 error "Open stat symlink"
9393                                 return
9394                         fi
9395                 }
9396         done
9397         i=`expr $i - 1`
9398         echo "The symlink depth = $i"
9399         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9400                                         error "Invalid symlink depth"
9401
9402         # Test recursive symlink
9403         ln -s symlink_self symlink_self
9404         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9405         echo "open symlink_self returns $ret"
9406         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9407 }
9408 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9409
9410 test_150() {
9411         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9412         local TF="$TMP/$tfile"
9413
9414         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9415         cp $TF $DIR/$tfile
9416         cancel_lru_locks osc
9417         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9418         remount_client $MOUNT
9419         df -P $MOUNT
9420         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9421
9422         $TRUNCATE $TF 6000
9423         $TRUNCATE $DIR/$tfile 6000
9424         cancel_lru_locks osc
9425         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9426
9427         echo "12345" >>$TF
9428         echo "12345" >>$DIR/$tfile
9429         cancel_lru_locks osc
9430         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9431
9432         echo "12345" >>$TF
9433         echo "12345" >>$DIR/$tfile
9434         cancel_lru_locks osc
9435         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9436
9437         rm -f $TF
9438         true
9439 }
9440 run_test 150 "truncate/append tests"
9441
9442 #LU-2902 roc_hit was not able to read all values from lproc
9443 function roc_hit_init() {
9444         local list=$(comma_list $(osts_nodes))
9445         local dir=$DIR/$tdir-check
9446         local file=$dir/file
9447         local BEFORE
9448         local AFTER
9449         local idx
9450
9451         test_mkdir -p $dir
9452         #use setstripe to do a write to every ost
9453         for i in $(seq 0 $((OSTCOUNT-1))); do
9454                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9455                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9456                 idx=$(printf %04x $i)
9457                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9458                         awk '$1 == "cache_access" {sum += $7}
9459                                 END { printf("%0.0f", sum) }')
9460
9461                 cancel_lru_locks osc
9462                 cat $file >/dev/null
9463
9464                 AFTER=$(get_osd_param $list *OST*$idx stats |
9465                         awk '$1 == "cache_access" {sum += $7}
9466                                 END { printf("%0.0f", sum) }')
9467
9468                 echo BEFORE:$BEFORE AFTER:$AFTER
9469                 if ! let "AFTER - BEFORE == 4"; then
9470                         rm -rf $dir
9471                         error "roc_hit is not safe to use"
9472                 fi
9473                 rm $file
9474         done
9475
9476         rm -rf $dir
9477 }
9478
9479 function roc_hit() {
9480         local list=$(comma_list $(osts_nodes))
9481         echo $(get_osd_param $list '' stats |
9482                 awk '$1 == "cache_hit" {sum += $7}
9483                         END { printf("%0.0f", sum) }')
9484 }
9485
9486 function set_cache() {
9487         local on=1
9488
9489         if [ "$2" == "off" ]; then
9490                 on=0;
9491         fi
9492         local list=$(comma_list $(osts_nodes))
9493         set_osd_param $list '' $1_cache_enable $on
9494
9495         cancel_lru_locks osc
9496 }
9497
9498 test_151() {
9499         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9500         remote_ost_nodsh && skip "remote OST with nodsh" && return
9501
9502         local CPAGES=3
9503         local list=$(comma_list $(osts_nodes))
9504
9505         # check whether obdfilter is cache capable at all
9506         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9507                 echo "not cache-capable obdfilter"
9508                 return 0
9509         fi
9510
9511         # check cache is enabled on all obdfilters
9512         if get_osd_param $list '' read_cache_enable | grep 0; then
9513                 echo "oss cache is disabled"
9514                 return 0
9515         fi
9516
9517         set_osd_param $list '' writethrough_cache_enable 1
9518
9519         # check write cache is enabled on all obdfilters
9520         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9521                 echo "oss write cache is NOT enabled"
9522                 return 0
9523         fi
9524
9525         roc_hit_init
9526
9527         #define OBD_FAIL_OBD_NO_LRU  0x609
9528         do_nodes $list $LCTL set_param fail_loc=0x609
9529
9530         # pages should be in the case right after write
9531         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9532                 error "dd failed"
9533
9534         local BEFORE=$(roc_hit)
9535         cancel_lru_locks osc
9536         cat $DIR/$tfile >/dev/null
9537         local AFTER=$(roc_hit)
9538
9539         do_nodes $list $LCTL set_param fail_loc=0
9540
9541         if ! let "AFTER - BEFORE == CPAGES"; then
9542                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9543         fi
9544
9545         # the following read invalidates the cache
9546         cancel_lru_locks osc
9547         set_osd_param $list '' read_cache_enable 0
9548         cat $DIR/$tfile >/dev/null
9549
9550         # now data shouldn't be found in the cache
9551         BEFORE=$(roc_hit)
9552         cancel_lru_locks osc
9553         cat $DIR/$tfile >/dev/null
9554         AFTER=$(roc_hit)
9555         if let "AFTER - BEFORE != 0"; then
9556                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9557         fi
9558
9559         set_osd_param $list '' read_cache_enable 1
9560         rm -f $DIR/$tfile
9561 }
9562 run_test 151 "test cache on oss and controls ==============================="
9563
9564 test_152() {
9565         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9566         local TF="$TMP/$tfile"
9567
9568         # simulate ENOMEM during write
9569 #define OBD_FAIL_OST_NOMEM      0x226
9570         lctl set_param fail_loc=0x80000226
9571         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9572         cp $TF $DIR/$tfile
9573         sync || error "sync failed"
9574         lctl set_param fail_loc=0
9575
9576         # discard client's cache
9577         cancel_lru_locks osc
9578
9579         # simulate ENOMEM during read
9580         lctl set_param fail_loc=0x80000226
9581         cmp $TF $DIR/$tfile || error "cmp failed"
9582         lctl set_param fail_loc=0
9583
9584         rm -f $TF
9585 }
9586 run_test 152 "test read/write with enomem ============================"
9587
9588 test_153() {
9589         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9590 }
9591 run_test 153 "test if fdatasync does not crash ======================="
9592
9593 dot_lustre_fid_permission_check() {
9594         local fid=$1
9595         local ffid=$MOUNT/.lustre/fid/$fid
9596         local test_dir=$2
9597
9598         echo "stat fid $fid"
9599         stat $ffid > /dev/null || error "stat $ffid failed."
9600         echo "touch fid $fid"
9601         touch $ffid || error "touch $ffid failed."
9602         echo "write to fid $fid"
9603         cat /etc/hosts > $ffid || error "write $ffid failed."
9604         echo "read fid $fid"
9605         diff /etc/hosts $ffid || error "read $ffid failed."
9606         echo "append write to fid $fid"
9607         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9608         echo "rename fid $fid"
9609         mv $ffid $test_dir/$tfile.1 &&
9610                 error "rename $ffid to $tfile.1 should fail."
9611         touch $test_dir/$tfile.1
9612         mv $test_dir/$tfile.1 $ffid &&
9613                 error "rename $tfile.1 to $ffid should fail."
9614         rm -f $test_dir/$tfile.1
9615         echo "truncate fid $fid"
9616         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9617         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9618                 echo "link fid $fid"
9619                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9620         fi
9621         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9622                 echo "setfacl fid $fid"
9623                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9624                 echo "getfacl fid $fid"
9625                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9626         fi
9627         echo "unlink fid $fid"
9628         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9629         echo "mknod fid $fid"
9630         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9631
9632         fid=[0xf00000400:0x1:0x0]
9633         ffid=$MOUNT/.lustre/fid/$fid
9634
9635         echo "stat non-exist fid $fid"
9636         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9637         echo "write to non-exist fid $fid"
9638         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9639         echo "link new fid $fid"
9640         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9641
9642         mkdir -p $test_dir/$tdir
9643         touch $test_dir/$tdir/$tfile
9644         fid=$($LFS path2fid $test_dir/$tdir)
9645         rc=$?
9646         [ $rc -ne 0 ] &&
9647                 error "error: could not get fid for $test_dir/$dir/$tfile."
9648
9649         ffid=$MOUNT/.lustre/fid/$fid
9650
9651         echo "ls $fid"
9652         ls $ffid > /dev/null || error "ls $ffid failed."
9653         echo "touch $fid/$tfile.1"
9654         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9655
9656         echo "touch $MOUNT/.lustre/fid/$tfile"
9657         touch $MOUNT/.lustre/fid/$tfile && \
9658                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9659
9660         echo "setxattr to $MOUNT/.lustre/fid"
9661         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9662
9663         echo "listxattr for $MOUNT/.lustre/fid"
9664         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9665
9666         echo "delxattr from $MOUNT/.lustre/fid"
9667         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9668
9669         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9670         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9671                 error "touch invalid fid should fail."
9672
9673         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9674         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9675                 error "touch non-normal fid should fail."
9676
9677         echo "rename $tdir to $MOUNT/.lustre/fid"
9678         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9679                 error "rename to $MOUNT/.lustre/fid should fail."
9680
9681         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9682         then            # LU-3547
9683                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9684                 local new_obf_mode=777
9685
9686                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9687                 chmod $new_obf_mode $DIR/.lustre/fid ||
9688                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9689
9690                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9691                 [ $obf_mode -eq $new_obf_mode ] ||
9692                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9693
9694                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9695                 chmod $old_obf_mode $DIR/.lustre/fid ||
9696                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9697         fi
9698
9699         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9700         fid=$($LFS path2fid $test_dir/$tfile-2)
9701
9702         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
9703         then # LU-5424
9704                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9705                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
9706                         error "create lov data thru .lustre failed"
9707         fi
9708         echo "cp /etc/passwd $test_dir/$tfile-2"
9709         cp /etc/passwd $test_dir/$tfile-2 ||
9710                 error "copy to $test_dir/$tfile-2 failed."
9711         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9712         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9713                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9714
9715         rm -rf $test_dir/tfile.lnk
9716         rm -rf $test_dir/$tfile-2
9717 }
9718
9719 test_154A() {
9720         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9721                 skip "Need MDS version at least 2.4.1" && return
9722
9723         touch $DIR/$tfile
9724         local FID=$($LFS path2fid $DIR/$tfile)
9725         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9726
9727         # check that we get the same pathname back
9728         local FOUND=$($LFS fid2path $MOUNT "$FID")
9729         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9730         [ "$FOUND" != "$DIR/$tfile" ] &&
9731                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9732
9733         rm -rf $DIR/$tfile
9734 }
9735 run_test 154A "lfs path2fid and fid2path basic checks"
9736
9737 test_154a() {
9738         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9739         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9740                 { skip "Need MDS version at least 2.2.51"; return 0; }
9741         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9742
9743         cp /etc/hosts $DIR/$tfile
9744
9745         fid=$($LFS path2fid $DIR/$tfile)
9746         rc=$?
9747         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9748
9749         dot_lustre_fid_permission_check "$fid" $DIR ||
9750                 error "dot lustre permission check $fid failed"
9751
9752         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9753
9754         touch $MOUNT/.lustre/file &&
9755                 error "creation is not allowed under .lustre"
9756
9757         mkdir $MOUNT/.lustre/dir &&
9758                 error "mkdir is not allowed under .lustre"
9759
9760         rm -rf $DIR/$tfile
9761 }
9762 run_test 154a "Open-by-FID"
9763
9764 test_154b() {
9765         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9766         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9767                 { skip "Need MDS version at least 2.2.51"; return 0; }
9768
9769         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9770
9771         local remote_dir=$DIR/$tdir/remote_dir
9772         local MDTIDX=1
9773         local rc=0
9774
9775         mkdir -p $DIR/$tdir
9776         $LFS mkdir -i $MDTIDX $remote_dir ||
9777                 error "create remote directory failed"
9778
9779         cp /etc/hosts $remote_dir/$tfile
9780
9781         fid=$($LFS path2fid $remote_dir/$tfile)
9782         rc=$?
9783         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9784
9785         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9786                 error "dot lustre permission check $fid failed"
9787         rm -rf $DIR/$tdir
9788 }
9789 run_test 154b "Open-by-FID for remote directory"
9790
9791 test_154c() {
9792         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9793                 skip "Need MDS version at least 2.4.1" && return
9794
9795         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9796         local FID1=$($LFS path2fid $DIR/$tfile.1)
9797         local FID2=$($LFS path2fid $DIR/$tfile.2)
9798         local FID3=$($LFS path2fid $DIR/$tfile.3)
9799
9800         local N=1
9801         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9802                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9803                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9804                 local want=FID$N
9805                 [ "$FID" = "${!want}" ] ||
9806                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9807                 N=$((N + 1))
9808         done
9809
9810         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
9811         do
9812                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
9813                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
9814                 N=$((N + 1))
9815         done
9816 }
9817 run_test 154c "lfs path2fid and fid2path multiple arguments"
9818
9819 test_154d() {
9820         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
9821                 skip "Need MDS version at least 2.5.53" && return
9822
9823         if remote_mds; then
9824                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
9825         else
9826                 nid="0@lo"
9827         fi
9828         local proc_ofile="mdt.*.exports.'$nid'.open_files"
9829         local fd
9830         local cmd
9831
9832         rm -f $DIR/$tfile
9833         touch $DIR/$tfile
9834
9835         local fid=$($LFS path2fid $DIR/$tfile)
9836         # Open the file
9837         fd=$(free_fd)
9838         cmd="exec $fd<$DIR/$tfile"
9839         eval $cmd
9840         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
9841         echo "$fid_list" | grep "$fid"
9842         rc=$?
9843
9844         cmd="exec $fd>/dev/null"
9845         eval $cmd
9846         if [ $rc -ne 0 ]; then
9847                 error "FID $fid not found in open files list $fid_list"
9848         fi
9849 }
9850 run_test 154d "Verify open file fid"
9851
9852 test_154e()
9853 {
9854         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
9855                 skip "Need MDS version at least 2.6.50" && return
9856
9857         if ls -a $MOUNT | grep -q '^\.lustre$'; then
9858                 error ".lustre returned by readdir"
9859         fi
9860 }
9861 run_test 154e ".lustre is not returned by readdir"
9862
9863 test_154f() {
9864         # create parent directory on a single MDT to avoid cross-MDT hardlinks
9865         test_mkdir -p -c1 $DIR/$tdir/d
9866         # test dirs inherit from its stripe
9867         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
9868         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
9869         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
9870         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
9871         touch $DIR/f
9872
9873         # get fid of parents
9874         local FID0=$($LFS path2fid $DIR/$tdir/d)
9875         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
9876         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
9877         local FID3=$($LFS path2fid $DIR)
9878
9879         # check that path2fid --parents returns expected <parent_fid>/name
9880         # 1) test for a directory (single parent)
9881         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
9882         [ "$parent" == "$FID0/foo1" ] ||
9883                 error "expected parent: $FID0/foo1, got: $parent"
9884
9885         # 2) test for a file with nlink > 1 (multiple parents)
9886         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
9887         echo "$parent" | grep -F "$FID1/$tfile" ||
9888                 error "$FID1/$tfile not returned in parent list"
9889         echo "$parent" | grep -F "$FID2/link" ||
9890                 error "$FID2/link not returned in parent list"
9891
9892         # 3) get parent by fid
9893         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
9894         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
9895         echo "$parent" | grep -F "$FID1/$tfile" ||
9896                 error "$FID1/$tfile not returned in parent list (by fid)"
9897         echo "$parent" | grep -F "$FID2/link" ||
9898                 error "$FID2/link not returned in parent list (by fid)"
9899
9900         # 4) test for entry in root directory
9901         parent=$($LFS path2fid --parents $DIR/f)
9902         echo "$parent" | grep -F "$FID3/f" ||
9903                 error "$FID3/f not returned in parent list"
9904
9905         # 5) test it on root directory
9906         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
9907                 error "$MOUNT should not have parents"
9908
9909         # enable xattr caching and check that linkea is correctly updated
9910         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
9911         save_lustre_params client "llite.*.xattr_cache" > $save
9912         lctl set_param llite.*.xattr_cache 1
9913
9914         # 6.1) linkea update on rename
9915         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
9916
9917         # get parents by fid
9918         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
9919         # foo1 should no longer be returned in parent list
9920         echo "$parent" | grep -F "$FID1" &&
9921                 error "$FID1 should no longer be in parent list"
9922         # the new path should appear
9923         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
9924                 error "$FID2/$tfile.moved is not in parent list"
9925
9926         # 6.2) linkea update on unlink
9927         rm -f $DIR/$tdir/d/foo2/link
9928         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
9929         # foo2/link should no longer be returned in parent list
9930         echo "$parent" | grep -F "$FID2/link" &&
9931                 error "$FID2/link should no longer be in parent list"
9932         true
9933
9934         rm -f $DIR/f
9935         restore_lustre_params < $save
9936 }
9937 run_test 154f "get parent fids by reading link ea"
9938
9939 test_154g()
9940 {
9941         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) ]] ||
9942                 { skip "Need MDS version at least 2.6.92"; return 0; }
9943
9944         mkdir -p $DIR/$tdir
9945         llapi_fid_test -d $DIR/$tdir
9946 }
9947 run_test 154g "various llapi FID tests"
9948
9949 test_155_small_load() {
9950     local temp=$TMP/$tfile
9951     local file=$DIR/$tfile
9952
9953     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
9954         error "dd of=$temp bs=6096 count=1 failed"
9955     cp $temp $file
9956     cancel_lru_locks osc
9957     cmp $temp $file || error "$temp $file differ"
9958
9959     $TRUNCATE $temp 6000
9960     $TRUNCATE $file 6000
9961     cmp $temp $file || error "$temp $file differ (truncate1)"
9962
9963     echo "12345" >>$temp
9964     echo "12345" >>$file
9965     cmp $temp $file || error "$temp $file differ (append1)"
9966
9967     echo "12345" >>$temp
9968     echo "12345" >>$file
9969     cmp $temp $file || error "$temp $file differ (append2)"
9970
9971     rm -f $temp $file
9972     true
9973 }
9974
9975 test_155_big_load() {
9976     remote_ost_nodsh && skip "remote OST with nodsh" && return
9977     local temp=$TMP/$tfile
9978     local file=$DIR/$tfile
9979
9980     free_min_max
9981     local cache_size=$(do_facet ost$((MAXI+1)) \
9982         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
9983     local large_file_size=$((cache_size * 2))
9984
9985     echo "OSS cache size: $cache_size KB"
9986     echo "Large file size: $large_file_size KB"
9987
9988     [ $MAXV -le $large_file_size ] && \
9989         skip_env "max available OST size needs > $large_file_size KB" && \
9990         return 0
9991
9992     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
9993
9994     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
9995         error "dd of=$temp bs=$large_file_size count=1k failed"
9996     cp $temp $file
9997     ls -lh $temp $file
9998     cancel_lru_locks osc
9999     cmp $temp $file || error "$temp $file differ"
10000
10001     rm -f $temp $file
10002     true
10003 }
10004
10005 test_155a() {
10006         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10007         set_cache read on
10008         set_cache writethrough on
10009         test_155_small_load
10010 }
10011 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
10012
10013 test_155b() {
10014         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10015         set_cache read on
10016         set_cache writethrough off
10017         test_155_small_load
10018 }
10019 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
10020
10021 test_155c() {
10022         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10023         set_cache read off
10024         set_cache writethrough on
10025         test_155_small_load
10026 }
10027 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
10028
10029 test_155d() {
10030         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10031         set_cache read off
10032         set_cache writethrough off
10033         test_155_small_load
10034 }
10035 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
10036
10037 test_155e() {
10038         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10039         set_cache read on
10040         set_cache writethrough on
10041         test_155_big_load
10042 }
10043 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
10044
10045 test_155f() {
10046         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10047         set_cache read on
10048         set_cache writethrough off
10049         test_155_big_load
10050 }
10051 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
10052
10053 test_155g() {
10054         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10055         set_cache read off
10056         set_cache writethrough on
10057         test_155_big_load
10058 }
10059 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
10060
10061 test_155h() {
10062         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10063         set_cache read off
10064         set_cache writethrough off
10065         test_155_big_load
10066 }
10067 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
10068
10069 test_156() {
10070         remote_ost_nodsh && skip "remote OST with nodsh" && return
10071         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10072         local CPAGES=3
10073         local BEFORE
10074         local AFTER
10075         local file="$DIR/$tfile"
10076
10077         [ "$(facet_fstype ost1)" = "zfs" ] &&
10078                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
10079                 return
10080
10081         roc_hit_init
10082
10083     log "Turn on read and write cache"
10084     set_cache read on
10085     set_cache writethrough on
10086
10087     log "Write data and read it back."
10088     log "Read should be satisfied from the cache."
10089     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10090     BEFORE=`roc_hit`
10091     cancel_lru_locks osc
10092     cat $file >/dev/null
10093     AFTER=`roc_hit`
10094     if ! let "AFTER - BEFORE == CPAGES"; then
10095         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10096     else
10097         log "cache hits:: before: $BEFORE, after: $AFTER"
10098     fi
10099
10100     log "Read again; it should be satisfied from the cache."
10101     BEFORE=$AFTER
10102     cancel_lru_locks osc
10103     cat $file >/dev/null
10104     AFTER=`roc_hit`
10105     if ! let "AFTER - BEFORE == CPAGES"; then
10106         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10107     else
10108         log "cache hits:: before: $BEFORE, after: $AFTER"
10109     fi
10110
10111
10112     log "Turn off the read cache and turn on the write cache"
10113     set_cache read off
10114     set_cache writethrough on
10115
10116     log "Read again; it should be satisfied from the cache."
10117     BEFORE=`roc_hit`
10118     cancel_lru_locks osc
10119     cat $file >/dev/null
10120     AFTER=`roc_hit`
10121     if ! let "AFTER - BEFORE == CPAGES"; then
10122         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10123     else
10124         log "cache hits:: before: $BEFORE, after: $AFTER"
10125     fi
10126
10127     log "Read again; it should not be satisfied from the cache."
10128     BEFORE=$AFTER
10129     cancel_lru_locks osc
10130     cat $file >/dev/null
10131     AFTER=`roc_hit`
10132     if ! let "AFTER - BEFORE == 0"; then
10133         error "IN CACHE: before: $BEFORE, after: $AFTER"
10134     else
10135         log "cache hits:: before: $BEFORE, after: $AFTER"
10136     fi
10137
10138     log "Write data and read it back."
10139     log "Read should be satisfied from the cache."
10140     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10141     BEFORE=`roc_hit`
10142     cancel_lru_locks osc
10143     cat $file >/dev/null
10144     AFTER=`roc_hit`
10145     if ! let "AFTER - BEFORE == CPAGES"; then
10146         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10147     else
10148         log "cache hits:: before: $BEFORE, after: $AFTER"
10149     fi
10150
10151     log "Read again; it should not be satisfied from the cache."
10152     BEFORE=$AFTER
10153     cancel_lru_locks osc
10154     cat $file >/dev/null
10155     AFTER=`roc_hit`
10156     if ! let "AFTER - BEFORE == 0"; then
10157         error "IN CACHE: before: $BEFORE, after: $AFTER"
10158     else
10159         log "cache hits:: before: $BEFORE, after: $AFTER"
10160     fi
10161
10162
10163     log "Turn off read and write cache"
10164     set_cache read off
10165     set_cache writethrough off
10166
10167     log "Write data and read it back"
10168     log "It should not be satisfied from the cache."
10169     rm -f $file
10170     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10171     cancel_lru_locks osc
10172     BEFORE=`roc_hit`
10173     cat $file >/dev/null
10174     AFTER=`roc_hit`
10175         if ! let "AFTER - BEFORE == 0"; then
10176                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10177         else
10178                 log "cache hits:: before: $BEFORE, after: $AFTER"
10179         fi
10180
10181     log "Turn on the read cache and turn off the write cache"
10182     set_cache read on
10183     set_cache writethrough off
10184
10185     log "Write data and read it back"
10186     log "It should not be satisfied from the cache."
10187     rm -f $file
10188     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10189     BEFORE=`roc_hit`
10190     cancel_lru_locks osc
10191     cat $file >/dev/null
10192     AFTER=`roc_hit`
10193         if ! let "AFTER - BEFORE == 0"; then
10194                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10195         else
10196                 log "cache hits:: before: $BEFORE, after: $AFTER"
10197         fi
10198
10199     log "Read again; it should be satisfied from the cache."
10200     BEFORE=`roc_hit`
10201     cancel_lru_locks osc
10202     cat $file >/dev/null
10203     AFTER=`roc_hit`
10204     if ! let "AFTER - BEFORE == CPAGES"; then
10205         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10206     else
10207         log "cache hits:: before: $BEFORE, after: $AFTER"
10208     fi
10209
10210     rm -f $file
10211 }
10212 run_test 156 "Verification of tunables ============================"
10213
10214 #Changelogs
10215 err17935 () {
10216         if [[ $MDSCOUNT -gt 1 ]]; then
10217                 error_ignore bz17935 $*
10218         else
10219                 error $*
10220         fi
10221 }
10222
10223 changelog_chmask()
10224 {
10225         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10226
10227         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
10228
10229         if [ $MASK -eq 1 ]; then
10230                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
10231         else
10232                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
10233         fi
10234 }
10235
10236 changelog_extract_field() {
10237         local mdt=$1
10238         local cltype=$2
10239         local file=$3
10240         local identifier=$4
10241
10242         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
10243                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10244                 tail -1
10245 }
10246
10247 test_160a() {
10248         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10249         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10250         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10251                 { skip "Need MDS version at least 2.2.0"; return; }
10252
10253         local CL_USERS="mdd.$MDT0.changelog_users"
10254         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10255         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10256         echo "Registered as changelog user $USER"
10257         $GET_CL_USERS | grep -q $USER ||
10258                 error "User $USER not found in changelog_users"
10259
10260         # change something
10261         test_mkdir -p $DIR/$tdir/pics/2008/zachy
10262         touch $DIR/$tdir/pics/2008/zachy/timestamp
10263         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
10264         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
10265         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
10266         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
10267         rm $DIR/$tdir/pics/desktop.jpg
10268
10269         $LFS changelog $MDT0 | tail -5
10270
10271         echo "verifying changelog mask"
10272         changelog_chmask "MKDIR"
10273         changelog_chmask "CLOSE"
10274
10275         test_mkdir -p $DIR/$tdir/pics/zach/sofia
10276         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10277
10278         changelog_chmask "MKDIR"
10279         changelog_chmask "CLOSE"
10280
10281         test_mkdir -p $DIR/$tdir/pics/2008/sofia
10282         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10283
10284         $LFS changelog $MDT0
10285         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
10286         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
10287         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
10288         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
10289
10290         # verify contents
10291         echo "verifying target fid"
10292         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
10293         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
10294         [ "$fidc" == "$fidf" ] ||
10295                 err17935 "fid in changelog $fidc != file fid $fidf"
10296         echo "verifying parent fid"
10297         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
10298         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
10299         [ "$fidc" == "$fidf" ] ||
10300                 err17935 "pfid in changelog $fidc != dir fid $fidf"
10301
10302         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10303         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
10304         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10305         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
10306         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
10307                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
10308
10309         MIN_REC=$($GET_CL_USERS |
10310                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
10311         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
10312         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
10313         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
10314                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
10315
10316         # LU-3446 changelog index reset on MDT restart
10317         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10318         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10319         $LFS changelog_clear $MDT0 $USER 0
10320         stop $SINGLEMDS || error "Fail to stop MDT."
10321         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10322         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10323         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
10324         [ $CUR_REC1 == $CUR_REC2 ] ||
10325                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
10326
10327         echo "verifying user deregister"
10328         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10329         $GET_CL_USERS | grep -q $USER &&
10330                 error "User $USER still in changelog_users"
10331
10332         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
10333         if [ $USERS -eq 0 ]; then
10334                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10335                 touch $DIR/$tdir/chloe
10336                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10337                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
10338                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
10339         else
10340                 echo "$USERS other changelog users; can't verify off"
10341         fi
10342 }
10343 run_test 160a "changelog sanity"
10344
10345 test_160b() { # LU-3587
10346         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10347         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10348         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10349                 { skip "Need MDS version at least 2.2.0"; return; }
10350
10351         local CL_USERS="mdd.$MDT0.changelog_users"
10352         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10353         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10354         echo "Registered as changelog user $USER"
10355         $GET_CL_USERS | grep -q $USER ||
10356                 error "User $USER not found in changelog_users"
10357
10358         local LONGNAME1=$(str_repeat a 255)
10359         local LONGNAME2=$(str_repeat b 255)
10360
10361         cd $DIR
10362         echo "creating very long named file"
10363         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
10364         echo "moving very long named file"
10365         mv $LONGNAME1 $LONGNAME2
10366
10367         $LFS changelog $MDT0 | grep RENME
10368
10369         echo "deregistering $USER"
10370         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10371
10372         rm -f $LONGNAME2
10373 }
10374 run_test 160b "Verify that very long rename doesn't crash in changelog"
10375
10376 test_160c() {
10377         local rc=0
10378         local server_version=$(lustre_version_code $SINGLEMDS)
10379
10380         [[ $server_version -gt $(version_code 2.5.57) ]] ||
10381                 [[ $server_version -gt $(version_code 2.5.1) &&
10382                    $server_version -lt $(version_code 2.5.50) ]] ||
10383                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
10384         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10385
10386         # Registration step
10387         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10388                 changelog_register -n)
10389
10390         rm -rf $DIR/$tdir
10391         mkdir -p $DIR/$tdir
10392         $MCREATE $DIR/$tdir/foo_160c
10393         changelog_chmask "TRUNC"
10394         $TRUNCATE $DIR/$tdir/foo_160c 200
10395         changelog_chmask "TRUNC"
10396         $TRUNCATE $DIR/$tdir/foo_160c 199
10397         $LFS changelog $MDT0
10398         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
10399         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
10400         $LFS changelog_clear $MDT0 $USER 0
10401
10402         # Deregistration step
10403         echo "deregistering $USER"
10404         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10405 }
10406 run_test 160c "verify that changelog log catch the truncate event"
10407
10408 test_161a() {
10409         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10410         test_mkdir -p -c1 $DIR/$tdir
10411         cp /etc/hosts $DIR/$tdir/$tfile
10412         test_mkdir -c1 $DIR/$tdir/foo1
10413         test_mkdir -c1 $DIR/$tdir/foo2
10414         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
10415         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
10416         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
10417         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
10418         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
10419         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10420                 $LFS fid2path $DIR $FID
10421                 err17935 "bad link ea"
10422         fi
10423     # middle
10424     rm $DIR/$tdir/foo2/zachary
10425     # last
10426     rm $DIR/$tdir/foo2/thor
10427     # first
10428     rm $DIR/$tdir/$tfile
10429     # rename
10430     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
10431     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
10432         then
10433         $LFS fid2path $DIR $FID
10434         err17935 "bad link rename"
10435     fi
10436     rm $DIR/$tdir/foo2/maggie
10437
10438         # overflow the EA
10439         local longname=filename_avg_len_is_thirty_two_
10440         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
10441                 error "failed to hardlink many files"
10442         links=$($LFS fid2path $DIR $FID | wc -l)
10443         echo -n "${links}/1000 links in link EA"
10444         [[ $links -gt 60 ]] ||
10445                 err17935 "expected at least 60 links in link EA"
10446         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
10447                 error "failed to unlink many hardlinks"
10448 }
10449 run_test 161a "link ea sanity"
10450
10451 test_161b() {
10452         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10453         [ $MDSCOUNT -lt 2 ] &&
10454                 skip "skipping remote directory test" && return
10455         local MDTIDX=1
10456         local remote_dir=$DIR/$tdir/remote_dir
10457
10458         mkdir -p $DIR/$tdir
10459         $LFS mkdir -i $MDTIDX $remote_dir ||
10460                 error "create remote directory failed"
10461
10462         cp /etc/hosts $remote_dir/$tfile
10463         mkdir -p $remote_dir/foo1
10464         mkdir -p $remote_dir/foo2
10465         ln $remote_dir/$tfile $remote_dir/foo1/sofia
10466         ln $remote_dir/$tfile $remote_dir/foo2/zachary
10467         ln $remote_dir/$tfile $remote_dir/foo1/luna
10468         ln $remote_dir/$tfile $remote_dir/foo2/thor
10469
10470         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
10471                      tr -d ']')
10472         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10473                 $LFS fid2path $DIR $FID
10474                 err17935 "bad link ea"
10475         fi
10476         # middle
10477         rm $remote_dir/foo2/zachary
10478         # last
10479         rm $remote_dir/foo2/thor
10480         # first
10481         rm $remote_dir/$tfile
10482         # rename
10483         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
10484         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
10485         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
10486                 $LFS fid2path $DIR $FID
10487                 err17935 "bad link rename"
10488         fi
10489         rm $remote_dir/foo2/maggie
10490
10491         # overflow the EA
10492         local longname=filename_avg_len_is_thirty_two_
10493         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10494                 error "failed to hardlink many files"
10495         links=$($LFS fid2path $DIR $FID | wc -l)
10496         echo -n "${links}/1000 links in link EA"
10497         [[ ${links} -gt 60 ]] ||
10498                 err17935 "expected at least 60 links in link EA"
10499         unlinkmany $remote_dir/foo2/$longname 1000 ||
10500         error "failed to unlink many hardlinks"
10501 }
10502 run_test 161b "link ea sanity under remote directory"
10503
10504 test_161c() {
10505         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10506         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10507         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10508                 skip "Need MDS version at least 2.1.5" && return
10509
10510         # define CLF_RENAME_LAST 0x0001
10511         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10512         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10513                 changelog_register -n)
10514         rm -rf $DIR/$tdir
10515         mkdir -p $DIR/$tdir
10516         touch $DIR/$tdir/foo_161c
10517         touch $DIR/$tdir/bar_161c
10518         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10519         $LFS changelog $MDT0 | grep RENME
10520         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10521                 cut -f5 -d' ')
10522         $LFS changelog_clear $MDT0 $USER 0
10523         if [ x$flags != "x0x1" ]; then
10524                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10525                         $USER
10526                 error "flag $flags is not 0x1"
10527         fi
10528         echo "rename overwrite a target having nlink = 1," \
10529                 "changelog record has flags of $flags"
10530
10531         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10532         touch $DIR/$tdir/foo_161c
10533         touch $DIR/$tdir/bar_161c
10534         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10535         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10536         $LFS changelog $MDT0 | grep RENME
10537         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10538         $LFS changelog_clear $MDT0 $USER 0
10539         if [ x$flags != "x0x0" ]; then
10540                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10541                         $USER
10542                 error "flag $flags is not 0x0"
10543         fi
10544         echo "rename overwrite a target having nlink > 1," \
10545                 "changelog record has flags of $flags"
10546
10547         # rename doesn't overwrite a target (changelog flag 0x0)
10548         touch $DIR/$tdir/foo_161c
10549         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10550         $LFS changelog $MDT0 | grep RENME
10551         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10552         $LFS changelog_clear $MDT0 $USER 0
10553         if [ x$flags != "x0x0" ]; then
10554                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10555                         $USER
10556                 error "flag $flags is not 0x0"
10557         fi
10558         echo "rename doesn't overwrite a target," \
10559                 "changelog record has flags of $flags"
10560
10561         # define CLF_UNLINK_LAST 0x0001
10562         # unlink a file having nlink = 1 (changelog flag 0x1)
10563         rm -f $DIR/$tdir/foo2_161c
10564         $LFS changelog $MDT0 | grep UNLNK
10565         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10566         $LFS changelog_clear $MDT0 $USER 0
10567         if [ x$flags != "x0x1" ]; then
10568                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10569                         $USER
10570                 error "flag $flags is not 0x1"
10571         fi
10572         echo "unlink a file having nlink = 1," \
10573                 "changelog record has flags of $flags"
10574
10575         # unlink a file having nlink > 1 (changelog flag 0x0)
10576         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10577         rm -f $DIR/$tdir/foobar_161c
10578         $LFS changelog $MDT0 | grep UNLNK
10579         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10580         $LFS changelog_clear $MDT0 $USER 0
10581         if [ x$flags != "x0x0" ]; then
10582                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10583                         $USER
10584                 error "flag $flags is not 0x0"
10585         fi
10586         echo "unlink a file having nlink > 1," \
10587                 "changelog record has flags of $flags"
10588         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10589 }
10590 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10591
10592 check_path() {
10593     local expected=$1
10594     shift
10595     local fid=$2
10596
10597     local path=$(${LFS} fid2path $*)
10598     # Remove the '//' indicating a remote directory
10599     path=$(echo $path | sed 's#//#/#g')
10600     RC=$?
10601
10602     if [ $RC -ne 0 ]; then
10603         err17935 "path looked up of $expected failed. Error $RC"
10604         return $RC
10605     elif [ "${path}" != "${expected}" ]; then
10606         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10607         return 2
10608     fi
10609     echo "fid $fid resolves to path $path (expected $expected)"
10610 }
10611
10612 test_162() {
10613         # Make changes to filesystem
10614         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10615         test_mkdir -p -c1 $DIR/$tdir/d2
10616         touch $DIR/$tdir/d2/$tfile
10617         touch $DIR/$tdir/d2/x1
10618         touch $DIR/$tdir/d2/x2
10619         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
10620         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
10621         # regular file
10622         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10623         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
10624                 error "check path $tdir/d2/$tfile failed"
10625
10626         # softlink
10627         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10628         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10629         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
10630                 error "check path $tdir/d2/p/q/r/slink failed"
10631
10632         # softlink to wrong file
10633         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10634         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10635         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
10636                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
10637
10638         # hardlink
10639         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10640         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10641         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10642         # fid2path dir/fsname should both work
10643         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
10644                 error "check path $tdir/d2/a/b/c/new_file failed"
10645         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
10646                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
10647
10648         # hardlink count: check that there are 2 links
10649         # Doesnt work with CMD yet: 17935
10650         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10651                 err17935 "expected 2 links"
10652
10653         # hardlink indexing: remove the first link
10654         rm $DIR/$tdir/d2/p/q/r/hlink
10655         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
10656                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
10657
10658         return 0
10659 }
10660 run_test 162 "path lookup sanity"
10661
10662 test_162b() {
10663         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10664         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10665
10666         mkdir $DIR/$tdir
10667         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
10668                                 error "create striped dir failed"
10669
10670         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
10671                                         tail -n 1 | awk '{print $2}')
10672         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
10673
10674         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
10675         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
10676
10677         # regular file
10678         for ((i=0;i<5;i++)); do
10679                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
10680                         error "get fid for f$i failed"
10681                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
10682                         error "check path $tdir/striped_dir/f$i failed"
10683
10684                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
10685                         error "get fid for d$i failed"
10686                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
10687                         error "check path $tdir/striped_dir/d$i failed"
10688         done
10689
10690         return 0
10691 }
10692 run_test 162b "striped directory path lookup sanity"
10693
10694 # LU-4239: Verify fid2path works with paths 100 or more directories deep
10695 test_162c() {
10696         test_mkdir $DIR/$tdir.local
10697         test_mkdir $DIR/$tdir.remote
10698         local lpath=$tdir.local
10699         local rpath=$tdir.remote
10700
10701         for ((i = 0; i <= 101; i++)); do
10702                 lpath="$lpath/$i"
10703                 mkdir $DIR/$lpath
10704                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
10705                         error "get fid for local directory $DIR/$lpath failed"
10706                 check_path "$DIR/$lpath" $MOUNT $FID --link 0 ||
10707                         error "check path for local directory $DIR/$lpath failed"
10708
10709                 rpath="$rpath/$i"
10710                 test_mkdir $DIR/$rpath
10711                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
10712                         error "get fid for remote directory $DIR/$rpath failed"
10713                 check_path "$DIR/$rpath" $MOUNT $FID --link 0 ||
10714                         error "check path for remote directory $DIR/$rpath failed"
10715         done
10716
10717         return 0
10718 }
10719 run_test 162c "fid2path works with paths 100 or more directories deep"
10720
10721 test_169() {
10722         # do directio so as not to populate the page cache
10723         log "creating a 10 Mb file"
10724         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10725         log "starting reads"
10726         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10727         log "truncating the file"
10728         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10729         log "killing dd"
10730         kill %+ || true # reads might have finished
10731         echo "wait until dd is finished"
10732         wait
10733         log "removing the temporary file"
10734         rm -rf $DIR/$tfile || error "tmp file removal failed"
10735 }
10736 run_test 169 "parallel read and truncate should not deadlock"
10737
10738 test_170() {
10739         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10740         $LCTL clear     # bug 18514
10741         $LCTL debug_daemon start $TMP/${tfile}_log_good
10742         touch $DIR/$tfile
10743         $LCTL debug_daemon stop
10744         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10745                error "sed failed to read log_good"
10746
10747         $LCTL debug_daemon start $TMP/${tfile}_log_good
10748         rm -rf $DIR/$tfile
10749         $LCTL debug_daemon stop
10750
10751         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10752                error "lctl df log_bad failed"
10753
10754         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10755         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10756
10757         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10758         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10759
10760         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10761                 error "bad_line good_line1 good_line2 are empty"
10762
10763         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10764         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10765         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10766
10767         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10768         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10769         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10770
10771         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
10772                 error "bad_line_new good_line_new are empty"
10773
10774         local expected_good=$((good_line1 + good_line2*2))
10775
10776         rm -f $TMP/${tfile}*
10777         # LU-231, short malformed line may not be counted into bad lines
10778         if [ $bad_line -ne $bad_line_new ] &&
10779                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
10780                 error "expected $bad_line bad lines, but got $bad_line_new"
10781                 return 1
10782         fi
10783
10784         if [ $expected_good -ne $good_line_new ]; then
10785                 error "expected $expected_good good lines, but got $good_line_new"
10786                 return 2
10787         fi
10788         true
10789 }
10790 run_test 170 "test lctl df to handle corrupted log ====================="
10791
10792 test_171() { # bug20592
10793         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10794 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
10795         $LCTL set_param fail_loc=0x50e
10796         $LCTL set_param fail_val=3000
10797         multiop_bg_pause $DIR/$tfile O_s || true
10798         local MULTIPID=$!
10799         kill -USR1 $MULTIPID
10800         # cause log dump
10801         sleep 3
10802         wait $MULTIPID
10803         if dmesg | grep "recursive fault"; then
10804                 error "caught a recursive fault"
10805         fi
10806         $LCTL set_param fail_loc=0
10807         true
10808 }
10809 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
10810
10811 # it would be good to share it with obdfilter-survey/iokit-libecho code
10812 setup_obdecho_osc () {
10813         local rc=0
10814         local ost_nid=$1
10815         local obdfilter_name=$2
10816         echo "Creating new osc for $obdfilter_name on $ost_nid"
10817         # make sure we can find loopback nid
10818         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
10819
10820         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
10821                            ${obdfilter_name}_osc_UUID || rc=2; }
10822         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
10823                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
10824         return $rc
10825 }
10826
10827 cleanup_obdecho_osc () {
10828         local obdfilter_name=$1
10829         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
10830         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
10831         return 0
10832 }
10833
10834 obdecho_test() {
10835         local OBD=$1
10836         local node=$2
10837         local pages=${3:-64}
10838         local rc=0
10839         local id
10840
10841         local count=10
10842         local obd_size=$(get_obd_size $node $OBD)
10843         local page_size=$(get_page_size $node)
10844         if [[ -n "$obd_size" ]]; then
10845                 local new_count=$((obd_size / (pages * page_size / 1024)))
10846                 [[ $new_count -ge $count ]] || count=$new_count
10847         fi
10848
10849         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
10850         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
10851                            rc=2; }
10852         if [ $rc -eq 0 ]; then
10853             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
10854             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
10855         fi
10856         echo "New object id is $id"
10857         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
10858                            rc=4; }
10859         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
10860                            "test_brw $count w v $pages $id" || rc=4; }
10861         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
10862                            rc=4; }
10863         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
10864                                         "cleanup" || rc=5; }
10865         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
10866                                         "detach" || rc=6; }
10867         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
10868         return $rc
10869 }
10870
10871 test_180a() {
10872         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10873         remote_ost_nodsh && skip "remote OST with nodsh" && return
10874         local rc=0
10875         local rmmod_local=0
10876
10877         if ! module_loaded obdecho; then
10878             load_module obdecho/obdecho
10879             rmmod_local=1
10880         fi
10881
10882         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
10883         local host=$(lctl get_param -n osc.$osc.import |
10884                              awk '/current_connection:/ {print $2}' )
10885         local target=$(lctl get_param -n osc.$osc.import |
10886                              awk '/target:/ {print $2}' )
10887         target=${target%_UUID}
10888
10889         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
10890         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
10891         [[ -n $target ]] && cleanup_obdecho_osc $target
10892         [ $rmmod_local -eq 1 ] && rmmod obdecho
10893         return $rc
10894 }
10895 run_test 180a "test obdecho on osc"
10896
10897 test_180b() {
10898         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10899         remote_ost_nodsh && skip "remote OST with nodsh" && return
10900         local rc=0
10901         local rmmod_remote=0
10902
10903         do_facet ost1 "lsmod | grep -q obdecho || "                      \
10904                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
10905                       "modprobe obdecho; }" && rmmod_remote=1
10906         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
10907         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
10908         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
10909         return $rc
10910 }
10911 run_test 180b "test obdecho directly on obdfilter"
10912
10913 test_180c() { # LU-2598
10914         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10915         remote_ost_nodsh && skip "remote OST with nodsh" && return
10916         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
10917                 skip "Need MDS version at least 2.4.0" && return
10918
10919         local rc=0
10920         local rmmod_remote=false
10921         local pages=16384 # 64MB bulk I/O RPC size
10922         local target
10923
10924         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
10925                 rmmod_remote=true || error "failed to load module obdecho"
10926
10927         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
10928                 head -n1)
10929         if [ -n "$target" ]; then
10930                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
10931         else
10932                 echo "there is no obdfilter target on ost1"
10933                 rc=2
10934         fi
10935         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
10936         return $rc
10937 }
10938 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
10939
10940 test_181() { # bug 22177
10941         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10942         # create enough files to index the directory
10943         createmany -o $DIR/$tdir/foobar 4000
10944         # print attributes for debug purpose
10945         lsattr -d .
10946         # open dir
10947         multiop_bg_pause $DIR/$tdir D_Sc || return 1
10948         MULTIPID=$!
10949         # remove the files & current working dir
10950         unlinkmany $DIR/$tdir/foobar 4000
10951         rmdir $DIR/$tdir
10952         kill -USR1 $MULTIPID
10953         wait $MULTIPID
10954         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
10955         return 0
10956 }
10957 run_test 181 "Test open-unlinked dir ========================"
10958
10959 test_182() {
10960         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10961         # disable MDC RPC lock wouldn't crash client
10962         local fcount=1000
10963         local tcount=4
10964
10965         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10966 #define OBD_FAIL_MDC_RPCS_SEM           0x804
10967         $LCTL set_param fail_loc=0x804
10968
10969         for (( i=0; i < $tcount; i++ )) ; do
10970                 mkdir $DIR/$tdir/$i
10971                 createmany -o $DIR/$tdir/$i/f- $fcount &
10972         done
10973         wait
10974
10975         for (( i=0; i < $tcount; i++ )) ; do
10976                 unlinkmany $DIR/$tdir/$i/f- $fcount &
10977         done
10978         wait
10979
10980         rm -rf $DIR/$tdir
10981
10982         $LCTL set_param fail_loc=0
10983 }
10984 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
10985
10986 test_183() { # LU-2275
10987         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10988         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
10989                 skip "Need MDS version at least 2.3.56" && return
10990
10991         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10992         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10993         echo aaa > $DIR/$tdir/$tfile
10994
10995 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
10996         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
10997
10998         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
10999         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
11000
11001         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
11002
11003         # Flush negative dentry cache
11004         touch $DIR/$tdir/$tfile
11005
11006         # We are not checking for any leaked references here, they'll
11007         # become evident next time we do cleanup with module unload.
11008         rm -rf $DIR/$tdir
11009 }
11010 run_test 183 "No crash or request leak in case of strange dispositions ========"
11011
11012 # test suite 184 is for LU-2016, LU-2017
11013 test_184a() {
11014         check_swap_layouts_support && return 0
11015
11016         dir0=$DIR/$tdir/$testnum
11017         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
11018         ref1=/etc/passwd
11019         ref2=/etc/group
11020         file1=$dir0/f1
11021         file2=$dir0/f2
11022         $SETSTRIPE -c1 $file1
11023         cp $ref1 $file1
11024         $SETSTRIPE -c2 $file2
11025         cp $ref2 $file2
11026         gen1=$($GETSTRIPE -g $file1)
11027         gen2=$($GETSTRIPE -g $file2)
11028
11029         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
11030         gen=$($GETSTRIPE -g $file1)
11031         [[ $gen1 != $gen ]] ||
11032                 "Layout generation on $file1 does not change"
11033         gen=$($GETSTRIPE -g $file2)
11034         [[ $gen2 != $gen ]] ||
11035                 "Layout generation on $file2 does not change"
11036
11037         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
11038         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
11039 }
11040 run_test 184a "Basic layout swap"
11041
11042 test_184b() {
11043         check_swap_layouts_support && return 0
11044
11045         dir0=$DIR/$tdir/$testnum
11046         mkdir -p $dir0 || error "creating dir $dir0"
11047         file1=$dir0/f1
11048         file2=$dir0/f2
11049         file3=$dir0/f3
11050         dir1=$dir0/d1
11051         dir2=$dir0/d2
11052         mkdir $dir1 $dir2
11053         $SETSTRIPE -c1 $file1
11054         $SETSTRIPE -c2 $file2
11055         $SETSTRIPE -c1 $file3
11056         chown $RUNAS_ID $file3
11057         gen1=$($GETSTRIPE -g $file1)
11058         gen2=$($GETSTRIPE -g $file2)
11059
11060         $LFS swap_layouts $dir1 $dir2 &&
11061                 error "swap of directories layouts should fail"
11062         $LFS swap_layouts $dir1 $file1 &&
11063                 error "swap of directory and file layouts should fail"
11064         $RUNAS $LFS swap_layouts $file1 $file2 &&
11065                 error "swap of file we cannot write should fail"
11066         $LFS swap_layouts $file1 $file3 &&
11067                 error "swap of file with different owner should fail"
11068         /bin/true # to clear error code
11069 }
11070 run_test 184b "Forbidden layout swap (will generate errors)"
11071
11072 test_184c() {
11073         check_swap_layouts_support && return 0
11074
11075         local dir0=$DIR/$tdir/$testnum
11076         mkdir -p $dir0 || error "creating dir $dir0"
11077
11078         local ref1=$dir0/ref1
11079         local ref2=$dir0/ref2
11080         local file1=$dir0/file1
11081         local file2=$dir0/file2
11082         # create a file large enough for the concurrent test
11083         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
11084         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
11085         echo "ref file size: ref1($(stat -c %s $ref1))," \
11086              "ref2($(stat -c %s $ref2))"
11087
11088         cp $ref2 $file2
11089         dd if=$ref1 of=$file1 bs=16k &
11090         local DD_PID=$!
11091
11092         # Make sure dd starts to copy file
11093         while [ ! -f $file1 ]; do sleep 0.1; done
11094
11095         $LFS swap_layouts $file1 $file2
11096         local rc=$?
11097         wait $DD_PID
11098         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
11099         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
11100
11101         # how many bytes copied before swapping layout
11102         local copied=$(stat -c %s $file2)
11103         local remaining=$(stat -c %s $ref1)
11104         remaining=$((remaining - copied))
11105         echo "Copied $copied bytes before swapping layout..."
11106
11107         cmp -n $copied $file1 $ref2 | grep differ &&
11108                 error "Content mismatch [0, $copied) of ref2 and file1"
11109         cmp -n $copied $file2 $ref1 ||
11110                 error "Content mismatch [0, $copied) of ref1 and file2"
11111         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
11112                 error "Content mismatch [$copied, EOF) of ref1 and file1"
11113
11114         # clean up
11115         rm -f $ref1 $ref2 $file1 $file2
11116 }
11117 run_test 184c "Concurrent write and layout swap"
11118
11119 test_184d() {
11120         check_swap_layouts_support && return 0
11121         [ -z "$(which getfattr 2>/dev/null)" ] &&
11122                 skip "no getfattr command" && return 0
11123
11124         local file1=$DIR/$tdir/$tfile-1
11125         local file2=$DIR/$tdir/$tfile-2
11126         local file3=$DIR/$tdir/$tfile-3
11127         local lovea1
11128         local lovea2
11129
11130         mkdir -p $DIR/$tdir
11131         touch $file1 || error "create $file1 failed"
11132         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11133                 error "create $file2 failed"
11134         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11135                 error "create $file3 failed"
11136         lovea1=$($LFS getstripe $file1 | sed 1d)
11137
11138         $LFS swap_layouts $file2 $file3 ||
11139                 error "swap $file2 $file3 layouts failed"
11140         $LFS swap_layouts $file1 $file2 ||
11141                 error "swap $file1 $file2 layouts failed"
11142
11143         lovea2=$($LFS getstripe $file2 | sed 1d)
11144         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
11145
11146         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11147         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
11148 }
11149 run_test 184d "allow stripeless layouts swap"
11150
11151 test_184e() {
11152         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
11153                 { skip "Need MDS version at least 2.6.94"; return 0; }
11154         check_swap_layouts_support && return 0
11155         [ -z "$(which getfattr 2>/dev/null)" ] &&
11156                 skip "no getfattr command" && return 0
11157
11158         local file1=$DIR/$tdir/$tfile-1
11159         local file2=$DIR/$tdir/$tfile-2
11160         local file3=$DIR/$tdir/$tfile-3
11161         local lovea
11162
11163         mkdir -p $DIR/$tdir
11164         touch $file1 || error "create $file1 failed"
11165         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11166                 error "create $file2 failed"
11167         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11168                 error "create $file3 failed"
11169
11170         $LFS swap_layouts $file1 $file2 ||
11171                 error "swap $file1 $file2 layouts failed"
11172
11173         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11174         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
11175
11176         echo 123 > $file1 || error "Should be able to write into $file1"
11177
11178         $LFS swap_layouts $file1 $file3 ||
11179                 error "swap $file1 $file3 layouts failed"
11180
11181         echo 123 > $file1 || error "Should be able to write into $file1"
11182
11183         rm -rf $file1 $file2 $file3
11184 }
11185 run_test 184e "Recreate layout after stripeless layout swaps"
11186
11187 test_185() { # LU-2441
11188         # LU-3553 - no volatile file support in old servers
11189         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
11190                 { skip "Need MDS version at least 2.3.60"; return 0; }
11191
11192         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11193         touch $DIR/$tdir/spoo
11194         local mtime1=$(stat -c "%Y" $DIR/$tdir)
11195         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
11196                 error "cannot create/write a volatile file"
11197         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
11198                 error "FID is still valid after close"
11199
11200         multiop_bg_pause $DIR/$tdir vVw4096_c
11201         local multi_pid=$!
11202
11203         local OLD_IFS=$IFS
11204         IFS=":"
11205         local fidv=($fid)
11206         IFS=$OLD_IFS
11207         # assume that the next FID for this client is sequential, since stdout
11208         # is unfortunately eaten by multiop_bg_pause
11209         local n=$((${fidv[1]} + 1))
11210         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
11211         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
11212                 error "FID is missing before close"
11213         kill -USR1 $multi_pid
11214         # 1 second delay, so if mtime change we will see it
11215         sleep 1
11216         local mtime2=$(stat -c "%Y" $DIR/$tdir)
11217         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
11218 }
11219 run_test 185 "Volatile file support"
11220
11221 test_187a() {
11222         local dir0=$DIR/$tdir/$testnum
11223         mkdir -p $dir0 || error "creating dir $dir0"
11224
11225         local file=$dir0/file1
11226         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
11227         local dv1=$($LFS data_version $file)
11228         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
11229         local dv2=$($LFS data_version $file)
11230         [[ $dv1 != $dv2 ]] ||
11231                 error "data version did not change on write $dv1 == $dv2"
11232
11233         # clean up
11234         rm -f $file1
11235 }
11236 run_test 187a "Test data version change"
11237
11238 test_187b() {
11239         local dir0=$DIR/$tdir/$testnum
11240         mkdir -p $dir0 || error "creating dir $dir0"
11241
11242         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
11243         [[ ${DV[0]} != ${DV[1]} ]] ||
11244                 error "data version did not change on write"\
11245                       " ${DV[0]} == ${DV[1]}"
11246
11247         # clean up
11248         rm -f $file1
11249 }
11250 run_test 187b "Test data version change on volatile file"
11251
11252 test_200() {
11253         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11254         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11255
11256         local POOL=${POOL:-cea1}
11257         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
11258         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
11259         # Pool OST targets
11260         local first_ost=0
11261         local last_ost=$(($OSTCOUNT - 1))
11262         local ost_step=2
11263         local ost_list=$(seq $first_ost $ost_step $last_ost)
11264         local ost_range="$first_ost $last_ost $ost_step"
11265         local test_path=$POOL_ROOT/$POOL_DIR_NAME
11266         local file_dir=$POOL_ROOT/file_tst
11267         local subdir=$test_path/subdir
11268
11269         local rc=0
11270         while : ; do
11271                 # former test_200a test_200b
11272                 pool_add $POOL                          || { rc=$? ; break; }
11273                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
11274                 # former test_200c test_200d
11275                 mkdir -p $test_path
11276                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
11277                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
11278                 mkdir -p $subdir
11279                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
11280                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
11281                                                         || { rc=$? ; break; }
11282                 # former test_200e test_200f
11283                 local files=$((OSTCOUNT*3))
11284                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
11285                                                         || { rc=$? ; break; }
11286                 pool_create_files $POOL $file_dir $files "$ost_list" \
11287                                                         || { rc=$? ; break; }
11288                 # former test_200g test_200h
11289                 pool_lfs_df $POOL                       || { rc=$? ; break; }
11290                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
11291
11292                 # former test_201a test_201b test_201c
11293                 pool_remove_first_target $POOL          || { rc=$? ; break; }
11294
11295                 local f=$test_path/$tfile
11296                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
11297                 pool_remove $POOL $f                    || { rc=$? ; break; }
11298                 break
11299         done
11300
11301         cleanup_pools
11302         return $rc
11303 }
11304 run_test 200 "OST pools"
11305
11306 # usage: default_attr <count | size | offset>
11307 default_attr() {
11308         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
11309 }
11310
11311 # usage: check_default_stripe_attr
11312 check_default_stripe_attr() {
11313         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
11314         case $1 in
11315         --stripe-count|--count)
11316                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
11317         --stripe-size|--size)
11318                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
11319         --stripe-index|--index)
11320                 EXPECTED=-1;;
11321         *)
11322                 error "unknown getstripe attr '$1'"
11323         esac
11324
11325         [ $ACTUAL != $EXPECTED ] &&
11326                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
11327 }
11328
11329 test_204a() {
11330         test_mkdir -p $DIR/$tdir
11331         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
11332
11333         check_default_stripe_attr --stripe-count
11334         check_default_stripe_attr --stripe-size
11335         check_default_stripe_attr --stripe-index
11336
11337         return 0
11338 }
11339 run_test 204a "Print default stripe attributes ================="
11340
11341 test_204b() {
11342         test_mkdir -p $DIR/$tdir
11343         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11344
11345         check_default_stripe_attr --stripe-size
11346         check_default_stripe_attr --stripe-index
11347
11348         return 0
11349 }
11350 run_test 204b "Print default stripe size and offset  ==========="
11351
11352 test_204c() {
11353         test_mkdir -p $DIR/$tdir
11354         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11355
11356         check_default_stripe_attr --stripe-count
11357         check_default_stripe_attr --stripe-index
11358
11359         return 0
11360 }
11361 run_test 204c "Print default stripe count and offset ==========="
11362
11363 test_204d() {
11364         test_mkdir -p $DIR/$tdir
11365         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11366
11367         check_default_stripe_attr --stripe-count
11368         check_default_stripe_attr --stripe-size
11369
11370         return 0
11371 }
11372 run_test 204d "Print default stripe count and size ============="
11373
11374 test_204e() {
11375         test_mkdir -p $DIR/$tdir
11376         $SETSTRIPE -d $DIR/$tdir
11377
11378         check_default_stripe_attr --stripe-count --raw
11379         check_default_stripe_attr --stripe-size --raw
11380         check_default_stripe_attr --stripe-index --raw
11381
11382         return 0
11383 }
11384 run_test 204e "Print raw stripe attributes ================="
11385
11386 test_204f() {
11387         test_mkdir -p $DIR/$tdir
11388         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11389
11390         check_default_stripe_attr --stripe-size --raw
11391         check_default_stripe_attr --stripe-index --raw
11392
11393         return 0
11394 }
11395 run_test 204f "Print raw stripe size and offset  ==========="
11396
11397 test_204g() {
11398         test_mkdir -p $DIR/$tdir
11399         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11400
11401         check_default_stripe_attr --stripe-count --raw
11402         check_default_stripe_attr --stripe-index --raw
11403
11404         return 0
11405 }
11406 run_test 204g "Print raw stripe count and offset ==========="
11407
11408 test_204h() {
11409         test_mkdir -p $DIR/$tdir
11410         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11411
11412         check_default_stripe_attr --stripe-count --raw
11413         check_default_stripe_attr --stripe-size --raw
11414
11415         return 0
11416 }
11417 run_test 204h "Print raw stripe count and size ============="
11418
11419 # Figure out which job scheduler is being used, if any,
11420 # or use a fake one
11421 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11422         JOBENV=SLURM_JOB_ID
11423 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11424         JOBENV=LSB_JOBID
11425 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11426         JOBENV=PBS_JOBID
11427 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11428         JOBENV=LOADL_STEP_ID
11429 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11430         JOBENV=JOB_ID
11431 else
11432         JOBENV=FAKE_JOBID
11433 fi
11434
11435 verify_jobstats() {
11436         local cmd=$1
11437         local target=$2
11438
11439         # clear old jobstats
11440         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
11441         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
11442
11443         # use a new JobID for this test, or we might see an old one
11444         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
11445
11446         JOBVAL=${!JOBENV}
11447         log "Test: $cmd"
11448         log "Using JobID environment variable $JOBENV=$JOBVAL"
11449
11450         if [ $JOBENV = "FAKE_JOBID" ]; then
11451                 FAKE_JOBID=$JOBVAL $cmd
11452         else
11453                 $cmd
11454         fi
11455
11456         if [ "$target" = "mdt" -o "$target" = "both" ]; then
11457                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
11458                 do_facet $FACET lctl get_param mdt.*.job_stats |
11459                         grep $JOBVAL || error "No job stats found on MDT $FACET"
11460         fi
11461         if [ "$target" = "ost" -o "$target" = "both" ]; then
11462                 FACET=ost1
11463                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
11464                         grep $JOBVAL || error "No job stats found on OST $FACET"
11465         fi
11466 }
11467
11468 jobstats_set() {
11469         trap 0
11470         NEW_JOBENV=${1:-$OLD_JOBENV}
11471         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11472         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11473 }
11474
11475 test_205() { # Job stats
11476         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11477         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11478         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11479                 skip "Server doesn't support jobstats" && return 0
11480         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11481
11482         local cmd
11483         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11484         if [ $OLD_JOBENV != $JOBENV ]; then
11485                 jobstats_set $JOBENV
11486                 trap jobstats_set EXIT
11487         fi
11488
11489         local user=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11490                      changelog_register -n)
11491         echo "Registered as changelog user $user"
11492
11493         # mkdir
11494         cmd="mkdir $DIR/$tfile"
11495         verify_jobstats "$cmd" "mdt"
11496         # rmdir
11497         cmd="rm -fr $DIR/$tfile"
11498         verify_jobstats "$cmd" "mdt"
11499         # mknod
11500         cmd="mknod $DIR/$tfile c 1 3"
11501         verify_jobstats "$cmd" "mdt"
11502         # unlink
11503         cmd="rm -f $DIR/$tfile"
11504         verify_jobstats "$cmd" "mdt"
11505         # open & close
11506         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11507         verify_jobstats "$cmd" "mdt"
11508         # setattr
11509         cmd="touch $DIR/$tfile"
11510         verify_jobstats "$cmd" "both"
11511         # write
11512         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11513         verify_jobstats "$cmd" "ost"
11514         # read
11515         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11516         verify_jobstats "$cmd" "ost"
11517         # truncate
11518         cmd="$TRUNCATE $DIR/$tfile 0"
11519         verify_jobstats "$cmd" "both"
11520         # rename
11521         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
11522         verify_jobstats "$cmd" "mdt"
11523
11524         # Ensure that jobid are present in changelog (if supported by MDS)
11525         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
11526         then
11527                 $LFS changelog $MDT0 | tail -9
11528                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
11529                 [ $jobids -eq 9 ] ||
11530                         error "Wrong changelog jobid count $jobids != 9"
11531
11532                 # LU-5862
11533                 JOBENV="disable"
11534                 jobstats_set $JOBENV
11535                 touch $DIR/$tfile
11536                 $LFS changelog $MDT0 | tail -1
11537                 jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
11538                 [ $jobids -eq 0 ] ||
11539                         error "Unexpected jobids when jobid_var=$JOBENV"
11540         fi
11541
11542         # cleanup
11543         rm -f $DIR/jobstats_test_rename
11544
11545         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11546 }
11547 run_test 205 "Verify job stats"
11548
11549 # LU-1480, LU-1773 and LU-1657
11550 test_206() {
11551         mkdir -p $DIR/$tdir
11552         $SETSTRIPE -c -1 $DIR/$tdir
11553 #define OBD_FAIL_LOV_INIT 0x1403
11554         $LCTL set_param fail_loc=0xa0001403
11555         $LCTL set_param fail_val=1
11556         touch $DIR/$tdir/$tfile || true
11557 }
11558 run_test 206 "fail lov_init_raid0() doesn't lbug"
11559
11560 test_207a() {
11561         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11562         local fsz=`stat -c %s $DIR/$tfile`
11563         cancel_lru_locks mdc
11564
11565         # do not return layout in getattr intent
11566 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11567         $LCTL set_param fail_loc=0x170
11568         local sz=`stat -c %s $DIR/$tfile`
11569
11570         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11571
11572         rm -rf $DIR/$tfile
11573 }
11574 run_test 207a "can refresh layout at glimpse"
11575
11576 test_207b() {
11577         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11578         local cksum=`md5sum $DIR/$tfile`
11579         local fsz=`stat -c %s $DIR/$tfile`
11580         cancel_lru_locks mdc
11581         cancel_lru_locks osc
11582
11583         # do not return layout in getattr intent
11584 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11585         $LCTL set_param fail_loc=0x171
11586
11587         # it will refresh layout after the file is opened but before read issues
11588         echo checksum is "$cksum"
11589         echo "$cksum" |md5sum -c --quiet || error "file differs"
11590
11591         rm -rf $DIR/$tfile
11592 }
11593 run_test 207b "can refresh layout at open"
11594
11595 test_208() {
11596         # FIXME: in this test suite, only RD lease is used. This is okay
11597         # for now as only exclusive open is supported. After generic lease
11598         # is done, this test suite should be revised. - Jinshan
11599
11600         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11601                 { skip "Need MDS version at least 2.4.52"; return 0; }
11602         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11603
11604         echo "==== test 1: verify get lease work"
11605         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11606
11607         echo "==== test 2: verify lease can be broken by upcoming open"
11608         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11609         local PID=$!
11610         sleep 1
11611
11612         $MULTIOP $DIR/$tfile oO_RDONLY:c
11613         kill -USR1 $PID && wait $PID || error "break lease error"
11614
11615         echo "==== test 3: verify lease can't be granted if an open already exists"
11616         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11617         local PID=$!
11618         sleep 1
11619
11620         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11621         kill -USR1 $PID && wait $PID || error "open file error"
11622
11623         echo "==== test 4: lease can sustain over recovery"
11624         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11625         PID=$!
11626         sleep 1
11627
11628         fail mds1
11629
11630         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11631
11632         echo "==== test 5: lease broken can't be regained by replay"
11633         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11634         PID=$!
11635         sleep 1
11636
11637         # open file to break lease and then recovery
11638         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11639         fail mds1
11640
11641         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11642
11643         rm -f $DIR/$tfile
11644 }
11645 run_test 208 "Exclusive open"
11646
11647 test_209() {
11648         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11649                 skip_env "must have disp_stripe" && return
11650
11651         touch $DIR/$tfile
11652         sync; sleep 5; sync;
11653
11654         echo 3 > /proc/sys/vm/drop_caches
11655         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11656
11657         # open/close 500 times
11658         for i in $(seq 500); do
11659                 cat $DIR/$tfile
11660         done
11661
11662         echo 3 > /proc/sys/vm/drop_caches
11663         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11664
11665         echo "before: $req_before, after: $req_after"
11666         [ $((req_after - req_before)) -ge 300 ] &&
11667                 error "open/close requests are not freed"
11668         return 0
11669 }
11670 run_test 209 "read-only open/close requests should be freed promptly"
11671
11672 test_212() {
11673         size=`date +%s`
11674         size=$((size % 8192 + 1))
11675         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11676         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11677         rm -f $DIR/f212 $DIR/f212.xyz
11678 }
11679 run_test 212 "Sendfile test ============================================"
11680
11681 test_213() {
11682         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11683         cancel_lru_locks osc
11684         lctl set_param fail_loc=0x8000040f
11685         # generate a read lock
11686         cat $DIR/$tfile > /dev/null
11687         # write to the file, it will try to cancel the above read lock.
11688         cat /etc/hosts >> $DIR/$tfile
11689 }
11690 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11691
11692 test_214() { # for bug 20133
11693         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11694         for (( i=0; i < 340; i++ )) ; do
11695                 touch $DIR/$tdir/d214c/a$i
11696         done
11697
11698         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11699         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11700         ls $DIR/d214c || error "ls $DIR/d214c failed"
11701         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11702         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11703 }
11704 run_test 214 "hash-indexed directory test - bug 20133"
11705
11706 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11707 create_lnet_proc_files() {
11708         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
11709         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11710
11711         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11712         rm -f "$TMP/lnet_$1.sys_tmp"
11713 }
11714
11715 # counterpart of create_lnet_proc_files
11716 remove_lnet_proc_files() {
11717         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11718 }
11719
11720 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11721 # 3rd arg as regexp for body
11722 check_lnet_proc_stats() {
11723         local l=$(cat "$TMP/lnet_$1" |wc -l)
11724         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
11725
11726         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
11727 }
11728
11729 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11730 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
11731 # optional and can be regexp for 2nd line (lnet.routes case)
11732 check_lnet_proc_entry() {
11733         local blp=2          # blp stands for 'position of 1st line of body'
11734         [ -z "$5" ] || blp=3 # lnet.routes case
11735
11736         local l=$(cat "$TMP/lnet_$1" |wc -l)
11737         # subtracting one from $blp because the body can be empty
11738         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
11739
11740         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
11741                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
11742
11743         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
11744                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
11745
11746         # bail out if any unexpected line happened
11747         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
11748         [ "$?" != 0 ] || error "$2 misformatted"
11749 }
11750
11751 test_215() { # for bugs 18102, 21079, 21517
11752         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11753         local N='(0|[1-9][0-9]*)'       # non-negative numeric
11754         local P='[1-9][0-9]*'           # positive numeric
11755         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
11756         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
11757         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
11758         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
11759
11760         local L1 # regexp for 1st line
11761         local L2 # regexp for 2nd line (optional)
11762         local BR # regexp for the rest (body)
11763
11764         # lnet.stats should look as 11 space-separated non-negative numerics
11765         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
11766         create_lnet_proc_files "stats"
11767         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
11768         remove_lnet_proc_files "stats"
11769
11770         # lnet.routes should look like this:
11771         # Routing disabled/enabled
11772         # net hops priority state router
11773         # where net is a string like tcp0, hops > 0, priority >= 0,
11774         # state is up/down,
11775         # router is a string like 192.168.1.1@tcp2
11776         L1="^Routing (disabled|enabled)$"
11777         L2="^net +hops +priority +state +router$"
11778         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
11779         create_lnet_proc_files "routes"
11780         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
11781         remove_lnet_proc_files "routes"
11782
11783         # lnet.routers should look like this:
11784         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
11785         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
11786         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
11787         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
11788         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
11789         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
11790         create_lnet_proc_files "routers"
11791         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
11792         remove_lnet_proc_files "routers"
11793
11794         # lnet.peers should look like this:
11795         # nid refs state last max rtr min tx min queue
11796         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
11797         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
11798         # numeric (0 or >0 or <0), queue >= 0.
11799         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
11800         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
11801         create_lnet_proc_files "peers"
11802         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
11803         remove_lnet_proc_files "peers"
11804
11805         # lnet.buffers  should look like this:
11806         # pages count credits min
11807         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
11808         L1="^pages +count +credits +min$"
11809         BR="^ +$N +$N +$I +$I$"
11810         create_lnet_proc_files "buffers"
11811         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
11812         remove_lnet_proc_files "buffers"
11813
11814         # lnet.nis should look like this:
11815         # nid status alive refs peer rtr max tx min
11816         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
11817         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
11818         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
11819         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
11820         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
11821         create_lnet_proc_files "nis"
11822         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
11823         remove_lnet_proc_files "nis"
11824
11825         # can we successfully write to lnet.stats?
11826         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
11827         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
11828 }
11829 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
11830
11831 test_216() { # bug 20317
11832         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11833         remote_ost_nodsh && skip "remote OST with nodsh" && return
11834
11835         local node
11836         local facets=$(get_facets OST)
11837         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11838
11839         save_lustre_params client "osc.*.contention_seconds" > $p
11840         save_lustre_params $facets \
11841                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
11842         save_lustre_params $facets \
11843                 "ldlm.namespaces.filter-*.contended_locks" >> $p
11844         save_lustre_params $facets \
11845                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
11846         clear_osc_stats
11847
11848         # agressive lockless i/o settings
11849         for node in $(osts_nodes); do
11850                 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'
11851         done
11852         lctl set_param -n osc.*.contention_seconds 60
11853
11854         $DIRECTIO write $DIR/$tfile 0 10 4096
11855         $CHECKSTAT -s 40960 $DIR/$tfile
11856
11857         # disable lockless i/o
11858         for node in $(osts_nodes); do
11859                 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'
11860         done
11861         lctl set_param -n osc.*.contention_seconds 0
11862         clear_osc_stats
11863
11864         dd if=/dev/zero of=$DIR/$tfile count=0
11865         $CHECKSTAT -s 0 $DIR/$tfile
11866
11867         restore_lustre_params <$p
11868         rm -f $p
11869         rm $DIR/$tfile
11870 }
11871 run_test 216 "check lockless direct write works and updates file size and kms correctly"
11872
11873 test_217() { # bug 22430
11874         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11875         local node
11876         local nid
11877
11878         for node in $(nodes_list); do
11879                 nid=$(host_nids_address $node $NETTYPE)
11880                 if [[ $nid = *-* ]] ; then
11881                         echo "lctl ping $nid@$NETTYPE"
11882                         lctl ping $nid@$NETTYPE
11883                 else
11884                         echo "skipping $node (no hyphen detected)"
11885                 fi
11886         done
11887 }
11888 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
11889
11890 test_218() {
11891        # do directio so as not to populate the page cache
11892        log "creating a 10 Mb file"
11893        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11894        log "starting reads"
11895        dd if=$DIR/$tfile of=/dev/null bs=4096 &
11896        log "truncating the file"
11897        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11898        log "killing dd"
11899        kill %+ || true # reads might have finished
11900        echo "wait until dd is finished"
11901        wait
11902        log "removing the temporary file"
11903        rm -rf $DIR/$tfile || error "tmp file removal failed"
11904 }
11905 run_test 218 "parallel read and truncate should not deadlock ======================="
11906
11907 test_219() {
11908         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11909         # write one partial page
11910         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
11911         # set no grant so vvp_io_commit_write will do sync write
11912         $LCTL set_param fail_loc=0x411
11913         # write a full page at the end of file
11914         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
11915
11916         $LCTL set_param fail_loc=0
11917         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
11918         $LCTL set_param fail_loc=0x411
11919         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
11920
11921         # LU-4201
11922         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
11923         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
11924 }
11925 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
11926
11927 test_220() { #LU-325
11928         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11929         remote_ost_nodsh && skip "remote OST with nodsh" && return
11930         local OSTIDX=0
11931
11932         test_mkdir -p $DIR/$tdir
11933         local OST=$($LFS osts | grep ${OSTIDX}": " | \
11934                 awk '{print $2}' | sed -e 's/_UUID$//')
11935
11936         # on the mdt's osc
11937         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
11938         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
11939                         osc.$mdtosc_proc1.prealloc_last_id)
11940         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
11941                         osc.$mdtosc_proc1.prealloc_next_id)
11942
11943         $LFS df -i
11944
11945         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
11946         #define OBD_FAIL_OST_ENOINO              0x229
11947         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
11948         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
11949         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
11950
11951         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
11952
11953         MDSOBJS=$((last_id - next_id))
11954         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
11955
11956         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
11957         echo "OST still has $count kbytes free"
11958
11959         echo "create $MDSOBJS files @next_id..."
11960         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
11961
11962         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11963                         osc.$mdtosc_proc1.prealloc_last_id)
11964         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11965                         osc.$mdtosc_proc1.prealloc_next_id)
11966
11967         echo "after creation, last_id=$last_id2, next_id=$next_id2"
11968         $LFS df -i
11969
11970         echo "cleanup..."
11971
11972         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
11973         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
11974
11975         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
11976         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
11977         echo "unlink $MDSOBJS files @$next_id..."
11978         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
11979 }
11980 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
11981
11982 test_221() {
11983         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11984         dd if=`which date` of=$MOUNT/date oflag=sync
11985         chmod +x $MOUNT/date
11986
11987         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
11988         $LCTL set_param fail_loc=0x80001401
11989
11990         $MOUNT/date > /dev/null
11991         rm -f $MOUNT/date
11992 }
11993 run_test 221 "make sure fault and truncate race to not cause OOM"
11994
11995 test_222a () {
11996         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11997        rm -rf $DIR/$tdir
11998        test_mkdir -p $DIR/$tdir
11999        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12000        createmany -o $DIR/$tdir/$tfile 10
12001        cancel_lru_locks mdc
12002        cancel_lru_locks osc
12003        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12004        $LCTL set_param fail_loc=0x31a
12005        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
12006        $LCTL set_param fail_loc=0
12007        rm -r $DIR/$tdir
12008 }
12009 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
12010
12011 test_222b () {
12012         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12013        rm -rf $DIR/$tdir
12014        test_mkdir -p $DIR/$tdir
12015        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12016        createmany -o $DIR/$tdir/$tfile 10
12017        cancel_lru_locks mdc
12018        cancel_lru_locks osc
12019        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12020        $LCTL set_param fail_loc=0x31a
12021        rm -r $DIR/$tdir || "AGL for rmdir failed"
12022        $LCTL set_param fail_loc=0
12023 }
12024 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
12025
12026 test_223 () {
12027         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12028        rm -rf $DIR/$tdir
12029        test_mkdir -p $DIR/$tdir
12030        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12031        createmany -o $DIR/$tdir/$tfile 10
12032        cancel_lru_locks mdc
12033        cancel_lru_locks osc
12034        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
12035        $LCTL set_param fail_loc=0x31b
12036        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
12037        $LCTL set_param fail_loc=0
12038        rm -r $DIR/$tdir
12039 }
12040 run_test 223 "osc reenqueue if without AGL lock granted ======================="
12041
12042 test_224a() { # LU-1039, MRP-303
12043         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12044         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
12045         $LCTL set_param fail_loc=0x508
12046         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
12047         $LCTL set_param fail_loc=0
12048         df $DIR
12049 }
12050 run_test 224a "Don't panic on bulk IO failure"
12051
12052 test_224b() { # LU-1039, MRP-303
12053         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12054         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
12055         cancel_lru_locks osc
12056         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
12057         $LCTL set_param fail_loc=0x515
12058         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
12059         $LCTL set_param fail_loc=0
12060         df $DIR
12061 }
12062 run_test 224b "Don't panic on bulk IO failure"
12063
12064 test_224c() { # LU-6441
12065         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12066         local pages_per_rpc=$($LCTL get_param \
12067                                 osc.*.max_pages_per_rpc)
12068         local at_max=$($LCTL get_param -n at_max)
12069         local timeout=$($LCTL get_param -n timeout)
12070         local test_at="$LCTL get_param -n at_max"
12071         local param_at="$FSNAME.sys.at_max"
12072         local test_timeout="$LCTL get_param -n timeout"
12073         local param_timeout="$FSNAME.sys.timeout"
12074
12075         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
12076
12077         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
12078                 error "conf_param at_max=0 failed"
12079         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
12080                 error "conf_param timeout=5 failed"
12081
12082         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
12083         $LCTL set_param fail_loc=0x520
12084         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
12085         sync
12086         $LCTL set_param fail_loc=0
12087
12088         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
12089                 error "conf_param at_max=$at_max failed"
12090         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
12091                 $timeout || error "conf_param timeout=$timeout failed"
12092
12093         $LCTL set_param -n $pages_per_rpc
12094 }
12095 run_test 224c "Don't hang if one of md lost during large bulk RPC"
12096
12097 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
12098 test_225a () {
12099         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12100         if [ -z ${MDSSURVEY} ]; then
12101               skip_env "mds-survey not found" && return
12102         fi
12103
12104         [ $MDSCOUNT -ge 2 ] &&
12105                 skip "skipping now for more than one MDT" && return
12106
12107        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12108             { skip "Need MDS version at least 2.2.51"; return; }
12109
12110        local mds=$(facet_host $SINGLEMDS)
12111        local target=$(do_nodes $mds 'lctl dl' | \
12112                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12113
12114        local cmd1="file_count=1000 thrhi=4"
12115        local cmd2="dir_count=2 layer=mdd stripe_count=0"
12116        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12117        local cmd="$cmd1 $cmd2 $cmd3"
12118
12119        rm -f ${TMP}/mds_survey*
12120        echo + $cmd
12121        eval $cmd || error "mds-survey with zero-stripe failed"
12122        cat ${TMP}/mds_survey*
12123        rm -f ${TMP}/mds_survey*
12124 }
12125 run_test 225a "Metadata survey sanity with zero-stripe"
12126
12127 test_225b () {
12128         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12129
12130         if [ -z ${MDSSURVEY} ]; then
12131               skip_env "mds-survey not found" && return
12132         fi
12133         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12134             { skip "Need MDS version at least 2.2.51"; return; }
12135
12136         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
12137               skip_env "Need to mount OST to test" && return
12138         fi
12139
12140         [ $MDSCOUNT -ge 2 ] &&
12141                 skip "skipping now for more than one MDT" && return
12142        local mds=$(facet_host $SINGLEMDS)
12143        local target=$(do_nodes $mds 'lctl dl' | \
12144                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12145
12146        local cmd1="file_count=1000 thrhi=4"
12147        local cmd2="dir_count=2 layer=mdd stripe_count=1"
12148        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12149        local cmd="$cmd1 $cmd2 $cmd3"
12150
12151        rm -f ${TMP}/mds_survey*
12152        echo + $cmd
12153        eval $cmd || error "mds-survey with stripe_count failed"
12154        cat ${TMP}/mds_survey*
12155        rm -f ${TMP}/mds_survey*
12156 }
12157 run_test 225b "Metadata survey sanity with stripe_count = 1"
12158
12159 mcreate_path2fid () {
12160         local mode=$1
12161         local major=$2
12162         local minor=$3
12163         local name=$4
12164         local desc=$5
12165         local path=$DIR/$tdir/$name
12166         local fid
12167         local rc
12168         local fid_path
12169
12170         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
12171                 error "cannot create $desc"
12172
12173         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
12174         rc=$?
12175         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
12176
12177         fid_path=$($LFS fid2path $MOUNT $fid)
12178         rc=$?
12179         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
12180
12181         [ "$path" == "$fid_path" ] ||
12182                 error "fid2path returned $fid_path, expected $path"
12183
12184         echo "pass with $path and $fid"
12185 }
12186
12187 test_226a () {
12188         rm -rf $DIR/$tdir
12189         mkdir -p $DIR/$tdir
12190
12191         mcreate_path2fid 0010666 0 0 fifo "FIFO"
12192         mcreate_path2fid 0020666 1 3 null "character special file (null)"
12193         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
12194         mcreate_path2fid 0040666 0 0 dir "directory"
12195         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
12196         mcreate_path2fid 0100666 0 0 file "regular file"
12197         mcreate_path2fid 0120666 0 0 link "symbolic link"
12198         mcreate_path2fid 0140666 0 0 sock "socket"
12199 }
12200 run_test 226a "call path2fid and fid2path on files of all type"
12201
12202 test_226b () {
12203         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12204         rm -rf $DIR/$tdir
12205         local MDTIDX=1
12206
12207         mkdir -p $DIR/$tdir
12208         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
12209                 error "create remote directory failed"
12210         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
12211         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
12212                                 "character special file (null)"
12213         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
12214                                 "character special file (no device)"
12215         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
12216         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
12217                                 "block special file (loop)"
12218         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
12219         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
12220         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
12221 }
12222 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
12223
12224 # LU-1299 Executing or running ldd on a truncated executable does not
12225 # cause an out-of-memory condition.
12226 test_227() {
12227         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12228         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
12229         dd if=$(which date) of=$MOUNT/date bs=1k count=1
12230         chmod +x $MOUNT/date
12231
12232         $MOUNT/date > /dev/null
12233         ldd $MOUNT/date > /dev/null
12234         rm -f $MOUNT/date
12235 }
12236 run_test 227 "running truncated executable does not cause OOM"
12237
12238 # LU-1512 try to reuse idle OI blocks
12239 test_228a() {
12240         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12241         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12242         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12243                 skip "non-ldiskfs backend" && return
12244
12245         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12246         local myDIR=$DIR/$tdir
12247
12248         mkdir -p $myDIR
12249         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12250         $LCTL set_param fail_loc=0x80001002
12251         createmany -o $myDIR/t- 10000
12252         $LCTL set_param fail_loc=0
12253         # The guard is current the largest FID holder
12254         touch $myDIR/guard
12255         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12256                     tr -d '[')
12257         local IDX=$(($SEQ % 64))
12258
12259         do_facet $SINGLEMDS sync
12260         # Make sure journal flushed.
12261         sleep 6
12262         local blk1=$(do_facet $SINGLEMDS \
12263                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12264                      grep Blockcount | awk '{print $4}')
12265
12266         # Remove old files, some OI blocks will become idle.
12267         unlinkmany $myDIR/t- 10000
12268         # Create new files, idle OI blocks should be reused.
12269         createmany -o $myDIR/t- 2000
12270         do_facet $SINGLEMDS sync
12271         # Make sure journal flushed.
12272         sleep 6
12273         local blk2=$(do_facet $SINGLEMDS \
12274                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12275                      grep Blockcount | awk '{print $4}')
12276
12277         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12278 }
12279 run_test 228a "try to reuse idle OI blocks"
12280
12281 test_228b() {
12282         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12283         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12284         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12285                 skip "non-ldiskfs backend" && return
12286
12287         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12288         local myDIR=$DIR/$tdir
12289
12290         mkdir -p $myDIR
12291         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12292         $LCTL set_param fail_loc=0x80001002
12293         createmany -o $myDIR/t- 10000
12294         $LCTL set_param fail_loc=0
12295         # The guard is current the largest FID holder
12296         touch $myDIR/guard
12297         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12298                     tr -d '[')
12299         local IDX=$(($SEQ % 64))
12300
12301         do_facet $SINGLEMDS sync
12302         # Make sure journal flushed.
12303         sleep 6
12304         local blk1=$(do_facet $SINGLEMDS \
12305                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12306                      grep Blockcount | awk '{print $4}')
12307
12308         # Remove old files, some OI blocks will become idle.
12309         unlinkmany $myDIR/t- 10000
12310
12311         # stop the MDT
12312         stop $SINGLEMDS || error "Fail to stop MDT."
12313         # remount the MDT
12314         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
12315
12316         df $MOUNT || error "Fail to df."
12317         # Create new files, idle OI blocks should be reused.
12318         createmany -o $myDIR/t- 2000
12319         do_facet $SINGLEMDS sync
12320         # Make sure journal flushed.
12321         sleep 6
12322         local blk2=$(do_facet $SINGLEMDS \
12323                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12324                      grep Blockcount | awk '{print $4}')
12325
12326         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12327 }
12328 run_test 228b "idle OI blocks can be reused after MDT restart"
12329
12330 #LU-1881
12331 test_228c() {
12332         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12333         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12334         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12335                 skip "non-ldiskfs backend" && return
12336
12337         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12338         local myDIR=$DIR/$tdir
12339
12340         mkdir -p $myDIR
12341         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12342         $LCTL set_param fail_loc=0x80001002
12343         # 20000 files can guarantee there are index nodes in the OI file
12344         createmany -o $myDIR/t- 20000
12345         $LCTL set_param fail_loc=0
12346         # The guard is current the largest FID holder
12347         touch $myDIR/guard
12348         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12349                     tr -d '[')
12350         local IDX=$(($SEQ % 64))
12351
12352         do_facet $SINGLEMDS sync
12353         # Make sure journal flushed.
12354         sleep 6
12355         local blk1=$(do_facet $SINGLEMDS \
12356                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12357                      grep Blockcount | awk '{print $4}')
12358
12359         # Remove old files, some OI blocks will become idle.
12360         unlinkmany $myDIR/t- 20000
12361         rm -f $myDIR/guard
12362         # The OI file should become empty now
12363
12364         # Create new files, idle OI blocks should be reused.
12365         createmany -o $myDIR/t- 2000
12366         do_facet $SINGLEMDS sync
12367         # Make sure journal flushed.
12368         sleep 6
12369         local blk2=$(do_facet $SINGLEMDS \
12370                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12371                      grep Blockcount | awk '{print $4}')
12372
12373         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12374 }
12375 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
12376
12377 test_229() { # LU-2482, LU-3448
12378         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
12379                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
12380                 return
12381         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12382         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
12383
12384         rm -f $DIR/$tfile
12385
12386         # Create a file with a released layout and stripe count 2.
12387         $MULTIOP $DIR/$tfile H2c ||
12388                 error "failed to create file with released layout"
12389
12390         $GETSTRIPE -v $DIR/$tfile
12391
12392         local pattern=$($GETSTRIPE -L $DIR/$tfile)
12393         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
12394
12395         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
12396         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
12397         stat $DIR/$tfile || error "failed to stat released file"
12398
12399         chown $RUNAS_ID $DIR/$tfile ||
12400                 error "chown $RUNAS_ID $DIR/$tfile failed"
12401
12402         chgrp $RUNAS_ID $DIR/$tfile ||
12403                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12404
12405         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12406         rm $DIR/$tfile || error "failed to remove released file"
12407 }
12408 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12409
12410 test_230a() {
12411         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12412         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12413         local MDTIDX=1
12414
12415         test_mkdir $DIR/$tdir
12416         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
12417         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12418         [ $mdt_idx -ne 0 ] &&
12419                 error "create local directory on wrong MDT $mdt_idx"
12420
12421         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12422                         error "create remote directory failed"
12423         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12424         [ $mdt_idx -ne $MDTIDX ] &&
12425                 error "create remote directory on wrong MDT $mdt_idx"
12426
12427         createmany -o $DIR/$tdir/test_230/t- 10 ||
12428                 error "create files on remote directory failed"
12429         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12430         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12431         rm -r $DIR/$tdir || error "unlink remote directory failed"
12432 }
12433 run_test 230a "Create remote directory and files under the remote directory"
12434
12435 test_230b() {
12436         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12437         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12438         local MDTIDX=1
12439         local mdt_index
12440         local i
12441         local file
12442         local pid
12443         local stripe_count
12444         local migrate_dir=$DIR/$tdir/migrate_dir
12445         local other_dir=$DIR/$tdir/other_dir
12446
12447         test_mkdir $DIR/$tdir
12448         test_mkdir -i0 -c1 $migrate_dir
12449         test_mkdir -i0 -c1 $other_dir
12450         for ((i=0; i<10; i++)); do
12451                 mkdir -p $migrate_dir/dir_${i}
12452                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12453                         error "create files under remote dir failed $i"
12454         done
12455
12456         cp /etc/passwd $migrate_dir/$tfile
12457         cp /etc/passwd $other_dir/$tfile
12458         chattr +SAD $migrate_dir
12459         chattr +SAD $migrate_dir/$tfile
12460
12461         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12462         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12463         local old_dir_mode=$(stat -c%f $migrate_dir)
12464         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
12465
12466         mkdir -p $migrate_dir/dir_default_stripe2
12467         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12468         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12469
12470         mkdir -p $other_dir
12471         ln $migrate_dir/$tfile $other_dir/luna
12472         ln $migrate_dir/$tfile $migrate_dir/sofia
12473         ln $other_dir/$tfile $migrate_dir/david
12474         ln -s $migrate_dir/$tfile $other_dir/zachary
12475         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12476         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12477
12478         $LFS mv -v -M $MDTIDX $migrate_dir ||
12479                 error "migrate remote dir error"
12480
12481         echo "migratate to MDT1, then checking.."
12482         for ((i = 0; i < 10; i++)); do
12483                 for file in $(find $migrate_dir/dir_${i}); do
12484                         mdt_index=$($LFS getstripe -M $file)
12485                         [ $mdt_index == $MDTIDX ] ||
12486                                 error "$file is not on MDT${MDTIDX}"
12487                 done
12488         done
12489
12490         # the multiple link file should still in MDT0
12491         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12492         [ $mdt_index == 0 ] ||
12493                 error "$file is not on MDT${MDTIDX}"
12494
12495         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12496         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12497                 error " expect $old_dir_flag get $new_dir_flag"
12498
12499         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12500         [ "$old_file_flag" = "$new_file_flag" ] ||
12501                 error " expect $old_file_flag get $new_file_flag"
12502
12503         local new_dir_mode=$(stat -c%f $migrate_dir)
12504         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12505                 error "expect mode $old_dir_mode get $new_dir_mode"
12506
12507         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12508         [ "$old_file_mode" = "$new_file_mode" ] ||
12509                 error "expect mode $old_file_mode get $new_file_mode"
12510
12511         diff /etc/passwd $migrate_dir/$tfile ||
12512                 error "$tfile different after migration"
12513
12514         diff /etc/passwd $other_dir/luna ||
12515                 error "luna different after migration"
12516
12517         diff /etc/passwd $migrate_dir/sofia ||
12518                 error "sofia different after migration"
12519
12520         diff /etc/passwd $migrate_dir/david ||
12521                 error "david different after migration"
12522
12523         diff /etc/passwd $other_dir/zachary ||
12524                 error "zachary different after migration"
12525
12526         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12527                 error "${tfile}_ln different after migration"
12528
12529         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12530                 error "${tfile}_ln_other different after migration"
12531
12532         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12533         [ $stripe_count = 2 ] ||
12534                 error "dir strpe_count $d != 2 after migration."
12535
12536         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12537         [ $stripe_count = 2 ] ||
12538                 error "file strpe_count $d != 2 after migration."
12539
12540         #migrate back to MDT0
12541         MDTIDX=0
12542         $LFS mv -v -M $MDTIDX $migrate_dir ||
12543                 error "migrate remote dir error"
12544
12545         echo "migrate back to MDT0, checking.."
12546         for file in $(find $migrate_dir); do
12547                 mdt_index=$($LFS getstripe -M $file)
12548                 [ $mdt_index == $MDTIDX ] ||
12549                         error "$file is not on MDT${MDTIDX}"
12550         done
12551
12552         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12553         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12554                 error " expect $old_dir_flag get $new_dir_flag"
12555
12556         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12557         [ "$old_file_flag" = "$new_file_flag" ] ||
12558                 error " expect $old_file_flag get $new_file_flag"
12559
12560         local new_dir_mode=$(stat -c%f $migrate_dir)
12561         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12562                 error "expect mode $old_dir_mode get $new_dir_mode"
12563
12564         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12565         [ "$old_file_mode" = "$new_file_mode" ] ||
12566                 error "expect mode $old_file_mode get $new_file_mode"
12567
12568         diff /etc/passwd ${migrate_dir}/$tfile ||
12569                 error "$tfile different after migration"
12570
12571         diff /etc/passwd ${other_dir}/luna ||
12572                 error "luna different after migration"
12573
12574         diff /etc/passwd ${migrate_dir}/sofia ||
12575                 error "sofia different after migration"
12576
12577         diff /etc/passwd ${other_dir}/zachary ||
12578                 error "zachary different after migration"
12579
12580         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12581                 error "${tfile}_ln different after migration"
12582
12583         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12584                 error "${tfile}_ln_other different after migration"
12585
12586         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12587         [ $stripe_count = 2 ] ||
12588                 error "dir strpe_count $d != 2 after migration."
12589
12590         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12591         [ $stripe_count = 2 ] ||
12592                 error "file strpe_count $d != 2 after migration."
12593
12594         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12595 }
12596 run_test 230b "migrate directory"
12597
12598 test_230c() {
12599         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12600         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12601         local MDTIDX=1
12602         local mdt_index
12603         local file
12604         local migrate_dir=$DIR/$tdir/migrate_dir
12605
12606         #If migrating directory fails in the middle, all entries of
12607         #the directory is still accessiable.
12608         test_mkdir $DIR/$tdir
12609         test_mkdir -i0 -c1 $migrate_dir
12610         stat $migrate_dir
12611         createmany -o $migrate_dir/f 10 ||
12612                 error "create files under ${migrate_dir} failed"
12613
12614         #failed after migrating 5 entries
12615         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12616         do_facet mds1 lctl set_param fail_loc=0x20001801
12617         do_facet mds1 lctl  set_param fail_val=5
12618         local t=$(ls $migrate_dir | wc -l)
12619         $LFS mv --mdt-index $MDTIDX $migrate_dir &&
12620                 error "migrate should fail after 5 entries"
12621         local u=$(ls $migrate_dir | wc -l)
12622         [ "$u" == "$t" ] || error "$u != $t during migration"
12623
12624         for file in $(find $migrate_dir); do
12625                 stat $file || error "stat $file failed"
12626         done
12627
12628         do_facet mds1 lctl set_param fail_loc=0
12629         do_facet mds1 lctl set_param fail_val=0
12630
12631         $LFS mv -M $MDTIDX $migrate_dir ||
12632                 error "migrate open files should failed with open files"
12633
12634         echo "Finish migration, then checking.."
12635         for file in $(find $migrate_dir); do
12636                 mdt_index=$($LFS getstripe -M $file)
12637                 [ $mdt_index == $MDTIDX ] ||
12638                         error "$file is not on MDT${MDTIDX}"
12639         done
12640
12641         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12642 }
12643 run_test 230c "check directory accessiblity if migration is failed"
12644
12645 test_230d() {
12646         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12647         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12648         local MDTIDX=1
12649         local mdt_index
12650         local migrate_dir=$DIR/$tdir/migrate_dir
12651         local i
12652         local j
12653
12654         test_mkdir $DIR/$tdir
12655         test_mkdir -i0 -c1 $migrate_dir
12656
12657         for ((i=0; i<100; i++)); do
12658                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
12659                 createmany -o $migrate_dir/dir_${i}/f 100 ||
12660                         error "create files under remote dir failed $i"
12661         done
12662
12663         $LFS mv -M $MDTIDX -v $migrate_dir || error "migrate remote dir error"
12664
12665         echo "Finish migration, then checking.."
12666         for file in $(find $migrate_dir); do
12667                 mdt_index=$($LFS getstripe -M $file)
12668                 [ $mdt_index == $MDTIDX ] ||
12669                         error "$file is not on MDT${MDTIDX}"
12670         done
12671
12672         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12673 }
12674 run_test 230d "check migrate big directory"
12675
12676 test_231a()
12677 {
12678         # For simplicity this test assumes that max_pages_per_rpc
12679         # is the same across all OSCs
12680         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
12681         local bulk_size=$((max_pages * 4096))
12682
12683         mkdir -p $DIR/$tdir
12684
12685         # clear the OSC stats
12686         $LCTL set_param osc.*.stats=0 &>/dev/null
12687
12688         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
12689         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
12690                 oflag=direct &>/dev/null || error "dd failed"
12691
12692         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
12693         if [ x$nrpcs != "x1" ]; then
12694                 error "found $nrpc ost_write RPCs, not 1 as expected"
12695         fi
12696
12697         # Drop the OSC cache, otherwise we will read from it
12698         cancel_lru_locks osc
12699
12700         # clear the OSC stats
12701         $LCTL set_param osc.*.stats=0 &>/dev/null
12702
12703         # Client reads $bulk_size.
12704         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
12705                 iflag=direct &>/dev/null || error "dd failed"
12706
12707         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
12708         if [ x$nrpcs != "x1" ]; then
12709                 error "found $nrpc ost_read RPCs, not 1 as expected"
12710         fi
12711 }
12712 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
12713
12714 test_231b() {
12715         mkdir -p $DIR/$tdir
12716         local i
12717         for i in {0..1023}; do
12718                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
12719                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
12720                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
12721         done
12722         sync
12723 }
12724 run_test 231b "must not assert on fully utilized OST request buffer"
12725
12726 test_232() {
12727         mkdir -p $DIR/$tdir
12728         #define OBD_FAIL_LDLM_OST_LVB            0x31c
12729         $LCTL set_param fail_loc=0x31c
12730
12731         # ignore dd failure
12732         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
12733
12734         $LCTL set_param fail_loc=0
12735         umount_client $MOUNT || error "umount failed"
12736         mount_client $MOUNT || error "mount failed"
12737 }
12738 run_test 232 "failed lock should not block umount"
12739
12740 test_233a() {
12741         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
12742         { skip "Need MDS version at least 2.3.64"; return; }
12743
12744         local fid=$($LFS path2fid $MOUNT)
12745         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12746                 error "cannot access $MOUNT using its FID '$fid'"
12747 }
12748 run_test 233a "checking that OBF of the FS root succeeds"
12749
12750 test_233b() {
12751         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
12752         { skip "Need MDS version at least 2.5.90"; return; }
12753
12754         local fid=$($LFS path2fid $MOUNT/.lustre)
12755         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12756                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
12757
12758         fid=$($LFS path2fid $MOUNT/.lustre/fid)
12759         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12760                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
12761 }
12762 run_test 233b "checking that OBF of the FS .lustre succeeds"
12763
12764 test_234() {
12765         local p="$TMP/sanityN-$TESTNAME.parameters"
12766         save_lustre_params client "llite.*.xattr_cache" > $p
12767         lctl set_param llite.*.xattr_cache 1 ||
12768                 { skip "xattr cache is not supported"; return 0; }
12769
12770         mkdir -p $DIR/$tdir || error "mkdir failed"
12771         touch $DIR/$tdir/$tfile || error "touch failed"
12772         # OBD_FAIL_LLITE_XATTR_ENOMEM
12773         $LCTL set_param fail_loc=0x1405
12774         # output of the form: attr 2 4 44 3 fc13 x86_64
12775         V=($(IFS=".-" rpm -q attr))
12776         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
12777               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
12778                 # attr pre-2.4.44-7 had a bug with rc
12779                 # LU-3703 - SLES 11 and FC13 clients have older attr
12780                 getfattr -n user.attr $DIR/$tdir/$tfile &&
12781                         error "getfattr should have failed with ENOMEM"
12782         else
12783                 skip "LU-3703: attr version $(getfattr --version) too old"
12784         fi
12785         $LCTL set_param fail_loc=0x0
12786         rm -rf $DIR/$tdir
12787
12788         restore_lustre_params < $p
12789         rm -f $p
12790 }
12791 run_test 234 "xattr cache should not crash on ENOMEM"
12792
12793 test_235() {
12794         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
12795                 skip "Need MDS version at least 2.4.52" && return
12796         flock_deadlock $DIR/$tfile
12797         local RC=$?
12798         case $RC in
12799                 0)
12800                 ;;
12801                 124) error "process hangs on a deadlock"
12802                 ;;
12803                 *) error "error executing flock_deadlock $DIR/$tfile"
12804                 ;;
12805         esac
12806 }
12807 run_test 235 "LU-1715: flock deadlock detection does not work properly"
12808
12809 #LU-2935
12810 test_236() {
12811         check_swap_layouts_support && return 0
12812         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
12813
12814         local ref1=/etc/passwd
12815         local ref2=/etc/group
12816         local file1=$DIR/$tdir/f1
12817         local file2=$DIR/$tdir/f2
12818
12819         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
12820         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
12821         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
12822         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
12823         local fd=$(free_fd)
12824         local cmd="exec $fd<>$file2"
12825         eval $cmd
12826         rm $file2
12827         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
12828                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
12829         cmd="exec $fd>&-"
12830         eval $cmd
12831         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12832
12833         #cleanup
12834         rm -rf $DIR/$tdir
12835 }
12836 run_test 236 "Layout swap on open unlinked file"
12837
12838 # test to verify file handle related system calls
12839 # (name_to_handle_at/open_by_handle_at)
12840 # The new system calls are supported in glibc >= 2.14.
12841
12842 test_237() {
12843         echo "Test file_handle syscalls" > $DIR/$tfile ||
12844                 error "write failed"
12845         check_fhandle_syscalls $DIR/$tfile ||
12846                 error "check_fhandle_syscalls failed"
12847 }
12848 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
12849
12850 # LU-4659 linkea consistency
12851 test_238() {
12852         local server_version=$(lustre_version_code $SINGLEMDS)
12853
12854         [[ $server_version -gt $(version_code 2.5.57) ]] ||
12855                 [[ $server_version -gt $(version_code 2.5.1) &&
12856                    $server_version -lt $(version_code 2.5.50) ]] ||
12857                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
12858
12859         touch $DIR/$tfile
12860         ln $DIR/$tfile $DIR/$tfile.lnk
12861         touch $DIR/$tfile.new
12862         mv $DIR/$tfile.new $DIR/$tfile
12863         local fid1=$($LFS path2fid $DIR/$tfile)
12864         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
12865         local path1=$($LFS fid2path $FSNAME "$fid1")
12866         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
12867         local path2=$($LFS fid2path $FSNAME "$fid2")
12868         [ $tfile.lnk == $path2 ] ||
12869                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
12870         rm -f $DIR/$tfile*
12871 }
12872 run_test 238 "Verify linkea consistency"
12873
12874 test_239() {
12875         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
12876                 skip "Need MDS version at least 2.5.60" && return
12877         local list=$(comma_list $(mdts_nodes))
12878
12879         mkdir -p $DIR/$tdir
12880         createmany -o $DIR/$tdir/f- 5000
12881         unlinkmany $DIR/$tdir/f- 5000
12882         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
12883         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
12884                         osc.*MDT*.sync_in_flight" | calc_sum)
12885         [ "$changes" -eq 0 ] || error "$changes not synced"
12886 }
12887 run_test 239 "osp_sync test"
12888
12889 test_240() {
12890         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12891
12892         mkdir -p $DIR/$tdir
12893
12894         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
12895                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
12896         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
12897                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
12898
12899         umount_client $MOUNT || error "umount failed"
12900         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
12901         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
12902         mount_client $MOUNT || error "failed to mount client"
12903
12904         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
12905         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
12906 }
12907 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
12908
12909 test_241_bio() {
12910         for LOOP in $(seq $1); do
12911                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
12912                 cancel_lru_locks osc
12913         done
12914 }
12915
12916 test_241_dio() {
12917         for LOOP in $(seq $1); do
12918                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
12919                                                 iflag=direct 2>/dev/null
12920         done
12921 }
12922
12923 test_241() {
12924         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
12925         ls -la $DIR/$tfile
12926         cancel_lru_locks osc
12927         test_241_bio 1000 &
12928         PID=$!
12929         test_241_dio 1000
12930         wait $PID
12931 }
12932 run_test 241 "bio vs dio"
12933
12934 test_241b() {
12935         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
12936         ls -la $DIR/$tfile
12937         test_241_dio 1000 &
12938         PID=$!
12939         test_241_dio 1000
12940         wait $PID
12941 }
12942 run_test 241b "dio vs dio"
12943
12944 test_242() {
12945         mkdir -p $DIR/$tdir
12946         touch $DIR/$tdir/$tfile
12947
12948         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
12949         do_facet mds1 lctl set_param fail_loc=0x105
12950         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
12951
12952         do_facet mds1 lctl set_param fail_loc=0
12953         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
12954 }
12955 run_test 242 "mdt_readpage failure should not cause directory unreadable"
12956
12957 test_243()
12958 {
12959         test_mkdir -p $DIR/$tdir
12960         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
12961 }
12962 run_test 243 "various group lock tests"
12963
12964 test_244()
12965 {
12966         test_mkdir -p $DIR/$tdir
12967         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
12968         sendfile_grouplock $DIR/$tdir/$tfile || \
12969                 error "sendfile+grouplock failed"
12970         rm -rf $DIR/$tdir
12971 }
12972 run_test 244 "sendfile with group lock tests"
12973
12974 test_250() {
12975         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
12976          && skip "no 16TB file size limit on ZFS" && return
12977
12978         $SETSTRIPE -c 1 $DIR/$tfile
12979         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
12980         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
12981         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
12982         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
12983                 conv=notrunc,fsync && error "append succeeded"
12984         return 0
12985 }
12986 run_test 250 "Write above 16T limit"
12987
12988 test_251() {
12989         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
12990
12991         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
12992         #Skip once - writing the first stripe will succeed
12993         $LCTL set_param fail_loc=0xa0001407 fail_val=1
12994         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
12995                 error "short write happened"
12996
12997         $LCTL set_param fail_loc=0xa0001407 fail_val=1
12998         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
12999                 error "short read happened"
13000
13001         rm -f $DIR/$tfile
13002 }
13003 run_test 251 "Handling short read and write correctly"
13004
13005 cleanup_test_300() {
13006         trap 0
13007         umask $SAVE_UMASK
13008 }
13009 test_striped_dir() {
13010         local mdt_index=$1
13011         local stripe_count
13012         local stripe_index
13013
13014         mkdir -p $DIR/$tdir
13015
13016         SAVE_UMASK=$(umask)
13017         trap cleanup_test_300 RETURN EXIT
13018
13019         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
13020                                                 $DIR/$tdir/striped_dir ||
13021                 error "set striped dir error"
13022
13023         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
13024         [ "$mode" = "755" ] || error "expect 755 got $mode"
13025
13026         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
13027         if [ "$stripe_count" != "2" ]; then
13028                 error "stripe_count is $stripe_count, expect 2"
13029         fi
13030
13031         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
13032         if [ "$stripe_index" != "$mdt_index" ]; then
13033                 error "stripe_index is $stripe_index, expect $mdt_index"
13034         fi
13035
13036         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13037                 error "nlink error after create striped dir"
13038
13039         mkdir $DIR/$tdir/striped_dir/a
13040         mkdir $DIR/$tdir/striped_dir/b
13041
13042         stat $DIR/$tdir/striped_dir/a ||
13043                 error "create dir under striped dir failed"
13044         stat $DIR/$tdir/striped_dir/b ||
13045                 error "create dir under striped dir failed"
13046
13047         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
13048                 error "nlink error after mkdir"
13049
13050         rmdir $DIR/$tdir/striped_dir/a
13051         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
13052                 error "nlink error after rmdir"
13053
13054         rmdir $DIR/$tdir/striped_dir/b
13055         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13056                 error "nlink error after rmdir"
13057
13058         chattr +i $DIR/$tdir/striped_dir
13059         createmany -o $DIR/$tdir/striped_dir/f 10 &&
13060                 error "immutable flags not working under striped dir!"
13061         chattr -i $DIR/$tdir/striped_dir
13062
13063         rmdir $DIR/$tdir/striped_dir ||
13064                 error "rmdir striped dir error"
13065
13066         cleanup_test_300
13067
13068         true
13069 }
13070
13071 test_300a() {
13072         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13073         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13074
13075         test_striped_dir 0 || error "failed on striped dir on MDT0"
13076         test_striped_dir 1 || error "failed on striped dir on MDT0"
13077 }
13078 run_test 300a "basic striped dir sanity test"
13079
13080 test_300b() {
13081         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13082         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13083         local i
13084         local mtime1
13085         local mtime2
13086         local mtime3
13087
13088         test_mkdir $DIR/$tdir || error "mkdir fail"
13089         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13090                 error "set striped dir error"
13091         for ((i=0; i<10; i++)); do
13092                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
13093                 sleep 1
13094                 touch $DIR/$tdir/striped_dir/file_$i ||
13095                                         error "touch error $i"
13096                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
13097                 [ $mtime1 -eq $mtime2 ] &&
13098                         error "mtime not change after create"
13099                 sleep 1
13100                 rm -f $DIR/$tdir/striped_dir/file_$i ||
13101                                         error "unlink error $i"
13102                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
13103                 [ $mtime2 -eq $mtime3 ] &&
13104                         error "mtime did not change after unlink"
13105         done
13106         true
13107 }
13108 run_test 300b "check ctime/mtime for striped dir"
13109
13110 test_300c() {
13111         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13112         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13113         local file_count
13114
13115         mkdir -p $DIR/$tdir
13116         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
13117                 error "set striped dir error"
13118
13119         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
13120                 error "chown striped dir failed"
13121
13122         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
13123                 error "create 5k files failed"
13124
13125         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
13126
13127         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
13128
13129         rm -rf $DIR/$tdir
13130 }
13131 run_test 300c "chown && check ls under striped directory"
13132
13133 test_300d() {
13134         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13135         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13136         local stripe_count
13137         local file
13138
13139         mkdir -p $DIR/$tdir
13140         $SETSTRIPE -c 2 $DIR/$tdir
13141
13142         #local striped directory
13143         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13144                 error "set striped dir error"
13145         createmany -o $DIR/$tdir/striped_dir/f 10 ||
13146                 error "create 10 files failed"
13147
13148         #remote striped directory
13149         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
13150                 error "set striped dir error"
13151         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
13152                 error "create 10 files failed"
13153
13154         for file in $(find $DIR/$tdir); do
13155                 stripe_count=$($GETSTRIPE -c $file)
13156                 [ $stripe_count -eq 2 ] ||
13157                         error "wrong stripe $stripe_count for $file"
13158         done
13159
13160         rm -rf $DIR/$tdir
13161 }
13162 run_test 300d "check default stripe under striped directory"
13163
13164 test_300e() {
13165         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13166         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13167         local stripe_count
13168         local file
13169
13170         mkdir -p $DIR/$tdir
13171
13172         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13173                 error "set striped dir error"
13174
13175         touch $DIR/$tdir/striped_dir/a
13176         touch $DIR/$tdir/striped_dir/b
13177         touch $DIR/$tdir/striped_dir/c
13178
13179         mkdir $DIR/$tdir/striped_dir/dir_a
13180         mkdir $DIR/$tdir/striped_dir/dir_b
13181         mkdir $DIR/$tdir/striped_dir/dir_c
13182
13183         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
13184                 error "set striped dir under striped dir error"
13185
13186         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
13187                 error "set striped dir under striped dir error"
13188
13189         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
13190                 error "set striped dir under striped dir error"
13191
13192         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/b &&
13193                 error "rename file under striped dir should fail"
13194
13195         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b &&
13196                 error "rename dir under striped dir should fail"
13197
13198         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b &&
13199                 error "rename dir under different stripes should fail"
13200
13201         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
13202                 error "rename file under striped dir should succeed"
13203
13204         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_c ||
13205                 error "rename dir under striped dir should succeed"
13206
13207         rm -rf $DIR/$tdir
13208 }
13209 run_test 300e "check rename under striped directory"
13210
13211 test_300f() {
13212         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13213         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13214         local stripe_count
13215         local file
13216
13217         rm -rf $DIR/$tdir
13218         mkdir -p $DIR/$tdir
13219
13220         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13221                 error "set striped dir error"
13222
13223         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
13224                 error "set striped dir error"
13225
13226         touch $DIR/$tdir/striped_dir/a
13227         mkdir $DIR/$tdir/striped_dir/dir_a
13228         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
13229                 error "create striped dir under striped dir fails"
13230
13231         touch $DIR/$tdir/striped_dir1/b
13232         mkdir $DIR/$tdir/striped_dir1/dir_b
13233         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
13234                 error "create striped dir under striped dir fails"
13235
13236         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/b &&
13237                 error "rename file under different striped dir should fail"
13238
13239         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b &&
13240                 error "rename dir under different striped dir should fail"
13241
13242         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b &&
13243                 error "rename striped dir under diff striped dir should fail"
13244
13245         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
13246                 error "rename file under diff striped dirs fails"
13247
13248         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_a ||
13249                 error "rename dir under diff striped dirs fails"
13250
13251         rm -rf $DIR/$tdir
13252 }
13253 run_test 300f "check rename cross striped directory"
13254
13255 test_300_check_default_striped_dir()
13256 {
13257         local dirname=$1
13258         local default_count=$2
13259         local default_index=$3
13260         local stripe_count
13261         local stripe_index
13262         local dir_stripe_index
13263         local dir
13264
13265         echo "checking $dirname $default_count $default_index"
13266         $LFS setdirstripe -D -c $default_count -i $default_index \
13267                                 -t all_char $DIR/$tdir/$dirname ||
13268                 error "set default stripe on striped dir error"
13269         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
13270         [ $stripe_count -eq $default_count ] ||
13271                 error "expect $default_count get $stripe_count for $dirname"
13272
13273         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
13274         [ $stripe_index -eq $default_index ] ||
13275                 error "expect $default_index get $stripe_index for $dirname"
13276
13277         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
13278                                                 error "create dirs failed"
13279
13280         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
13281         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
13282         for dir in $(find $DIR/$tdir/$dirname/*); do
13283                 stripe_count=$($LFS getdirstripe -c $dir)
13284                 [ $stripe_count -eq $default_count ] ||
13285                 error "stripe count $default_count != $stripe_count for $dir"
13286
13287                 stripe_index=$($LFS getdirstripe -i $dir)
13288                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
13289                         error "$stripe_index != $default_index for $dir"
13290
13291                 #check default stripe
13292                 stripe_count=$($LFS getdirstripe -D -c $dir)
13293                 [ $stripe_count -eq $default_count ] ||
13294                 error "default count $default_count != $stripe_count for $dir"
13295
13296                 stripe_index=$($LFS getdirstripe -D -i $dir)
13297                 [ $stripe_index -eq $default_index ] ||
13298                 error "default index $default_index != $stripe_index for $dir"
13299         done
13300         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
13301 }
13302
13303 test_300g() {
13304         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13305         local dir
13306         local stripe_count
13307         local stripe_index
13308
13309         mkdir $DIR/$tdir
13310         mkdir $DIR/$tdir/normal_dir
13311
13312         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
13313         test_300_check_default_striped_dir normal_dir 1 0
13314         test_300_check_default_striped_dir normal_dir 2 1
13315         test_300_check_default_striped_dir normal_dir 2 -1
13316
13317         #delete default stripe information
13318         echo "delete default stripeEA"
13319         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
13320                 error "set default stripe on striped dir error"
13321
13322         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
13323         for dir in $(find $DIR/$tdir/normal_dir/*); do
13324                 stripe_count=$($LFS getdirstripe -c $dir)
13325                 [ $stripe_count -eq 0 ] ||
13326                         error "expect 1 get $stripe_count for $dir"
13327                 stripe_index=$($LFS getdirstripe -i $dir)
13328                 [ $stripe_index -eq 0 ] ||
13329                         error "expect 0 get $stripe_index for $dir"
13330         done
13331 }
13332 run_test 300g "check default striped directory for normal directory"
13333
13334 test_300h() {
13335         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13336         local dir
13337         local stripe_count
13338
13339         mkdir $DIR/$tdir
13340         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
13341                                         $DIR/$tdir/striped_dir ||
13342                 error "set striped dir error"
13343
13344         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
13345         test_300_check_default_striped_dir striped_dir 1 0
13346         test_300_check_default_striped_dir striped_dir 2 1
13347         test_300_check_default_striped_dir striped_dir 2 -1
13348
13349         #delete default stripe information
13350         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
13351                 error "set default stripe on striped dir error"
13352
13353         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
13354         for dir in $(find $DIR/$tdir/striped_dir/*); do
13355                 stripe_count=$($LFS getdirstripe -c $dir)
13356                 [ $stripe_count -eq 0 ] ||
13357                         error "expect 1 get $stripe_count for $dir"
13358         done
13359 }
13360 run_test 300h "check default striped directory for striped directory"
13361
13362 test_300i() {
13363         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13364         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13365         local stripe_count
13366         local file
13367
13368         mkdir $DIR/$tdir
13369
13370         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
13371                 error "set striped dir error"
13372
13373         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
13374                 error "create files under striped dir failed"
13375
13376         # unfortunately, we need to umount to clear dir layout cache for now
13377         # once we fully implement dir layout, we can drop this
13378         umount_client $MOUNT || error "umount failed"
13379         mount_client $MOUNT || error "mount failed"
13380
13381         #set the stripe to be unknown hash type
13382         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
13383         $LCTL set_param fail_loc=0x1901
13384         for ((i = 0; i < 10; i++)); do
13385                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
13386                         error "stat f-$i failed"
13387                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
13388         done
13389
13390         touch $DIR/$tdir/striped_dir/f0 &&
13391                 error "create under striped dir with unknown hash should fail"
13392
13393         $LCTL set_param fail_loc=0
13394
13395         umount_client $MOUNT || error "umount failed"
13396         mount_client $MOUNT || error "mount failed"
13397
13398         return 0
13399 }
13400 run_test 300i "client handle unknown hash type striped directory"
13401
13402 test_400a() { # LU-1606, was conf-sanity test_74
13403         local extra_flags=''
13404         local out=$TMP/$tfile
13405         local prefix=/usr/include/lustre
13406         local prog
13407
13408         if ! which $CC > /dev/null 2>&1; then
13409                 skip_env "$CC is not installed"
13410                 return 0
13411         fi
13412
13413         if ! [[ -d $prefix ]]; then
13414                 # Assume we're running in tree and fixup the include path.
13415                 extra_flags+=" -I$LUSTRE/../libcfs/include"
13416                 extra_flags+=" -I$LUSTRE/include"
13417                 extra_flags+=" -L$LUSTRE/utils"
13418         fi
13419
13420         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
13421                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
13422                         error "client api broken"
13423         done
13424 }
13425 run_test 400a "Lustre client api program can compile and link"
13426
13427 test_400b() { # LU-1606, LU-5011
13428         local header
13429         local out=$TMP/$tfile
13430         local prefix=/usr/include/lustre
13431
13432         # We use a hard coded prefix so that this test will not fail
13433         # when run in tree. There are headers in lustre/include/lustre/
13434         # that are not packaged (like lustre_idl.h) and have more
13435         # complicated include dependencies (like config.h and lnet/types.h).
13436         # Since this test about correct packaging we just skip them when
13437         # they don't exist (see below) rather than try to fixup cppflags.
13438
13439         if ! which $CC > /dev/null 2>&1; then
13440                 skip_env "$CC is not installed"
13441                 return 0
13442         fi
13443
13444         for header in $prefix/*.h; do
13445                 if ! [[ -f "$header" ]]; then
13446                         continue
13447                 fi
13448
13449                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
13450                         continue # liblustreapi.h is deprecated.
13451                 fi
13452
13453                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
13454                         error "cannot compile '$header'"
13455         done
13456 }
13457 run_test 400b "packaged headers can be compiled"
13458
13459 #
13460 # tests that do cleanup/setup should be run at the end
13461 #
13462
13463 test_900() {
13464         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13465         local ls
13466         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
13467         $LCTL set_param fail_loc=0x903
13468
13469         cancel_lru_locks MGC
13470
13471         FAIL_ON_ERROR=true cleanup
13472         FAIL_ON_ERROR=true setup
13473 }
13474 run_test 900 "umount should not race with any mgc requeue thread"
13475
13476 complete $SECONDS
13477 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
13478 check_and_cleanup_lustre
13479 if [ "$I_MOUNTED" != "yes" ]; then
13480         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
13481 fi
13482 exit_status