Whamcloud - gitweb
LU-6602 update: split update llog record
[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"
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                 test_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         rm $DIR/$tdir/${tfile}_2 || error "unlink failed after rename"
358 }
359 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
360
361 test_16() {
362         test_mkdir $DIR/$tdir
363         touch $DIR/$tdir/$tfile
364         rm -rf $DIR/$tdir/$tfile
365         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
366 }
367 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
368
369 test_17a() {
370         test_mkdir -p $DIR/$tdir
371         touch $DIR/$tdir/$tfile
372         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
373         ls -l $DIR/$tdir
374         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
375                 error "$tdir/l-exist not a symlink"
376         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
377                 error "$tdir/l-exist not referencing a file"
378         rm -f $DIR/$tdir/l-exist
379         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
380 }
381 run_test 17a "symlinks: create, remove (real) =================="
382
383 test_17b() {
384         test_mkdir -p $DIR/$tdir
385         ln -s no-such-file $DIR/$tdir/l-dangle
386         ls -l $DIR/$tdir
387         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
388                 error "$tdir/l-dangle not referencing no-such-file"
389         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
390                 error "$tdir/l-dangle not referencing non-existent file"
391         rm -f $DIR/$tdir/l-dangle
392         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
393 }
394 run_test 17b "symlinks: create, remove (dangling) =============="
395
396 test_17c() { # bug 3440 - don't save failed open RPC for replay
397         test_mkdir -p $DIR/$tdir
398         ln -s foo $DIR/$tdir/$tfile
399         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
400 }
401 run_test 17c "symlinks: open dangling (should return error) ===="
402
403 test_17d() {
404         test_mkdir -p $DIR/$tdir
405         ln -s foo $DIR/$tdir/$tfile
406         touch $DIR/$tdir/$tfile || error "creating to new symlink"
407 }
408 run_test 17d "symlinks: create dangling ========================"
409
410 test_17e() {
411         test_mkdir -p $DIR/$tdir
412         local foo=$DIR/$tdir/$tfile
413         ln -s $foo $foo || error "create symlink failed"
414         ls -l $foo || error "ls -l failed"
415         ls $foo && error "ls not failed" || true
416 }
417 run_test 17e "symlinks: create recursive symlink (should return error) ===="
418
419 test_17f() {
420         test_mkdir -p $DIR/$tdir
421         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
422         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
423         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
424         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
425         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
426         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
427         ls -l  $DIR/$tdir
428 }
429 run_test 17f "symlinks: long and very long symlink name ========================"
430
431 # str_repeat(S, N) generate a string that is string S repeated N times
432 str_repeat() {
433         local s=$1
434         local n=$2
435         local ret=''
436         while [ $((n -= 1)) -ge 0 ]; do
437                 ret=$ret$s
438         done
439         echo $ret
440 }
441
442 # Long symlinks and LU-2241
443 test_17g() {
444         test_mkdir -p $DIR/$tdir
445         local TESTS="59 60 61 4094 4095"
446
447         # Fix for inode size boundary in 2.1.4
448         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
449                 TESTS="4094 4095"
450
451         # Patch not applied to 2.2 or 2.3 branches
452         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
453         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
454                 TESTS="4094 4095"
455
456         # skip long symlink name for rhel6.5.
457         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
458         grep -q '6.5' /etc/redhat-release &>/dev/null &&
459                 TESTS="59 60 61 4062 4063"
460
461         for i in $TESTS; do
462                 local SYMNAME=$(str_repeat 'x' $i)
463                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
464                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
465         done
466 }
467 run_test 17g "symlinks: really long symlink name and inode boundaries"
468
469 test_17h() { #bug 17378
470         remote_mds_nodsh && skip "remote MDS with nodsh" && return
471         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
472         local mdt_idx
473         test_mkdir -p $DIR/$tdir
474         if [[ $MDSCOUNT -gt 1 ]]; then
475                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
476         else
477                 mdt_idx=0
478         fi
479         $SETSTRIPE -c -1 $DIR/$tdir
480 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
481         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
482         touch $DIR/$tdir/$tfile || true
483 }
484 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
485
486 test_17i() { #bug 20018
487         remote_mds_nodsh && skip "remote MDS with nodsh" && return
488         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
489         test_mkdir -c1 $DIR/$tdir
490         local foo=$DIR/$tdir/$tfile
491         local mdt_idx
492         if [[ $MDSCOUNT -gt 1 ]]; then
493                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
494         else
495                 mdt_idx=0
496         fi
497         ln -s $foo $foo || error "create symlink failed"
498 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
499         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
500         ls -l $foo && error "error not detected"
501         return 0
502 }
503 run_test 17i "don't panic on short symlink"
504
505 test_17k() { #bug 22301
506         [[ -z "$(which rsync 2>/dev/null)" ]] &&
507                 skip "no rsync command" && return 0
508         rsync --help | grep -q xattr ||
509                 skip_env "$(rsync --version | head -n1) does not support xattrs"
510         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
511         test_mkdir -p $DIR/$tdir
512         test_mkdir -p $DIR/$tdir.new
513         touch $DIR/$tdir/$tfile
514         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
515         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
516                 error "rsync failed with xattrs enabled"
517 }
518 run_test 17k "symlinks: rsync with xattrs enabled ========================="
519
520 test_17l() { # LU-279
521         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
522                 skip "no getfattr command" && return 0
523         test_mkdir -p $DIR/$tdir
524         touch $DIR/$tdir/$tfile
525         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
526         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
527                 # -h to not follow symlinks. -m '' to list all the xattrs.
528                 # grep to remove first line: '# file: $path'.
529                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
530                 do
531                         lgetxattr_size_check $path $xattr ||
532                                 error "lgetxattr_size_check $path $xattr failed"
533                 done
534         done
535 }
536 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
537
538 # LU-1540
539 test_17m() {
540         local short_sym="0123456789"
541         local WDIR=$DIR/${tdir}m
542         local mds_index
543         local devname
544         local cmd
545         local i
546         local rc=0
547
548         remote_mds_nodsh && skip "remote MDS with nodsh" && return
549         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
550         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
551                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
552
553         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
554                 skip "only for ldiskfs MDT" && return 0
555
556         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
557
558         test_mkdir -p $WDIR
559         long_sym=$short_sym
560         # create a long symlink file
561         for ((i = 0; i < 4; ++i)); do
562                 long_sym=${long_sym}${long_sym}
563         done
564
565         echo "create 512 short and long symlink files under $WDIR"
566         for ((i = 0; i < 256; ++i)); do
567                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
568                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
569         done
570
571         echo "erase them"
572         rm -f $WDIR/*
573         sync
574         wait_delete_completed
575
576         echo "recreate the 512 symlink files with a shorter string"
577         for ((i = 0; i < 512; ++i)); do
578                 # rewrite the symlink file with a shorter string
579                 ln -sf ${long_sym} $WDIR/long-$i
580                 ln -sf ${short_sym} $WDIR/short-$i
581         done
582
583         mds_index=$($LFS getstripe -M $WDIR)
584         mds_index=$((mds_index+1))
585         devname=$(mdsdevname $mds_index)
586         cmd="$E2FSCK -fnvd $devname"
587
588         echo "stop and checking mds${mds_index}: $cmd"
589         # e2fsck should not return error
590         stop mds${mds_index}
591         do_facet mds${mds_index} $cmd || rc=$?
592
593         start mds${mds_index} $devname $MDS_MOUNT_OPTS || error "start failed"
594         df $MOUNT > /dev/null 2>&1
595         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
596                 "short/long symlink MDT: rc=$rc"
597         return $rc
598 }
599 run_test 17m "run e2fsck against MDT which contains short/long symlink"
600
601 check_fs_consistency_17n() {
602         local mdt_index
603         local devname
604         local cmd
605         local rc=0
606
607         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
608         # so it only check MDT1/MDT2 instead of all of MDTs.
609         for mdt_index in $(seq 1 2); do
610                 devname=$(mdsdevname $mdt_index)
611                 cmd="$E2FSCK -fnvd $devname"
612
613                 echo "stop and checking mds${mdt_index}: $cmd"
614                 # e2fsck should not return error
615                 stop mds${mdt_index}
616                 do_facet mds${mdt_index} $cmd || rc=$?
617
618                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
619                         error "mount mds${mdt_index} failed"
620                 df $MOUNT > /dev/null 2>&1
621                 [ $rc -ne 0 ] && break
622         done
623         return $rc
624 }
625
626 test_17n() {
627         local i
628
629         remote_mds_nodsh && skip "remote MDS with nodsh" && return
630         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
631         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
632                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
633
634         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
635                 skip "only for ldiskfs MDT" && return 0
636
637         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
638
639         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
640
641         test_mkdir $DIR/$tdir
642         for ((i=0; i<10; i++)); do
643                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
644                         error "create remote dir error $i"
645                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
646                         error "create files under remote dir failed $i"
647         done
648
649         check_fs_consistency_17n ||
650                 error "e2fsck report error after create files under remote dir"
651
652         for ((i = 0; i < 10; i++)); do
653                 rm -rf $DIR/$tdir/remote_dir_${i} ||
654                         error "destroy remote dir error $i"
655         done
656
657         check_fs_consistency_17n ||
658                 error "e2fsck report error after unlink files under remote dir"
659
660         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
661                 skip "lustre < 2.4.50 does not support migrate mv " && return
662
663         for ((i = 0; i < 10; i++)); do
664                 mkdir -p $DIR/$tdir/remote_dir_${i}
665                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
666                         error "create files under remote dir failed $i"
667                 $LFS mv --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
668                         error "migrate remote dir error $i"
669         done
670         check_fs_consistency_17n || error "e2fsck report error after migration"
671
672         for ((i = 0; i < 10; i++)); do
673                 rm -rf $DIR/$tdir/remote_dir_${i} ||
674                         error "destroy remote dir error $i"
675         done
676
677         check_fs_consistency_17n || error "e2fsck report error after unlink"
678 }
679 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
680
681 test_17o() {
682         remote_mds_nodsh && skip "remote MDS with nodsh" && return
683         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
684                 skip "Need MDS version at least 2.3.64" && return
685
686         local WDIR=$DIR/${tdir}o
687         local mdt_index
688         local rc=0
689
690         test_mkdir -p $WDIR
691         mdt_index=$($LFS getstripe -M $WDIR)
692         mdt_index=$((mdt_index+1))
693
694         touch $WDIR/$tfile
695
696         #fail mds will wait the failover finish then set
697         #following fail_loc to avoid interfer the recovery process.
698         fail mds${mdt_index}
699
700         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
701         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
702         ls -l $WDIR/$tfile && rc=1
703         do_facet mds${mdt_index} lctl set_param fail_loc=0
704         [[ $rc -ne 0 ]] && error "stat file should fail"
705         true
706 }
707 run_test 17o "stat file with incompat LMA feature"
708
709 test_18() {
710         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
711         ls $DIR || error "Failed to ls $DIR: $?"
712 }
713 run_test 18 "touch .../f ; ls ... =============================="
714
715 test_19a() {
716         touch $DIR/$tfile
717         ls -l $DIR
718         rm $DIR/$tfile
719         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
720 }
721 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
722
723 test_19b() {
724         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
725 }
726 run_test 19b "ls -l .../f19 (should return error) =============="
727
728 test_19c() {
729         [ $RUNAS_ID -eq $UID ] &&
730                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
731         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
732 }
733 run_test 19c "$RUNAS touch .../f19 (should return error) =="
734
735 test_19d() {
736         cat $DIR/f19 && error || true
737 }
738 run_test 19d "cat .../f19 (should return error) =============="
739
740 test_20() {
741         touch $DIR/$tfile
742         rm $DIR/$tfile
743         log "1 done"
744         touch $DIR/$tfile
745         rm $DIR/$tfile
746         log "2 done"
747         touch $DIR/$tfile
748         rm $DIR/$tfile
749         log "3 done"
750         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
751 }
752 run_test 20 "touch .../f ; ls -l ... ==========================="
753
754 test_21() {
755         test_mkdir -p $DIR/$tdir
756         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
757         ln -s dangle $DIR/$tdir/link
758         echo foo >> $DIR/$tdir/link
759         cat $DIR/$tdir/dangle
760         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
761         $CHECKSTAT -f -t file $DIR/$tdir/link ||
762                 error "$tdir/link not linked to a file"
763 }
764 run_test 21 "write to dangling link ============================"
765
766 test_22() {
767         WDIR=$DIR/$tdir
768         test_mkdir -p $DIR/$tdir
769         chown $RUNAS_ID:$RUNAS_GID $WDIR
770         (cd $WDIR || error "cd $WDIR failed";
771         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
772         $RUNAS tar xf -)
773         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
774         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
775         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
776 }
777 run_test 22 "unpack tar archive as non-root user ==============="
778
779 # was test_23
780 test_23a() {
781         test_mkdir -p $DIR/$tdir
782         local file=$DIR/$tdir/$tfile
783
784         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
785         openfile -f O_CREAT:O_EXCL $file &&
786                 error "$file recreate succeeded" || true
787 }
788 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
789
790 test_23b() { # bug 18988
791         test_mkdir -p $DIR/$tdir
792         local file=$DIR/$tdir/$tfile
793
794         rm -f $file
795         echo foo > $file || error "write filed"
796         echo bar >> $file || error "append filed"
797         $CHECKSTAT -s 8 $file || error "wrong size"
798         rm $file
799 }
800 run_test 23b "O_APPEND check =========================="
801
802 # rename sanity
803 test_24a() {
804         echo '-- same directory rename'
805         test_mkdir $DIR/$tdir
806         touch $DIR/$tdir/$tfile.1
807         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
808         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
809 }
810 run_test 24a "rename file to non-existent target"
811
812 test_24b() {
813         test_mkdir $DIR/$tdir
814         touch $DIR/$tdir/$tfile.{1,2}
815         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
816         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
817         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
818 }
819 run_test 24b "rename file to existing target"
820
821 test_24c() {
822         test_mkdir $DIR/$tdir
823         test_mkdir $DIR/$tdir/d$testnum.1
824         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
825         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
826         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
827 }
828 run_test 24c "rename directory to non-existent target"
829
830 test_24d() {
831         test_mkdir -c1 $DIR/$tdir
832         test_mkdir -c1 $DIR/$tdir/d$testnum.1
833         test_mkdir -c1 $DIR/$tdir/d$testnum.2
834         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
835         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
836         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
837 }
838 run_test 24d "rename directory to existing target"
839
840 test_24e() {
841         echo '-- cross directory renames --'
842         test_mkdir $DIR/R5a
843         test_mkdir $DIR/R5b
844         touch $DIR/R5a/f
845         mv $DIR/R5a/f $DIR/R5b/g
846         $CHECKSTAT -a $DIR/R5a/f || error
847         $CHECKSTAT -t file $DIR/R5b/g || error
848 }
849 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
850
851 test_24f() {
852         test_mkdir $DIR/R6a
853         test_mkdir $DIR/R6b
854         touch $DIR/R6a/f $DIR/R6b/g
855         mv $DIR/R6a/f $DIR/R6b/g
856         $CHECKSTAT -a $DIR/R6a/f || error
857         $CHECKSTAT -t file $DIR/R6b/g || error
858 }
859 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
860
861 test_24g() {
862         test_mkdir $DIR/R7a
863         test_mkdir $DIR/R7b
864         test_mkdir $DIR/R7a/d
865         mv $DIR/R7a/d $DIR/R7b/e
866         $CHECKSTAT -a $DIR/R7a/d || error
867         $CHECKSTAT -t dir $DIR/R7b/e || error
868 }
869 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
870
871 test_24h() {
872         test_mkdir -c1 $DIR/R8a
873         test_mkdir -c1 $DIR/R8b
874         test_mkdir -c1 $DIR/R8a/d
875         test_mkdir -c1 $DIR/R8b/e
876         mrename $DIR/R8a/d $DIR/R8b/e
877         $CHECKSTAT -a $DIR/R8a/d || error
878         $CHECKSTAT -t dir $DIR/R8b/e || error
879 }
880 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
881
882 test_24i() {
883         echo "-- rename error cases"
884         test_mkdir $DIR/R9
885         test_mkdir $DIR/R9/a
886         touch $DIR/R9/f
887         mrename $DIR/R9/f $DIR/R9/a
888         $CHECKSTAT -t file $DIR/R9/f || error
889         $CHECKSTAT -t dir  $DIR/R9/a || error
890         $CHECKSTAT -a $DIR/R9/a/f || error
891 }
892 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
893
894 test_24j() {
895         test_mkdir $DIR/R10
896         mrename $DIR/R10/f $DIR/R10/g
897         $CHECKSTAT -t dir $DIR/R10 || error
898         $CHECKSTAT -a $DIR/R10/f || error
899         $CHECKSTAT -a $DIR/R10/g || error
900 }
901 run_test 24j "source does not exist ============================"
902
903 test_24k() {
904         test_mkdir $DIR/R11a
905         test_mkdir $DIR/R11a/d
906         touch $DIR/R11a/f
907         mv $DIR/R11a/f $DIR/R11a/d
908         $CHECKSTAT -a $DIR/R11a/f || error
909         $CHECKSTAT -t file $DIR/R11a/d/f || error
910 }
911 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
912
913 # bug 2429 - rename foo foo foo creates invalid file
914 test_24l() {
915         f="$DIR/f24l"
916         $MULTIOP $f OcNs || error
917 }
918 run_test 24l "Renaming a file to itself ========================"
919
920 test_24m() {
921         f="$DIR/f24m"
922         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
923         # on ext3 this does not remove either the source or target files
924         # though the "expected" operation would be to remove the source
925         $CHECKSTAT -t file ${f} || error "${f} missing"
926         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
927 }
928 run_test 24m "Renaming a file to a hard link to itself ========="
929
930 test_24n() {
931     f="$DIR/f24n"
932     # this stats the old file after it was renamed, so it should fail
933     touch ${f}
934     $CHECKSTAT ${f}
935     mv ${f} ${f}.rename
936     $CHECKSTAT ${f}.rename
937     $CHECKSTAT -a ${f}
938 }
939 run_test 24n "Statting the old file after renaming (Posix rename 2)"
940
941 test_24o() {
942         test_mkdir -p $DIR/d24o
943         rename_many -s random -v -n 10 $DIR/d24o
944 }
945 run_test 24o "rename of files during htree split ==============="
946
947 test_24p() {
948         test_mkdir $DIR/R12a
949         test_mkdir $DIR/R12b
950         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
951         mrename $DIR/R12a $DIR/R12b
952         $CHECKSTAT -a $DIR/R12a || error
953         $CHECKSTAT -t dir $DIR/R12b || error
954         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
955         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
956 }
957 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
958
959 cleanup_multiop_pause() {
960         trap 0
961         kill -USR1 $MULTIPID
962 }
963
964 test_24q() {
965         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
966         test_mkdir $DIR/R13a
967         test_mkdir $DIR/R13b
968         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
969         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
970         MULTIPID=$!
971
972         trap cleanup_multiop_pause EXIT
973         mrename $DIR/R13a $DIR/R13b
974         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
975         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
976         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
977         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
978         cleanup_multiop_pause
979         wait $MULTIPID || error "multiop close failed"
980 }
981 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
982
983 test_24r() { #bug 3789
984         test_mkdir $DIR/R14a
985         test_mkdir $DIR/R14a/b
986         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
987         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
988         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
989 }
990 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
991
992 test_24s() {
993         test_mkdir $DIR/R15a
994         test_mkdir $DIR/R15a/b
995         test_mkdir $DIR/R15a/b/c
996         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
997         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
998         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
999 }
1000 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1001 test_24t() {
1002         test_mkdir $DIR/R16a
1003         test_mkdir $DIR/R16a/b
1004         test_mkdir $DIR/R16a/b/c
1005         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1006         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1007         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1008 }
1009 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1010
1011 test_24u() { # bug12192
1012         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1013         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1014 }
1015 run_test 24u "create stripe file"
1016
1017 page_size() {
1018         getconf PAGE_SIZE
1019 }
1020
1021 simple_cleanup_common() {
1022         trap 0
1023         rm -rf $DIR/$tdir
1024         wait_delete_completed
1025 }
1026
1027 max_pages_per_rpc() {
1028         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1029 }
1030
1031 test_24v() {
1032         local NRFILES=100000
1033         local FREE_INODES=$(mdt_free_inodes 0)
1034         [[ $FREE_INODES -lt $NRFILES ]] &&
1035                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1036                 return
1037
1038         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1039         trap simple_cleanup_common EXIT
1040
1041         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1042         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1043
1044         test_mkdir -p $DIR/$tdir
1045         createmany -m $DIR/$tdir/$tfile $NRFILES
1046
1047         cancel_lru_locks mdc
1048         lctl set_param mdc.*.stats clear
1049
1050         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1051
1052         # LU-5 large readdir
1053         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1054         #               8 bytes for name(filename is mostly 5 in this test) +
1055         #               8 bytes for luda_type
1056         # take into account of overhead in lu_dirpage header and end mark in
1057         # each page, plus one in RPC_NUM calculation.
1058         DIRENT_SIZE=48
1059         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1060         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1061         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1062                                 awk '/^mds_readpage/ {print $2}')
1063         [[ $mds_readpage -gt $RPC_NUM ]] &&
1064                 error "large readdir doesn't take effect"
1065
1066         simple_cleanup_common
1067 }
1068 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1069
1070 test_24w() { # bug21506
1071         SZ1=234852
1072         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1073         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1074         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1075         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1076         [[ "$SZ1" -eq "$SZ2" ]] ||
1077                 error "Error reading at the end of the file $tfile"
1078 }
1079 run_test 24w "Reading a file larger than 4Gb"
1080
1081 test_24x() {
1082         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1083         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1084         local MDTIDX=1
1085         local remote_dir=$DIR/$tdir/remote_dir
1086
1087         test_mkdir -p $DIR/$tdir
1088         $LFS mkdir -i $MDTIDX $remote_dir ||
1089                 error "create remote directory failed"
1090
1091         test_mkdir -p $DIR/$tdir/src_dir
1092         touch $DIR/$tdir/src_file
1093         test_mkdir -p $remote_dir/tgt_dir
1094         touch $remote_dir/tgt_file
1095
1096         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir ||
1097                 error "rename dir cross MDT failed!"
1098
1099         mrename $DIR/$tdir/src_file $remote_dir/tgt_file ||
1100                 error "rename file cross MDT failed!"
1101
1102         touch $DIR/$tdir/ln_file
1103         ln $DIR/$tdir/ln_file $remote_dir/ln_name ||
1104                 error "ln file cross MDT failed"
1105
1106         rm -rf $DIR/$tdir || error "Can not delete directories"
1107 }
1108 run_test 24x "cross MDT rename/link"
1109
1110 test_24y() {
1111         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1112         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1113         local MDTIDX=1
1114         local remote_dir=$DIR/$tdir/remote_dir
1115
1116         test_mkdir -p $DIR/$tdir
1117         $LFS mkdir -i $MDTIDX $remote_dir ||
1118                    error "create remote directory failed"
1119
1120         test_mkdir -p $remote_dir/src_dir
1121         touch $remote_dir/src_file
1122         test_mkdir -p $remote_dir/tgt_dir
1123         touch $remote_dir/tgt_file
1124
1125         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1126                 error "rename subdir in the same remote dir failed!"
1127
1128         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1129                 error "rename files in the same remote dir failed!"
1130
1131         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1132                 error "link files in the same remote dir failed!"
1133
1134         rm -rf $DIR/$tdir || error "Can not delete directories"
1135 }
1136 run_test 24y "rename/link on the same dir should succeed"
1137
1138 test_24A() { # LU-3182
1139         local NFILES=5000
1140
1141         rm -rf $DIR/$tdir
1142         test_mkdir -p $DIR/$tdir
1143         createmany -m $DIR/$tdir/$tfile $NFILES
1144         local t=$(ls $DIR/$tdir | wc -l)
1145         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1146         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1147         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1148                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1149         fi
1150
1151         rm -rf $DIR/$tdir || error "Can not delete directories"
1152 }
1153 run_test 24A "readdir() returns correct number of entries."
1154
1155 test_24B() { # LU-4805
1156         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1157         local count
1158
1159         test_mkdir $DIR/$tdir
1160         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1161                 error "create striped dir failed"
1162
1163         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1164         [ $count -eq 2 ] || error "Expected 2, got $count"
1165
1166         touch $DIR/$tdir/striped_dir/a
1167
1168         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1169         [ $count -eq 3 ] || error "Expected 3, got $count"
1170
1171         touch $DIR/$tdir/striped_dir/.f
1172
1173         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1174         [ $count -eq 4 ] || error "Expected 4, got $count"
1175
1176         rm -rf $DIR/$tdir || error "Can not delete directories"
1177 }
1178 run_test 24B "readdir for striped dir return correct number of entries"
1179
1180 test_24C() {
1181         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1182
1183         mkdir $DIR/$tdir
1184         mkdir $DIR/$tdir/d0
1185         mkdir $DIR/$tdir/d1
1186
1187         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1188                 error "create striped dir failed"
1189
1190         cd $DIR/$tdir/d0/striped_dir
1191
1192         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1193         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1194         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1195
1196         [ "$d0_ino" = "$parent_ino" ] ||
1197                 error ".. wrong, expect $d0_ino, get $parent_ino"
1198
1199         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1200                 error "mv striped dir failed"
1201
1202         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1203
1204         [ "$d1_ino" = "$parent_ino" ] ||
1205                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1206 }
1207 run_test 24C "check .. in striped dir"
1208
1209 test_24D() { # LU-6101
1210         local NFILES=50000
1211
1212         rm -rf $DIR/$tdir
1213         mkdir -p $DIR/$tdir
1214         createmany -m $DIR/$tdir/$tfile $NFILES
1215         local t=$(ls $DIR/$tdir | wc -l)
1216         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1217         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1218         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1219                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1220         fi
1221
1222         rm -rf $DIR/$tdir || error "Can not delete directories"
1223 }
1224 run_test 24D "readdir() returns correct number of entries after cursor reload"
1225
1226 test_24E() {
1227         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
1228         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1229
1230         mkdir -p $DIR/$tdir
1231         mkdir $DIR/$tdir/src_dir
1232         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
1233                 error "create remote source failed"
1234
1235         touch $DIR/$tdir/src_dir/src_child/a
1236
1237         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
1238                 error "create remote target dir failed"
1239
1240         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
1241                 error "create remote target child failed"
1242
1243         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
1244                 error "rename dir cross MDT failed!"
1245
1246         find $DIR/$tdir
1247
1248         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
1249                 error "src_child still exists after rename"
1250
1251         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
1252                 error "missing file(a) after rename"
1253
1254         rm -rf $DIR/$tdir || error "Can not delete directories"
1255 }
1256 run_test 24E "cross MDT rename/link"
1257
1258 test_25a() {
1259         echo '== symlink sanity ============================================='
1260
1261         test_mkdir $DIR/d25
1262         ln -s d25 $DIR/s25
1263         touch $DIR/s25/foo || error
1264 }
1265 run_test 25a "create file in symlinked directory ==============="
1266
1267 test_25b() {
1268         [ ! -d $DIR/d25 ] && test_25a
1269         $CHECKSTAT -t file $DIR/s25/foo || error
1270 }
1271 run_test 25b "lookup file in symlinked directory ==============="
1272
1273 test_26a() {
1274         test_mkdir $DIR/d26
1275         test_mkdir $DIR/d26/d26-2
1276         ln -s d26/d26-2 $DIR/s26
1277         touch $DIR/s26/foo || error
1278 }
1279 run_test 26a "multiple component symlink ======================="
1280
1281 test_26b() {
1282         test_mkdir -p $DIR/d26b/d26-2
1283         ln -s d26b/d26-2/foo $DIR/s26-2
1284         touch $DIR/s26-2 || error
1285 }
1286 run_test 26b "multiple component symlink at end of lookup ======"
1287
1288 test_26c() {
1289         test_mkdir $DIR/d26.2
1290         touch $DIR/d26.2/foo
1291         ln -s d26.2 $DIR/s26.2-1
1292         ln -s s26.2-1 $DIR/s26.2-2
1293         ln -s s26.2-2 $DIR/s26.2-3
1294         chmod 0666 $DIR/s26.2-3/foo
1295 }
1296 run_test 26c "chain of symlinks ================================"
1297
1298 # recursive symlinks (bug 439)
1299 test_26d() {
1300         ln -s d26-3/foo $DIR/d26-3
1301 }
1302 run_test 26d "create multiple component recursive symlink ======"
1303
1304 test_26e() {
1305         [ ! -h $DIR/d26-3 ] && test_26d
1306         rm $DIR/d26-3
1307 }
1308 run_test 26e "unlink multiple component recursive symlink ======"
1309
1310 # recursive symlinks (bug 7022)
1311 test_26f() {
1312         test_mkdir -p $DIR/$tdir
1313         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1314         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1315         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1316         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1317         cd $tfile                || error "cd $tfile failed"
1318         ln -s .. dotdot          || error "ln dotdot failed"
1319         ln -s dotdot/lndir lndir || error "ln lndir failed"
1320         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1321         output=`ls $tfile/$tfile/lndir/bar1`
1322         [ "$output" = bar1 ] && error "unexpected output"
1323         rm -r $tfile             || error "rm $tfile failed"
1324         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1325 }
1326 run_test 26f "rm -r of a directory which has recursive symlink ="
1327
1328 test_27a() {
1329         echo '== stripe sanity =============================================='
1330         test_mkdir -p $DIR/d27 || error "mkdir failed"
1331         $GETSTRIPE $DIR/d27
1332         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1333         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1334         log "== test_27a: write to one stripe file ========================="
1335         cp /etc/hosts $DIR/d27/f0 || error
1336 }
1337 run_test 27a "one stripe file =================================="
1338
1339 test_27b() {
1340         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1341         test_mkdir -p $DIR/d27
1342         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1343         $GETSTRIPE -c $DIR/d27/f01
1344         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1345                 error "two-stripe file doesn't have two stripes"
1346
1347         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1348 }
1349 run_test 27b "create and write to two stripe file"
1350
1351 test_27d() {
1352         test_mkdir -p $DIR/d27
1353         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1354         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1355         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1356 }
1357 run_test 27d "create file with default settings ================"
1358
1359 test_27e() {
1360         test_mkdir -p $DIR/d27
1361         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1362         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1363         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1364 }
1365 run_test 27e "setstripe existing file (should return error) ======"
1366
1367 test_27f() {
1368         test_mkdir $DIR/$tdir
1369         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1370                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1371         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1372                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1373         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1374         $GETSTRIPE $DIR/$tdir/$tfile || error "$GETSTRIPE failed"
1375 }
1376 run_test 27f "setstripe with bad stripe size (should return error)"
1377
1378 test_27g() {
1379         test_mkdir -p $DIR/d27
1380         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1381         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1382                 error "$DIR/d27/fnone has object"
1383 }
1384 run_test 27g "$GETSTRIPE with no objects"
1385
1386 test_27i() {
1387         test_mkdir $DIR/$tdir
1388         touch $DIR/$tdir/$tfile || error "touch failed"
1389         [[ $($GETSTRIPE -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1390                 error "missing objects"
1391 }
1392 run_test 27i "$GETSTRIPE with some objects"
1393
1394 test_27j() {
1395         test_mkdir -p $DIR/d27
1396         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1397 }
1398 run_test 27j "setstripe with bad stripe offset (should return error)"
1399
1400 test_27k() { # bug 2844
1401         test_mkdir -p $DIR/d27
1402         FILE=$DIR/d27/f27k
1403         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1404         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1405         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1406         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1407         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1408         dd if=/dev/zero of=$FILE bs=4k count=1
1409         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1410         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1411 }
1412 run_test 27k "limit i_blksize for broken user apps ============="
1413
1414 test_27l() {
1415         test_mkdir -p $DIR/d27
1416         mcreate $DIR/f27l || error "creating file"
1417         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1418                 error "setstripe should have failed" || true
1419 }
1420 run_test 27l "check setstripe permissions (should return error)"
1421
1422 test_27m() {
1423         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1424                 return
1425         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1426                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1427                 return
1428         fi
1429         trap simple_cleanup_common EXIT
1430         test_mkdir -p $DIR/$tdir
1431         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1432         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1433                 error "dd should fill OST0"
1434         i=2
1435         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1436                 i=$((i + 1))
1437                 [ $i -gt 256 ] && break
1438         done
1439         i=$((i + 1))
1440         touch $DIR/$tdir/f27m_$i
1441         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1442                 error "OST0 was full but new created file still use it"
1443         i=$((i + 1))
1444         touch $DIR/$tdir/f27m_$i
1445         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1446                 error "OST0 was full but new created file still use it"
1447         simple_cleanup_common
1448 }
1449 run_test 27m "create file while OST0 was full =================="
1450
1451 sleep_maxage() {
1452         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1453         sleep $DELAY
1454 }
1455
1456 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1457 # if the OST isn't full anymore.
1458 reset_enospc() {
1459         local OSTIDX=${1:-""}
1460
1461         local list=$(comma_list $(osts_nodes))
1462         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1463
1464         do_nodes $list lctl set_param fail_loc=0
1465         sync    # initiate all OST_DESTROYs from MDS to OST
1466         sleep_maxage
1467 }
1468
1469 exhaust_precreations() {
1470         local OSTIDX=$1
1471         local FAILLOC=$2
1472         local FAILIDX=${3:-$OSTIDX}
1473         local ofacet=ost$((OSTIDX + 1))
1474
1475         test_mkdir -p -c1 $DIR/$tdir
1476         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
1477         local mfacet=mds$((mdtidx + 1))
1478         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1479
1480         local OST=$(ostname_from_index $OSTIDX)
1481
1482         # on the mdt's osc
1483         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1484         local last_id=$(do_facet $mfacet lctl get_param -n \
1485                         osc.$mdtosc_proc1.prealloc_last_id)
1486         local next_id=$(do_facet $mfacet lctl get_param -n \
1487                         osc.$mdtosc_proc1.prealloc_next_id)
1488
1489         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1490         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1491
1492         test_mkdir -p $DIR/$tdir/${OST}
1493         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1494 #define OBD_FAIL_OST_ENOSPC              0x215
1495         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1496         echo "Creating to objid $last_id on ost $OST..."
1497         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1498         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1499         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1500         sleep_maxage
1501 }
1502
1503 exhaust_all_precreations() {
1504         local i
1505         for (( i=0; i < OSTCOUNT; i++ )) ; do
1506                 exhaust_precreations $i $1 -1
1507         done
1508 }
1509
1510 test_27n() {
1511         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1512         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1513         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1514         remote_ost_nodsh && skip "remote OST with nodsh" && return
1515
1516         reset_enospc
1517         rm -f $DIR/$tdir/$tfile
1518         exhaust_precreations 0 0x80000215
1519         $SETSTRIPE -c -1 $DIR/$tdir
1520         touch $DIR/$tdir/$tfile || error
1521         $GETSTRIPE $DIR/$tdir/$tfile
1522         reset_enospc
1523 }
1524 run_test 27n "create file with some full OSTs =================="
1525
1526 test_27o() {
1527         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1528         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1529         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1530         remote_ost_nodsh && skip "remote OST with nodsh" && return
1531
1532         reset_enospc
1533         rm -f $DIR/$tdir/$tfile
1534         exhaust_all_precreations 0x215
1535
1536         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1537
1538         reset_enospc
1539         rm -rf $DIR/$tdir/*
1540 }
1541 run_test 27o "create file with all full OSTs (should error) ===="
1542
1543 test_27p() {
1544         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1545         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1546         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1547         remote_ost_nodsh && skip "remote OST with nodsh" && return
1548
1549         reset_enospc
1550         rm -f $DIR/$tdir/$tfile
1551         test_mkdir -p $DIR/$tdir
1552
1553         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1554         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1555         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1556
1557         exhaust_precreations 0 0x80000215
1558         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1559         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1560         $GETSTRIPE $DIR/$tdir/$tfile
1561
1562         reset_enospc
1563 }
1564 run_test 27p "append to a truncated file with some full OSTs ==="
1565
1566 test_27q() {
1567         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1568         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1569         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1570         remote_ost_nodsh && skip "remote OST with nodsh" && return
1571
1572         reset_enospc
1573         rm -f $DIR/$tdir/$tfile
1574
1575         test_mkdir -p $DIR/$tdir
1576         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1577         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1578         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1579
1580         exhaust_all_precreations 0x215
1581
1582         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1583         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1584
1585         reset_enospc
1586 }
1587 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1588
1589 test_27r() {
1590         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1591         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1592         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1593         remote_ost_nodsh && skip "remote OST with nodsh" && return
1594
1595         reset_enospc
1596         rm -f $DIR/$tdir/$tfile
1597         exhaust_precreations 0 0x80000215
1598
1599         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1600
1601         reset_enospc
1602 }
1603 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1604
1605 test_27s() { # bug 10725
1606         test_mkdir -p $DIR/$tdir
1607         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1608         local stripe_count=0
1609         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1610         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1611                 error "stripe width >= 2^32 succeeded" || true
1612
1613 }
1614 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1615
1616 test_27t() { # bug 10864
1617         WDIR=$(pwd)
1618         WLFS=$(which lfs)
1619         cd $DIR
1620         touch $tfile
1621         $WLFS getstripe $tfile
1622         cd $WDIR
1623 }
1624 run_test 27t "check that utils parse path correctly"
1625
1626 test_27u() { # bug 4900
1627         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1628         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1629         local index
1630         local list=$(comma_list $(mdts_nodes))
1631
1632 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1633         do_nodes $list $LCTL set_param fail_loc=0x139
1634         test_mkdir -p $DIR/$tdir
1635         rm -rf $DIR/$tdir/*
1636         createmany -o $DIR/$tdir/t- 1000
1637         do_nodes $list $LCTL set_param fail_loc=0
1638
1639         TLOG=$DIR/$tfile.getstripe
1640         $GETSTRIPE $DIR/$tdir > $TLOG
1641         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1642         unlinkmany $DIR/$tdir/t- 1000
1643         [[ $OBJS -gt 0 ]] &&
1644                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1645 }
1646 run_test 27u "skip object creation on OSC w/o objects =========="
1647
1648 test_27v() { # bug 4900
1649         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1650         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1651         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1652         remote_ost_nodsh && skip "remote OST with nodsh" && return
1653
1654         exhaust_all_precreations 0x215
1655         reset_enospc
1656
1657         test_mkdir -p $DIR/$tdir
1658         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1659
1660         touch $DIR/$tdir/$tfile
1661         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1662         # all except ost1
1663         for (( i=1; i < OSTCOUNT; i++ )); do
1664                 do_facet ost$i lctl set_param fail_loc=0x705
1665         done
1666         local START=`date +%s`
1667         createmany -o $DIR/$tdir/$tfile 32
1668
1669         local FINISH=`date +%s`
1670         local TIMEOUT=`lctl get_param -n timeout`
1671         local PROCESS=$((FINISH - START))
1672         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1673                error "$FINISH - $START >= $TIMEOUT / 2"
1674         sleep $((TIMEOUT / 2 - PROCESS))
1675         reset_enospc
1676 }
1677 run_test 27v "skip object creation on slow OST ================="
1678
1679 test_27w() { # bug 10997
1680         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1681         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1682         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1683                 error "stripe size $size != 65536" || true
1684         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1685                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1686 }
1687 run_test 27w "check $SETSTRIPE -S option"
1688
1689 test_27wa() {
1690         [[ $OSTCOUNT -lt 2 ]] &&
1691                 skip_env "skipping multiple stripe count/offset test" && return
1692
1693         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1694         for i in $(seq 1 $OSTCOUNT); do
1695                 offset=$((i - 1))
1696                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1697                         error "setstripe -c $i -i $offset failed"
1698                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1699                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1700                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1701                 [ $index -ne $offset ] &&
1702                         error "stripe offset $index != $offset" || true
1703         done
1704 }
1705 run_test 27wa "check $SETSTRIPE -c -i options"
1706
1707 test_27x() {
1708         remote_ost_nodsh && skip "remote OST with nodsh" && return
1709         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1710         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1711         OFFSET=$(($OSTCOUNT - 1))
1712         OSTIDX=0
1713         local OST=$(ostname_from_index $OSTIDX)
1714
1715         test_mkdir -p $DIR/$tdir
1716         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1717         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1718         sleep_maxage
1719         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1720         for i in `seq 0 $OFFSET`; do
1721                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1722                 error "OST0 was degraded but new created file still use it"
1723         done
1724         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1725 }
1726 run_test 27x "create files while OST0 is degraded"
1727
1728 test_27y() {
1729         [[ $OSTCOUNT -lt 2 ]] &&
1730                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1731         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1732         remote_ost_nodsh && skip "remote OST with nodsh" && return
1733         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1734
1735         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1736         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1737             osc.$mdtosc.prealloc_last_id)
1738         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1739             osc.$mdtosc.prealloc_next_id)
1740         local fcount=$((last_id - next_id))
1741         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1742         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1743
1744         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1745                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1746         local OST_DEACTIVE_IDX=-1
1747         local OSC
1748         local OSTIDX
1749         local OST
1750
1751         for OSC in $MDS_OSCS; do
1752                 OST=$(osc_to_ost $OSC)
1753                 OSTIDX=$(index_from_ostuuid $OST)
1754                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1755                         OST_DEACTIVE_IDX=$OSTIDX
1756                 fi
1757                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1758                         echo $OSC "is Deactivated:"
1759                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1760                 fi
1761         done
1762
1763         OSTIDX=$(index_from_ostuuid $OST)
1764         test_mkdir -p $DIR/$tdir
1765         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1766
1767         for OSC in $MDS_OSCS; do
1768                 OST=$(osc_to_ost $OSC)
1769                 OSTIDX=$(index_from_ostuuid $OST)
1770                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1771                         echo $OST "is degraded:"
1772                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1773                                                 obdfilter.$OST.degraded=1
1774                 fi
1775         done
1776
1777         sleep_maxage
1778         createmany -o $DIR/$tdir/$tfile $fcount
1779
1780         for OSC in $MDS_OSCS; do
1781                 OST=$(osc_to_ost $OSC)
1782                 OSTIDX=$(index_from_ostuuid $OST)
1783                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1784                         echo $OST "is recovered from degraded:"
1785                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1786                                                 obdfilter.$OST.degraded=0
1787                 else
1788                         do_facet $SINGLEMDS lctl --device %$OSC activate
1789                 fi
1790         done
1791
1792         # all osp devices get activated, hence -1 stripe count restored
1793         local stripecnt=0
1794
1795         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1796         # devices get activated.
1797         sleep_maxage
1798         $SETSTRIPE -c -1 $DIR/$tfile
1799         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1800         rm -f $DIR/$tfile
1801         [ $stripecnt -ne $OSTCOUNT ] &&
1802                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1803         return 0
1804 }
1805 run_test 27y "create files while OST0 is degraded and the rest inactive"
1806
1807 check_seq_oid()
1808 {
1809         log "check file $1"
1810
1811         lmm_count=$($GETSTRIPE -c $1)
1812         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1813         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1814
1815         local old_ifs="$IFS"
1816         IFS=$'[:]'
1817         fid=($($LFS path2fid $1))
1818         IFS="$old_ifs"
1819
1820         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1821         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1822
1823         # compare lmm_seq and lu_fid->f_seq
1824         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1825         # compare lmm_object_id and lu_fid->oid
1826         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1827
1828         # check the trusted.fid attribute of the OST objects of the file
1829         local have_obdidx=false
1830         local stripe_nr=0
1831         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1832                 # skip lines up to and including "obdidx"
1833                 [ -z "$obdidx" ] && break
1834                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1835                 $have_obdidx || continue
1836
1837                 local ost=$((obdidx + 1))
1838                 local dev=$(ostdevname $ost)
1839                 local oid_hex
1840
1841                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1842
1843                 seq=$(echo $seq | sed -e "s/^0x//g")
1844                 if [ $seq == 0 ]; then
1845                         oid_hex=$(echo $oid)
1846                 else
1847                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1848                 fi
1849                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1850
1851                 local ff
1852                 #
1853                 # Don't unmount/remount the OSTs if we don't need to do that.
1854                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1855                 # update too, until that use mount/ll_decode_filter_fid/mount.
1856                 # Re-enable when debugfs will understand new filter_fid.
1857                 #
1858                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1859                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1860                                 $dev 2>/dev/null" | grep "parent=")
1861                 else
1862                         stop ost$ost
1863                         mount_fstype ost$ost
1864                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1865                                 $(facet_mntpt ost$ost)/$obj_file)
1866                         unmount_fstype ost$ost
1867                         start ost$ost $dev $OST_MOUNT_OPTS
1868                 fi
1869
1870                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1871
1872                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1873
1874                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1875                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1876                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1877                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1878                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1879                 local ff_pstripe
1880                 if echo $ff_parent | grep -q 'stripe='; then
1881                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1882                 else
1883                         #
1884                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1885                         # into f_ver in this case.  See the comment on
1886                         # ff_parent.
1887                         #
1888                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1889                                 sed -e 's/\]//')
1890                 fi
1891
1892                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1893                 [ $ff_pseq = $lmm_seq ] ||
1894                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1895                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1896                 [ $ff_poid = $lmm_oid ] ||
1897                         error "FF parent OID $ff_poid != $lmm_oid"
1898                 (($ff_pstripe == $stripe_nr)) ||
1899                         error "FF stripe $ff_pstripe != $stripe_nr"
1900
1901                 stripe_nr=$((stripe_nr + 1))
1902         done
1903 }
1904
1905 test_27z() {
1906         remote_ost_nodsh && skip "remote OST with nodsh" && return
1907         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1908         test_mkdir -p $DIR/$tdir
1909
1910         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1911                 { error "setstripe -c -1 failed"; return 1; }
1912         # We need to send a write to every object to get parent FID info set.
1913         # This _should_ also work for setattr, but does not currently.
1914         # touch $DIR/$tdir/$tfile-1 ||
1915         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1916                 { error "dd $tfile-1 failed"; return 2; }
1917         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1918                 { error "setstripe -c -1 failed"; return 3; }
1919         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1920                 { error "dd $tfile-2 failed"; return 4; }
1921
1922         # make sure write RPCs have been sent to OSTs
1923         sync; sleep 5; sync
1924
1925         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1926         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1927 }
1928 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1929
1930 test_27A() { # b=19102
1931         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1932         local restore_size=$($GETSTRIPE -S $MOUNT)
1933         local restore_count=$($GETSTRIPE -c $MOUNT)
1934         local restore_offset=$($GETSTRIPE -i $MOUNT)
1935         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1936         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1937                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1938         local default_size=$($GETSTRIPE -S $MOUNT)
1939         local default_offset=$($GETSTRIPE -i $MOUNT)
1940         local dsize=$((1024 * 1024))
1941         [ $default_size -eq $dsize ] ||
1942                 error "stripe size $default_size != $dsize"
1943         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1944         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1945 }
1946 run_test 27A "check filesystem-wide default LOV EA values"
1947
1948 test_27B() { # LU-2523
1949         test_mkdir -p $DIR/$tdir
1950         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1951         touch $DIR/$tdir/f0
1952         # open f1 with O_LOV_DELAY_CREATE
1953         # rename f0 onto f1
1954         # call setstripe ioctl on open file descriptor for f1
1955         # close
1956         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1957                 $DIR/$tdir/f0
1958
1959         rm -f $DIR/$tdir/f1
1960         # open f1 with O_LOV_DELAY_CREATE
1961         # unlink f1
1962         # call setstripe ioctl on open file descriptor for f1
1963         # close
1964         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1965
1966         # Allow multiop to fail in imitation of NFS's busted semantics.
1967         true
1968 }
1969 run_test 27B "call setstripe on open unlinked file/rename victim"
1970
1971 test_27C() { #LU-2871
1972         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1973
1974         declare -a ost_idx
1975         local index
1976         local found
1977         local i
1978         local j
1979
1980         test_mkdir -p $DIR/$tdir
1981         cd $DIR/$tdir
1982         for i in $(seq 0 $((OSTCOUNT - 1))); do
1983                 # set stripe across all OSTs starting from OST$i
1984                 $SETSTRIPE -i $i -c -1 $tfile$i
1985                 # get striping information
1986                 ost_idx=($($GETSTRIPE $tfile$i |
1987                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1988                 echo ${ost_idx[@]}
1989
1990                 # check the layout
1991                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1992                         error "${#ost_idx[@]} != $OSTCOUNT"
1993
1994                 for index in $(seq 0 $((OSTCOUNT - 1))); do
1995                         found=0
1996                         for j in $(echo ${ost_idx[@]}); do
1997                                 if [ $index -eq $j ]; then
1998                                         found=1
1999                                         break
2000                                 fi
2001                         done
2002                         [ $found = 1 ] ||
2003                                 error "Can not find $index in ${ost_idx[@]}"
2004                 done
2005         done
2006 }
2007 run_test 27C "check full striping across all OSTs"
2008
2009 test_27D() {
2010         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2011         local POOL=${POOL:-testpool}
2012         local first_ost=0
2013         local last_ost=$(($OSTCOUNT - 1))
2014         local ost_step=1
2015         local ost_list=$(seq $first_ost $ost_step $last_ost)
2016         local ost_range="$first_ost $last_ost $ost_step"
2017
2018         test_mkdir -p $DIR/$tdir
2019         pool_add $POOL || error "pool_add failed"
2020         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2021         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT ||
2022                 error "llapi_layout_test failed"
2023         cleanup_pools || error "cleanup_pools failed"
2024 }
2025 run_test 27D "validate llapi_layout API"
2026
2027 # Verify that default_easize is increased from its initial value after
2028 # accessing a widely striped file.
2029 test_27E() {
2030         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2031
2032         # 72 bytes is the minimum space required to store striping
2033         # information for a file striped across one OST:
2034         # (sizeof(struct lov_user_md_v3) +
2035         #  sizeof(struct lov_user_ost_data_v1))
2036         local min_easize=72
2037         $LCTL set_param -n llite.*.default_easize $min_easize ||
2038                 error "lctl set_param failed"
2039         local easize=$($LCTL get_param -n llite.*.default_easize)
2040
2041         [ $easize -eq $min_easize ] ||
2042                 error "failed to set default_easize"
2043
2044         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2045                 error "setstripe failed"
2046         cat $DIR/$tfile
2047         rm $DIR/$tfile
2048
2049         easize=$($LCTL get_param -n llite.*.default_easize)
2050
2051         [ $easize -gt $min_easize ] ||
2052                 error "default_easize not updated"
2053 }
2054 run_test 27E "check that default extended attribute size properly increases"
2055
2056 # createtest also checks that device nodes are created and
2057 # then visible correctly (#2091)
2058 test_28() { # bug 2091
2059         test_mkdir $DIR/d28
2060         $CREATETEST $DIR/d28/ct || error
2061 }
2062 run_test 28 "create/mknod/mkdir with bad file types ============"
2063
2064 test_29() {
2065         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2066         cancel_lru_locks mdc
2067         test_mkdir $DIR/d29
2068         touch $DIR/d29/foo
2069         log 'first d29'
2070         ls -l $DIR/d29
2071
2072         declare -i LOCKCOUNTORIG=0
2073         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2074                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2075         done
2076         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
2077
2078         declare -i LOCKUNUSEDCOUNTORIG=0
2079         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2080                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2081         done
2082
2083         log 'second d29'
2084         ls -l $DIR/d29
2085         log 'done'
2086
2087         declare -i LOCKCOUNTCURRENT=0
2088         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2089                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2090         done
2091
2092         declare -i LOCKUNUSEDCOUNTCURRENT=0
2093         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2094                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2095         done
2096
2097         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2098                 $LCTL set_param -n ldlm.dump_namespaces ""
2099                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2100                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2101                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2102                 return 2
2103         fi
2104         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2105                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2106                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2107                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2108                 return 3
2109         fi
2110 }
2111 run_test 29 "IT_GETATTR regression  ============================"
2112
2113 test_30a() { # was test_30
2114         cp $(which ls) $DIR || cp /bin/ls $DIR
2115         $DIR/ls / || error
2116         rm $DIR/ls
2117 }
2118 run_test 30a "execute binary from Lustre (execve) =============="
2119
2120 test_30b() {
2121         cp `which ls` $DIR || cp /bin/ls $DIR
2122         chmod go+rx $DIR/ls
2123         $RUNAS $DIR/ls / || error
2124         rm $DIR/ls
2125 }
2126 run_test 30b "execute binary from Lustre as non-root ==========="
2127
2128 test_30c() { # b=22376
2129         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2130         cp `which ls` $DIR || cp /bin/ls $DIR
2131         chmod a-rw $DIR/ls
2132         cancel_lru_locks mdc
2133         cancel_lru_locks osc
2134         $RUNAS $DIR/ls / || error
2135         rm -f $DIR/ls
2136 }
2137 run_test 30c "execute binary from Lustre without read perms ===="
2138
2139 test_31a() {
2140         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2141         $CHECKSTAT -a $DIR/f31 || error
2142 }
2143 run_test 31a "open-unlink file =================================="
2144
2145 test_31b() {
2146         touch $DIR/f31 || error
2147         ln $DIR/f31 $DIR/f31b || error
2148         $MULTIOP $DIR/f31b Ouc || error
2149         $CHECKSTAT -t file $DIR/f31 || error
2150 }
2151 run_test 31b "unlink file with multiple links while open ======="
2152
2153 test_31c() {
2154         touch $DIR/f31 || error
2155         ln $DIR/f31 $DIR/f31c || error
2156         multiop_bg_pause $DIR/f31 O_uc || return 1
2157         MULTIPID=$!
2158         $MULTIOP $DIR/f31c Ouc
2159         kill -USR1 $MULTIPID
2160         wait $MULTIPID
2161 }
2162 run_test 31c "open-unlink file with multiple links ============="
2163
2164 test_31d() {
2165         opendirunlink $DIR/d31d $DIR/d31d || error
2166         $CHECKSTAT -a $DIR/d31d || error
2167 }
2168 run_test 31d "remove of open directory ========================="
2169
2170 test_31e() { # bug 2904
2171         openfilleddirunlink $DIR/d31e || error
2172 }
2173 run_test 31e "remove of open non-empty directory ==============="
2174
2175 test_31f() { # bug 4554
2176         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2177         set -vx
2178         test_mkdir $DIR/d31f
2179         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2180         cp /etc/hosts $DIR/d31f
2181         ls -l $DIR/d31f
2182         $GETSTRIPE $DIR/d31f/hosts
2183         multiop_bg_pause $DIR/d31f D_c || return 1
2184         MULTIPID=$!
2185
2186         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2187         test_mkdir $DIR/d31f
2188         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2189         cp /etc/hosts $DIR/d31f
2190         ls -l $DIR/d31f
2191         $GETSTRIPE $DIR/d31f/hosts
2192         multiop_bg_pause $DIR/d31f D_c || return 1
2193         MULTIPID2=$!
2194
2195         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2196         wait $MULTIPID || error "first opendir $MULTIPID failed"
2197
2198         sleep 6
2199
2200         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2201         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2202         set +vx
2203 }
2204 run_test 31f "remove of open directory with open-unlink file ==="
2205
2206 test_31g() {
2207         echo "-- cross directory link --"
2208         test_mkdir -c1 $DIR/${tdir}ga
2209         test_mkdir -c1 $DIR/${tdir}gb
2210         touch $DIR/${tdir}ga/f
2211         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2212         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2213         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2214         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2215         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2216 }
2217 run_test 31g "cross directory link==============="
2218
2219 test_31h() {
2220         echo "-- cross directory link --"
2221         test_mkdir -c1 $DIR/${tdir}
2222         test_mkdir -c1 $DIR/${tdir}/dir
2223         touch $DIR/${tdir}/f
2224         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2225         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2226         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2227         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2228         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2229 }
2230 run_test 31h "cross directory link under child==============="
2231
2232 test_31i() {
2233         echo "-- cross directory link --"
2234         test_mkdir -c1 $DIR/$tdir
2235         test_mkdir -c1 $DIR/$tdir/dir
2236         touch $DIR/$tdir/dir/f
2237         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2238         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2239         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2240         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2241         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2242 }
2243 run_test 31i "cross directory link under parent==============="
2244
2245 test_31j() {
2246         test_mkdir -c1 -p $DIR/$tdir
2247         test_mkdir -c1 -p $DIR/$tdir/dir1
2248         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2249         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2250         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2251         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2252         return 0
2253 }
2254 run_test 31j "link for directory==============="
2255
2256 test_31k() {
2257         test_mkdir -c1 -p $DIR/$tdir
2258         touch $DIR/$tdir/s
2259         touch $DIR/$tdir/exist
2260         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2261         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2262         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2263         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2264         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2265         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2266         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2267         return 0
2268 }
2269 run_test 31k "link to file: the same, non-existing, dir==============="
2270
2271 test_31m() {
2272         mkdir $DIR/d31m
2273         touch $DIR/d31m/s
2274         mkdir $DIR/d31m2
2275         touch $DIR/d31m2/exist
2276         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2277         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2278         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2279         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2280         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2281         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2282         return 0
2283 }
2284 run_test 31m "link to file: the same, non-existing, dir==============="
2285
2286 test_31n() {
2287         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2288         nlink=$(stat --format=%h $DIR/$tfile)
2289         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2290         local fd=$(free_fd)
2291         local cmd="exec $fd<$DIR/$tfile"
2292         eval $cmd
2293         cmd="exec $fd<&-"
2294         trap "eval $cmd" EXIT
2295         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2296         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2297         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2298         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2299         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2300         eval $cmd
2301 }
2302 run_test 31n "check link count of unlinked file"
2303
2304 link_one() {
2305         local TEMPNAME=$(mktemp $1_XXXXXX)
2306         mlink $TEMPNAME $1 2> /dev/null &&
2307                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2308         munlink $TEMPNAME
2309 }
2310
2311 test_31o() { # LU-2901
2312         test_mkdir -p $DIR/$tdir
2313         for LOOP in $(seq 100); do
2314                 rm -f $DIR/$tdir/$tfile*
2315                 for THREAD in $(seq 8); do
2316                         link_one $DIR/$tdir/$tfile.$LOOP &
2317                 done
2318                 wait
2319                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2320                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2321                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2322                         break || true
2323         done
2324 }
2325 run_test 31o "duplicate hard links with same filename"
2326
2327 test_31p() {
2328         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2329
2330         test_mkdir $DIR/$tdir
2331         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2332         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2333
2334         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2335                 error "open unlink test1 failed"
2336         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2337                 error "open unlink test2 failed"
2338
2339         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2340                 error "test1 still exists"
2341         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2342                 error "test2 still exists"
2343 }
2344 run_test 31p "remove of open striped directory"
2345
2346 cleanup_test32_mount() {
2347         trap 0
2348         $UMOUNT -d $DIR/$tdir/ext2-mountpoint
2349 }
2350
2351 test_32a() {
2352         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2353         echo "== more mountpoints and symlinks ================="
2354         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2355         trap cleanup_test32_mount EXIT
2356         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2357         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2358         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2359         cleanup_test32_mount
2360 }
2361 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2362
2363 test_32b() {
2364         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2365         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2366         trap cleanup_test32_mount EXIT
2367         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2368         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2369         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2370         cleanup_test32_mount
2371 }
2372 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2373
2374 test_32c() {
2375         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2376         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2377         trap cleanup_test32_mount EXIT
2378         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2379         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2380         test_mkdir -p $DIR/$tdir/d2/test_dir
2381         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2382         cleanup_test32_mount
2383 }
2384 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2385
2386 test_32d() {
2387         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2388         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2389         trap cleanup_test32_mount EXIT
2390         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2391         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2392         test_mkdir -p $DIR/$tdir/d2/test_dir
2393         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2394         cleanup_test32_mount
2395 }
2396 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2397
2398 test_32e() {
2399         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2400         test_mkdir -p $DIR/d32e/tmp
2401         TMP_DIR=$DIR/d32e/tmp
2402         ln -s $DIR/d32e $TMP_DIR/symlink11
2403         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2404         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2405         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2406 }
2407 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2408
2409 test_32f() {
2410         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2411         test_mkdir -p $DIR/d32f/tmp
2412         TMP_DIR=$DIR/d32f/tmp
2413         ln -s $DIR/d32f $TMP_DIR/symlink11
2414         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2415         ls $DIR/d32f/tmp/symlink11  || error
2416         ls $DIR/d32f/symlink01 || error
2417 }
2418 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2419
2420 test_32g() {
2421         TMP_DIR=$DIR/$tdir/tmp
2422         test_mkdir -p $DIR/$tdir/tmp
2423         test_mkdir $DIR/${tdir}2
2424         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2425         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2426         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2427         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2428         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2429         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2430 }
2431 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2432
2433 test_32h() {
2434         rm -fr $DIR/$tdir $DIR/${tdir}2
2435         TMP_DIR=$DIR/$tdir/tmp
2436         test_mkdir -p $DIR/$tdir/tmp
2437         test_mkdir $DIR/${tdir}2
2438         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2439         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2440         ls $TMP_DIR/symlink12 || error
2441         ls $DIR/$tdir/symlink02  || error
2442 }
2443 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2444
2445 test_32i() {
2446         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2447         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2448         trap cleanup_test32_mount EXIT
2449         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2450         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2451         touch $DIR/$tdir/test_file
2452         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2453         cleanup_test32_mount
2454 }
2455 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2456
2457 test_32j() {
2458         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2459         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2460         trap cleanup_test32_mount EXIT
2461         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2462         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2463         touch $DIR/$tdir/test_file
2464         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2465         cleanup_test32_mount
2466 }
2467 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2468
2469 test_32k() {
2470         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2471         rm -fr $DIR/$tdir
2472         trap cleanup_test32_mount EXIT
2473         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2474         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2475         test_mkdir -p $DIR/$tdir/d2
2476         touch $DIR/$tdir/d2/test_file || error
2477         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2478         cleanup_test32_mount
2479 }
2480 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2481
2482 test_32l() {
2483         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2484         rm -fr $DIR/$tdir
2485         trap cleanup_test32_mount EXIT
2486         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2487         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2488         test_mkdir -p $DIR/$tdir/d2
2489         touch $DIR/$tdir/d2/test_file
2490         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2491         cleanup_test32_mount
2492 }
2493 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2494
2495 test_32m() {
2496         rm -fr $DIR/d32m
2497         test_mkdir -p $DIR/d32m/tmp
2498         TMP_DIR=$DIR/d32m/tmp
2499         ln -s $DIR $TMP_DIR/symlink11
2500         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2501         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2502         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2503 }
2504 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2505
2506 test_32n() {
2507         rm -fr $DIR/d32n
2508         test_mkdir -p $DIR/d32n/tmp
2509         TMP_DIR=$DIR/d32n/tmp
2510         ln -s $DIR $TMP_DIR/symlink11
2511         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2512         ls -l $DIR/d32n/tmp/symlink11  || error
2513         ls -l $DIR/d32n/symlink01 || error
2514 }
2515 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2516
2517 test_32o() {
2518         touch $DIR/$tfile
2519         test_mkdir -p $DIR/d32o/tmp
2520         TMP_DIR=$DIR/d32o/tmp
2521         ln -s $DIR/$tfile $TMP_DIR/symlink12
2522         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2523         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2524         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2525         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2526         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2527 }
2528 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2529
2530 test_32p() {
2531     log 32p_1
2532         rm -fr $DIR/d32p
2533     log 32p_2
2534         rm -f $DIR/$tfile
2535     log 32p_3
2536         touch $DIR/$tfile
2537     log 32p_4
2538         test_mkdir -p $DIR/d32p/tmp
2539     log 32p_5
2540         TMP_DIR=$DIR/d32p/tmp
2541     log 32p_6
2542         ln -s $DIR/$tfile $TMP_DIR/symlink12
2543     log 32p_7
2544         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2545     log 32p_8
2546         cat $DIR/d32p/tmp/symlink12 || error
2547     log 32p_9
2548         cat $DIR/d32p/symlink02 || error
2549     log 32p_10
2550 }
2551 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2552
2553 cleanup_testdir_mount() {
2554         trap 0
2555         $UMOUNT -d $DIR/$tdir
2556 }
2557
2558 test_32q() {
2559         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2560         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2561         trap cleanup_testdir_mount EXIT
2562         test_mkdir -p $DIR/$tdir
2563         touch $DIR/$tdir/under_the_mount
2564         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2565         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2566         cleanup_testdir_mount
2567 }
2568 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2569
2570 test_32r() {
2571         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2572         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2573         trap cleanup_testdir_mount EXIT
2574         test_mkdir -p $DIR/$tdir
2575         touch $DIR/$tdir/under_the_mount
2576         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2577         ls $DIR/$tdir | grep -q under_the_mount && error || true
2578         cleanup_testdir_mount
2579 }
2580 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2581
2582 test_33aa() {
2583         rm -f $DIR/$tfile
2584         touch $DIR/$tfile
2585         chmod 444 $DIR/$tfile
2586         chown $RUNAS_ID $DIR/$tfile
2587         log 33_1
2588         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2589         log 33_2
2590 }
2591 run_test 33aa "write file with mode 444 (should return error) ===="
2592
2593 test_33a() {
2594         rm -fr $DIR/d33
2595         test_mkdir -p $DIR/d33
2596         chown $RUNAS_ID $DIR/d33
2597         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2598         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2599                 error "open RDWR" || true
2600 }
2601 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2602
2603 test_33b() {
2604         rm -fr $DIR/d33
2605         test_mkdir -p $DIR/d33
2606         chown $RUNAS_ID $DIR/d33
2607         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 || true
2608 }
2609 run_test 33b "test open file with malformed flags (No panic)"
2610
2611 test_33c() {
2612         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2613         local ostnum
2614         local ostname
2615         local write_bytes
2616         local all_zeros
2617
2618         remote_ost_nodsh && skip "remote OST with nodsh" && return
2619         all_zeros=:
2620         rm -fr $DIR/d33
2621         test_mkdir -p $DIR/d33
2622         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2623
2624         sync
2625         for ostnum in $(seq $OSTCOUNT); do
2626                 # test-framework's OST numbering is one-based, while Lustre's
2627                 # is zero-based
2628                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2629                 # Parsing llobdstat's output sucks; we could grep the /proc
2630                 # path, but that's likely to not be as portable as using the
2631                 # llobdstat utility.  So we parse lctl output instead.
2632                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2633                         obdfilter/$ostname/stats |
2634                         awk '/^write_bytes/ {print $7}' )
2635                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2636                 if (( ${write_bytes:-0} > 0 ))
2637                 then
2638                         all_zeros=false
2639                         break;
2640                 fi
2641         done
2642
2643         $all_zeros || return 0
2644
2645         # Write four bytes
2646         echo foo > $DIR/d33/bar
2647         # Really write them
2648         sync
2649
2650         # Total up write_bytes after writing.  We'd better find non-zeros.
2651         for ostnum in $(seq $OSTCOUNT); do
2652                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2653                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2654                         obdfilter/$ostname/stats |
2655                         awk '/^write_bytes/ {print $7}' )
2656                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2657                 if (( ${write_bytes:-0} > 0 ))
2658                 then
2659                         all_zeros=false
2660                         break;
2661                 fi
2662         done
2663
2664         if $all_zeros
2665         then
2666                 for ostnum in $(seq $OSTCOUNT); do
2667                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2668                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2669                         do_facet ost$ostnum lctl get_param -n \
2670                                 obdfilter/$ostname/stats
2671                 done
2672                 error "OST not keeping write_bytes stats (b22312)"
2673         fi
2674 }
2675 run_test 33c "test llobdstat and write_bytes"
2676
2677 test_33d() {
2678         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2679         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2680         local MDTIDX=1
2681         local remote_dir=$DIR/$tdir/remote_dir
2682
2683         test_mkdir -p $DIR/$tdir
2684         $LFS mkdir -i $MDTIDX $remote_dir ||
2685                 error "create remote directory failed"
2686
2687         touch $remote_dir/$tfile
2688         chmod 444 $remote_dir/$tfile
2689         chown $RUNAS_ID $remote_dir/$tfile
2690
2691         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2692
2693         chown $RUNAS_ID $remote_dir
2694         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2695                                         error "create" || true
2696         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2697                                     error "open RDWR" || true
2698         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2699                                     error "create" || true
2700 }
2701 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2702
2703 test_33e() {
2704         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2705
2706         mkdir $DIR/$tdir
2707
2708         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2709         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2710         mkdir $DIR/$tdir/local_dir
2711
2712         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2713         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2714         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2715
2716         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2717                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2718
2719         rmdir $DIR/$tdir/* || error "rmdir failed"
2720
2721         umask 777
2722         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2723         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2724         mkdir $DIR/$tdir/local_dir
2725
2726         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2727         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2728         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2729
2730         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2731                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2732
2733         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2734
2735         umask 000
2736         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2737         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2738         mkdir $DIR/$tdir/local_dir
2739
2740         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2741         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2742         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2743
2744         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2745                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2746 }
2747 run_test 33e "mkdir and striped directory should have same mode"
2748
2749 cleanup_33f() {
2750         trap 0
2751         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
2752 }
2753
2754 test_33f() {
2755         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2756
2757         mkdir $DIR/$tdir
2758         chmod go+rwx $DIR/$tdir
2759         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
2760         trap cleanup_33f EXIT
2761
2762         $RUNAS lfs mkdir -c$MDSCOUNT $DIR/$tdir/striped_dir ||
2763                 error "cannot create striped directory"
2764
2765         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
2766                 error "cannot create files in striped directory"
2767
2768         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
2769                 error "cannot remove files in striped directory"
2770
2771         $RUNAS rmdir $DIR/$tdir/striped_dir ||
2772                 error "cannot remove striped directory"
2773
2774         cleanup_33f
2775 }
2776 run_test 33f "nonroot user can create, access, and remove a striped directory"
2777
2778 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2779 test_34a() {
2780         rm -f $DIR/f34
2781         $MCREATE $DIR/f34 || error
2782         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2783         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2784         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2785         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2786 }
2787 run_test 34a "truncate file that has not been opened ==========="
2788
2789 test_34b() {
2790         [ ! -f $DIR/f34 ] && test_34a
2791         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2792         $OPENFILE -f O_RDONLY $DIR/f34
2793         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2794         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2795 }
2796 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2797
2798 test_34c() {
2799         [ ! -f $DIR/f34 ] && test_34a
2800         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2801         $OPENFILE -f O_RDWR $DIR/f34
2802         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2803         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2804 }
2805 run_test 34c "O_RDWR opening file-with-size works =============="
2806
2807 test_34d() {
2808         [ ! -f $DIR/f34 ] && test_34a
2809         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2810         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2811         rm $DIR/f34
2812 }
2813 run_test 34d "write to sparse file ============================="
2814
2815 test_34e() {
2816         rm -f $DIR/f34e
2817         $MCREATE $DIR/f34e || error
2818         $TRUNCATE $DIR/f34e 1000 || error
2819         $CHECKSTAT -s 1000 $DIR/f34e || error
2820         $OPENFILE -f O_RDWR $DIR/f34e
2821         $CHECKSTAT -s 1000 $DIR/f34e || error
2822 }
2823 run_test 34e "create objects, some with size and some without =="
2824
2825 test_34f() { # bug 6242, 6243
2826         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2827         SIZE34F=48000
2828         rm -f $DIR/f34f
2829         $MCREATE $DIR/f34f || error
2830         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2831         dd if=$DIR/f34f of=$TMP/f34f
2832         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2833         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2834         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2835         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2836         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2837 }
2838 run_test 34f "read from a file with no objects until EOF ======="
2839
2840 test_34g() {
2841         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2842         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2843         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2844         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2845         cancel_lru_locks osc
2846         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2847                 error "wrong size after lock cancel"
2848
2849         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2850         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2851                 error "expanding truncate failed"
2852         cancel_lru_locks osc
2853         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2854                 error "wrong expanded size after lock cancel"
2855 }
2856 run_test 34g "truncate long file ==============================="
2857
2858 test_34h() {
2859         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2860         local gid=10
2861         local sz=1000
2862
2863         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2864         sync # Flush the cache so that multiop below does not block on cache
2865              # flush when getting the group lock
2866         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2867         MULTIPID=$!
2868
2869         # Since just timed wait is not good enough, let's do a sync write
2870         # that way we are sure enough time for a roundtrip + processing
2871         # passed + 2 seconds of extra margin.
2872         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2873         rm $DIR/${tfile}-1
2874         sleep 2
2875
2876         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2877                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2878                 kill -9 $MULTIPID
2879         fi
2880         wait $MULTIPID
2881         local nsz=`stat -c %s $DIR/$tfile`
2882         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2883 }
2884 run_test 34h "ftruncate file under grouplock should not block"
2885
2886 test_35a() {
2887         cp /bin/sh $DIR/f35a
2888         chmod 444 $DIR/f35a
2889         chown $RUNAS_ID $DIR/f35a
2890         $RUNAS $DIR/f35a && error || true
2891         rm $DIR/f35a
2892 }
2893 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2894
2895 test_36a() {
2896         rm -f $DIR/f36
2897         utime $DIR/f36 || error
2898 }
2899 run_test 36a "MDS utime check (mknod, utime) ==================="
2900
2901 test_36b() {
2902         echo "" > $DIR/f36
2903         utime $DIR/f36 || error
2904 }
2905 run_test 36b "OST utime check (open, utime) ===================="
2906
2907 test_36c() {
2908         rm -f $DIR/d36/f36
2909         test_mkdir $DIR/d36
2910         chown $RUNAS_ID $DIR/d36
2911         $RUNAS utime $DIR/d36/f36 || error
2912 }
2913 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2914
2915 test_36d() {
2916         [ ! -d $DIR/d36 ] && test_36c
2917         echo "" > $DIR/d36/f36
2918         $RUNAS utime $DIR/d36/f36 || error
2919 }
2920 run_test 36d "non-root OST utime check (open, utime) ==========="
2921
2922 test_36e() {
2923         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2924         test_mkdir -p $DIR/$tdir
2925         touch $DIR/$tdir/$tfile
2926         $RUNAS utime $DIR/$tdir/$tfile && \
2927                 error "utime worked, expected failure" || true
2928 }
2929 run_test 36e "utime on non-owned file (should return error) ===="
2930
2931 subr_36fh() {
2932         local fl="$1"
2933         local LANG_SAVE=$LANG
2934         local LC_LANG_SAVE=$LC_LANG
2935         export LANG=C LC_LANG=C # for date language
2936
2937         DATESTR="Dec 20  2000"
2938         test_mkdir -p $DIR/$tdir
2939         lctl set_param fail_loc=$fl
2940         date; date +%s
2941         cp /etc/hosts $DIR/$tdir/$tfile
2942         sync & # write RPC generated with "current" inode timestamp, but delayed
2943         sleep 1
2944         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2945         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2946         cancel_lru_locks osc
2947         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2948         date; date +%s
2949         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2950                 echo "BEFORE: $LS_BEFORE" && \
2951                 echo "AFTER : $LS_AFTER" && \
2952                 echo "WANT  : $DATESTR" && \
2953                 error "$DIR/$tdir/$tfile timestamps changed" || true
2954
2955         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2956 }
2957
2958 test_36f() {
2959         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2960         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2961         subr_36fh "0x80000214"
2962 }
2963 run_test 36f "utime on file racing with OST BRW write =========="
2964
2965 test_36g() {
2966         remote_ost_nodsh && skip "remote OST with nodsh" && return
2967         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2968         local fmd_max_age
2969         local fmd_before
2970         local fmd_after
2971
2972         test_mkdir -p $DIR/$tdir
2973         fmd_max_age=$(do_facet ost1 \
2974                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2975                 head -n 1")
2976
2977         fmd_before=$(do_facet ost1 \
2978                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2979         touch $DIR/$tdir/$tfile
2980         sleep $((fmd_max_age + 12))
2981         fmd_after=$(do_facet ost1 \
2982                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2983
2984         echo "fmd_before: $fmd_before"
2985         echo "fmd_after: $fmd_after"
2986         [[ $fmd_after -gt $fmd_before ]] &&
2987                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
2988                 error "fmd didn't expire after ping" || true
2989 }
2990 run_test 36g "filter mod data cache expiry ====================="
2991
2992 test_36h() {
2993         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2994         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2995         subr_36fh "0x80000227"
2996 }
2997 run_test 36h "utime on file racing with OST BRW write =========="
2998
2999 test_36i() {
3000         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3001
3002         test_mkdir $DIR/$tdir
3003         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
3004
3005         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3006         local new_mtime=$((mtime + 200))
3007
3008         #change Modify time of striped dir
3009         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3010                         error "change mtime failed"
3011
3012         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3013
3014         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3015 }
3016 run_test 36i "change mtime on striped directory"
3017
3018 # test_37 - duplicate with tests 32q 32r
3019
3020 test_38() {
3021         local file=$DIR/$tfile
3022         touch $file
3023         openfile -f O_DIRECTORY $file
3024         local RC=$?
3025         local ENOTDIR=20
3026         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3027         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3028 }
3029 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3030
3031 test_39() {
3032         touch $DIR/$tfile
3033         touch $DIR/${tfile}2
3034 #       ls -l  $DIR/$tfile $DIR/${tfile}2
3035 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
3036 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
3037         sleep 2
3038         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3039         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3040                 echo "mtime"
3041                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3042                 echo "atime"
3043                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3044                 echo "ctime"
3045                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3046                 error "O_TRUNC didn't change timestamps"
3047         fi
3048 }
3049 run_test 39 "mtime changed on create ==========================="
3050
3051 test_39b() {
3052         test_mkdir -p -c1 $DIR/$tdir
3053         cp -p /etc/passwd $DIR/$tdir/fopen
3054         cp -p /etc/passwd $DIR/$tdir/flink
3055         cp -p /etc/passwd $DIR/$tdir/funlink
3056         cp -p /etc/passwd $DIR/$tdir/frename
3057         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3058
3059         sleep 1
3060         echo "aaaaaa" >> $DIR/$tdir/fopen
3061         echo "aaaaaa" >> $DIR/$tdir/flink
3062         echo "aaaaaa" >> $DIR/$tdir/funlink
3063         echo "aaaaaa" >> $DIR/$tdir/frename
3064
3065         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3066         local link_new=`stat -c %Y $DIR/$tdir/flink`
3067         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3068         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3069
3070         cat $DIR/$tdir/fopen > /dev/null
3071         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3072         rm -f $DIR/$tdir/funlink2
3073         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3074
3075         for (( i=0; i < 2; i++ )) ; do
3076                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3077                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3078                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3079                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3080
3081                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3082                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3083                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3084                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3085
3086                 cancel_lru_locks osc
3087                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3088         done
3089 }
3090 run_test 39b "mtime change on open, link, unlink, rename  ======"
3091
3092 # this should be set to past
3093 TEST_39_MTIME=`date -d "1 year ago" +%s`
3094
3095 # bug 11063
3096 test_39c() {
3097         touch $DIR1/$tfile
3098         sleep 2
3099         local mtime0=`stat -c %Y $DIR1/$tfile`
3100
3101         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3102         local mtime1=`stat -c %Y $DIR1/$tfile`
3103         [ "$mtime1" = $TEST_39_MTIME ] || \
3104                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3105
3106         local d1=`date +%s`
3107         echo hello >> $DIR1/$tfile
3108         local d2=`date +%s`
3109         local mtime2=`stat -c %Y $DIR1/$tfile`
3110         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3111                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3112
3113         mv $DIR1/$tfile $DIR1/$tfile-1
3114
3115         for (( i=0; i < 2; i++ )) ; do
3116                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3117                 [ "$mtime2" = "$mtime3" ] || \
3118                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3119
3120                 cancel_lru_locks osc
3121                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3122         done
3123 }
3124 run_test 39c "mtime change on rename ==========================="
3125
3126 # bug 21114
3127 test_39d() {
3128         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3129         touch $DIR1/$tfile
3130
3131         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3132
3133         for (( i=0; i < 2; i++ )) ; do
3134                 local mtime=`stat -c %Y $DIR1/$tfile`
3135                 [ $mtime = $TEST_39_MTIME ] || \
3136                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3137
3138                 cancel_lru_locks osc
3139                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3140         done
3141 }
3142 run_test 39d "create, utime, stat =============================="
3143
3144 # bug 21114
3145 test_39e() {
3146         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3147         touch $DIR1/$tfile
3148         local mtime1=`stat -c %Y $DIR1/$tfile`
3149
3150         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3151
3152         for (( i=0; i < 2; i++ )) ; do
3153                 local mtime2=`stat -c %Y $DIR1/$tfile`
3154                 [ $mtime2 = $TEST_39_MTIME ] || \
3155                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3156
3157                 cancel_lru_locks osc
3158                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3159         done
3160 }
3161 run_test 39e "create, stat, utime, stat ========================"
3162
3163 # bug 21114
3164 test_39f() {
3165         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3166         touch $DIR1/$tfile
3167         mtime1=`stat -c %Y $DIR1/$tfile`
3168
3169         sleep 2
3170         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3171
3172         for (( i=0; i < 2; i++ )) ; do
3173                 local mtime2=`stat -c %Y $DIR1/$tfile`
3174                 [ $mtime2 = $TEST_39_MTIME ] || \
3175                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3176
3177                 cancel_lru_locks osc
3178                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3179         done
3180 }
3181 run_test 39f "create, stat, sleep, utime, stat ================="
3182
3183 # bug 11063
3184 test_39g() {
3185         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3186         echo hello >> $DIR1/$tfile
3187         local mtime1=`stat -c %Y $DIR1/$tfile`
3188
3189         sleep 2
3190         chmod o+r $DIR1/$tfile
3191
3192         for (( i=0; i < 2; i++ )) ; do
3193                 local mtime2=`stat -c %Y $DIR1/$tfile`
3194                 [ "$mtime1" = "$mtime2" ] || \
3195                         error "lost mtime: $mtime2, should be $mtime1"
3196
3197                 cancel_lru_locks osc
3198                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3199         done
3200 }
3201 run_test 39g "write, chmod, stat ==============================="
3202
3203 # bug 11063
3204 test_39h() {
3205         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3206         touch $DIR1/$tfile
3207         sleep 1
3208
3209         local d1=`date`
3210         echo hello >> $DIR1/$tfile
3211         local mtime1=`stat -c %Y $DIR1/$tfile`
3212
3213         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3214         local d2=`date`
3215         if [ "$d1" != "$d2" ]; then
3216                 echo "write and touch not within one second"
3217         else
3218                 for (( i=0; i < 2; i++ )) ; do
3219                         local mtime2=`stat -c %Y $DIR1/$tfile`
3220                         [ "$mtime2" = $TEST_39_MTIME ] || \
3221                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3222
3223                         cancel_lru_locks osc
3224                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3225                 done
3226         fi
3227 }
3228 run_test 39h "write, utime within one second, stat ============="
3229
3230 test_39i() {
3231         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3232         touch $DIR1/$tfile
3233         sleep 1
3234
3235         echo hello >> $DIR1/$tfile
3236         local mtime1=`stat -c %Y $DIR1/$tfile`
3237
3238         mv $DIR1/$tfile $DIR1/$tfile-1
3239
3240         for (( i=0; i < 2; i++ )) ; do
3241                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3242
3243                 [ "$mtime1" = "$mtime2" ] || \
3244                         error "lost mtime: $mtime2, should be $mtime1"
3245
3246                 cancel_lru_locks osc
3247                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3248         done
3249 }
3250 run_test 39i "write, rename, stat =============================="
3251
3252 test_39j() {
3253         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3254         start_full_debug_logging
3255         touch $DIR1/$tfile
3256         sleep 1
3257
3258         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3259         lctl set_param fail_loc=0x80000412
3260         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3261                 error "multiop failed"
3262         local multipid=$!
3263         local mtime1=`stat -c %Y $DIR1/$tfile`
3264
3265         mv $DIR1/$tfile $DIR1/$tfile-1
3266
3267         kill -USR1 $multipid
3268         wait $multipid || error "multiop close failed"
3269
3270         for (( i=0; i < 2; i++ )) ; do
3271                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3272                 [ "$mtime1" = "$mtime2" ] ||
3273                         error "mtime is lost on close: $mtime2, " \
3274                               "should be $mtime1"
3275
3276                 cancel_lru_locks osc
3277                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3278         done
3279         lctl set_param fail_loc=0
3280         stop_full_debug_logging
3281 }
3282 run_test 39j "write, rename, close, stat ======================="
3283
3284 test_39k() {
3285         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3286         touch $DIR1/$tfile
3287         sleep 1
3288
3289         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3290         local multipid=$!
3291         local mtime1=`stat -c %Y $DIR1/$tfile`
3292
3293         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3294
3295         kill -USR1 $multipid
3296         wait $multipid || error "multiop close failed"
3297
3298         for (( i=0; i < 2; i++ )) ; do
3299                 local mtime2=`stat -c %Y $DIR1/$tfile`
3300
3301                 [ "$mtime2" = $TEST_39_MTIME ] || \
3302                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3303
3304                 cancel_lru_locks osc
3305                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3306         done
3307 }
3308 run_test 39k "write, utime, close, stat ========================"
3309
3310 # this should be set to future
3311 TEST_39_ATIME=`date -d "1 year" +%s`
3312
3313 test_39l() {
3314         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3315         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3316         local atime_diff=$(do_facet $SINGLEMDS \
3317                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3318         rm -rf $DIR/$tdir
3319         mkdir -p $DIR/$tdir
3320
3321         # test setting directory atime to future
3322         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3323         local atime=$(stat -c %X $DIR/$tdir)
3324         [ "$atime" = $TEST_39_ATIME ] || \
3325                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3326
3327         # test setting directory atime from future to now
3328         local d1=$(date +%s)
3329         ls $DIR/$tdir
3330         local d2=$(date +%s)
3331
3332         cancel_lru_locks mdc
3333         atime=$(stat -c %X $DIR/$tdir)
3334         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3335                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3336
3337         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3338         sleep 3
3339
3340         # test setting directory atime when now > dir atime + atime_diff
3341         d1=$(date +%s)
3342         ls $DIR/$tdir
3343         d2=$(date +%s)
3344         cancel_lru_locks mdc
3345         atime=$(stat -c %X $DIR/$tdir)
3346         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3347                 error "atime is not updated  : $atime, should be $d2"
3348
3349         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3350         sleep 3
3351
3352         # test not setting directory atime when now < dir atime + atime_diff
3353         ls $DIR/$tdir
3354         cancel_lru_locks mdc
3355         atime=$(stat -c %X $DIR/$tdir)
3356         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3357                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3358
3359         do_facet $SINGLEMDS \
3360                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3361 }
3362 run_test 39l "directory atime update ==========================="
3363
3364 test_39m() {
3365         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3366         touch $DIR1/$tfile
3367         sleep 2
3368         local far_past_mtime=$(date -d "May 29 1953" +%s)
3369         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3370
3371         touch -m -d @$far_past_mtime $DIR1/$tfile
3372         touch -a -d @$far_past_atime $DIR1/$tfile
3373
3374         for (( i=0; i < 2; i++ )) ; do
3375                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3376                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3377                         error "atime or mtime set incorrectly"
3378
3379                 cancel_lru_locks osc
3380                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3381         done
3382 }
3383 run_test 39m "test atime and mtime before 1970"
3384
3385 test_39n() { # LU-3832
3386         local atime_diff=$(do_facet $SINGLEMDS \
3387                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3388         local atime0
3389         local atime1
3390         local atime2
3391
3392         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3393
3394         rm -rf $DIR/$tfile
3395         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3396         atime0=$(stat -c %X $DIR/$tfile)
3397
3398         sleep 5
3399         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3400         atime1=$(stat -c %X $DIR/$tfile)
3401
3402         sleep 5
3403         cancel_lru_locks mdc
3404         cancel_lru_locks osc
3405         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3406         atime2=$(stat -c %X $DIR/$tfile)
3407
3408         do_facet $SINGLEMDS \
3409                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3410
3411         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3412         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3413 }
3414 run_test 39n "check that O_NOATIME is honored"
3415
3416 test_39o() {
3417         TESTDIR=$DIR/$tdir/$tfile
3418         [ -e $TESTDIR ] && rm -rf $TESTDIR
3419         mkdir -p $TESTDIR
3420         cd $TESTDIR
3421         links1=2
3422         ls
3423         mkdir a b
3424         ls
3425         links2=$(stat -c %h .)
3426         [ $(($links1 + 2)) != $links2 ] &&
3427                 error "wrong links count $(($links1 + 2)) != $links2"
3428         rmdir b
3429         links3=$(stat -c %h .)
3430         [ $(($links1 + 1)) != $links3 ] &&
3431                 error "wrong links count $links1 != $links3"
3432         return 0
3433 }
3434 run_test 39o "directory cached attributes updated after create ========"
3435
3436 test_39p() {
3437         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3438         local MDTIDX=1
3439         TESTDIR=$DIR/$tdir/$tfile
3440         [ -e $TESTDIR ] && rm -rf $TESTDIR
3441         test_mkdir -p $TESTDIR
3442         cd $TESTDIR
3443         links1=2
3444         ls
3445         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3446         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3447         ls
3448         links2=$(stat -c %h .)
3449         [ $(($links1 + 2)) != $links2 ] &&
3450                 error "wrong links count $(($links1 + 2)) != $links2"
3451         rmdir remote_dir2
3452         links3=$(stat -c %h .)
3453         [ $(($links1 + 1)) != $links3 ] &&
3454                 error "wrong links count $links1 != $links3"
3455         return 0
3456 }
3457 run_test 39p "remote directory cached attributes updated after create ========"
3458
3459
3460 test_40() {
3461         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3462         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3463                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3464         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3465                 error "$tfile is not 4096 bytes in size"
3466 }
3467 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3468
3469 test_41() {
3470         # bug 1553
3471         small_write $DIR/f41 18
3472 }
3473 run_test 41 "test small file write + fstat ====================="
3474
3475 count_ost_writes() {
3476         lctl get_param -n osc.*.stats |
3477                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3478                         END { printf("%0.0f", writes) }'
3479 }
3480
3481 # decent default
3482 WRITEBACK_SAVE=500
3483 DIRTY_RATIO_SAVE=40
3484 MAX_DIRTY_RATIO=50
3485 BG_DIRTY_RATIO_SAVE=10
3486 MAX_BG_DIRTY_RATIO=25
3487
3488 start_writeback() {
3489         trap 0
3490         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3491         # dirty_ratio, dirty_background_ratio
3492         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3493                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3494                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3495                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3496         else
3497                 # if file not here, we are a 2.4 kernel
3498                 kill -CONT `pidof kupdated`
3499         fi
3500 }
3501
3502 stop_writeback() {
3503         # setup the trap first, so someone cannot exit the test at the
3504         # exact wrong time and mess up a machine
3505         trap start_writeback EXIT
3506         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3507         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3508                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3509                 sysctl -w vm.dirty_writeback_centisecs=0
3510                 sysctl -w vm.dirty_writeback_centisecs=0
3511                 # save and increase /proc/sys/vm/dirty_ratio
3512                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3513                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3514                 # save and increase /proc/sys/vm/dirty_background_ratio
3515                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3516                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3517         else
3518                 # if file not here, we are a 2.4 kernel
3519                 kill -STOP `pidof kupdated`
3520         fi
3521 }
3522
3523 # ensure that all stripes have some grant before we test client-side cache
3524 setup_test42() {
3525         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3526                 dd if=/dev/zero of=$i bs=4k count=1
3527                 rm $i
3528         done
3529 }
3530
3531 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3532 # file truncation, and file removal.
3533 test_42a() {
3534         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3535         setup_test42
3536         cancel_lru_locks osc
3537         stop_writeback
3538         sync; sleep 1; sync # just to be safe
3539         BEFOREWRITES=`count_ost_writes`
3540         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3541         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3542         AFTERWRITES=`count_ost_writes`
3543         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3544                 error "$BEFOREWRITES < $AFTERWRITES"
3545         start_writeback
3546 }
3547 run_test 42a "ensure that we don't flush on close =============="
3548
3549 test_42b() {
3550         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3551         setup_test42
3552         cancel_lru_locks osc
3553         stop_writeback
3554         sync
3555         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3556         BEFOREWRITES=$(count_ost_writes)
3557         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3558         AFTERWRITES=$(count_ost_writes)
3559         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3560                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3561         fi
3562         BEFOREWRITES=$(count_ost_writes)
3563         sync || error "sync: $?"
3564         AFTERWRITES=$(count_ost_writes)
3565         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3566                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3567         fi
3568         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3569         start_writeback
3570         return 0
3571 }
3572 run_test 42b "test destroy of file with cached dirty data ======"
3573
3574 # if these tests just want to test the effect of truncation,
3575 # they have to be very careful.  consider:
3576 # - the first open gets a {0,EOF}PR lock
3577 # - the first write conflicts and gets a {0, count-1}PW
3578 # - the rest of the writes are under {count,EOF}PW
3579 # - the open for truncate tries to match a {0,EOF}PR
3580 #   for the filesize and cancels the PWs.
3581 # any number of fixes (don't get {0,EOF} on open, match
3582 # composite locks, do smarter file size management) fix
3583 # this, but for now we want these tests to verify that
3584 # the cancellation with truncate intent works, so we
3585 # start the file with a full-file pw lock to match against
3586 # until the truncate.
3587 trunc_test() {
3588         test=$1
3589         file=$DIR/$test
3590         offset=$2
3591         cancel_lru_locks osc
3592         stop_writeback
3593         # prime the file with 0,EOF PW to match
3594         touch $file
3595         $TRUNCATE $file 0
3596         sync; sync
3597         # now the real test..
3598         dd if=/dev/zero of=$file bs=1024 count=100
3599         BEFOREWRITES=`count_ost_writes`
3600         $TRUNCATE $file $offset
3601         cancel_lru_locks osc
3602         AFTERWRITES=`count_ost_writes`
3603         start_writeback
3604 }
3605
3606 test_42c() {
3607         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3608         trunc_test 42c 1024
3609         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3610             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3611         rm $file
3612 }
3613 run_test 42c "test partial truncate of file with cached dirty data"
3614
3615 test_42d() {
3616         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3617         trunc_test 42d 0
3618         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3619             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3620         rm $file
3621 }
3622 run_test 42d "test complete truncate of file with cached dirty data"
3623
3624 test_42e() { # bug22074
3625         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3626         local TDIR=$DIR/${tdir}e
3627         local pagesz=$(page_size)
3628         local pages=16 # hardcoded 16 pages, don't change it.
3629         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3630         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3631         local max_dirty_mb
3632         local warmup_files
3633
3634         test_mkdir -p $DIR/${tdir}e
3635         $SETSTRIPE -c 1 $TDIR
3636         createmany -o $TDIR/f $files
3637
3638         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3639
3640         # we assume that with $OSTCOUNT files, at least one of them will
3641         # be allocated on OST0.
3642         warmup_files=$((OSTCOUNT * max_dirty_mb))
3643         createmany -o $TDIR/w $warmup_files
3644
3645         # write a large amount of data into one file and sync, to get good
3646         # avail_grant number from OST.
3647         for ((i=0; i<$warmup_files; i++)); do
3648                 idx=$($GETSTRIPE -i $TDIR/w$i)
3649                 [ $idx -ne 0 ] && continue
3650                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3651                 break
3652         done
3653         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3654         sync
3655         $LCTL get_param $proc_osc0/cur_dirty_bytes
3656         $LCTL get_param $proc_osc0/cur_grant_bytes
3657
3658         # create as much dirty pages as we can while not to trigger the actual
3659         # RPCs directly. but depends on the env, VFS may trigger flush during this
3660         # period, hopefully we are good.
3661         for ((i=0; i<$warmup_files; i++)); do
3662                 idx=$($GETSTRIPE -i $TDIR/w$i)
3663                 [ $idx -ne 0 ] && continue
3664                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3665         done
3666         $LCTL get_param $proc_osc0/cur_dirty_bytes
3667         $LCTL get_param $proc_osc0/cur_grant_bytes
3668
3669         # perform the real test
3670         $LCTL set_param $proc_osc0/rpc_stats 0
3671         for ((;i<$files; i++)); do
3672                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3673                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3674         done
3675         sync
3676         $LCTL get_param $proc_osc0/rpc_stats
3677
3678         local percent=0
3679         local have_ppr=false
3680         $LCTL get_param $proc_osc0/rpc_stats |
3681                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3682                         # skip lines until we are at the RPC histogram data
3683                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3684                         $have_ppr || continue
3685
3686                         # we only want the percent stat for < 16 pages
3687                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3688
3689                         percent=$((percent + WPCT))
3690                         if [[ $percent -gt 15 ]]; then
3691                                 error "less than 16-pages write RPCs" \
3692                                       "$percent% > 15%"
3693                                 break
3694                         fi
3695                 done
3696         rm -rf $TDIR
3697 }
3698 run_test 42e "verify sub-RPC writes are not done synchronously"
3699
3700 test_43() {
3701         test_mkdir -p $DIR/$tdir
3702         cp -p /bin/ls $DIR/$tdir/$tfile
3703         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3704         pid=$!
3705         # give multiop a chance to open
3706         sleep 1
3707
3708         $DIR/$tdir/$tfile && error || true
3709         kill -USR1 $pid
3710 }
3711 run_test 43 "execution of file opened for write should return -ETXTBSY"
3712
3713 test_43a() {
3714         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3715         test_mkdir -p $DIR/$tdir
3716         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3717                         cp -p multiop $DIR/$tdir/multiop
3718         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3719                         return 1
3720         MULTIOP_PID=$!
3721         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3722         kill -USR1 $MULTIOP_PID || return 2
3723         wait $MULTIOP_PID || return 3
3724         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3725 }
3726 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3727
3728 test_43b() {
3729         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3730         test_mkdir -p $DIR/$tdir
3731         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3732                         cp -p multiop $DIR/$tdir/multiop
3733         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3734                         return 1
3735         MULTIOP_PID=$!
3736         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3737         kill -USR1 $MULTIOP_PID || return 2
3738         wait $MULTIOP_PID || return 3
3739         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3740 }
3741 run_test 43b "truncate of file being executed should return -ETXTBSY"
3742
3743 test_43c() {
3744         local testdir="$DIR/$tdir"
3745         test_mkdir -p $DIR/$tdir
3746         cp $SHELL $testdir/
3747         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3748                 ( cd $testdir && md5sum -c)
3749 }
3750 run_test 43c "md5sum of copy into lustre========================"
3751
3752 test_44() {
3753         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3754         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3755         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3756 }
3757 run_test 44 "zero length read from a sparse stripe ============="
3758
3759 test_44a() {
3760         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3761                 awk '{ print $2 }')
3762         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3763         [[ $nstripe -gt $OSTCOUNT ]] &&
3764             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3765             return
3766         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3767                 awk '{ print $2 }')
3768         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3769                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3770                         awk '{ print $2 }')
3771         fi
3772
3773         OFFSETS="0 $((stride/2)) $((stride-1))"
3774         for offset in $OFFSETS; do
3775                 for i in $(seq 0 $((nstripe-1))); do
3776                         local GLOBALOFFSETS=""
3777                         # size in Bytes
3778                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3779                         local myfn=$DIR/d44a-$size
3780                         echo "--------writing $myfn at $size"
3781                         ll_sparseness_write $myfn $size ||
3782                                 error "ll_sparseness_write"
3783                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3784                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3785                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3786
3787                         for j in $(seq 0 $((nstripe-1))); do
3788                                 # size in Bytes
3789                                 size=$((((j + $nstripe )*$stride + $offset)))
3790                                 ll_sparseness_write $myfn $size ||
3791                                         error "ll_sparseness_write"
3792                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3793                         done
3794                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3795                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3796                         rm -f $myfn
3797                 done
3798         done
3799 }
3800 run_test 44a "test sparse pwrite ==============================="
3801
3802 dirty_osc_total() {
3803         tot=0
3804         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3805                 tot=$(($tot + $d))
3806         done
3807         echo $tot
3808 }
3809 do_dirty_record() {
3810         before=`dirty_osc_total`
3811         echo executing "\"$*\""
3812         eval $*
3813         after=`dirty_osc_total`
3814         echo before $before, after $after
3815 }
3816 test_45() {
3817         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3818         f="$DIR/f45"
3819         # Obtain grants from OST if it supports it
3820         echo blah > ${f}_grant
3821         stop_writeback
3822         sync
3823         do_dirty_record "echo blah > $f"
3824         [[ $before -eq $after ]] && error "write wasn't cached"
3825         do_dirty_record "> $f"
3826         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3827         do_dirty_record "echo blah > $f"
3828         [[ $before -eq $after ]] && error "write wasn't cached"
3829         do_dirty_record "sync"
3830         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3831         do_dirty_record "echo blah > $f"
3832         [[ $before -eq $after ]] && error "write wasn't cached"
3833         do_dirty_record "cancel_lru_locks osc"
3834         [[ $before -gt $after ]] ||
3835                 error "lock cancellation didn't lower dirty count"
3836         start_writeback
3837 }
3838 run_test 45 "osc io page accounting ============================"
3839
3840 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3841 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3842 # objects offset and an assert hit when an rpc was built with 1023's mapped
3843 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3844 test_46() {
3845         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3846         f="$DIR/f46"
3847         stop_writeback
3848         sync
3849         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3850         sync
3851         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3852         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3853         sync
3854         start_writeback
3855 }
3856 run_test 46 "dirtying a previously written page ================"
3857
3858 # test_47 is removed "Device nodes check" is moved to test_28
3859
3860 test_48a() { # bug 2399
3861         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
3862         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
3863                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly" &&
3864                 return
3865         test_mkdir $DIR/$tdir
3866         cd $DIR/$tdir
3867         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
3868         test_mkdir $DIR/$tdir || error "recreate directory failed"
3869         touch foo || error "'touch foo' failed after recreating cwd"
3870         test_mkdir bar || error "'mkdir foo' failed after recreating cwd"
3871         touch .foo || error "'touch .foo' failed after recreating cwd"
3872         test_mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
3873         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3874         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3875         cd . || error "'cd .' failed after recreating cwd"
3876         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3877         rmdir . && error "'rmdir .' worked after recreating cwd"
3878         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3879         cd .. || error "'cd ..' failed after recreating cwd"
3880 }
3881 run_test 48a "Access renamed working dir (should return errors)="
3882
3883 test_48b() { # bug 2399
3884         rm -rf $DIR/$tdir
3885         test_mkdir $DIR/$tdir
3886         cd $DIR/$tdir
3887         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3888         touch foo && error "'touch foo' worked after removing cwd"
3889         test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3890         touch .foo && error "'touch .foo' worked after removing cwd"
3891         test_mkdir .foo && error "'mkdir .foo' worked after removing cwd"
3892         ls . > /dev/null && error "'ls .' worked after removing cwd"
3893         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3894         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3895         test_mkdir . && error "'mkdir .' worked after removing cwd"
3896         rmdir . && error "'rmdir .' worked after removing cwd"
3897         ln -s . foo && error "'ln -s .' worked after removing cwd"
3898         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3899 }
3900 run_test 48b "Access removed working dir (should return errors)="
3901
3902 test_48c() { # bug 2350
3903         #lctl set_param debug=-1
3904         #set -vx
3905         rm -rf $DIR/$tdir
3906         test_mkdir -p $DIR/$tdir/dir
3907         cd $DIR/$tdir/dir
3908         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3909         $TRACE touch foo && error "touch foo worked after removing cwd"
3910         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3911         touch .foo && error "touch .foo worked after removing cwd"
3912         test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3913         $TRACE ls . && error "'ls .' worked after removing cwd"
3914         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3915         is_patchless || ( $TRACE cd . &&
3916                         error "'cd .' worked after removing cwd" )
3917         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3918         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3919         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3920         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3921 }
3922 run_test 48c "Access removed working subdir (should return errors)"
3923
3924 test_48d() { # bug 2350
3925         #lctl set_param debug=-1
3926         #set -vx
3927         rm -rf $DIR/$tdir
3928         test_mkdir -p $DIR/$tdir/dir
3929         cd $DIR/$tdir/dir
3930         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3931         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3932         $TRACE touch foo && error "'touch foo' worked after removing parent"
3933         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3934         touch .foo && error "'touch .foo' worked after removing parent"
3935         test_mkdir .foo && error "mkdir .foo worked after removing parent"
3936         $TRACE ls . && error "'ls .' worked after removing parent"
3937         $TRACE ls .. && error "'ls ..' worked after removing parent"
3938         is_patchless || ( $TRACE cd . &&
3939                         error "'cd .' worked after recreate parent" )
3940         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3941         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3942         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3943         is_patchless || ( $TRACE cd .. &&
3944                         error "'cd ..' worked after removing parent" || true )
3945 }
3946 run_test 48d "Access removed parent subdir (should return errors)"
3947
3948 test_48e() { # bug 4134
3949         #lctl set_param debug=-1
3950         #set -vx
3951         rm -rf $DIR/$tdir
3952         test_mkdir -p $DIR/$tdir/dir
3953         cd $DIR/$tdir/dir
3954         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3955         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3956         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3957         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3958         # On a buggy kernel addition of "touch foo" after cd .. will
3959         # produce kernel oops in lookup_hash_it
3960         touch ../foo && error "'cd ..' worked after recreate parent"
3961         cd $DIR
3962         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3963 }
3964 run_test 48e "Access to recreated parent subdir (should return errors)"
3965
3966 test_49() { # LU-1030
3967         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3968         # get ost1 size - lustre-OST0000
3969         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3970                 awk '{ print $4 }')
3971         # write 800M at maximum
3972         [[ $ost1_size -lt 2 ]] && ost1_size=2
3973         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3974
3975         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3976         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3977         local dd_pid=$!
3978
3979         # change max_pages_per_rpc while writing the file
3980         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3981         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3982         # loop until dd process exits
3983         while ps ax -opid | grep -wq $dd_pid; do
3984                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3985                 sleep $((RANDOM % 5 + 1))
3986         done
3987         # restore original max_pages_per_rpc
3988         $LCTL set_param $osc1_mppc=$orig_mppc
3989         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3990 }
3991 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3992
3993 test_50() {
3994         # bug 1485
3995         test_mkdir $DIR/$tdir
3996         cd $DIR/$tdir
3997         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3998 }
3999 run_test 50 "special situations: /proc symlinks  ==============="
4000
4001 test_51a() {    # was test_51
4002         # bug 1516 - create an empty entry right after ".." then split dir
4003         test_mkdir -c1 $DIR/$tdir
4004         touch $DIR/$tdir/foo
4005         $MCREATE $DIR/$tdir/bar
4006         rm $DIR/$tdir/foo
4007         createmany -m $DIR/$tdir/longfile 201
4008         FNUM=202
4009         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
4010                 $MCREATE $DIR/$tdir/longfile$FNUM
4011                 FNUM=$(($FNUM + 1))
4012                 echo -n "+"
4013         done
4014         echo
4015         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
4016 }
4017 run_test 51a "special situations: split htree with empty entry =="
4018
4019 export NUMTEST=70000
4020 test_51b() {
4021         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4022         local BASE=$DIR/d${base}.${TESTSUITE}
4023
4024         # cleanup the directory
4025         rm -fr $BASE
4026
4027         test_mkdir -p -c1 $BASE
4028
4029         $LFS df
4030         $LFS df -i
4031         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
4032         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
4033         [[ $numfree -lt 21000 ]] &&
4034                 skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
4035                 return
4036
4037         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
4038                 echo "reduced count to $NUMTEST due to inodes on MDT$mdtidx"
4039
4040         # need to check free space for the directories as well
4041         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
4042         numfree=$((blkfree / 4))
4043         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$((numfree - 50)) &&
4044                 echo "reduced count to $NUMTEST due to blocks on MDT$mdtidx"
4045
4046         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
4047         {
4048                 $LFS df
4049                 $LFS df -i
4050                 echo "failed" > $BASE/fnum
4051                 error "failed to create $NUMTEST subdirs in MDT$mdtidx:$BASE"
4052         }
4053 }
4054 run_test 51b "exceed 64k subdirectory nlink limit"
4055
4056 test_51ba() { # LU-993
4057         local BASE=$DIR/d${base}.${TESTSUITE}
4058         # unlink all but 100 subdirectories, then check it still works
4059         local LEFT=100
4060         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
4061
4062         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
4063         local DELETE=$((NUMTEST - LEFT))
4064
4065         # continue on to run this test even if 51b didn't finish,
4066         # just to delete the many subdirectories created.
4067         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
4068
4069         # for ldiskfs the nlink count should be 1, but this is OSD specific
4070         # and so this is listed for informational purposes only
4071         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
4072         unlinkmany -d $BASE/d $DELETE
4073         RC=$?
4074
4075         if [ $RC -ne 0 ]; then
4076                 if [ "$NUMPREV" == "failed" ]; then
4077                         skip "previous setup failed"
4078                         return 0
4079                 else
4080                         error "unlink of first $DELETE subdirs failed"
4081                         return $RC
4082                 fi
4083         fi
4084
4085         echo "nlink between: $(stat -c %h $BASE)"
4086         # trim the first line of ls output
4087         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
4088         [ $FOUND -ne $LEFT ] &&
4089                 error "can't find subdirs: found only $FOUND/$LEFT"
4090
4091         unlinkmany -d $BASE/d $DELETE $LEFT ||
4092                 error "unlink of second $LEFT subdirs failed"
4093         # regardless of whether the backing filesystem tracks nlink accurately
4094         # or not, the nlink count shouldn't be more than "." and ".." here
4095         local AFTER=$(stat -c %h $BASE)
4096         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
4097                 echo "nlink after: $AFTER"
4098 }
4099 run_test 51ba "verify nlink for many subdirectory cleanup"
4100
4101 test_51d() {
4102         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4103         [[ $OSTCOUNT -lt 3 ]] &&
4104                 skip_env "skipping test with few OSTs" && return
4105         test_mkdir -p $DIR/$tdir
4106         createmany -o $DIR/$tdir/t- 1000
4107         $GETSTRIPE $DIR/$tdir > $TMP/files
4108         for N in $(seq 0 $((OSTCOUNT - 1))); do
4109                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4110                         END { printf("%0.0f", objs) }' $TMP/files)
4111                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
4112                         '($1 == '$N') { objs += 1 } \
4113                         END { printf("%0.0f", objs) }')
4114                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4115         done
4116         unlinkmany $DIR/$tdir/t- 1000
4117
4118         NLAST=0
4119         for N in $(seq 1 $((OSTCOUNT - 1))); do
4120                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4121                         error "OST $N has less objects vs OST $NLAST" \
4122                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4123                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4124                         error "OST $N has less objects vs OST $NLAST" \
4125                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4126
4127                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4128                         error "OST $N has less #0 objects vs OST $NLAST" \
4129                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4130                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4131                         error "OST $N has less #0 objects vs OST $NLAST" \
4132                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4133                 NLAST=$N
4134         done
4135 }
4136 run_test 51d "check object distribution ===================="
4137
4138 test_51e() {
4139         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4140                 skip "Only applicable to ldiskfs-based MDTs"
4141                 return
4142         fi
4143
4144         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4145         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4146
4147         touch $DIR/$tdir/d0/foo
4148         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4149                 error "file exceed 65000 nlink limit!"
4150         unlinkmany $DIR/$tdir/d0/f- 65001
4151         return 0
4152 }
4153 run_test 51e "check file nlink limit"
4154
4155 test_52a() {
4156         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4157         test_mkdir -p $DIR/$tdir
4158         touch $DIR/$tdir/foo
4159         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4160         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4161         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4162         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4163         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4164                                         error "link worked"
4165         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4166         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4167         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4168                                                      error "lsattr"
4169         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4170         cp -r $DIR/$tdir /tmp/
4171         rm -fr $DIR/$tdir || error "cleanup rm failed"
4172 }
4173 run_test 52a "append-only flag test (should return errors) ====="
4174
4175 test_52b() {
4176         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4177         test_mkdir -p $DIR/$tdir
4178         touch $DIR/$tdir/foo
4179         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4180         cat test > $DIR/$tdir/foo && error "cat test worked"
4181         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4182         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4183         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4184                                         error "link worked"
4185         echo foo >> $DIR/$tdir/foo && error "echo worked"
4186         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4187         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4188         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4189         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4190                                                         error "lsattr"
4191         chattr -i $DIR/$tdir/foo || error "chattr failed"
4192
4193         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4194 }
4195 run_test 52b "immutable flag test (should return errors) ======="
4196
4197 test_53() {
4198         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4199         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4200         remote_ost_nodsh && skip "remote OST with nodsh" && return
4201
4202         local param
4203         local param_seq
4204         local ostname
4205         local mds_last
4206         local mds_last_seq
4207         local ost_last
4208         local ost_last_seq
4209         local ost_last_id
4210         local ostnum
4211         local node
4212         local found=false
4213         local support_last_seq=true
4214
4215         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4216                 support_last_seq=false
4217
4218         # only test MDT0000
4219         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4220         local value
4221         for value in $(do_facet $SINGLEMDS \
4222                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4223                 param=$(echo ${value[0]} | cut -d "=" -f1)
4224                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4225
4226                 if $support_last_seq; then
4227                         param_seq=$(echo $param |
4228                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4229                         mds_last_seq=$(do_facet $SINGLEMDS \
4230                                        $LCTL get_param -n $param_seq)
4231                 fi
4232                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4233
4234                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4235                 node=$(facet_active_host ost$((ostnum+1)))
4236                 param="obdfilter.$ostname.last_id"
4237                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4238                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4239                         ost_last_id=$ost_last
4240
4241                         if $support_last_seq; then
4242                                 ost_last_id=$(echo $ost_last |
4243                                               awk -F':' '{print $2}' |
4244                                               sed -e "s/^0x//g")
4245                                 ost_last_seq=$(echo $ost_last |
4246                                                awk -F':' '{print $1}')
4247                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4248                         fi
4249
4250                         if [[ $ost_last_id != $mds_last ]]; then
4251                                 error "$ost_last_id != $mds_last"
4252                         else
4253                                 found=true
4254                                 break
4255                         fi
4256                 done
4257         done
4258         $found || error "can not match last_seq/last_id for $mdtosc"
4259         return 0
4260 }
4261 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4262
4263 test_54a() {
4264         $SOCKETSERVER $DIR/socket ||
4265                 error "$SOCKETSERVER $DIR/socket failed: $?"
4266         $SOCKETCLIENT $DIR/socket ||
4267                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4268         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4269 }
4270 run_test 54a "unix domain socket test =========================="
4271
4272 test_54b() {
4273         f="$DIR/f54b"
4274         mknod $f c 1 3
4275         chmod 0666 $f
4276         dd if=/dev/zero of=$f bs=$(page_size) count=1
4277 }
4278 run_test 54b "char device works in lustre ======================"
4279
4280 find_loop_dev() {
4281         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4282         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4283         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4284
4285         for i in $(seq 3 7); do
4286                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4287                 LOOPDEV=$LOOPBASE$i
4288                 LOOPNUM=$i
4289                 break
4290         done
4291 }
4292
4293 cleanup_54c() {
4294         loopdev="$DIR/loop54c"
4295
4296         trap 0
4297         $UMOUNT -d $DIR/$tdir || rc=$?
4298         losetup -d $loopdev || true
4299         losetup -d $LOOPDEV || true
4300         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4301         return $rc
4302 }
4303
4304 test_54c() {
4305         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4306         loopdev="$DIR/loop54c"
4307
4308         find_loop_dev
4309         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4310         trap cleanup_54c EXIT
4311         mknod $loopdev b 7 $LOOPNUM
4312         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4313         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4314         losetup $loopdev $DIR/$tfile ||
4315                 error "can't set up $loopdev for $DIR/$tfile"
4316         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4317         test_mkdir -p $DIR/$tdir
4318         mount -t ext2 $loopdev $DIR/$tdir ||
4319                 error "error mounting $loopdev on $DIR/$tdir"
4320         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4321                 error "dd write"
4322         df $DIR/$tdir
4323         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4324                 error "dd read"
4325         cleanup_54c
4326 }
4327 run_test 54c "block device works in lustre ====================="
4328
4329 test_54d() {
4330         f="$DIR/f54d"
4331         string="aaaaaa"
4332         mknod $f p
4333         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4334 }
4335 run_test 54d "fifo device works in lustre ======================"
4336
4337 test_54e() {
4338         f="$DIR/f54e"
4339         string="aaaaaa"
4340         cp -aL /dev/console $f
4341         echo $string > $f || error "echo $string to $f failed"
4342 }
4343 run_test 54e "console/tty device works in lustre ======================"
4344
4345 #The test_55 used to be iopen test and it was removed by bz#24037.
4346 #run_test 55 "check iopen_connect_dentry() ======================"
4347
4348 test_56a() {    # was test_56
4349         rm -rf $DIR/$tdir
4350         $SETSTRIPE -d $DIR
4351         test_mkdir -p $DIR/$tdir/dir
4352         NUMFILES=3
4353         NUMFILESx2=$(($NUMFILES * 2))
4354         for i in $(seq 1 $NUMFILES); do
4355                 touch $DIR/$tdir/file$i
4356                 touch $DIR/$tdir/dir/file$i
4357         done
4358
4359         # test lfs getstripe with --recursive
4360         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4361         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4362                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4363         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4364         [[ $FILENUM -eq $NUMFILES ]] ||
4365                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4366         echo "$GETSTRIPE --recursive passed."
4367
4368         # test lfs getstripe with file instead of dir
4369         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4370         [[ $FILENUM -eq 1 ]] ||
4371                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4372         echo "$GETSTRIPE file1 passed."
4373
4374         #test lfs getstripe with --verbose
4375         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4376                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4377                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4378         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4379                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4380         echo "$GETSTRIPE --verbose passed."
4381
4382         #test lfs getstripe with --obd
4383         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4384                 grep -q "unknown obduuid" ||
4385                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4386
4387         [[ $OSTCOUNT -lt 2 ]] &&
4388                 skip_env "skipping other $GETSTRIPE --obd test" && return
4389
4390         OSTIDX=1
4391         OBDUUID=$(ostuuid_from_index $OSTIDX)
4392         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4393         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4394         [[ $FOUND -eq $FILENUM ]] ||
4395                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4396         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4397                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4398                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4399                 error "$GETSTRIPE --obd: should not show file on other obd"
4400         echo "$GETSTRIPE --obd passed"
4401 }
4402 run_test 56a "check $GETSTRIPE"
4403
4404 NUMFILES=3
4405 NUMDIRS=3
4406 setup_56() {
4407         local LOCAL_NUMFILES="$1"
4408         local LOCAL_NUMDIRS="$2"
4409         local MKDIR_PARAMS="$3"
4410         local DIR_STRIPE_PARAMS="$4"
4411
4412         if [ ! -d "$TDIR" ] ; then
4413                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4414                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4415                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4416                         touch $TDIR/file$i
4417                 done
4418                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4419                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4420                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4421                                 touch $TDIR/dir$i/file$j
4422                         done
4423                 done
4424         fi
4425 }
4426
4427 setup_56_special() {
4428         LOCAL_NUMFILES=$1
4429         LOCAL_NUMDIRS=$2
4430         setup_56 $1 $2
4431         if [ ! -e "$TDIR/loop1b" ] ; then
4432                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4433                         mknod $TDIR/loop${i}b b 7 $i
4434                         mknod $TDIR/null${i}c c 1 3
4435                         ln -s $TDIR/file1 $TDIR/link${i}l
4436                 done
4437                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4438                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4439                         mknod $TDIR/dir$i/null${i}c c 1 3
4440                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4441                 done
4442         fi
4443 }
4444
4445 test_56g() {
4446         $SETSTRIPE -d $DIR
4447
4448         TDIR=$DIR/${tdir}g
4449         setup_56 $NUMFILES $NUMDIRS
4450
4451         EXPECTED=$(($NUMDIRS + 2))
4452         # test lfs find with -name
4453         for i in $(seq 1 $NUMFILES) ; do
4454                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4455                 [ $NUMS -eq $EXPECTED ] ||
4456                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4457                               "found $NUMS, expected $EXPECTED"
4458         done
4459 }
4460 run_test 56g "check lfs find -name ============================="
4461
4462 test_56h() {
4463         $SETSTRIPE -d $DIR
4464
4465         TDIR=$DIR/${tdir}g
4466         setup_56 $NUMFILES $NUMDIRS
4467
4468         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4469         # test lfs find with ! -name
4470         for i in $(seq 1 $NUMFILES) ; do
4471                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4472                 [ $NUMS -eq $EXPECTED ] ||
4473                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4474                               "found $NUMS, expected $EXPECTED"
4475         done
4476 }
4477 run_test 56h "check lfs find ! -name ============================="
4478
4479 test_56i() {
4480        tdir=${tdir}i
4481        test_mkdir -p $DIR/$tdir
4482        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4483        CMD="$LFIND -ost $UUID $DIR/$tdir"
4484        OUT=$($CMD)
4485        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4486 }
4487 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4488
4489 test_56j() {
4490         TDIR=$DIR/${tdir}g
4491         setup_56_special $NUMFILES $NUMDIRS
4492
4493         EXPECTED=$((NUMDIRS + 1))
4494         CMD="$LFIND -type d $TDIR"
4495         NUMS=$($CMD | wc -l)
4496         [ $NUMS -eq $EXPECTED ] ||
4497                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4498 }
4499 run_test 56j "check lfs find -type d ============================="
4500
4501 test_56k() {
4502         TDIR=$DIR/${tdir}g
4503         setup_56_special $NUMFILES $NUMDIRS
4504
4505         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4506         CMD="$LFIND -type f $TDIR"
4507         NUMS=$($CMD | wc -l)
4508         [ $NUMS -eq $EXPECTED ] ||
4509                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4510 }
4511 run_test 56k "check lfs find -type f ============================="
4512
4513 test_56l() {
4514         TDIR=$DIR/${tdir}g
4515         setup_56_special $NUMFILES $NUMDIRS
4516
4517         EXPECTED=$((NUMDIRS + NUMFILES))
4518         CMD="$LFIND -type b $TDIR"
4519         NUMS=$($CMD | wc -l)
4520         [ $NUMS -eq $EXPECTED ] ||
4521                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4522 }
4523 run_test 56l "check lfs find -type b ============================="
4524
4525 test_56m() {
4526         TDIR=$DIR/${tdir}g
4527         setup_56_special $NUMFILES $NUMDIRS
4528
4529         EXPECTED=$((NUMDIRS + NUMFILES))
4530         CMD="$LFIND -type c $TDIR"
4531         NUMS=$($CMD | wc -l)
4532         [ $NUMS -eq $EXPECTED ] ||
4533                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4534 }
4535 run_test 56m "check lfs find -type c ============================="
4536
4537 test_56n() {
4538         TDIR=$DIR/${tdir}g
4539         setup_56_special $NUMFILES $NUMDIRS
4540
4541         EXPECTED=$((NUMDIRS + NUMFILES))
4542         CMD="$LFIND -type l $TDIR"
4543         NUMS=$($CMD | wc -l)
4544         [ $NUMS -eq $EXPECTED ] ||
4545                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4546 }
4547 run_test 56n "check lfs find -type l ============================="
4548
4549 test_56o() {
4550         TDIR=$DIR/${tdir}o
4551         setup_56 $NUMFILES $NUMDIRS
4552         utime $TDIR/file1 > /dev/null || error "utime (1)"
4553         utime $TDIR/file2 > /dev/null || error "utime (2)"
4554         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4555         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4556         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4557         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4558
4559         EXPECTED=4
4560         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4561         [ $NUMS -eq $EXPECTED ] || \
4562                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4563
4564         EXPECTED=12
4565         CMD="$LFIND -mtime 0 $TDIR"
4566         NUMS=$($CMD | wc -l)
4567         [ $NUMS -eq $EXPECTED ] ||
4568                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4569 }
4570 run_test 56o "check lfs find -mtime for old files =========================="
4571
4572 test_56p() {
4573         [ $RUNAS_ID -eq $UID ] &&
4574                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4575
4576         TDIR=$DIR/${tdir}p
4577         setup_56 $NUMFILES $NUMDIRS
4578
4579         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4580         EXPECTED=$NUMFILES
4581         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4582         NUMS=$($CMD | wc -l)
4583         [ $NUMS -eq $EXPECTED ] || \
4584                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4585
4586         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4587         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4588         NUMS=$($CMD | wc -l)
4589         [ $NUMS -eq $EXPECTED ] || \
4590                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4591 }
4592 run_test 56p "check lfs find -uid and ! -uid ==============================="
4593
4594 test_56q() {
4595         [ $RUNAS_ID -eq $UID ] &&
4596                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4597
4598         TDIR=$DIR/${tdir}q
4599         setup_56 $NUMFILES $NUMDIRS
4600
4601         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4602
4603         EXPECTED=$NUMFILES
4604         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4605         NUMS=$($CMD | wc -l)
4606         [ $NUMS -eq $EXPECTED ] ||
4607                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4608
4609         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4610         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4611         NUMS=$($CMD | wc -l)
4612         [ $NUMS -eq $EXPECTED ] ||
4613                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4614 }
4615 run_test 56q "check lfs find -gid and ! -gid ==============================="
4616
4617 test_56r() {
4618         TDIR=$DIR/${tdir}r
4619         setup_56 $NUMFILES $NUMDIRS
4620
4621         EXPECTED=12
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         EXPECTED=0
4627         CMD="$LFIND ! -size 0 -type f $TDIR"
4628         NUMS=$($CMD | wc -l)
4629         [ $NUMS -eq $EXPECTED ] ||
4630                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4631         echo "test" > $TDIR/$tfile
4632         echo "test2" > $TDIR/$tfile.2 && sync
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=1
4639         CMD="$LFIND -size +5 -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 +0 -type f $TDIR"
4645         NUMS=$($CMD | wc -l)
4646         [ $NUMS -eq $EXPECTED ] ||
4647                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4648         EXPECTED=2
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         EXPECTED=12
4654         CMD="$LFIND -size -5 -type f $TDIR"
4655         NUMS=$($CMD | wc -l)
4656         [ $NUMS -eq $EXPECTED ] ||
4657                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4658 }
4659 run_test 56r "check lfs find -size works =========================="
4660
4661 test_56s() { # LU-611
4662         TDIR=$DIR/${tdir}s
4663         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4664
4665         if [[ $OSTCOUNT -gt 1 ]]; then
4666                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4667                 ONESTRIPE=4
4668                 EXTRA=4
4669         else
4670                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4671                 EXTRA=0
4672         fi
4673
4674         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4675         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4676         NUMS=$($CMD | wc -l)
4677         [ $NUMS -eq $EXPECTED ] || {
4678                 $GETSTRIPE -R $TDIR
4679                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4680         }
4681
4682         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4683         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4684         NUMS=$($CMD | wc -l)
4685         [ $NUMS -eq $EXPECTED ] || {
4686                 $GETSTRIPE -R $TDIR
4687                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4688         }
4689
4690         EXPECTED=$ONESTRIPE
4691         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4692         NUMS=$($CMD | wc -l)
4693         [ $NUMS -eq $EXPECTED ] || {
4694                 $GETSTRIPE -R $TDIR
4695                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4696         }
4697
4698         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4699         NUMS=$($CMD | wc -l)
4700         [ $NUMS -eq $EXPECTED ] || {
4701                 $GETSTRIPE -R $TDIR
4702                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4703         }
4704
4705         EXPECTED=0
4706         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4707         NUMS=$($CMD | wc -l)
4708         [ $NUMS -eq $EXPECTED ] || {
4709                 $GETSTRIPE -R $TDIR
4710                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4711         }
4712 }
4713 run_test 56s "check lfs find -stripe-count works"
4714
4715 test_56t() { # LU-611
4716         TDIR=$DIR/${tdir}t
4717         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4718
4719         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4720
4721         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4722         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4723         NUMS=$($CMD | wc -l)
4724         [ $NUMS -eq $EXPECTED ] ||
4725                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4726
4727         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4728         NUMS=$($CMD | wc -l)
4729         [ $NUMS -eq $EXPECTED ] ||
4730                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4731
4732         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4733         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4734         NUMS=$($CMD | wc -l)
4735         [ $NUMS -eq $EXPECTED ] ||
4736                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4737
4738         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4739         NUMS=$($CMD | wc -l)
4740         [ $NUMS -eq $EXPECTED ] ||
4741                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4742
4743         EXPECTED=4
4744         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4745         NUMS=$($CMD | wc -l)
4746         [ $NUMS -eq $EXPECTED ] ||
4747                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4748
4749         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4750         NUMS=$($CMD | wc -l)
4751         [ $NUMS -eq $EXPECTED ] ||
4752                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4753
4754         EXPECTED=0
4755         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4756         NUMS=$($CMD | wc -l)
4757         [ $NUMS -eq $EXPECTED ] ||
4758                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4759 }
4760 run_test 56t "check lfs find -stripe-size works"
4761
4762 test_56u() { # LU-611
4763         TDIR=$DIR/${tdir}u
4764         setup_56 $NUMFILES $NUMDIRS "-i 0"
4765
4766         if [[ $OSTCOUNT -gt 1 ]]; then
4767                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4768                 ONESTRIPE=4
4769         else
4770                 ONESTRIPE=0
4771         fi
4772
4773         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4774         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4775         NUMS=$($CMD | wc -l)
4776         [ $NUMS -eq $EXPECTED ] ||
4777                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4778
4779         EXPECTED=$ONESTRIPE
4780         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4781         NUMS=$($CMD | wc -l)
4782         [ $NUMS -eq $EXPECTED ] ||
4783                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4784
4785         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4786         NUMS=$($CMD | wc -l)
4787         [ $NUMS -eq $EXPECTED ] ||
4788                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4789
4790         EXPECTED=0
4791         # This should produce an error and not return any files
4792         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4793         NUMS=$($CMD 2>/dev/null | wc -l)
4794         [ $NUMS -eq $EXPECTED ] ||
4795                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4796
4797         if [[ $OSTCOUNT -gt 1 ]]; then
4798                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4799                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4800                 NUMS=$($CMD | wc -l)
4801                 [ $NUMS -eq $EXPECTED ] ||
4802                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4803         fi
4804 }
4805 run_test 56u "check lfs find -stripe-index works"
4806
4807 test_56v() {
4808     local MDT_IDX=0
4809
4810     TDIR=$DIR/${tdir}v
4811     rm -rf $TDIR
4812     setup_56 $NUMFILES $NUMDIRS
4813
4814     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4815     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4816
4817     for file in $($LFIND -mdt $UUID $TDIR); do
4818         file_mdt_idx=$($GETSTRIPE -M $file)
4819         [ $file_mdt_idx -eq $MDT_IDX ] ||
4820             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4821     done
4822 }
4823 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4824
4825 test_56w() {
4826         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
4827                 return
4828         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4829         TDIR=$DIR/${tdir}w
4830
4831     rm -rf $TDIR || error "remove $TDIR failed"
4832     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4833
4834     local stripe_size
4835     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4836         error "$GETSTRIPE -S -d $TDIR failed"
4837     stripe_size=${stripe_size%% *}
4838
4839     local file_size=$((stripe_size * OSTCOUNT))
4840     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4841     local required_space=$((file_num * file_size))
4842     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4843     [[ $free_space -le $((required_space / 1024)) ]] &&
4844         skip_env "need at least $required_space bytes free space," \
4845                  "have $free_space kbytes" && return
4846
4847     local dd_bs=65536
4848     local dd_count=$((file_size / dd_bs))
4849
4850     # write data into the files
4851     local i
4852     local j
4853     local file
4854     for i in $(seq 1 $NUMFILES); do
4855         file=$TDIR/file$i
4856         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4857             error "write data into $file failed"
4858     done
4859     for i in $(seq 1 $NUMDIRS); do
4860         for j in $(seq 1 $NUMFILES); do
4861             file=$TDIR/dir$i/file$j
4862             yes | dd bs=$dd_bs count=$dd_count of=$file \
4863                 >/dev/null 2>&1 ||
4864                 error "write data into $file failed"
4865         done
4866     done
4867
4868     local expected=-1
4869     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4870
4871     # lfs_migrate file
4872     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4873     echo "$cmd"
4874     eval $cmd || error "$cmd failed"
4875
4876     check_stripe_count $TDIR/file1 $expected
4877
4878         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
4879         then
4880                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
4881                 # OST 1 if it is on OST 0. This file is small enough to
4882                 # be on only one stripe.
4883                 file=$TDIR/migr_1_ost
4884                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
4885                         error "write data into $file failed"
4886                 local obdidx=$($LFS getstripe -i $file)
4887                 local oldmd5=$(md5sum $file)
4888                 local newobdidx=0
4889                 [[ $obdidx -eq 0 ]] && newobdidx=1
4890                 cmd="$LFS migrate -i $newobdidx $file"
4891                 echo $cmd
4892                 eval $cmd || error "$cmd failed"
4893                 local realobdix=$($LFS getstripe -i $file)
4894                 local newmd5=$(md5sum $file)
4895                 [[ $newobdidx -ne $realobdix ]] &&
4896                         error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
4897                 [[ "$oldmd5" != "$newmd5" ]] &&
4898                         error "md5sum differ: $oldmd5, $newmd5"
4899         fi
4900
4901     # lfs_migrate dir
4902     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4903     echo "$cmd"
4904     eval $cmd || error "$cmd failed"
4905
4906     for j in $(seq 1 $NUMFILES); do
4907         check_stripe_count $TDIR/dir1/file$j $expected
4908     done
4909
4910     # lfs_migrate works with lfs find
4911     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4912          $LFS_MIGRATE -y -c $expected"
4913     echo "$cmd"
4914     eval $cmd || error "$cmd failed"
4915
4916     for i in $(seq 2 $NUMFILES); do
4917         check_stripe_count $TDIR/file$i $expected
4918     done
4919     for i in $(seq 2 $NUMDIRS); do
4920         for j in $(seq 1 $NUMFILES); do
4921             check_stripe_count $TDIR/dir$i/file$j $expected
4922         done
4923     done
4924 }
4925 run_test 56w "check lfs_migrate -c stripe_count works"
4926
4927 test_56x() {
4928         check_swap_layouts_support && return 0
4929         [[ $OSTCOUNT -lt 2 ]] &&
4930                 skip_env "need 2 OST, skipping test" && return
4931
4932         local dir0=$DIR/$tdir/$testnum
4933         test_mkdir -p $dir0 || error "creating dir $dir0"
4934
4935         local ref1=/etc/passwd
4936         local file1=$dir0/file1
4937
4938         $SETSTRIPE -c 2 $file1
4939         cp $ref1 $file1
4940         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4941         stripe=$($GETSTRIPE -c $file1)
4942         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4943         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4944
4945         # clean up
4946         rm -f $file1
4947 }
4948 run_test 56x "lfs migration support"
4949
4950 test_56y() {
4951         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4952                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
4953                 return
4954
4955         local res=""
4956         local dir0=$DIR/$tdir/$testnum
4957         test_mkdir -p $dir0 || error "creating dir $dir0"
4958         local f1=$dir0/file1
4959         local f2=$dir0/file2
4960
4961         touch $f1 || error "creating std file $f1"
4962         $MULTIOP $f2 H2c || error "creating released file $f2"
4963
4964         # a directory can be raid0, so ask only for files
4965         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4966         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4967
4968         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4969         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4970
4971         # only files can be released, so no need to force file search
4972         res=$($LFIND $dir0 -L released)
4973         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4974
4975         res=$($LFIND $dir0 \! -L released)
4976         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4977
4978 }
4979 run_test 56y "lfs find -L raid0|released"
4980
4981 test_56z() { # LU-4824
4982         # This checks to make sure 'lfs find' continues after errors
4983         # There are two classes of errors that should be caught:
4984         # - If multiple paths are provided, all should be searched even if one
4985         #   errors out
4986         # - If errors are encountered during the search, it should not terminate
4987         #   early
4988         local i
4989         test_mkdir $DIR/$tdir
4990         for i in d{0..9}; do
4991                 test_mkdir $DIR/$tdir/$i
4992         done
4993         touch $DIR/$tdir/d{0..9}/$tfile
4994         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
4995                 error "$LFS find did not return an error"
4996         # Make a directory unsearchable. This should NOT be the last entry in
4997         # directory order.  Arbitrarily pick the 6th entry
4998         chmod 700 $($LFS find $DIR/$tdir -type d | sed '6!d')
4999         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
5000         # The user should be able to see 10 directories and 9 files
5001         [ $count == 19 ] || error "$LFS find did not continue after error"
5002 }
5003 run_test 56z "lfs find should continue after an error"
5004
5005 test_56aa() { # LU-5937
5006         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5007
5008         mkdir $DIR/$tdir
5009         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
5010
5011         createmany -o $DIR/$tdir/striped_dir/${tfile}- 1024
5012         local dirs=$(lfs find --size +8k $DIR/$tdir/)
5013
5014         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5015 }
5016 run_test 56aa "lfs find --size under striped dir"
5017
5018 test_57a() {
5019         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5020         # note test will not do anything if MDS is not local
5021         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5022                 skip "Only applicable to ldiskfs-based MDTs"
5023                 return
5024         fi
5025
5026         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5027         local MNTDEV="osd*.*MDT*.mntdev"
5028         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
5029         [ -z "$DEV" ] && error "can't access $MNTDEV"
5030         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
5031                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
5032                         error "can't access $DEV"
5033                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
5034                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
5035                 rm $TMP/t57a.dump
5036         done
5037 }
5038 run_test 57a "verify MDS filesystem created with large inodes =="
5039
5040 test_57b() {
5041         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5042         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5043                 skip "Only applicable to ldiskfs-based MDTs"
5044                 return
5045         fi
5046
5047         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5048         local dir=$DIR/$tdir
5049
5050         local FILECOUNT=100
5051         local FILE1=$dir/f1
5052         local FILEN=$dir/f$FILECOUNT
5053
5054         rm -rf $dir || error "removing $dir"
5055         test_mkdir -p -c1 $dir || error "creating $dir"
5056         local mdtidx=$($LFS getstripe -M $dir)
5057         local mdtname=MDT$(printf %04x $mdtidx)
5058         local facet=mds$((mdtidx + 1))
5059
5060         echo "mcreating $FILECOUNT files"
5061         createmany -m $dir/f 1 $FILECOUNT || \
5062                 error "creating files in $dir"
5063
5064         # verify that files do not have EAs yet
5065         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5066         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5067
5068         sync
5069         sleep 1
5070         df $dir  #make sure we get new statfs data
5071         local MDSFREE=$(do_facet $facet \
5072                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5073         local MDCFREE=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5074         echo "opening files to create objects/EAs"
5075         local FILE
5076         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5077                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5078         done
5079
5080         # verify that files have EAs now
5081         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5082         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5083
5084         sleep 1  #make sure we get new statfs data
5085         df $dir
5086         local MDSFREE2=$(do_facet $facet \
5087                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5088         local MDCFREE2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5089         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5090                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5091                         error "MDC before $MDCFREE != after $MDCFREE2"
5092                 else
5093                         echo "MDC before $MDCFREE != after $MDCFREE2"
5094                         echo "unable to confirm if MDS has large inodes"
5095                 fi
5096         fi
5097         rm -rf $dir
5098 }
5099 run_test 57b "default LOV EAs are stored inside large inodes ==="
5100
5101 test_58() {
5102         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5103         [ -z "$(which wiretest 2>/dev/null)" ] &&
5104                         skip_env "could not find wiretest" && return
5105         wiretest
5106 }
5107 run_test 58 "verify cross-platform wire constants =============="
5108
5109 test_59() {
5110         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5111         echo "touch 130 files"
5112         createmany -o $DIR/f59- 130
5113         echo "rm 130 files"
5114         unlinkmany $DIR/f59- 130
5115         sync
5116         # wait for commitment of removal
5117         wait_delete_completed
5118 }
5119 run_test 59 "verify cancellation of llog records async ========="
5120
5121 TEST60_HEAD="test_60 run $RANDOM"
5122 test_60a() {
5123         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5124         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5125         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5126                 skip_env "missing subtest run-llog.sh" && return
5127         log "$TEST60_HEAD - from kernel mode"
5128         do_facet mgs sh run-llog.sh
5129 }
5130 run_test 60a "llog sanity tests run from kernel module =========="
5131
5132 test_60b() { # bug 6411
5133         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5134         dmesg > $DIR/$tfile
5135         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
5136                                  /llog.test/ {
5137                                          if (marker)
5138                                                  from_marker++
5139                                          from_begin++
5140                                  }
5141                                  END {
5142                                          if (marker)
5143                                                  print from_marker
5144                                          else
5145                                                  print from_begin
5146                                  }"`
5147         [[ $LLOG_COUNT -gt 50 ]] &&
5148                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5149 }
5150 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5151
5152 test_60c() {
5153         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5154         echo "create 5000 files"
5155         createmany -o $DIR/f60c- 5000
5156 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5157         lctl set_param fail_loc=0x80000137
5158         unlinkmany $DIR/f60c- 5000
5159         lctl set_param fail_loc=0
5160 }
5161 run_test 60c "unlink file when mds full"
5162
5163 test_60d() {
5164         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5165         SAVEPRINTK=$(lctl get_param -n printk)
5166
5167         # verify "lctl mark" is even working"
5168         MESSAGE="test message ID $RANDOM $$"
5169         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5170         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5171
5172         lctl set_param printk=0 || error "set lnet.printk failed"
5173         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5174         MESSAGE="new test message ID $RANDOM $$"
5175         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5176         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5177         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5178
5179         lctl set_param -n printk="$SAVEPRINTK"
5180 }
5181 run_test 60d "test printk console message masking"
5182
5183 test_61() {
5184         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5185         f="$DIR/f61"
5186         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5187         cancel_lru_locks osc
5188         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5189         sync
5190 }
5191 run_test 61 "mmap() writes don't make sync hang ================"
5192
5193 # bug 2330 - insufficient obd_match error checking causes LBUG
5194 test_62() {
5195         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5196         f="$DIR/f62"
5197         echo foo > $f
5198         cancel_lru_locks osc
5199         lctl set_param fail_loc=0x405
5200         cat $f && error "cat succeeded, expect -EIO"
5201         lctl set_param fail_loc=0
5202 }
5203 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5204 # match every page all of the time.
5205 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5206
5207 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5208 # Though this test is irrelevant anymore, it helped to reveal some
5209 # other grant bugs (LU-4482), let's keep it.
5210 test_63a() {   # was test_63
5211         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5212         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5213         for i in `seq 10` ; do
5214                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5215                 sleep 5
5216                 kill $!
5217                 sleep 1
5218         done
5219
5220         rm -f $DIR/f63 || true
5221 }
5222 run_test 63a "Verify oig_wait interruption does not crash ======="
5223
5224 # bug 2248 - async write errors didn't return to application on sync
5225 # bug 3677 - async write errors left page locked
5226 test_63b() {
5227         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5228         debugsave
5229         lctl set_param debug=-1
5230
5231         # ensure we have a grant to do async writes
5232         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5233         rm $DIR/$tfile
5234
5235         sync    # sync lest earlier test intercept the fail_loc
5236
5237         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5238         lctl set_param fail_loc=0x80000406
5239         $MULTIOP $DIR/$tfile Owy && \
5240                 error "sync didn't return ENOMEM"
5241         sync; sleep 2; sync     # do a real sync this time to flush page
5242         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5243                 error "locked page left in cache after async error" || true
5244         debugrestore
5245 }
5246 run_test 63b "async write errors should be returned to fsync ==="
5247
5248 test_64a () {
5249         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5250         df $DIR
5251         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5252 }
5253 run_test 64a "verify filter grant calculations (in kernel) ====="
5254
5255 test_64b () {
5256         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5257         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5258 }
5259 run_test 64b "check out-of-space detection on client ==========="
5260
5261 test_64c() {
5262         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5263 }
5264 run_test 64c "verify grant shrink ========================------"
5265
5266 # bug 1414 - set/get directories' stripe info
5267 test_65a() {
5268         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5269         test_mkdir -p $DIR/$tdir
5270         touch $DIR/$tdir/f1
5271         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5272 }
5273 run_test 65a "directory with no stripe info ===================="
5274
5275 test_65b() {
5276         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5277         test_mkdir -p $DIR/$tdir
5278         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5279                                                 error "setstripe"
5280         touch $DIR/$tdir/f2
5281         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5282 }
5283 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
5284
5285 test_65c() {
5286         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5287         if [[ $OSTCOUNT -gt 1 ]]; then
5288                 test_mkdir -p $DIR/$tdir
5289                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5290                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5291                 touch $DIR/$tdir/f3
5292                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5293         fi
5294 }
5295 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
5296
5297 test_65d() {
5298         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5299         test_mkdir -p $DIR/$tdir
5300         if [[ $STRIPECOUNT -le 0 ]]; then
5301                 sc=1
5302         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5303 #LOV_MAX_STRIPE_COUNT is 2000
5304                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5305         else
5306                 sc=$(($STRIPECOUNT - 1))
5307         fi
5308         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5309         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5310         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5311                 error "lverify failed"
5312 }
5313 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
5314
5315 test_65e() {
5316         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5317         test_mkdir -p $DIR/$tdir
5318
5319         $SETSTRIPE $DIR/$tdir || error "setstripe"
5320         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5321                                         error "no stripe info failed"
5322         touch $DIR/$tdir/f6
5323         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5324 }
5325 run_test 65e "directory setstripe defaults ======================="
5326
5327 test_65f() {
5328         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5329         test_mkdir -p $DIR/${tdir}f
5330         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5331 }
5332 run_test 65f "dir setstripe permission (should return error) ==="
5333
5334 test_65g() {
5335         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5336         test_mkdir -p $DIR/$tdir
5337         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5338                                                         error "setstripe"
5339         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5340         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5341                 error "delete default stripe failed"
5342 }
5343 run_test 65g "directory setstripe -d ==========================="
5344
5345 test_65h() {
5346         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5347         test_mkdir -p $DIR/$tdir
5348         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5349                                                         error "setstripe"
5350         test_mkdir -p $DIR/$tdir/dd1
5351         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5352                 error "stripe info inherit failed"
5353 }
5354 run_test 65h "directory stripe info inherit ===================="
5355
5356 test_65i() { # bug6367
5357         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5358         $SETSTRIPE -S 65536 -c -1 $MOUNT
5359 }
5360 run_test 65i "set non-default striping on root directory (bug 6367)="
5361
5362 test_65ia() { # bug12836
5363         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5364         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5365 }
5366 run_test 65ia "getstripe on -1 default directory striping"
5367
5368 test_65ib() { # bug12836
5369         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5370         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5371 }
5372 run_test 65ib "getstripe -v on -1 default directory striping"
5373
5374 test_65ic() { # bug12836
5375         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5376         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5377 }
5378 run_test 65ic "new find on -1 default directory striping"
5379
5380 test_65j() { # bug6367
5381         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5382         sync; sleep 1
5383         # if we aren't already remounting for each test, do so for this test
5384         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5385                 cleanup || error "failed to unmount"
5386                 setup
5387         fi
5388         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5389 }
5390 run_test 65j "set default striping on root directory (bug 6367)="
5391
5392 test_65k() { # bug11679
5393         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5394         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5395         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5396
5397     echo "Check OST status: "
5398     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5399               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5400
5401     for OSC in $MDS_OSCS; do
5402         echo $OSC "is activate"
5403         do_facet $SINGLEMDS lctl --device %$OSC activate
5404     done
5405
5406     mkdir -p $DIR/$tdir
5407     for INACTIVE_OSC in $MDS_OSCS; do
5408         echo "Deactivate: " $INACTIVE_OSC
5409         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5410         for STRIPE_OSC in $MDS_OSCS; do
5411             OST=`osc_to_ost $STRIPE_OSC`
5412             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5413                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5414
5415             [ -f $DIR/$tdir/$IDX ] && continue
5416             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5417             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5418             RC=$?
5419             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5420         done
5421         rm -f $DIR/$tdir/*
5422         echo $INACTIVE_OSC "is Activate."
5423         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5424     done
5425 }
5426 run_test 65k "validate manual striping works properly with deactivated OSCs"
5427
5428 test_65l() { # bug 12836
5429         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5430         test_mkdir -p $DIR/$tdir/test_dir
5431         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5432         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5433 }
5434 run_test 65l "lfs find on -1 stripe dir ========================"
5435
5436 # bug 2543 - update blocks count on client
5437 test_66() {
5438         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5439         COUNT=${COUNT:-8}
5440         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5441         sync; sync_all_data; sync; sync_all_data
5442         cancel_lru_locks osc
5443         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5444         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5445 }
5446 run_test 66 "update inode blocks count on client ==============="
5447
5448 LLOOP=
5449 LLITELOOPLOAD=
5450 cleanup_68() {
5451         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5452         trap 0
5453         if [ ! -z "$LLOOP" ]; then
5454                 if swapon -s | grep -q $LLOOP; then
5455                         swapoff $LLOOP || error "swapoff failed"
5456                 fi
5457
5458                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5459                 rm -f $LLOOP
5460                 unset LLOOP
5461         fi
5462         if [ ! -z "$LLITELOOPLOAD" ]; then
5463                 rmmod llite_lloop
5464                 unset LLITELOOPLOAD
5465         fi
5466         rm -f $DIR/f68*
5467 }
5468
5469 meminfo() {
5470         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5471 }
5472
5473 swap_used() {
5474         swapon -s | awk '($1 == "'$1'") { print $4 }'
5475 }
5476
5477 # test case for lloop driver, basic function
5478 test_68a() {
5479         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5480         [ "$UID" != 0 ] && skip_env "must run as root" && return
5481         llite_lloop_enabled || \
5482                 { skip_env "llite_lloop module disabled" && return; }
5483
5484         trap cleanup_68 EXIT
5485
5486         if ! module_loaded llite_lloop; then
5487                 if load_module llite/llite_lloop; then
5488                         LLITELOOPLOAD=yes
5489                 else
5490                         skip_env "can't find module llite_lloop"
5491                         return
5492                 fi
5493         fi
5494
5495         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5496         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5497         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5498
5499         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5500         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5501
5502         cleanup_68
5503 }
5504 run_test 68a "lloop driver - basic test ========================"
5505
5506 # excercise swapping to lustre by adding a high priority swapfile entry
5507 # and then consuming memory until it is used.
5508 test_68b() {  # was test_68
5509         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5510         [ "$UID" != 0 ] && skip_env "must run as root" && return
5511         lctl get_param -n devices | grep -q obdfilter && \
5512                 skip "local OST" && return
5513
5514         grep -q llite_lloop /proc/modules
5515         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5516
5517         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5518                 skip "can't reliably test swap with TCP" && return
5519
5520         MEMTOTAL=`meminfo MemTotal`
5521         NR_BLOCKS=$((MEMTOTAL>>8))
5522         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5523
5524         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5525         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5526         mkswap $DIR/f68b
5527
5528         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5529
5530         trap cleanup_68 EXIT
5531
5532         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5533
5534         echo "before: `swapon -s | grep $LLOOP`"
5535         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5536         echo "after: `swapon -s | grep $LLOOP`"
5537         SWAPUSED=`swap_used $LLOOP`
5538
5539         cleanup_68
5540
5541         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5542 }
5543 run_test 68b "support swapping to Lustre ========================"
5544
5545 # bug5265, obdfilter oa2dentry return -ENOENT
5546 # #define OBD_FAIL_OST_ENOENT 0x217
5547 test_69() {
5548         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5549         remote_ost_nodsh && skip "remote OST with nodsh" && return
5550
5551         f="$DIR/$tfile"
5552         $SETSTRIPE -c 1 -i 0 $f
5553
5554         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5555
5556         do_facet ost1 lctl set_param fail_loc=0x217
5557         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5558         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5559
5560         do_facet ost1 lctl set_param fail_loc=0
5561         $DIRECTIO write $f 0 2 || error "write error"
5562
5563         cancel_lru_locks osc
5564         $DIRECTIO read $f 0 1 || error "read error"
5565
5566         do_facet ost1 lctl set_param fail_loc=0x217
5567         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5568
5569         do_facet ost1 lctl set_param fail_loc=0
5570         rm -f $f
5571 }
5572 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5573
5574 test_71() {
5575         test_mkdir -p $DIR/$tdir
5576         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
5577         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5578 }
5579 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5580
5581 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5582         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5583         [ "$RUNAS_ID" = "$UID" ] &&
5584                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5585
5586         # Check that testing environment is properly set up. Skip if not
5587         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5588                 skip_env "User $RUNAS_ID does not exist - skipping"
5589                 return 0
5590         }
5591         touch $DIR/$tfile
5592         chmod 777 $DIR/$tfile
5593         chmod ug+s $DIR/$tfile
5594         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5595                 error "$RUNAS dd $DIR/$tfile failed"
5596         # See if we are still setuid/sgid
5597         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5598                 error "S/gid is not dropped on write"
5599         # Now test that MDS is updated too
5600         cancel_lru_locks mdc
5601         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5602                 error "S/gid is not dropped on MDS"
5603         rm -f $DIR/$tfile
5604 }
5605 run_test 72a "Test that remove suid works properly (bug5695) ===="
5606
5607 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5608         local perm
5609
5610         [ "$RUNAS_ID" = "$UID" ] && \
5611                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5612         [ "$RUNAS_ID" -eq 0 ] && \
5613                 skip_env "RUNAS_ID = 0 -- skipping" && return
5614
5615         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5616         # Check that testing environment is properly set up. Skip if not
5617         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5618                 skip_env "User $RUNAS_ID does not exist - skipping"
5619                 return 0
5620         }
5621         touch $DIR/${tfile}-f{g,u}
5622         test_mkdir $DIR/${tfile}-dg
5623         test_mkdir $DIR/${tfile}-du
5624         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5625         chmod g+s $DIR/${tfile}-{f,d}g
5626         chmod u+s $DIR/${tfile}-{f,d}u
5627         for perm in 777 2777 4777; do
5628                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5629                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5630                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5631                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5632         done
5633         true
5634 }
5635 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5636
5637 # bug 3462 - multiple simultaneous MDC requests
5638 test_73() {
5639         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5640         test_mkdir $DIR/d73-1
5641         test_mkdir $DIR/d73-2
5642         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5643         pid1=$!
5644
5645         lctl set_param fail_loc=0x80000129
5646         $MULTIOP $DIR/d73-1/f73-2 Oc &
5647         sleep 1
5648         lctl set_param fail_loc=0
5649
5650         $MULTIOP $DIR/d73-2/f73-3 Oc &
5651         pid3=$!
5652
5653         kill -USR1 $pid1
5654         wait $pid1 || return 1
5655
5656         sleep 25
5657
5658         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5659         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5660         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5661
5662         rm -rf $DIR/d73-*
5663 }
5664 run_test 73 "multiple MDC requests (should not deadlock)"
5665
5666 test_74a() { # bug 6149, 6184
5667         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5668         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5669         #
5670         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5671         # will spin in a tight reconnection loop
5672         touch $DIR/f74a
5673         $LCTL set_param fail_loc=0x8000030e
5674         # get any lock that won't be difficult - lookup works.
5675         ls $DIR/f74a
5676         $LCTL set_param fail_loc=0
5677         rm -f $DIR/f74a
5678         true
5679 }
5680 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5681
5682 test_74b() { # bug 13310
5683         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5684         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5685         #
5686         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5687         # will spin in a tight reconnection loop
5688         $LCTL set_param fail_loc=0x8000030e
5689         # get a "difficult" lock
5690         touch $DIR/f74b
5691         $LCTL set_param fail_loc=0
5692         rm -f $DIR/f74b
5693         true
5694 }
5695 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5696
5697 test_74c() {
5698         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5699         #define OBD_FAIL_LDLM_NEW_LOCK
5700         $LCTL set_param fail_loc=0x319
5701         touch $DIR/$tfile && error "touch successful"
5702         $LCTL set_param fail_loc=0
5703         true
5704 }
5705 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5706
5707 num_inodes() {
5708         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5709 }
5710
5711 get_inode_slab_tunables() {
5712         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5713 }
5714
5715 set_inode_slab_tunables() {
5716         echo "lustre_inode_cache $1" > /proc/slabinfo
5717 }
5718
5719 test_76() { # Now for bug 20433, added originally in bug 1443
5720         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5721         local SLAB_SETTINGS=`get_inode_slab_tunables`
5722         local CPUS=`getconf _NPROCESSORS_ONLN`
5723         # we cannot set limit below 1 which means 1 inode in each
5724         # per-cpu cache is still allowed
5725         set_inode_slab_tunables "1 1 0"
5726         cancel_lru_locks osc
5727         BEFORE_INODES=$(num_inodes)
5728         echo "before inodes: $BEFORE_INODES"
5729         local COUNT=1000
5730         [ "$SLOW" = "no" ] && COUNT=100
5731         for i in $(seq $COUNT); do
5732                 touch $DIR/$tfile
5733                 rm -f $DIR/$tfile
5734         done
5735         cancel_lru_locks osc
5736         AFTER_INODES=$(num_inodes)
5737         echo "after inodes: $AFTER_INODES"
5738         local wait=0
5739         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5740                 sleep 2
5741                 AFTER_INODES=$(num_inodes)
5742                 wait=$((wait+2))
5743                 echo "wait $wait seconds inodes: $AFTER_INODES"
5744                 if [ $wait -gt 30 ]; then
5745                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5746                 fi
5747         done
5748         set_inode_slab_tunables "$SLAB_SETTINGS"
5749 }
5750 run_test 76 "confirm clients recycle inodes properly ===="
5751
5752
5753 export ORIG_CSUM=""
5754 set_checksums()
5755 {
5756         # Note: in sptlrpc modes which enable its own bulk checksum, the
5757         # original crc32_le bulk checksum will be automatically disabled,
5758         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5759         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5760         # In this case set_checksums() will not be no-op, because sptlrpc
5761         # bulk checksum will be enabled all through the test.
5762
5763         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5764         lctl set_param -n osc.*.checksums $1
5765         return 0
5766 }
5767
5768 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5769                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5770 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5771 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5772 set_checksum_type()
5773 {
5774         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5775         log "set checksum type to $1"
5776         return 0
5777 }
5778 F77_TMP=$TMP/f77-temp
5779 F77SZ=8
5780 setup_f77() {
5781         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5782                 error "error writing to $F77_TMP"
5783 }
5784
5785 test_77a() { # bug 10889
5786         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5787         $GSS && skip "could not run with gss" && return
5788         [ ! -f $F77_TMP ] && setup_f77
5789         set_checksums 1
5790         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5791         set_checksums 0
5792         rm -f $DIR/$tfile
5793 }
5794 run_test 77a "normal checksum read/write operation"
5795
5796 test_77b() { # bug 10889
5797         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5798         $GSS && skip "could not run with gss" && return
5799         [ ! -f $F77_TMP ] && setup_f77
5800         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5801         $LCTL set_param fail_loc=0x80000409
5802         set_checksums 1
5803
5804         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5805                 error "dd error: $?"
5806         $LCTL set_param fail_loc=0
5807
5808         for algo in $CKSUM_TYPES; do
5809                 cancel_lru_locks osc
5810                 set_checksum_type $algo
5811                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5812                 $LCTL set_param fail_loc=0x80000408
5813                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5814                 $LCTL set_param fail_loc=0
5815         done
5816         set_checksums 0
5817         set_checksum_type $ORIG_CSUM_TYPE
5818         rm -f $DIR/$tfile
5819 }
5820 run_test 77b "checksum error on client write, read"
5821
5822 test_77d() { # bug 10889
5823         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5824         $GSS && skip "could not run with gss" && return
5825         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5826         $LCTL set_param fail_loc=0x80000409
5827         set_checksums 1
5828         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5829                 error "direct write: rc=$?"
5830         $LCTL set_param fail_loc=0
5831         set_checksums 0
5832
5833         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5834         $LCTL set_param fail_loc=0x80000408
5835         set_checksums 1
5836         cancel_lru_locks osc
5837         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5838                 error "direct read: rc=$?"
5839         $LCTL set_param fail_loc=0
5840         set_checksums 0
5841 }
5842 run_test 77d "checksum error on OST direct write, read"
5843
5844 test_77f() { # bug 10889
5845         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5846         $GSS && skip "could not run with gss" && return
5847         set_checksums 1
5848         for algo in $CKSUM_TYPES; do
5849                 cancel_lru_locks osc
5850                 set_checksum_type $algo
5851                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5852                 $LCTL set_param fail_loc=0x409
5853                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5854                         error "direct write succeeded"
5855                 $LCTL set_param fail_loc=0
5856         done
5857         set_checksum_type $ORIG_CSUM_TYPE
5858         set_checksums 0
5859 }
5860 run_test 77f "repeat checksum error on write (expect error)"
5861
5862 test_77g() { # bug 10889
5863         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5864         $GSS && skip "could not run with gss" && return
5865         remote_ost_nodsh && skip "remote OST with nodsh" && return
5866
5867         [ ! -f $F77_TMP ] && setup_f77
5868
5869         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5870         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5871         do_facet ost1 lctl set_param fail_loc=0x8000021a
5872         set_checksums 1
5873         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5874                 error "write error: rc=$?"
5875         do_facet ost1 lctl set_param fail_loc=0
5876         set_checksums 0
5877
5878         cancel_lru_locks osc
5879         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5880         do_facet ost1 lctl set_param fail_loc=0x8000021b
5881         set_checksums 1
5882         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5883         do_facet ost1 lctl set_param fail_loc=0
5884         set_checksums 0
5885 }
5886 run_test 77g "checksum error on OST write, read"
5887
5888 test_77i() { # bug 13805
5889         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5890         $GSS && skip "could not run with gss" && return
5891         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5892         lctl set_param fail_loc=0x40b
5893         remount_client $MOUNT
5894         lctl set_param fail_loc=0
5895         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5896                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5897                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5898                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5899         done
5900         remount_client $MOUNT
5901 }
5902 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5903
5904 test_77j() { # bug 13805
5905         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5906         $GSS && skip "could not run with gss" && return
5907         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5908         lctl set_param fail_loc=0x40c
5909         remount_client $MOUNT
5910         lctl set_param fail_loc=0
5911         sleep 2 # wait async osc connect to finish
5912         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5913                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5914                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5915                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5916         done
5917         remount_client $MOUNT
5918 }
5919 run_test 77j "client only supporting ADLER32"
5920
5921 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5922 rm -f $F77_TMP
5923 unset F77_TMP
5924
5925 test_78() { # bug 10901
5926         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5927         remote_ost || { skip_env "local OST" && return; }
5928
5929         NSEQ=5
5930         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5931         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5932         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5933         echo "MemTotal: $MEMTOTAL"
5934
5935         # reserve 256MB of memory for the kernel and other running processes,
5936         # and then take 1/2 of the remaining memory for the read/write buffers.
5937         if [ $MEMTOTAL -gt 512 ] ;then
5938                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5939         else
5940                 # for those poor memory-starved high-end clusters...
5941                 MEMTOTAL=$((MEMTOTAL / 2))
5942         fi
5943         echo "Mem to use for directio: $MEMTOTAL"
5944
5945         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
5946         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
5947         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
5948         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
5949                 head -n1)
5950         echo "Smallest OST: $SMALLESTOST"
5951         [[ $SMALLESTOST -lt 10240 ]] &&
5952                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5953
5954         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
5955                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5956
5957         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5958         echo "File size: $F78SIZE"
5959         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5960         for i in $(seq 1 $NSEQ); do
5961                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5962                 echo directIO rdwr round $i of $NSEQ
5963                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5964         done
5965
5966         rm -f $DIR/$tfile
5967 }
5968 run_test 78 "handle large O_DIRECT writes correctly ============"
5969
5970 test_79() { # bug 12743
5971         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5972         wait_delete_completed
5973
5974         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5975         BKFREE=$(calc_osc_kbytes kbytesfree)
5976         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5977
5978         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5979         DFTOTAL=`echo $STRING | cut -d, -f1`
5980         DFUSED=`echo $STRING  | cut -d, -f2`
5981         DFAVAIL=`echo $STRING | cut -d, -f3`
5982         DFFREE=$(($DFTOTAL - $DFUSED))
5983
5984         ALLOWANCE=$((64 * $OSTCOUNT))
5985
5986         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5987            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5988                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5989         fi
5990         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5991            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5992                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5993         fi
5994         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5995            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5996                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5997         fi
5998 }
5999 run_test 79 "df report consistency check ======================="
6000
6001 test_80() { # bug 10718
6002         remote_ost_nodsh && skip "remote OST with nodsh" && return
6003         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6004         # relax strong synchronous semantics for slow backends like ZFS
6005         local soc="obdfilter.*.sync_on_lock_cancel"
6006         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
6007         local hosts=
6008         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
6009                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
6010                           facet_active_host $host; done | sort -u)
6011                 do_nodes $hosts lctl set_param $soc=never
6012         fi
6013
6014         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
6015         sync; sleep 1; sync
6016         local BEFORE=`date +%s`
6017         cancel_lru_locks osc
6018         local AFTER=`date +%s`
6019         local DIFF=$((AFTER-BEFORE))
6020         if [ $DIFF -gt 1 ] ; then
6021                 error "elapsed for 1M@1T = $DIFF"
6022         fi
6023
6024         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
6025
6026         rm -f $DIR/$tfile
6027 }
6028 run_test 80 "Page eviction is equally fast at high offsets too  ===="
6029
6030 test_81a() { # LU-456
6031         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6032         remote_ost_nodsh && skip "remote OST with nodsh" && return
6033         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6034         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
6035         do_facet ost1 lctl set_param fail_loc=0x80000228
6036
6037         # write should trigger a retry and success
6038         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6039         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6040         RC=$?
6041         if [ $RC -ne 0 ] ; then
6042                 error "write should success, but failed for $RC"
6043         fi
6044 }
6045 run_test 81a "OST should retry write when get -ENOSPC ==============="
6046
6047 test_81b() { # LU-456
6048         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6049         remote_ost_nodsh && skip "remote OST with nodsh" && return
6050         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6051         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
6052         do_facet ost1 lctl set_param fail_loc=0x228
6053
6054         # write should retry several times and return -ENOSPC finally
6055         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6056         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6057         RC=$?
6058         ENOSPC=28
6059         if [ $RC -ne $ENOSPC ] ; then
6060                 error "dd should fail for -ENOSPC, but succeed."
6061         fi
6062 }
6063 run_test 81b "OST should return -ENOSPC when retry still fails ======="
6064
6065 test_82() { # LU-1031
6066         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
6067         local gid1=14091995
6068         local gid2=16022000
6069
6070         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
6071         local MULTIPID1=$!
6072         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
6073         local MULTIPID2=$!
6074         kill -USR1 $MULTIPID2
6075         sleep 2
6076         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6077                 error "First grouplock does not block second one"
6078         else
6079                 echo "Second grouplock blocks first one"
6080         fi
6081         kill -USR1 $MULTIPID1
6082         wait $MULTIPID1
6083         wait $MULTIPID2
6084 }
6085 run_test 82 "Basic grouplock test ==============================="
6086
6087 test_99a() {
6088         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6089                 return
6090         test_mkdir -p $DIR/d99cvsroot
6091         chown $RUNAS_ID $DIR/d99cvsroot
6092         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6093         cd $TMP
6094
6095         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6096         cd $oldPWD
6097 }
6098 run_test 99a "cvs init ========================================="
6099
6100 test_99b() {
6101         [ -z "$(which cvs 2>/dev/null)" ] &&
6102                 skip_env "could not find cvs" && return
6103         [ ! -d $DIR/d99cvsroot ] && test_99a
6104         cd /etc/init.d
6105         # some versions of cvs import exit(1) when asked to import links or
6106         # files they can't read.  ignore those files.
6107         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6108                         ! -perm +4 -printf '-I %f\n')
6109         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6110                 d99reposname vtag rtag
6111 }
6112 run_test 99b "cvs import ======================================="
6113
6114 test_99c() {
6115         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6116         [ ! -d $DIR/d99cvsroot ] && test_99b
6117         cd $DIR
6118         test_mkdir -p $DIR/d99reposname
6119         chown $RUNAS_ID $DIR/d99reposname
6120         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6121 }
6122 run_test 99c "cvs checkout ====================================="
6123
6124 test_99d() {
6125         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6126         [ ! -d $DIR/d99cvsroot ] && test_99c
6127         cd $DIR/d99reposname
6128         $RUNAS touch foo99
6129         $RUNAS cvs add -m 'addmsg' foo99
6130 }
6131 run_test 99d "cvs add =========================================="
6132
6133 test_99e() {
6134         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6135         [ ! -d $DIR/d99cvsroot ] && test_99c
6136         cd $DIR/d99reposname
6137         $RUNAS cvs update
6138 }
6139 run_test 99e "cvs update ======================================="
6140
6141 test_99f() {
6142         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6143         [ ! -d $DIR/d99cvsroot ] && test_99d
6144         cd $DIR/d99reposname
6145         $RUNAS cvs commit -m 'nomsg' foo99
6146     rm -fr $DIR/d99cvsroot
6147 }
6148 run_test 99f "cvs commit ======================================="
6149
6150 test_100() {
6151         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6152         [ "$NETTYPE" = tcp ] || \
6153                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
6154                         return ; }
6155
6156         remote_ost_nodsh && skip "remote OST with nodsh" && return
6157         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6158         remote_servers || \
6159                 { skip "useless for local single node setup" && return; }
6160
6161         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6162                 [ "$PROT" != "tcp" ] && continue
6163                 RPORT=$(echo $REMOTE | cut -d: -f2)
6164                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6165
6166                 rc=0
6167                 LPORT=`echo $LOCAL | cut -d: -f2`
6168                 if [ $LPORT -ge 1024 ]; then
6169                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6170                         netstat -tna
6171                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6172                 fi
6173         done
6174         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6175 }
6176 run_test 100 "check local port using privileged port ==========="
6177
6178 function get_named_value()
6179 {
6180     local tag
6181
6182     tag=$1
6183     while read ;do
6184         line=$REPLY
6185         case $line in
6186         $tag*)
6187             echo $line | sed "s/^$tag[ ]*//"
6188             break
6189             ;;
6190         esac
6191     done
6192 }
6193
6194 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6195                    awk '/^max_cached_mb/ { print $2 }')
6196
6197 cleanup_101a() {
6198         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6199         trap 0
6200 }
6201
6202 test_101a() {
6203         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6204         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
6205         local s
6206         local discard
6207         local nreads=10000
6208         local cache_limit=32
6209
6210         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6211         trap cleanup_101a EXIT
6212         $LCTL set_param -n llite.*.read_ahead_stats 0
6213         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6214
6215         #
6216         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6217         #
6218         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6219         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6220
6221         discard=0
6222         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6223                 get_named_value 'read but discarded' | cut -d" " -f1); do
6224                         discard=$(($discard + $s))
6225         done
6226         cleanup_101a
6227
6228         if [[ $(($discard * 10)) -gt $nreads ]]; then
6229                 $LCTL get_param osc.*-osc*.rpc_stats
6230                 $LCTL get_param llite.*.read_ahead_stats
6231                 error "too many ($discard) discarded pages"
6232         fi
6233         rm -f $DIR/$tfile || true
6234 }
6235 run_test 101a "check read-ahead for random reads ================"
6236
6237 setup_test101bc() {
6238         test_mkdir -p $DIR/$tdir
6239         local STRIPE_SIZE=$1
6240         local FILE_LENGTH=$2
6241         STRIPE_OFFSET=0
6242
6243         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6244
6245         local list=$(comma_list $(osts_nodes))
6246         set_osd_param $list '' read_cache_enable 0
6247         set_osd_param $list '' writethrough_cache_enable 0
6248
6249         trap cleanup_test101bc EXIT
6250         # prepare the read-ahead file
6251         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6252
6253         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6254                                 count=$FILE_SIZE_MB 2> /dev/null
6255
6256 }
6257
6258 cleanup_test101bc() {
6259         trap 0
6260         rm -rf $DIR/$tdir
6261         rm -f $DIR/$tfile
6262
6263         local list=$(comma_list $(osts_nodes))
6264         set_osd_param $list '' read_cache_enable 1
6265         set_osd_param $list '' writethrough_cache_enable 1
6266 }
6267
6268 calc_total() {
6269         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6270 }
6271
6272 ra_check_101() {
6273         local READ_SIZE=$1
6274         local STRIPE_SIZE=$2
6275         local FILE_LENGTH=$3
6276         local RA_INC=1048576
6277         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6278         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6279                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6280         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6281                         get_named_value 'read but discarded' |
6282                         cut -d" " -f1 | calc_total)
6283         if [[ $DISCARD -gt $discard_limit ]]; then
6284                 $LCTL get_param llite.*.read_ahead_stats
6285                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6286         else
6287                 echo "Read-ahead success for size ${READ_SIZE}"
6288         fi
6289 }
6290
6291 test_101b() {
6292         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6293         [[ $OSTCOUNT -lt 2 ]] &&
6294                 skip_env "skipping stride IO stride-ahead test" && return
6295         local STRIPE_SIZE=1048576
6296         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6297         if [ $SLOW == "yes" ]; then
6298                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6299         else
6300                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6301         fi
6302
6303         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6304
6305         # prepare the read-ahead file
6306         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6307         cancel_lru_locks osc
6308         for BIDX in 2 4 8 16 32 64 128 256
6309         do
6310                 local BSIZE=$((BIDX*4096))
6311                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6312                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6313                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6314                 $LCTL set_param -n llite.*.read_ahead_stats 0
6315                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6316                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6317                 cancel_lru_locks osc
6318                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6319         done
6320         cleanup_test101bc
6321         true
6322 }
6323 run_test 101b "check stride-io mode read-ahead ================="
6324
6325 test_101c() {
6326         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6327         local STRIPE_SIZE=1048576
6328         local FILE_LENGTH=$((STRIPE_SIZE*100))
6329         local nreads=10000
6330         local osc_rpc_stats
6331
6332         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6333
6334         cancel_lru_locks osc
6335         $LCTL set_param osc.*.rpc_stats 0
6336         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6337         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6338                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6339                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6340                 local size
6341
6342                 if [ $lines -le 20 ]; then
6343                         continue
6344                 fi
6345                 for size in 1 2 4 8; do
6346                         local rpc=$(echo "$stats" |
6347                                     awk '($1 == "'$size':") {print $2; exit; }')
6348                         [ $rpc != 0 ] &&
6349                                 error "Small $((size*4))k read IO $rpc !"
6350                 done
6351                 echo "$osc_rpc_stats check passed!"
6352         done
6353         cleanup_test101bc
6354         true
6355 }
6356 run_test 101c "check stripe_size aligned read-ahead ================="
6357
6358 set_read_ahead() {
6359         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6360         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6361 }
6362
6363 test_101d() {
6364         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6365         local file=$DIR/$tfile
6366         local sz_MB=${FILESIZE_101d:-500}
6367         local ra_MB=${READAHEAD_MB:-40}
6368
6369         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6370         [ $free_MB -lt $sz_MB ] &&
6371                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6372
6373         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6374         $SETSTRIPE -c -1 $file || error "setstripe failed"
6375
6376         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6377         echo Cancel LRU locks on lustre client to flush the client cache
6378         cancel_lru_locks osc
6379
6380         echo Disable read-ahead
6381         local old_READAHEAD=$(set_read_ahead 0)
6382
6383         echo Reading the test file $file with read-ahead disabled
6384         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6385
6386         echo Cancel LRU locks on lustre client to flush the client cache
6387         cancel_lru_locks osc
6388         echo Enable read-ahead with ${ra_MB}MB
6389         set_read_ahead $ra_MB
6390
6391         echo Reading the test file $file with read-ahead enabled
6392         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6393
6394         echo "read-ahead disabled time read $raOFF"
6395         echo "read-ahead enabled  time read $raON"
6396
6397         set_read_ahead $old_READAHEAD
6398         rm -f $file
6399         wait_delete_completed
6400
6401         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6402                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6403 }
6404 run_test 101d "file read with and without read-ahead enabled"
6405
6406 test_101e() {
6407         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6408         local file=$DIR/$tfile
6409         local size_KB=500  #KB
6410         local count=100
6411         local bsize=1024
6412
6413         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6414         local need_KB=$((count * size_KB))
6415         [[ $free_KB -le $need_KB ]] &&
6416                 skip_env "Need free space $need_KB, have $free_KB" && return
6417
6418         echo "Creating $count ${size_KB}K test files"
6419         for ((i = 0; i < $count; i++)); do
6420                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6421         done
6422
6423         echo "Cancel LRU locks on lustre client to flush the client cache"
6424         cancel_lru_locks osc
6425
6426         echo "Reset readahead stats"
6427         $LCTL set_param -n llite.*.read_ahead_stats 0
6428
6429         for ((i = 0; i < $count; i++)); do
6430                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6431         done
6432
6433         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6434                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6435
6436         for ((i = 0; i < $count; i++)); do
6437                 rm -rf $file.$i 2>/dev/null
6438         done
6439
6440         #10000 means 20% reads are missing in readahead
6441         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6442 }
6443 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6444
6445 cleanup_test101f() {
6446     trap 0
6447     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6448     rm -rf $DIR/$tfile 2>/dev/null
6449 }
6450
6451 test_101f() {
6452         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6453     local file=$DIR/$tfile
6454     local nreads=1000
6455
6456     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6457     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6458     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6459     trap cleanup_test101f EXIT
6460
6461     echo Cancel LRU locks on lustre client to flush the client cache
6462     cancel_lru_locks osc
6463
6464     echo Reset readahead stats
6465     $LCTL set_param -n llite.*.read_ahead_stats 0
6466     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6467     # readahead should read in 2M file on second read, so only miss
6468     # 2 pages.
6469     echo Random 4K reads on 2M file for 1000 times
6470     $READS -f $file -s 2097152 -b 4096 -n $nreads
6471
6472     echo checking missing pages
6473     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6474           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6475
6476     [ $miss -lt 3 ] || error "misses too much pages!"
6477     cleanup_test101f
6478 }
6479 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6480
6481 setup_test102() {
6482         test_mkdir -p $DIR/$tdir
6483         chown $RUNAS_ID $DIR/$tdir
6484         STRIPE_SIZE=65536
6485         STRIPE_OFFSET=1
6486         STRIPE_COUNT=$OSTCOUNT
6487         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6488
6489         trap cleanup_test102 EXIT
6490         cd $DIR
6491         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6492         cd $DIR/$tdir
6493         for num in 1 2 3 4; do
6494                 for count in $(seq 1 $STRIPE_COUNT); do
6495                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6496                                 local size=`expr $STRIPE_SIZE \* $num`
6497                                 local file=file"$num-$idx-$count"
6498                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6499                         done
6500                 done
6501         done
6502
6503         cd $DIR
6504         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6505 }
6506
6507 cleanup_test102() {
6508         trap 0
6509         rm -f $TMP/f102.tar
6510         rm -rf $DIR/d0.sanity/d102
6511 }
6512
6513 test_102a() {
6514         local testfile=$DIR/$tfile
6515
6516         touch $testfile
6517
6518         [ "$UID" != 0 ] && skip_env "must run as root" && return
6519         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6520                 skip_env "must have user_xattr" && return
6521
6522         [ -z "$(which setfattr 2>/dev/null)" ] &&
6523                 skip_env "could not find setfattr" && return
6524
6525         echo "set/get xattr..."
6526         setfattr -n trusted.name1 -v value1 $testfile ||
6527                 error "setfattr -n trusted.name1=value1 $testfile failed"
6528         getfattr -n trusted.name1 $testfile 2> /dev/null |
6529           grep "trusted.name1=.value1" ||
6530                 error "$testfile missing trusted.name1=value1"
6531
6532         setfattr -n user.author1 -v author1 $testfile ||
6533                 error "setfattr -n user.author1=author1 $testfile failed"
6534         getfattr -n user.author1 $testfile 2> /dev/null |
6535           grep "user.author1=.author1" ||
6536                 error "$testfile missing trusted.author1=author1"
6537
6538         echo "listxattr..."
6539         setfattr -n trusted.name2 -v value2 $testfile ||
6540                 error "$testfile unable to set trusted.name2"
6541         setfattr -n trusted.name3 -v value3 $testfile ||
6542                 error "$testfile unable to set trusted.name3"
6543         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6544             grep "trusted.name" | wc -l) -eq 3 ] ||
6545                 error "$testfile missing 3 trusted.name xattrs"
6546
6547         setfattr -n user.author2 -v author2 $testfile ||
6548                 error "$testfile unable to set user.author2"
6549         setfattr -n user.author3 -v author3 $testfile ||
6550                 error "$testfile unable to set user.author3"
6551         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6552             grep "user.author" | wc -l) -eq 3 ] ||
6553                 error "$testfile missing 3 user.author xattrs"
6554
6555         echo "remove xattr..."
6556         setfattr -x trusted.name1 $testfile ||
6557                 error "$testfile error deleting trusted.name1"
6558         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6559                 error "$testfile did not delete trusted.name1 xattr"
6560
6561         setfattr -x user.author1 $testfile ||
6562                 error "$testfile error deleting user.author1"
6563         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6564                 error "$testfile did not delete trusted.name1 xattr"
6565
6566         # b10667: setting lustre special xattr be silently discarded
6567         echo "set lustre special xattr ..."
6568         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6569                 error "$testfile allowed setting trusted.lov"
6570 }
6571 run_test 102a "user xattr test =================================="
6572
6573 test_102b() {
6574         [ -z "$(which setfattr 2>/dev/null)" ] &&
6575                 skip_env "could not find setfattr" && return
6576
6577         # b10930: get/set/list trusted.lov xattr
6578         echo "get/set/list trusted.lov xattr ..."
6579         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6580         local testfile=$DIR/$tfile
6581         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6582                 error "setstripe failed"
6583         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6584                 error "getstripe failed"
6585         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6586                 error "can't get trusted.lov from $testfile"
6587
6588         local testfile2=${testfile}2
6589         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6590                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6591
6592         $MCREATE $testfile2
6593         setfattr -n trusted.lov -v $value $testfile2
6594         local stripe_size=$($GETSTRIPE -S $testfile2)
6595         local stripe_count=$($GETSTRIPE -c $testfile2)
6596         [[ $stripe_size -eq 65536 ]] ||
6597                 error "stripe size $stripe_size != 65536"
6598         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6599                 error "stripe count $stripe_count != $STRIPECOUNT"
6600         rm -f $DIR/$tfile
6601 }
6602 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6603
6604 test_102c() {
6605         [ -z "$(which setfattr 2>/dev/null)" ] &&
6606                 skip_env "could not find setfattr" && return
6607
6608         # b10930: get/set/list lustre.lov xattr
6609         echo "get/set/list lustre.lov xattr ..."
6610         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6611         test_mkdir -p $DIR/$tdir
6612         chown $RUNAS_ID $DIR/$tdir
6613         local testfile=$DIR/$tdir/$tfile
6614         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6615                 error "setstripe failed"
6616         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6617                 error "getstripe failed"
6618         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6619         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6620
6621         local testfile2=${testfile}2
6622         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6623                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6624
6625         $RUNAS $MCREATE $testfile2
6626         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6627         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6628         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6629         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6630         [ $stripe_count -eq $STRIPECOUNT ] ||
6631                 error "stripe count $stripe_count != $STRIPECOUNT"
6632 }
6633 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6634
6635 compare_stripe_info1() {
6636         local stripe_index_all_zero=true
6637
6638         for num in 1 2 3 4; do
6639                 for count in $(seq 1 $STRIPE_COUNT); do
6640                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6641                                 local size=$((STRIPE_SIZE * num))
6642                                 local file=file"$num-$offset-$count"
6643                                 stripe_size=$($LFS getstripe -S $PWD/$file)
6644                                 [[ $stripe_size -ne $size ]] &&
6645                                     error "$file: size $stripe_size != $size"
6646                                 stripe_count=$($LFS getstripe -c $PWD/$file)
6647                                 # allow fewer stripes to be created, ORI-601
6648                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6649                                     error "$file: count $stripe_count != $count"
6650                                 stripe_index=$($LFS getstripe -i $PWD/$file)
6651                                 [[ $stripe_index -ne 0 ]] &&
6652                                         stripe_index_all_zero=false
6653                         done
6654                 done
6655         done
6656         $stripe_index_all_zero &&
6657                 error "all files are being extracted starting from OST index 0"
6658         return 0
6659 }
6660
6661 find_lustre_tar() {
6662         [ -n "$(which tar 2>/dev/null)" ] &&
6663                 strings $(which tar) | grep -q "lustre" && echo tar
6664 }
6665
6666 test_102d() {
6667         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6668         # b10930: tar test for trusted.lov xattr
6669         TAR=$(find_lustre_tar)
6670         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6671         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6672         setup_test102
6673         test_mkdir -p $DIR/d102d
6674         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6675         cd $DIR/d102d/$tdir
6676         compare_stripe_info1
6677 }
6678 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6679
6680 test_102f() {
6681         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6682         # b10930: tar test for trusted.lov xattr
6683         TAR=$(find_lustre_tar)
6684         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6685         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6686         setup_test102
6687         test_mkdir -p $DIR/d102f
6688         cd $DIR
6689         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6690         cd $DIR/d102f/$tdir
6691         compare_stripe_info1
6692 }
6693 run_test 102f "tar copy files, not keep osts ==========="
6694
6695 grow_xattr() {
6696         local xsize=${1:-1024}  # in bytes
6697         local file=$DIR/$tfile
6698
6699         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6700                 skip "must have user_xattr" && return 0
6701         [ -z "$(which setfattr 2>/dev/null)" ] &&
6702                 skip_env "could not find setfattr" && return 0
6703         [ -z "$(which getfattr 2>/dev/null)" ] &&
6704                 skip_env "could not find getfattr" && return 0
6705
6706         touch $file
6707
6708         local value="$(generate_string $xsize)"
6709
6710         local xbig=trusted.big
6711         log "save $xbig on $file"
6712         setfattr -n $xbig -v $value $file ||
6713                 error "saving $xbig on $file failed"
6714
6715         local orig=$(get_xattr_value $xbig $file)
6716         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6717
6718         local xsml=trusted.sml
6719         log "save $xsml on $file"
6720         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6721
6722         local new=$(get_xattr_value $xbig $file)
6723         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6724
6725         log "grow $xsml on $file"
6726         setfattr -n $xsml -v "$value" $file ||
6727                 error "growing $xsml on $file failed"
6728
6729         new=$(get_xattr_value $xbig $file)
6730         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6731         log "$xbig still valid after growing $xsml"
6732
6733         rm -f $file
6734 }
6735
6736 test_102h() { # bug 15777
6737         grow_xattr 1024
6738 }
6739 run_test 102h "grow xattr from inside inode to external block"
6740
6741 test_102ha() {
6742         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6743         grow_xattr $(max_xattr_size)
6744 }
6745 run_test 102ha "grow xattr from inside inode to external inode"
6746
6747 test_102i() { # bug 17038
6748         [ -z "$(which getfattr 2>/dev/null)" ] &&
6749                 skip "could not find getfattr" && return
6750         touch $DIR/$tfile
6751         ln -s $DIR/$tfile $DIR/${tfile}link
6752         getfattr -n trusted.lov $DIR/$tfile ||
6753                 error "lgetxattr on $DIR/$tfile failed"
6754         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6755                 grep -i "no such attr" ||
6756                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6757         rm -f $DIR/$tfile $DIR/${tfile}link
6758 }
6759 run_test 102i "lgetxattr test on symbolic link ============"
6760
6761 test_102j() {
6762         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6763         TAR=$(find_lustre_tar)
6764         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6765         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6766         setup_test102 "$RUNAS"
6767         test_mkdir -p $DIR/d102j
6768         chown $RUNAS_ID $DIR/d102j
6769         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6770         cd $DIR/d102j/$tdir
6771         compare_stripe_info1 "$RUNAS"
6772 }
6773 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6774
6775 test_102k() {
6776         [ -z "$(which setfattr 2>/dev/null)" ] &&
6777                 skip "could not find setfattr" && return
6778         touch $DIR/$tfile
6779         # b22187 just check that does not crash for regular file.
6780         setfattr -n trusted.lov $DIR/$tfile
6781         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6782         local test_kdir=$DIR/d102k
6783         test_mkdir $test_kdir
6784         local default_size=`$GETSTRIPE -S $test_kdir`
6785         local default_count=`$GETSTRIPE -c $test_kdir`
6786         local default_offset=`$GETSTRIPE -i $test_kdir`
6787         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6788                 error 'dir setstripe failed'
6789         setfattr -n trusted.lov $test_kdir
6790         local stripe_size=`$GETSTRIPE -S $test_kdir`
6791         local stripe_count=`$GETSTRIPE -c $test_kdir`
6792         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6793         [ $stripe_size -eq $default_size ] ||
6794                 error "stripe size $stripe_size != $default_size"
6795         [ $stripe_count -eq $default_count ] ||
6796                 error "stripe count $stripe_count != $default_count"
6797         [ $stripe_offset -eq $default_offset ] ||
6798                 error "stripe offset $stripe_offset != $default_offset"
6799         rm -rf $DIR/$tfile $test_kdir
6800 }
6801 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6802
6803 test_102l() {
6804         [ -z "$(which getfattr 2>/dev/null)" ] &&
6805                 skip "could not find getfattr" && return
6806
6807         # LU-532 trusted. xattr is invisible to non-root
6808         local testfile=$DIR/$tfile
6809
6810         touch $testfile
6811
6812         echo "listxattr as user..."
6813         chown $RUNAS_ID $testfile
6814         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6815             grep -q "trusted" &&
6816                 error "$testfile trusted xattrs are user visible"
6817
6818         return 0;
6819 }
6820 run_test 102l "listxattr size test =================================="
6821
6822 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6823         local path=$DIR/$tfile
6824         touch $path
6825
6826         listxattr_size_check $path || error "listattr_size_check $path failed"
6827 }
6828 run_test 102m "Ensure listxattr fails on small bufffer ========"
6829
6830 cleanup_test102
6831
6832 getxattr() { # getxattr path name
6833         # Return the base64 encoding of the value of xattr name on path.
6834         local path=$1
6835         local name=$2
6836
6837         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6838         # file: $path
6839         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6840         #
6841         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6842
6843         getfattr --absolute-names --encoding=base64 --name=$name $path |
6844                 awk -F= -v name=$name '$1 == name {
6845                         print substr($0, index($0, "=") + 1);
6846         }'
6847 }
6848
6849 test_102n() { # LU-4101 mdt: protect internal xattrs
6850         local file0=$DIR/$tfile.0
6851         local file1=$DIR/$tfile.1
6852         local xattr0=$TMP/$tfile.0
6853         local xattr1=$TMP/$tfile.1
6854         local name
6855         local value
6856
6857         [ -z "$(which setfattr 2>/dev/null)" ] &&
6858                 skip "could not find setfattr" && return
6859
6860         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6861         then
6862                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6863                 return
6864         fi
6865
6866         rm -rf $file0 $file1 $xattr0 $xattr1
6867         touch $file0 $file1
6868
6869         # Get 'before' xattrs of $file1.
6870         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6871
6872         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6873                 # Try to copy xattr from $file0 to $file1.
6874                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6875
6876                 setfattr --name=trusted.$name --value="$value" $file1 ||
6877                         error "setxattr 'trusted.$name' failed"
6878
6879                 # Try to set a garbage xattr.
6880                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6881
6882                 setfattr --name=trusted.$name --value="$value" $file1 ||
6883                         error "setxattr 'trusted.$name' failed"
6884
6885                 # Try to remove the xattr from $file1. We don't care if this
6886                 # appears to succeed or fail, we just don't want there to be
6887                 # any changes or crashes.
6888                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6889         done
6890
6891         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
6892         then
6893                 name="lfsck_ns"
6894                 # Try to copy xattr from $file0 to $file1.
6895                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6896
6897                 setfattr --name=trusted.$name --value="$value" $file1 ||
6898                         error "setxattr 'trusted.$name' failed"
6899
6900                 # Try to set a garbage xattr.
6901                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6902
6903                 setfattr --name=trusted.$name --value="$value" $file1 ||
6904                         error "setxattr 'trusted.$name' failed"
6905
6906                 # Try to remove the xattr from $file1. We don't care if this
6907                 # appears to succeed or fail, we just don't want there to be
6908                 # any changes or crashes.
6909                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6910         fi
6911
6912         # Get 'after' xattrs of file1.
6913         getfattr --absolute-names --dump --match=- $file1 > $xattr1
6914
6915         if ! diff $xattr0 $xattr1; then
6916                 error "before and after xattrs of '$file1' differ"
6917         fi
6918
6919         rm -rf $file0 $file1 $xattr0 $xattr1
6920
6921         return 0
6922 }
6923 run_test 102n "silently ignore setxattr on internal trusted xattrs"
6924
6925 test_102p() { # LU-4703 setxattr did not check ownership
6926         local testfile=$DIR/$tfile
6927
6928         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
6929                 skip "MDS needs to be at least 2.5.56" && return
6930
6931         touch $testfile
6932
6933         echo "setfacl as user..."
6934         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
6935         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
6936
6937         echo "setfattr as user..."
6938         setfacl -m "u:$RUNAS_ID:---" $testfile
6939         $RUNAS setfattr -x system.posix_acl_access $testfile
6940         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
6941 }
6942 run_test 102p "check setxattr(2) correctly fails without permission"
6943
6944 test_102q() {
6945         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
6946                 skip "MDS needs to be at least 2.6.92" && return
6947         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
6948 }
6949 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
6950
6951 test_102r() {
6952         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
6953                 skip "MDS needs to be at least 2.6.93" && return
6954         touch $DIR/$tfile || error "touch"
6955         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
6956         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
6957         rm $DIR/$tfile || error "rm"
6958
6959         #normal directory
6960         mkdir -p $DIR/$tdir || error "mkdir"
6961         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
6962         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
6963         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
6964                 error "$testfile error deleting user.author1"
6965         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
6966                 grep "user.$(basename $tdir)" &&
6967                 error "$tdir did not delete user.$(basename $tdir)"
6968         rmdir $DIR/$tdir || error "rmdir"
6969
6970         #striped directory
6971         test_mkdir -p $DIR/$tdir || error "make striped dir"
6972         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
6973         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
6974         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
6975                 error "$testfile error deleting user.author1"
6976         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
6977                 grep "user.$(basename $tdir)" &&
6978                 error "$tdir did not delete user.$(basename $tdir)"
6979         rmdir $DIR/$tdir || error "rm striped dir"
6980 }
6981 run_test 102r "set EAs with empty values"
6982
6983 run_acl_subtest()
6984 {
6985     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6986     return $?
6987 }
6988
6989 test_103a() {
6990         [ "$UID" != 0 ] && skip_env "must run as root" && return
6991         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6992                 skip "must have acl enabled" && return
6993         [ -z "$(which setfacl 2>/dev/null)" ] &&
6994                 skip_env "could not find setfacl" && return
6995         $GSS && skip "could not run under gss" && return
6996
6997         gpasswd -a daemon bin                           # LU-5641
6998         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
6999
7000         declare -a identity_old
7001
7002         for num in $(seq $MDSCOUNT); do
7003                 switch_identity $num true || identity_old[$num]=$?
7004         done
7005
7006         SAVE_UMASK=$(umask)
7007         umask 0022
7008         cd $DIR
7009
7010         echo "performing cp ..."
7011         run_acl_subtest cp || error "run_acl_subtest cp failed"
7012         echo "performing getfacl-noacl..."
7013         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
7014         echo "performing misc..."
7015         run_acl_subtest misc || error  "misc test failed"
7016         echo "performing permissions..."
7017         run_acl_subtest permissions || error "permissions failed"
7018         echo "performing setfacl..."
7019         run_acl_subtest setfacl || error  "setfacl test failed"
7020
7021         # inheritance test got from HP
7022         echo "performing inheritance..."
7023         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
7024         chmod +x make-tree || error "chmod +x failed"
7025         run_acl_subtest inheritance || error "inheritance test failed"
7026         rm -f make-tree
7027
7028         echo "LU-974 ignore umask when acl is enabled..."
7029         run_acl_subtest 974 || error "LU-974 umask test failed"
7030         if [ $MDSCOUNT -ge 2 ]; then
7031                 run_acl_subtest 974_remote ||
7032                         error "LU-974 umask test failed under remote dir"
7033         fi
7034
7035         echo "LU-2561 newly created file is same size as directory..."
7036         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
7037                 run_acl_subtest 2561 || error "LU-2561 test failed"
7038         else
7039                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
7040         fi
7041
7042         run_acl_subtest 4924 || error "LU-4924 test failed"
7043
7044         cd $SAVE_PWD
7045         umask $SAVE_UMASK
7046
7047         for num in $(seq $MDSCOUNT); do
7048                 if [ "${identity_old[$num]}" = 1 ]; then
7049                         switch_identity $num false || identity_old[$num]=$?
7050                 fi
7051         done
7052 }
7053 run_test 103a "acl test ========================================="
7054
7055 test_103b() {
7056         local noacl=false
7057         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
7058         local mountopts=$MDS_MOUNT_OPTS
7059
7060         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
7061                 noacl=true
7062         else
7063                 # stop the MDT
7064                 stop $SINGLEMDS || error "failed to stop MDT."
7065                 # remount the MDT
7066                 if [ -z "$MDS_MOUNT_OPTS" ]; then
7067                         MDS_MOUNT_OPTS="-o noacl"
7068                 else
7069                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
7070                 fi
7071                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7072                         error "failed to start MDT."
7073                 MDS_MOUNT_OPTS=$mountopts
7074         fi
7075
7076         touch $DIR/$tfile
7077         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
7078
7079         if ! $noacl; then
7080                 # stop the MDT
7081                 stop $SINGLEMDS || error "failed to stop MDT."
7082                 # remount the MDT
7083                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7084                         error "failed to start MDT."
7085         fi
7086
7087         true
7088 }
7089 run_test 103b "MDS mount option 'noacl'"
7090
7091 test_103c() {
7092         mkdir -p $DIR/$tdir
7093         cp -rp $DIR/$tdir $DIR/$tdir.bak
7094
7095         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
7096                 error "$DIR/$tdir shouldn't contain default ACL"
7097         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
7098                 error "$DIR/$tdir.bak shouldn't contain default ACL"
7099         true
7100 }
7101 run_test 103c "'cp -rp' won't set empty acl"
7102
7103 test_104a() {
7104         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7105         touch $DIR/$tfile
7106         lfs df || error "lfs df failed"
7107         lfs df -ih || error "lfs df -ih failed"
7108         lfs df -h $DIR || error "lfs df -h $DIR failed"
7109         lfs df -i $DIR || error "lfs df -i $DIR failed"
7110         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
7111         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
7112
7113         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
7114         lctl --device %$OSC deactivate
7115         lfs df || error "lfs df with deactivated OSC failed"
7116         lctl --device %$OSC activate
7117         # wait the osc back to normal
7118         wait_osc_import_state client ost FULL
7119
7120         lfs df || error "lfs df with reactivated OSC failed"
7121         rm -f $DIR/$tfile
7122 }
7123 run_test 104a "lfs df [-ih] [path] test ========================="
7124
7125 test_104b() {
7126         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7127         [ $RUNAS_ID -eq $UID ] &&
7128                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
7129         chmod 666 /dev/obd
7130         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
7131                         grep "Permission denied" | wc -l)))
7132         if [ $denied_cnt -ne 0 ]; then
7133                 error "lfs check servers test failed"
7134         fi
7135 }
7136 run_test 104b "$RUNAS lfs check servers test ===================="
7137
7138 test_105a() {
7139         # doesn't work on 2.4 kernels
7140         touch $DIR/$tfile
7141         if $(flock_is_enabled); then
7142                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7143         else
7144                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7145         fi
7146         rm -f $DIR/$tfile
7147 }
7148 run_test 105a "flock when mounted without -o flock test ========"
7149
7150 test_105b() {
7151         touch $DIR/$tfile
7152         if $(flock_is_enabled); then
7153                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7154         else
7155                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7156         fi
7157         rm -f $DIR/$tfile
7158 }
7159 run_test 105b "fcntl when mounted without -o flock test ========"
7160
7161 test_105c() {
7162         touch $DIR/$tfile
7163         if $(flock_is_enabled); then
7164                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7165         else
7166                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7167         fi
7168         rm -f $DIR/$tfile
7169 }
7170 run_test 105c "lockf when mounted without -o flock test ========"
7171
7172 test_105d() { # bug 15924
7173         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7174         test_mkdir -p $DIR/$tdir
7175         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7176         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7177         $LCTL set_param fail_loc=0x80000315
7178         flocks_test 2 $DIR/$tdir
7179 }
7180 run_test 105d "flock race (should not freeze) ========"
7181
7182 test_105e() { # bug 22660 && 22040
7183         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7184         touch $DIR/$tfile
7185         flocks_test 3 $DIR/$tfile
7186 }
7187 run_test 105e "Two conflicting flocks from same process ======="
7188
7189 test_106() { #bug 10921
7190         test_mkdir -p $DIR/$tdir
7191         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7192         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7193 }
7194 run_test 106 "attempt exec of dir followed by chown of that dir"
7195
7196 test_107() {
7197         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7198         CDIR=`pwd`
7199         cd $DIR
7200
7201         local file=core
7202         rm -f $file
7203
7204         local save_pattern=$(sysctl -n kernel.core_pattern)
7205         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7206         sysctl -w kernel.core_pattern=$file
7207         sysctl -w kernel.core_uses_pid=0
7208
7209         ulimit -c unlimited
7210         sleep 60 &
7211         SLEEPPID=$!
7212
7213         sleep 1
7214
7215         kill -s 11 $SLEEPPID
7216         wait $SLEEPPID
7217         if [ -e $file ]; then
7218                 size=`stat -c%s $file`
7219                 [ $size -eq 0 ] && error "Fail to create core file $file"
7220         else
7221                 error "Fail to create core file $file"
7222         fi
7223         rm -f $file
7224         sysctl -w kernel.core_pattern=$save_pattern
7225         sysctl -w kernel.core_uses_pid=$save_uses_pid
7226         cd $CDIR
7227 }
7228 run_test 107 "Coredump on SIG"
7229
7230 test_110() {
7231         test_mkdir -p $DIR/$tdir
7232         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7233                 error "mkdir with 255 char failed"
7234         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7235                 error "mkdir with 256 char should fail, but did not"
7236         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7237                 error "create with 255 char failed"
7238         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7239                 error "create with 256 char should fail, but did not"
7240
7241         ls -l $DIR/$tdir
7242         rm -rf $DIR/$tdir
7243 }
7244 run_test 110 "filename length checking"
7245
7246 test_115() {
7247         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7248         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
7249                 tail -1 | cut -c11-20)
7250         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
7251         echo "Starting with $OSTIO_pre threads"
7252
7253         NUMTEST=20000
7254         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7255         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
7256         echo "$NUMTEST creates/unlinks"
7257         test_mkdir -p $DIR/$tdir
7258         createmany -o $DIR/$tdir/$tfile $NUMTEST
7259         unlinkmany $DIR/$tdir/$tfile $NUMTEST
7260
7261         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
7262                 tail -1 | cut -c11-20)
7263
7264         # don't return an error
7265         [ $OSTIO_post == $OSTIO_pre ] && echo \
7266             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
7267             echo "This may be fine, depending on what ran before this test" &&
7268             echo "and how fast this system is." && return
7269
7270         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
7271 }
7272 run_test 115 "verify dynamic thread creation===================="
7273
7274 free_min_max () {
7275         wait_delete_completed
7276         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7277         echo OST kbytes available: ${AVAIL[@]}
7278         MAXI=0; MAXV=${AVAIL[0]}
7279         MINI=0; MINV=${AVAIL[0]}
7280         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7281                 #echo OST $i: ${AVAIL[i]}kb
7282                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7283                         MAXV=${AVAIL[i]}; MAXI=$i
7284                 fi
7285                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7286                         MINV=${AVAIL[i]}; MINI=$i
7287                 fi
7288         done
7289         echo Min free space: OST $MINI: $MINV
7290         echo Max free space: OST $MAXI: $MAXV
7291 }
7292
7293 test_116a() { # was previously test_116()
7294         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7295         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
7296
7297         echo -n "Free space priority "
7298         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7299                 head -n1
7300         declare -a AVAIL
7301         free_min_max
7302
7303         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7304         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7305                 && return
7306         trap simple_cleanup_common EXIT
7307
7308
7309         # Check if we need to generate uneven OSTs
7310         test_mkdir -p $DIR/$tdir/OST${MINI}
7311         local FILL=$(($MINV / 4))
7312         local DIFF=$(($MAXV - $MINV))
7313         local DIFF2=$(($DIFF * 100 / $MINV))
7314
7315         local threshold=$(do_facet $SINGLEMDS \
7316                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7317         threshold=${threshold%%%}
7318         echo -n "Check for uneven OSTs: "
7319         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7320
7321         if [[ $DIFF2 -gt $threshold ]]; then
7322                 echo "ok"
7323                 echo "Don't need to fill OST$MINI"
7324         else
7325                 # generate uneven OSTs. Write 2% over the QOS threshold value
7326                 echo "no"
7327                 DIFF=$(($threshold - $DIFF2 + 2))
7328                 DIFF2=$(( ($MINV * $DIFF)/100 ))
7329                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
7330                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7331                         error "setstripe failed"
7332                 DIFF=$(($DIFF2 / 2048))
7333                 i=0
7334                 while [ $i -lt $DIFF ]; do
7335                         i=$(($i + 1))
7336                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7337                                 bs=2M count=1 2>/dev/null
7338                         echo -n .
7339                 done
7340                 echo .
7341                 sync
7342                 sleep_maxage
7343                 free_min_max
7344         fi
7345
7346         DIFF=$(($MAXV - $MINV))
7347         DIFF2=$(($DIFF * 100 / $MINV))
7348         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
7349         if [[ $DIFF2 -gt $threshold ]]; then
7350                 echo "ok"
7351         else
7352                 echo "failed - QOS mode won't be used"
7353                 skip "QOS imbalance criteria not met"
7354                 simple_cleanup_common
7355                 return
7356         fi
7357
7358         MINI1=$MINI; MINV1=$MINV
7359         MAXI1=$MAXI; MAXV1=$MAXV
7360
7361         # now fill using QOS
7362         $SETSTRIPE -c 1 $DIR/$tdir
7363         FILL=$(($FILL / 200))
7364         if [ $FILL -gt 600 ]; then
7365                 FILL=600
7366         fi
7367         echo "writing $FILL files to QOS-assigned OSTs"
7368         i=0
7369         while [ $i -lt $FILL ]; do
7370                 i=$((i + 1))
7371                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7372                         count=1 2>/dev/null
7373                 echo -n .
7374         done
7375         echo "wrote $i 200k files"
7376         sync
7377         sleep_maxage
7378
7379         echo "Note: free space may not be updated, so measurements might be off"
7380         free_min_max
7381         DIFF2=$(($MAXV - $MINV))
7382         echo "free space delta: orig $DIFF final $DIFF2"
7383         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7384         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
7385         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7386         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
7387         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7388         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7389         [ $DIFF -gt 0 ] &&
7390                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7391
7392         # Figure out which files were written where
7393         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7394                   awk '/'$MINI1': / {print $2; exit}')
7395         echo $UUID
7396         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7397         echo "$MINC files created on smaller OST $MINI1"
7398         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7399                   awk '/'$MAXI1': / {print $2; exit}')
7400         echo $UUID
7401         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7402         echo "$MAXC files created on larger OST $MAXI1"
7403         FILL=$(($MAXC * 100 / $MINC - 100))
7404         [[ $MINC -gt 0 ]] &&
7405                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7406         [[ $MAXC -gt $MINC ]] ||
7407                 error_ignore LU-9 "stripe QOS didn't balance free space"
7408         simple_cleanup_common
7409 }
7410 run_test 116a "stripe QOS: free space balance ==================="
7411
7412 test_116b() { # LU-2093
7413         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7414 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7415         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7416                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7417         [ -z "$old_rr" ] && skip "no QOS" && return 0
7418         do_facet $SINGLEMDS lctl set_param \
7419                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7420         mkdir -p $DIR/$tdir
7421         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7422         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7423         do_facet $SINGLEMDS lctl set_param fail_loc=0
7424         rm -rf $DIR/$tdir
7425         do_facet $SINGLEMDS lctl set_param \
7426                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7427 }
7428 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7429
7430 test_117() # bug 10891
7431 {
7432         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7433         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7434         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7435         lctl set_param fail_loc=0x21e
7436         > $DIR/$tfile || error "truncate failed"
7437         lctl set_param fail_loc=0
7438         echo "Truncate succeeded."
7439         rm -f $DIR/$tfile
7440 }
7441 run_test 117 "verify osd extend =========="
7442
7443 NO_SLOW_RESENDCOUNT=4
7444 export OLD_RESENDCOUNT=""
7445 set_resend_count () {
7446         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7447         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7448         lctl set_param -n $PROC_RESENDCOUNT $1
7449         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7450 }
7451
7452 # for reduce test_118* time (b=14842)
7453 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7454
7455 # Reset async IO behavior after error case
7456 reset_async() {
7457         FILE=$DIR/reset_async
7458
7459         # Ensure all OSCs are cleared
7460         $SETSTRIPE -c -1 $FILE
7461         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7462         sync
7463         rm $FILE
7464 }
7465
7466 test_118a() #bug 11710
7467 {
7468         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7469         reset_async
7470
7471         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7472         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7473         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7474
7475         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7476                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7477                 return 1;
7478         fi
7479         rm -f $DIR/$tfile
7480 }
7481 run_test 118a "verify O_SYNC works =========="
7482
7483 test_118b()
7484 {
7485         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7486         remote_ost_nodsh && skip "remote OST with nodsh" && return
7487
7488         reset_async
7489
7490         #define OBD_FAIL_OST_ENOENT 0x217
7491         set_nodes_failloc "$(osts_nodes)" 0x217
7492         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7493         RC=$?
7494         set_nodes_failloc "$(osts_nodes)" 0
7495         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7496         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7497                     grep -c writeback)
7498
7499         if [[ $RC -eq 0 ]]; then
7500                 error "Must return error due to dropped pages, rc=$RC"
7501                 return 1;
7502         fi
7503
7504         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7505                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7506                 return 1;
7507         fi
7508
7509         echo "Dirty pages not leaked on ENOENT"
7510
7511         # Due to the above error the OSC will issue all RPCs syncronously
7512         # until a subsequent RPC completes successfully without error.
7513         $MULTIOP $DIR/$tfile Ow4096yc
7514         rm -f $DIR/$tfile
7515
7516         return 0
7517 }
7518 run_test 118b "Reclaim dirty pages on fatal error =========="
7519
7520 test_118c()
7521 {
7522         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7523
7524         # for 118c, restore the original resend count, LU-1940
7525         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7526                                 set_resend_count $OLD_RESENDCOUNT
7527         remote_ost_nodsh && skip "remote OST with nodsh" && return
7528
7529         reset_async
7530
7531         #define OBD_FAIL_OST_EROFS               0x216
7532         set_nodes_failloc "$(osts_nodes)" 0x216
7533
7534         # multiop should block due to fsync until pages are written
7535         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7536         MULTIPID=$!
7537         sleep 1
7538
7539         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7540                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7541         fi
7542
7543         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7544                     grep -c writeback)
7545         if [[ $WRITEBACK -eq 0 ]]; then
7546                 error "No page in writeback, writeback=$WRITEBACK"
7547         fi
7548
7549         set_nodes_failloc "$(osts_nodes)" 0
7550         wait $MULTIPID
7551         RC=$?
7552         if [[ $RC -ne 0 ]]; then
7553                 error "Multiop fsync failed, rc=$RC"
7554         fi
7555
7556         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7557         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7558                     grep -c writeback)
7559         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7560                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7561         fi
7562
7563         rm -f $DIR/$tfile
7564         echo "Dirty pages flushed via fsync on EROFS"
7565         return 0
7566 }
7567 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7568
7569 # continue to use small resend count to reduce test_118* time (b=14842)
7570 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7571
7572 test_118d()
7573 {
7574         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7575         remote_ost_nodsh && skip "remote OST with nodsh" && return
7576
7577         reset_async
7578
7579         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7580         set_nodes_failloc "$(osts_nodes)" 0x214
7581         # multiop should block due to fsync until pages are written
7582         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7583         MULTIPID=$!
7584         sleep 1
7585
7586         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7587                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7588         fi
7589
7590         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7591                     grep -c writeback)
7592         if [[ $WRITEBACK -eq 0 ]]; then
7593                 error "No page in writeback, writeback=$WRITEBACK"
7594         fi
7595
7596         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7597         set_nodes_failloc "$(osts_nodes)" 0
7598
7599         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7600         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7601                     grep -c writeback)
7602         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7603                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7604         fi
7605
7606         rm -f $DIR/$tfile
7607         echo "Dirty pages gaurenteed flushed via fsync"
7608         return 0
7609 }
7610 run_test 118d "Fsync validation inject a delay of the bulk =========="
7611
7612 test_118f() {
7613         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7614         reset_async
7615
7616         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7617         lctl set_param fail_loc=0x8000040a
7618
7619         # Should simulate EINVAL error which is fatal
7620         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7621         RC=$?
7622         if [[ $RC -eq 0 ]]; then
7623                 error "Must return error due to dropped pages, rc=$RC"
7624         fi
7625
7626         lctl set_param fail_loc=0x0
7627
7628         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7629         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7630         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7631                     grep -c writeback)
7632         if [[ $LOCKED -ne 0 ]]; then
7633                 error "Locked pages remain in cache, locked=$LOCKED"
7634         fi
7635
7636         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7637                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7638         fi
7639
7640         rm -f $DIR/$tfile
7641         echo "No pages locked after fsync"
7642
7643         reset_async
7644         return 0
7645 }
7646 run_test 118f "Simulate unrecoverable OSC side error =========="
7647
7648 test_118g() {
7649         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7650         reset_async
7651
7652         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7653         lctl set_param fail_loc=0x406
7654
7655         # simulate local -ENOMEM
7656         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7657         RC=$?
7658
7659         lctl set_param fail_loc=0
7660         if [[ $RC -eq 0 ]]; then
7661                 error "Must return error due to dropped pages, rc=$RC"
7662         fi
7663
7664         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7665         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7666         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7667                         grep -c writeback)
7668         if [[ $LOCKED -ne 0 ]]; then
7669                 error "Locked pages remain in cache, locked=$LOCKED"
7670         fi
7671
7672         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7673                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7674         fi
7675
7676         rm -f $DIR/$tfile
7677         echo "No pages locked after fsync"
7678
7679         reset_async
7680         return 0
7681 }
7682 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7683
7684 test_118h() {
7685         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7686         remote_ost_nodsh && skip "remote OST with nodsh" && return
7687
7688         reset_async
7689
7690         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7691         set_nodes_failloc "$(osts_nodes)" 0x20e
7692         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7693         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7694         RC=$?
7695
7696         set_nodes_failloc "$(osts_nodes)" 0
7697         if [[ $RC -eq 0 ]]; then
7698                 error "Must return error due to dropped pages, rc=$RC"
7699         fi
7700
7701         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7702         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7703         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7704                     grep -c writeback)
7705         if [[ $LOCKED -ne 0 ]]; then
7706                 error "Locked pages remain in cache, locked=$LOCKED"
7707         fi
7708
7709         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7710                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7711         fi
7712
7713         rm -f $DIR/$tfile
7714         echo "No pages locked after fsync"
7715
7716         return 0
7717 }
7718 run_test 118h "Verify timeout in handling recoverables errors  =========="
7719
7720 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7721
7722 test_118i() {
7723         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7724         remote_ost_nodsh && skip "remote OST with nodsh" && return
7725
7726         reset_async
7727
7728         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7729         set_nodes_failloc "$(osts_nodes)" 0x20e
7730
7731         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7732         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7733         PID=$!
7734         sleep 5
7735         set_nodes_failloc "$(osts_nodes)" 0
7736
7737         wait $PID
7738         RC=$?
7739         if [[ $RC -ne 0 ]]; then
7740                 error "got error, but should be not, rc=$RC"
7741         fi
7742
7743         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7744         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7745         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7746         if [[ $LOCKED -ne 0 ]]; then
7747                 error "Locked pages remain in cache, locked=$LOCKED"
7748         fi
7749
7750         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7751                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7752         fi
7753
7754         rm -f $DIR/$tfile
7755         echo "No pages locked after fsync"
7756
7757         return 0
7758 }
7759 run_test 118i "Fix error before timeout in recoverable error  =========="
7760
7761 [ "$SLOW" = "no" ] && set_resend_count 4
7762
7763 test_118j() {
7764         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7765         remote_ost_nodsh && skip "remote OST with nodsh" && return
7766
7767         reset_async
7768
7769         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7770         set_nodes_failloc "$(osts_nodes)" 0x220
7771
7772         # return -EIO from OST
7773         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7774         RC=$?
7775         set_nodes_failloc "$(osts_nodes)" 0x0
7776         if [[ $RC -eq 0 ]]; then
7777                 error "Must return error due to dropped pages, rc=$RC"
7778         fi
7779
7780         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7781         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7782         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7783         if [[ $LOCKED -ne 0 ]]; then
7784                 error "Locked pages remain in cache, locked=$LOCKED"
7785         fi
7786
7787         # in recoverable error on OST we want resend and stay until it finished
7788         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7789                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7790         fi
7791
7792         rm -f $DIR/$tfile
7793         echo "No pages locked after fsync"
7794
7795         return 0
7796 }
7797 run_test 118j "Simulate unrecoverable OST side error =========="
7798
7799 test_118k()
7800 {
7801         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7802         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7803
7804         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7805         set_nodes_failloc "$(osts_nodes)" 0x20e
7806         test_mkdir -p $DIR/$tdir
7807
7808         for ((i=0;i<10;i++)); do
7809                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7810                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7811                 SLEEPPID=$!
7812                 sleep 0.500s
7813                 kill $SLEEPPID
7814                 wait $SLEEPPID
7815         done
7816
7817         set_nodes_failloc "$(osts_nodes)" 0
7818         rm -rf $DIR/$tdir
7819 }
7820 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7821
7822 test_118l()
7823 {
7824         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7825         # LU-646
7826         test_mkdir -p $DIR/$tdir
7827         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7828         rm -rf $DIR/$tdir
7829 }
7830 run_test 118l "fsync dir ========="
7831
7832 test_118m() # LU-3066
7833 {
7834         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7835         test_mkdir -p $DIR/$tdir
7836         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7837         rm -rf $DIR/$tdir
7838 }
7839 run_test 118m "fdatasync dir ========="
7840
7841 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7842
7843 test_119a() # bug 11737
7844 {
7845         BSIZE=$((512 * 1024))
7846         directio write $DIR/$tfile 0 1 $BSIZE
7847         # We ask to read two blocks, which is more than a file size.
7848         # directio will indicate an error when requested and actual
7849         # sizes aren't equeal (a normal situation in this case) and
7850         # print actual read amount.
7851         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7852         if [ "$NOB" != "$BSIZE" ]; then
7853                 error "read $NOB bytes instead of $BSIZE"
7854         fi
7855         rm -f $DIR/$tfile
7856 }
7857 run_test 119a "Short directIO read must return actual read amount"
7858
7859 test_119b() # bug 11737
7860 {
7861         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7862
7863         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7864         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7865         sync
7866         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7867                 error "direct read failed"
7868         rm -f $DIR/$tfile
7869 }
7870 run_test 119b "Sparse directIO read must return actual read amount"
7871
7872 test_119c() # bug 13099
7873 {
7874         BSIZE=1048576
7875         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7876         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7877         rm -f $DIR/$tfile
7878 }
7879 run_test 119c "Testing for direct read hitting hole"
7880
7881 test_119d() # bug 15950
7882 {
7883         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7884         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7885         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7886         BSIZE=1048576
7887         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7888         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7889         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7890         lctl set_param fail_loc=0x40d
7891         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7892         pid_dio=$!
7893         sleep 1
7894         cat $DIR/$tfile > /dev/null &
7895         lctl set_param fail_loc=0
7896         pid_reads=$!
7897         wait $pid_dio
7898         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7899         sleep 2
7900         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7901         error "the read rpcs have not completed in 2s"
7902         rm -f $DIR/$tfile
7903         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7904 }
7905 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7906
7907 test_120a() {
7908         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7909         test_mkdir -p $DIR/$tdir
7910         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7911                skip "no early lock cancel on server" && return 0
7912
7913         lru_resize_disable mdc
7914         lru_resize_disable osc
7915         cancel_lru_locks mdc
7916         # asynchronous object destroy at MDT could cause bl ast to client
7917         cancel_lru_locks osc
7918
7919         stat $DIR/$tdir > /dev/null
7920         can1=$(do_facet $SINGLEMDS \
7921                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7922                awk '/ldlm_cancel/ {print $2}')
7923         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7924                awk '/ldlm_bl_callback/ {print $2}')
7925         test_mkdir -c1 $DIR/$tdir/d1
7926         can2=$(do_facet $SINGLEMDS \
7927                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7928                awk '/ldlm_cancel/ {print $2}')
7929         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7930                awk '/ldlm_bl_callback/ {print $2}')
7931         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7932         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7933         lru_resize_enable mdc
7934         lru_resize_enable osc
7935 }
7936 run_test 120a "Early Lock Cancel: mkdir test"
7937
7938 test_120b() {
7939         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7940         test_mkdir $DIR/$tdir
7941         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7942                skip "no early lock cancel on server" && return 0
7943         lru_resize_disable mdc
7944         lru_resize_disable osc
7945         cancel_lru_locks mdc
7946         stat $DIR/$tdir > /dev/null
7947         can1=$(do_facet $SINGLEMDS \
7948                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7949                awk '/ldlm_cancel/ {print $2}')
7950         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7951                awk '/ldlm_bl_callback/ {print $2}')
7952         touch $DIR/$tdir/f1
7953         can2=$(do_facet $SINGLEMDS \
7954                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7955                awk '/ldlm_cancel/ {print $2}')
7956         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7957                awk '/ldlm_bl_callback/ {print $2}')
7958         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7959         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7960         lru_resize_enable mdc
7961         lru_resize_enable osc
7962 }
7963 run_test 120b "Early Lock Cancel: create test"
7964
7965 test_120c() {
7966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7967         test_mkdir -c1 $DIR/$tdir
7968         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7969                skip "no early lock cancel on server" && return 0
7970         lru_resize_disable mdc
7971         lru_resize_disable osc
7972         test_mkdir -p -c1 $DIR/$tdir/d1
7973         test_mkdir -p -c1 $DIR/$tdir/d2
7974         touch $DIR/$tdir/d1/f1
7975         cancel_lru_locks mdc
7976         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7977         can1=$(do_facet $SINGLEMDS \
7978                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7979                awk '/ldlm_cancel/ {print $2}')
7980         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7981                awk '/ldlm_bl_callback/ {print $2}')
7982         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7983         can2=$(do_facet $SINGLEMDS \
7984                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7985                awk '/ldlm_cancel/ {print $2}')
7986         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7987                awk '/ldlm_bl_callback/ {print $2}')
7988         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7989         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7990         lru_resize_enable mdc
7991         lru_resize_enable osc
7992 }
7993 run_test 120c "Early Lock Cancel: link test"
7994
7995 test_120d() {
7996         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7997         test_mkdir -p -c1 $DIR/$tdir
7998         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7999                skip "no early lock cancel on server" && return 0
8000         lru_resize_disable mdc
8001         lru_resize_disable osc
8002         touch $DIR/$tdir
8003         cancel_lru_locks mdc
8004         stat $DIR/$tdir > /dev/null
8005         can1=$(do_facet $SINGLEMDS \
8006                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8007                awk '/ldlm_cancel/ {print $2}')
8008         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8009                awk '/ldlm_bl_callback/ {print $2}')
8010         chmod a+x $DIR/$tdir
8011         can2=$(do_facet $SINGLEMDS \
8012                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8013                awk '/ldlm_cancel/ {print $2}')
8014         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8015                awk '/ldlm_bl_callback/ {print $2}')
8016         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8017         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8018         lru_resize_enable mdc
8019         lru_resize_enable osc
8020 }
8021 run_test 120d "Early Lock Cancel: setattr test"
8022
8023 test_120e() {
8024         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8025         test_mkdir -p -c1 $DIR/$tdir
8026         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8027                skip "no early lock cancel on server" && return 0
8028         lru_resize_disable mdc
8029         lru_resize_disable osc
8030         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
8031         cancel_lru_locks mdc
8032         cancel_lru_locks osc
8033         dd if=$DIR/$tdir/f1 of=/dev/null
8034         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
8035         # XXX client can not do early lock cancel of OST lock
8036         # during unlink (LU-4206), so cancel osc lock now.
8037         cancel_lru_locks osc
8038         can1=$(do_facet $SINGLEMDS \
8039                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8040                awk '/ldlm_cancel/ {print $2}')
8041         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8042                awk '/ldlm_bl_callback/ {print $2}')
8043         unlink $DIR/$tdir/f1
8044         sleep 5
8045         can2=$(do_facet $SINGLEMDS \
8046                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8047                awk '/ldlm_cancel/ {print $2}')
8048         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8049                awk '/ldlm_bl_callback/ {print $2}')
8050         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8051         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8052         lru_resize_enable mdc
8053         lru_resize_enable osc
8054 }
8055 run_test 120e "Early Lock Cancel: unlink test"
8056
8057 test_120f() {
8058         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8059         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8060                skip "no early lock cancel on server" && return 0
8061         test_mkdir -p -c1 $DIR/$tdir
8062         lru_resize_disable mdc
8063         lru_resize_disable osc
8064         test_mkdir -p -c1 $DIR/$tdir/d1
8065         test_mkdir -p -c1 $DIR/$tdir/d2
8066         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
8067         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
8068         cancel_lru_locks mdc
8069         cancel_lru_locks osc
8070         dd if=$DIR/$tdir/d1/f1 of=/dev/null
8071         dd if=$DIR/$tdir/d2/f2 of=/dev/null
8072         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
8073         # XXX client can not do early lock cancel of OST lock
8074         # during rename (LU-4206), so cancel osc lock now.
8075         cancel_lru_locks osc
8076         can1=$(do_facet $SINGLEMDS \
8077                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8078                awk '/ldlm_cancel/ {print $2}')
8079         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8080                awk '/ldlm_bl_callback/ {print $2}')
8081         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8082         sleep 5
8083         can2=$(do_facet $SINGLEMDS \
8084                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8085                awk '/ldlm_cancel/ {print $2}')
8086         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8087                awk '/ldlm_bl_callback/ {print $2}')
8088         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8089         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8090         lru_resize_enable mdc
8091         lru_resize_enable osc
8092 }
8093 run_test 120f "Early Lock Cancel: rename test"
8094
8095 test_120g() {
8096         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8097         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8098                skip "no early lock cancel on server" && return 0
8099         lru_resize_disable mdc
8100         lru_resize_disable osc
8101         count=10000
8102         echo create $count files
8103         test_mkdir -p $DIR/$tdir
8104         cancel_lru_locks mdc
8105         cancel_lru_locks osc
8106         t0=`date +%s`
8107
8108         can0=$(do_facet $SINGLEMDS \
8109                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8110                awk '/ldlm_cancel/ {print $2}')
8111         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8112                awk '/ldlm_bl_callback/ {print $2}')
8113         createmany -o $DIR/$tdir/f $count
8114         sync
8115         can1=$(do_facet $SINGLEMDS \
8116                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8117                awk '/ldlm_cancel/ {print $2}')
8118         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8119                awk '/ldlm_bl_callback/ {print $2}')
8120         t1=$(date +%s)
8121         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
8122         echo rm $count files
8123         rm -r $DIR/$tdir
8124         sync
8125         can2=$(do_facet $SINGLEMDS \
8126                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8127                awk '/ldlm_cancel/ {print $2}')
8128         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8129                awk '/ldlm_bl_callback/ {print $2}')
8130         t2=$(date +%s)
8131         echo total: $count removes in $((t2-t1))
8132         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
8133         sleep 2
8134         # wait for commitment of removal
8135         lru_resize_enable mdc
8136         lru_resize_enable osc
8137 }
8138 run_test 120g "Early Lock Cancel: performance test"
8139
8140 test_121() { #bug #10589
8141         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8142         rm -rf $DIR/$tfile
8143         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8144 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8145         lctl set_param fail_loc=0x310
8146         cancel_lru_locks osc > /dev/null
8147         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8148         lctl set_param fail_loc=0
8149         [[ $reads -eq $writes ]] ||
8150                 error "read $reads blocks, must be $writes blocks"
8151 }
8152 run_test 121 "read cancel race ========="
8153
8154 test_123a() { # was test 123, statahead(bug 11401)
8155         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8156         SLOWOK=0
8157         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8158             log "testing on UP system. Performance may be not as good as expected."
8159                         SLOWOK=1
8160         fi
8161
8162         rm -rf $DIR/$tdir
8163         test_mkdir -p $DIR/$tdir
8164         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8165         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8166         MULT=10
8167         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8168                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8169
8170                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8171                 lctl set_param -n llite.*.statahead_max 0
8172                 lctl get_param llite.*.statahead_max
8173                 cancel_lru_locks mdc
8174                 cancel_lru_locks osc
8175                 stime=`date +%s`
8176                 time ls -l $DIR/$tdir | wc -l
8177                 etime=`date +%s`
8178                 delta=$((etime - stime))
8179                 log "ls $i files without statahead: $delta sec"
8180                 lctl set_param llite.*.statahead_max=$max
8181
8182                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8183                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8184                 cancel_lru_locks mdc
8185                 cancel_lru_locks osc
8186                 stime=`date +%s`
8187                 time ls -l $DIR/$tdir | wc -l
8188                 etime=`date +%s`
8189                 delta_sa=$((etime - stime))
8190                 log "ls $i files with statahead: $delta_sa sec"
8191                 lctl get_param -n llite.*.statahead_stats
8192                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8193
8194                 [[ $swrong -lt $ewrong ]] &&
8195                         log "statahead was stopped, maybe too many locks held!"
8196                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8197
8198                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8199                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8200                     lctl set_param -n llite.*.statahead_max 0
8201                     lctl get_param llite.*.statahead_max
8202                     cancel_lru_locks mdc
8203                     cancel_lru_locks osc
8204                     stime=`date +%s`
8205                     time ls -l $DIR/$tdir | wc -l
8206                     etime=`date +%s`
8207                     delta=$((etime - stime))
8208                     log "ls $i files again without statahead: $delta sec"
8209                     lctl set_param llite.*.statahead_max=$max
8210                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8211                         if [  $SLOWOK -eq 0 ]; then
8212                                 error "ls $i files is slower with statahead!"
8213                         else
8214                                 log "ls $i files is slower with statahead!"
8215                         fi
8216                         break
8217                     fi
8218                 fi
8219
8220                 [ $delta -gt 20 ] && break
8221                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8222                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8223         done
8224         log "ls done"
8225
8226         stime=`date +%s`
8227         rm -r $DIR/$tdir
8228         sync
8229         etime=`date +%s`
8230         delta=$((etime - stime))
8231         log "rm -r $DIR/$tdir/: $delta seconds"
8232         log "rm done"
8233         lctl get_param -n llite.*.statahead_stats
8234 }
8235 run_test 123a "verify statahead work"
8236
8237 test_123b () { # statahead(bug 15027)
8238         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8239         test_mkdir -p $DIR/$tdir
8240         createmany -o $DIR/$tdir/$tfile-%d 1000
8241
8242         cancel_lru_locks mdc
8243         cancel_lru_locks osc
8244
8245 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8246         lctl set_param fail_loc=0x80000803
8247         ls -lR $DIR/$tdir > /dev/null
8248         log "ls done"
8249         lctl set_param fail_loc=0x0
8250         lctl get_param -n llite.*.statahead_stats
8251         rm -r $DIR/$tdir
8252         sync
8253
8254 }
8255 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8256
8257 test_124a() {
8258         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8259         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8260                 skip "no lru resize on server" && return 0
8261         local NR=2000
8262         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8263
8264         log "create $NR files at $DIR/$tdir"
8265         createmany -o $DIR/$tdir/f $NR ||
8266                 error "failed to create $NR files in $DIR/$tdir"
8267
8268         cancel_lru_locks mdc
8269         ls -l $DIR/$tdir > /dev/null
8270
8271         local NSDIR=""
8272         local LRU_SIZE=0
8273         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8274                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8275                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8276                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8277                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8278                         log "NSDIR=$NSDIR"
8279                         log "NS=$(basename $NSDIR)"
8280                         break
8281                 fi
8282         done
8283
8284         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8285                 skip "Not enough cached locks created!"
8286                 return 0
8287         fi
8288         log "LRU=$LRU_SIZE"
8289
8290         local SLEEP=30
8291
8292         # We know that lru resize allows one client to hold $LIMIT locks
8293         # for 10h. After that locks begin to be killed by client.
8294         local MAX_HRS=10
8295         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8296         log "LIMIT=$LIMIT"
8297         if [ $LIMIT -lt $LRU_SIZE ]; then
8298             skip "Limit is too small $LIMIT"
8299             return 0
8300         fi
8301
8302         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8303         # killing locks. Some time was spent for creating locks. This means
8304         # that up to the moment of sleep finish we must have killed some of
8305         # them (10-100 locks). This depends on how fast ther were created.
8306         # Many of them were touched in almost the same moment and thus will
8307         # be killed in groups.
8308         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8309
8310         # Use $LRU_SIZE_B here to take into account real number of locks
8311         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8312         local LRU_SIZE_B=$LRU_SIZE
8313         log "LVF=$LVF"
8314         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8315         log "OLD_LVF=$OLD_LVF"
8316         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8317
8318         # Let's make sure that we really have some margin. Client checks
8319         # cached locks every 10 sec.
8320         SLEEP=$((SLEEP+20))
8321         log "Sleep ${SLEEP} sec"
8322         local SEC=0
8323         while ((SEC<$SLEEP)); do
8324                 echo -n "..."
8325                 sleep 5
8326                 SEC=$((SEC+5))
8327                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8328                 echo -n "$LRU_SIZE"
8329         done
8330         echo ""
8331         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8332         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8333
8334         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8335                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8336                 unlinkmany $DIR/$tdir/f $NR
8337                 return
8338         }
8339
8340         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8341         log "unlink $NR files at $DIR/$tdir"
8342         unlinkmany $DIR/$tdir/f $NR
8343 }
8344 run_test 124a "lru resize ======================================="
8345
8346 get_max_pool_limit()
8347 {
8348         local limit=$($LCTL get_param \
8349                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8350         local max=0
8351         for l in $limit; do
8352                 if [[ $l -gt $max ]]; then
8353                         max=$l
8354                 fi
8355         done
8356         echo $max
8357 }
8358
8359 test_124b() {
8360         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8361         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8362                 skip "no lru resize on server" && return 0
8363
8364         LIMIT=$(get_max_pool_limit)
8365
8366         NR=$(($(default_lru_size)*20))
8367         if [[ $NR -gt $LIMIT ]]; then
8368                 log "Limit lock number by $LIMIT locks"
8369                 NR=$LIMIT
8370         fi
8371         lru_resize_disable mdc
8372         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8373                 error "failed to create $DIR/$tdir/disable_lru_resize"
8374
8375         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8376         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8377         cancel_lru_locks mdc
8378         stime=`date +%s`
8379         PID=""
8380         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8381         PID="$PID $!"
8382         sleep 2
8383         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8384         PID="$PID $!"
8385         sleep 2
8386         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8387         PID="$PID $!"
8388         wait $PID
8389         etime=`date +%s`
8390         nolruresize_delta=$((etime-stime))
8391         log "ls -la time: $nolruresize_delta seconds"
8392         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8393         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8394
8395         lru_resize_enable mdc
8396         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8397                 error "failed to create $DIR/$tdir/enable_lru_resize"
8398
8399         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8400         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8401         cancel_lru_locks mdc
8402         stime=`date +%s`
8403         PID=""
8404         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8405         PID="$PID $!"
8406         sleep 2
8407         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8408         PID="$PID $!"
8409         sleep 2
8410         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8411         PID="$PID $!"
8412         wait $PID
8413         etime=`date +%s`
8414         lruresize_delta=$((etime-stime))
8415         log "ls -la time: $lruresize_delta seconds"
8416         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8417
8418         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8419                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8420         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8421                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8422         else
8423                 log "lru resize performs the same with no lru resize"
8424         fi
8425         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8426 }
8427 run_test 124b "lru resize (performance test) ======================="
8428
8429 test_124c() {
8430         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8431         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8432                 skip "no lru resize on server" && return 0
8433
8434         # cache ununsed locks on client
8435         local nr=100
8436         cancel_lru_locks mdc
8437         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8438         createmany -o $DIR/$tdir/f $nr ||
8439                 error "failed to create $nr files in $DIR/$tdir"
8440         ls -l $DIR/$tdir > /dev/null
8441
8442         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
8443         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
8444         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
8445         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
8446         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
8447
8448         # set lru_max_age to 1 sec
8449         $LCTL set_param $nsdir.lru_max_age=1000 # jiffies
8450         echo "sleep $((recalc_p * 2)) seconds..."
8451         sleep $((recalc_p * 2))
8452
8453         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
8454         # restore lru_max_age
8455         $LCTL set_param -n $nsdir.lru_max_age $max_age
8456         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
8457         unlinkmany $DIR/$tdir/f $nr
8458 }
8459 run_test 124c "LRUR cancel very aged locks"
8460
8461 test_125() { # 13358
8462         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8463         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8464         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8465         test_mkdir -p $DIR/d125 || error "mkdir failed"
8466         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8467         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8468         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8469 }
8470 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8471
8472 test_126() { # bug 12829/13455
8473         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8474         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8475         $GSS && skip "must run as gss disabled" && return
8476
8477         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8478         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8479         rm -f $DIR/$tfile
8480         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8481 }
8482 run_test 126 "check that the fsgid provided by the client is taken into account"
8483
8484 test_127a() { # bug 15521
8485         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8486         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8487         $LCTL set_param osc.*.stats=0
8488         FSIZE=$((2048 * 1024))
8489         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8490         cancel_lru_locks osc
8491         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8492
8493         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8494         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8495                 echo "got $COUNT $NAME"
8496                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8497                 eval $NAME=$COUNT || error "Wrong proc format"
8498
8499                 case $NAME in
8500                         read_bytes|write_bytes)
8501                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8502                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8503                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8504                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8505                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8506                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8507                                 error "sumsquare is too small: $SUMSQ"
8508                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8509                                 error "sumsquare is too big: $SUMSQ"
8510                         ;;
8511                         *) ;;
8512                 esac
8513         done < $DIR/${tfile}.tmp
8514
8515         #check that we actually got some stats
8516         [ "$read_bytes" ] || error "Missing read_bytes stats"
8517         [ "$write_bytes" ] || error "Missing write_bytes stats"
8518         [ "$read_bytes" != 0 ] || error "no read done"
8519         [ "$write_bytes" != 0 ] || error "no write done"
8520 }
8521 run_test 127a "verify the client stats are sane"
8522
8523 test_127b() { # bug LU-333
8524         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8525         $LCTL set_param llite.*.stats=0
8526         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8527         # perform 2 reads and writes so MAX is different from SUM.
8528         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8529         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8530         cancel_lru_locks osc
8531         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8532         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8533
8534         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8535         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8536                 echo "got $COUNT $NAME"
8537                 eval $NAME=$COUNT || error "Wrong proc format"
8538
8539         case $NAME in
8540                 read_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                 write_bytes)
8547                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8548                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8549                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8550                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8551                         ;;
8552                         *) ;;
8553                 esac
8554         done < $TMP/${tfile}.tmp
8555
8556         #check that we actually got some stats
8557         [ "$read_bytes" ] || error "Missing read_bytes stats"
8558         [ "$write_bytes" ] || error "Missing write_bytes stats"
8559         [ "$read_bytes" != 0 ] || error "no read done"
8560         [ "$write_bytes" != 0 ] || error "no write done"
8561 }
8562 run_test 127b "verify the llite client stats are sane"
8563
8564 test_128() { # bug 15212
8565         touch $DIR/$tfile
8566         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8567                 find $DIR/$tfile
8568                 find $DIR/$tfile
8569         EOF
8570
8571         result=$(grep error $TMP/$tfile.log)
8572         rm -f $DIR/$tfile
8573         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8574 }
8575 run_test 128 "interactive lfs for 2 consecutive find's"
8576
8577 set_dir_limits () {
8578         local mntdev
8579         local canondev
8580         local node
8581
8582         local LDPROC=/proc/fs/ldiskfs
8583         local facets=$(get_facets MDS)
8584
8585         for facet in ${facets//,/ }; do
8586                 canondev=$(ldiskfs_canon \
8587                            *.$(convert_facet2label $facet).mntdev $facet)
8588                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8589                                                 LDPROC=/sys/fs/ldiskfs
8590                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8591         done
8592 }
8593
8594 test_129() {
8595         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8596         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8597                 skip "Only applicable to ldiskfs-based MDTs"
8598                 return
8599         fi
8600         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8601         ENOSPC=28
8602         EFBIG=27
8603
8604         rm -rf $DIR/$tdir
8605         test_mkdir -p $DIR/$tdir
8606
8607         # block size of mds1
8608         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8609         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8610         local MAX=$((MDSBLOCKSIZE * 3))
8611         set_dir_limits $MAX
8612         local I=$(stat -c%s "$DIR/$tdir")
8613         local J=0
8614         local STRIPE_COUNT=1
8615         [[ $MDSCOUNT -ge 2 ]] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8616         MAX=$((MAX*STRIPE_COUNT))
8617         while [[ $I -le $MAX ]]; do
8618                 $MULTIOP $DIR/$tdir/$J Oc
8619                 rc=$?
8620                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8621                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8622                 #and EFBIG for previous versions
8623                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8624                         set_dir_limits 0
8625                         echo "return code $rc received as expected"
8626                         multiop $DIR/$tdir/$J Oc ||
8627                                 error_exit "multiop failed w/o dir size limit"
8628
8629                         I=$(stat -c%s "$DIR/$tdir")
8630
8631                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8632                                         $(version_code 2.4.51) ]
8633                         then
8634                                 [[ $I -eq $MAX ]] && return 0
8635                         else
8636                                 [[ $I -gt $MAX ]] && return 0
8637                         fi
8638                         error_exit "current dir size $I, previous limit $MAX"
8639                 elif [ $rc -ne 0 ]; then
8640                         set_dir_limits 0
8641                         error_exit "return code $rc received instead of expected " \
8642                                    "$EFBIG or $ENOSPC, files in dir $I"
8643                 fi
8644                 J=$((J+1))
8645                 I=$(stat -c%s "$DIR/$tdir")
8646         done
8647
8648         set_dir_limits 0
8649         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8650 }
8651 run_test 129 "test directory size limit ========================"
8652
8653 OLDIFS="$IFS"
8654 cleanup_130() {
8655         trap 0
8656         IFS="$OLDIFS"
8657 }
8658
8659 test_130a() {
8660         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8661         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8662                 return
8663
8664         trap cleanup_130 EXIT RETURN
8665
8666         local fm_file=$DIR/$tfile
8667         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8668         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8669                 error "dd failed for $fm_file"
8670
8671         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8672         filefrag -ves $fm_file
8673         RC=$?
8674         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8675                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8676         [ $RC != 0 ] && error "filefrag $fm_file failed"
8677
8678         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8679                       grep -v "ext:" | grep -v "found")
8680         lun=$($GETSTRIPE -i $fm_file)
8681
8682         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8683         IFS=$'\n'
8684         tot_len=0
8685         for line in $filefrag_op
8686         do
8687                 frag_lun=`echo $line | cut -d: -f5`
8688                 ext_len=`echo $line | cut -d: -f4`
8689                 if (( $frag_lun != $lun )); then
8690                         cleanup_130
8691                         error "FIEMAP on 1-stripe file($fm_file) failed"
8692                         return
8693                 fi
8694                 (( tot_len += ext_len ))
8695         done
8696
8697         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8698                 cleanup_130
8699                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8700                 return
8701         fi
8702
8703         cleanup_130
8704
8705         echo "FIEMAP on single striped file succeeded"
8706 }
8707 run_test 130a "FIEMAP (1-stripe file)"
8708
8709 test_130b() {
8710         [ "$OSTCOUNT" -lt "2" ] &&
8711                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8712
8713         [ "$OSTCOUNT" -ge "10" ] &&
8714                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8715
8716         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8717         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8718                 return
8719
8720         trap cleanup_130 EXIT RETURN
8721
8722         local fm_file=$DIR/$tfile
8723         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8724         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8725                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8726
8727         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8728                 error "dd failed on $fm_file"
8729
8730         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8731         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8732                       grep -v "ext:" | grep -v "found")
8733
8734         last_lun=$(echo $filefrag_op | cut -d: -f5)
8735
8736         IFS=$'\n'
8737         tot_len=0
8738         num_luns=1
8739         for line in $filefrag_op
8740         do
8741                 frag_lun=`echo $line | cut -d: -f5`
8742                 ext_len=`echo $line | cut -d: -f4`
8743                 if (( $frag_lun != $last_lun )); then
8744                         if (( tot_len != 1024 )); then
8745                                 cleanup_130
8746                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8747                                 return
8748                         else
8749                                 (( num_luns += 1 ))
8750                                 tot_len=0
8751                         fi
8752                 fi
8753                 (( tot_len += ext_len ))
8754                 last_lun=$frag_lun
8755         done
8756         if (( num_luns != 2 || tot_len != 1024 )); then
8757                 cleanup_130
8758                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8759                 return
8760         fi
8761
8762         cleanup_130
8763
8764         echo "FIEMAP on 2-stripe file succeeded"
8765 }
8766 run_test 130b "FIEMAP (2-stripe file)"
8767
8768 test_130c() {
8769         [ "$OSTCOUNT" -lt "2" ] &&
8770                 skip_env "skipping FIEMAP on 2-stripe file" && return
8771
8772         [ "$OSTCOUNT" -ge "10" ] &&
8773                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8774
8775         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8776         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8777                 return
8778
8779         trap cleanup_130 EXIT RETURN
8780
8781         local fm_file=$DIR/$tfile
8782         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8783         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8784                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8785
8786         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8787
8788         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8789         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8790
8791         last_lun=`echo $filefrag_op | cut -d: -f5`
8792
8793         IFS=$'\n'
8794         tot_len=0
8795         num_luns=1
8796         for line in $filefrag_op
8797         do
8798                 frag_lun=`echo $line | cut -d: -f5`
8799                 ext_len=`echo $line | cut -d: -f4`
8800                 if (( $frag_lun != $last_lun )); then
8801                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8802                         if (( logical != 512 )); then
8803                                 cleanup_130
8804                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8805                                 return
8806                         fi
8807                         if (( tot_len != 512 )); then
8808                                 cleanup_130
8809                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8810                                 return
8811                         else
8812                                 (( num_luns += 1 ))
8813                                 tot_len=0
8814                         fi
8815                 fi
8816                 (( tot_len += ext_len ))
8817                 last_lun=$frag_lun
8818         done
8819         if (( num_luns != 2 || tot_len != 512 )); then
8820                 cleanup_130
8821                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8822                 return
8823         fi
8824
8825         cleanup_130
8826
8827         echo "FIEMAP on 2-stripe file with hole succeeded"
8828 }
8829 run_test 130c "FIEMAP (2-stripe file with hole)"
8830
8831 test_130d() {
8832         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8833
8834         [ "$OSTCOUNT" -ge "10" ] &&
8835                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8836
8837         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8838         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8839
8840         trap cleanup_130 EXIT RETURN
8841
8842         local fm_file=$DIR/$tfile
8843         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8844         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8845                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8846
8847         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8848         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8849                 error "dd failed on $fm_file"
8850
8851         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8852         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8853                 grep -v "ext:" | grep -v "found"`
8854
8855         last_lun=`echo $filefrag_op | cut -d: -f5`
8856
8857         IFS=$'\n'
8858         tot_len=0
8859         num_luns=1
8860         for line in $filefrag_op
8861         do
8862                 frag_lun=`echo $line | cut -d: -f5`
8863                 ext_len=`echo $line | cut -d: -f4`
8864                 if (( $frag_lun != $last_lun )); then
8865                         if (( tot_len != 1024 )); then
8866                                 cleanup_130
8867                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8868                                 return
8869                         else
8870                                 (( num_luns += 1 ))
8871                                 tot_len=0
8872                         fi
8873                 fi
8874                 (( tot_len += ext_len ))
8875                 last_lun=$frag_lun
8876         done
8877         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8878                 cleanup_130
8879                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8880                 return
8881         fi
8882
8883         cleanup_130
8884
8885         echo "FIEMAP on N-stripe file succeeded"
8886 }
8887 run_test 130d "FIEMAP (N-stripe file)"
8888
8889 test_130e() {
8890         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8891
8892         [ "$OSTCOUNT" -ge "10" ] &&
8893                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8894
8895         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8896         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8897
8898         trap cleanup_130 EXIT RETURN
8899
8900         local fm_file=$DIR/$tfile
8901         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8902         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8903                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8904
8905         NUM_BLKS=512
8906         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8907         for ((i = 0; i < $NUM_BLKS; i++))
8908         do
8909                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8910         done
8911
8912         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8913         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8914
8915         last_lun=`echo $filefrag_op | cut -d: -f5`
8916
8917         IFS=$'\n'
8918         tot_len=0
8919         num_luns=1
8920         for line in $filefrag_op
8921         do
8922                 frag_lun=`echo $line | cut -d: -f5`
8923                 ext_len=`echo $line | cut -d: -f4`
8924                 if (( $frag_lun != $last_lun )); then
8925                         if (( tot_len != $EXPECTED_LEN )); then
8926                                 cleanup_130
8927                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8928                                 return
8929                         else
8930                                 (( num_luns += 1 ))
8931                                 tot_len=0
8932                         fi
8933                 fi
8934                 (( tot_len += ext_len ))
8935                 last_lun=$frag_lun
8936         done
8937         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8938                 cleanup_130
8939                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8940                 return
8941         fi
8942
8943         cleanup_130
8944
8945         echo "FIEMAP with continuation calls succeeded"
8946 }
8947 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8948
8949 # Test for writev/readv
8950 test_131a() {
8951         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8952         error "writev test failed"
8953         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8954         error "readv failed"
8955         rm -f $DIR/$tfile
8956 }
8957 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8958
8959 test_131b() {
8960         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8961         error "append writev test failed"
8962         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8963         error "append writev test failed"
8964         rm -f $DIR/$tfile
8965 }
8966 run_test 131b "test append writev"
8967
8968 test_131c() {
8969         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8970         error "NOT PASS"
8971 }
8972 run_test 131c "test read/write on file w/o objects"
8973
8974 test_131d() {
8975         rwv -f $DIR/$tfile -w -n 1 1572864
8976         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8977         if [ "$NOB" != 1572864 ]; then
8978                 error "Short read filed: read $NOB bytes instead of 1572864"
8979         fi
8980         rm -f $DIR/$tfile
8981 }
8982 run_test 131d "test short read"
8983
8984 test_131e() {
8985         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8986         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8987         error "read hitting hole failed"
8988         rm -f $DIR/$tfile
8989 }
8990 run_test 131e "test read hitting hole"
8991
8992 check_stats() {
8993         local res
8994         local count
8995         case $1 in
8996         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8997                  ;;
8998         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8999                  ;;
9000         *) error "Wrong argument $1" ;;
9001         esac
9002         echo $res
9003         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
9004         # if the argument $3 is zero, it means any stat increment is ok.
9005         if [[ $3 -gt 0 ]]; then
9006                 count=$(echo $res | awk '{ print $2 }')
9007                 [[ $count -ne $3 ]] &&
9008                         error "The $2 counter on $1 is wrong - expected $3"
9009         fi
9010 }
9011
9012 test_133a() {
9013         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9014         remote_ost_nodsh && skip "remote OST with nodsh" && return
9015         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9016
9017         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9018                 { skip "MDS doesn't support rename stats"; return; }
9019         local testdir=$DIR/${tdir}/stats_testdir
9020         mkdir -p $DIR/${tdir}
9021
9022         # clear stats.
9023         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9024         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9025
9026         # verify mdt stats first.
9027         mkdir ${testdir} || error "mkdir failed"
9028         check_stats $SINGLEMDS "mkdir" 1
9029         touch ${testdir}/${tfile} || "touch failed"
9030         check_stats $SINGLEMDS "open" 1
9031         check_stats $SINGLEMDS "close" 1
9032         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
9033         check_stats $SINGLEMDS "mknod" 1
9034         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
9035         check_stats $SINGLEMDS "unlink" 1
9036         rm -f ${testdir}/${tfile} || error "file remove failed"
9037         check_stats $SINGLEMDS "unlink" 2
9038
9039         # remove working dir and check mdt stats again.
9040         rmdir ${testdir} || error "rmdir failed"
9041         check_stats $SINGLEMDS "rmdir" 1
9042
9043         local testdir1=$DIR/${tdir}/stats_testdir1
9044         mkdir -p ${testdir}
9045         mkdir -p ${testdir1}
9046         touch ${testdir1}/test1
9047         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
9048         check_stats $SINGLEMDS "crossdir_rename" 1
9049
9050         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
9051         check_stats $SINGLEMDS "samedir_rename" 1
9052
9053         rm -rf $DIR/${tdir}
9054 }
9055 run_test 133a "Verifying MDT stats ========================================"
9056
9057 test_133b() {
9058         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9059         remote_ost_nodsh && skip "remote OST with nodsh" && return
9060         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9061         local testdir=$DIR/${tdir}/stats_testdir
9062         mkdir -p ${testdir} || error "mkdir failed"
9063         touch ${testdir}/${tfile} || "touch failed"
9064         cancel_lru_locks mdc
9065
9066         # clear stats.
9067         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9068         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9069
9070         # extra mdt stats verification.
9071         chmod 444 ${testdir}/${tfile} || error "chmod failed"
9072         check_stats $SINGLEMDS "setattr" 1
9073         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9074         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
9075         then            # LU-1740
9076                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
9077                 check_stats $SINGLEMDS "getattr" 1
9078         fi
9079         $LFS df || error "lfs failed"
9080         check_stats $SINGLEMDS "statfs" 1
9081
9082         rm -rf $DIR/${tdir}
9083 }
9084 run_test 133b "Verifying extra MDT stats =================================="
9085
9086 test_133c() {
9087         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9088         remote_ost_nodsh && skip "remote OST with nodsh" && return
9089         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9090         local testdir=$DIR/${tdir}/stats_testdir
9091         test_mkdir -p ${testdir} || error "mkdir failed"
9092
9093         # verify obdfilter stats.
9094         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9095         sync
9096         cancel_lru_locks osc
9097         wait_delete_completed
9098
9099         # clear stats.
9100         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9101         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9102
9103         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
9104         sync
9105         cancel_lru_locks osc
9106         check_stats ost "write" 1
9107
9108         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9109         check_stats ost "read" 1
9110
9111         > ${testdir}/${tfile} || error "truncate failed"
9112         check_stats ost "punch" 1
9113
9114         rm -f ${testdir}/${tfile} || error "file remove failed"
9115         wait_delete_completed
9116         check_stats ost "destroy" 1
9117
9118         rm -rf $DIR/${tdir}
9119 }
9120 run_test 133c "Verifying OST stats ========================================"
9121
9122 order_2() {
9123         local value=$1
9124         local orig=$value
9125         local order=1
9126
9127         while [ $value -ge 2 ]; do
9128                 order=$((order*2))
9129                 value=$((value/2))
9130         done
9131
9132         if [ $orig -gt $order ]; then
9133                 order=$((order*2))
9134         fi
9135         echo $order
9136 }
9137
9138 size_in_KMGT() {
9139     local value=$1
9140     local size=('K' 'M' 'G' 'T');
9141     local i=0
9142     local size_string=$value
9143
9144     while [ $value -ge 1024 ]; do
9145         if [ $i -gt 3 ]; then
9146             #T is the biggest unit we get here, if that is bigger,
9147             #just return XXXT
9148             size_string=${value}T
9149             break
9150         fi
9151         value=$((value >> 10))
9152         if [ $value -lt 1024 ]; then
9153             size_string=${value}${size[$i]}
9154             break
9155         fi
9156         i=$((i + 1))
9157     done
9158
9159     echo $size_string
9160 }
9161
9162 get_rename_size() {
9163     local size=$1
9164     local context=${2:-.}
9165     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9166                 grep -A1 $context |
9167                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9168     echo $sample
9169 }
9170
9171 test_133d() {
9172         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9173         remote_ost_nodsh && skip "remote OST with nodsh" && return
9174         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9175         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9176         { skip "MDS doesn't support rename stats"; return; }
9177
9178         local testdir1=$DIR/${tdir}/stats_testdir1
9179         local testdir2=$DIR/${tdir}/stats_testdir2
9180
9181         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9182
9183         mkdir -p ${testdir1} || error "mkdir failed"
9184         mkdir -p ${testdir2} || error "mkdir failed"
9185
9186         createmany -o $testdir1/test 512 || error "createmany failed"
9187
9188         # check samedir rename size
9189         mv ${testdir1}/test0 ${testdir1}/test_0
9190
9191         local testdir1_size=$(ls -l $DIR/${tdir} |
9192                 awk '/stats_testdir1/ {print $5}')
9193         local testdir2_size=$(ls -l $DIR/${tdir} |
9194                 awk '/stats_testdir2/ {print $5}')
9195
9196         testdir1_size=$(order_2 $testdir1_size)
9197         testdir2_size=$(order_2 $testdir2_size)
9198
9199         testdir1_size=$(size_in_KMGT $testdir1_size)
9200         testdir2_size=$(size_in_KMGT $testdir2_size)
9201
9202         echo "source rename dir size: ${testdir1_size}"
9203         echo "target rename dir size: ${testdir2_size}"
9204
9205         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9206         eval $cmd || error "$cmd failed"
9207         local samedir=$($cmd | grep 'same_dir')
9208         local same_sample=$(get_rename_size $testdir1_size)
9209         [ -z "$samedir" ] && error "samedir_rename_size count error"
9210         [[ $same_sample -eq 1 ]] ||
9211                 error "samedir_rename_size error $same_sample"
9212         echo "Check same dir rename stats success"
9213
9214         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9215
9216         # check crossdir rename size
9217         mv ${testdir1}/test_0 ${testdir2}/test_0
9218
9219         testdir1_size=$(ls -l $DIR/${tdir} |
9220                 awk '/stats_testdir1/ {print $5}')
9221         testdir2_size=$(ls -l $DIR/${tdir} |
9222                 awk '/stats_testdir2/ {print $5}')
9223
9224         testdir1_size=$(order_2 $testdir1_size)
9225         testdir2_size=$(order_2 $testdir2_size)
9226
9227         testdir1_size=$(size_in_KMGT $testdir1_size)
9228         testdir2_size=$(size_in_KMGT $testdir2_size)
9229
9230         echo "source rename dir size: ${testdir1_size}"
9231         echo "target rename dir size: ${testdir2_size}"
9232
9233         eval $cmd || error "$cmd failed"
9234         local crossdir=$($cmd | grep 'crossdir')
9235         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9236         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9237         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9238         [[ $src_sample -eq 1 ]] ||
9239                 error "crossdir_rename_size error $src_sample"
9240         [[ $tgt_sample -eq 1 ]] ||
9241                 error "crossdir_rename_size error $tgt_sample"
9242         echo "Check cross dir rename stats success"
9243         rm -rf $DIR/${tdir}
9244 }
9245 run_test 133d "Verifying rename_stats ========================================"
9246
9247 test_133e() {
9248         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9249         remote_ost_nodsh && skip "remote OST with nodsh" && return
9250         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9251         local testdir=$DIR/${tdir}/stats_testdir
9252         local ctr f0 f1 bs=32768 count=42 sum
9253
9254         mkdir -p ${testdir} || error "mkdir failed"
9255
9256         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9257
9258         for ctr in {write,read}_bytes; do
9259                 sync
9260                 cancel_lru_locks osc
9261
9262                 do_facet ost1 $LCTL set_param -n \
9263                         "obdfilter.*.exports.clear=clear"
9264
9265                 if [ $ctr = write_bytes ]; then
9266                         f0=/dev/zero
9267                         f1=${testdir}/${tfile}
9268                 else
9269                         f0=${testdir}/${tfile}
9270                         f1=/dev/null
9271                 fi
9272
9273                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9274                         error "dd failed"
9275                 sync
9276                 cancel_lru_locks osc
9277
9278                 sum=$(do_facet ost1 $LCTL get_param \
9279                         "obdfilter.*.exports.*.stats" |
9280                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9281                                 $1 == ctr { sum += $7 }
9282                                 END { printf("%0.0f", sum) }')
9283
9284                 if ((sum != bs * count)); then
9285                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9286                 fi
9287         done
9288
9289         rm -rf $DIR/${tdir}
9290 }
9291 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9292
9293 test_133f() {
9294         local proc_dirs
9295
9296         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9297 /sys/fs/lustre/ /sys/fs/lnet/"
9298         local dir
9299         for dir in $dirs; do
9300                 if [ -d $dir ]; then
9301                         proc_dirs="$proc_dirs $dir"
9302                 fi
9303         done
9304
9305         local facet
9306
9307         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9308         remote_ost_nodsh && skip "remote OST with nodsh" && return
9309         # First without trusting modes.
9310         find $proc_dirs -exec cat '{}' \; &> /dev/null
9311
9312         # Second verifying readability.
9313         find $proc_dirs \
9314                 -type f \
9315                 -exec cat '{}' \; &> /dev/null ||
9316                         error "proc file read failed"
9317
9318         for facet in $SINGLEMDS ost1; do
9319                 do_facet $facet find $proc_dirs \
9320                         ! -name req_history \
9321                         -exec cat '{}' \\\; &> /dev/null
9322
9323                 do_facet $facet find $proc_dirs \
9324                         ! -name req_history \
9325                         -type f \
9326                         -exec cat '{}' \\\; &> /dev/null ||
9327                                 error "proc file read failed"
9328         done
9329 }
9330 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9331
9332 test_133g() {
9333         local proc_dirs
9334
9335         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9336 /sys/fs/lustre/ /sys/fs/lnet/"
9337         local dir
9338         for dir in $dirs; do
9339                 if [ -d $dir ]; then
9340                         proc_dirs="$proc_dirs $dir"
9341                 fi
9342         done
9343
9344         local facet
9345
9346         # Second verifying readability.
9347         find $proc_dirs \
9348                 -type f \
9349                 -not -name force_lbug \
9350                 -not -name changelog_mask \
9351                 -exec badarea_io '{}' \; &> /dev/null ||
9352                 error "find $proc_dirs failed"
9353
9354         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
9355                 skip "Too old lustre on MDS" && return
9356
9357         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
9358                 skip "Too old lustre on ost1" && return
9359
9360         for facet in $SINGLEMDS ost1; do
9361                 do_facet $facet find $proc_dirs \
9362                         -type f \
9363                         -not -name force_lbug \
9364                         -not -name changelog_mask \
9365                         -exec badarea_io '{}' \\\; &> /dev/null ||
9366                 error "$facet find $proc_dirs failed"
9367
9368         done
9369
9370         # remount the FS in case writes/reads /proc break the FS
9371         cleanup || error "failed to unmount"
9372         setup || error "failed to setup"
9373         true
9374 }
9375 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9376
9377 test_140() { #bug-17379
9378         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9379         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
9380         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
9381         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
9382
9383         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9384         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9385         local i=0
9386         while i=`expr $i + 1`; do
9387                 test_mkdir -p $i || error "Creating dir $i"
9388                 cd $i || error "Changing to $i"
9389                 ln -s ../stat stat || error "Creating stat symlink"
9390                 # Read the symlink until ELOOP present,
9391                 # not LBUGing the system is considered success,
9392                 # we didn't overrun the stack.
9393                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9394                 [ $ret -ne 0 ] && {
9395                         if [ $ret -eq 40 ]; then
9396                                 break  # -ELOOP
9397                         else
9398                                 error "Open stat symlink"
9399                                 return
9400                         fi
9401                 }
9402         done
9403         i=`expr $i - 1`
9404         echo "The symlink depth = $i"
9405         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9406                                         error "Invalid symlink depth"
9407
9408         # Test recursive symlink
9409         ln -s symlink_self symlink_self
9410         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9411         echo "open symlink_self returns $ret"
9412         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9413 }
9414 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9415
9416 test_150() {
9417         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9418         local TF="$TMP/$tfile"
9419
9420         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9421         cp $TF $DIR/$tfile
9422         cancel_lru_locks osc
9423         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9424         remount_client $MOUNT
9425         df -P $MOUNT
9426         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9427
9428         $TRUNCATE $TF 6000
9429         $TRUNCATE $DIR/$tfile 6000
9430         cancel_lru_locks osc
9431         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9432
9433         echo "12345" >>$TF
9434         echo "12345" >>$DIR/$tfile
9435         cancel_lru_locks osc
9436         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9437
9438         echo "12345" >>$TF
9439         echo "12345" >>$DIR/$tfile
9440         cancel_lru_locks osc
9441         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9442
9443         rm -f $TF
9444         true
9445 }
9446 run_test 150 "truncate/append tests"
9447
9448 #LU-2902 roc_hit was not able to read all values from lproc
9449 function roc_hit_init() {
9450         local list=$(comma_list $(osts_nodes))
9451         local dir=$DIR/$tdir-check
9452         local file=$dir/file
9453         local BEFORE
9454         local AFTER
9455         local idx
9456
9457         test_mkdir -p $dir
9458         #use setstripe to do a write to every ost
9459         for i in $(seq 0 $((OSTCOUNT-1))); do
9460                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9461                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9462                 idx=$(printf %04x $i)
9463                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9464                         awk '$1 == "cache_access" {sum += $7}
9465                                 END { printf("%0.0f", sum) }')
9466
9467                 cancel_lru_locks osc
9468                 cat $file >/dev/null
9469
9470                 AFTER=$(get_osd_param $list *OST*$idx stats |
9471                         awk '$1 == "cache_access" {sum += $7}
9472                                 END { printf("%0.0f", sum) }')
9473
9474                 echo BEFORE:$BEFORE AFTER:$AFTER
9475                 if ! let "AFTER - BEFORE == 4"; then
9476                         rm -rf $dir
9477                         error "roc_hit is not safe to use"
9478                 fi
9479                 rm $file
9480         done
9481
9482         rm -rf $dir
9483 }
9484
9485 function roc_hit() {
9486         local list=$(comma_list $(osts_nodes))
9487         echo $(get_osd_param $list '' stats |
9488                 awk '$1 == "cache_hit" {sum += $7}
9489                         END { printf("%0.0f", sum) }')
9490 }
9491
9492 function set_cache() {
9493         local on=1
9494
9495         if [ "$2" == "off" ]; then
9496                 on=0;
9497         fi
9498         local list=$(comma_list $(osts_nodes))
9499         set_osd_param $list '' $1_cache_enable $on
9500
9501         cancel_lru_locks osc
9502 }
9503
9504 test_151() {
9505         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9506         remote_ost_nodsh && skip "remote OST with nodsh" && return
9507
9508         local CPAGES=3
9509         local list=$(comma_list $(osts_nodes))
9510
9511         # check whether obdfilter is cache capable at all
9512         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9513                 echo "not cache-capable obdfilter"
9514                 return 0
9515         fi
9516
9517         # check cache is enabled on all obdfilters
9518         if get_osd_param $list '' read_cache_enable | grep 0; then
9519                 echo "oss cache is disabled"
9520                 return 0
9521         fi
9522
9523         set_osd_param $list '' writethrough_cache_enable 1
9524
9525         # check write cache is enabled on all obdfilters
9526         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9527                 echo "oss write cache is NOT enabled"
9528                 return 0
9529         fi
9530
9531         roc_hit_init
9532
9533         #define OBD_FAIL_OBD_NO_LRU  0x609
9534         do_nodes $list $LCTL set_param fail_loc=0x609
9535
9536         # pages should be in the case right after write
9537         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9538                 error "dd failed"
9539
9540         local BEFORE=$(roc_hit)
9541         cancel_lru_locks osc
9542         cat $DIR/$tfile >/dev/null
9543         local AFTER=$(roc_hit)
9544
9545         do_nodes $list $LCTL set_param fail_loc=0
9546
9547         if ! let "AFTER - BEFORE == CPAGES"; then
9548                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9549         fi
9550
9551         # the following read invalidates the cache
9552         cancel_lru_locks osc
9553         set_osd_param $list '' read_cache_enable 0
9554         cat $DIR/$tfile >/dev/null
9555
9556         # now data shouldn't be found in the cache
9557         BEFORE=$(roc_hit)
9558         cancel_lru_locks osc
9559         cat $DIR/$tfile >/dev/null
9560         AFTER=$(roc_hit)
9561         if let "AFTER - BEFORE != 0"; then
9562                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9563         fi
9564
9565         set_osd_param $list '' read_cache_enable 1
9566         rm -f $DIR/$tfile
9567 }
9568 run_test 151 "test cache on oss and controls ==============================="
9569
9570 test_152() {
9571         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9572         local TF="$TMP/$tfile"
9573
9574         # simulate ENOMEM during write
9575 #define OBD_FAIL_OST_NOMEM      0x226
9576         lctl set_param fail_loc=0x80000226
9577         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9578         cp $TF $DIR/$tfile
9579         sync || error "sync failed"
9580         lctl set_param fail_loc=0
9581
9582         # discard client's cache
9583         cancel_lru_locks osc
9584
9585         # simulate ENOMEM during read
9586         lctl set_param fail_loc=0x80000226
9587         cmp $TF $DIR/$tfile || error "cmp failed"
9588         lctl set_param fail_loc=0
9589
9590         rm -f $TF
9591 }
9592 run_test 152 "test read/write with enomem ============================"
9593
9594 test_153() {
9595         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9596 }
9597 run_test 153 "test if fdatasync does not crash ======================="
9598
9599 dot_lustre_fid_permission_check() {
9600         local fid=$1
9601         local ffid=$MOUNT/.lustre/fid/$fid
9602         local test_dir=$2
9603
9604         echo "stat fid $fid"
9605         stat $ffid > /dev/null || error "stat $ffid failed."
9606         echo "touch fid $fid"
9607         touch $ffid || error "touch $ffid failed."
9608         echo "write to fid $fid"
9609         cat /etc/hosts > $ffid || error "write $ffid failed."
9610         echo "read fid $fid"
9611         diff /etc/hosts $ffid || error "read $ffid failed."
9612         echo "append write to fid $fid"
9613         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9614         echo "rename fid $fid"
9615         mv $ffid $test_dir/$tfile.1 &&
9616                 error "rename $ffid to $tfile.1 should fail."
9617         touch $test_dir/$tfile.1
9618         mv $test_dir/$tfile.1 $ffid &&
9619                 error "rename $tfile.1 to $ffid should fail."
9620         rm -f $test_dir/$tfile.1
9621         echo "truncate fid $fid"
9622         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9623         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9624                 echo "link fid $fid"
9625                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9626         fi
9627         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9628                 echo "setfacl fid $fid"
9629                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9630                 echo "getfacl fid $fid"
9631                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9632         fi
9633         echo "unlink fid $fid"
9634         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9635         echo "mknod fid $fid"
9636         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9637
9638         fid=[0xf00000400:0x1:0x0]
9639         ffid=$MOUNT/.lustre/fid/$fid
9640
9641         echo "stat non-exist fid $fid"
9642         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9643         echo "write to non-exist fid $fid"
9644         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9645         echo "link new fid $fid"
9646         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9647
9648         mkdir -p $test_dir/$tdir
9649         touch $test_dir/$tdir/$tfile
9650         fid=$($LFS path2fid $test_dir/$tdir)
9651         rc=$?
9652         [ $rc -ne 0 ] &&
9653                 error "error: could not get fid for $test_dir/$dir/$tfile."
9654
9655         ffid=$MOUNT/.lustre/fid/$fid
9656
9657         echo "ls $fid"
9658         ls $ffid > /dev/null || error "ls $ffid failed."
9659         echo "touch $fid/$tfile.1"
9660         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9661
9662         echo "touch $MOUNT/.lustre/fid/$tfile"
9663         touch $MOUNT/.lustre/fid/$tfile && \
9664                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9665
9666         echo "setxattr to $MOUNT/.lustre/fid"
9667         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9668
9669         echo "listxattr for $MOUNT/.lustre/fid"
9670         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9671
9672         echo "delxattr from $MOUNT/.lustre/fid"
9673         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9674
9675         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9676         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9677                 error "touch invalid fid should fail."
9678
9679         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9680         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9681                 error "touch non-normal fid should fail."
9682
9683         echo "rename $tdir to $MOUNT/.lustre/fid"
9684         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9685                 error "rename to $MOUNT/.lustre/fid should fail."
9686
9687         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9688         then            # LU-3547
9689                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9690                 local new_obf_mode=777
9691
9692                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9693                 chmod $new_obf_mode $DIR/.lustre/fid ||
9694                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9695
9696                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9697                 [ $obf_mode -eq $new_obf_mode ] ||
9698                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9699
9700                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9701                 chmod $old_obf_mode $DIR/.lustre/fid ||
9702                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9703         fi
9704
9705         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9706         fid=$($LFS path2fid $test_dir/$tfile-2)
9707
9708         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
9709         then # LU-5424
9710                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9711                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
9712                         error "create lov data thru .lustre failed"
9713         fi
9714         echo "cp /etc/passwd $test_dir/$tfile-2"
9715         cp /etc/passwd $test_dir/$tfile-2 ||
9716                 error "copy to $test_dir/$tfile-2 failed."
9717         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9718         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9719                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9720
9721         rm -rf $test_dir/tfile.lnk
9722         rm -rf $test_dir/$tfile-2
9723 }
9724
9725 test_154A() {
9726         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9727                 skip "Need MDS version at least 2.4.1" && return
9728
9729         touch $DIR/$tfile
9730         local FID=$($LFS path2fid $DIR/$tfile)
9731         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9732
9733         # check that we get the same pathname back
9734         local FOUND=$($LFS fid2path $MOUNT "$FID")
9735         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9736         [ "$FOUND" != "$DIR/$tfile" ] &&
9737                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9738
9739         rm -rf $DIR/$tfile
9740 }
9741 run_test 154A "lfs path2fid and fid2path basic checks"
9742
9743 test_154a() {
9744         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9745         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9746                 { skip "Need MDS version at least 2.2.51"; return 0; }
9747         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9748
9749         cp /etc/hosts $DIR/$tfile
9750
9751         fid=$($LFS path2fid $DIR/$tfile)
9752         rc=$?
9753         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9754
9755         dot_lustre_fid_permission_check "$fid" $DIR ||
9756                 error "dot lustre permission check $fid failed"
9757
9758         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9759
9760         touch $MOUNT/.lustre/file &&
9761                 error "creation is not allowed under .lustre"
9762
9763         mkdir $MOUNT/.lustre/dir &&
9764                 error "mkdir is not allowed under .lustre"
9765
9766         rm -rf $DIR/$tfile
9767 }
9768 run_test 154a "Open-by-FID"
9769
9770 test_154b() {
9771         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9772         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9773                 { skip "Need MDS version at least 2.2.51"; return 0; }
9774
9775         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9776
9777         local remote_dir=$DIR/$tdir/remote_dir
9778         local MDTIDX=1
9779         local rc=0
9780
9781         mkdir -p $DIR/$tdir
9782         $LFS mkdir -i $MDTIDX $remote_dir ||
9783                 error "create remote directory failed"
9784
9785         cp /etc/hosts $remote_dir/$tfile
9786
9787         fid=$($LFS path2fid $remote_dir/$tfile)
9788         rc=$?
9789         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9790
9791         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9792                 error "dot lustre permission check $fid failed"
9793         rm -rf $DIR/$tdir
9794 }
9795 run_test 154b "Open-by-FID for remote directory"
9796
9797 test_154c() {
9798         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9799                 skip "Need MDS version at least 2.4.1" && return
9800
9801         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9802         local FID1=$($LFS path2fid $DIR/$tfile.1)
9803         local FID2=$($LFS path2fid $DIR/$tfile.2)
9804         local FID3=$($LFS path2fid $DIR/$tfile.3)
9805
9806         local N=1
9807         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9808                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9809                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9810                 local want=FID$N
9811                 [ "$FID" = "${!want}" ] ||
9812                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9813                 N=$((N + 1))
9814         done
9815
9816         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
9817         do
9818                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
9819                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
9820                 N=$((N + 1))
9821         done
9822 }
9823 run_test 154c "lfs path2fid and fid2path multiple arguments"
9824
9825 test_154d() {
9826         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
9827                 skip "Need MDS version at least 2.5.53" && return
9828
9829         if remote_mds; then
9830                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
9831         else
9832                 nid="0@lo"
9833         fi
9834         local proc_ofile="mdt.*.exports.'$nid'.open_files"
9835         local fd
9836         local cmd
9837
9838         rm -f $DIR/$tfile
9839         touch $DIR/$tfile
9840
9841         local fid=$($LFS path2fid $DIR/$tfile)
9842         # Open the file
9843         fd=$(free_fd)
9844         cmd="exec $fd<$DIR/$tfile"
9845         eval $cmd
9846         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
9847         echo "$fid_list" | grep "$fid"
9848         rc=$?
9849
9850         cmd="exec $fd>/dev/null"
9851         eval $cmd
9852         if [ $rc -ne 0 ]; then
9853                 error "FID $fid not found in open files list $fid_list"
9854         fi
9855 }
9856 run_test 154d "Verify open file fid"
9857
9858 test_154e()
9859 {
9860         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
9861                 skip "Need MDS version at least 2.6.50" && return
9862
9863         if ls -a $MOUNT | grep -q '^\.lustre$'; then
9864                 error ".lustre returned by readdir"
9865         fi
9866 }
9867 run_test 154e ".lustre is not returned by readdir"
9868
9869 test_154f() {
9870         # create parent directory on a single MDT to avoid cross-MDT hardlinks
9871         test_mkdir -p -c1 $DIR/$tdir/d
9872         # test dirs inherit from its stripe
9873         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
9874         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
9875         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
9876         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
9877         touch $DIR/f
9878
9879         # get fid of parents
9880         local FID0=$($LFS path2fid $DIR/$tdir/d)
9881         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
9882         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
9883         local FID3=$($LFS path2fid $DIR)
9884
9885         # check that path2fid --parents returns expected <parent_fid>/name
9886         # 1) test for a directory (single parent)
9887         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
9888         [ "$parent" == "$FID0/foo1" ] ||
9889                 error "expected parent: $FID0/foo1, got: $parent"
9890
9891         # 2) test for a file with nlink > 1 (multiple parents)
9892         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
9893         echo "$parent" | grep -F "$FID1/$tfile" ||
9894                 error "$FID1/$tfile not returned in parent list"
9895         echo "$parent" | grep -F "$FID2/link" ||
9896                 error "$FID2/link not returned in parent list"
9897
9898         # 3) get parent by fid
9899         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
9900         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
9901         echo "$parent" | grep -F "$FID1/$tfile" ||
9902                 error "$FID1/$tfile not returned in parent list (by fid)"
9903         echo "$parent" | grep -F "$FID2/link" ||
9904                 error "$FID2/link not returned in parent list (by fid)"
9905
9906         # 4) test for entry in root directory
9907         parent=$($LFS path2fid --parents $DIR/f)
9908         echo "$parent" | grep -F "$FID3/f" ||
9909                 error "$FID3/f not returned in parent list"
9910
9911         # 5) test it on root directory
9912         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
9913                 error "$MOUNT should not have parents"
9914
9915         # enable xattr caching and check that linkea is correctly updated
9916         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
9917         save_lustre_params client "llite.*.xattr_cache" > $save
9918         lctl set_param llite.*.xattr_cache 1
9919
9920         # 6.1) linkea update on rename
9921         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
9922
9923         # get parents by fid
9924         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
9925         # foo1 should no longer be returned in parent list
9926         echo "$parent" | grep -F "$FID1" &&
9927                 error "$FID1 should no longer be in parent list"
9928         # the new path should appear
9929         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
9930                 error "$FID2/$tfile.moved is not in parent list"
9931
9932         # 6.2) linkea update on unlink
9933         rm -f $DIR/$tdir/d/foo2/link
9934         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
9935         # foo2/link should no longer be returned in parent list
9936         echo "$parent" | grep -F "$FID2/link" &&
9937                 error "$FID2/link should no longer be in parent list"
9938         true
9939
9940         rm -f $DIR/f
9941         restore_lustre_params < $save
9942 }
9943 run_test 154f "get parent fids by reading link ea"
9944
9945 test_154g()
9946 {
9947         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) ]] ||
9948                 { skip "Need MDS version at least 2.6.92"; return 0; }
9949
9950         mkdir -p $DIR/$tdir
9951         llapi_fid_test -d $DIR/$tdir
9952 }
9953 run_test 154g "various llapi FID tests"
9954
9955 test_155_small_load() {
9956     local temp=$TMP/$tfile
9957     local file=$DIR/$tfile
9958
9959     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
9960         error "dd of=$temp bs=6096 count=1 failed"
9961     cp $temp $file
9962     cancel_lru_locks osc
9963     cmp $temp $file || error "$temp $file differ"
9964
9965     $TRUNCATE $temp 6000
9966     $TRUNCATE $file 6000
9967     cmp $temp $file || error "$temp $file differ (truncate1)"
9968
9969     echo "12345" >>$temp
9970     echo "12345" >>$file
9971     cmp $temp $file || error "$temp $file differ (append1)"
9972
9973     echo "12345" >>$temp
9974     echo "12345" >>$file
9975     cmp $temp $file || error "$temp $file differ (append2)"
9976
9977     rm -f $temp $file
9978     true
9979 }
9980
9981 test_155_big_load() {
9982     remote_ost_nodsh && skip "remote OST with nodsh" && return
9983     local temp=$TMP/$tfile
9984     local file=$DIR/$tfile
9985
9986     free_min_max
9987     local cache_size=$(do_facet ost$((MAXI+1)) \
9988         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
9989     local large_file_size=$((cache_size * 2))
9990
9991     echo "OSS cache size: $cache_size KB"
9992     echo "Large file size: $large_file_size KB"
9993
9994     [ $MAXV -le $large_file_size ] && \
9995         skip_env "max available OST size needs > $large_file_size KB" && \
9996         return 0
9997
9998     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
9999
10000     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
10001         error "dd of=$temp bs=$large_file_size count=1k failed"
10002     cp $temp $file
10003     ls -lh $temp $file
10004     cancel_lru_locks osc
10005     cmp $temp $file || error "$temp $file differ"
10006
10007     rm -f $temp $file
10008     true
10009 }
10010
10011 test_155a() {
10012         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10013         set_cache read on
10014         set_cache writethrough on
10015         test_155_small_load
10016 }
10017 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
10018
10019 test_155b() {
10020         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10021         set_cache read on
10022         set_cache writethrough off
10023         test_155_small_load
10024 }
10025 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
10026
10027 test_155c() {
10028         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10029         set_cache read off
10030         set_cache writethrough on
10031         test_155_small_load
10032 }
10033 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
10034
10035 test_155d() {
10036         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10037         set_cache read off
10038         set_cache writethrough off
10039         test_155_small_load
10040 }
10041 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
10042
10043 test_155e() {
10044         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10045         set_cache read on
10046         set_cache writethrough on
10047         test_155_big_load
10048 }
10049 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
10050
10051 test_155f() {
10052         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10053         set_cache read on
10054         set_cache writethrough off
10055         test_155_big_load
10056 }
10057 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
10058
10059 test_155g() {
10060         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10061         set_cache read off
10062         set_cache writethrough on
10063         test_155_big_load
10064 }
10065 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
10066
10067 test_155h() {
10068         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10069         set_cache read off
10070         set_cache writethrough off
10071         test_155_big_load
10072 }
10073 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
10074
10075 test_156() {
10076         remote_ost_nodsh && skip "remote OST with nodsh" && return
10077         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10078         local CPAGES=3
10079         local BEFORE
10080         local AFTER
10081         local file="$DIR/$tfile"
10082
10083         [ "$(facet_fstype ost1)" = "zfs" ] &&
10084                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
10085                 return
10086
10087         roc_hit_init
10088
10089     log "Turn on read and write cache"
10090     set_cache read on
10091     set_cache writethrough on
10092
10093     log "Write data and read it back."
10094     log "Read should be satisfied from the cache."
10095     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10096     BEFORE=`roc_hit`
10097     cancel_lru_locks osc
10098     cat $file >/dev/null
10099     AFTER=`roc_hit`
10100     if ! let "AFTER - BEFORE == CPAGES"; then
10101         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10102     else
10103         log "cache hits:: before: $BEFORE, after: $AFTER"
10104     fi
10105
10106     log "Read again; it should be satisfied from the cache."
10107     BEFORE=$AFTER
10108     cancel_lru_locks osc
10109     cat $file >/dev/null
10110     AFTER=`roc_hit`
10111     if ! let "AFTER - BEFORE == CPAGES"; then
10112         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10113     else
10114         log "cache hits:: before: $BEFORE, after: $AFTER"
10115     fi
10116
10117
10118     log "Turn off the read cache and turn on the write cache"
10119     set_cache read off
10120     set_cache writethrough on
10121
10122     log "Read again; it should be satisfied from the cache."
10123     BEFORE=`roc_hit`
10124     cancel_lru_locks osc
10125     cat $file >/dev/null
10126     AFTER=`roc_hit`
10127     if ! let "AFTER - BEFORE == CPAGES"; then
10128         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10129     else
10130         log "cache hits:: before: $BEFORE, after: $AFTER"
10131     fi
10132
10133     log "Read again; it should not be satisfied from the cache."
10134     BEFORE=$AFTER
10135     cancel_lru_locks osc
10136     cat $file >/dev/null
10137     AFTER=`roc_hit`
10138     if ! let "AFTER - BEFORE == 0"; then
10139         error "IN CACHE: before: $BEFORE, after: $AFTER"
10140     else
10141         log "cache hits:: before: $BEFORE, after: $AFTER"
10142     fi
10143
10144     log "Write data and read it back."
10145     log "Read should be satisfied from the cache."
10146     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10147     BEFORE=`roc_hit`
10148     cancel_lru_locks osc
10149     cat $file >/dev/null
10150     AFTER=`roc_hit`
10151     if ! let "AFTER - BEFORE == CPAGES"; then
10152         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10153     else
10154         log "cache hits:: before: $BEFORE, after: $AFTER"
10155     fi
10156
10157     log "Read again; it should not be satisfied from the cache."
10158     BEFORE=$AFTER
10159     cancel_lru_locks osc
10160     cat $file >/dev/null
10161     AFTER=`roc_hit`
10162     if ! let "AFTER - BEFORE == 0"; then
10163         error "IN CACHE: before: $BEFORE, after: $AFTER"
10164     else
10165         log "cache hits:: before: $BEFORE, after: $AFTER"
10166     fi
10167
10168
10169     log "Turn off read and write cache"
10170     set_cache read off
10171     set_cache writethrough off
10172
10173     log "Write data and read it back"
10174     log "It should not be satisfied from the cache."
10175     rm -f $file
10176     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10177     cancel_lru_locks osc
10178     BEFORE=`roc_hit`
10179     cat $file >/dev/null
10180     AFTER=`roc_hit`
10181         if ! let "AFTER - BEFORE == 0"; then
10182                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10183         else
10184                 log "cache hits:: before: $BEFORE, after: $AFTER"
10185         fi
10186
10187     log "Turn on the read cache and turn off the write cache"
10188     set_cache read on
10189     set_cache writethrough off
10190
10191     log "Write data and read it back"
10192     log "It should not be satisfied from the cache."
10193     rm -f $file
10194     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10195     BEFORE=`roc_hit`
10196     cancel_lru_locks osc
10197     cat $file >/dev/null
10198     AFTER=`roc_hit`
10199         if ! let "AFTER - BEFORE == 0"; then
10200                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10201         else
10202                 log "cache hits:: before: $BEFORE, after: $AFTER"
10203         fi
10204
10205     log "Read again; it should be satisfied from the cache."
10206     BEFORE=`roc_hit`
10207     cancel_lru_locks osc
10208     cat $file >/dev/null
10209     AFTER=`roc_hit`
10210     if ! let "AFTER - BEFORE == CPAGES"; then
10211         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10212     else
10213         log "cache hits:: before: $BEFORE, after: $AFTER"
10214     fi
10215
10216     rm -f $file
10217 }
10218 run_test 156 "Verification of tunables ============================"
10219
10220 #Changelogs
10221 err17935 () {
10222         if [[ $MDSCOUNT -gt 1 ]]; then
10223                 error_ignore bz17935 $*
10224         else
10225                 error $*
10226         fi
10227 }
10228
10229 changelog_chmask()
10230 {
10231         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10232
10233         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
10234
10235         if [ $MASK -eq 1 ]; then
10236                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
10237         else
10238                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
10239         fi
10240 }
10241
10242 changelog_extract_field() {
10243         local mdt=$1
10244         local cltype=$2
10245         local file=$3
10246         local identifier=$4
10247
10248         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
10249                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10250                 tail -1
10251 }
10252
10253 test_160a() {
10254         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10255         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10256         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10257                 { skip "Need MDS version at least 2.2.0"; return; }
10258
10259         local CL_USERS="mdd.$MDT0.changelog_users"
10260         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10261         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10262         echo "Registered as changelog user $USER"
10263         $GET_CL_USERS | grep -q $USER ||
10264                 error "User $USER not found in changelog_users"
10265
10266         # change something
10267         test_mkdir -p $DIR/$tdir/pics/2008/zachy
10268         touch $DIR/$tdir/pics/2008/zachy/timestamp
10269         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
10270         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
10271         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
10272         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
10273         rm $DIR/$tdir/pics/desktop.jpg
10274
10275         $LFS changelog $MDT0 | tail -5
10276
10277         echo "verifying changelog mask"
10278         changelog_chmask "MKDIR"
10279         changelog_chmask "CLOSE"
10280
10281         test_mkdir -p $DIR/$tdir/pics/zach/sofia
10282         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10283
10284         changelog_chmask "MKDIR"
10285         changelog_chmask "CLOSE"
10286
10287         test_mkdir -p $DIR/$tdir/pics/2008/sofia
10288         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10289
10290         $LFS changelog $MDT0
10291         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
10292         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
10293         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
10294         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
10295
10296         # verify contents
10297         echo "verifying target fid"
10298         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
10299         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
10300         [ "$fidc" == "$fidf" ] ||
10301                 err17935 "fid in changelog $fidc != file fid $fidf"
10302         echo "verifying parent fid"
10303         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
10304         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
10305         [ "$fidc" == "$fidf" ] ||
10306                 err17935 "pfid in changelog $fidc != dir fid $fidf"
10307
10308         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10309         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
10310         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10311         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
10312         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
10313                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
10314
10315         MIN_REC=$($GET_CL_USERS |
10316                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
10317         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
10318         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
10319         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
10320                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
10321
10322         # LU-3446 changelog index reset on MDT restart
10323         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10324         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10325         $LFS changelog_clear $MDT0 $USER 0
10326         stop $SINGLEMDS || error "Fail to stop MDT."
10327         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10328         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10329         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
10330         [ $CUR_REC1 == $CUR_REC2 ] ||
10331                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
10332
10333         echo "verifying user deregister"
10334         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10335         $GET_CL_USERS | grep -q $USER &&
10336                 error "User $USER still in changelog_users"
10337
10338         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
10339         if [ $USERS -eq 0 ]; then
10340                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10341                 touch $DIR/$tdir/chloe
10342                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10343                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
10344                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
10345         else
10346                 echo "$USERS other changelog users; can't verify off"
10347         fi
10348 }
10349 run_test 160a "changelog sanity"
10350
10351 test_160b() { # LU-3587
10352         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10353         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10354         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10355                 { skip "Need MDS version at least 2.2.0"; return; }
10356
10357         local CL_USERS="mdd.$MDT0.changelog_users"
10358         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10359         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10360         echo "Registered as changelog user $USER"
10361         $GET_CL_USERS | grep -q $USER ||
10362                 error "User $USER not found in changelog_users"
10363
10364         local LONGNAME1=$(str_repeat a 255)
10365         local LONGNAME2=$(str_repeat b 255)
10366
10367         cd $DIR
10368         echo "creating very long named file"
10369         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
10370         echo "moving very long named file"
10371         mv $LONGNAME1 $LONGNAME2
10372
10373         $LFS changelog $MDT0 | grep RENME
10374
10375         echo "deregistering $USER"
10376         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10377
10378         rm -f $LONGNAME2
10379 }
10380 run_test 160b "Verify that very long rename doesn't crash in changelog"
10381
10382 test_160c() {
10383         local rc=0
10384         local server_version=$(lustre_version_code $SINGLEMDS)
10385
10386         [[ $server_version -gt $(version_code 2.5.57) ]] ||
10387                 [[ $server_version -gt $(version_code 2.5.1) &&
10388                    $server_version -lt $(version_code 2.5.50) ]] ||
10389                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
10390         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10391
10392         # Registration step
10393         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10394                 changelog_register -n)
10395
10396         rm -rf $DIR/$tdir
10397         mkdir -p $DIR/$tdir
10398         $MCREATE $DIR/$tdir/foo_160c
10399         changelog_chmask "TRUNC"
10400         $TRUNCATE $DIR/$tdir/foo_160c 200
10401         changelog_chmask "TRUNC"
10402         $TRUNCATE $DIR/$tdir/foo_160c 199
10403         $LFS changelog $MDT0
10404         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
10405         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
10406         $LFS changelog_clear $MDT0 $USER 0
10407
10408         # Deregistration step
10409         echo "deregistering $USER"
10410         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10411 }
10412 run_test 160c "verify that changelog log catch the truncate event"
10413
10414 test_161a() {
10415         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10416         test_mkdir -p -c1 $DIR/$tdir
10417         cp /etc/hosts $DIR/$tdir/$tfile
10418         test_mkdir -c1 $DIR/$tdir/foo1
10419         test_mkdir -c1 $DIR/$tdir/foo2
10420         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
10421         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
10422         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
10423         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
10424         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
10425         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10426                 $LFS fid2path $DIR $FID
10427                 err17935 "bad link ea"
10428         fi
10429     # middle
10430     rm $DIR/$tdir/foo2/zachary
10431     # last
10432     rm $DIR/$tdir/foo2/thor
10433     # first
10434     rm $DIR/$tdir/$tfile
10435     # rename
10436     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
10437     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
10438         then
10439         $LFS fid2path $DIR $FID
10440         err17935 "bad link rename"
10441     fi
10442     rm $DIR/$tdir/foo2/maggie
10443
10444         # overflow the EA
10445         local longname=filename_avg_len_is_thirty_two_
10446         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
10447                 error "failed to hardlink many files"
10448         links=$($LFS fid2path $DIR $FID | wc -l)
10449         echo -n "${links}/1000 links in link EA"
10450         [[ $links -gt 60 ]] ||
10451                 err17935 "expected at least 60 links in link EA"
10452         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
10453                 error "failed to unlink many hardlinks"
10454 }
10455 run_test 161a "link ea sanity"
10456
10457 test_161b() {
10458         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10459         [ $MDSCOUNT -lt 2 ] &&
10460                 skip "skipping remote directory test" && return
10461         local MDTIDX=1
10462         local remote_dir=$DIR/$tdir/remote_dir
10463
10464         mkdir -p $DIR/$tdir
10465         $LFS mkdir -i $MDTIDX $remote_dir ||
10466                 error "create remote directory failed"
10467
10468         cp /etc/hosts $remote_dir/$tfile
10469         mkdir -p $remote_dir/foo1
10470         mkdir -p $remote_dir/foo2
10471         ln $remote_dir/$tfile $remote_dir/foo1/sofia
10472         ln $remote_dir/$tfile $remote_dir/foo2/zachary
10473         ln $remote_dir/$tfile $remote_dir/foo1/luna
10474         ln $remote_dir/$tfile $remote_dir/foo2/thor
10475
10476         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
10477                      tr -d ']')
10478         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10479                 $LFS fid2path $DIR $FID
10480                 err17935 "bad link ea"
10481         fi
10482         # middle
10483         rm $remote_dir/foo2/zachary
10484         # last
10485         rm $remote_dir/foo2/thor
10486         # first
10487         rm $remote_dir/$tfile
10488         # rename
10489         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
10490         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
10491         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
10492                 $LFS fid2path $DIR $FID
10493                 err17935 "bad link rename"
10494         fi
10495         rm $remote_dir/foo2/maggie
10496
10497         # overflow the EA
10498         local longname=filename_avg_len_is_thirty_two_
10499         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10500                 error "failed to hardlink many files"
10501         links=$($LFS fid2path $DIR $FID | wc -l)
10502         echo -n "${links}/1000 links in link EA"
10503         [[ ${links} -gt 60 ]] ||
10504                 err17935 "expected at least 60 links in link EA"
10505         unlinkmany $remote_dir/foo2/$longname 1000 ||
10506         error "failed to unlink many hardlinks"
10507 }
10508 run_test 161b "link ea sanity under remote directory"
10509
10510 test_161c() {
10511         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10512         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10513         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10514                 skip "Need MDS version at least 2.1.5" && return
10515
10516         # define CLF_RENAME_LAST 0x0001
10517         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10518         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10519                 changelog_register -n)
10520         rm -rf $DIR/$tdir
10521         mkdir -p $DIR/$tdir
10522         touch $DIR/$tdir/foo_161c
10523         touch $DIR/$tdir/bar_161c
10524         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10525         $LFS changelog $MDT0 | grep RENME
10526         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10527                 cut -f5 -d' ')
10528         $LFS changelog_clear $MDT0 $USER 0
10529         if [ x$flags != "x0x1" ]; then
10530                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10531                         $USER
10532                 error "flag $flags is not 0x1"
10533         fi
10534         echo "rename overwrite a target having nlink = 1," \
10535                 "changelog record has flags of $flags"
10536
10537         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10538         touch $DIR/$tdir/foo_161c
10539         touch $DIR/$tdir/bar_161c
10540         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10541         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10542         $LFS changelog $MDT0 | grep RENME
10543         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10544         $LFS changelog_clear $MDT0 $USER 0
10545         if [ x$flags != "x0x0" ]; then
10546                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10547                         $USER
10548                 error "flag $flags is not 0x0"
10549         fi
10550         echo "rename overwrite a target having nlink > 1," \
10551                 "changelog record has flags of $flags"
10552
10553         # rename doesn't overwrite a target (changelog flag 0x0)
10554         touch $DIR/$tdir/foo_161c
10555         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10556         $LFS changelog $MDT0 | grep RENME
10557         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10558         $LFS changelog_clear $MDT0 $USER 0
10559         if [ x$flags != "x0x0" ]; then
10560                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10561                         $USER
10562                 error "flag $flags is not 0x0"
10563         fi
10564         echo "rename doesn't overwrite a target," \
10565                 "changelog record has flags of $flags"
10566
10567         # define CLF_UNLINK_LAST 0x0001
10568         # unlink a file having nlink = 1 (changelog flag 0x1)
10569         rm -f $DIR/$tdir/foo2_161c
10570         $LFS changelog $MDT0 | grep UNLNK
10571         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10572         $LFS changelog_clear $MDT0 $USER 0
10573         if [ x$flags != "x0x1" ]; then
10574                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10575                         $USER
10576                 error "flag $flags is not 0x1"
10577         fi
10578         echo "unlink a file having nlink = 1," \
10579                 "changelog record has flags of $flags"
10580
10581         # unlink a file having nlink > 1 (changelog flag 0x0)
10582         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10583         rm -f $DIR/$tdir/foobar_161c
10584         $LFS changelog $MDT0 | grep UNLNK
10585         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10586         $LFS changelog_clear $MDT0 $USER 0
10587         if [ x$flags != "x0x0" ]; then
10588                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10589                         $USER
10590                 error "flag $flags is not 0x0"
10591         fi
10592         echo "unlink a file having nlink > 1," \
10593                 "changelog record has flags of $flags"
10594         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10595 }
10596 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10597
10598 check_path() {
10599     local expected=$1
10600     shift
10601     local fid=$2
10602
10603     local path=$(${LFS} fid2path $*)
10604     # Remove the '//' indicating a remote directory
10605     path=$(echo $path | sed 's#//#/#g')
10606     RC=$?
10607
10608     if [ $RC -ne 0 ]; then
10609         err17935 "path looked up of $expected failed. Error $RC"
10610         return $RC
10611     elif [ "${path}" != "${expected}" ]; then
10612         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10613         return 2
10614     fi
10615     echo "fid $fid resolves to path $path (expected $expected)"
10616 }
10617
10618 test_162() {
10619         # Make changes to filesystem
10620         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10621         test_mkdir -p -c1 $DIR/$tdir/d2
10622         touch $DIR/$tdir/d2/$tfile
10623         touch $DIR/$tdir/d2/x1
10624         touch $DIR/$tdir/d2/x2
10625         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
10626         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
10627         # regular file
10628         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10629         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
10630                 error "check path $tdir/d2/$tfile failed"
10631
10632         # softlink
10633         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10634         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10635         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
10636                 error "check path $tdir/d2/p/q/r/slink failed"
10637
10638         # softlink to wrong file
10639         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10640         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10641         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
10642                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
10643
10644         # hardlink
10645         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10646         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10647         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10648         # fid2path dir/fsname should both work
10649         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
10650                 error "check path $tdir/d2/a/b/c/new_file failed"
10651         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
10652                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
10653
10654         # hardlink count: check that there are 2 links
10655         # Doesnt work with CMD yet: 17935
10656         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10657                 err17935 "expected 2 links"
10658
10659         # hardlink indexing: remove the first link
10660         rm $DIR/$tdir/d2/p/q/r/hlink
10661         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
10662                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
10663
10664         return 0
10665 }
10666 run_test 162 "path lookup sanity"
10667
10668 test_162b() {
10669         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10670         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10671
10672         mkdir $DIR/$tdir
10673         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
10674                                 error "create striped dir failed"
10675
10676         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
10677                                         tail -n 1 | awk '{print $2}')
10678         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
10679
10680         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
10681         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
10682
10683         # regular file
10684         for ((i=0;i<5;i++)); do
10685                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
10686                         error "get fid for f$i failed"
10687                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
10688                         error "check path $tdir/striped_dir/f$i failed"
10689
10690                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
10691                         error "get fid for d$i failed"
10692                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
10693                         error "check path $tdir/striped_dir/d$i failed"
10694         done
10695
10696         return 0
10697 }
10698 run_test 162b "striped directory path lookup sanity"
10699
10700 # LU-4239: Verify fid2path works with paths 100 or more directories deep
10701 test_162c() {
10702         test_mkdir $DIR/$tdir.local
10703         test_mkdir $DIR/$tdir.remote
10704         local lpath=$tdir.local
10705         local rpath=$tdir.remote
10706
10707         for ((i = 0; i <= 101; i++)); do
10708                 lpath="$lpath/$i"
10709                 mkdir $DIR/$lpath
10710                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
10711                         error "get fid for local directory $DIR/$lpath failed"
10712                 check_path "$DIR/$lpath" $MOUNT $FID --link 0 ||
10713                         error "check path for local directory $DIR/$lpath failed"
10714
10715                 rpath="$rpath/$i"
10716                 test_mkdir $DIR/$rpath
10717                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
10718                         error "get fid for remote directory $DIR/$rpath failed"
10719                 check_path "$DIR/$rpath" $MOUNT $FID --link 0 ||
10720                         error "check path for remote directory $DIR/$rpath failed"
10721         done
10722
10723         return 0
10724 }
10725 run_test 162c "fid2path works with paths 100 or more directories deep"
10726
10727 test_169() {
10728         # do directio so as not to populate the page cache
10729         log "creating a 10 Mb file"
10730         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10731         log "starting reads"
10732         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10733         log "truncating the file"
10734         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10735         log "killing dd"
10736         kill %+ || true # reads might have finished
10737         echo "wait until dd is finished"
10738         wait
10739         log "removing the temporary file"
10740         rm -rf $DIR/$tfile || error "tmp file removal failed"
10741 }
10742 run_test 169 "parallel read and truncate should not deadlock"
10743
10744 test_170() {
10745         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10746         $LCTL clear     # bug 18514
10747         $LCTL debug_daemon start $TMP/${tfile}_log_good
10748         touch $DIR/$tfile
10749         $LCTL debug_daemon stop
10750         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10751                error "sed failed to read log_good"
10752
10753         $LCTL debug_daemon start $TMP/${tfile}_log_good
10754         rm -rf $DIR/$tfile
10755         $LCTL debug_daemon stop
10756
10757         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10758                error "lctl df log_bad failed"
10759
10760         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10761         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10762
10763         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10764         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10765
10766         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10767                 error "bad_line good_line1 good_line2 are empty"
10768
10769         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10770         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10771         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10772
10773         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10774         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10775         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10776
10777         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
10778                 error "bad_line_new good_line_new are empty"
10779
10780         local expected_good=$((good_line1 + good_line2*2))
10781
10782         rm -f $TMP/${tfile}*
10783         # LU-231, short malformed line may not be counted into bad lines
10784         if [ $bad_line -ne $bad_line_new ] &&
10785                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
10786                 error "expected $bad_line bad lines, but got $bad_line_new"
10787                 return 1
10788         fi
10789
10790         if [ $expected_good -ne $good_line_new ]; then
10791                 error "expected $expected_good good lines, but got $good_line_new"
10792                 return 2
10793         fi
10794         true
10795 }
10796 run_test 170 "test lctl df to handle corrupted log ====================="
10797
10798 test_171() { # bug20592
10799         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10800 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
10801         $LCTL set_param fail_loc=0x50e
10802         $LCTL set_param fail_val=3000
10803         multiop_bg_pause $DIR/$tfile O_s || true
10804         local MULTIPID=$!
10805         kill -USR1 $MULTIPID
10806         # cause log dump
10807         sleep 3
10808         wait $MULTIPID
10809         if dmesg | grep "recursive fault"; then
10810                 error "caught a recursive fault"
10811         fi
10812         $LCTL set_param fail_loc=0
10813         true
10814 }
10815 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
10816
10817 # it would be good to share it with obdfilter-survey/iokit-libecho code
10818 setup_obdecho_osc () {
10819         local rc=0
10820         local ost_nid=$1
10821         local obdfilter_name=$2
10822         echo "Creating new osc for $obdfilter_name on $ost_nid"
10823         # make sure we can find loopback nid
10824         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
10825
10826         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
10827                            ${obdfilter_name}_osc_UUID || rc=2; }
10828         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
10829                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
10830         return $rc
10831 }
10832
10833 cleanup_obdecho_osc () {
10834         local obdfilter_name=$1
10835         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
10836         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
10837         return 0
10838 }
10839
10840 obdecho_test() {
10841         local OBD=$1
10842         local node=$2
10843         local pages=${3:-64}
10844         local rc=0
10845         local id
10846
10847         local count=10
10848         local obd_size=$(get_obd_size $node $OBD)
10849         local page_size=$(get_page_size $node)
10850         if [[ -n "$obd_size" ]]; then
10851                 local new_count=$((obd_size / (pages * page_size / 1024)))
10852                 [[ $new_count -ge $count ]] || count=$new_count
10853         fi
10854
10855         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
10856         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
10857                            rc=2; }
10858         if [ $rc -eq 0 ]; then
10859             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
10860             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
10861         fi
10862         echo "New object id is $id"
10863         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
10864                            rc=4; }
10865         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
10866                            "test_brw $count w v $pages $id" || rc=4; }
10867         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
10868                            rc=4; }
10869         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
10870                                         "cleanup" || rc=5; }
10871         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
10872                                         "detach" || rc=6; }
10873         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
10874         return $rc
10875 }
10876
10877 test_180a() {
10878         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10879         remote_ost_nodsh && skip "remote OST with nodsh" && return
10880         local rc=0
10881         local rmmod_local=0
10882
10883         if ! module_loaded obdecho; then
10884             load_module obdecho/obdecho
10885             rmmod_local=1
10886         fi
10887
10888         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
10889         local host=$(lctl get_param -n osc.$osc.import |
10890                              awk '/current_connection:/ {print $2}' )
10891         local target=$(lctl get_param -n osc.$osc.import |
10892                              awk '/target:/ {print $2}' )
10893         target=${target%_UUID}
10894
10895         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
10896         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
10897         [[ -n $target ]] && cleanup_obdecho_osc $target
10898         [ $rmmod_local -eq 1 ] && rmmod obdecho
10899         return $rc
10900 }
10901 run_test 180a "test obdecho on osc"
10902
10903 test_180b() {
10904         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10905         remote_ost_nodsh && skip "remote OST with nodsh" && return
10906         local rc=0
10907         local rmmod_remote=0
10908
10909         do_facet ost1 "lsmod | grep -q obdecho || "                      \
10910                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
10911                       "modprobe obdecho; }" && rmmod_remote=1
10912         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
10913         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
10914         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
10915         return $rc
10916 }
10917 run_test 180b "test obdecho directly on obdfilter"
10918
10919 test_180c() { # LU-2598
10920         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10921         remote_ost_nodsh && skip "remote OST with nodsh" && return
10922         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
10923                 skip "Need MDS version at least 2.4.0" && return
10924
10925         local rc=0
10926         local rmmod_remote=false
10927         local pages=16384 # 64MB bulk I/O RPC size
10928         local target
10929
10930         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
10931                 rmmod_remote=true || error "failed to load module obdecho"
10932
10933         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
10934                 head -n1)
10935         if [ -n "$target" ]; then
10936                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
10937         else
10938                 echo "there is no obdfilter target on ost1"
10939                 rc=2
10940         fi
10941         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
10942         return $rc
10943 }
10944 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
10945
10946 test_181() { # bug 22177
10947         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10948         # create enough files to index the directory
10949         createmany -o $DIR/$tdir/foobar 4000
10950         # print attributes for debug purpose
10951         lsattr -d .
10952         # open dir
10953         multiop_bg_pause $DIR/$tdir D_Sc || return 1
10954         MULTIPID=$!
10955         # remove the files & current working dir
10956         unlinkmany $DIR/$tdir/foobar 4000
10957         rmdir $DIR/$tdir
10958         kill -USR1 $MULTIPID
10959         wait $MULTIPID
10960         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
10961         return 0
10962 }
10963 run_test 181 "Test open-unlinked dir ========================"
10964
10965 test_182() {
10966         local fcount=1000
10967         local tcount=10
10968
10969         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10970
10971         $LCTL set_param mdc.*.rpc_stats=clear
10972
10973         for (( i = 0; i < $tcount; i++ )) ; do
10974                 mkdir $DIR/$tdir/$i
10975         done
10976
10977         for (( i = 0; i < $tcount; i++ )) ; do
10978                 createmany -o $DIR/$tdir/$i/f- $fcount &
10979         done
10980         wait
10981
10982         for (( i = 0; i < $tcount; i++ )) ; do
10983                 unlinkmany $DIR/$tdir/$i/f- $fcount &
10984         done
10985         wait
10986
10987         $LCTL get_param mdc.*.rpc_stats
10988
10989         rm -rf $DIR/$tdir
10990 }
10991 run_test 182 "Test parallel modify metadata operations ================"
10992
10993 test_183() { # LU-2275
10994         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10995         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
10996                 skip "Need MDS version at least 2.3.56" && return
10997
10998         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10999         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11000         echo aaa > $DIR/$tdir/$tfile
11001
11002 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
11003         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
11004
11005         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
11006         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
11007
11008         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
11009
11010         # Flush negative dentry cache
11011         touch $DIR/$tdir/$tfile
11012
11013         # We are not checking for any leaked references here, they'll
11014         # become evident next time we do cleanup with module unload.
11015         rm -rf $DIR/$tdir
11016 }
11017 run_test 183 "No crash or request leak in case of strange dispositions ========"
11018
11019 # test suite 184 is for LU-2016, LU-2017
11020 test_184a() {
11021         check_swap_layouts_support && return 0
11022
11023         dir0=$DIR/$tdir/$testnum
11024         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
11025         ref1=/etc/passwd
11026         ref2=/etc/group
11027         file1=$dir0/f1
11028         file2=$dir0/f2
11029         $SETSTRIPE -c1 $file1
11030         cp $ref1 $file1
11031         $SETSTRIPE -c2 $file2
11032         cp $ref2 $file2
11033         gen1=$($GETSTRIPE -g $file1)
11034         gen2=$($GETSTRIPE -g $file2)
11035
11036         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
11037         gen=$($GETSTRIPE -g $file1)
11038         [[ $gen1 != $gen ]] ||
11039                 "Layout generation on $file1 does not change"
11040         gen=$($GETSTRIPE -g $file2)
11041         [[ $gen2 != $gen ]] ||
11042                 "Layout generation on $file2 does not change"
11043
11044         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
11045         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
11046 }
11047 run_test 184a "Basic layout swap"
11048
11049 test_184b() {
11050         check_swap_layouts_support && return 0
11051
11052         dir0=$DIR/$tdir/$testnum
11053         mkdir -p $dir0 || error "creating dir $dir0"
11054         file1=$dir0/f1
11055         file2=$dir0/f2
11056         file3=$dir0/f3
11057         dir1=$dir0/d1
11058         dir2=$dir0/d2
11059         mkdir $dir1 $dir2
11060         $SETSTRIPE -c1 $file1
11061         $SETSTRIPE -c2 $file2
11062         $SETSTRIPE -c1 $file3
11063         chown $RUNAS_ID $file3
11064         gen1=$($GETSTRIPE -g $file1)
11065         gen2=$($GETSTRIPE -g $file2)
11066
11067         $LFS swap_layouts $dir1 $dir2 &&
11068                 error "swap of directories layouts should fail"
11069         $LFS swap_layouts $dir1 $file1 &&
11070                 error "swap of directory and file layouts should fail"
11071         $RUNAS $LFS swap_layouts $file1 $file2 &&
11072                 error "swap of file we cannot write should fail"
11073         $LFS swap_layouts $file1 $file3 &&
11074                 error "swap of file with different owner should fail"
11075         /bin/true # to clear error code
11076 }
11077 run_test 184b "Forbidden layout swap (will generate errors)"
11078
11079 test_184c() {
11080         check_swap_layouts_support && return 0
11081
11082         local dir0=$DIR/$tdir/$testnum
11083         mkdir -p $dir0 || error "creating dir $dir0"
11084
11085         local ref1=$dir0/ref1
11086         local ref2=$dir0/ref2
11087         local file1=$dir0/file1
11088         local file2=$dir0/file2
11089         # create a file large enough for the concurrent test
11090         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
11091         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
11092         echo "ref file size: ref1($(stat -c %s $ref1))," \
11093              "ref2($(stat -c %s $ref2))"
11094
11095         cp $ref2 $file2
11096         dd if=$ref1 of=$file1 bs=16k &
11097         local DD_PID=$!
11098
11099         # Make sure dd starts to copy file
11100         while [ ! -f $file1 ]; do sleep 0.1; done
11101
11102         $LFS swap_layouts $file1 $file2
11103         local rc=$?
11104         wait $DD_PID
11105         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
11106         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
11107
11108         # how many bytes copied before swapping layout
11109         local copied=$(stat -c %s $file2)
11110         local remaining=$(stat -c %s $ref1)
11111         remaining=$((remaining - copied))
11112         echo "Copied $copied bytes before swapping layout..."
11113
11114         cmp -n $copied $file1 $ref2 | grep differ &&
11115                 error "Content mismatch [0, $copied) of ref2 and file1"
11116         cmp -n $copied $file2 $ref1 ||
11117                 error "Content mismatch [0, $copied) of ref1 and file2"
11118         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
11119                 error "Content mismatch [$copied, EOF) of ref1 and file1"
11120
11121         # clean up
11122         rm -f $ref1 $ref2 $file1 $file2
11123 }
11124 run_test 184c "Concurrent write and layout swap"
11125
11126 test_184d() {
11127         check_swap_layouts_support && return 0
11128         [ -z "$(which getfattr 2>/dev/null)" ] &&
11129                 skip "no getfattr command" && return 0
11130
11131         local file1=$DIR/$tdir/$tfile-1
11132         local file2=$DIR/$tdir/$tfile-2
11133         local file3=$DIR/$tdir/$tfile-3
11134         local lovea1
11135         local lovea2
11136
11137         mkdir -p $DIR/$tdir
11138         touch $file1 || error "create $file1 failed"
11139         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11140                 error "create $file2 failed"
11141         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11142                 error "create $file3 failed"
11143         lovea1=$($LFS getstripe $file1 | sed 1d)
11144
11145         $LFS swap_layouts $file2 $file3 ||
11146                 error "swap $file2 $file3 layouts failed"
11147         $LFS swap_layouts $file1 $file2 ||
11148                 error "swap $file1 $file2 layouts failed"
11149
11150         lovea2=$($LFS getstripe $file2 | sed 1d)
11151         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
11152
11153         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11154         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
11155 }
11156 run_test 184d "allow stripeless layouts swap"
11157
11158 test_184e() {
11159         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
11160                 { skip "Need MDS version at least 2.6.94"; return 0; }
11161         check_swap_layouts_support && return 0
11162         [ -z "$(which getfattr 2>/dev/null)" ] &&
11163                 skip "no getfattr command" && return 0
11164
11165         local file1=$DIR/$tdir/$tfile-1
11166         local file2=$DIR/$tdir/$tfile-2
11167         local file3=$DIR/$tdir/$tfile-3
11168         local lovea
11169
11170         mkdir -p $DIR/$tdir
11171         touch $file1 || error "create $file1 failed"
11172         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11173                 error "create $file2 failed"
11174         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11175                 error "create $file3 failed"
11176
11177         $LFS swap_layouts $file1 $file2 ||
11178                 error "swap $file1 $file2 layouts failed"
11179
11180         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11181         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
11182
11183         echo 123 > $file1 || error "Should be able to write into $file1"
11184
11185         $LFS swap_layouts $file1 $file3 ||
11186                 error "swap $file1 $file3 layouts failed"
11187
11188         echo 123 > $file1 || error "Should be able to write into $file1"
11189
11190         rm -rf $file1 $file2 $file3
11191 }
11192 run_test 184e "Recreate layout after stripeless layout swaps"
11193
11194 test_185() { # LU-2441
11195         # LU-3553 - no volatile file support in old servers
11196         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
11197                 { skip "Need MDS version at least 2.3.60"; return 0; }
11198
11199         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11200         touch $DIR/$tdir/spoo
11201         local mtime1=$(stat -c "%Y" $DIR/$tdir)
11202         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
11203                 error "cannot create/write a volatile file"
11204         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
11205                 error "FID is still valid after close"
11206
11207         multiop_bg_pause $DIR/$tdir vVw4096_c
11208         local multi_pid=$!
11209
11210         local OLD_IFS=$IFS
11211         IFS=":"
11212         local fidv=($fid)
11213         IFS=$OLD_IFS
11214         # assume that the next FID for this client is sequential, since stdout
11215         # is unfortunately eaten by multiop_bg_pause
11216         local n=$((${fidv[1]} + 1))
11217         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
11218         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
11219                 error "FID is missing before close"
11220         kill -USR1 $multi_pid
11221         # 1 second delay, so if mtime change we will see it
11222         sleep 1
11223         local mtime2=$(stat -c "%Y" $DIR/$tdir)
11224         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
11225 }
11226 run_test 185 "Volatile file support"
11227
11228 test_187a() {
11229         local dir0=$DIR/$tdir/$testnum
11230         mkdir -p $dir0 || error "creating dir $dir0"
11231
11232         local file=$dir0/file1
11233         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
11234         local dv1=$($LFS data_version $file)
11235         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
11236         local dv2=$($LFS data_version $file)
11237         [[ $dv1 != $dv2 ]] ||
11238                 error "data version did not change on write $dv1 == $dv2"
11239
11240         # clean up
11241         rm -f $file1
11242 }
11243 run_test 187a "Test data version change"
11244
11245 test_187b() {
11246         local dir0=$DIR/$tdir/$testnum
11247         mkdir -p $dir0 || error "creating dir $dir0"
11248
11249         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
11250         [[ ${DV[0]} != ${DV[1]} ]] ||
11251                 error "data version did not change on write"\
11252                       " ${DV[0]} == ${DV[1]}"
11253
11254         # clean up
11255         rm -f $file1
11256 }
11257 run_test 187b "Test data version change on volatile file"
11258
11259 test_200() {
11260         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11261         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11262
11263         local POOL=${POOL:-cea1}
11264         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
11265         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
11266         # Pool OST targets
11267         local first_ost=0
11268         local last_ost=$(($OSTCOUNT - 1))
11269         local ost_step=2
11270         local ost_list=$(seq $first_ost $ost_step $last_ost)
11271         local ost_range="$first_ost $last_ost $ost_step"
11272         local test_path=$POOL_ROOT/$POOL_DIR_NAME
11273         local file_dir=$POOL_ROOT/file_tst
11274         local subdir=$test_path/subdir
11275
11276         local rc=0
11277         while : ; do
11278                 # former test_200a test_200b
11279                 pool_add $POOL                          || { rc=$? ; break; }
11280                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
11281                 # former test_200c test_200d
11282                 mkdir -p $test_path
11283                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
11284                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
11285                 mkdir -p $subdir
11286                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
11287                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
11288                                                         || { rc=$? ; break; }
11289                 # former test_200e test_200f
11290                 local files=$((OSTCOUNT*3))
11291                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
11292                                                         || { rc=$? ; break; }
11293                 pool_create_files $POOL $file_dir $files "$ost_list" \
11294                                                         || { rc=$? ; break; }
11295                 # former test_200g test_200h
11296                 pool_lfs_df $POOL                       || { rc=$? ; break; }
11297                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
11298
11299                 # former test_201a test_201b test_201c
11300                 pool_remove_first_target $POOL          || { rc=$? ; break; }
11301
11302                 local f=$test_path/$tfile
11303                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
11304                 pool_remove $POOL $f                    || { rc=$? ; break; }
11305                 break
11306         done
11307
11308         cleanup_pools
11309         return $rc
11310 }
11311 run_test 200 "OST pools"
11312
11313 # usage: default_attr <count | size | offset>
11314 default_attr() {
11315         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
11316 }
11317
11318 # usage: check_default_stripe_attr
11319 check_default_stripe_attr() {
11320         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
11321         case $1 in
11322         --stripe-count|--count)
11323                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
11324         --stripe-size|--size)
11325                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
11326         --stripe-index|--index)
11327                 EXPECTED=-1;;
11328         *)
11329                 error "unknown getstripe attr '$1'"
11330         esac
11331
11332         [ $ACTUAL != $EXPECTED ] &&
11333                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
11334 }
11335
11336 test_204a() {
11337         test_mkdir -p $DIR/$tdir
11338         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
11339
11340         check_default_stripe_attr --stripe-count
11341         check_default_stripe_attr --stripe-size
11342         check_default_stripe_attr --stripe-index
11343
11344         return 0
11345 }
11346 run_test 204a "Print default stripe attributes ================="
11347
11348 test_204b() {
11349         test_mkdir -p $DIR/$tdir
11350         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11351
11352         check_default_stripe_attr --stripe-size
11353         check_default_stripe_attr --stripe-index
11354
11355         return 0
11356 }
11357 run_test 204b "Print default stripe size and offset  ==========="
11358
11359 test_204c() {
11360         test_mkdir -p $DIR/$tdir
11361         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11362
11363         check_default_stripe_attr --stripe-count
11364         check_default_stripe_attr --stripe-index
11365
11366         return 0
11367 }
11368 run_test 204c "Print default stripe count and offset ==========="
11369
11370 test_204d() {
11371         test_mkdir -p $DIR/$tdir
11372         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11373
11374         check_default_stripe_attr --stripe-count
11375         check_default_stripe_attr --stripe-size
11376
11377         return 0
11378 }
11379 run_test 204d "Print default stripe count and size ============="
11380
11381 test_204e() {
11382         test_mkdir -p $DIR/$tdir
11383         $SETSTRIPE -d $DIR/$tdir
11384
11385         check_default_stripe_attr --stripe-count --raw
11386         check_default_stripe_attr --stripe-size --raw
11387         check_default_stripe_attr --stripe-index --raw
11388
11389         return 0
11390 }
11391 run_test 204e "Print raw stripe attributes ================="
11392
11393 test_204f() {
11394         test_mkdir -p $DIR/$tdir
11395         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11396
11397         check_default_stripe_attr --stripe-size --raw
11398         check_default_stripe_attr --stripe-index --raw
11399
11400         return 0
11401 }
11402 run_test 204f "Print raw stripe size and offset  ==========="
11403
11404 test_204g() {
11405         test_mkdir -p $DIR/$tdir
11406         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11407
11408         check_default_stripe_attr --stripe-count --raw
11409         check_default_stripe_attr --stripe-index --raw
11410
11411         return 0
11412 }
11413 run_test 204g "Print raw stripe count and offset ==========="
11414
11415 test_204h() {
11416         test_mkdir -p $DIR/$tdir
11417         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11418
11419         check_default_stripe_attr --stripe-count --raw
11420         check_default_stripe_attr --stripe-size --raw
11421
11422         return 0
11423 }
11424 run_test 204h "Print raw stripe count and size ============="
11425
11426 # Figure out which job scheduler is being used, if any,
11427 # or use a fake one
11428 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11429         JOBENV=SLURM_JOB_ID
11430 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11431         JOBENV=LSB_JOBID
11432 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11433         JOBENV=PBS_JOBID
11434 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11435         JOBENV=LOADL_STEP_ID
11436 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11437         JOBENV=JOB_ID
11438 else
11439         JOBENV=FAKE_JOBID
11440 fi
11441
11442 verify_jobstats() {
11443         local cmd=$1
11444         local target=$2
11445
11446         # clear old jobstats
11447         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
11448         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
11449
11450         # use a new JobID for this test, or we might see an old one
11451         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
11452
11453         JOBVAL=${!JOBENV}
11454         log "Test: $cmd"
11455         log "Using JobID environment variable $JOBENV=$JOBVAL"
11456
11457         if [ $JOBENV = "FAKE_JOBID" ]; then
11458                 FAKE_JOBID=$JOBVAL $cmd
11459         else
11460                 $cmd
11461         fi
11462
11463         if [ "$target" = "mdt" -o "$target" = "both" ]; then
11464                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
11465                 do_facet $FACET lctl get_param mdt.*.job_stats |
11466                         grep $JOBVAL || error "No job stats found on MDT $FACET"
11467         fi
11468         if [ "$target" = "ost" -o "$target" = "both" ]; then
11469                 FACET=ost1
11470                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
11471                         grep $JOBVAL || error "No job stats found on OST $FACET"
11472         fi
11473 }
11474
11475 jobstats_set() {
11476         trap 0
11477         NEW_JOBENV=${1:-$OLD_JOBENV}
11478         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11479         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11480 }
11481
11482 test_205() { # Job stats
11483         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11484         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11485         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11486                 skip "Server doesn't support jobstats" && return 0
11487         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11488
11489         local cmd
11490         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11491         if [ $OLD_JOBENV != $JOBENV ]; then
11492                 jobstats_set $JOBENV
11493                 trap jobstats_set EXIT
11494         fi
11495
11496         local user=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11497                      changelog_register -n)
11498         echo "Registered as changelog user $user"
11499
11500         # mkdir
11501         cmd="mkdir $DIR/$tfile"
11502         verify_jobstats "$cmd" "mdt"
11503         # rmdir
11504         cmd="rm -fr $DIR/$tfile"
11505         verify_jobstats "$cmd" "mdt"
11506         # mknod
11507         cmd="mknod $DIR/$tfile c 1 3"
11508         verify_jobstats "$cmd" "mdt"
11509         # unlink
11510         cmd="rm -f $DIR/$tfile"
11511         verify_jobstats "$cmd" "mdt"
11512         # open & close
11513         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11514         verify_jobstats "$cmd" "mdt"
11515         # setattr
11516         cmd="touch $DIR/$tfile"
11517         verify_jobstats "$cmd" "both"
11518         # write
11519         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11520         verify_jobstats "$cmd" "ost"
11521         # read
11522         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11523         verify_jobstats "$cmd" "ost"
11524         # truncate
11525         cmd="$TRUNCATE $DIR/$tfile 0"
11526         verify_jobstats "$cmd" "both"
11527         # rename
11528         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
11529         verify_jobstats "$cmd" "mdt"
11530
11531         # Ensure that jobid are present in changelog (if supported by MDS)
11532         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
11533         then
11534                 $LFS changelog $MDT0 | tail -9
11535                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
11536                 [ $jobids -eq 9 ] ||
11537                         error "Wrong changelog jobid count $jobids != 9"
11538
11539                 # LU-5862
11540                 JOBENV="disable"
11541                 jobstats_set $JOBENV
11542                 touch $DIR/$tfile
11543                 $LFS changelog $MDT0 | tail -1
11544                 jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
11545                 [ $jobids -eq 0 ] ||
11546                         error "Unexpected jobids when jobid_var=$JOBENV"
11547         fi
11548
11549         # cleanup
11550         rm -f $DIR/jobstats_test_rename
11551
11552         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11553 }
11554 run_test 205 "Verify job stats"
11555
11556 # LU-1480, LU-1773 and LU-1657
11557 test_206() {
11558         mkdir -p $DIR/$tdir
11559         $SETSTRIPE -c -1 $DIR/$tdir
11560 #define OBD_FAIL_LOV_INIT 0x1403
11561         $LCTL set_param fail_loc=0xa0001403
11562         $LCTL set_param fail_val=1
11563         touch $DIR/$tdir/$tfile || true
11564 }
11565 run_test 206 "fail lov_init_raid0() doesn't lbug"
11566
11567 test_207a() {
11568         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11569         local fsz=`stat -c %s $DIR/$tfile`
11570         cancel_lru_locks mdc
11571
11572         # do not return layout in getattr intent
11573 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11574         $LCTL set_param fail_loc=0x170
11575         local sz=`stat -c %s $DIR/$tfile`
11576
11577         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11578
11579         rm -rf $DIR/$tfile
11580 }
11581 run_test 207a "can refresh layout at glimpse"
11582
11583 test_207b() {
11584         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11585         local cksum=`md5sum $DIR/$tfile`
11586         local fsz=`stat -c %s $DIR/$tfile`
11587         cancel_lru_locks mdc
11588         cancel_lru_locks osc
11589
11590         # do not return layout in getattr intent
11591 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11592         $LCTL set_param fail_loc=0x171
11593
11594         # it will refresh layout after the file is opened but before read issues
11595         echo checksum is "$cksum"
11596         echo "$cksum" |md5sum -c --quiet || error "file differs"
11597
11598         rm -rf $DIR/$tfile
11599 }
11600 run_test 207b "can refresh layout at open"
11601
11602 test_208() {
11603         # FIXME: in this test suite, only RD lease is used. This is okay
11604         # for now as only exclusive open is supported. After generic lease
11605         # is done, this test suite should be revised. - Jinshan
11606
11607         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11608                 { skip "Need MDS version at least 2.4.52"; return 0; }
11609         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11610
11611         echo "==== test 1: verify get lease work"
11612         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11613
11614         echo "==== test 2: verify lease can be broken by upcoming open"
11615         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11616         local PID=$!
11617         sleep 1
11618
11619         $MULTIOP $DIR/$tfile oO_RDONLY:c
11620         kill -USR1 $PID && wait $PID || error "break lease error"
11621
11622         echo "==== test 3: verify lease can't be granted if an open already exists"
11623         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11624         local PID=$!
11625         sleep 1
11626
11627         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11628         kill -USR1 $PID && wait $PID || error "open file error"
11629
11630         echo "==== test 4: lease can sustain over recovery"
11631         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11632         PID=$!
11633         sleep 1
11634
11635         fail mds1
11636
11637         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11638
11639         echo "==== test 5: lease broken can't be regained by replay"
11640         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11641         PID=$!
11642         sleep 1
11643
11644         # open file to break lease and then recovery
11645         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11646         fail mds1
11647
11648         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11649
11650         rm -f $DIR/$tfile
11651 }
11652 run_test 208 "Exclusive open"
11653
11654 test_209() {
11655         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11656                 skip_env "must have disp_stripe" && return
11657
11658         touch $DIR/$tfile
11659         sync; sleep 5; sync;
11660
11661         echo 3 > /proc/sys/vm/drop_caches
11662         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11663
11664         # open/close 500 times
11665         for i in $(seq 500); do
11666                 cat $DIR/$tfile
11667         done
11668
11669         echo 3 > /proc/sys/vm/drop_caches
11670         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11671
11672         echo "before: $req_before, after: $req_after"
11673         [ $((req_after - req_before)) -ge 300 ] &&
11674                 error "open/close requests are not freed"
11675         return 0
11676 }
11677 run_test 209 "read-only open/close requests should be freed promptly"
11678
11679 test_212() {
11680         size=`date +%s`
11681         size=$((size % 8192 + 1))
11682         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11683         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11684         rm -f $DIR/f212 $DIR/f212.xyz
11685 }
11686 run_test 212 "Sendfile test ============================================"
11687
11688 test_213() {
11689         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11690         cancel_lru_locks osc
11691         lctl set_param fail_loc=0x8000040f
11692         # generate a read lock
11693         cat $DIR/$tfile > /dev/null
11694         # write to the file, it will try to cancel the above read lock.
11695         cat /etc/hosts >> $DIR/$tfile
11696 }
11697 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11698
11699 test_214() { # for bug 20133
11700         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11701         for (( i=0; i < 340; i++ )) ; do
11702                 touch $DIR/$tdir/d214c/a$i
11703         done
11704
11705         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11706         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11707         ls $DIR/d214c || error "ls $DIR/d214c failed"
11708         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11709         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11710 }
11711 run_test 214 "hash-indexed directory test - bug 20133"
11712
11713 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11714 create_lnet_proc_files() {
11715         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
11716         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11717
11718         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11719         rm -f "$TMP/lnet_$1.sys_tmp"
11720 }
11721
11722 # counterpart of create_lnet_proc_files
11723 remove_lnet_proc_files() {
11724         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11725 }
11726
11727 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11728 # 3rd arg as regexp for body
11729 check_lnet_proc_stats() {
11730         local l=$(cat "$TMP/lnet_$1" |wc -l)
11731         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
11732
11733         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
11734 }
11735
11736 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11737 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
11738 # optional and can be regexp for 2nd line (lnet.routes case)
11739 check_lnet_proc_entry() {
11740         local blp=2          # blp stands for 'position of 1st line of body'
11741         [ -z "$5" ] || blp=3 # lnet.routes case
11742
11743         local l=$(cat "$TMP/lnet_$1" |wc -l)
11744         # subtracting one from $blp because the body can be empty
11745         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
11746
11747         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
11748                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
11749
11750         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
11751                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
11752
11753         # bail out if any unexpected line happened
11754         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
11755         [ "$?" != 0 ] || error "$2 misformatted"
11756 }
11757
11758 test_215() { # for bugs 18102, 21079, 21517
11759         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11760         local N='(0|[1-9][0-9]*)'       # non-negative numeric
11761         local P='[1-9][0-9]*'           # positive numeric
11762         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
11763         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
11764         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
11765         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
11766
11767         local L1 # regexp for 1st line
11768         local L2 # regexp for 2nd line (optional)
11769         local BR # regexp for the rest (body)
11770
11771         # lnet.stats should look as 11 space-separated non-negative numerics
11772         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
11773         create_lnet_proc_files "stats"
11774         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
11775         remove_lnet_proc_files "stats"
11776
11777         # lnet.routes should look like this:
11778         # Routing disabled/enabled
11779         # net hops priority state router
11780         # where net is a string like tcp0, hops > 0, priority >= 0,
11781         # state is up/down,
11782         # router is a string like 192.168.1.1@tcp2
11783         L1="^Routing (disabled|enabled)$"
11784         L2="^net +hops +priority +state +router$"
11785         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
11786         create_lnet_proc_files "routes"
11787         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
11788         remove_lnet_proc_files "routes"
11789
11790         # lnet.routers should look like this:
11791         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
11792         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
11793         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
11794         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
11795         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
11796         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
11797         create_lnet_proc_files "routers"
11798         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
11799         remove_lnet_proc_files "routers"
11800
11801         # lnet.peers should look like this:
11802         # nid refs state last max rtr min tx min queue
11803         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
11804         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
11805         # numeric (0 or >0 or <0), queue >= 0.
11806         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
11807         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
11808         create_lnet_proc_files "peers"
11809         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
11810         remove_lnet_proc_files "peers"
11811
11812         # lnet.buffers  should look like this:
11813         # pages count credits min
11814         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
11815         L1="^pages +count +credits +min$"
11816         BR="^ +$N +$N +$I +$I$"
11817         create_lnet_proc_files "buffers"
11818         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
11819         remove_lnet_proc_files "buffers"
11820
11821         # lnet.nis should look like this:
11822         # nid status alive refs peer rtr max tx min
11823         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
11824         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
11825         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
11826         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
11827         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
11828         create_lnet_proc_files "nis"
11829         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
11830         remove_lnet_proc_files "nis"
11831
11832         # can we successfully write to lnet.stats?
11833         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
11834         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
11835 }
11836 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
11837
11838 test_216() { # bug 20317
11839         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11840         remote_ost_nodsh && skip "remote OST with nodsh" && return
11841
11842         local node
11843         local facets=$(get_facets OST)
11844         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11845
11846         save_lustre_params client "osc.*.contention_seconds" > $p
11847         save_lustre_params $facets \
11848                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
11849         save_lustre_params $facets \
11850                 "ldlm.namespaces.filter-*.contended_locks" >> $p
11851         save_lustre_params $facets \
11852                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
11853         clear_osc_stats
11854
11855         # agressive lockless i/o settings
11856         for node in $(osts_nodes); do
11857                 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'
11858         done
11859         lctl set_param -n osc.*.contention_seconds 60
11860
11861         $DIRECTIO write $DIR/$tfile 0 10 4096
11862         $CHECKSTAT -s 40960 $DIR/$tfile
11863
11864         # disable lockless i/o
11865         for node in $(osts_nodes); do
11866                 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'
11867         done
11868         lctl set_param -n osc.*.contention_seconds 0
11869         clear_osc_stats
11870
11871         dd if=/dev/zero of=$DIR/$tfile count=0
11872         $CHECKSTAT -s 0 $DIR/$tfile
11873
11874         restore_lustre_params <$p
11875         rm -f $p
11876         rm $DIR/$tfile
11877 }
11878 run_test 216 "check lockless direct write works and updates file size and kms correctly"
11879
11880 test_217() { # bug 22430
11881         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11882         local node
11883         local nid
11884
11885         for node in $(nodes_list); do
11886                 nid=$(host_nids_address $node $NETTYPE)
11887                 if [[ $nid = *-* ]] ; then
11888                         echo "lctl ping $nid@$NETTYPE"
11889                         lctl ping $nid@$NETTYPE
11890                 else
11891                         echo "skipping $node (no hyphen detected)"
11892                 fi
11893         done
11894 }
11895 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
11896
11897 test_218() {
11898        # do directio so as not to populate the page cache
11899        log "creating a 10 Mb file"
11900        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11901        log "starting reads"
11902        dd if=$DIR/$tfile of=/dev/null bs=4096 &
11903        log "truncating the file"
11904        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11905        log "killing dd"
11906        kill %+ || true # reads might have finished
11907        echo "wait until dd is finished"
11908        wait
11909        log "removing the temporary file"
11910        rm -rf $DIR/$tfile || error "tmp file removal failed"
11911 }
11912 run_test 218 "parallel read and truncate should not deadlock ======================="
11913
11914 test_219() {
11915         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11916         # write one partial page
11917         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
11918         # set no grant so vvp_io_commit_write will do sync write
11919         $LCTL set_param fail_loc=0x411
11920         # write a full page at the end of file
11921         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
11922
11923         $LCTL set_param fail_loc=0
11924         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
11925         $LCTL set_param fail_loc=0x411
11926         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
11927
11928         # LU-4201
11929         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
11930         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
11931 }
11932 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
11933
11934 test_220() { #LU-325
11935         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11936         remote_ost_nodsh && skip "remote OST with nodsh" && return
11937         local OSTIDX=0
11938
11939         test_mkdir -p $DIR/$tdir
11940         local OST=$($LFS osts | grep ${OSTIDX}": " | \
11941                 awk '{print $2}' | sed -e 's/_UUID$//')
11942
11943         # on the mdt's osc
11944         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
11945         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
11946                         osc.$mdtosc_proc1.prealloc_last_id)
11947         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
11948                         osc.$mdtosc_proc1.prealloc_next_id)
11949
11950         $LFS df -i
11951
11952         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
11953         #define OBD_FAIL_OST_ENOINO              0x229
11954         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
11955         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
11956         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
11957
11958         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
11959
11960         MDSOBJS=$((last_id - next_id))
11961         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
11962
11963         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
11964         echo "OST still has $count kbytes free"
11965
11966         echo "create $MDSOBJS files @next_id..."
11967         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
11968
11969         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11970                         osc.$mdtosc_proc1.prealloc_last_id)
11971         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11972                         osc.$mdtosc_proc1.prealloc_next_id)
11973
11974         echo "after creation, last_id=$last_id2, next_id=$next_id2"
11975         $LFS df -i
11976
11977         echo "cleanup..."
11978
11979         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
11980         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
11981
11982         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
11983         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
11984         echo "unlink $MDSOBJS files @$next_id..."
11985         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
11986 }
11987 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
11988
11989 test_221() {
11990         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11991         dd if=`which date` of=$MOUNT/date oflag=sync
11992         chmod +x $MOUNT/date
11993
11994         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
11995         $LCTL set_param fail_loc=0x80001401
11996
11997         $MOUNT/date > /dev/null
11998         rm -f $MOUNT/date
11999 }
12000 run_test 221 "make sure fault and truncate race to not cause OOM"
12001
12002 test_222a () {
12003         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12004        rm -rf $DIR/$tdir
12005        test_mkdir -p $DIR/$tdir
12006        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12007        createmany -o $DIR/$tdir/$tfile 10
12008        cancel_lru_locks mdc
12009        cancel_lru_locks osc
12010        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12011        $LCTL set_param fail_loc=0x31a
12012        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
12013        $LCTL set_param fail_loc=0
12014        rm -r $DIR/$tdir
12015 }
12016 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
12017
12018 test_222b () {
12019         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12020        rm -rf $DIR/$tdir
12021        test_mkdir -p $DIR/$tdir
12022        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12023        createmany -o $DIR/$tdir/$tfile 10
12024        cancel_lru_locks mdc
12025        cancel_lru_locks osc
12026        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12027        $LCTL set_param fail_loc=0x31a
12028        rm -r $DIR/$tdir || "AGL for rmdir failed"
12029        $LCTL set_param fail_loc=0
12030 }
12031 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
12032
12033 test_223 () {
12034         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12035        rm -rf $DIR/$tdir
12036        test_mkdir -p $DIR/$tdir
12037        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12038        createmany -o $DIR/$tdir/$tfile 10
12039        cancel_lru_locks mdc
12040        cancel_lru_locks osc
12041        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
12042        $LCTL set_param fail_loc=0x31b
12043        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
12044        $LCTL set_param fail_loc=0
12045        rm -r $DIR/$tdir
12046 }
12047 run_test 223 "osc reenqueue if without AGL lock granted ======================="
12048
12049 test_224a() { # LU-1039, MRP-303
12050         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12051         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
12052         $LCTL set_param fail_loc=0x508
12053         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
12054         $LCTL set_param fail_loc=0
12055         df $DIR
12056 }
12057 run_test 224a "Don't panic on bulk IO failure"
12058
12059 test_224b() { # LU-1039, MRP-303
12060         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12061         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
12062         cancel_lru_locks osc
12063         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
12064         $LCTL set_param fail_loc=0x515
12065         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
12066         $LCTL set_param fail_loc=0
12067         df $DIR
12068 }
12069 run_test 224b "Don't panic on bulk IO failure"
12070
12071 test_224c() { # LU-6441
12072         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12073         local pages_per_rpc=$($LCTL get_param \
12074                                 osc.*.max_pages_per_rpc)
12075         local at_max=$($LCTL get_param -n at_max)
12076         local timeout=$($LCTL get_param -n timeout)
12077         local test_at="$LCTL get_param -n at_max"
12078         local param_at="$FSNAME.sys.at_max"
12079         local test_timeout="$LCTL get_param -n timeout"
12080         local param_timeout="$FSNAME.sys.timeout"
12081
12082         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
12083
12084         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
12085                 error "conf_param at_max=0 failed"
12086         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
12087                 error "conf_param timeout=5 failed"
12088
12089         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
12090         $LCTL set_param fail_loc=0x520
12091         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
12092         sync
12093         $LCTL set_param fail_loc=0
12094
12095         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
12096                 error "conf_param at_max=$at_max failed"
12097         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
12098                 $timeout || error "conf_param timeout=$timeout failed"
12099
12100         $LCTL set_param -n $pages_per_rpc
12101 }
12102 run_test 224c "Don't hang if one of md lost during large bulk RPC"
12103
12104 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
12105 test_225a () {
12106         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12107         if [ -z ${MDSSURVEY} ]; then
12108               skip_env "mds-survey not found" && return
12109         fi
12110
12111         [ $MDSCOUNT -ge 2 ] &&
12112                 skip "skipping now for more than one MDT" && return
12113
12114        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12115             { skip "Need MDS version at least 2.2.51"; return; }
12116
12117        local mds=$(facet_host $SINGLEMDS)
12118        local target=$(do_nodes $mds 'lctl dl' | \
12119                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12120
12121        local cmd1="file_count=1000 thrhi=4"
12122        local cmd2="dir_count=2 layer=mdd stripe_count=0"
12123        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12124        local cmd="$cmd1 $cmd2 $cmd3"
12125
12126        rm -f ${TMP}/mds_survey*
12127        echo + $cmd
12128        eval $cmd || error "mds-survey with zero-stripe failed"
12129        cat ${TMP}/mds_survey*
12130        rm -f ${TMP}/mds_survey*
12131 }
12132 run_test 225a "Metadata survey sanity with zero-stripe"
12133
12134 test_225b () {
12135         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12136
12137         if [ -z ${MDSSURVEY} ]; then
12138               skip_env "mds-survey not found" && return
12139         fi
12140         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12141             { skip "Need MDS version at least 2.2.51"; return; }
12142
12143         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
12144               skip_env "Need to mount OST to test" && return
12145         fi
12146
12147         [ $MDSCOUNT -ge 2 ] &&
12148                 skip "skipping now for more than one MDT" && return
12149        local mds=$(facet_host $SINGLEMDS)
12150        local target=$(do_nodes $mds 'lctl dl' | \
12151                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12152
12153        local cmd1="file_count=1000 thrhi=4"
12154        local cmd2="dir_count=2 layer=mdd stripe_count=1"
12155        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12156        local cmd="$cmd1 $cmd2 $cmd3"
12157
12158        rm -f ${TMP}/mds_survey*
12159        echo + $cmd
12160        eval $cmd || error "mds-survey with stripe_count failed"
12161        cat ${TMP}/mds_survey*
12162        rm -f ${TMP}/mds_survey*
12163 }
12164 run_test 225b "Metadata survey sanity with stripe_count = 1"
12165
12166 mcreate_path2fid () {
12167         local mode=$1
12168         local major=$2
12169         local minor=$3
12170         local name=$4
12171         local desc=$5
12172         local path=$DIR/$tdir/$name
12173         local fid
12174         local rc
12175         local fid_path
12176
12177         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
12178                 error "cannot create $desc"
12179
12180         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
12181         rc=$?
12182         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
12183
12184         fid_path=$($LFS fid2path $MOUNT $fid)
12185         rc=$?
12186         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
12187
12188         [ "$path" == "$fid_path" ] ||
12189                 error "fid2path returned $fid_path, expected $path"
12190
12191         echo "pass with $path and $fid"
12192 }
12193
12194 test_226a () {
12195         rm -rf $DIR/$tdir
12196         mkdir -p $DIR/$tdir
12197
12198         mcreate_path2fid 0010666 0 0 fifo "FIFO"
12199         mcreate_path2fid 0020666 1 3 null "character special file (null)"
12200         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
12201         mcreate_path2fid 0040666 0 0 dir "directory"
12202         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
12203         mcreate_path2fid 0100666 0 0 file "regular file"
12204         mcreate_path2fid 0120666 0 0 link "symbolic link"
12205         mcreate_path2fid 0140666 0 0 sock "socket"
12206 }
12207 run_test 226a "call path2fid and fid2path on files of all type"
12208
12209 test_226b () {
12210         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12211         rm -rf $DIR/$tdir
12212         local MDTIDX=1
12213
12214         mkdir -p $DIR/$tdir
12215         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
12216                 error "create remote directory failed"
12217         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
12218         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
12219                                 "character special file (null)"
12220         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
12221                                 "character special file (no device)"
12222         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
12223         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
12224                                 "block special file (loop)"
12225         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
12226         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
12227         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
12228 }
12229 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
12230
12231 # LU-1299 Executing or running ldd on a truncated executable does not
12232 # cause an out-of-memory condition.
12233 test_227() {
12234         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12235         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
12236         dd if=$(which date) of=$MOUNT/date bs=1k count=1
12237         chmod +x $MOUNT/date
12238
12239         $MOUNT/date > /dev/null
12240         ldd $MOUNT/date > /dev/null
12241         rm -f $MOUNT/date
12242 }
12243 run_test 227 "running truncated executable does not cause OOM"
12244
12245 # LU-1512 try to reuse idle OI blocks
12246 test_228a() {
12247         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12248         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12249         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12250                 skip "non-ldiskfs backend" && return
12251
12252         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12253         local myDIR=$DIR/$tdir
12254
12255         mkdir -p $myDIR
12256         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12257         $LCTL set_param fail_loc=0x80001002
12258         createmany -o $myDIR/t- 10000
12259         $LCTL set_param fail_loc=0
12260         # The guard is current the largest FID holder
12261         touch $myDIR/guard
12262         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12263                     tr -d '[')
12264         local IDX=$(($SEQ % 64))
12265
12266         do_facet $SINGLEMDS sync
12267         # Make sure journal flushed.
12268         sleep 6
12269         local blk1=$(do_facet $SINGLEMDS \
12270                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12271                      grep Blockcount | awk '{print $4}')
12272
12273         # Remove old files, some OI blocks will become idle.
12274         unlinkmany $myDIR/t- 10000
12275         # Create new files, idle OI blocks should be reused.
12276         createmany -o $myDIR/t- 2000
12277         do_facet $SINGLEMDS sync
12278         # Make sure journal flushed.
12279         sleep 6
12280         local blk2=$(do_facet $SINGLEMDS \
12281                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12282                      grep Blockcount | awk '{print $4}')
12283
12284         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12285 }
12286 run_test 228a "try to reuse idle OI blocks"
12287
12288 test_228b() {
12289         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12290         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12291         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12292                 skip "non-ldiskfs backend" && return
12293
12294         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12295         local myDIR=$DIR/$tdir
12296
12297         mkdir -p $myDIR
12298         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12299         $LCTL set_param fail_loc=0x80001002
12300         createmany -o $myDIR/t- 10000
12301         $LCTL set_param fail_loc=0
12302         # The guard is current the largest FID holder
12303         touch $myDIR/guard
12304         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12305                     tr -d '[')
12306         local IDX=$(($SEQ % 64))
12307
12308         do_facet $SINGLEMDS sync
12309         # Make sure journal flushed.
12310         sleep 6
12311         local blk1=$(do_facet $SINGLEMDS \
12312                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12313                      grep Blockcount | awk '{print $4}')
12314
12315         # Remove old files, some OI blocks will become idle.
12316         unlinkmany $myDIR/t- 10000
12317
12318         # stop the MDT
12319         stop $SINGLEMDS || error "Fail to stop MDT."
12320         # remount the MDT
12321         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
12322
12323         df $MOUNT || error "Fail to df."
12324         # Create new files, idle OI blocks should be reused.
12325         createmany -o $myDIR/t- 2000
12326         do_facet $SINGLEMDS sync
12327         # Make sure journal flushed.
12328         sleep 6
12329         local blk2=$(do_facet $SINGLEMDS \
12330                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12331                      grep Blockcount | awk '{print $4}')
12332
12333         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12334 }
12335 run_test 228b "idle OI blocks can be reused after MDT restart"
12336
12337 #LU-1881
12338 test_228c() {
12339         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12340         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12341         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12342                 skip "non-ldiskfs backend" && return
12343
12344         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12345         local myDIR=$DIR/$tdir
12346
12347         mkdir -p $myDIR
12348         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12349         $LCTL set_param fail_loc=0x80001002
12350         # 20000 files can guarantee there are index nodes in the OI file
12351         createmany -o $myDIR/t- 20000
12352         $LCTL set_param fail_loc=0
12353         # The guard is current the largest FID holder
12354         touch $myDIR/guard
12355         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12356                     tr -d '[')
12357         local IDX=$(($SEQ % 64))
12358
12359         do_facet $SINGLEMDS sync
12360         # Make sure journal flushed.
12361         sleep 6
12362         local blk1=$(do_facet $SINGLEMDS \
12363                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12364                      grep Blockcount | awk '{print $4}')
12365
12366         # Remove old files, some OI blocks will become idle.
12367         unlinkmany $myDIR/t- 20000
12368         rm -f $myDIR/guard
12369         # The OI file should become empty now
12370
12371         # Create new files, idle OI blocks should be reused.
12372         createmany -o $myDIR/t- 2000
12373         do_facet $SINGLEMDS sync
12374         # Make sure journal flushed.
12375         sleep 6
12376         local blk2=$(do_facet $SINGLEMDS \
12377                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12378                      grep Blockcount | awk '{print $4}')
12379
12380         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12381 }
12382 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
12383
12384 test_229() { # LU-2482, LU-3448
12385         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
12386                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
12387                 return
12388         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12389         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
12390
12391         rm -f $DIR/$tfile
12392
12393         # Create a file with a released layout and stripe count 2.
12394         $MULTIOP $DIR/$tfile H2c ||
12395                 error "failed to create file with released layout"
12396
12397         $GETSTRIPE -v $DIR/$tfile
12398
12399         local pattern=$($GETSTRIPE -L $DIR/$tfile)
12400         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
12401
12402         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
12403         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
12404         stat $DIR/$tfile || error "failed to stat released file"
12405
12406         chown $RUNAS_ID $DIR/$tfile ||
12407                 error "chown $RUNAS_ID $DIR/$tfile failed"
12408
12409         chgrp $RUNAS_ID $DIR/$tfile ||
12410                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12411
12412         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12413         rm $DIR/$tfile || error "failed to remove released file"
12414 }
12415 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12416
12417 test_230a() {
12418         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12419         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12420         local MDTIDX=1
12421
12422         test_mkdir $DIR/$tdir
12423         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
12424         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12425         [ $mdt_idx -ne 0 ] &&
12426                 error "create local directory on wrong MDT $mdt_idx"
12427
12428         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12429                         error "create remote directory failed"
12430         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12431         [ $mdt_idx -ne $MDTIDX ] &&
12432                 error "create remote directory on wrong MDT $mdt_idx"
12433
12434         createmany -o $DIR/$tdir/test_230/t- 10 ||
12435                 error "create files on remote directory failed"
12436         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12437         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12438         rm -r $DIR/$tdir || error "unlink remote directory failed"
12439 }
12440 run_test 230a "Create remote directory and files under the remote directory"
12441
12442 test_230b() {
12443         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12444         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12445         local MDTIDX=1
12446         local mdt_index
12447         local i
12448         local file
12449         local pid
12450         local stripe_count
12451         local migrate_dir=$DIR/$tdir/migrate_dir
12452         local other_dir=$DIR/$tdir/other_dir
12453
12454         test_mkdir $DIR/$tdir
12455         test_mkdir -i0 -c1 $migrate_dir
12456         test_mkdir -i0 -c1 $other_dir
12457         for ((i=0; i<10; i++)); do
12458                 mkdir -p $migrate_dir/dir_${i}
12459                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12460                         error "create files under remote dir failed $i"
12461         done
12462
12463         cp /etc/passwd $migrate_dir/$tfile
12464         cp /etc/passwd $other_dir/$tfile
12465         chattr +SAD $migrate_dir
12466         chattr +SAD $migrate_dir/$tfile
12467
12468         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12469         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12470         local old_dir_mode=$(stat -c%f $migrate_dir)
12471         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
12472
12473         mkdir -p $migrate_dir/dir_default_stripe2
12474         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12475         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12476
12477         mkdir -p $other_dir
12478         ln $migrate_dir/$tfile $other_dir/luna
12479         ln $migrate_dir/$tfile $migrate_dir/sofia
12480         ln $other_dir/$tfile $migrate_dir/david
12481         ln -s $migrate_dir/$tfile $other_dir/zachary
12482         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12483         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12484
12485         $LFS mv -v -M $MDTIDX $migrate_dir ||
12486                 error "migrate remote dir error"
12487
12488         echo "migratate to MDT1, then checking.."
12489         for ((i = 0; i < 10; i++)); do
12490                 for file in $(find $migrate_dir/dir_${i}); do
12491                         mdt_index=$($LFS getstripe -M $file)
12492                         [ $mdt_index == $MDTIDX ] ||
12493                                 error "$file is not on MDT${MDTIDX}"
12494                 done
12495         done
12496
12497         # the multiple link file should still in MDT0
12498         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12499         [ $mdt_index == 0 ] ||
12500                 error "$file is not on MDT${MDTIDX}"
12501
12502         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12503         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12504                 error " expect $old_dir_flag get $new_dir_flag"
12505
12506         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12507         [ "$old_file_flag" = "$new_file_flag" ] ||
12508                 error " expect $old_file_flag get $new_file_flag"
12509
12510         local new_dir_mode=$(stat -c%f $migrate_dir)
12511         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12512                 error "expect mode $old_dir_mode get $new_dir_mode"
12513
12514         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12515         [ "$old_file_mode" = "$new_file_mode" ] ||
12516                 error "expect mode $old_file_mode get $new_file_mode"
12517
12518         diff /etc/passwd $migrate_dir/$tfile ||
12519                 error "$tfile different after migration"
12520
12521         diff /etc/passwd $other_dir/luna ||
12522                 error "luna different after migration"
12523
12524         diff /etc/passwd $migrate_dir/sofia ||
12525                 error "sofia different after migration"
12526
12527         diff /etc/passwd $migrate_dir/david ||
12528                 error "david different after migration"
12529
12530         diff /etc/passwd $other_dir/zachary ||
12531                 error "zachary different after migration"
12532
12533         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12534                 error "${tfile}_ln different after migration"
12535
12536         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12537                 error "${tfile}_ln_other different after migration"
12538
12539         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12540         [ $stripe_count = 2 ] ||
12541                 error "dir strpe_count $d != 2 after migration."
12542
12543         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12544         [ $stripe_count = 2 ] ||
12545                 error "file strpe_count $d != 2 after migration."
12546
12547         #migrate back to MDT0
12548         MDTIDX=0
12549         $LFS mv -v -M $MDTIDX $migrate_dir ||
12550                 error "migrate remote dir error"
12551
12552         echo "migrate back to MDT0, checking.."
12553         for file in $(find $migrate_dir); do
12554                 mdt_index=$($LFS getstripe -M $file)
12555                 [ $mdt_index == $MDTIDX ] ||
12556                         error "$file is not on MDT${MDTIDX}"
12557         done
12558
12559         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12560         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12561                 error " expect $old_dir_flag get $new_dir_flag"
12562
12563         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12564         [ "$old_file_flag" = "$new_file_flag" ] ||
12565                 error " expect $old_file_flag get $new_file_flag"
12566
12567         local new_dir_mode=$(stat -c%f $migrate_dir)
12568         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12569                 error "expect mode $old_dir_mode get $new_dir_mode"
12570
12571         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12572         [ "$old_file_mode" = "$new_file_mode" ] ||
12573                 error "expect mode $old_file_mode get $new_file_mode"
12574
12575         diff /etc/passwd ${migrate_dir}/$tfile ||
12576                 error "$tfile different after migration"
12577
12578         diff /etc/passwd ${other_dir}/luna ||
12579                 error "luna different after migration"
12580
12581         diff /etc/passwd ${migrate_dir}/sofia ||
12582                 error "sofia different after migration"
12583
12584         diff /etc/passwd ${other_dir}/zachary ||
12585                 error "zachary different after migration"
12586
12587         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12588                 error "${tfile}_ln different after migration"
12589
12590         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12591                 error "${tfile}_ln_other different after migration"
12592
12593         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12594         [ $stripe_count = 2 ] ||
12595                 error "dir strpe_count $d != 2 after migration."
12596
12597         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12598         [ $stripe_count = 2 ] ||
12599                 error "file strpe_count $d != 2 after migration."
12600
12601         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12602 }
12603 run_test 230b "migrate directory"
12604
12605 test_230c() {
12606         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12607         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12608         local MDTIDX=1
12609         local mdt_index
12610         local file
12611         local migrate_dir=$DIR/$tdir/migrate_dir
12612
12613         #If migrating directory fails in the middle, all entries of
12614         #the directory is still accessiable.
12615         test_mkdir $DIR/$tdir
12616         test_mkdir -i0 -c1 $migrate_dir
12617         stat $migrate_dir
12618         createmany -o $migrate_dir/f 10 ||
12619                 error "create files under ${migrate_dir} failed"
12620
12621         #failed after migrating 5 entries
12622         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12623         do_facet mds1 lctl set_param fail_loc=0x20001801
12624         do_facet mds1 lctl  set_param fail_val=5
12625         local t=$(ls $migrate_dir | wc -l)
12626         $LFS mv --mdt-index $MDTIDX $migrate_dir &&
12627                 error "migrate should fail after 5 entries"
12628         local u=$(ls $migrate_dir | wc -l)
12629         [ "$u" == "$t" ] || error "$u != $t during migration"
12630
12631         for file in $(find $migrate_dir); do
12632                 stat $file || error "stat $file failed"
12633         done
12634
12635         do_facet mds1 lctl set_param fail_loc=0
12636         do_facet mds1 lctl set_param fail_val=0
12637
12638         $LFS mv -M $MDTIDX $migrate_dir ||
12639                 error "migrate open files should failed with open files"
12640
12641         echo "Finish migration, then checking.."
12642         for file in $(find $migrate_dir); do
12643                 mdt_index=$($LFS getstripe -M $file)
12644                 [ $mdt_index == $MDTIDX ] ||
12645                         error "$file is not on MDT${MDTIDX}"
12646         done
12647
12648         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12649 }
12650 run_test 230c "check directory accessiblity if migration is failed"
12651
12652 test_230d() {
12653         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12654         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12655         local MDTIDX=1
12656         local mdt_index
12657         local migrate_dir=$DIR/$tdir/migrate_dir
12658         local i
12659         local j
12660
12661         test_mkdir $DIR/$tdir
12662         test_mkdir -i0 -c1 $migrate_dir
12663
12664         for ((i=0; i<100; i++)); do
12665                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
12666                 createmany -o $migrate_dir/dir_${i}/f 100 ||
12667                         error "create files under remote dir failed $i"
12668         done
12669
12670         $LFS mv -M $MDTIDX -v $migrate_dir || error "migrate remote dir error"
12671
12672         echo "Finish migration, then checking.."
12673         for file in $(find $migrate_dir); do
12674                 mdt_index=$($LFS getstripe -M $file)
12675                 [ $mdt_index == $MDTIDX ] ||
12676                         error "$file is not on MDT${MDTIDX}"
12677         done
12678
12679         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12680 }
12681 run_test 230d "check migrate big directory"
12682
12683 test_231a()
12684 {
12685         # For simplicity this test assumes that max_pages_per_rpc
12686         # is the same across all OSCs
12687         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
12688         local bulk_size=$((max_pages * 4096))
12689
12690         mkdir -p $DIR/$tdir
12691
12692         # clear the OSC stats
12693         $LCTL set_param osc.*.stats=0 &>/dev/null
12694
12695         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
12696         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
12697                 oflag=direct &>/dev/null || error "dd failed"
12698
12699         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
12700         if [ x$nrpcs != "x1" ]; then
12701                 error "found $nrpc ost_write RPCs, not 1 as expected"
12702         fi
12703
12704         # Drop the OSC cache, otherwise we will read from it
12705         cancel_lru_locks osc
12706
12707         # clear the OSC stats
12708         $LCTL set_param osc.*.stats=0 &>/dev/null
12709
12710         # Client reads $bulk_size.
12711         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
12712                 iflag=direct &>/dev/null || error "dd failed"
12713
12714         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
12715         if [ x$nrpcs != "x1" ]; then
12716                 error "found $nrpc ost_read RPCs, not 1 as expected"
12717         fi
12718 }
12719 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
12720
12721 test_231b() {
12722         mkdir -p $DIR/$tdir
12723         local i
12724         for i in {0..1023}; do
12725                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
12726                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
12727                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
12728         done
12729         sync
12730 }
12731 run_test 231b "must not assert on fully utilized OST request buffer"
12732
12733 test_232() {
12734         mkdir -p $DIR/$tdir
12735         #define OBD_FAIL_LDLM_OST_LVB            0x31c
12736         $LCTL set_param fail_loc=0x31c
12737
12738         # ignore dd failure
12739         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
12740
12741         $LCTL set_param fail_loc=0
12742         umount_client $MOUNT || error "umount failed"
12743         mount_client $MOUNT || error "mount failed"
12744 }
12745 run_test 232 "failed lock should not block umount"
12746
12747 test_233a() {
12748         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
12749         { skip "Need MDS version at least 2.3.64"; return; }
12750
12751         local fid=$($LFS path2fid $MOUNT)
12752         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12753                 error "cannot access $MOUNT using its FID '$fid'"
12754 }
12755 run_test 233a "checking that OBF of the FS root succeeds"
12756
12757 test_233b() {
12758         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
12759         { skip "Need MDS version at least 2.5.90"; return; }
12760
12761         local fid=$($LFS path2fid $MOUNT/.lustre)
12762         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12763                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
12764
12765         fid=$($LFS path2fid $MOUNT/.lustre/fid)
12766         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12767                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
12768 }
12769 run_test 233b "checking that OBF of the FS .lustre succeeds"
12770
12771 test_234() {
12772         local p="$TMP/sanityN-$TESTNAME.parameters"
12773         save_lustre_params client "llite.*.xattr_cache" > $p
12774         lctl set_param llite.*.xattr_cache 1 ||
12775                 { skip "xattr cache is not supported"; return 0; }
12776
12777         mkdir -p $DIR/$tdir || error "mkdir failed"
12778         touch $DIR/$tdir/$tfile || error "touch failed"
12779         # OBD_FAIL_LLITE_XATTR_ENOMEM
12780         $LCTL set_param fail_loc=0x1405
12781         # output of the form: attr 2 4 44 3 fc13 x86_64
12782         V=($(IFS=".-" rpm -q attr))
12783         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
12784               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
12785                 # attr pre-2.4.44-7 had a bug with rc
12786                 # LU-3703 - SLES 11 and FC13 clients have older attr
12787                 getfattr -n user.attr $DIR/$tdir/$tfile &&
12788                         error "getfattr should have failed with ENOMEM"
12789         else
12790                 skip "LU-3703: attr version $(getfattr --version) too old"
12791         fi
12792         $LCTL set_param fail_loc=0x0
12793         rm -rf $DIR/$tdir
12794
12795         restore_lustre_params < $p
12796         rm -f $p
12797 }
12798 run_test 234 "xattr cache should not crash on ENOMEM"
12799
12800 test_235() {
12801         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
12802                 skip "Need MDS version at least 2.4.52" && return
12803         flock_deadlock $DIR/$tfile
12804         local RC=$?
12805         case $RC in
12806                 0)
12807                 ;;
12808                 124) error "process hangs on a deadlock"
12809                 ;;
12810                 *) error "error executing flock_deadlock $DIR/$tfile"
12811                 ;;
12812         esac
12813 }
12814 run_test 235 "LU-1715: flock deadlock detection does not work properly"
12815
12816 #LU-2935
12817 test_236() {
12818         check_swap_layouts_support && return 0
12819         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
12820
12821         local ref1=/etc/passwd
12822         local ref2=/etc/group
12823         local file1=$DIR/$tdir/f1
12824         local file2=$DIR/$tdir/f2
12825
12826         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
12827         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
12828         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
12829         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
12830         local fd=$(free_fd)
12831         local cmd="exec $fd<>$file2"
12832         eval $cmd
12833         rm $file2
12834         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
12835                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
12836         cmd="exec $fd>&-"
12837         eval $cmd
12838         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12839
12840         #cleanup
12841         rm -rf $DIR/$tdir
12842 }
12843 run_test 236 "Layout swap on open unlinked file"
12844
12845 # test to verify file handle related system calls
12846 # (name_to_handle_at/open_by_handle_at)
12847 # The new system calls are supported in glibc >= 2.14.
12848
12849 test_237() {
12850         echo "Test file_handle syscalls" > $DIR/$tfile ||
12851                 error "write failed"
12852         check_fhandle_syscalls $DIR/$tfile ||
12853                 error "check_fhandle_syscalls failed"
12854 }
12855 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
12856
12857 # LU-4659 linkea consistency
12858 test_238() {
12859         local server_version=$(lustre_version_code $SINGLEMDS)
12860
12861         [[ $server_version -gt $(version_code 2.5.57) ]] ||
12862                 [[ $server_version -gt $(version_code 2.5.1) &&
12863                    $server_version -lt $(version_code 2.5.50) ]] ||
12864                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
12865
12866         touch $DIR/$tfile
12867         ln $DIR/$tfile $DIR/$tfile.lnk
12868         touch $DIR/$tfile.new
12869         mv $DIR/$tfile.new $DIR/$tfile
12870         local fid1=$($LFS path2fid $DIR/$tfile)
12871         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
12872         local path1=$($LFS fid2path $FSNAME "$fid1")
12873         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
12874         local path2=$($LFS fid2path $FSNAME "$fid2")
12875         [ $tfile.lnk == $path2 ] ||
12876                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
12877         rm -f $DIR/$tfile*
12878 }
12879 run_test 238 "Verify linkea consistency"
12880
12881 test_239() {
12882         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
12883                 skip "Need MDS version at least 2.5.60" && return
12884         local list=$(comma_list $(mdts_nodes))
12885
12886         mkdir -p $DIR/$tdir
12887         createmany -o $DIR/$tdir/f- 5000
12888         unlinkmany $DIR/$tdir/f- 5000
12889         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
12890         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
12891                         osc.*MDT*.sync_in_flight" | calc_sum)
12892         [ "$changes" -eq 0 ] || error "$changes not synced"
12893 }
12894 run_test 239 "osp_sync test"
12895
12896 test_240() {
12897         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12898
12899         mkdir -p $DIR/$tdir
12900
12901         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
12902                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
12903         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
12904                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
12905
12906         umount_client $MOUNT || error "umount failed"
12907         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
12908         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
12909         mount_client $MOUNT || error "failed to mount client"
12910
12911         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
12912         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
12913 }
12914 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
12915
12916 test_241_bio() {
12917         for LOOP in $(seq $1); do
12918                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
12919                 cancel_lru_locks osc
12920         done
12921 }
12922
12923 test_241_dio() {
12924         for LOOP in $(seq $1); do
12925                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
12926                                                 iflag=direct 2>/dev/null
12927         done
12928 }
12929
12930 test_241() {
12931         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
12932         ls -la $DIR/$tfile
12933         cancel_lru_locks osc
12934         test_241_bio 1000 &
12935         PID=$!
12936         test_241_dio 1000
12937         wait $PID
12938 }
12939 run_test 241 "bio vs dio"
12940
12941 test_241b() {
12942         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
12943         ls -la $DIR/$tfile
12944         test_241_dio 1000 &
12945         PID=$!
12946         test_241_dio 1000
12947         wait $PID
12948 }
12949 run_test 241b "dio vs dio"
12950
12951 test_242() {
12952         mkdir -p $DIR/$tdir
12953         touch $DIR/$tdir/$tfile
12954
12955         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
12956         do_facet mds1 lctl set_param fail_loc=0x105
12957         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
12958
12959         do_facet mds1 lctl set_param fail_loc=0
12960         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
12961 }
12962 run_test 242 "mdt_readpage failure should not cause directory unreadable"
12963
12964 test_243()
12965 {
12966         test_mkdir -p $DIR/$tdir
12967         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
12968 }
12969 run_test 243 "various group lock tests"
12970
12971 test_244()
12972 {
12973         test_mkdir -p $DIR/$tdir
12974         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
12975         sendfile_grouplock $DIR/$tdir/$tfile || \
12976                 error "sendfile+grouplock failed"
12977         rm -rf $DIR/$tdir
12978 }
12979 run_test 244 "sendfile with group lock tests"
12980
12981 test_250() {
12982         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
12983          && skip "no 16TB file size limit on ZFS" && return
12984
12985         $SETSTRIPE -c 1 $DIR/$tfile
12986         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
12987         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
12988         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
12989         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
12990                 conv=notrunc,fsync && error "append succeeded"
12991         return 0
12992 }
12993 run_test 250 "Write above 16T limit"
12994
12995 test_251() {
12996         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
12997
12998         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
12999         #Skip once - writing the first stripe will succeed
13000         $LCTL set_param fail_loc=0xa0001407 fail_val=1
13001         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
13002                 error "short write happened"
13003
13004         $LCTL set_param fail_loc=0xa0001407 fail_val=1
13005         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
13006                 error "short read happened"
13007
13008         rm -f $DIR/$tfile
13009 }
13010 run_test 251 "Handling short read and write correctly"
13011
13012 cleanup_test_300() {
13013         trap 0
13014         umask $SAVE_UMASK
13015 }
13016 test_striped_dir() {
13017         local mdt_index=$1
13018         local stripe_count
13019         local stripe_index
13020
13021         mkdir -p $DIR/$tdir
13022
13023         SAVE_UMASK=$(umask)
13024         trap cleanup_test_300 RETURN EXIT
13025
13026         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
13027                                                 $DIR/$tdir/striped_dir ||
13028                 error "set striped dir error"
13029
13030         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
13031         [ "$mode" = "755" ] || error "expect 755 got $mode"
13032
13033         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
13034                 error "getdirstripe failed"
13035         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
13036         if [ "$stripe_count" != "2" ]; then
13037                 error "stripe_count is $stripe_count, expect 2"
13038         fi
13039
13040         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
13041         if [ "$stripe_index" != "$mdt_index" ]; then
13042                 error "stripe_index is $stripe_index, expect $mdt_index"
13043         fi
13044
13045         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13046                 error "nlink error after create striped dir"
13047
13048         mkdir $DIR/$tdir/striped_dir/a
13049         mkdir $DIR/$tdir/striped_dir/b
13050
13051         stat $DIR/$tdir/striped_dir/a ||
13052                 error "create dir under striped dir failed"
13053         stat $DIR/$tdir/striped_dir/b ||
13054                 error "create dir under striped dir failed"
13055
13056         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
13057                 error "nlink error after mkdir"
13058
13059         rmdir $DIR/$tdir/striped_dir/a
13060         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
13061                 error "nlink error after rmdir"
13062
13063         rmdir $DIR/$tdir/striped_dir/b
13064         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13065                 error "nlink error after rmdir"
13066
13067         chattr +i $DIR/$tdir/striped_dir
13068         createmany -o $DIR/$tdir/striped_dir/f 10 &&
13069                 error "immutable flags not working under striped dir!"
13070         chattr -i $DIR/$tdir/striped_dir
13071
13072         rmdir $DIR/$tdir/striped_dir ||
13073                 error "rmdir striped dir error"
13074
13075         cleanup_test_300
13076
13077         true
13078 }
13079
13080 test_300a() {
13081         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13082         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13083
13084         test_striped_dir 0 || error "failed on striped dir on MDT0"
13085         test_striped_dir 1 || error "failed on striped dir on MDT0"
13086 }
13087 run_test 300a "basic striped dir sanity test"
13088
13089 test_300b() {
13090         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13091         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13092         local i
13093         local mtime1
13094         local mtime2
13095         local mtime3
13096
13097         test_mkdir $DIR/$tdir || error "mkdir fail"
13098         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13099                 error "set striped dir error"
13100         for ((i=0; i<10; i++)); do
13101                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
13102                 sleep 1
13103                 touch $DIR/$tdir/striped_dir/file_$i ||
13104                                         error "touch error $i"
13105                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
13106                 [ $mtime1 -eq $mtime2 ] &&
13107                         error "mtime not change after create"
13108                 sleep 1
13109                 rm -f $DIR/$tdir/striped_dir/file_$i ||
13110                                         error "unlink error $i"
13111                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
13112                 [ $mtime2 -eq $mtime3 ] &&
13113                         error "mtime did not change after unlink"
13114         done
13115         true
13116 }
13117 run_test 300b "check ctime/mtime for striped dir"
13118
13119 test_300c() {
13120         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13121         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13122         local file_count
13123
13124         mkdir -p $DIR/$tdir
13125         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
13126                 error "set striped dir error"
13127
13128         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
13129                 error "chown striped dir failed"
13130
13131         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
13132                 error "create 5k files failed"
13133
13134         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
13135
13136         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
13137
13138         rm -rf $DIR/$tdir
13139 }
13140 run_test 300c "chown && check ls under striped directory"
13141
13142 test_300d() {
13143         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13144         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13145         local stripe_count
13146         local file
13147
13148         mkdir -p $DIR/$tdir
13149         $SETSTRIPE -c 2 $DIR/$tdir
13150
13151         #local striped directory
13152         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13153                 error "set striped dir error"
13154         createmany -o $DIR/$tdir/striped_dir/f 10 ||
13155                 error "create 10 files failed"
13156
13157         #remote striped directory
13158         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
13159                 error "set striped dir error"
13160         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
13161                 error "create 10 files failed"
13162
13163         for file in $(find $DIR/$tdir); do
13164                 stripe_count=$($GETSTRIPE -c $file)
13165                 [ $stripe_count -eq 2 ] ||
13166                         error "wrong stripe $stripe_count for $file"
13167         done
13168
13169         rm -rf $DIR/$tdir
13170 }
13171 run_test 300d "check default stripe under striped directory"
13172
13173 test_300e() {
13174         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13175         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13176         local stripe_count
13177         local file
13178
13179         mkdir -p $DIR/$tdir
13180
13181         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13182                 error "set striped dir error"
13183
13184         touch $DIR/$tdir/striped_dir/a
13185         touch $DIR/$tdir/striped_dir/b
13186         touch $DIR/$tdir/striped_dir/c
13187
13188         mkdir $DIR/$tdir/striped_dir/dir_a
13189         mkdir $DIR/$tdir/striped_dir/dir_b
13190         mkdir $DIR/$tdir/striped_dir/dir_c
13191
13192         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
13193                 error "set striped dir under striped dir error"
13194
13195         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
13196                 error "set striped dir under striped dir error"
13197
13198         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
13199                 error "set striped dir under striped dir error"
13200
13201         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
13202                 error "rename dir under striped dir fails"
13203
13204         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
13205                 error "rename dir under different stripes fails"
13206
13207         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
13208                 error "rename file under striped dir should succeed"
13209
13210         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
13211                 error "rename dir under striped dir should succeed"
13212
13213         rm -rf $DIR/$tdir
13214 }
13215 run_test 300e "check rename under striped directory"
13216
13217 test_300f() {
13218         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13219         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13220         local stripe_count
13221         local file
13222
13223         rm -rf $DIR/$tdir
13224         mkdir -p $DIR/$tdir
13225
13226         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13227                 error "set striped dir error"
13228
13229         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
13230                 error "set striped dir error"
13231
13232         touch $DIR/$tdir/striped_dir/a
13233         mkdir $DIR/$tdir/striped_dir/dir_a
13234         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
13235                 error "create striped dir under striped dir fails"
13236
13237         touch $DIR/$tdir/striped_dir1/b
13238         mkdir $DIR/$tdir/striped_dir1/dir_b
13239         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
13240                 error "create striped dir under striped dir fails"
13241
13242         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
13243                 error "rename dir under different striped dir should fail"
13244
13245         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
13246                 error "rename striped dir under diff striped dir should fail"
13247
13248         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
13249                 error "rename file 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_300j() {
13403         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13404         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13405                 skip "Need MDS version at least 2.7.55" && return
13406         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13407         local stripe_count
13408         local file
13409
13410         mkdir $DIR/$tdir
13411
13412         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
13413         $LCTL set_param fail_loc=0x1702
13414         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
13415                 error "set striped dir error"
13416
13417         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
13418                 error "create files under striped dir failed"
13419
13420         $LCTL set_param fail_loc=0
13421
13422         rm -rf $DIR/$tdir || error "unlink striped dir fails"
13423
13424         return 0
13425 }
13426 run_test 300j "test large update record"
13427
13428 test_300k() {
13429         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13430         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13431                 skip "Need MDS version at least 2.7.55" && return
13432         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13433         local stripe_count
13434         local file
13435
13436         mkdir $DIR/$tdir
13437
13438         #define OBD_FAIL_LARGE_STRIPE   0x1703
13439         $LCTL set_param fail_loc=0x1703
13440         $LFS setdirstripe -i 0 -c512 $DIR/$tdir/striped_dir ||
13441                 error "set striped dir error"
13442         $LCTL set_param fail_loc=0
13443
13444         $LFS getdirstripe $DIR/$tdir/striped_dir ||
13445                 error "getstripeddir fails"
13446         rm -rf $DIR/$tdir/striped_dir ||
13447                 error "unlink striped dir fails"
13448
13449         return 0
13450 }
13451 run_test 300k "test large striped directory"
13452
13453 prepare_remote_file() {
13454         mkdir $DIR/$tdir/src_dir ||
13455                 error "create remote source failed"
13456
13457         cp /etc/hosts $DIR/$tdir/src_dir/a || error
13458         touch $DIR/$tdir/src_dir/a
13459
13460         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
13461                 error "create remote target dir failed"
13462
13463         touch $DIR/$tdir/tgt_dir/b
13464
13465         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
13466                 error "rename dir cross MDT failed!"
13467
13468         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
13469                 error "src_child still exists after rename"
13470
13471         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
13472                 error "missing file(a) after rename"
13473
13474         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
13475                 error "diff after rename"
13476 }
13477
13478 test_310a() {
13479         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
13480         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13481         local remote_file=$DIR/$tdir/tgt_dir/b
13482
13483         mkdir -p $DIR/$tdir
13484
13485         prepare_remote_file || error "prepare remote file failed"
13486
13487         #open-unlink file
13488         $OPENUNLINK $remote_file $remote_file || error
13489         $CHECKSTAT -a $remote_file || error
13490 }
13491 run_test 310a "open unlink remote file"
13492
13493 test_310b() {
13494         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
13495         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13496         local remote_file=$DIR/$tdir/tgt_dir/b
13497
13498         mkdir -p $DIR/$tdir
13499
13500         prepare_remote_file || error "prepare remote file failed"
13501
13502         ln $remote_file $DIR/$tfile || error "link failed for remote file"
13503         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
13504         $CHECKSTAT -t file $remote_file || error "check file failed"
13505 }
13506 run_test 310b "unlink remote file with multiple links while open"
13507
13508 test_310c() {
13509         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
13510         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13511         local remote_file=$DIR/$tdir/tgt_dir/b
13512
13513         mkdir -p $DIR/$tdir
13514
13515         prepare_remote_file || error "prepare remote file failed"
13516
13517         ln $remote_file $DIR/$tfile || error "link failed for remote file"
13518         multiop_bg_pause $remote_file O_uc ||
13519                         error "mulitop failed for remote file"
13520         MULTIPID=$!
13521         $MULTIOP $DIR/$tfile Ouc
13522         kill -USR1 $MULTIPID
13523         wait $MULTIPID
13524 }
13525 run_test 310c "open-unlink remote file with multiple links"
13526
13527 test_400a() { # LU-1606, was conf-sanity test_74
13528         local extra_flags=''
13529         local out=$TMP/$tfile
13530         local prefix=/usr/include/lustre
13531         local prog
13532
13533         if ! which $CC > /dev/null 2>&1; then
13534                 skip_env "$CC is not installed"
13535                 return 0
13536         fi
13537
13538         if ! [[ -d $prefix ]]; then
13539                 # Assume we're running in tree and fixup the include path.
13540                 extra_flags+=" -I$LUSTRE/../libcfs/include"
13541                 extra_flags+=" -I$LUSTRE/include"
13542                 extra_flags+=" -L$LUSTRE/utils"
13543         fi
13544
13545         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
13546                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
13547                         error "client api broken"
13548         done
13549 }
13550 run_test 400a "Lustre client api program can compile and link"
13551
13552 test_400b() { # LU-1606, LU-5011
13553         local header
13554         local out=$TMP/$tfile
13555         local prefix=/usr/include/lustre
13556
13557         # We use a hard coded prefix so that this test will not fail
13558         # when run in tree. There are headers in lustre/include/lustre/
13559         # that are not packaged (like lustre_idl.h) and have more
13560         # complicated include dependencies (like config.h and lnet/types.h).
13561         # Since this test about correct packaging we just skip them when
13562         # they don't exist (see below) rather than try to fixup cppflags.
13563
13564         if ! which $CC > /dev/null 2>&1; then
13565                 skip_env "$CC is not installed"
13566                 return 0
13567         fi
13568
13569         for header in $prefix/*.h; do
13570                 if ! [[ -f "$header" ]]; then
13571                         continue
13572                 fi
13573
13574                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
13575                         continue # liblustreapi.h is deprecated.
13576                 fi
13577
13578                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
13579                         error "cannot compile '$header'"
13580         done
13581 }
13582 run_test 400b "packaged headers can be compiled"
13583
13584 #
13585 # tests that do cleanup/setup should be run at the end
13586 #
13587
13588 test_900() {
13589         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13590         local ls
13591         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
13592         $LCTL set_param fail_loc=0x903
13593
13594         cancel_lru_locks MGC
13595
13596         FAIL_ON_ERROR=true cleanup
13597         FAIL_ON_ERROR=true setup
13598 }
13599 run_test 900 "umount should not race with any mgc requeue thread"
13600
13601 complete $SECONDS
13602 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
13603 check_and_cleanup_lustre
13604 if [ "$I_MOUNTED" != "yes" ]; then
13605         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
13606 fi
13607 exit_status