Whamcloud - gitweb
LU-10199 utils: disable sanity test 56xb
[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: LU-9693 LU-6493 LU-9693 3561 5188
12 ALWAYS_EXCEPT="                42a    42b      42c     45   68b $SANITY_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # skipped tests: LU-8411 LU-9096 LU-9054 LU-10199
16 ALWAYS_EXCEPT="  407     253     312     56xb     $ALWAYS_EXCEPT"
17
18 # Check Grants after these tests
19 GRANT_CHECK_LIST="$GRANT_CHECK_LIST 42a 42b 42c 42d 42e 63a 63b 64a 64b 64c"
20
21 is_sles11()                                             # LU-4341
22 {
23         if [ -r /etc/SuSE-release ]
24         then
25                 local vers=$(grep VERSION /etc/SuSE-release | awk '{print $3}')
26                 local patchlev=$(grep PATCHLEVEL /etc/SuSE-release |
27                         awk '{ print $3 }')
28                 if [ $vers -eq 11 ] && [ $patchlev -ge 3 ]; then
29                         return 0
30                 fi
31         fi
32         return 1
33 }
34
35 if is_sles11; then                                      # LU-4341
36         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 170"
37 fi
38
39 SRCDIR=$(cd $(dirname $0); echo $PWD)
40 export PATH=$PATH:/sbin
41
42 TMP=${TMP:-/tmp}
43
44 CC=${CC:-cc}
45 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
46 CREATETEST=${CREATETEST:-createtest}
47 LFS=${LFS:-lfs}
48 LFIND=${LFIND:-"$LFS find"}
49 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
50 LCTL=${LCTL:-lctl}
51 OPENFILE=${OPENFILE:-openfile}
52 OPENUNLINK=${OPENUNLINK:-openunlink}
53 export MULTIOP=${MULTIOP:-multiop}
54 READS=${READS:-"reads"}
55 MUNLINK=${MUNLINK:-munlink}
56 SOCKETSERVER=${SOCKETSERVER:-socketserver}
57 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
58 MEMHOG=${MEMHOG:-memhog}
59 DIRECTIO=${DIRECTIO:-directio}
60 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
61 STRIPES_PER_OBJ=-1
62 CHECK_GRANT=${CHECK_GRANT:-"yes"}
63 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
64 export PARALLEL=${PARALLEL:-"no"}
65
66 export NAME=${NAME:-local}
67
68 SAVE_PWD=$PWD
69
70 CLEANUP=${CLEANUP:-:}
71 SETUP=${SETUP:-:}
72 TRACE=${TRACE:-""}
73 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
74 LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
75 . $LUSTRE/tests/test-framework.sh
76 init_test_env $@
77 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
78 init_logging
79
80 #                                  5          12          (min)"
81 [ "$SLOW" = "no" ] && EXCEPT_SLOW="27m 64b 68 71 115 300o"
82
83 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
84         # bug number for skipped test: LU-1957
85         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  180"
86         #                                               13    (min)"
87         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b"
88 fi
89
90 FAIL_ON_ERROR=false
91
92 cleanup() {
93         echo -n "cln.."
94         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
95         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
96 }
97 setup() {
98         echo -n "mnt.."
99         load_modules
100         setupall || exit 10
101         echo "done"
102 }
103
104 check_swap_layouts_support()
105 {
106         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
107                 { skip "Does not support layout lock."; return 0; }
108         return 1
109 }
110
111 check_and_setup_lustre
112 DIR=${DIR:-$MOUNT}
113 assert_DIR
114
115 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
116         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
117 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
118
119 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
120 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
121 rm -rf $DIR/[Rdfs][0-9]*
122
123 # $RUNAS_ID may get set incorrectly somewhere else
124 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
125
126 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
127
128 build_test_filter
129
130 if [ "${ONLY}" = "MOUNT" ] ; then
131         echo "Lustre is up, please go on"
132         exit
133 fi
134
135 echo "preparing for tests involving mounts"
136 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
137 touch $EXT2_DEV
138 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
139 echo # add a newline after mke2fs.
140
141 umask 077
142
143 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
144 lctl set_param debug=-1 2> /dev/null || true
145 test_0a() {
146         touch $DIR/$tfile
147         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
148         rm $DIR/$tfile
149         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
150 }
151 run_test 0a "touch; rm ====================="
152
153 test_0b() {
154         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
155         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
156 }
157 run_test 0b "chmod 0755 $DIR ============================="
158
159 test_0c() {
160         $LCTL get_param mdc.*.import | grep "state: FULL" ||
161                 error "import not FULL"
162         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
163                 error "bad target"
164 }
165 run_test 0c "check import proc"
166
167 test_1() {
168         test_mkdir $DIR/$tdir
169         test_mkdir $DIR/$tdir/d2
170         mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
171         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
172         rmdir $DIR/$tdir/d2
173         rmdir $DIR/$tdir
174         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
175 }
176 run_test 1 "mkdir; remkdir; rmdir"
177
178 test_2() {
179         test_mkdir $DIR/$tdir
180         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
181         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
182         rm -r $DIR/$tdir
183         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
184 }
185 run_test 2 "mkdir; touch; rmdir; check file"
186
187 test_3() {
188         test_mkdir $DIR/$tdir
189         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
190         touch $DIR/$tdir/$tfile
191         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
192         rm -r $DIR/$tdir
193         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
194 }
195 run_test 3 "mkdir; touch; rmdir; check dir"
196
197 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
198 test_4() {
199         test_mkdir -i 1 $DIR/$tdir
200
201         touch $DIR/$tdir/$tfile ||
202                 error "Create file under remote directory failed"
203
204         rmdir $DIR/$tdir &&
205                 error "Expect error removing in-use dir $DIR/$tdir"
206
207         test -d $DIR/$tdir || error "Remote directory disappeared"
208
209         rm -rf $DIR/$tdir || error "remove remote dir error"
210 }
211 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
212
213 test_5() {
214         test_mkdir $DIR/$tdir
215         test_mkdir $DIR/$tdir/d2
216         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
217         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
218         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
219 }
220 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2"
221
222 test_6a() {
223         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
224         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
225         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
226                 error "$tfile does not have perm 0666 or UID $UID"
227         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
228         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
229                 error "$tfile should be 0666 and owned by UID $UID"
230 }
231 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
232
233 test_6c() {
234         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
235         touch $DIR/$tfile
236         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
237         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
238                 error "$tfile should be owned by UID $RUNAS_ID"
239         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
240         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
241                 error "$tfile should be owned by UID $RUNAS_ID"
242 }
243 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
244
245 test_6e() {
246         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
247         touch $DIR/$tfile
248         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
249         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
250                 error "$tfile should be owned by GID $UID"
251         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
252         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
253                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
254 }
255 run_test 6e "touch+chgrp $tfile; $RUNAS chgrp $tfile (should return error)"
256
257 test_6g() {
258         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
259         test_mkdir $DIR/$tdir
260         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
261         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
262         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
263         test_mkdir $DIR/$tdir/d/subdir
264         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
265                 error "$tdir/d/subdir should be GID $RUNAS_GID"
266         if [[ $MDSCOUNT -gt 1 ]]; then
267                 # check remote dir sgid inherite
268                 $LFS mkdir -i 0 $DIR/$tdir.local ||
269                         error "mkdir $tdir.local failed"
270                 chmod g+s $DIR/$tdir.local ||
271                         error "chmod $tdir.local failed"
272                 chgrp $RUNAS_GID $DIR/$tdir.local ||
273                         error "chgrp $tdir.local failed"
274                 $LFS mkdir -i 1 $DIR/$tdir.local/$tdir.remote ||
275                         error "mkdir $tdir.remote failed"
276                 $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir.local/$tdir.remote ||
277                         error "$tdir.remote should be owned by $UID.$RUNAS_ID"
278                 $CHECKSTAT -p 02755 $DIR/$tdir.local/$tdir.remote ||
279                         error "$tdir.remote should be mode 02755"
280         fi
281 }
282 run_test 6g "verify new dir in sgid dir inherits group"
283
284 test_6h() { # bug 7331
285         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
286         touch $DIR/$tfile || error "touch failed"
287         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
288         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
289                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
290         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
291                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
292 }
293 run_test 6h "$RUNAS chown RUNAS_ID.0 .../$tfile (should return error)"
294
295 test_7a() {
296         test_mkdir $DIR/$tdir
297         $MCREATE $DIR/$tdir/$tfile
298         chmod 0666 $DIR/$tdir/$tfile
299         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
300                 error "$tdir/$tfile should be mode 0666"
301 }
302 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
303
304 test_7b() {
305         if [ ! -d $DIR/$tdir ]; then
306                 test_mkdir $DIR/$tdir
307         fi
308         $MCREATE $DIR/$tdir/$tfile
309         echo -n foo > $DIR/$tdir/$tfile
310         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
311         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
312 }
313 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
314
315 test_8() {
316         test_mkdir $DIR/$tdir
317         touch $DIR/$tdir/$tfile
318         chmod 0666 $DIR/$tdir/$tfile
319         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
320                 error "$tfile mode not 0666"
321 }
322 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
323
324 test_9() {
325         test_mkdir $DIR/$tdir
326         test_mkdir $DIR/$tdir/d2
327         test_mkdir $DIR/$tdir/d2/d3
328         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
329 }
330 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
331
332 test_10() {
333         test_mkdir $DIR/$tdir
334         test_mkdir $DIR/$tdir/d2
335         touch $DIR/$tdir/d2/$tfile
336         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
337                 error "$tdir/d2/$tfile not a file"
338 }
339 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
340
341 test_11() {
342         test_mkdir $DIR/$tdir
343         test_mkdir $DIR/$tdir/d2
344         chmod 0666 $DIR/$tdir/d2
345         chmod 0705 $DIR/$tdir/d2
346         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
347                 error "$tdir/d2 mode not 0705"
348 }
349 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
350
351 test_12() {
352         test_mkdir $DIR/$tdir
353         touch $DIR/$tdir/$tfile
354         chmod 0666 $DIR/$tdir/$tfile
355         chmod 0654 $DIR/$tdir/$tfile
356         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
357                 error "$tdir/d2 mode not 0654"
358 }
359 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
360
361 test_13() {
362         test_mkdir $DIR/$tdir
363         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
364         >  $DIR/$tdir/$tfile
365         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
366                 error "$tdir/$tfile size not 0 after truncate"
367 }
368 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
369
370 test_14() {
371         test_mkdir $DIR/$tdir
372         touch $DIR/$tdir/$tfile
373         rm $DIR/$tdir/$tfile
374         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
375 }
376 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
377
378 test_15() {
379         test_mkdir $DIR/$tdir
380         touch $DIR/$tdir/$tfile
381         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
382         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
383                 error "$tdir/${tfile_2} not a file after rename"
384         rm $DIR/$tdir/${tfile}_2 || error "unlink failed after rename"
385 }
386 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
387
388 test_16() {
389         test_mkdir $DIR/$tdir
390         touch $DIR/$tdir/$tfile
391         rm -rf $DIR/$tdir/$tfile
392         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
393 }
394 run_test 16 "touch .../d16/f; rm -rf .../d16/f"
395
396 test_17a() {
397         test_mkdir $DIR/$tdir
398         touch $DIR/$tdir/$tfile
399         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
400         ls -l $DIR/$tdir
401         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
402                 error "$tdir/l-exist not a symlink"
403         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
404                 error "$tdir/l-exist not referencing a file"
405         rm -f $DIR/$tdir/l-exist
406         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
407 }
408 run_test 17a "symlinks: create, remove (real)"
409
410 test_17b() {
411         test_mkdir $DIR/$tdir
412         ln -s no-such-file $DIR/$tdir/l-dangle
413         ls -l $DIR/$tdir
414         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
415                 error "$tdir/l-dangle not referencing no-such-file"
416         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
417                 error "$tdir/l-dangle not referencing non-existent file"
418         rm -f $DIR/$tdir/l-dangle
419         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
420 }
421 run_test 17b "symlinks: create, remove (dangling)"
422
423 test_17c() { # bug 3440 - don't save failed open RPC for replay
424         test_mkdir $DIR/$tdir
425         ln -s foo $DIR/$tdir/$tfile
426         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
427 }
428 run_test 17c "symlinks: open dangling (should return error)"
429
430 test_17d() {
431         test_mkdir $DIR/$tdir
432         ln -s foo $DIR/$tdir/$tfile
433         touch $DIR/$tdir/$tfile || error "creating to new symlink"
434 }
435 run_test 17d "symlinks: create dangling"
436
437 test_17e() {
438         test_mkdir $DIR/$tdir
439         local foo=$DIR/$tdir/$tfile
440         ln -s $foo $foo || error "create symlink failed"
441         ls -l $foo || error "ls -l failed"
442         ls $foo && error "ls not failed" || true
443 }
444 run_test 17e "symlinks: create recursive symlink (should return error)"
445
446 test_17f() {
447         test_mkdir $DIR/$tdir
448         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
449         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
450         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
451         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
452         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
453         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
454         ls -l  $DIR/$tdir
455 }
456 run_test 17f "symlinks: long and very long symlink name"
457
458 # str_repeat(S, N) generate a string that is string S repeated N times
459 str_repeat() {
460         local s=$1
461         local n=$2
462         local ret=''
463         while [ $((n -= 1)) -ge 0 ]; do
464                 ret=$ret$s
465         done
466         echo $ret
467 }
468
469 # Long symlinks and LU-2241
470 test_17g() {
471         test_mkdir $DIR/$tdir
472         local TESTS="59 60 61 4094 4095"
473
474         # Fix for inode size boundary in 2.1.4
475         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
476                 TESTS="4094 4095"
477
478         # Patch not applied to 2.2 or 2.3 branches
479         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
480         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
481                 TESTS="4094 4095"
482
483         # skip long symlink name for rhel6.5.
484         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
485         grep -q '6.5' /etc/redhat-release &>/dev/null &&
486                 TESTS="59 60 61 4062 4063"
487
488         for i in $TESTS; do
489                 local SYMNAME=$(str_repeat 'x' $i)
490                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
491                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
492         done
493 }
494 run_test 17g "symlinks: really long symlink name and inode boundaries"
495
496 test_17h() { #bug 17378
497         remote_mds_nodsh && skip "remote MDS with nodsh" && return
498         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
499         local mdt_idx
500         test_mkdir $DIR/$tdir
501         if [[ $MDSCOUNT -gt 1 ]]; then
502                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
503         else
504                 mdt_idx=0
505         fi
506         $LFS setstripe -c -1 $DIR/$tdir
507         #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
508         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
509         touch $DIR/$tdir/$tfile || true
510 }
511 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
512
513 test_17i() { #bug 20018
514         remote_mds_nodsh && skip "remote MDS with nodsh" && return
515         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
516         test_mkdir -c1 $DIR/$tdir
517         local foo=$DIR/$tdir/$tfile
518         local mdt_idx
519         if [[ $MDSCOUNT -gt 1 ]]; then
520                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
521         else
522                 mdt_idx=0
523         fi
524         ln -s $foo $foo || error "create symlink failed"
525 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
526         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
527         ls -l $foo && error "error not detected"
528         return 0
529 }
530 run_test 17i "don't panic on short symlink"
531
532 test_17k() { #bug 22301
533         [[ -z "$(which rsync 2>/dev/null)" ]] &&
534                 skip "no rsync command" && return 0
535         rsync --help | grep -q xattr ||
536                 skip_env "$(rsync --version | head -n1) does not support xattrs"
537         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
538         test_mkdir $DIR/$tdir
539         test_mkdir $DIR/$tdir.new
540         touch $DIR/$tdir/$tfile
541         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
542         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
543                 error "rsync failed with xattrs enabled"
544 }
545 run_test 17k "symlinks: rsync with xattrs enabled"
546
547 test_17l() { # LU-279
548         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
549                 skip "no getfattr command" && return 0
550         test_mkdir $DIR/$tdir
551         touch $DIR/$tdir/$tfile
552         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
553         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
554                 # -h to not follow symlinks. -m '' to list all the xattrs.
555                 # grep to remove first line: '# file: $path'.
556                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
557                 do
558                         lgetxattr_size_check $path $xattr ||
559                                 error "lgetxattr_size_check $path $xattr failed"
560                 done
561         done
562 }
563 run_test 17l "Ensure lgetxattr's returned xattr size is consistent"
564
565 # LU-1540
566 test_17m() {
567         local short_sym="0123456789"
568         local wdir=$DIR/$tdir
569         local i
570
571         remote_mds_nodsh && skip "remote MDS with nodsh" && return
572         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
573         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
574                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
575
576         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
577                 skip "ldiskfs only test" && return 0
578
579         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
580
581         test_mkdir $wdir
582         long_sym=$short_sym
583         # create a long symlink file
584         for ((i = 0; i < 4; ++i)); do
585                 long_sym=${long_sym}${long_sym}
586         done
587
588         echo "create 512 short and long symlink files under $wdir"
589         for ((i = 0; i < 256; ++i)); do
590                 ln -sf ${long_sym}"a5a5" $wdir/long-$i
591                 ln -sf ${short_sym}"a5a5" $wdir/short-$i
592         done
593
594         echo "erase them"
595         rm -f $wdir/*
596         sync
597         wait_delete_completed
598
599         echo "recreate the 512 symlink files with a shorter string"
600         for ((i = 0; i < 512; ++i)); do
601                 # rewrite the symlink file with a shorter string
602                 ln -sf ${long_sym} $wdir/long-$i || error "long_sym failed"
603                 ln -sf ${short_sym} $wdir/short-$i || error "short_sym failed"
604         done
605
606         local mds_index=$(($($LFS getstripe -M $wdir) + 1))
607         local devname=$(mdsdevname $mds_index)
608
609         echo "stop and checking mds${mds_index}:"
610         # e2fsck should not return error
611         stop mds${mds_index}
612         run_e2fsck $(facet_active_host mds${mds_index}) $devname -n
613         rc=$?
614
615         start mds${mds_index} $devname $MDS_MOUNT_OPTS ||
616                 error "start mds${mds_index} failed"
617         df $MOUNT > /dev/null 2>&1
618         [ $rc -eq 0 ] ||
619                 error "e2fsck detected error for short/long symlink: rc=$rc"
620 }
621 run_test 17m "run e2fsck against MDT which contains short/long symlink"
622
623 check_fs_consistency_17n() {
624         local mdt_index
625         local rc=0
626
627         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
628         # so it only check MDT1/MDT2 instead of all of MDTs.
629         for mdt_index in 1 2; do
630                 local devname=$(mdsdevname $mdt_index)
631                 # e2fsck should not return error
632                 stop mds${mdt_index}
633                 run_e2fsck $(facet_active_host mds$mdt_index) $devname -n ||
634                         rc=$((rc + $?))
635
636                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
637                         error "mount mds$mdt_index failed"
638                 df $MOUNT > /dev/null 2>&1
639         done
640         return $rc
641 }
642
643 test_17n() {
644         local i
645
646         remote_mds_nodsh && skip "remote MDS with nodsh" && return
647         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
648         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
649                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
650
651         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
652                 skip "ldiskfs only test" && return 0
653
654         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
655
656         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
657
658         test_mkdir $DIR/$tdir
659         for ((i=0; i<10; i++)); do
660                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
661                         error "create remote dir error $i"
662                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
663                         error "create files under remote dir failed $i"
664         done
665
666         check_fs_consistency_17n ||
667                 error "e2fsck report error after create files under remote dir"
668
669         for ((i = 0; i < 10; i++)); do
670                 rm -rf $DIR/$tdir/remote_dir_${i} ||
671                         error "destroy remote dir error $i"
672         done
673
674         check_fs_consistency_17n ||
675                 error "e2fsck report error after unlink files under remote dir"
676
677         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
678                 skip "lustre < 2.4.50 does not support migrate mv " && return
679
680         for ((i = 0; i < 10; i++)); do
681                 mkdir -p $DIR/$tdir/remote_dir_${i}
682                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
683                         error "create files under remote dir failed $i"
684                 $LFS migrate --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
685                         error "migrate remote dir error $i"
686         done
687         check_fs_consistency_17n || error "e2fsck report error after migration"
688
689         for ((i = 0; i < 10; i++)); do
690                 rm -rf $DIR/$tdir/remote_dir_${i} ||
691                         error "destroy remote dir error $i"
692         done
693
694         check_fs_consistency_17n || error "e2fsck report error after unlink"
695 }
696 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
697
698 test_17o() {
699         remote_mds_nodsh && skip "remote MDS with nodsh" && return
700         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
701                 skip "Need MDS version at least 2.3.64" && return
702
703         local wdir=$DIR/${tdir}o
704         local mdt_index
705         local rc=0
706
707         test_mkdir $wdir
708         touch $wdir/$tfile
709         mdt_index=$($LFS getstripe -M $wdir/$tfile)
710         mdt_index=$((mdt_index + 1))
711
712         cancel_lru_locks mdc
713         #fail mds will wait the failover finish then set
714         #following fail_loc to avoid interfer the recovery process.
715         fail mds${mdt_index}
716
717         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
718         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
719         ls -l $wdir/$tfile && rc=1
720         do_facet mds${mdt_index} lctl set_param fail_loc=0
721         [[ $rc -eq 0 ]] || error "stat file should fail"
722 }
723 run_test 17o "stat file with incompat LMA feature"
724
725 test_18() {
726         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
727         ls $DIR || error "Failed to ls $DIR: $?"
728 }
729 run_test 18 "touch .../f ; ls ... =============================="
730
731 test_19a() {
732         touch $DIR/$tfile
733         ls -l $DIR
734         rm $DIR/$tfile
735         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
736 }
737 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
738
739 test_19b() {
740         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
741 }
742 run_test 19b "ls -l .../f19 (should return error) =============="
743
744 test_19c() {
745         [ $RUNAS_ID -eq $UID ] &&
746                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
747         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
748 }
749 run_test 19c "$RUNAS touch .../f19 (should return error) =="
750
751 test_19d() {
752         cat $DIR/f19 && error || true
753 }
754 run_test 19d "cat .../f19 (should return error) =============="
755
756 test_20() {
757         touch $DIR/$tfile
758         rm $DIR/$tfile
759         touch $DIR/$tfile
760         rm $DIR/$tfile
761         touch $DIR/$tfile
762         rm $DIR/$tfile
763         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
764 }
765 run_test 20 "touch .../f ; ls -l ..."
766
767 test_21() {
768         test_mkdir $DIR/$tdir
769         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
770         ln -s dangle $DIR/$tdir/link
771         echo foo >> $DIR/$tdir/link
772         cat $DIR/$tdir/dangle
773         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
774         $CHECKSTAT -f -t file $DIR/$tdir/link ||
775                 error "$tdir/link not linked to a file"
776 }
777 run_test 21 "write to dangling link"
778
779 test_22() {
780         local wdir=$DIR/$tdir
781         test_mkdir $wdir
782         chown $RUNAS_ID:$RUNAS_GID $wdir
783         (cd $wdir || error "cd $wdir failed";
784                 $RUNAS tar cf - /etc/hosts /etc/sysconfig/network |
785                 $RUNAS tar xf -)
786         ls -lR $wdir/etc || error "ls -lR $wdir/etc failed"
787         $CHECKSTAT -t dir $wdir/etc || error "checkstat -t dir failed"
788         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $wdir/etc ||
789                 error "checkstat -u failed"
790 }
791 run_test 22 "unpack tar archive as non-root user"
792
793 # was test_23
794 test_23a() {
795         test_mkdir $DIR/$tdir
796         local file=$DIR/$tdir/$tfile
797
798         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
799         openfile -f O_CREAT:O_EXCL $file &&
800                 error "$file recreate succeeded" || true
801 }
802 run_test 23a "O_CREAT|O_EXCL in subdir"
803
804 test_23b() { # bug 18988
805         test_mkdir $DIR/$tdir
806         local file=$DIR/$tdir/$tfile
807
808         rm -f $file
809         echo foo > $file || error "write filed"
810         echo bar >> $file || error "append filed"
811         $CHECKSTAT -s 8 $file || error "wrong size"
812         rm $file
813 }
814 run_test 23b "O_APPEND check"
815
816 # rename sanity
817 test_24a() {
818         echo '-- same directory rename'
819         test_mkdir $DIR/$tdir
820         touch $DIR/$tdir/$tfile.1
821         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
822         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
823 }
824 run_test 24a "rename file to non-existent target"
825
826 test_24b() {
827         test_mkdir $DIR/$tdir
828         touch $DIR/$tdir/$tfile.{1,2}
829         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
830         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
831         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
832 }
833 run_test 24b "rename file to existing target"
834
835 test_24c() {
836         test_mkdir $DIR/$tdir
837         test_mkdir $DIR/$tdir/d$testnum.1
838         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
839         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
840         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
841 }
842 run_test 24c "rename directory to non-existent target"
843
844 test_24d() {
845         test_mkdir -c1 $DIR/$tdir
846         test_mkdir -c1 $DIR/$tdir/d$testnum.1
847         test_mkdir -c1 $DIR/$tdir/d$testnum.2
848         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
849         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
850         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
851 }
852 run_test 24d "rename directory to existing target"
853
854 test_24e() {
855         echo '-- cross directory renames --'
856         test_mkdir $DIR/R5a
857         test_mkdir $DIR/R5b
858         touch $DIR/R5a/f
859         mv $DIR/R5a/f $DIR/R5b/g
860         $CHECKSTAT -a $DIR/R5a/f || error
861         $CHECKSTAT -t file $DIR/R5b/g || error
862 }
863 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
864
865 test_24f() {
866         test_mkdir $DIR/R6a
867         test_mkdir $DIR/R6b
868         touch $DIR/R6a/f $DIR/R6b/g
869         mv $DIR/R6a/f $DIR/R6b/g
870         $CHECKSTAT -a $DIR/R6a/f || error
871         $CHECKSTAT -t file $DIR/R6b/g || error
872 }
873 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
874
875 test_24g() {
876         test_mkdir $DIR/R7a
877         test_mkdir $DIR/R7b
878         test_mkdir $DIR/R7a/d
879         mv $DIR/R7a/d $DIR/R7b/e
880         $CHECKSTAT -a $DIR/R7a/d || error
881         $CHECKSTAT -t dir $DIR/R7b/e || error
882 }
883 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
884
885 test_24h() {
886         test_mkdir -c1 $DIR/R8a
887         test_mkdir -c1 $DIR/R8b
888         test_mkdir -c1 $DIR/R8a/d
889         test_mkdir -c1 $DIR/R8b/e
890         mrename $DIR/R8a/d $DIR/R8b/e
891         $CHECKSTAT -a $DIR/R8a/d || error
892         $CHECKSTAT -t dir $DIR/R8b/e || error
893 }
894 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
895
896 test_24i() {
897         echo "-- rename error cases"
898         test_mkdir $DIR/R9
899         test_mkdir $DIR/R9/a
900         touch $DIR/R9/f
901         mrename $DIR/R9/f $DIR/R9/a
902         $CHECKSTAT -t file $DIR/R9/f || error
903         $CHECKSTAT -t dir  $DIR/R9/a || error
904         $CHECKSTAT -a $DIR/R9/a/f || error
905 }
906 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
907
908 test_24j() {
909         test_mkdir $DIR/R10
910         mrename $DIR/R10/f $DIR/R10/g
911         $CHECKSTAT -t dir $DIR/R10 || error
912         $CHECKSTAT -a $DIR/R10/f || error
913         $CHECKSTAT -a $DIR/R10/g || error
914 }
915 run_test 24j "source does not exist ============================"
916
917 test_24k() {
918         test_mkdir $DIR/R11a
919         test_mkdir $DIR/R11a/d
920         touch $DIR/R11a/f
921         mv $DIR/R11a/f $DIR/R11a/d
922         $CHECKSTAT -a $DIR/R11a/f || error
923         $CHECKSTAT -t file $DIR/R11a/d/f || error
924 }
925 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
926
927 # bug 2429 - rename foo foo foo creates invalid file
928 test_24l() {
929         f="$DIR/f24l"
930         $MULTIOP $f OcNs || error
931 }
932 run_test 24l "Renaming a file to itself ========================"
933
934 test_24m() {
935         f="$DIR/f24m"
936         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
937         # on ext3 this does not remove either the source or target files
938         # though the "expected" operation would be to remove the source
939         $CHECKSTAT -t file ${f} || error "${f} missing"
940         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
941 }
942 run_test 24m "Renaming a file to a hard link to itself ========="
943
944 test_24n() {
945     f="$DIR/f24n"
946     # this stats the old file after it was renamed, so it should fail
947     touch ${f}
948     $CHECKSTAT ${f}
949     mv ${f} ${f}.rename
950     $CHECKSTAT ${f}.rename
951     $CHECKSTAT -a ${f}
952 }
953 run_test 24n "Statting the old file after renaming (Posix rename 2)"
954
955 test_24o() {
956         test_mkdir $DIR/$tdir
957         rename_many -s random -v -n 10 $DIR/$tdir
958 }
959 run_test 24o "rename of files during htree split"
960
961 test_24p() {
962         test_mkdir $DIR/R12a
963         test_mkdir $DIR/R12b
964         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
965         mrename $DIR/R12a $DIR/R12b
966         $CHECKSTAT -a $DIR/R12a || error
967         $CHECKSTAT -t dir $DIR/R12b || error
968         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
969         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
970 }
971 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
972
973 cleanup_multiop_pause() {
974         trap 0
975         kill -USR1 $MULTIPID
976 }
977
978 test_24q() {
979         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
980         test_mkdir $DIR/R13a
981         test_mkdir $DIR/R13b
982         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
983         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
984         MULTIPID=$!
985
986         trap cleanup_multiop_pause EXIT
987         mrename $DIR/R13a $DIR/R13b
988         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
989         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
990         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
991         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
992         cleanup_multiop_pause
993         wait $MULTIPID || error "multiop close failed"
994 }
995 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
996
997 test_24r() { #bug 3789
998         test_mkdir $DIR/R14a
999         test_mkdir $DIR/R14a/b
1000         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1001         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1002         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1003 }
1004 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1005
1006 test_24s() {
1007         test_mkdir $DIR/R15a
1008         test_mkdir $DIR/R15a/b
1009         test_mkdir $DIR/R15a/b/c
1010         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1011         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1012         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1013 }
1014 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1015 test_24t() {
1016         test_mkdir $DIR/R16a
1017         test_mkdir $DIR/R16a/b
1018         test_mkdir $DIR/R16a/b/c
1019         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1020         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1021         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1022 }
1023 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1024
1025 test_24u() { # bug12192
1026         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1027         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1028 }
1029 run_test 24u "create stripe file"
1030
1031 page_size() {
1032         local size
1033         size=$(getconf PAGE_SIZE 2>/dev/null)
1034         echo -n ${size:-4096}
1035 }
1036
1037 simple_cleanup_common() {
1038         local rc=0
1039         trap 0
1040         [ -z "$DIR" -o -z "$tdir" ] && return 0
1041
1042         local start=$SECONDS
1043         rm -rf $DIR/$tdir
1044         rc=$?
1045         wait_delete_completed
1046         echo "cleanup time $((SECONDS - start))"
1047         return $rc
1048 }
1049
1050 max_pages_per_rpc() {
1051         local mdtname="$(printf "MDT%04x" ${1:-0})"
1052         $LCTL get_param -n mdc.*$mdtname*.max_pages_per_rpc
1053 }
1054
1055 test_24v() {
1056         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1057         local nrfiles=${COUNT:-100000}
1058         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1059         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && nrfiles=${COUNT:-10000}
1060
1061         local fname="$DIR/$tdir/$tfile"
1062         test_mkdir "$(dirname $fname)"
1063         # assume MDT0000 has the fewest inodes
1064         local stripes=$($LFS getdirstripe -c $(dirname $fname))
1065         local free_inodes=$(($(mdt_free_inodes 0) * stripes))
1066         [[ $free_inodes -lt $nrfiles ]] && nrfiles=$free_inodes
1067
1068         trap simple_cleanup_common EXIT
1069
1070         createmany -m "$fname" $nrfiles
1071
1072         cancel_lru_locks mdc
1073         lctl set_param mdc.*.stats clear
1074
1075         # was previously test_24D: LU-6101
1076         # readdir() returns correct number of entries after cursor reload
1077         local num_ls=$(ls $DIR/$tdir | wc -l)
1078         local num_uniq=$(ls $DIR/$tdir | sort -u | wc -l)
1079         local num_all=$(ls -a $DIR/$tdir | wc -l)
1080         if [ $num_ls -ne $nrfiles -o $num_uniq -ne $nrfiles -o \
1081              $num_all -ne $((nrfiles + 2)) ]; then
1082                 error "Expected $nrfiles files, got $num_ls " \
1083                         "($num_uniq unique $num_all .&..)"
1084         fi
1085         # LU-5 large readdir
1086         # dirent_size = 32 bytes for sizeof(struct lu_dirent) +
1087         #               N bytes for name (len($nrfiles) rounded to 8 bytes) +
1088         #               8 bytes for luda_type (4 bytes rounded to 8 bytes)
1089         # take into account of overhead in lu_dirpage header and end mark in
1090         # each page, plus one in rpc_num calculation.
1091         local dirent_size=$((32 + (${#tfile} | 7) + 1 + 8))
1092         local page_entries=$((($(page_size) - 24) / dirent_size))
1093         local mdt_idx=$($LFS getdirstripe -i $(dirname $fname))
1094         local rpc_pages=$(max_pages_per_rpc $mdt_idx)
1095         local rpc_max=$((nrfiles / (page_entries * rpc_pages) + stripes))
1096         local mds_readpage=$(calc_stats mdc.*.stats mds_readpage)
1097         echo "readpages: $mds_readpage rpc_max: $rpc_max"
1098         (( $mds_readpage < $rpc_max - 2 || $mds_readpage > $rpc_max + 1)) &&
1099                 error "large readdir doesn't take effect: " \
1100                       "$mds_readpage should be about $rpc_max"
1101
1102         simple_cleanup_common
1103 }
1104 run_test 24v "list large directory (test hash collision, b=17560)"
1105
1106 test_24w() { # bug21506
1107         SZ1=234852
1108         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1109         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1110         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1111         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1112         [[ "$SZ1" -eq "$SZ2" ]] ||
1113                 error "Error reading at the end of the file $tfile"
1114 }
1115 run_test 24w "Reading a file larger than 4Gb"
1116
1117 test_24x() {
1118         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1119
1120         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1121                 skip "Need MDS version at least 2.7.56" && return
1122
1123         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1124         local MDTIDX=1
1125         local remote_dir=$DIR/$tdir/remote_dir
1126
1127         test_mkdir $DIR/$tdir
1128         $LFS mkdir -i $MDTIDX $remote_dir ||
1129                 error "create remote directory failed"
1130
1131         test_mkdir $DIR/$tdir/src_dir
1132         touch $DIR/$tdir/src_file
1133         test_mkdir $remote_dir/tgt_dir
1134         touch $remote_dir/tgt_file
1135
1136         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir ||
1137                 error "rename dir cross MDT failed!"
1138
1139         mrename $DIR/$tdir/src_file $remote_dir/tgt_file ||
1140                 error "rename file cross MDT failed!"
1141
1142         touch $DIR/$tdir/ln_file
1143         ln $DIR/$tdir/ln_file $remote_dir/ln_name ||
1144                 error "ln file cross MDT failed"
1145
1146         rm -rf $DIR/$tdir || error "Can not delete directories"
1147 }
1148 run_test 24x "cross MDT rename/link"
1149
1150 test_24y() {
1151         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1152         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1153         local remote_dir=$DIR/$tdir/remote_dir
1154         local mdtidx=1
1155
1156         test_mkdir $DIR/$tdir
1157         $LFS mkdir -i $mdtidx $remote_dir ||
1158                    error "create remote directory failed"
1159
1160         test_mkdir $remote_dir/src_dir
1161         touch $remote_dir/src_file
1162         test_mkdir $remote_dir/tgt_dir
1163         touch $remote_dir/tgt_file
1164
1165         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1166                 error "rename subdir in the same remote dir failed!"
1167
1168         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1169                 error "rename files in the same remote dir failed!"
1170
1171         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1172                 error "link files in the same remote dir failed!"
1173
1174         rm -rf $DIR/$tdir || error "Can not delete directories"
1175 }
1176 run_test 24y "rename/link on the same dir should succeed"
1177
1178 test_24A() { # LU-3182
1179         local NFILES=5000
1180
1181         rm -rf $DIR/$tdir
1182         test_mkdir $DIR/$tdir
1183         trap simple_cleanup_common EXIT
1184         createmany -m $DIR/$tdir/$tfile $NFILES
1185         local t=$(ls $DIR/$tdir | wc -l)
1186         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1187         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1188         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1189                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1190         fi
1191
1192         simple_cleanup_common || error "Can not delete directories"
1193 }
1194 run_test 24A "readdir() returns correct number of entries."
1195
1196 test_24B() { # LU-4805
1197         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1198         local count
1199
1200         test_mkdir $DIR/$tdir
1201         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1202                 error "create striped dir failed"
1203
1204         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1205         [ $count -eq 2 ] || error "Expected 2, got $count"
1206
1207         touch $DIR/$tdir/striped_dir/a
1208
1209         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1210         [ $count -eq 3 ] || error "Expected 3, got $count"
1211
1212         touch $DIR/$tdir/striped_dir/.f
1213
1214         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1215         [ $count -eq 4 ] || error "Expected 4, got $count"
1216
1217         rm -rf $DIR/$tdir || error "Can not delete directories"
1218 }
1219 run_test 24B "readdir for striped dir return correct number of entries"
1220
1221 test_24C() {
1222         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1223
1224         mkdir $DIR/$tdir
1225         mkdir $DIR/$tdir/d0
1226         mkdir $DIR/$tdir/d1
1227
1228         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1229                 error "create striped dir failed"
1230
1231         cd $DIR/$tdir/d0/striped_dir
1232
1233         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1234         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1235         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1236
1237         [ "$d0_ino" = "$parent_ino" ] ||
1238                 error ".. wrong, expect $d0_ino, get $parent_ino"
1239
1240         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1241                 error "mv striped dir failed"
1242
1243         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1244
1245         [ "$d1_ino" = "$parent_ino" ] ||
1246                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1247 }
1248 run_test 24C "check .. in striped dir"
1249
1250 test_24E() {
1251         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
1252         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1253
1254         mkdir -p $DIR/$tdir
1255         mkdir $DIR/$tdir/src_dir
1256         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
1257                 error "create remote source failed"
1258
1259         touch $DIR/$tdir/src_dir/src_child/a
1260
1261         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
1262                 error "create remote target dir failed"
1263
1264         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
1265                 error "create remote target child failed"
1266
1267         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
1268                 error "rename dir cross MDT failed!"
1269
1270         find $DIR/$tdir
1271
1272         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
1273                 error "src_child still exists after rename"
1274
1275         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
1276                 error "missing file(a) after rename"
1277
1278         rm -rf $DIR/$tdir || error "Can not delete directories"
1279 }
1280 run_test 24E "cross MDT rename/link"
1281
1282 test_25a() {
1283         echo '== symlink sanity ============================================='
1284
1285         test_mkdir $DIR/d25
1286         ln -s d25 $DIR/s25
1287         touch $DIR/s25/foo || error
1288 }
1289 run_test 25a "create file in symlinked directory ==============="
1290
1291 test_25b() {
1292         [ ! -d $DIR/d25 ] && test_25a
1293         $CHECKSTAT -t file $DIR/s25/foo || error
1294 }
1295 run_test 25b "lookup file in symlinked directory ==============="
1296
1297 test_26a() {
1298         test_mkdir $DIR/d26
1299         test_mkdir $DIR/d26/d26-2
1300         ln -s d26/d26-2 $DIR/s26
1301         touch $DIR/s26/foo || error
1302 }
1303 run_test 26a "multiple component symlink ======================="
1304
1305 test_26b() {
1306         test_mkdir -p $DIR/$tdir/d26-2
1307         ln -s $tdir/d26-2/foo $DIR/s26-2
1308         touch $DIR/s26-2 || error
1309 }
1310 run_test 26b "multiple component symlink at end of lookup ======"
1311
1312 test_26c() {
1313         test_mkdir $DIR/d26.2
1314         touch $DIR/d26.2/foo
1315         ln -s d26.2 $DIR/s26.2-1
1316         ln -s s26.2-1 $DIR/s26.2-2
1317         ln -s s26.2-2 $DIR/s26.2-3
1318         chmod 0666 $DIR/s26.2-3/foo
1319 }
1320 run_test 26c "chain of symlinks"
1321
1322 # recursive symlinks (bug 439)
1323 test_26d() {
1324         ln -s d26-3/foo $DIR/d26-3
1325 }
1326 run_test 26d "create multiple component recursive symlink"
1327
1328 test_26e() {
1329         [ ! -h $DIR/d26-3 ] && test_26d
1330         rm $DIR/d26-3
1331 }
1332 run_test 26e "unlink multiple component recursive symlink"
1333
1334 # recursive symlinks (bug 7022)
1335 test_26f() {
1336         test_mkdir $DIR/$tdir
1337         test_mkdir $DIR/$tdir/$tfile
1338         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1339         test_mkdir -p lndir/bar1
1340         test_mkdir $DIR/$tdir/$tfile/$tfile
1341         cd $tfile                || error "cd $tfile failed"
1342         ln -s .. dotdot          || error "ln dotdot failed"
1343         ln -s dotdot/lndir lndir || error "ln lndir failed"
1344         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1345         output=`ls $tfile/$tfile/lndir/bar1`
1346         [ "$output" = bar1 ] && error "unexpected output"
1347         rm -r $tfile             || error "rm $tfile failed"
1348         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1349 }
1350 run_test 26f "rm -r of a directory which has recursive symlink"
1351
1352 test_27a() {
1353         test_mkdir $DIR/$tdir
1354         $LFS getstripe $DIR/$tdir
1355         $LFS setstripe -c 1 $DIR/$tdir/$tfile || error "setstripe failed"
1356         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1357         cp /etc/hosts $DIR/$tdir/$tfile || error
1358 }
1359 run_test 27a "one stripe file"
1360
1361 test_27b() {
1362         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1363         test_mkdir $DIR/$tdir
1364         $LFS setstripe -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1365         $LFS getstripe -c $DIR/$tdir/$tfile
1366         [ $($LFS getstripe -c $DIR/$tdir/$tfile) -eq 2 ] ||
1367                 error "two-stripe file doesn't have two stripes"
1368
1369         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1370 }
1371 run_test 27b "create and write to two stripe file"
1372
1373 test_27d() {
1374         test_mkdir $DIR/$tdir
1375         $LFS setstripe -c 0 -i -1 -S 0 $DIR/$tdir/$tfile ||
1376                 error "setstripe failed"
1377         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1378         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1379 }
1380 run_test 27d "create file with default settings"
1381
1382 test_27e() {
1383         # LU-5839 adds check for existed layout before setting it
1384         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1385                 skip "Need MDS version at least 2.7.56" && return
1386         test_mkdir $DIR/$tdir
1387         $LFS setstripe -c 2 $DIR/$tdir/$tfile || error "setstripe failed"
1388         $LFS setstripe -c 2 $DIR/$tdir/$tfile && error "setstripe worked twice"
1389         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "checkstat failed"
1390 }
1391 run_test 27e "setstripe existing file (should return error)"
1392
1393 test_27f() {
1394         test_mkdir $DIR/$tdir
1395         $LFS setstripe -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1396                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1397         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1398                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1399         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1400         $LFS getstripe $DIR/$tdir/$tfile || error "$LFS getstripe failed"
1401 }
1402 run_test 27f "setstripe with bad stripe size (should return error)"
1403
1404 test_27g() {
1405         test_mkdir $DIR/$tdir
1406         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1407         $LFS getstripe $DIR/$tdir/$tfile 2>&1 | grep "no stripe info" ||
1408                 error "$DIR/$tdir/$tfile has object"
1409 }
1410 run_test 27g "$LFS getstripe with no objects"
1411
1412 test_27i() {
1413         test_mkdir $DIR/$tdir
1414         touch $DIR/$tdir/$tfile || error "touch failed"
1415         [[ $($LFS getstripe -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1416                 error "missing objects"
1417 }
1418 run_test 27i "$LFS getstripe with some objects"
1419
1420 test_27j() {
1421         test_mkdir $DIR/$tdir
1422         $LFS setstripe -i $OSTCOUNT $DIR/$tdir/$tfile &&
1423                 error "setstripe failed" || true
1424 }
1425 run_test 27j "setstripe with bad stripe offset (should return error)"
1426
1427 test_27k() { # bug 2844
1428         test_mkdir $DIR/$tdir
1429         local file=$DIR/$tdir/$tfile
1430         local ll_max_blksize=$((4 * 1024 * 1024))
1431         $LFS setstripe -S 67108864 $file || error "setstripe failed"
1432         local blksize=$(stat $file | awk '/IO Block:/ { print $7 }')
1433         [ $blksize -le $ll_max_blksize ] || error "1:$blksize > $ll_max_blksize"
1434         dd if=/dev/zero of=$file bs=4k count=1
1435         blksize=$(stat $file | awk '/IO Block:/ { print $7 }')
1436         [ $blksize -le $ll_max_blksize ] || error "2:$blksize > $ll_max_blksize"
1437 }
1438 run_test 27k "limit i_blksize for broken user apps"
1439
1440 test_27l() {
1441         mcreate $DIR/$tfile || error "creating file"
1442         $RUNAS $LFS setstripe -c 1 $DIR/$tfile &&
1443                 error "setstripe should have failed" || true
1444 }
1445 run_test 27l "check setstripe permissions (should return error)"
1446
1447 test_27m() {
1448         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1449
1450         ORIGFREE=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
1451                    head -n1)
1452         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1453                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1454                 return
1455         fi
1456         trap simple_cleanup_common EXIT
1457         test_mkdir $DIR/$tdir
1458         $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.1
1459         dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=1024 count=$MAXFREE &&
1460                 error "dd should fill OST0"
1461         i=2
1462         while $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.$i; do
1463                 i=$((i + 1))
1464                 [ $i -gt 256 ] && break
1465         done
1466         i=$((i + 1))
1467         touch $DIR/$tdir/$tfile.$i
1468         [ $($LFS getstripe $DIR/$tdir/$tfile.$i | grep -A 10 obdidx |
1469             awk '{print $1}'| grep -w "0") ] &&
1470                 error "OST0 was full but new created file still use it"
1471         i=$((i + 1))
1472         touch $DIR/$tdir/$tfile.$i
1473         [ $($LFS getstripe $DIR/$tdir/$tfile.$i | grep -A 10 obdidx |
1474             awk '{print $1}'| grep -w "0") ] &&
1475                 error "OST0 was full but new created file still use it"
1476         simple_cleanup_common
1477 }
1478 run_test 27m "create file while OST0 was full"
1479
1480 sleep_maxage() {
1481         local delay=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage |
1482                       head -n 1 | awk '{ print $1 * 2 }')
1483         sleep $delay
1484 }
1485
1486 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1487 # if the OST isn't full anymore.
1488 reset_enospc() {
1489         local OSTIDX=${1:-""}
1490
1491         local list=$(comma_list $(osts_nodes))
1492         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1493
1494         do_nodes $list lctl set_param fail_loc=0
1495         sync    # initiate all OST_DESTROYs from MDS to OST
1496         sleep_maxage
1497 }
1498
1499 exhaust_precreations() {
1500         local OSTIDX=$1
1501         local FAILLOC=$2
1502         local FAILIDX=${3:-$OSTIDX}
1503         local ofacet=ost$((OSTIDX + 1))
1504
1505         test_mkdir -p -c1 $DIR/$tdir
1506         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
1507         local mfacet=mds$((mdtidx + 1))
1508         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1509
1510         local OST=$(ostname_from_index $OSTIDX)
1511
1512         # on the mdt's osc
1513         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1514         local last_id=$(do_facet $mfacet lctl get_param -n \
1515                         osc.$mdtosc_proc1.prealloc_last_id)
1516         local next_id=$(do_facet $mfacet lctl get_param -n \
1517                         osc.$mdtosc_proc1.prealloc_next_id)
1518
1519         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1520         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1521
1522         test_mkdir -p $DIR/$tdir/${OST}
1523         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1524 #define OBD_FAIL_OST_ENOSPC              0x215
1525         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1526         echo "Creating to objid $last_id on ost $OST..."
1527         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1528         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1529         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1530         sleep_maxage
1531 }
1532
1533 exhaust_all_precreations() {
1534         local i
1535         for (( i=0; i < OSTCOUNT; i++ )) ; do
1536                 exhaust_precreations $i $1 -1
1537         done
1538 }
1539
1540 test_27n() {
1541         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1542         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1543         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1544         remote_ost_nodsh && skip "remote OST with nodsh" && return
1545
1546         reset_enospc
1547         rm -f $DIR/$tdir/$tfile
1548         exhaust_precreations 0 0x80000215
1549         $LFS setstripe -c -1 $DIR/$tdir
1550         touch $DIR/$tdir/$tfile || error
1551         $LFS getstripe $DIR/$tdir/$tfile
1552         reset_enospc
1553 }
1554 run_test 27n "create file with some full OSTs"
1555
1556 test_27o() {
1557         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1558         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1559         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1560         remote_ost_nodsh && skip "remote OST with nodsh" && return
1561
1562         reset_enospc
1563         rm -f $DIR/$tdir/$tfile
1564         exhaust_all_precreations 0x215
1565
1566         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1567
1568         reset_enospc
1569         rm -rf $DIR/$tdir/*
1570 }
1571 run_test 27o "create file with all full OSTs (should error)"
1572
1573 test_27p() {
1574         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1575         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1576         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1577         remote_ost_nodsh && skip "remote OST with nodsh" && return
1578
1579         reset_enospc
1580         rm -f $DIR/$tdir/$tfile
1581         test_mkdir $DIR/$tdir
1582
1583         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1584         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1585         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1586
1587         exhaust_precreations 0 0x80000215
1588         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1589         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1590         $LFS getstripe $DIR/$tdir/$tfile
1591
1592         reset_enospc
1593 }
1594 run_test 27p "append to a truncated file with some full OSTs"
1595
1596 test_27q() {
1597         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1598         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1599         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1600         remote_ost_nodsh && skip "remote OST with nodsh" && return
1601
1602         reset_enospc
1603         rm -f $DIR/$tdir/$tfile
1604
1605         test_mkdir $DIR/$tdir
1606         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1607         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||
1608                 error "truncate $DIR/$tdir/$tfile failed"
1609         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1610
1611         exhaust_all_precreations 0x215
1612
1613         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1614         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1615
1616         reset_enospc
1617 }
1618 run_test 27q "append to truncated file with all OSTs full (should error)"
1619
1620 test_27r() {
1621         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1622         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1623         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1624         remote_ost_nodsh && skip "remote OST with nodsh" && return
1625
1626         reset_enospc
1627         rm -f $DIR/$tdir/$tfile
1628         exhaust_precreations 0 0x80000215
1629
1630         $LFS setstripe -i 0 -c 2 $DIR/$tdir/$tfile # && error
1631
1632         reset_enospc
1633 }
1634 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1635
1636 test_27s() { # bug 10725
1637         test_mkdir $DIR/$tdir
1638         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1639         local stripe_count=0
1640         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1641         $LFS setstripe -S $stripe_size -c $stripe_count $DIR/$tdir &&
1642                 error "stripe width >= 2^32 succeeded" || true
1643
1644 }
1645 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1646
1647 test_27t() { # bug 10864
1648         WDIR=$(pwd)
1649         WLFS=$(which lfs)
1650         cd $DIR
1651         touch $tfile
1652         $WLFS getstripe $tfile
1653         cd $WDIR
1654 }
1655 run_test 27t "check that utils parse path correctly"
1656
1657 test_27u() { # bug 4900
1658         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1659         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1660         local index
1661         local list=$(comma_list $(mdts_nodes))
1662
1663 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1664         do_nodes $list $LCTL set_param fail_loc=0x139
1665         test_mkdir -p $DIR/$tdir
1666         trap simple_cleanup_common EXIT
1667         createmany -o $DIR/$tdir/t- 1000
1668         do_nodes $list $LCTL set_param fail_loc=0
1669
1670         TLOG=$TMP/$tfile.getstripe
1671         $LFS getstripe $DIR/$tdir > $TLOG
1672         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1673         unlinkmany $DIR/$tdir/t- 1000
1674         trap 0
1675         [[ $OBJS -gt 0 ]] &&
1676                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1677 }
1678 run_test 27u "skip object creation on OSC w/o objects"
1679
1680 test_27v() { # bug 4900
1681         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1682         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1683         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1684         remote_ost_nodsh && skip "remote OST with nodsh" && return
1685
1686         exhaust_all_precreations 0x215
1687         reset_enospc
1688
1689         $LFS setstripe -c 1 $DIR/$tdir         # 1 stripe / file
1690
1691         touch $DIR/$tdir/$tfile
1692         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1693         # all except ost1
1694         for (( i=1; i < OSTCOUNT; i++ )); do
1695                 do_facet ost$i lctl set_param fail_loc=0x705
1696         done
1697         local START=`date +%s`
1698         createmany -o $DIR/$tdir/$tfile 32
1699
1700         local FINISH=`date +%s`
1701         local TIMEOUT=`lctl get_param -n timeout`
1702         local PROCESS=$((FINISH - START))
1703         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1704                error "$FINISH - $START >= $TIMEOUT / 2"
1705         sleep $((TIMEOUT / 2 - PROCESS))
1706         reset_enospc
1707 }
1708 run_test 27v "skip object creation on slow OST"
1709
1710 test_27w() { # bug 10997
1711         test_mkdir $DIR/$tdir
1712         $LFS setstripe -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1713         [ $($LFS getstripe -S $DIR/$tdir/f0) -ne 65536 ] &&
1714                 error "stripe size $size != 65536" || true
1715         [ $($LFS getstripe -d $DIR/$tdir | grep -c "stripe_count") -eq 0 ] &&
1716                 error "$LFS getstripe -d $DIR/$tdir no 'stripe_count'" || true
1717 }
1718 run_test 27w "check $LFS setstripe -S and getstrip -d options"
1719
1720 test_27wa() {
1721         [[ $OSTCOUNT -lt 2 ]] &&
1722                 skip_env "skipping multiple stripe count/offset test" && return
1723
1724         test_mkdir $DIR/$tdir
1725         for i in $(seq 1 $OSTCOUNT); do
1726                 offset=$((i - 1))
1727                 $LFS setstripe -c $i -i $offset $DIR/$tdir/f$i ||
1728                         error "setstripe -c $i -i $offset failed"
1729                 count=$($LFS getstripe -c $DIR/$tdir/f$i)
1730                 index=$($LFS getstripe -i $DIR/$tdir/f$i)
1731                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1732                 [ $index -ne $offset ] &&
1733                         error "stripe offset $index != $offset" || true
1734         done
1735 }
1736 run_test 27wa "check $LFS setstripe -c -i options"
1737
1738 test_27x() {
1739         remote_ost_nodsh && skip "remote OST with nodsh" && return
1740         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1741         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1742         OFFSET=$(($OSTCOUNT - 1))
1743         OSTIDX=0
1744         local OST=$(ostname_from_index $OSTIDX)
1745
1746         test_mkdir $DIR/$tdir
1747         $LFS setstripe -c 1 $DIR/$tdir  # 1 stripe per file
1748         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1749         sleep_maxage
1750         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1751         for i in $(seq 0 $OFFSET); do
1752                 [ $($LFS getstripe $DIR/$tdir/$tfile$i | grep -A 10 obdidx |
1753                         awk '{print $1}' | grep -w "$OSTIDX") ] &&
1754                 error "OST0 was degraded but new created file still use it"
1755         done
1756         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1757 }
1758 run_test 27x "create files while OST0 is degraded"
1759
1760 test_27y() {
1761         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1762         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1763         remote_ost_nodsh && skip "remote OST with nodsh" && return
1764         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1765
1766         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1767         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1768                 osc.$mdtosc.prealloc_last_id)
1769         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1770                 osc.$mdtosc.prealloc_next_id)
1771         local fcount=$((last_id - next_id))
1772         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1773         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1774
1775         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1776                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1777         local OST_DEACTIVE_IDX=-1
1778         local OSC
1779         local OSTIDX
1780         local OST
1781
1782         for OSC in $MDS_OSCS; do
1783                 OST=$(osc_to_ost $OSC)
1784                 OSTIDX=$(index_from_ostuuid $OST)
1785                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1786                         OST_DEACTIVE_IDX=$OSTIDX
1787                 fi
1788                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1789                         echo $OSC "is Deactivated:"
1790                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1791                 fi
1792         done
1793
1794         OSTIDX=$(index_from_ostuuid $OST)
1795         test_mkdir $DIR/$tdir
1796         $LFS setstripe -c 1 $DIR/$tdir      # 1 stripe / file
1797
1798         for OSC in $MDS_OSCS; do
1799                 OST=$(osc_to_ost $OSC)
1800                 OSTIDX=$(index_from_ostuuid $OST)
1801                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1802                         echo $OST "is degraded:"
1803                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1804                                                 obdfilter.$OST.degraded=1
1805                 fi
1806         done
1807
1808         sleep_maxage
1809         createmany -o $DIR/$tdir/$tfile $fcount
1810
1811         for OSC in $MDS_OSCS; do
1812                 OST=$(osc_to_ost $OSC)
1813                 OSTIDX=$(index_from_ostuuid $OST)
1814                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1815                         echo $OST "is recovered from degraded:"
1816                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1817                                                 obdfilter.$OST.degraded=0
1818                 else
1819                         do_facet $SINGLEMDS lctl --device %$OSC activate
1820                 fi
1821         done
1822
1823         # all osp devices get activated, hence -1 stripe count restored
1824         local stripe_count=0
1825
1826         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1827         # devices get activated.
1828         sleep_maxage
1829         $LFS setstripe -c -1 $DIR/$tfile
1830         stripe_count=$($LFS getstripe -c $DIR/$tfile)
1831         rm -f $DIR/$tfile
1832         [ $stripe_count -ne $OSTCOUNT ] &&
1833                 error "Of $OSTCOUNT OSTs, only $stripe_count is available"
1834         return 0
1835 }
1836 run_test 27y "create files while OST0 is degraded and the rest inactive"
1837
1838 check_seq_oid()
1839 {
1840         log "check file $1"
1841
1842         lmm_count=$($GETSTRIPE -c $1)
1843         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1844         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1845
1846         local old_ifs="$IFS"
1847         IFS=$'[:]'
1848         fid=($($LFS path2fid $1))
1849         IFS="$old_ifs"
1850
1851         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1852         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1853
1854         # compare lmm_seq and lu_fid->f_seq
1855         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1856         # compare lmm_object_id and lu_fid->oid
1857         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1858
1859         # check the trusted.fid attribute of the OST objects of the file
1860         local have_obdidx=false
1861         local stripe_nr=0
1862         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1863                 # skip lines up to and including "obdidx"
1864                 [ -z "$obdidx" ] && break
1865                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1866                 $have_obdidx || continue
1867
1868                 local ost=$((obdidx + 1))
1869                 local dev=$(ostdevname $ost)
1870                 local oid_hex
1871
1872                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1873
1874                 seq=$(echo $seq | sed -e "s/^0x//g")
1875                 if [ $seq == 0 ] || [ $(facet_fstype ost$ost) == zfs ]; then
1876                         oid_hex=$(echo $oid)
1877                 else
1878                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1879                 fi
1880                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1881
1882                 local ff=""
1883                 #
1884                 # Don't unmount/remount the OSTs if we don't need to do that.
1885                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1886                 # update too, until that use mount/ll_decode_filter_fid/mount.
1887                 # Re-enable when debugfs will understand new filter_fid.
1888                 #
1889                 if [ $(facet_fstype ost$ost) == ldiskfs ]; then
1890                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1891                                 $dev 2>/dev/null" | grep "parent=")
1892                 fi
1893                 if [ -z "$ff" ]; then
1894                         stop ost$ost
1895                         mount_fstype ost$ost
1896                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1897                                 $(facet_mntpt ost$ost)/$obj_file)
1898                         unmount_fstype ost$ost
1899                         start ost$ost $dev $OST_MOUNT_OPTS
1900                         clients_up
1901                 fi
1902
1903                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1904
1905                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1906
1907                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1908                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1909                 #
1910                 # fid: parent=[0x200000400:0x1e:0x0] stripe=1 stripe_count=2 \
1911                 #       stripe_size=1048576 component_id=1 component_start=0 \
1912                 #       component_end=33554432
1913                 local ff_parent=$(sed -e 's/.*parent=.//' <<<$ff)
1914                 local ff_pseq=$(cut -d: -f1 <<<$ff_parent)
1915                 local ff_poid=$(cut -d: -f2 <<<$ff_parent)
1916                 local ff_pstripe
1917                 if grep -q 'stripe=' <<<$ff; then
1918                         ff_pstripe=$(sed -e 's/.*stripe=//' -e 's/ .*//' <<<$ff)
1919                 else
1920                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1921                         # into f_ver in this case.  See comment on ff_parent.
1922                         ff_pstripe=$(cut -d: -f3 <<<$ff_parent | sed -e 's/]//')
1923                 fi
1924
1925                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1926                 [ $ff_pseq = $lmm_seq ] ||
1927                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1928                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1929                 [ $ff_poid = $lmm_oid ] ||
1930                         error "FF parent OID $ff_poid != $lmm_oid"
1931                 (($ff_pstripe == $stripe_nr)) ||
1932                         error "FF stripe $ff_pstripe != $stripe_nr"
1933
1934                 stripe_nr=$((stripe_nr + 1))
1935                 [ $(lustre_version_code client) -lt $(version_code 2.9.55) ] &&
1936                         continue
1937                 if grep -q 'stripe_count=' <<<$ff; then
1938                         local ff_scnt=$(sed -e 's/.*stripe_count=//' \
1939                                             -e 's/ .*//' <<<$ff)
1940                         [ $lmm_count = $ff_scnt ] ||
1941                                 error "FF stripe count $lmm_count != $ff_scnt"
1942                 fi
1943         done
1944 }
1945
1946 test_27z() {
1947         remote_ost_nodsh && skip "remote OST with nodsh" && return
1948         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1949         test_mkdir $DIR/$tdir
1950
1951         $LFS setstripe -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1952                 { error "setstripe -c -1 failed"; return 1; }
1953         # We need to send a write to every object to get parent FID info set.
1954         # This _should_ also work for setattr, but does not currently.
1955         # touch $DIR/$tdir/$tfile-1 ||
1956         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1957                 { error "dd $tfile-1 failed"; return 2; }
1958         $LFS setstripe -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1959                 { error "setstripe -c -1 failed"; return 3; }
1960         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1961                 { error "dd $tfile-2 failed"; return 4; }
1962
1963         # make sure write RPCs have been sent to OSTs
1964         sync; sleep 5; sync
1965
1966         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1967         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1968 }
1969 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1970
1971 test_27A() { # b=19102
1972         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1973         local restore_size=$($GETSTRIPE -S $MOUNT)
1974         local restore_count=$($GETSTRIPE -c $MOUNT)
1975         local restore_offset=$($GETSTRIPE -i $MOUNT)
1976         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1977         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1978                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1979         local default_size=$($GETSTRIPE -S $MOUNT)
1980         local default_offset=$($GETSTRIPE -i $MOUNT)
1981         local dsize=$((1024 * 1024))
1982         [ $default_size -eq $dsize ] ||
1983                 error "stripe size $default_size != $dsize"
1984         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1985         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1986 }
1987 run_test 27A "check filesystem-wide default LOV EA values"
1988
1989 test_27B() { # LU-2523
1990         test_mkdir $DIR/$tdir
1991         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1992         touch $DIR/$tdir/f0
1993         # open f1 with O_LOV_DELAY_CREATE
1994         # rename f0 onto f1
1995         # call setstripe ioctl on open file descriptor for f1
1996         # close
1997         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1998                 $DIR/$tdir/f0
1999
2000         rm -f $DIR/$tdir/f1
2001         # open f1 with O_LOV_DELAY_CREATE
2002         # unlink f1
2003         # call setstripe ioctl on open file descriptor for f1
2004         # close
2005         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
2006
2007         # Allow multiop to fail in imitation of NFS's busted semantics.
2008         true
2009 }
2010 run_test 27B "call setstripe on open unlinked file/rename victim"
2011
2012 test_27C() { #LU-2871
2013         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
2014
2015         declare -a ost_idx
2016         local index
2017         local found
2018         local i
2019         local j
2020
2021         test_mkdir $DIR/$tdir
2022         cd $DIR/$tdir
2023         for i in $(seq 0 $((OSTCOUNT - 1))); do
2024                 # set stripe across all OSTs starting from OST$i
2025                 $SETSTRIPE -i $i -c -1 $tfile$i
2026                 # get striping information
2027                 ost_idx=($($GETSTRIPE $tfile$i |
2028                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
2029                 echo ${ost_idx[@]}
2030
2031                 # check the layout
2032                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
2033                         error "${#ost_idx[@]} != $OSTCOUNT"
2034
2035                 for index in $(seq 0 $((OSTCOUNT - 1))); do
2036                         found=0
2037                         for j in $(echo ${ost_idx[@]}); do
2038                                 if [ $index -eq $j ]; then
2039                                         found=1
2040                                         break
2041                                 fi
2042                         done
2043                         [ $found = 1 ] ||
2044                                 error "Can not find $index in ${ost_idx[@]}"
2045                 done
2046         done
2047 }
2048 run_test 27C "check full striping across all OSTs"
2049
2050 test_27D() {
2051         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2052         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
2053         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2054         local POOL=${POOL:-testpool}
2055         local first_ost=0
2056         local last_ost=$(($OSTCOUNT - 1))
2057         local ost_step=1
2058         local ost_list=$(seq $first_ost $ost_step $last_ost)
2059         local ost_range="$first_ost $last_ost $ost_step"
2060
2061         test_mkdir $DIR/$tdir
2062         pool_add $POOL || error "pool_add failed"
2063         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2064
2065         local skip27D
2066         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ] &&
2067                 skip27D += "-s 29"
2068         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.55) -o \
2069           $(lustre_version_code client) -lt $(version_code 2.9.55) ] &&
2070                 skip27D += "-s 30,31"
2071         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT $skip27D ||
2072                 error "llapi_layout_test failed"
2073
2074         destroy_test_pools || error "destroy test pools failed"
2075 }
2076 run_test 27D "validate llapi_layout API"
2077
2078 # Verify that default_easize is increased from its initial value after
2079 # accessing a widely striped file.
2080 test_27E() {
2081         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2082         [ $(lustre_version_code client) -lt $(version_code 2.5.57) ] &&
2083                 skip "client does not have LU-3338 fix" && return
2084
2085         # 72 bytes is the minimum space required to store striping
2086         # information for a file striped across one OST:
2087         # (sizeof(struct lov_user_md_v3) +
2088         #  sizeof(struct lov_user_ost_data_v1))
2089         local min_easize=72
2090         $LCTL set_param -n llite.*.default_easize $min_easize ||
2091                 error "lctl set_param failed"
2092         local easize=$($LCTL get_param -n llite.*.default_easize)
2093
2094         [ $easize -eq $min_easize ] ||
2095                 error "failed to set default_easize"
2096
2097         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2098                 error "setstripe failed"
2099         cat $DIR/$tfile
2100         rm $DIR/$tfile
2101
2102         easize=$($LCTL get_param -n llite.*.default_easize)
2103
2104         [ $easize -gt $min_easize ] ||
2105                 error "default_easize not updated"
2106 }
2107 run_test 27E "check that default extended attribute size properly increases"
2108
2109 test_27F() { # LU-5346/LU-7975
2110         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2111         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.51) ]] &&
2112                 skip "Need MDS version at least 2.8.51" && return
2113         remote_ost_nodsh && skip "remote OST with nodsh" && return
2114
2115         test_mkdir $DIR/$tdir
2116         rm -f $DIR/$tdir/f0
2117         $SETSTRIPE -c 2 $DIR/$tdir
2118
2119         # stop all OSTs to reproduce situation for LU-7975 ticket
2120         for num in $(seq $OSTCOUNT); do
2121                 stop ost$num
2122         done
2123
2124         # open/create f0 with O_LOV_DELAY_CREATE
2125         # truncate f0 to a non-0 size
2126         # close
2127         multiop $DIR/$tdir/f0 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T1050000c
2128
2129         $CHECKSTAT -s 1050000 $DIR/$tdir/f0 || error "checkstat failed"
2130         # open/write it again to force delayed layout creation
2131         cat /etc/hosts > $DIR/$tdir/f0 &
2132         catpid=$!
2133
2134         # restart OSTs
2135         for num in $(seq $OSTCOUNT); do
2136                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
2137                         error "ost$num failed to start"
2138         done
2139
2140         wait $catpid || error "cat failed"
2141
2142         cmp /etc/hosts $DIR/$tdir/f0 || error "cmp failed"
2143         [[ $($GETSTRIPE -c $DIR/$tdir/f0) == 2 ]] || error "wrong stripecount"
2144
2145 }
2146 run_test 27F "Client resend delayed layout creation with non-zero size"
2147
2148 # createtest also checks that device nodes are created and
2149 # then visible correctly (#2091)
2150 test_28() { # bug 2091
2151         test_mkdir $DIR/d28
2152         $CREATETEST $DIR/d28/ct || error
2153 }
2154 run_test 28 "create/mknod/mkdir with bad file types ============"
2155
2156 test_29() {
2157         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
2158         sync; sleep 1; sync # flush out any dirty pages from previous tests
2159         cancel_lru_locks
2160         test_mkdir $DIR/d29
2161         touch $DIR/d29/foo
2162         log 'first d29'
2163         ls -l $DIR/d29
2164
2165         declare -i LOCKCOUNTORIG=0
2166         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2167                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2168         done
2169         [ $LOCKCOUNTORIG -eq 0 ] && error "No mdc lock count" && return 1
2170
2171         declare -i LOCKUNUSEDCOUNTORIG=0
2172         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2173                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2174         done
2175
2176         log 'second d29'
2177         ls -l $DIR/d29
2178         log 'done'
2179
2180         declare -i LOCKCOUNTCURRENT=0
2181         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2182                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2183         done
2184
2185         declare -i LOCKUNUSEDCOUNTCURRENT=0
2186         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2187                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2188         done
2189
2190         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2191                 $LCTL set_param -n ldlm.dump_namespaces ""
2192                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2193                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2194                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2195                 return 2
2196         fi
2197         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2198                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2199                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2200                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2201                 return 3
2202         fi
2203 }
2204 run_test 29 "IT_GETATTR regression  ============================"
2205
2206 test_30a() { # was test_30
2207         cp $(which ls) $DIR || cp /bin/ls $DIR
2208         $DIR/ls / || error
2209         rm $DIR/ls
2210 }
2211 run_test 30a "execute binary from Lustre (execve) =============="
2212
2213 test_30b() {
2214         cp `which ls` $DIR || cp /bin/ls $DIR
2215         chmod go+rx $DIR/ls
2216         $RUNAS $DIR/ls / || error
2217         rm $DIR/ls
2218 }
2219 run_test 30b "execute binary from Lustre as non-root ==========="
2220
2221 test_30c() { # b=22376
2222         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2223         cp `which ls` $DIR || cp /bin/ls $DIR
2224         chmod a-rw $DIR/ls
2225         cancel_lru_locks mdc
2226         cancel_lru_locks osc
2227         $RUNAS $DIR/ls / || error
2228         rm -f $DIR/ls
2229 }
2230 run_test 30c "execute binary from Lustre without read perms ===="
2231
2232 test_31a() {
2233         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2234         $CHECKSTAT -a $DIR/f31 || error
2235 }
2236 run_test 31a "open-unlink file =================================="
2237
2238 test_31b() {
2239         touch $DIR/f31 || error
2240         ln $DIR/f31 $DIR/f31b || error
2241         $MULTIOP $DIR/f31b Ouc || error
2242         $CHECKSTAT -t file $DIR/f31 || error
2243 }
2244 run_test 31b "unlink file with multiple links while open ======="
2245
2246 test_31c() {
2247         touch $DIR/f31 || error
2248         ln $DIR/f31 $DIR/f31c || error
2249         multiop_bg_pause $DIR/f31 O_uc || return 1
2250         MULTIPID=$!
2251         $MULTIOP $DIR/f31c Ouc
2252         kill -USR1 $MULTIPID
2253         wait $MULTIPID
2254 }
2255 run_test 31c "open-unlink file with multiple links ============="
2256
2257 test_31d() {
2258         opendirunlink $DIR/d31d $DIR/d31d || error
2259         $CHECKSTAT -a $DIR/d31d || error
2260 }
2261 run_test 31d "remove of open directory ========================="
2262
2263 test_31e() { # bug 2904
2264         openfilleddirunlink $DIR/d31e || error
2265 }
2266 run_test 31e "remove of open non-empty directory ==============="
2267
2268 test_31f() { # bug 4554
2269         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2270         set -vx
2271         test_mkdir $DIR/d31f
2272         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2273         cp /etc/hosts $DIR/d31f
2274         ls -l $DIR/d31f
2275         $GETSTRIPE $DIR/d31f/hosts
2276         multiop_bg_pause $DIR/d31f D_c || return 1
2277         MULTIPID=$!
2278
2279         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2280         test_mkdir $DIR/d31f
2281         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2282         cp /etc/hosts $DIR/d31f
2283         ls -l $DIR/d31f
2284         $GETSTRIPE $DIR/d31f/hosts
2285         multiop_bg_pause $DIR/d31f D_c || return 1
2286         MULTIPID2=$!
2287
2288         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2289         wait $MULTIPID || error "first opendir $MULTIPID failed"
2290
2291         sleep 6
2292
2293         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2294         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2295         set +vx
2296 }
2297 run_test 31f "remove of open directory with open-unlink file ==="
2298
2299 test_31g() {
2300         echo "-- cross directory link --"
2301         test_mkdir -c1 $DIR/${tdir}ga
2302         test_mkdir -c1 $DIR/${tdir}gb
2303         touch $DIR/${tdir}ga/f
2304         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2305         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2306         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2307         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2308         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2309 }
2310 run_test 31g "cross directory link==============="
2311
2312 test_31h() {
2313         echo "-- cross directory link --"
2314         test_mkdir -c1 $DIR/${tdir}
2315         test_mkdir -c1 $DIR/${tdir}/dir
2316         touch $DIR/${tdir}/f
2317         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2318         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2319         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2320         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2321         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2322 }
2323 run_test 31h "cross directory link under child==============="
2324
2325 test_31i() {
2326         echo "-- cross directory link --"
2327         test_mkdir -c1 $DIR/$tdir
2328         test_mkdir -c1 $DIR/$tdir/dir
2329         touch $DIR/$tdir/dir/f
2330         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2331         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2332         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2333         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2334         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2335 }
2336 run_test 31i "cross directory link under parent==============="
2337
2338 test_31j() {
2339         test_mkdir -c1 -p $DIR/$tdir
2340         test_mkdir -c1 -p $DIR/$tdir/dir1
2341         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2342         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2343         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2344         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2345         return 0
2346 }
2347 run_test 31j "link for directory==============="
2348
2349 test_31k() {
2350         test_mkdir -c1 -p $DIR/$tdir
2351         touch $DIR/$tdir/s
2352         touch $DIR/$tdir/exist
2353         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2354         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2355         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2356         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2357         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2358         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2359         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2360         return 0
2361 }
2362 run_test 31k "link to file: the same, non-existing, dir==============="
2363
2364 test_31m() {
2365         mkdir $DIR/d31m
2366         touch $DIR/d31m/s
2367         mkdir $DIR/d31m2
2368         touch $DIR/d31m2/exist
2369         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2370         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2371         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2372         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2373         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2374         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2375         return 0
2376 }
2377 run_test 31m "link to file: the same, non-existing, dir==============="
2378
2379 test_31n() {
2380         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2381         nlink=$(stat --format=%h $DIR/$tfile)
2382         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2383         local fd=$(free_fd)
2384         local cmd="exec $fd<$DIR/$tfile"
2385         eval $cmd
2386         cmd="exec $fd<&-"
2387         trap "eval $cmd" EXIT
2388         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2389         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2390         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2391         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2392         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2393         eval $cmd
2394 }
2395 run_test 31n "check link count of unlinked file"
2396
2397 link_one() {
2398         local TEMPNAME=$(mktemp $1_XXXXXX)
2399         mlink $TEMPNAME $1 2> /dev/null &&
2400                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2401         munlink $TEMPNAME
2402 }
2403
2404 test_31o() { # LU-2901
2405         test_mkdir $DIR/$tdir
2406         for LOOP in $(seq 100); do
2407                 rm -f $DIR/$tdir/$tfile*
2408                 for THREAD in $(seq 8); do
2409                         link_one $DIR/$tdir/$tfile.$LOOP &
2410                 done
2411                 wait
2412                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2413                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2414                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2415                         break || true
2416         done
2417 }
2418 run_test 31o "duplicate hard links with same filename"
2419
2420 test_31p() {
2421         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2422
2423         test_mkdir $DIR/$tdir
2424         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2425         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2426
2427         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2428                 error "open unlink test1 failed"
2429         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2430                 error "open unlink test2 failed"
2431
2432         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2433                 error "test1 still exists"
2434         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2435                 error "test2 still exists"
2436 }
2437 run_test 31p "remove of open striped directory"
2438
2439 cleanup_test32_mount() {
2440         local rc=0
2441         trap 0
2442         local loopdev=$(losetup -a | grep $EXT2_DEV | sed -ne 's/:.*$//p')
2443         $UMOUNT $DIR/$tdir/ext2-mountpoint || rc=$?
2444         losetup -d $loopdev || true
2445         rm -rf $DIR/$tdir
2446         return $rc
2447 }
2448
2449 test_32a() {
2450         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2451         echo "== more mountpoints and symlinks ================="
2452         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2453         trap cleanup_test32_mount EXIT
2454         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2455         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2456         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2457         cleanup_test32_mount
2458 }
2459 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2460
2461 test_32b() {
2462         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2463         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2464         trap cleanup_test32_mount EXIT
2465         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2466         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2467         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2468         cleanup_test32_mount
2469 }
2470 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2471
2472 test_32c() {
2473         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2474         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2475         trap cleanup_test32_mount EXIT
2476         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2477         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2478         test_mkdir -p $DIR/$tdir/d2/test_dir
2479         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2480         cleanup_test32_mount
2481 }
2482 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2483
2484 test_32d() {
2485         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2486         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2487         trap cleanup_test32_mount EXIT
2488         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2489         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2490         test_mkdir -p $DIR/$tdir/d2/test_dir
2491         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2492         cleanup_test32_mount
2493 }
2494 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir"
2495
2496 test_32e() {
2497         rm -fr $DIR/$tdir
2498         test_mkdir -p $DIR/$tdir/tmp
2499         local tmp_dir=$DIR/$tdir/tmp
2500         ln -s $DIR/$tdir $tmp_dir/symlink11
2501         ln -s $tmp_dir/symlink11 $tmp_dir/../symlink01
2502         $CHECKSTAT -t link $DIR/$tdir/tmp/symlink11 || error "symlink11 bad"
2503         $CHECKSTAT -t link $DIR/$tdir/symlink01 || error "symlink01 bad"
2504 }
2505 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir"
2506
2507 test_32f() {
2508         rm -fr $DIR/$tdir
2509         test_mkdir -p $DIR/$tdir/tmp
2510         local tmp_dir=$DIR/$tdir/tmp
2511         ln -s $DIR/$tdir $tmp_dir/symlink11
2512         ln -s $tmp_dir/symlink11 $tmp_dir/../symlink01
2513         ls $DIR/$tdir/tmp/symlink11  || error "symlink11 bad"
2514         ls $DIR/$tdir/symlink01 || error "symlink01 bad"
2515 }
2516 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir"
2517
2518 test_32g() {
2519         local tmp_dir=$DIR/$tdir/tmp
2520         test_mkdir -p $tmp_dir
2521         test_mkdir $DIR/${tdir}2
2522         ln -s $DIR/${tdir}2 $tmp_dir/symlink12
2523         ln -s $tmp_dir/symlink12 $tmp_dir/../symlink02
2524         $CHECKSTAT -t link $tmp_dir/symlink12 || error "symlink12 not a link"
2525         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error "symlink02 not a link"
2526         $CHECKSTAT -t dir -f $tmp_dir/symlink12 || error "symlink12 not a dir"
2527         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error "symlink12 not a dir"
2528 }
2529 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2530
2531 test_32h() {
2532         rm -fr $DIR/$tdir $DIR/${tdir}2
2533         tmp_dir=$DIR/$tdir/tmp
2534         test_mkdir -p $tmp_dir
2535         test_mkdir $DIR/${tdir}2
2536         ln -s $DIR/${tdir}2 $tmp_dir/symlink12
2537         ln -s $tmp_dir/symlink12 $tmp_dir/../symlink02
2538         ls $tmp_dir/symlink12 || error "listing symlink12"
2539         ls $DIR/$tdir/symlink02  || error "listing symlink02"
2540 }
2541 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2542
2543 test_32i() {
2544         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2545         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2546         trap cleanup_test32_mount EXIT
2547         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2548         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2549         touch $DIR/$tdir/test_file
2550         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2551         cleanup_test32_mount
2552 }
2553 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2554
2555 test_32j() {
2556         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2557         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2558         trap cleanup_test32_mount EXIT
2559         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2560         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2561         touch $DIR/$tdir/test_file
2562         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2563         cleanup_test32_mount
2564 }
2565 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2566
2567 test_32k() {
2568         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2569         rm -fr $DIR/$tdir
2570         trap cleanup_test32_mount EXIT
2571         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2572         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2573         test_mkdir -p $DIR/$tdir/d2
2574         touch $DIR/$tdir/d2/test_file || error
2575         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2576         cleanup_test32_mount
2577 }
2578 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2579
2580 test_32l() {
2581         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2582         rm -fr $DIR/$tdir
2583         trap cleanup_test32_mount EXIT
2584         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2585         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2586         test_mkdir -p $DIR/$tdir/d2
2587         touch $DIR/$tdir/d2/test_file
2588         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2589         cleanup_test32_mount
2590 }
2591 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2592
2593 test_32m() {
2594         rm -fr $DIR/d32m
2595         test_mkdir -p $DIR/d32m/tmp
2596         TMP_DIR=$DIR/d32m/tmp
2597         ln -s $DIR $TMP_DIR/symlink11
2598         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2599         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2600         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2601 }
2602 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2603
2604 test_32n() {
2605         rm -fr $DIR/d32n
2606         test_mkdir -p $DIR/d32n/tmp
2607         TMP_DIR=$DIR/d32n/tmp
2608         ln -s $DIR $TMP_DIR/symlink11
2609         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2610         ls -l $DIR/d32n/tmp/symlink11  || error
2611         ls -l $DIR/d32n/symlink01 || error
2612 }
2613 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2614
2615 test_32o() {
2616         touch $DIR/$tfile
2617         test_mkdir -p $DIR/d32o/tmp
2618         TMP_DIR=$DIR/d32o/tmp
2619         ln -s $DIR/$tfile $TMP_DIR/symlink12
2620         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2621         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2622         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2623         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2624         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2625 }
2626 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2627
2628 test_32p() {
2629         log 32p_1
2630         rm -fr $DIR/d32p
2631         log 32p_2
2632         rm -f $DIR/$tfile
2633         log 32p_3
2634         touch $DIR/$tfile
2635         log 32p_4
2636         test_mkdir -p $DIR/d32p/tmp
2637         log 32p_5
2638         TMP_DIR=$DIR/d32p/tmp
2639         log 32p_6
2640         ln -s $DIR/$tfile $TMP_DIR/symlink12
2641         log 32p_7
2642         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2643         log 32p_8
2644         cat $DIR/d32p/tmp/symlink12 || error
2645         log 32p_9
2646         cat $DIR/d32p/symlink02 || error
2647         log 32p_10
2648 }
2649 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2650
2651 test_32q() {
2652         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2653         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2654         trap cleanup_test32_mount EXIT
2655         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2656         touch $DIR/$tdir/ext2-mountpoint/under_the_mount
2657         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2658         ls $DIR/$tdir/ext2-mountpoint | grep "\<under_the_mount\>" && error
2659         cleanup_test32_mount
2660 }
2661 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2662
2663 test_32r() {
2664         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2665         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2666         trap cleanup_test32_mount EXIT
2667         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2668         touch $DIR/$tdir/ext2-mountpoint/under_the_mount
2669         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2670         ls $DIR/$tdir/ext2-mountpoint | grep -q under_the_mount && error || true
2671         cleanup_test32_mount
2672 }
2673 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2674
2675 test_33aa() {
2676         rm -f $DIR/$tfile
2677         touch $DIR/$tfile
2678         chmod 444 $DIR/$tfile
2679         chown $RUNAS_ID $DIR/$tfile
2680         log 33_1
2681         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2682         log 33_2
2683 }
2684 run_test 33aa "write file with mode 444 (should return error)"
2685
2686 test_33a() {
2687         rm -fr $DIR/$tdir
2688         test_mkdir $DIR/$tdir
2689         chown $RUNAS_ID $DIR/$tdir
2690         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/$tdir/$tfile ||
2691                 error "$RUNAS create $tdir/$tfile failed"
2692         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/$tdir/$tfile &&
2693                 error "open RDWR" || true
2694 }
2695 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2696
2697 test_33b() {
2698         rm -fr $DIR/$tdir
2699         test_mkdir $DIR/$tdir
2700         chown $RUNAS_ID $DIR/$tdir
2701         $RUNAS $OPENFILE -f 1286739555 $DIR/$tdir/$tfile || true
2702 }
2703 run_test 33b "test open file with malformed flags (No panic)"
2704
2705 test_33c() {
2706         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2707         local ostnum
2708         local ostname
2709         local write_bytes
2710         local all_zeros
2711
2712         remote_ost_nodsh && skip "remote OST with nodsh" && return
2713         all_zeros=:
2714         rm -fr $DIR/$tdir
2715         test_mkdir $DIR/$tdir
2716         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2717
2718         sync
2719         for ostnum in $(seq $OSTCOUNT); do
2720                 # test-framework's OST numbering is one-based, while Lustre's
2721                 # is zero-based
2722                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2723                 # Parsing llobdstat's output sucks; we could grep the /proc
2724                 # path, but that's likely to not be as portable as using the
2725                 # llobdstat utility.  So we parse lctl output instead.
2726                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2727                         obdfilter/$ostname/stats |
2728                         awk '/^write_bytes/ {print $7}' )
2729                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2730                 if (( ${write_bytes:-0} > 0 ))
2731                 then
2732                         all_zeros=false
2733                         break;
2734                 fi
2735         done
2736
2737         $all_zeros || return 0
2738
2739         # Write four bytes
2740         echo foo > $DIR/$tdir/bar
2741         # Really write them
2742         sync
2743
2744         # Total up write_bytes after writing.  We'd better find non-zeros.
2745         for ostnum in $(seq $OSTCOUNT); do
2746                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2747                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2748                         obdfilter/$ostname/stats |
2749                         awk '/^write_bytes/ {print $7}' )
2750                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2751                 if (( ${write_bytes:-0} > 0 ))
2752                 then
2753                         all_zeros=false
2754                         break;
2755                 fi
2756         done
2757
2758         if $all_zeros
2759         then
2760                 for ostnum in $(seq $OSTCOUNT); do
2761                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2762                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2763                         do_facet ost$ostnum lctl get_param -n \
2764                                 obdfilter/$ostname/stats
2765                 done
2766                 error "OST not keeping write_bytes stats (b22312)"
2767         fi
2768 }
2769 run_test 33c "test llobdstat and write_bytes"
2770
2771 test_33d() {
2772         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2773         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2774         local MDTIDX=1
2775         local remote_dir=$DIR/$tdir/remote_dir
2776
2777         test_mkdir $DIR/$tdir
2778         $LFS mkdir -i $MDTIDX $remote_dir ||
2779                 error "create remote directory failed"
2780
2781         touch $remote_dir/$tfile
2782         chmod 444 $remote_dir/$tfile
2783         chown $RUNAS_ID $remote_dir/$tfile
2784
2785         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2786
2787         chown $RUNAS_ID $remote_dir
2788         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2789                                         error "create" || true
2790         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2791                                     error "open RDWR" || true
2792         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 || true
2793 }
2794 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2795
2796 test_33e() {
2797         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2798
2799         mkdir $DIR/$tdir
2800
2801         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2802         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2803         mkdir $DIR/$tdir/local_dir
2804
2805         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2806         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2807         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2808
2809         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2810                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2811
2812         rmdir $DIR/$tdir/* || error "rmdir failed"
2813
2814         umask 777
2815         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2816         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2817         mkdir $DIR/$tdir/local_dir
2818
2819         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2820         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2821         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2822
2823         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2824                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2825
2826         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2827
2828         umask 000
2829         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2830         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2831         mkdir $DIR/$tdir/local_dir
2832
2833         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2834         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2835         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2836
2837         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2838                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2839 }
2840 run_test 33e "mkdir and striped directory should have same mode"
2841
2842 cleanup_33f() {
2843         trap 0
2844         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
2845 }
2846
2847 test_33f() {
2848         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2849         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2850
2851         mkdir $DIR/$tdir
2852         chmod go+rwx $DIR/$tdir
2853         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
2854         trap cleanup_33f EXIT
2855
2856         $RUNAS lfs mkdir -c$MDSCOUNT $DIR/$tdir/striped_dir ||
2857                 error "cannot create striped directory"
2858
2859         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
2860                 error "cannot create files in striped directory"
2861
2862         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
2863                 error "cannot remove files in striped directory"
2864
2865         $RUNAS rmdir $DIR/$tdir/striped_dir ||
2866                 error "cannot remove striped directory"
2867
2868         cleanup_33f
2869 }
2870 run_test 33f "nonroot user can create, access, and remove a striped directory"
2871
2872 test_33g() {
2873         mkdir -p $DIR/$tdir/dir2
2874
2875         local err=$($RUNAS mkdir $DIR/$tdir/dir2 2>&1)
2876         echo $err
2877         [[ $err =~ "exists" ]] || error "Not exists error"
2878 }
2879 run_test 33g "nonroot user create already existing root created file"
2880
2881 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2882 test_34a() {
2883         rm -f $DIR/f34
2884         $MCREATE $DIR/f34 || error
2885         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2886         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2887         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2888         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2889 }
2890 run_test 34a "truncate file that has not been opened ==========="
2891
2892 test_34b() {
2893         [ ! -f $DIR/f34 ] && test_34a
2894         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2895         $OPENFILE -f O_RDONLY $DIR/f34
2896         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2897         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2898 }
2899 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2900
2901 test_34c() {
2902         [ ! -f $DIR/f34 ] && test_34a
2903         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2904         $OPENFILE -f O_RDWR $DIR/f34
2905         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2906         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2907 }
2908 run_test 34c "O_RDWR opening file-with-size works =============="
2909
2910 test_34d() {
2911         [ ! -f $DIR/f34 ] && test_34a
2912         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2913         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2914         rm $DIR/f34
2915 }
2916 run_test 34d "write to sparse file ============================="
2917
2918 test_34e() {
2919         rm -f $DIR/f34e
2920         $MCREATE $DIR/f34e || error
2921         $TRUNCATE $DIR/f34e 1000 || error
2922         $CHECKSTAT -s 1000 $DIR/f34e || error
2923         $OPENFILE -f O_RDWR $DIR/f34e
2924         $CHECKSTAT -s 1000 $DIR/f34e || error
2925 }
2926 run_test 34e "create objects, some with size and some without =="
2927
2928 test_34f() { # bug 6242, 6243
2929         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2930         SIZE34F=48000
2931         rm -f $DIR/f34f
2932         $MCREATE $DIR/f34f || error
2933         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2934         dd if=$DIR/f34f of=$TMP/f34f
2935         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2936         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2937         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2938         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2939         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2940 }
2941 run_test 34f "read from a file with no objects until EOF ======="
2942
2943 test_34g() {
2944         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2945         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2946         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2947         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2948         cancel_lru_locks osc
2949         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2950                 error "wrong size after lock cancel"
2951
2952         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2953         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2954                 error "expanding truncate failed"
2955         cancel_lru_locks osc
2956         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2957                 error "wrong expanded size after lock cancel"
2958 }
2959 run_test 34g "truncate long file ==============================="
2960
2961 test_34h() {
2962         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2963         local gid=10
2964         local sz=1000
2965
2966         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2967         sync # Flush the cache so that multiop below does not block on cache
2968              # flush when getting the group lock
2969         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2970         MULTIPID=$!
2971
2972         # Since just timed wait is not good enough, let's do a sync write
2973         # that way we are sure enough time for a roundtrip + processing
2974         # passed + 2 seconds of extra margin.
2975         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2976         rm $DIR/${tfile}-1
2977         sleep 2
2978
2979         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2980                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2981                 kill -9 $MULTIPID
2982         fi
2983         wait $MULTIPID
2984         local nsz=`stat -c %s $DIR/$tfile`
2985         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2986 }
2987 run_test 34h "ftruncate file under grouplock should not block"
2988
2989 test_35a() {
2990         cp /bin/sh $DIR/f35a
2991         chmod 444 $DIR/f35a
2992         chown $RUNAS_ID $DIR/f35a
2993         $RUNAS $DIR/f35a && error || true
2994         rm $DIR/f35a
2995 }
2996 run_test 35a "exec file with mode 444 (should return and not leak)"
2997
2998 test_36a() {
2999         rm -f $DIR/f36
3000         utime $DIR/f36 || error
3001 }
3002 run_test 36a "MDS utime check (mknod, utime)"
3003
3004 test_36b() {
3005         echo "" > $DIR/f36
3006         utime $DIR/f36 || error
3007 }
3008 run_test 36b "OST utime check (open, utime)"
3009
3010 test_36c() {
3011         rm -f $DIR/d36/f36
3012         test_mkdir $DIR/d36
3013         chown $RUNAS_ID $DIR/d36
3014         $RUNAS utime $DIR/d36/f36 || error
3015 }
3016 run_test 36c "non-root MDS utime check (mknod, utime)"
3017
3018 test_36d() {
3019         [ ! -d $DIR/d36 ] && test_36c
3020         echo "" > $DIR/d36/f36
3021         $RUNAS utime $DIR/d36/f36 || error
3022 }
3023 run_test 36d "non-root OST utime check (open, utime)"
3024
3025 test_36e() {
3026         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
3027         test_mkdir $DIR/$tdir
3028         touch $DIR/$tdir/$tfile
3029         $RUNAS utime $DIR/$tdir/$tfile &&
3030                 error "utime worked, expected failure" || true
3031 }
3032 run_test 36e "utime on non-owned file (should return error)"
3033
3034 subr_36fh() {
3035         local fl="$1"
3036         local LANG_SAVE=$LANG
3037         local LC_LANG_SAVE=$LC_LANG
3038         export LANG=C LC_LANG=C # for date language
3039
3040         DATESTR="Dec 20  2000"
3041         test_mkdir $DIR/$tdir
3042         lctl set_param fail_loc=$fl
3043         date; date +%s
3044         cp /etc/hosts $DIR/$tdir/$tfile
3045         sync & # write RPC generated with "current" inode timestamp, but delayed
3046         sleep 1
3047         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
3048         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
3049         cancel_lru_locks osc
3050         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
3051         date; date +%s
3052         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
3053                 echo "BEFORE: $LS_BEFORE" && \
3054                 echo "AFTER : $LS_AFTER" && \
3055                 echo "WANT  : $DATESTR" && \
3056                 error "$DIR/$tdir/$tfile timestamps changed" || true
3057
3058         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
3059 }
3060
3061 test_36f() {
3062         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3063         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
3064         subr_36fh "0x80000214"
3065 }
3066 run_test 36f "utime on file racing with OST BRW write =========="
3067
3068 test_36g() {
3069         remote_ost_nodsh && skip "remote OST with nodsh" && return
3070         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3071         local fmd_max_age
3072         local fmd_before
3073         local fmd_after
3074
3075         test_mkdir $DIR/$tdir
3076         fmd_max_age=$(do_facet ost1 \
3077                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
3078                 head -n 1")
3079
3080         fmd_before=$(do_facet ost1 \
3081                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3082         touch $DIR/$tdir/$tfile
3083         sleep $((fmd_max_age + 12))
3084         fmd_after=$(do_facet ost1 \
3085                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3086
3087         echo "fmd_before: $fmd_before"
3088         echo "fmd_after: $fmd_after"
3089         [[ $fmd_after -gt $fmd_before ]] &&
3090                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
3091                 error "fmd didn't expire after ping" || true
3092 }
3093 run_test 36g "filter mod data cache expiry ====================="
3094
3095 test_36h() {
3096         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3097         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
3098         subr_36fh "0x80000227"
3099 }
3100 run_test 36h "utime on file racing with OST BRW write =========="
3101
3102 test_36i() {
3103         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3104
3105         test_mkdir $DIR/$tdir
3106         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
3107
3108         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3109         local new_mtime=$((mtime + 200))
3110
3111         #change Modify time of striped dir
3112         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3113                         error "change mtime failed"
3114
3115         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3116
3117         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3118 }
3119 run_test 36i "change mtime on striped directory"
3120
3121 # test_37 - duplicate with tests 32q 32r
3122
3123 test_38() {
3124         local file=$DIR/$tfile
3125         touch $file
3126         openfile -f O_DIRECTORY $file
3127         local RC=$?
3128         local ENOTDIR=20
3129         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3130         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3131 }
3132 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3133
3134 test_39a() { # was test_39
3135         touch $DIR/$tfile
3136         touch $DIR/${tfile}2
3137 #       ls -l  $DIR/$tfile $DIR/${tfile}2
3138 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
3139 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
3140         sleep 2
3141         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3142         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3143                 echo "mtime"
3144                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3145                 echo "atime"
3146                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3147                 echo "ctime"
3148                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3149                 error "O_TRUNC didn't change timestamps"
3150         fi
3151 }
3152 run_test 39a "mtime changed on create"
3153
3154 test_39b() {
3155         test_mkdir -c1 $DIR/$tdir
3156         cp -p /etc/passwd $DIR/$tdir/fopen
3157         cp -p /etc/passwd $DIR/$tdir/flink
3158         cp -p /etc/passwd $DIR/$tdir/funlink
3159         cp -p /etc/passwd $DIR/$tdir/frename
3160         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3161
3162         sleep 1
3163         echo "aaaaaa" >> $DIR/$tdir/fopen
3164         echo "aaaaaa" >> $DIR/$tdir/flink
3165         echo "aaaaaa" >> $DIR/$tdir/funlink
3166         echo "aaaaaa" >> $DIR/$tdir/frename
3167
3168         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3169         local link_new=`stat -c %Y $DIR/$tdir/flink`
3170         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3171         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3172
3173         cat $DIR/$tdir/fopen > /dev/null
3174         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3175         rm -f $DIR/$tdir/funlink2
3176         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3177
3178         for (( i=0; i < 2; i++ )) ; do
3179                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3180                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3181                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3182                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3183
3184                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3185                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3186                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3187                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3188
3189                 cancel_lru_locks osc
3190                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3191         done
3192 }
3193 run_test 39b "mtime change on open, link, unlink, rename  ======"
3194
3195 # this should be set to past
3196 TEST_39_MTIME=`date -d "1 year ago" +%s`
3197
3198 # bug 11063
3199 test_39c() {
3200         touch $DIR1/$tfile
3201         sleep 2
3202         local mtime0=`stat -c %Y $DIR1/$tfile`
3203
3204         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3205         local mtime1=`stat -c %Y $DIR1/$tfile`
3206         [ "$mtime1" = $TEST_39_MTIME ] || \
3207                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3208
3209         local d1=`date +%s`
3210         echo hello >> $DIR1/$tfile
3211         local d2=`date +%s`
3212         local mtime2=`stat -c %Y $DIR1/$tfile`
3213         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3214                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3215
3216         mv $DIR1/$tfile $DIR1/$tfile-1
3217
3218         for (( i=0; i < 2; i++ )) ; do
3219                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3220                 [ "$mtime2" = "$mtime3" ] || \
3221                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3222
3223                 cancel_lru_locks osc
3224                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3225         done
3226 }
3227 run_test 39c "mtime change on rename ==========================="
3228
3229 # bug 21114
3230 test_39d() {
3231         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3232         touch $DIR1/$tfile
3233
3234         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3235
3236         for (( i=0; i < 2; i++ )) ; do
3237                 local mtime=`stat -c %Y $DIR1/$tfile`
3238                 [ $mtime = $TEST_39_MTIME ] || \
3239                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3240
3241                 cancel_lru_locks osc
3242                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3243         done
3244 }
3245 run_test 39d "create, utime, stat =============================="
3246
3247 # bug 21114
3248 test_39e() {
3249         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3250         touch $DIR1/$tfile
3251         local mtime1=`stat -c %Y $DIR1/$tfile`
3252
3253         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3254
3255         for (( i=0; i < 2; i++ )) ; do
3256                 local mtime2=`stat -c %Y $DIR1/$tfile`
3257                 [ $mtime2 = $TEST_39_MTIME ] || \
3258                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3259
3260                 cancel_lru_locks osc
3261                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3262         done
3263 }
3264 run_test 39e "create, stat, utime, stat ========================"
3265
3266 # bug 21114
3267 test_39f() {
3268         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3269         touch $DIR1/$tfile
3270         mtime1=`stat -c %Y $DIR1/$tfile`
3271
3272         sleep 2
3273         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3274
3275         for (( i=0; i < 2; i++ )) ; do
3276                 local mtime2=`stat -c %Y $DIR1/$tfile`
3277                 [ $mtime2 = $TEST_39_MTIME ] || \
3278                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3279
3280                 cancel_lru_locks osc
3281                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3282         done
3283 }
3284 run_test 39f "create, stat, sleep, utime, stat ================="
3285
3286 # bug 11063
3287 test_39g() {
3288         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3289         echo hello >> $DIR1/$tfile
3290         local mtime1=`stat -c %Y $DIR1/$tfile`
3291
3292         sleep 2
3293         chmod o+r $DIR1/$tfile
3294
3295         for (( i=0; i < 2; i++ )) ; do
3296                 local mtime2=`stat -c %Y $DIR1/$tfile`
3297                 [ "$mtime1" = "$mtime2" ] || \
3298                         error "lost mtime: $mtime2, should be $mtime1"
3299
3300                 cancel_lru_locks osc
3301                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3302         done
3303 }
3304 run_test 39g "write, chmod, stat ==============================="
3305
3306 # bug 11063
3307 test_39h() {
3308         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3309         touch $DIR1/$tfile
3310         sleep 1
3311
3312         local d1=`date`
3313         echo hello >> $DIR1/$tfile
3314         local mtime1=`stat -c %Y $DIR1/$tfile`
3315
3316         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3317         local d2=`date`
3318         if [ "$d1" != "$d2" ]; then
3319                 echo "write and touch not within one second"
3320         else
3321                 for (( i=0; i < 2; i++ )) ; do
3322                         local mtime2=`stat -c %Y $DIR1/$tfile`
3323                         [ "$mtime2" = $TEST_39_MTIME ] || \
3324                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3325
3326                         cancel_lru_locks osc
3327                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3328                 done
3329         fi
3330 }
3331 run_test 39h "write, utime within one second, stat ============="
3332
3333 test_39i() {
3334         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3335         touch $DIR1/$tfile
3336         sleep 1
3337
3338         echo hello >> $DIR1/$tfile
3339         local mtime1=`stat -c %Y $DIR1/$tfile`
3340
3341         mv $DIR1/$tfile $DIR1/$tfile-1
3342
3343         for (( i=0; i < 2; i++ )) ; do
3344                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3345
3346                 [ "$mtime1" = "$mtime2" ] || \
3347                         error "lost mtime: $mtime2, should be $mtime1"
3348
3349                 cancel_lru_locks osc
3350                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3351         done
3352 }
3353 run_test 39i "write, rename, stat =============================="
3354
3355 test_39j() {
3356         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3357         start_full_debug_logging
3358         touch $DIR1/$tfile
3359         sleep 1
3360
3361         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3362         lctl set_param fail_loc=0x80000412
3363         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3364                 error "multiop failed"
3365         local multipid=$!
3366         local mtime1=`stat -c %Y $DIR1/$tfile`
3367
3368         mv $DIR1/$tfile $DIR1/$tfile-1
3369
3370         kill -USR1 $multipid
3371         wait $multipid || error "multiop close failed"
3372
3373         for (( i=0; i < 2; i++ )) ; do
3374                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3375                 [ "$mtime1" = "$mtime2" ] ||
3376                         error "mtime is lost on close: $mtime2, " \
3377                               "should be $mtime1"
3378
3379                 cancel_lru_locks osc
3380                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3381         done
3382         lctl set_param fail_loc=0
3383         stop_full_debug_logging
3384 }
3385 run_test 39j "write, rename, close, stat ======================="
3386
3387 test_39k() {
3388         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3389         touch $DIR1/$tfile
3390         sleep 1
3391
3392         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3393         local multipid=$!
3394         local mtime1=`stat -c %Y $DIR1/$tfile`
3395
3396         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3397
3398         kill -USR1 $multipid
3399         wait $multipid || error "multiop close failed"
3400
3401         for (( i=0; i < 2; i++ )) ; do
3402                 local mtime2=`stat -c %Y $DIR1/$tfile`
3403
3404                 [ "$mtime2" = $TEST_39_MTIME ] || \
3405                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3406
3407                 cancel_lru_locks osc
3408                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3409         done
3410 }
3411 run_test 39k "write, utime, close, stat ========================"
3412
3413 # this should be set to future
3414 TEST_39_ATIME=`date -d "1 year" +%s`
3415
3416 test_39l() {
3417         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3418         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3419         local atime_diff=$(do_facet $SINGLEMDS \
3420                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3421         rm -rf $DIR/$tdir
3422         mkdir -p $DIR/$tdir
3423
3424         # test setting directory atime to future
3425         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3426         local atime=$(stat -c %X $DIR/$tdir)
3427         [ "$atime" = $TEST_39_ATIME ] ||
3428                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3429
3430         # test setting directory atime from future to now
3431         local now=$(date +%s)
3432         touch -a -d @$now $DIR/$tdir
3433
3434         atime=$(stat -c %X $DIR/$tdir)
3435         [ "$atime" -eq "$now"  ] ||
3436                 error "atime is not updated from future: $atime, $now"
3437
3438         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3439         sleep 3
3440
3441         # test setting directory atime when now > dir atime + atime_diff
3442         local d1=$(date +%s)
3443         ls $DIR/$tdir
3444         local d2=$(date +%s)
3445         cancel_lru_locks mdc
3446         atime=$(stat -c %X $DIR/$tdir)
3447         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
3448                 error "atime is not updated  : $atime, should be $d2"
3449
3450         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3451         sleep 3
3452
3453         # test not setting directory atime when now < dir atime + atime_diff
3454         ls $DIR/$tdir
3455         cancel_lru_locks mdc
3456         atime=$(stat -c %X $DIR/$tdir)
3457         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
3458                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3459
3460         do_facet $SINGLEMDS \
3461                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3462 }
3463 run_test 39l "directory atime update ==========================="
3464
3465 test_39m() {
3466         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3467         touch $DIR1/$tfile
3468         sleep 2
3469         local far_past_mtime=$(date -d "May 29 1953" +%s)
3470         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3471
3472         touch -m -d @$far_past_mtime $DIR1/$tfile
3473         touch -a -d @$far_past_atime $DIR1/$tfile
3474
3475         for (( i=0; i < 2; i++ )) ; do
3476                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3477                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3478                         error "atime or mtime set incorrectly"
3479
3480                 cancel_lru_locks osc
3481                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3482         done
3483 }
3484 run_test 39m "test atime and mtime before 1970"
3485
3486 test_39n() { # LU-3832
3487         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3488         local atime_diff=$(do_facet $SINGLEMDS \
3489                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3490         local atime0
3491         local atime1
3492         local atime2
3493
3494         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3495
3496         rm -rf $DIR/$tfile
3497         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3498         atime0=$(stat -c %X $DIR/$tfile)
3499
3500         sleep 5
3501         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3502         atime1=$(stat -c %X $DIR/$tfile)
3503
3504         sleep 5
3505         cancel_lru_locks mdc
3506         cancel_lru_locks osc
3507         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3508         atime2=$(stat -c %X $DIR/$tfile)
3509
3510         do_facet $SINGLEMDS \
3511                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3512
3513         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3514         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3515 }
3516 run_test 39n "check that O_NOATIME is honored"
3517
3518 test_39o() {
3519         TESTDIR=$DIR/$tdir/$tfile
3520         [ -e $TESTDIR ] && rm -rf $TESTDIR
3521         mkdir -p $TESTDIR
3522         cd $TESTDIR
3523         links1=2
3524         ls
3525         mkdir a b
3526         ls
3527         links2=$(stat -c %h .)
3528         [ $(($links1 + 2)) != $links2 ] &&
3529                 error "wrong links count $(($links1 + 2)) != $links2"
3530         rmdir b
3531         links3=$(stat -c %h .)
3532         [ $(($links1 + 1)) != $links3 ] &&
3533                 error "wrong links count $links1 != $links3"
3534         return 0
3535 }
3536 run_test 39o "directory cached attributes updated after create"
3537
3538 test_39p() {
3539         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3540         local MDTIDX=1
3541         TESTDIR=$DIR/$tdir/$tdir
3542         [ -e $TESTDIR ] && rm -rf $TESTDIR
3543         test_mkdir -p $TESTDIR
3544         cd $TESTDIR
3545         links1=2
3546         ls
3547         test_mkdir -i $MDTIDX $TESTDIR/remote_dir1
3548         test_mkdir -i $MDTIDX $TESTDIR/remote_dir2
3549         ls
3550         links2=$(stat -c %h .)
3551         [ $(($links1 + 2)) != $links2 ] &&
3552                 error "wrong links count $(($links1 + 2)) != $links2"
3553         rmdir remote_dir2
3554         links3=$(stat -c %h .)
3555         [ $(($links1 + 1)) != $links3 ] &&
3556                 error "wrong links count $links1 != $links3"
3557         return 0
3558 }
3559 run_test 39p "remote directory cached attributes updated after create ========"
3560
3561
3562 test_39q() { # LU-8041
3563         local testdir=$DIR/$tdir
3564         mkdir -p $testdir
3565         multiop_bg_pause $testdir D_c || error "multiop failed"
3566         local multipid=$!
3567         cancel_lru_locks mdc
3568         kill -USR1 $multipid
3569         local atime=$(stat -c %X $testdir)
3570         [ "$atime" -ne 0 ] || error "atime is zero"
3571 }
3572 run_test 39q "close won't zero out atime"
3573
3574 test_40() {
3575         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3576         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3577                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3578         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3579                 error "$tfile is not 4096 bytes in size"
3580 }
3581 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3582
3583 test_41() {
3584         # bug 1553
3585         small_write $DIR/f41 18
3586 }
3587 run_test 41 "test small file write + fstat ====================="
3588
3589 count_ost_writes() {
3590         lctl get_param -n osc.*.stats |
3591                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3592                         END { printf("%0.0f", writes) }'
3593 }
3594
3595 # decent default
3596 WRITEBACK_SAVE=500
3597 DIRTY_RATIO_SAVE=40
3598 MAX_DIRTY_RATIO=50
3599 BG_DIRTY_RATIO_SAVE=10
3600 MAX_BG_DIRTY_RATIO=25
3601
3602 start_writeback() {
3603         trap 0
3604         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3605         # dirty_ratio, dirty_background_ratio
3606         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3607                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3608                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3609                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3610         else
3611                 # if file not here, we are a 2.4 kernel
3612                 kill -CONT `pidof kupdated`
3613         fi
3614 }
3615
3616 stop_writeback() {
3617         # setup the trap first, so someone cannot exit the test at the
3618         # exact wrong time and mess up a machine
3619         trap start_writeback EXIT
3620         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3621         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3622                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3623                 sysctl -w vm.dirty_writeback_centisecs=0
3624                 sysctl -w vm.dirty_writeback_centisecs=0
3625                 # save and increase /proc/sys/vm/dirty_ratio
3626                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3627                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3628                 # save and increase /proc/sys/vm/dirty_background_ratio
3629                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3630                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3631         else
3632                 # if file not here, we are a 2.4 kernel
3633                 kill -STOP `pidof kupdated`
3634         fi
3635 }
3636
3637 # ensure that all stripes have some grant before we test client-side cache
3638 setup_test42() {
3639         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3640                 dd if=/dev/zero of=$i bs=4k count=1
3641                 rm $i
3642         done
3643 }
3644
3645 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3646 # file truncation, and file removal.
3647 test_42a() {
3648         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3649         setup_test42
3650         cancel_lru_locks osc
3651         stop_writeback
3652         sync; sleep 1; sync # just to be safe
3653         BEFOREWRITES=`count_ost_writes`
3654         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3655         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3656         AFTERWRITES=`count_ost_writes`
3657         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3658                 error "$BEFOREWRITES < $AFTERWRITES"
3659         start_writeback
3660 }
3661 run_test 42a "ensure that we don't flush on close"
3662
3663 test_42b() {
3664         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3665         setup_test42
3666         cancel_lru_locks osc
3667         stop_writeback
3668         sync
3669         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3670         BEFOREWRITES=$(count_ost_writes)
3671         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3672         AFTERWRITES=$(count_ost_writes)
3673         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3674                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3675         fi
3676         BEFOREWRITES=$(count_ost_writes)
3677         sync || error "sync: $?"
3678         AFTERWRITES=$(count_ost_writes)
3679         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3680                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3681         fi
3682         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3683         start_writeback
3684         return 0
3685 }
3686 run_test 42b "test destroy of file with cached dirty data ======"
3687
3688 # if these tests just want to test the effect of truncation,
3689 # they have to be very careful.  consider:
3690 # - the first open gets a {0,EOF}PR lock
3691 # - the first write conflicts and gets a {0, count-1}PW
3692 # - the rest of the writes are under {count,EOF}PW
3693 # - the open for truncate tries to match a {0,EOF}PR
3694 #   for the filesize and cancels the PWs.
3695 # any number of fixes (don't get {0,EOF} on open, match
3696 # composite locks, do smarter file size management) fix
3697 # this, but for now we want these tests to verify that
3698 # the cancellation with truncate intent works, so we
3699 # start the file with a full-file pw lock to match against
3700 # until the truncate.
3701 trunc_test() {
3702         test=$1
3703         file=$DIR/$test
3704         offset=$2
3705         cancel_lru_locks osc
3706         stop_writeback
3707         # prime the file with 0,EOF PW to match
3708         touch $file
3709         $TRUNCATE $file 0
3710         sync; sync
3711         # now the real test..
3712         dd if=/dev/zero of=$file bs=1024 count=100
3713         BEFOREWRITES=`count_ost_writes`
3714         $TRUNCATE $file $offset
3715         cancel_lru_locks osc
3716         AFTERWRITES=`count_ost_writes`
3717         start_writeback
3718 }
3719
3720 test_42c() {
3721         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3722         trunc_test 42c 1024
3723         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3724             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3725         rm $file
3726 }
3727 run_test 42c "test partial truncate of file with cached dirty data"
3728
3729 test_42d() {
3730         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3731         trunc_test 42d 0
3732         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3733             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3734         rm $file
3735 }
3736 run_test 42d "test complete truncate of file with cached dirty data"
3737
3738 test_42e() { # bug22074
3739         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3740         local TDIR=$DIR/${tdir}e
3741         local pagesz=$(page_size)
3742         local pages=16 # hardcoded 16 pages, don't change it.
3743         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3744         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3745         local max_dirty_mb
3746         local warmup_files
3747
3748         test_mkdir $DIR/${tdir}e
3749         $SETSTRIPE -c 1 $TDIR
3750         createmany -o $TDIR/f $files
3751
3752         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3753
3754         # we assume that with $OSTCOUNT files, at least one of them will
3755         # be allocated on OST0.
3756         warmup_files=$((OSTCOUNT * max_dirty_mb))
3757         createmany -o $TDIR/w $warmup_files
3758
3759         # write a large amount of data into one file and sync, to get good
3760         # avail_grant number from OST.
3761         for ((i=0; i<$warmup_files; i++)); do
3762                 idx=$($GETSTRIPE -i $TDIR/w$i)
3763                 [ $idx -ne 0 ] && continue
3764                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3765                 break
3766         done
3767         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3768         sync
3769         $LCTL get_param $proc_osc0/cur_dirty_bytes
3770         $LCTL get_param $proc_osc0/cur_grant_bytes
3771
3772         # create as much dirty pages as we can while not to trigger the actual
3773         # RPCs directly. but depends on the env, VFS may trigger flush during this
3774         # period, hopefully we are good.
3775         for ((i=0; i<$warmup_files; i++)); do
3776                 idx=$($GETSTRIPE -i $TDIR/w$i)
3777                 [ $idx -ne 0 ] && continue
3778                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3779         done
3780         $LCTL get_param $proc_osc0/cur_dirty_bytes
3781         $LCTL get_param $proc_osc0/cur_grant_bytes
3782
3783         # perform the real test
3784         $LCTL set_param $proc_osc0/rpc_stats 0
3785         for ((;i<$files; i++)); do
3786                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3787                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3788         done
3789         sync
3790         $LCTL get_param $proc_osc0/rpc_stats
3791
3792         local percent=0
3793         local have_ppr=false
3794         $LCTL get_param $proc_osc0/rpc_stats |
3795                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3796                         # skip lines until we are at the RPC histogram data
3797                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3798                         $have_ppr || continue
3799
3800                         # we only want the percent stat for < 16 pages
3801                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3802
3803                         percent=$((percent + WPCT))
3804                         if [[ $percent -gt 15 ]]; then
3805                                 error "less than 16-pages write RPCs" \
3806                                       "$percent% > 15%"
3807                                 break
3808                         fi
3809                 done
3810         rm -rf $TDIR
3811 }
3812 run_test 42e "verify sub-RPC writes are not done synchronously"
3813
3814 test_43A() { # was test_43
3815         test_mkdir $DIR/$tdir
3816         cp -p /bin/ls $DIR/$tdir/$tfile
3817         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3818         pid=$!
3819         # give multiop a chance to open
3820         sleep 1
3821
3822         $DIR/$tdir/$tfile && error "execute $DIR/$tdir/$tfile succeeded" || true
3823         kill -USR1 $pid
3824 }
3825 run_test 43A "execution of file opened for write should return -ETXTBSY"
3826
3827 test_43a() {
3828         test_mkdir $DIR/$tdir
3829         cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
3830                 cp -p multiop $DIR/$tdir/multiop
3831         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3832                 error "multiop open $TMP/$tfile.junk failed"
3833         MULTIOP_PID=$!
3834         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3835         kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
3836         wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
3837 }
3838 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3839
3840 test_43b() {
3841         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3842         test_mkdir $DIR/$tdir
3843         cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
3844                 cp -p multiop $DIR/$tdir/multiop
3845         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3846                 error "multiop open $TMP/$tfile.junk failed"
3847         MULTIOP_PID=$!
3848         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3849         kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
3850         wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
3851 }
3852 run_test 43b "truncate of file being executed should return -ETXTBSY"
3853
3854 test_43c() {
3855         local testdir="$DIR/$tdir"
3856         test_mkdir $testdir
3857         cp $SHELL $testdir/
3858         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) |
3859                 ( cd $testdir && md5sum -c )
3860 }
3861 run_test 43c "md5sum of copy into lustre"
3862
3863 test_44A() { # was test_44
3864         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
3865         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3866         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3867 }
3868 run_test 44A "zero length read from a sparse stripe"
3869
3870 test_44a() {
3871         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3872                 awk '{ print $2 }')
3873         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3874         [[ $nstripe -gt $OSTCOUNT ]] &&
3875             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3876             return
3877         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3878                 awk '{ print $2 }')
3879         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3880                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3881                         awk '{ print $2 }')
3882         fi
3883
3884         OFFSETS="0 $((stride/2)) $((stride-1))"
3885         for offset in $OFFSETS; do
3886                 for i in $(seq 0 $((nstripe-1))); do
3887                         local GLOBALOFFSETS=""
3888                         # size in Bytes
3889                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3890                         local myfn=$DIR/d44a-$size
3891                         echo "--------writing $myfn at $size"
3892                         ll_sparseness_write $myfn $size ||
3893                                 error "ll_sparseness_write"
3894                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3895                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3896                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3897
3898                         for j in $(seq 0 $((nstripe-1))); do
3899                                 # size in Bytes
3900                                 size=$((((j + $nstripe )*$stride + $offset)))
3901                                 ll_sparseness_write $myfn $size ||
3902                                         error "ll_sparseness_write"
3903                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3904                         done
3905                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3906                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3907                         rm -f $myfn
3908                 done
3909         done
3910 }
3911 run_test 44a "test sparse pwrite ==============================="
3912
3913 dirty_osc_total() {
3914         tot=0
3915         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3916                 tot=$(($tot + $d))
3917         done
3918         echo $tot
3919 }
3920 do_dirty_record() {
3921         before=`dirty_osc_total`
3922         echo executing "\"$*\""
3923         eval $*
3924         after=`dirty_osc_total`
3925         echo before $before, after $after
3926 }
3927 test_45() {
3928         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3929         f="$DIR/f45"
3930         # Obtain grants from OST if it supports it
3931         echo blah > ${f}_grant
3932         stop_writeback
3933         sync
3934         do_dirty_record "echo blah > $f"
3935         [[ $before -eq $after ]] && error "write wasn't cached"
3936         do_dirty_record "> $f"
3937         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3938         do_dirty_record "echo blah > $f"
3939         [[ $before -eq $after ]] && error "write wasn't cached"
3940         do_dirty_record "sync"
3941         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3942         do_dirty_record "echo blah > $f"
3943         [[ $before -eq $after ]] && error "write wasn't cached"
3944         do_dirty_record "cancel_lru_locks osc"
3945         [[ $before -gt $after ]] ||
3946                 error "lock cancellation didn't lower dirty count"
3947         start_writeback
3948 }
3949 run_test 45 "osc io page accounting ============================"
3950
3951 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3952 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3953 # objects offset and an assert hit when an rpc was built with 1023's mapped
3954 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3955 test_46() {
3956         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3957         f="$DIR/f46"
3958         stop_writeback
3959         sync
3960         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3961         sync
3962         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3963         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3964         sync
3965         start_writeback
3966 }
3967 run_test 46 "dirtying a previously written page ================"
3968
3969 # test_47 is removed "Device nodes check" is moved to test_28
3970
3971 test_48a() { # bug 2399
3972         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
3973         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
3974                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly" &&
3975                 return
3976         test_mkdir $DIR/$tdir
3977         cd $DIR/$tdir
3978         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
3979         test_mkdir $DIR/$tdir
3980         touch foo || error "'touch foo' failed after recreating cwd"
3981         test_mkdir bar
3982         touch .foo || error "'touch .foo' failed after recreating cwd"
3983         test_mkdir .bar
3984         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3985         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3986         cd . || error "'cd .' failed after recreating cwd"
3987         mkdir . && error "'mkdir .' worked after recreating cwd"
3988         rmdir . && error "'rmdir .' worked after recreating cwd"
3989         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3990         cd .. || error "'cd ..' failed after recreating cwd"
3991 }
3992 run_test 48a "Access renamed working dir (should return errors)="
3993
3994 test_48b() { # bug 2399
3995         rm -rf $DIR/$tdir
3996         test_mkdir $DIR/$tdir
3997         cd $DIR/$tdir
3998         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3999         touch foo && error "'touch foo' worked after removing cwd"
4000         mkdir foo && error "'mkdir foo' worked after removing cwd"
4001         touch .foo && error "'touch .foo' worked after removing cwd"
4002         mkdir .foo && error "'mkdir .foo' worked after removing cwd"
4003         ls . > /dev/null && error "'ls .' worked after removing cwd"
4004         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
4005         mkdir . && error "'mkdir .' worked after removing cwd"
4006         rmdir . && error "'rmdir .' worked after removing cwd"
4007         ln -s . foo && error "'ln -s .' worked after removing cwd"
4008         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
4009 }
4010 run_test 48b "Access removed working dir (should return errors)="
4011
4012 test_48c() { # bug 2350
4013         #lctl set_param debug=-1
4014         #set -vx
4015         rm -rf $DIR/$tdir
4016         test_mkdir -p $DIR/$tdir/dir
4017         cd $DIR/$tdir/dir
4018         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4019         $TRACE touch foo && error "touch foo worked after removing cwd"
4020         $TRACE mkdir foo && error "'mkdir foo' worked after removing cwd"
4021         touch .foo && error "touch .foo worked after removing cwd"
4022         mkdir .foo && error "mkdir .foo worked after removing cwd"
4023         $TRACE ls . && error "'ls .' worked after removing cwd"
4024         $TRACE ls .. || error "'ls ..' failed after removing cwd"
4025         $TRACE mkdir . && error "'mkdir .' worked after removing cwd"
4026         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
4027         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
4028         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
4029 }
4030 run_test 48c "Access removed working subdir (should return errors)"
4031
4032 test_48d() { # bug 2350
4033         #lctl set_param debug=-1
4034         #set -vx
4035         rm -rf $DIR/$tdir
4036         test_mkdir -p $DIR/$tdir/dir
4037         cd $DIR/$tdir/dir
4038         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4039         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
4040         $TRACE touch foo && error "'touch foo' worked after removing parent"
4041         $TRACE mkdir foo && error "mkdir foo worked after removing parent"
4042         touch .foo && error "'touch .foo' worked after removing parent"
4043         mkdir .foo && error "mkdir .foo worked after removing parent"
4044         $TRACE ls . && error "'ls .' worked after removing parent"
4045         $TRACE ls .. && error "'ls ..' worked after removing parent"
4046         $TRACE mkdir . && error "'mkdir .' worked after removing parent"
4047         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
4048         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
4049         true
4050 }
4051 run_test 48d "Access removed parent subdir (should return errors)"
4052
4053 test_48e() { # bug 4134
4054         #lctl set_param debug=-1
4055         #set -vx
4056         rm -rf $DIR/$tdir
4057         test_mkdir -p $DIR/$tdir/dir
4058         cd $DIR/$tdir/dir
4059         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4060         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
4061         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
4062         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
4063         # On a buggy kernel addition of "touch foo" after cd .. will
4064         # produce kernel oops in lookup_hash_it
4065         touch ../foo && error "'cd ..' worked after recreate parent"
4066         cd $DIR
4067         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
4068 }
4069 run_test 48e "Access to recreated parent subdir (should return errors)"
4070
4071 test_49() { # LU-1030
4072         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4073         remote_ost_nodsh && skip "remote OST with nodsh" && return
4074         # get ost1 size - lustre-OST0000
4075         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
4076                 awk '{ print $4 }')
4077         # write 800M at maximum
4078         [[ $ost1_size -lt 2 ]] && ost1_size=2
4079         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
4080
4081         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
4082         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
4083         local dd_pid=$!
4084
4085         # change max_pages_per_rpc while writing the file
4086         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
4087         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
4088         # loop until dd process exits
4089         while ps ax -opid | grep -wq $dd_pid; do
4090                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
4091                 sleep $((RANDOM % 5 + 1))
4092         done
4093         # restore original max_pages_per_rpc
4094         $LCTL set_param $osc1_mppc=$orig_mppc
4095         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
4096 }
4097 run_test 49 "Change max_pages_per_rpc won't break osc extent"
4098
4099 test_50() {
4100         # bug 1485
4101         test_mkdir $DIR/$tdir
4102         cd $DIR/$tdir
4103         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
4104 }
4105 run_test 50 "special situations: /proc symlinks  ==============="
4106
4107 test_51a() {    # was test_51
4108         # bug 1516 - create an empty entry right after ".." then split dir
4109         test_mkdir -c1 $DIR/$tdir
4110         touch $DIR/$tdir/foo
4111         $MCREATE $DIR/$tdir/bar
4112         rm $DIR/$tdir/foo
4113         createmany -m $DIR/$tdir/longfile 201
4114         FNUM=202
4115         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
4116                 $MCREATE $DIR/$tdir/longfile$FNUM
4117                 FNUM=$(($FNUM + 1))
4118                 echo -n "+"
4119         done
4120         echo
4121         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
4122 }
4123 run_test 51a "special situations: split htree with empty entry =="
4124
4125 cleanup_print_lfs_df () {
4126         trap 0
4127         $LFS df
4128         $LFS df -i
4129 }
4130
4131 test_51b() {
4132         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4133         local dir=$DIR/$tdir
4134
4135         local nrdirs=$((65536 + 100))
4136
4137         # cleanup the directory
4138         rm -fr $dir
4139
4140         test_mkdir -c1 $dir
4141
4142         $LFS df
4143         $LFS df -i
4144         local mdtidx=$(printf "%04x" $($LFS getstripe -M $dir))
4145         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
4146         [[ $numfree -lt $nrdirs ]] &&
4147                 skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
4148                 return
4149
4150         # need to check free space for the directories as well
4151         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
4152         numfree=$(( blkfree / $(fs_inode_ksize) ))
4153         [[ $numfree -lt $nrdirs ]] && skip "not enough blocks ($numfree)" &&
4154                 return
4155
4156         trap cleanup_print_lfsdf EXIT
4157
4158         # create files
4159         createmany -d $dir/d $nrdirs ||
4160                 error "failed to create $nrdirs subdirs in MDT$mdtidx:$dir"
4161
4162         # really created :
4163         nrdirs=$(ls -U $dir | wc -l)
4164
4165         # unlink all but 100 subdirectories, then check it still works
4166         local left=100
4167         local delete=$((nrdirs - left))
4168
4169         $LFS df
4170         $LFS df -i
4171
4172         # for ldiskfs the nlink count should be 1, but this is OSD specific
4173         # and so this is listed for informational purposes only
4174         echo "nlink before: $(stat -c %h $dir), created before: $nrdirs"
4175         unlinkmany -d $dir/d $delete ||
4176                 error "unlink of first $delete subdirs failed"
4177
4178         echo "nlink between: $(stat -c %h $dir)"
4179         local found=$(ls -U $dir | wc -l)
4180         [ $found -ne $left ] &&
4181                 error "can't find subdirs: found only $found, expected $left"
4182
4183         unlinkmany -d $dir/d $delete $left ||
4184                 error "unlink of second $left subdirs failed"
4185         # regardless of whether the backing filesystem tracks nlink accurately
4186         # or not, the nlink count shouldn't be more than "." and ".." here
4187         local after=$(stat -c %h $dir)
4188         [[ $after -gt 2 ]] && error "nlink after: $after > 2" ||
4189                 echo "nlink after: $after"
4190
4191         cleanup_print_lfs_df
4192 }
4193 run_test 51b "exceed 64k subdirectory nlink limit on create, verify unlink"
4194
4195 test_51d() {
4196         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4197         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs" && return
4198         test_mkdir $DIR/$tdir
4199         createmany -o $DIR/$tdir/t- 1000
4200         $LFS getstripe $DIR/$tdir > $TMP/$tfile
4201         for N in $(seq 0 $((OSTCOUNT - 1))); do
4202                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4203                         END { printf("%0.0f", objs) }' $TMP/$tfile)
4204                 OBJS0[$N]=$(grep -A 1 idx $TMP/$tfile | awk -vobjs=0 \
4205                         '($1 == '$N') { objs += 1 } \
4206                         END { printf("%0.0f", objs) }')
4207                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4208         done
4209         unlinkmany $DIR/$tdir/t- 1000
4210
4211         NLAST=0
4212         for N in $(seq 1 $((OSTCOUNT - 1))); do
4213                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4214                         error "OST $N has less objects vs OST $NLAST" \
4215                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4216                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4217                         error "OST $N has less objects vs OST $NLAST" \
4218                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4219
4220                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4221                         error "OST $N has less #0 objects vs OST $NLAST" \
4222                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4223                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4224                         error "OST $N has less #0 objects vs OST $NLAST" \
4225                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4226                 NLAST=$N
4227         done
4228         rm -f $TMP/$tfile
4229 }
4230 run_test 51d "check object distribution"
4231
4232 test_51e() {
4233         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4234                 skip "ldiskfs only test"
4235                 return
4236         fi
4237
4238         test_mkdir -c1 $DIR/$tdir
4239         test_mkdir -c1 $DIR/$tdir/d0
4240
4241         touch $DIR/$tdir/d0/foo
4242         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4243                 error "file exceed 65000 nlink limit!"
4244         unlinkmany $DIR/$tdir/d0/f- 65001
4245         return 0
4246 }
4247 run_test 51e "check file nlink limit"
4248
4249 test_51f() {
4250         test_mkdir $DIR/$tdir
4251
4252         local max=100000
4253         local ulimit_old=$(ulimit -n)
4254         local spare=20 # number of spare fd's for scripts/libraries, etc.
4255         local mdt=$(lfs getstripe -M $DIR/$tdir)
4256         local numfree=$(lfs df -i $DIR/$tdir | awk '/MDT:'$mdt'/ { print $4 }')
4257
4258         echo "MDT$mdt numfree=$numfree, max=$max"
4259         [[ $numfree -gt $max ]] && numfree=$max || numfree=$((numfree * 7 / 8))
4260         if [ $((numfree + spare)) -gt $ulimit_old ]; then
4261                 while ! ulimit -n $((numfree + spare)); do
4262                         numfree=$((numfree * 3 / 4))
4263                 done
4264                 echo "changed ulimit from $ulimit_old to $((numfree + spare))"
4265         else
4266                 echo "left ulimit at $ulimit_old"
4267         fi
4268
4269         createmany -o -k -t 120 $DIR/$tdir/f $numfree ||
4270                 error "create+open $numfree files in $DIR/$tdir failed"
4271         ulimit -n $ulimit_old
4272
4273         # if createmany exits at 120s there will be fewer than $numfree files
4274         unlinkmany $DIR/$tdir/f $numfree || true
4275 }
4276 run_test 51f "check many open files limit"
4277
4278 test_52a() {
4279         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4280         test_mkdir $DIR/$tdir
4281         touch $DIR/$tdir/foo
4282         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4283         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4284         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4285         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4286         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4287                                         error "link worked"
4288         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4289         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4290         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4291                                                      error "lsattr"
4292         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4293         cp -r $DIR/$tdir $TMP/
4294         rm -fr $DIR/$tdir $TMP/$tdir || error "cleanup rm failed"
4295 }
4296 run_test 52a "append-only flag test (should return errors)"
4297
4298 test_52b() {
4299         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4300         test_mkdir $DIR/$tdir
4301         touch $DIR/$tdir/foo
4302         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4303         cat test > $DIR/$tdir/foo && error "cat test worked"
4304         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4305         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4306         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4307                                         error "link worked"
4308         echo foo >> $DIR/$tdir/foo && error "echo worked"
4309         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4310         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4311         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4312         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4313                                                         error "lsattr"
4314         chattr -i $DIR/$tdir/foo || error "chattr failed"
4315
4316         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4317 }
4318 run_test 52b "immutable flag test (should return errors) ======="
4319
4320 test_53() {
4321         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4322         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4323         remote_ost_nodsh && skip "remote OST with nodsh" && return
4324
4325         local param
4326         local param_seq
4327         local ostname
4328         local mds_last
4329         local mds_last_seq
4330         local ost_last
4331         local ost_last_seq
4332         local ost_last_id
4333         local ostnum
4334         local node
4335         local found=false
4336         local support_last_seq=true
4337
4338         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4339                 support_last_seq=false
4340
4341         # only test MDT0000
4342         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4343         local value
4344         for value in $(do_facet $SINGLEMDS \
4345                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4346                 param=$(echo ${value[0]} | cut -d "=" -f1)
4347                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4348
4349                 if $support_last_seq; then
4350                         param_seq=$(echo $param |
4351                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4352                         mds_last_seq=$(do_facet $SINGLEMDS \
4353                                        $LCTL get_param -n $param_seq)
4354                 fi
4355                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4356
4357                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4358                 node=$(facet_active_host ost$((ostnum+1)))
4359                 param="obdfilter.$ostname.last_id"
4360                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4361                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4362                         ost_last_id=$ost_last
4363
4364                         if $support_last_seq; then
4365                                 ost_last_id=$(echo $ost_last |
4366                                               awk -F':' '{print $2}' |
4367                                               sed -e "s/^0x//g")
4368                                 ost_last_seq=$(echo $ost_last |
4369                                                awk -F':' '{print $1}')
4370                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4371                         fi
4372
4373                         if [[ $ost_last_id != $mds_last ]]; then
4374                                 error "$ost_last_id != $mds_last"
4375                         else
4376                                 found=true
4377                                 break
4378                         fi
4379                 done
4380         done
4381         $found || error "can not match last_seq/last_id for $mdtosc"
4382         return 0
4383 }
4384 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4385
4386 test_54a() {
4387         perl -MSocket -e ';' || { skip "no Socket perl module installed" && return; }
4388
4389         $SOCKETSERVER $DIR/socket ||
4390                 error "$SOCKETSERVER $DIR/socket failed: $?"
4391         $SOCKETCLIENT $DIR/socket ||
4392                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4393         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4394 }
4395 run_test 54a "unix domain socket test =========================="
4396
4397 test_54b() {
4398         f="$DIR/f54b"
4399         mknod $f c 1 3
4400         chmod 0666 $f
4401         dd if=/dev/zero of=$f bs=$(page_size) count=1
4402 }
4403 run_test 54b "char device works in lustre ======================"
4404
4405 find_loop_dev() {
4406         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4407         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4408         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4409
4410         for i in $(seq 3 7); do
4411                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4412                 LOOPDEV=$LOOPBASE$i
4413                 LOOPNUM=$i
4414                 break
4415         done
4416 }
4417
4418 cleanup_54c() {
4419         local rc=0
4420         loopdev="$DIR/loop54c"
4421
4422         trap 0
4423         $UMOUNT $DIR/$tdir || rc=$?
4424         losetup -d $loopdev || true
4425         losetup -d $LOOPDEV || true
4426         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4427         return $rc
4428 }
4429
4430 test_54c() {
4431         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4432         loopdev="$DIR/loop54c"
4433
4434         find_loop_dev
4435         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4436         trap cleanup_54c EXIT
4437         mknod $loopdev b 7 $LOOPNUM
4438         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4439         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4440         losetup $loopdev $DIR/$tfile ||
4441                 error "can't set up $loopdev for $DIR/$tfile"
4442         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4443         test_mkdir $DIR/$tdir
4444         mount -t ext2 $loopdev $DIR/$tdir ||
4445                 error "error mounting $loopdev on $DIR/$tdir"
4446         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4447                 error "dd write"
4448         df $DIR/$tdir
4449         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4450                 error "dd read"
4451         cleanup_54c
4452 }
4453 run_test 54c "block device works in lustre ====================="
4454
4455 test_54d() {
4456         f="$DIR/f54d"
4457         string="aaaaaa"
4458         mknod $f p
4459         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4460 }
4461 run_test 54d "fifo device works in lustre ======================"
4462
4463 test_54e() {
4464         f="$DIR/f54e"
4465         string="aaaaaa"
4466         cp -aL /dev/console $f
4467         echo $string > $f || error "echo $string to $f failed"
4468 }
4469 run_test 54e "console/tty device works in lustre ======================"
4470
4471 #The test_55 used to be iopen test and it was removed by bz#24037.
4472 #run_test 55 "check iopen_connect_dentry() ======================"
4473
4474 test_56a() {    # was test_56
4475         rm -rf $DIR/$tdir
4476         $SETSTRIPE -d $DIR
4477         test_mkdir -p $DIR/$tdir/dir
4478         NUMFILES=3
4479         NUMFILESx2=$(($NUMFILES * 2))
4480         for i in $(seq 1 $NUMFILES); do
4481                 touch $DIR/$tdir/file$i
4482                 touch $DIR/$tdir/dir/file$i
4483         done
4484
4485         # test lfs getstripe with --recursive
4486         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4487         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4488                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4489         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4490         [[ $FILENUM -eq $NUMFILES ]] ||
4491                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4492         echo "$GETSTRIPE --recursive passed."
4493
4494         # test lfs getstripe with file instead of dir
4495         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4496         [[ $FILENUM -eq 1 ]] ||
4497                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4498         echo "$GETSTRIPE file1 passed."
4499
4500         #test lfs getstripe with --verbose
4501         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4502                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4503                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4504         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4505                 error "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4506
4507         #test lfs getstripe with -v prints lmm_fid
4508         [[ $($GETSTRIPE -v $DIR/$tdir | grep -c lmm_fid) -eq $NUMFILES ]] ||
4509                 error "$GETSTRIPE -v $DIR/$tdir: want $NUMFILES lmm_fid: lines"
4510         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_fid) -eq 0 ]] ||
4511                 error "$GETSTRIPE $DIR/$tdir: showed lmm_fid"
4512         echo "$GETSTRIPE --verbose passed."
4513
4514         #check for FID information
4515         local fid1=$($GETSTRIPE --fid $DIR/$tdir/file1)
4516         local fid2=$($GETSTRIPE --verbose $DIR/$tdir/file1 |
4517                        awk '/lmm_fid: / { print $2 }')
4518         local fid3=$($LFS path2fid $DIR/$tdir/file1)
4519         [ "$fid1" != "$fid2" ] &&
4520                 error "getstripe --fid $fid1 != getstripe --verbose $fid2"
4521         [ "$fid1" != "$fid3" ] &&
4522                 error "getstripe --fid $fid1 != lfs path2fid $fid3"
4523         echo "$GETSTRIPE --fid passed."
4524
4525         #test lfs getstripe with --obd
4526         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4527                 grep -q "unknown obduuid" ||
4528                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4529
4530         [[ $OSTCOUNT -lt 2 ]] &&
4531                 skip_env "skipping other $GETSTRIPE --obd test" && return
4532
4533         OSTIDX=1
4534         OBDUUID=$(ostuuid_from_index $OSTIDX)
4535         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4536         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4537         [[ $FOUND -eq $FILENUM ]] ||
4538                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4539         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4540                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4541                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4542                 error "$GETSTRIPE --obd: should not show file on other obd"
4543         echo "$GETSTRIPE --obd passed"
4544 }
4545 run_test 56a "check $GETSTRIPE"
4546
4547 test_56b() {
4548         test_mkdir $DIR/$tdir
4549         NUMDIRS=3
4550         for i in $(seq 1 $NUMDIRS); do
4551                 test_mkdir $DIR/$tdir/dir$i
4552         done
4553
4554         # test lfs getdirstripe default mode is non-recursion, which is
4555         # different from lfs getstripe
4556         dircnt=$($LFS getdirstripe $DIR/$tdir | grep -c lmv_stripe_count)
4557         [[ $dircnt -eq 1 ]] ||
4558                 error "$LFS getdirstripe: found $dircnt, not 1"
4559         dircnt=$($LFS getdirstripe --recursive $DIR/$tdir |
4560                 grep -c lmv_stripe_count)
4561         [[ $dircnt -eq $((NUMDIRS + 1)) ]] ||
4562                 error "$LFS getdirstripe --recursive: found $dircnt, \
4563                         not $((NUMDIRS + 1))"
4564 }
4565 run_test 56b "check $LFS getdirstripe"
4566
4567 test_56c() {
4568         local ost_idx=0
4569         local ost_name=$(ostname_from_index $ost_idx)
4570
4571         local old_status=$(ost_dev_status $ost_idx)
4572         [[ -z "$old_status" ]] ||
4573                 { skip_env "OST $ost_name is in $old_status status"; return 0; }
4574
4575         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
4576         sleep_maxage
4577
4578         local new_status=$(ost_dev_status $ost_idx)
4579         [[ "$new_status" = "D" ]] ||
4580                 error "OST $ost_name is in status of '$new_status', not 'D'"
4581
4582         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
4583         sleep_maxage
4584
4585         new_status=$(ost_dev_status $ost_idx)
4586         [[ -z "$new_status" ]] ||
4587                 error "OST $ost_name is in status of '$new_status', not ''"
4588 }
4589 run_test 56c "check 'lfs df' showing device status"
4590
4591 NUMFILES=3
4592 NUMDIRS=3
4593 setup_56() {
4594         local LOCAL_NUMFILES="$1"
4595         local LOCAL_NUMDIRS="$2"
4596         local MKDIR_PARAMS="$3"
4597         local DIR_STRIPE_PARAMS="$4"
4598
4599         if [ ! -d "$TDIR" ] ; then
4600                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4601                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4602                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4603                         touch $TDIR/file$i
4604                 done
4605                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4606                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4607                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4608                                 touch $TDIR/dir$i/file$j
4609                         done
4610                 done
4611         fi
4612 }
4613
4614 setup_56_special() {
4615         LOCAL_NUMFILES=$1
4616         LOCAL_NUMDIRS=$2
4617         setup_56 $1 $2
4618         if [ ! -e "$TDIR/loop1b" ] ; then
4619                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4620                         mknod $TDIR/loop${i}b b 7 $i
4621                         mknod $TDIR/null${i}c c 1 3
4622                         ln -s $TDIR/file1 $TDIR/link${i}l
4623                 done
4624                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4625                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4626                         mknod $TDIR/dir$i/null${i}c c 1 3
4627                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4628                 done
4629         fi
4630 }
4631
4632 test_56g() {
4633         $SETSTRIPE -d $DIR
4634
4635         TDIR=$DIR/${tdir}g
4636         setup_56 $NUMFILES $NUMDIRS
4637
4638         EXPECTED=$(($NUMDIRS + 2))
4639         # test lfs find with -name
4640         for i in $(seq 1 $NUMFILES) ; do
4641                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4642                 [ $NUMS -eq $EXPECTED ] ||
4643                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4644                               "found $NUMS, expected $EXPECTED"
4645         done
4646 }
4647 run_test 56g "check lfs find -name ============================="
4648
4649 test_56h() {
4650         $SETSTRIPE -d $DIR
4651
4652         TDIR=$DIR/${tdir}g
4653         setup_56 $NUMFILES $NUMDIRS
4654
4655         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4656         # test lfs find with ! -name
4657         for i in $(seq 1 $NUMFILES) ; do
4658                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4659                 [ $NUMS -eq $EXPECTED ] ||
4660                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4661                               "found $NUMS, expected $EXPECTED"
4662         done
4663 }
4664 run_test 56h "check lfs find ! -name"
4665
4666 test_56i() {
4667         tdir=${tdir}i
4668         test_mkdir $DIR/$tdir
4669         UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4670         CMD="$LFIND -ost $UUID $DIR/$tdir"
4671         OUT=$($CMD)
4672         [ -z "$OUT" ] || error "'$CMD' returned directory '$OUT'"
4673 }
4674 run_test 56i "check 'lfs find -ost UUID' skips directories"
4675
4676 test_56j() {
4677         TDIR=$DIR/${tdir}g
4678         setup_56_special $NUMFILES $NUMDIRS
4679
4680         EXPECTED=$((NUMDIRS + 1))
4681         CMD="$LFIND -type d $TDIR"
4682         NUMS=$($CMD | wc -l)
4683         [ $NUMS -eq $EXPECTED ] ||
4684                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4685 }
4686 run_test 56j "check lfs find -type d ============================="
4687
4688 test_56k() {
4689         TDIR=$DIR/${tdir}g
4690         setup_56_special $NUMFILES $NUMDIRS
4691
4692         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4693         CMD="$LFIND -type f $TDIR"
4694         NUMS=$($CMD | wc -l)
4695         [ $NUMS -eq $EXPECTED ] ||
4696                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4697 }
4698 run_test 56k "check lfs find -type f ============================="
4699
4700 test_56l() {
4701         TDIR=$DIR/${tdir}g
4702         setup_56_special $NUMFILES $NUMDIRS
4703
4704         EXPECTED=$((NUMDIRS + NUMFILES))
4705         CMD="$LFIND -type b $TDIR"
4706         NUMS=$($CMD | wc -l)
4707         [ $NUMS -eq $EXPECTED ] ||
4708                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4709 }
4710 run_test 56l "check lfs find -type b ============================="
4711
4712 test_56m() {
4713         TDIR=$DIR/${tdir}g
4714         setup_56_special $NUMFILES $NUMDIRS
4715
4716         EXPECTED=$((NUMDIRS + NUMFILES))
4717         CMD="$LFIND -type c $TDIR"
4718         NUMS=$($CMD | wc -l)
4719         [ $NUMS -eq $EXPECTED ] ||
4720                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4721 }
4722 run_test 56m "check lfs find -type c ============================="
4723
4724 test_56n() {
4725         TDIR=$DIR/${tdir}g
4726         setup_56_special $NUMFILES $NUMDIRS
4727
4728         EXPECTED=$((NUMDIRS + NUMFILES))
4729         CMD="$LFIND -type l $TDIR"
4730         NUMS=$($CMD | wc -l)
4731         [ $NUMS -eq $EXPECTED ] ||
4732                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4733 }
4734 run_test 56n "check lfs find -type l ============================="
4735
4736 test_56o() {
4737         TDIR=$DIR/${tdir}o
4738         setup_56 $NUMFILES $NUMDIRS
4739         utime $TDIR/file1 > /dev/null || error "utime (1)"
4740         utime $TDIR/file2 > /dev/null || error "utime (2)"
4741         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4742         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4743         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4744         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4745
4746         EXPECTED=4
4747         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4748         [ $NUMS -eq $EXPECTED ] || \
4749                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4750
4751         EXPECTED=12
4752         CMD="$LFIND -mtime 0 $TDIR"
4753         NUMS=$($CMD | wc -l)
4754         [ $NUMS -eq $EXPECTED ] ||
4755                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4756 }
4757 run_test 56o "check lfs find -mtime for old files =========================="
4758
4759 test_56p() {
4760         [ $RUNAS_ID -eq $UID ] &&
4761                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4762
4763         TDIR=$DIR/${tdir}p
4764         setup_56 $NUMFILES $NUMDIRS
4765
4766         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4767         EXPECTED=$NUMFILES
4768         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4769         NUMS=$($CMD | wc -l)
4770         [ $NUMS -eq $EXPECTED ] || \
4771                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4772
4773         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4774         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4775         NUMS=$($CMD | wc -l)
4776         [ $NUMS -eq $EXPECTED ] || \
4777                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4778 }
4779 run_test 56p "check lfs find -uid and ! -uid ==============================="
4780
4781 test_56q() {
4782         [ $RUNAS_ID -eq $UID ] &&
4783                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4784
4785         TDIR=$DIR/${tdir}q
4786         setup_56 $NUMFILES $NUMDIRS
4787
4788         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4789
4790         EXPECTED=$NUMFILES
4791         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4792         NUMS=$($CMD | wc -l)
4793         [ $NUMS -eq $EXPECTED ] ||
4794                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4795
4796         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4797         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4798         NUMS=$($CMD | wc -l)
4799         [ $NUMS -eq $EXPECTED ] ||
4800                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4801 }
4802 run_test 56q "check lfs find -gid and ! -gid ==============================="
4803
4804 test_56r() {
4805         TDIR=$DIR/${tdir}r
4806         setup_56 $NUMFILES $NUMDIRS
4807
4808         EXPECTED=12
4809         CMD="$LFIND -size 0 -type f $TDIR"
4810         NUMS=$($CMD | wc -l)
4811         [ $NUMS -eq $EXPECTED ] ||
4812                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4813         EXPECTED=0
4814         CMD="$LFIND ! -size 0 -type f $TDIR"
4815         NUMS=$($CMD | wc -l)
4816         [ $NUMS -eq $EXPECTED ] ||
4817                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4818         echo "test" > $TDIR/$tfile
4819         echo "test2" > $TDIR/$tfile.2 && sync
4820         EXPECTED=1
4821         CMD="$LFIND -size 5 -type f $TDIR"
4822         NUMS=$($CMD | wc -l)
4823         [ $NUMS -eq $EXPECTED ] ||
4824                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4825         EXPECTED=1
4826         CMD="$LFIND -size +5 -type f $TDIR"
4827         NUMS=$($CMD | wc -l)
4828         [ $NUMS -eq $EXPECTED ] ||
4829                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4830         EXPECTED=2
4831         CMD="$LFIND -size +0 -type f $TDIR"
4832         NUMS=$($CMD | wc -l)
4833         [ $NUMS -eq $EXPECTED ] ||
4834                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4835         EXPECTED=2
4836         CMD="$LFIND ! -size -5 -type f $TDIR"
4837         NUMS=$($CMD | wc -l)
4838         [ $NUMS -eq $EXPECTED ] ||
4839                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4840         EXPECTED=12
4841         CMD="$LFIND -size -5 -type f $TDIR"
4842         NUMS=$($CMD | wc -l)
4843         [ $NUMS -eq $EXPECTED ] ||
4844                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4845 }
4846 run_test 56r "check lfs find -size works =========================="
4847
4848 test_56s() { # LU-611
4849         TDIR=$DIR/${tdir}s
4850
4851         #LU-9369
4852         setup_56 0 $NUMDIRS
4853         for i in $(seq 1 $NUMDIRS); do
4854                 $SETSTRIPE -c $((OSTCOUNT + 1)) $TDIR/dir$i/$tfile
4855         done
4856         EXPECTED=$NUMDIRS
4857         CMD="$LFIND -c $OSTCOUNT $TDIR"
4858         NUMS=$($CMD | wc -l)
4859         [ $NUMS -eq $EXPECTED ] || {
4860                 $GETSTRIPE -R $TDIR
4861                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4862         }
4863         rm -rf $TDIR
4864
4865         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4866         if [[ $OSTCOUNT -gt 1 ]]; then
4867                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4868                 ONESTRIPE=4
4869                 EXTRA=4
4870         else
4871                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4872                 EXTRA=0
4873         fi
4874
4875         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4876         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4877         NUMS=$($CMD | wc -l)
4878         [ $NUMS -eq $EXPECTED ] || {
4879                 $GETSTRIPE -R $TDIR
4880                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4881         }
4882
4883         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4884         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4885         NUMS=$($CMD | wc -l)
4886         [ $NUMS -eq $EXPECTED ] || {
4887                 $GETSTRIPE -R $TDIR
4888                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4889         }
4890
4891         EXPECTED=$ONESTRIPE
4892         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4893         NUMS=$($CMD | wc -l)
4894         [ $NUMS -eq $EXPECTED ] || {
4895                 $GETSTRIPE -R $TDIR
4896                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4897         }
4898
4899         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4900         NUMS=$($CMD | wc -l)
4901         [ $NUMS -eq $EXPECTED ] || {
4902                 $GETSTRIPE -R $TDIR
4903                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4904         }
4905
4906         EXPECTED=0
4907         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4908         NUMS=$($CMD | wc -l)
4909         [ $NUMS -eq $EXPECTED ] || {
4910                 $GETSTRIPE -R $TDIR
4911                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4912         }
4913 }
4914 run_test 56s "check lfs find -stripe-count works"
4915
4916 test_56t() { # LU-611
4917         TDIR=$DIR/${tdir}t
4918
4919         #LU-9369
4920         setup_56 0 $NUMDIRS
4921         for i in $(seq 1 $NUMDIRS); do
4922                 $SETSTRIPE -S 4M $TDIR/dir$i/$tfile
4923         done
4924         EXPECTED=$NUMDIRS
4925         CMD="$LFIND -S 4M $TDIR"
4926         NUMS=$($CMD | wc -l)
4927         [ $NUMS -eq $EXPECTED ] || {
4928                 $GETSTRIPE -R $TDIR
4929                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4930         }
4931         rm -rf $TDIR
4932
4933         setup_56 $NUMFILES $NUMDIRS "--stripe-size 512k"
4934
4935         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4936
4937         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4938         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4939         NUMS=$($CMD | wc -l)
4940         [ $NUMS -eq $EXPECTED ] ||
4941                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4942
4943         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4944         NUMS=$($CMD | wc -l)
4945         [ $NUMS -eq $EXPECTED ] ||
4946                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4947
4948         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4949         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4950         NUMS=$($CMD | wc -l)
4951         [ $NUMS -eq $EXPECTED ] ||
4952                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4953
4954         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4955         NUMS=$($CMD | wc -l)
4956         [ $NUMS -eq $EXPECTED ] ||
4957                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4958
4959         EXPECTED=4
4960         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4961         NUMS=$($CMD | wc -l)
4962         [ $NUMS -eq $EXPECTED ] ||
4963                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4964
4965         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4966         NUMS=$($CMD | wc -l)
4967         [ $NUMS -eq $EXPECTED ] ||
4968                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4969
4970         EXPECTED=0
4971         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4972         NUMS=$($CMD | wc -l)
4973         [ $NUMS -eq $EXPECTED ] ||
4974                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4975 }
4976 run_test 56t "check lfs find -stripe-size works"
4977
4978 test_56u() { # LU-611
4979         TDIR=$DIR/${tdir}u
4980         setup_56 $NUMFILES $NUMDIRS "-i 0"
4981
4982         if [[ $OSTCOUNT -gt 1 ]]; then
4983                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4984                 ONESTRIPE=4
4985         else
4986                 ONESTRIPE=0
4987         fi
4988
4989         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4990         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4991         NUMS=$($CMD | wc -l)
4992         [ $NUMS -eq $EXPECTED ] ||
4993                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4994
4995         EXPECTED=$ONESTRIPE
4996         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4997         NUMS=$($CMD | wc -l)
4998         [ $NUMS -eq $EXPECTED ] ||
4999                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5000
5001         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
5002         NUMS=$($CMD | wc -l)
5003         [ $NUMS -eq $EXPECTED ] ||
5004                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5005
5006         EXPECTED=0
5007         # This should produce an error and not return any files
5008         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
5009         NUMS=$($CMD 2>/dev/null | wc -l)
5010         [ $NUMS -eq $EXPECTED ] ||
5011                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5012
5013         if [[ $OSTCOUNT -gt 1 ]]; then
5014                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
5015                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
5016                 NUMS=$($CMD | wc -l)
5017                 [ $NUMS -eq $EXPECTED ] ||
5018                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5019         fi
5020 }
5021 run_test 56u "check lfs find -stripe-index works"
5022
5023 test_56v() {
5024     local MDT_IDX=0
5025
5026     TDIR=$DIR/${tdir}v
5027     rm -rf $TDIR
5028     setup_56 $NUMFILES $NUMDIRS
5029
5030     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
5031     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
5032
5033     for file in $($LFIND -mdt $UUID $TDIR); do
5034         file_mdt_idx=$($GETSTRIPE -M $file)
5035         [ $file_mdt_idx -eq $MDT_IDX ] ||
5036             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
5037     done
5038 }
5039 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
5040
5041 test_56w() {
5042         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5043         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5044         TDIR=$DIR/${tdir}w
5045
5046         rm -rf $TDIR || error "remove $TDIR failed"
5047         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
5048
5049         local stripe_size
5050         stripe_size=$($GETSTRIPE -S -d $TDIR) ||
5051                 error "$GETSTRIPE -S -d $TDIR failed"
5052         stripe_size=${stripe_size%% *}
5053
5054         local file_size=$((stripe_size * OSTCOUNT))
5055         local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
5056         local required_space=$((file_num * file_size))
5057
5058         local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
5059                            head -n1)
5060         [[ $free_space -le $((required_space / 1024)) ]] &&
5061                 skip_env "need $required_space bytes, have $free_space KB" &&
5062                 return
5063
5064         local dd_bs=65536
5065         local dd_count=$((file_size / dd_bs))
5066
5067         # write data into the files
5068         local i
5069         local j
5070         local file
5071         for i in $(seq 1 $NUMFILES); do
5072                 file=$TDIR/file$i
5073                 yes | dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
5074                         error "write data into $file failed"
5075         done
5076         for i in $(seq 1 $NUMDIRS); do
5077                 for j in $(seq 1 $NUMFILES); do
5078                         file=$TDIR/dir$i/file$j
5079                         yes|dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
5080                                 error "write data into $file failed"
5081                 done
5082         done
5083
5084         # $LFS_MIGRATE will fail if hard link migration is unsupported
5085         if [[ $(lustre_version_code mds1) -gt $(version_code 2.5.55) ]]; then
5086                 createmany -l$TDIR/dir1/file1 $TDIR/dir1/link 200 ||
5087                         error "creating links to $TDIR/dir1/file1 failed"
5088         fi
5089
5090         local expected=-1
5091         [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
5092
5093         # lfs_migrate file
5094         local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
5095         echo "$cmd"
5096         eval $cmd || error "$cmd failed"
5097
5098         check_stripe_count $TDIR/file1 $expected
5099
5100         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
5101         then
5102                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
5103                 # OST 1 if it is on OST 0. This file is small enough to
5104                 # be on only one stripe.
5105                 file=$TDIR/migr_1_ost
5106                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
5107                         error "write data into $file failed"
5108                 local obdidx=$($LFS getstripe -i $file)
5109                 local oldmd5=$(md5sum $file)
5110                 local newobdidx=0
5111                 [[ $obdidx -eq 0 ]] && newobdidx=1
5112                 cmd="$LFS migrate -i $newobdidx $file"
5113                 echo $cmd
5114                 eval $cmd || error "$cmd failed"
5115                 local realobdix=$($LFS getstripe -i $file)
5116                 local newmd5=$(md5sum $file)
5117                 [[ $newobdidx -ne $realobdix ]] &&
5118                         error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
5119                 [[ "$oldmd5" != "$newmd5" ]] &&
5120                         error "md5sum differ: $oldmd5, $newmd5"
5121         fi
5122
5123     # lfs_migrate dir
5124     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
5125     echo "$cmd"
5126     eval $cmd || error "$cmd failed"
5127
5128     for j in $(seq 1 $NUMFILES); do
5129         check_stripe_count $TDIR/dir1/file$j $expected
5130     done
5131
5132     # lfs_migrate works with lfs find
5133     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
5134          $LFS_MIGRATE -y -c $expected"
5135     echo "$cmd"
5136     eval $cmd || error "$cmd failed"
5137
5138     for i in $(seq 2 $NUMFILES); do
5139         check_stripe_count $TDIR/file$i $expected
5140     done
5141     for i in $(seq 2 $NUMDIRS); do
5142         for j in $(seq 1 $NUMFILES); do
5143             check_stripe_count $TDIR/dir$i/file$j $expected
5144         done
5145     done
5146 }
5147 run_test 56w "check lfs_migrate -c stripe_count works"
5148
5149 test_56x() {
5150         check_swap_layouts_support && return 0
5151         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5152
5153         local dir0=$DIR/$tdir
5154         local ref1=/etc/passwd
5155         local file1=$dir0/file1
5156
5157         test_mkdir $dir0 || error "creating dir $dir0"
5158         $LFS setstripe -c 2 $file1
5159         cp $ref1 $file1
5160         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
5161         stripe=$($LFS getstripe -c $file1)
5162         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5163         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5164
5165         # clean up
5166         rm -f $file1
5167 }
5168 run_test 56x "lfs migration support"
5169
5170 test_56xa() {
5171         check_swap_layouts_support && return 0
5172         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5173
5174         local dir0=$DIR/$tdir/$testnum
5175         test_mkdir -p $dir0
5176
5177         local ref1=/etc/passwd
5178         local file1=$dir0/file1
5179
5180         $LFS setstripe -c 2 $file1
5181         cp $ref1 $file1
5182         $LFS migrate --block -c 1 $file1 || error "migrate failed rc = $?"
5183         local stripe=$($LFS getstripe -c $file1)
5184         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5185         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5186
5187         # clean up
5188         rm -f $file1
5189 }
5190 run_test 56xa "lfs migration --block support"
5191
5192 check_migrate_links() {
5193         local dir="$1"
5194         local file1="$dir/file1"
5195         local begin="$2"
5196         local count="$3"
5197         local total_count=$(($begin + $count - 1))
5198         local symlink_count=10
5199         local uniq_count=10
5200
5201         if [ ! -f "$file1" ]; then
5202                 echo -n "creating initial file..."
5203                 $LFS setstripe -c 1 -S "512k" "$file1" ||
5204                         error "cannot setstripe initial file"
5205                 echo "done"
5206
5207                 echo -n "creating symlinks..."
5208                 for s in $(seq 1 $symlink_count); do
5209                         ln -s "$file1" "$dir/slink$s" ||
5210                                 error "cannot create symlinks"
5211                 done
5212                 echo "done"
5213
5214                 echo -n "creating nonlinked files..."
5215                 createmany -o "$dir/uniq" 1 10 &> /dev/null ||
5216                         error "cannot create nonlinked files"
5217                 echo "done"
5218         fi
5219
5220         # create hard links
5221         if [ ! -f "$dir/file$total_count" ]; then
5222                 echo -n "creating hard links $begin:$total_count..."
5223                 createmany -l"$file1" "$dir/file" "$begin" "$count" &>  \
5224                         /dev/null || error "cannot create hard links"
5225                 echo "done"
5226         fi
5227
5228         echo -n "checking number of hard links listed in xattrs..."
5229         local fid=$($LFS getstripe -F "$file1")
5230         local paths=($($LFS fid2path "$MOUNT" "$fid" 2> /dev/null))
5231
5232         echo "${#paths[*]}"
5233         if [ ${#paths[*]} -lt $total_count -a "$begin" -eq 2  ]; then
5234                         echo "hard link list has unexpected size, skipping test"
5235                         return 0
5236         fi
5237         if [ ${#paths[*]} -ge $total_count -a "$begin" -ne 2  ]; then
5238                         error "link names should exceed xattrs size"
5239         fi
5240
5241         echo -n "migrating files..."
5242         local migrate_out=$($LFS_MIGRATE -y -S '1m' $dir)
5243         local rc=$?
5244         [ $rc -eq 0 ] || error "migrate failed rc = $rc"
5245         echo "done"
5246
5247         # make sure all links have been properly migrated
5248         echo -n "verifying files..."
5249         fid=$($LFS getstripe -F "$file1") ||
5250                 error "cannot get fid for file $file1"
5251         for i in $(seq 2 $total_count); do
5252                 local fid2=$($LFS getstripe -F $dir/file$i)
5253                 [ "$fid2" == "$fid" ] ||
5254                         error "migrated hard link has mismatched FID"
5255         done
5256
5257         # make sure hard links were properly detected, and migration was
5258         # performed only once for the entire link set; nonlinked files should
5259         # also be migrated
5260         local actual=$(grep -c 'done migrate' <<< "$migrate_out")
5261         local expected=$(($uniq_count + 1))
5262         [ "$actual" -eq  "$expected" ] ||
5263                 error "hard links individually migrated ($actual != $expected)"
5264
5265         # make sure the correct number of hard links are present
5266         local hardlinks=$(stat -c '%h' "$file1")
5267         [ $hardlinks -eq $total_count ] ||
5268                 error "num hard links $hardlinks != $total_count"
5269         echo "done"
5270
5271         return 0
5272 }
5273
5274 test_56xb() {
5275         local dir0="$DIR/$tdir"
5276
5277         test_mkdir "$dir0" || error "cannot create dir $dir0"
5278
5279         echo "testing lfs migrate mode when all links fit within xattrs"
5280         LFS_MIGRATE_RSYNC=false check_migrate_links "$dir0" 2 99
5281
5282         echo "testing rsync mode when all links fit within xattrs"
5283         LFS_MIGRATE_RSYNC=true check_migrate_links "$dir0" 2 99
5284
5285         echo "testing lfs migrate mode when all links do not fit within xattrs"
5286         LFS_MIGRATE_RSYNC=false check_migrate_links "$dir0" 101 100
5287
5288         echo "testing rsync mode when all links do not fit within xattrs"
5289         LFS_MIGRATE_RSYNC=true check_migrate_links "$dir0" 101 100
5290
5291         # clean up
5292         rm -rf $dir0
5293 }
5294 run_test 56xb "lfs migration hard link support"
5295
5296 test_56y() {
5297         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
5298                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
5299                 return
5300
5301         local res=""
5302         local dir0=$DIR/$tdir/$testnum
5303         test_mkdir -p $dir0
5304         local f1=$dir0/file1
5305         local f2=$dir0/file2
5306
5307         touch $f1 || error "creating std file $f1"
5308         $MULTIOP $f2 H2c || error "creating released file $f2"
5309
5310         # a directory can be raid0, so ask only for files
5311         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
5312         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
5313
5314         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
5315         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
5316
5317         # only files can be released, so no need to force file search
5318         res=$($LFIND $dir0 -L released)
5319         [[ $res == $f2 ]] || error "search released: found $res != $f2"
5320
5321         res=$($LFIND $dir0 \! -L released)
5322         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
5323
5324 }
5325 run_test 56y "lfs find -L raid0|released"
5326
5327 test_56z() { # LU-4824
5328         # This checks to make sure 'lfs find' continues after errors
5329         # There are two classes of errors that should be caught:
5330         # - If multiple paths are provided, all should be searched even if one
5331         #   errors out
5332         # - If errors are encountered during the search, it should not terminate
5333         #   early
5334         local i
5335         test_mkdir $DIR/$tdir
5336         for i in d{0..9}; do
5337                 test_mkdir $DIR/$tdir/$i
5338         done
5339         touch $DIR/$tdir/d{0..9}/$tfile
5340         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
5341                 error "$LFS find did not return an error"
5342         # Make a directory unsearchable. This should NOT be the last entry in
5343         # directory order.  Arbitrarily pick the 6th entry
5344         chmod 700 $($LFS find $DIR/$tdir -type d | sed '6!d')
5345         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
5346         # The user should be able to see 10 directories and 9 files
5347         [ $count == 19 ] || error "$LFS find did not continue after error"
5348 }
5349 run_test 56z "lfs find should continue after an error"
5350
5351 test_56aa() { # LU-5937
5352         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5353
5354         mkdir $DIR/$tdir
5355         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
5356
5357         createmany -o $DIR/$tdir/striped_dir/${tfile}- 1024
5358         local dirs=$(lfs find --size +8k $DIR/$tdir/)
5359
5360         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5361 }
5362 run_test 56aa "lfs find --size under striped dir"
5363
5364 test_57a() {
5365         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5366         # note test will not do anything if MDS is not local
5367         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5368                 skip "ldiskfs only test"
5369                 return
5370         fi
5371
5372         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5373         local MNTDEV="osd*.*MDT*.mntdev"
5374         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
5375         [ -z "$DEV" ] && error "can't access $MNTDEV"
5376         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
5377                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
5378                         error "can't access $DEV"
5379                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
5380                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
5381                 rm $TMP/t57a.dump
5382         done
5383 }
5384 run_test 57a "verify MDS filesystem created with large inodes =="
5385
5386 test_57b() {
5387         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5388         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5389                 skip "ldiskfs only test"
5390                 return
5391         fi
5392
5393         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5394         local dir=$DIR/$tdir
5395
5396         local FILECOUNT=100
5397         local FILE1=$dir/f1
5398         local FILEN=$dir/f$FILECOUNT
5399
5400         rm -rf $dir || error "removing $dir"
5401         test_mkdir -c1 $dir
5402         local mdtidx=$($LFS getstripe -M $dir)
5403         local mdtname=MDT$(printf %04x $mdtidx)
5404         local facet=mds$((mdtidx + 1))
5405
5406         echo "mcreating $FILECOUNT files"
5407         createmany -m $dir/f 1 $FILECOUNT || \
5408                 error "creating files in $dir"
5409
5410         # verify that files do not have EAs yet
5411         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5412         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5413
5414         sync
5415         sleep 1
5416         df $dir  #make sure we get new statfs data
5417         local MDSFREE=$(do_facet $facet \
5418                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5419         local MDCFREE=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5420         echo "opening files to create objects/EAs"
5421         local FILE
5422         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5423                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5424         done
5425
5426         # verify that files have EAs now
5427         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5428         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5429
5430         sleep 1  #make sure we get new statfs data
5431         df $dir
5432         local MDSFREE2=$(do_facet $facet \
5433                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5434         local MDCFREE2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5435         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5436                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5437                         error "MDC before $MDCFREE != after $MDCFREE2"
5438                 else
5439                         echo "MDC before $MDCFREE != after $MDCFREE2"
5440                         echo "unable to confirm if MDS has large inodes"
5441                 fi
5442         fi
5443         rm -rf $dir
5444 }
5445 run_test 57b "default LOV EAs are stored inside large inodes ==="
5446
5447 test_58() {
5448         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5449         [ -z "$(which wiretest 2>/dev/null)" ] &&
5450                         skip_env "could not find wiretest" && return
5451         wiretest
5452 }
5453 run_test 58 "verify cross-platform wire constants =============="
5454
5455 test_59() {
5456         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5457         echo "touch 130 files"
5458         createmany -o $DIR/f59- 130
5459         echo "rm 130 files"
5460         unlinkmany $DIR/f59- 130
5461         sync
5462         # wait for commitment of removal
5463         wait_delete_completed
5464 }
5465 run_test 59 "verify cancellation of llog records async ========="
5466
5467 TEST60_HEAD="test_60 run $RANDOM"
5468 test_60a() {
5469         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5470         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5471         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5472                 do_facet mgs "! ls run-llog.sh &> /dev/null" &&
5473                         skip_env "missing subtest run-llog.sh" && return
5474
5475         log "$TEST60_HEAD - from kernel mode"
5476         do_facet mgs "$LCTL set_param debug=warning; $LCTL dk > /dev/null"
5477         do_facet mgs "sh run-llog.sh" || error "run-llog.sh failed"
5478         do_facet mgs $LCTL dk > $TMP/$tfile
5479
5480         # LU-6388: test llog_reader
5481         local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5482         llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5483         [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5484                         skip_env "missing llog_reader" && return
5485         local fstype=$(facet_fstype mgs)
5486         [ $fstype != ldiskfs -a $fstype != zfs ] &&
5487                 skip_env "Only for ldiskfs or zfs type mgs" && return
5488
5489         local mntpt=$(facet_mntpt mgs)
5490         local mgsdev=$(mgsdevname 1)
5491         local fid_list
5492         local fid
5493         local rec_list
5494         local rec
5495         local rec_type
5496         local obj_file
5497         local path
5498         local seq
5499         local oid
5500         local pass=true
5501
5502         #get fid and record list
5503         fid_list=($(awk '/9_sub.*record/ { print $NF }' /$TMP/$tfile |
5504                 tail -n 4))
5505         rec_list=($(awk '/9_sub.*record/ { print $((NF-3)) }' /$TMP/$tfile |
5506                 tail -n 4))
5507         #remount mgs as ldiskfs or zfs type
5508         stop mgs || error "stop mgs failed"
5509         mount_fstype mgs || error "remount mgs failed"
5510         for ((i = 0; i < ${#fid_list[@]}; i++)); do
5511                 fid=${fid_list[i]}
5512                 rec=${rec_list[i]}
5513                 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
5514                 oid=$(echo $fid | awk -F ':' '{ print $2 }' | sed -e "s/^0x//g")
5515                 oid=$((16#$oid))
5516
5517                 case $fstype in
5518                         ldiskfs )
5519                                 obj_file=$mntpt/O/$seq/d$((oid%32))/$oid ;;
5520                         zfs )
5521                                 obj_file=$mntpt/oi.$(($((16#$seq))&127))/$fid ;;
5522                 esac
5523                 echo "obj_file is $obj_file"
5524                 do_facet mgs $llog_reader $obj_file
5525
5526                 rec_type=$(do_facet mgs $llog_reader $obj_file | grep "type=" |
5527                         awk '{ print $3 }' | sed -e "s/^type=//g")
5528                 if [ $rec_type != $rec ]; then
5529                         echo "FAILED test_60a wrong record type $rec_type," \
5530                               "should be $rec"
5531                         pass=false
5532                         break
5533                 fi
5534
5535                 #check obj path if record type is LLOG_LOGID_MAGIC
5536                 if [ "$rec" == "1064553b" ]; then
5537                         path=$(do_facet mgs $llog_reader $obj_file |
5538                                 grep "path=" | awk '{ print $NF }' |
5539                                 sed -e "s/^path=//g")
5540                         if [ $obj_file != $mntpt/$path ]; then
5541                                 echo "FAILED test_60a wrong obj path" \
5542                                       "$montpt/$path, should be $obj_file"
5543                                 pass=false
5544                                 break
5545                         fi
5546                 fi
5547         done
5548         rm -f $TMP/$tfile
5549         #restart mgs before "error", otherwise it will block the next test
5550         stop mgs || error "stop mgs failed"
5551         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
5552         $pass || error "test failed, see FAILED test_60a messages for specifics"
5553 }
5554 run_test 60a "llog_test run from kernel module and test llog_reader"
5555
5556 test_60aa() {
5557         # test old logid format
5558         if [ $(lustre_version_code mgs) -le $(version_code 3.1.53) ]; then
5559                 do_facet mgs $LCTL dl | grep MGS
5560                 do_facet mgs "$LCTL --device %MGS llog_print \\\\\\\$$FSNAME-client" ||
5561                         error "old llog_print failed"
5562         fi
5563
5564         # test new logid format
5565         if [ $(lustre_version_code mgs) -ge $(version_code 2.9.53) ]; then
5566                 do_facet mgs "$LCTL --device MGS llog_print $FSNAME-client" ||
5567                         error "new llog_print failed"
5568         fi
5569 }
5570 run_test 60aa "llog_print works with FIDs and simple names"
5571
5572 test_60b() { # bug 6411
5573         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5574         dmesg > $DIR/$tfile
5575         LLOG_COUNT=$(dmesg | awk "/$TEST60_HEAD/ { marker = 1; from_marker = 0; }
5576                                 /llog.test/ {
5577                                         if (marker)
5578                                                 from_marker++
5579                                         from_begin++
5580                                 }
5581                                 END {
5582                                         if (marker)
5583                                                 print from_marker
5584                                         else
5585                                                 print from_begin
5586                                 }")
5587         [[ $LLOG_COUNT -gt 100 ]] &&
5588                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5589 }
5590 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5591
5592 test_60c() {
5593         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5594         echo "create 5000 files"
5595         createmany -o $DIR/f60c- 5000
5596 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5597         lctl set_param fail_loc=0x80000137
5598         unlinkmany $DIR/f60c- 5000
5599         lctl set_param fail_loc=0
5600 }
5601 run_test 60c "unlink file when mds full"
5602
5603 test_60d() {
5604         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5605         SAVEPRINTK=$(lctl get_param -n printk)
5606
5607         # verify "lctl mark" is even working"
5608         MESSAGE="test message ID $RANDOM $$"
5609         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5610         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5611
5612         lctl set_param printk=0 || error "set lnet.printk failed"
5613         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5614         MESSAGE="new test message ID $RANDOM $$"
5615         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5616         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5617         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5618
5619         lctl set_param -n printk="$SAVEPRINTK"
5620 }
5621 run_test 60d "test printk console message masking"
5622
5623 test_60e() {
5624         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5625         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5626         touch $DIR/$tfile
5627 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED2  0x15b
5628         do_facet mds1 lctl set_param fail_loc=0x15b
5629         rm $DIR/$tfile
5630 }
5631 run_test 60e "no space while new llog is being created"
5632
5633 test_61() {
5634         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5635         f="$DIR/f61"
5636         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5637         cancel_lru_locks osc
5638         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5639         sync
5640 }
5641 run_test 61 "mmap() writes don't make sync hang ================"
5642
5643 # bug 2330 - insufficient obd_match error checking causes LBUG
5644 test_62() {
5645         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5646         f="$DIR/f62"
5647         echo foo > $f
5648         cancel_lru_locks osc
5649         lctl set_param fail_loc=0x405
5650         cat $f && error "cat succeeded, expect -EIO"
5651         lctl set_param fail_loc=0
5652 }
5653 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5654 # match every page all of the time.
5655 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5656
5657 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5658 # Though this test is irrelevant anymore, it helped to reveal some
5659 # other grant bugs (LU-4482), let's keep it.
5660 test_63a() {   # was test_63
5661         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5662         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5663         for i in `seq 10` ; do
5664                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5665                 sleep 5
5666                 kill $!
5667                 sleep 1
5668         done
5669
5670         rm -f $DIR/f63 || true
5671 }
5672 run_test 63a "Verify oig_wait interruption does not crash ======="
5673
5674 # bug 2248 - async write errors didn't return to application on sync
5675 # bug 3677 - async write errors left page locked
5676 test_63b() {
5677         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5678         debugsave
5679         lctl set_param debug=-1
5680
5681         # ensure we have a grant to do async writes
5682         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5683         rm $DIR/$tfile
5684
5685         sync    # sync lest earlier test intercept the fail_loc
5686
5687         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5688         lctl set_param fail_loc=0x80000406
5689         $MULTIOP $DIR/$tfile Owy && \
5690                 error "sync didn't return ENOMEM"
5691         sync; sleep 2; sync     # do a real sync this time to flush page
5692         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5693                 error "locked page left in cache after async error" || true
5694         debugrestore
5695 }
5696 run_test 63b "async write errors should be returned to fsync ==="
5697
5698 test_64a () {
5699         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5700         df $DIR
5701         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5702 }
5703 run_test 64a "verify filter grant calculations (in kernel) ====="
5704
5705 test_64b () {
5706         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5707         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5708 }
5709 run_test 64b "check out-of-space detection on client"
5710
5711 test_64c() {
5712         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5713 }
5714 run_test 64c "verify grant shrink"
5715
5716 # bug 1414 - set/get directories' stripe info
5717 test_65a() {
5718         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5719         test_mkdir $DIR/$tdir
5720         touch $DIR/$tdir/f1
5721         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5722 }
5723 run_test 65a "directory with no stripe info"
5724
5725 test_65b() {
5726         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5727         test_mkdir $DIR/$tdir
5728         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5729
5730         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5731                                                 error "setstripe"
5732         touch $DIR/$tdir/f2
5733         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5734 }
5735 run_test 65b "directory setstripe -S stripe_size*2 -i 0 -c 1"
5736
5737 test_65c() {
5738         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5739         [ $OSTCOUNT -lt 2 ] && skip "need at least 2 OSTs" && return
5740         test_mkdir $DIR/$tdir
5741         local stripesize=$($GETSTRIPE -S $DIR/$tdir)
5742
5743         $LFS setstripe -S $((stripesize * 4)) -i 1 \
5744                 -c $((OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5745         touch $DIR/$tdir/f3
5746         $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5747 }
5748 run_test 65c "directory setstripe -S stripe_size*4 -i 1 -c $((OSTCOUNT-1))"
5749
5750 test_65d() {
5751         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5752         test_mkdir $DIR/$tdir
5753         local STRIPECOUNT=$($GETSTRIPE -c $DIR/$tdir)
5754         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5755
5756         if [[ $STRIPECOUNT -le 0 ]]; then
5757                 sc=1
5758         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5759 #LOV_MAX_STRIPE_COUNT is 2000
5760                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5761         else
5762                 sc=$(($STRIPECOUNT - 1))
5763         fi
5764         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5765         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5766         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5767                 error "lverify failed"
5768 }
5769 run_test 65d "directory setstripe -S stripe_size -c stripe_count"
5770
5771 test_65e() {
5772         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5773         test_mkdir $DIR/$tdir
5774
5775         $SETSTRIPE $DIR/$tdir || error "setstripe"
5776         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5777                                         error "no stripe info failed"
5778         touch $DIR/$tdir/f6
5779         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5780 }
5781 run_test 65e "directory setstripe defaults"
5782
5783 test_65f() {
5784         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5785         test_mkdir $DIR/${tdir}f
5786         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5787 }
5788 run_test 65f "dir setstripe permission (should return error) ==="
5789
5790 test_65g() {
5791         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5792         test_mkdir $DIR/$tdir
5793         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5794
5795         $LFS setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5796                 error "setstripe -S failed"
5797         $LFS setstripe -d $DIR/$tdir || error "setstripe -d failed"
5798         $LFS getstripe -v $DIR/$tdir | grep "Default" ||
5799                 error "delete default stripe failed"
5800 }
5801 run_test 65g "directory setstripe -d"
5802
5803 test_65h() {
5804         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5805         test_mkdir $DIR/$tdir
5806         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5807
5808         $LFS setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5809                 error "setstripe -S failed"
5810         test_mkdir $DIR/$tdir/dd1
5811         [ $($LFS getstripe -c $DIR/$tdir) = $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5812                 error "stripe info inherit failed"
5813 }
5814 run_test 65h "directory stripe info inherit ===================="
5815
5816 test_65i() { # bug6367
5817         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5818         $SETSTRIPE -S 65536 -c -1 $MOUNT
5819 }
5820 run_test 65i "set non-default striping on root directory (bug 6367)="
5821
5822 test_65ia() { # bug12836
5823         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5824         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5825 }
5826 run_test 65ia "getstripe on -1 default directory striping"
5827
5828 test_65ib() { # bug12836
5829         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5830         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5831 }
5832 run_test 65ib "getstripe -v on -1 default directory striping"
5833
5834 test_65ic() { # bug12836
5835         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5836         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5837 }
5838 run_test 65ic "new find on -1 default directory striping"
5839
5840 test_65j() { # bug6367
5841         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5842         sync; sleep 1
5843         # if we aren't already remounting for each test, do so for this test
5844         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5845                 cleanup || error "failed to unmount"
5846                 setup
5847         fi
5848         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5849 }
5850 run_test 65j "set default striping on root directory (bug 6367)="
5851
5852 test_65k() { # bug11679
5853         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5854         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5855         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5856
5857         local disable_precreate=true
5858         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.8.54) ] &&
5859                 disable_precreate=false
5860
5861         echo "Check OST status: "
5862         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
5863                 awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
5864
5865         for OSC in $MDS_OSCS; do
5866                 echo $OSC "is active"
5867                 do_facet $SINGLEMDS lctl --device %$OSC activate
5868         done
5869
5870         for INACTIVE_OSC in $MDS_OSCS; do
5871                 local ost=$(osc_to_ost $INACTIVE_OSC)
5872                 local ostnum=$(do_facet $SINGLEMDS lctl get_param -n \
5873                                lov.*md*.target_obd |
5874                                awk -F: /$ost/'{ print $1 }' | head -n 1)
5875
5876                 mkdir -p $DIR/$tdir
5877                 $SETSTRIPE -i $ostnum -c 1 $DIR/$tdir
5878                 createmany -o $DIR/$tdir/$tfile.$ostnum. 1000
5879
5880                 echo "Deactivate: " $INACTIVE_OSC
5881                 do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5882
5883                 local count=$(do_facet $SINGLEMDS "lctl get_param -n \
5884                               osp.$ost*MDT0000.create_count")
5885                 local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
5886                                   osp.$ost*MDT0000.max_create_count")
5887                 $disable_precreate &&
5888                         do_facet $SINGLEMDS "lctl set_param -n \
5889                                 osp.$ost*MDT0000.max_create_count=0"
5890
5891                 for idx in $(seq 0 $((OSTCOUNT - 1))); do
5892                         [ -f $DIR/$tdir/$idx ] && continue
5893                         echo "$SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx"
5894                         $SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx ||
5895                                 error "setstripe $idx should succeed"
5896                         rm -f $DIR/$tdir/$idx || error "rm $idx failed"
5897                 done
5898                 unlinkmany $DIR/$tdir/$tfile.$ostnum. 1000
5899                 rmdir $DIR/$tdir
5900
5901                 do_facet $SINGLEMDS "lctl set_param -n \
5902                         osp.$ost*MDT0000.max_create_count=$max_count"
5903                 do_facet $SINGLEMDS "lctl set_param -n \
5904                         osp.$ost*MDT0000.create_count=$count"
5905                 do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5906                 echo $INACTIVE_OSC "is Activate"
5907
5908                 wait_osc_import_state mds ost$ostnum FULL
5909         done
5910 }
5911 run_test 65k "validate manual striping works properly with deactivated OSCs"
5912
5913 test_65l() { # bug 12836
5914         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5915         test_mkdir -p $DIR/$tdir/test_dir
5916         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5917         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5918 }
5919 run_test 65l "lfs find on -1 stripe dir ========================"
5920
5921 test_65m() {
5922         $RUNAS $SETSTRIPE -c 2 $MOUNT && error "setstripe should fail"
5923         true
5924 }
5925 run_test 65m "normal user can't set filesystem default stripe"
5926
5927 # bug 2543 - update blocks count on client
5928 test_66() {
5929         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5930         COUNT=${COUNT:-8}
5931         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5932         sync; sync_all_data; sync; sync_all_data
5933         cancel_lru_locks osc
5934         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5935         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5936 }
5937 run_test 66 "update inode blocks count on client ==============="
5938
5939 meminfo() {
5940         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5941 }
5942
5943 swap_used() {
5944         swapon -s | awk '($1 == "'$1'") { print $4 }'
5945 }
5946
5947 # bug5265, obdfilter oa2dentry return -ENOENT
5948 # #define OBD_FAIL_SRV_ENOENT 0x217
5949 test_69() {
5950         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5951         remote_ost_nodsh && skip "remote OST with nodsh" && return
5952
5953         f="$DIR/$tfile"
5954         $SETSTRIPE -c 1 -i 0 $f
5955
5956         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5957
5958         do_facet ost1 lctl set_param fail_loc=0x217
5959         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5960         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5961
5962         do_facet ost1 lctl set_param fail_loc=0
5963         $DIRECTIO write $f 0 2 || error "write error"
5964
5965         cancel_lru_locks osc
5966         $DIRECTIO read $f 0 1 || error "read error"
5967
5968         do_facet ost1 lctl set_param fail_loc=0x217
5969         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5970
5971         do_facet ost1 lctl set_param fail_loc=0
5972         rm -f $f
5973 }
5974 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5975
5976 test_71() {
5977         test_mkdir $DIR/$tdir
5978         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
5979         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5980 }
5981 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5982
5983 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5984         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5985         [ "$RUNAS_ID" = "$UID" ] &&
5986                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5987
5988         # Check that testing environment is properly set up. Skip if not
5989         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5990                 skip_env "User $RUNAS_ID does not exist - skipping"
5991                 return 0
5992         }
5993         touch $DIR/$tfile
5994         chmod 777 $DIR/$tfile
5995         chmod ug+s $DIR/$tfile
5996         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5997                 error "$RUNAS dd $DIR/$tfile failed"
5998         # See if we are still setuid/sgid
5999         test -u $DIR/$tfile -o -g $DIR/$tfile &&
6000                 error "S/gid is not dropped on write"
6001         # Now test that MDS is updated too
6002         cancel_lru_locks mdc
6003         test -u $DIR/$tfile -o -g $DIR/$tfile &&
6004                 error "S/gid is not dropped on MDS"
6005         rm -f $DIR/$tfile
6006 }
6007 run_test 72a "Test that remove suid works properly (bug5695) ===="
6008
6009 test_72b() { # bug 24226 -- keep mode setting when size is not changing
6010         local perm
6011
6012         [ "$RUNAS_ID" = "$UID" ] && \
6013                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6014         [ "$RUNAS_ID" -eq 0 ] && \
6015                 skip_env "RUNAS_ID = 0 -- skipping" && return
6016
6017         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6018         # Check that testing environment is properly set up. Skip if not
6019         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
6020                 skip_env "User $RUNAS_ID does not exist - skipping"
6021                 return 0
6022         }
6023         touch $DIR/${tfile}-f{g,u}
6024         test_mkdir $DIR/${tfile}-dg
6025         test_mkdir $DIR/${tfile}-du
6026         chmod 770 $DIR/${tfile}-{f,d}{g,u}
6027         chmod g+s $DIR/${tfile}-{f,d}g
6028         chmod u+s $DIR/${tfile}-{f,d}u
6029         for perm in 777 2777 4777; do
6030                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
6031                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
6032                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
6033                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
6034         done
6035         true
6036 }
6037 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
6038
6039 # bug 3462 - multiple simultaneous MDC requests
6040 test_73() {
6041         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6042         test_mkdir $DIR/d73-1
6043         test_mkdir $DIR/d73-2
6044         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
6045         pid1=$!
6046
6047         lctl set_param fail_loc=0x80000129
6048         $MULTIOP $DIR/d73-1/f73-2 Oc &
6049         sleep 1
6050         lctl set_param fail_loc=0
6051
6052         $MULTIOP $DIR/d73-2/f73-3 Oc &
6053         pid3=$!
6054
6055         kill -USR1 $pid1
6056         wait $pid1 || return 1
6057
6058         sleep 25
6059
6060         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
6061         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
6062         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
6063
6064         rm -rf $DIR/d73-*
6065 }
6066 run_test 73 "multiple MDC requests (should not deadlock)"
6067
6068 test_74a() { # bug 6149, 6184
6069         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6070         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
6071         #
6072         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
6073         # will spin in a tight reconnection loop
6074         touch $DIR/f74a
6075         $LCTL set_param fail_loc=0x8000030e
6076         # get any lock that won't be difficult - lookup works.
6077         ls $DIR/f74a
6078         $LCTL set_param fail_loc=0
6079         rm -f $DIR/f74a
6080         true
6081 }
6082 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
6083
6084 test_74b() { # bug 13310
6085         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6086         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
6087         #
6088         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
6089         # will spin in a tight reconnection loop
6090         $LCTL set_param fail_loc=0x8000030e
6091         # get a "difficult" lock
6092         touch $DIR/f74b
6093         $LCTL set_param fail_loc=0
6094         rm -f $DIR/f74b
6095         true
6096 }
6097 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
6098
6099 test_74c() {
6100         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6101         #define OBD_FAIL_LDLM_NEW_LOCK
6102         $LCTL set_param fail_loc=0x319
6103         touch $DIR/$tfile && error "touch successful"
6104         $LCTL set_param fail_loc=0
6105         true
6106 }
6107 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
6108
6109 num_inodes() {
6110         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
6111 }
6112
6113 test_76() { # Now for bug 20433, added originally in bug 1443
6114         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6115         local CPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
6116         cancel_lru_locks osc
6117         BEFORE_INODES=$(num_inodes)
6118         echo "before inodes: $BEFORE_INODES"
6119         local COUNT=1000
6120         [ "$SLOW" = "no" ] && COUNT=100
6121         for i in $(seq $COUNT); do
6122                 touch $DIR/$tfile
6123                 rm -f $DIR/$tfile
6124         done
6125         cancel_lru_locks osc
6126         AFTER_INODES=$(num_inodes)
6127         echo "after inodes: $AFTER_INODES"
6128         local wait=0
6129         while [[ $((AFTER_INODES-1*${CPUS:-1})) -gt $BEFORE_INODES ]]; do
6130                 sleep 2
6131                 AFTER_INODES=$(num_inodes)
6132                 wait=$((wait+2))
6133                 echo "wait $wait seconds inodes: $AFTER_INODES"
6134                 if [ $wait -gt 30 ]; then
6135                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
6136                 fi
6137         done
6138 }
6139 run_test 76 "confirm clients recycle inodes properly ===="
6140
6141
6142 export ORIG_CSUM=""
6143 set_checksums()
6144 {
6145         # Note: in sptlrpc modes which enable its own bulk checksum, the
6146         # original crc32_le bulk checksum will be automatically disabled,
6147         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
6148         # will be checked by sptlrpc code against sptlrpc bulk checksum.
6149         # In this case set_checksums() will not be no-op, because sptlrpc
6150         # bulk checksum will be enabled all through the test.
6151
6152         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
6153         lctl set_param -n osc.*.checksums $1
6154         return 0
6155 }
6156
6157 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
6158                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
6159 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
6160 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
6161 set_checksum_type()
6162 {
6163         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
6164         log "set checksum type to $1"
6165         return 0
6166 }
6167 F77_TMP=$TMP/f77-temp
6168 F77SZ=8
6169 setup_f77() {
6170         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
6171                 error "error writing to $F77_TMP"
6172 }
6173
6174 test_77a() { # bug 10889
6175         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6176         $GSS && skip "could not run with gss" && return
6177         [ ! -f $F77_TMP ] && setup_f77
6178         set_checksums 1
6179         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
6180         set_checksums 0
6181         rm -f $DIR/$tfile
6182 }
6183 run_test 77a "normal checksum read/write operation"
6184
6185 test_77b() { # bug 10889
6186         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6187         $GSS && skip "could not run with gss" && return
6188         [ ! -f $F77_TMP ] && setup_f77
6189         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6190         $LCTL set_param fail_loc=0x80000409
6191         set_checksums 1
6192
6193         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
6194                 error "dd error: $?"
6195         $LCTL set_param fail_loc=0
6196
6197         for algo in $CKSUM_TYPES; do
6198                 cancel_lru_locks osc
6199                 set_checksum_type $algo
6200                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
6201                 $LCTL set_param fail_loc=0x80000408
6202                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
6203                 $LCTL set_param fail_loc=0
6204         done
6205         set_checksums 0
6206         set_checksum_type $ORIG_CSUM_TYPE
6207         rm -f $DIR/$tfile
6208 }
6209 run_test 77b "checksum error on client write, read"
6210
6211 cleanup_77c() {
6212         trap 0
6213         set_checksums 0
6214         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=0
6215         $check_ost &&
6216                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=0
6217         [ -n $osc_file_prefix ] && rm -f ${osc_file_prefix}*
6218         $check_ost && [ -n $ost_file_prefix ] &&
6219                 do_facet ost1 rm -f ${ost_file_prefix}\*
6220 }
6221
6222 test_77c() {
6223         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6224         $GSS && skip "could not run with gss" && return
6225
6226         local bad1
6227         local osc_file_prefix
6228         local osc_file
6229         local check_ost=false
6230         local ost_file_prefix
6231         local ost_file
6232         local orig_cksum
6233         local dump_cksum
6234         local fid
6235
6236         # ensure corruption will occur on first OSS/OST
6237         $LFS setstripe -i 0 $DIR/$tfile
6238
6239         [ ! -f $F77_TMP ] && setup_f77
6240         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
6241                 error "dd write error: $?"
6242         fid=$($LFS path2fid $DIR/$tfile)
6243
6244         if [ $(lustre_version_code ost1) -ge $(version_code 2.9.57) ]
6245         then
6246                 check_ost=true
6247                 ost_file_prefix=$(do_facet ost1 $LCTL get_param -n debug_path)
6248                 ost_file_prefix=${ost_file_prefix}-checksum_dump-ost-\\${fid}
6249         else
6250                 echo "OSS do not support bulk pages dump upon error"
6251         fi
6252
6253         osc_file_prefix=$($LCTL get_param -n debug_path)
6254         osc_file_prefix=${osc_file_prefix}-checksum_dump-osc-\\${fid}
6255
6256         trap cleanup_77c EXIT
6257
6258         set_checksums 1
6259         # enable bulk pages dump upon error on Client
6260         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=1
6261         # enable bulk pages dump upon error on OSS
6262         $check_ost &&
6263                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=1
6264
6265         # flush Client cache to allow next read to reach OSS
6266         cancel_lru_locks osc
6267
6268         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE       0x408
6269         $LCTL set_param fail_loc=0x80000408
6270         dd if=$DIR/$tfile of=/dev/null bs=1M || error "dd read error: $?"
6271         $LCTL set_param fail_loc=0
6272
6273         rm -f $DIR/$tfile
6274
6275         # check cksum dump on Client
6276         osc_file=$(ls ${osc_file_prefix}*)
6277         [ -n "$osc_file" ] || error "no checksum dump file on Client"
6278         # OBD_FAIL_OSC_CHECKSUM_RECEIVE corrupts with "bad1" at start of file
6279         bad1=$(dd if=$osc_file bs=1 count=4 2>/dev/null) || error "dd error: $?"
6280         [ $bad1 == "bad1" ] || error "unexpected corrupt pattern"
6281         orig_cksum=$(dd if=$F77_TMP bs=1 skip=4 count=1048572 2>/dev/null |
6282                      cksum)
6283         dump_cksum=$(dd if=$osc_file bs=1 skip=4 2>/dev/null | cksum)
6284         [[ "$orig_cksum" == "$dump_cksum" ]] ||
6285                 error "dump content does not match on Client"
6286
6287         $check_ost || skip "No need to check cksum dump on OSS"
6288
6289         # check cksum dump on OSS
6290         ost_file=$(do_facet ost1 ls ${ost_file_prefix}\*)
6291         [ -n "$ost_file" ] || error "no checksum dump file on OSS"
6292         orig_cksum=$(dd if=$F77_TMP bs=1048576 count=1 2>/dev/null | cksum)
6293         dump_cksum=$(do_facet ost1 dd if=$ost_file 2>/dev/null \| cksum)
6294         [[ "$orig_cksum" == "$dump_cksum" ]] ||
6295                 error "dump content does not match on OSS"
6296
6297         cleanup_77c
6298 }
6299 run_test 77c "checksum error on client read with debug"
6300
6301 test_77d() { # bug 10889
6302         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6303         $GSS && skip "could not run with gss" && return
6304         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6305         $LCTL set_param fail_loc=0x80000409
6306         set_checksums 1
6307         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
6308                 error "direct write: rc=$?"
6309         $LCTL set_param fail_loc=0
6310         set_checksums 0
6311
6312         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
6313         $LCTL set_param fail_loc=0x80000408
6314         set_checksums 1
6315         cancel_lru_locks osc
6316         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
6317                 error "direct read: rc=$?"
6318         $LCTL set_param fail_loc=0
6319         set_checksums 0
6320 }
6321 run_test 77d "checksum error on OST direct write, read"
6322
6323 test_77f() { # bug 10889
6324         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6325         $GSS && skip "could not run with gss" && return
6326         set_checksums 1
6327         for algo in $CKSUM_TYPES; do
6328                 cancel_lru_locks osc
6329                 set_checksum_type $algo
6330                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6331                 $LCTL set_param fail_loc=0x409
6332                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
6333                         error "direct write succeeded"
6334                 $LCTL set_param fail_loc=0
6335         done
6336         set_checksum_type $ORIG_CSUM_TYPE
6337         set_checksums 0
6338 }
6339 run_test 77f "repeat checksum error on write (expect error)"
6340
6341 test_77g() { # bug 10889
6342         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6343         $GSS && skip "could not run with gss" && return
6344         remote_ost_nodsh && skip "remote OST with nodsh" && return
6345
6346         [ ! -f $F77_TMP ] && setup_f77
6347
6348         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
6349         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
6350         do_facet ost1 lctl set_param fail_loc=0x8000021a
6351         set_checksums 1
6352         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
6353                 error "write error: rc=$?"
6354         do_facet ost1 lctl set_param fail_loc=0
6355         set_checksums 0
6356
6357         cancel_lru_locks osc
6358         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
6359         do_facet ost1 lctl set_param fail_loc=0x8000021b
6360         set_checksums 1
6361         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
6362         do_facet ost1 lctl set_param fail_loc=0
6363         set_checksums 0
6364 }
6365 run_test 77g "checksum error on OST write, read"
6366
6367 test_77j() { # bug 13805
6368         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6369         $GSS && skip "could not run with gss" && return
6370         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
6371         lctl set_param fail_loc=0x40c
6372         remount_client $MOUNT
6373         lctl set_param fail_loc=0
6374         # wait async osc connect to finish and reflect updated state value
6375         local i
6376         for (( i=0; i < OSTCOUNT; i++ )) ; do
6377                 wait_osc_import_state client ost$((i+1)) FULL
6378         done
6379
6380         for VALUE in $(lctl get_param osc.*osc-[^mM]*.checksum_type); do
6381                 PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
6382                 algo=$(lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g')
6383                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
6384         done
6385         remount_client $MOUNT
6386 }
6387 run_test 77j "client only supporting ADLER32"
6388
6389 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
6390 rm -f $F77_TMP
6391 unset F77_TMP
6392
6393 cleanup_test_78() {
6394         trap 0
6395         rm -f $DIR/$tfile
6396 }
6397
6398 test_78() { # bug 10901
6399         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6400         remote_ost || { skip_env "local OST" && return; }
6401
6402         NSEQ=5
6403         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
6404         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
6405         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
6406         echo "MemTotal: $MEMTOTAL"
6407
6408         # reserve 256MB of memory for the kernel and other running processes,
6409         # and then take 1/2 of the remaining memory for the read/write buffers.
6410         if [ $MEMTOTAL -gt 512 ] ;then
6411                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
6412         else
6413                 # for those poor memory-starved high-end clusters...
6414                 MEMTOTAL=$((MEMTOTAL / 2))
6415         fi
6416         echo "Mem to use for directio: $MEMTOTAL"
6417
6418         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
6419         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
6420         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
6421         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
6422                 head -n1)
6423         echo "Smallest OST: $SMALLESTOST"
6424         [[ $SMALLESTOST -lt 10240 ]] &&
6425                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
6426
6427         trap cleanup_test_78 EXIT
6428
6429         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
6430                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
6431
6432         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
6433         echo "File size: $F78SIZE"
6434         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
6435         for i in $(seq 1 $NSEQ); do
6436                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
6437                 echo directIO rdwr round $i of $NSEQ
6438                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
6439         done
6440
6441         cleanup_test_78
6442 }
6443 run_test 78 "handle large O_DIRECT writes correctly ============"
6444
6445 test_79() { # bug 12743
6446         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6447         wait_delete_completed
6448
6449         BKTOTAL=$(calc_osc_kbytes kbytestotal)
6450         BKFREE=$(calc_osc_kbytes kbytesfree)
6451         BKAVAIL=$(calc_osc_kbytes kbytesavail)
6452
6453         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
6454         DFTOTAL=`echo $STRING | cut -d, -f1`
6455         DFUSED=`echo $STRING  | cut -d, -f2`
6456         DFAVAIL=`echo $STRING | cut -d, -f3`
6457         DFFREE=$(($DFTOTAL - $DFUSED))
6458
6459         ALLOWANCE=$((64 * $OSTCOUNT))
6460
6461         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
6462            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
6463                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
6464         fi
6465         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
6466            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
6467                 error "df free($DFFREE) mismatch OST free($BKFREE)"
6468         fi
6469         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
6470            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
6471                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
6472         fi
6473 }
6474 run_test 79 "df report consistency check ======================="
6475
6476 test_80() { # bug 10718
6477         remote_ost_nodsh && skip "remote OST with nodsh" && return
6478         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6479         # relax strong synchronous semantics for slow backends like ZFS
6480         local soc="obdfilter.*.sync_on_lock_cancel"
6481         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
6482         local hosts=
6483         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
6484                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
6485                           facet_active_host $host; done | sort -u)
6486                 do_nodes $hosts lctl set_param $soc=never
6487         fi
6488
6489         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
6490         sync; sleep 1; sync
6491         local BEFORE=`date +%s`
6492         cancel_lru_locks osc
6493         local AFTER=`date +%s`
6494         local DIFF=$((AFTER-BEFORE))
6495         if [ $DIFF -gt 1 ] ; then
6496                 error "elapsed for 1M@1T = $DIFF"
6497         fi
6498
6499         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
6500
6501         rm -f $DIR/$tfile
6502 }
6503 run_test 80 "Page eviction is equally fast at high offsets too  ===="
6504
6505 test_81a() { # LU-456
6506         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6507         remote_ost_nodsh && skip "remote OST with nodsh" && return
6508         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6509         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
6510         do_facet ost1 lctl set_param fail_loc=0x80000228
6511
6512         # write should trigger a retry and success
6513         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6514         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6515         RC=$?
6516         if [ $RC -ne 0 ] ; then
6517                 error "write should success, but failed for $RC"
6518         fi
6519 }
6520 run_test 81a "OST should retry write when get -ENOSPC ==============="
6521
6522 test_81b() { # LU-456
6523         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6524         remote_ost_nodsh && skip "remote OST with nodsh" && return
6525         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6526         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
6527         do_facet ost1 lctl set_param fail_loc=0x228
6528
6529         # write should retry several times and return -ENOSPC finally
6530         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6531         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6532         RC=$?
6533         ENOSPC=28
6534         if [ $RC -ne $ENOSPC ] ; then
6535                 error "dd should fail for -ENOSPC, but succeed."
6536         fi
6537 }
6538 run_test 81b "OST should return -ENOSPC when retry still fails ======="
6539
6540 test_82() { # LU-1031
6541         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
6542         local gid1=14091995
6543         local gid2=16022000
6544
6545         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
6546         local MULTIPID1=$!
6547         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
6548         local MULTIPID2=$!
6549         kill -USR1 $MULTIPID2
6550         sleep 2
6551         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6552                 error "First grouplock does not block second one"
6553         else
6554                 echo "Second grouplock blocks first one"
6555         fi
6556         kill -USR1 $MULTIPID1
6557         wait $MULTIPID1
6558         wait $MULTIPID2
6559 }
6560 run_test 82 "Basic grouplock test"
6561
6562 test_83() {
6563         local sfile="/boot/System.map-$(uname -r)"
6564         # define OBD_FAIL_LLITE_PTASK_IO_FAIL 0x140d
6565         $LCTL set_param fail_loc=0x140d
6566         cp $sfile $DIR/$tfile || error "write failed"
6567         diff -c $sfile $DIR/$tfile || error "files are different"
6568         $LCTL set_param fail_loc=0
6569         rm -f $DIR/$tfile
6570 }
6571 run_test 83 "Short write in ptask ==============================="
6572
6573 test_99() {
6574         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6575                 return
6576         test_mkdir $DIR/$tdir.cvsroot
6577         chown $RUNAS_ID $DIR/$tdir.cvsroot
6578
6579         cd $TMP
6580         $RUNAS cvs -d $DIR/$tdir.cvsroot init || error "cvs init failed"
6581
6582         cd /etc/init.d
6583         # some versions of cvs import exit(1) when asked to import links or
6584         # files they can't read.  ignore those files.
6585         local toignore=$(find . -type l -printf '-I %f\n' -o \
6586                          ! -perm /4 -printf '-I %f\n')
6587         $RUNAS cvs -d $DIR/$tdir.cvsroot import -m "nomesg" $toignore \
6588                 $tdir.reposname vtag rtag
6589
6590         cd $DIR
6591         test_mkdir $DIR/$tdir.reposname
6592         chown $RUNAS_ID $DIR/$tdir.reposname
6593         $RUNAS cvs -d $DIR/$tdir.cvsroot co $tdir.reposname
6594
6595         cd $DIR/$tdir.reposname
6596         $RUNAS touch foo99
6597         $RUNAS cvs add -m 'addmsg' foo99
6598         $RUNAS cvs update
6599         $RUNAS cvs commit -m 'nomsg' foo99
6600         rm -fr $DIR/$tdir.cvsroot
6601 }
6602 run_test 99 "cvs strange file/directory operations"
6603
6604 test_100() {
6605         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6606         [[ "$NETTYPE" =~ tcp ]] ||
6607                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" &&
6608                         return ; }
6609
6610         remote_ost_nodsh && skip "remote OST with nodsh" && return
6611         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6612         remote_servers ||
6613                 { skip "useless for local single node setup" && return; }
6614
6615         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6616                 [ "$PROT" != "tcp" ] && continue
6617                 RPORT=$(echo $REMOTE | cut -d: -f2)
6618                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6619
6620                 rc=0
6621                 LPORT=`echo $LOCAL | cut -d: -f2`
6622                 if [ $LPORT -ge 1024 ]; then
6623                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6624                         netstat -tna
6625                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6626                 fi
6627         done
6628         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6629 }
6630 run_test 100 "check local port using privileged port ==========="
6631
6632 function get_named_value()
6633 {
6634     local tag
6635
6636     tag=$1
6637     while read ;do
6638         line=$REPLY
6639         case $line in
6640         $tag*)
6641             echo $line | sed "s/^$tag[ ]*//"
6642             break
6643             ;;
6644         esac
6645     done
6646 }
6647
6648 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6649                    awk '/^max_cached_mb/ { print $2 }')
6650
6651 cleanup_101a() {
6652         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6653         trap 0
6654 }
6655
6656 test_101a() {
6657         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6658         [ $MDSCOUNT -ge 2 ] && skip "needs < 2 MDTs" && return #LU-4322
6659         local s
6660         local discard
6661         local nreads=10000
6662         local cache_limit=32
6663
6664         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6665         trap cleanup_101a EXIT
6666         $LCTL set_param -n llite.*.read_ahead_stats 0
6667         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6668
6669         #
6670         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6671         #
6672         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6673         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6674
6675         discard=0
6676         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6677                 get_named_value 'read but discarded' | cut -d" " -f1); do
6678                         discard=$(($discard + $s))
6679         done
6680         cleanup_101a
6681
6682         if [[ $(($discard * 10)) -gt $nreads ]]; then
6683                 $LCTL get_param osc.*-osc*.rpc_stats
6684                 $LCTL get_param llite.*.read_ahead_stats
6685                 error "too many ($discard) discarded pages"
6686         fi
6687         rm -f $DIR/$tfile || true
6688 }
6689 run_test 101a "check read-ahead for random reads"
6690
6691 setup_test101bc() {
6692         test_mkdir $DIR/$tdir
6693         local STRIPE_SIZE=$1
6694         local FILE_LENGTH=$2
6695         STRIPE_OFFSET=0
6696
6697         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6698
6699         local list=$(comma_list $(osts_nodes))
6700         set_osd_param $list '' read_cache_enable 0
6701         set_osd_param $list '' writethrough_cache_enable 0
6702
6703         trap cleanup_test101bc EXIT
6704         # prepare the read-ahead file
6705         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6706
6707         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6708                                 count=$FILE_SIZE_MB 2> /dev/null
6709
6710 }
6711
6712 cleanup_test101bc() {
6713         trap 0
6714         rm -rf $DIR/$tdir
6715         rm -f $DIR/$tfile
6716
6717         local list=$(comma_list $(osts_nodes))
6718         set_osd_param $list '' read_cache_enable 1
6719         set_osd_param $list '' writethrough_cache_enable 1
6720 }
6721
6722 calc_total() {
6723         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6724 }
6725
6726 ra_check_101() {
6727         local READ_SIZE=$1
6728         local STRIPE_SIZE=$2
6729         local FILE_LENGTH=$3
6730         local RA_INC=1048576
6731         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6732         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6733                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6734         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6735                         get_named_value 'read but discarded' |
6736                         cut -d" " -f1 | calc_total)
6737         if [[ $DISCARD -gt $discard_limit ]]; then
6738                 $LCTL get_param llite.*.read_ahead_stats
6739                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6740         else
6741                 echo "Read-ahead success for size ${READ_SIZE}"
6742         fi
6743 }
6744
6745 test_101b() {
6746         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6747         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
6748         local STRIPE_SIZE=1048576
6749         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6750         if [ $SLOW == "yes" ]; then
6751                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6752         else
6753                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6754         fi
6755
6756         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6757
6758         # prepare the read-ahead file
6759         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6760         cancel_lru_locks osc
6761         for BIDX in 2 4 8 16 32 64 128 256
6762         do
6763                 local BSIZE=$((BIDX*4096))
6764                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6765                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6766                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6767                 $LCTL set_param -n llite.*.read_ahead_stats 0
6768                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6769                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6770                 cancel_lru_locks osc
6771                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6772         done
6773         cleanup_test101bc
6774         true
6775 }
6776 run_test 101b "check stride-io mode read-ahead ================="
6777
6778 test_101c() {
6779         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6780         local STRIPE_SIZE=1048576
6781         local FILE_LENGTH=$((STRIPE_SIZE*100))
6782         local nreads=10000
6783         local osc_rpc_stats
6784
6785         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6786
6787         cancel_lru_locks osc
6788         $LCTL set_param osc.*.rpc_stats 0
6789         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6790         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6791                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6792                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6793                 local size
6794
6795                 if [ $lines -le 20 ]; then
6796                         continue
6797                 fi
6798                 for size in 1 2 4 8; do
6799                         local rpc=$(echo "$stats" |
6800                                     awk '($1 == "'$size':") {print $2; exit; }')
6801                         [ $rpc != 0 ] &&
6802                                 error "Small $((size*4))k read IO $rpc !"
6803                 done
6804                 echo "$osc_rpc_stats check passed!"
6805         done
6806         cleanup_test101bc
6807         true
6808 }
6809 run_test 101c "check stripe_size aligned read-ahead ================="
6810
6811 set_read_ahead() {
6812         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6813         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6814 }
6815
6816 test_101d() {
6817         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6818         local file=$DIR/$tfile
6819         local sz_MB=${FILESIZE_101d:-500}
6820         local ra_MB=${READAHEAD_MB:-40}
6821
6822         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6823         [ $free_MB -lt $sz_MB ] &&
6824                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6825
6826         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6827         $SETSTRIPE -c -1 $file || error "setstripe failed"
6828
6829         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6830         echo Cancel LRU locks on lustre client to flush the client cache
6831         cancel_lru_locks osc
6832
6833         echo Disable read-ahead
6834         local old_READAHEAD=$(set_read_ahead 0)
6835
6836         echo Reading the test file $file with read-ahead disabled
6837         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6838
6839         echo Cancel LRU locks on lustre client to flush the client cache
6840         cancel_lru_locks osc
6841         echo Enable read-ahead with ${ra_MB}MB
6842         set_read_ahead $ra_MB
6843
6844         echo Reading the test file $file with read-ahead enabled
6845         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6846
6847         echo "read-ahead disabled time read $raOFF"
6848         echo "read-ahead enabled  time read $raON"
6849
6850         set_read_ahead $old_READAHEAD
6851         rm -f $file
6852         wait_delete_completed
6853
6854         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6855                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6856 }
6857 run_test 101d "file read with and without read-ahead enabled"
6858
6859 test_101e() {
6860         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6861         local file=$DIR/$tfile
6862         local size_KB=500  #KB
6863         local count=100
6864         local bsize=1024
6865
6866         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6867         local need_KB=$((count * size_KB))
6868         [[ $free_KB -le $need_KB ]] &&
6869                 skip_env "Need free space $need_KB, have $free_KB" && return
6870
6871         echo "Creating $count ${size_KB}K test files"
6872         for ((i = 0; i < $count; i++)); do
6873                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6874         done
6875
6876         echo "Cancel LRU locks on lustre client to flush the client cache"
6877         cancel_lru_locks osc
6878
6879         echo "Reset readahead stats"
6880         $LCTL set_param -n llite.*.read_ahead_stats 0
6881
6882         for ((i = 0; i < $count; i++)); do
6883                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6884         done
6885
6886         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6887                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6888
6889         for ((i = 0; i < $count; i++)); do
6890                 rm -rf $file.$i 2>/dev/null
6891         done
6892
6893         #10000 means 20% reads are missing in readahead
6894         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6895 }
6896 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6897
6898 test_101f() {
6899         which iozone || { skip "no iozone installed" && return; }
6900
6901         local old_debug=$($LCTL get_param debug)
6902         old_debug=${old_debug#*=}
6903         $LCTL set_param debug="reada mmap"
6904
6905         # create a test file
6906         iozone -i 0 -+n -r 1m -s 128m -w -f $DIR/$tfile > /dev/null 2>&1
6907
6908         echo Cancel LRU locks on lustre client to flush the client cache
6909         cancel_lru_locks osc
6910
6911         echo Reset readahead stats
6912         $LCTL set_param -n llite.*.read_ahead_stats 0
6913
6914         echo mmap read the file with small block size
6915         iozone -i 1 -u 1 -l 1 -+n -r 32k -s 128m -B -f $DIR/$tfile \
6916                 > /dev/null 2>&1
6917
6918         echo checking missing pages
6919         $LCTL get_param llite.*.read_ahead_stats
6920         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6921                         get_named_value 'misses' | cut -d" " -f1 | calc_total)
6922
6923         $LCTL set_param debug="$old_debug"
6924         [ $miss -lt 3 ] || error "misses too much pages ('$miss')!"
6925         rm -f $DIR/$tfile
6926 }
6927 run_test 101f "check mmap read performance"
6928
6929 test_101g_brw_size_test() {
6930         local mb=$1
6931         local pages=$((mb * 1048576 / $(page_size)))
6932
6933         $LCTL set_param osc.*.max_pages_per_rpc=${mb}M ||
6934                 { error "unable to set max_pages_per_rpc=${mb}M"; return 1; }
6935         for mp in $($LCTL get_param -n osc.*.max_pages_per_rpc); do
6936                 [ $mp -ne $pages ] && error "max_pages_per_rpc $mp != $pages" &&
6937                         return 2
6938         done
6939
6940         $LCTL set_param -n osc.*.rpc_stats=0
6941
6942         # 10 RPCs should be enough for the test
6943         local count=10
6944         dd if=/dev/zero of=$DIR/$tfile bs=${mb}M count=$count ||
6945                 { error "dd write ${mb} MB blocks failed"; return 3; }
6946         cancel_lru_locks osc
6947         dd of=/dev/null if=$DIR/$tfile bs=${mb}M count=$count ||
6948                 { error "dd write ${mb} MB blocks failed"; return 4; }
6949
6950         # calculate number of full-sized read and write RPCs
6951         rpcs=($($LCTL get_param -n 'osc.*.rpc_stats' |
6952                 sed -n '/pages per rpc/,/^$/p' |
6953                 awk '/'$pages':/ { reads += $2; writes += $6 }; \
6954                 END { print reads,writes }'))
6955         [ ${rpcs[0]} -ne $count ] && error "${rpcs[0]} != $count read RPCs" &&
6956                 return 5
6957         [ ${rpcs[1]} -ne $count ] && error "${rpcs[1]} != $count write RPCs" &&
6958                 return 6
6959
6960         return 0
6961 }
6962
6963 test_101g() {
6964         local rpcs
6965         local osts=$(get_facets OST)
6966         local list=$(comma_list $(osts_nodes))
6967         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
6968         local brw_size="obdfilter.*.brw_size"
6969
6970         $LFS setstripe -i 0 -c 1 $DIR/$tfile
6971
6972         local orig_mb=$(do_facet ost1 $LCTL get_param -n $brw_size | head -n 1)
6973         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.52) -a \
6974              $(lustre_version_code client) -ge $(version_code 2.8.52) ]; then
6975                 [ $(lustre_version_code ost1) -ge $(version_code 2.9.52) ] &&
6976                         suffix="M"
6977                 if [[ $orig_mb -lt 16 ]]; then
6978                         save_lustre_params $osts "$brw_size" > $p
6979                         do_nodes $list $LCTL set_param -n $brw_size=16$suffix ||
6980                                 error "set 16MB RPC size failed"
6981
6982                         echo "remount client to enable new RPC size"
6983                         remount_client $MOUNT || error "remount_client failed"
6984                 fi
6985
6986                 test_101g_brw_size_test 16 || error "16MB RPC test failed"
6987                 # should be able to set brw_size=12, but no rpc_stats for that
6988                 test_101g_brw_size_test 8 || error "8MB RPC test failed"
6989         fi
6990
6991         test_101g_brw_size_test 4 || error "4MB RPC test failed"
6992
6993         if [[ $orig_mb -lt 16 ]]; then
6994                 restore_lustre_params < $p
6995                 remount_client $MOUNT || error "remount_client restore failed"
6996         fi
6997
6998         rm -f $p $DIR/$tfile
6999 }
7000 run_test 101g "Big bulk(4/16 MiB) readahead"
7001
7002 setup_test102() {
7003         test_mkdir $DIR/$tdir
7004         chown $RUNAS_ID $DIR/$tdir
7005         STRIPE_SIZE=65536
7006         STRIPE_OFFSET=1
7007         STRIPE_COUNT=$OSTCOUNT
7008         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
7009
7010         trap cleanup_test102 EXIT
7011         cd $DIR
7012         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
7013         cd $DIR/$tdir
7014         for num in 1 2 3 4; do
7015                 for count in $(seq 1 $STRIPE_COUNT); do
7016                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
7017                                 local size=`expr $STRIPE_SIZE \* $num`
7018                                 local file=file"$num-$idx-$count"
7019                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
7020                         done
7021                 done
7022         done
7023
7024         cd $DIR
7025         $1 tar cf $TMP/f102.tar $tdir --xattrs
7026 }
7027
7028 cleanup_test102() {
7029         trap 0
7030         rm -f $TMP/f102.tar
7031         rm -rf $DIR/d0.sanity/d102
7032 }
7033
7034 test_102a() {
7035         local testfile=$DIR/$tfile
7036
7037         touch $testfile
7038
7039         [ "$UID" != 0 ] && skip_env "must run as root" && return
7040         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
7041                 skip_env "must have user_xattr" && return
7042
7043         [ -z "$(which setfattr 2>/dev/null)" ] &&
7044                 skip_env "could not find setfattr" && return
7045
7046         echo "set/get xattr..."
7047         setfattr -n trusted.name1 -v value1 $testfile ||
7048                 error "setfattr -n trusted.name1=value1 $testfile failed"
7049         getfattr -n trusted.name1 $testfile 2> /dev/null |
7050           grep "trusted.name1=.value1" ||
7051                 error "$testfile missing trusted.name1=value1"
7052
7053         setfattr -n user.author1 -v author1 $testfile ||
7054                 error "setfattr -n user.author1=author1 $testfile failed"
7055         getfattr -n user.author1 $testfile 2> /dev/null |
7056           grep "user.author1=.author1" ||
7057                 error "$testfile missing trusted.author1=author1"
7058
7059         echo "listxattr..."
7060         setfattr -n trusted.name2 -v value2 $testfile ||
7061                 error "$testfile unable to set trusted.name2"
7062         setfattr -n trusted.name3 -v value3 $testfile ||
7063                 error "$testfile unable to set trusted.name3"
7064         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
7065             grep "trusted.name" | wc -l) -eq 3 ] ||
7066                 error "$testfile missing 3 trusted.name xattrs"
7067
7068         setfattr -n user.author2 -v author2 $testfile ||
7069                 error "$testfile unable to set user.author2"
7070         setfattr -n user.author3 -v author3 $testfile ||
7071                 error "$testfile unable to set user.author3"
7072         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
7073             grep "user.author" | wc -l) -eq 3 ] ||
7074                 error "$testfile missing 3 user.author xattrs"
7075
7076         echo "remove xattr..."
7077         setfattr -x trusted.name1 $testfile ||
7078                 error "$testfile error deleting trusted.name1"
7079         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
7080                 error "$testfile did not delete trusted.name1 xattr"
7081
7082         setfattr -x user.author1 $testfile ||
7083                 error "$testfile error deleting user.author1"
7084         echo "set lustre special xattr ..."
7085         $LFS setstripe -c1 $testfile
7086         local lovea=$(getfattr -n "trusted.lov" -e hex $testfile |
7087                 awk -F "=" '/trusted.lov/ { print $2 }' )
7088         setfattr -n "trusted.lov" -v $lovea $testfile ||
7089                 error "$testfile doesn't ignore setting trusted.lov again"
7090         setfattr -n "trusted.lov" -v "invalid_value" $testfile &&
7091                 error "$testfile allow setting invalid trusted.lov"
7092         rm -f $testfile
7093 }
7094 run_test 102a "user xattr test =================================="
7095
7096 test_102b() {
7097         [ -z "$(which setfattr 2>/dev/null)" ] &&
7098                 skip_env "could not find setfattr" && return
7099
7100         # b10930: get/set/list trusted.lov xattr
7101         echo "get/set/list trusted.lov xattr ..."
7102         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7103         local testfile=$DIR/$tfile
7104         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7105                 error "setstripe failed"
7106         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
7107                 error "getstripe failed"
7108         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
7109                 error "can't get trusted.lov from $testfile"
7110
7111         local testfile2=${testfile}2
7112         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
7113                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
7114
7115         $MCREATE $testfile2
7116         setfattr -n trusted.lov -v $value $testfile2
7117         local stripe_size=$($GETSTRIPE -S $testfile2)
7118         local stripe_count=$($GETSTRIPE -c $testfile2)
7119         [[ $stripe_size -eq 65536 ]] ||
7120                 error "stripe size $stripe_size != 65536"
7121         [[ $stripe_count -eq $STRIPECOUNT ]] ||
7122                 error "stripe count $stripe_count != $STRIPECOUNT"
7123         rm -f $DIR/$tfile
7124 }
7125 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
7126
7127 test_102c() {
7128         [ -z "$(which setfattr 2>/dev/null)" ] &&
7129                 skip_env "could not find setfattr" && return
7130
7131         # b10930: get/set/list lustre.lov xattr
7132         echo "get/set/list lustre.lov xattr ..."
7133         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7134         test_mkdir $DIR/$tdir
7135         chown $RUNAS_ID $DIR/$tdir
7136         local testfile=$DIR/$tdir/$tfile
7137         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7138                 error "setstripe failed"
7139         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
7140                 error "getstripe failed"
7141         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
7142         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
7143
7144         local testfile2=${testfile}2
7145         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
7146                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
7147
7148         $RUNAS $MCREATE $testfile2
7149         $RUNAS setfattr -n lustre.lov -v $value $testfile2
7150         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
7151         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
7152         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
7153         [ $stripe_count -eq $STRIPECOUNT ] ||
7154                 error "stripe count $stripe_count != $STRIPECOUNT"
7155 }
7156 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
7157
7158 compare_stripe_info1() {
7159         local stripe_index_all_zero=true
7160
7161         for num in 1 2 3 4; do
7162                 for count in $(seq 1 $STRIPE_COUNT); do
7163                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
7164                                 local size=$((STRIPE_SIZE * num))
7165                                 local file=file"$num-$offset-$count"
7166                                 stripe_size=$($LFS getstripe -S $PWD/$file)
7167                                 [[ $stripe_size -ne $size ]] &&
7168                                     error "$file: size $stripe_size != $size"
7169                                 stripe_count=$($LFS getstripe -c $PWD/$file)
7170                                 # allow fewer stripes to be created, ORI-601
7171                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
7172                                     error "$file: count $stripe_count != $count"
7173                                 stripe_index=$($LFS getstripe -i $PWD/$file)
7174                                 [[ $stripe_index -ne 0 ]] &&
7175                                         stripe_index_all_zero=false
7176                         done
7177                 done
7178         done
7179         $stripe_index_all_zero &&
7180                 error "all files are being extracted starting from OST index 0"
7181         return 0
7182 }
7183
7184 have_xattrs_include() {
7185         tar --help | grep -q xattrs-include &&
7186                 echo --xattrs-include="lustre.*"
7187 }
7188
7189 test_102d() {
7190         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7191         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7192         XINC=$(have_xattrs_include)
7193         setup_test102
7194         tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $XINC
7195         cd $DIR/$tdir/$tdir
7196         compare_stripe_info1
7197 }
7198 run_test 102d "tar restore stripe info from tarfile,not keep osts"
7199
7200 test_102f() {
7201         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7202         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7203         XINC=$(have_xattrs_include)
7204         setup_test102
7205         test_mkdir $DIR/$tdir.restore
7206         cd $DIR
7207         tar cf - --xattrs $tdir | tar xf - \
7208                 -C $DIR/$tdir.restore --xattrs $XINC
7209         cd $DIR/$tdir.restore/$tdir
7210         compare_stripe_info1
7211 }
7212 run_test 102f "tar copy files, not keep osts"
7213
7214 grow_xattr() {
7215         local xsize=${1:-1024}  # in bytes
7216         local file=$DIR/$tfile
7217
7218         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep xattr)" ] &&
7219                 skip "must have user_xattr" && return 0
7220         [ -z "$(which setfattr 2>/dev/null)" ] &&
7221                 skip_env "could not find setfattr" && return 0
7222         [ -z "$(which getfattr 2>/dev/null)" ] &&
7223                 skip_env "could not find getfattr" && return 0
7224
7225         touch $file
7226
7227         local value="$(generate_string $xsize)"
7228
7229         local xbig=trusted.big
7230         log "save $xbig on $file"
7231         setfattr -n $xbig -v $value $file ||
7232                 error "saving $xbig on $file failed"
7233
7234         local orig=$(get_xattr_value $xbig $file)
7235         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
7236
7237         local xsml=trusted.sml
7238         log "save $xsml on $file"
7239         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
7240
7241         local new=$(get_xattr_value $xbig $file)
7242         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
7243
7244         log "grow $xsml on $file"
7245         setfattr -n $xsml -v "$value" $file ||
7246                 error "growing $xsml on $file failed"
7247
7248         new=$(get_xattr_value $xbig $file)
7249         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
7250         log "$xbig still valid after growing $xsml"
7251
7252         rm -f $file
7253 }
7254
7255 test_102h() { # bug 15777
7256         grow_xattr 1024
7257 }
7258 run_test 102h "grow xattr from inside inode to external block"
7259
7260 test_102ha() {
7261         large_xattr_enabled || { skip "large_xattr disabled" && return; }
7262         grow_xattr $(max_xattr_size)
7263 }
7264 run_test 102ha "grow xattr from inside inode to external inode"
7265
7266 test_102i() { # bug 17038
7267         [ -z "$(which getfattr 2>/dev/null)" ] &&
7268                 skip "could not find getfattr" && return
7269         touch $DIR/$tfile
7270         ln -s $DIR/$tfile $DIR/${tfile}link
7271         getfattr -n trusted.lov $DIR/$tfile ||
7272                 error "lgetxattr on $DIR/$tfile failed"
7273         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
7274                 grep -i "no such attr" ||
7275                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
7276         rm -f $DIR/$tfile $DIR/${tfile}link
7277 }
7278 run_test 102i "lgetxattr test on symbolic link ============"
7279
7280 test_102j() {
7281         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7282         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7283         XINC=$(have_xattrs_include)
7284         setup_test102 "$RUNAS"
7285         chown $RUNAS_ID $DIR/$tdir
7286         $RUNAS tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $XINC
7287         cd $DIR/$tdir/$tdir
7288         compare_stripe_info1 "$RUNAS"
7289 }
7290 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
7291
7292 test_102k() {
7293         [ -z "$(which setfattr 2>/dev/null)" ] &&
7294                 skip "could not find setfattr" && return
7295         touch $DIR/$tfile
7296         # b22187 just check that does not crash for regular file.
7297         setfattr -n trusted.lov $DIR/$tfile
7298         # b22187 'setfattr -n trusted.lov' should remove LOV EA for directories
7299         local test_kdir=$DIR/$tdir
7300         test_mkdir $test_kdir
7301         local default_size=$($LFS getstripe -S $test_kdir)
7302         local default_count=$($LFS getstripe -c $test_kdir)
7303         local default_offset=$($LFS getstripe -i $test_kdir)
7304         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
7305                 error 'dir setstripe failed'
7306         setfattr -n trusted.lov $test_kdir
7307         local stripe_size=$($LFS getstripe -S $test_kdir)
7308         local stripe_count=$($LFS getstripe -c $test_kdir)
7309         local stripe_offset=$($LFS getstripe -i $test_kdir)
7310         [ $stripe_size -eq $default_size ] ||
7311                 error "stripe size $stripe_size != $default_size"
7312         [ $stripe_count -eq $default_count ] ||
7313                 error "stripe count $stripe_count != $default_count"
7314         [ $stripe_offset -eq $default_offset ] ||
7315                 error "stripe offset $stripe_offset != $default_offset"
7316         rm -rf $DIR/$tfile $test_kdir
7317 }
7318 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
7319
7320 test_102l() {
7321         [ -z "$(which getfattr 2>/dev/null)" ] &&
7322                 skip "could not find getfattr" && return
7323
7324         # LU-532 trusted. xattr is invisible to non-root
7325         local testfile=$DIR/$tfile
7326
7327         touch $testfile
7328
7329         echo "listxattr as user..."
7330         chown $RUNAS_ID $testfile
7331         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
7332             grep -q "trusted" &&
7333                 error "$testfile trusted xattrs are user visible"
7334
7335         return 0;
7336 }
7337 run_test 102l "listxattr size test =================================="
7338
7339 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
7340         local path=$DIR/$tfile
7341         touch $path
7342
7343         listxattr_size_check $path || error "listattr_size_check $path failed"
7344 }
7345 run_test 102m "Ensure listxattr fails on small bufffer ========"
7346
7347 cleanup_test102
7348
7349 getxattr() { # getxattr path name
7350         # Return the base64 encoding of the value of xattr name on path.
7351         local path=$1
7352         local name=$2
7353
7354         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
7355         # file: $path
7356         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
7357         #
7358         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
7359
7360         getfattr --absolute-names --encoding=base64 --name=$name $path |
7361                 awk -F= -v name=$name '$1 == name {
7362                         print substr($0, index($0, "=") + 1);
7363         }'
7364 }
7365
7366 test_102n() { # LU-4101 mdt: protect internal xattrs
7367         [ -z "$(which setfattr 2>/dev/null)" ] &&
7368                 skip "could not find setfattr" && return
7369         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
7370         then
7371                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
7372                 return
7373         fi
7374
7375         local file0=$DIR/$tfile.0
7376         local file1=$DIR/$tfile.1
7377         local xattr0=$TMP/$tfile.0
7378         local xattr1=$TMP/$tfile.1
7379         local namelist="lov lma lmv link fid version som hsm"
7380         local name
7381         local value
7382
7383         rm -rf $file0 $file1 $xattr0 $xattr1
7384         touch $file0 $file1
7385
7386         # Get 'before' xattrs of $file1.
7387         getfattr --absolute-names --dump --match=- $file1 > $xattr0
7388
7389         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
7390                 namelist+=" lfsck_namespace"
7391         for name in $namelist; do
7392                 # Try to copy xattr from $file0 to $file1.
7393                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7394
7395                 setfattr --name=trusted.$name --value="$value" $file1 ||
7396                         error "setxattr 'trusted.$name' failed"
7397
7398                 # Try to set a garbage xattr.
7399                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7400
7401                 if [[ x$name == "xlov" ]]; then
7402                         setfattr --name=trusted.lov --value="$value" $file1 &&
7403                         error "setxattr invalid 'trusted.lov' success"
7404                 else
7405                         setfattr --name=trusted.$name --value="$value" $file1 ||
7406                                 error "setxattr invalid 'trusted.$name' failed"
7407                 fi
7408
7409                 # Try to remove the xattr from $file1. We don't care if this
7410                 # appears to succeed or fail, we just don't want there to be
7411                 # any changes or crashes.
7412                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7413         done
7414
7415         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
7416         then
7417                 name="lfsck_ns"
7418                 # Try to copy xattr from $file0 to $file1.
7419                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7420
7421                 setfattr --name=trusted.$name --value="$value" $file1 ||
7422                         error "setxattr 'trusted.$name' failed"
7423
7424                 # Try to set a garbage xattr.
7425                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7426
7427                 setfattr --name=trusted.$name --value="$value" $file1 ||
7428                         error "setxattr 'trusted.$name' failed"
7429
7430                 # Try to remove the xattr from $file1. We don't care if this
7431                 # appears to succeed or fail, we just don't want there to be
7432                 # any changes or crashes.
7433                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7434         fi
7435
7436         # Get 'after' xattrs of file1.
7437         getfattr --absolute-names --dump --match=- $file1 > $xattr1
7438
7439         if ! diff $xattr0 $xattr1; then
7440                 error "before and after xattrs of '$file1' differ"
7441         fi
7442
7443         rm -rf $file0 $file1 $xattr0 $xattr1
7444
7445         return 0
7446 }
7447 run_test 102n "silently ignore setxattr on internal trusted xattrs"
7448
7449 test_102p() { # LU-4703 setxattr did not check ownership
7450         local testfile=$DIR/$tfile
7451
7452         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
7453                 skip "MDS needs to be at least 2.5.56" && return
7454
7455         touch $testfile
7456
7457         echo "setfacl as user..."
7458         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
7459         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
7460
7461         echo "setfattr as user..."
7462         setfacl -m "u:$RUNAS_ID:---" $testfile
7463         $RUNAS setfattr -x system.posix_acl_access $testfile
7464         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
7465 }
7466 run_test 102p "check setxattr(2) correctly fails without permission"
7467
7468 test_102q() {
7469         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
7470                 skip "MDS needs to be at least 2.6.92" && return
7471         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
7472 }
7473 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
7474
7475 test_102r() {
7476         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
7477                 skip "MDS needs to be at least 2.6.93" && return
7478         touch $DIR/$tfile || error "touch"
7479         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
7480         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
7481         rm $DIR/$tfile || error "rm"
7482
7483         #normal directory
7484         mkdir -p $DIR/$tdir || error "mkdir"
7485         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7486         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7487         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7488                 error "$testfile error deleting user.author1"
7489         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7490                 grep "user.$(basename $tdir)" &&
7491                 error "$tdir did not delete user.$(basename $tdir)"
7492         rmdir $DIR/$tdir || error "rmdir"
7493
7494         #striped directory
7495         test_mkdir $DIR/$tdir
7496         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7497         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7498         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7499                 error "$testfile error deleting user.author1"
7500         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7501                 grep "user.$(basename $tdir)" &&
7502                 error "$tdir did not delete user.$(basename $tdir)"
7503         rmdir $DIR/$tdir || error "rm striped dir"
7504 }
7505 run_test 102r "set EAs with empty values"
7506
7507 run_acl_subtest()
7508 {
7509     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
7510     return $?
7511 }
7512
7513 test_103a() {
7514         [ "$UID" != 0 ] && skip_env "must run as root" && return
7515         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
7516                 skip "must have acl enabled" && return
7517         [ -z "$(which setfacl 2>/dev/null)" ] &&
7518                 skip_env "could not find setfacl" && return
7519         $GSS && skip "could not run under gss" && return
7520         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7521
7522         gpasswd -a daemon bin                           # LU-5641
7523         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
7524
7525         declare -a identity_old
7526
7527         for num in $(seq $MDSCOUNT); do
7528                 switch_identity $num true || identity_old[$num]=$?
7529         done
7530
7531         SAVE_UMASK=$(umask)
7532         umask 0022
7533         mkdir -p $DIR/$tdir
7534         cd $DIR/$tdir
7535
7536         echo "performing cp ..."
7537         run_acl_subtest cp || error "run_acl_subtest cp failed"
7538         echo "performing getfacl-noacl..."
7539         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
7540         echo "performing misc..."
7541         run_acl_subtest misc || error  "misc test failed"
7542         echo "performing permissions..."
7543         run_acl_subtest permissions || error "permissions failed"
7544         # LU-1482 mdd: Setting xattr are properly checked with and without ACLs
7545         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.8.55) -o \
7546              \( $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6) -a \
7547              $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.29) \) ]
7548         then
7549                 echo "performing permissions xattr..."
7550                 run_acl_subtest permissions_xattr ||
7551                         error "permissions_xattr failed"
7552         fi
7553         echo "performing setfacl..."
7554         run_acl_subtest setfacl || error  "setfacl test failed"
7555
7556         # inheritance test got from HP
7557         echo "performing inheritance..."
7558         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
7559         chmod +x make-tree || error "chmod +x failed"
7560         run_acl_subtest inheritance || error "inheritance test failed"
7561         rm -f make-tree
7562
7563         echo "LU-974 ignore umask when acl is enabled..."
7564         run_acl_subtest 974 || error "LU-974 umask test failed"
7565         if [ $MDSCOUNT -ge 2 ]; then
7566                 run_acl_subtest 974_remote ||
7567                         error "LU-974 umask test failed under remote dir"
7568         fi
7569
7570         echo "LU-2561 newly created file is same size as directory..."
7571         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
7572                 run_acl_subtest 2561 || error "LU-2561 test failed"
7573         else
7574                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
7575         fi
7576
7577         run_acl_subtest 4924 || error "LU-4924 test failed"
7578
7579         cd $SAVE_PWD
7580         umask $SAVE_UMASK
7581
7582         for num in $(seq $MDSCOUNT); do
7583                 if [ "${identity_old[$num]}" = 1 ]; then
7584                         switch_identity $num false || identity_old[$num]=$?
7585                 fi
7586         done
7587 }
7588 run_test 103a "acl test ========================================="
7589
7590 test_103c() {
7591         mkdir -p $DIR/$tdir
7592         cp -rp $DIR/$tdir $DIR/$tdir.bak
7593
7594         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
7595                 error "$DIR/$tdir shouldn't contain default ACL"
7596         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
7597                 error "$DIR/$tdir.bak shouldn't contain default ACL"
7598         true
7599 }
7600 run_test 103c "'cp -rp' won't set empty acl"
7601
7602 test_104a() {
7603         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7604         touch $DIR/$tfile
7605         lfs df || error "lfs df failed"
7606         lfs df -ih || error "lfs df -ih failed"
7607         lfs df -h $DIR || error "lfs df -h $DIR failed"
7608         lfs df -i $DIR || error "lfs df -i $DIR failed"
7609         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
7610         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
7611
7612         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
7613         lctl --device %$OSC deactivate
7614         lfs df || error "lfs df with deactivated OSC failed"
7615         lctl --device %$OSC activate
7616         # wait the osc back to normal
7617         wait_osc_import_state client ost FULL
7618
7619         lfs df || error "lfs df with reactivated OSC failed"
7620         rm -f $DIR/$tfile
7621 }
7622 run_test 104a "lfs df [-ih] [path] test ========================="
7623
7624 test_104b() {
7625         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7626         [ $RUNAS_ID -eq $UID ] &&
7627                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
7628         chmod 666 /dev/obd
7629         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
7630                         grep "Permission denied" | wc -l)))
7631         if [ $denied_cnt -ne 0 ]; then
7632                 error "lfs check servers test failed"
7633         fi
7634 }
7635 run_test 104b "$RUNAS lfs check servers test ===================="
7636
7637 test_105a() {
7638         # doesn't work on 2.4 kernels
7639         touch $DIR/$tfile
7640         if $(flock_is_enabled); then
7641                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7642         else
7643                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7644         fi
7645         rm -f $DIR/$tfile
7646 }
7647 run_test 105a "flock when mounted without -o flock test ========"
7648
7649 test_105b() {
7650         touch $DIR/$tfile
7651         if $(flock_is_enabled); then
7652                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7653         else
7654                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7655         fi
7656         rm -f $DIR/$tfile
7657 }
7658 run_test 105b "fcntl when mounted without -o flock test ========"
7659
7660 test_105c() {
7661         touch $DIR/$tfile
7662         if $(flock_is_enabled); then
7663                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7664         else
7665                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7666         fi
7667         rm -f $DIR/$tfile
7668 }
7669 run_test 105c "lockf when mounted without -o flock test"
7670
7671 test_105d() { # bug 15924
7672         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7673         test_mkdir $DIR/$tdir
7674         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7675         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7676         $LCTL set_param fail_loc=0x80000315
7677         flocks_test 2 $DIR/$tdir
7678 }
7679 run_test 105d "flock race (should not freeze) ========"
7680
7681 test_105e() { # bug 22660 && 22040
7682         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7683         touch $DIR/$tfile
7684         flocks_test 3 $DIR/$tfile
7685 }
7686 run_test 105e "Two conflicting flocks from same process"
7687
7688 test_106() { #bug 10921
7689         test_mkdir $DIR/$tdir
7690         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7691         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7692 }
7693 run_test 106 "attempt exec of dir followed by chown of that dir"
7694
7695 test_107() {
7696         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7697         CDIR=`pwd`
7698         cd $DIR
7699
7700         local file=core
7701         rm -f $file
7702
7703         local save_pattern=$(sysctl -n kernel.core_pattern)
7704         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7705         sysctl -w kernel.core_pattern=$file
7706         sysctl -w kernel.core_uses_pid=0
7707
7708         ulimit -c unlimited
7709         sleep 60 &
7710         SLEEPPID=$!
7711
7712         sleep 1
7713
7714         kill -s 11 $SLEEPPID
7715         wait $SLEEPPID
7716         if [ -e $file ]; then
7717                 size=`stat -c%s $file`
7718                 [ $size -eq 0 ] && error "Fail to create core file $file"
7719         else
7720                 error "Fail to create core file $file"
7721         fi
7722         rm -f $file
7723         sysctl -w kernel.core_pattern=$save_pattern
7724         sysctl -w kernel.core_uses_pid=$save_uses_pid
7725         cd $CDIR
7726 }
7727 run_test 107 "Coredump on SIG"
7728
7729 test_110() {
7730         test_mkdir $DIR/$tdir
7731         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255)
7732         $LFS mkdir -c $MDSCOUNT $DIR/$tdir/$(str_repeat 'b' 256) &&
7733                 error "mkdir with 256 char should fail, but did not"
7734         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7735                 error "create with 255 char failed"
7736         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7737                 error "create with 256 char should fail, but did not"
7738
7739         ls -l $DIR/$tdir
7740         rm -rf $DIR/$tdir
7741 }
7742 run_test 110 "filename length checking"
7743
7744 #
7745 # Purpose: To verify dynamic thread (OSS) creation.
7746 #
7747 test_115() {
7748         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7749         remote_ost_nodsh && skip "remote OST with nodsh" && return
7750
7751         # Lustre does not stop service threads once they are started.
7752         # Reset number of running threads to default.
7753         stopall
7754         setupall
7755
7756         local OSTIO_pre
7757         local save_params="$TMP/sanity-$TESTNAME.parameters"
7758
7759         # Get ll_ost_io count before I/O
7760         OSTIO_pre=$(do_facet ost1 \
7761                 "$LCTL get_param ost.OSS.ost_io.threads_started | cut -d= -f2")
7762         # Exit if lustre is not running (ll_ost_io not running).
7763         [ -z "$OSTIO_pre" ] && error "no OSS threads"
7764
7765         echo "Starting with $OSTIO_pre threads"
7766         local thread_max=$((OSTIO_pre * 2))
7767         local rpc_in_flight=$((thread_max * 2))
7768         # Number of I/O Process proposed to be started.
7769         local nfiles
7770         local facets=$(get_facets OST)
7771
7772         save_lustre_params client "osc.*OST*.max_rpcs_in_flight" > $save_params
7773         save_lustre_params $facets "ost.OSS.ost_io.threads_max" >> $save_params
7774
7775         # Set in_flight to $rpc_in_flight
7776         $LCTL set_param osc.*OST*.max_rpcs_in_flight=$rpc_in_flight ||
7777                 error "Failed to set max_rpcs_in_flight to $rpc_in_flight"
7778         nfiles=${rpc_in_flight}
7779         # Set ost thread_max to $thread_max
7780         do_facet ost1 "$LCTL set_param ost.OSS.ost_io.threads_max=$thread_max"
7781
7782         # 5 Minutes should be sufficient for max number of OSS
7783         # threads(thread_max) to be created.
7784         local timeout=300
7785
7786         # Start I/O.
7787         local WTL=${WTL:-"$LUSTRE/tests/write_time_limit"}
7788         test_mkdir $DIR/$tdir
7789         for i in $(seq $nfiles); do
7790                 local file=$DIR/$tdir/${tfile}-$i
7791                 $LFS setstripe -c -1 -i 0 $file
7792                 ($WTL $file $timeout)&
7793         done
7794
7795         # I/O Started - Wait for thread_started to reach thread_max or report
7796         # error if thread_started is more than thread_max.
7797         echo "Waiting for thread_started to reach thread_max"
7798         local thread_started=0
7799         local end_time=$((SECONDS + timeout))
7800
7801         while [ $SECONDS -le $end_time ] ; do
7802                 echo -n "."
7803                 # Get ost i/o thread_started count.
7804                 thread_started=$(do_facet ost1 \
7805                         "$LCTL get_param \
7806                         ost.OSS.ost_io.threads_started | cut -d= -f2")
7807                 # Break out if thread_started is equal/greater than thread_max
7808                 if [[ $thread_started -ge $thread_max ]]; then
7809                         echo ll_ost_io thread_started $thread_started, \
7810                                 equal/greater than thread_max $thread_max
7811                         break
7812                 fi
7813                 sleep 1
7814         done
7815
7816         # Cleanup - We have the numbers, Kill i/o jobs if running.
7817         jobcount=($(jobs -p))
7818         for i in $(seq 0 $((${#jobcount[@]}-1)))
7819         do
7820                 kill -9 ${jobcount[$i]}
7821                 if [ $? -ne 0 ] ; then
7822                         echo Warning: \
7823                         Failed to Kill \'WTL\(I/O\)\' with pid ${jobcount[$i]}
7824                 fi
7825         done
7826
7827         # Cleanup files left by WTL binary.
7828         for i in $(seq $nfiles); do
7829                 local file=$DIR/$tdir/${tfile}-$i
7830                 rm -rf $file
7831                 if [ $? -ne 0 ] ; then
7832                         echo "Warning: Failed to delete file $file"
7833                 fi
7834         done
7835
7836         restore_lustre_params <$save_params
7837         rm -f $save_params || echo "Warning: delete file '$save_params' failed"
7838
7839         # Error out if no new thread has started or Thread started is greater
7840         # than thread max.
7841         if [[ $thread_started -le $OSTIO_pre ||
7842                         $thread_started -gt $thread_max ]]; then
7843                 error "ll_ost_io: thread_started $thread_started" \
7844                       "OSTIO_pre $OSTIO_pre, thread_max $thread_max." \
7845                       "No new thread started or thread started greater " \
7846                       "than thread_max."
7847         fi
7848 }
7849 run_test 115 "verify dynamic thread creation===================="
7850
7851 free_min_max () {
7852         wait_delete_completed
7853         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7854         echo "OST kbytes available: ${AVAIL[@]}"
7855         MAXV=${AVAIL[0]}
7856         MAXI=0
7857         MINV=${AVAIL[0]}
7858         MINI=0
7859         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7860                 #echo OST $i: ${AVAIL[i]}kb
7861                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7862                         MAXV=${AVAIL[i]}
7863                         MAXI=$i
7864                 fi
7865                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7866                         MINV=${AVAIL[i]}
7867                         MINI=$i
7868                 fi
7869         done
7870         echo "Min free space: OST $MINI: $MINV"
7871         echo "Max free space: OST $MAXI: $MAXV"
7872 }
7873
7874 test_116a() { # was previously test_116()
7875         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7876         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7877
7878         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7879
7880         echo -n "Free space priority "
7881         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7882                 head -n1
7883         declare -a AVAIL
7884         free_min_max
7885
7886         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7887         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7888                 && return
7889         trap simple_cleanup_common EXIT
7890
7891
7892         # Check if we need to generate uneven OSTs
7893         test_mkdir -p $DIR/$tdir/OST${MINI}
7894         local FILL=$((MINV / 4))
7895         local DIFF=$((MAXV - MINV))
7896         local DIFF2=$((DIFF * 100 / MINV))
7897
7898         local threshold=$(do_facet $SINGLEMDS \
7899                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7900         threshold=${threshold%%%}
7901         echo -n "Check for uneven OSTs: "
7902         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7903
7904         if [[ $DIFF2 -gt $threshold ]]; then
7905                 echo "ok"
7906                 echo "Don't need to fill OST$MINI"
7907         else
7908                 # generate uneven OSTs. Write 2% over the QOS threshold value
7909                 echo "no"
7910                 DIFF=$((threshold - DIFF2 + 2))
7911                 DIFF2=$((MINV * DIFF / 100))
7912                 echo "Fill $DIFF% remaining space in OST$MINI with ${DIFF2}KB"
7913                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7914                         error "setstripe failed"
7915                 DIFF=$((DIFF2 / 2048))
7916                 i=0
7917                 while [ $i -lt $DIFF ]; do
7918                         i=$((i + 1))
7919                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7920                                 bs=2M count=1 2>/dev/null
7921                         echo -n .
7922                 done
7923                 echo .
7924                 sync
7925                 sleep_maxage
7926                 free_min_max
7927         fi
7928
7929         DIFF=$((MAXV - MINV))
7930         DIFF2=$((DIFF * 100 / MINV))
7931         echo -n "diff=$DIFF=$DIFF2% must be > $threshold% for QOS mode..."
7932         if [ $DIFF2 -gt $threshold ]; then
7933                 echo "ok"
7934         else
7935                 echo "failed - QOS mode won't be used"
7936                 skip "QOS imbalance criteria not met"
7937                 simple_cleanup_common
7938                 return
7939         fi
7940
7941         MINI1=$MINI
7942         MINV1=$MINV
7943         MAXI1=$MAXI
7944         MAXV1=$MAXV
7945
7946         # now fill using QOS
7947         $SETSTRIPE -c 1 $DIR/$tdir
7948         FILL=$((FILL / 200))
7949         if [ $FILL -gt 600 ]; then
7950                 FILL=600
7951         fi
7952         echo "writing $FILL files to QOS-assigned OSTs"
7953         i=0
7954         while [ $i -lt $FILL ]; do
7955                 i=$((i + 1))
7956                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7957                         count=1 2>/dev/null
7958                 echo -n .
7959         done
7960         echo "wrote $i 200k files"
7961         sync
7962         sleep_maxage
7963
7964         echo "Note: free space may not be updated, so measurements might be off"
7965         free_min_max
7966         DIFF2=$((MAXV - MINV))
7967         echo "free space delta: orig $DIFF final $DIFF2"
7968         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7969         DIFF=$((MINV1 - ${AVAIL[$MINI1]}))
7970         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7971         DIFF2=$((MAXV1 - ${AVAIL[$MAXI1]}))
7972         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7973         if [[ $DIFF -gt 0 ]]; then
7974                 FILL=$((DIFF2 * 100 / DIFF - 100))
7975                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7976         fi
7977
7978         # Figure out which files were written where
7979         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7980                awk '/'$MINI1': / {print $2; exit}')
7981         echo $UUID
7982         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7983         echo "$MINC files created on smaller OST $MINI1"
7984         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7985                awk '/'$MAXI1': / {print $2; exit}')
7986         echo $UUID
7987         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7988         echo "$MAXC files created on larger OST $MAXI1"
7989         if [[ $MINC -gt 0 ]]; then
7990                 FILL=$((MAXC * 100 / MINC - 100))
7991                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7992         fi
7993         [[ $MAXC -gt $MINC ]] ||
7994                 error_ignore LU-9 "stripe QOS didn't balance free space"
7995         simple_cleanup_common
7996 }
7997 run_test 116a "stripe QOS: free space balance ==================="
7998
7999 test_116b() { # LU-2093
8000         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8001         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8002
8003 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
8004         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
8005                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
8006         [ -z "$old_rr" ] && skip "no QOS" && return 0
8007         do_facet $SINGLEMDS lctl set_param \
8008                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
8009         mkdir -p $DIR/$tdir
8010         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
8011         createmany -o $DIR/$tdir/f- 20 || error "can't create"
8012         do_facet $SINGLEMDS lctl set_param fail_loc=0
8013         rm -rf $DIR/$tdir
8014         do_facet $SINGLEMDS lctl set_param \
8015                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
8016 }
8017 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
8018
8019 test_117() # bug 10891
8020 {
8021         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8022         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
8023         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
8024         lctl set_param fail_loc=0x21e
8025         > $DIR/$tfile || error "truncate failed"
8026         lctl set_param fail_loc=0
8027         echo "Truncate succeeded."
8028         rm -f $DIR/$tfile
8029 }
8030 run_test 117 "verify osd extend =========="
8031
8032 NO_SLOW_RESENDCOUNT=4
8033 export OLD_RESENDCOUNT=""
8034 set_resend_count () {
8035         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
8036         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
8037         lctl set_param -n $PROC_RESENDCOUNT $1
8038         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
8039 }
8040
8041 # for reduce test_118* time (b=14842)
8042 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
8043
8044 # Reset async IO behavior after error case
8045 reset_async() {
8046         FILE=$DIR/reset_async
8047
8048         # Ensure all OSCs are cleared
8049         $SETSTRIPE -c -1 $FILE
8050         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
8051         sync
8052         rm $FILE
8053 }
8054
8055 test_118a() #bug 11710
8056 {
8057         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8058         reset_async
8059
8060         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8061         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8062         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8063
8064         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8065                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8066                 return 1;
8067         fi
8068         rm -f $DIR/$tfile
8069 }
8070 run_test 118a "verify O_SYNC works =========="
8071
8072 test_118b()
8073 {
8074         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8075         remote_ost_nodsh && skip "remote OST with nodsh" && return
8076
8077         reset_async
8078
8079         #define OBD_FAIL_SRV_ENOENT 0x217
8080         set_nodes_failloc "$(osts_nodes)" 0x217
8081         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8082         RC=$?
8083         set_nodes_failloc "$(osts_nodes)" 0
8084         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8085         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8086                     grep -c writeback)
8087
8088         if [[ $RC -eq 0 ]]; then
8089                 error "Must return error due to dropped pages, rc=$RC"
8090                 return 1;
8091         fi
8092
8093         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8094                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8095                 return 1;
8096         fi
8097
8098         echo "Dirty pages not leaked on ENOENT"
8099
8100         # Due to the above error the OSC will issue all RPCs syncronously
8101         # until a subsequent RPC completes successfully without error.
8102         $MULTIOP $DIR/$tfile Ow4096yc
8103         rm -f $DIR/$tfile
8104
8105         return 0
8106 }
8107 run_test 118b "Reclaim dirty pages on fatal error =========="
8108
8109 test_118c()
8110 {
8111         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8112
8113         # for 118c, restore the original resend count, LU-1940
8114         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
8115                                 set_resend_count $OLD_RESENDCOUNT
8116         remote_ost_nodsh && skip "remote OST with nodsh" && return
8117
8118         reset_async
8119
8120         #define OBD_FAIL_OST_EROFS               0x216
8121         set_nodes_failloc "$(osts_nodes)" 0x216
8122
8123         # multiop should block due to fsync until pages are written
8124         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8125         MULTIPID=$!
8126         sleep 1
8127
8128         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
8129                 error "Multiop failed to block on fsync, pid=$MULTIPID"
8130         fi
8131
8132         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8133                     grep -c writeback)
8134         if [[ $WRITEBACK -eq 0 ]]; then
8135                 error "No page in writeback, writeback=$WRITEBACK"
8136         fi
8137
8138         set_nodes_failloc "$(osts_nodes)" 0
8139         wait $MULTIPID
8140         RC=$?
8141         if [[ $RC -ne 0 ]]; then
8142                 error "Multiop fsync failed, rc=$RC"
8143         fi
8144
8145         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8146         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8147                     grep -c writeback)
8148         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8149                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8150         fi
8151
8152         rm -f $DIR/$tfile
8153         echo "Dirty pages flushed via fsync on EROFS"
8154         return 0
8155 }
8156 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
8157
8158 # continue to use small resend count to reduce test_118* time (b=14842)
8159 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
8160
8161 test_118d()
8162 {
8163         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8164         remote_ost_nodsh && skip "remote OST with nodsh" && return
8165
8166         reset_async
8167
8168         #define OBD_FAIL_OST_BRW_PAUSE_BULK
8169         set_nodes_failloc "$(osts_nodes)" 0x214
8170         # multiop should block due to fsync until pages are written
8171         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8172         MULTIPID=$!
8173         sleep 1
8174
8175         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
8176                 error "Multiop failed to block on fsync, pid=$MULTIPID"
8177         fi
8178
8179         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8180                     grep -c writeback)
8181         if [[ $WRITEBACK -eq 0 ]]; then
8182                 error "No page in writeback, writeback=$WRITEBACK"
8183         fi
8184
8185         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
8186         set_nodes_failloc "$(osts_nodes)" 0
8187
8188         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8189         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8190                     grep -c writeback)
8191         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8192                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8193         fi
8194
8195         rm -f $DIR/$tfile
8196         echo "Dirty pages gaurenteed flushed via fsync"
8197         return 0
8198 }
8199 run_test 118d "Fsync validation inject a delay of the bulk =========="
8200
8201 test_118f() {
8202         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8203         reset_async
8204
8205         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
8206         lctl set_param fail_loc=0x8000040a
8207
8208         # Should simulate EINVAL error which is fatal
8209         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8210         RC=$?
8211         if [[ $RC -eq 0 ]]; then
8212                 error "Must return error due to dropped pages, rc=$RC"
8213         fi
8214
8215         lctl set_param fail_loc=0x0
8216
8217         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8218         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8219         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8220                     grep -c writeback)
8221         if [[ $LOCKED -ne 0 ]]; then
8222                 error "Locked pages remain in cache, locked=$LOCKED"
8223         fi
8224
8225         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8226                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8227         fi
8228
8229         rm -f $DIR/$tfile
8230         echo "No pages locked after fsync"
8231
8232         reset_async
8233         return 0
8234 }
8235 run_test 118f "Simulate unrecoverable OSC side error =========="
8236
8237 test_118g() {
8238         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8239         reset_async
8240
8241         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
8242         lctl set_param fail_loc=0x406
8243
8244         # simulate local -ENOMEM
8245         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8246         RC=$?
8247
8248         lctl set_param fail_loc=0
8249         if [[ $RC -eq 0 ]]; then
8250                 error "Must return error due to dropped pages, rc=$RC"
8251         fi
8252
8253         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8254         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8255         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8256                         grep -c writeback)
8257         if [[ $LOCKED -ne 0 ]]; then
8258                 error "Locked pages remain in cache, locked=$LOCKED"
8259         fi
8260
8261         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8262                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8263         fi
8264
8265         rm -f $DIR/$tfile
8266         echo "No pages locked after fsync"
8267
8268         reset_async
8269         return 0
8270 }
8271 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
8272
8273 test_118h() {
8274         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8275         remote_ost_nodsh && skip "remote OST with nodsh" && return
8276
8277         reset_async
8278
8279         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8280         set_nodes_failloc "$(osts_nodes)" 0x20e
8281         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
8282         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8283         RC=$?
8284
8285         set_nodes_failloc "$(osts_nodes)" 0
8286         if [[ $RC -eq 0 ]]; then
8287                 error "Must return error due to dropped pages, rc=$RC"
8288         fi
8289
8290         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8291         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8292         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8293                     grep -c writeback)
8294         if [[ $LOCKED -ne 0 ]]; then
8295                 error "Locked pages remain in cache, locked=$LOCKED"
8296         fi
8297
8298         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8299                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8300         fi
8301
8302         rm -f $DIR/$tfile
8303         echo "No pages locked after fsync"
8304
8305         return 0
8306 }
8307 run_test 118h "Verify timeout in handling recoverables errors  =========="
8308
8309 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
8310
8311 test_118i() {
8312         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8313         remote_ost_nodsh && skip "remote OST with nodsh" && return
8314
8315         reset_async
8316
8317         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8318         set_nodes_failloc "$(osts_nodes)" 0x20e
8319
8320         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
8321         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8322         PID=$!
8323         sleep 5
8324         set_nodes_failloc "$(osts_nodes)" 0
8325
8326         wait $PID
8327         RC=$?
8328         if [[ $RC -ne 0 ]]; then
8329                 error "got error, but should be not, rc=$RC"
8330         fi
8331
8332         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8333         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8334         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8335         if [[ $LOCKED -ne 0 ]]; then
8336                 error "Locked pages remain in cache, locked=$LOCKED"
8337         fi
8338
8339         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8340                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8341         fi
8342
8343         rm -f $DIR/$tfile
8344         echo "No pages locked after fsync"
8345
8346         return 0
8347 }
8348 run_test 118i "Fix error before timeout in recoverable error  =========="
8349
8350 [ "$SLOW" = "no" ] && set_resend_count 4
8351
8352 test_118j() {
8353         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8354         remote_ost_nodsh && skip "remote OST with nodsh" && return
8355
8356         reset_async
8357
8358         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
8359         set_nodes_failloc "$(osts_nodes)" 0x220
8360
8361         # return -EIO from OST
8362         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8363         RC=$?
8364         set_nodes_failloc "$(osts_nodes)" 0x0
8365         if [[ $RC -eq 0 ]]; then
8366                 error "Must return error due to dropped pages, rc=$RC"
8367         fi
8368
8369         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8370         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8371         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8372         if [[ $LOCKED -ne 0 ]]; then
8373                 error "Locked pages remain in cache, locked=$LOCKED"
8374         fi
8375
8376         # in recoverable error on OST we want resend and stay until it finished
8377         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8378                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8379         fi
8380
8381         rm -f $DIR/$tfile
8382         echo "No pages locked after fsync"
8383
8384         return 0
8385 }
8386 run_test 118j "Simulate unrecoverable OST side error =========="
8387
8388 test_118k()
8389 {
8390         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8391         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
8392
8393         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8394         set_nodes_failloc "$(osts_nodes)" 0x20e
8395         test_mkdir $DIR/$tdir
8396
8397         for ((i=0;i<10;i++)); do
8398                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
8399                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
8400                 SLEEPPID=$!
8401                 sleep 0.500s
8402                 kill $SLEEPPID
8403                 wait $SLEEPPID
8404         done
8405
8406         set_nodes_failloc "$(osts_nodes)" 0
8407         rm -rf $DIR/$tdir
8408 }
8409 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
8410
8411 test_118l()
8412 {
8413         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8414         # LU-646
8415         test_mkdir $DIR/$tdir
8416         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
8417         rm -rf $DIR/$tdir
8418 }
8419 run_test 118l "fsync dir"
8420
8421 test_118m() # LU-3066
8422 {
8423         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8424         test_mkdir $DIR/$tdir
8425         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
8426         rm -rf $DIR/$tdir
8427 }
8428 run_test 118m "fdatasync dir ========="
8429
8430 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
8431
8432 test_119a() # bug 11737
8433 {
8434         BSIZE=$((512 * 1024))
8435         directio write $DIR/$tfile 0 1 $BSIZE
8436         # We ask to read two blocks, which is more than a file size.
8437         # directio will indicate an error when requested and actual
8438         # sizes aren't equeal (a normal situation in this case) and
8439         # print actual read amount.
8440         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
8441         if [ "$NOB" != "$BSIZE" ]; then
8442                 error "read $NOB bytes instead of $BSIZE"
8443         fi
8444         rm -f $DIR/$tfile
8445 }
8446 run_test 119a "Short directIO read must return actual read amount"
8447
8448 test_119b() # bug 11737
8449 {
8450         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
8451
8452         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
8453         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
8454         sync
8455         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
8456                 error "direct read failed"
8457         rm -f $DIR/$tfile
8458 }
8459 run_test 119b "Sparse directIO read must return actual read amount"
8460
8461 test_119c() # bug 13099
8462 {
8463         BSIZE=1048576
8464         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
8465         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
8466         rm -f $DIR/$tfile
8467 }
8468 run_test 119c "Testing for direct read hitting hole"
8469
8470 test_119d() # bug 15950
8471 {
8472         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8473         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
8474         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
8475         BSIZE=1048576
8476         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
8477         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
8478         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
8479         lctl set_param fail_loc=0x40d
8480         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
8481         pid_dio=$!
8482         sleep 1
8483         cat $DIR/$tfile > /dev/null &
8484         lctl set_param fail_loc=0
8485         pid_reads=$!
8486         wait $pid_dio
8487         log "the DIO writes have completed, now wait for the reads (should not block very long)"
8488         sleep 2
8489         [ -n "`ps h -p $pid_reads -o comm`" ] && \
8490         error "the read rpcs have not completed in 2s"
8491         rm -f $DIR/$tfile
8492         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
8493 }
8494 run_test 119d "The DIO path should try to send a new rpc once one is completed"
8495
8496 test_120a() {
8497         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8498         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8499         test_mkdir $DIR/$tdir
8500         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
8501                 { skip "no early lock cancel on server"; return 0; }
8502
8503         lru_resize_disable mdc
8504         lru_resize_disable osc
8505         cancel_lru_locks mdc
8506         # asynchronous object destroy at MDT could cause bl ast to client
8507         cancel_lru_locks osc
8508
8509         stat $DIR/$tdir > /dev/null
8510         can1=$(do_facet $SINGLEMDS \
8511                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8512                awk '/ldlm_cancel/ {print $2}')
8513         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8514                awk '/ldlm_bl_callback/ {print $2}')
8515         test_mkdir -c1 $DIR/$tdir/d1
8516         can2=$(do_facet $SINGLEMDS \
8517                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8518                awk '/ldlm_cancel/ {print $2}')
8519         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8520                awk '/ldlm_bl_callback/ {print $2}')
8521         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8522         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8523         lru_resize_enable mdc
8524         lru_resize_enable osc
8525 }
8526 run_test 120a "Early Lock Cancel: mkdir test"
8527
8528 test_120b() {
8529         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8530         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8531         test_mkdir $DIR/$tdir
8532         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
8533                 { skip "no early lock cancel on server"; return 0; }
8534         lru_resize_disable mdc
8535         lru_resize_disable osc
8536         cancel_lru_locks mdc
8537         stat $DIR/$tdir > /dev/null
8538         can1=$(do_facet $SINGLEMDS \
8539                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8540                awk '/ldlm_cancel/ {print $2}')
8541         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8542                awk '/ldlm_bl_callback/ {print $2}')
8543         touch $DIR/$tdir/f1
8544         can2=$(do_facet $SINGLEMDS \
8545                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8546                awk '/ldlm_cancel/ {print $2}')
8547         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8548                awk '/ldlm_bl_callback/ {print $2}')
8549         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8550         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8551         lru_resize_enable mdc
8552         lru_resize_enable osc
8553 }
8554 run_test 120b "Early Lock Cancel: create test"
8555
8556 test_120c() {
8557         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8558         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8559         test_mkdir -c1 $DIR/$tdir
8560         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
8561                 { skip "no early lock cancel on server"; return 0; }
8562         lru_resize_disable mdc
8563         lru_resize_disable osc
8564         test_mkdir -c1 $DIR/$tdir/d1
8565         test_mkdir -c1 $DIR/$tdir/d2
8566         touch $DIR/$tdir/d1/f1
8567         cancel_lru_locks mdc
8568         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
8569         can1=$(do_facet $SINGLEMDS \
8570                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8571                awk '/ldlm_cancel/ {print $2}')
8572         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8573                awk '/ldlm_bl_callback/ {print $2}')
8574         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8575         can2=$(do_facet $SINGLEMDS \
8576                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8577                awk '/ldlm_cancel/ {print $2}')
8578         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8579                awk '/ldlm_bl_callback/ {print $2}')
8580         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8581         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8582         lru_resize_enable mdc
8583         lru_resize_enable osc
8584 }
8585 run_test 120c "Early Lock Cancel: link test"
8586
8587 test_120d() {
8588         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8589         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8590         test_mkdir -c1 $DIR/$tdir
8591         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
8592                 { skip "no early lock cancel on server"; return 0; }
8593         lru_resize_disable mdc
8594         lru_resize_disable osc
8595         touch $DIR/$tdir
8596         cancel_lru_locks mdc
8597         stat $DIR/$tdir > /dev/null
8598         can1=$(do_facet $SINGLEMDS \
8599                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8600                awk '/ldlm_cancel/ {print $2}')
8601         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8602                awk '/ldlm_bl_callback/ {print $2}')
8603         chmod a+x $DIR/$tdir
8604         can2=$(do_facet $SINGLEMDS \
8605                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8606                awk '/ldlm_cancel/ {print $2}')
8607         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8608                awk '/ldlm_bl_callback/ {print $2}')
8609         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8610         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8611         lru_resize_enable mdc
8612         lru_resize_enable osc
8613 }
8614 run_test 120d "Early Lock Cancel: setattr test"
8615
8616 test_120e() {
8617         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8618         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
8619                 { skip "no early lock cancel on server"; return 0; }
8620         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8621         local dlmtrace_set=false
8622
8623         test_mkdir -c1 $DIR/$tdir
8624         lru_resize_disable mdc
8625         lru_resize_disable osc
8626         ! $LCTL get_param debug | grep -q dlmtrace &&
8627                 $LCTL set_param debug=+dlmtrace && dlmtrace_set=true
8628         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
8629         cancel_lru_locks mdc
8630         cancel_lru_locks osc
8631         dd if=$DIR/$tdir/f1 of=/dev/null
8632         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
8633         # XXX client can not do early lock cancel of OST lock
8634         # during unlink (LU-4206), so cancel osc lock now.
8635         sleep 2
8636         cancel_lru_locks osc
8637         can1=$(do_facet $SINGLEMDS \
8638                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8639                awk '/ldlm_cancel/ {print $2}')
8640         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8641                awk '/ldlm_bl_callback/ {print $2}')
8642         unlink $DIR/$tdir/f1
8643         sleep 5
8644         can2=$(do_facet $SINGLEMDS \
8645                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8646                awk '/ldlm_cancel/ {print $2}')
8647         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8648                awk '/ldlm_bl_callback/ {print $2}')
8649         [ $can1 -ne $can2 ] && error "$((can2 - can1)) cancel RPC occured" &&
8650                 $LCTL dk $TMP/cancel.debug.txt
8651         [ $blk1 -ne $blk2 ] && error "$((blk2 - blk1)) blocking RPC occured" &&
8652                 $LCTL dk $TMP/blocking.debug.txt
8653         $dlmtrace_set && $LCTL set_param debug=-dlmtrace
8654         lru_resize_enable mdc
8655         lru_resize_enable osc
8656 }
8657 run_test 120e "Early Lock Cancel: unlink test"
8658
8659 test_120f() {
8660         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8661         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
8662                 { skip "no early lock cancel on server"; return 0; }
8663         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8664         test_mkdir -c1 $DIR/$tdir
8665         lru_resize_disable mdc
8666         lru_resize_disable osc
8667         test_mkdir -c1 $DIR/$tdir/d1
8668         test_mkdir -c1 $DIR/$tdir/d2
8669         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
8670         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
8671         cancel_lru_locks mdc
8672         cancel_lru_locks osc
8673         dd if=$DIR/$tdir/d1/f1 of=/dev/null
8674         dd if=$DIR/$tdir/d2/f2 of=/dev/null
8675         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
8676         # XXX client can not do early lock cancel of OST lock
8677         # during rename (LU-4206), so cancel osc lock now.
8678         sleep 2
8679         cancel_lru_locks osc
8680         can1=$(do_facet $SINGLEMDS \
8681                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8682                awk '/ldlm_cancel/ {print $2}')
8683         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8684                awk '/ldlm_bl_callback/ {print $2}')
8685         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8686         sleep 5
8687         can2=$(do_facet $SINGLEMDS \
8688                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8689                awk '/ldlm_cancel/ {print $2}')
8690         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8691                awk '/ldlm_bl_callback/ {print $2}')
8692         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8693         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8694         lru_resize_enable mdc
8695         lru_resize_enable osc
8696 }
8697 run_test 120f "Early Lock Cancel: rename test"
8698
8699 test_120g() {
8700         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8701         $LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_cancel ||
8702                 { skip "no early lock cancel on server"; return 0; }
8703         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8704         lru_resize_disable mdc
8705         lru_resize_disable osc
8706         count=10000
8707         echo create $count files
8708         test_mkdir $DIR/$tdir
8709         cancel_lru_locks mdc
8710         cancel_lru_locks osc
8711         t0=$(date +%s)
8712
8713         can0=$(do_facet $SINGLEMDS \
8714                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8715                awk '/ldlm_cancel/ {print $2}')
8716         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8717                awk '/ldlm_bl_callback/ {print $2}')
8718         createmany -o $DIR/$tdir/f $count
8719         sync
8720         can1=$(do_facet $SINGLEMDS \
8721                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8722                awk '/ldlm_cancel/ {print $2}')
8723         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8724                awk '/ldlm_bl_callback/ {print $2}')
8725         t1=$(date +%s)
8726         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
8727         echo rm $count files
8728         rm -r $DIR/$tdir
8729         sync
8730         can2=$(do_facet $SINGLEMDS \
8731                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8732                awk '/ldlm_cancel/ {print $2}')
8733         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8734                awk '/ldlm_bl_callback/ {print $2}')
8735         t2=$(date +%s)
8736         echo total: $count removes in $((t2-t1))
8737         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
8738         sleep 2
8739         # wait for commitment of removal
8740         lru_resize_enable mdc
8741         lru_resize_enable osc
8742 }
8743 run_test 120g "Early Lock Cancel: performance test"
8744
8745 test_121() { #bug #10589
8746         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8747         rm -rf $DIR/$tfile
8748         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8749 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8750         lctl set_param fail_loc=0x310
8751         cancel_lru_locks osc > /dev/null
8752         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8753         lctl set_param fail_loc=0
8754         [[ $reads -eq $writes ]] ||
8755                 error "read $reads blocks, must be $writes blocks"
8756 }
8757 run_test 121 "read cancel race ========="
8758
8759 test_123a() { # was test 123, statahead(bug 11401)
8760         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8761         SLOWOK=0
8762         if ! grep -q "processor.*: 1" /proc/cpuinfo; then
8763                 log "testing UP system. Performance may be lower than expected."
8764                 SLOWOK=1
8765         fi
8766
8767         rm -rf $DIR/$tdir
8768         test_mkdir $DIR/$tdir
8769         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8770         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8771         MULT=10
8772         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8773                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8774
8775                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8776                 lctl set_param -n llite.*.statahead_max 0
8777                 lctl get_param llite.*.statahead_max
8778                 cancel_lru_locks mdc
8779                 cancel_lru_locks osc
8780                 stime=`date +%s`
8781                 time ls -l $DIR/$tdir | wc -l
8782                 etime=`date +%s`
8783                 delta=$((etime - stime))
8784                 log "ls $i files without statahead: $delta sec"
8785                 lctl set_param llite.*.statahead_max=$max
8786
8787                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8788                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8789                 cancel_lru_locks mdc
8790                 cancel_lru_locks osc
8791                 stime=`date +%s`
8792                 time ls -l $DIR/$tdir | wc -l
8793                 etime=`date +%s`
8794                 delta_sa=$((etime - stime))
8795                 log "ls $i files with statahead: $delta_sa sec"
8796                 lctl get_param -n llite.*.statahead_stats
8797                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8798
8799                 [[ $swrong -lt $ewrong ]] &&
8800                         log "statahead was stopped, maybe too many locks held!"
8801                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8802
8803                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8804                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8805                     lctl set_param -n llite.*.statahead_max 0
8806                     lctl get_param llite.*.statahead_max
8807                     cancel_lru_locks mdc
8808                     cancel_lru_locks osc
8809                     stime=`date +%s`
8810                     time ls -l $DIR/$tdir | wc -l
8811                     etime=`date +%s`
8812                     delta=$((etime - stime))
8813                     log "ls $i files again without statahead: $delta sec"
8814                     lctl set_param llite.*.statahead_max=$max
8815                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8816                         if [  $SLOWOK -eq 0 ]; then
8817                                 error "ls $i files is slower with statahead!"
8818                         else
8819                                 log "ls $i files is slower with statahead!"
8820                         fi
8821                         break
8822                     fi
8823                 fi
8824
8825                 [ $delta -gt 20 ] && break
8826                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8827                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8828         done
8829         log "ls done"
8830
8831         stime=`date +%s`
8832         rm -r $DIR/$tdir
8833         sync
8834         etime=`date +%s`
8835         delta=$((etime - stime))
8836         log "rm -r $DIR/$tdir/: $delta seconds"
8837         log "rm done"
8838         lctl get_param -n llite.*.statahead_stats
8839 }
8840 run_test 123a "verify statahead work"
8841
8842 test_123b () { # statahead(bug 15027)
8843         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8844         test_mkdir $DIR/$tdir
8845         createmany -o $DIR/$tdir/$tfile-%d 1000
8846
8847         cancel_lru_locks mdc
8848         cancel_lru_locks osc
8849
8850 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8851         lctl set_param fail_loc=0x80000803
8852         ls -lR $DIR/$tdir > /dev/null
8853         log "ls done"
8854         lctl set_param fail_loc=0x0
8855         lctl get_param -n llite.*.statahead_stats
8856         rm -r $DIR/$tdir
8857         sync
8858
8859 }
8860 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8861
8862 test_124a() {
8863         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8864         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
8865                 { skip "no lru resize on server"; return 0; }
8866         local NR=2000
8867         test_mkdir $DIR/$tdir
8868
8869         log "create $NR files at $DIR/$tdir"
8870         createmany -o $DIR/$tdir/f $NR ||
8871                 error "failed to create $NR files in $DIR/$tdir"
8872
8873         cancel_lru_locks mdc
8874         ls -l $DIR/$tdir > /dev/null
8875
8876         local NSDIR=""
8877         local LRU_SIZE=0
8878         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8879                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8880                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8881                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8882                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8883                         log "NSDIR=$NSDIR"
8884                         log "NS=$(basename $NSDIR)"
8885                         break
8886                 fi
8887         done
8888
8889         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8890                 skip "Not enough cached locks created!"
8891                 return 0
8892         fi
8893         log "LRU=$LRU_SIZE"
8894
8895         local SLEEP=30
8896
8897         # We know that lru resize allows one client to hold $LIMIT locks
8898         # for 10h. After that locks begin to be killed by client.
8899         local MAX_HRS=10
8900         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8901         log "LIMIT=$LIMIT"
8902         if [ $LIMIT -lt $LRU_SIZE ]; then
8903             skip "Limit is too small $LIMIT"
8904             return 0
8905         fi
8906
8907         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8908         # killing locks. Some time was spent for creating locks. This means
8909         # that up to the moment of sleep finish we must have killed some of
8910         # them (10-100 locks). This depends on how fast ther were created.
8911         # Many of them were touched in almost the same moment and thus will
8912         # be killed in groups.
8913         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8914
8915         # Use $LRU_SIZE_B here to take into account real number of locks
8916         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8917         local LRU_SIZE_B=$LRU_SIZE
8918         log "LVF=$LVF"
8919         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8920         log "OLD_LVF=$OLD_LVF"
8921         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8922
8923         # Let's make sure that we really have some margin. Client checks
8924         # cached locks every 10 sec.
8925         SLEEP=$((SLEEP+20))
8926         log "Sleep ${SLEEP} sec"
8927         local SEC=0
8928         while ((SEC<$SLEEP)); do
8929                 echo -n "..."
8930                 sleep 5
8931                 SEC=$((SEC+5))
8932                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8933                 echo -n "$LRU_SIZE"
8934         done
8935         echo ""
8936         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8937         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8938
8939         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8940                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8941                 unlinkmany $DIR/$tdir/f $NR
8942                 return
8943         }
8944
8945         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8946         log "unlink $NR files at $DIR/$tdir"
8947         unlinkmany $DIR/$tdir/f $NR
8948 }
8949 run_test 124a "lru resize ======================================="
8950
8951 get_max_pool_limit()
8952 {
8953         local limit=$($LCTL get_param \
8954                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8955         local max=0
8956         for l in $limit; do
8957                 if [[ $l -gt $max ]]; then
8958                         max=$l
8959                 fi
8960         done
8961         echo $max
8962 }
8963
8964 test_124b() {
8965         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8966         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
8967                 { skip "no lru resize on server"; return 0; }
8968
8969         LIMIT=$(get_max_pool_limit)
8970
8971         NR=$(($(default_lru_size)*20))
8972         if [[ $NR -gt $LIMIT ]]; then
8973                 log "Limit lock number by $LIMIT locks"
8974                 NR=$LIMIT
8975         fi
8976
8977         IFree=$(mdsrate_inodes_available)
8978         if [ $IFree -lt $NR ]; then
8979                 log "Limit lock number by $IFree inodes"
8980                 NR=$IFree
8981         fi
8982
8983         lru_resize_disable mdc
8984         test_mkdir -p $DIR/$tdir/disable_lru_resize
8985
8986         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8987         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8988         cancel_lru_locks mdc
8989         stime=`date +%s`
8990         PID=""
8991         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8992         PID="$PID $!"
8993         sleep 2
8994         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8995         PID="$PID $!"
8996         sleep 2
8997         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8998         PID="$PID $!"
8999         wait $PID
9000         etime=`date +%s`
9001         nolruresize_delta=$((etime-stime))
9002         log "ls -la time: $nolruresize_delta seconds"
9003         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
9004         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
9005
9006         lru_resize_enable mdc
9007         test_mkdir -p $DIR/$tdir/enable_lru_resize
9008
9009         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
9010         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
9011         cancel_lru_locks mdc
9012         stime=`date +%s`
9013         PID=""
9014         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9015         PID="$PID $!"
9016         sleep 2
9017         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9018         PID="$PID $!"
9019         sleep 2
9020         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9021         PID="$PID $!"
9022         wait $PID
9023         etime=`date +%s`
9024         lruresize_delta=$((etime-stime))
9025         log "ls -la time: $lruresize_delta seconds"
9026         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
9027
9028         if [ $lruresize_delta -gt $nolruresize_delta ]; then
9029                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
9030         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
9031                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
9032         else
9033                 log "lru resize performs the same with no lru resize"
9034         fi
9035         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
9036 }
9037 run_test 124b "lru resize (performance test) ======================="
9038
9039 test_124c() {
9040         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9041         $LCTL get_param -n mdc.*.connect_flags | grep -q lru_resize ||
9042                 { skip "no lru resize on server"; return 0; }
9043
9044         # cache ununsed locks on client
9045         local nr=100
9046         cancel_lru_locks mdc
9047         test_mkdir $DIR/$tdir
9048         createmany -o $DIR/$tdir/f $nr ||
9049                 error "failed to create $nr files in $DIR/$tdir"
9050         ls -l $DIR/$tdir > /dev/null
9051
9052         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
9053         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9054         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
9055         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
9056         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
9057
9058         # set lru_max_age to 1 sec
9059         $LCTL set_param $nsdir.lru_max_age=1000 # milliseconds
9060         echo "sleep $((recalc_p * 2)) seconds..."
9061         sleep $((recalc_p * 2))
9062
9063         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
9064         # restore lru_max_age
9065         $LCTL set_param -n $nsdir.lru_max_age $max_age
9066         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
9067         unlinkmany $DIR/$tdir/f $nr
9068 }
9069 run_test 124c "LRUR cancel very aged locks"
9070
9071 test_125() { # 13358
9072         $LCTL get_param -n llite.*.client_type | grep -q local ||
9073                 { skip "must run as local client"; return; }
9074         $LCTL get_param -n mdc.*-mdc-*.connect_flags | grep -q acl ||
9075                 { skip "must have acl enabled"; return; }
9076         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9077         test_mkdir $DIR/$tdir
9078         $LFS setstripe -S 65536 -c -1 $DIR/$tdir || error "setstripe failed"
9079         setfacl -R -m u:bin:rwx $DIR/$tdir || error "setfacl $DIR/$tdir failed"
9080         ls -ld $DIR/$tdir || error "cannot access $DIR/$tdir"
9081 }
9082 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
9083
9084 test_126() { # bug 12829/13455
9085         $LCTL get_param -n llite.*.client_type | grep -q local ||
9086                 { skip "must run as local client"; return; }
9087         [ "$UID" != 0 ] && skip_env "$TESTNAME (must run as root)" && return
9088         $GSS && skip "must run as gss disabled" && return
9089
9090         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
9091         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
9092         rm -f $DIR/$tfile
9093         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
9094 }
9095 run_test 126 "check that the fsgid provided by the client is taken into account"
9096
9097 test_127a() { # bug 15521
9098         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9099         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
9100         $LCTL set_param osc.*.stats=0
9101         FSIZE=$((2048 * 1024))
9102         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9103         cancel_lru_locks osc
9104         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
9105
9106         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
9107         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
9108                 echo "got $COUNT $NAME"
9109                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
9110                 eval $NAME=$COUNT || error "Wrong proc format"
9111
9112                 case $NAME in
9113                         read_bytes|write_bytes)
9114                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
9115                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
9116                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
9117                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
9118                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
9119                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
9120                                 error "sumsquare is too small: $SUMSQ"
9121                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
9122                                 error "sumsquare is too big: $SUMSQ"
9123                         ;;
9124                         *) ;;
9125                 esac
9126         done < $DIR/${tfile}.tmp
9127
9128         #check that we actually got some stats
9129         [ "$read_bytes" ] || error "Missing read_bytes stats"
9130         [ "$write_bytes" ] || error "Missing write_bytes stats"
9131         [ "$read_bytes" != 0 ] || error "no read done"
9132         [ "$write_bytes" != 0 ] || error "no write done"
9133 }
9134 run_test 127a "verify the client stats are sane"
9135
9136 test_127b() { # bug LU-333
9137         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9138         $LCTL set_param llite.*.stats=0
9139         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
9140         # perform 2 reads and writes so MAX is different from SUM.
9141         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9142         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9143         cancel_lru_locks osc
9144         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
9145         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
9146
9147         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
9148         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
9149                 echo "got $COUNT $NAME"
9150                 eval $NAME=$COUNT || error "Wrong proc format"
9151
9152         case $NAME in
9153                 read_bytes)
9154                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
9155                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
9156                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
9157                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
9158                         ;;
9159                 write_bytes)
9160                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
9161                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
9162                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
9163                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
9164                         ;;
9165                         *) ;;
9166                 esac
9167         done < $TMP/${tfile}.tmp
9168
9169         #check that we actually got some stats
9170         [ "$read_bytes" ] || error "Missing read_bytes stats"
9171         [ "$write_bytes" ] || error "Missing write_bytes stats"
9172         [ "$read_bytes" != 0 ] || error "no read done"
9173         [ "$write_bytes" != 0 ] || error "no write done"
9174
9175         rm -f $TMP/${tfile}.tmp
9176 }
9177 run_test 127b "verify the llite client stats are sane"
9178
9179 test_128() { # bug 15212
9180         touch $DIR/$tfile
9181         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
9182                 find $DIR/$tfile
9183                 find $DIR/$tfile
9184         EOF
9185
9186         result=$(grep error $TMP/$tfile.log)
9187         rm -f $DIR/$tfile $TMP/$tfile.log
9188         [ -z "$result" ] ||
9189                 error "consecutive find's under interactive lfs failed"
9190 }
9191 run_test 128 "interactive lfs for 2 consecutive find's"
9192
9193 set_dir_limits () {
9194         local mntdev
9195         local canondev
9196         local node
9197
9198         local ldproc=/proc/fs/ldiskfs
9199         local facets=$(get_facets MDS)
9200
9201         for facet in ${facets//,/ }; do
9202                 canondev=$(ldiskfs_canon \
9203                            *.$(convert_facet2label $facet).mntdev $facet)
9204                 do_facet $facet "test -e $ldproc/$canondev/max_dir_size" ||
9205                         ldproc=/sys/fs/ldiskfs
9206                 do_facet $facet "echo $1 >$ldproc/$canondev/max_dir_size"
9207                 do_facet $facet "echo $2 >$ldproc/$canondev/warning_dir_size"
9208         done
9209 }
9210
9211 check_mds_dmesg() {
9212         local facets=$(get_facets MDS)
9213         for facet in ${facets//,/ }; do
9214                 do_facet $facet "dmesg | tail -3 | grep -q $1" && return 0
9215         done
9216         return 1
9217 }
9218
9219 test_129() {
9220         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.56) ]] ||
9221                 { skip "Need MDS version with at least 2.5.56"; return 0; }
9222
9223         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9224         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
9225                 skip "ldiskfs only test"
9226                 return
9227         fi
9228         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9229         local ENOSPC=28
9230         local EFBIG=27
9231         local has_warning=false
9232
9233         rm -rf $DIR/$tdir
9234         mkdir -p $DIR/$tdir
9235
9236         # block size of mds1
9237         local maxsize=$(($($LCTL get_param -n mdc.*MDT0000*.blocksize) * 5))
9238         set_dir_limits $maxsize $maxsize
9239         local dirsize=$(stat -c%s "$DIR/$tdir")
9240         local nfiles=0
9241         while [[ $dirsize -le $maxsize ]]; do
9242                 $MULTIOP $DIR/$tdir/file_base_$nfiles Oc
9243                 rc=$?
9244                 if ! $has_warning; then
9245                         check_mds_dmesg '"is approaching"' && has_warning=true
9246                 fi
9247                 # check two errors:
9248                 # ENOSPC for new ext4 max_dir_size (kernel commit df981d03ee)
9249                 # EFBIG for previous versions included in ldiskfs series
9250                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
9251                         set_dir_limits 0 0
9252                         echo "return code $rc received as expected"
9253
9254                         createmany -o $DIR/$tdir/file_extra_$nfiles. 5 ||
9255                                 error_exit "create failed w/o dir size limit"
9256
9257                         check_mds_dmesg '"has reached"' ||
9258                                 error_exit "reached message should be output"
9259
9260                         [ $has_warning -eq 0 ] &&
9261                                 error_exit "warning message should be output"
9262
9263                         dirsize=$(stat -c%s "$DIR/$tdir")
9264
9265                         [[ $dirsize -ge $maxsize ]] && return 0
9266                         error_exit "current dir size $dirsize, " \
9267                                    "previous limit $maxsize"
9268                 elif [ $rc -ne 0 ]; then
9269                         set_dir_limits 0 0
9270                         error_exit "return $rc received instead of expected " \
9271                                    "$EFBIG or $ENOSPC, files in dir $dirsize"
9272                 fi
9273                 nfiles=$((nfiles + 1))
9274                 dirsize=$(stat -c%s "$DIR/$tdir")
9275         done
9276
9277         set_dir_limits 0 0
9278         error "exceeded dir size limit $maxsize($MDSCOUNT) : $dirsize bytes"
9279 }
9280 run_test 129 "test directory size limit ========================"
9281
9282 OLDIFS="$IFS"
9283 cleanup_130() {
9284         trap 0
9285         IFS="$OLDIFS"
9286 }
9287
9288 test_130a() {
9289         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9290         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
9291                 return
9292
9293         trap cleanup_130 EXIT RETURN
9294
9295         local fm_file=$DIR/$tfile
9296         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
9297         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
9298                 error "dd failed for $fm_file"
9299
9300         # LU-1795: test filefrag/FIEMAP once, even if unsupported
9301         filefrag -ves $fm_file
9302         RC=$?
9303         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9304                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9305         [ $RC != 0 ] && error "filefrag $fm_file failed"
9306
9307         filefrag_op=$(filefrag -ve $fm_file |
9308                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9309         lun=$($GETSTRIPE -i $fm_file)
9310
9311         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
9312         IFS=$'\n'
9313         tot_len=0
9314         for line in $filefrag_op
9315         do
9316                 frag_lun=`echo $line | cut -d: -f5`
9317                 ext_len=`echo $line | cut -d: -f4`
9318                 if (( $frag_lun != $lun )); then
9319                         cleanup_130
9320                         error "FIEMAP on 1-stripe file($fm_file) failed"
9321                         return
9322                 fi
9323                 (( tot_len += ext_len ))
9324         done
9325
9326         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
9327                 cleanup_130
9328                 error "FIEMAP on 1-stripe file($fm_file) failed;"
9329                 return
9330         fi
9331
9332         cleanup_130
9333
9334         echo "FIEMAP on single striped file succeeded"
9335 }
9336 run_test 130a "FIEMAP (1-stripe file)"
9337
9338 test_130b() {
9339         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
9340
9341         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9342         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
9343                 return
9344
9345         trap cleanup_130 EXIT RETURN
9346
9347         local fm_file=$DIR/$tfile
9348         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
9349                         error "setstripe on $fm_file"
9350         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9351                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9352
9353         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT ||
9354                 error "dd failed on $fm_file"
9355
9356         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9357         filefrag_op=$(filefrag -ve $fm_file |
9358                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9359
9360         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9361                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9362
9363         IFS=$'\n'
9364         tot_len=0
9365         num_luns=1
9366         for line in $filefrag_op
9367         do
9368                 frag_lun=$(echo $line | cut -d: -f5 |
9369                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9370                 ext_len=$(echo $line | cut -d: -f4)
9371                 if (( $frag_lun != $last_lun )); then
9372                         if (( tot_len != 1024 )); then
9373                                 cleanup_130
9374                                 error "FIEMAP on $fm_file failed; returned " \
9375                                 "len $tot_len for OST $last_lun instead of 1024"
9376                                 return
9377                         else
9378                                 (( num_luns += 1 ))
9379                                 tot_len=0
9380                         fi
9381                 fi
9382                 (( tot_len += ext_len ))
9383                 last_lun=$frag_lun
9384         done
9385         if (( num_luns != $OSTCOUNT || tot_len != 1024 )); then
9386                 cleanup_130
9387                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9388                         "luns or wrong len for OST $last_lun"
9389                 return
9390         fi
9391
9392         cleanup_130
9393
9394         echo "FIEMAP on $OSTCOUNT-stripe file succeeded"
9395 }
9396 run_test 130b "FIEMAP ($OSTCOUNT-stripe file)"
9397
9398 test_130c() {
9399         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
9400
9401         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9402         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
9403                 return
9404
9405         trap cleanup_130 EXIT RETURN
9406
9407         local fm_file=$DIR/$tfile
9408         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
9409         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9410                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9411
9412         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 ||
9413                         error "dd failed on $fm_file"
9414
9415         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9416         filefrag_op=$(filefrag -ve $fm_file |
9417                 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9418
9419         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9420                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9421
9422         IFS=$'\n'
9423         tot_len=0
9424         num_luns=1
9425         for line in $filefrag_op
9426         do
9427                 frag_lun=$(echo $line | cut -d: -f5 |
9428                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9429                 ext_len=$(echo $line | cut -d: -f4)
9430                 if (( $frag_lun != $last_lun )); then
9431                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
9432                         if (( logical != 512 )); then
9433                                 cleanup_130
9434                                 error "FIEMAP on $fm_file failed; returned " \
9435                                 "logical start for lun $logical instead of 512"
9436                                 return
9437                         fi
9438                         if (( tot_len != 512 )); then
9439                                 cleanup_130
9440                                 error "FIEMAP on $fm_file failed; returned " \
9441                                 "len $tot_len for OST $last_lun instead of 1024"
9442                                 return
9443                         else
9444                                 (( num_luns += 1 ))
9445                                 tot_len=0
9446                         fi
9447                 fi
9448                 (( tot_len += ext_len ))
9449                 last_lun=$frag_lun
9450         done
9451         if (( num_luns != 2 || tot_len != 512 )); then
9452                 cleanup_130
9453                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9454                         "luns or wrong len for OST $last_lun"
9455                 return
9456         fi
9457
9458         cleanup_130
9459
9460         echo "FIEMAP on 2-stripe file with hole succeeded"
9461 }
9462 run_test 130c "FIEMAP (2-stripe file with hole)"
9463
9464 test_130d() {
9465         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs" && return
9466
9467         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9468         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
9469                 return
9470
9471         trap cleanup_130 EXIT RETURN
9472
9473         local fm_file=$DIR/$tfile
9474         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
9475                         error "setstripe on $fm_file"
9476         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9477                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9478
9479         local actual_stripe_count=$($GETSTRIPE -c $fm_file)
9480         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripe_count ||
9481                 error "dd failed on $fm_file"
9482
9483         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9484         filefrag_op=$(filefrag -ve $fm_file |
9485                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9486
9487         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9488                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9489
9490         IFS=$'\n'
9491         tot_len=0
9492         num_luns=1
9493         for line in $filefrag_op
9494         do
9495                 frag_lun=$(echo $line | cut -d: -f5 |
9496                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9497                 ext_len=$(echo $line | cut -d: -f4)
9498                 if (( $frag_lun != $last_lun )); then
9499                         if (( tot_len != 1024 )); then
9500                                 cleanup_130
9501                                 error "FIEMAP on $fm_file failed; returned " \
9502                                 "len $tot_len for OST $last_lun instead of 1024"
9503                                 return
9504                         else
9505                                 (( num_luns += 1 ))
9506                                 tot_len=0
9507                         fi
9508                 fi
9509                 (( tot_len += ext_len ))
9510                 last_lun=$frag_lun
9511         done
9512         if (( num_luns != actual_stripe_count || tot_len != 1024 )); then
9513                 cleanup_130
9514                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9515                         "luns or wrong len for OST $last_lun"
9516                 return
9517         fi
9518
9519         cleanup_130
9520
9521         echo "FIEMAP on N-stripe file succeeded"
9522 }
9523 run_test 130d "FIEMAP (N-stripe file)"
9524
9525 test_130e() {
9526         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
9527
9528         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9529         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
9530
9531         trap cleanup_130 EXIT RETURN
9532
9533         local fm_file=$DIR/$tfile
9534         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
9535         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9536                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9537
9538         NUM_BLKS=512
9539         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
9540         for ((i = 0; i < $NUM_BLKS; i++))
9541         do
9542                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
9543         done
9544
9545         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9546         filefrag_op=$(filefrag -ve $fm_file |
9547                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9548
9549         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9550                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9551
9552         IFS=$'\n'
9553         tot_len=0
9554         num_luns=1
9555         for line in $filefrag_op
9556         do
9557                 frag_lun=$(echo $line | cut -d: -f5 |
9558                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9559                 ext_len=$(echo $line | cut -d: -f4)
9560                 if (( $frag_lun != $last_lun )); then
9561                         if (( tot_len != $EXPECTED_LEN )); then
9562                                 cleanup_130
9563                                 error "FIEMAP on $fm_file failed; returned " \
9564                                 "len $tot_len for OST $last_lun instead " \
9565                                 "of $EXPECTED_LEN"
9566                                 return
9567                         else
9568                                 (( num_luns += 1 ))
9569                                 tot_len=0
9570                         fi
9571                 fi
9572                 (( tot_len += ext_len ))
9573                 last_lun=$frag_lun
9574         done
9575         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
9576                 cleanup_130
9577                 error "FIEMAP on $fm_file failed; returned wrong number " \
9578                         "of luns or wrong len for OST $last_lun"
9579                 return
9580         fi
9581
9582         cleanup_130
9583
9584         echo "FIEMAP with continuation calls succeeded"
9585 }
9586 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
9587
9588 # Test for writev/readv
9589 test_131a() {
9590         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 ||
9591                 error "writev test failed"
9592         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 ||
9593                 error "readv failed"
9594         rm -f $DIR/$tfile
9595 }
9596 run_test 131a "test iov's crossing stripe boundary for writev/readv"
9597
9598 test_131b() {
9599         local fsize=$((524288 + 1048576 + 1572864))
9600         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 &&
9601                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
9602                         error "append writev test failed"
9603
9604         ((fsize += 1572864 + 1048576))
9605         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 &&
9606                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
9607                         error "append writev test failed"
9608         rm -f $DIR/$tfile
9609 }
9610 run_test 131b "test append writev"
9611
9612 test_131c() {
9613         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
9614         error "NOT PASS"
9615 }
9616 run_test 131c "test read/write on file w/o objects"
9617
9618 test_131d() {
9619         rwv -f $DIR/$tfile -w -n 1 1572864
9620         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
9621         if [ "$NOB" != 1572864 ]; then
9622                 error "Short read filed: read $NOB bytes instead of 1572864"
9623         fi
9624         rm -f $DIR/$tfile
9625 }
9626 run_test 131d "test short read"
9627
9628 test_131e() {
9629         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
9630         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
9631         error "read hitting hole failed"
9632         rm -f $DIR/$tfile
9633 }
9634 run_test 131e "test read hitting hole"
9635
9636 check_stats() {
9637         local facet=$1
9638         local op=$2
9639         local want=${3:-0}
9640         local res
9641
9642         case $facet in
9643         mds*) res=$(do_facet $facet \
9644                    $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$op")
9645                  ;;
9646         ost*) res=$(do_facet $facet \
9647                    $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$op")
9648                  ;;
9649         *) error "Wrong facet '$facet'" ;;
9650         esac
9651         echo $res
9652         [ "$res" ] || error "The counter for $op on $facet was not incremented"
9653         # if the argument $3 is zero, it means any stat increment is ok.
9654         if [[ $want -gt 0 ]]; then
9655                 local count=$(echo $res | awk '{ print $2 }')
9656                 [[ $count -ne $want ]] &&
9657                         error "The $op counter on $facet is $count, not $want"
9658         fi
9659 }
9660
9661 test_133a() {
9662         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9663         remote_ost_nodsh && skip "remote OST with nodsh" && return
9664         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9665
9666         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9667                 { skip "MDS doesn't support rename stats"; return; }
9668         local testdir=$DIR/${tdir}/stats_testdir
9669         mkdir -p $DIR/${tdir}
9670
9671         # clear stats.
9672         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9673         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9674
9675         # verify mdt stats first.
9676         mkdir ${testdir} || error "mkdir failed"
9677         check_stats $SINGLEMDS "mkdir" 1
9678         touch ${testdir}/${tfile} || error "touch failed"
9679         check_stats $SINGLEMDS "open" 1
9680         check_stats $SINGLEMDS "close" 1
9681         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ] && {
9682                 mknod ${testdir}/${tfile}-pipe p || error "mknod failed"
9683                 check_stats $SINGLEMDS "mknod" 2
9684         }
9685         rm -f ${testdir}/${tfile}-pipe || error "pipe remove failed"
9686         check_stats $SINGLEMDS "unlink" 1
9687         rm -f ${testdir}/${tfile} || error "file remove failed"
9688         check_stats $SINGLEMDS "unlink" 2
9689
9690         # remove working dir and check mdt stats again.
9691         rmdir ${testdir} || error "rmdir failed"
9692         check_stats $SINGLEMDS "rmdir" 1
9693
9694         local testdir1=$DIR/${tdir}/stats_testdir1
9695         mkdir -p ${testdir}
9696         mkdir -p ${testdir1}
9697         touch ${testdir1}/test1
9698         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
9699         check_stats $SINGLEMDS "crossdir_rename" 1
9700
9701         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
9702         check_stats $SINGLEMDS "samedir_rename" 1
9703
9704         rm -rf $DIR/${tdir}
9705 }
9706 run_test 133a "Verifying MDT stats ========================================"
9707
9708 test_133b() {
9709         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9710         remote_ost_nodsh && skip "remote OST with nodsh" && return
9711         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9712         local testdir=$DIR/${tdir}/stats_testdir
9713         mkdir -p ${testdir} || error "mkdir failed"
9714         touch ${testdir}/${tfile} || error "touch failed"
9715         cancel_lru_locks mdc
9716
9717         # clear stats.
9718         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9719         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9720
9721         # extra mdt stats verification.
9722         chmod 444 ${testdir}/${tfile} || error "chmod failed"
9723         check_stats $SINGLEMDS "setattr" 1
9724         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9725         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
9726         then            # LU-1740
9727                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
9728                 check_stats $SINGLEMDS "getattr" 1
9729         fi
9730         $LFS df || error "lfs failed"
9731         check_stats $SINGLEMDS "statfs" 1
9732
9733         rm -rf $DIR/${tdir}
9734 }
9735 run_test 133b "Verifying extra MDT stats =================================="
9736
9737 test_133c() {
9738         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9739         remote_ost_nodsh && skip "remote OST with nodsh" && return
9740         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9741         local testdir=$DIR/$tdir/stats_testdir
9742         test_mkdir -p $testdir
9743
9744         # verify obdfilter stats.
9745         $SETSTRIPE -c 1 -i 0 $testdir/$tfile
9746         sync
9747         cancel_lru_locks osc
9748         wait_delete_completed
9749
9750         # clear stats.
9751         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9752         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9753
9754         dd if=/dev/zero of=$testdir/$tfile conv=notrunc bs=512k count=1 ||
9755                 error "dd failed"
9756         sync
9757         cancel_lru_locks osc
9758         check_stats ost1 "write" 1
9759
9760         dd if=$testdir/$tfile of=/dev/null bs=1k count=1 || error "dd failed"
9761         check_stats ost1 "read" 1
9762
9763         > $testdir/$tfile || error "truncate failed"
9764         check_stats ost1 "punch" 1
9765
9766         rm -f $testdir/$tfile || error "file remove failed"
9767         wait_delete_completed
9768         check_stats ost1 "destroy" 1
9769
9770         rm -rf $DIR/$tdir
9771 }
9772 run_test 133c "Verifying OST stats ========================================"
9773
9774 order_2() {
9775         local value=$1
9776         local orig=$value
9777         local order=1
9778
9779         while [ $value -ge 2 ]; do
9780                 order=$((order*2))
9781                 value=$((value/2))
9782         done
9783
9784         if [ $orig -gt $order ]; then
9785                 order=$((order*2))
9786         fi
9787         echo $order
9788 }
9789
9790 size_in_KMGT() {
9791     local value=$1
9792     local size=('K' 'M' 'G' 'T');
9793     local i=0
9794     local size_string=$value
9795
9796     while [ $value -ge 1024 ]; do
9797         if [ $i -gt 3 ]; then
9798             #T is the biggest unit we get here, if that is bigger,
9799             #just return XXXT
9800             size_string=${value}T
9801             break
9802         fi
9803         value=$((value >> 10))
9804         if [ $value -lt 1024 ]; then
9805             size_string=${value}${size[$i]}
9806             break
9807         fi
9808         i=$((i + 1))
9809     done
9810
9811     echo $size_string
9812 }
9813
9814 get_rename_size() {
9815     local size=$1
9816     local context=${2:-.}
9817     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9818                 grep -A1 $context |
9819                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9820     echo $sample
9821 }
9822
9823 test_133d() {
9824         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9825         remote_ost_nodsh && skip "remote OST with nodsh" && return
9826         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9827         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9828         { skip "MDS doesn't support rename stats"; return; }
9829
9830         local testdir1=$DIR/${tdir}/stats_testdir1
9831         local testdir2=$DIR/${tdir}/stats_testdir2
9832
9833         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9834
9835         mkdir -p ${testdir1} || error "mkdir failed"
9836         mkdir -p ${testdir2} || error "mkdir failed"
9837
9838         createmany -o $testdir1/test 512 || error "createmany failed"
9839
9840         # check samedir rename size
9841         mv ${testdir1}/test0 ${testdir1}/test_0
9842
9843         local testdir1_size=$(ls -l $DIR/${tdir} |
9844                 awk '/stats_testdir1/ {print $5}')
9845         local testdir2_size=$(ls -l $DIR/${tdir} |
9846                 awk '/stats_testdir2/ {print $5}')
9847
9848         testdir1_size=$(order_2 $testdir1_size)
9849         testdir2_size=$(order_2 $testdir2_size)
9850
9851         testdir1_size=$(size_in_KMGT $testdir1_size)
9852         testdir2_size=$(size_in_KMGT $testdir2_size)
9853
9854         echo "source rename dir size: ${testdir1_size}"
9855         echo "target rename dir size: ${testdir2_size}"
9856
9857         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9858         eval $cmd || error "$cmd failed"
9859         local samedir=$($cmd | grep 'same_dir')
9860         local same_sample=$(get_rename_size $testdir1_size)
9861         [ -z "$samedir" ] && error "samedir_rename_size count error"
9862         [[ $same_sample -eq 1 ]] ||
9863                 error "samedir_rename_size error $same_sample"
9864         echo "Check same dir rename stats success"
9865
9866         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9867
9868         # check crossdir rename size
9869         mv ${testdir1}/test_0 ${testdir2}/test_0
9870
9871         testdir1_size=$(ls -l $DIR/${tdir} |
9872                 awk '/stats_testdir1/ {print $5}')
9873         testdir2_size=$(ls -l $DIR/${tdir} |
9874                 awk '/stats_testdir2/ {print $5}')
9875
9876         testdir1_size=$(order_2 $testdir1_size)
9877         testdir2_size=$(order_2 $testdir2_size)
9878
9879         testdir1_size=$(size_in_KMGT $testdir1_size)
9880         testdir2_size=$(size_in_KMGT $testdir2_size)
9881
9882         echo "source rename dir size: ${testdir1_size}"
9883         echo "target rename dir size: ${testdir2_size}"
9884
9885         eval $cmd || error "$cmd failed"
9886         local crossdir=$($cmd | grep 'crossdir')
9887         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9888         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9889         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9890         [[ $src_sample -eq 1 ]] ||
9891                 error "crossdir_rename_size error $src_sample"
9892         [[ $tgt_sample -eq 1 ]] ||
9893                 error "crossdir_rename_size error $tgt_sample"
9894         echo "Check cross dir rename stats success"
9895         rm -rf $DIR/${tdir}
9896 }
9897 run_test 133d "Verifying rename_stats ========================================"
9898
9899 test_133e() {
9900         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9901         remote_ost_nodsh && skip "remote OST with nodsh" && return
9902         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9903         local testdir=$DIR/${tdir}/stats_testdir
9904         local ctr f0 f1 bs=32768 count=42 sum
9905
9906         mkdir -p ${testdir} || error "mkdir failed"
9907
9908         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9909
9910         for ctr in {write,read}_bytes; do
9911                 sync
9912                 cancel_lru_locks osc
9913
9914                 do_facet ost1 $LCTL set_param -n \
9915                         "obdfilter.*.exports.clear=clear"
9916
9917                 if [ $ctr = write_bytes ]; then
9918                         f0=/dev/zero
9919                         f1=${testdir}/${tfile}
9920                 else
9921                         f0=${testdir}/${tfile}
9922                         f1=/dev/null
9923                 fi
9924
9925                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9926                         error "dd failed"
9927                 sync
9928                 cancel_lru_locks osc
9929
9930                 sum=$(do_facet ost1 $LCTL get_param \
9931                         "obdfilter.*.exports.*.stats" |
9932                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9933                                 $1 == ctr { sum += $7 }
9934                                 END { printf("%0.0f", sum) }')
9935
9936                 if ((sum != bs * count)); then
9937                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9938                 fi
9939         done
9940
9941         rm -rf $DIR/${tdir}
9942 }
9943 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9944
9945 proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
9946
9947 test_133f() {
9948         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9949         remote_ost_nodsh && skip "remote OST with nodsh" && return
9950         # First without trusting modes.
9951         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
9952         echo "proc_dirs='$proc_dirs'"
9953         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
9954         find $proc_dirs -exec cat '{}' \; &> /dev/null
9955
9956         # Second verifying readability.
9957         $LCTL get_param -R '*' &> /dev/null || error "proc file read failed"
9958
9959         # eventually, this can also be replaced with "lctl get_param -R",
9960         # but not until that option is always available on the server
9961         local facet
9962         for facet in mds1 ost1; do
9963                 local facet_proc_dirs=$(do_facet $facet \
9964                                         \\\ls -d $proc_regexp 2>/dev/null)
9965                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
9966                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
9967                 do_facet $facet find $facet_proc_dirs \
9968                         ! -name req_history \
9969                         -exec cat '{}' \\\; &> /dev/null
9970
9971                 do_facet $facet find $facet_proc_dirs \
9972                         ! -name req_history \
9973                         -type f \
9974                         -exec cat '{}' \\\; &> /dev/null ||
9975                                 error "proc file read failed"
9976         done
9977 }
9978 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9979
9980 test_133g() {
9981         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9982         remote_ost_nodsh && skip "remote OST with nodsh" && return
9983         # Second verifying writability.
9984         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
9985         echo "proc_dirs='$proc_dirs'"
9986         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
9987         find $proc_dirs \
9988                 -type f \
9989                 -not -name force_lbug \
9990                 -not -name changelog_mask \
9991                 -exec badarea_io '{}' \; &> /dev/null ||
9992                 error "find $proc_dirs failed"
9993
9994         local facet
9995         for facet in mds1 ost1; do
9996                 [ $(lustre_version_code $facet) -le $(version_code 2.5.54) ] &&
9997                         skip "Too old lustre on $facet" && continue
9998                 local facet_proc_dirs=$(do_facet $facet \
9999                                         \\\ls -d $proc_regexp 2> /dev/null)
10000                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
10001                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
10002                 do_facet $facet find $facet_proc_dirs \
10003                         -type f \
10004                         -not -name force_lbug \
10005                         -not -name changelog_mask \
10006                         -exec badarea_io '{}' \\\; &> /dev/null ||
10007                                 error "$facet find $facet_proc_dirs failed"
10008         done
10009
10010         # remount the FS in case writes/reads /proc break the FS
10011         cleanup || error "failed to unmount"
10012         setup || error "failed to setup"
10013         true
10014 }
10015 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
10016
10017 test_133h() {
10018         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10019         remote_ost_nodsh && skip "remote OST with nodsh" && return
10020         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.54) ]] &&
10021                 skip "Need MDS version at least 2.9.54" && return
10022
10023         local facet
10024         for facet in client mds1 ost1; do
10025                 local facet_proc_dirs=$(do_facet $facet \
10026                                         \\\ls -d $proc_regexp 2> /dev/null)
10027                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
10028                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
10029                 # Get the list of files that are missing the terminating newline
10030                 local missing=($(do_facet $facet \
10031                         find ${facet_proc_dirs} -type f \|              \
10032                                 while read F\; do                       \
10033                                         awk -v FS='\v' -v RS='\v\v'     \
10034                                         "'END { if(NR>0 &&              \
10035                                         \\\$NF !~ /.*\\\n\$/)           \
10036                                                 print FILENAME}'"       \
10037                                         '\$F'\;                         \
10038                                 done 2>/dev/null))
10039                 [ ${#missing[*]} -eq 0 ] ||
10040                         error "files do not end with newline: ${missing[*]}"
10041         done
10042 }
10043 run_test 133h "Proc files should end with newlines"
10044
10045 test_134a() {
10046         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10047         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
10048                 skip "Need MDS version at least 2.7.54" && return
10049
10050         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
10051         cancel_lru_locks mdc
10052
10053         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
10054         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
10055         [ $unused -eq 0 ] || error "$unused locks are not cleared"
10056
10057         local nr=1000
10058         createmany -o $DIR/$tdir/f $nr ||
10059                 error "failed to create $nr files in $DIR/$tdir"
10060         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
10061
10062         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
10063         do_facet mds1 $LCTL set_param fail_loc=0x327
10064         do_facet mds1 $LCTL set_param fail_val=500
10065         touch $DIR/$tdir/m
10066
10067         echo "sleep 10 seconds ..."
10068         sleep 10
10069         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
10070
10071         do_facet mds1 $LCTL set_param fail_loc=0
10072         do_facet mds1 $LCTL set_param fail_val=0
10073         [ $lck_cnt -lt $unused ] ||
10074                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
10075
10076         rm $DIR/$tdir/m
10077         unlinkmany $DIR/$tdir/f $nr
10078 }
10079 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
10080
10081 test_134b() {
10082         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10083         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
10084                 skip "Need MDS version at least 2.7.54" && return
10085
10086         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
10087         cancel_lru_locks mdc
10088
10089         local low_wm=$(do_facet mds1 $LCTL get_param -n \
10090                         ldlm.lock_reclaim_threshold_mb)
10091         # disable reclaim temporarily
10092         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
10093
10094         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
10095         do_facet mds1 $LCTL set_param fail_loc=0x328
10096         do_facet mds1 $LCTL set_param fail_val=500
10097
10098         $LCTL set_param debug=+trace
10099
10100         local nr=600
10101         createmany -o $DIR/$tdir/f $nr &
10102         local create_pid=$!
10103
10104         echo "Sleep $TIMEOUT seconds ..."
10105         sleep $TIMEOUT
10106         if ! ps -p $create_pid  > /dev/null 2>&1; then
10107                 do_facet mds1 $LCTL set_param fail_loc=0
10108                 do_facet mds1 $LCTL set_param fail_val=0
10109                 do_facet mds1 $LCTL set_param \
10110                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
10111                 error "createmany finished incorrectly!"
10112         fi
10113         do_facet mds1 $LCTL set_param fail_loc=0
10114         do_facet mds1 $LCTL set_param fail_val=0
10115         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
10116         wait $create_pid || return 1
10117
10118         unlinkmany $DIR/$tdir/f $nr
10119 }
10120 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
10121
10122 test_140() { #bug-17379
10123         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10124         test_mkdir $DIR/$tdir
10125         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
10126         cp $(which stat) . || error "Copying stat to $DIR/$tdir"
10127
10128         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
10129         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
10130         local i=0
10131         while i=$((i + 1)); do
10132                 test_mkdir $i
10133                 cd $i || error "Changing to $i"
10134                 ln -s ../stat stat || error "Creating stat symlink"
10135                 # Read the symlink until ELOOP present,
10136                 # not LBUGing the system is considered success,
10137                 # we didn't overrun the stack.
10138                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
10139                 if [ $ret -ne 0 ]; then
10140                         if [ $ret -eq 40 ]; then
10141                                 break  # -ELOOP
10142                         else
10143                                 error "Open stat symlink"
10144                                         return
10145                         fi
10146                 fi
10147         done
10148         i=$((i - 1))
10149         echo "The symlink depth = $i"
10150         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
10151                                         error "Invalid symlink depth"
10152
10153         # Test recursive symlink
10154         ln -s symlink_self symlink_self
10155         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
10156         echo "open symlink_self returns $ret"
10157         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
10158 }
10159 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
10160
10161 test_150() {
10162         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10163         local TF="$TMP/$tfile"
10164
10165         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
10166         cp $TF $DIR/$tfile
10167         cancel_lru_locks osc
10168         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
10169         remount_client $MOUNT
10170         df -P $MOUNT
10171         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
10172
10173         $TRUNCATE $TF 6000
10174         $TRUNCATE $DIR/$tfile 6000
10175         cancel_lru_locks osc
10176         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
10177
10178         echo "12345" >>$TF
10179         echo "12345" >>$DIR/$tfile
10180         cancel_lru_locks osc
10181         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
10182
10183         echo "12345" >>$TF
10184         echo "12345" >>$DIR/$tfile
10185         cancel_lru_locks osc
10186         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
10187
10188         rm -f $TF
10189         true
10190 }
10191 run_test 150 "truncate/append tests"
10192
10193 #LU-2902 roc_hit was not able to read all values from lproc
10194 function roc_hit_init() {
10195         local list=$(comma_list $(osts_nodes))
10196         local dir=$DIR/$tdir-check
10197         local file=$dir/$tfile
10198         local BEFORE
10199         local AFTER
10200         local idx
10201
10202         test_mkdir $dir
10203         #use setstripe to do a write to every ost
10204         for i in $(seq 0 $((OSTCOUNT-1))); do
10205                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
10206                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
10207                 idx=$(printf %04x $i)
10208                 BEFORE=$(get_osd_param $list *OST*$idx stats |
10209                         awk '$1 == "cache_access" {sum += $7}
10210                                 END { printf("%0.0f", sum) }')
10211
10212                 cancel_lru_locks osc
10213                 cat $file >/dev/null
10214
10215                 AFTER=$(get_osd_param $list *OST*$idx stats |
10216                         awk '$1 == "cache_access" {sum += $7}
10217                                 END { printf("%0.0f", sum) }')
10218
10219                 echo BEFORE:$BEFORE AFTER:$AFTER
10220                 if ! let "AFTER - BEFORE == 4"; then
10221                         rm -rf $dir
10222                         error "roc_hit is not safe to use"
10223                 fi
10224                 rm $file
10225         done
10226
10227         rm -rf $dir
10228 }
10229
10230 function roc_hit() {
10231         local list=$(comma_list $(osts_nodes))
10232         echo $(get_osd_param $list '' stats |
10233                 awk '$1 == "cache_hit" {sum += $7}
10234                         END { printf("%0.0f", sum) }')
10235 }
10236
10237 function set_cache() {
10238         local on=1
10239
10240         if [ "$2" == "off" ]; then
10241                 on=0;
10242         fi
10243         local list=$(comma_list $(osts_nodes))
10244         set_osd_param $list '' $1_cache_enable $on
10245
10246         cancel_lru_locks osc
10247 }
10248
10249 test_151() {
10250         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10251         remote_ost_nodsh && skip "remote OST with nodsh" && return
10252
10253         local CPAGES=3
10254         local list=$(comma_list $(osts_nodes))
10255
10256         # check whether obdfilter is cache capable at all
10257         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
10258                 echo "not cache-capable obdfilter"
10259                 return 0
10260         fi
10261
10262         # check cache is enabled on all obdfilters
10263         if get_osd_param $list '' read_cache_enable | grep 0; then
10264                 echo "oss cache is disabled"
10265                 return 0
10266         fi
10267
10268         set_osd_param $list '' writethrough_cache_enable 1
10269
10270         # check write cache is enabled on all obdfilters
10271         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
10272                 echo "oss write cache is NOT enabled"
10273                 return 0
10274         fi
10275
10276         roc_hit_init
10277
10278         #define OBD_FAIL_OBD_NO_LRU  0x609
10279         do_nodes $list $LCTL set_param fail_loc=0x609
10280
10281         # pages should be in the case right after write
10282         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
10283                 error "dd failed"
10284
10285         local BEFORE=$(roc_hit)
10286         cancel_lru_locks osc
10287         cat $DIR/$tfile >/dev/null
10288         local AFTER=$(roc_hit)
10289
10290         do_nodes $list $LCTL set_param fail_loc=0
10291
10292         if ! let "AFTER - BEFORE == CPAGES"; then
10293                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10294         fi
10295
10296         # the following read invalidates the cache
10297         cancel_lru_locks osc
10298         set_osd_param $list '' read_cache_enable 0
10299         cat $DIR/$tfile >/dev/null
10300
10301         # now data shouldn't be found in the cache
10302         BEFORE=$(roc_hit)
10303         cancel_lru_locks osc
10304         cat $DIR/$tfile >/dev/null
10305         AFTER=$(roc_hit)
10306         if let "AFTER - BEFORE != 0"; then
10307                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10308         fi
10309
10310         set_osd_param $list '' read_cache_enable 1
10311         rm -f $DIR/$tfile
10312 }
10313 run_test 151 "test cache on oss and controls ==============================="
10314
10315 test_152() {
10316         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10317         local TF="$TMP/$tfile"
10318
10319         # simulate ENOMEM during write
10320 #define OBD_FAIL_OST_NOMEM      0x226
10321         lctl set_param fail_loc=0x80000226
10322         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
10323         cp $TF $DIR/$tfile
10324         sync || error "sync failed"
10325         lctl set_param fail_loc=0
10326
10327         # discard client's cache
10328         cancel_lru_locks osc
10329
10330         # simulate ENOMEM during read
10331         lctl set_param fail_loc=0x80000226
10332         cmp $TF $DIR/$tfile || error "cmp failed"
10333         lctl set_param fail_loc=0
10334
10335         rm -f $TF
10336 }
10337 run_test 152 "test read/write with enomem ============================"
10338
10339 test_153() {
10340         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
10341 }
10342 run_test 153 "test if fdatasync does not crash ======================="
10343
10344 dot_lustre_fid_permission_check() {
10345         local fid=$1
10346         local ffid=$MOUNT/.lustre/fid/$fid
10347         local test_dir=$2
10348
10349         echo "stat fid $fid"
10350         stat $ffid > /dev/null || error "stat $ffid failed."
10351         echo "touch fid $fid"
10352         touch $ffid || error "touch $ffid failed."
10353         echo "write to fid $fid"
10354         cat /etc/hosts > $ffid || error "write $ffid failed."
10355         echo "read fid $fid"
10356         diff /etc/hosts $ffid || error "read $ffid failed."
10357         echo "append write to fid $fid"
10358         cat /etc/hosts >> $ffid || error "append write $ffid failed."
10359         echo "rename fid $fid"
10360         mv $ffid $test_dir/$tfile.1 &&
10361                 error "rename $ffid to $tfile.1 should fail."
10362         touch $test_dir/$tfile.1
10363         mv $test_dir/$tfile.1 $ffid &&
10364                 error "rename $tfile.1 to $ffid should fail."
10365         rm -f $test_dir/$tfile.1
10366         echo "truncate fid $fid"
10367         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
10368         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
10369                 echo "link fid $fid"
10370                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
10371         fi
10372         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
10373                 echo "setfacl fid $fid"
10374                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
10375                 echo "getfacl fid $fid"
10376                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
10377         fi
10378         echo "unlink fid $fid"
10379         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
10380         echo "mknod fid $fid"
10381         mknod $ffid c 1 3 && error "mknod $ffid should fail."
10382
10383         fid=[0xf00000400:0x1:0x0]
10384         ffid=$MOUNT/.lustre/fid/$fid
10385
10386         echo "stat non-exist fid $fid"
10387         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
10388         echo "write to non-exist fid $fid"
10389         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
10390         echo "link new fid $fid"
10391         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
10392
10393         mkdir -p $test_dir/$tdir
10394         touch $test_dir/$tdir/$tfile
10395         fid=$($LFS path2fid $test_dir/$tdir)
10396         rc=$?
10397         [ $rc -ne 0 ] &&
10398                 error "error: could not get fid for $test_dir/$dir/$tfile."
10399
10400         ffid=$MOUNT/.lustre/fid/$fid
10401
10402         echo "ls $fid"
10403         ls $ffid > /dev/null || error "ls $ffid failed."
10404         echo "touch $fid/$tfile.1"
10405         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
10406
10407         echo "touch $MOUNT/.lustre/fid/$tfile"
10408         touch $MOUNT/.lustre/fid/$tfile && \
10409                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
10410
10411         echo "setxattr to $MOUNT/.lustre/fid"
10412         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
10413
10414         echo "listxattr for $MOUNT/.lustre/fid"
10415         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
10416
10417         echo "delxattr from $MOUNT/.lustre/fid"
10418         setfattr -x trusted.name1 $MOUNT/.lustre/fid
10419
10420         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
10421         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
10422                 error "touch invalid fid should fail."
10423
10424         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
10425         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
10426                 error "touch non-normal fid should fail."
10427
10428         echo "rename $tdir to $MOUNT/.lustre/fid"
10429         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
10430                 error "rename to $MOUNT/.lustre/fid should fail."
10431
10432         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
10433         then            # LU-3547
10434                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
10435                 local new_obf_mode=777
10436
10437                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
10438                 chmod $new_obf_mode $DIR/.lustre/fid ||
10439                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
10440
10441                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
10442                 [ $obf_mode -eq $new_obf_mode ] ||
10443                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
10444
10445                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
10446                 chmod $old_obf_mode $DIR/.lustre/fid ||
10447                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
10448         fi
10449
10450         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
10451         fid=$($LFS path2fid $test_dir/$tfile-2)
10452
10453         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
10454         then # LU-5424
10455                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
10456                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
10457                         error "create lov data thru .lustre failed"
10458         fi
10459         echo "cp /etc/passwd $test_dir/$tfile-2"
10460         cp /etc/passwd $test_dir/$tfile-2 ||
10461                 error "copy to $test_dir/$tfile-2 failed."
10462         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
10463         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
10464                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
10465
10466         rm -rf $test_dir/tfile.lnk
10467         rm -rf $test_dir/$tfile-2
10468 }
10469
10470 test_154A() {
10471         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10472                 skip "Need MDS version at least 2.4.1" && return
10473
10474         local tf=$DIR/$tfile
10475         touch $tf
10476
10477         local fid=$($LFS path2fid $tf)
10478         [ -z "$fid" ] && error "path2fid unable to get $tf FID"
10479
10480         # check that we get the same pathname back
10481         local found=$($LFS fid2path $MOUNT "$fid")
10482         [ -z "$found" ] && error "fid2path unable to get '$fid' path"
10483         [ "$found" == "$tf" ] ||
10484                 error "fid2path($fid=path2fid($tf)) = $found != $tf"
10485 }
10486 run_test 154A "lfs path2fid and fid2path basic checks"
10487
10488 test_154B() {
10489         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10490                 skip "Need MDS version at least 2.4.1" && return
10491
10492         mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
10493         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
10494         local linkea=$($LL_DECODE_LINKEA $DIR/$tdir/$tfile | grep 'pfid')
10495         [ -z "$linkea" ] && error "decode linkea $DIR/$tdir/$tfile failed"
10496
10497         local name=$(echo $linkea | awk '/pfid/ {print $5}' | sed -e "s/'//g")
10498         local PFID=$(echo $linkea | awk '/pfid/ {print $3}' | sed -e "s/,//g")
10499
10500         # check that we get the same pathname
10501         echo "PFID: $PFID, name: $name"
10502         local FOUND=$($LFS fid2path $MOUNT "$PFID")
10503         [ -z "$FOUND" ] && error "fid2path unable to get $PFID path"
10504         [ "$FOUND/$name" != "$DIR/$tdir/$tfile" ] &&
10505                 error "ll_decode_linkea has $FOUND/$name != $DIR/$tdir/$tfile"
10506
10507         rm -rf $DIR/$tdir || error "Can not delete directory $DIR/$tdir"
10508 }
10509 run_test 154B "verify the ll_decode_linkea tool"
10510
10511 test_154a() {
10512         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10513         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
10514                 { skip "Need MDS version at least 2.2.51"; return 0; }
10515         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
10516         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10517
10518         cp /etc/hosts $DIR/$tfile
10519
10520         fid=$($LFS path2fid $DIR/$tfile)
10521         rc=$?
10522         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
10523
10524         dot_lustre_fid_permission_check "$fid" $DIR ||
10525                 error "dot lustre permission check $fid failed"
10526
10527         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
10528
10529         touch $MOUNT/.lustre/file &&
10530                 error "creation is not allowed under .lustre"
10531
10532         mkdir $MOUNT/.lustre/dir &&
10533                 error "mkdir is not allowed under .lustre"
10534
10535         rm -rf $DIR/$tfile
10536 }
10537 run_test 154a "Open-by-FID"
10538
10539 test_154b() {
10540         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10541         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
10542                 { skip "Need MDS version at least 2.2.51"; return 0; }
10543         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10544
10545         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10546
10547         local remote_dir=$DIR/$tdir/remote_dir
10548         local MDTIDX=1
10549         local rc=0
10550
10551         mkdir -p $DIR/$tdir
10552         $LFS mkdir -i $MDTIDX $remote_dir ||
10553                 error "create remote directory failed"
10554
10555         cp /etc/hosts $remote_dir/$tfile
10556
10557         fid=$($LFS path2fid $remote_dir/$tfile)
10558         rc=$?
10559         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
10560
10561         dot_lustre_fid_permission_check "$fid" $remote_dir ||
10562                 error "dot lustre permission check $fid failed"
10563         rm -rf $DIR/$tdir
10564 }
10565 run_test 154b "Open-by-FID for remote directory"
10566
10567 test_154c() {
10568         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10569                 skip "Need MDS version at least 2.4.1" && return
10570
10571         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
10572         local FID1=$($LFS path2fid $DIR/$tfile.1)
10573         local FID2=$($LFS path2fid $DIR/$tfile.2)
10574         local FID3=$($LFS path2fid $DIR/$tfile.3)
10575
10576         local N=1
10577         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
10578                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
10579                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
10580                 local want=FID$N
10581                 [ "$FID" = "${!want}" ] ||
10582                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
10583                 N=$((N + 1))
10584         done
10585
10586         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
10587         do
10588                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
10589                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
10590                 N=$((N + 1))
10591         done
10592 }
10593 run_test 154c "lfs path2fid and fid2path multiple arguments"
10594
10595 test_154d() {
10596         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10597         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
10598                 skip "Need MDS version at least 2.5.53" && return
10599
10600         if remote_mds; then
10601                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
10602         else
10603                 nid="0@lo"
10604         fi
10605         local proc_ofile="mdt.*.exports.'$nid'.open_files"
10606         local fd
10607         local cmd
10608
10609         rm -f $DIR/$tfile
10610         touch $DIR/$tfile
10611
10612         local fid=$($LFS path2fid $DIR/$tfile)
10613         # Open the file
10614         fd=$(free_fd)
10615         cmd="exec $fd<$DIR/$tfile"
10616         eval $cmd
10617         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
10618         echo "$fid_list" | grep "$fid"
10619         rc=$?
10620
10621         cmd="exec $fd>/dev/null"
10622         eval $cmd
10623         if [ $rc -ne 0 ]; then
10624                 error "FID $fid not found in open files list $fid_list"
10625         fi
10626 }
10627 run_test 154d "Verify open file fid"
10628
10629 test_154e()
10630 {
10631         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
10632                 skip "Need MDS version at least 2.6.50" && return
10633
10634         if ls -a $MOUNT | grep -q '^\.lustre$'; then
10635                 error ".lustre returned by readdir"
10636         fi
10637 }
10638 run_test 154e ".lustre is not returned by readdir"
10639
10640 test_154f() {
10641         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10642         # create parent directory on a single MDT to avoid cross-MDT hardlinks
10643         test_mkdir -p -c1 $DIR/$tdir/d
10644         # test dirs inherit from its stripe
10645         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
10646         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
10647         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
10648         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
10649         touch $DIR/f
10650
10651         # get fid of parents
10652         local FID0=$($LFS path2fid $DIR/$tdir/d)
10653         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
10654         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
10655         local FID3=$($LFS path2fid $DIR)
10656
10657         # check that path2fid --parents returns expected <parent_fid>/name
10658         # 1) test for a directory (single parent)
10659         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
10660         [ "$parent" == "$FID0/foo1" ] ||
10661                 error "expected parent: $FID0/foo1, got: $parent"
10662
10663         # 2) test for a file with nlink > 1 (multiple parents)
10664         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
10665         echo "$parent" | grep -F "$FID1/$tfile" ||
10666                 error "$FID1/$tfile not returned in parent list"
10667         echo "$parent" | grep -F "$FID2/link" ||
10668                 error "$FID2/link not returned in parent list"
10669
10670         # 3) get parent by fid
10671         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
10672         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10673         echo "$parent" | grep -F "$FID1/$tfile" ||
10674                 error "$FID1/$tfile not returned in parent list (by fid)"
10675         echo "$parent" | grep -F "$FID2/link" ||
10676                 error "$FID2/link not returned in parent list (by fid)"
10677
10678         # 4) test for entry in root directory
10679         parent=$($LFS path2fid --parents $DIR/f)
10680         echo "$parent" | grep -F "$FID3/f" ||
10681                 error "$FID3/f not returned in parent list"
10682
10683         # 5) test it on root directory
10684         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
10685                 error "$MOUNT should not have parents"
10686
10687         # enable xattr caching and check that linkea is correctly updated
10688         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
10689         save_lustre_params client "llite.*.xattr_cache" > $save
10690         lctl set_param llite.*.xattr_cache 1
10691
10692         # 6.1) linkea update on rename
10693         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
10694
10695         # get parents by fid
10696         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10697         # foo1 should no longer be returned in parent list
10698         echo "$parent" | grep -F "$FID1" &&
10699                 error "$FID1 should no longer be in parent list"
10700         # the new path should appear
10701         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
10702                 error "$FID2/$tfile.moved is not in parent list"
10703
10704         # 6.2) linkea update on unlink
10705         rm -f $DIR/$tdir/d/foo2/link
10706         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10707         # foo2/link should no longer be returned in parent list
10708         echo "$parent" | grep -F "$FID2/link" &&
10709                 error "$FID2/link should no longer be in parent list"
10710         true
10711
10712         rm -f $DIR/f
10713         restore_lustre_params < $save
10714         rm -f $save
10715 }
10716 run_test 154f "get parent fids by reading link ea"
10717
10718 test_154g()
10719 {
10720         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) && \
10721            $(lustre_version_code client) -gt $(version_code 2.6.99) ]] ||
10722                 { skip "Need MDS version at least 2.6.92"; return 0; }
10723         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10724
10725         mkdir -p $DIR/$tdir
10726         llapi_fid_test -d $DIR/$tdir
10727 }
10728 run_test 154g "various llapi FID tests"
10729
10730 test_155_small_load() {
10731     local temp=$TMP/$tfile
10732     local file=$DIR/$tfile
10733
10734     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
10735         error "dd of=$temp bs=6096 count=1 failed"
10736     cp $temp $file
10737     cancel_lru_locks osc
10738     cmp $temp $file || error "$temp $file differ"
10739
10740     $TRUNCATE $temp 6000
10741     $TRUNCATE $file 6000
10742     cmp $temp $file || error "$temp $file differ (truncate1)"
10743
10744     echo "12345" >>$temp
10745     echo "12345" >>$file
10746     cmp $temp $file || error "$temp $file differ (append1)"
10747
10748     echo "12345" >>$temp
10749     echo "12345" >>$file
10750     cmp $temp $file || error "$temp $file differ (append2)"
10751
10752     rm -f $temp $file
10753     true
10754 }
10755
10756 test_155_big_load() {
10757     remote_ost_nodsh && skip "remote OST with nodsh" && return
10758     local temp=$TMP/$tfile
10759     local file=$DIR/$tfile
10760
10761     free_min_max
10762     local cache_size=$(do_facet ost$((MAXI+1)) \
10763         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
10764     local large_file_size=$((cache_size * 2))
10765
10766     echo "OSS cache size: $cache_size KB"
10767     echo "Large file size: $large_file_size KB"
10768
10769     [ $MAXV -le $large_file_size ] && \
10770         skip_env "max available OST size needs > $large_file_size KB" && \
10771         return 0
10772
10773     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
10774
10775     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
10776         error "dd of=$temp bs=$large_file_size count=1k failed"
10777     cp $temp $file
10778     ls -lh $temp $file
10779     cancel_lru_locks osc
10780     cmp $temp $file || error "$temp $file differ"
10781
10782     rm -f $temp $file
10783     true
10784 }
10785
10786 save_writethrough() {
10787         local facets=$(get_facets OST)
10788
10789         save_lustre_params $facets "obdfilter.*.writethrough_cache_enable" > $1
10790         save_lustre_params $facets "osd-*.*.writethrough_cache_enable" >> $1
10791 }
10792
10793 test_155a() {
10794         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10795         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10796         save_writethrough $p
10797
10798         set_cache read on
10799         set_cache writethrough on
10800         test_155_small_load
10801         restore_lustre_params < $p
10802         rm -f $p
10803 }
10804 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
10805
10806 test_155b() {
10807         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10808         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10809         save_writethrough $p
10810
10811         set_cache read on
10812         set_cache writethrough off
10813         test_155_small_load
10814         restore_lustre_params < $p
10815         rm -f $p
10816 }
10817 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
10818
10819 test_155c() {
10820         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10821         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10822         save_writethrough $p
10823
10824         set_cache read off
10825         set_cache writethrough on
10826         test_155_small_load
10827         restore_lustre_params < $p
10828         rm -f $p
10829 }
10830 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
10831
10832 test_155d() {
10833         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10834         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10835         save_writethrough $p
10836
10837         set_cache read off
10838         set_cache writethrough off
10839         test_155_small_load
10840         restore_lustre_params < $p
10841         rm -f $p
10842 }
10843 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
10844
10845 test_155e() {
10846         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10847         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10848         save_writethrough $p
10849
10850         set_cache read on
10851         set_cache writethrough on
10852         test_155_big_load
10853         restore_lustre_params < $p
10854         rm -f $p
10855 }
10856 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
10857
10858 test_155f() {
10859         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10860         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10861         save_writethrough $p
10862
10863         set_cache read on
10864         set_cache writethrough off
10865         test_155_big_load
10866         restore_lustre_params < $p
10867         rm -f $p
10868 }
10869 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
10870
10871 test_155g() {
10872         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10873         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10874         save_writethrough $p
10875
10876         set_cache read off
10877         set_cache writethrough on
10878         test_155_big_load
10879         restore_lustre_params < $p
10880         rm -f $p
10881 }
10882 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
10883
10884 test_155h() {
10885         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10886         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10887         save_writethrough $p
10888
10889         set_cache read off
10890         set_cache writethrough off
10891         test_155_big_load
10892         restore_lustre_params < $p
10893         rm -f $p
10894 }
10895 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
10896
10897 test_156() {
10898         remote_ost_nodsh && skip "remote OST with nodsh" && return
10899         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10900         local CPAGES=3
10901         local BEFORE
10902         local AFTER
10903         local file="$DIR/$tfile"
10904         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
10905
10906         [ "$(facet_fstype ost1)" = "zfs" -a \
10907            $(lustre_version_code ost1 -lt $(version_code 2.6.93)) ] &&
10908                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS" &&
10909                 return
10910
10911         save_writethrough $p
10912         roc_hit_init
10913
10914         log "Turn on read and write cache"
10915         set_cache read on
10916         set_cache writethrough on
10917
10918         log "Write data and read it back."
10919         log "Read should be satisfied from the cache."
10920         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10921         BEFORE=$(roc_hit)
10922         cancel_lru_locks osc
10923         cat $file >/dev/null
10924         AFTER=$(roc_hit)
10925         if ! let "AFTER - BEFORE == CPAGES"; then
10926                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10927         else
10928                 log "cache hits:: before: $BEFORE, after: $AFTER"
10929         fi
10930
10931         log "Read again; it should be satisfied from the cache."
10932         BEFORE=$AFTER
10933         cancel_lru_locks osc
10934         cat $file >/dev/null
10935         AFTER=$(roc_hit)
10936         if ! let "AFTER - BEFORE == CPAGES"; then
10937                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10938         else
10939                 log "cache hits:: before: $BEFORE, after: $AFTER"
10940         fi
10941
10942         log "Turn off the read cache and turn on the write cache"
10943         set_cache read off
10944         set_cache writethrough on
10945
10946         log "Read again; it should be satisfied from the cache."
10947         BEFORE=$(roc_hit)
10948         cancel_lru_locks osc
10949         cat $file >/dev/null
10950         AFTER=$(roc_hit)
10951         if ! let "AFTER - BEFORE == CPAGES"; then
10952                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10953         else
10954                 log "cache hits:: before: $BEFORE, after: $AFTER"
10955         fi
10956
10957         log "Read again; it should not be satisfied from the cache."
10958         BEFORE=$AFTER
10959         cancel_lru_locks osc
10960         cat $file >/dev/null
10961         AFTER=$(roc_hit)
10962         if ! let "AFTER - BEFORE == 0"; then
10963                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10964         else
10965                 log "cache hits:: before: $BEFORE, after: $AFTER"
10966         fi
10967
10968         log "Write data and read it back."
10969         log "Read should be satisfied from the cache."
10970         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10971         BEFORE=$(roc_hit)
10972         cancel_lru_locks osc
10973         cat $file >/dev/null
10974         AFTER=$(roc_hit)
10975         if ! let "AFTER - BEFORE == CPAGES"; then
10976                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10977         else
10978                 log "cache hits:: before: $BEFORE, after: $AFTER"
10979         fi
10980
10981         log "Read again; it should not be satisfied from the cache."
10982         BEFORE=$AFTER
10983         cancel_lru_locks osc
10984         cat $file >/dev/null
10985         AFTER=$(roc_hit)
10986         if ! let "AFTER - BEFORE == 0"; then
10987                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10988         else
10989                 log "cache hits:: before: $BEFORE, after: $AFTER"
10990         fi
10991
10992         log "Turn off read and write cache"
10993         set_cache read off
10994         set_cache writethrough off
10995
10996         log "Write data and read it back"
10997         log "It should not be satisfied from the cache."
10998         rm -f $file
10999         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11000         cancel_lru_locks osc
11001         BEFORE=$(roc_hit)
11002         cat $file >/dev/null
11003         AFTER=$(roc_hit)
11004         if ! let "AFTER - BEFORE == 0"; then
11005                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
11006         else
11007                 log "cache hits:: before: $BEFORE, after: $AFTER"
11008         fi
11009
11010         log "Turn on the read cache and turn off the write cache"
11011         set_cache read on
11012         set_cache writethrough off
11013
11014         log "Write data and read it back"
11015         log "It should not be satisfied from the cache."
11016         rm -f $file
11017         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11018         BEFORE=$(roc_hit)
11019         cancel_lru_locks osc
11020         cat $file >/dev/null
11021         AFTER=$(roc_hit)
11022         if ! let "AFTER - BEFORE == 0"; then
11023                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
11024         else
11025                 log "cache hits:: before: $BEFORE, after: $AFTER"
11026         fi
11027
11028         log "Read again; it should be satisfied from the cache."
11029         BEFORE=$(roc_hit)
11030         cancel_lru_locks osc
11031         cat $file >/dev/null
11032         AFTER=$(roc_hit)
11033         if ! let "AFTER - BEFORE == CPAGES"; then
11034                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11035         else
11036                 log "cache hits:: before: $BEFORE, after: $AFTER"
11037         fi
11038
11039         rm -f $file
11040         restore_lustre_params < $p
11041         rm -f $p
11042 }
11043 run_test 156 "Verification of tunables"
11044
11045 #Changelogs
11046 cleanup_changelog () {
11047         trap 0
11048         echo "Deregistering changelog client $CL_USER"
11049         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
11050 }
11051
11052 err17935 () {
11053         if [[ $MDSCOUNT -gt 1 ]]; then
11054                 error_ignore bz17935 $*
11055         else
11056                 error $*
11057         fi
11058 }
11059
11060 changelog_chmask()
11061 {
11062         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
11063
11064         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
11065
11066         if [ $MASK -eq 1 ]; then
11067                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
11068         else
11069                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
11070         fi
11071 }
11072
11073 changelog_extract_field() {
11074         local mdt=$1
11075         local cltype=$2
11076         local file=$3
11077         local identifier=$4
11078
11079         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
11080                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
11081                 tail -1
11082 }
11083
11084 test_160a() {
11085         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11086         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11087         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
11088                 { skip "Need MDS version at least 2.2.0"; return; }
11089
11090         local CL_USERS="mdd.$MDT0.changelog_users"
11091         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
11092         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11093                 changelog_register -n)
11094         echo "Registered as changelog user $CL_USER"
11095         trap cleanup_changelog EXIT
11096         $GET_CL_USERS | grep -q $CL_USER ||
11097                 error "User $CL_USER not found in changelog_users"
11098
11099         # change something
11100         test_mkdir -p $DIR/$tdir/pics/2008/zachy
11101         touch $DIR/$tdir/pics/2008/zachy/timestamp
11102         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
11103         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
11104         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
11105         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
11106         rm $DIR/$tdir/pics/desktop.jpg
11107
11108         $LFS changelog $MDT0 | tail -5
11109
11110         echo "verifying changelog mask"
11111         changelog_chmask "MKDIR"
11112         changelog_chmask "CLOSE"
11113
11114         test_mkdir -p $DIR/$tdir/pics/zach/sofia
11115         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
11116
11117         changelog_chmask "MKDIR"
11118         changelog_chmask "CLOSE"
11119
11120         test_mkdir -p $DIR/$tdir/pics/2008/sofia
11121         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
11122
11123         $LFS changelog $MDT0
11124         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
11125         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
11126         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
11127         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
11128
11129         # verify contents
11130         echo "verifying target fid"
11131         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
11132         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
11133         [ "$fidc" == "$fidf" ] ||
11134                 err17935 "fid in changelog $fidc != file fid $fidf"
11135         echo "verifying parent fid"
11136         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
11137         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
11138         [ "$fidc" == "$fidf" ] ||
11139                 err17935 "pfid in changelog $fidc != dir fid $fidf"
11140
11141         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
11142         $LFS changelog_clear $MDT0 $CL_USER $(($USER_REC1 + 5))
11143         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
11144         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
11145         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
11146                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
11147
11148         MIN_REC=$($GET_CL_USERS |
11149                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
11150         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
11151         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
11152         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
11153                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
11154
11155         # LU-3446 changelog index reset on MDT restart
11156         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11157         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11158         $LFS changelog_clear $MDT0 $CL_USER 0
11159         stop $SINGLEMDS || error "Fail to stop MDT."
11160         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
11161         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11162         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
11163         [ $CUR_REC1 == $CUR_REC2 ] ||
11164                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
11165
11166         echo "verifying user deregister"
11167         cleanup_changelog
11168         $GET_CL_USERS | grep -q $CL_USER &&
11169                 error "User $CL_USER still in changelog_users"
11170
11171         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
11172         if [ $CL_USER -eq 0 ]; then
11173                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11174                 touch $DIR/$tdir/chloe
11175                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11176                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
11177                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
11178         else
11179                 echo "$CL_USER other changelog users; can't verify off"
11180         fi
11181 }
11182 run_test 160a "changelog sanity"
11183
11184 test_160b() { # LU-3587
11185         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11186         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11187         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
11188                 { skip "Need MDS version at least 2.2.0"; return; }
11189
11190         local CL_USERS="mdd.$MDT0.changelog_users"
11191         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
11192         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11193                 changelog_register -n)
11194         echo "Registered as changelog user $CL_USER"
11195         trap cleanup_changelog EXIT
11196         $GET_CL_USERS | grep -q $CL_USER ||
11197                 error "User $CL_USER not found in changelog_users"
11198
11199         local LONGNAME1=$(str_repeat a 255)
11200         local LONGNAME2=$(str_repeat b 255)
11201
11202         cd $DIR
11203         echo "creating very long named file"
11204         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
11205         echo "moving very long named file"
11206         mv $LONGNAME1 $LONGNAME2
11207
11208         $LFS changelog $MDT0 | grep RENME
11209         rm -f $LONGNAME2
11210         cleanup_changelog
11211 }
11212 run_test 160b "Verify that very long rename doesn't crash in changelog"
11213
11214 test_160c() {
11215         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11216
11217         local rc=0
11218         local server_version=$(lustre_version_code $SINGLEMDS)
11219
11220         [[ $server_version -gt $(version_code 2.5.57) ]] ||
11221                 [[ $server_version -gt $(version_code 2.5.1) &&
11222                    $server_version -lt $(version_code 2.5.50) ]] ||
11223                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
11224         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11225
11226         # Registration step
11227         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11228                 changelog_register -n)
11229         trap cleanup_changelog EXIT
11230
11231         rm -rf $DIR/$tdir
11232         mkdir -p $DIR/$tdir
11233         $MCREATE $DIR/$tdir/foo_160c
11234         changelog_chmask "TRUNC"
11235         $TRUNCATE $DIR/$tdir/foo_160c 200
11236         changelog_chmask "TRUNC"
11237         $TRUNCATE $DIR/$tdir/foo_160c 199
11238         $LFS changelog $MDT0
11239         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
11240         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
11241         $LFS changelog_clear $MDT0 $CL_USER 0
11242
11243         # Deregistration step
11244         cleanup_changelog
11245 }
11246 run_test 160c "verify that changelog log catch the truncate event"
11247
11248 test_160d() {
11249         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11250         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11251
11252         local server_version=$(lustre_version_code mds1)
11253         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
11254
11255         [[ $server_version -ge $(version_code 2.7.60) ]] ||
11256                 { skip "Need MDS version at least 2.7.60+"; return; }
11257         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11258
11259         # Registration step
11260         CL_USER=$(do_facet mds1 $LCTL --device $MDT0 \
11261                 changelog_register -n)
11262
11263         trap cleanup_changelog EXIT
11264         mkdir -p $DIR/$tdir/migrate_dir
11265         $LFS changelog_clear $MDT0 $CL_USER 0
11266
11267         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
11268         $LFS changelog $MDT0
11269         MIGRATES=$($LFS changelog $MDT0 | tail -5 | grep -c "MIGRT")
11270         $LFS changelog_clear $MDT0 $CL_USER 0
11271         [ $MIGRATES -eq 1 ] ||
11272                 error "MIGRATE changelog mask count $MIGRATES != 1"
11273
11274         # Deregistration step
11275         cleanup_changelog
11276 }
11277 run_test 160d "verify that changelog log catch the migrate event"
11278
11279 test_160e() {
11280         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11281
11282         # Create a user
11283         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11284                 changelog_register -n)
11285         echo "Registered as changelog user $CL_USER"
11286         trap cleanup_changelog EXIT
11287
11288         # Delete a future user (expect fail)
11289         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister cl77
11290         local rc=$?
11291
11292         if [ $rc -eq 0 ]; then
11293                 error "Deleted non-existant user cl77"
11294         elif [ $rc -ne 2 ]; then
11295                 error "changelog_deregister failed with $rc, " \
11296                         "expected 2 (ENOENT)"
11297         fi
11298
11299         # Clear to a bad index (1 billion should be safe)
11300         $LFS changelog_clear $MDT0 $CL_USER 1000000000
11301         rc=$?
11302
11303         if [ $rc -eq 0 ]; then
11304                 error "Successfully cleared to invalid CL index"
11305         elif [ $rc -ne 22 ]; then
11306                 error "changelog_clear failed with $rc, expected 22 (EINVAL)"
11307         fi
11308 }
11309 run_test 160e "changelog negative testing"
11310
11311 test_161a() {
11312         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11313         test_mkdir -c1 $DIR/$tdir
11314         cp /etc/hosts $DIR/$tdir/$tfile
11315         test_mkdir -c1 $DIR/$tdir/foo1
11316         test_mkdir -c1 $DIR/$tdir/foo2
11317         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
11318         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
11319         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
11320         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
11321         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
11322         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
11323                 $LFS fid2path $DIR $FID
11324                 err17935 "bad link ea"
11325         fi
11326     # middle
11327     rm $DIR/$tdir/foo2/zachary
11328     # last
11329     rm $DIR/$tdir/foo2/thor
11330     # first
11331     rm $DIR/$tdir/$tfile
11332     # rename
11333     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
11334     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
11335         then
11336         $LFS fid2path $DIR $FID
11337         err17935 "bad link rename"
11338     fi
11339     rm $DIR/$tdir/foo2/maggie
11340
11341         # overflow the EA
11342         local longname=filename_avg_len_is_thirty_two_
11343         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
11344                 error "failed to hardlink many files"
11345         links=$($LFS fid2path $DIR $FID | wc -l)
11346         echo -n "${links}/1000 links in link EA"
11347         [[ $links -gt 60 ]] ||
11348                 err17935 "expected at least 60 links in link EA"
11349         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
11350                 error "failed to unlink many hardlinks"
11351 }
11352 run_test 161a "link ea sanity"
11353
11354 test_161b() {
11355         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11356         [ $MDSCOUNT -lt 2 ] && skip "skipping remote directory test" && return
11357         local MDTIDX=1
11358         local remote_dir=$DIR/$tdir/remote_dir
11359
11360         mkdir -p $DIR/$tdir
11361         $LFS mkdir -i $MDTIDX $remote_dir ||
11362                 error "create remote directory failed"
11363
11364         cp /etc/hosts $remote_dir/$tfile
11365         mkdir -p $remote_dir/foo1
11366         mkdir -p $remote_dir/foo2
11367         ln $remote_dir/$tfile $remote_dir/foo1/sofia
11368         ln $remote_dir/$tfile $remote_dir/foo2/zachary
11369         ln $remote_dir/$tfile $remote_dir/foo1/luna
11370         ln $remote_dir/$tfile $remote_dir/foo2/thor
11371
11372         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
11373                      tr -d ']')
11374         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
11375                 $LFS fid2path $DIR $FID
11376                 err17935 "bad link ea"
11377         fi
11378         # middle
11379         rm $remote_dir/foo2/zachary
11380         # last
11381         rm $remote_dir/foo2/thor
11382         # first
11383         rm $remote_dir/$tfile
11384         # rename
11385         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
11386         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
11387         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
11388                 $LFS fid2path $DIR $FID
11389                 err17935 "bad link rename"
11390         fi
11391         rm $remote_dir/foo2/maggie
11392
11393         # overflow the EA
11394         local longname=filename_avg_len_is_thirty_two_
11395         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
11396                 error "failed to hardlink many files"
11397         links=$($LFS fid2path $DIR $FID | wc -l)
11398         echo -n "${links}/1000 links in link EA"
11399         [[ ${links} -gt 60 ]] ||
11400                 err17935 "expected at least 60 links in link EA"
11401         unlinkmany $remote_dir/foo2/$longname 1000 ||
11402         error "failed to unlink many hardlinks"
11403 }
11404 run_test 161b "link ea sanity under remote directory"
11405
11406 test_161c() {
11407         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11408         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11409         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
11410                 skip "Need MDS version at least 2.1.5" && return
11411
11412         # define CLF_RENAME_LAST 0x0001
11413         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
11414         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11415                 changelog_register -n)
11416
11417         trap cleanup_changelog EXIT
11418         rm -rf $DIR/$tdir
11419         mkdir -p $DIR/$tdir
11420         touch $DIR/$tdir/foo_161c
11421         touch $DIR/$tdir/bar_161c
11422         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
11423         $LFS changelog $MDT0 | grep RENME
11424         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
11425                 cut -f5 -d' ')
11426         $LFS changelog_clear $MDT0 $CL_USER 0
11427         if [ x$flags != "x0x1" ]; then
11428                 error "flag $flags is not 0x1"
11429         fi
11430         echo "rename overwrite a target having nlink = 1," \
11431                 "changelog record has flags of $flags"
11432
11433         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
11434         touch $DIR/$tdir/foo_161c
11435         touch $DIR/$tdir/bar_161c
11436         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
11437         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
11438         $LFS changelog $MDT0 | grep RENME
11439         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
11440         $LFS changelog_clear $MDT0 $CL_USER 0
11441         if [ x$flags != "x0x0" ]; then
11442                 error "flag $flags is not 0x0"
11443         fi
11444         echo "rename overwrite a target having nlink > 1," \
11445                 "changelog record has flags of $flags"
11446
11447         # rename doesn't overwrite a target (changelog flag 0x0)
11448         touch $DIR/$tdir/foo_161c
11449         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
11450         $LFS changelog $MDT0 | grep RENME
11451         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
11452         $LFS changelog_clear $MDT0 $CL_USER 0
11453         if [ x$flags != "x0x0" ]; then
11454                 error "flag $flags is not 0x0"
11455         fi
11456         echo "rename doesn't overwrite a target," \
11457                 "changelog record has flags of $flags"
11458
11459         # define CLF_UNLINK_LAST 0x0001
11460         # unlink a file having nlink = 1 (changelog flag 0x1)
11461         rm -f $DIR/$tdir/foo2_161c
11462         $LFS changelog $MDT0 | grep UNLNK
11463         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
11464         $LFS changelog_clear $MDT0 $CL_USER 0
11465         if [ x$flags != "x0x1" ]; then
11466                 error "flag $flags is not 0x1"
11467         fi
11468         echo "unlink a file having nlink = 1," \
11469                 "changelog record has flags of $flags"
11470
11471         # unlink a file having nlink > 1 (changelog flag 0x0)
11472         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
11473         rm -f $DIR/$tdir/foobar_161c
11474         $LFS changelog $MDT0 | grep UNLNK
11475         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
11476         $LFS changelog_clear $MDT0 $CL_USER 0
11477         if [ x$flags != "x0x0" ]; then
11478                 error "flag $flags is not 0x0"
11479         fi
11480         echo "unlink a file having nlink > 1," \
11481                 "changelog record has flags of $flags"
11482         cleanup_changelog
11483 }
11484 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
11485
11486 test_161d() {
11487         local user
11488         local pid
11489         local fid
11490
11491         # cleanup previous run
11492         rm -rf $DIR/$tdir/$tfile
11493
11494         user=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11495                 changelog_register -n)
11496         [[ $? -eq 0 ]] || error "changelog_register failed"
11497
11498         # work in a standalone dir to avoid locking on $DIR/$MOUNT to
11499         # interfer with $MOUNT/.lustre/fid/ access
11500         mkdir $DIR/$tdir
11501         [[ $? -eq 0 ]] || error "mkdir failed"
11502
11503         #define OBD_FAIL_LLITE_CREATE_NODE_PAUSE 0x140c | OBD_FAIL_ONCE
11504         $LCTL set_param fail_loc=0x8000140c
11505         # 5s pause
11506         $LCTL set_param fail_val=5
11507
11508         # create file
11509         echo foofoo > $DIR/$tdir/$tfile &
11510         pid=$!
11511
11512         # wait for create to be delayed
11513         sleep 2
11514
11515         ps -p $pid
11516         [[ $? -eq 0 ]] || error "create should be blocked"
11517
11518         local tempfile=$(mktemp)
11519         fid=$(changelog_extract_field $MDT0 "CREAT" "$tfile" "t=")
11520         cat $MOUNT/.lustre/fid/$fid 2>/dev/null >$tempfile || error "cat failed"
11521         # some delay may occur during ChangeLog publishing and file read just
11522         # above, that could allow file write to happen finally
11523         [[ -s $tempfile ]] && echo "file should be empty"
11524
11525         $LCTL set_param fail_loc=0
11526
11527         wait $pid
11528         [[ $? -eq 0 ]] || error "create failed"
11529
11530         $LFS changelog_clear $MDT0 $user 0
11531         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $user
11532 }
11533 run_test 161d "create with concurrent .lustre/fid access"
11534
11535 check_path() {
11536     local expected=$1
11537     shift
11538     local fid=$2
11539
11540     local path=$(${LFS} fid2path $*)
11541     # Remove the '//' indicating a remote directory
11542     path=$(echo $path | sed 's#//#/#g')
11543     RC=$?
11544
11545     if [ $RC -ne 0 ]; then
11546         err17935 "path looked up of $expected failed. Error $RC"
11547         return $RC
11548     elif [ "${path}" != "${expected}" ]; then
11549         err17935 "path looked up \"${path}\" instead of \"${expected}\""
11550         return 2
11551     fi
11552     echo "fid $fid resolves to path $path (expected $expected)"
11553 }
11554
11555 test_162a() { # was test_162
11556         # Make changes to filesystem
11557         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11558         test_mkdir -p -c1 $DIR/$tdir/d2
11559         touch $DIR/$tdir/d2/$tfile
11560         touch $DIR/$tdir/d2/x1
11561         touch $DIR/$tdir/d2/x2
11562         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
11563         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
11564         # regular file
11565         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
11566         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
11567                 error "check path $tdir/d2/$tfile failed"
11568
11569         # softlink
11570         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
11571         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
11572         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
11573                 error "check path $tdir/d2/p/q/r/slink failed"
11574
11575         # softlink to wrong file
11576         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
11577         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
11578         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
11579                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
11580
11581         # hardlink
11582         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
11583         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
11584         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
11585         # fid2path dir/fsname should both work
11586         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
11587                 error "check path $tdir/d2/a/b/c/new_file failed"
11588         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
11589                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
11590
11591         # hardlink count: check that there are 2 links
11592         # Doesnt work with CMD yet: 17935
11593         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
11594                 err17935 "expected 2 links"
11595
11596         # hardlink indexing: remove the first link
11597         rm $DIR/$tdir/d2/p/q/r/hlink
11598         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
11599                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
11600
11601         return 0
11602 }
11603 run_test 162a "path lookup sanity"
11604
11605 test_162b() {
11606         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11607         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11608
11609         mkdir $DIR/$tdir
11610         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
11611                                 error "create striped dir failed"
11612
11613         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
11614                                         tail -n 1 | awk '{print $2}')
11615         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
11616
11617         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
11618         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
11619
11620         # regular file
11621         for ((i=0;i<5;i++)); do
11622                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
11623                         error "get fid for f$i failed"
11624                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
11625                         error "check path $tdir/striped_dir/f$i failed"
11626
11627                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
11628                         error "get fid for d$i failed"
11629                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
11630                         error "check path $tdir/striped_dir/d$i failed"
11631         done
11632
11633         return 0
11634 }
11635 run_test 162b "striped directory path lookup sanity"
11636
11637 # LU-4239: Verify fid2path works with paths 100 or more directories deep
11638 test_162c() {
11639         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.51) ]] &&
11640                 skip "Need MDS version at least 2.7.51" && return
11641         test_mkdir $DIR/$tdir.local
11642         test_mkdir $DIR/$tdir.remote
11643         local lpath=$tdir.local
11644         local rpath=$tdir.remote
11645
11646         for ((i = 0; i <= 101; i++)); do
11647                 lpath="$lpath/$i"
11648                 mkdir $DIR/$lpath
11649                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
11650                         error "get fid for local directory $DIR/$lpath failed"
11651                 check_path "$DIR/$lpath" $MOUNT $FID --link 0 ||
11652                         error "check path for local directory $DIR/$lpath failed"
11653
11654                 rpath="$rpath/$i"
11655                 test_mkdir $DIR/$rpath
11656                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
11657                         error "get fid for remote directory $DIR/$rpath failed"
11658                 check_path "$DIR/$rpath" $MOUNT $FID --link 0 ||
11659                         error "check path for remote directory $DIR/$rpath failed"
11660         done
11661
11662         return 0
11663 }
11664 run_test 162c "fid2path works with paths 100 or more directories deep"
11665
11666 test_169() {
11667         # do directio so as not to populate the page cache
11668         log "creating a 10 Mb file"
11669         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11670         log "starting reads"
11671         dd if=$DIR/$tfile of=/dev/null bs=4096 &
11672         log "truncating the file"
11673         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11674         log "killing dd"
11675         kill %+ || true # reads might have finished
11676         echo "wait until dd is finished"
11677         wait
11678         log "removing the temporary file"
11679         rm -rf $DIR/$tfile || error "tmp file removal failed"
11680 }
11681 run_test 169 "parallel read and truncate should not deadlock"
11682
11683 test_170() {
11684         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11685         $LCTL clear     # bug 18514
11686         $LCTL debug_daemon start $TMP/${tfile}_log_good
11687         touch $DIR/$tfile
11688         $LCTL debug_daemon stop
11689         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
11690                error "sed failed to read log_good"
11691
11692         $LCTL debug_daemon start $TMP/${tfile}_log_good
11693         rm -rf $DIR/$tfile
11694         $LCTL debug_daemon stop
11695
11696         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
11697                error "lctl df log_bad failed"
11698
11699         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
11700         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
11701
11702         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
11703         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
11704
11705         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
11706                 error "bad_line good_line1 good_line2 are empty"
11707
11708         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11709         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
11710         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11711
11712         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
11713         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
11714         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
11715
11716         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
11717                 error "bad_line_new good_line_new are empty"
11718
11719         local expected_good=$((good_line1 + good_line2*2))
11720
11721         rm -f $TMP/${tfile}*
11722         # LU-231, short malformed line may not be counted into bad lines
11723         if [ $bad_line -ne $bad_line_new ] &&
11724                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
11725                 error "expected $bad_line bad lines, but got $bad_line_new"
11726                 return 1
11727         fi
11728
11729         if [ $expected_good -ne $good_line_new ]; then
11730                 error "expected $expected_good good lines, but got $good_line_new"
11731                 return 2
11732         fi
11733         true
11734 }
11735 run_test 170 "test lctl df to handle corrupted log ====================="
11736
11737 test_171() { # bug20592
11738         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11739 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
11740         $LCTL set_param fail_loc=0x50e
11741         $LCTL set_param fail_val=3000
11742         multiop_bg_pause $DIR/$tfile O_s || true
11743         local MULTIPID=$!
11744         kill -USR1 $MULTIPID
11745         # cause log dump
11746         sleep 3
11747         wait $MULTIPID
11748         if dmesg | grep "recursive fault"; then
11749                 error "caught a recursive fault"
11750         fi
11751         $LCTL set_param fail_loc=0
11752         true
11753 }
11754 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
11755
11756 # it would be good to share it with obdfilter-survey/iokit-libecho code
11757 setup_obdecho_osc () {
11758         local rc=0
11759         local ost_nid=$1
11760         local obdfilter_name=$2
11761         echo "Creating new osc for $obdfilter_name on $ost_nid"
11762         # make sure we can find loopback nid
11763         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
11764
11765         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
11766                            ${obdfilter_name}_osc_UUID || rc=2; }
11767         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
11768                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
11769         return $rc
11770 }
11771
11772 cleanup_obdecho_osc () {
11773         local obdfilter_name=$1
11774         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
11775         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
11776         return 0
11777 }
11778
11779 obdecho_test() {
11780         local OBD=$1
11781         local node=$2
11782         local pages=${3:-64}
11783         local rc=0
11784         local id
11785
11786         local count=10
11787         local obd_size=$(get_obd_size $node $OBD)
11788         local page_size=$(get_page_size $node)
11789         if [[ -n "$obd_size" ]]; then
11790                 local new_count=$((obd_size / (pages * page_size / 1024)))
11791                 [[ $new_count -ge $count ]] || count=$new_count
11792         fi
11793
11794         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
11795         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
11796                            rc=2; }
11797         if [ $rc -eq 0 ]; then
11798             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
11799             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
11800         fi
11801         echo "New object id is $id"
11802         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
11803                            rc=4; }
11804         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
11805                            "test_brw $count w v $pages $id" || rc=4; }
11806         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
11807                            rc=4; }
11808         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
11809                                         "cleanup" || rc=5; }
11810         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
11811                                         "detach" || rc=6; }
11812         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
11813         return $rc
11814 }
11815
11816 test_180a() {
11817         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11818         remote_ost_nodsh && skip "remote OST with nodsh" && return
11819         local rc=0
11820         local rmmod_local=0
11821
11822         if ! module_loaded obdecho; then
11823             load_module obdecho/obdecho
11824             rmmod_local=1
11825         fi
11826
11827         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
11828         local host=$(lctl get_param -n osc.$osc.import |
11829                              awk '/current_connection:/ {print $2}' )
11830         local target=$(lctl get_param -n osc.$osc.import |
11831                              awk '/target:/ {print $2}' )
11832         target=${target%_UUID}
11833
11834         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
11835         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
11836         [[ -n $target ]] && cleanup_obdecho_osc $target
11837         [ $rmmod_local -eq 1 ] && rmmod obdecho
11838         return $rc
11839 }
11840 run_test 180a "test obdecho on osc"
11841
11842 test_180b() {
11843         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11844         remote_ost_nodsh && skip "remote OST with nodsh" && return
11845         local rc=0
11846         local rmmod_remote=0
11847
11848         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
11849                 rmmod_remote=true || error "failed to load module obdecho"
11850         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
11851         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
11852         $rmmod_remote && do_facet ost1 "rmmod obdecho"
11853         return $rc
11854 }
11855 run_test 180b "test obdecho directly on obdfilter"
11856
11857 test_180c() { # LU-2598
11858         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11859         remote_ost_nodsh && skip "remote OST with nodsh" && return
11860         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
11861                 skip "Need MDS version at least 2.4.0" && return
11862
11863         local rc=0
11864         local rmmod_remote=false
11865         local pages=16384 # 64MB bulk I/O RPC size
11866         local target
11867
11868         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
11869                 rmmod_remote=true || error "failed to load module obdecho"
11870
11871         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
11872                 head -n1)
11873         if [ -n "$target" ]; then
11874                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
11875         else
11876                 echo "there is no obdfilter target on ost1"
11877                 rc=2
11878         fi
11879         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
11880         return $rc
11881 }
11882 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
11883
11884 test_181() { # bug 22177
11885         test_mkdir $DIR/$tdir
11886         # create enough files to index the directory
11887         createmany -o $DIR/$tdir/foobar 4000
11888         # print attributes for debug purpose
11889         lsattr -d .
11890         # open dir
11891         multiop_bg_pause $DIR/$tdir D_Sc || return 1
11892         MULTIPID=$!
11893         # remove the files & current working dir
11894         unlinkmany $DIR/$tdir/foobar 4000
11895         rmdir $DIR/$tdir
11896         kill -USR1 $MULTIPID
11897         wait $MULTIPID
11898         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
11899         return 0
11900 }
11901 run_test 181 "Test open-unlinked dir ========================"
11902
11903 test_182() {
11904         local fcount=1000
11905         local tcount=10
11906
11907         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11908
11909         $LCTL set_param mdc.*.rpc_stats=clear
11910
11911         for (( i = 0; i < $tcount; i++ )) ; do
11912                 mkdir $DIR/$tdir/$i
11913         done
11914
11915         for (( i = 0; i < $tcount; i++ )) ; do
11916                 createmany -o $DIR/$tdir/$i/f- $fcount &
11917         done
11918         wait
11919
11920         for (( i = 0; i < $tcount; i++ )) ; do
11921                 unlinkmany $DIR/$tdir/$i/f- $fcount &
11922         done
11923         wait
11924
11925         $LCTL get_param mdc.*.rpc_stats
11926
11927         rm -rf $DIR/$tdir
11928 }
11929 run_test 182 "Test parallel modify metadata operations ================"
11930
11931 test_183() { # LU-2275
11932         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11933         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
11934                 skip "Need MDS version at least 2.3.56" && return
11935
11936         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11937         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11938         echo aaa > $DIR/$tdir/$tfile
11939
11940 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
11941         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
11942
11943         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
11944         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
11945
11946         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
11947
11948         # Flush negative dentry cache
11949         touch $DIR/$tdir/$tfile
11950
11951         # We are not checking for any leaked references here, they'll
11952         # become evident next time we do cleanup with module unload.
11953         rm -rf $DIR/$tdir
11954 }
11955 run_test 183 "No crash or request leak in case of strange dispositions ========"
11956
11957 # test suite 184 is for LU-2016, LU-2017
11958 test_184a() {
11959         check_swap_layouts_support && return 0
11960
11961         dir0=$DIR/$tdir/$testnum
11962         test_mkdir -p -c1 $dir0
11963         ref1=/etc/passwd
11964         ref2=/etc/group
11965         file1=$dir0/f1
11966         file2=$dir0/f2
11967         $SETSTRIPE -c1 $file1
11968         cp $ref1 $file1
11969         $SETSTRIPE -c2 $file2
11970         cp $ref2 $file2
11971         gen1=$($GETSTRIPE -g $file1)
11972         gen2=$($GETSTRIPE -g $file2)
11973
11974         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
11975         gen=$($GETSTRIPE -g $file1)
11976         [[ $gen1 != $gen ]] ||
11977                 "Layout generation on $file1 does not change"
11978         gen=$($GETSTRIPE -g $file2)
11979         [[ $gen2 != $gen ]] ||
11980                 "Layout generation on $file2 does not change"
11981
11982         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
11983         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
11984 }
11985 run_test 184a "Basic layout swap"
11986
11987 test_184b() {
11988         check_swap_layouts_support && return 0
11989
11990         dir0=$DIR/$tdir/$testnum
11991         mkdir -p $dir0 || error "creating dir $dir0"
11992         file1=$dir0/f1
11993         file2=$dir0/f2
11994         file3=$dir0/f3
11995         dir1=$dir0/d1
11996         dir2=$dir0/d2
11997         mkdir $dir1 $dir2
11998         $SETSTRIPE -c1 $file1
11999         $SETSTRIPE -c2 $file2
12000         $SETSTRIPE -c1 $file3
12001         chown $RUNAS_ID $file3
12002         gen1=$($GETSTRIPE -g $file1)
12003         gen2=$($GETSTRIPE -g $file2)
12004
12005         $LFS swap_layouts $dir1 $dir2 &&
12006                 error "swap of directories layouts should fail"
12007         $LFS swap_layouts $dir1 $file1 &&
12008                 error "swap of directory and file layouts should fail"
12009         $RUNAS $LFS swap_layouts $file1 $file2 &&
12010                 error "swap of file we cannot write should fail"
12011         $LFS swap_layouts $file1 $file3 &&
12012                 error "swap of file with different owner should fail"
12013         /bin/true # to clear error code
12014 }
12015 run_test 184b "Forbidden layout swap (will generate errors)"
12016
12017 test_184c() {
12018         local cmpn_arg=$(cmp -n 2>&1 | grep "invalid option")
12019         [ -n "$cmpn_arg" ] && skip_env "cmp does not support -n" && return
12020         check_swap_layouts_support && return 0
12021
12022         local dir0=$DIR/$tdir/$testnum
12023         mkdir -p $dir0 || error "creating dir $dir0"
12024
12025         local ref1=$dir0/ref1
12026         local ref2=$dir0/ref2
12027         local file1=$dir0/file1
12028         local file2=$dir0/file2
12029         # create a file large enough for the concurrent test
12030         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
12031         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
12032         echo "ref file size: ref1($(stat -c %s $ref1))," \
12033              "ref2($(stat -c %s $ref2))"
12034
12035         cp $ref2 $file2
12036         dd if=$ref1 of=$file1 bs=16k &
12037         local DD_PID=$!
12038
12039         # Make sure dd starts to copy file
12040         while [ ! -f $file1 ]; do sleep 0.1; done
12041
12042         $LFS swap_layouts $file1 $file2
12043         local rc=$?
12044         wait $DD_PID
12045         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
12046         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
12047
12048         # how many bytes copied before swapping layout
12049         local copied=$(stat -c %s $file2)
12050         local remaining=$(stat -c %s $ref1)
12051         remaining=$((remaining - copied))
12052         echo "Copied $copied bytes before swapping layout..."
12053
12054         cmp -n $copied $file1 $ref2 | grep differ &&
12055                 error "Content mismatch [0, $copied) of ref2 and file1"
12056         cmp -n $copied $file2 $ref1 ||
12057                 error "Content mismatch [0, $copied) of ref1 and file2"
12058         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
12059                 error "Content mismatch [$copied, EOF) of ref1 and file1"
12060
12061         # clean up
12062         rm -f $ref1 $ref2 $file1 $file2
12063 }
12064 run_test 184c "Concurrent write and layout swap"
12065
12066 test_184d() {
12067         check_swap_layouts_support && return 0
12068         [ -z "$(which getfattr 2>/dev/null)" ] &&
12069                 skip "no getfattr command" && return 0
12070
12071         local file1=$DIR/$tdir/$tfile-1
12072         local file2=$DIR/$tdir/$tfile-2
12073         local file3=$DIR/$tdir/$tfile-3
12074         local lovea1
12075         local lovea2
12076
12077         mkdir -p $DIR/$tdir
12078         touch $file1 || error "create $file1 failed"
12079         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
12080                 error "create $file2 failed"
12081         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
12082                 error "create $file3 failed"
12083         lovea1=$(get_layout_param $file1)
12084
12085         $LFS swap_layouts $file2 $file3 ||
12086                 error "swap $file2 $file3 layouts failed"
12087         $LFS swap_layouts $file1 $file2 ||
12088                 error "swap $file1 $file2 layouts failed"
12089
12090         lovea2=$(get_layout_param $file2)
12091         echo "$lovea1"
12092         echo "$lovea2"
12093         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
12094
12095         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
12096         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
12097 }
12098 run_test 184d "allow stripeless layouts swap"
12099
12100 test_184e() {
12101         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
12102                 { skip "Need MDS version at least 2.6.94"; return 0; }
12103         check_swap_layouts_support && return 0
12104         [ -z "$(which getfattr 2>/dev/null)" ] &&
12105                 skip "no getfattr command" && return 0
12106
12107         local file1=$DIR/$tdir/$tfile-1
12108         local file2=$DIR/$tdir/$tfile-2
12109         local file3=$DIR/$tdir/$tfile-3
12110         local lovea
12111
12112         mkdir -p $DIR/$tdir
12113         touch $file1 || error "create $file1 failed"
12114         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
12115                 error "create $file2 failed"
12116         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
12117                 error "create $file3 failed"
12118
12119         $LFS swap_layouts $file1 $file2 ||
12120                 error "swap $file1 $file2 layouts failed"
12121
12122         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
12123         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
12124
12125         echo 123 > $file1 || error "Should be able to write into $file1"
12126
12127         $LFS swap_layouts $file1 $file3 ||
12128                 error "swap $file1 $file3 layouts failed"
12129
12130         echo 123 > $file1 || error "Should be able to write into $file1"
12131
12132         rm -rf $file1 $file2 $file3
12133 }
12134 run_test 184e "Recreate layout after stripeless layout swaps"
12135
12136 test_185() { # LU-2441
12137         # LU-3553 - no volatile file support in old servers
12138         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
12139                 { skip "Need MDS version at least 2.3.60"; return 0; }
12140
12141         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12142         touch $DIR/$tdir/spoo
12143         local mtime1=$(stat -c "%Y" $DIR/$tdir)
12144         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
12145                 error "cannot create/write a volatile file"
12146         [ "$FILESET" == "" ] &&
12147         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
12148                 error "FID is still valid after close"
12149
12150         multiop_bg_pause $DIR/$tdir vVw4096_c
12151         local multi_pid=$!
12152
12153         local OLD_IFS=$IFS
12154         IFS=":"
12155         local fidv=($fid)
12156         IFS=$OLD_IFS
12157         # assume that the next FID for this client is sequential, since stdout
12158         # is unfortunately eaten by multiop_bg_pause
12159         local n=$((${fidv[1]} + 1))
12160         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
12161         if [ "$FILESET" == "" ]; then
12162                 $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
12163                         error "FID is missing before close"
12164         fi
12165         kill -USR1 $multi_pid
12166         # 1 second delay, so if mtime change we will see it
12167         sleep 1
12168         local mtime2=$(stat -c "%Y" $DIR/$tdir)
12169         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
12170 }
12171 run_test 185 "Volatile file support"
12172
12173 test_187a() {
12174         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12175         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
12176                 skip "Need MDS version at least 2.3.0" && return
12177
12178         local dir0=$DIR/$tdir/$testnum
12179         mkdir -p $dir0 || error "creating dir $dir0"
12180
12181         local file=$dir0/file1
12182         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
12183         local dv1=$($LFS data_version $file)
12184         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
12185         local dv2=$($LFS data_version $file)
12186         [[ $dv1 != $dv2 ]] ||
12187                 error "data version did not change on write $dv1 == $dv2"
12188
12189         # clean up
12190         rm -f $file1
12191 }
12192 run_test 187a "Test data version change"
12193
12194 test_187b() {
12195         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12196         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
12197                 skip "Need MDS version at least 2.3.0" && return
12198
12199         local dir0=$DIR/$tdir/$testnum
12200         mkdir -p $dir0 || error "creating dir $dir0"
12201
12202         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
12203         [[ ${DV[0]} != ${DV[1]} ]] ||
12204                 error "data version did not change on write"\
12205                       " ${DV[0]} == ${DV[1]}"
12206
12207         # clean up
12208         rm -f $file1
12209 }
12210 run_test 187b "Test data version change on volatile file"
12211
12212 test_200() {
12213         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12214         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12215         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
12216
12217         local POOL=${POOL:-cea1}
12218         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
12219         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
12220         # Pool OST targets
12221         local first_ost=0
12222         local last_ost=$(($OSTCOUNT - 1))
12223         local ost_step=2
12224         local ost_list=$(seq $first_ost $ost_step $last_ost)
12225         local ost_range="$first_ost $last_ost $ost_step"
12226         local test_path=$POOL_ROOT/$POOL_DIR_NAME
12227         local file_dir=$POOL_ROOT/file_tst
12228         local subdir=$test_path/subdir
12229
12230         local rc=0
12231         while : ; do
12232                 # former test_200a test_200b
12233                 pool_add $POOL                          || { rc=$? ; break; }
12234                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
12235                 # former test_200c test_200d
12236                 mkdir -p $test_path
12237                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
12238                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
12239                 mkdir -p $subdir
12240                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
12241                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
12242                                                         || { rc=$? ; break; }
12243                 # former test_200e test_200f
12244                 local files=$((OSTCOUNT*3))
12245                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
12246                                                         || { rc=$? ; break; }
12247                 pool_create_files $POOL $file_dir $files "$ost_list" \
12248                                                         || { rc=$? ; break; }
12249                 # former test_200g test_200h
12250                 pool_lfs_df $POOL                       || { rc=$? ; break; }
12251                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
12252
12253                 # former test_201a test_201b test_201c
12254                 pool_remove_first_target $POOL          || { rc=$? ; break; }
12255
12256                 local f=$test_path/$tfile
12257                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
12258                 pool_remove $POOL $f                    || { rc=$? ; break; }
12259                 break
12260         done
12261
12262         destroy_test_pools
12263         return $rc
12264 }
12265 run_test 200 "OST pools"
12266
12267 # usage: default_attr <count | size | offset>
12268 default_attr() {
12269         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
12270 }
12271
12272 # usage: check_default_stripe_attr
12273 check_default_stripe_attr() {
12274         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
12275         case $1 in
12276         --stripe-count|-c)
12277                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
12278         --stripe-size|-S)
12279                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
12280         --stripe-index|-i)
12281                 EXPECTED=-1;;
12282         *)
12283                 error "unknown getstripe attr '$1'"
12284         esac
12285
12286         [ $ACTUAL == $EXPECTED ] ||
12287                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
12288 }
12289
12290 test_204a() {
12291         test_mkdir $DIR/$tdir
12292         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
12293
12294         check_default_stripe_attr --stripe-count
12295         check_default_stripe_attr --stripe-size
12296         check_default_stripe_attr --stripe-index
12297 }
12298 run_test 204a "Print default stripe attributes"
12299
12300 test_204b() {
12301         test_mkdir $DIR/$tdir
12302         $SETSTRIPE --stripe-count 1 $DIR/$tdir
12303
12304         check_default_stripe_attr --stripe-size
12305         check_default_stripe_attr --stripe-index
12306 }
12307 run_test 204b "Print default stripe size and offset"
12308
12309 test_204c() {
12310         test_mkdir $DIR/$tdir
12311         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
12312
12313         check_default_stripe_attr --stripe-count
12314         check_default_stripe_attr --stripe-index
12315 }
12316 run_test 204c "Print default stripe count and offset"
12317
12318 test_204d() {
12319         test_mkdir $DIR/$tdir
12320         $SETSTRIPE --stripe-index 0 $DIR/$tdir
12321
12322         check_default_stripe_attr --stripe-count
12323         check_default_stripe_attr --stripe-size
12324 }
12325 run_test 204d "Print default stripe count and size"
12326
12327 test_204e() {
12328         test_mkdir $DIR/$tdir
12329         $SETSTRIPE -d $DIR/$tdir
12330
12331         check_default_stripe_attr --stripe-count --raw
12332         check_default_stripe_attr --stripe-size --raw
12333         check_default_stripe_attr --stripe-index --raw
12334 }
12335 run_test 204e "Print raw stripe attributes"
12336
12337 test_204f() {
12338         test_mkdir $DIR/$tdir
12339         $SETSTRIPE --stripe-count 1 $DIR/$tdir
12340
12341         check_default_stripe_attr --stripe-size --raw
12342         check_default_stripe_attr --stripe-index --raw
12343 }
12344 run_test 204f "Print raw stripe size and offset"
12345
12346 test_204g() {
12347         test_mkdir $DIR/$tdir
12348         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
12349
12350         check_default_stripe_attr --stripe-count --raw
12351         check_default_stripe_attr --stripe-index --raw
12352 }
12353 run_test 204g "Print raw stripe count and offset"
12354
12355 test_204h() {
12356         test_mkdir $DIR/$tdir
12357         $SETSTRIPE --stripe-index 0 $DIR/$tdir
12358
12359         check_default_stripe_attr --stripe-count --raw
12360         check_default_stripe_attr --stripe-size --raw
12361 }
12362 run_test 204h "Print raw stripe count and size"
12363
12364 # Figure out which job scheduler is being used, if any,
12365 # or use a fake one
12366 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
12367         JOBENV=SLURM_JOB_ID
12368 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
12369         JOBENV=LSB_JOBID
12370 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
12371         JOBENV=PBS_JOBID
12372 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
12373         JOBENV=LOADL_STEP_ID
12374 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
12375         JOBENV=JOB_ID
12376 else
12377         $LCTL list_param jobid_name > /dev/null 2>&1
12378         if [ $? -eq 0 ]; then
12379                 JOBENV=nodelocal
12380         else
12381                 JOBENV=FAKE_JOBID
12382         fi
12383 fi
12384
12385 verify_jobstats() {
12386         local cmd=($1)
12387         shift
12388         local facets="$@"
12389
12390 # we don't really need to clear the stats for this test to work, since each
12391 # command has a unique jobid, but it makes debugging easier if needed.
12392 #       for facet in $facets; do
12393 #               local dev=$(convert_facet2label $facet)
12394 #               # clear old jobstats
12395 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
12396 #       done
12397
12398         # use a new JobID for each test, or we might see an old one
12399         [ "$JOBENV" = "FAKE_JOBID" ] &&
12400                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
12401
12402         JOBVAL=${!JOBENV}
12403
12404         [ "$JOBENV" = "nodelocal" ] && {
12405                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
12406                 $LCTL set_param jobid_name=$FAKE_JOBID
12407                 JOBVAL=$FAKE_JOBID
12408         }
12409
12410         log "Test: ${cmd[*]}"
12411         log "Using JobID environment variable $JOBENV=$JOBVAL"
12412
12413         if [ $JOBENV = "FAKE_JOBID" ]; then
12414                 FAKE_JOBID=$JOBVAL ${cmd[*]}
12415         else
12416                 ${cmd[*]}
12417         fi
12418
12419         # all files are created on OST0000
12420         for facet in $facets; do
12421                 local stats="*.$(convert_facet2label $facet).job_stats"
12422                 if [ $(do_facet $facet lctl get_param $stats |
12423                        grep -c $JOBVAL) -ne 1 ]; then
12424                         do_facet $facet lctl get_param $stats
12425                         error "No jobstats for $JOBVAL found on $facet::$stats"
12426                 fi
12427         done
12428 }
12429
12430 jobstats_set() {
12431         trap 0
12432         NEW_JOBENV=${1:-$OLD_JOBENV}
12433         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
12434         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
12435 }
12436
12437 cleanup_205() {
12438         trap 0
12439         do_facet $SINGLEMDS \
12440                 $LCTL set_param mdt.*.job_cleanup_interval=$OLD_INTERVAL
12441         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
12442         cleanup_changelog
12443 }
12444
12445 test_205() { # Job stats
12446         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.1) ]] ||
12447                 { skip "Need MDS version with at least 2.7.1"; return 0; }
12448
12449         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12450         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12451         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12452         remote_ost_nodsh && skip "remote OST with nodsh" && return
12453
12454         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
12455                 skip "Server doesn't support jobstats" && return 0
12456         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
12457
12458         OLD_JOBENV=$($LCTL get_param -n jobid_var)
12459         if [ $OLD_JOBENV != $JOBENV ]; then
12460                 jobstats_set $JOBENV
12461                 trap cleanup_205 EXIT
12462         fi
12463
12464         CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
12465         echo "Registered as changelog user $CL_USER"
12466
12467         OLD_INTERVAL=$(do_facet $SINGLEMDS \
12468                        lctl get_param -n mdt.*.job_cleanup_interval)
12469         local interval_new=5
12470         do_facet $SINGLEMDS \
12471                 $LCTL set_param mdt.*.job_cleanup_interval=$interval_new
12472         local start=$SECONDS
12473
12474         local cmd
12475         # mkdir
12476         cmd="mkdir $DIR/$tdir"
12477         verify_jobstats "$cmd" "$SINGLEMDS"
12478         # rmdir
12479         cmd="rmdir $DIR/$tdir"
12480         verify_jobstats "$cmd" "$SINGLEMDS"
12481         # mkdir on secondary MDT
12482         if [ $MDSCOUNT -gt 1 ]; then
12483                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
12484                 verify_jobstats "$cmd" "mds2"
12485         fi
12486         # mknod
12487         cmd="mknod $DIR/$tfile c 1 3"
12488         verify_jobstats "$cmd" "$SINGLEMDS"
12489         # unlink
12490         cmd="rm -f $DIR/$tfile"
12491         verify_jobstats "$cmd" "$SINGLEMDS"
12492         # create all files on OST0000 so verify_jobstats can find OST stats
12493         # open & close
12494         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
12495         verify_jobstats "$cmd" "$SINGLEMDS"
12496         # setattr
12497         cmd="touch $DIR/$tfile"
12498         verify_jobstats "$cmd" "$SINGLEMDS ost1"
12499         # write
12500         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
12501         verify_jobstats "$cmd" "ost1"
12502         # read
12503         cancel_lru_locks osc
12504         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
12505         verify_jobstats "$cmd" "ost1"
12506         # truncate
12507         cmd="$TRUNCATE $DIR/$tfile 0"
12508         verify_jobstats "$cmd" "$SINGLEMDS ost1"
12509         # rename
12510         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
12511         verify_jobstats "$cmd" "$SINGLEMDS"
12512         # jobstats expiry - sleep until old stats should be expired
12513         local left=$((interval_new + 5 - (SECONDS - start)))
12514         [ $left -ge 0 ] && wait_update_facet $SINGLEMDS \
12515                 "lctl get_param *.*.job_stats | grep -c 'job_id.*mkdir'" \
12516                         "0" $left
12517         cmd="mkdir $DIR/$tdir.expire"
12518         verify_jobstats "$cmd" "$SINGLEMDS"
12519         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
12520             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
12521
12522         # Ensure that jobid are present in changelog (if supported by MDS)
12523         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
12524         then
12525                 $LFS changelog $MDT0 | tail -9
12526                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
12527                 [ $jobids -eq 9 ] ||
12528                         error "Wrong changelog jobid count $jobids != 9"
12529
12530                 # LU-5862
12531                 JOBENV="disable"
12532                 jobstats_set $JOBENV
12533                 touch $DIR/$tfile
12534                 $LFS changelog $MDT0 | tail -1
12535                 jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
12536                 [ $jobids -eq 0 ] ||
12537                         error "Unexpected jobids when jobid_var=$JOBENV"
12538         fi
12539
12540         cleanup_205
12541 }
12542 run_test 205 "Verify job stats"
12543
12544 # LU-1480, LU-1773 and LU-1657
12545 test_206() {
12546         mkdir -p $DIR/$tdir
12547         $SETSTRIPE -c -1 $DIR/$tdir
12548 #define OBD_FAIL_LOV_INIT 0x1403
12549         $LCTL set_param fail_loc=0xa0001403
12550         $LCTL set_param fail_val=1
12551         touch $DIR/$tdir/$tfile || true
12552 }
12553 run_test 206 "fail lov_init_raid0() doesn't lbug"
12554
12555 test_207a() {
12556         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
12557         local fsz=`stat -c %s $DIR/$tfile`
12558         cancel_lru_locks mdc
12559
12560         # do not return layout in getattr intent
12561 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
12562         $LCTL set_param fail_loc=0x170
12563         local sz=`stat -c %s $DIR/$tfile`
12564
12565         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
12566
12567         rm -rf $DIR/$tfile
12568 }
12569 run_test 207a "can refresh layout at glimpse"
12570
12571 test_207b() {
12572         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
12573         local cksum=`md5sum $DIR/$tfile`
12574         local fsz=`stat -c %s $DIR/$tfile`
12575         cancel_lru_locks mdc
12576         cancel_lru_locks osc
12577
12578         # do not return layout in getattr intent
12579 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
12580         $LCTL set_param fail_loc=0x171
12581
12582         # it will refresh layout after the file is opened but before read issues
12583         echo checksum is "$cksum"
12584         echo "$cksum" |md5sum -c --quiet || error "file differs"
12585
12586         rm -rf $DIR/$tfile
12587 }
12588 run_test 207b "can refresh layout at open"
12589
12590 test_208() {
12591         # FIXME: in this test suite, only RD lease is used. This is okay
12592         # for now as only exclusive open is supported. After generic lease
12593         # is done, this test suite should be revised. - Jinshan
12594
12595         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12596         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
12597                 { skip "Need MDS version at least 2.4.52"; return 0; }
12598
12599         echo "==== test 1: verify get lease work"
12600         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
12601
12602         echo "==== test 2: verify lease can be broken by upcoming open"
12603         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
12604         local PID=$!
12605         sleep 1
12606
12607         $MULTIOP $DIR/$tfile oO_RDONLY:c
12608         kill -USR1 $PID && wait $PID || error "break lease error"
12609
12610         echo "==== test 3: verify lease can't be granted if an open already exists"
12611         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
12612         local PID=$!
12613         sleep 1
12614
12615         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
12616         kill -USR1 $PID && wait $PID || error "open file error"
12617
12618         echo "==== test 4: lease can sustain over recovery"
12619         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
12620         PID=$!
12621         sleep 1
12622
12623         fail mds1
12624
12625         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
12626
12627         echo "==== test 5: lease broken can't be regained by replay"
12628         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
12629         PID=$!
12630         sleep 1
12631
12632         # open file to break lease and then recovery
12633         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
12634         fail mds1
12635
12636         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
12637
12638         rm -f $DIR/$tfile
12639 }
12640 run_test 208 "Exclusive open"
12641
12642 test_209() {
12643         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
12644                 skip_env "must have disp_stripe" && return
12645
12646         touch $DIR/$tfile
12647         sync; sleep 5; sync;
12648
12649         echo 3 > /proc/sys/vm/drop_caches
12650         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
12651
12652         # open/close 500 times
12653         for i in $(seq 500); do
12654                 cat $DIR/$tfile
12655         done
12656
12657         echo 3 > /proc/sys/vm/drop_caches
12658         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
12659
12660         echo "before: $req_before, after: $req_after"
12661         [ $((req_after - req_before)) -ge 300 ] &&
12662                 error "open/close requests are not freed"
12663         return 0
12664 }
12665 run_test 209 "read-only open/close requests should be freed promptly"
12666
12667 test_212() {
12668         size=`date +%s`
12669         size=$((size % 8192 + 1))
12670         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
12671         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
12672         rm -f $DIR/f212 $DIR/f212.xyz
12673 }
12674 run_test 212 "Sendfile test ============================================"
12675
12676 test_213() {
12677         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
12678         cancel_lru_locks osc
12679         lctl set_param fail_loc=0x8000040f
12680         # generate a read lock
12681         cat $DIR/$tfile > /dev/null
12682         # write to the file, it will try to cancel the above read lock.
12683         cat /etc/hosts >> $DIR/$tfile
12684 }
12685 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
12686
12687 test_214() { # for bug 20133
12688         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
12689         for (( i=0; i < 340; i++ )) ; do
12690                 touch $DIR/$tdir/d214c/a$i
12691         done
12692
12693         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
12694         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
12695         ls $DIR/d214c || error "ls $DIR/d214c failed"
12696         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
12697         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
12698 }
12699 run_test 214 "hash-indexed directory test - bug 20133"
12700
12701 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
12702 create_lnet_proc_files() {
12703         lctl get_param -n $1 >$TMP/lnet_$1.sys || error "cannot read lnet.$1"
12704 }
12705
12706 # counterpart of create_lnet_proc_files
12707 remove_lnet_proc_files() {
12708         rm -f $TMP/lnet_$1.sys
12709 }
12710
12711 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12712 # 3rd arg as regexp for body
12713 check_lnet_proc_stats() {
12714         local l=$(cat "$TMP/lnet_$1" |wc -l)
12715         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
12716
12717         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
12718 }
12719
12720 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12721 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
12722 # optional and can be regexp for 2nd line (lnet.routes case)
12723 check_lnet_proc_entry() {
12724         local blp=2          # blp stands for 'position of 1st line of body'
12725         [ -z "$5" ] || blp=3 # lnet.routes case
12726
12727         local l=$(cat "$TMP/lnet_$1" |wc -l)
12728         # subtracting one from $blp because the body can be empty
12729         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
12730
12731         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
12732                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
12733
12734         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
12735                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
12736
12737         # bail out if any unexpected line happened
12738         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
12739         [ "$?" != 0 ] || error "$2 misformatted"
12740 }
12741
12742 test_215() { # for bugs 18102, 21079, 21517
12743         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12744         local N='(0|[1-9][0-9]*)'       # non-negative numeric
12745         local P='[1-9][0-9]*'           # positive numeric
12746         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
12747         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
12748         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
12749         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
12750
12751         local L1 # regexp for 1st line
12752         local L2 # regexp for 2nd line (optional)
12753         local BR # regexp for the rest (body)
12754
12755         # lnet.stats should look as 11 space-separated non-negative numerics
12756         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
12757         create_lnet_proc_files "stats"
12758         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
12759         remove_lnet_proc_files "stats"
12760
12761         # lnet.routes should look like this:
12762         # Routing disabled/enabled
12763         # net hops priority state router
12764         # where net is a string like tcp0, hops > 0, priority >= 0,
12765         # state is up/down,
12766         # router is a string like 192.168.1.1@tcp2
12767         L1="^Routing (disabled|enabled)$"
12768         L2="^net +hops +priority +state +router$"
12769         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
12770         create_lnet_proc_files "routes"
12771         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
12772         remove_lnet_proc_files "routes"
12773
12774         # lnet.routers should look like this:
12775         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
12776         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
12777         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
12778         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
12779         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
12780         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
12781         create_lnet_proc_files "routers"
12782         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
12783         remove_lnet_proc_files "routers"
12784
12785         # lnet.peers should look like this:
12786         # nid refs state last max rtr min tx min queue
12787         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
12788         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
12789         # numeric (0 or >0 or <0), queue >= 0.
12790         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
12791         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
12792         create_lnet_proc_files "peers"
12793         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
12794         remove_lnet_proc_files "peers"
12795
12796         # lnet.buffers  should look like this:
12797         # pages count credits min
12798         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
12799         L1="^pages +count +credits +min$"
12800         BR="^ +$N +$N +$I +$I$"
12801         create_lnet_proc_files "buffers"
12802         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
12803         remove_lnet_proc_files "buffers"
12804
12805         # lnet.nis should look like this:
12806         # nid status alive refs peer rtr max tx min
12807         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
12808         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
12809         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
12810         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
12811         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
12812         create_lnet_proc_files "nis"
12813         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
12814         remove_lnet_proc_files "nis"
12815
12816         # can we successfully write to lnet.stats?
12817         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
12818 }
12819 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
12820
12821 test_216() { # bug 20317
12822         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12823         remote_ost_nodsh && skip "remote OST with nodsh" && return
12824
12825         local node
12826         local facets=$(get_facets OST)
12827         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
12828
12829         save_lustre_params client "osc.*.contention_seconds" > $p
12830         save_lustre_params $facets \
12831                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
12832         save_lustre_params $facets \
12833                 "ldlm.namespaces.filter-*.contended_locks" >> $p
12834         save_lustre_params $facets \
12835                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
12836         clear_stats osc.*.osc_stats
12837
12838         # agressive lockless i/o settings
12839         do_nodes $(comma_list $(osts_nodes)) \
12840                 "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
12841                         ldlm.namespaces.filter-*.contended_locks=0 \
12842                         ldlm.namespaces.filter-*.contention_seconds=60"
12843         lctl set_param -n osc.*.contention_seconds=60
12844
12845         $DIRECTIO write $DIR/$tfile 0 10 4096
12846         $CHECKSTAT -s 40960 $DIR/$tfile
12847
12848         # disable lockless i/o
12849         do_nodes $(comma_list $(osts_nodes)) \
12850                 "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
12851                         ldlm.namespaces.filter-*.contended_locks=32 \
12852                         ldlm.namespaces.filter-*.contention_seconds=0"
12853         lctl set_param -n osc.*.contention_seconds=0
12854         clear_stats osc.*.osc_stats
12855
12856         dd if=/dev/zero of=$DIR/$tfile count=0
12857         $CHECKSTAT -s 0 $DIR/$tfile
12858
12859         restore_lustre_params <$p
12860         rm -f $p
12861         rm $DIR/$tfile
12862 }
12863 run_test 216 "check lockless direct write updates file size and kms correctly"
12864
12865 test_217() { # bug 22430
12866         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12867         local node
12868         local nid
12869
12870         for node in $(nodes_list); do
12871                 nid=$(host_nids_address $node $NETTYPE)
12872                 if [[ $nid = *-* ]] ; then
12873                         echo "lctl ping $(h2nettype $nid)"
12874                         lctl ping $(h2nettype $nid)
12875                 else
12876                         echo "skipping $node (no hyphen detected)"
12877                 fi
12878         done
12879 }
12880 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
12881
12882 test_218() {
12883        # do directio so as not to populate the page cache
12884        log "creating a 10 Mb file"
12885        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
12886        log "starting reads"
12887        dd if=$DIR/$tfile of=/dev/null bs=4096 &
12888        log "truncating the file"
12889        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
12890        log "killing dd"
12891        kill %+ || true # reads might have finished
12892        echo "wait until dd is finished"
12893        wait
12894        log "removing the temporary file"
12895        rm -rf $DIR/$tfile || error "tmp file removal failed"
12896 }
12897 run_test 218 "parallel read and truncate should not deadlock ======================="
12898
12899 test_219() {
12900         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12901         # write one partial page
12902         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
12903         # set no grant so vvp_io_commit_write will do sync write
12904         $LCTL set_param fail_loc=0x411
12905         # write a full page at the end of file
12906         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
12907
12908         $LCTL set_param fail_loc=0
12909         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
12910         $LCTL set_param fail_loc=0x411
12911         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
12912
12913         # LU-4201
12914         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
12915         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
12916 }
12917 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
12918
12919 test_220() { #LU-325
12920         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12921         remote_ost_nodsh && skip "remote OST with nodsh" && return
12922         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12923         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12924         local OSTIDX=0
12925
12926         # create on MDT0000 so the last_id and next_id are correct
12927         mkdir $DIR/$tdir
12928         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
12929         OST=${OST%_UUID}
12930
12931         # on the mdt's osc
12932         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
12933         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
12934                         osc.$mdtosc_proc1.prealloc_last_id)
12935         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
12936                         osc.$mdtosc_proc1.prealloc_next_id)
12937
12938         $LFS df -i
12939
12940         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
12941         #define OBD_FAIL_OST_ENOINO              0x229
12942         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
12943         create_pool $FSNAME.$TESTNAME || return 1
12944         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
12945
12946         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
12947
12948         MDSOBJS=$((last_id - next_id))
12949         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
12950
12951         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
12952         echo "OST still has $count kbytes free"
12953
12954         echo "create $MDSOBJS files @next_id..."
12955         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
12956
12957         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12958                         osc.$mdtosc_proc1.prealloc_last_id)
12959         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12960                         osc.$mdtosc_proc1.prealloc_next_id)
12961
12962         echo "after creation, last_id=$last_id2, next_id=$next_id2"
12963         $LFS df -i
12964
12965         echo "cleanup..."
12966
12967         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
12968         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
12969
12970         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
12971         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
12972         echo "unlink $MDSOBJS files @$next_id..."
12973         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
12974 }
12975 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
12976
12977 test_221() {
12978         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12979         dd if=`which date` of=$MOUNT/date oflag=sync
12980         chmod +x $MOUNT/date
12981
12982         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
12983         $LCTL set_param fail_loc=0x80001401
12984
12985         $MOUNT/date > /dev/null
12986         rm -f $MOUNT/date
12987 }
12988 run_test 221 "make sure fault and truncate race to not cause OOM"
12989
12990 test_222a () {
12991         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12992         rm -rf $DIR/$tdir
12993         test_mkdir $DIR/$tdir
12994         $LFS setstripe -c 1 -i 0 $DIR/$tdir
12995         createmany -o $DIR/$tdir/$tfile 10
12996         cancel_lru_locks mdc
12997         cancel_lru_locks osc
12998         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12999         $LCTL set_param fail_loc=0x31a
13000         ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
13001         $LCTL set_param fail_loc=0
13002         rm -r $DIR/$tdir
13003 }
13004 run_test 222a "AGL for ls should not trigger CLIO lock failure"
13005
13006 test_222b () {
13007         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13008         rm -rf $DIR/$tdir
13009         test_mkdir $DIR/$tdir
13010         $LFS setstripe -c 1 -i 0 $DIR/$tdir
13011         createmany -o $DIR/$tdir/$tfile 10
13012         cancel_lru_locks mdc
13013         cancel_lru_locks osc
13014         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
13015         $LCTL set_param fail_loc=0x31a
13016         rm -r $DIR/$tdir || error "AGL for rmdir failed"
13017         $LCTL set_param fail_loc=0
13018 }
13019 run_test 222b "AGL for rmdir should not trigger CLIO lock failure"
13020
13021 test_223 () {
13022         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13023         rm -rf $DIR/$tdir
13024         test_mkdir $DIR/$tdir
13025         $LFS setstripe -c 1 -i 0 $DIR/$tdir
13026         createmany -o $DIR/$tdir/$tfile 10
13027         cancel_lru_locks mdc
13028         cancel_lru_locks osc
13029         #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
13030         $LCTL set_param fail_loc=0x31b
13031         ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
13032         $LCTL set_param fail_loc=0
13033         rm -r $DIR/$tdir
13034 }
13035 run_test 223 "osc reenqueue if without AGL lock granted ======================="
13036
13037 test_224a() { # LU-1039, MRP-303
13038         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13039         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
13040         $LCTL set_param fail_loc=0x508
13041         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
13042         $LCTL set_param fail_loc=0
13043         df $DIR
13044 }
13045 run_test 224a "Don't panic on bulk IO failure"
13046
13047 test_224b() { # LU-1039, MRP-303
13048         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13049         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
13050         cancel_lru_locks osc
13051         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
13052         $LCTL set_param fail_loc=0x515
13053         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
13054         $LCTL set_param fail_loc=0
13055         df $DIR
13056 }
13057 run_test 224b "Don't panic on bulk IO failure"
13058
13059 test_224c() { # LU-6441
13060         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13061         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13062
13063         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13064         save_writethrough $p
13065         set_cache writethrough on
13066
13067         local pages_per_rpc=$($LCTL get_param \
13068                                 osc.*.max_pages_per_rpc)
13069         local at_max=$($LCTL get_param -n at_max)
13070         local timeout=$($LCTL get_param -n timeout)
13071         local test_at="$LCTL get_param -n at_max"
13072         local param_at="$FSNAME.sys.at_max"
13073         local test_timeout="$LCTL get_param -n timeout"
13074         local param_timeout="$FSNAME.sys.timeout"
13075
13076         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
13077
13078         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
13079                 error "conf_param at_max=0 failed"
13080         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
13081                 error "conf_param timeout=5 failed"
13082
13083         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
13084         do_facet ost1 $LCTL set_param fail_loc=0x520
13085         $LFS setstripe -c 1 -i 0 $DIR/$tfile
13086         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
13087         sync
13088         do_facet ost1 $LCTL set_param fail_loc=0
13089
13090         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
13091                 error "conf_param at_max=$at_max failed"
13092         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
13093                 $timeout || error "conf_param timeout=$timeout failed"
13094
13095         $LCTL set_param -n $pages_per_rpc
13096         restore_lustre_params < $p
13097         rm -f $p
13098 }
13099 run_test 224c "Don't hang if one of md lost during large bulk RPC"
13100
13101 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
13102 test_225a () {
13103         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13104         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13105         if [ -z ${MDSSURVEY} ]; then
13106               skip_env "mds-survey not found" && return
13107         fi
13108
13109         [ $MDSCOUNT -ge 2 ] &&
13110                 skip "skipping now for more than one MDT" && return
13111
13112        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
13113             { skip "Need MDS version at least 2.2.51"; return; }
13114
13115        local mds=$(facet_host $SINGLEMDS)
13116        local target=$(do_nodes $mds 'lctl dl' | \
13117                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
13118
13119        local cmd1="file_count=1000 thrhi=4"
13120        local cmd2="dir_count=2 layer=mdd stripe_count=0"
13121        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
13122        local cmd="$cmd1 $cmd2 $cmd3"
13123
13124        rm -f ${TMP}/mds_survey*
13125        echo + $cmd
13126        eval $cmd || error "mds-survey with zero-stripe failed"
13127        cat ${TMP}/mds_survey*
13128        rm -f ${TMP}/mds_survey*
13129 }
13130 run_test 225a "Metadata survey sanity with zero-stripe"
13131
13132 test_225b () {
13133         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13134         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13135         if [ -z ${MDSSURVEY} ]; then
13136               skip_env "mds-survey not found" && return
13137         fi
13138         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
13139             { skip "Need MDS version at least 2.2.51"; return; }
13140
13141         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
13142               skip_env "Need to mount OST to test" && return
13143         fi
13144
13145         [ $MDSCOUNT -ge 2 ] &&
13146                 skip "skipping now for more than one MDT" && return
13147        local mds=$(facet_host $SINGLEMDS)
13148        local target=$(do_nodes $mds 'lctl dl' | \
13149                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
13150
13151        local cmd1="file_count=1000 thrhi=4"
13152        local cmd2="dir_count=2 layer=mdd stripe_count=1"
13153        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
13154        local cmd="$cmd1 $cmd2 $cmd3"
13155
13156        rm -f ${TMP}/mds_survey*
13157        echo + $cmd
13158        eval $cmd || error "mds-survey with stripe_count failed"
13159        cat ${TMP}/mds_survey*
13160        rm -f ${TMP}/mds_survey*
13161 }
13162 run_test 225b "Metadata survey sanity with stripe_count = 1"
13163
13164 mcreate_path2fid () {
13165         local mode=$1
13166         local major=$2
13167         local minor=$3
13168         local name=$4
13169         local desc=$5
13170         local path=$DIR/$tdir/$name
13171         local fid
13172         local rc
13173         local fid_path
13174
13175         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
13176                 error "cannot create $desc"
13177
13178         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
13179         rc=$?
13180         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
13181
13182         fid_path=$($LFS fid2path $MOUNT $fid)
13183         rc=$?
13184         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
13185
13186         [ "$path" == "$fid_path" ] ||
13187                 error "fid2path returned $fid_path, expected $path"
13188
13189         echo "pass with $path and $fid"
13190 }
13191
13192 test_226a () {
13193         rm -rf $DIR/$tdir
13194         mkdir -p $DIR/$tdir
13195
13196         mcreate_path2fid 0010666 0 0 fifo "FIFO"
13197         mcreate_path2fid 0020666 1 3 null "character special file (null)"
13198         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
13199         mcreate_path2fid 0040666 0 0 dir "directory"
13200         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
13201         mcreate_path2fid 0100666 0 0 file "regular file"
13202         mcreate_path2fid 0120666 0 0 link "symbolic link"
13203         mcreate_path2fid 0140666 0 0 sock "socket"
13204 }
13205 run_test 226a "call path2fid and fid2path on files of all type"
13206
13207 test_226b () {
13208         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13209         rm -rf $DIR/$tdir
13210         local MDTIDX=1
13211
13212         mkdir -p $DIR/$tdir
13213         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
13214                 error "create remote directory failed"
13215         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
13216         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
13217                                 "character special file (null)"
13218         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
13219                                 "character special file (no device)"
13220         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
13221         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
13222                                 "block special file (loop)"
13223         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
13224         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
13225         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
13226 }
13227 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
13228
13229 # LU-1299 Executing or running ldd on a truncated executable does not
13230 # cause an out-of-memory condition.
13231 test_227() {
13232         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13233         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
13234         dd if=$(which date) of=$MOUNT/date bs=1k count=1
13235         chmod +x $MOUNT/date
13236
13237         $MOUNT/date > /dev/null
13238         ldd $MOUNT/date > /dev/null
13239         rm -f $MOUNT/date
13240 }
13241 run_test 227 "running truncated executable does not cause OOM"
13242
13243 # LU-1512 try to reuse idle OI blocks
13244 test_228a() {
13245         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13246         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13247         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13248                 skip "ldiskfs only test" && return
13249
13250         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13251         local myDIR=$DIR/$tdir
13252
13253         mkdir -p $myDIR
13254         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13255         $LCTL set_param fail_loc=0x80001002
13256         createmany -o $myDIR/t- 10000
13257         $LCTL set_param fail_loc=0
13258         # The guard is current the largest FID holder
13259         touch $myDIR/guard
13260         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13261                     tr -d '[')
13262         local IDX=$(($SEQ % 64))
13263
13264         do_facet $SINGLEMDS sync
13265         # Make sure journal flushed.
13266         sleep 6
13267         local blk1=$(do_facet $SINGLEMDS \
13268                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13269                      grep Blockcount | awk '{print $4}')
13270
13271         # Remove old files, some OI blocks will become idle.
13272         unlinkmany $myDIR/t- 10000
13273         # Create new files, idle OI blocks should be reused.
13274         createmany -o $myDIR/t- 2000
13275         do_facet $SINGLEMDS sync
13276         # Make sure journal flushed.
13277         sleep 6
13278         local blk2=$(do_facet $SINGLEMDS \
13279                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13280                      grep Blockcount | awk '{print $4}')
13281
13282         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13283 }
13284 run_test 228a "try to reuse idle OI blocks"
13285
13286 test_228b() {
13287         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13288         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13289         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13290                 skip "ldiskfs only test" && return
13291
13292         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13293         local myDIR=$DIR/$tdir
13294
13295         mkdir -p $myDIR
13296         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13297         $LCTL set_param fail_loc=0x80001002
13298         createmany -o $myDIR/t- 10000
13299         $LCTL set_param fail_loc=0
13300         # The guard is current the largest FID holder
13301         touch $myDIR/guard
13302         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13303                     tr -d '[')
13304         local IDX=$(($SEQ % 64))
13305
13306         do_facet $SINGLEMDS sync
13307         # Make sure journal flushed.
13308         sleep 6
13309         local blk1=$(do_facet $SINGLEMDS \
13310                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13311                      grep Blockcount | awk '{print $4}')
13312
13313         # Remove old files, some OI blocks will become idle.
13314         unlinkmany $myDIR/t- 10000
13315
13316         # stop the MDT
13317         stop $SINGLEMDS || error "Fail to stop MDT."
13318         # remount the MDT
13319         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
13320
13321         df $MOUNT || error "Fail to df."
13322         # Create new files, idle OI blocks should be reused.
13323         createmany -o $myDIR/t- 2000
13324         do_facet $SINGLEMDS sync
13325         # Make sure journal flushed.
13326         sleep 6
13327         local blk2=$(do_facet $SINGLEMDS \
13328                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13329                      grep Blockcount | awk '{print $4}')
13330
13331         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13332 }
13333 run_test 228b "idle OI blocks can be reused after MDT restart"
13334
13335 #LU-1881
13336 test_228c() {
13337         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13338         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13339         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13340                 skip "ldiskfs only test" && return
13341
13342         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13343         local myDIR=$DIR/$tdir
13344
13345         mkdir -p $myDIR
13346         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13347         $LCTL set_param fail_loc=0x80001002
13348         # 20000 files can guarantee there are index nodes in the OI file
13349         createmany -o $myDIR/t- 20000
13350         $LCTL set_param fail_loc=0
13351         # The guard is current the largest FID holder
13352         touch $myDIR/guard
13353         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13354                     tr -d '[')
13355         local IDX=$(($SEQ % 64))
13356
13357         do_facet $SINGLEMDS sync
13358         # Make sure journal flushed.
13359         sleep 6
13360         local blk1=$(do_facet $SINGLEMDS \
13361                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13362                      grep Blockcount | awk '{print $4}')
13363
13364         # Remove old files, some OI blocks will become idle.
13365         unlinkmany $myDIR/t- 20000
13366         rm -f $myDIR/guard
13367         # The OI file should become empty now
13368
13369         # Create new files, idle OI blocks should be reused.
13370         createmany -o $myDIR/t- 2000
13371         do_facet $SINGLEMDS sync
13372         # Make sure journal flushed.
13373         sleep 6
13374         local blk2=$(do_facet $SINGLEMDS \
13375                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13376                      grep Blockcount | awk '{print $4}')
13377
13378         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13379 }
13380 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
13381
13382 test_229() { # LU-2482, LU-3448
13383         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
13384                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
13385                 return
13386         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13387         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
13388
13389         rm -f $DIR/$tfile
13390
13391         # Create a file with a released layout and stripe count 2.
13392         $MULTIOP $DIR/$tfile H2c ||
13393                 error "failed to create file with released layout"
13394
13395         $GETSTRIPE -v $DIR/$tfile
13396
13397         local pattern=$($GETSTRIPE -L $DIR/$tfile)
13398         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
13399
13400         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
13401         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
13402         stat $DIR/$tfile || error "failed to stat released file"
13403
13404         chown $RUNAS_ID $DIR/$tfile ||
13405                 error "chown $RUNAS_ID $DIR/$tfile failed"
13406
13407         chgrp $RUNAS_ID $DIR/$tfile ||
13408                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
13409
13410         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
13411         rm $DIR/$tfile || error "failed to remove released file"
13412 }
13413 run_test 229 "getstripe/stat/rm/attr changes work on released files"
13414
13415 test_230a() {
13416         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13417         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13418         local MDTIDX=1
13419
13420         test_mkdir $DIR/$tdir
13421         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
13422         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
13423         [ $mdt_idx -ne 0 ] &&
13424                 error "create local directory on wrong MDT $mdt_idx"
13425
13426         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
13427                         error "create remote directory failed"
13428         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
13429         [ $mdt_idx -ne $MDTIDX ] &&
13430                 error "create remote directory on wrong MDT $mdt_idx"
13431
13432         createmany -o $DIR/$tdir/test_230/t- 10 ||
13433                 error "create files on remote directory failed"
13434         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
13435         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
13436         rm -r $DIR/$tdir || error "unlink remote directory failed"
13437 }
13438 run_test 230a "Create remote directory and files under the remote directory"
13439
13440 test_230b() {
13441         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13442         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13443         local MDTIDX=1
13444         local mdt_index
13445         local i
13446         local file
13447         local pid
13448         local stripe_count
13449         local migrate_dir=$DIR/$tdir/migrate_dir
13450         local other_dir=$DIR/$tdir/other_dir
13451
13452         test_mkdir $DIR/$tdir
13453         test_mkdir -i0 -c1 $migrate_dir
13454         test_mkdir -i0 -c1 $other_dir
13455         for ((i=0; i<10; i++)); do
13456                 mkdir -p $migrate_dir/dir_${i}
13457                 createmany -o $migrate_dir/dir_${i}/f 10 ||
13458                         error "create files under remote dir failed $i"
13459         done
13460
13461         cp /etc/passwd $migrate_dir/$tfile
13462         cp /etc/passwd $other_dir/$tfile
13463         chattr +SAD $migrate_dir
13464         chattr +SAD $migrate_dir/$tfile
13465
13466         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13467         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13468         local old_dir_mode=$(stat -c%f $migrate_dir)
13469         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
13470
13471         mkdir -p $migrate_dir/dir_default_stripe2
13472         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
13473         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
13474
13475         mkdir -p $other_dir
13476         ln $migrate_dir/$tfile $other_dir/luna
13477         ln $migrate_dir/$tfile $migrate_dir/sofia
13478         ln $other_dir/$tfile $migrate_dir/david
13479         ln -s $migrate_dir/$tfile $other_dir/zachary
13480         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
13481         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
13482
13483         $LFS migrate -m $MDTIDX $migrate_dir ||
13484                 error "fails on migrating remote dir to MDT1"
13485
13486         echo "migratate to MDT1, then checking.."
13487         for ((i = 0; i < 10; i++)); do
13488                 for file in $(find $migrate_dir/dir_${i}); do
13489                         mdt_index=$($LFS getstripe -M $file)
13490                         [ $mdt_index == $MDTIDX ] ||
13491                                 error "$file is not on MDT${MDTIDX}"
13492                 done
13493         done
13494
13495         # the multiple link file should still in MDT0
13496         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
13497         [ $mdt_index == 0 ] ||
13498                 error "$file is not on MDT${MDTIDX}"
13499
13500         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13501         [ "$old_dir_flag" = "$new_dir_flag" ] ||
13502                 error " expect $old_dir_flag get $new_dir_flag"
13503
13504         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13505         [ "$old_file_flag" = "$new_file_flag" ] ||
13506                 error " expect $old_file_flag get $new_file_flag"
13507
13508         local new_dir_mode=$(stat -c%f $migrate_dir)
13509         [ "$old_dir_mode" = "$new_dir_mode" ] ||
13510                 error "expect mode $old_dir_mode get $new_dir_mode"
13511
13512         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
13513         [ "$old_file_mode" = "$new_file_mode" ] ||
13514                 error "expect mode $old_file_mode get $new_file_mode"
13515
13516         diff /etc/passwd $migrate_dir/$tfile ||
13517                 error "$tfile different after migration"
13518
13519         diff /etc/passwd $other_dir/luna ||
13520                 error "luna different after migration"
13521
13522         diff /etc/passwd $migrate_dir/sofia ||
13523                 error "sofia different after migration"
13524
13525         diff /etc/passwd $migrate_dir/david ||
13526                 error "david different after migration"
13527
13528         diff /etc/passwd $other_dir/zachary ||
13529                 error "zachary different after migration"
13530
13531         diff /etc/passwd $migrate_dir/${tfile}_ln ||
13532                 error "${tfile}_ln different after migration"
13533
13534         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
13535                 error "${tfile}_ln_other different after migration"
13536
13537         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
13538         [ $stripe_count = 2 ] ||
13539                 error "dir strpe_count $d != 2 after migration."
13540
13541         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
13542         [ $stripe_count = 2 ] ||
13543                 error "file strpe_count $d != 2 after migration."
13544
13545         #migrate back to MDT0
13546         MDTIDX=0
13547
13548         $LFS migrate -m $MDTIDX $migrate_dir ||
13549                 error "fails on migrating remote dir to MDT0"
13550
13551         echo "migrate back to MDT0, checking.."
13552         for file in $(find $migrate_dir); do
13553                 mdt_index=$($LFS getstripe -M $file)
13554                 [ $mdt_index == $MDTIDX ] ||
13555                         error "$file is not on MDT${MDTIDX}"
13556         done
13557
13558         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13559         [ "$old_dir_flag" = "$new_dir_flag" ] ||
13560                 error " expect $old_dir_flag get $new_dir_flag"
13561
13562         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13563         [ "$old_file_flag" = "$new_file_flag" ] ||
13564                 error " expect $old_file_flag get $new_file_flag"
13565
13566         local new_dir_mode=$(stat -c%f $migrate_dir)
13567         [ "$old_dir_mode" = "$new_dir_mode" ] ||
13568                 error "expect mode $old_dir_mode get $new_dir_mode"
13569
13570         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
13571         [ "$old_file_mode" = "$new_file_mode" ] ||
13572                 error "expect mode $old_file_mode get $new_file_mode"
13573
13574         diff /etc/passwd ${migrate_dir}/$tfile ||
13575                 error "$tfile different after migration"
13576
13577         diff /etc/passwd ${other_dir}/luna ||
13578                 error "luna different after migration"
13579
13580         diff /etc/passwd ${migrate_dir}/sofia ||
13581                 error "sofia different after migration"
13582
13583         diff /etc/passwd ${other_dir}/zachary ||
13584                 error "zachary different after migration"
13585
13586         diff /etc/passwd $migrate_dir/${tfile}_ln ||
13587                 error "${tfile}_ln different after migration"
13588
13589         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
13590                 error "${tfile}_ln_other different after migration"
13591
13592         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
13593         [ $stripe_count = 2 ] ||
13594                 error "dir strpe_count $d != 2 after migration."
13595
13596         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
13597         [ $stripe_count = 2 ] ||
13598                 error "file strpe_count $d != 2 after migration."
13599
13600         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13601 }
13602 run_test 230b "migrate directory"
13603
13604 test_230c() {
13605         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13606         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13607         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13608         local MDTIDX=1
13609         local mdt_index
13610         local file
13611         local migrate_dir=$DIR/$tdir/migrate_dir
13612
13613         #If migrating directory fails in the middle, all entries of
13614         #the directory is still accessiable.
13615         test_mkdir $DIR/$tdir
13616         test_mkdir -i0 -c1 $migrate_dir
13617         stat $migrate_dir
13618         createmany -o $migrate_dir/f 10 ||
13619                 error "create files under ${migrate_dir} failed"
13620
13621         #failed after migrating 5 entries
13622         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
13623         do_facet mds1 lctl set_param fail_loc=0x20001801
13624         do_facet mds1 lctl  set_param fail_val=5
13625         local t=$(ls $migrate_dir | wc -l)
13626         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
13627                 error "migrate should fail after 5 entries"
13628
13629         mkdir $migrate_dir/dir &&
13630                 error "mkdir succeeds under migrating directory"
13631         touch $migrate_dir/file &&
13632                 error "touch file succeeds under migrating directory"
13633
13634         local u=$(ls $migrate_dir | wc -l)
13635         [ "$u" == "$t" ] || error "$u != $t during migration"
13636
13637         for file in $(find $migrate_dir); do
13638                 stat $file || error "stat $file failed"
13639         done
13640
13641         do_facet mds1 lctl set_param fail_loc=0
13642         do_facet mds1 lctl set_param fail_val=0
13643
13644         $LFS migrate -m $MDTIDX $migrate_dir ||
13645                 error "migrate open files should failed with open files"
13646
13647         echo "Finish migration, then checking.."
13648         for file in $(find $migrate_dir); do
13649                 mdt_index=$($LFS getstripe -M $file)
13650                 [ $mdt_index == $MDTIDX ] ||
13651                         error "$file is not on MDT${MDTIDX}"
13652         done
13653
13654         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13655 }
13656 run_test 230c "check directory accessiblity if migration is failed"
13657
13658 test_230d() {
13659         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13660         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13661         local MDTIDX=1
13662         local mdt_index
13663         local migrate_dir=$DIR/$tdir/migrate_dir
13664         local i
13665         local j
13666
13667         test_mkdir $DIR/$tdir
13668         test_mkdir -i0 -c1 $migrate_dir
13669
13670         for ((i=0; i<100; i++)); do
13671                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
13672                 createmany -o $migrate_dir/dir_${i}/f 100 ||
13673                         error "create files under remote dir failed $i"
13674         done
13675
13676         $LFS migrate -m $MDTIDX $migrate_dir ||
13677                 error "migrate remote dir error"
13678
13679         echo "Finish migration, then checking.."
13680         for file in $(find $migrate_dir); do
13681                 mdt_index=$($LFS getstripe -M $file)
13682                 [ $mdt_index == $MDTIDX ] ||
13683                         error "$file is not on MDT${MDTIDX}"
13684         done
13685
13686         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13687 }
13688 run_test 230d "check migrate big directory"
13689
13690 test_230e() {
13691         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13692         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13693         local i
13694         local j
13695         local a_fid
13696         local b_fid
13697
13698         mkdir -p $DIR/$tdir
13699         mkdir $DIR/$tdir/migrate_dir
13700         mkdir $DIR/$tdir/other_dir
13701         touch $DIR/$tdir/migrate_dir/a
13702         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
13703         ls $DIR/$tdir/other_dir
13704
13705         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13706                 error "migrate dir fails"
13707
13708         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13709         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
13710
13711         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13712         [ $mdt_index == 0 ] || error "a is not on MDT0"
13713
13714         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
13715                 error "migrate dir fails"
13716
13717         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir)
13718         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
13719
13720         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13721         [ $mdt_index == 1 ] || error "a is not on MDT1"
13722
13723         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir/b)
13724         [ $mdt_index == 1 ] || error "b is not on MDT1"
13725
13726         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13727         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
13728
13729         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
13730
13731         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13732 }
13733 run_test 230e "migrate mulitple local link files"
13734
13735 test_230f() {
13736         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13737         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13738         local a_fid
13739         local ln_fid
13740
13741         mkdir -p $DIR/$tdir
13742         mkdir $DIR/$tdir/migrate_dir
13743         $LFS mkdir -i1 $DIR/$tdir/other_dir
13744         touch $DIR/$tdir/migrate_dir/a
13745         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
13746         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
13747         ls $DIR/$tdir/other_dir
13748
13749         # a should be migrated to MDT1, since no other links on MDT0
13750         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13751                 error "#1 migrate dir fails"
13752         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13753         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
13754         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13755         [ $mdt_index == 1 ] || error "a is not on MDT1"
13756
13757         # a should stay on MDT1, because it is a mulitple link file
13758         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13759                 error "#2 migrate dir fails"
13760         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13761         [ $mdt_index == 1 ] || error "a is not on MDT1"
13762
13763         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13764                 error "#3 migrate dir fails"
13765
13766         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13767         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
13768         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
13769
13770         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
13771         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
13772
13773         # a should be migrated to MDT0, since no other links on MDT1
13774         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13775                 error "#4 migrate dir fails"
13776         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13777         [ $mdt_index == 0 ] || error "a is not on MDT0"
13778
13779         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13780 }
13781 run_test 230f "migrate mulitple remote link files"
13782
13783 test_230g() {
13784         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13785         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13786
13787         mkdir -p $DIR/$tdir/migrate_dir
13788
13789         $LFS migrate -m 1000 $DIR/$tdir/migrate_dir &&
13790                 error "migrating dir to non-exist MDT succeeds"
13791         true
13792 }
13793 run_test 230g "migrate dir to non-exist MDT"
13794
13795 test_230h() {
13796         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13797         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13798         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
13799                 skip "Need MDS version at least 2.7.64" && return
13800         local mdt_index
13801
13802         mkdir -p $DIR/$tdir/migrate_dir
13803
13804         $LFS migrate -m1 $DIR &&
13805                 error "migrating mountpoint1 should fail"
13806
13807         $LFS migrate -m1 $DIR/$tdir/.. &&
13808                 error "migrating mountpoint2 should fail"
13809
13810         $LFS migrate -m1 $DIR/$tdir/migrate_dir/.. ||
13811                 error "migrating $tdir fail"
13812
13813         mdt_index=$($LFS getstripe -M $DIR/$tdir)
13814         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13815
13816         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13817         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13818
13819 }
13820 run_test 230h "migrate .. and root"
13821
13822 test_230i() {
13823         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13824         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13825
13826         mkdir -p $DIR/$tdir/migrate_dir
13827
13828         $LFS migrate -m 1 $DIR/$tdir/migrate_dir/ ||
13829                 error "migration fails with a tailing slash"
13830
13831         $LFS migrate -m 0 $DIR/$tdir/migrate_dir// ||
13832                 error "migration fails with two tailing slashes"
13833 }
13834 run_test 230i "lfs migrate -m tolerates trailing slashes"
13835
13836 test_231a()
13837 {
13838         # For simplicity this test assumes that max_pages_per_rpc
13839         # is the same across all OSCs
13840         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
13841         local bulk_size=$((max_pages * 4096))
13842         local brw_size=$(do_facet ost1 $LCTL get_param -n obdfilter.*.brw_size |
13843                                        head -n 1)
13844
13845         mkdir -p $DIR/$tdir
13846         $LFS setstripe -S ${brw_size}M $DIR/$tdir ||
13847                 error "failed to set stripe with -S ${brw_size}M option"
13848
13849         # clear the OSC stats
13850         $LCTL set_param osc.*.stats=0 &>/dev/null
13851         stop_writeback
13852
13853         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
13854         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
13855                 oflag=direct &>/dev/null || error "dd failed"
13856
13857         sync; sleep 1; sync # just to be safe
13858         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
13859         if [ x$nrpcs != "x1" ]; then
13860                 $LCTL get_param osc.*.stats
13861                 error "found $nrpcs ost_write RPCs, not 1 as expected"
13862         fi
13863
13864         start_writeback
13865         # Drop the OSC cache, otherwise we will read from it
13866         cancel_lru_locks osc
13867
13868         # clear the OSC stats
13869         $LCTL set_param osc.*.stats=0 &>/dev/null
13870
13871         # Client reads $bulk_size.
13872         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
13873                 iflag=direct &>/dev/null || error "dd failed"
13874
13875         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
13876         if [ x$nrpcs != "x1" ]; then
13877                 $LCTL get_param osc.*.stats
13878                 error "found $nrpcs ost_read RPCs, not 1 as expected"
13879         fi
13880 }
13881 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
13882
13883 test_231b() {
13884         mkdir -p $DIR/$tdir
13885         local i
13886         for i in {0..1023}; do
13887                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
13888                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
13889                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
13890         done
13891         sync
13892 }
13893 run_test 231b "must not assert on fully utilized OST request buffer"
13894
13895 test_232() {
13896         mkdir -p $DIR/$tdir
13897         #define OBD_FAIL_LDLM_OST_LVB            0x31c
13898         $LCTL set_param fail_loc=0x31c
13899
13900         # ignore dd failure
13901         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
13902
13903         $LCTL set_param fail_loc=0
13904         umount_client $MOUNT || error "umount failed"
13905         mount_client $MOUNT || error "mount failed"
13906 }
13907 run_test 232 "failed lock should not block umount"
13908
13909 test_233a() {
13910         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
13911         { skip "Need MDS version at least 2.3.64"; return; }
13912         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
13913
13914         local fid=$($LFS path2fid $MOUNT)
13915         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13916                 error "cannot access $MOUNT using its FID '$fid'"
13917 }
13918 run_test 233a "checking that OBF of the FS root succeeds"
13919
13920 test_233b() {
13921         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
13922         { skip "Need MDS version at least 2.5.90"; return; }
13923         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
13924
13925         local fid=$($LFS path2fid $MOUNT/.lustre)
13926         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13927                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
13928
13929         fid=$($LFS path2fid $MOUNT/.lustre/fid)
13930         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13931                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
13932 }
13933 run_test 233b "checking that OBF of the FS .lustre succeeds"
13934
13935 test_234() {
13936         local p="$TMP/sanityN-$TESTNAME.parameters"
13937         save_lustre_params client "llite.*.xattr_cache" > $p
13938         lctl set_param llite.*.xattr_cache 1 ||
13939                 { skip "xattr cache is not supported"; return 0; }
13940
13941         mkdir -p $DIR/$tdir || error "mkdir failed"
13942         touch $DIR/$tdir/$tfile || error "touch failed"
13943         # OBD_FAIL_LLITE_XATTR_ENOMEM
13944         $LCTL set_param fail_loc=0x1405
13945         # output of the form: attr 2 4 44 3 fc13 x86_64
13946         V=($(IFS=".-" rpm -q attr))
13947         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
13948               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
13949                 # attr pre-2.4.44-7 had a bug with rc
13950                 # LU-3703 - SLES 11 and FC13 clients have older attr
13951                 getfattr -n user.attr $DIR/$tdir/$tfile &&
13952                         error "getfattr should have failed with ENOMEM"
13953         else
13954                 skip "LU-3703: attr version $(getfattr --version) too old"
13955         fi
13956         $LCTL set_param fail_loc=0x0
13957         rm -rf $DIR/$tdir
13958
13959         restore_lustre_params < $p
13960         rm -f $p
13961 }
13962 run_test 234 "xattr cache should not crash on ENOMEM"
13963
13964 test_235() {
13965         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
13966                 skip "Need MDS version at least 2.4.52" && return
13967         flock_deadlock $DIR/$tfile
13968         local RC=$?
13969         case $RC in
13970                 0)
13971                 ;;
13972                 124) error "process hangs on a deadlock"
13973                 ;;
13974                 *) error "error executing flock_deadlock $DIR/$tfile"
13975                 ;;
13976         esac
13977 }
13978 run_test 235 "LU-1715: flock deadlock detection does not work properly"
13979
13980 #LU-2935
13981 test_236() {
13982         check_swap_layouts_support && return 0
13983         test_mkdir -c1 $DIR/$tdir
13984
13985         local ref1=/etc/passwd
13986         local ref2=/etc/group
13987         local file1=$DIR/$tdir/f1
13988         local file2=$DIR/$tdir/f2
13989
13990         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
13991         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
13992         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
13993         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
13994         local fd=$(free_fd)
13995         local cmd="exec $fd<>$file2"
13996         eval $cmd
13997         rm $file2
13998         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
13999                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
14000         cmd="exec $fd>&-"
14001         eval $cmd
14002         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
14003
14004         #cleanup
14005         rm -rf $DIR/$tdir
14006 }
14007 run_test 236 "Layout swap on open unlinked file"
14008
14009 # test to verify file handle related system calls
14010 # (name_to_handle_at/open_by_handle_at)
14011 # The new system calls are supported in glibc >= 2.14.
14012
14013 test_237() {
14014         echo "Test file_handle syscalls" > $DIR/$tfile ||
14015                 error "write failed"
14016         check_fhandle_syscalls $DIR/$tfile ||
14017                 error "check_fhandle_syscalls failed"
14018 }
14019 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
14020
14021 # LU-4659 linkea consistency
14022 test_238() {
14023         local server_version=$(lustre_version_code $SINGLEMDS)
14024
14025         [[ $server_version -gt $(version_code 2.5.57) ]] ||
14026                 [[ $server_version -gt $(version_code 2.5.1) &&
14027                    $server_version -lt $(version_code 2.5.50) ]] ||
14028                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
14029
14030         touch $DIR/$tfile
14031         ln $DIR/$tfile $DIR/$tfile.lnk
14032         touch $DIR/$tfile.new
14033         mv $DIR/$tfile.new $DIR/$tfile
14034         local fid1=$($LFS path2fid $DIR/$tfile)
14035         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
14036         local path1=$($LFS fid2path $FSNAME "$fid1")
14037         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
14038         local path2=$($LFS fid2path $FSNAME "$fid2")
14039         [ $tfile.lnk == $path2 ] ||
14040                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
14041         rm -f $DIR/$tfile*
14042 }
14043 run_test 238 "Verify linkea consistency"
14044
14045 test_239() {
14046         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
14047                 skip "Need MDS version at least 2.5.60" && return
14048         local list=$(comma_list $(mdts_nodes))
14049
14050         mkdir -p $DIR/$tdir
14051         createmany -o $DIR/$tdir/f- 5000
14052         unlinkmany $DIR/$tdir/f- 5000
14053         [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.10.53) ] &&
14054                 do_nodes $list "lctl set_param -n osp.*.force_sync=1"
14055         changes=$(do_nodes $list "lctl get_param -n osp.*MDT*.sync_changes \
14056                         osp.*MDT*.sync_in_flight" | calc_sum)
14057         [ "$changes" -eq 0 ] || error "$changes not synced"
14058 }
14059 run_test 239 "osp_sync test"
14060
14061 test_239a() { #LU-5297
14062         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14063         touch $DIR/$tfile
14064         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
14065         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
14066         chgrp $RUNAS_GID $DIR/$tfile
14067         wait_delete_completed
14068 }
14069 run_test 239a "process invalid osp sync record correctly"
14070
14071 test_239b() { #LU-5297
14072         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14073         touch $DIR/$tfile1
14074         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
14075         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
14076         chgrp $RUNAS_GID $DIR/$tfile1
14077         wait_delete_completed
14078         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
14079         touch $DIR/$tfile2
14080         chgrp $RUNAS_GID $DIR/$tfile2
14081         wait_delete_completed
14082 }
14083 run_test 239b "process osp sync record with ENOMEM error correctly"
14084
14085 test_240() {
14086         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14087         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14088
14089         mkdir -p $DIR/$tdir
14090
14091         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
14092                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
14093         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
14094                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
14095
14096         umount_client $MOUNT || error "umount failed"
14097         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
14098         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
14099         mount_client $MOUNT || error "failed to mount client"
14100
14101         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
14102         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
14103 }
14104 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
14105
14106 test_241_bio() {
14107         for LOOP in $(seq $1); do
14108                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
14109                 cancel_lru_locks osc || true
14110         done
14111 }
14112
14113 test_241_dio() {
14114         for LOOP in $(seq $1); do
14115                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
14116                                                 iflag=direct 2>/dev/null
14117         done
14118 }
14119
14120 test_241a() { # was test_241
14121         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
14122         ls -la $DIR/$tfile
14123         cancel_lru_locks osc
14124         test_241_bio 1000 &
14125         PID=$!
14126         test_241_dio 1000
14127         wait $PID
14128 }
14129 run_test 241a "bio vs dio"
14130
14131 test_241b() {
14132         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
14133         ls -la $DIR/$tfile
14134         test_241_dio 1000 &
14135         PID=$!
14136         test_241_dio 1000
14137         wait $PID
14138 }
14139 run_test 241b "dio vs dio"
14140
14141 test_242() {
14142         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14143         mkdir -p $DIR/$tdir
14144         touch $DIR/$tdir/$tfile
14145
14146         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
14147         do_facet mds1 lctl set_param fail_loc=0x105
14148         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
14149
14150         do_facet mds1 lctl set_param fail_loc=0
14151         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
14152 }
14153 run_test 242 "mdt_readpage failure should not cause directory unreadable"
14154
14155 test_243()
14156 {
14157         test_mkdir $DIR/$tdir
14158         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
14159 }
14160 run_test 243 "various group lock tests"
14161
14162 test_244()
14163 {
14164         test_mkdir $DIR/$tdir
14165         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
14166         sendfile_grouplock $DIR/$tdir/$tfile || \
14167                 error "sendfile+grouplock failed"
14168         rm -rf $DIR/$tdir
14169 }
14170 run_test 244 "sendfile with group lock tests"
14171
14172 test_245() {
14173         local flagname="multi_mod_rpcs"
14174         local connect_data_name="max_mod_rpcs"
14175         local out
14176
14177         # check if multiple modify RPCs flag is set
14178         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
14179                 grep "connect_flags:")
14180         echo "$out"
14181
14182         echo "$out" | grep -qw $flagname
14183         if [ $? -ne 0 ]; then
14184                 echo "connect flag $flagname is not set"
14185                 return
14186         fi
14187
14188         # check if multiple modify RPCs data is set
14189         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
14190         echo "$out"
14191
14192         echo "$out" | grep -qw $connect_data_name ||
14193                 error "import should have connect data $connect_data_name"
14194 }
14195 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
14196
14197 test_246() { # LU-7371
14198         remote_ost_nodsh && skip "remote OST with nodsh" && return
14199         [ $(lustre_version_code ost1) -lt $(version_code 2.7.62) ] &&
14200                 skip "Need OST version >= 2.7.62" && return 0
14201         do_facet ost1 $LCTL set_param fail_val=4095
14202 #define OBD_FAIL_OST_READ_SIZE          0x234
14203         do_facet ost1 $LCTL set_param fail_loc=0x234
14204         $LFS setstripe $DIR/$tfile -i 0 -c 1
14205         dd if=/dev/zero of=$DIR/$tfile bs=4095 count=1 > /dev/null 2>&1
14206         cancel_lru_locks $FSNAME-OST0000
14207         dd if=$DIR/$tfile of=/dev/null bs=1048576 || error "Read failed"
14208 }
14209 run_test 246 "Read file of size 4095 should return right length"
14210
14211 test_247a() {
14212         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
14213                 grep -q subtree ||
14214                 { skip "Fileset feature is not supported"; return; }
14215
14216         local submount=${MOUNT}_$tdir
14217
14218         mkdir $MOUNT/$tdir
14219         mkdir -p $submount || error "mkdir $submount failed"
14220         FILESET="$FILESET/$tdir" mount_client $submount ||
14221                 error "mount $submount failed"
14222         echo foo > $submount/$tfile || error "write $submount/$tfile failed"
14223         [ $(cat $MOUNT/$tdir/$tfile) = "foo" ] ||
14224                 error "read $MOUNT/$tdir/$tfile failed"
14225         umount_client $submount || error "umount $submount failed"
14226         rmdir $submount
14227 }
14228 run_test 247a "mount subdir as fileset"
14229
14230 test_247b() {
14231         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14232                 { skip "Fileset feature is not supported"; return; }
14233
14234         local submount=${MOUNT}_$tdir
14235
14236         rm -rf $MOUNT/$tdir
14237         mkdir -p $submount || error "mkdir $submount failed"
14238         SKIP_FILESET=1
14239         FILESET="$FILESET/$tdir" mount_client $submount &&
14240                 error "mount $submount should fail"
14241         rmdir $submount
14242 }
14243 run_test 247b "mount subdir that dose not exist"
14244
14245 test_247c() {
14246         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14247                 { skip "Fileset feature is not supported"; return; }
14248
14249         local submount=${MOUNT}_$tdir
14250
14251         mkdir -p $MOUNT/$tdir/dir1
14252         mkdir -p $submount || error "mkdir $submount failed"
14253         FILESET="$FILESET/$tdir" mount_client $submount ||
14254                 error "mount $submount failed"
14255         local fid=$($LFS path2fid $MOUNT/)
14256         $LFS fid2path $submount $fid && error "fid2path should fail"
14257         umount_client $submount || error "umount $submount failed"
14258         rmdir $submount
14259 }
14260 run_test 247c "running fid2path outside root"
14261
14262 test_247d() {
14263         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14264                 { skip "Fileset feature is not supported"; return; }
14265
14266         local submount=${MOUNT}_$tdir
14267
14268         mkdir -p $MOUNT/$tdir/dir1
14269         mkdir -p $submount || error "mkdir $submount failed"
14270         FILESET="$FILESET/$tdir" mount_client $submount ||
14271                 error "mount $submount failed"
14272         local fid=$($LFS path2fid $submount/dir1)
14273         $LFS fid2path $submount $fid || error "fid2path should succeed"
14274         umount_client $submount || error "umount $submount failed"
14275         rmdir $submount
14276 }
14277 run_test 247d "running fid2path inside root"
14278
14279 # LU-8037
14280 test_247e() {
14281         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
14282                 grep -q subtree ||
14283                 { skip "Fileset feature is not supported"; return; }
14284
14285         local submount=${MOUNT}_$tdir
14286
14287         mkdir $MOUNT/$tdir
14288         mkdir -p $submount || error "mkdir $submount failed"
14289         FILESET="$FILESET/.." mount_client $submount &&
14290                 error "mount $submount should fail"
14291         rmdir $submount
14292 }
14293 run_test 247e "mount .. as fileset"
14294
14295 test_248() {
14296         local fast_read_sav=$($LCTL get_param -n llite.*.fast_read 2>/dev/null)
14297         [ -z "$fast_read_sav" ] && skip "no fast read support" && return
14298
14299         # create a large file for fast read verification
14300         dd if=/dev/zero of=$DIR/$tfile bs=1M count=128 > /dev/null 2>&1
14301
14302         # make sure the file is created correctly
14303         $CHECKSTAT -s $((128*1024*1024)) $DIR/$tfile ||
14304                 { rm -f $DIR/$tfile; skip "file creation error" && return; }
14305
14306         echo "Test 1: verify that fast read is 4 times faster on cache read"
14307
14308         # small read with fast read enabled
14309         $LCTL set_param -n llite.*.fast_read=1
14310         local t_fast=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
14311                 awk '/copied/ { print $6 }')
14312
14313         # small read with fast read disabled
14314         $LCTL set_param -n llite.*.fast_read=0
14315         local t_slow=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
14316                 awk '/copied/ { print $6 }')
14317
14318         # verify that fast read is 4 times faster for cache read
14319         [ $(bc <<< "4 * $t_fast < $t_slow") -eq 1 ] ||
14320                 error_not_in_vm "fast read was not 4 times faster: " \
14321                            "$t_fast vs $t_slow"
14322
14323         echo "Test 2: verify the performance between big and small read"
14324         $LCTL set_param -n llite.*.fast_read=1
14325
14326         # 1k non-cache read
14327         cancel_lru_locks osc
14328         local t_1k=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
14329                 awk '/copied/ { print $6 }')
14330
14331         # 1M non-cache read
14332         cancel_lru_locks osc
14333         local t_1m=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
14334                 awk '/copied/ { print $6 }')
14335
14336         # verify that big IO is not 4 times faster than small IO
14337         [ $(bc <<< "4 * $t_1k >= $t_1m") -eq 1 ] ||
14338                 error_not_in_vm "bigger IO is way too fast: $t_1k vs $t_1m"
14339
14340         $LCTL set_param -n llite.*.fast_read=$fast_read_sav
14341         rm -f $DIR/$tfile
14342 }
14343 run_test 248 "fast read verification"
14344
14345 test_249() { # LU-7890
14346         rm -f $DIR/$tfile
14347         $SETSTRIPE -c 1 $DIR/$tfile
14348
14349         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
14350         skip "Need at least version 2.8.54"
14351
14352         # Offset 2T == 4k * 512M
14353         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 seek=512M ||
14354                 error "dd to 2T offset failed"
14355 }
14356 run_test 249 "Write above 2T file size"
14357
14358 test_250() {
14359         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
14360          && skip "no 16TB file size limit on ZFS" && return
14361
14362         $SETSTRIPE -c 1 $DIR/$tfile
14363         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
14364         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
14365         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
14366         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
14367                 conv=notrunc,fsync && error "append succeeded"
14368         return 0
14369 }
14370 run_test 250 "Write above 16T limit"
14371
14372 test_251() {
14373         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
14374
14375         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
14376         #Skip once - writing the first stripe will succeed
14377         $LCTL set_param fail_loc=0xa0001407 fail_val=1
14378         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
14379                 error "short write happened"
14380
14381         $LCTL set_param fail_loc=0xa0001407 fail_val=1
14382         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
14383                 error "short read happened"
14384
14385         rm -f $DIR/$tfile
14386 }
14387 run_test 251 "Handling short read and write correctly"
14388
14389 test_252() {
14390         local tgt
14391         local dev
14392         local out
14393         local uuid
14394         local num
14395         local gen
14396
14397         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14398         remote_ost_nodsh && skip "remote OST with nodsh" && return
14399         if [ "$(facet_fstype ost1)" != "ldiskfs" -o \
14400              "$(facet_fstype mds1)" != "ldiskfs" ]; then
14401                 skip "ldiskfs only test"
14402                 return
14403         fi
14404
14405         # check lr_reader on OST0000
14406         tgt=ost1
14407         dev=$(facet_device $tgt)
14408         out=$(do_facet $tgt $LR_READER $dev)
14409         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14410         echo "$out"
14411         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
14412         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
14413                 error "Invalid uuid returned by $LR_READER on target $tgt"
14414         echo -e "uuid returned by $LR_READER is '$uuid'\n"
14415
14416         # check lr_reader -c on MDT0000
14417         tgt=mds1
14418         dev=$(facet_device $tgt)
14419         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
14420                 echo "$LR_READER does not support additional options"
14421                 return 0
14422         fi
14423         out=$(do_facet $tgt $LR_READER -c $dev)
14424         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14425         echo "$out"
14426         num=$(echo "$out" | grep -c "mdtlov")
14427         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
14428                 error "Invalid number of mdtlov clients returned by $LR_READER"
14429         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
14430
14431         # check lr_reader -cr on MDT0000
14432         out=$(do_facet $tgt $LR_READER -cr $dev)
14433         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14434         echo "$out"
14435         echo "$out" | grep -q "^reply_data:$" ||
14436                 error "$LR_READER should have returned 'reply_data' section"
14437         num=$(echo "$out" | grep -c "client_generation")
14438         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
14439 }
14440 run_test 252 "check lr_reader tool"
14441
14442 test_253_fill_ost() {
14443         local size_mb #how many MB should we write to pass watermark
14444         local lwm=$3  #low watermark
14445         local free_10mb #10% of free space
14446
14447         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
14448         size_mb=$((free_kb / 1024 - lwm))
14449         free_10mb=$((free_kb / 10240))
14450         #If 10% of free space cross low watermark use it
14451         if (( free_10mb > size_mb )); then
14452                 size_mb=$free_10mb
14453         else
14454                 #At least we need to store 1.1 of difference between
14455                 #free space and low watermark
14456                 size_mb=$((size_mb + size_mb / 10))
14457         fi
14458         if (( lwm <= $((free_kb / 1024)) )) || [ ! -f $DIR/$tdir/1 ]; then
14459                 dd if=/dev/zero of=$DIR/$tdir/1 bs=1M count=$size_mb \
14460                          oflag=append conv=notrunc
14461         fi
14462
14463         sleep_maxage
14464
14465         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
14466         echo "OST still has $((free_kb / 1024)) mbytes free"
14467 }
14468
14469 test_253() {
14470         local ostidx=0
14471         local rc=0
14472
14473         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14474         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14475         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
14476
14477         local ost_name=$($LFS osts |
14478                 sed -n 's/^'$ostidx': \(.*\)_UUID .*/\1/p')
14479         # on the mdt's osc
14480         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
14481         do_facet $SINGLEMDS $LCTL get_param -n \
14482                 osp.$mdtosc_proc1.reserved_mb_high ||
14483                 { skip  "remote MDS does not support reserved_mb_high" &&
14484                   return; }
14485
14486         rm -rf $DIR/$tdir
14487         wait_mds_ost_sync
14488         wait_delete_completed
14489         mkdir $DIR/$tdir
14490
14491         local last_wm_h=$(do_facet $SINGLEMDS $LCTL get_param -n \
14492                         osp.$mdtosc_proc1.reserved_mb_high)
14493         local last_wm_l=$(do_facet $SINGLEMDS $LCTL get_param -n \
14494                         osp.$mdtosc_proc1.reserved_mb_low)
14495         echo "prev high watermark $last_wm_h, prev low watermark $last_wm_l"
14496
14497         create_pool $FSNAME.$TESTNAME || error "Pool creation failed"
14498         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $ost_name ||
14499                 error "Adding $ost_name to pool failed"
14500
14501         # Wait for client to see a OST at pool
14502         wait_update $HOSTNAME "$LCTL get_param -n
14503                 lov.$FSNAME-*.pools.$TESTNAME | sort -u |
14504                 grep $ost_name" "$ost_name""_UUID" $((TIMEOUT/2)) ||
14505                 error "Client can not see the pool"
14506         $SETSTRIPE $DIR/$tdir -i $ostidx -c 1 -p $FSNAME.$TESTNAME ||
14507                 error "Setstripe failed"
14508
14509         dd if=/dev/zero of=$DIR/$tdir/0 bs=1M count=10
14510         local blocks=$($LFS df $MOUNT | grep $ost_name | awk '{ print $4 }')
14511         echo "OST still has $((blocks/1024)) mbytes free"
14512
14513         local new_lwm=$((blocks/1024-10))
14514         do_facet $SINGLEMDS $LCTL set_param \
14515                         osp.$mdtosc_proc1.reserved_mb_high=$((new_lwm+5))
14516         do_facet $SINGLEMDS $LCTL set_param \
14517                         osp.$mdtosc_proc1.reserved_mb_low=$new_lwm
14518
14519         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
14520
14521         #First enospc could execute orphan deletion so repeat.
14522         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
14523
14524         local oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
14525                         osp.$mdtosc_proc1.prealloc_status)
14526         echo "prealloc_status $oa_status"
14527
14528         dd if=/dev/zero of=$DIR/$tdir/2 bs=1M count=1 &&
14529                 error "File creation should fail"
14530         #object allocation was stopped, but we still able to append files
14531         dd if=/dev/zero of=$DIR/$tdir/1 bs=1M seek=6 count=5 oflag=append ||
14532                 error "Append failed"
14533         rm -f $DIR/$tdir/1 $DIR/$tdir/0 $DIR/$tdir/r*
14534
14535         wait_delete_completed
14536
14537         sleep_maxage
14538
14539         for i in $(seq 10 12); do
14540                 dd if=/dev/zero of=$DIR/$tdir/$i bs=1M count=1 2>/dev/null ||
14541                         error "File creation failed after rm";
14542         done
14543
14544         oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
14545                         osp.$mdtosc_proc1.prealloc_status)
14546         echo "prealloc_status $oa_status"
14547
14548         if (( oa_status != 0 )); then
14549                 error "Object allocation still disable after rm"
14550         fi
14551         do_facet $SINGLEMDS $LCTL set_param \
14552                         osp.$mdtosc_proc1.reserved_mb_high=$last_wm_h
14553         do_facet $SINGLEMDS $LCTL set_param \
14554                         osp.$mdtosc_proc1.reserved_mb_low=$last_wm_l
14555
14556
14557         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $ost_name ||
14558                 error "Remove $ost_name from pool failed"
14559         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
14560                 error "Pool destroy fialed"
14561 }
14562 run_test 253 "Check object allocation limit"
14563
14564 test_254() {
14565         local cl_user
14566
14567         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14568         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14569         do_facet mds1 $LCTL get_param -n mdd.$MDT0.changelog_size ||
14570                 { skip "MDS does not support changelog_size" && return; }
14571
14572         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
14573         echo "Registered as changelog user $cl_user"
14574
14575         $LFS changelog_clear $MDT0 $cl_user 0
14576
14577         local size1=$(do_facet mds1 \
14578                       $LCTL get_param -n mdd.$MDT0.changelog_size)
14579         echo "Changelog size $size1"
14580
14581         rm -rf $DIR/$tdir
14582         $LFS mkdir -i 0 $DIR/$tdir
14583         # change something
14584         mkdir -p $DIR/$tdir/pics/2008/zachy
14585         touch $DIR/$tdir/pics/2008/zachy/timestamp
14586         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
14587         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
14588         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
14589         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
14590         rm $DIR/$tdir/pics/desktop.jpg
14591
14592         local size2=$(do_facet mds1 \
14593                       $LCTL get_param -n mdd.$MDT0.changelog_size)
14594         echo "Changelog size after work $size2"
14595
14596         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
14597
14598         if (( size2 <= size1 )); then
14599                 error "Changelog size after work should be greater than original"
14600         fi
14601         return 0
14602 }
14603 run_test 254 "Check changelog size"
14604
14605 ladvise_no_type()
14606 {
14607         local type=$1
14608         local file=$2
14609
14610         lfs ladvise -a invalid $file 2>&1 | grep "Valid types" |
14611                 awk -F: '{print $2}' | grep $type > /dev/null
14612         if [ $? -ne 0 ]; then
14613                 return 0
14614         fi
14615         return 1
14616 }
14617
14618 ladvise_no_ioctl()
14619 {
14620         local file=$1
14621
14622         lfs ladvise -a willread $file > /dev/null 2>&1
14623         if [ $? -eq 0 ]; then
14624                 return 1
14625         fi
14626
14627         lfs ladvise -a willread $file 2>&1 |
14628                 grep "Inappropriate ioctl for device" > /dev/null
14629         if [ $? -eq 0 ]; then
14630                 return 0
14631         fi
14632         return 1
14633 }
14634
14635 percent() {
14636         bc <<<"scale=2; ($1 - $2) * 100 / $2"
14637 }
14638
14639 # run a random read IO workload
14640 # usage: random_read_iops <filename> <filesize> <iosize>
14641 random_read_iops() {
14642         local file=$1
14643         local fsize=$2
14644         local iosize=${3:-4096}
14645
14646         $READS -f $file -s $fsize -b $iosize -n $((fsize / iosize)) -t 60 |
14647                 sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##'
14648 }
14649
14650 drop_file_oss_cache() {
14651         local file="$1"
14652         local nodes="$2"
14653
14654         $LFS ladvise -a dontneed $file 2>/dev/null ||
14655                 do_nodes $nodes "echo 3 > /proc/sys/vm/drop_caches"
14656 }
14657
14658 ladvise_willread_performance()
14659 {
14660         local repeat=10
14661         local average_origin=0
14662         local average_cache=0
14663         local average_ladvise=0
14664
14665         for ((i = 1; i <= $repeat; i++)); do
14666                 echo "Iter $i/$repeat: reading without willread hint"
14667                 cancel_lru_locks osc
14668                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
14669                 local speed_origin=$(random_read_iops $DIR/$tfile $size)
14670                 echo "Iter $i/$repeat: uncached speed: $speed_origin"
14671                 average_origin=$(bc <<<"$average_origin + $speed_origin")
14672
14673                 cancel_lru_locks osc
14674                 local speed_cache=$(random_read_iops $DIR/$tfile $size)
14675                 echo "Iter $i/$repeat: OSS cache speed: $speed_cache"
14676                 average_cache=$(bc <<<"$average_cache + $speed_cache")
14677
14678                 cancel_lru_locks osc
14679                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
14680                 $LFS ladvise -a willread $DIR/$tfile || error "ladvise failed"
14681                 local speed_ladvise=$(random_read_iops $DIR/$tfile $size)
14682                 echo "Iter $i/$repeat: ladvise speed: $speed_ladvise"
14683                 average_ladvise=$(bc <<<"$average_ladvise + $speed_ladvise")
14684         done
14685         average_origin=$(bc <<<"scale=2; $average_origin / $repeat")
14686         average_cache=$(bc <<<"scale=2; $average_cache / $repeat")
14687         average_ladvise=$(bc <<<"scale=2; $average_ladvise / $repeat")
14688
14689         speedup_cache=$(percent $average_cache $average_origin)
14690         speedup_ladvise=$(percent $average_ladvise $average_origin)
14691
14692         echo "Average uncached read: $average_origin"
14693         echo "Average speedup with OSS cached read: " \
14694                 "$average_cache = +$speedup_cache%"
14695         echo "Average speedup with ladvise willread: " \
14696                 "$average_ladvise = +$speedup_ladvise%"
14697
14698         local lowest_speedup=20
14699         if [ ${average_cache%.*} -lt $lowest_speedup ]; then
14700                 echo "Speedup with OSS cached read less than $lowest_speedup%, "
14701                         "got $average_cache%. Skipping ladvise willread check."
14702                 return 0
14703         fi
14704
14705         # the test won't work on ZFS until it supports 'ladvise dontneed', but
14706         # it is still good to run until then to exercise 'ladvise willread'
14707         ! $LFS ladvise -a dontneed $DIR/$tfile &&
14708                 [ "$(facet_fstype ost1)" = "zfs" ] &&
14709                 echo "osd-zfs does not support dontneed or drop_caches" &&
14710                 return 0
14711
14712         lowest_speedup=$(bc <<<"scale=2; $average_cache / 2")
14713         [ ${average_ladvise%.*} -gt $lowest_speedup ] ||
14714                 error_not_in_vm "Speedup with willread is less than " \
14715                         "$lowest_speedup%, got $average_ladvise%"
14716 }
14717
14718 test_255a() {
14719         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
14720                 skip "lustre < 2.8.54 does not support ladvise " && return
14721         remote_ost_nodsh && skip "remote OST with nodsh" && return
14722
14723         lfs setstripe -c -1 -i 0 $DIR/$tfile || error "$tfile failed"
14724
14725         ladvise_no_type willread $DIR/$tfile &&
14726                 skip "willread ladvise is not supported" && return
14727
14728         ladvise_no_ioctl $DIR/$tfile &&
14729                 skip "ladvise ioctl is not supported" && return
14730
14731         local size_mb=100
14732         local size=$((size_mb * 1048576))
14733         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
14734                 error "dd to $DIR/$tfile failed"
14735
14736         lfs ladvise -a willread $DIR/$tfile ||
14737                 error "Ladvise failed with no range argument"
14738
14739         lfs ladvise -a willread -s 0 $DIR/$tfile ||
14740                 error "Ladvise failed with no -l or -e argument"
14741
14742         lfs ladvise -a willread -e 1 $DIR/$tfile ||
14743                 error "Ladvise failed with only -e argument"
14744
14745         lfs ladvise -a willread -l 1 $DIR/$tfile ||
14746                 error "Ladvise failed with only -l argument"
14747
14748         lfs ladvise -a willread -s 2 -e 1 $DIR/$tfile &&
14749                 error "End offset should not be smaller than start offset"
14750
14751         lfs ladvise -a willread -s 2 -e 2 $DIR/$tfile &&
14752                 error "End offset should not be equal to start offset"
14753
14754         lfs ladvise -a willread -s $size -l 1 $DIR/$tfile ||
14755                 error "Ladvise failed with overflowing -s argument"
14756
14757         lfs ladvise -a willread -s 1 -e $((size + 1)) $DIR/$tfile ||
14758                 error "Ladvise failed with overflowing -e argument"
14759
14760         lfs ladvise -a willread -s 1 -l $size $DIR/$tfile ||
14761                 error "Ladvise failed with overflowing -l argument"
14762
14763         lfs ladvise -a willread -l 1 -e 2 $DIR/$tfile &&
14764                 error "Ladvise succeeded with conflicting -l and -e arguments"
14765
14766         echo "Synchronous ladvise should wait"
14767         local delay=4
14768 #define OBD_FAIL_OST_LADVISE_PAUSE       0x237
14769         do_nodes $(comma_list $(osts_nodes)) \
14770                 $LCTL set_param fail_val=$delay fail_loc=0x237
14771
14772         local start_ts=$SECONDS
14773         lfs ladvise -a willread $DIR/$tfile ||
14774                 error "Ladvise failed with no range argument"
14775         local end_ts=$SECONDS
14776         local inteval_ts=$((end_ts - start_ts))
14777
14778         if [ $inteval_ts -lt $(($delay - 1)) ]; then
14779                 error "Synchronous advice didn't wait reply"
14780         fi
14781
14782         echo "Asynchronous ladvise shouldn't wait"
14783         local start_ts=$SECONDS
14784         lfs ladvise -a willread -b $DIR/$tfile ||
14785                 error "Ladvise failed with no range argument"
14786         local end_ts=$SECONDS
14787         local inteval_ts=$((end_ts - start_ts))
14788
14789         if [ $inteval_ts -gt $(($delay / 2)) ]; then
14790                 error "Asynchronous advice blocked"
14791         fi
14792
14793         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0
14794         ladvise_willread_performance
14795 }
14796 run_test 255a "check 'lfs ladvise -a willread'"
14797
14798 facet_meminfo() {
14799         local facet=$1
14800         local info=$2
14801
14802         do_facet $facet "cat /proc/meminfo | grep ^${info}:" | awk '{print $2}'
14803 }
14804
14805 test_255b() {
14806         remote_ost_nodsh && skip "remote OST with nodsh" && return
14807
14808         lfs setstripe -c 1 -i 0 $DIR/$tfile
14809
14810         ladvise_no_type dontneed $DIR/$tfile &&
14811                 skip "dontneed ladvise is not supported" && return
14812
14813         ladvise_no_ioctl $DIR/$tfile &&
14814                 skip "ladvise ioctl is not supported" && return
14815
14816         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
14817                 skip "lustre < 2.8.54 does not support ladvise" && return
14818
14819         ! $LFS ladvise -a dontneed $DIR/$tfile &&
14820                 [ "$(facet_fstype ost1)" = "zfs" ] &&
14821                 skip "zfs-osd does not support 'ladvise dontneed'" && return
14822
14823         local size_mb=100
14824         local size=$((size_mb * 1048576))
14825         # In order to prevent disturbance of other processes, only check 3/4
14826         # of the memory usage
14827         local kibibytes=$((size_mb * 1024 * 3 / 4))
14828
14829         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
14830                 error "dd to $DIR/$tfile failed"
14831
14832         local total=$(facet_meminfo ost1 MemTotal)
14833         echo "Total memory: $total KiB"
14834
14835         do_facet ost1 "sync && echo 3 > /proc/sys/vm/drop_caches"
14836         local before_read=$(facet_meminfo ost1 Cached)
14837         echo "Cache used before read: $before_read KiB"
14838
14839         lfs ladvise -a willread $DIR/$tfile ||
14840                 error "Ladvise willread failed"
14841         local after_read=$(facet_meminfo ost1 Cached)
14842         echo "Cache used after read: $after_read KiB"
14843
14844         lfs ladvise -a dontneed $DIR/$tfile ||
14845                 error "Ladvise dontneed again failed"
14846         local no_read=$(facet_meminfo ost1 Cached)
14847         echo "Cache used after dontneed ladvise: $no_read KiB"
14848
14849         if [ $total -lt $((before_read + kibibytes)) ]; then
14850                 echo "Memory is too small, abort checking"
14851                 return 0
14852         fi
14853
14854         if [ $((before_read + kibibytes)) -gt $after_read ]; then
14855                 error "Ladvise willread should use more memory" \
14856                         "than $kibibytes KiB"
14857         fi
14858
14859         if [ $((no_read + kibibytes)) -gt $after_read ]; then
14860                 error "Ladvise dontneed should release more memory" \
14861                         "than $kibibytes KiB"
14862         fi
14863 }
14864 run_test 255b "check 'lfs ladvise -a dontneed'"
14865
14866 test_255c() {
14867         local count
14868         local new_count
14869         local difference
14870         local i
14871         local rc
14872         test_mkdir -p $DIR/$tdir
14873         $SETSTRIPE -i 0 $DIR/$tdir
14874
14875         #test 10 returns only success/failure
14876         i=10
14877         lockahead_test -d $DIR/$tdir -t $i
14878         rc=$?
14879         if [ $rc -eq 255 ]; then
14880                 error "Ladvise test${i} failed, ${rc}"
14881         fi
14882
14883         #test 11 counts lock enqueue requests, all others count new locks
14884         i=11
14885         count=$(do_facet ost1 \
14886                 $LCTL get_param -n ost.OSS.ost.stats)
14887         count=$(echo "$count" | grep ldlm_extent_enqueue | awk '{ print $2 }')
14888
14889         lockahead_test -d $DIR/$tdir -t $i
14890         rc=$?
14891         if [ $rc -eq 255 ]; then
14892                 error "Ladvise test${i} failed, ${rc}"
14893         fi
14894
14895         new_count=$(do_facet ost1 \
14896                 $LCTL get_param -n ost.OSS.ost.stats)
14897         new_count=$(echo "$new_count" | grep ldlm_extent_enqueue | \
14898                    awk '{ print $2 }')
14899
14900         difference="$((new_count - count))"
14901         if [ $difference -ne $rc ]; then
14902                 error "Ladvise test${i}, bad enqueue count, returned " \
14903                       "${rc}, actual ${difference}"
14904         fi
14905
14906         for i in $(seq 12 21); do
14907                 # If we do not do this, we run the risk of having too many
14908                 # locks and starting lock cancellation while we are checking
14909                 # lock counts.
14910                 cancel_lru_locks osc
14911
14912                 count=$($LCTL get_param -n \
14913                        ldlm.namespaces.$FSNAME-OST0000*osc-f*.lock_unused_count)
14914
14915                 lockahead_test -d $DIR/$tdir -t $i
14916                 rc=$?
14917                 if [ $rc -eq 255 ]; then
14918                         error "Ladvise test ${i} failed, ${rc}"
14919                 fi
14920
14921                 new_count=$($LCTL get_param -n \
14922                        ldlm.namespaces.$FSNAME-OST0000*osc-f*.lock_unused_count)
14923                 difference="$((new_count - count))"
14924
14925                 # Test 15 output is divided by 1000 to map down to valid return
14926                 if [ $i -eq 15 ]; then
14927                         rc="$((rc * 1000))"
14928                 fi
14929
14930                 if [ $difference -ne $rc ]; then
14931                         error "Ladvise test ${i}, bad lock count, returned " \
14932                               "${rc}, actual ${difference}"
14933                 fi
14934         done
14935
14936         #test 22 returns only success/failure
14937         i=22
14938         lockahead_test -d $DIR/$tdir -t $i
14939         rc=$?
14940         if [ $rc -eq 255 ]; then
14941                 error "Ladvise test${i} failed, ${rc}"
14942         fi
14943
14944 }
14945 run_test 255c "suite of ladvise lockahead tests"
14946
14947 test_256() {
14948         local cl_user
14949         local cat_sl
14950         local mdt_dev
14951
14952         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14953         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14954         [ "$(facet_fstype mds1)" != "ldiskfs" ] &&
14955                 skip "ldiskfs only test" && return
14956
14957         mdt_dev=$(mdsdevname 1)
14958         echo $mdt_dev
14959         cl_user=$(do_facet mds1 \
14960         "$LCTL get_param -n mdd.$MDT0.changelog_users | grep cl")
14961         if [[ -n $cl_user ]]; then
14962                 skip "active changelog user"
14963                 return
14964         fi
14965
14966         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
14967         echo "Registered as changelog user $cl_user"
14968
14969         rm -rf $DIR/$tdir
14970         mkdir -p $DIR/$tdir
14971
14972         $LFS changelog_clear $MDT0 $cl_user 0
14973
14974         # change something
14975         touch $DIR/$tdir/{1..10}
14976
14977         # stop the MDT
14978         stop mds1 || error "Fail to stop MDT."
14979
14980         # remount the MDT
14981         start mds1 $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT."
14982
14983         #after mount new plainllog is used
14984         touch $DIR/$tdir/{11..19}
14985         do_facet mds1 sync
14986         local TEMP256FILE=$(mktemp -u TEMP256XXXXXX)
14987         cat_sl=$(do_facet mds1 \
14988         "$DEBUGFS -R \\\"dump changelog_catalog $TEMP256FILE\\\" $mdt_dev; \
14989          llog_reader $TEMP256FILE | grep \\\"type=1064553b\\\" | wc -l")
14990         do_facet mds1 rm $TEMP256FILE
14991
14992         if (( cat_sl != 2 )); then
14993                 do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
14994                 error "Changelog catalog has wrong number of slots $cat_sl"
14995         fi
14996
14997         $LFS changelog_clear $MDT0 $cl_user 0
14998
14999         do_facet mds1 sync
15000         TEMP256FILE=$(mktemp -u TEMP256XXXXXX)
15001         cat_sl=$(do_facet mds1 \
15002         "$DEBUGFS -R \\\"dump changelog_catalog $TEMP256FILE\\\" $mdt_dev; \
15003          llog_reader $TEMP256FILE | grep \\\"type=1064553b\\\" | wc -l")
15004         do_facet mds1 rm $TEMP256FILE
15005
15006         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
15007
15008         if (( cat_sl == 2 )); then
15009                 error "Empty plain llog was not deleted from changelog catalog"
15010         fi
15011         if (( cat_sl != 1 )); then
15012                 error "Active plain llog shouldn\`t be deleted from catalog"
15013         fi
15014 }
15015 run_test 256 "Check llog delete for empty and not full state"
15016
15017 test_257() {
15018         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15019         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
15020                 skip "Need MDS version at least 2.8.55" && return
15021
15022         test_mkdir $DIR/$tdir
15023
15024         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
15025                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
15026         stat $DIR/$tdir
15027
15028 #define OBD_FAIL_MDS_XATTR_REP                  0x161
15029         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
15030         local facet=mds$((mdtidx + 1))
15031         set_nodes_failloc $(facet_active_host $facet) 0x80000161
15032         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null
15033
15034         stop $facet || error "stop MDS failed"
15035         start $facet $(mdsdevname $((mdtidx + 1))) $MDS_MOUNT_OPTS ||
15036                 error "start MDS fail"
15037 }
15038 run_test 257 "xattr locks are not lost"
15039
15040 # Verify we take the i_mutex when security requires it
15041 test_258a() {
15042 #define OBD_FAIL_IMUTEX_SEC 0x141c
15043         $LCTL set_param fail_loc=0x141c
15044         touch $DIR/$tfile
15045         chmod u+s $DIR/$tfile
15046         chmod a+rwx $DIR/$tfile
15047         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
15048         RC=$?
15049         if [ $RC -ne 0 ]; then
15050                 error "error, failed to take i_mutex, rc=$?"
15051         fi
15052         rm -f $DIR/$tfile
15053 }
15054 run_test 258a
15055
15056 # Verify we do NOT take the i_mutex in the normal case
15057 test_258b() {
15058 #define OBD_FAIL_IMUTEX_NOSEC 0x141d
15059         $LCTL set_param fail_loc=0x141d
15060         touch $DIR/$tfile
15061         chmod a+rwx $DIR
15062         chmod a+rw $DIR/$tfile
15063         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
15064         RC=$?
15065         if [ $RC -ne 0 ]; then
15066                 error "error, took i_mutex unnecessarily, rc=$?"
15067         fi
15068         rm -f $DIR/$tfile
15069
15070 }
15071 run_test 258b "verify i_mutex security behavior"
15072
15073 test_260() {
15074 #define OBD_FAIL_MDC_CLOSE               0x806
15075         $LCTL set_param fail_loc=0x80000806
15076         touch $DIR/$tfile
15077
15078 }
15079 run_test 260 "Check mdc_close fail"
15080
15081 cleanup_test_300() {
15082         trap 0
15083         umask $SAVE_UMASK
15084 }
15085 test_striped_dir() {
15086         local mdt_index=$1
15087         local stripe_count
15088         local stripe_index
15089
15090         mkdir -p $DIR/$tdir
15091
15092         SAVE_UMASK=$(umask)
15093         trap cleanup_test_300 RETURN EXIT
15094
15095         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
15096                                                 $DIR/$tdir/striped_dir ||
15097                 error "set striped dir error"
15098
15099         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
15100         [ "$mode" = "755" ] || error "expect 755 got $mode"
15101
15102         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
15103                 error "getdirstripe failed"
15104         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
15105         if [ "$stripe_count" != "2" ]; then
15106                 error "1:stripe_count is $stripe_count, expect 2"
15107         fi
15108         stripe_count=$($LFS getdirstripe -T $DIR/$tdir/striped_dir)
15109         if [ "$stripe_count" != "2" ]; then
15110                 error "2:stripe_count is $stripe_count, expect 2"
15111         fi
15112
15113         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
15114         if [ "$stripe_index" != "$mdt_index" ]; then
15115                 error "stripe_index is $stripe_index, expect $mdt_index"
15116         fi
15117
15118         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
15119                 error "nlink error after create striped dir"
15120
15121         mkdir $DIR/$tdir/striped_dir/a
15122         mkdir $DIR/$tdir/striped_dir/b
15123
15124         stat $DIR/$tdir/striped_dir/a ||
15125                 error "create dir under striped dir failed"
15126         stat $DIR/$tdir/striped_dir/b ||
15127                 error "create dir under striped dir failed"
15128
15129         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
15130                 error "nlink error after mkdir"
15131
15132         rmdir $DIR/$tdir/striped_dir/a
15133         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
15134                 error "nlink error after rmdir"
15135
15136         rmdir $DIR/$tdir/striped_dir/b
15137         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
15138                 error "nlink error after rmdir"
15139
15140         chattr +i $DIR/$tdir/striped_dir
15141         createmany -o $DIR/$tdir/striped_dir/f 10 &&
15142                 error "immutable flags not working under striped dir!"
15143         chattr -i $DIR/$tdir/striped_dir
15144
15145         rmdir $DIR/$tdir/striped_dir ||
15146                 error "rmdir striped dir error"
15147
15148         cleanup_test_300
15149
15150         true
15151 }
15152
15153 test_300a() {
15154         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15155                 skip "skipped for lustre < 2.7.0" && return
15156         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15157         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15158
15159         test_striped_dir 0 || error "failed on striped dir on MDT0"
15160         test_striped_dir 1 || error "failed on striped dir on MDT0"
15161 }
15162 run_test 300a "basic striped dir sanity test"
15163
15164 test_300b() {
15165         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15166                 skip "skipped for lustre < 2.7.0" && return
15167         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15168         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15169         local i
15170         local mtime1
15171         local mtime2
15172         local mtime3
15173
15174         test_mkdir $DIR/$tdir
15175         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15176                 error "set striped dir error"
15177         for ((i=0; i<10; i++)); do
15178                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
15179                 sleep 1
15180                 touch $DIR/$tdir/striped_dir/file_$i ||
15181                                         error "touch error $i"
15182                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
15183                 [ $mtime1 -eq $mtime2 ] &&
15184                         error "mtime not change after create"
15185                 sleep 1
15186                 rm -f $DIR/$tdir/striped_dir/file_$i ||
15187                                         error "unlink error $i"
15188                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
15189                 [ $mtime2 -eq $mtime3 ] &&
15190                         error "mtime did not change after unlink"
15191         done
15192         true
15193 }
15194 run_test 300b "check ctime/mtime for striped dir"
15195
15196 test_300c() {
15197         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15198                 skip "skipped for lustre < 2.7.0" && return
15199         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15200         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15201         local file_count
15202
15203         mkdir -p $DIR/$tdir
15204         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
15205                 error "set striped dir error"
15206
15207         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
15208                 error "chown striped dir failed"
15209
15210         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
15211                 error "create 5k files failed"
15212
15213         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
15214
15215         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
15216
15217         rm -rf $DIR/$tdir
15218 }
15219 run_test 300c "chown && check ls under striped directory"
15220
15221 test_300d() {
15222         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15223                 skip "skipped for lustre < 2.7.0" && return
15224         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15225         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15226         local stripe_count
15227         local file
15228
15229         mkdir -p $DIR/$tdir
15230         $SETSTRIPE -c 2 $DIR/$tdir
15231
15232         #local striped directory
15233         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15234                 error "set striped dir error"
15235         createmany -o $DIR/$tdir/striped_dir/f 10 ||
15236                 error "create 10 files failed"
15237
15238         #remote striped directory
15239         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
15240                 error "set striped dir error"
15241         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
15242                 error "create 10 files failed"
15243
15244         for file in $(find $DIR/$tdir); do
15245                 stripe_count=$($GETSTRIPE -c $file)
15246                 [ $stripe_count -eq 2 ] ||
15247                         error "wrong stripe $stripe_count for $file"
15248         done
15249
15250         rm -rf $DIR/$tdir
15251 }
15252 run_test 300d "check default stripe under striped directory"
15253
15254 test_300e() {
15255         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15256                 skip "Need MDS version at least 2.7.55" && return
15257         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15258         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15259         local stripe_count
15260         local file
15261
15262         mkdir -p $DIR/$tdir
15263
15264         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15265                 error "set striped dir error"
15266
15267         touch $DIR/$tdir/striped_dir/a
15268         touch $DIR/$tdir/striped_dir/b
15269         touch $DIR/$tdir/striped_dir/c
15270
15271         mkdir $DIR/$tdir/striped_dir/dir_a
15272         mkdir $DIR/$tdir/striped_dir/dir_b
15273         mkdir $DIR/$tdir/striped_dir/dir_c
15274
15275         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
15276                 error "set striped adir under striped dir error"
15277
15278         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_b ||
15279                 error "set striped bdir under striped dir error"
15280
15281         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
15282                 error "set striped cdir under striped dir error"
15283
15284         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
15285                 error "rename dir under striped dir fails"
15286
15287         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
15288                 error "rename dir under different stripes fails"
15289
15290         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
15291                 error "rename file under striped dir should succeed"
15292
15293         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
15294                 error "rename dir under striped dir should succeed"
15295
15296         rm -rf $DIR/$tdir
15297 }
15298 run_test 300e "check rename under striped directory"
15299
15300 test_300f() {
15301         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15302                 skip "Need MDS version at least 2.7.55" && return
15303         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15304         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15305         local stripe_count
15306         local file
15307
15308         rm -rf $DIR/$tdir
15309         mkdir -p $DIR/$tdir
15310
15311         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15312                 error "set striped dir error"
15313
15314         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
15315                 error "set striped dir error"
15316
15317         touch $DIR/$tdir/striped_dir/a
15318         mkdir $DIR/$tdir/striped_dir/dir_a
15319         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
15320                 error "create striped dir under striped dir fails"
15321
15322         touch $DIR/$tdir/striped_dir1/b
15323         mkdir $DIR/$tdir/striped_dir1/dir_b
15324         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
15325                 error "create striped dir under striped dir fails"
15326
15327         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
15328                 error "rename dir under different striped dir should fail"
15329
15330         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
15331                 error "rename striped dir under diff striped dir should fail"
15332
15333         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
15334                 error "rename file under diff striped dirs fails"
15335
15336         rm -rf $DIR/$tdir
15337 }
15338 run_test 300f "check rename cross striped directory"
15339
15340 test_300_check_default_striped_dir()
15341 {
15342         local dirname=$1
15343         local default_count=$2
15344         local default_index=$3
15345         local stripe_count
15346         local stripe_index
15347         local dir_stripe_index
15348         local dir
15349
15350         echo "checking $dirname $default_count $default_index"
15351         $LFS setdirstripe -D -c $default_count -i $default_index \
15352                                 -t all_char $DIR/$tdir/$dirname ||
15353                 error "set default stripe on striped dir error"
15354         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
15355         [ $stripe_count -eq $default_count ] ||
15356                 error "expect $default_count get $stripe_count for $dirname"
15357
15358         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
15359         [ $stripe_index -eq $default_index ] ||
15360                 error "expect $default_index get $stripe_index for $dirname"
15361
15362         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
15363                                                 error "create dirs failed"
15364
15365         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
15366         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
15367         for dir in $(find $DIR/$tdir/$dirname/*); do
15368                 stripe_count=$($LFS getdirstripe -c $dir)
15369                 [ $stripe_count -eq $default_count ] ||
15370                 [ $stripe_count -eq 0 -o $default_count -eq 1 ] ||
15371                 error "stripe count $default_count != $stripe_count for $dir"
15372
15373                 stripe_index=$($LFS getdirstripe -i $dir)
15374                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
15375                         error "$stripe_index != $default_index for $dir"
15376
15377                 #check default stripe
15378                 stripe_count=$($LFS getdirstripe -D -c $dir)
15379                 [ $stripe_count -eq $default_count ] ||
15380                 error "default count $default_count != $stripe_count for $dir"
15381
15382                 stripe_index=$($LFS getdirstripe -D -i $dir)
15383                 [ $stripe_index -eq $default_index ] ||
15384                 error "default index $default_index != $stripe_index for $dir"
15385         done
15386         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
15387 }
15388
15389 test_300g() {
15390         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15391                 skip "Need MDS version at least 2.7.55" && return
15392         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15393         local dir
15394         local stripe_count
15395         local stripe_index
15396
15397         mkdir $DIR/$tdir
15398         mkdir $DIR/$tdir/normal_dir
15399
15400         #Checking when client cache stripe index
15401         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
15402         $LFS setdirstripe -D -i1 $DIR/$tdir/striped_dir ||
15403                 error "create striped_dir failed"
15404
15405         $LFS setdirstripe -i0 $DIR/$tdir/striped_dir/dir0 ||
15406                 error "create dir0 fails"
15407         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir0)
15408         [ $stripe_index -eq 0 ] ||
15409                 error "dir0 expect index 0 got $stripe_index"
15410
15411         mkdir $DIR/$tdir/striped_dir/dir1 ||
15412                 error "create dir1 fails"
15413         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir1)
15414         [ $stripe_index -eq 1 ] ||
15415                 error "dir1 expect index 1 got $stripe_index"
15416
15417         #check default stripe count/stripe index
15418         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
15419         test_300_check_default_striped_dir normal_dir 1 0
15420         test_300_check_default_striped_dir normal_dir 2 1
15421         test_300_check_default_striped_dir normal_dir 2 -1
15422
15423         #delete default stripe information
15424         echo "delete default stripeEA"
15425         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
15426                 error "set default stripe on striped dir error"
15427
15428         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
15429         for dir in $(find $DIR/$tdir/normal_dir/*); do
15430                 stripe_count=$($LFS getdirstripe -c $dir)
15431                 [ $stripe_count -eq 0 ] ||
15432                         error "expect 1 get $stripe_count for $dir"
15433                 stripe_index=$($LFS getdirstripe -i $dir)
15434                 [ $stripe_index -eq 0 ] ||
15435                         error "expect 0 get $stripe_index for $dir"
15436         done
15437 }
15438 run_test 300g "check default striped directory for normal directory"
15439
15440 test_300h() {
15441         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15442                 skip "Need MDS version at least 2.7.55" && return
15443         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15444         local dir
15445         local stripe_count
15446
15447         mkdir $DIR/$tdir
15448         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
15449                                         $DIR/$tdir/striped_dir ||
15450                 error "set striped dir error"
15451
15452         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
15453         test_300_check_default_striped_dir striped_dir 1 0
15454         test_300_check_default_striped_dir striped_dir 2 1
15455         test_300_check_default_striped_dir striped_dir 2 -1
15456
15457         #delete default stripe information
15458         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
15459                 error "set default stripe on striped dir error"
15460
15461         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
15462         for dir in $(find $DIR/$tdir/striped_dir/*); do
15463                 stripe_count=$($LFS getdirstripe -c $dir)
15464                 [ $stripe_count -eq 0 ] ||
15465                         error "expect 1 get $stripe_count for $dir"
15466         done
15467 }
15468 run_test 300h "check default striped directory for striped directory"
15469
15470 test_300i() {
15471         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15472                 skip "Need MDS version at least 2.7.55" && return
15473         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15474         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15475         local stripe_count
15476         local file
15477
15478         mkdir $DIR/$tdir
15479
15480         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
15481                 error "set striped dir error"
15482
15483         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
15484                 error "create files under striped dir failed"
15485
15486         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir ||
15487                 error "set striped hashdir error"
15488
15489         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir/d0 ||
15490                 error "create dir0 under hash dir failed"
15491         $LFS setdirstripe -i0 -c$MDSCOUNT -H fnv_1a_64 $DIR/$tdir/hashdir/d1 ||
15492                 error "create dir1 under hash dir failed"
15493
15494         # unfortunately, we need to umount to clear dir layout cache for now
15495         # once we fully implement dir layout, we can drop this
15496         umount_client $MOUNT || error "umount failed"
15497         mount_client $MOUNT || error "mount failed"
15498
15499         $LFS find -H fnv_1a_64 $DIR/$tdir/hashdir
15500         local dircnt=$($LFS find -H fnv_1a_64 $DIR/$tdir/hashdir | wc -l)
15501         [ $dircnt -eq 1 ] || error "lfs find striped dir got:$dircnt,except:1"
15502
15503         #set the stripe to be unknown hash type
15504         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
15505         $LCTL set_param fail_loc=0x1901
15506         for ((i = 0; i < 10; i++)); do
15507                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
15508                         error "stat f-$i failed"
15509                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
15510         done
15511
15512         touch $DIR/$tdir/striped_dir/f0 &&
15513                 error "create under striped dir with unknown hash should fail"
15514
15515         $LCTL set_param fail_loc=0
15516
15517         umount_client $MOUNT || error "umount failed"
15518         mount_client $MOUNT || error "mount failed"
15519
15520         return 0
15521 }
15522 run_test 300i "client handle unknown hash type striped directory"
15523
15524 test_300j() {
15525         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15526         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15527                 skip "Need MDS version at least 2.7.55" && return
15528         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15529         local stripe_count
15530         local file
15531
15532         mkdir $DIR/$tdir
15533
15534         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
15535         $LCTL set_param fail_loc=0x1702
15536         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
15537                 error "set striped dir error"
15538
15539         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
15540                 error "create files under striped dir failed"
15541
15542         $LCTL set_param fail_loc=0
15543
15544         rm -rf $DIR/$tdir || error "unlink striped dir fails"
15545
15546         return 0
15547 }
15548 run_test 300j "test large update record"
15549
15550 test_300k() {
15551         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15552                 skip "Need MDS version at least 2.7.55" && return
15553         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15554         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15555         local stripe_count
15556         local file
15557
15558         mkdir $DIR/$tdir
15559
15560         #define OBD_FAIL_LARGE_STRIPE   0x1703
15561         $LCTL set_param fail_loc=0x1703
15562         $LFS setdirstripe -i 0 -c512 $DIR/$tdir/striped_dir ||
15563                 error "set striped dir error"
15564         $LCTL set_param fail_loc=0
15565
15566         $LFS getdirstripe $DIR/$tdir/striped_dir ||
15567                 error "getstripeddir fails"
15568         rm -rf $DIR/$tdir/striped_dir ||
15569                 error "unlink striped dir fails"
15570
15571         return 0
15572 }
15573 run_test 300k "test large striped directory"
15574
15575 test_300l() {
15576         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15577                 skip "Need MDS version at least 2.7.55" && return
15578         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15579         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15580         local stripe_index
15581
15582         test_mkdir -p $DIR/$tdir/striped_dir
15583         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
15584                         error "chown $RUNAS_ID failed"
15585         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
15586                 error "set default striped dir failed"
15587
15588         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
15589         $LCTL set_param fail_loc=0x80000158
15590         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
15591
15592         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
15593         [ $stripe_index -eq 1 ] ||
15594                 error "expect 1 get $stripe_index for $dir"
15595 }
15596 run_test 300l "non-root user to create dir under striped dir with stale layout"
15597
15598 test_300m() {
15599         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15600                 skip "Need MDS version at least 2.7.55" && return
15601         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15602         [ $MDSCOUNT -ge 2 ] && skip "Only for single MDT" && return
15603
15604         mkdir -p $DIR/$tdir/striped_dir
15605         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
15606                 error "set default stripes dir error"
15607
15608         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
15609
15610         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
15611         [ $stripe_count -eq 0 ] ||
15612                         error "expect 0 get $stripe_count for a"
15613
15614         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
15615                 error "set default stripes dir error"
15616
15617         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
15618
15619         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
15620         [ $stripe_count -eq 0 ] ||
15621                         error "expect 0 get $stripe_count for b"
15622
15623         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
15624                 error "set default stripes dir error"
15625
15626         mkdir $DIR/$tdir/striped_dir/c &&
15627                 error "default stripe_index is invalid, mkdir c should fails"
15628
15629         rm -rf $DIR/$tdir || error "rmdir fails"
15630 }
15631 run_test 300m "setstriped directory on single MDT FS"
15632
15633 cleanup_300n() {
15634         local list=$(comma_list $(mdts_nodes))
15635
15636         trap 0
15637         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
15638 }
15639
15640 test_300n() {
15641         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15642                 skip "Need MDS version at least 2.7.55" && return
15643         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15644         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15645         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15646
15647         local stripe_index
15648         local list=$(comma_list $(mdts_nodes))
15649
15650         trap cleanup_300n RETURN EXIT
15651         mkdir -p $DIR/$tdir
15652         chmod 777 $DIR/$tdir
15653         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
15654                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
15655                 error "create striped dir succeeds with gid=0"
15656
15657         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
15658         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
15659                 error "create striped dir fails with gid=-1"
15660
15661         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
15662         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
15663                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
15664                 error "set default striped dir succeeds with gid=0"
15665
15666
15667         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
15668         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
15669                 error "set default striped dir fails with gid=-1"
15670
15671
15672         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
15673         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
15674                                         error "create test_dir fails"
15675         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
15676                                         error "create test_dir1 fails"
15677         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
15678                                         error "create test_dir2 fails"
15679         cleanup_300n
15680 }
15681 run_test 300n "non-root user to create dir under striped dir with default EA"
15682
15683 test_300o() {
15684         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15685                 skip "Need MDS version at least 2.7.55" && return
15686         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15687         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15688         local numfree1
15689         local numfree2
15690
15691         mkdir -p $DIR/$tdir
15692
15693         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
15694         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
15695         if [ $numfree1 -lt 66000 -o $numfree2 -lt 66000 ]; then
15696                 skip "not enough free inodes $numfree1 $numfree2"
15697                 return
15698         fi
15699
15700         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
15701         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
15702         if [ $numfree1 -lt 300000 -o $numfree2 -lt 300000 ]; then
15703                 skip "not enough free space $numfree1 $numfree2"
15704                 return
15705         fi
15706
15707         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
15708                 error "setdirstripe fails"
15709
15710         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
15711                 error "create dirs fails"
15712
15713         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
15714         ls $DIR/$tdir/striped_dir > /dev/null ||
15715                 error "ls striped dir fails"
15716         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
15717                 error "unlink big striped dir fails"
15718 }
15719 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
15720
15721 test_300p() {
15722         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15723         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15724         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15725
15726         mkdir -p $DIR/$tdir
15727
15728         #define OBD_FAIL_OUT_ENOSPC     0x1704
15729         do_facet mds2 lctl set_param fail_loc=0x80001704
15730         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 &&
15731                         error "create striped directory should fail"
15732
15733         [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
15734
15735         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir
15736         true
15737 }
15738 run_test 300p "create striped directory without space"
15739
15740 test_300q() {
15741         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15742         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15743
15744         local fd=$(free_fd)
15745         local cmd="exec $fd<$tdir"
15746         cd $DIR
15747         $LFS mkdir -c $MDSCOUNT $tdir || error "create $tdir fails"
15748         eval $cmd
15749         cmd="exec $fd<&-"
15750         trap "eval $cmd" EXIT
15751         cd $tdir || error "cd $tdir fails"
15752         rmdir  ../$tdir || error "rmdir $tdir fails"
15753         mkdir local_dir && error "create dir succeeds"
15754         $LFS setdirstripe -i1 remote_dir && error "create remote dir succeeds"
15755         eval $cmd
15756         return 0
15757 }
15758 run_test 300q "create remote directory under orphan directory"
15759
15760 prepare_remote_file() {
15761         mkdir $DIR/$tdir/src_dir ||
15762                 error "create remote source failed"
15763
15764         cp /etc/hosts $DIR/$tdir/src_dir/a || error
15765         touch $DIR/$tdir/src_dir/a
15766
15767         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
15768                 error "create remote target dir failed"
15769
15770         touch $DIR/$tdir/tgt_dir/b
15771
15772         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
15773                 error "rename dir cross MDT failed!"
15774
15775         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
15776                 error "src_child still exists after rename"
15777
15778         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
15779                 error "missing file(a) after rename"
15780
15781         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
15782                 error "diff after rename"
15783 }
15784
15785 test_310a() {
15786         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
15787         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15788         local remote_file=$DIR/$tdir/tgt_dir/b
15789
15790         mkdir -p $DIR/$tdir
15791
15792         prepare_remote_file || error "prepare remote file failed"
15793
15794         #open-unlink file
15795         $OPENUNLINK $remote_file $remote_file || error
15796         $CHECKSTAT -a $remote_file || error
15797 }
15798 run_test 310a "open unlink remote file"
15799
15800 test_310b() {
15801         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
15802         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15803         local remote_file=$DIR/$tdir/tgt_dir/b
15804
15805         mkdir -p $DIR/$tdir
15806
15807         prepare_remote_file || error "prepare remote file failed"
15808
15809         ln $remote_file $DIR/$tfile || error "link failed for remote file"
15810         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
15811         $CHECKSTAT -t file $remote_file || error "check file failed"
15812 }
15813 run_test 310b "unlink remote file with multiple links while open"
15814
15815 test_310c() {
15816         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
15817         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15818         local remote_file=$DIR/$tdir/tgt_dir/b
15819
15820         mkdir -p $DIR/$tdir
15821
15822         prepare_remote_file || error "prepare remote file failed"
15823
15824         ln $remote_file $DIR/$tfile || error "link failed for remote file"
15825         multiop_bg_pause $remote_file O_uc ||
15826                         error "mulitop failed for remote file"
15827         MULTIPID=$!
15828         $MULTIOP $DIR/$tfile Ouc
15829         kill -USR1 $MULTIPID
15830         wait $MULTIPID
15831 }
15832 run_test 310c "open-unlink remote file with multiple links"
15833
15834 #LU-4825
15835 test_311() {
15836         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.54) ] &&
15837                 skip "lustre < 2.8.54 does not contain LU-4825 fix" && return
15838         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15839         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15840
15841         local old_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
15842
15843         mkdir -p $DIR/$tdir
15844         $SETSTRIPE -i 0 -c 1 $DIR/$tdir
15845         createmany -o $DIR/$tdir/$tfile. 1000
15846
15847         # statfs data is not real time, let's just calculate it
15848         old_iused=$((old_iused + 1000))
15849
15850         local count=$(do_facet $SINGLEMDS "lctl get_param -n \
15851                         osp.*OST0000*MDT0000.create_count")
15852         local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
15853                                 osp.*OST0000*MDT0000.max_create_count")
15854         for idx in $(seq $MDSCOUNT); do
15855                 do_facet mds$idx "lctl set_param -n \
15856                         osp.*OST0000*MDT000?.max_create_count=0"
15857         done
15858
15859         $SETSTRIPE -i 0 $DIR/$tdir/$tfile || error "setstripe failed"
15860         local index=$($GETSTRIPE -i $DIR/$tdir/$tfile)
15861         [ $index -ne 0 ] || error "$tfile stripe index is 0"
15862
15863         unlinkmany $DIR/$tdir/$tfile. 1000
15864
15865         for idx in $(seq $MDSCOUNT); do
15866                 do_facet mds$idx "lctl set_param -n \
15867                         osp.*OST0000*MDT000?.max_create_count=$max_count"
15868                 do_facet mds$idx "lctl set_param -n \
15869                         osp.*OST0000*MDT000?.create_count=$count"
15870         done
15871
15872         local new_iused
15873         for i in $(seq 120); do
15874                 new_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
15875                 # system may be too busy to destroy all objs in time, use
15876                 # a somewhat small value to not fail autotest
15877                 [ $((old_iused - new_iused)) -gt 400 ] && break
15878                 sleep 1
15879         done
15880
15881         echo "waited $i sec, old Iused $old_iused, new Iused $new_iused"
15882         [ $((old_iused - new_iused)) -gt 400 ] ||
15883                 error "objs not destroyed after unlink"
15884 }
15885 run_test 311 "disable OSP precreate, and unlink should destroy objs"
15886
15887 zfs_oid_to_objid()
15888 {
15889         local ost=$1
15890         local objid=$2
15891
15892         local vdevdir=$(dirname $(facet_vdevice $ost))
15893         local cmd="$ZDB -e -p $vdevdir -ddddd $(facet_device $ost)"
15894         local zfs_zapid=$(do_facet $ost $cmd |
15895                           grep -w "/O/0/d$((objid%32))" -C 5 |
15896                           awk '/Object/{getline; print $1}')
15897         local zfs_objid=$(do_facet $ost $cmd $zfs_zapid |
15898                           awk "/$objid = /"'{printf $3}')
15899
15900         echo $zfs_objid
15901 }
15902
15903 zfs_object_blksz() {
15904         local ost=$1
15905         local objid=$2
15906
15907         local vdevdir=$(dirname $(facet_vdevice $ost))
15908         local cmd="$ZDB -e -p $vdevdir -dddd $(facet_device $ost)"
15909         local blksz=$(do_facet $ost $cmd $objid |
15910                       awk '/dblk/{getline; printf $4}')
15911
15912         case "${blksz: -1}" in
15913                 k|K) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024)) ;;
15914                 m|M) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024*1024)) ;;
15915                 *) ;;
15916         esac
15917
15918         echo $blksz
15919 }
15920
15921 test_312() { # LU-4856
15922         remote_ost_nodsh && skip "remote OST with nodsh" && return
15923
15924         [ $(facet_fstype ost1) = "zfs" ] ||
15925                 { skip "the test only applies to zfs" && return; }
15926
15927         local max_blksz=$(do_facet ost1 \
15928                           $ZFS get -p recordsize $(facet_device ost1) |
15929                           awk '!/VALUE/{print $3}')
15930         local min_blksz=$(getconf PAGE_SIZE)
15931
15932         # to make life a little bit easier
15933         $LFS mkdir -c 1 -i 0 $DIR/$tdir
15934         $LFS setstripe -c 1 -i 0 $DIR/$tdir
15935
15936         local tf=$DIR/$tdir/$tfile
15937         touch $tf
15938         local oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
15939
15940         # Get ZFS object id
15941         local zfs_objid=$(zfs_oid_to_objid ost1 $oid)
15942
15943         # block size change by sequential over write
15944         local blksz
15945         for ((bs=$min_blksz; bs <= max_blksz; bs <<= 2)); do
15946                 dd if=/dev/zero of=$tf bs=$bs count=1 oflag=sync conv=notrunc
15947
15948                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
15949                 [ $blksz -eq $bs ] || error "blksz error: $blksz, expected: $bs"
15950         done
15951         rm -f $tf
15952
15953         # block size change by sequential append write
15954         dd if=/dev/zero of=$tf bs=$min_blksz count=1 oflag=sync conv=notrunc
15955         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
15956         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
15957
15958         for ((count = 1; count < $((max_blksz / min_blksz)); count *= 2)); do
15959                 dd if=/dev/zero of=$tf bs=$min_blksz count=$count seek=$count \
15960                         oflag=sync conv=notrunc
15961
15962                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
15963                 [ $blksz -eq $((2 * count * min_blksz)) ] ||
15964                         error "blksz error, actual $blksz, "    \
15965                                 "expected: 2 * $count * $min_blksz"
15966         done
15967         rm -f $tf
15968
15969         # random write
15970         touch $tf
15971         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
15972         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
15973
15974         dd if=/dev/zero of=$tf bs=1K count=1 oflag=sync conv=notrunc
15975         blksz=$(zfs_object_blksz ost1 $zfs_objid)
15976         [ $blksz -eq $min_blksz ] ||
15977                 error "blksz error: $blksz, expected: $min_blksz"
15978
15979         dd if=/dev/zero of=$tf bs=64K count=1 oflag=sync conv=notrunc seek=128
15980         blksz=$(zfs_object_blksz ost1 $zfs_objid)
15981         [ $blksz -eq 65536 ] || error "blksz error: $blksz, expected: 64k"
15982
15983         dd if=/dev/zero of=$tf bs=1M count=1 oflag=sync conv=notrunc
15984         blksz=$(zfs_object_blksz ost1 $zfs_objid)
15985         [ $blksz -eq 65536 ] || error "rewrite error: $blksz, expected: 64k"
15986 }
15987 run_test 312 "make sure ZFS adjusts its block size by write pattern"
15988
15989 test_313() {
15990         remote_ost_nodsh && skip "remote OST with nodsh" && return
15991
15992         local file=$DIR/$tfile
15993         rm -f $file
15994         $SETSTRIPE -c 1 -i 0 $file || error "setstripe failed"
15995
15996         # define OBD_FAIL_TGT_RCVD_EIO           0x720
15997         do_facet ost1 "$LCTL set_param fail_loc=0x720"
15998         dd if=/dev/zero of=$file bs=4096 oflag=direct count=1 &&
15999                 error "write should failed"
16000         do_facet ost1 "$LCTL set_param fail_loc=0"
16001         rm -f $file
16002 }
16003 run_test 313 "io should fail after last_rcvd update fail"
16004
16005 test_fake_rw() {
16006         local read_write=$1
16007         if [ "$read_write" = "write" ]; then
16008                 local dd_cmd="dd if=/dev/zero of=$DIR/$tfile"
16009         elif [ "$read_write" = "read" ]; then
16010                 local dd_cmd="dd of=/dev/null if=$DIR/$tfile"
16011         else
16012                 error "argument error"
16013         fi
16014
16015         # turn off debug for performance testing
16016         local saved_debug=$($LCTL get_param -n debug)
16017         $LCTL set_param debug=0
16018
16019         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
16020
16021         # get ost1 size - lustre-OST0000
16022         local ost1_avail_size=$($LFS df | awk /${ost1_svc}/'{ print $4 }')
16023         local blocks=$((ost1_avail_size/2/1024)) # half avail space by megabytes
16024         [ $blocks -gt 1000 ] && blocks=1000 # 1G in maximum
16025
16026         if [ "$read_write" = "read" ]; then
16027                 truncate -s $(expr 1048576 \* $blocks) $DIR/$tfile
16028         fi
16029
16030         local start_time=$(date +%s.%N)
16031         $dd_cmd bs=1M count=$blocks oflag=sync ||
16032                 error "real dd $read_write error"
16033         local duration=$(bc <<< "$(date +%s.%N) - $start_time")
16034
16035         if [ "$read_write" = "write" ]; then
16036                 rm -f $DIR/$tfile
16037         fi
16038
16039         # define OBD_FAIL_OST_FAKE_RW           0x238
16040         do_facet ost1 $LCTL set_param fail_loc=0x238
16041
16042         local start_time=$(date +%s.%N)
16043         $dd_cmd bs=1M count=$blocks oflag=sync ||
16044                 error "fake dd $read_write error"
16045         local duration_fake=$(bc <<< "$(date +%s.%N) - $start_time")
16046
16047         if [ "$read_write" = "write" ]; then
16048                 # verify file size
16049                 cancel_lru_locks osc
16050                 $CHECKSTAT -t file -s $((blocks * 1024 * 1024)) $DIR/$tfile ||
16051                         error "$tfile size not $blocks MB"
16052         fi
16053         do_facet ost1 $LCTL set_param fail_loc=0
16054
16055         echo "fake $read_write $duration_fake vs. normal $read_write" \
16056                 "$duration in seconds"
16057         [ $(bc <<< "$duration_fake < $duration") -eq 1 ] ||
16058                 error_not_in_vm "fake write is slower"
16059
16060         $LCTL set_param -n debug="$saved_debug"
16061         rm -f $DIR/$tfile
16062 }
16063 test_399a() { # LU-7655 for OST fake write
16064         remote_ost_nodsh && skip "remote OST with nodsh" && return
16065
16066         test_fake_rw write
16067 }
16068 run_test 399a "fake write should not be slower than normal write"
16069
16070 test_399b() { # LU-8726 for OST fake read
16071         remote_ost_nodsh && skip "remote OST with nodsh" && return
16072
16073         if [ "$(facet_fstype ost1)" != "ldiskfs" ]; then
16074                 skip "ldiskfs only test" && return 0
16075         fi
16076         test_fake_rw read
16077 }
16078 run_test 399b "fake read should not be slower than normal read"
16079
16080 test_400a() { # LU-1606, was conf-sanity test_74
16081         local extra_flags=''
16082         local out=$TMP/$tfile
16083         local prefix=/usr/include/lustre
16084         local prog
16085
16086         if ! which $CC > /dev/null 2>&1; then
16087                 skip_env "$CC is not installed"
16088                 return 0
16089         fi
16090
16091         if ! [[ -d $prefix ]]; then
16092                 # Assume we're running in tree and fixup the include path.
16093                 extra_flags+=" -I$LUSTRE/include"
16094                 extra_flags+=" -L$LUSTRE/utils"
16095         fi
16096
16097         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
16098                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
16099                         error "client api broken"
16100         done
16101         rm -f $out
16102 }
16103 run_test 400a "Lustre client api program can compile and link"
16104
16105 test_400b() { # LU-1606, LU-5011
16106         local header
16107         local out=$TMP/$tfile
16108         local prefix=/usr/include/linux/lustre
16109
16110         # We use a hard coded prefix so that this test will not fail
16111         # when run in tree. There are headers in lustre/include/lustre/
16112         # that are not packaged (like lustre_idl.h) and have more
16113         # complicated include dependencies (like config.h and lnet/types.h).
16114         # Since this test about correct packaging we just skip them when
16115         # they don't exist (see below) rather than try to fixup cppflags.
16116
16117         if ! which $CC > /dev/null 2>&1; then
16118                 skip_env "$CC is not installed"
16119                 return 0
16120         fi
16121
16122         for header in $prefix/*.h; do
16123                 if ! [[ -f "$header" ]]; then
16124                         continue
16125                 fi
16126
16127                 if [[ "$(basename $header)" == lustre_ioctl.h ]]; then
16128                         continue # lustre_ioctl.h is internal header
16129                 fi
16130
16131                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
16132                         error "cannot compile '$header'"
16133         done
16134         rm -f $out
16135 }
16136 run_test 400b "packaged headers can be compiled"
16137
16138 test_401a() { #LU-7437
16139         local printf_arg=$(find -printf 2>&1 | grep "unrecognized:")
16140         [ -n "$printf_arg" ] && skip_env "find does not support -printf" &&
16141                 return
16142         #count the number of parameters by "list_param -R"
16143         local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
16144         #count the number of parameters by listing proc files
16145         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
16146         echo "proc_dirs='$proc_dirs'"
16147         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
16148         local procs=$(find -L $proc_dirs -mindepth 1 -printf '%P\n' 2>/dev/null|
16149                       sort -u | wc -l)
16150
16151         [ $params -eq $procs ] ||
16152                 error "found $params parameters vs. $procs proc files"
16153
16154         # test the list_param -D option only returns directories
16155         params=$($LCTL list_param -R -D '*' 2>/dev/null | wc -l)
16156         #count the number of parameters by listing proc directories
16157         procs=$(find -L $proc_dirs -mindepth 1 -type d -printf '%P\n' 2>/dev/null |
16158                 sort -u | wc -l)
16159
16160         [ $params -eq $procs ] ||
16161                 error "found $params parameters vs. $procs proc files"
16162 }
16163 run_test 401a "Verify if 'lctl list_param -R' can list parameters recursively"
16164
16165 test_401b() {
16166         local save=$($LCTL get_param -n jobid_var)
16167         local tmp=testing
16168
16169         $LCTL set_param foo=bar jobid_var=$tmp bar=baz &&
16170                 error "no error returned when setting bad parameters"
16171
16172         local jobid_new=$($LCTL get_param -n foe jobid_var baz)
16173         [[ "$jobid_new" == "$tmp" ]] || error "jobid tmp $jobid_new != $tmp"
16174
16175         $LCTL set_param -n fog=bam jobid_var=$save bat=fog
16176         local jobid_old=$($LCTL get_param -n foe jobid_var bag)
16177         [[ "$jobid_old" == "$save" ]] || error "jobid new $jobid_old != $save"
16178 }
16179 run_test 401b "Verify 'lctl {get,set}_param' continue after error"
16180
16181 test_401c() {
16182         local jobid_var_old=$($LCTL get_param -n jobid_var)
16183         local jobid_var_new
16184
16185         $LCTL set_param jobid_var= &&
16186                 error "no error returned for 'set_param a='"
16187
16188         jobid_var_new=$($LCTL get_param -n jobid_var)
16189         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
16190                 error "jobid_var was changed by setting without value"
16191
16192         $LCTL set_param jobid_var &&
16193                 error "no error returned for 'set_param a'"
16194
16195         jobid_var_new=$($LCTL get_param -n jobid_var)
16196         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
16197                 error "jobid_var was changed by setting without value"
16198 }
16199 run_test 401c "Verify 'lctl set_param' without value fails in either format."
16200
16201 test_401d() {
16202         local jobid_var_old=$($LCTL get_param -n jobid_var)
16203         local jobid_var_new
16204         local new_value="foo=bar"
16205
16206         $LCTL set_param jobid_var=$new_value ||
16207                 error "'set_param a=b' did not accept a value containing '='"
16208
16209         jobid_var_new=$($LCTL get_param -n jobid_var)
16210         [[ "$jobid_var_new" == "$new_value" ]] ||
16211                 error "'set_param a=b' failed on a value containing '='"
16212
16213         # Reset the jobid_var to test the other format
16214         $LCTL set_param jobid_var=$jobid_var_old
16215         jobid_var_new=$($LCTL get_param -n jobid_var)
16216         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
16217                 error "failed to reset jobid_var"
16218
16219         $LCTL set_param jobid_var $new_value ||
16220                 error "'set_param a b' did not accept a value containing '='"
16221
16222         jobid_var_new=$($LCTL get_param -n jobid_var)
16223         [[ "$jobid_var_new" == "$new_value" ]] ||
16224                 error "'set_param a b' failed on a value containing '='"
16225
16226         $LCTL set_param jobid_var $jobid_var_old
16227         jobid_var_new=$($LCTL get_param -n jobid_var)
16228         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
16229                 error "failed to reset jobid_var"
16230 }
16231 run_test 401d "Verify 'lctl set_param' accepts values containing '='"
16232
16233 test_402() {
16234         local server_version=$(lustre_version_code $SINGLEMDS)
16235         [[ $server_version -ge $(version_code 2.7.66) ]] ||
16236         [[ $server_version -ge $(version_code 2.7.18.4) &&
16237                 $server_version -lt $(version_code 2.7.50) ]] ||
16238         [[ $server_version -ge $(version_code 2.7.2) &&
16239                 $server_version -lt $(version_code 2.7.11) ]] ||
16240                 { skip "Need MDS version 2.7.2+ or 2.7.18.4+ or 2.7.66+";
16241                         return; }
16242         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16243         $LFS setdirstripe -i 0 $DIR/$tdir || error "setdirstripe -i 0 failed"
16244 #define OBD_FAIL_MDS_FLD_LOOKUP 0x15c
16245         do_facet mds1 "lctl set_param fail_loc=0x8000015c"
16246         touch $DIR/$tdir/$tfile && error "touch should fail with ENOENT" ||
16247                 echo "Touch failed - OK"
16248 }
16249 run_test 402 "Return ENOENT to lod_generate_and_set_lovea"
16250
16251 test_403() {
16252         local file1=$DIR/$tfile.1
16253         local file2=$DIR/$tfile.2
16254         local tfile=$TMP/$tfile
16255
16256         rm -f $file1 $file2 $tfile
16257
16258         touch $file1
16259         ln $file1 $file2
16260
16261         # 30 sec OBD_TIMEOUT in ll_getattr()
16262         # right before populating st_nlink
16263         $LCTL set_param fail_loc=0x80001409
16264         stat -c %h $file1 > $tfile &
16265
16266         # create an alias, drop all locks and reclaim the dentry
16267         < $file2
16268         cancel_lru_locks mdc
16269         cancel_lru_locks osc
16270         sysctl -w vm.drop_caches=2
16271
16272         wait
16273
16274         [ `cat $tfile` -gt 0 ] || error "wrong nlink count: `cat $tfile`"
16275
16276         rm -f $tfile $file1 $file2
16277 }
16278 run_test 403 "i_nlink should not drop to zero due to aliasing"
16279
16280 test_404() { # LU-6601
16281         local server_version=$(lustre_version_code $SINGLEMDS)
16282         [[ $server_version -ge $(version_code 2.8.53) ]] ||
16283                 { skip "Need server version newer than 2.8.52"; return 0; }
16284
16285         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16286         local mosps=$(do_facet $SINGLEMDS $LCTL dl |
16287                 awk '/osp .*-osc-MDT/ { print $4}')
16288
16289         local osp
16290         for osp in $mosps; do
16291                 echo "Deactivate: " $osp
16292                 do_facet $SINGLEMDS $LCTL --device %$osp deactivate
16293                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
16294                         awk -vp=$osp '$4 == p { print $2 }')
16295                 [ $stat = IN ] || {
16296                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
16297                         error "deactivate error"
16298                 }
16299                 echo "Activate: " $osp
16300                 do_facet $SINGLEMDS $LCTL --device %$osp activate
16301                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
16302                         awk -vp=$osp '$4 == p { print $2 }')
16303                 [ $stat = UP ] || {
16304                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
16305                         error "activate error"
16306                 }
16307         done
16308 }
16309 run_test 404 "validate manual {de}activated works properly for OSPs"
16310
16311 test_405() {
16312         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) -o \
16313         [ $(lustre_version_code client) -lt $(version_code 2.6.99) ] &&
16314                 skip "Layout swap lock is not supported" && return
16315
16316         check_swap_layouts_support && return 0
16317
16318         test_mkdir $DIR/$tdir
16319         swap_lock_test -d $DIR/$tdir ||
16320                 error "One layout swap locked test failed"
16321 }
16322 run_test 405 "Various layout swap lock tests"
16323
16324 test_406() {
16325         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16326         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
16327         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
16328         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16329         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.50) ] &&
16330                 skip "Need MDS version at least 2.8.50" && return
16331
16332         local def_stripe_count=$($GETSTRIPE -c $MOUNT)
16333         local def_stripe_size=$($GETSTRIPE -S $MOUNT)
16334         local def_stripe_offset=$($GETSTRIPE -i $MOUNT)
16335         local def_pool=$($GETSTRIPE -p $MOUNT)
16336
16337         local test_pool=$TESTNAME
16338         pool_add $test_pool || error "pool_add failed"
16339         pool_add_targets $test_pool 0 $(($OSTCOUNT - 1)) 1 ||
16340                 error "pool_add_targets failed"
16341
16342         # parent set default stripe count only, child will stripe from both
16343         # parent and fs default
16344         $SETSTRIPE -c 1 -i 1 -S $((def_stripe_size * 2)) -p $test_pool $MOUNT ||
16345                 error "setstripe $MOUNT failed"
16346         $LFS mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
16347         $SETSTRIPE -c $OSTCOUNT $DIR/$tdir || error "setstripe $tdir failed"
16348         for i in $(seq 10); do
16349                 local f=$DIR/$tdir/$tfile.$i
16350                 touch $f || error "touch failed"
16351                 local count=$($GETSTRIPE -c $f)
16352                 [ $count -eq $OSTCOUNT ] ||
16353                         error "$f stripe count $count != $OSTCOUNT"
16354                 local offset=$($GETSTRIPE -i $f)
16355                 [ $offset -eq 1 ] || error "$f stripe offset $offset != 1"
16356                 local size=$($GETSTRIPE -S $f)
16357                 [ $size -eq $((def_stripe_size * 2)) ] ||
16358                         error "$f stripe size $size != $((def_stripe_size * 2))"
16359                 local pool=$($GETSTRIPE -p $f)
16360                 [ $pool == $test_pool ] || error "$f pool $pool != $test_pool"
16361         done
16362
16363         # change fs default striping, delete parent default striping, now child
16364         # will stripe from new fs default striping only
16365         $SETSTRIPE -c 1 -S $def_stripe_size -i 0 $MOUNT ||
16366                 error "change $MOUNT default stripe failed"
16367         $SETSTRIPE -c 0 $DIR/$tdir || error "delete $tdir default stripe failed"
16368         for i in $(seq 11 20); do
16369                 local f=$DIR/$tdir/$tfile.$i
16370                 touch $f || error "touch $f failed"
16371                 local count=$($GETSTRIPE -c $f)
16372                 [ $count -eq 1 ] || error "$f stripe count $count != 1"
16373                 local offset=$($GETSTRIPE -i $f)
16374                 [ $offset -eq 0 ] || error "$f stripe offset $offset != 0"
16375                 local size=$($GETSTRIPE -S $f)
16376                 [ $size -eq $def_stripe_size ] ||
16377                         error "$f stripe size $size != $def_stripe_size"
16378                 local pool=$($GETSTRIPE -p $f)
16379                 [ "#$pool" == "#" ] || error "$f pool $pool is set"
16380
16381         done
16382
16383         unlinkmany $DIR/$tdir/$tfile. 1 20
16384
16385         # restore FS default striping
16386         if [ -z $def_pool ]; then
16387                 $SETSTRIPE -c $def_stripe_count -S $def_stripe_size \
16388                         -i $def_stripe_offset $MOUNT ||
16389                         error "restore default striping failed"
16390         else
16391                 $SETSTRIPE -c $def_stripe_count -S $def_stripe_size \
16392                         -i $def_stripe_offset -p $def_pool $MOUNT ||
16393                         error "restore default striping with $def_pool failed"
16394         fi
16395
16396         local f=$DIR/$tdir/$tfile
16397         pool_remove_all_targets $test_pool $f
16398         pool_remove $test_pool $f
16399 }
16400 run_test 406 "DNE support fs default striping"
16401
16402 test_407() {
16403         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16404         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
16405                 skip "Need MDS version at least 2.8.55" && return
16406         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16407
16408         $LFS mkdir -i 0 -c 1 $DIR/$tdir.0 ||
16409                 error "$LFS mkdir -i 0 -c 1 $tdir.0 failed"
16410         $LFS mkdir -i 1 -c 1 $DIR/$tdir.1 ||
16411                 error "$LFS mkdir -i 1 -c 1 $tdir.1 failed"
16412         touch $DIR/$tdir.0/$tfile.0 || error "touch $tdir.0/$tfile.0 failed"
16413
16414         #define OBD_FAIL_DT_TXN_STOP    0x2019
16415         for idx in $(seq $MDSCOUNT); do
16416                 do_facet mds$idx "lctl set_param fail_loc=0x2019"
16417         done
16418         $LFS mkdir -c 2 $DIR/$tdir && error "$LFS mkdir -c 2 $tdir should fail"
16419         mv $DIR/$tdir.0/$tfile.0 $DIR/$tdir.1/$tfile.1 &&
16420                 error "mv $tdir.0/$tfile.0 $tdir.1/$tfile.1 should fail"
16421         true
16422 }
16423 run_test 407 "transaction fail should cause operation fail"
16424
16425 test_408() {
16426         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 oflag=direct
16427
16428         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
16429         lctl set_param fail_loc=0x8000040a
16430         # let ll_prepare_partial_page() fail
16431         dd if=/dev/zero of=$DIR/$tfile bs=2048 count=1 conv=notrunc || true
16432
16433         rm -f $DIR/$tfile
16434
16435         # create at least 100 unused inodes so that
16436         # shrink_icache_memory(0) should not return 0
16437         touch $DIR/$tfile-{0..100}
16438         rm -f $DIR/$tfile-{0..100}
16439         sync
16440
16441         echo 2 > /proc/sys/vm/drop_caches
16442 }
16443 run_test 408 "drop_caches should not hang due to page leaks"
16444
16445 test_409()
16446 {
16447         [ $MDSCOUNT -lt 2 ] &&
16448                 skip "We need at least 2 MDTs for this test" && return
16449
16450         check_mount_and_prep
16451
16452         mkdir -p $DIR/$tdir || error "(0) Fail to mkdir"
16453         $LFS mkdir -i 1 -c 2 $DIR/$tdir/foo || error "(1) Fail to mkdir"
16454         touch $DIR/$tdir/guard || error "(2) Fail to create"
16455
16456         local PREFIX=$(str_repeat 'A' 128)
16457         echo "Create 1K hard links start at $(date)"
16458         createmany -l $DIR/$tdir/guard $DIR/$tdir/foo/${PREFIX}_ 1000 ||
16459                 error "(3) Fail to hard link"
16460
16461         echo "Links count should be right although linkEA overflow"
16462         stat $DIR/$tdir/guard || error "(4) Fail to stat"
16463         local linkcount=$(stat --format=%h $DIR/$tdir/guard)
16464         [ $linkcount -eq 1001 ] ||
16465                 error "(5) Unexpected hard links count: $linkcount"
16466
16467         echo "List all links start at $(date)"
16468         ls -l $DIR/$tdir/foo > /dev/null ||
16469                 error "(6) Fail to list $DIR/$tdir/foo"
16470
16471         echo "Unlink hard links start at $(date)"
16472         unlinkmany $DIR/$tdir/foo/${PREFIX}_ 1000 ||
16473                 error "(7) Fail to unlink"
16474 }
16475 run_test 409 "Large amount of cross-MDTs hard links on the same file"
16476
16477 test_410()
16478 {
16479         [[ $(lustre_version_code client) -lt $(version_code 2.9.59) ]] &&
16480                 skip "Need client version at least 2.9.59" && return
16481
16482         # Create a file, and stat it from the kernel
16483         local testfile=$DIR/$tfile
16484         touch $testfile
16485
16486         local run_id=$RANDOM
16487         local my_ino=$(stat --format "%i" $testfile)
16488
16489         # Try to insert the module. This will always fail as the
16490         # module is designed to not be inserted.
16491         insmod $LUSTRE/tests/kernel/kinode.ko run_id=$run_id fname=$testfile \
16492             &> /dev/null
16493
16494         # Anything but success is a test failure
16495         dmesg | grep -q \
16496             "lustre_kinode_$run_id: inode numbers are identical: $my_ino" ||
16497             error "no inode match"
16498 }
16499 run_test 410 "Test inode number returned from kernel thread"
16500
16501 cleanup_test411_cgroup() {
16502         trap 0
16503         rmdir "$1"
16504 }
16505
16506 test_411() {
16507         local cg_basedir=/sys/fs/cgroup/memory
16508         # LU-9966
16509         test -f "$cg_basedir/memory.kmem.limit_in_bytes" ||
16510                 { skip "no setup for cgroup"; return; }
16511
16512         dd if=/dev/zero of=$DIR/$tfile bs=1M count=100 conv=fsync ||
16513                 error "test file creation failed"
16514         cancel_lru_locks osc
16515
16516         # Create a very small memory cgroup to force a slab allocation error
16517         local cgdir=$cg_basedir/osc_slab_alloc
16518         mkdir $cgdir || error "cgroup mkdir '$cgdir' failed"
16519         trap "cleanup_test411_cgroup $cgdir" EXIT
16520         echo 2M > $cgdir/memory.kmem.limit_in_bytes
16521         echo 1M > $cgdir/memory.limit_in_bytes
16522
16523         # Should not LBUG, just be killed by oom-killer
16524         sh -c "echo \$$ > $cgdir/tasks && dd if=$DIR/$tfile of=/dev/null" &&
16525                 error "fail to trigger a memory allocation error"
16526
16527         cleanup_test411_cgroup $cgdir
16528
16529         return 0
16530 }
16531 run_test 411 "Slab allocation error with cgroup does not LBUG"
16532
16533 prep_801() {
16534         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
16535         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
16536                 skip "Need server version at least 2.9.55" & exit 0
16537         start_full_debug_logging
16538 }
16539
16540 post_801() {
16541         stop_full_debug_logging
16542 }
16543
16544 barrier_stat() {
16545         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
16546                 local st=$(do_facet mgs $LCTL barrier_stat $FSNAME |
16547                            awk '/The barrier for/ { print $7 }')
16548                 echo $st
16549         else
16550                 local st=$(do_facet mgs $LCTL barrier_stat -s $FSNAME)
16551                 echo \'$st\'
16552         fi
16553 }
16554
16555 barrier_expired() {
16556         local expired
16557
16558         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
16559                 expired=$(do_facet mgs $LCTL barrier_stat $FSNAME |
16560                           awk '/will be expired/ { print $7 }')
16561         else
16562                 expired=$(do_facet mgs $LCTL barrier_stat -t $FSNAME)
16563         fi
16564
16565         echo $expired
16566 }
16567
16568 test_801a() {
16569         prep_801
16570
16571         echo "Start barrier_freeze at: $(date)"
16572         #define OBD_FAIL_BARRIER_DELAY          0x2202
16573         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
16574         do_facet mgs $LCTL barrier_freeze $FSNAME 10 &
16575
16576         sleep 2
16577         local b_status=$(barrier_stat)
16578         echo "Got barrier status at: $(date)"
16579         [ "$b_status" = "'freezing_p1'" ] ||
16580                 error "(1) unexpected barrier status $b_status"
16581
16582         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
16583         wait
16584         b_status=$(barrier_stat)
16585         [ "$b_status" = "'frozen'" ] ||
16586                 error "(2) unexpected barrier status $b_status"
16587
16588         local expired=$(barrier_expired)
16589         echo "sleep $((expired + 3)) seconds, then the barrier will be expired"
16590         sleep $((expired + 3))
16591
16592         b_status=$(barrier_stat)
16593         [ "$b_status" = "'expired'" ] ||
16594                 error "(3) unexpected barrier status $b_status"
16595
16596         do_facet mgs $LCTL barrier_freeze $FSNAME 10 ||
16597                 error "(4) fail to freeze barrier"
16598
16599         b_status=$(barrier_stat)
16600         [ "$b_status" = "'frozen'" ] ||
16601                 error "(5) unexpected barrier status $b_status"
16602
16603         echo "Start barrier_thaw at: $(date)"
16604         #define OBD_FAIL_BARRIER_DELAY          0x2202
16605         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
16606         do_facet mgs $LCTL barrier_thaw $FSNAME &
16607
16608         sleep 2
16609         b_status=$(barrier_stat)
16610         echo "Got barrier status at: $(date)"
16611         [ "$b_status" = "'thawing'" ] ||
16612                 error "(6) unexpected barrier status $b_status"
16613
16614         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
16615         wait
16616         b_status=$(barrier_stat)
16617         [ "$b_status" = "'thawed'" ] ||
16618                 error "(7) unexpected barrier status $b_status"
16619
16620         #define OBD_FAIL_BARRIER_FAILURE        0x2203
16621         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2203
16622         do_facet mgs $LCTL barrier_freeze $FSNAME
16623
16624         b_status=$(barrier_stat)
16625         [ "$b_status" = "'failed'" ] ||
16626                 error "(8) unexpected barrier status $b_status"
16627
16628         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
16629         do_facet mgs $LCTL barrier_thaw $FSNAME
16630
16631         post_801
16632 }
16633 run_test 801a "write barrier user interfaces and stat machine"
16634
16635 test_801b() {
16636         prep_801
16637
16638         mkdir $DIR/$tdir || error "(1) fail to mkdir"
16639         createmany -d $DIR/$tdir/d 6 || "(2) fail to mkdir"
16640         touch $DIR/$tdir/d2/f10 || error "(3) fail to touch"
16641         touch $DIR/$tdir/d3/f11 || error "(4) fail to touch"
16642         touch $DIR/$tdir/d4/f12 || error "(5) fail to touch"
16643
16644         cancel_lru_locks mdc
16645
16646         # 180 seconds should be long enough
16647         do_facet mgs $LCTL barrier_freeze $FSNAME 180
16648
16649         local b_status=$(barrier_stat)
16650         [ "$b_status" = "'frozen'" ] ||
16651                 error "(6) unexpected barrier status $b_status"
16652
16653         mkdir $DIR/$tdir/d0/d10 &
16654         mkdir_pid=$!
16655
16656         touch $DIR/$tdir/d1/f13 &
16657         touch_pid=$!
16658
16659         ln $DIR/$tdir/d2/f10 $DIR/$tdir/d2/f14 &
16660         ln_pid=$!
16661
16662         mv $DIR/$tdir/d3/f11 $DIR/$tdir/d3/f15 &
16663         mv_pid=$!
16664
16665         rm -f $DIR/$tdir/d4/f12 &
16666         rm_pid=$!
16667
16668         stat $DIR/$tdir/d5 || error "(7) stat should succeed"
16669
16670         # To guarantee taht the 'stat' is not blocked
16671         b_status=$(barrier_stat)
16672         [ "$b_status" = "'frozen'" ] ||
16673                 error "(8) unexpected barrier status $b_status"
16674
16675         # let above commands to run at background
16676         sleep 5
16677
16678         ps -p $mkdir_pid || error "(9) mkdir should be blocked"
16679         ps -p $touch_pid || error "(10) touch should be blocked"
16680         ps -p $ln_pid || error "(11) link should be blocked"
16681         ps -p $mv_pid || error "(12) rename should be blocked"
16682         ps -p $rm_pid || error "(13) unlink should be blocked"
16683
16684         b_status=$(barrier_stat)
16685         [ "$b_status" = "'frozen'" ] ||
16686                 error "(14) unexpected barrier status $b_status"
16687
16688         do_facet mgs $LCTL barrier_thaw $FSNAME
16689         b_status=$(barrier_stat)
16690         [ "$b_status" = "'thawed'" ] ||
16691                 error "(15) unexpected barrier status $b_status"
16692
16693         wait $mkdir_pid || error "(16) mkdir should succeed"
16694         wait $touch_pid || error "(17) touch should succeed"
16695         wait $ln_pid || error "(18) link should succeed"
16696         wait $mv_pid || error "(19) rename should succeed"
16697         wait $rm_pid || error "(20) unlink should succeed"
16698
16699         post_801
16700 }
16701 run_test 801b "modification will be blocked by write barrier"
16702
16703 test_801c() {
16704         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
16705
16706         prep_801
16707
16708         stop mds2 || error "(1) Fail to stop mds2"
16709
16710         do_facet mgs $LCTL barrier_freeze $FSNAME 30
16711
16712         local b_status=$(barrier_stat)
16713         [ "$b_status" = "'expired'" -o "$b_status" = "'failed'" ] || {
16714                 do_facet mgs $LCTL barrier_thaw $FSNAME
16715                 error "(2) unexpected barrier status $b_status"
16716         }
16717
16718         do_facet mgs $LCTL barrier_rescan $FSNAME ||
16719                 error "(3) Fail to rescan barrier bitmap"
16720
16721         do_facet mgs $LCTL barrier_freeze $FSNAME 10
16722
16723         b_status=$(barrier_stat)
16724         [ "$b_status" = "'frozen'" ] ||
16725                 error "(4) unexpected barrier status $b_status"
16726
16727         do_facet mgs $LCTL barrier_thaw $FSNAME
16728         b_status=$(barrier_stat)
16729         [ "$b_status" = "'thawed'" ] ||
16730                 error "(5) unexpected barrier status $b_status"
16731
16732         local devname=$(mdsdevname 2)
16733
16734         start mds2 $devname $MDS_MOUNT_OPTS || error "(6) Fail to start mds2"
16735
16736         do_facet mgs $LCTL barrier_rescan $FSNAME ||
16737                 error "(7) Fail to rescan barrier bitmap"
16738
16739         post_801
16740 }
16741 run_test 801c "rescan barrier bitmap"
16742
16743 saved_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
16744 saved_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
16745 saved_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
16746
16747 cleanup_802() {
16748         trap 0
16749
16750         stopall
16751         MGS_MOUNT_OPTS=$saved_MGS_MOUNT_OPTS
16752         MDS_MOUNT_OPTS=$saved_MDS_MOUNT_OPTS
16753         OST_MOUNT_OPTS=$saved_OST_MOUNT_OPTS
16754         setupall
16755 }
16756
16757 test_802() {
16758
16759         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
16760         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
16761                 skip "Need server version at least 2.9.55" & exit 0
16762
16763         mkdir $DIR/$tdir || error "(1) fail to mkdir"
16764
16765         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
16766                 error "(2) Fail to copy"
16767
16768         trap cleanup_802 EXIT
16769
16770         # sync by force before remount as readonly
16771         sync; sync_all_data; sleep 3; sync_all_data
16772
16773         stopall
16774
16775         MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
16776         MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
16777         OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
16778
16779         echo "Mount the server as read only"
16780         setupall server_only || error "(3) Fail to start servers"
16781
16782         echo "Mount client without ro should fail"
16783         mount_client $MOUNT &&
16784                 error "(4) Mount client without 'ro' should fail"
16785
16786         echo "Mount client with ro should succeed"
16787         mount_client $MOUNT ro ||
16788                 error "(5) Mount client with 'ro' should succeed"
16789
16790         echo "Modify should be refused"
16791         touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
16792
16793         echo "Read should be allowed"
16794         diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
16795                 error "(7) Read should succeed under ro mode"
16796
16797         cleanup_802
16798 }
16799 run_test 802 "simulate readonly device"
16800
16801 #
16802 # tests that do cleanup/setup should be run at the end
16803 #
16804
16805 test_900() {
16806         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16807         local ls
16808         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
16809         $LCTL set_param fail_loc=0x903
16810
16811         cancel_lru_locks MGC
16812
16813         FAIL_ON_ERROR=true cleanup
16814         FAIL_ON_ERROR=true setup
16815 }
16816 run_test 900 "umount should not race with any mgc requeue thread"
16817
16818 complete $SECONDS
16819 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
16820 check_and_cleanup_lustre
16821 if [ "$I_MOUNTED" != "yes" ]; then
16822         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
16823 fi
16824 exit_status