Whamcloud - gitweb
LU-11757 lod: use calculated stripe count
[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
12 ALWAYS_EXCEPT="$SANITY_EXCEPT  42a     42b     42c"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # skipped tests: LU-8411 LU-9096 LU-9054
16 ALWAYS_EXCEPT="  407     253     312 $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 SRCDIR=$(cd $(dirname $0); echo $PWD)
22 export PATH=$PATH:/sbin
23
24 TMP=${TMP:-/tmp}
25
26 CC=${CC:-cc}
27 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
28 CREATETEST=${CREATETEST:-createtest}
29 LFS=${LFS:-lfs}
30 LFIND=${LFIND:-"$LFS find"}
31 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
32 LCTL=${LCTL:-lctl}
33 OPENFILE=${OPENFILE:-openfile}
34 OPENUNLINK=${OPENUNLINK:-openunlink}
35 export MULTIOP=${MULTIOP:-multiop}
36 READS=${READS:-"reads"}
37 MUNLINK=${MUNLINK:-munlink}
38 SOCKETSERVER=${SOCKETSERVER:-socketserver}
39 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
40 MEMHOG=${MEMHOG:-memhog}
41 DIRECTIO=${DIRECTIO:-directio}
42 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
43 STRIPES_PER_OBJ=-1
44 CHECK_GRANT=${CHECK_GRANT:-"yes"}
45 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
46 export PARALLEL=${PARALLEL:-"no"}
47
48 export NAME=${NAME:-local}
49
50 SAVE_PWD=$PWD
51
52 CLEANUP=${CLEANUP:-:}
53 SETUP=${SETUP:-:}
54 TRACE=${TRACE:-""}
55 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
56 LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
57 . $LUSTRE/tests/test-framework.sh
58 init_test_env $@
59 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
60 init_logging
61
62 #                                  5          12          (min)"
63 [ "$SLOW" = "no" ] && EXCEPT_SLOW="27m 64b 68 71 115 300o"
64
65 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
66         # bug number for skipped test: LU-4536 LU-1957
67         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  65ic    180"
68         #                                               13    (min)"
69         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b"
70 fi
71
72
73 is_sles11()                                             # LU-4341
74 {
75         if [ -r /etc/SuSE-release ]
76         then
77                 local vers=$(grep VERSION /etc/SuSE-release | awk '{print $3}')
78                 local patchlev=$(grep PATCHLEVEL /etc/SuSE-release |
79                         awk '{ print $3 }')
80                 if [ $vers -eq 11 ] && [ $patchlev -ge 3 ]; then
81                         return 0
82                 fi
83         fi
84         return 1
85 }
86
87 # Check if we are running on Ubuntu or SLES so we can make decisions on
88 # what tests to run
89 if is_sles11; then
90         # bug number for skipped test: LU-4341
91         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  170"
92 elif [ -r /etc/os-release ]; then
93         if grep -qi ubuntu /etc/os-release; then
94                 ubuntu_version=$(version_code $(sed -n -e 's/"//g' \
95                                                 -e 's/^VERSION=//p' \
96                                                 /etc/os-release |
97                                                 awk '{ print $1 }'))
98
99                 if [[ $ubuntu_version -gt $(version_code 16.0.0) ]]; then
100                         # bug number for skipped test:
101                         #                LU-10334 LU-10335 LU-10335 LU-10335
102                         ALWAYS_EXCEPT+=" 103a     130a     130b     130c"
103                         #                LU-10335 LU-10335 LU-10365 LU-10366
104                         ALWAYS_EXCEPT+=" 130d     130e     400a     410"
105                 fi
106         fi
107 fi
108
109 FAIL_ON_ERROR=false
110
111 cleanup() {
112         echo -n "cln.."
113         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
114         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
115 }
116 setup() {
117         echo -n "mnt.."
118         load_modules
119         setupall || exit 10
120         echo "done"
121 }
122
123 check_swap_layouts_support()
124 {
125         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
126                 { skip "Does not support layout lock."; return 0; }
127         return 1
128 }
129
130 check_and_setup_lustre
131 DIR=${DIR:-$MOUNT}
132 assert_DIR
133
134 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
135         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
136 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
137
138 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
139 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
140 rm -rf $DIR/[Rdfs][0-9]*
141
142 # $RUNAS_ID may get set incorrectly somewhere else
143 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
144
145 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
146
147 build_test_filter
148
149 if [ "${ONLY}" = "MOUNT" ] ; then
150         echo "Lustre is up, please go on"
151         exit
152 fi
153
154 echo "preparing for tests involving mounts"
155 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
156 touch $EXT2_DEV
157 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
158 echo # add a newline after mke2fs.
159
160 umask 077
161
162 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
163 lctl set_param debug=-1 2> /dev/null || true
164 test_0a() {
165         touch $DIR/$tfile
166         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
167         rm $DIR/$tfile
168         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
169 }
170 run_test 0a "touch; rm ====================="
171
172 test_0b() {
173         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
174         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
175 }
176 run_test 0b "chmod 0755 $DIR ============================="
177
178 test_0c() {
179         $LCTL get_param mdc.*.import | grep "state: FULL" ||
180                 error "import not FULL"
181         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
182                 error "bad target"
183 }
184 run_test 0c "check import proc ============================="
185
186 test_1() {
187         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
188         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
189         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
190         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
191         rmdir $DIR/$tdir/d2
192         rmdir $DIR/$tdir
193         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
194 }
195 run_test 1 "mkdir; remkdir; rmdir =============================="
196
197 test_2() {
198         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
199         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
200         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
201         rm -r $DIR/$tdir
202         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
203 }
204 run_test 2 "mkdir; touch; rmdir; check file ===================="
205
206 test_3() {
207         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
208         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
209         touch $DIR/$tdir/$tfile
210         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
211         rm -r $DIR/$tdir
212         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
213 }
214 run_test 3 "mkdir; touch; rmdir; check dir ====================="
215
216 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
217 test_4() {
218         local MDTIDX=1
219
220         test_mkdir $DIR/$tdir ||
221                 error "Create remote directory failed"
222
223         touch $DIR/$tdir/$tfile ||
224                 error "Create file under remote directory failed"
225
226         rmdir $DIR/$tdir &&
227                 error "Expect error removing in-use dir $DIR/$tdir"
228
229         test -d $DIR/$tdir || error "Remote directory disappeared"
230
231         rm -rf $DIR/$tdir || error "remove remote dir error"
232 }
233 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
234
235 test_5() {
236         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
237         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
238         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
239         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
240         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
241 }
242 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
243
244 test_6a() {
245         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
246         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
247         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
248                 error "$tfile does not have perm 0666 or UID $UID"
249         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
250         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
251                 error "$tfile should be 0666 and owned by UID $UID"
252 }
253 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
254
255 test_6c() {
256         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
257         touch $DIR/$tfile
258         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
259         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
260                 error "$tfile should be owned by UID $RUNAS_ID"
261         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
262         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
263                 error "$tfile should be owned by UID $RUNAS_ID"
264 }
265 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
266
267 test_6e() {
268         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
269         touch $DIR/$tfile
270         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
271         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
272                 error "$tfile should be owned by GID $UID"
273         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
274         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
275                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
276 }
277 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
278
279 test_6g() {
280         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
281         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
282         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
283         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
284         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
285         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
286         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
287                 error "$tdir/d/subdir should be GID $RUNAS_GID"
288         if [[ $MDSCOUNT -gt 1 ]]; then
289                 # check remote dir sgid inherite
290                 $LFS mkdir -i 0 $DIR/$tdir.local ||
291                         error "mkdir $tdir.local failed"
292                 chmod g+s $DIR/$tdir.local ||
293                         error "chmod $tdir.local failed"
294                 chgrp $RUNAS_GID $DIR/$tdir.local ||
295                         error "chgrp $tdir.local failed"
296                 $LFS mkdir -i 1 $DIR/$tdir.local/$tdir.remote ||
297                         error "mkdir $tdir.remote failed"
298                 $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir.local/$tdir.remote ||
299                         error "$tdir.remote should be owned by $UID.$RUNAS_ID"
300                 $CHECKSTAT -p 02755 $DIR/$tdir.local/$tdir.remote ||
301                         error "$tdir.remote should be mode 02755"
302         fi
303 }
304 run_test 6g "Is new dir in sgid dir inheriting group?"
305
306 test_6h() { # bug 7331
307         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
308         touch $DIR/$tfile || error "touch failed"
309         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
310         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
311                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
312         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
313                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
314 }
315 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
316
317 test_7a() {
318         test_mkdir $DIR/$tdir
319         $MCREATE $DIR/$tdir/$tfile
320         chmod 0666 $DIR/$tdir/$tfile
321         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
322                 error "$tdir/$tfile should be mode 0666"
323 }
324 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
325
326 test_7b() {
327         if [ ! -d $DIR/$tdir ]; then
328                 test_mkdir $DIR/$tdir
329         fi
330         $MCREATE $DIR/$tdir/$tfile
331         echo -n foo > $DIR/$tdir/$tfile
332         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
333         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
334 }
335 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
336
337 test_8() {
338         test_mkdir $DIR/$tdir
339         touch $DIR/$tdir/$tfile
340         chmod 0666 $DIR/$tdir/$tfile
341         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
342                 error "$tfile mode not 0666"
343 }
344 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
345
346 test_9() {
347         test_mkdir $DIR/$tdir
348         test_mkdir $DIR/$tdir/d2
349         test_mkdir $DIR/$tdir/d2/d3
350         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
351 }
352 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
353
354 test_10() {
355         test_mkdir $DIR/$tdir
356         test_mkdir $DIR/$tdir/d2
357         touch $DIR/$tdir/d2/$tfile
358         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
359                 error "$tdir/d2/$tfile not a file"
360 }
361 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
362
363 test_11() {
364         test_mkdir $DIR/$tdir
365         test_mkdir $DIR/$tdir/d2
366         chmod 0666 $DIR/$tdir/d2
367         chmod 0705 $DIR/$tdir/d2
368         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
369                 error "$tdir/d2 mode not 0705"
370 }
371 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
372
373 test_12() {
374         test_mkdir $DIR/$tdir
375         touch $DIR/$tdir/$tfile
376         chmod 0666 $DIR/$tdir/$tfile
377         chmod 0654 $DIR/$tdir/$tfile
378         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
379                 error "$tdir/d2 mode not 0654"
380 }
381 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
382
383 test_13() {
384         test_mkdir $DIR/$tdir
385         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
386         >  $DIR/$tdir/$tfile
387         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
388                 error "$tdir/$tfile size not 0 after truncate"
389 }
390 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
391
392 test_14() {
393         test_mkdir $DIR/$tdir
394         touch $DIR/$tdir/$tfile
395         rm $DIR/$tdir/$tfile
396         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
397 }
398 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
399
400 test_15() {
401         test_mkdir $DIR/$tdir
402         touch $DIR/$tdir/$tfile
403         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
404         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
405                 error "$tdir/${tfile_2} not a file after rename"
406         rm $DIR/$tdir/${tfile}_2 || error "unlink failed after rename"
407 }
408 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
409
410 test_16() {
411         test_mkdir $DIR/$tdir
412         touch $DIR/$tdir/$tfile
413         rm -rf $DIR/$tdir/$tfile
414         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
415 }
416 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
417
418 test_17a() {
419         test_mkdir -p $DIR/$tdir
420         touch $DIR/$tdir/$tfile
421         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
422         ls -l $DIR/$tdir
423         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
424                 error "$tdir/l-exist not a symlink"
425         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
426                 error "$tdir/l-exist not referencing a file"
427         rm -f $DIR/$tdir/l-exist
428         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
429 }
430 run_test 17a "symlinks: create, remove (real) =================="
431
432 test_17b() {
433         test_mkdir -p $DIR/$tdir
434         ln -s no-such-file $DIR/$tdir/l-dangle
435         ls -l $DIR/$tdir
436         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
437                 error "$tdir/l-dangle not referencing no-such-file"
438         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
439                 error "$tdir/l-dangle not referencing non-existent file"
440         rm -f $DIR/$tdir/l-dangle
441         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
442 }
443 run_test 17b "symlinks: create, remove (dangling) =============="
444
445 test_17c() { # bug 3440 - don't save failed open RPC for replay
446         test_mkdir -p $DIR/$tdir
447         ln -s foo $DIR/$tdir/$tfile
448         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
449 }
450 run_test 17c "symlinks: open dangling (should return error) ===="
451
452 test_17d() {
453         test_mkdir -p $DIR/$tdir
454         ln -s foo $DIR/$tdir/$tfile
455         touch $DIR/$tdir/$tfile || error "creating to new symlink"
456 }
457 run_test 17d "symlinks: create dangling ========================"
458
459 test_17e() {
460         test_mkdir -p $DIR/$tdir
461         local foo=$DIR/$tdir/$tfile
462         ln -s $foo $foo || error "create symlink failed"
463         ls -l $foo || error "ls -l failed"
464         ls $foo && error "ls not failed" || true
465 }
466 run_test 17e "symlinks: create recursive symlink (should return error) ===="
467
468 test_17f() {
469         test_mkdir -p $DIR/$tdir
470         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
471         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
472         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
473         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
474         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
475         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
476         ls -l  $DIR/$tdir
477 }
478 run_test 17f "symlinks: long and very long symlink name ========================"
479
480 # str_repeat(S, N) generate a string that is string S repeated N times
481 str_repeat() {
482         local s=$1
483         local n=$2
484         local ret=''
485         while [ $((n -= 1)) -ge 0 ]; do
486                 ret=$ret$s
487         done
488         echo $ret
489 }
490
491 # Long symlinks and LU-2241
492 test_17g() {
493         test_mkdir -p $DIR/$tdir
494         local TESTS="59 60 61 4094 4095"
495
496         # Fix for inode size boundary in 2.1.4
497         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
498                 TESTS="4094 4095"
499
500         # Patch not applied to 2.2 or 2.3 branches
501         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
502         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
503                 TESTS="4094 4095"
504
505         # skip long symlink name for rhel6.5.
506         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
507         grep -q '6.5' /etc/redhat-release &>/dev/null &&
508                 TESTS="59 60 61 4062 4063"
509
510         for i in $TESTS; do
511                 local SYMNAME=$(str_repeat 'x' $i)
512                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
513                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
514         done
515 }
516 run_test 17g "symlinks: really long symlink name and inode boundaries"
517
518 test_17h() { #bug 17378
519         remote_mds_nodsh && skip "remote MDS with nodsh" && return
520         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
521         local mdt_idx
522         test_mkdir -p $DIR/$tdir
523         if [[ $MDSCOUNT -gt 1 ]]; then
524                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
525         else
526                 mdt_idx=0
527         fi
528         $SETSTRIPE -c -1 $DIR/$tdir
529 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
530         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
531         touch $DIR/$tdir/$tfile || true
532 }
533 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
534
535 test_17i() { #bug 20018
536         remote_mds_nodsh && skip "remote MDS with nodsh" && return
537         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
538         test_mkdir -c1 $DIR/$tdir
539         local foo=$DIR/$tdir/$tfile
540         local mdt_idx
541         if [[ $MDSCOUNT -gt 1 ]]; then
542                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
543         else
544                 mdt_idx=0
545         fi
546         ln -s $foo $foo || error "create symlink failed"
547 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
548         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
549         ls -l $foo && error "error not detected"
550         return 0
551 }
552 run_test 17i "don't panic on short symlink"
553
554 test_17k() { #bug 22301
555         [[ -z "$(which rsync 2>/dev/null)" ]] &&
556                 skip "no rsync command" && return 0
557         rsync --help | grep -q xattr ||
558                 skip_env "$(rsync --version | head -n1) does not support xattrs"
559         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
560         test_mkdir -p $DIR/$tdir
561         test_mkdir -p $DIR/$tdir.new
562         touch $DIR/$tdir/$tfile
563         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
564         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
565                 error "rsync failed with xattrs enabled"
566 }
567 run_test 17k "symlinks: rsync with xattrs enabled ========================="
568
569 test_17l() { # LU-279
570         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
571                 skip "no getfattr command" && return 0
572         test_mkdir -p $DIR/$tdir
573         touch $DIR/$tdir/$tfile
574         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
575         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
576                 # -h to not follow symlinks. -m '' to list all the xattrs.
577                 # grep to remove first line: '# file: $path'.
578                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
579                 do
580                         lgetxattr_size_check $path $xattr ||
581                                 error "lgetxattr_size_check $path $xattr failed"
582                 done
583         done
584 }
585 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
586
587 # LU-1540
588 test_17m() {
589         local short_sym="0123456789"
590         local WDIR=$DIR/${tdir}m
591         local i
592
593         remote_mds_nodsh && skip "remote MDS with nodsh" && return
594         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
595         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
596                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
597
598         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
599                 skip "ldiskfs only test" && return 0
600
601         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
602
603         test_mkdir -p $WDIR
604         long_sym=$short_sym
605         # create a long symlink file
606         for ((i = 0; i < 4; ++i)); do
607                 long_sym=${long_sym}${long_sym}
608         done
609
610         echo "create 512 short and long symlink files under $WDIR"
611         for ((i = 0; i < 256; ++i)); do
612                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
613                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
614         done
615
616         echo "erase them"
617         rm -f $WDIR/*
618         sync
619         wait_delete_completed
620
621         echo "recreate the 512 symlink files with a shorter string"
622         for ((i = 0; i < 512; ++i)); do
623                 # rewrite the symlink file with a shorter string
624                 ln -sf ${long_sym} $WDIR/long-$i || error "long_sym failed"
625                 ln -sf ${short_sym} $WDIR/short-$i || error "short_sym failed"
626         done
627
628         local mds_index=$(($($LFS getstripe -M $WDIR) + 1))
629         local devname=$(mdsdevname $mds_index)
630
631         echo "stop and checking mds${mds_index}:"
632         # e2fsck should not return error
633         stop mds${mds_index}
634         run_e2fsck $(facet_active_host mds${mds_index}) $devname -n
635         rc=$?
636
637         start mds${mds_index} $devname $MDS_MOUNT_OPTS || error "start failed"
638         df $MOUNT > /dev/null 2>&1
639         [ $rc -eq 0 ] ||
640                 error "e2fsck detected error for short/long symlink: rc=$rc"
641 }
642 run_test 17m "run e2fsck against MDT which contains short/long symlink"
643
644 check_fs_consistency_17n() {
645         local mdt_index
646         local rc=0
647
648         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
649         # so it only check MDT1/MDT2 instead of all of MDTs.
650         for mdt_index in 1 2; do
651                 local devname=$(mdsdevname $mdt_index)
652                 # e2fsck should not return error
653                 stop mds${mdt_index}
654                 run_e2fsck $(facet_active_host mds$mdt_index) $devname -n ||
655                         rc=$((rc + $?))
656
657                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
658                         error "mount mds$mdt_index failed"
659                 df $MOUNT > /dev/null 2>&1
660         done
661         return $rc
662 }
663
664 test_17n() {
665         local i
666
667         remote_mds_nodsh && skip "remote MDS with nodsh" && return
668         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
669         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
670                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
671
672         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
673                 skip "ldiskfs only test" && return 0
674
675         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
676
677         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
678
679         test_mkdir $DIR/$tdir
680         for ((i=0; i<10; i++)); do
681                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
682                         error "create remote dir error $i"
683                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
684                         error "create files under remote dir failed $i"
685         done
686
687         check_fs_consistency_17n ||
688                 error "e2fsck report error after create files under remote dir"
689
690         for ((i = 0; i < 10; i++)); do
691                 rm -rf $DIR/$tdir/remote_dir_${i} ||
692                         error "destroy remote dir error $i"
693         done
694
695         check_fs_consistency_17n ||
696                 error "e2fsck report error after unlink files under remote dir"
697
698         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
699                 skip "lustre < 2.4.50 does not support migrate mv " && return
700
701         for ((i = 0; i < 10; i++)); do
702                 mkdir -p $DIR/$tdir/remote_dir_${i}
703                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
704                         error "create files under remote dir failed $i"
705                 $LFS migrate --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
706                         error "migrate remote dir error $i"
707         done
708         check_fs_consistency_17n || error "e2fsck report error after migration"
709
710         for ((i = 0; i < 10; i++)); do
711                 rm -rf $DIR/$tdir/remote_dir_${i} ||
712                         error "destroy remote dir error $i"
713         done
714
715         check_fs_consistency_17n || error "e2fsck report error after unlink"
716 }
717 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
718
719 test_17o() {
720         remote_mds_nodsh && skip "remote MDS with nodsh" && return
721         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
722                 skip "Need MDS version at least 2.3.64" && return
723
724         local WDIR=$DIR/${tdir}o
725         local mdt_index
726         local rc=0
727
728         test_mkdir -p $WDIR
729         touch $WDIR/$tfile
730         mdt_index=$($LFS getstripe -M $WDIR/$tfile)
731         mdt_index=$((mdt_index+1))
732
733         cancel_lru_locks mdc
734         #fail mds will wait the failover finish then set
735         #following fail_loc to avoid interfer the recovery process.
736         fail mds${mdt_index}
737
738         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
739         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
740         ls -l $WDIR/$tfile && rc=1
741         do_facet mds${mdt_index} lctl set_param fail_loc=0
742         [[ $rc -ne 0 ]] && error "stat file should fail"
743         true
744 }
745 run_test 17o "stat file with incompat LMA feature"
746
747 test_18() {
748         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
749         ls $DIR || error "Failed to ls $DIR: $?"
750 }
751 run_test 18 "touch .../f ; ls ... =============================="
752
753 test_19a() {
754         touch $DIR/$tfile
755         ls -l $DIR
756         rm $DIR/$tfile
757         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
758 }
759 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
760
761 test_19b() {
762         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
763 }
764 run_test 19b "ls -l .../f19 (should return error) =============="
765
766 test_19c() {
767         [ $RUNAS_ID -eq $UID ] &&
768                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
769         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
770 }
771 run_test 19c "$RUNAS touch .../f19 (should return error) =="
772
773 test_19d() {
774         cat $DIR/f19 && error || true
775 }
776 run_test 19d "cat .../f19 (should return error) =============="
777
778 test_20() {
779         touch $DIR/$tfile
780         rm $DIR/$tfile
781         touch $DIR/$tfile
782         rm $DIR/$tfile
783         touch $DIR/$tfile
784         rm $DIR/$tfile
785         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
786 }
787 run_test 20 "touch .../f ; ls -l ... ==========================="
788
789 test_21() {
790         test_mkdir -p $DIR/$tdir
791         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
792         ln -s dangle $DIR/$tdir/link
793         echo foo >> $DIR/$tdir/link
794         cat $DIR/$tdir/dangle
795         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
796         $CHECKSTAT -f -t file $DIR/$tdir/link ||
797                 error "$tdir/link not linked to a file"
798 }
799 run_test 21 "write to dangling link ============================"
800
801 test_22() {
802         WDIR=$DIR/$tdir
803         test_mkdir -p $DIR/$tdir
804         chown $RUNAS_ID:$RUNAS_GID $WDIR
805         (cd $WDIR || error "cd $WDIR failed";
806         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
807         $RUNAS tar xf -)
808         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
809         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
810         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
811 }
812 run_test 22 "unpack tar archive as non-root user ==============="
813
814 # was test_23
815 test_23a() {
816         test_mkdir -p $DIR/$tdir
817         local file=$DIR/$tdir/$tfile
818
819         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
820         openfile -f O_CREAT:O_EXCL $file &&
821                 error "$file recreate succeeded" || true
822 }
823 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
824
825 test_23b() { # bug 18988
826         test_mkdir -p $DIR/$tdir
827         local file=$DIR/$tdir/$tfile
828
829         rm -f $file
830         echo foo > $file || error "write filed"
831         echo bar >> $file || error "append filed"
832         $CHECKSTAT -s 8 $file || error "wrong size"
833         rm $file
834 }
835 run_test 23b "O_APPEND check =========================="
836
837 # LU-11069 file offset is correct after appending writes
838 test_23d() {
839         local file=$DIR/$tfile
840         local offset
841
842         echo CentaurHauls > $file
843         offset=$($MULTIOP $file oO_WRONLY:O_APPEND:w13Zp)
844         if ((offset != 26)); then
845                 error "wrong offset, expected 26, got '$offset'"
846         fi
847 }
848 run_test 23d "file offset is correct after appending writes"
849
850 # rename sanity
851 test_24a() {
852         echo '-- same directory rename'
853         test_mkdir $DIR/$tdir
854         touch $DIR/$tdir/$tfile.1
855         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
856         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
857 }
858 run_test 24a "rename file to non-existent target"
859
860 test_24b() {
861         test_mkdir $DIR/$tdir
862         touch $DIR/$tdir/$tfile.{1,2}
863         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
864         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
865         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
866 }
867 run_test 24b "rename file to existing target"
868
869 test_24c() {
870         test_mkdir $DIR/$tdir
871         test_mkdir $DIR/$tdir/d$testnum.1
872         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
873         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
874         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
875 }
876 run_test 24c "rename directory to non-existent target"
877
878 test_24d() {
879         test_mkdir -c1 $DIR/$tdir
880         test_mkdir -c1 $DIR/$tdir/d$testnum.1
881         test_mkdir -c1 $DIR/$tdir/d$testnum.2
882         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
883         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
884         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
885 }
886 run_test 24d "rename directory to existing target"
887
888 test_24e() {
889         echo '-- cross directory renames --'
890         test_mkdir $DIR/R5a
891         test_mkdir $DIR/R5b
892         touch $DIR/R5a/f
893         mv $DIR/R5a/f $DIR/R5b/g
894         $CHECKSTAT -a $DIR/R5a/f || error
895         $CHECKSTAT -t file $DIR/R5b/g || error
896 }
897 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
898
899 test_24f() {
900         test_mkdir $DIR/R6a
901         test_mkdir $DIR/R6b
902         touch $DIR/R6a/f $DIR/R6b/g
903         mv $DIR/R6a/f $DIR/R6b/g
904         $CHECKSTAT -a $DIR/R6a/f || error
905         $CHECKSTAT -t file $DIR/R6b/g || error
906 }
907 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
908
909 test_24g() {
910         test_mkdir $DIR/R7a
911         test_mkdir $DIR/R7b
912         test_mkdir $DIR/R7a/d
913         mv $DIR/R7a/d $DIR/R7b/e
914         $CHECKSTAT -a $DIR/R7a/d || error
915         $CHECKSTAT -t dir $DIR/R7b/e || error
916 }
917 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
918
919 test_24h() {
920         test_mkdir -c1 $DIR/R8a
921         test_mkdir -c1 $DIR/R8b
922         test_mkdir -c1 $DIR/R8a/d
923         test_mkdir -c1 $DIR/R8b/e
924         mrename $DIR/R8a/d $DIR/R8b/e
925         $CHECKSTAT -a $DIR/R8a/d || error
926         $CHECKSTAT -t dir $DIR/R8b/e || error
927 }
928 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
929
930 test_24i() {
931         echo "-- rename error cases"
932         test_mkdir $DIR/R9
933         test_mkdir $DIR/R9/a
934         touch $DIR/R9/f
935         mrename $DIR/R9/f $DIR/R9/a
936         $CHECKSTAT -t file $DIR/R9/f || error
937         $CHECKSTAT -t dir  $DIR/R9/a || error
938         $CHECKSTAT -a $DIR/R9/a/f || error
939 }
940 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
941
942 test_24j() {
943         test_mkdir $DIR/R10
944         mrename $DIR/R10/f $DIR/R10/g
945         $CHECKSTAT -t dir $DIR/R10 || error
946         $CHECKSTAT -a $DIR/R10/f || error
947         $CHECKSTAT -a $DIR/R10/g || error
948 }
949 run_test 24j "source does not exist ============================"
950
951 test_24k() {
952         test_mkdir $DIR/R11a
953         test_mkdir $DIR/R11a/d
954         touch $DIR/R11a/f
955         mv $DIR/R11a/f $DIR/R11a/d
956         $CHECKSTAT -a $DIR/R11a/f || error
957         $CHECKSTAT -t file $DIR/R11a/d/f || error
958 }
959 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
960
961 # bug 2429 - rename foo foo foo creates invalid file
962 test_24l() {
963         f="$DIR/f24l"
964         $MULTIOP $f OcNs || error
965 }
966 run_test 24l "Renaming a file to itself ========================"
967
968 test_24m() {
969         f="$DIR/f24m"
970         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
971         # on ext3 this does not remove either the source or target files
972         # though the "expected" operation would be to remove the source
973         $CHECKSTAT -t file ${f} || error "${f} missing"
974         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
975 }
976 run_test 24m "Renaming a file to a hard link to itself ========="
977
978 test_24n() {
979     f="$DIR/f24n"
980     # this stats the old file after it was renamed, so it should fail
981     touch ${f}
982     $CHECKSTAT ${f}
983     mv ${f} ${f}.rename
984     $CHECKSTAT ${f}.rename
985     $CHECKSTAT -a ${f}
986 }
987 run_test 24n "Statting the old file after renaming (Posix rename 2)"
988
989 test_24o() {
990         test_mkdir -p $DIR/d24o
991         rename_many -s random -v -n 10 $DIR/d24o
992 }
993 run_test 24o "rename of files during htree split ==============="
994
995 test_24p() {
996         test_mkdir $DIR/R12a
997         test_mkdir $DIR/R12b
998         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
999         mrename $DIR/R12a $DIR/R12b
1000         $CHECKSTAT -a $DIR/R12a || error
1001         $CHECKSTAT -t dir $DIR/R12b || error
1002         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
1003         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
1004 }
1005 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
1006
1007 cleanup_multiop_pause() {
1008         trap 0
1009         kill -USR1 $MULTIPID
1010 }
1011
1012 test_24q() {
1013         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1014         test_mkdir $DIR/R13a
1015         test_mkdir $DIR/R13b
1016         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
1017         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
1018         MULTIPID=$!
1019
1020         trap cleanup_multiop_pause EXIT
1021         mrename $DIR/R13a $DIR/R13b
1022         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
1023         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
1024         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
1025         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
1026         cleanup_multiop_pause
1027         wait $MULTIPID || error "multiop close failed"
1028 }
1029 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
1030
1031 test_24r() { #bug 3789
1032         test_mkdir $DIR/R14a
1033         test_mkdir $DIR/R14a/b
1034         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1035         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1036         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1037 }
1038 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1039
1040 test_24s() {
1041         test_mkdir $DIR/R15a
1042         test_mkdir $DIR/R15a/b
1043         test_mkdir $DIR/R15a/b/c
1044         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1045         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1046         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1047 }
1048 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1049 test_24t() {
1050         test_mkdir $DIR/R16a
1051         test_mkdir $DIR/R16a/b
1052         test_mkdir $DIR/R16a/b/c
1053         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1054         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1055         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1056 }
1057 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1058
1059 test_24u() { # bug12192
1060         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1061         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1062 }
1063 run_test 24u "create stripe file"
1064
1065 page_size() {
1066         local size
1067         size=$(getconf PAGE_SIZE 2>/dev/null)
1068         echo -n ${size:-4096}
1069 }
1070
1071 simple_cleanup_common() {
1072         local rc=0
1073         trap 0
1074         [ -z "$DIR" -o -z "$tdir" ] && return 0
1075
1076         local start=$SECONDS
1077         rm -rf $DIR/$tdir
1078         rc=$?
1079         wait_delete_completed
1080         echo "cleanup time $((SECONDS - start))"
1081         return $rc
1082 }
1083
1084 max_pages_per_rpc() {
1085         local mdtname="$(printf "MDT%04x" ${1:-0})"
1086         $LCTL get_param -n mdc.*$mdtname*.max_pages_per_rpc
1087 }
1088
1089 test_24v() {
1090         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1091         local nrfiles=${COUNT:-100000}
1092         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1093         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && nrfiles=${COUNT:-10000}
1094
1095         local fname="$DIR/$tdir/$tfile"
1096         test_mkdir "$(dirname $fname)"
1097         # assume MDT0000 has the fewest inodes
1098         local stripes=$($LFS getdirstripe -c $(dirname $fname))
1099         local free_inodes=$(($(mdt_free_inodes 0) * stripes))
1100         [[ $free_inodes -lt $nrfiles ]] && nrfiles=$free_inodes
1101
1102         trap simple_cleanup_common EXIT
1103
1104         createmany -m "$fname" $nrfiles
1105
1106         cancel_lru_locks mdc
1107         lctl set_param mdc.*.stats clear
1108
1109         # was previously test_24D: LU-6101
1110         # readdir() returns correct number of entries after cursor reload
1111         local num_ls=$(ls $DIR/$tdir | wc -l)
1112         local num_uniq=$(ls $DIR/$tdir | sort -u | wc -l)
1113         local num_all=$(ls -a $DIR/$tdir | wc -l)
1114         if [ $num_ls -ne $nrfiles -o $num_uniq -ne $nrfiles -o \
1115              $num_all -ne $((nrfiles + 2)) ]; then
1116                 error "Expected $nrfiles files, got $num_ls " \
1117                         "($num_uniq unique $num_all .&..)"
1118         fi
1119         # LU-5 large readdir
1120         # dirent_size = 32 bytes for sizeof(struct lu_dirent) +
1121         #               N bytes for name (len($nrfiles) rounded to 8 bytes) +
1122         #               8 bytes for luda_type (4 bytes rounded to 8 bytes)
1123         # take into account of overhead in lu_dirpage header and end mark in
1124         # each page, plus one in rpc_num calculation.
1125         local dirent_size=$((32 + (${#tfile} | 7) + 1 + 8))
1126         local page_entries=$((($(page_size) - 24) / dirent_size))
1127         local mdt_idx=$($LFS getdirstripe -i $(dirname $fname))
1128         local rpc_pages=$(max_pages_per_rpc $mdt_idx)
1129         local rpc_max=$((nrfiles / (page_entries * rpc_pages) + stripes))
1130         local mds_readpage=$(calc_stats mdc.*.stats mds_readpage)
1131         echo "readpages: $mds_readpage rpc_max: $rpc_max"
1132         (( $mds_readpage < $rpc_max - 2 || $mds_readpage > $rpc_max + 1)) &&
1133                 error "large readdir doesn't take effect: " \
1134                       "$mds_readpage should be about $rpc_max"
1135
1136         simple_cleanup_common
1137 }
1138 run_test 24v "list large directory (test hash collision, b=17560)"
1139
1140 test_24w() { # bug21506
1141         SZ1=234852
1142         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1143         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1144         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1145         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1146         [[ "$SZ1" -eq "$SZ2" ]] ||
1147                 error "Error reading at the end of the file $tfile"
1148 }
1149 run_test 24w "Reading a file larger than 4Gb"
1150
1151 test_24x() {
1152         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1153
1154         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1155                 skip "Need MDS version at least 2.7.56" && return
1156
1157         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1158         local MDTIDX=1
1159         local remote_dir=$DIR/$tdir/remote_dir
1160
1161         test_mkdir -p $DIR/$tdir
1162         $LFS mkdir -i $MDTIDX $remote_dir ||
1163                 error "create remote directory failed"
1164
1165         test_mkdir -p $DIR/$tdir/src_dir
1166         touch $DIR/$tdir/src_file
1167         test_mkdir -p $remote_dir/tgt_dir
1168         touch $remote_dir/tgt_file
1169
1170         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir ||
1171                 error "rename dir cross MDT failed!"
1172
1173         mrename $DIR/$tdir/src_file $remote_dir/tgt_file ||
1174                 error "rename file cross MDT failed!"
1175
1176         touch $DIR/$tdir/ln_file
1177         ln $DIR/$tdir/ln_file $remote_dir/ln_name ||
1178                 error "ln file cross MDT failed"
1179
1180         rm -rf $DIR/$tdir || error "Can not delete directories"
1181 }
1182 run_test 24x "cross MDT rename/link"
1183
1184 test_24y() {
1185         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1186         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1187         local MDTIDX=1
1188         local remote_dir=$DIR/$tdir/remote_dir
1189
1190         test_mkdir -p $DIR/$tdir
1191         $LFS mkdir -i $MDTIDX $remote_dir ||
1192                    error "create remote directory failed"
1193
1194         test_mkdir -p $remote_dir/src_dir
1195         touch $remote_dir/src_file
1196         test_mkdir -p $remote_dir/tgt_dir
1197         touch $remote_dir/tgt_file
1198
1199         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1200                 error "rename subdir in the same remote dir failed!"
1201
1202         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1203                 error "rename files in the same remote dir failed!"
1204
1205         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1206                 error "link files in the same remote dir failed!"
1207
1208         rm -rf $DIR/$tdir || error "Can not delete directories"
1209 }
1210 run_test 24y "rename/link on the same dir should succeed"
1211
1212 test_24A() { # LU-3182
1213         local NFILES=5000
1214
1215         rm -rf $DIR/$tdir
1216         test_mkdir -p $DIR/$tdir
1217         trap simple_cleanup_common EXIT
1218         createmany -m $DIR/$tdir/$tfile $NFILES
1219         local t=$(ls $DIR/$tdir | wc -l)
1220         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1221         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1222         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1223                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1224         fi
1225
1226         simple_cleanup_common || error "Can not delete directories"
1227 }
1228 run_test 24A "readdir() returns correct number of entries."
1229
1230 test_24B() { # LU-4805
1231         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1232         local count
1233
1234         test_mkdir $DIR/$tdir
1235         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1236                 error "create striped dir failed"
1237
1238         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1239         [ $count -eq 2 ] || error "Expected 2, got $count"
1240
1241         touch $DIR/$tdir/striped_dir/a
1242
1243         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1244         [ $count -eq 3 ] || error "Expected 3, got $count"
1245
1246         touch $DIR/$tdir/striped_dir/.f
1247
1248         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1249         [ $count -eq 4 ] || error "Expected 4, got $count"
1250
1251         rm -rf $DIR/$tdir || error "Can not delete directories"
1252 }
1253 run_test 24B "readdir for striped dir return correct number of entries"
1254
1255 test_24C() {
1256         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1257
1258         mkdir $DIR/$tdir
1259         mkdir $DIR/$tdir/d0
1260         mkdir $DIR/$tdir/d1
1261
1262         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1263                 error "create striped dir failed"
1264
1265         cd $DIR/$tdir/d0/striped_dir
1266
1267         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1268         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1269         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1270
1271         [ "$d0_ino" = "$parent_ino" ] ||
1272                 error ".. wrong, expect $d0_ino, get $parent_ino"
1273
1274         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1275                 error "mv striped dir failed"
1276
1277         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1278
1279         [ "$d1_ino" = "$parent_ino" ] ||
1280                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1281 }
1282 run_test 24C "check .. in striped dir"
1283
1284 test_24E() {
1285         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
1286         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1287
1288         mkdir -p $DIR/$tdir
1289         mkdir $DIR/$tdir/src_dir
1290         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
1291                 error "create remote source failed"
1292
1293         touch $DIR/$tdir/src_dir/src_child/a
1294
1295         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
1296                 error "create remote target dir failed"
1297
1298         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
1299                 error "create remote target child failed"
1300
1301         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
1302                 error "rename dir cross MDT failed!"
1303
1304         find $DIR/$tdir
1305
1306         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
1307                 error "src_child still exists after rename"
1308
1309         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
1310                 error "missing file(a) after rename"
1311
1312         rm -rf $DIR/$tdir || error "Can not delete directories"
1313 }
1314 run_test 24E "cross MDT rename/link"
1315
1316 test_25a() {
1317         echo '== symlink sanity ============================================='
1318
1319         test_mkdir $DIR/d25
1320         ln -s d25 $DIR/s25
1321         touch $DIR/s25/foo || error
1322 }
1323 run_test 25a "create file in symlinked directory ==============="
1324
1325 test_25b() {
1326         [ ! -d $DIR/d25 ] && test_25a
1327         $CHECKSTAT -t file $DIR/s25/foo || error
1328 }
1329 run_test 25b "lookup file in symlinked directory ==============="
1330
1331 test_26a() {
1332         test_mkdir $DIR/d26
1333         test_mkdir $DIR/d26/d26-2
1334         ln -s d26/d26-2 $DIR/s26
1335         touch $DIR/s26/foo || error
1336 }
1337 run_test 26a "multiple component symlink ======================="
1338
1339 test_26b() {
1340         test_mkdir -p $DIR/d26b/d26-2
1341         ln -s d26b/d26-2/foo $DIR/s26-2
1342         touch $DIR/s26-2 || error
1343 }
1344 run_test 26b "multiple component symlink at end of lookup ======"
1345
1346 test_26c() {
1347         test_mkdir $DIR/d26.2
1348         touch $DIR/d26.2/foo
1349         ln -s d26.2 $DIR/s26.2-1
1350         ln -s s26.2-1 $DIR/s26.2-2
1351         ln -s s26.2-2 $DIR/s26.2-3
1352         chmod 0666 $DIR/s26.2-3/foo
1353 }
1354 run_test 26c "chain of symlinks ================================"
1355
1356 # recursive symlinks (bug 439)
1357 test_26d() {
1358         ln -s d26-3/foo $DIR/d26-3
1359 }
1360 run_test 26d "create multiple component recursive symlink ======"
1361
1362 test_26e() {
1363         [ ! -h $DIR/d26-3 ] && test_26d
1364         rm $DIR/d26-3
1365 }
1366 run_test 26e "unlink multiple component recursive symlink ======"
1367
1368 # recursive symlinks (bug 7022)
1369 test_26f() {
1370         test_mkdir -p $DIR/$tdir
1371         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1372         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1373         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1374         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1375         cd $tfile                || error "cd $tfile failed"
1376         ln -s .. dotdot          || error "ln dotdot failed"
1377         ln -s dotdot/lndir lndir || error "ln lndir failed"
1378         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1379         output=`ls $tfile/$tfile/lndir/bar1`
1380         [ "$output" = bar1 ] && error "unexpected output"
1381         rm -r $tfile             || error "rm $tfile failed"
1382         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1383 }
1384 run_test 26f "rm -r of a directory which has recursive symlink"
1385
1386 test_27a() {
1387         test_mkdir -p $DIR/d27 || error "mkdir failed"
1388         $LFS getstripe $DIR/d27
1389         $LFS setstripe -c 1 $DIR/d27/f0 || error "setstripe failed"
1390         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1391         cp /etc/hosts $DIR/d27/f0 || error
1392 }
1393 run_test 27a "one stripe file"
1394
1395 test_27b() {
1396         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1397         test_mkdir -p $DIR/d27
1398         $LFS setstripe -c 2 $DIR/d27/f01 || error "setstripe failed"
1399         $LFS getstripe -c $DIR/d27/f01
1400         [ $($LFS getstripe -c $DIR/d27/f01) -eq 2 ] ||
1401                 error "two-stripe file doesn't have two stripes"
1402
1403         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1404 }
1405 run_test 27b "create and write to two stripe file"
1406
1407 test_27d() {
1408         test_mkdir -p $DIR/d27
1409         $LFS setstripe -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1410         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1411         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1412 }
1413 run_test 27d "create file with default settings"
1414
1415 test_27e() {
1416         # LU-5839 adds check for existed layout before setting it
1417         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1418                 skip "Need MDS version at least 2.7.56" && return
1419         test_mkdir -p $DIR/d27
1420         $LFS setstripe -c 2 $DIR/d27/f12 || error "setstripe failed"
1421         $LFS setstripe -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1422         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1423 }
1424 run_test 27e "setstripe existing file (should return error)"
1425
1426 test_27f() {
1427         test_mkdir $DIR/$tdir
1428         $LFS setstripe -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1429                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1430         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1431                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1432         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1433         $LFS getstripe $DIR/$tdir/$tfile || error "$LFS getstripe failed"
1434 }
1435 run_test 27f "setstripe with bad stripe size (should return error)"
1436
1437 test_27g() {
1438         test_mkdir -p $DIR/d27
1439         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1440         $LFS getstripe $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1441                 error "$DIR/d27/fnone has object"
1442 }
1443 run_test 27g "$LFS getstripe with no objects"
1444
1445 test_27i() {
1446         test_mkdir $DIR/$tdir
1447         touch $DIR/$tdir/$tfile || error "touch failed"
1448         [[ $($LFS getstripe -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1449                 error "missing objects"
1450 }
1451 run_test 27i "$LFS getstripe with some objects"
1452
1453 test_27j() {
1454         test_mkdir -p $DIR/d27
1455         $LFS setstripe -i $OSTCOUNT $DIR/d27/f27j &&
1456                 error "setstripe failed" || true
1457 }
1458 run_test 27j "setstripe with bad stripe offset (should return error)"
1459
1460 test_27k() { # bug 2844
1461         test_mkdir -p $DIR/d27
1462         FILE=$DIR/d27/f27k
1463         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1464         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1465         $LFS setstripe -S 67108864 $FILE || error "setstripe failed"
1466         BLKSIZE=$(stat $FILE | awk '/IO Block:/ { print $7 }')
1467         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1468         dd if=/dev/zero of=$FILE bs=4k count=1
1469         BLKSIZE=$(stat $FILE | awk '/IO Block:/ { print $7 }')
1470         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1471 }
1472 run_test 27k "limit i_blksize for broken user apps"
1473
1474 test_27l() {
1475         test_mkdir -p $DIR/d27
1476         mcreate $DIR/f27l || error "creating file"
1477         $RUNAS $SETSTRIPE -c 1 $DIR/f27l &&
1478                 error "setstripe should have failed" || true
1479 }
1480 run_test 27l "check setstripe permissions (should return error)"
1481
1482 test_27m() {
1483         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1484
1485         ORIGFREE=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
1486                    head -n1)
1487         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1488                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1489                 return
1490         fi
1491         trap simple_cleanup_common EXIT
1492         test_mkdir -p $DIR/$tdir
1493         $LFS setstripe -i 0 -c 1 $DIR/$tdir/f27m_1
1494         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1495                 error "dd should fill OST0"
1496         i=2
1497         while $LFS setstripe -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1498                 i=$((i + 1))
1499                 [ $i -gt 256 ] && break
1500         done
1501         i=$((i + 1))
1502         touch $DIR/$tdir/f27m_$i
1503         [ $($LFS getstripe $DIR/$tdir/f27m_$i | grep -A 10 obdidx |
1504             awk '{print $1}' | grep -w "0") ] &&
1505                 error "OST0 was full but new created file still use it"
1506         i=$((i + 1))
1507         touch $DIR/$tdir/f27m_$i
1508         [ $($LFS getstripe $DIR/$tdir/f27m_$i | grep -A 10 obdidx |
1509             awk '{print $1}'| grep -w "0") ] &&
1510                 error "OST0 was full but new created file still use it"
1511         simple_cleanup_common
1512 }
1513 run_test 27m "create file while OST0 was full"
1514
1515 sleep_maxage() {
1516         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage |
1517                       head -n 1 | awk '{print $1 * 2}')
1518         sleep $DELAY
1519 }
1520
1521 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1522 # if the OST isn't full anymore.
1523 reset_enospc() {
1524         local OSTIDX=${1:-""}
1525
1526         local list=$(comma_list $(osts_nodes))
1527         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1528
1529         do_nodes $list lctl set_param fail_loc=0
1530         sync    # initiate all OST_DESTROYs from MDS to OST
1531         sleep_maxage
1532 }
1533
1534 exhaust_precreations() {
1535         local OSTIDX=$1
1536         local FAILLOC=$2
1537         local FAILIDX=${3:-$OSTIDX}
1538         local ofacet=ost$((OSTIDX + 1))
1539
1540         test_mkdir -p -c1 $DIR/$tdir
1541         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
1542         local mfacet=mds$((mdtidx + 1))
1543         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1544
1545         local OST=$(ostname_from_index $OSTIDX)
1546
1547         # on the mdt's osc
1548         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1549         local last_id=$(do_facet $mfacet lctl get_param -n \
1550                         osc.$mdtosc_proc1.prealloc_last_id)
1551         local next_id=$(do_facet $mfacet lctl get_param -n \
1552                         osc.$mdtosc_proc1.prealloc_next_id)
1553
1554         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1555         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1556
1557         test_mkdir -p $DIR/$tdir/${OST}
1558         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1559 #define OBD_FAIL_OST_ENOSPC              0x215
1560         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1561         echo "Creating to objid $last_id on ost $OST..."
1562         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1563         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1564         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1565         sleep_maxage
1566 }
1567
1568 exhaust_all_precreations() {
1569         local i
1570         for (( i=0; i < OSTCOUNT; i++ )) ; do
1571                 exhaust_precreations $i $1 -1
1572         done
1573 }
1574
1575 test_27n() {
1576         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1577         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1578         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1579         remote_ost_nodsh && skip "remote OST with nodsh" && return
1580
1581         reset_enospc
1582         rm -f $DIR/$tdir/$tfile
1583         exhaust_precreations 0 0x80000215
1584         $LFS setstripe -c -1 $DIR/$tdir
1585         touch $DIR/$tdir/$tfile || error
1586         $LFS getstripe $DIR/$tdir/$tfile
1587         reset_enospc
1588 }
1589 run_test 27n "create file with some full OSTs"
1590
1591 test_27o() {
1592         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1593         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1594         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1595         remote_ost_nodsh && skip "remote OST with nodsh" && return
1596
1597         reset_enospc
1598         rm -f $DIR/$tdir/$tfile
1599         exhaust_all_precreations 0x215
1600
1601         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1602
1603         reset_enospc
1604         rm -rf $DIR/$tdir/*
1605 }
1606 run_test 27o "create file with all full OSTs (should error)"
1607
1608 test_27p() {
1609         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1610         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1611         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1612         remote_ost_nodsh && skip "remote OST with nodsh" && return
1613
1614         reset_enospc
1615         rm -f $DIR/$tdir/$tfile
1616         test_mkdir -p $DIR/$tdir
1617
1618         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1619         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1620         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1621
1622         exhaust_precreations 0 0x80000215
1623         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1624         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1625         $LFS getstripe $DIR/$tdir/$tfile
1626
1627         reset_enospc
1628 }
1629 run_test 27p "append to a truncated file with some full OSTs"
1630
1631 test_27q() {
1632         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1633         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1634         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1635         remote_ost_nodsh && skip "remote OST with nodsh" && return
1636
1637         reset_enospc
1638         rm -f $DIR/$tdir/$tfile
1639
1640         test_mkdir -p $DIR/$tdir
1641         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1642         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||
1643                 error "truncate $DIR/$tdir/$tfile failed"
1644         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1645
1646         exhaust_all_precreations 0x215
1647
1648         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1649         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1650
1651         reset_enospc
1652 }
1653 run_test 27q "append to truncated file with all OSTs full (should error)"
1654
1655 test_27r() {
1656         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1657         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1658         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1659         remote_ost_nodsh && skip "remote OST with nodsh" && return
1660
1661         reset_enospc
1662         rm -f $DIR/$tdir/$tfile
1663         exhaust_precreations 0 0x80000215
1664
1665         $LFS setstripe -i 0 -c 2 $DIR/$tdir/$tfile # && error
1666
1667         reset_enospc
1668 }
1669 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1670
1671 test_27s() { # bug 10725
1672         test_mkdir -p $DIR/$tdir
1673         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1674         local stripe_count=0
1675         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1676         $LFS setstripe -S $stripe_size -c $stripe_count $DIR/$tdir &&
1677                 error "stripe width >= 2^32 succeeded" || true
1678
1679 }
1680 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1681
1682 test_27t() { # bug 10864
1683         WDIR=$(pwd)
1684         WLFS=$(which lfs)
1685         cd $DIR
1686         touch $tfile
1687         $WLFS getstripe $tfile
1688         cd $WDIR
1689 }
1690 run_test 27t "check that utils parse path correctly"
1691
1692 test_27u() { # bug 4900
1693         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1694         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1695         local index
1696         local list=$(comma_list $(mdts_nodes))
1697
1698 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1699         do_nodes $list $LCTL set_param fail_loc=0x139
1700         test_mkdir -p $DIR/$tdir
1701         trap simple_cleanup_common EXIT
1702         createmany -o $DIR/$tdir/t- 1000
1703         do_nodes $list $LCTL set_param fail_loc=0
1704
1705         TLOG=$TMP/$tfile.getstripe
1706         $LFS getstripe $DIR/$tdir > $TLOG
1707         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1708         unlinkmany $DIR/$tdir/t- 1000
1709         trap 0
1710         [[ $OBJS -gt 0 ]] &&
1711                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1712 }
1713 run_test 27u "skip object creation on OSC w/o objects"
1714
1715 test_27v() { # bug 4900
1716         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1717         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1718         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1719         remote_ost_nodsh && skip "remote OST with nodsh" && return
1720
1721         exhaust_all_precreations 0x215
1722         reset_enospc
1723
1724         test_mkdir $DIR/$tdir
1725         $LFS setstripe -c 1 $DIR/$tdir         # 1 stripe / file
1726
1727         touch $DIR/$tdir/$tfile
1728         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1729         # all except ost1
1730         for (( i=1; i < OSTCOUNT; i++ )); do
1731                 do_facet ost$i lctl set_param fail_loc=0x705
1732         done
1733         local START=`date +%s`
1734         createmany -o $DIR/$tdir/$tfile 32
1735
1736         local FINISH=`date +%s`
1737         local TIMEOUT=`lctl get_param -n timeout`
1738         local PROCESS=$((FINISH - START))
1739         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1740                error "$FINISH - $START >= $TIMEOUT / 2"
1741         sleep $((TIMEOUT / 2 - PROCESS))
1742         reset_enospc
1743 }
1744 run_test 27v "skip object creation on slow OST"
1745
1746 test_27w() { # bug 10997
1747         test_mkdir $DIR/$tdir || error "mkdir failed"
1748         $LFS setstripe -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1749         [ $($LFS getstripe -S $DIR/$tdir/f0) -ne 65536 ] &&
1750                 error "stripe size $size != 65536" || true
1751         [ $($LFS getstripe -d $DIR/$tdir | grep -c "stripe_count") -eq 0 ] &&
1752                 error "$LFS getstripe -d $DIR/$tdir no 'stripe_count'" || true
1753 }
1754 run_test 27w "check $LFS setstripe -S and getstrip -d options"
1755
1756 test_27wa() {
1757         [[ $OSTCOUNT -lt 2 ]] &&
1758                 skip_env "skipping multiple stripe count/offset test" && return
1759
1760         test_mkdir $DIR/$tdir || error "mkdir failed"
1761         for i in $(seq 1 $OSTCOUNT); do
1762                 offset=$((i - 1))
1763                 $LFS setstripe -c $i -i $offset $DIR/$tdir/f$i ||
1764                         error "setstripe -c $i -i $offset failed"
1765                 count=$($LFS getstripe -c $DIR/$tdir/f$i)
1766                 index=$($LFS getstripe -i $DIR/$tdir/f$i)
1767                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1768                 [ $index -ne $offset ] &&
1769                         error "stripe offset $index != $offset" || true
1770         done
1771 }
1772 run_test 27wa "check $LFS setstripe -c -i options"
1773
1774 test_27x() {
1775         remote_ost_nodsh && skip "remote OST with nodsh" && return
1776         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1777         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1778         OFFSET=$(($OSTCOUNT - 1))
1779         OSTIDX=0
1780         local OST=$(ostname_from_index $OSTIDX)
1781
1782         test_mkdir -p $DIR/$tdir
1783         $LFS setstripe -c 1 $DIR/$tdir  # 1 stripe per file
1784         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1785         sleep_maxage
1786         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1787         for i in $(seq 0 $OFFSET); do
1788                 [ $($LFS getstripe $DIR/$tdir/$tfile$i | grep -A 10 obdidx |
1789                         awk '{print $1}' | grep -w "$OSTIDX") ] &&
1790                 error "OST0 was degraded but new created file still use it"
1791         done
1792         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1793 }
1794 run_test 27x "create files while OST0 is degraded"
1795
1796 test_27y() {
1797         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
1798         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1799         remote_ost_nodsh && skip "remote OST with nodsh" && return
1800         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1801
1802         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1803         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1804                 osc.$mdtosc.prealloc_last_id)
1805         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1806                 osc.$mdtosc.prealloc_next_id)
1807         local fcount=$((last_id - next_id))
1808         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1809         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1810
1811         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1812                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1813         local OST_DEACTIVE_IDX=-1
1814         local OSC
1815         local OSTIDX
1816         local OST
1817
1818         for OSC in $MDS_OSCS; do
1819                 OST=$(osc_to_ost $OSC)
1820                 OSTIDX=$(index_from_ostuuid $OST)
1821                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1822                         OST_DEACTIVE_IDX=$OSTIDX
1823                 fi
1824                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1825                         echo $OSC "is Deactivated:"
1826                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1827                 fi
1828         done
1829
1830         OSTIDX=$(index_from_ostuuid $OST)
1831         test_mkdir -p $DIR/$tdir
1832         $LFS setstripe -c 1 $DIR/$tdir      # 1 stripe / file
1833
1834         for OSC in $MDS_OSCS; do
1835                 OST=$(osc_to_ost $OSC)
1836                 OSTIDX=$(index_from_ostuuid $OST)
1837                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1838                         echo $OST "is degraded:"
1839                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1840                                                 obdfilter.$OST.degraded=1
1841                 fi
1842         done
1843
1844         sleep_maxage
1845         createmany -o $DIR/$tdir/$tfile $fcount
1846
1847         for OSC in $MDS_OSCS; do
1848                 OST=$(osc_to_ost $OSC)
1849                 OSTIDX=$(index_from_ostuuid $OST)
1850                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1851                         echo $OST "is recovered from degraded:"
1852                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1853                                                 obdfilter.$OST.degraded=0
1854                 else
1855                         do_facet $SINGLEMDS lctl --device %$OSC activate
1856                 fi
1857         done
1858
1859         # all osp devices get activated, hence -1 stripe count restored
1860         local stripe_count=0
1861
1862         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1863         # devices get activated.
1864         sleep_maxage
1865         $LFS setstripe -c -1 $DIR/$tfile
1866         stripe_count=$($LFS getstripe -c $DIR/$tfile)
1867         rm -f $DIR/$tfile
1868         [ $stripe_count -ne $OSTCOUNT ] &&
1869                 error "Of $OSTCOUNT OSTs, only $stripe_count is available"
1870         return 0
1871 }
1872 run_test 27y "create files while OST0 is degraded and the rest inactive"
1873
1874 check_seq_oid()
1875 {
1876         log "check file $1"
1877
1878         lmm_count=$($GETSTRIPE -c $1)
1879         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1880         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1881
1882         local old_ifs="$IFS"
1883         IFS=$'[:]'
1884         fid=($($LFS path2fid $1))
1885         IFS="$old_ifs"
1886
1887         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1888         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1889
1890         # compare lmm_seq and lu_fid->f_seq
1891         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1892         # compare lmm_object_id and lu_fid->oid
1893         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1894
1895         # check the trusted.fid attribute of the OST objects of the file
1896         local have_obdidx=false
1897         local stripe_nr=0
1898         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1899                 # skip lines up to and including "obdidx"
1900                 [ -z "$obdidx" ] && break
1901                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1902                 $have_obdidx || continue
1903
1904                 local ost=$((obdidx + 1))
1905                 local dev=$(ostdevname $ost)
1906                 local oid_hex
1907
1908                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1909
1910                 seq=$(echo $seq | sed -e "s/^0x//g")
1911                 if [ $seq == 0 ] || [ $(facet_fstype ost$ost) == zfs ]; then
1912                         oid_hex=$(echo $oid)
1913                 else
1914                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1915                 fi
1916                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1917
1918                 local ff=""
1919                 #
1920                 # Don't unmount/remount the OSTs if we don't need to do that.
1921                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1922                 # update too, until that use mount/ll_decode_filter_fid/mount.
1923                 # Re-enable when debugfs will understand new filter_fid.
1924                 #
1925                 if [ $(facet_fstype ost$ost) == ldiskfs ]; then
1926                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1927                                 $dev 2>/dev/null" | grep "parent=")
1928                 fi
1929                 if [ -z "$ff" ]; then
1930                         stop ost$ost
1931                         mount_fstype ost$ost
1932                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1933                                 $(facet_mntpt ost$ost)/$obj_file)
1934                         unmount_fstype ost$ost
1935                         start ost$ost $dev $OST_MOUNT_OPTS
1936                         clients_up
1937                 fi
1938
1939                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1940
1941                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1942
1943                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1944                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1945                 #
1946                 # fid: parent=[0x200000400:0x1e:0x0] stripe=1 stripe_count=2 \
1947                 #       stripe_size=1048576 component_id=1 component_start=0 \
1948                 #       component_end=33554432
1949                 local ff_parent=$(sed -e 's/.*parent=.//' <<<$ff)
1950                 local ff_pseq=$(cut -d: -f1 <<<$ff_parent)
1951                 local ff_poid=$(cut -d: -f2 <<<$ff_parent)
1952                 local ff_pstripe
1953                 if grep -q 'stripe=' <<<$ff; then
1954                         ff_pstripe=$(sed -e 's/.*stripe=//' -e 's/ .*//' <<<$ff)
1955                 else
1956                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1957                         # into f_ver in this case.  See comment on ff_parent.
1958                         ff_pstripe=$(cut -d: -f3 <<<$ff_parent | sed -e 's/]//')
1959                 fi
1960
1961                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1962                 [ $ff_pseq = $lmm_seq ] ||
1963                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1964                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1965                 [ $ff_poid = $lmm_oid ] ||
1966                         error "FF parent OID $ff_poid != $lmm_oid"
1967                 (($ff_pstripe == $stripe_nr)) ||
1968                         error "FF stripe $ff_pstripe != $stripe_nr"
1969
1970                 stripe_nr=$((stripe_nr + 1))
1971                 [ $(lustre_version_code client) -lt $(version_code 2.9.55) ] &&
1972                         continue
1973                 if grep -q 'stripe_count=' <<<$ff; then
1974                         local ff_scnt=$(sed -e 's/.*stripe_count=//' \
1975                                             -e 's/ .*//' <<<$ff)
1976                         [ $lmm_count = $ff_scnt ] ||
1977                                 error "FF stripe count $lmm_count != $ff_scnt"
1978                 fi
1979         done
1980 }
1981
1982 test_27z() {
1983         remote_ost_nodsh && skip "remote OST with nodsh" && return
1984         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1985         test_mkdir -p $DIR/$tdir
1986
1987         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1988                 { error "setstripe -c -1 failed"; return 1; }
1989         # We need to send a write to every object to get parent FID info set.
1990         # This _should_ also work for setattr, but does not currently.
1991         # touch $DIR/$tdir/$tfile-1 ||
1992         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1993                 { error "dd $tfile-1 failed"; return 2; }
1994         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1995                 { error "setstripe -c -1 failed"; return 3; }
1996         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1997                 { error "dd $tfile-2 failed"; return 4; }
1998
1999         # make sure write RPCs have been sent to OSTs
2000         sync; sleep 5; sync
2001
2002         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
2003         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
2004 }
2005 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
2006
2007 test_27A() { # b=19102
2008         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2009         local restore_size=$($GETSTRIPE -S $MOUNT)
2010         local restore_count=$($GETSTRIPE -c $MOUNT)
2011         local restore_offset=$($GETSTRIPE -i $MOUNT)
2012         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
2013         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
2014                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
2015         local default_size=$($GETSTRIPE -S $MOUNT)
2016         local default_offset=$($GETSTRIPE -i $MOUNT)
2017         local dsize=$((1024 * 1024))
2018         [ $default_size -eq $dsize ] ||
2019                 error "stripe size $default_size != $dsize"
2020         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
2021         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
2022 }
2023 run_test 27A "check filesystem-wide default LOV EA values"
2024
2025 test_27B() { # LU-2523
2026         test_mkdir -p $DIR/$tdir
2027         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
2028         touch $DIR/$tdir/f0
2029         # open f1 with O_LOV_DELAY_CREATE
2030         # rename f0 onto f1
2031         # call setstripe ioctl on open file descriptor for f1
2032         # close
2033         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
2034                 $DIR/$tdir/f0
2035
2036         rm -f $DIR/$tdir/f1
2037         # open f1 with O_LOV_DELAY_CREATE
2038         # unlink f1
2039         # call setstripe ioctl on open file descriptor for f1
2040         # close
2041         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
2042
2043         # Allow multiop to fail in imitation of NFS's busted semantics.
2044         true
2045 }
2046 run_test 27B "call setstripe on open unlinked file/rename victim"
2047
2048 test_27C() { #LU-2871
2049         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
2050
2051         declare -a ost_idx
2052         local index
2053         local found
2054         local i
2055         local j
2056
2057         test_mkdir -p $DIR/$tdir
2058         cd $DIR/$tdir
2059         for i in $(seq 0 $((OSTCOUNT - 1))); do
2060                 # set stripe across all OSTs starting from OST$i
2061                 $SETSTRIPE -i $i -c -1 $tfile$i
2062                 # get striping information
2063                 ost_idx=($($GETSTRIPE $tfile$i |
2064                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
2065                 echo ${ost_idx[@]}
2066
2067                 # check the layout
2068                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
2069                         error "${#ost_idx[@]} != $OSTCOUNT"
2070
2071                 for index in $(seq 0 $((OSTCOUNT - 1))); do
2072                         found=0
2073                         for j in $(echo ${ost_idx[@]}); do
2074                                 if [ $index -eq $j ]; then
2075                                         found=1
2076                                         break
2077                                 fi
2078                         done
2079                         [ $found = 1 ] ||
2080                                 error "Can not find $index in ${ost_idx[@]}"
2081                 done
2082         done
2083 }
2084 run_test 27C "check full striping across all OSTs"
2085
2086 test_27D() {
2087         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2088         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
2089         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2090         local POOL=${POOL:-testpool}
2091         local first_ost=0
2092         local last_ost=$(($OSTCOUNT - 1))
2093         local ost_step=1
2094         local ost_list=$(seq $first_ost $ost_step $last_ost)
2095         local ost_range="$first_ost $last_ost $ost_step"
2096
2097         if ! combined_mgs_mds ; then
2098                 mount_mgs_client
2099         fi
2100
2101         test_mkdir -p $DIR/$tdir
2102         pool_add $POOL || error "pool_add failed"
2103         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2104
2105         local skip27D
2106         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ] &&
2107                 skip27D+="-s 29"
2108         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.55) -o \
2109           $(lustre_version_code client) -lt $(version_code 2.9.55) ] &&
2110                 skip27D+=" -s 30,31"
2111         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT $skip27D ||
2112                 error "llapi_layout_test failed"
2113
2114         destroy_test_pools || error "destroy test pools failed"
2115
2116         if ! combined_mgs_mds ; then
2117                 umount_mgs_client
2118         fi
2119 }
2120 run_test 27D "validate llapi_layout API"
2121
2122 # Verify that default_easize is increased from its initial value after
2123 # accessing a widely striped file.
2124 test_27E() {
2125         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2126         [ $(lustre_version_code client) -lt $(version_code 2.5.57) ] &&
2127                 skip "client does not have LU-3338 fix" && return
2128
2129         # 72 bytes is the minimum space required to store striping
2130         # information for a file striped across one OST:
2131         # (sizeof(struct lov_user_md_v3) +
2132         #  sizeof(struct lov_user_ost_data_v1))
2133         local min_easize=72
2134         $LCTL set_param -n llite.*.default_easize $min_easize ||
2135                 error "lctl set_param failed"
2136         local easize=$($LCTL get_param -n llite.*.default_easize)
2137
2138         [ $easize -eq $min_easize ] ||
2139                 error "failed to set default_easize"
2140
2141         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2142                 error "setstripe failed"
2143         cat $DIR/$tfile
2144         rm $DIR/$tfile
2145
2146         easize=$($LCTL get_param -n llite.*.default_easize)
2147
2148         [ $easize -gt $min_easize ] ||
2149                 error "default_easize not updated"
2150 }
2151 run_test 27E "check that default extended attribute size properly increases"
2152
2153 test_27F() { # LU-5346/LU-7975
2154         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
2155         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2156         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.51) ]] &&
2157                 skip "Need MDS version at least 2.8.51" && return
2158         remote_ost_nodsh && skip "remote OST with nodsh" && return
2159
2160         test_mkdir -p $DIR/$tdir
2161         rm -f $DIR/$tdir/f0
2162         $SETSTRIPE -c 2 $DIR/$tdir
2163
2164         # stop all OSTs to reproduce situation for LU-7975 ticket
2165         for num in $(seq $OSTCOUNT); do
2166                 stop ost$num
2167         done
2168
2169         # open/create f0 with O_LOV_DELAY_CREATE
2170         # truncate f0 to a non-0 size
2171         # close
2172         multiop $DIR/$tdir/f0 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T1050000c
2173
2174         $CHECKSTAT -s 1050000 $DIR/$tdir/f0 || error "checkstat failed"
2175         # open/write it again to force delayed layout creation
2176         cat /etc/hosts > $DIR/$tdir/f0 &
2177         catpid=$!
2178
2179         # restart OSTs
2180         for num in $(seq $OSTCOUNT); do
2181                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
2182                         error "ost$num failed to start"
2183         done
2184
2185         wait $catpid || error "cat failed"
2186
2187         cmp /etc/hosts $DIR/$tdir/f0 || error "cmp failed"
2188         [[ $($GETSTRIPE -c $DIR/$tdir/f0) == 2 ]] || error "wrong stripecount"
2189
2190 }
2191 run_test 27F "Client resend delayed layout creation with non-zero size"
2192
2193 test_27G() { #LU-10629
2194         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
2195         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2196         local POOL=${POOL:-testpool}
2197         local ostrange="0 0 1"
2198
2199         test_mkdir $DIR/$tdir
2200         pool_add $POOL || error "pool_add failed"
2201         pool_add_targets $POOL $ostrange || error "pool_add_targets failed"
2202         $LFS setstripe -p $POOL $DIR/$tdir
2203
2204         local pool=$($LFS getstripe -p $DIR/$tdir)
2205
2206         [ "$pool" = "$POOL" ] || error "Striping failed got '$pool' not '$POOL'"
2207
2208         $LFS setstripe -d $DIR/$tdir
2209
2210         pool=$($LFS getstripe -p $DIR/$tdir)
2211
2212         rmdir $DIR/$tdir
2213
2214         [ -z "$pool" ] || error "'$pool' is not empty"
2215 }
2216 run_test 27G "Clear OST pool from stripe"
2217
2218 # createtest also checks that device nodes are created and
2219 # then visible correctly (#2091)
2220 test_28() { # bug 2091
2221         test_mkdir $DIR/d28
2222         $CREATETEST $DIR/d28/ct || error
2223 }
2224 run_test 28 "create/mknod/mkdir with bad file types ============"
2225
2226 test_29() {
2227         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
2228         sync; sleep 1; sync # flush out any dirty pages from previous tests
2229         cancel_lru_locks
2230         test_mkdir $DIR/d29
2231         touch $DIR/d29/foo
2232         log 'first d29'
2233         ls -l $DIR/d29
2234
2235         declare -i LOCKCOUNTORIG=0
2236         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2237                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2238         done
2239         [ $LOCKCOUNTORIG -eq 0 ] && error "No mdc lock count" && return 1
2240
2241         declare -i LOCKUNUSEDCOUNTORIG=0
2242         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2243                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2244         done
2245
2246         log 'second d29'
2247         ls -l $DIR/d29
2248         log 'done'
2249
2250         declare -i LOCKCOUNTCURRENT=0
2251         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2252                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2253         done
2254
2255         declare -i LOCKUNUSEDCOUNTCURRENT=0
2256         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2257                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2258         done
2259
2260         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2261                 $LCTL set_param -n ldlm.dump_namespaces ""
2262                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2263                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2264                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2265                 return 2
2266         fi
2267         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2268                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2269                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2270                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2271                 return 3
2272         fi
2273 }
2274 run_test 29 "IT_GETATTR regression  ============================"
2275
2276 test_30a() { # was test_30
2277         cp $(which ls) $DIR || cp /bin/ls $DIR
2278         $DIR/ls / || error
2279         rm $DIR/ls
2280 }
2281 run_test 30a "execute binary from Lustre (execve) =============="
2282
2283 test_30b() {
2284         cp `which ls` $DIR || cp /bin/ls $DIR
2285         chmod go+rx $DIR/ls
2286         $RUNAS $DIR/ls / || error
2287         rm $DIR/ls
2288 }
2289 run_test 30b "execute binary from Lustre as non-root ==========="
2290
2291 test_30c() { # b=22376
2292         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2293         cp `which ls` $DIR || cp /bin/ls $DIR
2294         chmod a-rw $DIR/ls
2295         cancel_lru_locks mdc
2296         cancel_lru_locks osc
2297         $RUNAS $DIR/ls / || error
2298         rm -f $DIR/ls
2299 }
2300 run_test 30c "execute binary from Lustre without read perms ===="
2301
2302 test_31a() {
2303         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2304         $CHECKSTAT -a $DIR/f31 || error
2305 }
2306 run_test 31a "open-unlink file =================================="
2307
2308 test_31b() {
2309         touch $DIR/f31 || error
2310         ln $DIR/f31 $DIR/f31b || error
2311         $MULTIOP $DIR/f31b Ouc || error
2312         $CHECKSTAT -t file $DIR/f31 || error
2313 }
2314 run_test 31b "unlink file with multiple links while open ======="
2315
2316 test_31c() {
2317         touch $DIR/f31 || error
2318         ln $DIR/f31 $DIR/f31c || error
2319         multiop_bg_pause $DIR/f31 O_uc || return 1
2320         MULTIPID=$!
2321         $MULTIOP $DIR/f31c Ouc
2322         kill -USR1 $MULTIPID
2323         wait $MULTIPID
2324 }
2325 run_test 31c "open-unlink file with multiple links ============="
2326
2327 test_31d() {
2328         opendirunlink $DIR/d31d $DIR/d31d || error
2329         $CHECKSTAT -a $DIR/d31d || error
2330 }
2331 run_test 31d "remove of open directory ========================="
2332
2333 test_31e() { # bug 2904
2334         openfilleddirunlink $DIR/d31e || error
2335 }
2336 run_test 31e "remove of open non-empty directory ==============="
2337
2338 test_31f() { # bug 4554
2339         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2340         set -vx
2341         test_mkdir $DIR/d31f
2342         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2343         cp /etc/hosts $DIR/d31f
2344         ls -l $DIR/d31f
2345         $GETSTRIPE $DIR/d31f/hosts
2346         multiop_bg_pause $DIR/d31f D_c || return 1
2347         MULTIPID=$!
2348
2349         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2350         test_mkdir $DIR/d31f
2351         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2352         cp /etc/hosts $DIR/d31f
2353         ls -l $DIR/d31f
2354         $GETSTRIPE $DIR/d31f/hosts
2355         multiop_bg_pause $DIR/d31f D_c || return 1
2356         MULTIPID2=$!
2357
2358         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2359         wait $MULTIPID || error "first opendir $MULTIPID failed"
2360
2361         sleep 6
2362
2363         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2364         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2365         set +vx
2366 }
2367 run_test 31f "remove of open directory with open-unlink file ==="
2368
2369 test_31g() {
2370         echo "-- cross directory link --"
2371         test_mkdir -c1 $DIR/${tdir}ga
2372         test_mkdir -c1 $DIR/${tdir}gb
2373         touch $DIR/${tdir}ga/f
2374         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2375         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2376         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2377         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2378         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2379 }
2380 run_test 31g "cross directory link==============="
2381
2382 test_31h() {
2383         echo "-- cross directory link --"
2384         test_mkdir -c1 $DIR/${tdir}
2385         test_mkdir -c1 $DIR/${tdir}/dir
2386         touch $DIR/${tdir}/f
2387         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2388         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2389         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2390         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2391         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2392 }
2393 run_test 31h "cross directory link under child==============="
2394
2395 test_31i() {
2396         echo "-- cross directory link --"
2397         test_mkdir -c1 $DIR/$tdir
2398         test_mkdir -c1 $DIR/$tdir/dir
2399         touch $DIR/$tdir/dir/f
2400         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2401         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2402         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2403         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2404         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2405 }
2406 run_test 31i "cross directory link under parent==============="
2407
2408 test_31j() {
2409         test_mkdir -c1 -p $DIR/$tdir
2410         test_mkdir -c1 -p $DIR/$tdir/dir1
2411         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2412         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2413         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2414         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2415         return 0
2416 }
2417 run_test 31j "link for directory==============="
2418
2419 test_31k() {
2420         test_mkdir -c1 -p $DIR/$tdir
2421         touch $DIR/$tdir/s
2422         touch $DIR/$tdir/exist
2423         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2424         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2425         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2426         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2427         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2428         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2429         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2430         return 0
2431 }
2432 run_test 31k "link to file: the same, non-existing, dir==============="
2433
2434 test_31m() {
2435         mkdir $DIR/d31m
2436         touch $DIR/d31m/s
2437         mkdir $DIR/d31m2
2438         touch $DIR/d31m2/exist
2439         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2440         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2441         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2442         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2443         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2444         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2445         return 0
2446 }
2447 run_test 31m "link to file: the same, non-existing, dir==============="
2448
2449 test_31n() {
2450         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2451         nlink=$(stat --format=%h $DIR/$tfile)
2452         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2453         local fd=$(free_fd)
2454         local cmd="exec $fd<$DIR/$tfile"
2455         eval $cmd
2456         cmd="exec $fd<&-"
2457         trap "eval $cmd" EXIT
2458         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2459         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2460         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2461         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2462         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2463         eval $cmd
2464 }
2465 run_test 31n "check link count of unlinked file"
2466
2467 link_one() {
2468         local TEMPNAME=$(mktemp $1_XXXXXX)
2469         mlink $TEMPNAME $1 2> /dev/null &&
2470                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2471         munlink $TEMPNAME
2472 }
2473
2474 test_31o() { # LU-2901
2475         test_mkdir -p $DIR/$tdir
2476         for LOOP in $(seq 100); do
2477                 rm -f $DIR/$tdir/$tfile*
2478                 for THREAD in $(seq 8); do
2479                         link_one $DIR/$tdir/$tfile.$LOOP &
2480                 done
2481                 wait
2482                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2483                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2484                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2485                         break || true
2486         done
2487 }
2488 run_test 31o "duplicate hard links with same filename"
2489
2490 test_31p() {
2491         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2492
2493         test_mkdir $DIR/$tdir
2494         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2495         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2496
2497         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2498                 error "open unlink test1 failed"
2499         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2500                 error "open unlink test2 failed"
2501
2502         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2503                 error "test1 still exists"
2504         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2505                 error "test2 still exists"
2506 }
2507 run_test 31p "remove of open striped directory"
2508
2509 cleanup_test32_mount() {
2510         local rc=0
2511         trap 0
2512         local loopdev=$(losetup -a | grep $EXT2_DEV | sed -ne 's/:.*$//p')
2513         $UMOUNT $DIR/$tdir/ext2-mountpoint || rc=$?
2514         losetup -d $loopdev || true
2515         rm -rf $DIR/$tdir
2516         return $rc
2517 }
2518
2519 test_32a() {
2520         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2521         echo "== more mountpoints and symlinks ================="
2522         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2523         trap cleanup_test32_mount EXIT
2524         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2525         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2526         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2527         cleanup_test32_mount
2528 }
2529 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2530
2531 test_32b() {
2532         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2533         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2534         trap cleanup_test32_mount EXIT
2535         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2536         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2537         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2538         cleanup_test32_mount
2539 }
2540 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2541
2542 test_32c() {
2543         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2544         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2545         trap cleanup_test32_mount EXIT
2546         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2547         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2548         test_mkdir -p $DIR/$tdir/d2/test_dir
2549         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2550         cleanup_test32_mount
2551 }
2552 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2553
2554 test_32d() {
2555         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2556         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2557         trap cleanup_test32_mount EXIT
2558         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2559         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2560         test_mkdir -p $DIR/$tdir/d2/test_dir
2561         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2562         cleanup_test32_mount
2563 }
2564 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2565
2566 test_32e() {
2567         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2568         test_mkdir -p $DIR/d32e/tmp
2569         TMP_DIR=$DIR/d32e/tmp
2570         ln -s $DIR/d32e $TMP_DIR/symlink11
2571         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2572         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2573         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2574 }
2575 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2576
2577 test_32f() {
2578         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2579         test_mkdir -p $DIR/d32f/tmp
2580         TMP_DIR=$DIR/d32f/tmp
2581         ln -s $DIR/d32f $TMP_DIR/symlink11
2582         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2583         ls $DIR/d32f/tmp/symlink11  || error
2584         ls $DIR/d32f/symlink01 || error
2585 }
2586 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2587
2588 test_32g() {
2589         TMP_DIR=$DIR/$tdir/tmp
2590         test_mkdir -p $DIR/$tdir/tmp
2591         test_mkdir $DIR/${tdir}2
2592         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2593         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2594         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2595         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2596         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2597         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2598 }
2599 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2600
2601 test_32h() {
2602         rm -fr $DIR/$tdir $DIR/${tdir}2
2603         TMP_DIR=$DIR/$tdir/tmp
2604         test_mkdir -p $DIR/$tdir/tmp
2605         test_mkdir $DIR/${tdir}2
2606         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2607         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2608         ls $TMP_DIR/symlink12 || error
2609         ls $DIR/$tdir/symlink02  || error
2610 }
2611 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2612
2613 test_32i() {
2614         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2615         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2616         trap cleanup_test32_mount EXIT
2617         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2618         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2619         touch $DIR/$tdir/test_file
2620         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2621         cleanup_test32_mount
2622 }
2623 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2624
2625 test_32j() {
2626         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2627         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2628         trap cleanup_test32_mount EXIT
2629         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2630         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2631         touch $DIR/$tdir/test_file
2632         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2633         cleanup_test32_mount
2634 }
2635 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2636
2637 test_32k() {
2638         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2639         rm -fr $DIR/$tdir
2640         trap cleanup_test32_mount EXIT
2641         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2642         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2643         test_mkdir -p $DIR/$tdir/d2
2644         touch $DIR/$tdir/d2/test_file || error
2645         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2646         cleanup_test32_mount
2647 }
2648 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2649
2650 test_32l() {
2651         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2652         rm -fr $DIR/$tdir
2653         trap cleanup_test32_mount EXIT
2654         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2655         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2656         test_mkdir -p $DIR/$tdir/d2
2657         touch $DIR/$tdir/d2/test_file
2658         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2659         cleanup_test32_mount
2660 }
2661 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2662
2663 test_32m() {
2664         rm -fr $DIR/d32m
2665         test_mkdir -p $DIR/d32m/tmp
2666         TMP_DIR=$DIR/d32m/tmp
2667         ln -s $DIR $TMP_DIR/symlink11
2668         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2669         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2670         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2671 }
2672 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2673
2674 test_32n() {
2675         rm -fr $DIR/d32n
2676         test_mkdir -p $DIR/d32n/tmp
2677         TMP_DIR=$DIR/d32n/tmp
2678         ln -s $DIR $TMP_DIR/symlink11
2679         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2680         ls -l $DIR/d32n/tmp/symlink11  || error
2681         ls -l $DIR/d32n/symlink01 || error
2682 }
2683 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2684
2685 test_32o() {
2686         touch $DIR/$tfile
2687         test_mkdir -p $DIR/d32o/tmp
2688         TMP_DIR=$DIR/d32o/tmp
2689         ln -s $DIR/$tfile $TMP_DIR/symlink12
2690         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2691         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2692         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2693         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2694         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2695 }
2696 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2697
2698 test_32p() {
2699         log 32p_1
2700         rm -fr $DIR/d32p
2701         log 32p_2
2702         rm -f $DIR/$tfile
2703         log 32p_3
2704         touch $DIR/$tfile
2705         log 32p_4
2706         test_mkdir -p $DIR/d32p/tmp
2707         log 32p_5
2708         TMP_DIR=$DIR/d32p/tmp
2709         log 32p_6
2710         ln -s $DIR/$tfile $TMP_DIR/symlink12
2711         log 32p_7
2712         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2713         log 32p_8
2714         cat $DIR/d32p/tmp/symlink12 || error
2715         log 32p_9
2716         cat $DIR/d32p/symlink02 || error
2717         log 32p_10
2718 }
2719 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2720
2721 test_32q() {
2722         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2723         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2724         trap cleanup_test32_mount EXIT
2725         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2726         touch $DIR/$tdir/ext2-mountpoint/under_the_mount
2727         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2728         ls $DIR/$tdir/ext2-mountpoint | grep "\<under_the_mount\>" && error
2729         cleanup_test32_mount
2730 }
2731 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2732
2733 test_32r() {
2734         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2735         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2736         trap cleanup_test32_mount EXIT
2737         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2738         touch $DIR/$tdir/ext2-mountpoint/under_the_mount
2739         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2740         ls $DIR/$tdir/ext2-mountpoint | grep -q under_the_mount && error || true
2741         cleanup_test32_mount
2742 }
2743 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2744
2745 test_33aa() {
2746         rm -f $DIR/$tfile
2747         touch $DIR/$tfile
2748         chmod 444 $DIR/$tfile
2749         chown $RUNAS_ID $DIR/$tfile
2750         log 33_1
2751         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2752         log 33_2
2753 }
2754 run_test 33aa "write file with mode 444 (should return error) ===="
2755
2756 test_33a() {
2757         rm -fr $DIR/d33
2758         test_mkdir -p $DIR/d33
2759         chown $RUNAS_ID $DIR/d33
2760         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2761         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2762                 error "open RDWR" || true
2763 }
2764 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2765
2766 test_33b() {
2767         rm -fr $DIR/d33
2768         test_mkdir -p $DIR/d33
2769         chown $RUNAS_ID $DIR/d33
2770         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 || true
2771 }
2772 run_test 33b "test open file with malformed flags (No panic)"
2773
2774 test_33c() {
2775         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2776         local ostnum
2777         local ostname
2778         local write_bytes
2779         local all_zeros
2780
2781         remote_ost_nodsh && skip "remote OST with nodsh" && return
2782         all_zeros=:
2783         rm -fr $DIR/d33
2784         test_mkdir -p $DIR/d33
2785         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2786
2787         sync
2788         for ostnum in $(seq $OSTCOUNT); do
2789                 # test-framework's OST numbering is one-based, while Lustre's
2790                 # is zero-based
2791                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2792                 # Parsing llobdstat's output sucks; we could grep the /proc
2793                 # path, but that's likely to not be as portable as using the
2794                 # llobdstat utility.  So we parse lctl output instead.
2795                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2796                         obdfilter/$ostname/stats |
2797                         awk '/^write_bytes/ {print $7}' )
2798                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2799                 if (( ${write_bytes:-0} > 0 ))
2800                 then
2801                         all_zeros=false
2802                         break;
2803                 fi
2804         done
2805
2806         $all_zeros || return 0
2807
2808         # Write four bytes
2809         echo foo > $DIR/d33/bar
2810         # Really write them
2811         sync
2812
2813         # Total up write_bytes after writing.  We'd better find non-zeros.
2814         for ostnum in $(seq $OSTCOUNT); do
2815                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2816                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2817                         obdfilter/$ostname/stats |
2818                         awk '/^write_bytes/ {print $7}' )
2819                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2820                 if (( ${write_bytes:-0} > 0 ))
2821                 then
2822                         all_zeros=false
2823                         break;
2824                 fi
2825         done
2826
2827         if $all_zeros
2828         then
2829                 for ostnum in $(seq $OSTCOUNT); do
2830                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2831                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2832                         do_facet ost$ostnum lctl get_param -n \
2833                                 obdfilter/$ostname/stats
2834                 done
2835                 error "OST not keeping write_bytes stats (b22312)"
2836         fi
2837 }
2838 run_test 33c "test llobdstat and write_bytes"
2839
2840 test_33d() {
2841         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2842         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2843         local MDTIDX=1
2844         local remote_dir=$DIR/$tdir/remote_dir
2845
2846         test_mkdir -p $DIR/$tdir
2847         $LFS mkdir -i $MDTIDX $remote_dir ||
2848                 error "create remote directory failed"
2849
2850         touch $remote_dir/$tfile
2851         chmod 444 $remote_dir/$tfile
2852         chown $RUNAS_ID $remote_dir/$tfile
2853
2854         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2855
2856         chown $RUNAS_ID $remote_dir
2857         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2858                                         error "create" || true
2859         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2860                                     error "open RDWR" || true
2861         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 || true
2862 }
2863 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2864
2865 test_33e() {
2866         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2867
2868         mkdir $DIR/$tdir
2869
2870         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2871         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2872         mkdir $DIR/$tdir/local_dir
2873
2874         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2875         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2876         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2877
2878         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2879                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2880
2881         rmdir $DIR/$tdir/* || error "rmdir failed"
2882
2883         umask 777
2884         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2885         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2886         mkdir $DIR/$tdir/local_dir
2887
2888         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2889         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2890         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2891
2892         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2893                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2894
2895         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2896
2897         umask 000
2898         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2899         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2900         mkdir $DIR/$tdir/local_dir
2901
2902         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2903         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2904         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2905
2906         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2907                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2908 }
2909 run_test 33e "mkdir and striped directory should have same mode"
2910
2911 cleanup_33f() {
2912         trap 0
2913         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
2914 }
2915
2916 test_33f() {
2917         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2918         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2919
2920         mkdir $DIR/$tdir
2921         chmod go+rwx $DIR/$tdir
2922         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
2923         trap cleanup_33f EXIT
2924
2925         $RUNAS lfs mkdir -c$MDSCOUNT $DIR/$tdir/striped_dir ||
2926                 error "cannot create striped directory"
2927
2928         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
2929                 error "cannot create files in striped directory"
2930
2931         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
2932                 error "cannot remove files in striped directory"
2933
2934         $RUNAS rmdir $DIR/$tdir/striped_dir ||
2935                 error "cannot remove striped directory"
2936
2937         cleanup_33f
2938 }
2939 run_test 33f "nonroot user can create, access, and remove a striped directory"
2940
2941 test_33g() {
2942         mkdir -p $DIR/$tdir/dir2
2943
2944         local err=$($RUNAS mkdir $DIR/$tdir/dir2 2>&1)
2945         echo $err
2946         [[ $err =~ "exists" ]] || error "Not exists error"
2947 }
2948 run_test 33g "nonroot user create already existing root created file"
2949
2950 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2951 test_34a() {
2952         rm -f $DIR/f34
2953         $MCREATE $DIR/f34 || error
2954         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2955         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2956         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2957         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2958 }
2959 run_test 34a "truncate file that has not been opened ==========="
2960
2961 test_34b() {
2962         [ ! -f $DIR/f34 ] && test_34a
2963         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2964         $OPENFILE -f O_RDONLY $DIR/f34
2965         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2966         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2967 }
2968 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2969
2970 test_34c() {
2971         [ ! -f $DIR/f34 ] && test_34a
2972         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2973         $OPENFILE -f O_RDWR $DIR/f34
2974         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2975         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2976 }
2977 run_test 34c "O_RDWR opening file-with-size works =============="
2978
2979 test_34d() {
2980         [ ! -f $DIR/f34 ] && test_34a
2981         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2982         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2983         rm $DIR/f34
2984 }
2985 run_test 34d "write to sparse file ============================="
2986
2987 test_34e() {
2988         rm -f $DIR/f34e
2989         $MCREATE $DIR/f34e || error
2990         $TRUNCATE $DIR/f34e 1000 || error
2991         $CHECKSTAT -s 1000 $DIR/f34e || error
2992         $OPENFILE -f O_RDWR $DIR/f34e
2993         $CHECKSTAT -s 1000 $DIR/f34e || error
2994 }
2995 run_test 34e "create objects, some with size and some without =="
2996
2997 test_34f() { # bug 6242, 6243
2998         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2999         SIZE34F=48000
3000         rm -f $DIR/f34f
3001         $MCREATE $DIR/f34f || error
3002         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
3003         dd if=$DIR/f34f of=$TMP/f34f
3004         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
3005         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
3006         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
3007         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
3008         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
3009 }
3010 run_test 34f "read from a file with no objects until EOF ======="
3011
3012 test_34g() {
3013         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3014         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
3015         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
3016         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
3017         cancel_lru_locks osc
3018         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
3019                 error "wrong size after lock cancel"
3020
3021         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
3022         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
3023                 error "expanding truncate failed"
3024         cancel_lru_locks osc
3025         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
3026                 error "wrong expanded size after lock cancel"
3027 }
3028 run_test 34g "truncate long file ==============================="
3029
3030 test_34h() {
3031         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3032         local gid=10
3033         local sz=1000
3034
3035         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
3036         sync # Flush the cache so that multiop below does not block on cache
3037              # flush when getting the group lock
3038         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
3039         MULTIPID=$!
3040
3041         # Since just timed wait is not good enough, let's do a sync write
3042         # that way we are sure enough time for a roundtrip + processing
3043         # passed + 2 seconds of extra margin.
3044         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
3045         rm $DIR/${tfile}-1
3046         sleep 2
3047
3048         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
3049                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
3050                 kill -9 $MULTIPID
3051         fi
3052         wait $MULTIPID
3053         local nsz=`stat -c %s $DIR/$tfile`
3054         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
3055 }
3056 run_test 34h "ftruncate file under grouplock should not block"
3057
3058 test_35a() {
3059         cp /bin/sh $DIR/f35a
3060         chmod 444 $DIR/f35a
3061         chown $RUNAS_ID $DIR/f35a
3062         $RUNAS $DIR/f35a && error || true
3063         rm $DIR/f35a
3064 }
3065 run_test 35a "exec file with mode 444 (should return and not leak) ====="
3066
3067 test_36a() {
3068         rm -f $DIR/f36
3069         utime $DIR/f36 || error
3070 }
3071 run_test 36a "MDS utime check (mknod, utime) ==================="
3072
3073 test_36b() {
3074         echo "" > $DIR/f36
3075         utime $DIR/f36 || error
3076 }
3077 run_test 36b "OST utime check (open, utime) ===================="
3078
3079 test_36c() {
3080         rm -f $DIR/d36/f36
3081         test_mkdir $DIR/d36
3082         chown $RUNAS_ID $DIR/d36
3083         $RUNAS utime $DIR/d36/f36 || error
3084 }
3085 run_test 36c "non-root MDS utime check (mknod, utime) =========="
3086
3087 test_36d() {
3088         [ ! -d $DIR/d36 ] && test_36c
3089         echo "" > $DIR/d36/f36
3090         $RUNAS utime $DIR/d36/f36 || error
3091 }
3092 run_test 36d "non-root OST utime check (open, utime) ==========="
3093
3094 test_36e() {
3095         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
3096         test_mkdir -p $DIR/$tdir
3097         touch $DIR/$tdir/$tfile
3098         $RUNAS utime $DIR/$tdir/$tfile && \
3099                 error "utime worked, expected failure" || true
3100 }
3101 run_test 36e "utime on non-owned file (should return error) ===="
3102
3103 subr_36fh() {
3104         local fl="$1"
3105         local LANG_SAVE=$LANG
3106         local LC_LANG_SAVE=$LC_LANG
3107         export LANG=C LC_LANG=C # for date language
3108
3109         DATESTR="Dec 20  2000"
3110         test_mkdir -p $DIR/$tdir
3111         lctl set_param fail_loc=$fl
3112         date; date +%s
3113         cp /etc/hosts $DIR/$tdir/$tfile
3114         sync & # write RPC generated with "current" inode timestamp, but delayed
3115         sleep 1
3116         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
3117         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
3118         cancel_lru_locks osc
3119         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
3120         date; date +%s
3121         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
3122                 echo "BEFORE: $LS_BEFORE" && \
3123                 echo "AFTER : $LS_AFTER" && \
3124                 echo "WANT  : $DATESTR" && \
3125                 error "$DIR/$tdir/$tfile timestamps changed" || true
3126
3127         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
3128 }
3129
3130 test_36f() {
3131         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3132         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
3133         subr_36fh "0x80000214"
3134 }
3135 run_test 36f "utime on file racing with OST BRW write =========="
3136
3137 test_36g() {
3138         remote_ost_nodsh && skip "remote OST with nodsh" && return
3139         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3140         local fmd_max_age
3141         local fmd_before
3142         local fmd_after
3143
3144         test_mkdir -p $DIR/$tdir
3145         fmd_max_age=$(do_facet ost1 \
3146                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
3147                 head -n 1")
3148
3149         fmd_before=$(do_facet ost1 \
3150                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3151         touch $DIR/$tdir/$tfile
3152         sleep $((fmd_max_age + 12))
3153         fmd_after=$(do_facet ost1 \
3154                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3155
3156         echo "fmd_before: $fmd_before"
3157         echo "fmd_after: $fmd_after"
3158         [[ $fmd_after -gt $fmd_before ]] &&
3159                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
3160                 error "fmd didn't expire after ping" || true
3161 }
3162 run_test 36g "filter mod data cache expiry ====================="
3163
3164 test_36h() {
3165         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3166         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
3167         subr_36fh "0x80000227"
3168 }
3169 run_test 36h "utime on file racing with OST BRW write =========="
3170
3171 test_36i() {
3172         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3173
3174         test_mkdir $DIR/$tdir
3175         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
3176
3177         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3178         local new_mtime=$((mtime + 200))
3179
3180         #change Modify time of striped dir
3181         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3182                         error "change mtime failed"
3183
3184         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3185
3186         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3187 }
3188 run_test 36i "change mtime on striped directory"
3189
3190 # test_37 - duplicate with tests 32q 32r
3191
3192 test_38() {
3193         local file=$DIR/$tfile
3194         touch $file
3195         openfile -f O_DIRECTORY $file
3196         local RC=$?
3197         local ENOTDIR=20
3198         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3199         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3200 }
3201 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3202
3203 test_39a() { # was test_39
3204         touch $DIR/$tfile
3205         touch $DIR/${tfile}2
3206 #       ls -l  $DIR/$tfile $DIR/${tfile}2
3207 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
3208 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
3209         sleep 2
3210         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3211         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3212                 echo "mtime"
3213                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3214                 echo "atime"
3215                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3216                 echo "ctime"
3217                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3218                 error "O_TRUNC didn't change timestamps"
3219         fi
3220 }
3221 run_test 39a "mtime changed on create ==========================="
3222
3223 test_39b() {
3224         test_mkdir -p -c1 $DIR/$tdir
3225         cp -p /etc/passwd $DIR/$tdir/fopen
3226         cp -p /etc/passwd $DIR/$tdir/flink
3227         cp -p /etc/passwd $DIR/$tdir/funlink
3228         cp -p /etc/passwd $DIR/$tdir/frename
3229         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3230
3231         sleep 1
3232         echo "aaaaaa" >> $DIR/$tdir/fopen
3233         echo "aaaaaa" >> $DIR/$tdir/flink
3234         echo "aaaaaa" >> $DIR/$tdir/funlink
3235         echo "aaaaaa" >> $DIR/$tdir/frename
3236
3237         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3238         local link_new=`stat -c %Y $DIR/$tdir/flink`
3239         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3240         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3241
3242         cat $DIR/$tdir/fopen > /dev/null
3243         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3244         rm -f $DIR/$tdir/funlink2
3245         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3246
3247         for (( i=0; i < 2; i++ )) ; do
3248                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3249                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3250                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3251                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3252
3253                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3254                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3255                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3256                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3257
3258                 cancel_lru_locks osc
3259                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3260         done
3261 }
3262 run_test 39b "mtime change on open, link, unlink, rename  ======"
3263
3264 # this should be set to past
3265 TEST_39_MTIME=`date -d "1 year ago" +%s`
3266
3267 # bug 11063
3268 test_39c() {
3269         touch $DIR1/$tfile
3270         sleep 2
3271         local mtime0=`stat -c %Y $DIR1/$tfile`
3272
3273         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3274         local mtime1=`stat -c %Y $DIR1/$tfile`
3275         [ "$mtime1" = $TEST_39_MTIME ] || \
3276                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3277
3278         local d1=`date +%s`
3279         echo hello >> $DIR1/$tfile
3280         local d2=`date +%s`
3281         local mtime2=`stat -c %Y $DIR1/$tfile`
3282         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3283                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3284
3285         mv $DIR1/$tfile $DIR1/$tfile-1
3286
3287         for (( i=0; i < 2; i++ )) ; do
3288                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3289                 [ "$mtime2" = "$mtime3" ] || \
3290                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3291
3292                 cancel_lru_locks osc
3293                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3294         done
3295 }
3296 run_test 39c "mtime change on rename ==========================="
3297
3298 # bug 21114
3299 test_39d() {
3300         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3301         touch $DIR1/$tfile
3302
3303         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3304
3305         for (( i=0; i < 2; i++ )) ; do
3306                 local mtime=`stat -c %Y $DIR1/$tfile`
3307                 [ $mtime = $TEST_39_MTIME ] || \
3308                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3309
3310                 cancel_lru_locks osc
3311                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3312         done
3313 }
3314 run_test 39d "create, utime, stat =============================="
3315
3316 # bug 21114
3317 test_39e() {
3318         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3319         touch $DIR1/$tfile
3320         local mtime1=`stat -c %Y $DIR1/$tfile`
3321
3322         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3323
3324         for (( i=0; i < 2; i++ )) ; do
3325                 local mtime2=`stat -c %Y $DIR1/$tfile`
3326                 [ $mtime2 = $TEST_39_MTIME ] || \
3327                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3328
3329                 cancel_lru_locks osc
3330                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3331         done
3332 }
3333 run_test 39e "create, stat, utime, stat ========================"
3334
3335 # bug 21114
3336 test_39f() {
3337         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3338         touch $DIR1/$tfile
3339         mtime1=`stat -c %Y $DIR1/$tfile`
3340
3341         sleep 2
3342         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3343
3344         for (( i=0; i < 2; i++ )) ; do
3345                 local mtime2=`stat -c %Y $DIR1/$tfile`
3346                 [ $mtime2 = $TEST_39_MTIME ] || \
3347                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3348
3349                 cancel_lru_locks osc
3350                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3351         done
3352 }
3353 run_test 39f "create, stat, sleep, utime, stat ================="
3354
3355 # bug 11063
3356 test_39g() {
3357         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3358         echo hello >> $DIR1/$tfile
3359         local mtime1=`stat -c %Y $DIR1/$tfile`
3360
3361         sleep 2
3362         chmod o+r $DIR1/$tfile
3363
3364         for (( i=0; i < 2; i++ )) ; do
3365                 local mtime2=`stat -c %Y $DIR1/$tfile`
3366                 [ "$mtime1" = "$mtime2" ] || \
3367                         error "lost mtime: $mtime2, should be $mtime1"
3368
3369                 cancel_lru_locks osc
3370                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3371         done
3372 }
3373 run_test 39g "write, chmod, stat ==============================="
3374
3375 # bug 11063
3376 test_39h() {
3377         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3378         touch $DIR1/$tfile
3379         sleep 1
3380
3381         local d1=`date`
3382         echo hello >> $DIR1/$tfile
3383         local mtime1=`stat -c %Y $DIR1/$tfile`
3384
3385         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3386         local d2=`date`
3387         if [ "$d1" != "$d2" ]; then
3388                 echo "write and touch not within one second"
3389         else
3390                 for (( i=0; i < 2; i++ )) ; do
3391                         local mtime2=`stat -c %Y $DIR1/$tfile`
3392                         [ "$mtime2" = $TEST_39_MTIME ] || \
3393                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3394
3395                         cancel_lru_locks osc
3396                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3397                 done
3398         fi
3399 }
3400 run_test 39h "write, utime within one second, stat ============="
3401
3402 test_39i() {
3403         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3404         touch $DIR1/$tfile
3405         sleep 1
3406
3407         echo hello >> $DIR1/$tfile
3408         local mtime1=`stat -c %Y $DIR1/$tfile`
3409
3410         mv $DIR1/$tfile $DIR1/$tfile-1
3411
3412         for (( i=0; i < 2; i++ )) ; do
3413                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3414
3415                 [ "$mtime1" = "$mtime2" ] || \
3416                         error "lost mtime: $mtime2, should be $mtime1"
3417
3418                 cancel_lru_locks osc
3419                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3420         done
3421 }
3422 run_test 39i "write, rename, stat =============================="
3423
3424 test_39j() {
3425         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3426         start_full_debug_logging
3427         touch $DIR1/$tfile
3428         sleep 1
3429
3430         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3431         lctl set_param fail_loc=0x80000412
3432         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3433                 error "multiop failed"
3434         local multipid=$!
3435         local mtime1=`stat -c %Y $DIR1/$tfile`
3436
3437         mv $DIR1/$tfile $DIR1/$tfile-1
3438
3439         kill -USR1 $multipid
3440         wait $multipid || error "multiop close failed"
3441
3442         for (( i=0; i < 2; i++ )) ; do
3443                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3444                 [ "$mtime1" = "$mtime2" ] ||
3445                         error "mtime is lost on close: $mtime2, " \
3446                               "should be $mtime1"
3447
3448                 cancel_lru_locks osc
3449                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3450         done
3451         lctl set_param fail_loc=0
3452         stop_full_debug_logging
3453 }
3454 run_test 39j "write, rename, close, stat ======================="
3455
3456 test_39k() {
3457         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3458         touch $DIR1/$tfile
3459         sleep 1
3460
3461         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3462         local multipid=$!
3463         local mtime1=`stat -c %Y $DIR1/$tfile`
3464
3465         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3466
3467         kill -USR1 $multipid
3468         wait $multipid || error "multiop close failed"
3469
3470         for (( i=0; i < 2; i++ )) ; do
3471                 local mtime2=`stat -c %Y $DIR1/$tfile`
3472
3473                 [ "$mtime2" = $TEST_39_MTIME ] || \
3474                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3475
3476                 cancel_lru_locks osc
3477                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3478         done
3479 }
3480 run_test 39k "write, utime, close, stat ========================"
3481
3482 # this should be set to future
3483 TEST_39_ATIME=`date -d "1 year" +%s`
3484
3485 test_39l() {
3486         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
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         rm -rf $DIR/$tdir
3491         mkdir -p $DIR/$tdir
3492
3493         # test setting directory atime to future
3494         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3495         local atime=$(stat -c %X $DIR/$tdir)
3496         [ "$atime" = $TEST_39_ATIME ] ||
3497                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3498
3499         # test setting directory atime from future to now
3500         local now=$(date +%s)
3501         touch -a -d @$now $DIR/$tdir
3502
3503         atime=$(stat -c %X $DIR/$tdir)
3504         [ "$atime" -eq "$now"  ] ||
3505                 error "atime is not updated from future: $atime, $now"
3506
3507         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3508         sleep 3
3509
3510         # test setting directory atime when now > dir atime + atime_diff
3511         local d1=$(date +%s)
3512         ls $DIR/$tdir
3513         local d2=$(date +%s)
3514         cancel_lru_locks mdc
3515         atime=$(stat -c %X $DIR/$tdir)
3516         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
3517                 error "atime is not updated  : $atime, should be $d2"
3518
3519         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3520         sleep 3
3521
3522         # test not setting directory atime when now < dir atime + atime_diff
3523         ls $DIR/$tdir
3524         cancel_lru_locks mdc
3525         atime=$(stat -c %X $DIR/$tdir)
3526         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
3527                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3528
3529         do_facet $SINGLEMDS \
3530                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3531 }
3532 run_test 39l "directory atime update ==========================="
3533
3534 test_39m() {
3535         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3536         touch $DIR1/$tfile
3537         sleep 2
3538         local far_past_mtime=$(date -d "May 29 1953" +%s)
3539         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3540
3541         touch -m -d @$far_past_mtime $DIR1/$tfile
3542         touch -a -d @$far_past_atime $DIR1/$tfile
3543
3544         for (( i=0; i < 2; i++ )) ; do
3545                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3546                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3547                         error "atime or mtime set incorrectly"
3548
3549                 cancel_lru_locks osc
3550                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3551         done
3552 }
3553 run_test 39m "test atime and mtime before 1970"
3554
3555 test_39n() { # LU-3832
3556         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3557         local atime_diff=$(do_facet $SINGLEMDS \
3558                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3559         local atime0
3560         local atime1
3561         local atime2
3562
3563         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3564
3565         rm -rf $DIR/$tfile
3566         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3567         atime0=$(stat -c %X $DIR/$tfile)
3568
3569         sleep 5
3570         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3571         atime1=$(stat -c %X $DIR/$tfile)
3572
3573         sleep 5
3574         cancel_lru_locks mdc
3575         cancel_lru_locks osc
3576         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3577         atime2=$(stat -c %X $DIR/$tfile)
3578
3579         do_facet $SINGLEMDS \
3580                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3581
3582         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3583         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3584 }
3585 run_test 39n "check that O_NOATIME is honored"
3586
3587 test_39o() {
3588         TESTDIR=$DIR/$tdir/$tfile
3589         [ -e $TESTDIR ] && rm -rf $TESTDIR
3590         mkdir -p $TESTDIR
3591         cd $TESTDIR
3592         links1=2
3593         ls
3594         mkdir a b
3595         ls
3596         links2=$(stat -c %h .)
3597         [ $(($links1 + 2)) != $links2 ] &&
3598                 error "wrong links count $(($links1 + 2)) != $links2"
3599         rmdir b
3600         links3=$(stat -c %h .)
3601         [ $(($links1 + 1)) != $links3 ] &&
3602                 error "wrong links count $links1 != $links3"
3603         return 0
3604 }
3605 run_test 39o "directory cached attributes updated after create ========"
3606
3607 test_39p() {
3608         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3609         local MDTIDX=1
3610         TESTDIR=$DIR/$tdir/$tfile
3611         [ -e $TESTDIR ] && rm -rf $TESTDIR
3612         test_mkdir -p $TESTDIR
3613         cd $TESTDIR
3614         links1=2
3615         ls
3616         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3617         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3618         ls
3619         links2=$(stat -c %h .)
3620         [ $(($links1 + 2)) != $links2 ] &&
3621                 error "wrong links count $(($links1 + 2)) != $links2"
3622         rmdir remote_dir2
3623         links3=$(stat -c %h .)
3624         [ $(($links1 + 1)) != $links3 ] &&
3625                 error "wrong links count $links1 != $links3"
3626         return 0
3627 }
3628 run_test 39p "remote directory cached attributes updated after create ========"
3629
3630
3631 test_39q() { # LU-8041
3632         local testdir=$DIR/$tdir
3633         mkdir -p $testdir
3634         multiop_bg_pause $testdir D_c || error "multiop failed"
3635         local multipid=$!
3636         cancel_lru_locks mdc
3637         kill -USR1 $multipid
3638         local atime=$(stat -c %X $testdir)
3639         [ "$atime" -ne 0 ] || error "atime is zero"
3640 }
3641 run_test 39q "close won't zero out atime"
3642
3643 test_40() {
3644         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3645         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3646                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3647         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3648                 error "$tfile is not 4096 bytes in size"
3649 }
3650 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3651
3652 test_41() {
3653         # bug 1553
3654         small_write $DIR/f41 18
3655 }
3656 run_test 41 "test small file write + fstat ====================="
3657
3658 count_ost_writes() {
3659         lctl get_param -n osc.*.stats |
3660                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3661                         END { printf("%0.0f", writes) }'
3662 }
3663
3664 # decent default
3665 WRITEBACK_SAVE=500
3666 DIRTY_RATIO_SAVE=40
3667 MAX_DIRTY_RATIO=50
3668 BG_DIRTY_RATIO_SAVE=10
3669 MAX_BG_DIRTY_RATIO=25
3670
3671 start_writeback() {
3672         trap 0
3673         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3674         # dirty_ratio, dirty_background_ratio
3675         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3676                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3677                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3678                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3679         else
3680                 # if file not here, we are a 2.4 kernel
3681                 kill -CONT `pidof kupdated`
3682         fi
3683 }
3684
3685 stop_writeback() {
3686         # setup the trap first, so someone cannot exit the test at the
3687         # exact wrong time and mess up a machine
3688         trap start_writeback EXIT
3689         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3690         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3691                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3692                 sysctl -w vm.dirty_writeback_centisecs=0
3693                 sysctl -w vm.dirty_writeback_centisecs=0
3694                 # save and increase /proc/sys/vm/dirty_ratio
3695                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3696                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3697                 # save and increase /proc/sys/vm/dirty_background_ratio
3698                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3699                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3700         else
3701                 # if file not here, we are a 2.4 kernel
3702                 kill -STOP `pidof kupdated`
3703         fi
3704 }
3705
3706 # ensure that all stripes have some grant before we test client-side cache
3707 setup_test42() {
3708         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3709                 dd if=/dev/zero of=$i bs=4k count=1
3710                 rm $i
3711         done
3712 }
3713
3714 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3715 # file truncation, and file removal.
3716 test_42a() {
3717         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3718         setup_test42
3719         cancel_lru_locks osc
3720         stop_writeback
3721         sync; sleep 1; sync # just to be safe
3722         BEFOREWRITES=`count_ost_writes`
3723         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3724         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3725         AFTERWRITES=`count_ost_writes`
3726         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3727                 error "$BEFOREWRITES < $AFTERWRITES"
3728         start_writeback
3729 }
3730 run_test 42a "ensure that we don't flush on close"
3731
3732 test_42b() {
3733         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3734         setup_test42
3735         cancel_lru_locks osc
3736         stop_writeback
3737         sync
3738         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3739         BEFOREWRITES=$(count_ost_writes)
3740         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3741         AFTERWRITES=$(count_ost_writes)
3742         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3743                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3744         fi
3745         BEFOREWRITES=$(count_ost_writes)
3746         sync || error "sync: $?"
3747         AFTERWRITES=$(count_ost_writes)
3748         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3749                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3750         fi
3751         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3752         start_writeback
3753         return 0
3754 }
3755 run_test 42b "test destroy of file with cached dirty data ======"
3756
3757 # if these tests just want to test the effect of truncation,
3758 # they have to be very careful.  consider:
3759 # - the first open gets a {0,EOF}PR lock
3760 # - the first write conflicts and gets a {0, count-1}PW
3761 # - the rest of the writes are under {count,EOF}PW
3762 # - the open for truncate tries to match a {0,EOF}PR
3763 #   for the filesize and cancels the PWs.
3764 # any number of fixes (don't get {0,EOF} on open, match
3765 # composite locks, do smarter file size management) fix
3766 # this, but for now we want these tests to verify that
3767 # the cancellation with truncate intent works, so we
3768 # start the file with a full-file pw lock to match against
3769 # until the truncate.
3770 trunc_test() {
3771         test=$1
3772         file=$DIR/$test
3773         offset=$2
3774         cancel_lru_locks osc
3775         stop_writeback
3776         # prime the file with 0,EOF PW to match
3777         touch $file
3778         $TRUNCATE $file 0
3779         sync; sync
3780         # now the real test..
3781         dd if=/dev/zero of=$file bs=1024 count=100
3782         BEFOREWRITES=`count_ost_writes`
3783         $TRUNCATE $file $offset
3784         cancel_lru_locks osc
3785         AFTERWRITES=`count_ost_writes`
3786         start_writeback
3787 }
3788
3789 test_42c() {
3790         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3791         trunc_test 42c 1024
3792         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3793             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3794         rm $file
3795 }
3796 run_test 42c "test partial truncate of file with cached dirty data"
3797
3798 test_42d() {
3799         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3800         trunc_test 42d 0
3801         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3802             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3803         rm $file
3804 }
3805 run_test 42d "test complete truncate of file with cached dirty data"
3806
3807 test_42e() { # bug22074
3808         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3809         local TDIR=$DIR/${tdir}e
3810         local pagesz=$(page_size)
3811         local pages=16 # hardcoded 16 pages, don't change it.
3812         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3813         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3814         local max_dirty_mb
3815         local warmup_files
3816
3817         test_mkdir -p $DIR/${tdir}e
3818         $SETSTRIPE -c 1 $TDIR
3819         createmany -o $TDIR/f $files
3820
3821         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3822
3823         # we assume that with $OSTCOUNT files, at least one of them will
3824         # be allocated on OST0.
3825         warmup_files=$((OSTCOUNT * max_dirty_mb))
3826         createmany -o $TDIR/w $warmup_files
3827
3828         # write a large amount of data into one file and sync, to get good
3829         # avail_grant number from OST.
3830         for ((i=0; i<$warmup_files; i++)); do
3831                 idx=$($GETSTRIPE -i $TDIR/w$i)
3832                 [ $idx -ne 0 ] && continue
3833                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3834                 break
3835         done
3836         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3837         sync
3838         $LCTL get_param $proc_osc0/cur_dirty_bytes
3839         $LCTL get_param $proc_osc0/cur_grant_bytes
3840
3841         # create as much dirty pages as we can while not to trigger the actual
3842         # RPCs directly. but depends on the env, VFS may trigger flush during this
3843         # period, hopefully we are good.
3844         for ((i=0; i<$warmup_files; i++)); do
3845                 idx=$($GETSTRIPE -i $TDIR/w$i)
3846                 [ $idx -ne 0 ] && continue
3847                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3848         done
3849         $LCTL get_param $proc_osc0/cur_dirty_bytes
3850         $LCTL get_param $proc_osc0/cur_grant_bytes
3851
3852         # perform the real test
3853         $LCTL set_param $proc_osc0/rpc_stats 0
3854         for ((;i<$files; i++)); do
3855                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3856                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3857         done
3858         sync
3859         $LCTL get_param $proc_osc0/rpc_stats
3860
3861         local percent=0
3862         local have_ppr=false
3863         $LCTL get_param $proc_osc0/rpc_stats |
3864                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3865                         # skip lines until we are at the RPC histogram data
3866                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3867                         $have_ppr || continue
3868
3869                         # we only want the percent stat for < 16 pages
3870                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3871
3872                         percent=$((percent + WPCT))
3873                         if [[ $percent -gt 15 ]]; then
3874                                 error "less than 16-pages write RPCs" \
3875                                       "$percent% > 15%"
3876                                 break
3877                         fi
3878                 done
3879         rm -rf $TDIR
3880 }
3881 run_test 42e "verify sub-RPC writes are not done synchronously"
3882
3883 test_43A() { # was test_43
3884         test_mkdir -p $DIR/$tdir
3885         cp -p /bin/ls $DIR/$tdir/$tfile
3886         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3887         pid=$!
3888         # give multiop a chance to open
3889         sleep 1
3890
3891         $DIR/$tdir/$tfile && error "execute $DIR/$tdir/$tfile succeeded" || true
3892         kill -USR1 $pid
3893 }
3894 run_test 43A "execution of file opened for write should return -ETXTBSY"
3895
3896 test_43a() {
3897         test_mkdir $DIR/$tdir
3898         cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
3899                 cp -p multiop $DIR/$tdir/multiop
3900         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3901                 error "multiop open $TMP/$tfile.junk failed"
3902         MULTIOP_PID=$!
3903         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3904         kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
3905         wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
3906 }
3907 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3908
3909 test_43b() {
3910         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3911         test_mkdir $DIR/$tdir
3912         cp -p $(which $MULTIOP) $DIR/$tdir/multiop ||
3913                 cp -p multiop $DIR/$tdir/multiop
3914         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3915                 error "multiop open $TMP/$tfile.junk failed"
3916         MULTIOP_PID=$!
3917         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3918         kill -USR1 $MULTIOP_PID || error "kill -USR1 PID $MULTIOP_PID failed"
3919         wait $MULTIOP_PID || error "wait PID $MULTIOP_PID failed"
3920 }
3921 run_test 43b "truncate of file being executed should return -ETXTBSY"
3922
3923 test_43c() {
3924         local testdir="$DIR/$tdir"
3925         test_mkdir $testdir
3926         cp $SHELL $testdir/
3927         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) |
3928                 ( cd $testdir && md5sum -c )
3929 }
3930 run_test 43c "md5sum of copy into lustre"
3931
3932 test_44A() { # was test_44
3933         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
3934         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3935         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3936 }
3937 run_test 44A "zero length read from a sparse stripe"
3938
3939 test_44a() {
3940         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3941                 awk '{ print $2 }')
3942         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3943         [[ $nstripe -gt $OSTCOUNT ]] &&
3944             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3945             return
3946         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3947                 awk '{ print $2 }')
3948         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3949                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3950                         awk '{ print $2 }')
3951         fi
3952
3953         OFFSETS="0 $((stride/2)) $((stride-1))"
3954         for offset in $OFFSETS; do
3955                 for i in $(seq 0 $((nstripe-1))); do
3956                         local GLOBALOFFSETS=""
3957                         # size in Bytes
3958                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3959                         local myfn=$DIR/d44a-$size
3960                         echo "--------writing $myfn at $size"
3961                         ll_sparseness_write $myfn $size ||
3962                                 error "ll_sparseness_write"
3963                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3964                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3965                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3966
3967                         for j in $(seq 0 $((nstripe-1))); do
3968                                 # size in Bytes
3969                                 size=$((((j + $nstripe )*$stride + $offset)))
3970                                 ll_sparseness_write $myfn $size ||
3971                                         error "ll_sparseness_write"
3972                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3973                         done
3974                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3975                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3976                         rm -f $myfn
3977                 done
3978         done
3979 }
3980 run_test 44a "test sparse pwrite ==============================="
3981
3982 dirty_osc_total() {
3983         tot=0
3984         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3985                 tot=$(($tot + $d))
3986         done
3987         echo $tot
3988 }
3989 do_dirty_record() {
3990         before=`dirty_osc_total`
3991         echo executing "\"$*\""
3992         eval $*
3993         after=`dirty_osc_total`
3994         echo before $before, after $after
3995 }
3996 test_45() {
3997         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3998         f="$DIR/f45"
3999         # Obtain grants from OST if it supports it
4000         echo blah > ${f}_grant
4001         stop_writeback
4002         sync
4003         do_dirty_record "echo blah > $f"
4004         [[ $before -eq $after ]] && error "write wasn't cached"
4005         do_dirty_record "> $f"
4006         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
4007         do_dirty_record "echo blah > $f"
4008         [[ $before -eq $after ]] && error "write wasn't cached"
4009         do_dirty_record "sync"
4010         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
4011         do_dirty_record "echo blah > $f"
4012         [[ $before -eq $after ]] && error "write wasn't cached"
4013         do_dirty_record "cancel_lru_locks osc"
4014         [[ $before -gt $after ]] ||
4015                 error "lock cancellation didn't lower dirty count"
4016         start_writeback
4017 }
4018 run_test 45 "osc io page accounting ============================"
4019
4020 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
4021 # test tickles a bug where re-dirtying a page was failing to be mapped to the
4022 # objects offset and an assert hit when an rpc was built with 1023's mapped
4023 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
4024 test_46() {
4025         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4026         f="$DIR/f46"
4027         stop_writeback
4028         sync
4029         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
4030         sync
4031         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
4032         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
4033         sync
4034         start_writeback
4035 }
4036 run_test 46 "dirtying a previously written page ================"
4037
4038 # test_47 is removed "Device nodes check" is moved to test_28
4039
4040 test_48a() { # bug 2399
4041         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
4042         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
4043                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly" &&
4044                 return
4045         test_mkdir $DIR/$tdir
4046         cd $DIR/$tdir
4047         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
4048         test_mkdir $DIR/$tdir || error "recreate directory failed"
4049         touch foo || error "'touch foo' failed after recreating cwd"
4050         test_mkdir bar || error "'mkdir foo' failed after recreating cwd"
4051         touch .foo || error "'touch .foo' failed after recreating cwd"
4052         test_mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
4053         ls . > /dev/null || error "'ls .' failed after recreating cwd"
4054         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
4055         cd . || error "'cd .' failed after recreating cwd"
4056         test_mkdir . && error "'mkdir .' worked after recreating cwd"
4057         rmdir . && error "'rmdir .' worked after recreating cwd"
4058         ln -s . baz || error "'ln -s .' failed after recreating cwd"
4059         cd .. || error "'cd ..' failed after recreating cwd"
4060 }
4061 run_test 48a "Access renamed working dir (should return errors)="
4062
4063 test_48b() { # bug 2399
4064         rm -rf $DIR/$tdir
4065         test_mkdir $DIR/$tdir
4066         cd $DIR/$tdir
4067         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
4068         touch foo && error "'touch foo' worked after removing cwd"
4069         test_mkdir foo && error "'mkdir foo' worked after removing cwd"
4070         touch .foo && error "'touch .foo' worked after removing cwd"
4071         test_mkdir .foo && error "'mkdir .foo' worked after removing cwd"
4072         ls . > /dev/null && error "'ls .' worked after removing cwd"
4073         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
4074         test_mkdir . && error "'mkdir .' worked after removing cwd"
4075         rmdir . && error "'rmdir .' worked after removing cwd"
4076         ln -s . foo && error "'ln -s .' worked after removing cwd"
4077         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
4078 }
4079 run_test 48b "Access removed working dir (should return errors)="
4080
4081 test_48c() { # bug 2350
4082         #lctl set_param debug=-1
4083         #set -vx
4084         rm -rf $DIR/$tdir
4085         test_mkdir -p $DIR/$tdir/dir
4086         cd $DIR/$tdir/dir
4087         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4088         $TRACE touch foo && error "touch foo worked after removing cwd"
4089         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
4090         touch .foo && error "touch .foo worked after removing cwd"
4091         test_mkdir .foo && error "mkdir .foo worked after removing cwd"
4092         $TRACE ls . && error "'ls .' worked after removing cwd"
4093         $TRACE ls .. || error "'ls ..' failed after removing cwd"
4094         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
4095         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
4096         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
4097         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
4098 }
4099 run_test 48c "Access removed working subdir (should return errors)"
4100
4101 test_48d() { # bug 2350
4102         #lctl set_param debug=-1
4103         #set -vx
4104         rm -rf $DIR/$tdir
4105         test_mkdir -p $DIR/$tdir/dir
4106         cd $DIR/$tdir/dir
4107         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4108         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
4109         $TRACE touch foo && error "'touch foo' worked after removing parent"
4110         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
4111         touch .foo && error "'touch .foo' worked after removing parent"
4112         test_mkdir .foo && error "mkdir .foo worked after removing parent"
4113         $TRACE ls . && error "'ls .' worked after removing parent"
4114         $TRACE ls .. && error "'ls ..' worked after removing parent"
4115         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
4116         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
4117         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
4118         true
4119 }
4120 run_test 48d "Access removed parent subdir (should return errors)"
4121
4122 test_48e() { # bug 4134
4123         #lctl set_param debug=-1
4124         #set -vx
4125         rm -rf $DIR/$tdir
4126         test_mkdir -p $DIR/$tdir/dir
4127         cd $DIR/$tdir/dir
4128         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
4129         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
4130         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
4131         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
4132         # On a buggy kernel addition of "touch foo" after cd .. will
4133         # produce kernel oops in lookup_hash_it
4134         touch ../foo && error "'cd ..' worked after recreate parent"
4135         cd $DIR
4136         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
4137 }
4138 run_test 48e "Access to recreated parent subdir (should return errors)"
4139
4140 test_49() { # LU-1030
4141         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4142         remote_ost_nodsh && skip "remote OST with nodsh" && return
4143         # get ost1 size - lustre-OST0000
4144         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
4145                 awk '{ print $4 }')
4146         # write 800M at maximum
4147         [[ $ost1_size -lt 2 ]] && ost1_size=2
4148         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
4149
4150         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
4151         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
4152         local dd_pid=$!
4153
4154         # change max_pages_per_rpc while writing the file
4155         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
4156         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
4157         # loop until dd process exits
4158         while ps ax -opid | grep -wq $dd_pid; do
4159                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
4160                 sleep $((RANDOM % 5 + 1))
4161         done
4162         # restore original max_pages_per_rpc
4163         $LCTL set_param $osc1_mppc=$orig_mppc
4164         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
4165 }
4166 run_test 49 "Change max_pages_per_rpc won't break osc extent"
4167
4168 test_50() {
4169         # bug 1485
4170         test_mkdir $DIR/$tdir
4171         cd $DIR/$tdir
4172         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
4173 }
4174 run_test 50 "special situations: /proc symlinks  ==============="
4175
4176 test_51a() {    # was test_51
4177         # bug 1516 - create an empty entry right after ".." then split dir
4178         test_mkdir -c1 $DIR/$tdir
4179         touch $DIR/$tdir/foo
4180         $MCREATE $DIR/$tdir/bar
4181         rm $DIR/$tdir/foo
4182         createmany -m $DIR/$tdir/longfile 201
4183         FNUM=202
4184         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
4185                 $MCREATE $DIR/$tdir/longfile$FNUM
4186                 FNUM=$(($FNUM + 1))
4187                 echo -n "+"
4188         done
4189         echo
4190         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
4191 }
4192 run_test 51a "special situations: split htree with empty entry =="
4193
4194 cleanup_print_lfs_df () {
4195         trap 0
4196         $LFS df
4197         $LFS df -i
4198 }
4199
4200 test_51b() {
4201         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4202         local dir=$DIR/$tdir
4203
4204         local nrdirs=$((65536 + 100))
4205
4206         # cleanup the directory
4207         rm -fr $dir
4208
4209         test_mkdir -p -c1 $dir
4210
4211         $LFS df
4212         $LFS df -i
4213         local mdtidx=$(printf "%04x" $($LFS getstripe -M $dir))
4214         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
4215         [[ $numfree -lt $nrdirs ]] &&
4216                 skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
4217                 return
4218
4219         # need to check free space for the directories as well
4220         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
4221         numfree=$(( blkfree / $(fs_inode_ksize) ))
4222         [[ $numfree -lt $nrdirs ]] && skip "not enough blocks ($numfree)" &&
4223                 return
4224
4225         trap cleanup_print_lfs_df EXIT
4226
4227         # create files
4228         createmany -d $dir/d $nrdirs || {
4229                 unlinkmany $dir/d $nrdirs
4230                 error "failed to create $nrdirs subdirs in MDT$mdtidx:$dir"
4231         }
4232
4233         # really created :
4234         nrdirs=$(ls -U $dir | wc -l)
4235
4236         # unlink all but 100 subdirectories, then check it still works
4237         local left=100
4238         local delete=$((nrdirs - left))
4239
4240         $LFS df
4241         $LFS df -i
4242
4243         # for ldiskfs the nlink count should be 1, but this is OSD specific
4244         # and so this is listed for informational purposes only
4245         echo "nlink before: $(stat -c %h $dir), created before: $nrdirs"
4246         unlinkmany -d $dir/d $delete ||
4247                 error "unlink of first $delete subdirs failed"
4248
4249         echo "nlink between: $(stat -c %h $dir)"
4250         local found=$(ls -U $dir | wc -l)
4251         [ $found -ne $left ] &&
4252                 error "can't find subdirs: found only $found, expected $left"
4253
4254         unlinkmany -d $dir/d $delete $left ||
4255                 error "unlink of second $left subdirs failed"
4256         # regardless of whether the backing filesystem tracks nlink accurately
4257         # or not, the nlink count shouldn't be more than "." and ".." here
4258         local after=$(stat -c %h $dir)
4259         [[ $after -gt 2 ]] && error "nlink after: $after > 2" ||
4260                 echo "nlink after: $after"
4261
4262         cleanup_print_lfs_df
4263 }
4264 run_test 51b "exceed 64k subdirectory nlink limit on create, verify unlink"
4265
4266 test_51d() {
4267         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4268         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs" && return
4269         test_mkdir -p $DIR/$tdir
4270         createmany -o $DIR/$tdir/t- 1000
4271         $GETSTRIPE $DIR/$tdir > $TMP/$tfile
4272         for N in $(seq 0 $((OSTCOUNT - 1))); do
4273                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4274                         END { printf("%0.0f", objs) }' $TMP/$tfile)
4275                 OBJS0[$N]=$(grep -A 1 idx $TMP/$tfile | awk -vobjs=0 \
4276                         '($1 == '$N') { objs += 1 } \
4277                         END { printf("%0.0f", objs) }')
4278                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4279         done
4280         unlinkmany $DIR/$tdir/t- 1000
4281
4282         NLAST=0
4283         for N in $(seq 1 $((OSTCOUNT - 1))); do
4284                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4285                         error "OST $N has less objects vs OST $NLAST" \
4286                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4287                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4288                         error "OST $N has less objects vs OST $NLAST" \
4289                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4290
4291                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4292                         error "OST $N has less #0 objects vs OST $NLAST" \
4293                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4294                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4295                         error "OST $N has less #0 objects vs OST $NLAST" \
4296                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4297                 NLAST=$N
4298         done
4299         rm -f $TMP/$tfile
4300 }
4301 run_test 51d "check object distribution"
4302
4303 test_51e() {
4304         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4305                 skip "ldiskfs only test"
4306                 return
4307         fi
4308
4309         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4310         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4311
4312         touch $DIR/$tdir/d0/foo
4313         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4314                 error "file exceed 65000 nlink limit!"
4315         unlinkmany $DIR/$tdir/d0/f- 65001
4316         return 0
4317 }
4318 run_test 51e "check file nlink limit"
4319
4320 test_51f() {
4321         test_mkdir $DIR/$tdir
4322
4323         local max=100000
4324         local ulimit_old=$(ulimit -n)
4325         local spare=20 # number of spare fd's for scripts/libraries, etc.
4326         local mdt=$(lfs getstripe -M $DIR/$tdir)
4327         local numfree=$(lfs df -i $DIR/$tdir | awk '/MDT:'$mdt'/ { print $4 }')
4328
4329         echo "MDT$mdt numfree=$numfree, max=$max"
4330         [[ $numfree -gt $max ]] && numfree=$max || numfree=$((numfree * 7 / 8))
4331         if [ $((numfree + spare)) -gt $ulimit_old ]; then
4332                 while ! ulimit -n $((numfree + spare)); do
4333                         numfree=$((numfree * 3 / 4))
4334                 done
4335                 echo "changed ulimit from $ulimit_old to $((numfree + spare))"
4336         else
4337                 echo "left ulimit at $ulimit_old"
4338         fi
4339
4340         createmany -o -k -t 120 $DIR/$tdir/f $numfree || {
4341                 unlinkmany $DIR/$tdir/f $numfree
4342                 error "create+open $numfree files in $DIR/$tdir failed"
4343         }
4344         ulimit -n $ulimit_old
4345
4346         # if createmany exits at 120s there will be fewer than $numfree files
4347         unlinkmany $DIR/$tdir/f $numfree || true
4348 }
4349 run_test 51f "check many open files limit"
4350
4351 test_52a() {
4352         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4353         test_mkdir -p $DIR/$tdir
4354         touch $DIR/$tdir/foo
4355         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4356         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4357         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4358         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4359         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4360                                         error "link worked"
4361         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4362         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4363         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4364                                                      error "lsattr"
4365         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4366         cp -r $DIR/$tdir $TMP/
4367         rm -fr $DIR/$tdir $TMP/$tdir || error "cleanup rm failed"
4368 }
4369 run_test 52a "append-only flag test (should return errors)"
4370
4371 test_52b() {
4372         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4373         test_mkdir -p $DIR/$tdir
4374         touch $DIR/$tdir/foo
4375         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4376         cat test > $DIR/$tdir/foo && error "cat test worked"
4377         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4378         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4379         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4380                                         error "link worked"
4381         echo foo >> $DIR/$tdir/foo && error "echo worked"
4382         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4383         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4384         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4385         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4386                                                         error "lsattr"
4387         chattr -i $DIR/$tdir/foo || error "chattr failed"
4388
4389         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4390 }
4391 run_test 52b "immutable flag test (should return errors) ======="
4392
4393 test_53() {
4394         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4395         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4396         remote_ost_nodsh && skip "remote OST with nodsh" && return
4397
4398         local param
4399         local param_seq
4400         local ostname
4401         local mds_last
4402         local mds_last_seq
4403         local ost_last
4404         local ost_last_seq
4405         local ost_last_id
4406         local ostnum
4407         local node
4408         local found=false
4409         local support_last_seq=true
4410
4411         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4412                 support_last_seq=false
4413
4414         # only test MDT0000
4415         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4416         local value
4417         for value in $(do_facet $SINGLEMDS \
4418                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4419                 param=$(echo ${value[0]} | cut -d "=" -f1)
4420                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4421
4422                 if $support_last_seq; then
4423                         param_seq=$(echo $param |
4424                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4425                         mds_last_seq=$(do_facet $SINGLEMDS \
4426                                        $LCTL get_param -n $param_seq)
4427                 fi
4428                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4429
4430                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4431                 node=$(facet_active_host ost$((ostnum+1)))
4432                 param="obdfilter.$ostname.last_id"
4433                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4434                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4435                         ost_last_id=$ost_last
4436
4437                         if $support_last_seq; then
4438                                 ost_last_id=$(echo $ost_last |
4439                                               awk -F':' '{print $2}' |
4440                                               sed -e "s/^0x//g")
4441                                 ost_last_seq=$(echo $ost_last |
4442                                                awk -F':' '{print $1}')
4443                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4444                         fi
4445
4446                         if [[ $ost_last_id != $mds_last ]]; then
4447                                 error "$ost_last_id != $mds_last"
4448                         else
4449                                 found=true
4450                                 break
4451                         fi
4452                 done
4453         done
4454         $found || error "can not match last_seq/last_id for $mdtosc"
4455         return 0
4456 }
4457 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4458
4459 test_54a() {
4460         perl -MSocket -e ';' || { skip "no Socket perl module installed" && return; }
4461
4462         $SOCKETSERVER $DIR/socket ||
4463                 error "$SOCKETSERVER $DIR/socket failed: $?"
4464         $SOCKETCLIENT $DIR/socket ||
4465                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4466         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4467 }
4468 run_test 54a "unix domain socket test =========================="
4469
4470 test_54b() {
4471         f="$DIR/f54b"
4472         mknod $f c 1 3
4473         chmod 0666 $f
4474         dd if=/dev/zero of=$f bs=$(page_size) count=1
4475 }
4476 run_test 54b "char device works in lustre ======================"
4477
4478 find_loop_dev() {
4479         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4480         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4481         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4482
4483         for i in $(seq 3 7); do
4484                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4485                 LOOPDEV=$LOOPBASE$i
4486                 LOOPNUM=$i
4487                 break
4488         done
4489 }
4490
4491 cleanup_54c() {
4492         local rc=0
4493         loopdev="$DIR/loop54c"
4494
4495         trap 0
4496         $UMOUNT $DIR/$tdir || rc=$?
4497         losetup -d $loopdev || true
4498         losetup -d $LOOPDEV || true
4499         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4500         return $rc
4501 }
4502
4503 test_54c() {
4504         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4505         loopdev="$DIR/loop54c"
4506
4507         find_loop_dev
4508         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4509         trap cleanup_54c EXIT
4510         mknod $loopdev b 7 $LOOPNUM
4511         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4512         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4513         losetup $loopdev $DIR/$tfile ||
4514                 error "can't set up $loopdev for $DIR/$tfile"
4515         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4516         test_mkdir -p $DIR/$tdir
4517         mount -t ext2 $loopdev $DIR/$tdir ||
4518                 error "error mounting $loopdev on $DIR/$tdir"
4519         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4520                 error "dd write"
4521         df $DIR/$tdir
4522         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4523                 error "dd read"
4524         cleanup_54c
4525 }
4526 run_test 54c "block device works in lustre ====================="
4527
4528 test_54d() {
4529         f="$DIR/f54d"
4530         string="aaaaaa"
4531         mknod $f p
4532         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4533 }
4534 run_test 54d "fifo device works in lustre ======================"
4535
4536 test_54e() {
4537         f="$DIR/f54e"
4538         string="aaaaaa"
4539         cp -aL /dev/console $f
4540         echo $string > $f || error "echo $string to $f failed"
4541 }
4542 run_test 54e "console/tty device works in lustre ======================"
4543
4544 #The test_55 used to be iopen test and it was removed by bz#24037.
4545 #run_test 55 "check iopen_connect_dentry() ======================"
4546
4547 test_56a() {    # was test_56
4548         rm -rf $DIR/$tdir
4549         $SETSTRIPE -d $DIR
4550         test_mkdir -p $DIR/$tdir/dir
4551         NUMFILES=3
4552         NUMFILESx2=$(($NUMFILES * 2))
4553         for i in $(seq 1 $NUMFILES); do
4554                 touch $DIR/$tdir/file$i
4555                 touch $DIR/$tdir/dir/file$i
4556         done
4557
4558         # test lfs getstripe with --recursive
4559         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4560         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4561                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4562         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4563         [[ $FILENUM -eq $NUMFILES ]] ||
4564                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4565         echo "$GETSTRIPE --recursive passed."
4566
4567         # test lfs getstripe with file instead of dir
4568         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4569         [[ $FILENUM -eq 1 ]] ||
4570                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4571         echo "$GETSTRIPE file1 passed."
4572
4573         #test lfs getstripe with --verbose
4574         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4575                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4576                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4577         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4578                 error "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4579
4580         #test lfs getstripe with -v prints lmm_fid
4581         [[ $($GETSTRIPE -v $DIR/$tdir | grep -c lmm_fid) -eq $NUMFILES ]] ||
4582                 error "$GETSTRIPE -v $DIR/$tdir: want $NUMFILES lmm_fid: lines"
4583         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_fid) -eq 0 ]] ||
4584                 error "$GETSTRIPE $DIR/$tdir: showed lmm_fid"
4585         echo "$GETSTRIPE --verbose passed."
4586
4587         #check for FID information
4588         local fid1=$($GETSTRIPE --fid $DIR/$tdir/file1)
4589         local fid2=$($GETSTRIPE --verbose $DIR/$tdir/file1 |
4590                        awk '/lmm_fid: / { print $2 }')
4591         local fid3=$($LFS path2fid $DIR/$tdir/file1)
4592         [ "$fid1" != "$fid2" ] &&
4593                 error "getstripe --fid $fid1 != getstripe --verbose $fid2"
4594         [ "$fid1" != "$fid3" ] &&
4595                 error "getstripe --fid $fid1 != lfs path2fid $fid3"
4596         echo "$GETSTRIPE --fid passed."
4597
4598         #test lfs getstripe with --obd
4599         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4600                 grep -q "unknown obduuid" ||
4601                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4602
4603         [[ $OSTCOUNT -lt 2 ]] &&
4604                 skip_env "skipping other $GETSTRIPE --obd test" && return
4605
4606         OSTIDX=1
4607         OBDUUID=$(ostuuid_from_index $OSTIDX)
4608         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4609         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4610         [[ $FOUND -eq $FILENUM ]] ||
4611                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4612         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4613                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4614                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4615                 error "$GETSTRIPE --obd: should not show file on other obd"
4616         echo "$GETSTRIPE --obd passed"
4617 }
4618 run_test 56a "check $GETSTRIPE"
4619
4620 test_56b() {
4621         test_mkdir $DIR/$tdir
4622         NUMDIRS=3
4623         for i in $(seq 1 $NUMDIRS); do
4624                 test_mkdir $DIR/$tdir/dir$i
4625         done
4626
4627         # test lfs getdirstripe default mode is non-recursion, which is
4628         # different from lfs getstripe
4629         dircnt=$($LFS getdirstripe $DIR/$tdir | grep -c lmv_stripe_count)
4630         [[ $dircnt -eq 1 ]] ||
4631                 error "$LFS getdirstripe: found $dircnt, not 1"
4632         dircnt=$($LFS getdirstripe --recursive $DIR/$tdir |
4633                 grep -c lmv_stripe_count)
4634         [[ $dircnt -eq $((NUMDIRS + 1)) ]] ||
4635                 error "$LFS getdirstripe --recursive: found $dircnt, \
4636                         not $((NUMDIRS + 1))"
4637 }
4638 run_test 56b "check $LFS getdirstripe"
4639
4640 test_56c() {
4641         local ost_idx=0
4642         local ost_name=$(ostname_from_index $ost_idx)
4643
4644         local old_status=$(ost_dev_status $ost_idx)
4645         [[ -z "$old_status" ]] ||
4646                 { skip_env "OST $ost_name is in $old_status status"; return 0; }
4647
4648         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
4649         sleep_maxage
4650
4651         local new_status=$(ost_dev_status $ost_idx)
4652         [[ "$new_status" = "D" ]] ||
4653                 error "OST $ost_name is in status of '$new_status', not 'D'"
4654
4655         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=0
4656         sleep_maxage
4657
4658         new_status=$(ost_dev_status $ost_idx)
4659         [[ -z "$new_status" ]] ||
4660                 error "OST $ost_name is in status of '$new_status', not ''"
4661 }
4662 run_test 56c "check 'lfs df' showing device status"
4663
4664 NUMFILES=3
4665 NUMDIRS=3
4666 setup_56() {
4667         local LOCAL_NUMFILES="$1"
4668         local LOCAL_NUMDIRS="$2"
4669         local MKDIR_PARAMS="$3"
4670         local DIR_STRIPE_PARAMS="$4"
4671
4672         if [ ! -d "$TDIR" ] ; then
4673                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4674                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4675                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4676                         touch $TDIR/file$i
4677                 done
4678                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4679                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4680                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4681                                 touch $TDIR/dir$i/file$j
4682                         done
4683                 done
4684         fi
4685 }
4686
4687 setup_56_special() {
4688         LOCAL_NUMFILES=$1
4689         LOCAL_NUMDIRS=$2
4690         setup_56 $1 $2
4691         if [ ! -e "$TDIR/loop1b" ] ; then
4692                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4693                         mknod $TDIR/loop${i}b b 7 $i
4694                         mknod $TDIR/null${i}c c 1 3
4695                         ln -s $TDIR/file1 $TDIR/link${i}l
4696                 done
4697                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4698                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4699                         mknod $TDIR/dir$i/null${i}c c 1 3
4700                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4701                 done
4702         fi
4703 }
4704
4705 test_56g() {
4706         $SETSTRIPE -d $DIR
4707
4708         TDIR=$DIR/${tdir}g
4709         setup_56 $NUMFILES $NUMDIRS
4710
4711         EXPECTED=$(($NUMDIRS + 2))
4712         # test lfs find with -name
4713         for i in $(seq 1 $NUMFILES) ; do
4714                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4715                 [ $NUMS -eq $EXPECTED ] ||
4716                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4717                               "found $NUMS, expected $EXPECTED"
4718         done
4719 }
4720 run_test 56g "check lfs find -name ============================="
4721
4722 test_56h() {
4723         $SETSTRIPE -d $DIR
4724
4725         TDIR=$DIR/${tdir}g
4726         setup_56 $NUMFILES $NUMDIRS
4727
4728         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4729         # test lfs find with ! -name
4730         for i in $(seq 1 $NUMFILES) ; do
4731                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4732                 [ $NUMS -eq $EXPECTED ] ||
4733                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4734                               "found $NUMS, expected $EXPECTED"
4735         done
4736 }
4737 run_test 56h "check lfs find ! -name ============================="
4738
4739 test_56i() {
4740        tdir=${tdir}i
4741        test_mkdir -p $DIR/$tdir
4742        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4743        CMD="$LFIND -ost $UUID $DIR/$tdir"
4744        OUT=$($CMD)
4745        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4746 }
4747 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4748
4749 test_56j() {
4750         TDIR=$DIR/${tdir}g
4751         setup_56_special $NUMFILES $NUMDIRS
4752
4753         EXPECTED=$((NUMDIRS + 1))
4754         CMD="$LFIND -type d $TDIR"
4755         NUMS=$($CMD | wc -l)
4756         [ $NUMS -eq $EXPECTED ] ||
4757                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4758 }
4759 run_test 56j "check lfs find -type d ============================="
4760
4761 test_56k() {
4762         TDIR=$DIR/${tdir}g
4763         setup_56_special $NUMFILES $NUMDIRS
4764
4765         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4766         CMD="$LFIND -type f $TDIR"
4767         NUMS=$($CMD | wc -l)
4768         [ $NUMS -eq $EXPECTED ] ||
4769                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4770 }
4771 run_test 56k "check lfs find -type f ============================="
4772
4773 test_56l() {
4774         TDIR=$DIR/${tdir}g
4775         setup_56_special $NUMFILES $NUMDIRS
4776
4777         EXPECTED=$((NUMDIRS + NUMFILES))
4778         CMD="$LFIND -type b $TDIR"
4779         NUMS=$($CMD | wc -l)
4780         [ $NUMS -eq $EXPECTED ] ||
4781                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4782 }
4783 run_test 56l "check lfs find -type b ============================="
4784
4785 test_56m() {
4786         TDIR=$DIR/${tdir}g
4787         setup_56_special $NUMFILES $NUMDIRS
4788
4789         EXPECTED=$((NUMDIRS + NUMFILES))
4790         CMD="$LFIND -type c $TDIR"
4791         NUMS=$($CMD | wc -l)
4792         [ $NUMS -eq $EXPECTED ] ||
4793                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4794 }
4795 run_test 56m "check lfs find -type c ============================="
4796
4797 test_56n() {
4798         TDIR=$DIR/${tdir}g
4799         setup_56_special $NUMFILES $NUMDIRS
4800
4801         EXPECTED=$((NUMDIRS + NUMFILES))
4802         CMD="$LFIND -type l $TDIR"
4803         NUMS=$($CMD | wc -l)
4804         [ $NUMS -eq $EXPECTED ] ||
4805                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4806 }
4807 run_test 56n "check lfs find -type l ============================="
4808
4809 test_56o() {
4810         TDIR=$DIR/${tdir}o
4811         setup_56 $NUMFILES $NUMDIRS
4812         utime $TDIR/file1 > /dev/null || error "utime (1)"
4813         utime $TDIR/file2 > /dev/null || error "utime (2)"
4814         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4815         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4816         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4817         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4818
4819         EXPECTED=4
4820         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4821         [ $NUMS -eq $EXPECTED ] || \
4822                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4823
4824         EXPECTED=12
4825         CMD="$LFIND -mtime 0 $TDIR"
4826         NUMS=$($CMD | wc -l)
4827         [ $NUMS -eq $EXPECTED ] ||
4828                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4829 }
4830 run_test 56o "check lfs find -mtime for old files =========================="
4831
4832 test_56p() {
4833         [ $RUNAS_ID -eq $UID ] &&
4834                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4835
4836         TDIR=$DIR/${tdir}p
4837         setup_56 $NUMFILES $NUMDIRS
4838
4839         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4840         EXPECTED=$NUMFILES
4841         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4842         NUMS=$($CMD | wc -l)
4843         [ $NUMS -eq $EXPECTED ] || \
4844                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4845
4846         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4847         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4848         NUMS=$($CMD | wc -l)
4849         [ $NUMS -eq $EXPECTED ] || \
4850                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4851 }
4852 run_test 56p "check lfs find -uid and ! -uid ==============================="
4853
4854 test_56q() {
4855         [ $RUNAS_ID -eq $UID ] &&
4856                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4857
4858         TDIR=$DIR/${tdir}q
4859         setup_56 $NUMFILES $NUMDIRS
4860
4861         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4862
4863         EXPECTED=$NUMFILES
4864         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4865         NUMS=$($CMD | wc -l)
4866         [ $NUMS -eq $EXPECTED ] ||
4867                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4868
4869         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4870         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4871         NUMS=$($CMD | wc -l)
4872         [ $NUMS -eq $EXPECTED ] ||
4873                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4874 }
4875 run_test 56q "check lfs find -gid and ! -gid ==============================="
4876
4877 test_56r() {
4878         TDIR=$DIR/${tdir}r
4879         setup_56 $NUMFILES $NUMDIRS
4880
4881         EXPECTED=12
4882         CMD="$LFIND -size 0 -type f $TDIR"
4883         NUMS=$($CMD | wc -l)
4884         [ $NUMS -eq $EXPECTED ] ||
4885                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4886         EXPECTED=0
4887         CMD="$LFIND ! -size 0 -type f $TDIR"
4888         NUMS=$($CMD | wc -l)
4889         [ $NUMS -eq $EXPECTED ] ||
4890                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4891         echo "test" > $TDIR/$tfile
4892         echo "test2" > $TDIR/$tfile.2 && sync
4893         EXPECTED=1
4894         CMD="$LFIND -size 5 -type f $TDIR"
4895         NUMS=$($CMD | wc -l)
4896         [ $NUMS -eq $EXPECTED ] ||
4897                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4898         EXPECTED=1
4899         CMD="$LFIND -size +5 -type f $TDIR"
4900         NUMS=$($CMD | wc -l)
4901         [ $NUMS -eq $EXPECTED ] ||
4902                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4903         EXPECTED=2
4904         CMD="$LFIND -size +0 -type f $TDIR"
4905         NUMS=$($CMD | wc -l)
4906         [ $NUMS -eq $EXPECTED ] ||
4907                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4908         EXPECTED=2
4909         CMD="$LFIND ! -size -5 -type f $TDIR"
4910         NUMS=$($CMD | wc -l)
4911         [ $NUMS -eq $EXPECTED ] ||
4912                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4913         EXPECTED=12
4914         CMD="$LFIND -size -5 -type f $TDIR"
4915         NUMS=$($CMD | wc -l)
4916         [ $NUMS -eq $EXPECTED ] ||
4917                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4918 }
4919 run_test 56r "check lfs find -size works =========================="
4920
4921 test_56s() { # LU-611
4922         TDIR=$DIR/${tdir}s
4923
4924         #LU-9369
4925         setup_56 0 $NUMDIRS
4926         for i in $(seq 1 $NUMDIRS); do
4927                 $SETSTRIPE -c $((OSTCOUNT + 1)) $TDIR/dir$i/$tfile
4928         done
4929         EXPECTED=$NUMDIRS
4930         CMD="$LFIND -c $OSTCOUNT $TDIR"
4931         NUMS=$($CMD | wc -l)
4932         [ $NUMS -eq $EXPECTED ] || {
4933                 $GETSTRIPE -R $TDIR
4934                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4935         }
4936         rm -rf $TDIR
4937
4938         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4939         if [[ $OSTCOUNT -gt 1 ]]; then
4940                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4941                 ONESTRIPE=4
4942                 EXTRA=4
4943         else
4944                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4945                 EXTRA=0
4946         fi
4947
4948         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4949         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4950         NUMS=$($CMD | wc -l)
4951         [ $NUMS -eq $EXPECTED ] || {
4952                 $GETSTRIPE -R $TDIR
4953                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4954         }
4955
4956         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4957         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4958         NUMS=$($CMD | wc -l)
4959         [ $NUMS -eq $EXPECTED ] || {
4960                 $GETSTRIPE -R $TDIR
4961                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4962         }
4963
4964         EXPECTED=$ONESTRIPE
4965         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4966         NUMS=$($CMD | wc -l)
4967         [ $NUMS -eq $EXPECTED ] || {
4968                 $GETSTRIPE -R $TDIR
4969                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4970         }
4971
4972         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4973         NUMS=$($CMD | wc -l)
4974         [ $NUMS -eq $EXPECTED ] || {
4975                 $GETSTRIPE -R $TDIR
4976                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4977         }
4978
4979         EXPECTED=0
4980         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4981         NUMS=$($CMD | wc -l)
4982         [ $NUMS -eq $EXPECTED ] || {
4983                 $GETSTRIPE -R $TDIR
4984                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4985         }
4986 }
4987 run_test 56s "check lfs find -stripe-count works"
4988
4989 test_56t() { # LU-611
4990         TDIR=$DIR/${tdir}t
4991
4992         #LU-9369
4993         setup_56 0 $NUMDIRS
4994         for i in $(seq 1 $NUMDIRS); do
4995                 $SETSTRIPE -S 4M $TDIR/dir$i/$tfile
4996         done
4997         EXPECTED=$NUMDIRS
4998         CMD="$LFIND -S 4M $TDIR"
4999         NUMS=$($CMD | wc -l)
5000         [ $NUMS -eq $EXPECTED ] || {
5001                 $GETSTRIPE -R $TDIR
5002                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5003         }
5004         rm -rf $TDIR
5005
5006         setup_56 $NUMFILES $NUMDIRS "--stripe-size 512k"
5007
5008         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
5009
5010         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
5011         CMD="$LFIND -stripe-size 512k -type f $TDIR"
5012         NUMS=$($CMD | wc -l)
5013         [ $NUMS -eq $EXPECTED ] ||
5014                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5015
5016         CMD="$LFIND -stripe-size +320k -type f $TDIR"
5017         NUMS=$($CMD | wc -l)
5018         [ $NUMS -eq $EXPECTED ] ||
5019                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5020
5021         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
5022         CMD="$LFIND -stripe-size +200k -type f $TDIR"
5023         NUMS=$($CMD | wc -l)
5024         [ $NUMS -eq $EXPECTED ] ||
5025                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5026
5027         CMD="$LFIND -stripe-size -640k -type f $TDIR"
5028         NUMS=$($CMD | wc -l)
5029         [ $NUMS -eq $EXPECTED ] ||
5030                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5031
5032         EXPECTED=4
5033         CMD="$LFIND -stripe-size 256k -type f $TDIR"
5034         NUMS=$($CMD | wc -l)
5035         [ $NUMS -eq $EXPECTED ] ||
5036                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5037
5038         CMD="$LFIND -stripe-size -320k -type f $TDIR"
5039         NUMS=$($CMD | wc -l)
5040         [ $NUMS -eq $EXPECTED ] ||
5041                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5042
5043         EXPECTED=0
5044         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
5045         NUMS=$($CMD | wc -l)
5046         [ $NUMS -eq $EXPECTED ] ||
5047                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5048 }
5049 run_test 56t "check lfs find -stripe-size works"
5050
5051 test_56u() { # LU-611
5052         TDIR=$DIR/${tdir}u
5053         setup_56 $NUMFILES $NUMDIRS "-i 0"
5054
5055         if [[ $OSTCOUNT -gt 1 ]]; then
5056                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
5057                 ONESTRIPE=4
5058         else
5059                 ONESTRIPE=0
5060         fi
5061
5062         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
5063         CMD="$LFIND -stripe-index 0 -type f $TDIR"
5064         NUMS=$($CMD | wc -l)
5065         [ $NUMS -eq $EXPECTED ] ||
5066                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5067
5068         EXPECTED=$ONESTRIPE
5069         CMD="$LFIND -stripe-index 1 -type f $TDIR"
5070         NUMS=$($CMD | wc -l)
5071         [ $NUMS -eq $EXPECTED ] ||
5072                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5073
5074         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
5075         NUMS=$($CMD | wc -l)
5076         [ $NUMS -eq $EXPECTED ] ||
5077                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5078
5079         EXPECTED=0
5080         # This should produce an error and not return any files
5081         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
5082         NUMS=$($CMD 2>/dev/null | wc -l)
5083         [ $NUMS -eq $EXPECTED ] ||
5084                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5085
5086         if [[ $OSTCOUNT -gt 1 ]]; then
5087                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
5088                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
5089                 NUMS=$($CMD | wc -l)
5090                 [ $NUMS -eq $EXPECTED ] ||
5091                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
5092         fi
5093 }
5094 run_test 56u "check lfs find -stripe-index works"
5095
5096 test_56v() {
5097     local MDT_IDX=0
5098
5099     TDIR=$DIR/${tdir}v
5100     rm -rf $TDIR
5101     setup_56 $NUMFILES $NUMDIRS
5102
5103     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
5104     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
5105
5106     for file in $($LFIND -mdt $UUID $TDIR); do
5107         file_mdt_idx=$($GETSTRIPE -M $file)
5108         [ $file_mdt_idx -eq $MDT_IDX ] ||
5109             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
5110     done
5111 }
5112 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
5113
5114 test_56w() {
5115         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5116         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5117         TDIR=$DIR/${tdir}w
5118
5119         rm -rf $TDIR || error "remove $TDIR failed"
5120         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
5121
5122         local stripe_size
5123         stripe_size=$($GETSTRIPE -S -d $TDIR) ||
5124                 error "$GETSTRIPE -S -d $TDIR failed"
5125         stripe_size=${stripe_size%% *}
5126
5127         local file_size=$((stripe_size * OSTCOUNT))
5128         local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
5129         local required_space=$((file_num * file_size))
5130
5131         local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
5132                            head -n1)
5133         [[ $free_space -le $((required_space / 1024)) ]] &&
5134                 skip_env "need $required_space bytes, have $free_space KB" &&
5135                 return
5136
5137         local dd_bs=65536
5138         local dd_count=$((file_size / dd_bs))
5139
5140         # write data into the files
5141         local i
5142         local j
5143         local file
5144         for i in $(seq 1 $NUMFILES); do
5145                 file=$TDIR/file$i
5146                 yes | dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
5147                         error "write data into $file failed"
5148         done
5149         for i in $(seq 1 $NUMDIRS); do
5150                 for j in $(seq 1 $NUMFILES); do
5151                         file=$TDIR/dir$i/file$j
5152                         yes|dd bs=$dd_bs count=$dd_count of=$file &>/dev/null ||
5153                                 error "write data into $file failed"
5154                 done
5155         done
5156
5157         # $LFS_MIGRATE will fail if hard link migration is unsupported
5158         if [[ $(lustre_version_code mds1) -gt $(version_code 2.5.55) ]]; then
5159                 createmany -l$TDIR/dir1/file1 $TDIR/dir1/link 200 ||
5160                         error "creating links to $TDIR/dir1/file1 failed"
5161         fi
5162
5163         local expected=-1
5164         [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
5165
5166         # lfs_migrate file
5167         local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
5168         echo "$cmd"
5169         eval $cmd || error "$cmd failed"
5170
5171         check_stripe_count $TDIR/file1 $expected
5172
5173         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
5174         then
5175                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
5176                 # OST 1 if it is on OST 0. This file is small enough to
5177                 # be on only one stripe.
5178                 file=$TDIR/migr_1_ost
5179                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
5180                         error "write data into $file failed"
5181                 local obdidx=$($LFS getstripe -i $file)
5182                 local oldmd5=$(md5sum $file)
5183                 local newobdidx=0
5184                 [[ $obdidx -eq 0 ]] && newobdidx=1
5185                 cmd="$LFS migrate -i $newobdidx $file"
5186                 echo $cmd
5187                 eval $cmd || error "$cmd failed"
5188                 local realobdix=$($LFS getstripe -i $file)
5189                 local newmd5=$(md5sum $file)
5190                 [[ $newobdidx -ne $realobdix ]] &&
5191                         error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
5192                 [[ "$oldmd5" != "$newmd5" ]] &&
5193                         error "md5sum differ: $oldmd5, $newmd5"
5194         fi
5195
5196     # lfs_migrate dir
5197     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
5198     echo "$cmd"
5199     eval $cmd || error "$cmd failed"
5200
5201     for j in $(seq 1 $NUMFILES); do
5202         check_stripe_count $TDIR/dir1/file$j $expected
5203     done
5204
5205     # lfs_migrate works with lfs find
5206     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
5207          $LFS_MIGRATE -y -c $expected"
5208     echo "$cmd"
5209     eval $cmd || error "$cmd failed"
5210
5211     for i in $(seq 2 $NUMFILES); do
5212         check_stripe_count $TDIR/file$i $expected
5213     done
5214     for i in $(seq 2 $NUMDIRS); do
5215         for j in $(seq 1 $NUMFILES); do
5216             check_stripe_count $TDIR/dir$i/file$j $expected
5217         done
5218     done
5219 }
5220 run_test 56w "check lfs_migrate -c stripe_count works"
5221
5222 test_56x() {
5223         check_swap_layouts_support && return 0
5224         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5225
5226         local dir0=$DIR/$tdir
5227         local ref1=/etc/passwd
5228         local file1=$dir0/file1
5229
5230         test_mkdir $dir0 || error "creating dir $dir0"
5231         $LFS setstripe -c 2 $file1
5232         cp $ref1 $file1
5233         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
5234         stripe=$($LFS getstripe -c $file1)
5235         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5236         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5237
5238         # clean up
5239         rm -f $file1
5240 }
5241 run_test 56x "lfs migration support"
5242
5243 test_56xa() {
5244         check_swap_layouts_support && return 0
5245         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
5246
5247         local dir0=$DIR/$tdir/$testnum
5248         test_mkdir -p $dir0 || error "creating dir $dir0"
5249
5250         local ref1=/etc/passwd
5251         local file1=$dir0/file1
5252
5253         $LFS setstripe -c 2 $file1
5254         cp $ref1 $file1
5255         $LFS migrate --block -c 1 $file1 || error "migrate failed rc = $?"
5256         local stripe=$($LFS getstripe -c $file1)
5257         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
5258         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
5259
5260         # clean up
5261         rm -f $file1
5262 }
5263 run_test 56xa "lfs migration --block support"
5264
5265 check_migrate_links() {
5266         local dir="$1"
5267         local file1="$dir/file1"
5268         local begin="$2"
5269         local count="$3"
5270         local total_count=$(($begin + $count - 1))
5271         local symlink_count=10
5272         local uniq_count=10
5273
5274         if [ ! -f "$file1" ]; then
5275                 echo -n "creating initial file..."
5276                 $LFS setstripe -c 1 -S "512k" "$file1" ||
5277                         error "cannot setstripe initial file"
5278                 echo "done"
5279
5280                 echo -n "creating symlinks..."
5281                 for s in $(seq 1 $symlink_count); do
5282                         ln -s "$file1" "$dir/slink$s" ||
5283                                 error "cannot create symlinks"
5284                 done
5285                 echo "done"
5286
5287                 echo -n "creating nonlinked files..."
5288                 createmany -o "$dir/uniq" 1 10 &> /dev/null ||
5289                         error "cannot create nonlinked files"
5290                 echo "done"
5291         fi
5292
5293         # create hard links
5294         if [ ! -f "$dir/file$total_count" ]; then
5295                 echo -n "creating hard links $begin:$total_count..."
5296                 createmany -l"$file1" "$dir/file" "$begin" "$count" &>  \
5297                         /dev/null || error "cannot create hard links"
5298                 echo "done"
5299         fi
5300
5301         echo -n "checking number of hard links listed in xattrs..."
5302         local fid=$($LFS getstripe -F "$file1")
5303         local paths=($($LFS fid2path "$MOUNT" "$fid" 2> /dev/null))
5304
5305         echo "${#paths[*]}"
5306         if [ ${#paths[*]} -lt $total_count -a "$begin" -eq 2  ]; then
5307                         echo "hard link list has unexpected size, skipping test"
5308                         return 0
5309         fi
5310         if [ ${#paths[*]} -ge $total_count -a "$begin" -ne 2  ]; then
5311                         error "link names should exceed xattrs size"
5312         fi
5313
5314         echo -n "migrating files..."
5315         local migrate_out=$($LFS_MIGRATE -y -S '1m' $dir)
5316         local rc=$?
5317         [ $rc -eq 0 ] || error "migrate failed rc = $rc"
5318         echo "done"
5319
5320         # make sure all links have been properly migrated
5321         echo -n "verifying files..."
5322         fid=$($LFS getstripe -F "$file1") ||
5323                 error "cannot get fid for file $file1"
5324         for i in $(seq 2 $total_count); do
5325                 local fid2=$($LFS getstripe -F $dir/file$i)
5326                 [ "$fid2" == "$fid" ] ||
5327                         error "migrated hard link has mismatched FID"
5328         done
5329
5330         # make sure hard links were properly detected, and migration was
5331         # performed only once for the entire link set; nonlinked files should
5332         # also be migrated
5333         local actual=$(grep -c 'done migrate' <<< "$migrate_out")
5334         local expected=$(($uniq_count + 1))
5335         [ "$actual" -eq  "$expected" ] ||
5336                 error "hard links individually migrated ($actual != $expected)"
5337
5338         # make sure the correct number of hard links are present
5339         local hardlinks=$(stat -c '%h' "$file1")
5340         [ $hardlinks -eq $total_count ] ||
5341                 error "num hard links $hardlinks != $total_count"
5342         echo "done"
5343
5344         return 0
5345 }
5346
5347 test_56xb() {
5348         local dir0="$DIR/$tdir"
5349
5350         test_mkdir "$dir0" || error "cannot create dir $dir0"
5351
5352         echo "testing lfs migrate mode when all links fit within xattrs"
5353         LFS_MIGRATE_RSYNC=false check_migrate_links "$dir0" 2 99
5354
5355         echo "testing rsync mode when all links fit within xattrs"
5356         LFS_MIGRATE_RSYNC=true check_migrate_links "$dir0" 2 99
5357
5358         echo "testing lfs migrate mode when all links do not fit within xattrs"
5359         LFS_MIGRATE_RSYNC=false check_migrate_links "$dir0" 101 100
5360
5361         echo "testing rsync mode when all links do not fit within xattrs"
5362         LFS_MIGRATE_RSYNC=true check_migrate_links "$dir0" 101 100
5363
5364         # clean up
5365         rm -rf $dir0
5366 }
5367 run_test 56xb "lfs migration hard link support"
5368
5369 test_56y() {
5370         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
5371                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
5372                 return
5373
5374         local res=""
5375         local dir0=$DIR/$tdir/$testnum
5376         test_mkdir -p $dir0 || error "creating dir $dir0"
5377         local f1=$dir0/file1
5378         local f2=$dir0/file2
5379
5380         touch $f1 || error "creating std file $f1"
5381         $MULTIOP $f2 H2c || error "creating released file $f2"
5382
5383         # a directory can be raid0, so ask only for files
5384         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
5385         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
5386
5387         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
5388         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
5389
5390         # only files can be released, so no need to force file search
5391         res=$($LFIND $dir0 -L released)
5392         [[ $res == $f2 ]] || error "search released: found $res != $f2"
5393
5394         res=$($LFIND $dir0 \! -L released)
5395         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
5396
5397 }
5398 run_test 56y "lfs find -L raid0|released"
5399
5400 test_56z() { # LU-4824
5401         # This checks to make sure 'lfs find' continues after errors
5402         # There are two classes of errors that should be caught:
5403         # - If multiple paths are provided, all should be searched even if one
5404         #   errors out
5405         # - If errors are encountered during the search, it should not terminate
5406         #   early
5407         local i
5408         test_mkdir $DIR/$tdir
5409         for i in d{0..9}; do
5410                 test_mkdir $DIR/$tdir/$i
5411         done
5412         touch $DIR/$tdir/d{0..9}/$tfile
5413         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
5414                 error "$LFS find did not return an error"
5415         # Make a directory unsearchable. This should NOT be the last entry in
5416         # directory order.  Arbitrarily pick the 6th entry
5417         chmod 700 $($LFS find $DIR/$tdir -type d | sed '6!d')
5418         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
5419         # The user should be able to see 10 directories and 9 files
5420         [ $count == 19 ] || error "$LFS find did not continue after error"
5421 }
5422 run_test 56z "lfs find should continue after an error"
5423
5424 test_56aa() { # LU-5937
5425         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5426
5427         mkdir $DIR/$tdir
5428         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
5429
5430         createmany -o $DIR/$tdir/striped_dir/${tfile}- 1024
5431         local dirs=$(lfs find --size +8k $DIR/$tdir/)
5432
5433         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5434 }
5435 run_test 56aa "lfs find --size under striped dir"
5436
5437 test_57a() {
5438         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5439         # note test will not do anything if MDS is not local
5440         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5441                 skip "ldiskfs only test"
5442                 return
5443         fi
5444
5445         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5446         local MNTDEV="osd*.*MDT*.mntdev"
5447         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
5448         [ -z "$DEV" ] && error "can't access $MNTDEV"
5449         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
5450                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
5451                         error "can't access $DEV"
5452                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
5453                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
5454                 rm $TMP/t57a.dump
5455         done
5456 }
5457 run_test 57a "verify MDS filesystem created with large inodes =="
5458
5459 test_57b() {
5460         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5461         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5462                 skip "ldiskfs only test"
5463                 return
5464         fi
5465
5466         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5467         local dir=$DIR/$tdir
5468
5469         local FILECOUNT=100
5470         local FILE1=$dir/f1
5471         local FILEN=$dir/f$FILECOUNT
5472
5473         rm -rf $dir || error "removing $dir"
5474         test_mkdir -p -c1 $dir || error "creating $dir"
5475         local mdtidx=$($LFS getstripe -M $dir)
5476         local mdtname=MDT$(printf %04x $mdtidx)
5477         local facet=mds$((mdtidx + 1))
5478
5479         echo "mcreating $FILECOUNT files"
5480         createmany -m $dir/f 1 $FILECOUNT || \
5481                 error "creating files in $dir"
5482
5483         # verify that files do not have EAs yet
5484         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5485         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5486
5487         sync
5488         sleep 1
5489         df $dir  #make sure we get new statfs data
5490         local MDSFREE=$(do_facet $facet \
5491                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5492         local MDCFREE=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5493         echo "opening files to create objects/EAs"
5494         local FILE
5495         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5496                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5497         done
5498
5499         # verify that files have EAs now
5500         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5501         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5502
5503         sleep 1  #make sure we get new statfs data
5504         df $dir
5505         local MDSFREE2=$(do_facet $facet \
5506                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5507         local MDCFREE2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5508         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5509                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5510                         error "MDC before $MDCFREE != after $MDCFREE2"
5511                 else
5512                         echo "MDC before $MDCFREE != after $MDCFREE2"
5513                         echo "unable to confirm if MDS has large inodes"
5514                 fi
5515         fi
5516         rm -rf $dir
5517 }
5518 run_test 57b "default LOV EAs are stored inside large inodes ==="
5519
5520 test_58() {
5521         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5522         [ -z "$(which wiretest 2>/dev/null)" ] &&
5523                         skip_env "could not find wiretest" && return
5524         wiretest
5525 }
5526 run_test 58 "verify cross-platform wire constants =============="
5527
5528 test_59() {
5529         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5530         echo "touch 130 files"
5531         createmany -o $DIR/f59- 130
5532         echo "rm 130 files"
5533         unlinkmany $DIR/f59- 130
5534         sync
5535         # wait for commitment of removal
5536         wait_delete_completed
5537 }
5538 run_test 59 "verify cancellation of llog records async ========="
5539
5540 TEST60_HEAD="test_60 run $RANDOM"
5541 test_60a() {
5542         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5543         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5544         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5545                 do_facet mgs "! ls run-llog.sh &> /dev/null" &&
5546                         skip_env "missing subtest run-llog.sh" && return
5547
5548         log "$TEST60_HEAD - from kernel mode"
5549         do_facet mgs "$LCTL set_param debug=warning; $LCTL dk > /dev/null"
5550         do_facet mgs sh run-llog.sh
5551         do_facet mgs $LCTL dk > $TMP/$tfile
5552
5553         # LU-6388: test llog_reader
5554         local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5555         llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5556         [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5557                         skip_env "missing llog_reader" && return
5558         local fstype=$(facet_fstype mgs)
5559         [ $fstype != ldiskfs -a $fstype != zfs ] &&
5560                 skip_env "Only for ldiskfs or zfs type mgs" && return
5561
5562         local mntpt=$(facet_mntpt mgs)
5563         local mgsdev=$(mgsdevname 1)
5564         local fid_list
5565         local fid
5566         local rec_list
5567         local rec
5568         local rec_type
5569         local obj_file
5570         local path
5571         local seq
5572         local oid
5573         local pass=true
5574
5575         #get fid and record list
5576         fid_list=($(awk '/9_sub.*record/ { print $NF }' /$TMP/$tfile |
5577                 tail -n 4))
5578         rec_list=($(awk '/9_sub.*record/ { print $((NF-3)) }' /$TMP/$tfile |
5579                 tail -n 4))
5580         #remount mgs as ldiskfs or zfs type
5581         stop mgs || error "stop mgs failed"
5582         mount_fstype mgs || error "remount mgs failed"
5583         for ((i = 0; i < ${#fid_list[@]}; i++)); do
5584                 fid=${fid_list[i]}
5585                 rec=${rec_list[i]}
5586                 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
5587                 oid=$(echo $fid | awk -F ':' '{ print $2 }' | sed -e "s/^0x//g")
5588                 oid=$((16#$oid))
5589
5590                 case $fstype in
5591                         ldiskfs )
5592                                 obj_file=$mntpt/O/$seq/d$((oid%32))/$oid ;;
5593                         zfs )
5594                                 obj_file=$mntpt/oi.$(($((16#$seq))&127))/$fid ;;
5595                 esac
5596                 echo "obj_file is $obj_file"
5597                 do_facet mgs $llog_reader $obj_file
5598
5599                 rec_type=$(do_facet mgs $llog_reader $obj_file | grep "type=" |
5600                         awk '{ print $3 }' | sed -e "s/^type=//g")
5601                 if [ $rec_type != $rec ]; then
5602                         echo "FAILED test_60a wrong record type $rec_type," \
5603                               "should be $rec"
5604                         pass=false
5605                         break
5606                 fi
5607
5608                 #check obj path if record type is LLOG_LOGID_MAGIC
5609                 if [ "$rec" == "1064553b" ]; then
5610                         path=$(do_facet mgs $llog_reader $obj_file |
5611                                 grep "path=" | awk '{ print $NF }' |
5612                                 sed -e "s/^path=//g")
5613                         if [ $obj_file != $mntpt/$path ]; then
5614                                 echo "FAILED test_60a wrong obj path" \
5615                                       "$montpt/$path, should be $obj_file"
5616                                 pass=false
5617                                 break
5618                         fi
5619                 fi
5620         done
5621         rm -f $TMP/$tfile
5622         #restart mgs before "error", otherwise it will block the next test
5623         stop mgs || error "stop mgs failed"
5624         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
5625         $pass || error "test failed, see FAILED test_60a messages for specifics"
5626 }
5627 run_test 60a "llog_test run from kernel module and test llog_reader"
5628
5629 test_60aa() {
5630         # test old logid format
5631         if [ $(lustre_version_code mgs) -le $(version_code 3.1.53) ]; then
5632                 do_facet mgs $LCTL dl | grep MGS
5633                 do_facet mgs "$LCTL --device %MGS llog_print \\\\\\\$$FSNAME-client" ||
5634                         error "old llog_print failed"
5635         fi
5636
5637         # test new logid format
5638         if [ $(lustre_version_code mgs) -ge $(version_code 2.9.53) ]; then
5639                 do_facet mgs "$LCTL --device MGS llog_print $FSNAME-client" ||
5640                         error "new llog_print failed"
5641         fi
5642 }
5643 run_test 60aa "llog_print works with FIDs and simple names"
5644
5645 test_60b() { # bug 6411
5646         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5647         dmesg > $DIR/$tfile
5648         LLOG_COUNT=$(dmesg | awk "/$TEST60_HEAD/ { marker = 1; from_marker = 0; }
5649                                 /llog.test/ {
5650                                         if (marker)
5651                                                 from_marker++
5652                                         from_begin++
5653                                 }
5654                                 END {
5655                                         if (marker)
5656                                                 print from_marker
5657                                         else
5658                                                 print from_begin
5659                                 }")
5660         [[ $LLOG_COUNT -gt 100 ]] &&
5661                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5662 }
5663 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5664
5665 test_60c() {
5666         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5667         echo "create 5000 files"
5668         createmany -o $DIR/f60c- 5000
5669 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5670         lctl set_param fail_loc=0x80000137
5671         unlinkmany $DIR/f60c- 5000
5672         lctl set_param fail_loc=0
5673 }
5674 run_test 60c "unlink file when mds full"
5675
5676 test_60d() {
5677         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5678         SAVEPRINTK=$(lctl get_param -n printk)
5679
5680         # verify "lctl mark" is even working"
5681         MESSAGE="test message ID $RANDOM $$"
5682         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5683         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5684
5685         lctl set_param printk=0 || error "set lnet.printk failed"
5686         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5687         MESSAGE="new test message ID $RANDOM $$"
5688         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5689         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5690         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5691
5692         lctl set_param -n printk="$SAVEPRINTK"
5693 }
5694 run_test 60d "test printk console message masking"
5695
5696 test_60e() {
5697         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5698         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5699         touch $DIR/$tfile
5700 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED2  0x15b
5701         do_facet mds1 lctl set_param fail_loc=0x15b
5702         rm $DIR/$tfile
5703 }
5704 run_test 60e "no space while new llog is being created"
5705
5706 test_61() {
5707         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5708         f="$DIR/f61"
5709         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5710         cancel_lru_locks osc
5711         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5712         sync
5713 }
5714 run_test 61 "mmap() writes don't make sync hang ================"
5715
5716 # bug 2330 - insufficient obd_match error checking causes LBUG
5717 test_62() {
5718         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5719         f="$DIR/f62"
5720         echo foo > $f
5721         cancel_lru_locks osc
5722         lctl set_param fail_loc=0x405
5723         cat $f && error "cat succeeded, expect -EIO"
5724         lctl set_param fail_loc=0
5725 }
5726 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5727 # match every page all of the time.
5728 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5729
5730 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5731 # Though this test is irrelevant anymore, it helped to reveal some
5732 # other grant bugs (LU-4482), let's keep it.
5733 test_63a() {   # was test_63
5734         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5735         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5736         for i in `seq 10` ; do
5737                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5738                 sleep 5
5739                 kill $!
5740                 sleep 1
5741         done
5742
5743         rm -f $DIR/f63 || true
5744 }
5745 run_test 63a "Verify oig_wait interruption does not crash ======="
5746
5747 # bug 2248 - async write errors didn't return to application on sync
5748 # bug 3677 - async write errors left page locked
5749 test_63b() {
5750         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5751         debugsave
5752         lctl set_param debug=-1
5753
5754         # ensure we have a grant to do async writes
5755         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5756         rm $DIR/$tfile
5757
5758         sync    # sync lest earlier test intercept the fail_loc
5759
5760         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5761         lctl set_param fail_loc=0x80000406
5762         $MULTIOP $DIR/$tfile Owy && \
5763                 error "sync didn't return ENOMEM"
5764         sync; sleep 2; sync     # do a real sync this time to flush page
5765         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5766                 error "locked page left in cache after async error" || true
5767         debugrestore
5768 }
5769 run_test 63b "async write errors should be returned to fsync ==="
5770
5771 test_64a () {
5772         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5773         df $DIR
5774         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5775 }
5776 run_test 64a "verify filter grant calculations (in kernel) ====="
5777
5778 test_64b () {
5779         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5780         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5781 }
5782 run_test 64b "check out-of-space detection on client ==========="
5783
5784 test_64c() {
5785         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5786 }
5787 run_test 64c "verify grant shrink ========================------"
5788
5789 # this does exactly what osc_request.c:osc_announce_cached() does in
5790 # order to calculate max amount of grants to ask from server
5791 want_grant() {
5792         local tgt=$1
5793
5794         local page_size=$(get_page_size client)
5795
5796         local nrpages=$($LCTL get_param -n osc.${tgt}.max_pages_per_rpc)
5797         local rpc_in_flight=$($LCTL get_param -n osc.${tgt}.max_rpcs_in_flight)
5798
5799         ((rpc_in_flight ++));
5800         nrpages=$((nrpages * rpc_in_flight))
5801
5802         local dirty_max_pages=$($LCTL get_param -n osc.${tgt}.max_dirty_mb)
5803
5804         dirty_max_pages=$((dirty_max_pages * 1024 * 1024 / page_size))
5805
5806         [[ $dirty_max_pages -gt $nrpages ]] && nrpages=$dirty_max_pages
5807         local undirty=$((nrpages * page_size))
5808
5809         local max_extent_pages
5810         max_extent_pages=$($LCTL get_param osc.${tgt}.import |
5811             grep grant_max_extent_size | awk '{print $2}')
5812         max_extent_pages=$((max_extent_pages / page_size))
5813         local nrextents=$(((nrpages + max_extent_pages - 1) / max_extent_pages))
5814         local grant_extent_tax
5815         grant_extent_tax=$($LCTL get_param osc.${tgt}.import |
5816             grep grant_extent_tax | awk '{print $2}')
5817
5818         undirty=$((undirty + nrextents * grant_extent_tax))
5819
5820         echo $undirty
5821 }
5822
5823 # this is size of unit for grant allocation. It should be equal to
5824 # what tgt_grant.c:tgt_grant_chunk() calculates
5825 grant_chunk() {
5826         local tgt=$1
5827         local max_brw_size
5828         local grant_extent_tax
5829
5830         max_brw_size=$($LCTL get_param osc.${tgt}.import |
5831             grep max_brw_size | awk '{print $2}')
5832
5833         grant_extent_tax=$($LCTL get_param osc.${tgt}.import |
5834             grep grant_extent_tax | awk '{print $2}')
5835
5836         echo $(((max_brw_size + grant_extent_tax) * 2))
5837 }
5838
5839 test_64d() {
5840         [ $(lustre_version_code ost1) -lt $(version_code 2.10.56) ] &&
5841                 skip "OST < 2.10.55 doesn't limit grants enough" && return 0
5842
5843         local tgt=$($LCTL dl | grep "0000-osc-[^mM]" | awk '{print $4}')
5844
5845         [[ $($LCTL get_param osc.${tgt}.import |
5846                     grep "connect_flags:.*grant_param") ]] || \
5847                         { skip "no grant_param connect flag"; return; }
5848
5849         local olddebug=$($LCTL get_param -n debug 2> /dev/null)
5850
5851         $LCTL set_param debug="$OLDDEBUG" 2> /dev/null || true
5852
5853         local max_cur_granted=$(($(want_grant $tgt) + $(grant_chunk $tgt)))
5854
5855         $SETSTRIPE $DIR/$tfile -i 0 -c 1
5856         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1000 &
5857         ddpid=$!
5858
5859         while true
5860         do
5861                 local cur_grant=$($LCTL get_param -n osc.${tgt}.cur_grant_bytes)
5862                 if [[ $cur_grant -gt $max_cur_granted ]]
5863                 then
5864                         kill $ddpid
5865                         error "cur_grant $cur_grant > $max_cur_granted"
5866                 fi
5867                 kill -0 $ddpid
5868                 [[ $? -ne 0 ]] && break;
5869                 sleep 2
5870         done
5871         $LCTL set_param debug="$olddebug" 2> /dev/null || true
5872 }
5873 run_test 64d "check grant limit exceed"
5874
5875 # bug 1414 - set/get directories' stripe info
5876 test_65a() {
5877         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5878         test_mkdir -p $DIR/$tdir
5879         touch $DIR/$tdir/f1
5880         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5881 }
5882 run_test 65a "directory with no stripe info ===================="
5883
5884 test_65b() {
5885         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5886         test_mkdir -p $DIR/$tdir
5887         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5888
5889         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5890                                                 error "setstripe"
5891         touch $DIR/$tdir/f2
5892         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5893 }
5894 run_test 65b "directory setstripe -S stripe_size*2 -i 0 -c 1"
5895
5896 test_65c() {
5897         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5898         if [[ $OSTCOUNT -gt 1 ]]; then
5899                 test_mkdir -p $DIR/$tdir
5900                 local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5901
5902                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5903                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5904                 touch $DIR/$tdir/f3
5905                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5906         fi
5907 }
5908 run_test 65c "directory setstripe -S stripe_size*4 -i 1 -c $((OSTCOUNT-1))"
5909
5910 test_65d() {
5911         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5912         test_mkdir -p $DIR/$tdir
5913         local STRIPECOUNT=$($GETSTRIPE -c $DIR/$tdir)
5914         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5915
5916         if [[ $STRIPECOUNT -le 0 ]]; then
5917                 sc=1
5918         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5919 #LOV_MAX_STRIPE_COUNT is 2000
5920                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5921         else
5922                 sc=$(($STRIPECOUNT - 1))
5923         fi
5924         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5925         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5926         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5927                 error "lverify failed"
5928 }
5929 run_test 65d "directory setstripe -S stripe_size -c stripe_count"
5930
5931 test_65e() {
5932         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5933         test_mkdir -p $DIR/$tdir
5934
5935         $SETSTRIPE $DIR/$tdir || error "setstripe"
5936         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5937                                         error "no stripe info failed"
5938         touch $DIR/$tdir/f6
5939         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5940 }
5941 run_test 65e "directory setstripe defaults ======================="
5942
5943 test_65f() {
5944         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5945         test_mkdir -p $DIR/${tdir}f
5946         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5947 }
5948 run_test 65f "dir setstripe permission (should return error) ==="
5949
5950 test_65g() {
5951         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5952         test_mkdir -p $DIR/$tdir
5953         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5954
5955         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5956                                                         error "setstripe"
5957         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5958         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5959                 error "delete default stripe failed"
5960 }
5961 run_test 65g "directory setstripe -d ==========================="
5962
5963 test_65h() {
5964         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5965         test_mkdir -p $DIR/$tdir
5966         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5967
5968         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5969                                                         error "setstripe"
5970         test_mkdir -p $DIR/$tdir/dd1
5971         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5972                 error "stripe info inherit failed"
5973 }
5974 run_test 65h "directory stripe info inherit ===================="
5975
5976 test_65i() { # bug6367
5977         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5978         $SETSTRIPE -S 65536 -c -1 $MOUNT
5979 }
5980 run_test 65i "set non-default striping on root directory (bug 6367)="
5981
5982 test_65ia() { # bug12836
5983         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5984         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5985 }
5986 run_test 65ia "getstripe on -1 default directory striping"
5987
5988 test_65ib() { # bug12836
5989         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5990         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5991 }
5992 run_test 65ib "getstripe -v on -1 default directory striping"
5993
5994 test_65ic() { # bug12836
5995         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5996         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5997 }
5998 run_test 65ic "new find on -1 default directory striping"
5999
6000 test_65j() { # bug6367
6001         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6002         sync; sleep 1
6003         # if we aren't already remounting for each test, do so for this test
6004         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
6005                 cleanup || error "failed to unmount"
6006                 setup
6007         fi
6008         $SETSTRIPE -d $MOUNT || error "setstripe failed"
6009 }
6010 run_test 65j "set default striping on root directory (bug 6367)="
6011
6012 test_65k() { # bug11679
6013         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6014         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
6015         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6016
6017         local disable_precreate=true
6018         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.8.54) ] &&
6019                 disable_precreate=false
6020
6021         echo "Check OST status: "
6022         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
6023                 awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
6024
6025         for OSC in $MDS_OSCS; do
6026                 echo $OSC "is active"
6027                 do_facet $SINGLEMDS lctl --device %$OSC activate
6028         done
6029
6030         for INACTIVE_OSC in $MDS_OSCS; do
6031                 local ost=$(osc_to_ost $INACTIVE_OSC)
6032                 local ostnum=$(do_facet $SINGLEMDS lctl get_param -n \
6033                                lov.*md*.target_obd |
6034                                awk -F: /$ost/'{ print $1 }' | head -n 1)
6035
6036                 mkdir -p $DIR/$tdir
6037                 $SETSTRIPE -i $ostnum -c 1 $DIR/$tdir
6038                 createmany -o $DIR/$tdir/$tfile.$ostnum. 1000
6039
6040                 echo "Deactivate: " $INACTIVE_OSC
6041                 do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
6042
6043                 local count=$(do_facet $SINGLEMDS "lctl get_param -n \
6044                               osp.$ost*MDT0000.create_count")
6045                 local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
6046                                   osp.$ost*MDT0000.max_create_count")
6047                 $disable_precreate &&
6048                         do_facet $SINGLEMDS "lctl set_param -n \
6049                                 osp.$ost*MDT0000.max_create_count=0"
6050
6051                 for idx in $(seq 0 $((OSTCOUNT - 1))); do
6052                         [ -f $DIR/$tdir/$idx ] && continue
6053                         echo "$SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx"
6054                         $SETSTRIPE -i $idx -c 1 $DIR/$tdir/$idx ||
6055                                 error "setstripe $idx should succeed"
6056                         rm -f $DIR/$tdir/$idx || error "rm $idx failed"
6057                 done
6058                 unlinkmany $DIR/$tdir/$tfile.$ostnum. 1000
6059                 rmdir $DIR/$tdir
6060
6061                 do_facet $SINGLEMDS "lctl set_param -n \
6062                         osp.$ost*MDT0000.max_create_count=$max_count"
6063                 do_facet $SINGLEMDS "lctl set_param -n \
6064                         osp.$ost*MDT0000.create_count=$count"
6065                 do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
6066                 echo $INACTIVE_OSC "is Activate"
6067
6068                 wait_osc_import_state mds ost$ostnum FULL
6069         done
6070 }
6071 run_test 65k "validate manual striping works properly with deactivated OSCs"
6072
6073 test_65l() { # bug 12836
6074         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6075         test_mkdir -p $DIR/$tdir/test_dir
6076         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
6077         $LFS find -mtime -1 $DIR/$tdir >/dev/null
6078 }
6079 run_test 65l "lfs find on -1 stripe dir ========================"
6080
6081 test_65m() {
6082         $RUNAS $SETSTRIPE -c 2 $MOUNT && error "setstripe should fail"
6083         true
6084 }
6085 run_test 65m "normal user can't set filesystem default stripe"
6086
6087 # bug 2543 - update blocks count on client
6088 test_66() {
6089         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6090         COUNT=${COUNT:-8}
6091         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
6092         sync; sync_all_data; sync; sync_all_data
6093         cancel_lru_locks osc
6094         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
6095         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
6096 }
6097 run_test 66 "update inode blocks count on client ==============="
6098
6099 meminfo() {
6100         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
6101 }
6102
6103 swap_used() {
6104         swapon -s | awk '($1 == "'$1'") { print $4 }'
6105 }
6106
6107 # bug5265, obdfilter oa2dentry return -ENOENT
6108 # #define OBD_FAIL_SRV_ENOENT 0x217
6109 test_69() {
6110         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6111         remote_ost_nodsh && skip "remote OST with nodsh" && return
6112
6113         f="$DIR/$tfile"
6114         $SETSTRIPE -c 1 -i 0 $f
6115
6116         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
6117
6118         do_facet ost1 lctl set_param fail_loc=0x217
6119         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
6120         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
6121
6122         do_facet ost1 lctl set_param fail_loc=0
6123         $DIRECTIO write $f 0 2 || error "write error"
6124
6125         cancel_lru_locks osc
6126         $DIRECTIO read $f 0 1 || error "read error"
6127
6128         do_facet ost1 lctl set_param fail_loc=0x217
6129         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
6130
6131         do_facet ost1 lctl set_param fail_loc=0
6132         rm -f $f
6133 }
6134 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
6135
6136 test_71() {
6137         test_mkdir -p $DIR/$tdir
6138         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
6139         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
6140 }
6141 run_test 71 "Running dbench on lustre (don't segment fault) ===="
6142
6143 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
6144         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6145         [ "$RUNAS_ID" = "$UID" ] &&
6146                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6147
6148         # Check that testing environment is properly set up. Skip if not
6149         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
6150                 skip_env "User $RUNAS_ID does not exist - skipping"
6151                 return 0
6152         }
6153         touch $DIR/$tfile
6154         chmod 777 $DIR/$tfile
6155         chmod ug+s $DIR/$tfile
6156         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
6157                 error "$RUNAS dd $DIR/$tfile failed"
6158         # See if we are still setuid/sgid
6159         test -u $DIR/$tfile -o -g $DIR/$tfile &&
6160                 error "S/gid is not dropped on write"
6161         # Now test that MDS is updated too
6162         cancel_lru_locks mdc
6163         test -u $DIR/$tfile -o -g $DIR/$tfile &&
6164                 error "S/gid is not dropped on MDS"
6165         rm -f $DIR/$tfile
6166 }
6167 run_test 72a "Test that remove suid works properly (bug5695) ===="
6168
6169 test_72b() { # bug 24226 -- keep mode setting when size is not changing
6170         local perm
6171
6172         [ "$RUNAS_ID" = "$UID" ] && \
6173                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6174         [ "$RUNAS_ID" -eq 0 ] && \
6175                 skip_env "RUNAS_ID = 0 -- skipping" && return
6176
6177         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6178         # Check that testing environment is properly set up. Skip if not
6179         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
6180                 skip_env "User $RUNAS_ID does not exist - skipping"
6181                 return 0
6182         }
6183         touch $DIR/${tfile}-f{g,u}
6184         test_mkdir $DIR/${tfile}-dg
6185         test_mkdir $DIR/${tfile}-du
6186         chmod 770 $DIR/${tfile}-{f,d}{g,u}
6187         chmod g+s $DIR/${tfile}-{f,d}g
6188         chmod u+s $DIR/${tfile}-{f,d}u
6189         for perm in 777 2777 4777; do
6190                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
6191                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
6192                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
6193                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
6194         done
6195         true
6196 }
6197 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
6198
6199 # bug 3462 - multiple simultaneous MDC requests
6200 test_73() {
6201         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6202         test_mkdir $DIR/d73-1
6203         test_mkdir $DIR/d73-2
6204         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
6205         pid1=$!
6206
6207         lctl set_param fail_loc=0x80000129
6208         $MULTIOP $DIR/d73-1/f73-2 Oc &
6209         sleep 1
6210         lctl set_param fail_loc=0
6211
6212         $MULTIOP $DIR/d73-2/f73-3 Oc &
6213         pid3=$!
6214
6215         kill -USR1 $pid1
6216         wait $pid1 || return 1
6217
6218         sleep 25
6219
6220         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
6221         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
6222         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
6223
6224         rm -rf $DIR/d73-*
6225 }
6226 run_test 73 "multiple MDC requests (should not deadlock)"
6227
6228 test_74a() { # bug 6149, 6184
6229         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6230         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
6231         #
6232         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
6233         # will spin in a tight reconnection loop
6234         touch $DIR/f74a
6235         $LCTL set_param fail_loc=0x8000030e
6236         # get any lock that won't be difficult - lookup works.
6237         ls $DIR/f74a
6238         $LCTL set_param fail_loc=0
6239         rm -f $DIR/f74a
6240         true
6241 }
6242 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
6243
6244 test_74b() { # bug 13310
6245         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6246         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
6247         #
6248         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
6249         # will spin in a tight reconnection loop
6250         $LCTL set_param fail_loc=0x8000030e
6251         # get a "difficult" lock
6252         touch $DIR/f74b
6253         $LCTL set_param fail_loc=0
6254         rm -f $DIR/f74b
6255         true
6256 }
6257 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
6258
6259 test_74c() {
6260         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6261         #define OBD_FAIL_LDLM_NEW_LOCK
6262         $LCTL set_param fail_loc=0x319
6263         touch $DIR/$tfile && error "touch successful"
6264         $LCTL set_param fail_loc=0
6265         true
6266 }
6267 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
6268
6269 num_inodes() {
6270         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
6271 }
6272
6273 test_76() { # Now for bug 20433, added originally in bug 1443
6274         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6275         local CPUS=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
6276         cancel_lru_locks osc
6277         BEFORE_INODES=$(num_inodes)
6278         echo "before inodes: $BEFORE_INODES"
6279         local COUNT=1000
6280         [ "$SLOW" = "no" ] && COUNT=100
6281         for i in $(seq $COUNT); do
6282                 touch $DIR/$tfile
6283                 rm -f $DIR/$tfile
6284         done
6285         cancel_lru_locks osc
6286         AFTER_INODES=$(num_inodes)
6287         echo "after inodes: $AFTER_INODES"
6288         local wait=0
6289         while [[ $((AFTER_INODES-1*${CPUS:-1})) -gt $BEFORE_INODES ]]; do
6290                 sleep 2
6291                 AFTER_INODES=$(num_inodes)
6292                 wait=$((wait+2))
6293                 echo "wait $wait seconds inodes: $AFTER_INODES"
6294                 if [ $wait -gt 30 ]; then
6295                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
6296                 fi
6297         done
6298 }
6299 run_test 76 "confirm clients recycle inodes properly ===="
6300
6301
6302 export ORIG_CSUM=""
6303 set_checksums()
6304 {
6305         # Note: in sptlrpc modes which enable its own bulk checksum, the
6306         # original crc32_le bulk checksum will be automatically disabled,
6307         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
6308         # will be checked by sptlrpc code against sptlrpc bulk checksum.
6309         # In this case set_checksums() will not be no-op, because sptlrpc
6310         # bulk checksum will be enabled all through the test.
6311
6312         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
6313         lctl set_param -n osc.*.checksums $1
6314         return 0
6315 }
6316
6317 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
6318                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
6319 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
6320 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
6321 set_checksum_type()
6322 {
6323         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
6324         log "set checksum type to $1"
6325         return 0
6326 }
6327 F77_TMP=$TMP/f77-temp
6328 F77SZ=8
6329 setup_f77() {
6330         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
6331                 error "error writing to $F77_TMP"
6332 }
6333
6334 test_77a() { # bug 10889
6335         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6336         $GSS && skip "could not run with gss" && return
6337         [ ! -f $F77_TMP ] && setup_f77
6338         set_checksums 1
6339         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
6340         set_checksums 0
6341         rm -f $DIR/$tfile
6342 }
6343 run_test 77a "normal checksum read/write operation"
6344
6345 test_77b() { # bug 10889
6346         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6347         $GSS && skip "could not run with gss" && return
6348         [ ! -f $F77_TMP ] && setup_f77
6349         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6350         $LCTL set_param fail_loc=0x80000409
6351         set_checksums 1
6352
6353         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
6354                 error "dd error: $?"
6355         $LCTL set_param fail_loc=0
6356
6357         for algo in $CKSUM_TYPES; do
6358                 cancel_lru_locks osc
6359                 set_checksum_type $algo
6360                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
6361                 $LCTL set_param fail_loc=0x80000408
6362                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
6363                 $LCTL set_param fail_loc=0
6364         done
6365         set_checksums 0
6366         set_checksum_type $ORIG_CSUM_TYPE
6367         rm -f $DIR/$tfile
6368 }
6369 run_test 77b "checksum error on client write, read"
6370
6371 cleanup_77c() {
6372         trap 0
6373         set_checksums 0
6374         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=0
6375         $check_ost &&
6376                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=0
6377         [ -n $osc_file_prefix ] && rm -f ${osc_file_prefix}*
6378         $check_ost && [ -n $ost_file_prefix ] &&
6379                 do_facet ost1 rm -f ${ost_file_prefix}\*
6380 }
6381
6382 test_77c() {
6383         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6384         $GSS && skip "could not run with gss" && return
6385
6386         local bad1
6387         local osc_file_prefix
6388         local osc_file
6389         local check_ost=false
6390         local ost_file_prefix
6391         local ost_file
6392         local orig_cksum
6393         local dump_cksum
6394         local fid
6395
6396         # ensure corruption will occur on first OSS/OST
6397         $LFS setstripe -i 0 $DIR/$tfile
6398
6399         [ ! -f $F77_TMP ] && setup_f77
6400         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
6401                 error "dd write error: $?"
6402         fid=$($LFS path2fid $DIR/$tfile)
6403
6404         if [ $(lustre_version_code ost1) -ge $(version_code 2.9.57) ]
6405         then
6406                 check_ost=true
6407                 ost_file_prefix=$(do_facet ost1 $LCTL get_param -n debug_path)
6408                 ost_file_prefix=${ost_file_prefix}-checksum_dump-ost-\\${fid}
6409         else
6410                 echo "OSS do not support bulk pages dump upon error"
6411         fi
6412
6413         osc_file_prefix=$($LCTL get_param -n debug_path)
6414         osc_file_prefix=${osc_file_prefix}-checksum_dump-osc-\\${fid}
6415
6416         trap cleanup_77c EXIT
6417
6418         set_checksums 1
6419         # enable bulk pages dump upon error on Client
6420         $LCTL set_param osc.*osc-[^mM]*.checksum_dump=1
6421         # enable bulk pages dump upon error on OSS
6422         $check_ost &&
6423                 do_facet ost1 $LCTL set_param obdfilter.*-OST*.checksum_dump=1
6424
6425         # flush Client cache to allow next read to reach OSS
6426         cancel_lru_locks osc
6427
6428         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE       0x408
6429         $LCTL set_param fail_loc=0x80000408
6430         dd if=$DIR/$tfile of=/dev/null bs=1M || error "dd read error: $?"
6431         $LCTL set_param fail_loc=0
6432
6433         rm -f $DIR/$tfile
6434
6435         # check cksum dump on Client
6436         osc_file=$(ls ${osc_file_prefix}*)
6437         [ -n "$osc_file" ] || error "no checksum dump file on Client"
6438         # OBD_FAIL_OSC_CHECKSUM_RECEIVE corrupts with "bad1" at start of file
6439         bad1=$(dd if=$osc_file bs=1 count=4 2>/dev/null) || error "dd error: $?"
6440         [ $bad1 == "bad1" ] || error "unexpected corrupt pattern"
6441         orig_cksum=$(dd if=$F77_TMP bs=1 skip=4 count=1048572 2>/dev/null |
6442                      cksum)
6443         dump_cksum=$(dd if=$osc_file bs=1 skip=4 2>/dev/null | cksum)
6444         [[ "$orig_cksum" == "$dump_cksum" ]] ||
6445                 error "dump content does not match on Client"
6446
6447         $check_ost || { skip "No need to check cksum dump on OSS"; return 0; }
6448
6449         # check cksum dump on OSS
6450         ost_file=$(do_facet ost1 ls ${ost_file_prefix}\*)
6451         [ -n "$ost_file" ] || error "no checksum dump file on OSS"
6452         orig_cksum=$(dd if=$F77_TMP bs=1048576 count=1 2>/dev/null | cksum)
6453         dump_cksum=$(do_facet ost1 dd if=$ost_file 2>/dev/null \| cksum)
6454         [[ "$orig_cksum" == "$dump_cksum" ]] ||
6455                 error "dump content does not match on OSS"
6456
6457         cleanup_77c
6458 }
6459 run_test 77c "checksum error on client read with debug"
6460
6461 test_77d() { # bug 10889
6462         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6463         $GSS && skip "could not run with gss" && return
6464         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6465         $LCTL set_param fail_loc=0x80000409
6466         set_checksums 1
6467         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
6468                 error "direct write: rc=$?"
6469         $LCTL set_param fail_loc=0
6470         set_checksums 0
6471
6472         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
6473         $LCTL set_param fail_loc=0x80000408
6474         set_checksums 1
6475         cancel_lru_locks osc
6476         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
6477                 error "direct read: rc=$?"
6478         $LCTL set_param fail_loc=0
6479         set_checksums 0
6480 }
6481 run_test 77d "checksum error on OST direct write, read"
6482
6483 test_77f() { # bug 10889
6484         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6485         $GSS && skip "could not run with gss" && return
6486         set_checksums 1
6487         for algo in $CKSUM_TYPES; do
6488                 cancel_lru_locks osc
6489                 set_checksum_type $algo
6490                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
6491                 $LCTL set_param fail_loc=0x409
6492                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
6493                         error "direct write succeeded"
6494                 $LCTL set_param fail_loc=0
6495         done
6496         set_checksum_type $ORIG_CSUM_TYPE
6497         set_checksums 0
6498 }
6499 run_test 77f "repeat checksum error on write (expect error)"
6500
6501 test_77g() { # bug 10889
6502         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6503         $GSS && skip "could not run with gss" && return
6504         remote_ost_nodsh && skip "remote OST with nodsh" && return
6505
6506         [ ! -f $F77_TMP ] && setup_f77
6507
6508         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
6509         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
6510         do_facet ost1 lctl set_param fail_loc=0x8000021a
6511         set_checksums 1
6512         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
6513                 error "write error: rc=$?"
6514         do_facet ost1 lctl set_param fail_loc=0
6515         set_checksums 0
6516
6517         cancel_lru_locks osc
6518         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
6519         do_facet ost1 lctl set_param fail_loc=0x8000021b
6520         set_checksums 1
6521         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
6522         do_facet ost1 lctl set_param fail_loc=0
6523         set_checksums 0
6524 }
6525 run_test 77g "checksum error on OST write, read"
6526
6527 test_77j() { # bug 13805
6528         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6529         $GSS && skip "could not run with gss" && return
6530         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
6531         lctl set_param fail_loc=0x40c
6532         remount_client $MOUNT
6533         lctl set_param fail_loc=0
6534         # wait async osc connect to finish and reflect updated state value
6535         local i
6536         for (( i=0; i < OSTCOUNT; i++ )) ; do
6537                 wait_osc_import_state client ost$((i+1)) FULL
6538         done
6539
6540         for VALUE in $(lctl get_param osc.*osc-[^mM]*.checksum_type); do
6541                 PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
6542                 algo=$(lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g')
6543                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
6544         done
6545         remount_client $MOUNT
6546 }
6547 run_test 77j "client only supporting ADLER32"
6548
6549 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
6550 rm -f $F77_TMP
6551 unset F77_TMP
6552
6553 cleanup_test_78() {
6554         trap 0
6555         rm -f $DIR/$tfile
6556 }
6557
6558 test_78() { # bug 10901
6559         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6560         remote_ost || { skip_env "local OST" && return; }
6561
6562         NSEQ=5
6563         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
6564         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
6565         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
6566         echo "MemTotal: $MEMTOTAL"
6567
6568         # reserve 256MB of memory for the kernel and other running processes,
6569         # and then take 1/2 of the remaining memory for the read/write buffers.
6570         if [ $MEMTOTAL -gt 512 ] ;then
6571                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
6572         else
6573                 # for those poor memory-starved high-end clusters...
6574                 MEMTOTAL=$((MEMTOTAL / 2))
6575         fi
6576         echo "Mem to use for directio: $MEMTOTAL"
6577
6578         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
6579         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
6580         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
6581         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
6582                 head -n1)
6583         echo "Smallest OST: $SMALLESTOST"
6584         [[ $SMALLESTOST -lt 10240 ]] &&
6585                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
6586
6587         trap cleanup_test_78 EXIT
6588
6589         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
6590                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
6591
6592         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
6593         echo "File size: $F78SIZE"
6594         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
6595         for i in $(seq 1 $NSEQ); do
6596                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
6597                 echo directIO rdwr round $i of $NSEQ
6598                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
6599         done
6600
6601         cleanup_test_78
6602 }
6603 run_test 78 "handle large O_DIRECT writes correctly ============"
6604
6605 test_79() { # bug 12743
6606         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6607         wait_delete_completed
6608
6609         BKTOTAL=$(calc_osc_kbytes kbytestotal)
6610         BKFREE=$(calc_osc_kbytes kbytesfree)
6611         BKAVAIL=$(calc_osc_kbytes kbytesavail)
6612
6613         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
6614         DFTOTAL=`echo $STRING | cut -d, -f1`
6615         DFUSED=`echo $STRING  | cut -d, -f2`
6616         DFAVAIL=`echo $STRING | cut -d, -f3`
6617         DFFREE=$(($DFTOTAL - $DFUSED))
6618
6619         ALLOWANCE=$((64 * $OSTCOUNT))
6620
6621         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
6622            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
6623                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
6624         fi
6625         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
6626            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
6627                 error "df free($DFFREE) mismatch OST free($BKFREE)"
6628         fi
6629         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
6630            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
6631                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
6632         fi
6633 }
6634 run_test 79 "df report consistency check ======================="
6635
6636 test_80() { # bug 10718
6637         remote_ost_nodsh && skip "remote OST with nodsh" && return
6638         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6639         # relax strong synchronous semantics for slow backends like ZFS
6640         local soc="obdfilter.*.sync_on_lock_cancel"
6641         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
6642         local hosts=
6643         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
6644                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
6645                           facet_active_host $host; done | sort -u)
6646                 do_nodes $hosts lctl set_param $soc=never
6647         fi
6648
6649         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
6650         sync; sleep 1; sync
6651         local BEFORE=`date +%s`
6652         cancel_lru_locks osc
6653         local AFTER=`date +%s`
6654         local DIFF=$((AFTER-BEFORE))
6655         if [ $DIFF -gt 1 ] ; then
6656                 error "elapsed for 1M@1T = $DIFF"
6657         fi
6658
6659         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
6660
6661         rm -f $DIR/$tfile
6662 }
6663 run_test 80 "Page eviction is equally fast at high offsets too  ===="
6664
6665 test_81a() { # LU-456
6666         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6667         remote_ost_nodsh && skip "remote OST with nodsh" && return
6668         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6669         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
6670         do_facet ost1 lctl set_param fail_loc=0x80000228
6671
6672         # write should trigger a retry and success
6673         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6674         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6675         RC=$?
6676         if [ $RC -ne 0 ] ; then
6677                 error "write should success, but failed for $RC"
6678         fi
6679 }
6680 run_test 81a "OST should retry write when get -ENOSPC ==============="
6681
6682 test_81b() { # LU-456
6683         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6684         remote_ost_nodsh && skip "remote OST with nodsh" && return
6685         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6686         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
6687         do_facet ost1 lctl set_param fail_loc=0x228
6688
6689         # write should retry several times and return -ENOSPC finally
6690         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6691         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6692         RC=$?
6693         ENOSPC=28
6694         if [ $RC -ne $ENOSPC ] ; then
6695                 error "dd should fail for -ENOSPC, but succeed."
6696         fi
6697 }
6698 run_test 81b "OST should return -ENOSPC when retry still fails ======="
6699
6700 test_82() { # LU-1031
6701         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
6702         local gid1=14091995
6703         local gid2=16022000
6704
6705         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
6706         local MULTIPID1=$!
6707         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
6708         local MULTIPID2=$!
6709         kill -USR1 $MULTIPID2
6710         sleep 2
6711         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6712                 error "First grouplock does not block second one"
6713         else
6714                 echo "Second grouplock blocks first one"
6715         fi
6716         kill -USR1 $MULTIPID1
6717         wait $MULTIPID1
6718         wait $MULTIPID2
6719 }
6720 run_test 82 "Basic grouplock test ==============================="
6721
6722 test_83() {
6723         local sfile="/boot/System.map-$(uname -r)"
6724         # define OBD_FAIL_LLITE_PTASK_IO_FAIL 0x140d
6725         $LCTL set_param fail_loc=0x140d
6726         cp $sfile $DIR/$tfile || error "write failed"
6727         diff -c $sfile $DIR/$tfile || error "files are different"
6728         $LCTL set_param fail_loc=0
6729         rm -f $DIR/$tfile
6730 }
6731 run_test 83 "Short write in ptask ==============================="
6732
6733 test_99a() {
6734         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6735                 return
6736         test_mkdir -p $DIR/d99cvsroot
6737         chown $RUNAS_ID $DIR/d99cvsroot
6738         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6739         cd $TMP
6740
6741         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6742         cd $oldPWD
6743 }
6744 run_test 99a "cvs init ========================================="
6745
6746 test_99b() {
6747         [ -z "$(which cvs 2>/dev/null)" ] &&
6748                 skip_env "could not find cvs" && return
6749         [ ! -d $DIR/d99cvsroot ] && test_99a
6750         cd /etc/init.d
6751         # some versions of cvs import exit(1) when asked to import links or
6752         # files they can't read.  ignore those files.
6753         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6754                         ! -perm /4 -printf '-I %f\n')
6755         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6756                 d99reposname vtag rtag
6757 }
6758 run_test 99b "cvs import ======================================="
6759
6760 test_99c() {
6761         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6762         [ ! -d $DIR/d99cvsroot ] && test_99b
6763         cd $DIR
6764         test_mkdir -p $DIR/d99reposname
6765         chown $RUNAS_ID $DIR/d99reposname
6766         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6767 }
6768 run_test 99c "cvs checkout ====================================="
6769
6770 test_99d() {
6771         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6772         [ ! -d $DIR/d99cvsroot ] && test_99c
6773         cd $DIR/d99reposname
6774         $RUNAS touch foo99
6775         $RUNAS cvs add -m 'addmsg' foo99
6776 }
6777 run_test 99d "cvs add =========================================="
6778
6779 test_99e() {
6780         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6781         [ ! -d $DIR/d99cvsroot ] && test_99c
6782         cd $DIR/d99reposname
6783         $RUNAS cvs update
6784 }
6785 run_test 99e "cvs update ======================================="
6786
6787 test_99f() {
6788         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6789         [ ! -d $DIR/d99cvsroot ] && test_99d
6790         cd $DIR/d99reposname
6791         $RUNAS cvs commit -m 'nomsg' foo99
6792     rm -fr $DIR/d99cvsroot
6793 }
6794 run_test 99f "cvs commit ======================================="
6795
6796 test_100() {
6797         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6798         [[ "$NETTYPE" =~ tcp ]] ||
6799                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" &&
6800                         return ; }
6801
6802         remote_ost_nodsh && skip "remote OST with nodsh" && return
6803         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6804         remote_servers ||
6805                 { skip "useless for local single node setup" && return; }
6806
6807         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6808                 [ "$PROT" != "tcp" ] && continue
6809                 RPORT=$(echo $REMOTE | cut -d: -f2)
6810                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6811
6812                 rc=0
6813                 LPORT=`echo $LOCAL | cut -d: -f2`
6814                 if [ $LPORT -ge 1024 ]; then
6815                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6816                         netstat -tna
6817                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6818                 fi
6819         done
6820         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6821 }
6822 run_test 100 "check local port using privileged port ==========="
6823
6824 function get_named_value()
6825 {
6826     local tag
6827
6828     tag=$1
6829     while read ;do
6830         line=$REPLY
6831         case $line in
6832         $tag*)
6833             echo $line | sed "s/^$tag[ ]*//"
6834             break
6835             ;;
6836         esac
6837     done
6838 }
6839
6840 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6841                    awk '/^max_cached_mb/ { print $2 }')
6842
6843 cleanup_101a() {
6844         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6845         trap 0
6846 }
6847
6848 test_101a() {
6849         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6850         [ $MDSCOUNT -ge 2 ] && skip "needs < 2 MDTs" && return #LU-4322
6851         local s
6852         local discard
6853         local nreads=10000
6854         local cache_limit=32
6855
6856         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6857         trap cleanup_101a EXIT
6858         $LCTL set_param -n llite.*.read_ahead_stats 0
6859         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6860
6861         #
6862         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6863         #
6864         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6865         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6866
6867         discard=0
6868         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6869                 get_named_value 'read but discarded' | cut -d" " -f1); do
6870                         discard=$(($discard + $s))
6871         done
6872         cleanup_101a
6873
6874         if [[ $(($discard * 10)) -gt $nreads ]]; then
6875                 $LCTL get_param osc.*-osc*.rpc_stats
6876                 $LCTL get_param llite.*.read_ahead_stats
6877                 error "too many ($discard) discarded pages"
6878         fi
6879         rm -f $DIR/$tfile || true
6880 }
6881 run_test 101a "check read-ahead for random reads ================"
6882
6883 setup_test101bc() {
6884         test_mkdir -p $DIR/$tdir
6885         local STRIPE_SIZE=$1
6886         local FILE_LENGTH=$2
6887         STRIPE_OFFSET=0
6888
6889         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6890
6891         local list=$(comma_list $(osts_nodes))
6892         set_osd_param $list '' read_cache_enable 0
6893         set_osd_param $list '' writethrough_cache_enable 0
6894
6895         trap cleanup_test101bc EXIT
6896         # prepare the read-ahead file
6897         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6898
6899         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6900                                 count=$FILE_SIZE_MB 2> /dev/null
6901
6902 }
6903
6904 cleanup_test101bc() {
6905         trap 0
6906         rm -rf $DIR/$tdir
6907         rm -f $DIR/$tfile
6908
6909         local list=$(comma_list $(osts_nodes))
6910         set_osd_param $list '' read_cache_enable 1
6911         set_osd_param $list '' writethrough_cache_enable 1
6912 }
6913
6914 calc_total() {
6915         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6916 }
6917
6918 ra_check_101() {
6919         local READ_SIZE=$1
6920         local STRIPE_SIZE=$2
6921         local FILE_LENGTH=$3
6922         local RA_INC=1048576
6923         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6924         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6925                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6926         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6927                         get_named_value 'read but discarded' |
6928                         cut -d" " -f1 | calc_total)
6929         if [[ $DISCARD -gt $discard_limit ]]; then
6930                 $LCTL get_param llite.*.read_ahead_stats
6931                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6932         else
6933                 echo "Read-ahead success for size ${READ_SIZE}"
6934         fi
6935 }
6936
6937 test_101b() {
6938         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6939         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
6940         local STRIPE_SIZE=1048576
6941         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6942         if [ $SLOW == "yes" ]; then
6943                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6944         else
6945                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6946         fi
6947
6948         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6949
6950         # prepare the read-ahead file
6951         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6952         cancel_lru_locks osc
6953         for BIDX in 2 4 8 16 32 64 128 256
6954         do
6955                 local BSIZE=$((BIDX*4096))
6956                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6957                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6958                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6959                 $LCTL set_param -n llite.*.read_ahead_stats 0
6960                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6961                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6962                 cancel_lru_locks osc
6963                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6964         done
6965         cleanup_test101bc
6966         true
6967 }
6968 run_test 101b "check stride-io mode read-ahead ================="
6969
6970 test_101c() {
6971         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6972         local STRIPE_SIZE=1048576
6973         local FILE_LENGTH=$((STRIPE_SIZE*100))
6974         local nreads=10000
6975         local osc_rpc_stats
6976
6977         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6978
6979         cancel_lru_locks osc
6980         $LCTL set_param osc.*.rpc_stats 0
6981         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6982         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6983                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6984                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6985                 local size
6986
6987                 if [ $lines -le 20 ]; then
6988                         continue
6989                 fi
6990                 for size in 1 2 4 8; do
6991                         local rpc=$(echo "$stats" |
6992                                     awk '($1 == "'$size':") {print $2; exit; }')
6993                         [ $rpc != 0 ] &&
6994                                 error "Small $((size*4))k read IO $rpc !"
6995                 done
6996                 echo "$osc_rpc_stats check passed!"
6997         done
6998         cleanup_test101bc
6999         true
7000 }
7001 run_test 101c "check stripe_size aligned read-ahead ================="
7002
7003 set_read_ahead() {
7004         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
7005         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
7006 }
7007
7008 test_101d() {
7009         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7010         local file=$DIR/$tfile
7011         local sz_MB=${FILESIZE_101d:-500}
7012         local ra_MB=${READAHEAD_MB:-40}
7013
7014         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
7015         [ $free_MB -lt $sz_MB ] &&
7016                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
7017
7018         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
7019         $SETSTRIPE -c -1 $file || error "setstripe failed"
7020
7021         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
7022         echo Cancel LRU locks on lustre client to flush the client cache
7023         cancel_lru_locks osc
7024
7025         echo Disable read-ahead
7026         local old_READAHEAD=$(set_read_ahead 0)
7027
7028         echo Reading the test file $file with read-ahead disabled
7029         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
7030
7031         echo Cancel LRU locks on lustre client to flush the client cache
7032         cancel_lru_locks osc
7033         echo Enable read-ahead with ${ra_MB}MB
7034         set_read_ahead $ra_MB
7035
7036         echo Reading the test file $file with read-ahead enabled
7037         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
7038
7039         echo "read-ahead disabled time read $raOFF"
7040         echo "read-ahead enabled  time read $raON"
7041
7042         set_read_ahead $old_READAHEAD
7043         rm -f $file
7044         wait_delete_completed
7045
7046         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
7047                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
7048 }
7049 run_test 101d "file read with and without read-ahead enabled"
7050
7051 test_101e() {
7052         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7053         local file=$DIR/$tfile
7054         local size_KB=500  #KB
7055         local count=100
7056         local bsize=1024
7057
7058         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
7059         local need_KB=$((count * size_KB))
7060         [[ $free_KB -le $need_KB ]] &&
7061                 skip_env "Need free space $need_KB, have $free_KB" && return
7062
7063         echo "Creating $count ${size_KB}K test files"
7064         for ((i = 0; i < $count; i++)); do
7065                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
7066         done
7067
7068         echo "Cancel LRU locks on lustre client to flush the client cache"
7069         cancel_lru_locks osc
7070
7071         echo "Reset readahead stats"
7072         $LCTL set_param -n llite.*.read_ahead_stats 0
7073
7074         for ((i = 0; i < $count; i++)); do
7075                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
7076         done
7077
7078         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
7079                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
7080
7081         for ((i = 0; i < $count; i++)); do
7082                 rm -rf $file.$i 2>/dev/null
7083         done
7084
7085         #10000 means 20% reads are missing in readahead
7086         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
7087 }
7088 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
7089
7090 test_101f() {
7091         which iozone || { skip "no iozone installed" && return; }
7092
7093         local old_debug=$($LCTL get_param debug)
7094         old_debug=${old_debug#*=}
7095         $LCTL set_param debug="reada mmap"
7096
7097         # create a test file
7098         iozone -i 0 -+n -r 1m -s 128m -w -f $DIR/$tfile > /dev/null 2>&1
7099
7100         echo Cancel LRU locks on lustre client to flush the client cache
7101         cancel_lru_locks osc
7102
7103         echo Reset readahead stats
7104         $LCTL set_param -n llite.*.read_ahead_stats 0
7105
7106         echo mmap read the file with small block size
7107         iozone -i 1 -u 1 -l 1 -+n -r 32k -s 128m -B -f $DIR/$tfile \
7108                 > /dev/null 2>&1
7109
7110         echo checking missing pages
7111         $LCTL get_param llite.*.read_ahead_stats
7112         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
7113                         get_named_value 'misses' | cut -d" " -f1 | calc_total)
7114
7115         $LCTL set_param debug="$old_debug"
7116         [ $miss -lt 3 ] || error "misses too much pages ('$miss')!"
7117         rm -f $DIR/$tfile
7118 }
7119 run_test 101f "check mmap read performance"
7120
7121 test_101g_brw_size_test() {
7122         local mb=$1
7123         local pages=$((mb * 1048576 / $(page_size)))
7124
7125         $LCTL set_param osc.*.max_pages_per_rpc=${mb}M ||
7126                 { error "unable to set max_pages_per_rpc=${mb}M"; return 1; }
7127         for mp in $($LCTL get_param -n osc.*.max_pages_per_rpc); do
7128                 [ $mp -ne $pages ] && error "max_pages_per_rpc $mp != $pages" &&
7129                         return 2
7130         done
7131
7132         $LCTL set_param -n osc.*.rpc_stats=0
7133
7134         # 10 RPCs should be enough for the test
7135         local count=10
7136         dd if=/dev/zero of=$DIR/$tfile bs=${mb}M count=$count ||
7137                 { error "dd write ${mb} MB blocks failed"; return 3; }
7138         cancel_lru_locks osc
7139         dd of=/dev/null if=$DIR/$tfile bs=${mb}M count=$count ||
7140                 { error "dd write ${mb} MB blocks failed"; return 4; }
7141
7142         # calculate number of full-sized read and write RPCs
7143         rpcs=($($LCTL get_param -n 'osc.*.rpc_stats' |
7144                 sed -n '/pages per rpc/,/^$/p' |
7145                 awk '/'$pages':/ { reads += $2; writes += $6 }; \
7146                 END { print reads,writes }'))
7147         [ ${rpcs[0]} -ne $count ] && error "${rpcs[0]} != $count read RPCs" &&
7148                 return 5
7149         [ ${rpcs[1]} -ne $count ] && error "${rpcs[1]} != $count write RPCs" &&
7150                 return 6
7151
7152         return 0
7153 }
7154
7155 test_101g() {
7156         local rpcs
7157         local osts=$(get_facets OST)
7158         local list=$(comma_list $(osts_nodes))
7159         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
7160         local brw_size="obdfilter.*.brw_size"
7161         local ostver=$(lustre_version_code ost1)
7162
7163         $LFS setstripe -i 0 -c 1 $DIR/$tfile
7164
7165         local orig_mb=$(do_facet ost1 $LCTL get_param -n $brw_size | head -n 1)
7166         if [ $ostver -ge $(version_code 2.8.52) ] ||
7167            [ $ostver -ge $(version_code 2.7.17) -a \
7168              $ostver -lt $(version_code 2.7.50) ]; then
7169                 [ $ostver -ge $(version_code 2.9.52) ] && suffix="M"
7170                 if [[ $orig_mb -lt 16 ]]; then
7171                         save_lustre_params $osts "$brw_size" > $p
7172                         do_nodes $list $LCTL set_param -n $brw_size=16$suffix ||
7173                                 error "set 16MB RPC size failed"
7174
7175                         echo "remount client to enable new RPC size"
7176                         remount_client $MOUNT || error "remount_client failed"
7177                 fi
7178
7179                 test_101g_brw_size_test 16 || error "16MB RPC test failed"
7180                 # should be able to set brw_size=12, but no rpc_stats for that
7181                 test_101g_brw_size_test 8 || error "8MB RPC test failed"
7182         fi
7183
7184         test_101g_brw_size_test 4 || error "4MB RPC test failed"
7185
7186         if [[ $orig_mb -lt 16 ]]; then
7187                 restore_lustre_params < $p
7188                 remount_client $MOUNT || error "remount_client restore failed"
7189         fi
7190
7191         rm -f $p $DIR/$tfile
7192 }
7193 run_test 101g "Big bulk(4/16 MiB) readahead"
7194
7195 setup_test102() {
7196         test_mkdir $DIR/$tdir
7197         chown $RUNAS_ID $DIR/$tdir
7198         STRIPE_SIZE=65536
7199         STRIPE_OFFSET=1
7200         STRIPE_COUNT=$OSTCOUNT
7201         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
7202
7203         trap cleanup_test102 EXIT
7204         cd $DIR
7205         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
7206         cd $DIR/$tdir
7207         for num in 1 2 3 4; do
7208                 for count in $(seq 1 $STRIPE_COUNT); do
7209                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
7210                                 local size=`expr $STRIPE_SIZE \* $num`
7211                                 local file=file"$num-$idx-$count"
7212                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
7213                         done
7214                 done
7215         done
7216
7217         cd $DIR
7218         $1 tar cf $TMP/f102.tar $tdir --xattrs
7219 }
7220
7221 cleanup_test102() {
7222         trap 0
7223         rm -f $TMP/f102.tar
7224         rm -rf $DIR/d0.sanity/d102
7225 }
7226
7227 test_102a() {
7228         local testfile=$DIR/$tfile
7229
7230         touch $testfile
7231
7232         [ "$UID" != 0 ] && skip_env "must run as root" && return
7233         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
7234                 skip_env "must have user_xattr" && return
7235
7236         [ -z "$(which setfattr 2>/dev/null)" ] &&
7237                 skip_env "could not find setfattr" && return
7238
7239         echo "set/get xattr..."
7240         setfattr -n trusted.name1 -v value1 $testfile ||
7241                 error "setfattr -n trusted.name1=value1 $testfile failed"
7242         getfattr -n trusted.name1 $testfile 2> /dev/null |
7243           grep "trusted.name1=.value1" ||
7244                 error "$testfile missing trusted.name1=value1"
7245
7246         setfattr -n user.author1 -v author1 $testfile ||
7247                 error "setfattr -n user.author1=author1 $testfile failed"
7248         getfattr -n user.author1 $testfile 2> /dev/null |
7249           grep "user.author1=.author1" ||
7250                 error "$testfile missing trusted.author1=author1"
7251
7252         echo "listxattr..."
7253         setfattr -n trusted.name2 -v value2 $testfile ||
7254                 error "$testfile unable to set trusted.name2"
7255         setfattr -n trusted.name3 -v value3 $testfile ||
7256                 error "$testfile unable to set trusted.name3"
7257         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
7258             grep "trusted.name" | wc -l) -eq 3 ] ||
7259                 error "$testfile missing 3 trusted.name xattrs"
7260
7261         setfattr -n user.author2 -v author2 $testfile ||
7262                 error "$testfile unable to set user.author2"
7263         setfattr -n user.author3 -v author3 $testfile ||
7264                 error "$testfile unable to set user.author3"
7265         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
7266             grep "user.author" | wc -l) -eq 3 ] ||
7267                 error "$testfile missing 3 user.author xattrs"
7268
7269         echo "remove xattr..."
7270         setfattr -x trusted.name1 $testfile ||
7271                 error "$testfile error deleting trusted.name1"
7272         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
7273                 error "$testfile did not delete trusted.name1 xattr"
7274
7275         setfattr -x user.author1 $testfile ||
7276                 error "$testfile error deleting user.author1"
7277         echo "set lustre special xattr ..."
7278         $LFS setstripe -c1 $testfile
7279         local lovea=$(getfattr -n "trusted.lov" -e hex $testfile |
7280                 awk -F "=" '/trusted.lov/ { print $2 }' )
7281         setfattr -n "trusted.lov" -v $lovea $testfile ||
7282                 error "$testfile doesn't ignore setting trusted.lov again"
7283         setfattr -n "trusted.lov" -v "invalid_value" $testfile &&
7284                 error "$testfile allow setting invalid trusted.lov"
7285         rm -f $testfile
7286 }
7287 run_test 102a "user xattr test =================================="
7288
7289 test_102b() {
7290         [ -z "$(which setfattr 2>/dev/null)" ] &&
7291                 skip_env "could not find setfattr" && return
7292
7293         # b10930: get/set/list trusted.lov xattr
7294         echo "get/set/list trusted.lov xattr ..."
7295         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7296         local testfile=$DIR/$tfile
7297         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7298                 error "setstripe failed"
7299         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
7300                 error "getstripe failed"
7301         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
7302                 error "can't get trusted.lov from $testfile"
7303
7304         local testfile2=${testfile}2
7305         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
7306                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
7307
7308         $MCREATE $testfile2
7309         setfattr -n trusted.lov -v $value $testfile2
7310         local stripe_size=$($GETSTRIPE -S $testfile2)
7311         local stripe_count=$($GETSTRIPE -c $testfile2)
7312         [[ $stripe_size -eq 65536 ]] ||
7313                 error "stripe size $stripe_size != 65536"
7314         [[ $stripe_count -eq $STRIPECOUNT ]] ||
7315                 error "stripe count $stripe_count != $STRIPECOUNT"
7316         rm -f $DIR/$tfile
7317 }
7318 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
7319
7320 test_102c() {
7321         [ -z "$(which setfattr 2>/dev/null)" ] &&
7322                 skip_env "could not find setfattr" && return
7323
7324         # b10930: get/set/list lustre.lov xattr
7325         echo "get/set/list lustre.lov xattr ..."
7326         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7327         test_mkdir $DIR/$tdir
7328         chown $RUNAS_ID $DIR/$tdir
7329         local testfile=$DIR/$tdir/$tfile
7330         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
7331                 error "setstripe failed"
7332         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
7333                 error "getstripe failed"
7334         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
7335         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
7336
7337         local testfile2=${testfile}2
7338         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
7339                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
7340
7341         $RUNAS $MCREATE $testfile2
7342         $RUNAS setfattr -n lustre.lov -v $value $testfile2
7343         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
7344         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
7345         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
7346         [ $stripe_count -eq $STRIPECOUNT ] ||
7347                 error "stripe count $stripe_count != $STRIPECOUNT"
7348 }
7349 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
7350
7351 compare_stripe_info1() {
7352         local stripe_index_all_zero=true
7353
7354         for num in 1 2 3 4; do
7355                 for count in $(seq 1 $STRIPE_COUNT); do
7356                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
7357                                 local size=$((STRIPE_SIZE * num))
7358                                 local file=file"$num-$offset-$count"
7359                                 stripe_size=$($LFS getstripe -S $PWD/$file)
7360                                 [[ $stripe_size -ne $size ]] &&
7361                                     error "$file: size $stripe_size != $size"
7362                                 stripe_count=$($LFS getstripe -c $PWD/$file)
7363                                 # allow fewer stripes to be created, ORI-601
7364                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
7365                                     error "$file: count $stripe_count != $count"
7366                                 stripe_index=$($LFS getstripe -i $PWD/$file)
7367                                 [[ $stripe_index -ne 0 ]] &&
7368                                         stripe_index_all_zero=false
7369                         done
7370                 done
7371         done
7372         $stripe_index_all_zero &&
7373                 error "all files are being extracted starting from OST index 0"
7374         return 0
7375 }
7376
7377 have_xattrs_include() {
7378         tar --help | grep -q xattrs-include &&
7379                 echo --xattrs-include="lustre.*"
7380 }
7381
7382 test_102d() {
7383         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7384         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7385         local xinc=$(have_xattrs_include)
7386         setup_test102
7387         tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $xinc
7388         cd $DIR/$tdir/$tdir
7389         compare_stripe_info1
7390 }
7391 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
7392
7393 test_102f() {
7394         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7395         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7396         local xinc=$(have_xattrs_include)
7397         setup_test102
7398         test_mkdir $DIR/$tdir.restore
7399         cd $DIR
7400         tar cf - --xattrs $tdir | tar xf - \
7401                 -C $DIR/$tdir.restore --xattrs $xinc
7402         cd $DIR/$tdir.restore/$tdir
7403         compare_stripe_info1
7404 }
7405 run_test 102f "tar copy files, not keep osts ==========="
7406
7407 grow_xattr() {
7408         local xsize=${1:-1024}  # in bytes
7409         local file=$DIR/$tfile
7410
7411         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep xattr)" ] &&
7412                 skip "must have user_xattr" && return 0
7413         [ -z "$(which setfattr 2>/dev/null)" ] &&
7414                 skip_env "could not find setfattr" && return 0
7415         [ -z "$(which getfattr 2>/dev/null)" ] &&
7416                 skip_env "could not find getfattr" && return 0
7417
7418         touch $file
7419
7420         local value="$(generate_string $xsize)"
7421
7422         local xbig=trusted.big
7423         log "save $xbig on $file"
7424         setfattr -n $xbig -v $value $file ||
7425                 error "saving $xbig on $file failed"
7426
7427         local orig=$(get_xattr_value $xbig $file)
7428         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
7429
7430         local xsml=trusted.sml
7431         log "save $xsml on $file"
7432         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
7433
7434         local new=$(get_xattr_value $xbig $file)
7435         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
7436
7437         log "grow $xsml on $file"
7438         setfattr -n $xsml -v "$value" $file ||
7439                 error "growing $xsml on $file failed"
7440
7441         new=$(get_xattr_value $xbig $file)
7442         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
7443         log "$xbig still valid after growing $xsml"
7444
7445         rm -f $file
7446 }
7447
7448 test_102h() { # bug 15777
7449         grow_xattr 1024
7450 }
7451 run_test 102h "grow xattr from inside inode to external block"
7452
7453 test_102ha() {
7454         large_xattr_enabled || { skip "ea_inode feature disabled" && return; }
7455         grow_xattr $(max_xattr_size)
7456 }
7457 run_test 102ha "grow xattr from inside inode to external inode"
7458
7459 test_102i() { # bug 17038
7460         [ -z "$(which getfattr 2>/dev/null)" ] &&
7461                 skip "could not find getfattr" && return
7462         touch $DIR/$tfile
7463         ln -s $DIR/$tfile $DIR/${tfile}link
7464         getfattr -n trusted.lov $DIR/$tfile ||
7465                 error "lgetxattr on $DIR/$tfile failed"
7466         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
7467                 grep -i "no such attr" ||
7468                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
7469         rm -f $DIR/$tfile $DIR/${tfile}link
7470 }
7471 run_test 102i "lgetxattr test on symbolic link ============"
7472
7473 test_102j() {
7474         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7475         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
7476         local xinc=$(have_xattrs_include)
7477         setup_test102 "$RUNAS"
7478         chown $RUNAS_ID $DIR/$tdir
7479         $RUNAS tar xf $TMP/f102.tar -C $DIR/$tdir --xattrs $xinc
7480         cd $DIR/$tdir/$tdir
7481         compare_stripe_info1 "$RUNAS"
7482 }
7483 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
7484
7485 test_102k() {
7486         [ -z "$(which setfattr 2>/dev/null)" ] &&
7487                 skip "could not find setfattr" && return
7488         touch $DIR/$tfile
7489         # b22187 just check that does not crash for regular file.
7490         setfattr -n trusted.lov $DIR/$tfile
7491         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
7492         local test_kdir=$DIR/$tdir
7493         test_mkdir $test_kdir
7494         local default_size=`$GETSTRIPE -S $test_kdir`
7495         local default_count=`$GETSTRIPE -c $test_kdir`
7496         local default_offset=`$GETSTRIPE -i $test_kdir`
7497         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
7498                 error 'dir setstripe failed'
7499         setfattr -n trusted.lov $test_kdir
7500         local stripe_size=`$GETSTRIPE -S $test_kdir`
7501         local stripe_count=`$GETSTRIPE -c $test_kdir`
7502         local stripe_offset=`$GETSTRIPE -i $test_kdir`
7503         [ $stripe_size -eq $default_size ] ||
7504                 error "stripe size $stripe_size != $default_size"
7505         [ $stripe_count -eq $default_count ] ||
7506                 error "stripe count $stripe_count != $default_count"
7507         [ $stripe_offset -eq $default_offset ] ||
7508                 error "stripe offset $stripe_offset != $default_offset"
7509         rm -rf $DIR/$tfile $test_kdir
7510 }
7511 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
7512
7513 test_102l() {
7514         [ -z "$(which getfattr 2>/dev/null)" ] &&
7515                 skip "could not find getfattr" && return
7516
7517         # LU-532 trusted. xattr is invisible to non-root
7518         local testfile=$DIR/$tfile
7519
7520         touch $testfile
7521
7522         echo "listxattr as user..."
7523         chown $RUNAS_ID $testfile
7524         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
7525             grep -q "trusted" &&
7526                 error "$testfile trusted xattrs are user visible"
7527
7528         return 0;
7529 }
7530 run_test 102l "listxattr size test =================================="
7531
7532 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
7533         local path=$DIR/$tfile
7534         touch $path
7535
7536         listxattr_size_check $path || error "listattr_size_check $path failed"
7537 }
7538 run_test 102m "Ensure listxattr fails on small bufffer ========"
7539
7540 cleanup_test102
7541
7542 getxattr() { # getxattr path name
7543         # Return the base64 encoding of the value of xattr name on path.
7544         local path=$1
7545         local name=$2
7546
7547         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
7548         # file: $path
7549         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
7550         #
7551         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
7552
7553         getfattr --absolute-names --encoding=base64 --name=$name $path |
7554                 awk -F= -v name=$name '$1 == name {
7555                         print substr($0, index($0, "=") + 1);
7556         }'
7557 }
7558
7559 test_102n() { # LU-4101 mdt: protect internal xattrs
7560         [ -z "$(which setfattr 2>/dev/null)" ] &&
7561                 skip "could not find setfattr" && return
7562         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
7563         then
7564                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
7565                 return
7566         fi
7567
7568         local file0=$DIR/$tfile.0
7569         local file1=$DIR/$tfile.1
7570         local xattr0=$TMP/$tfile.0
7571         local xattr1=$TMP/$tfile.1
7572         local namelist="lov lma lmv link fid version som hsm"
7573         local name
7574         local value
7575
7576         rm -rf $file0 $file1 $xattr0 $xattr1
7577         touch $file0 $file1
7578
7579         # Get 'before' xattrs of $file1.
7580         getfattr --absolute-names --dump --match=- $file1 > $xattr0
7581
7582         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
7583                 namelist+=" lfsck_namespace"
7584         for name in $namelist; do
7585                 # Try to copy xattr from $file0 to $file1.
7586                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7587
7588                 setfattr --name=trusted.$name --value="$value" $file1 ||
7589                         error "setxattr 'trusted.$name' failed"
7590
7591                 # Try to set a garbage xattr.
7592                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7593
7594                 if [[ x$name == "xlov" ]]; then
7595                         setfattr --name=trusted.lov --value="$value" $file1 &&
7596                         error "setxattr invalid 'trusted.lov' success"
7597                 else
7598                         setfattr --name=trusted.$name --value="$value" $file1 ||
7599                                 error "setxattr invalid 'trusted.$name' failed"
7600                 fi
7601
7602                 # Try to remove the xattr from $file1. We don't care if this
7603                 # appears to succeed or fail, we just don't want there to be
7604                 # any changes or crashes.
7605                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7606         done
7607
7608         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
7609         then
7610                 name="lfsck_ns"
7611                 # Try to copy xattr from $file0 to $file1.
7612                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7613
7614                 setfattr --name=trusted.$name --value="$value" $file1 ||
7615                         error "setxattr 'trusted.$name' failed"
7616
7617                 # Try to set a garbage xattr.
7618                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7619
7620                 setfattr --name=trusted.$name --value="$value" $file1 ||
7621                         error "setxattr 'trusted.$name' failed"
7622
7623                 # Try to remove the xattr from $file1. We don't care if this
7624                 # appears to succeed or fail, we just don't want there to be
7625                 # any changes or crashes.
7626                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7627         fi
7628
7629         # Get 'after' xattrs of file1.
7630         getfattr --absolute-names --dump --match=- $file1 > $xattr1
7631
7632         if ! diff $xattr0 $xattr1; then
7633                 error "before and after xattrs of '$file1' differ"
7634         fi
7635
7636         rm -rf $file0 $file1 $xattr0 $xattr1
7637
7638         return 0
7639 }
7640 run_test 102n "silently ignore setxattr on internal trusted xattrs"
7641
7642 test_102p() { # LU-4703 setxattr did not check ownership
7643         local testfile=$DIR/$tfile
7644
7645         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
7646                 skip "MDS needs to be at least 2.5.56" && return
7647
7648         touch $testfile
7649
7650         echo "setfacl as user..."
7651         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
7652         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
7653
7654         echo "setfattr as user..."
7655         setfacl -m "u:$RUNAS_ID:---" $testfile
7656         $RUNAS setfattr -x system.posix_acl_access $testfile
7657         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
7658 }
7659 run_test 102p "check setxattr(2) correctly fails without permission"
7660
7661 test_102q() {
7662         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
7663                 skip "MDS needs to be at least 2.6.92" && return
7664         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
7665 }
7666 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
7667
7668 test_102r() {
7669         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
7670                 skip "MDS needs to be at least 2.6.93" && return
7671         touch $DIR/$tfile || error "touch"
7672         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
7673         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
7674         rm $DIR/$tfile || error "rm"
7675
7676         #normal directory
7677         mkdir -p $DIR/$tdir || error "mkdir"
7678         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7679         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7680         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7681                 error "$testfile error deleting user.author1"
7682         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7683                 grep "user.$(basename $tdir)" &&
7684                 error "$tdir did not delete user.$(basename $tdir)"
7685         rmdir $DIR/$tdir || error "rmdir"
7686
7687         #striped directory
7688         test_mkdir $DIR/$tdir || error "make striped dir"
7689         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7690         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7691         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7692                 error "$testfile error deleting user.author1"
7693         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7694                 grep "user.$(basename $tdir)" &&
7695                 error "$tdir did not delete user.$(basename $tdir)"
7696         rmdir $DIR/$tdir || error "rm striped dir"
7697 }
7698 run_test 102r "set EAs with empty values"
7699
7700 test_102s() {
7701         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.52) ] &&
7702                 skip "MDS needs to be at least 2.11.52"
7703
7704         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
7705
7706         save_lustre_params client "llite.*.xattr_cache" > $save
7707
7708         for cache in 0 1; do
7709                 lctl set_param llite.*.xattr_cache=$cache
7710
7711                 rm -f $DIR/$tfile
7712                 touch $DIR/$tfile || error "touch"
7713                 for prefix in lustre security system trusted user; do
7714                         # Note getxattr() may fail with 'Operation not
7715                         # supported' or 'No such attribute' depending
7716                         # on prefix and cache.
7717                         getfattr -n $prefix.n102s $DIR/$tfile &&
7718                                 error "getxattr '$prefix.n102s' should fail (cache = $cache)"
7719                 done
7720         done
7721
7722         restore_lustre_params < $save
7723 }
7724 run_test 102s "getting nonexistent xattrs should fail"
7725
7726 run_acl_subtest()
7727 {
7728     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
7729     return $?
7730 }
7731
7732 test_103a() {
7733         [ "$UID" != 0 ] && skip_env "must run as root" && return
7734         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
7735                 skip "must have acl enabled" && return
7736         [ -z "$(which setfacl 2>/dev/null)" ] &&
7737                 skip_env "could not find setfacl" && return
7738         $GSS && skip "could not run under gss" && return
7739         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7740
7741         gpasswd -a daemon bin                           # LU-5641
7742         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
7743
7744         declare -a identity_old
7745
7746         for num in $(seq $MDSCOUNT); do
7747                 switch_identity $num true || identity_old[$num]=$?
7748         done
7749
7750         SAVE_UMASK=$(umask)
7751         umask 0022
7752         mkdir -p $DIR/$tdir
7753         cd $DIR/$tdir
7754
7755         echo "performing cp ..."
7756         run_acl_subtest cp || error "run_acl_subtest cp failed"
7757         echo "performing getfacl-noacl..."
7758         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
7759         echo "performing misc..."
7760         run_acl_subtest misc || error  "misc test failed"
7761         echo "performing permissions..."
7762         run_acl_subtest permissions || error "permissions failed"
7763         # LU-1482 mdd: Setting xattr are properly checked with and without ACLs
7764         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.8.55) -o \
7765              \( $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6) -a \
7766              $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.29) \) ]
7767         then
7768                 echo "performing permissions xattr..."
7769                 run_acl_subtest permissions_xattr ||
7770                         error "permissions_xattr failed"
7771         fi
7772         echo "performing setfacl..."
7773         run_acl_subtest setfacl || error  "setfacl test failed"
7774
7775         # inheritance test got from HP
7776         echo "performing inheritance..."
7777         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
7778         chmod +x make-tree || error "chmod +x failed"
7779         run_acl_subtest inheritance || error "inheritance test failed"
7780         rm -f make-tree
7781
7782         echo "LU-974 ignore umask when acl is enabled..."
7783         run_acl_subtest 974 || error "LU-974 umask test failed"
7784         if [ $MDSCOUNT -ge 2 ]; then
7785                 run_acl_subtest 974_remote ||
7786                         error "LU-974 umask test failed under remote dir"
7787         fi
7788
7789         echo "LU-2561 newly created file is same size as directory..."
7790         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
7791                 run_acl_subtest 2561 || error "LU-2561 test failed"
7792         else
7793                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
7794         fi
7795
7796         run_acl_subtest 4924 || error "LU-4924 test failed"
7797
7798         cd $SAVE_PWD
7799         umask $SAVE_UMASK
7800
7801         for num in $(seq $MDSCOUNT); do
7802                 if [ "${identity_old[$num]}" = 1 ]; then
7803                         switch_identity $num false || identity_old[$num]=$?
7804                 fi
7805         done
7806 }
7807 run_test 103a "acl test ========================================="
7808
7809 test_103b() {
7810         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7811         local noacl=false
7812         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
7813         local mountopts=$MDS_MOUNT_OPTS
7814
7815         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
7816                 noacl=true
7817         else
7818                 # stop the MDT
7819                 stop $SINGLEMDS || error "failed to stop MDT."
7820                 # remount the MDT
7821                 if [ -z "$MDS_MOUNT_OPTS" ]; then
7822                         MDS_MOUNT_OPTS="-o noacl"
7823                 else
7824                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
7825                 fi
7826                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7827                         error "failed to start MDT."
7828                 MDS_MOUNT_OPTS=$mountopts
7829         fi
7830
7831         touch $DIR/$tfile
7832         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
7833
7834         if ! $noacl; then
7835                 # stop the MDT
7836                 stop $SINGLEMDS || error "failed to stop MDT."
7837                 # remount the MDT
7838                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7839                         error "failed to start MDT."
7840         fi
7841
7842         true
7843 }
7844 run_test 103b "MDS mount option 'noacl'"
7845
7846 test_103c() {
7847         mkdir -p $DIR/$tdir
7848         cp -rp $DIR/$tdir $DIR/$tdir.bak
7849
7850         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
7851                 error "$DIR/$tdir shouldn't contain default ACL"
7852         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
7853                 error "$DIR/$tdir.bak shouldn't contain default ACL"
7854         true
7855 }
7856 run_test 103c "'cp -rp' won't set empty acl"
7857
7858 test_104a() {
7859         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7860         touch $DIR/$tfile
7861         lfs df || error "lfs df failed"
7862         lfs df -ih || error "lfs df -ih failed"
7863         lfs df -h $DIR || error "lfs df -h $DIR failed"
7864         lfs df -i $DIR || error "lfs df -i $DIR failed"
7865         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
7866         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
7867
7868         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
7869         lctl --device %$OSC deactivate
7870         lfs df || error "lfs df with deactivated OSC failed"
7871         lctl --device %$OSC activate
7872         # wait the osc back to normal
7873         wait_osc_import_state client ost FULL
7874
7875         lfs df || error "lfs df with reactivated OSC failed"
7876         rm -f $DIR/$tfile
7877 }
7878 run_test 104a "lfs df [-ih] [path] test ========================="
7879
7880 test_104b() {
7881         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7882         [ $RUNAS_ID -eq $UID ] &&
7883                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
7884         chmod 666 /dev/obd
7885         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
7886                         grep "Permission denied" | wc -l)))
7887         if [ $denied_cnt -ne 0 ]; then
7888                 error "lfs check servers test failed"
7889         fi
7890 }
7891 run_test 104b "$RUNAS lfs check servers test ===================="
7892
7893 test_105a() {
7894         # doesn't work on 2.4 kernels
7895         touch $DIR/$tfile
7896         if $(flock_is_enabled); then
7897                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7898         else
7899                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7900         fi
7901         rm -f $DIR/$tfile
7902 }
7903 run_test 105a "flock when mounted without -o flock test ========"
7904
7905 test_105b() {
7906         touch $DIR/$tfile
7907         if $(flock_is_enabled); then
7908                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7909         else
7910                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7911         fi
7912         rm -f $DIR/$tfile
7913 }
7914 run_test 105b "fcntl when mounted without -o flock test ========"
7915
7916 test_105c() {
7917         touch $DIR/$tfile
7918         if $(flock_is_enabled); then
7919                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7920         else
7921                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7922         fi
7923         rm -f $DIR/$tfile
7924 }
7925 run_test 105c "lockf when mounted without -o flock test ========"
7926
7927 test_105d() { # bug 15924
7928         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7929         test_mkdir -p $DIR/$tdir
7930         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7931         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7932         $LCTL set_param fail_loc=0x80000315
7933         flocks_test 2 $DIR/$tdir
7934 }
7935 run_test 105d "flock race (should not freeze) ========"
7936
7937 test_105e() { # bug 22660 && 22040
7938         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7939         touch $DIR/$tfile
7940         flocks_test 3 $DIR/$tfile
7941 }
7942 run_test 105e "Two conflicting flocks from same process ======="
7943
7944 test_106() { #bug 10921
7945         test_mkdir -p $DIR/$tdir
7946         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7947         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7948 }
7949 run_test 106 "attempt exec of dir followed by chown of that dir"
7950
7951 test_107() {
7952         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7953         CDIR=`pwd`
7954         cd $DIR
7955
7956         local file=core
7957         rm -f $file
7958
7959         local save_pattern=$(sysctl -n kernel.core_pattern)
7960         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7961         sysctl -w kernel.core_pattern=$file
7962         sysctl -w kernel.core_uses_pid=0
7963
7964         ulimit -c unlimited
7965         sleep 60 &
7966         SLEEPPID=$!
7967
7968         sleep 1
7969
7970         kill -s 11 $SLEEPPID
7971         wait $SLEEPPID
7972         if [ -e $file ]; then
7973                 size=`stat -c%s $file`
7974                 [ $size -eq 0 ] && error "Fail to create core file $file"
7975         else
7976                 error "Fail to create core file $file"
7977         fi
7978         rm -f $file
7979         sysctl -w kernel.core_pattern=$save_pattern
7980         sysctl -w kernel.core_uses_pid=$save_uses_pid
7981         cd $CDIR
7982 }
7983 run_test 107 "Coredump on SIG"
7984
7985 test_110() {
7986         test_mkdir -p $DIR/$tdir
7987         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7988                 error "mkdir with 255 char failed"
7989         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7990                 error "mkdir with 256 char should fail, but did not"
7991         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7992                 error "create with 255 char failed"
7993         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7994                 error "create with 256 char should fail, but did not"
7995
7996         ls -l $DIR/$tdir
7997         rm -rf $DIR/$tdir
7998 }
7999 run_test 110 "filename length checking"
8000
8001 #
8002 # Purpose: To verify dynamic thread (OSS) creation.
8003 #
8004 test_115() {
8005         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8006         remote_ost_nodsh && skip "remote OST with nodsh" && return
8007
8008         # Lustre does not stop service threads once they are started.
8009         # Reset number of running threads to default.
8010         stopall
8011         setupall
8012
8013         local OSTIO_pre
8014         local save_params="$TMP/sanity-$TESTNAME.parameters"
8015
8016         # Get ll_ost_io count before I/O
8017         OSTIO_pre=$(do_facet ost1 \
8018                 "$LCTL get_param ost.OSS.ost_io.threads_started | cut -d= -f2")
8019         # Exit if lustre is not running (ll_ost_io not running).
8020         [ -z "$OSTIO_pre" ] && error "no OSS threads"
8021
8022         echo "Starting with $OSTIO_pre threads"
8023         local thread_max=$((OSTIO_pre * 2))
8024         local rpc_in_flight=$((thread_max * 2))
8025         # Number of I/O Process proposed to be started.
8026         local nfiles
8027         local facets=$(get_facets OST)
8028
8029         save_lustre_params client \
8030                 "osc.*OST*.max_rpcs_in_flight" > $save_params
8031         save_lustre_params $facets \
8032                 "ost.OSS.ost_io.threads_max" >> $save_params
8033
8034         # Set in_flight to $rpc_in_flight
8035         $LCTL set_param osc.*OST*.max_rpcs_in_flight=$rpc_in_flight ||
8036                 error "Failed to set max_rpcs_in_flight to $rpc_in_flight"
8037         nfiles=${rpc_in_flight}
8038         # Set ost thread_max to $thread_max
8039         do_facet ost1 \
8040                 "$LCTL set_param ost.OSS.ost_io.threads_max=$thread_max"
8041
8042         # 5 Minutes should be sufficient for max number of OSS
8043         # threads(thread_max) to be created.
8044         local timeout=300
8045
8046         # Start I/O.
8047         local WTL=${WTL:-"$LUSTRE/tests/write_time_limit"}
8048         mkdir -p $DIR/$tdir
8049         for i in $(seq $nfiles); do
8050                 local file=$DIR/$tdir/${tfile}-$i
8051                 $LFS setstripe -c -1 -i 0 $file
8052                 ($WTL $file $timeout)&
8053         done
8054
8055         # I/O Started - Wait for thread_started to reach thread_max or report
8056         # error if thread_started is more than thread_max.
8057         echo "Waiting for thread_started to reach thread_max"
8058         local thread_started=0
8059         local end_time=$((SECONDS + timeout))
8060
8061         while [ $SECONDS -le $end_time ] ; do
8062                 echo -n "."
8063                 # Get ost i/o thread_started count.
8064                 thread_started=$(do_facet ost1 \
8065                         "$LCTL get_param \
8066                         ost.OSS.ost_io.threads_started | cut -d= -f2")
8067                 # Break out if thread_started is equal/greater than thread_max
8068                 if [[ $thread_started -ge $thread_max ]]; then
8069                         echo ll_ost_io thread_started $thread_started, \
8070                                 equal/greater than thread_max $thread_max
8071                         break
8072                 fi
8073                 sleep 1
8074         done
8075
8076         # Cleanup - We have the numbers, Kill i/o jobs if running.
8077         jobcount=($(jobs -p))
8078         for i in $(seq 0 $((${#jobcount[@]}-1)))
8079         do
8080                 kill -9 ${jobcount[$i]}
8081                 if [ $? -ne 0 ] ; then
8082                         echo Warning: \
8083                         Failed to Kill \'WTL\(I/O\)\' with pid ${jobcount[$i]}
8084                 fi
8085         done
8086
8087         # Cleanup files left by WTL binary.
8088         for i in $(seq $nfiles); do
8089                 local file=$DIR/$tdir/${tfile}-$i
8090                 rm -rf $file
8091                 if [ $? -ne 0 ] ; then
8092                         echo "Warning: Failed to delete file $file"
8093                 fi
8094         done
8095
8096         restore_lustre_params <$save_params
8097         rm -f $save_params || echo "Warning: delete file '$save_params' failed"
8098
8099         # Error out if no new thread has started or Thread started is greater
8100         # than thread max.
8101         if [[ $thread_started -le $OSTIO_pre ||
8102                         $thread_started -gt $thread_max ]]; then
8103                 error "ll_ost_io: thread_started $thread_started" \
8104                       "OSTIO_pre $OSTIO_pre, thread_max $thread_max." \
8105                       "No new thread started or thread started greater " \
8106                       "than thread_max."
8107         fi
8108 }
8109 run_test 115 "verify dynamic thread creation===================="
8110
8111 free_min_max () {
8112         wait_delete_completed
8113         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
8114         echo "OST kbytes available: ${AVAIL[@]}"
8115         MAXV=${AVAIL[0]}
8116         MAXI=0
8117         MINV=${AVAIL[0]}
8118         MINI=0
8119         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
8120                 #echo OST $i: ${AVAIL[i]}kb
8121                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
8122                         MAXV=${AVAIL[i]}
8123                         MAXI=$i
8124                 fi
8125                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
8126                         MINV=${AVAIL[i]}
8127                         MINI=$i
8128                 fi
8129         done
8130         echo "Min free space: OST $MINI: $MINV"
8131         echo "Max free space: OST $MAXI: $MAXV"
8132 }
8133
8134 test_116a() { # was previously test_116()
8135         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8136         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8137
8138         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
8139
8140         echo -n "Free space priority "
8141         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
8142                 head -n1
8143         declare -a AVAIL
8144         free_min_max
8145
8146         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
8147         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
8148                 && return
8149         trap simple_cleanup_common EXIT
8150
8151
8152         # Check if we need to generate uneven OSTs
8153         test_mkdir -p $DIR/$tdir/OST${MINI}
8154         local FILL=$((MINV / 4))
8155         local DIFF=$((MAXV - MINV))
8156         local DIFF2=$((DIFF * 100 / MINV))
8157
8158         local threshold=$(do_facet $SINGLEMDS \
8159                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
8160         threshold=${threshold%%%}
8161         echo -n "Check for uneven OSTs: "
8162         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
8163
8164         if [[ $DIFF2 -gt $threshold ]]; then
8165                 echo "ok"
8166                 echo "Don't need to fill OST$MINI"
8167         else
8168                 # generate uneven OSTs. Write 2% over the QOS threshold value
8169                 echo "no"
8170                 DIFF=$((threshold - DIFF2 + 2))
8171                 DIFF2=$((MINV * DIFF / 100))
8172                 echo "Fill $DIFF% remaining space in OST$MINI with ${DIFF2}KB"
8173                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
8174                         error "setstripe failed"
8175                 DIFF=$((DIFF2 / 2048))
8176                 i=0
8177                 while [ $i -lt $DIFF ]; do
8178                         i=$((i + 1))
8179                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
8180                                 bs=2M count=1 2>/dev/null
8181                         echo -n .
8182                 done
8183                 echo .
8184                 sync
8185                 sleep_maxage
8186                 free_min_max
8187         fi
8188
8189         DIFF=$((MAXV - MINV))
8190         DIFF2=$((DIFF * 100 / MINV))
8191         echo -n "diff=$DIFF=$DIFF2% must be > $threshold% for QOS mode..."
8192         if [ $DIFF2 -gt $threshold ]; then
8193                 echo "ok"
8194         else
8195                 echo "failed - QOS mode won't be used"
8196                 skip "QOS imbalance criteria not met"
8197                 simple_cleanup_common
8198                 return
8199         fi
8200
8201         MINI1=$MINI
8202         MINV1=$MINV
8203         MAXI1=$MAXI
8204         MAXV1=$MAXV
8205
8206         # now fill using QOS
8207         $SETSTRIPE -c 1 $DIR/$tdir
8208         FILL=$((FILL / 200))
8209         if [ $FILL -gt 600 ]; then
8210                 FILL=600
8211         fi
8212         echo "writing $FILL files to QOS-assigned OSTs"
8213         i=0
8214         while [ $i -lt $FILL ]; do
8215                 i=$((i + 1))
8216                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
8217                         count=1 2>/dev/null
8218                 echo -n .
8219         done
8220         echo "wrote $i 200k files"
8221         sync
8222         sleep_maxage
8223
8224         echo "Note: free space may not be updated, so measurements might be off"
8225         free_min_max
8226         DIFF2=$((MAXV - MINV))
8227         echo "free space delta: orig $DIFF final $DIFF2"
8228         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
8229         DIFF=$((MINV1 - ${AVAIL[$MINI1]}))
8230         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
8231         DIFF2=$((MAXV1 - ${AVAIL[$MAXI1]}))
8232         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
8233         if [[ $DIFF -gt 0 ]]; then
8234                 FILL=$((DIFF2 * 100 / DIFF - 100))
8235                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
8236         fi
8237
8238         # Figure out which files were written where
8239         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
8240                awk '/'$MINI1': / {print $2; exit}')
8241         echo $UUID
8242         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
8243         echo "$MINC files created on smaller OST $MINI1"
8244         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
8245                awk '/'$MAXI1': / {print $2; exit}')
8246         echo $UUID
8247         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
8248         echo "$MAXC files created on larger OST $MAXI1"
8249         if [[ $MINC -gt 0 ]]; then
8250                 FILL=$((MAXC * 100 / MINC - 100))
8251                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
8252         fi
8253         [[ $MAXC -gt $MINC ]] ||
8254                 error_ignore LU-9 "stripe QOS didn't balance free space"
8255         simple_cleanup_common
8256 }
8257 run_test 116a "stripe QOS: free space balance ==================="
8258
8259 test_116b() { # LU-2093
8260         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8261         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8262
8263 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
8264         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
8265                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
8266         [ -z "$old_rr" ] && skip "no QOS" && return 0
8267         do_facet $SINGLEMDS lctl set_param \
8268                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
8269         mkdir -p $DIR/$tdir
8270         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
8271         createmany -o $DIR/$tdir/f- 20 || error "can't create"
8272         do_facet $SINGLEMDS lctl set_param fail_loc=0
8273         rm -rf $DIR/$tdir
8274         do_facet $SINGLEMDS lctl set_param \
8275                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
8276 }
8277 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
8278
8279 test_117() # bug 10891
8280 {
8281         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8282         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
8283         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
8284         lctl set_param fail_loc=0x21e
8285         > $DIR/$tfile || error "truncate failed"
8286         lctl set_param fail_loc=0
8287         echo "Truncate succeeded."
8288         rm -f $DIR/$tfile
8289 }
8290 run_test 117 "verify osd extend =========="
8291
8292 NO_SLOW_RESENDCOUNT=4
8293 export OLD_RESENDCOUNT=""
8294 set_resend_count () {
8295         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
8296         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
8297         lctl set_param -n $PROC_RESENDCOUNT $1
8298         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
8299 }
8300
8301 # for reduce test_118* time (b=14842)
8302 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
8303
8304 # Reset async IO behavior after error case
8305 reset_async() {
8306         FILE=$DIR/reset_async
8307
8308         # Ensure all OSCs are cleared
8309         $SETSTRIPE -c -1 $FILE
8310         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
8311         sync
8312         rm $FILE
8313 }
8314
8315 test_118a() #bug 11710
8316 {
8317         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8318         reset_async
8319
8320         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8321         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8322         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8323
8324         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8325                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8326                 return 1;
8327         fi
8328         rm -f $DIR/$tfile
8329 }
8330 run_test 118a "verify O_SYNC works =========="
8331
8332 test_118b()
8333 {
8334         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8335         remote_ost_nodsh && skip "remote OST with nodsh" && return
8336
8337         reset_async
8338
8339         #define OBD_FAIL_SRV_ENOENT 0x217
8340         set_nodes_failloc "$(osts_nodes)" 0x217
8341         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8342         RC=$?
8343         set_nodes_failloc "$(osts_nodes)" 0
8344         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8345         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8346                     grep -c writeback)
8347
8348         if [[ $RC -eq 0 ]]; then
8349                 error "Must return error due to dropped pages, rc=$RC"
8350                 return 1;
8351         fi
8352
8353         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8354                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8355                 return 1;
8356         fi
8357
8358         echo "Dirty pages not leaked on ENOENT"
8359
8360         # Due to the above error the OSC will issue all RPCs syncronously
8361         # until a subsequent RPC completes successfully without error.
8362         $MULTIOP $DIR/$tfile Ow4096yc
8363         rm -f $DIR/$tfile
8364
8365         return 0
8366 }
8367 run_test 118b "Reclaim dirty pages on fatal error =========="
8368
8369 test_118c()
8370 {
8371         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8372
8373         # for 118c, restore the original resend count, LU-1940
8374         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
8375                                 set_resend_count $OLD_RESENDCOUNT
8376         remote_ost_nodsh && skip "remote OST with nodsh" && return
8377
8378         reset_async
8379
8380         #define OBD_FAIL_OST_EROFS               0x216
8381         set_nodes_failloc "$(osts_nodes)" 0x216
8382
8383         # multiop should block due to fsync until pages are written
8384         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8385         MULTIPID=$!
8386         sleep 1
8387
8388         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
8389                 error "Multiop failed to block on fsync, pid=$MULTIPID"
8390         fi
8391
8392         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8393                     grep -c writeback)
8394         if [[ $WRITEBACK -eq 0 ]]; then
8395                 error "No page in writeback, writeback=$WRITEBACK"
8396         fi
8397
8398         set_nodes_failloc "$(osts_nodes)" 0
8399         wait $MULTIPID
8400         RC=$?
8401         if [[ $RC -ne 0 ]]; then
8402                 error "Multiop fsync failed, rc=$RC"
8403         fi
8404
8405         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8406         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8407                     grep -c writeback)
8408         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8409                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8410         fi
8411
8412         rm -f $DIR/$tfile
8413         echo "Dirty pages flushed via fsync on EROFS"
8414         return 0
8415 }
8416 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
8417
8418 # continue to use small resend count to reduce test_118* time (b=14842)
8419 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
8420
8421 test_118d()
8422 {
8423         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8424         remote_ost_nodsh && skip "remote OST with nodsh" && return
8425
8426         reset_async
8427
8428         #define OBD_FAIL_OST_BRW_PAUSE_BULK
8429         set_nodes_failloc "$(osts_nodes)" 0x214
8430         # multiop should block due to fsync until pages are written
8431         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8432         MULTIPID=$!
8433         sleep 1
8434
8435         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
8436                 error "Multiop failed to block on fsync, pid=$MULTIPID"
8437         fi
8438
8439         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8440                     grep -c writeback)
8441         if [[ $WRITEBACK -eq 0 ]]; then
8442                 error "No page in writeback, writeback=$WRITEBACK"
8443         fi
8444
8445         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
8446         set_nodes_failloc "$(osts_nodes)" 0
8447
8448         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8449         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8450                     grep -c writeback)
8451         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8452                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8453         fi
8454
8455         rm -f $DIR/$tfile
8456         echo "Dirty pages gaurenteed flushed via fsync"
8457         return 0
8458 }
8459 run_test 118d "Fsync validation inject a delay of the bulk =========="
8460
8461 test_118f() {
8462         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8463         reset_async
8464
8465         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
8466         lctl set_param fail_loc=0x8000040a
8467
8468         # Should simulate EINVAL error which is fatal
8469         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8470         RC=$?
8471         if [[ $RC -eq 0 ]]; then
8472                 error "Must return error due to dropped pages, rc=$RC"
8473         fi
8474
8475         lctl set_param fail_loc=0x0
8476
8477         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8478         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8479         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8480                     grep -c writeback)
8481         if [[ $LOCKED -ne 0 ]]; then
8482                 error "Locked pages remain in cache, locked=$LOCKED"
8483         fi
8484
8485         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8486                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8487         fi
8488
8489         rm -f $DIR/$tfile
8490         echo "No pages locked after fsync"
8491
8492         reset_async
8493         return 0
8494 }
8495 run_test 118f "Simulate unrecoverable OSC side error =========="
8496
8497 test_118g() {
8498         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8499         reset_async
8500
8501         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
8502         lctl set_param fail_loc=0x406
8503
8504         # simulate local -ENOMEM
8505         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8506         RC=$?
8507
8508         lctl set_param fail_loc=0
8509         if [[ $RC -eq 0 ]]; then
8510                 error "Must return error due to dropped pages, rc=$RC"
8511         fi
8512
8513         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8514         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8515         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8516                         grep -c writeback)
8517         if [[ $LOCKED -ne 0 ]]; then
8518                 error "Locked pages remain in cache, locked=$LOCKED"
8519         fi
8520
8521         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8522                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8523         fi
8524
8525         rm -f $DIR/$tfile
8526         echo "No pages locked after fsync"
8527
8528         reset_async
8529         return 0
8530 }
8531 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
8532
8533 test_118h() {
8534         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8535         remote_ost_nodsh && skip "remote OST with nodsh" && return
8536
8537         reset_async
8538
8539         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8540         set_nodes_failloc "$(osts_nodes)" 0x20e
8541         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
8542         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8543         RC=$?
8544
8545         set_nodes_failloc "$(osts_nodes)" 0
8546         if [[ $RC -eq 0 ]]; then
8547                 error "Must return error due to dropped pages, rc=$RC"
8548         fi
8549
8550         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8551         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8552         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
8553                     grep -c writeback)
8554         if [[ $LOCKED -ne 0 ]]; then
8555                 error "Locked pages remain in cache, locked=$LOCKED"
8556         fi
8557
8558         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8559                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8560         fi
8561
8562         rm -f $DIR/$tfile
8563         echo "No pages locked after fsync"
8564
8565         return 0
8566 }
8567 run_test 118h "Verify timeout in handling recoverables errors  =========="
8568
8569 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
8570
8571 test_118i() {
8572         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8573         remote_ost_nodsh && skip "remote OST with nodsh" && return
8574
8575         reset_async
8576
8577         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8578         set_nodes_failloc "$(osts_nodes)" 0x20e
8579
8580         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
8581         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
8582         PID=$!
8583         sleep 5
8584         set_nodes_failloc "$(osts_nodes)" 0
8585
8586         wait $PID
8587         RC=$?
8588         if [[ $RC -ne 0 ]]; then
8589                 error "got error, but should be not, rc=$RC"
8590         fi
8591
8592         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8593         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8594         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8595         if [[ $LOCKED -ne 0 ]]; then
8596                 error "Locked pages remain in cache, locked=$LOCKED"
8597         fi
8598
8599         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8600                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8601         fi
8602
8603         rm -f $DIR/$tfile
8604         echo "No pages locked after fsync"
8605
8606         return 0
8607 }
8608 run_test 118i "Fix error before timeout in recoverable error  =========="
8609
8610 [ "$SLOW" = "no" ] && set_resend_count 4
8611
8612 test_118j() {
8613         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8614         remote_ost_nodsh && skip "remote OST with nodsh" && return
8615
8616         reset_async
8617
8618         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
8619         set_nodes_failloc "$(osts_nodes)" 0x220
8620
8621         # return -EIO from OST
8622         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
8623         RC=$?
8624         set_nodes_failloc "$(osts_nodes)" 0x0
8625         if [[ $RC -eq 0 ]]; then
8626                 error "Must return error due to dropped pages, rc=$RC"
8627         fi
8628
8629         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
8630         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
8631         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
8632         if [[ $LOCKED -ne 0 ]]; then
8633                 error "Locked pages remain in cache, locked=$LOCKED"
8634         fi
8635
8636         # in recoverable error on OST we want resend and stay until it finished
8637         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
8638                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
8639         fi
8640
8641         rm -f $DIR/$tfile
8642         echo "No pages locked after fsync"
8643
8644         return 0
8645 }
8646 run_test 118j "Simulate unrecoverable OST side error =========="
8647
8648 test_118k()
8649 {
8650         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8651         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
8652
8653         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
8654         set_nodes_failloc "$(osts_nodes)" 0x20e
8655         test_mkdir -p $DIR/$tdir
8656
8657         for ((i=0;i<10;i++)); do
8658                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
8659                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
8660                 SLEEPPID=$!
8661                 sleep 0.500s
8662                 kill $SLEEPPID
8663                 wait $SLEEPPID
8664         done
8665
8666         set_nodes_failloc "$(osts_nodes)" 0
8667         rm -rf $DIR/$tdir
8668 }
8669 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
8670
8671 test_118l()
8672 {
8673         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8674         # LU-646
8675         test_mkdir -p $DIR/$tdir
8676         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
8677         rm -rf $DIR/$tdir
8678 }
8679 run_test 118l "fsync dir ========="
8680
8681 test_118m() # LU-3066
8682 {
8683         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8684         test_mkdir -p $DIR/$tdir
8685         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
8686         rm -rf $DIR/$tdir
8687 }
8688 run_test 118m "fdatasync dir ========="
8689
8690 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
8691
8692 test_119a() # bug 11737
8693 {
8694         BSIZE=$((512 * 1024))
8695         directio write $DIR/$tfile 0 1 $BSIZE
8696         # We ask to read two blocks, which is more than a file size.
8697         # directio will indicate an error when requested and actual
8698         # sizes aren't equeal (a normal situation in this case) and
8699         # print actual read amount.
8700         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
8701         if [ "$NOB" != "$BSIZE" ]; then
8702                 error "read $NOB bytes instead of $BSIZE"
8703         fi
8704         rm -f $DIR/$tfile
8705 }
8706 run_test 119a "Short directIO read must return actual read amount"
8707
8708 test_119b() # bug 11737
8709 {
8710         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
8711
8712         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
8713         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
8714         sync
8715         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
8716                 error "direct read failed"
8717         rm -f $DIR/$tfile
8718 }
8719 run_test 119b "Sparse directIO read must return actual read amount"
8720
8721 test_119c() # bug 13099
8722 {
8723         BSIZE=1048576
8724         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
8725         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
8726         rm -f $DIR/$tfile
8727 }
8728 run_test 119c "Testing for direct read hitting hole"
8729
8730 test_119d() # bug 15950
8731 {
8732         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8733         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
8734         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
8735         BSIZE=1048576
8736         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
8737         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
8738         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
8739         lctl set_param fail_loc=0x40d
8740         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
8741         pid_dio=$!
8742         sleep 1
8743         cat $DIR/$tfile > /dev/null &
8744         lctl set_param fail_loc=0
8745         pid_reads=$!
8746         wait $pid_dio
8747         log "the DIO writes have completed, now wait for the reads (should not block very long)"
8748         sleep 2
8749         [ -n "`ps h -p $pid_reads -o comm`" ] && \
8750         error "the read rpcs have not completed in 2s"
8751         rm -f $DIR/$tfile
8752         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
8753 }
8754 run_test 119d "The DIO path should try to send a new rpc once one is completed"
8755
8756 test_120a() {
8757         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8758         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8759         test_mkdir -p $DIR/$tdir
8760         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8761                skip "no early lock cancel on server" && return 0
8762
8763         lru_resize_disable mdc
8764         lru_resize_disable osc
8765         cancel_lru_locks mdc
8766         # asynchronous object destroy at MDT could cause bl ast to client
8767         cancel_lru_locks osc
8768
8769         stat $DIR/$tdir > /dev/null
8770         can1=$(do_facet $SINGLEMDS \
8771                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8772                awk '/ldlm_cancel/ {print $2}')
8773         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8774                awk '/ldlm_bl_callback/ {print $2}')
8775         test_mkdir -c1 $DIR/$tdir/d1
8776         can2=$(do_facet $SINGLEMDS \
8777                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8778                awk '/ldlm_cancel/ {print $2}')
8779         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8780                awk '/ldlm_bl_callback/ {print $2}')
8781         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8782         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8783         lru_resize_enable mdc
8784         lru_resize_enable osc
8785 }
8786 run_test 120a "Early Lock Cancel: mkdir test"
8787
8788 test_120b() {
8789         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8790         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8791         test_mkdir $DIR/$tdir
8792         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8793                skip "no early lock cancel on server" && return 0
8794         lru_resize_disable mdc
8795         lru_resize_disable osc
8796         cancel_lru_locks mdc
8797         stat $DIR/$tdir > /dev/null
8798         can1=$(do_facet $SINGLEMDS \
8799                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8800                awk '/ldlm_cancel/ {print $2}')
8801         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8802                awk '/ldlm_bl_callback/ {print $2}')
8803         touch $DIR/$tdir/f1
8804         can2=$(do_facet $SINGLEMDS \
8805                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8806                awk '/ldlm_cancel/ {print $2}')
8807         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8808                awk '/ldlm_bl_callback/ {print $2}')
8809         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8810         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8811         lru_resize_enable mdc
8812         lru_resize_enable osc
8813 }
8814 run_test 120b "Early Lock Cancel: create test"
8815
8816 test_120c() {
8817         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8818         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8819         test_mkdir -c1 $DIR/$tdir
8820         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8821                skip "no early lock cancel on server" && return 0
8822         lru_resize_disable mdc
8823         lru_resize_disable osc
8824         test_mkdir -p -c1 $DIR/$tdir/d1
8825         test_mkdir -p -c1 $DIR/$tdir/d2
8826         touch $DIR/$tdir/d1/f1
8827         cancel_lru_locks mdc
8828         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
8829         can1=$(do_facet $SINGLEMDS \
8830                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8831                awk '/ldlm_cancel/ {print $2}')
8832         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8833                awk '/ldlm_bl_callback/ {print $2}')
8834         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8835         can2=$(do_facet $SINGLEMDS \
8836                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8837                awk '/ldlm_cancel/ {print $2}')
8838         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8839                awk '/ldlm_bl_callback/ {print $2}')
8840         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8841         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8842         lru_resize_enable mdc
8843         lru_resize_enable osc
8844 }
8845 run_test 120c "Early Lock Cancel: link test"
8846
8847 test_120d() {
8848         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8849         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8850         test_mkdir -p -c1 $DIR/$tdir
8851         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8852                skip "no early lock cancel on server" && return 0
8853         lru_resize_disable mdc
8854         lru_resize_disable osc
8855         touch $DIR/$tdir
8856         cancel_lru_locks mdc
8857         stat $DIR/$tdir > /dev/null
8858         can1=$(do_facet $SINGLEMDS \
8859                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8860                awk '/ldlm_cancel/ {print $2}')
8861         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8862                awk '/ldlm_bl_callback/ {print $2}')
8863         chmod a+x $DIR/$tdir
8864         can2=$(do_facet $SINGLEMDS \
8865                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8866                awk '/ldlm_cancel/ {print $2}')
8867         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8868                awk '/ldlm_bl_callback/ {print $2}')
8869         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8870         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8871         lru_resize_enable mdc
8872         lru_resize_enable osc
8873 }
8874 run_test 120d "Early Lock Cancel: setattr test"
8875
8876 test_120e() {
8877         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8878         ! $($LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_can) &&
8879                 skip "no early lock cancel on server" && return 0
8880         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8881         local dlmtrace_set=false
8882
8883         test_mkdir -p -c1 $DIR/$tdir
8884         lru_resize_disable mdc
8885         lru_resize_disable osc
8886         ! $LCTL get_param debug | grep -q dlmtrace &&
8887                 $LCTL set_param debug=+dlmtrace && dlmtrace_set=true
8888         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
8889         cancel_lru_locks mdc
8890         cancel_lru_locks osc
8891         dd if=$DIR/$tdir/f1 of=/dev/null
8892         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
8893         # XXX client can not do early lock cancel of OST lock
8894         # during unlink (LU-4206), so cancel osc lock now.
8895         sleep 2
8896         cancel_lru_locks osc
8897         can1=$(do_facet $SINGLEMDS \
8898                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8899                awk '/ldlm_cancel/ {print $2}')
8900         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8901                awk '/ldlm_bl_callback/ {print $2}')
8902         unlink $DIR/$tdir/f1
8903         sleep 5
8904         can2=$(do_facet $SINGLEMDS \
8905                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8906                awk '/ldlm_cancel/ {print $2}')
8907         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8908                awk '/ldlm_bl_callback/ {print $2}')
8909         [ $can1 -ne $can2 ] && error "$((can2 - can1)) cancel RPC occured" &&
8910                 $LCTL dk $TMP/cancel.debug.txt
8911         [ $blk1 -ne $blk2 ] && error "$((blk2 - blk1)) blocking RPC occured" &&
8912                 $LCTL dk $TMP/blocking.debug.txt
8913         $dlmtrace_set && $LCTL set_param debug=-dlmtrace
8914         lru_resize_enable mdc
8915         lru_resize_enable osc
8916 }
8917 run_test 120e "Early Lock Cancel: unlink test"
8918
8919 test_120f() {
8920         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8921         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8922                skip "no early lock cancel on server" && return 0
8923         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8924         test_mkdir -p -c1 $DIR/$tdir
8925         lru_resize_disable mdc
8926         lru_resize_disable osc
8927         test_mkdir -p -c1 $DIR/$tdir/d1
8928         test_mkdir -p -c1 $DIR/$tdir/d2
8929         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
8930         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
8931         cancel_lru_locks mdc
8932         cancel_lru_locks osc
8933         dd if=$DIR/$tdir/d1/f1 of=/dev/null
8934         dd if=$DIR/$tdir/d2/f2 of=/dev/null
8935         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
8936         # XXX client can not do early lock cancel of OST lock
8937         # during rename (LU-4206), so cancel osc lock now.
8938         sleep 2
8939         cancel_lru_locks osc
8940         can1=$(do_facet $SINGLEMDS \
8941                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8942                awk '/ldlm_cancel/ {print $2}')
8943         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8944                awk '/ldlm_bl_callback/ {print $2}')
8945         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8946         sleep 5
8947         can2=$(do_facet $SINGLEMDS \
8948                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8949                awk '/ldlm_cancel/ {print $2}')
8950         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8951                awk '/ldlm_bl_callback/ {print $2}')
8952         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8953         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8954         lru_resize_enable mdc
8955         lru_resize_enable osc
8956 }
8957 run_test 120f "Early Lock Cancel: rename test"
8958
8959 test_120g() {
8960         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8961         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8962                skip "no early lock cancel on server" && return 0
8963         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8964         lru_resize_disable mdc
8965         lru_resize_disable osc
8966         count=10000
8967         echo create $count files
8968         test_mkdir -p $DIR/$tdir
8969         cancel_lru_locks mdc
8970         cancel_lru_locks osc
8971         t0=`date +%s`
8972
8973         can0=$(do_facet $SINGLEMDS \
8974                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8975                awk '/ldlm_cancel/ {print $2}')
8976         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8977                awk '/ldlm_bl_callback/ {print $2}')
8978         createmany -o $DIR/$tdir/f $count
8979         sync
8980         can1=$(do_facet $SINGLEMDS \
8981                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8982                awk '/ldlm_cancel/ {print $2}')
8983         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8984                awk '/ldlm_bl_callback/ {print $2}')
8985         t1=$(date +%s)
8986         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
8987         echo rm $count files
8988         rm -r $DIR/$tdir
8989         sync
8990         can2=$(do_facet $SINGLEMDS \
8991                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8992                awk '/ldlm_cancel/ {print $2}')
8993         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8994                awk '/ldlm_bl_callback/ {print $2}')
8995         t2=$(date +%s)
8996         echo total: $count removes in $((t2-t1))
8997         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
8998         sleep 2
8999         # wait for commitment of removal
9000         lru_resize_enable mdc
9001         lru_resize_enable osc
9002 }
9003 run_test 120g "Early Lock Cancel: performance test"
9004
9005 test_121() { #bug #10589
9006         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9007         rm -rf $DIR/$tfile
9008         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
9009 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
9010         lctl set_param fail_loc=0x310
9011         cancel_lru_locks osc > /dev/null
9012         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
9013         lctl set_param fail_loc=0
9014         [[ $reads -eq $writes ]] ||
9015                 error "read $reads blocks, must be $writes blocks"
9016 }
9017 run_test 121 "read cancel race ========="
9018
9019 test_123a() { # was test 123, statahead(bug 11401)
9020         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9021         SLOWOK=0
9022         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
9023             log "testing on UP system. Performance may be not as good as expected."
9024                         SLOWOK=1
9025         fi
9026
9027         rm -rf $DIR/$tdir
9028         test_mkdir -p $DIR/$tdir
9029         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
9030         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
9031         MULT=10
9032         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
9033                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
9034
9035                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
9036                 lctl set_param -n llite.*.statahead_max 0
9037                 lctl get_param llite.*.statahead_max
9038                 cancel_lru_locks mdc
9039                 cancel_lru_locks osc
9040                 stime=`date +%s`
9041                 time ls -l $DIR/$tdir | wc -l
9042                 etime=`date +%s`
9043                 delta=$((etime - stime))
9044                 log "ls $i files without statahead: $delta sec"
9045                 lctl set_param llite.*.statahead_max=$max
9046
9047                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
9048                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
9049                 cancel_lru_locks mdc
9050                 cancel_lru_locks osc
9051                 stime=`date +%s`
9052                 time ls -l $DIR/$tdir | wc -l
9053                 etime=`date +%s`
9054                 delta_sa=$((etime - stime))
9055                 log "ls $i files with statahead: $delta_sa sec"
9056                 lctl get_param -n llite.*.statahead_stats
9057                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
9058
9059                 [[ $swrong -lt $ewrong ]] &&
9060                         log "statahead was stopped, maybe too many locks held!"
9061                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
9062
9063                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
9064                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
9065                     lctl set_param -n llite.*.statahead_max 0
9066                     lctl get_param llite.*.statahead_max
9067                     cancel_lru_locks mdc
9068                     cancel_lru_locks osc
9069                     stime=`date +%s`
9070                     time ls -l $DIR/$tdir | wc -l
9071                     etime=`date +%s`
9072                     delta=$((etime - stime))
9073                     log "ls $i files again without statahead: $delta sec"
9074                     lctl set_param llite.*.statahead_max=$max
9075                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
9076                         if [  $SLOWOK -eq 0 ]; then
9077                                 error "ls $i files is slower with statahead!"
9078                         else
9079                                 log "ls $i files is slower with statahead!"
9080                         fi
9081                         break
9082                     fi
9083                 fi
9084
9085                 [ $delta -gt 20 ] && break
9086                 [ $delta -gt 8 ] && MULT=$((50 / delta))
9087                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
9088         done
9089         log "ls done"
9090
9091         stime=`date +%s`
9092         rm -r $DIR/$tdir
9093         sync
9094         etime=`date +%s`
9095         delta=$((etime - stime))
9096         log "rm -r $DIR/$tdir/: $delta seconds"
9097         log "rm done"
9098         lctl get_param -n llite.*.statahead_stats
9099 }
9100 run_test 123a "verify statahead work"
9101
9102 test_123b () { # statahead(bug 15027)
9103         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9104         test_mkdir -p $DIR/$tdir
9105         createmany -o $DIR/$tdir/$tfile-%d 1000
9106
9107         cancel_lru_locks mdc
9108         cancel_lru_locks osc
9109
9110 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
9111         lctl set_param fail_loc=0x80000803
9112         ls -lR $DIR/$tdir > /dev/null
9113         log "ls done"
9114         lctl set_param fail_loc=0x0
9115         lctl get_param -n llite.*.statahead_stats
9116         rm -r $DIR/$tdir
9117         sync
9118
9119 }
9120 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
9121
9122 test_124a() {
9123         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9124         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
9125                 skip "no lru resize on server" && return 0
9126         local NR=2000
9127         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9128
9129         log "create $NR files at $DIR/$tdir"
9130         createmany -o $DIR/$tdir/f $NR ||
9131                 error "failed to create $NR files in $DIR/$tdir"
9132
9133         cancel_lru_locks mdc
9134         ls -l $DIR/$tdir > /dev/null
9135
9136         local NSDIR=""
9137         local LRU_SIZE=0
9138         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
9139                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
9140                 LRU_SIZE=$($LCTL get_param -n $PARAM)
9141                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
9142                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
9143                         log "NSDIR=$NSDIR"
9144                         log "NS=$(basename $NSDIR)"
9145                         break
9146                 fi
9147         done
9148
9149         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
9150                 skip "Not enough cached locks created!"
9151                 return 0
9152         fi
9153         log "LRU=$LRU_SIZE"
9154
9155         local SLEEP=30
9156
9157         # We know that lru resize allows one client to hold $LIMIT locks
9158         # for 10h. After that locks begin to be killed by client.
9159         local MAX_HRS=10
9160         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
9161         log "LIMIT=$LIMIT"
9162         if [ $LIMIT -lt $LRU_SIZE ]; then
9163             skip "Limit is too small $LIMIT"
9164             return 0
9165         fi
9166
9167         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
9168         # killing locks. Some time was spent for creating locks. This means
9169         # that up to the moment of sleep finish we must have killed some of
9170         # them (10-100 locks). This depends on how fast ther were created.
9171         # Many of them were touched in almost the same moment and thus will
9172         # be killed in groups.
9173         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
9174
9175         # Use $LRU_SIZE_B here to take into account real number of locks
9176         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
9177         local LRU_SIZE_B=$LRU_SIZE
9178         log "LVF=$LVF"
9179         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
9180         log "OLD_LVF=$OLD_LVF"
9181         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
9182
9183         # Let's make sure that we really have some margin. Client checks
9184         # cached locks every 10 sec.
9185         SLEEP=$((SLEEP+20))
9186         log "Sleep ${SLEEP} sec"
9187         local SEC=0
9188         while ((SEC<$SLEEP)); do
9189                 echo -n "..."
9190                 sleep 5
9191                 SEC=$((SEC+5))
9192                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
9193                 echo -n "$LRU_SIZE"
9194         done
9195         echo ""
9196         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
9197         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
9198
9199         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
9200                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
9201                 unlinkmany $DIR/$tdir/f $NR
9202                 return
9203         }
9204
9205         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
9206         log "unlink $NR files at $DIR/$tdir"
9207         unlinkmany $DIR/$tdir/f $NR
9208 }
9209 run_test 124a "lru resize ======================================="
9210
9211 get_max_pool_limit()
9212 {
9213         local limit=$($LCTL get_param \
9214                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
9215         local max=0
9216         for l in $limit; do
9217                 if [[ $l -gt $max ]]; then
9218                         max=$l
9219                 fi
9220         done
9221         echo $max
9222 }
9223
9224 test_124b() {
9225         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9226         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
9227                 skip "no lru resize on server" && return 0
9228
9229         LIMIT=$(get_max_pool_limit)
9230
9231         NR=$(($(default_lru_size)*20))
9232         if [[ $NR -gt $LIMIT ]]; then
9233                 log "Limit lock number by $LIMIT locks"
9234                 NR=$LIMIT
9235         fi
9236
9237         IFree=$(mdsrate_inodes_available)
9238         if [ $IFree -lt $NR ]; then
9239                 log "Limit lock number by $IFree inodes"
9240                 NR=$IFree
9241         fi
9242
9243         lru_resize_disable mdc
9244         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
9245                 error "failed to create $DIR/$tdir/disable_lru_resize"
9246
9247         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
9248         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
9249         cancel_lru_locks mdc
9250         stime=`date +%s`
9251         PID=""
9252         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
9253         PID="$PID $!"
9254         sleep 2
9255         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
9256         PID="$PID $!"
9257         sleep 2
9258         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
9259         PID="$PID $!"
9260         wait $PID
9261         etime=`date +%s`
9262         nolruresize_delta=$((etime-stime))
9263         log "ls -la time: $nolruresize_delta seconds"
9264         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
9265         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
9266
9267         lru_resize_enable mdc
9268         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
9269                 error "failed to create $DIR/$tdir/enable_lru_resize"
9270
9271         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
9272         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
9273         cancel_lru_locks mdc
9274         stime=`date +%s`
9275         PID=""
9276         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9277         PID="$PID $!"
9278         sleep 2
9279         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9280         PID="$PID $!"
9281         sleep 2
9282         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
9283         PID="$PID $!"
9284         wait $PID
9285         etime=`date +%s`
9286         lruresize_delta=$((etime-stime))
9287         log "ls -la time: $lruresize_delta seconds"
9288         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
9289
9290         if [ $lruresize_delta -gt $nolruresize_delta ]; then
9291                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
9292         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
9293                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
9294         else
9295                 log "lru resize performs the same with no lru resize"
9296         fi
9297         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
9298 }
9299 run_test 124b "lru resize (performance test) ======================="
9300
9301 test_124c() {
9302         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9303         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
9304                 skip "no lru resize on server" && return 0
9305
9306         # cache ununsed locks on client
9307         local nr=100
9308         cancel_lru_locks mdc
9309         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9310         createmany -o $DIR/$tdir/f $nr ||
9311                 error "failed to create $nr files in $DIR/$tdir"
9312         ls -l $DIR/$tdir > /dev/null
9313
9314         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
9315         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9316         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
9317         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
9318         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
9319
9320         # set lru_max_age to 1 sec
9321         $LCTL set_param $nsdir.lru_max_age=1000 # milliseconds
9322         echo "sleep $((recalc_p * 2)) seconds..."
9323         sleep $((recalc_p * 2))
9324
9325         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
9326         # restore lru_max_age
9327         $LCTL set_param -n $nsdir.lru_max_age $max_age
9328         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
9329         unlinkmany $DIR/$tdir/f $nr
9330 }
9331 run_test 124c "LRUR cancel very aged locks"
9332
9333 test_125() { # 13358
9334         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
9335         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
9336         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9337         test_mkdir -p $DIR/d125 || error "mkdir failed"
9338         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
9339         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
9340         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
9341 }
9342 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
9343
9344 test_126() { # bug 12829/13455
9345         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
9346         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
9347         $GSS && skip "must run as gss disabled" && return
9348
9349         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
9350         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
9351         rm -f $DIR/$tfile
9352         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
9353 }
9354 run_test 126 "check that the fsgid provided by the client is taken into account"
9355
9356 test_127a() { # bug 15521
9357         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9358         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
9359         $LCTL set_param osc.*.stats=0
9360         FSIZE=$((2048 * 1024))
9361         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9362         cancel_lru_locks osc
9363         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
9364
9365         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
9366         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
9367                 echo "got $COUNT $NAME"
9368                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
9369                 eval $NAME=$COUNT || error "Wrong proc format"
9370
9371                 case $NAME in
9372                         read_bytes|write_bytes)
9373                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
9374                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
9375                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
9376                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
9377                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
9378                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
9379                                 error "sumsquare is too small: $SUMSQ"
9380                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
9381                                 error "sumsquare is too big: $SUMSQ"
9382                         ;;
9383                         *) ;;
9384                 esac
9385         done < $DIR/${tfile}.tmp
9386
9387         #check that we actually got some stats
9388         [ "$read_bytes" ] || error "Missing read_bytes stats"
9389         [ "$write_bytes" ] || error "Missing write_bytes stats"
9390         [ "$read_bytes" != 0 ] || error "no read done"
9391         [ "$write_bytes" != 0 ] || error "no write done"
9392 }
9393 run_test 127a "verify the client stats are sane"
9394
9395 test_127b() { # bug LU-333
9396         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9397         $LCTL set_param llite.*.stats=0
9398         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
9399         # perform 2 reads and writes so MAX is different from SUM.
9400         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9401         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
9402         cancel_lru_locks osc
9403         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
9404         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
9405
9406         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
9407         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
9408                 echo "got $COUNT $NAME"
9409                 eval $NAME=$COUNT || error "Wrong proc format"
9410
9411         case $NAME in
9412                 read_bytes)
9413                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
9414                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
9415                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
9416                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
9417                         ;;
9418                 write_bytes)
9419                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
9420                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
9421                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
9422                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
9423                         ;;
9424                         *) ;;
9425                 esac
9426         done < $TMP/${tfile}.tmp
9427
9428         #check that we actually got some stats
9429         [ "$read_bytes" ] || error "Missing read_bytes stats"
9430         [ "$write_bytes" ] || error "Missing write_bytes stats"
9431         [ "$read_bytes" != 0 ] || error "no read done"
9432         [ "$write_bytes" != 0 ] || error "no write done"
9433
9434         rm -f $TMP/${tfile}.tmp
9435 }
9436 run_test 127b "verify the llite client stats are sane"
9437
9438 test_128() { # bug 15212
9439         touch $DIR/$tfile
9440         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
9441                 find $DIR/$tfile
9442                 find $DIR/$tfile
9443         EOF
9444
9445         result=$(grep error $TMP/$tfile.log)
9446         rm -f $DIR/$tfile $TMP/$tfile.log
9447         [ -z "$result" ] ||
9448                 error "consecutive find's under interactive lfs failed"
9449 }
9450 run_test 128 "interactive lfs for 2 consecutive find's"
9451
9452 set_dir_limits () {
9453         local mntdev
9454         local canondev
9455         local node
9456
9457         local ldproc=/proc/fs/ldiskfs
9458         local facets=$(get_facets MDS)
9459
9460         for facet in ${facets//,/ }; do
9461                 canondev=$(ldiskfs_canon \
9462                            *.$(convert_facet2label $facet).mntdev $facet)
9463                 do_facet $facet "test -e $ldproc/$canondev/max_dir_size" ||
9464                         ldproc=/sys/fs/ldiskfs
9465                 do_facet $facet "echo $1 >$ldproc/$canondev/max_dir_size"
9466                 do_facet $facet "echo $2 >$ldproc/$canondev/warning_dir_size"
9467         done
9468 }
9469
9470 check_mds_dmesg() {
9471         local facets=$(get_facets MDS)
9472         for facet in ${facets//,/ }; do
9473                 do_facet $facet "dmesg | tail -3 | grep -q $1" && return 0
9474         done
9475         return 1
9476 }
9477
9478 test_129() {
9479         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.56) ]] ||
9480                 { skip "Need MDS version with at least 2.5.56"; return 0; }
9481
9482         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9483         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
9484                 skip "ldiskfs only test"
9485                 return
9486         fi
9487         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9488         local ENOSPC=28
9489         local EFBIG=27
9490         local has_warning=false
9491
9492         rm -rf $DIR/$tdir
9493         mkdir -p $DIR/$tdir
9494
9495         # block size of mds1
9496         local maxsize=$(($($LCTL get_param -n mdc.*MDT0000*.blocksize) * 5))
9497         set_dir_limits $maxsize $maxsize
9498         local dirsize=$(stat -c%s "$DIR/$tdir")
9499         local nfiles=0
9500         while [[ $dirsize -le $maxsize ]]; do
9501                 $MULTIOP $DIR/$tdir/file_base_$nfiles Oc
9502                 rc=$?
9503                 if ! $has_warning; then
9504                         check_mds_dmesg '"is approaching"' && has_warning=true
9505                 fi
9506                 # check two errors:
9507                 # ENOSPC for new ext4 max_dir_size (kernel commit df981d03ee)
9508                 # EFBIG for previous versions included in ldiskfs series
9509                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
9510                         set_dir_limits 0 0
9511                         echo "return code $rc received as expected"
9512
9513                         createmany -o $DIR/$tdir/file_extra_$nfiles. 5 ||
9514                                 error_exit "create failed w/o dir size limit"
9515
9516                         check_mds_dmesg '"has reached"' ||
9517                                 error_exit "reached message should be output"
9518
9519                         [ $has_warning = "false" ] &&
9520                                 error_exit "warning message should be output"
9521
9522                         dirsize=$(stat -c%s "$DIR/$tdir")
9523
9524                         [[ $dirsize -ge $maxsize ]] && return 0
9525                         error_exit "current dir size $dirsize, " \
9526                                    "previous limit $maxsize"
9527                 elif [ $rc -ne 0 ]; then
9528                         set_dir_limits 0 0
9529                         error_exit "return $rc received instead of expected " \
9530                                    "$EFBIG or $ENOSPC, files in dir $dirsize"
9531                 fi
9532                 nfiles=$((nfiles + 1))
9533                 dirsize=$(stat -c%s "$DIR/$tdir")
9534         done
9535
9536         set_dir_limits 0 0
9537         error "exceeded dir size limit $maxsize($MDSCOUNT) : $dirsize bytes"
9538 }
9539 run_test 129 "test directory size limit ========================"
9540
9541 OLDIFS="$IFS"
9542 cleanup_130() {
9543         trap 0
9544         IFS="$OLDIFS"
9545 }
9546
9547 test_130a() {
9548         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9549         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
9550                 return
9551
9552         trap cleanup_130 EXIT RETURN
9553
9554         local fm_file=$DIR/$tfile
9555         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
9556         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
9557                 error "dd failed for $fm_file"
9558
9559         # LU-1795: test filefrag/FIEMAP once, even if unsupported
9560         filefrag -ves $fm_file
9561         RC=$?
9562         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9563                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9564         [ $RC != 0 ] && error "filefrag $fm_file failed"
9565
9566         filefrag_op=$(filefrag -ve $fm_file |
9567                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9568         lun=$($GETSTRIPE -i $fm_file)
9569
9570         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
9571         IFS=$'\n'
9572         tot_len=0
9573         for line in $filefrag_op
9574         do
9575                 frag_lun=`echo $line | cut -d: -f5`
9576                 ext_len=`echo $line | cut -d: -f4`
9577                 if (( $frag_lun != $lun )); then
9578                         cleanup_130
9579                         error "FIEMAP on 1-stripe file($fm_file) failed"
9580                         return
9581                 fi
9582                 (( tot_len += ext_len ))
9583         done
9584
9585         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
9586                 cleanup_130
9587                 error "FIEMAP on 1-stripe file($fm_file) failed;"
9588                 return
9589         fi
9590
9591         cleanup_130
9592
9593         echo "FIEMAP on single striped file succeeded"
9594 }
9595 run_test 130a "FIEMAP (1-stripe file)"
9596
9597 test_130b() {
9598         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
9599
9600         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9601         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
9602                 return
9603
9604         trap cleanup_130 EXIT RETURN
9605
9606         local fm_file=$DIR/$tfile
9607         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
9608                         error "setstripe on $fm_file"
9609         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9610                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9611
9612         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT ||
9613                 error "dd failed on $fm_file"
9614
9615         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9616         filefrag_op=$(filefrag -ve $fm_file |
9617                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9618
9619         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9620                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9621
9622         IFS=$'\n'
9623         tot_len=0
9624         num_luns=1
9625         for line in $filefrag_op
9626         do
9627                 frag_lun=$(echo $line | cut -d: -f5 |
9628                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9629                 ext_len=$(echo $line | cut -d: -f4)
9630                 if (( $frag_lun != $last_lun )); then
9631                         if (( tot_len != 1024 )); then
9632                                 cleanup_130
9633                                 error "FIEMAP on $fm_file failed; returned " \
9634                                 "len $tot_len for OST $last_lun instead of 1024"
9635                                 return
9636                         else
9637                                 (( num_luns += 1 ))
9638                                 tot_len=0
9639                         fi
9640                 fi
9641                 (( tot_len += ext_len ))
9642                 last_lun=$frag_lun
9643         done
9644         if (( num_luns != $OSTCOUNT || tot_len != 1024 )); then
9645                 cleanup_130
9646                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9647                         "luns or wrong len for OST $last_lun"
9648                 return
9649         fi
9650
9651         cleanup_130
9652
9653         echo "FIEMAP on $OSTCOUNT-stripe file succeeded"
9654 }
9655 run_test 130b "FIEMAP ($OSTCOUNT-stripe file)"
9656
9657 test_130c() {
9658         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
9659
9660         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9661         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
9662                 return
9663
9664         trap cleanup_130 EXIT RETURN
9665
9666         local fm_file=$DIR/$tfile
9667         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
9668         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9669                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9670
9671         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 ||
9672                         error "dd failed on $fm_file"
9673
9674         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9675         filefrag_op=$(filefrag -ve $fm_file |
9676                 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9677
9678         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9679                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9680
9681         IFS=$'\n'
9682         tot_len=0
9683         num_luns=1
9684         for line in $filefrag_op
9685         do
9686                 frag_lun=$(echo $line | cut -d: -f5 |
9687                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9688                 ext_len=$(echo $line | cut -d: -f4)
9689                 if (( $frag_lun != $last_lun )); then
9690                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
9691                         if (( logical != 512 )); then
9692                                 cleanup_130
9693                                 error "FIEMAP on $fm_file failed; returned " \
9694                                 "logical start for lun $logical instead of 512"
9695                                 return
9696                         fi
9697                         if (( tot_len != 512 )); then
9698                                 cleanup_130
9699                                 error "FIEMAP on $fm_file failed; returned " \
9700                                 "len $tot_len for OST $last_lun instead of 1024"
9701                                 return
9702                         else
9703                                 (( num_luns += 1 ))
9704                                 tot_len=0
9705                         fi
9706                 fi
9707                 (( tot_len += ext_len ))
9708                 last_lun=$frag_lun
9709         done
9710         if (( num_luns != 2 || tot_len != 512 )); then
9711                 cleanup_130
9712                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9713                         "luns or wrong len for OST $last_lun"
9714                 return
9715         fi
9716
9717         cleanup_130
9718
9719         echo "FIEMAP on 2-stripe file with hole succeeded"
9720 }
9721 run_test 130c "FIEMAP (2-stripe file with hole)"
9722
9723 test_130d() {
9724         [[ $OSTCOUNT -lt 3 ]] && skip_env "needs >= 3 OSTs" && return
9725
9726         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9727         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
9728                 return
9729
9730         trap cleanup_130 EXIT RETURN
9731
9732         local fm_file=$DIR/$tfile
9733         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
9734                         error "setstripe on $fm_file"
9735         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9736                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9737
9738         local actual_stripe_count=$($GETSTRIPE -c $fm_file)
9739         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripe_count ||
9740                 error "dd failed on $fm_file"
9741
9742         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9743         filefrag_op=$(filefrag -ve $fm_file |
9744                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9745
9746         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9747                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9748
9749         IFS=$'\n'
9750         tot_len=0
9751         num_luns=1
9752         for line in $filefrag_op
9753         do
9754                 frag_lun=$(echo $line | cut -d: -f5 |
9755                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9756                 ext_len=$(echo $line | cut -d: -f4)
9757                 if (( $frag_lun != $last_lun )); then
9758                         if (( tot_len != 1024 )); then
9759                                 cleanup_130
9760                                 error "FIEMAP on $fm_file failed; returned " \
9761                                 "len $tot_len for OST $last_lun instead of 1024"
9762                                 return
9763                         else
9764                                 (( num_luns += 1 ))
9765                                 tot_len=0
9766                         fi
9767                 fi
9768                 (( tot_len += ext_len ))
9769                 last_lun=$frag_lun
9770         done
9771         if (( num_luns != actual_stripe_count || tot_len != 1024 )); then
9772                 cleanup_130
9773                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9774                         "luns or wrong len for OST $last_lun"
9775                 return
9776         fi
9777
9778         cleanup_130
9779
9780         echo "FIEMAP on N-stripe file succeeded"
9781 }
9782 run_test 130d "FIEMAP (N-stripe file)"
9783
9784 test_130e() {
9785         [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs" && return
9786
9787         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9788         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
9789
9790         trap cleanup_130 EXIT RETURN
9791
9792         local fm_file=$DIR/$tfile
9793         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
9794         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9795                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9796
9797         NUM_BLKS=512
9798         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
9799         for ((i = 0; i < $NUM_BLKS; i++))
9800         do
9801                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
9802         done
9803
9804         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9805         filefrag_op=$(filefrag -ve $fm_file |
9806                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9807
9808         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9809                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9810
9811         IFS=$'\n'
9812         tot_len=0
9813         num_luns=1
9814         for line in $filefrag_op
9815         do
9816                 frag_lun=$(echo $line | cut -d: -f5 |
9817                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9818                 ext_len=$(echo $line | cut -d: -f4)
9819                 if (( $frag_lun != $last_lun )); then
9820                         if (( tot_len != $EXPECTED_LEN )); then
9821                                 cleanup_130
9822                                 error "FIEMAP on $fm_file failed; returned " \
9823                                 "len $tot_len for OST $last_lun instead " \
9824                                 "of $EXPECTED_LEN"
9825                                 return
9826                         else
9827                                 (( num_luns += 1 ))
9828                                 tot_len=0
9829                         fi
9830                 fi
9831                 (( tot_len += ext_len ))
9832                 last_lun=$frag_lun
9833         done
9834         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
9835                 cleanup_130
9836                 error "FIEMAP on $fm_file failed; returned wrong number " \
9837                         "of luns or wrong len for OST $last_lun"
9838                 return
9839         fi
9840
9841         cleanup_130
9842
9843         echo "FIEMAP with continuation calls succeeded"
9844 }
9845 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
9846
9847 # Test for writev/readv
9848 test_131a() {
9849         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 ||
9850                 error "writev test failed"
9851         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 ||
9852                 error "readv failed"
9853         rm -f $DIR/$tfile
9854 }
9855 run_test 131a "test iov's crossing stripe boundary for writev/readv"
9856
9857 test_131b() {
9858         local fsize=$((524288 + 1048576 + 1572864))
9859         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 &&
9860                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
9861                         error "append writev test failed"
9862
9863         ((fsize += 1572864 + 1048576))
9864         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 &&
9865                 $CHECKSTAT -t file $DIR/$tfile -s $fsize ||
9866                         error "append writev test failed"
9867         rm -f $DIR/$tfile
9868 }
9869 run_test 131b "test append writev"
9870
9871 test_131c() {
9872         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
9873         error "NOT PASS"
9874 }
9875 run_test 131c "test read/write on file w/o objects"
9876
9877 test_131d() {
9878         rwv -f $DIR/$tfile -w -n 1 1572864
9879         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
9880         if [ "$NOB" != 1572864 ]; then
9881                 error "Short read filed: read $NOB bytes instead of 1572864"
9882         fi
9883         rm -f $DIR/$tfile
9884 }
9885 run_test 131d "test short read"
9886
9887 test_131e() {
9888         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
9889         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
9890         error "read hitting hole failed"
9891         rm -f $DIR/$tfile
9892 }
9893 run_test 131e "test read hitting hole"
9894
9895 check_stats() {
9896         local facet=$1
9897         local op=$2
9898         local want=${3:-0}
9899         local res
9900
9901         case $facet in
9902         mds*) res=$(do_facet $facet \
9903                    $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$op")
9904                  ;;
9905         ost*) res=$(do_facet $facet \
9906                    $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$op")
9907                  ;;
9908         *) error "Wrong facet '$facet'" ;;
9909         esac
9910         echo $res
9911         [ "$res" ] || error "The counter for $op on $facet was not incremented"
9912         # if the argument $3 is zero, it means any stat increment is ok.
9913         if [[ $want -gt 0 ]]; then
9914                 local count=$(echo $res | awk '{ print $2 }')
9915                 [[ $count -ne $want ]] &&
9916                         error "The $op counter on $facet is $count, not $want"
9917         fi
9918 }
9919
9920 test_133a() {
9921         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9922         remote_ost_nodsh && skip "remote OST with nodsh" && return
9923         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9924
9925         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9926                 { skip "MDS doesn't support rename stats"; return; }
9927         local testdir=$DIR/${tdir}/stats_testdir
9928         mkdir -p $DIR/${tdir}
9929
9930         # clear stats.
9931         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9932         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9933
9934         # verify mdt stats first.
9935         mkdir ${testdir} || error "mkdir failed"
9936         check_stats $SINGLEMDS "mkdir" 1
9937         touch ${testdir}/${tfile} || error "touch failed"
9938         check_stats $SINGLEMDS "open" 1
9939         check_stats $SINGLEMDS "close" 1
9940         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ] && {
9941                 mknod ${testdir}/${tfile}-pipe p || error "mknod failed"
9942                 check_stats $SINGLEMDS "mknod" 2
9943         }
9944         rm -f ${testdir}/${tfile}-pipe || error "pipe remove failed"
9945         check_stats $SINGLEMDS "unlink" 1
9946         rm -f ${testdir}/${tfile} || error "file remove failed"
9947         check_stats $SINGLEMDS "unlink" 2
9948
9949         # remove working dir and check mdt stats again.
9950         rmdir ${testdir} || error "rmdir failed"
9951         check_stats $SINGLEMDS "rmdir" 1
9952
9953         local testdir1=$DIR/${tdir}/stats_testdir1
9954         mkdir -p ${testdir}
9955         mkdir -p ${testdir1}
9956         touch ${testdir1}/test1
9957         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
9958         check_stats $SINGLEMDS "crossdir_rename" 1
9959
9960         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
9961         check_stats $SINGLEMDS "samedir_rename" 1
9962
9963         rm -rf $DIR/${tdir}
9964 }
9965 run_test 133a "Verifying MDT stats ========================================"
9966
9967 test_133b() {
9968         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9969         remote_ost_nodsh && skip "remote OST with nodsh" && return
9970         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9971         local testdir=$DIR/${tdir}/stats_testdir
9972         mkdir -p ${testdir} || error "mkdir failed"
9973         touch ${testdir}/${tfile} || error "touch failed"
9974         cancel_lru_locks mdc
9975
9976         # clear stats.
9977         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9978         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9979
9980         # extra mdt stats verification.
9981         chmod 444 ${testdir}/${tfile} || error "chmod failed"
9982         check_stats $SINGLEMDS "setattr" 1
9983         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9984         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
9985         then            # LU-1740
9986                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
9987                 check_stats $SINGLEMDS "getattr" 1
9988         fi
9989         $LFS df || error "lfs failed"
9990         check_stats $SINGLEMDS "statfs" 1
9991
9992         rm -rf $DIR/${tdir}
9993 }
9994 run_test 133b "Verifying extra MDT stats =================================="
9995
9996 test_133c() {
9997         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9998         remote_ost_nodsh && skip "remote OST with nodsh" && return
9999         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10000         local testdir=$DIR/${tdir}/stats_testdir
10001         test_mkdir -p ${testdir} || error "mkdir failed"
10002
10003         # verify obdfilter stats.
10004         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
10005         sync
10006         cancel_lru_locks osc
10007         wait_delete_completed
10008
10009         # clear stats.
10010         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
10011         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
10012
10013         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
10014         sync
10015         cancel_lru_locks osc
10016         check_stats ost1 "write" 1
10017
10018         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
10019         check_stats ost1 "read" 1
10020
10021         > ${testdir}/${tfile} || error "truncate failed"
10022         check_stats ost1 "punch" 1
10023
10024         rm -f ${testdir}/${tfile} || error "file remove failed"
10025         wait_delete_completed
10026         check_stats ost1 "destroy" 1
10027
10028         rm -rf $DIR/${tdir}
10029 }
10030 run_test 133c "Verifying OST stats ========================================"
10031
10032 order_2() {
10033         local value=$1
10034         local orig=$value
10035         local order=1
10036
10037         while [ $value -ge 2 ]; do
10038                 order=$((order*2))
10039                 value=$((value/2))
10040         done
10041
10042         if [ $orig -gt $order ]; then
10043                 order=$((order*2))
10044         fi
10045         echo $order
10046 }
10047
10048 size_in_KMGT() {
10049     local value=$1
10050     local size=('K' 'M' 'G' 'T');
10051     local i=0
10052     local size_string=$value
10053
10054     while [ $value -ge 1024 ]; do
10055         if [ $i -gt 3 ]; then
10056             #T is the biggest unit we get here, if that is bigger,
10057             #just return XXXT
10058             size_string=${value}T
10059             break
10060         fi
10061         value=$((value >> 10))
10062         if [ $value -lt 1024 ]; then
10063             size_string=${value}${size[$i]}
10064             break
10065         fi
10066         i=$((i + 1))
10067     done
10068
10069     echo $size_string
10070 }
10071
10072 get_rename_size() {
10073         local size=$1
10074         local context=${2:-.}
10075         local sample=$(do_facet $SINGLEMDS $LCTL \
10076                 get_param mdt.$FSNAME-MDT0000.rename_stats |
10077                 grep -A1 $context |
10078                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
10079         echo $sample
10080 }
10081
10082 test_133d() {
10083         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10084         remote_ost_nodsh && skip "remote OST with nodsh" && return
10085         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10086         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
10087         { skip "MDS doesn't support rename stats"; return; }
10088
10089         local testdir1=$DIR/${tdir}/stats_testdir1
10090         local testdir2=$DIR/${tdir}/stats_testdir2
10091         mkdir -p $DIR/${tdir}
10092
10093         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
10094
10095         lfs mkdir -i 0 -c 1 ${testdir1} || error "mkdir failed"
10096         lfs mkdir -i 0 -c 1 ${testdir2} || error "mkdir failed"
10097
10098         createmany -o $testdir1/test 512 || error "createmany failed"
10099
10100         # check samedir rename size
10101         mv ${testdir1}/test0 ${testdir1}/test_0
10102
10103         local testdir1_size=$(ls -l $DIR/${tdir} |
10104                 awk '/stats_testdir1/ {print $5}')
10105         local testdir2_size=$(ls -l $DIR/${tdir} |
10106                 awk '/stats_testdir2/ {print $5}')
10107
10108         testdir1_size=$(order_2 $testdir1_size)
10109         testdir2_size=$(order_2 $testdir2_size)
10110
10111         testdir1_size=$(size_in_KMGT $testdir1_size)
10112         testdir2_size=$(size_in_KMGT $testdir2_size)
10113
10114         echo "source rename dir size: ${testdir1_size}"
10115         echo "target rename dir size: ${testdir2_size}"
10116
10117         local cmd="do_facet $SINGLEMDS $LCTL "
10118         cmd+="get_param mdt.$FSNAME-MDT0000.rename_stats"
10119
10120         eval $cmd || error "$cmd failed"
10121         local samedir=$($cmd | grep 'same_dir')
10122         local same_sample=$(get_rename_size $testdir1_size)
10123         [ -z "$samedir" ] && error "samedir_rename_size count error"
10124         [[ $same_sample -eq 1 ]] ||
10125                 error "samedir_rename_size error $same_sample"
10126         echo "Check same dir rename stats success"
10127
10128         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
10129
10130         # check crossdir rename size
10131         mv ${testdir1}/test_0 ${testdir2}/test_0
10132
10133         testdir1_size=$(ls -l $DIR/${tdir} |
10134                 awk '/stats_testdir1/ {print $5}')
10135         testdir2_size=$(ls -l $DIR/${tdir} |
10136                 awk '/stats_testdir2/ {print $5}')
10137
10138         testdir1_size=$(order_2 $testdir1_size)
10139         testdir2_size=$(order_2 $testdir2_size)
10140
10141         testdir1_size=$(size_in_KMGT $testdir1_size)
10142         testdir2_size=$(size_in_KMGT $testdir2_size)
10143
10144         echo "source rename dir size: ${testdir1_size}"
10145         echo "target rename dir size: ${testdir2_size}"
10146
10147         eval $cmd || error "$cmd failed"
10148         local crossdir=$($cmd | grep 'crossdir')
10149         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
10150         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
10151         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
10152         [[ $src_sample -eq 1 ]] ||
10153                 error "crossdir_rename_size error $src_sample"
10154         [[ $tgt_sample -eq 1 ]] ||
10155                 error "crossdir_rename_size error $tgt_sample"
10156         echo "Check cross dir rename stats success"
10157         rm -rf $DIR/${tdir}
10158 }
10159 run_test 133d "Verifying rename_stats ========================================"
10160
10161 test_133e() {
10162         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10163         remote_ost_nodsh && skip "remote OST with nodsh" && return
10164         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10165         local testdir=$DIR/${tdir}/stats_testdir
10166         local ctr f0 f1 bs=32768 count=42 sum
10167
10168         mkdir -p ${testdir} || error "mkdir failed"
10169
10170         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
10171
10172         for ctr in {write,read}_bytes; do
10173                 sync
10174                 cancel_lru_locks osc
10175
10176                 do_facet ost1 $LCTL set_param -n \
10177                         "obdfilter.*.exports.clear=clear"
10178
10179                 if [ $ctr = write_bytes ]; then
10180                         f0=/dev/zero
10181                         f1=${testdir}/${tfile}
10182                 else
10183                         f0=${testdir}/${tfile}
10184                         f1=/dev/null
10185                 fi
10186
10187                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
10188                         error "dd failed"
10189                 sync
10190                 cancel_lru_locks osc
10191
10192                 sum=$(do_facet ost1 $LCTL get_param \
10193                         "obdfilter.*.exports.*.stats" |
10194                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
10195                                 $1 == ctr { sum += $7 }
10196                                 END { printf("%0.0f", sum) }')
10197
10198                 if ((sum != bs * count)); then
10199                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
10200                 fi
10201         done
10202
10203         rm -rf $DIR/${tdir}
10204 }
10205 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
10206
10207 proc_regexp="/{proc,sys}/{fs,sys,kernel/debug}/{lustre,lnet}/"
10208
10209 test_133f() {
10210         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10211         remote_ost_nodsh && skip "remote OST with nodsh" && return
10212         # First without trusting modes.
10213         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
10214         echo "proc_dirs='$proc_dirs'"
10215         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
10216         find $proc_dirs -exec cat '{}' \; &> /dev/null
10217
10218         # Second verifying readability.
10219         $LCTL get_param -R '*' &> /dev/null || error "proc file read failed"
10220
10221         # eventually, this can also be replaced with "lctl get_param -R",
10222         # but not until that option is always available on the server
10223         local facet
10224         for facet in mds1 ost1; do
10225                 local facet_proc_dirs=$(do_facet $facet \
10226                                         \\\ls -d $proc_regexp 2>/dev/null)
10227                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
10228                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
10229                 do_facet $facet find $facet_proc_dirs \
10230                         ! -name req_history \
10231                         -exec cat '{}' \\\; &> /dev/null
10232
10233                 do_facet $facet find $facet_proc_dirs \
10234                         ! -name req_history \
10235                         -type f \
10236                         -exec cat '{}' \\\; &> /dev/null ||
10237                                 error "proc file read failed"
10238         done
10239 }
10240 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
10241
10242 test_133g() {
10243         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10244         remote_ost_nodsh && skip "remote OST with nodsh" && return
10245         # Second verifying writability.
10246         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
10247         echo "proc_dirs='$proc_dirs'"
10248         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
10249         find $proc_dirs \
10250                 -type f \
10251                 -not -name force_lbug \
10252                 -not -name changelog_mask \
10253                 -exec badarea_io '{}' \; &> /dev/null ||
10254                 error "find $proc_dirs failed"
10255
10256         local facet
10257         for facet in mds1 ost1; do
10258                 [ $(lustre_version_code $facet) -le $(version_code 2.5.54) ] &&
10259                         skip "Too old lustre on $facet" && continue
10260                 local facet_proc_dirs=$(do_facet $facet \
10261                                         \\\ls -d $proc_regexp 2> /dev/null)
10262                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
10263                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
10264                 do_facet $facet find $facet_proc_dirs \
10265                         -type f \
10266                         -not -name force_lbug \
10267                         -not -name changelog_mask \
10268                         -exec badarea_io '{}' \\\; &> /dev/null ||
10269                                 error "$facet find $facet_proc_dirs failed"
10270         done
10271
10272         # remount the FS in case writes/reads /proc break the FS
10273         cleanup || error "failed to unmount"
10274         setup || error "failed to setup"
10275         true
10276 }
10277 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
10278
10279 test_133h() {
10280         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10281         remote_ost_nodsh && skip "remote OST with nodsh" && return
10282         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.54) ]] &&
10283                 skip "Need MDS version at least 2.9.54" && return
10284
10285         local facet
10286         for facet in client mds1 ost1; do
10287                 local facet_proc_dirs=$(do_facet $facet \
10288                                         \\\ls -d $proc_regexp 2> /dev/null)
10289                 [ -z "$facet_proc_dirs" ] && error "no proc_dirs on $facet"
10290                 echo "${facet}_proc_dirs='$facet_proc_dirs'"
10291                 # Get the list of files that are missing the terminating newline
10292                 local missing=($(do_facet $facet \
10293                         find ${facet_proc_dirs} -type f \|              \
10294                                 while read F\; do                       \
10295                                         awk -v FS='\v' -v RS='\v\v'     \
10296                                         "'END { if(NR>0 &&              \
10297                                         \\\$NF !~ /.*\\\n\$/)           \
10298                                                 print FILENAME}'"       \
10299                                         '\$F'\;                         \
10300                                 done 2>/dev/null))
10301                 [ ${#missing[*]} -eq 0 ] ||
10302                         error "files do not end with newline: ${missing[*]}"
10303         done
10304 }
10305 run_test 133h "Proc files should end with newlines"
10306
10307 test_134a() {
10308         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10309         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
10310                 skip "Need MDS version at least 2.7.54" && return
10311
10312         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
10313         cancel_lru_locks mdc
10314
10315         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
10316         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
10317         [ $unused -eq 0 ] || error "$unused locks are not cleared"
10318
10319         local nr=1000
10320         createmany -o $DIR/$tdir/f $nr ||
10321                 error "failed to create $nr files in $DIR/$tdir"
10322         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
10323
10324         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
10325         do_facet mds1 $LCTL set_param fail_loc=0x327
10326         do_facet mds1 $LCTL set_param fail_val=500
10327         touch $DIR/$tdir/m
10328
10329         echo "sleep 10 seconds ..."
10330         sleep 10
10331         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
10332
10333         do_facet mds1 $LCTL set_param fail_loc=0
10334         do_facet mds1 $LCTL set_param fail_val=0
10335         [ $lck_cnt -lt $unused ] ||
10336                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
10337
10338         rm $DIR/$tdir/m
10339         unlinkmany $DIR/$tdir/f $nr
10340 }
10341 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
10342
10343 test_134b() {
10344         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10345         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
10346                 skip "Need MDS version at least 2.7.54" && return
10347
10348         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
10349         cancel_lru_locks mdc
10350
10351         local low_wm=$(do_facet mds1 $LCTL get_param -n \
10352                         ldlm.lock_reclaim_threshold_mb)
10353         # disable reclaim temporarily
10354         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
10355
10356         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
10357         do_facet mds1 $LCTL set_param fail_loc=0x328
10358         do_facet mds1 $LCTL set_param fail_val=500
10359
10360         $LCTL set_param debug=+trace
10361
10362         local nr=600
10363         createmany -o $DIR/$tdir/f $nr &
10364         local create_pid=$!
10365
10366         echo "Sleep $TIMEOUT seconds ..."
10367         sleep $TIMEOUT
10368         if ! ps -p $create_pid  > /dev/null 2>&1; then
10369                 do_facet mds1 $LCTL set_param fail_loc=0
10370                 do_facet mds1 $LCTL set_param fail_val=0
10371                 do_facet mds1 $LCTL set_param \
10372                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
10373                 error "createmany finished incorrectly!"
10374         fi
10375         do_facet mds1 $LCTL set_param fail_loc=0
10376         do_facet mds1 $LCTL set_param fail_val=0
10377         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
10378         wait $create_pid || return 1
10379
10380         unlinkmany $DIR/$tdir/f $nr
10381 }
10382 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
10383
10384 test_140() { #bug-17379
10385         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10386         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
10387         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
10388         cp $(which stat) . || error "Copying stat to $DIR/$tdir"
10389
10390         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
10391         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
10392         local i=0
10393         while i=`expr $i + 1`; do
10394                 test_mkdir -p $i || error "Creating dir $i"
10395                 cd $i || error "Changing to $i"
10396                 ln -s ../stat stat || error "Creating stat symlink"
10397                 # Read the symlink until ELOOP present,
10398                 # not LBUGing the system is considered success,
10399                 # we didn't overrun the stack.
10400                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
10401                 [ $ret -ne 0 ] && {
10402                         if [ $ret -eq 40 ]; then
10403                                 break  # -ELOOP
10404                         else
10405                                 error "Open stat symlink"
10406                                 return
10407                         fi
10408                 }
10409         done
10410         i=`expr $i - 1`
10411         echo "The symlink depth = $i"
10412         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
10413                                         error "Invalid symlink depth"
10414
10415         # Test recursive symlink
10416         ln -s symlink_self symlink_self
10417         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
10418         echo "open symlink_self returns $ret"
10419         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
10420 }
10421 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
10422
10423 test_150() {
10424         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10425         local TF="$TMP/$tfile"
10426
10427         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
10428         cp $TF $DIR/$tfile
10429         cancel_lru_locks osc
10430         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
10431         remount_client $MOUNT
10432         df -P $MOUNT
10433         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
10434
10435         $TRUNCATE $TF 6000
10436         $TRUNCATE $DIR/$tfile 6000
10437         cancel_lru_locks osc
10438         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
10439
10440         echo "12345" >>$TF
10441         echo "12345" >>$DIR/$tfile
10442         cancel_lru_locks osc
10443         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
10444
10445         echo "12345" >>$TF
10446         echo "12345" >>$DIR/$tfile
10447         cancel_lru_locks osc
10448         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
10449
10450         rm -f $TF
10451         true
10452 }
10453 run_test 150 "truncate/append tests"
10454
10455 #LU-2902 roc_hit was not able to read all values from lproc
10456 function roc_hit_init() {
10457         local list=$(comma_list $(osts_nodes))
10458         local dir=$DIR/$tdir-check
10459         local file=$dir/file
10460         local BEFORE
10461         local AFTER
10462         local idx
10463
10464         test_mkdir -p $dir
10465         #use setstripe to do a write to every ost
10466         for i in $(seq 0 $((OSTCOUNT-1))); do
10467                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
10468                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
10469                 idx=$(printf %04x $i)
10470                 BEFORE=$(get_osd_param $list *OST*$idx stats |
10471                         awk '$1 == "cache_access" {sum += $7}
10472                                 END { printf("%0.0f", sum) }')
10473
10474                 cancel_lru_locks osc
10475                 cat $file >/dev/null
10476
10477                 AFTER=$(get_osd_param $list *OST*$idx stats |
10478                         awk '$1 == "cache_access" {sum += $7}
10479                                 END { printf("%0.0f", sum) }')
10480
10481                 echo BEFORE:$BEFORE AFTER:$AFTER
10482                 if ! let "AFTER - BEFORE == 4"; then
10483                         rm -rf $dir
10484                         error "roc_hit is not safe to use"
10485                 fi
10486                 rm $file
10487         done
10488
10489         rm -rf $dir
10490 }
10491
10492 function roc_hit() {
10493         local list=$(comma_list $(osts_nodes))
10494         echo $(get_osd_param $list '' stats |
10495                 awk '$1 == "cache_hit" {sum += $7}
10496                         END { printf("%0.0f", sum) }')
10497 }
10498
10499 function set_cache() {
10500         local on=1
10501
10502         if [ "$2" == "off" ]; then
10503                 on=0;
10504         fi
10505         local list=$(comma_list $(osts_nodes))
10506         set_osd_param $list '' $1_cache_enable $on
10507
10508         cancel_lru_locks osc
10509 }
10510
10511 test_151() {
10512         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10513         remote_ost_nodsh && skip "remote OST with nodsh" && return
10514
10515         local CPAGES=3
10516         local list=$(comma_list $(osts_nodes))
10517
10518         # check whether obdfilter is cache capable at all
10519         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
10520                 echo "not cache-capable obdfilter"
10521                 return 0
10522         fi
10523
10524         # check cache is enabled on all obdfilters
10525         if get_osd_param $list '' read_cache_enable | grep 0; then
10526                 echo "oss cache is disabled"
10527                 return 0
10528         fi
10529
10530         set_osd_param $list '' writethrough_cache_enable 1
10531
10532         # check write cache is enabled on all obdfilters
10533         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
10534                 echo "oss write cache is NOT enabled"
10535                 return 0
10536         fi
10537
10538         roc_hit_init
10539
10540         #define OBD_FAIL_OBD_NO_LRU  0x609
10541         do_nodes $list $LCTL set_param fail_loc=0x609
10542
10543         # pages should be in the case right after write
10544         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
10545                 error "dd failed"
10546
10547         local BEFORE=$(roc_hit)
10548         cancel_lru_locks osc
10549         cat $DIR/$tfile >/dev/null
10550         local AFTER=$(roc_hit)
10551
10552         do_nodes $list $LCTL set_param fail_loc=0
10553
10554         if ! let "AFTER - BEFORE == CPAGES"; then
10555                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10556         fi
10557
10558         # the following read invalidates the cache
10559         cancel_lru_locks osc
10560         set_osd_param $list '' read_cache_enable 0
10561         cat $DIR/$tfile >/dev/null
10562
10563         # now data shouldn't be found in the cache
10564         BEFORE=$(roc_hit)
10565         cancel_lru_locks osc
10566         cat $DIR/$tfile >/dev/null
10567         AFTER=$(roc_hit)
10568         if let "AFTER - BEFORE != 0"; then
10569                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10570         fi
10571
10572         set_osd_param $list '' read_cache_enable 1
10573         rm -f $DIR/$tfile
10574 }
10575 run_test 151 "test cache on oss and controls ==============================="
10576
10577 test_152() {
10578         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10579         local TF="$TMP/$tfile"
10580
10581         # simulate ENOMEM during write
10582 #define OBD_FAIL_OST_NOMEM      0x226
10583         lctl set_param fail_loc=0x80000226
10584         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
10585         cp $TF $DIR/$tfile
10586         sync || error "sync failed"
10587         lctl set_param fail_loc=0
10588
10589         # discard client's cache
10590         cancel_lru_locks osc
10591
10592         # simulate ENOMEM during read
10593         lctl set_param fail_loc=0x80000226
10594         cmp $TF $DIR/$tfile || error "cmp failed"
10595         lctl set_param fail_loc=0
10596
10597         rm -f $TF
10598 }
10599 run_test 152 "test read/write with enomem ============================"
10600
10601 test_153() {
10602         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
10603 }
10604 run_test 153 "test if fdatasync does not crash ======================="
10605
10606 dot_lustre_fid_permission_check() {
10607         local fid=$1
10608         local ffid=$MOUNT/.lustre/fid/$fid
10609         local test_dir=$2
10610
10611         echo "stat fid $fid"
10612         stat $ffid > /dev/null || error "stat $ffid failed."
10613         echo "touch fid $fid"
10614         touch $ffid || error "touch $ffid failed."
10615         echo "write to fid $fid"
10616         cat /etc/hosts > $ffid || error "write $ffid failed."
10617         echo "read fid $fid"
10618         diff /etc/hosts $ffid || error "read $ffid failed."
10619         echo "append write to fid $fid"
10620         cat /etc/hosts >> $ffid || error "append write $ffid failed."
10621         echo "rename fid $fid"
10622         mv $ffid $test_dir/$tfile.1 &&
10623                 error "rename $ffid to $tfile.1 should fail."
10624         touch $test_dir/$tfile.1
10625         mv $test_dir/$tfile.1 $ffid &&
10626                 error "rename $tfile.1 to $ffid should fail."
10627         rm -f $test_dir/$tfile.1
10628         echo "truncate fid $fid"
10629         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
10630         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
10631                 echo "link fid $fid"
10632                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
10633         fi
10634         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
10635                 echo "setfacl fid $fid"
10636                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
10637                 echo "getfacl fid $fid"
10638                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
10639         fi
10640         echo "unlink fid $fid"
10641         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
10642         echo "mknod fid $fid"
10643         mknod $ffid c 1 3 && error "mknod $ffid should fail."
10644
10645         fid=[0xf00000400:0x1:0x0]
10646         ffid=$MOUNT/.lustre/fid/$fid
10647
10648         echo "stat non-exist fid $fid"
10649         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
10650         echo "write to non-exist fid $fid"
10651         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
10652         echo "link new fid $fid"
10653         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
10654
10655         mkdir -p $test_dir/$tdir
10656         touch $test_dir/$tdir/$tfile
10657         fid=$($LFS path2fid $test_dir/$tdir)
10658         rc=$?
10659         [ $rc -ne 0 ] &&
10660                 error "error: could not get fid for $test_dir/$dir/$tfile."
10661
10662         ffid=$MOUNT/.lustre/fid/$fid
10663
10664         echo "ls $fid"
10665         ls $ffid > /dev/null || error "ls $ffid failed."
10666         echo "touch $fid/$tfile.1"
10667         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
10668
10669         echo "touch $MOUNT/.lustre/fid/$tfile"
10670         touch $MOUNT/.lustre/fid/$tfile && \
10671                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
10672
10673         echo "setxattr to $MOUNT/.lustre/fid"
10674         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
10675
10676         echo "listxattr for $MOUNT/.lustre/fid"
10677         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
10678
10679         echo "delxattr from $MOUNT/.lustre/fid"
10680         setfattr -x trusted.name1 $MOUNT/.lustre/fid
10681
10682         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
10683         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
10684                 error "touch invalid fid should fail."
10685
10686         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
10687         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
10688                 error "touch non-normal fid should fail."
10689
10690         echo "rename $tdir to $MOUNT/.lustre/fid"
10691         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
10692                 error "rename to $MOUNT/.lustre/fid should fail."
10693
10694         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
10695         then            # LU-3547
10696                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
10697                 local new_obf_mode=777
10698
10699                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
10700                 chmod $new_obf_mode $DIR/.lustre/fid ||
10701                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
10702
10703                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
10704                 [ $obf_mode -eq $new_obf_mode ] ||
10705                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
10706
10707                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
10708                 chmod $old_obf_mode $DIR/.lustre/fid ||
10709                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
10710         fi
10711
10712         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
10713         fid=$($LFS path2fid $test_dir/$tfile-2)
10714
10715         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
10716         then # LU-5424
10717                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
10718                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
10719                         error "create lov data thru .lustre failed"
10720         fi
10721         echo "cp /etc/passwd $test_dir/$tfile-2"
10722         cp /etc/passwd $test_dir/$tfile-2 ||
10723                 error "copy to $test_dir/$tfile-2 failed."
10724         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
10725         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
10726                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
10727
10728         rm -rf $test_dir/tfile.lnk
10729         rm -rf $test_dir/$tfile-2
10730 }
10731
10732 test_154A() {
10733         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10734                 skip "Need MDS version at least 2.4.1" && return
10735
10736         local tf=$DIR/$tfile
10737         touch $tf
10738
10739         local fid=$($LFS path2fid $tf)
10740         [ -z "$fid" ] && error "path2fid unable to get $tf FID"
10741
10742         # check that we get the same pathname back
10743         local found=$($LFS fid2path $MOUNT "$fid")
10744         [ -z "$found" ] && error "fid2path unable to get '$fid' path"
10745         [ "$found" == "$tf" ] ||
10746                 error "fid2path($fid=path2fid($tf)) = $found != $tf"
10747 }
10748 run_test 154A "lfs path2fid and fid2path basic checks"
10749
10750 test_154B() {
10751         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10752                 skip "Need MDS version at least 2.4.1" && return
10753
10754         mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
10755         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
10756         local linkea=$($LL_DECODE_LINKEA $DIR/$tdir/$tfile | grep 'pfid')
10757         [ -z "$linkea" ] && error "decode linkea $DIR/$tdir/$tfile failed"
10758
10759         local name=$(echo $linkea | awk '/pfid/ {print $5}' | sed -e "s/'//g")
10760         local PFID=$(echo $linkea | awk '/pfid/ {print $3}' | sed -e "s/,//g")
10761
10762         # check that we get the same pathname
10763         echo "PFID: $PFID, name: $name"
10764         local FOUND=$($LFS fid2path $MOUNT "$PFID")
10765         [ -z "$FOUND" ] && error "fid2path unable to get $PFID path"
10766         [ "$FOUND/$name" != "$DIR/$tdir/$tfile" ] &&
10767                 error "ll_decode_linkea has $FOUND/$name != $DIR/$tdir/$tfile"
10768
10769         rm -rf $DIR/$tdir || error "Can not delete directory $DIR/$tdir"
10770 }
10771 run_test 154B "verify the ll_decode_linkea tool"
10772
10773 test_154a() {
10774         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10775         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
10776                 { skip "Need MDS version at least 2.2.51"; return 0; }
10777         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
10778         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10779
10780         cp /etc/hosts $DIR/$tfile
10781
10782         fid=$($LFS path2fid $DIR/$tfile)
10783         rc=$?
10784         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
10785
10786         dot_lustre_fid_permission_check "$fid" $DIR ||
10787                 error "dot lustre permission check $fid failed"
10788
10789         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
10790
10791         touch $MOUNT/.lustre/file &&
10792                 error "creation is not allowed under .lustre"
10793
10794         mkdir $MOUNT/.lustre/dir &&
10795                 error "mkdir is not allowed under .lustre"
10796
10797         rm -rf $DIR/$tfile
10798 }
10799 run_test 154a "Open-by-FID"
10800
10801 test_154b() {
10802         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10803         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
10804                 { skip "Need MDS version at least 2.2.51"; return 0; }
10805         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10806
10807         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10808
10809         local remote_dir=$DIR/$tdir/remote_dir
10810         local MDTIDX=1
10811         local rc=0
10812
10813         mkdir -p $DIR/$tdir
10814         $LFS mkdir -i $MDTIDX $remote_dir ||
10815                 error "create remote directory failed"
10816
10817         cp /etc/hosts $remote_dir/$tfile
10818
10819         fid=$($LFS path2fid $remote_dir/$tfile)
10820         rc=$?
10821         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
10822
10823         dot_lustre_fid_permission_check "$fid" $remote_dir ||
10824                 error "dot lustre permission check $fid failed"
10825         rm -rf $DIR/$tdir
10826 }
10827 run_test 154b "Open-by-FID for remote directory"
10828
10829 test_154c() {
10830         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10831                 skip "Need MDS version at least 2.4.1" && return
10832
10833         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
10834         local FID1=$($LFS path2fid $DIR/$tfile.1)
10835         local FID2=$($LFS path2fid $DIR/$tfile.2)
10836         local FID3=$($LFS path2fid $DIR/$tfile.3)
10837
10838         local N=1
10839         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
10840                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
10841                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
10842                 local want=FID$N
10843                 [ "$FID" = "${!want}" ] ||
10844                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
10845                 N=$((N + 1))
10846         done
10847
10848         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
10849         do
10850                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
10851                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
10852                 N=$((N + 1))
10853         done
10854 }
10855 run_test 154c "lfs path2fid and fid2path multiple arguments"
10856
10857 test_154d() {
10858         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10859         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
10860                 skip "Need MDS version at least 2.5.53" && return
10861
10862         if remote_mds; then
10863                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
10864         else
10865                 nid="0@lo"
10866         fi
10867         local proc_ofile="mdt.*.exports.'$nid'.open_files"
10868         local fd
10869         local cmd
10870
10871         rm -f $DIR/$tfile
10872         touch $DIR/$tfile
10873
10874         local fid=$($LFS path2fid $DIR/$tfile)
10875         # Open the file
10876         fd=$(free_fd)
10877         cmd="exec $fd<$DIR/$tfile"
10878         eval $cmd
10879         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
10880         echo "$fid_list" | grep "$fid"
10881         rc=$?
10882
10883         cmd="exec $fd>/dev/null"
10884         eval $cmd
10885         if [ $rc -ne 0 ]; then
10886                 error "FID $fid not found in open files list $fid_list"
10887         fi
10888 }
10889 run_test 154d "Verify open file fid"
10890
10891 test_154e()
10892 {
10893         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
10894                 skip "Need MDS version at least 2.6.50" && return
10895
10896         if ls -a $MOUNT | grep -q '^\.lustre$'; then
10897                 error ".lustre returned by readdir"
10898         fi
10899 }
10900 run_test 154e ".lustre is not returned by readdir"
10901
10902 test_154f() {
10903         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10904         # create parent directory on a single MDT to avoid cross-MDT hardlinks
10905         test_mkdir -p -c1 $DIR/$tdir/d
10906         # test dirs inherit from its stripe
10907         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
10908         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
10909         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
10910         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
10911         touch $DIR/f
10912
10913         # get fid of parents
10914         local FID0=$($LFS path2fid $DIR/$tdir/d)
10915         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
10916         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
10917         local FID3=$($LFS path2fid $DIR)
10918
10919         # check that path2fid --parents returns expected <parent_fid>/name
10920         # 1) test for a directory (single parent)
10921         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
10922         [ "$parent" == "$FID0/foo1" ] ||
10923                 error "expected parent: $FID0/foo1, got: $parent"
10924
10925         # 2) test for a file with nlink > 1 (multiple parents)
10926         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
10927         echo "$parent" | grep -F "$FID1/$tfile" ||
10928                 error "$FID1/$tfile not returned in parent list"
10929         echo "$parent" | grep -F "$FID2/link" ||
10930                 error "$FID2/link not returned in parent list"
10931
10932         # 3) get parent by fid
10933         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
10934         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10935         echo "$parent" | grep -F "$FID1/$tfile" ||
10936                 error "$FID1/$tfile not returned in parent list (by fid)"
10937         echo "$parent" | grep -F "$FID2/link" ||
10938                 error "$FID2/link not returned in parent list (by fid)"
10939
10940         # 4) test for entry in root directory
10941         parent=$($LFS path2fid --parents $DIR/f)
10942         echo "$parent" | grep -F "$FID3/f" ||
10943                 error "$FID3/f not returned in parent list"
10944
10945         # 5) test it on root directory
10946         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
10947                 error "$MOUNT should not have parents"
10948
10949         # enable xattr caching and check that linkea is correctly updated
10950         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
10951         save_lustre_params client "llite.*.xattr_cache" > $save
10952         lctl set_param llite.*.xattr_cache 1
10953
10954         # 6.1) linkea update on rename
10955         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
10956
10957         # get parents by fid
10958         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10959         # foo1 should no longer be returned in parent list
10960         echo "$parent" | grep -F "$FID1" &&
10961                 error "$FID1 should no longer be in parent list"
10962         # the new path should appear
10963         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
10964                 error "$FID2/$tfile.moved is not in parent list"
10965
10966         # 6.2) linkea update on unlink
10967         rm -f $DIR/$tdir/d/foo2/link
10968         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10969         # foo2/link should no longer be returned in parent list
10970         echo "$parent" | grep -F "$FID2/link" &&
10971                 error "$FID2/link should no longer be in parent list"
10972         true
10973
10974         rm -f $DIR/f
10975         restore_lustre_params < $save
10976         rm -f $save
10977 }
10978 run_test 154f "get parent fids by reading link ea"
10979
10980 test_154g()
10981 {
10982         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) && \
10983            $(lustre_version_code client) -gt $(version_code 2.6.99) ]] ||
10984                 { skip "Need MDS version at least 2.6.92"; return 0; }
10985         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10986
10987         mkdir -p $DIR/$tdir
10988         llapi_fid_test -d $DIR/$tdir
10989 }
10990 run_test 154g "various llapi FID tests"
10991
10992 test_155_small_load() {
10993     local temp=$TMP/$tfile
10994     local file=$DIR/$tfile
10995
10996     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
10997         error "dd of=$temp bs=6096 count=1 failed"
10998     cp $temp $file
10999     cancel_lru_locks osc
11000     cmp $temp $file || error "$temp $file differ"
11001
11002     $TRUNCATE $temp 6000
11003     $TRUNCATE $file 6000
11004     cmp $temp $file || error "$temp $file differ (truncate1)"
11005
11006     echo "12345" >>$temp
11007     echo "12345" >>$file
11008     cmp $temp $file || error "$temp $file differ (append1)"
11009
11010     echo "12345" >>$temp
11011     echo "12345" >>$file
11012     cmp $temp $file || error "$temp $file differ (append2)"
11013
11014     rm -f $temp $file
11015     true
11016 }
11017
11018 test_155_big_load() {
11019     remote_ost_nodsh && skip "remote OST with nodsh" && return
11020     local temp=$TMP/$tfile
11021     local file=$DIR/$tfile
11022
11023     free_min_max
11024     local cache_size=$(do_facet ost$((MAXI+1)) \
11025         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
11026     local large_file_size=$((cache_size * 2))
11027
11028     echo "OSS cache size: $cache_size KB"
11029     echo "Large file size: $large_file_size KB"
11030
11031     [ $MAXV -le $large_file_size ] && \
11032         skip_env "max available OST size needs > $large_file_size KB" && \
11033         return 0
11034
11035     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
11036
11037     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
11038         error "dd of=$temp bs=$large_file_size count=1k failed"
11039     cp $temp $file
11040     ls -lh $temp $file
11041     cancel_lru_locks osc
11042     cmp $temp $file || error "$temp $file differ"
11043
11044     rm -f $temp $file
11045     true
11046 }
11047
11048 save_writethrough() {
11049         local facets=$(get_facets OST)
11050
11051         save_lustre_params $facets "obdfilter.*.writethrough_cache_enable" > $1
11052         save_lustre_params $facets "osd-*.*.writethrough_cache_enable" >> $1
11053 }
11054
11055 test_155a() {
11056         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11057         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11058         save_writethrough $p
11059
11060         set_cache read on
11061         set_cache writethrough on
11062         test_155_small_load
11063         restore_lustre_params < $p
11064         rm -f $p
11065 }
11066 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
11067
11068 test_155b() {
11069         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11070         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11071         save_writethrough $p
11072
11073         set_cache read on
11074         set_cache writethrough off
11075         test_155_small_load
11076         restore_lustre_params < $p
11077         rm -f $p
11078 }
11079 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
11080
11081 test_155c() {
11082         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11083         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11084         save_writethrough $p
11085
11086         set_cache read off
11087         set_cache writethrough on
11088         test_155_small_load
11089         restore_lustre_params < $p
11090         rm -f $p
11091 }
11092 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
11093
11094 test_155d() {
11095         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11096         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11097         save_writethrough $p
11098
11099         set_cache read off
11100         set_cache writethrough off
11101         test_155_small_load
11102         restore_lustre_params < $p
11103         rm -f $p
11104 }
11105 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
11106
11107 test_155e() {
11108         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11109         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11110         save_writethrough $p
11111
11112         set_cache read on
11113         set_cache writethrough on
11114         test_155_big_load
11115         restore_lustre_params < $p
11116         rm -f $p
11117 }
11118 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
11119
11120 test_155f() {
11121         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11122         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11123         save_writethrough $p
11124
11125         set_cache read on
11126         set_cache writethrough off
11127         test_155_big_load
11128         restore_lustre_params < $p
11129         rm -f $p
11130 }
11131 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
11132
11133 test_155g() {
11134         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11135         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11136         save_writethrough $p
11137
11138         set_cache read off
11139         set_cache writethrough on
11140         test_155_big_load
11141         restore_lustre_params < $p
11142         rm -f $p
11143 }
11144 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
11145
11146 test_155h() {
11147         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11148         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11149         save_writethrough $p
11150
11151         set_cache read off
11152         set_cache writethrough off
11153         test_155_big_load
11154         restore_lustre_params < $p
11155         rm -f $p
11156 }
11157 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
11158
11159 test_156() {
11160         remote_ost_nodsh && skip "remote OST with nodsh" && return
11161         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11162         local CPAGES=3
11163         local BEFORE
11164         local AFTER
11165         local file="$DIR/$tfile"
11166         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11167
11168         [ "$(facet_fstype ost1)" = "zfs" -a \
11169            $(lustre_version_code ost1 -lt $(version_code 2.6.93)) ] &&
11170                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS" &&
11171                 return
11172
11173         save_writethrough $p
11174         roc_hit_init
11175
11176         log "Turn on read and write cache"
11177         set_cache read on
11178         set_cache writethrough on
11179
11180         log "Write data and read it back."
11181         log "Read should be satisfied from the cache."
11182         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11183         BEFORE=$(roc_hit)
11184         cancel_lru_locks osc
11185         cat $file >/dev/null
11186         AFTER=$(roc_hit)
11187         if ! let "AFTER - BEFORE == CPAGES"; then
11188                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11189         else
11190                 log "cache hits:: before: $BEFORE, after: $AFTER"
11191         fi
11192
11193         log "Read again; it should be satisfied from the cache."
11194         BEFORE=$AFTER
11195         cancel_lru_locks osc
11196         cat $file >/dev/null
11197         AFTER=$(roc_hit)
11198         if ! let "AFTER - BEFORE == CPAGES"; then
11199                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11200         else
11201                 log "cache hits:: before: $BEFORE, after: $AFTER"
11202         fi
11203
11204         log "Turn off the read cache and turn on the write cache"
11205         set_cache read off
11206         set_cache writethrough on
11207
11208         log "Read again; it should be satisfied from the cache."
11209         BEFORE=$(roc_hit)
11210         cancel_lru_locks osc
11211         cat $file >/dev/null
11212         AFTER=$(roc_hit)
11213         if ! let "AFTER - BEFORE == CPAGES"; then
11214                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11215         else
11216                 log "cache hits:: before: $BEFORE, after: $AFTER"
11217         fi
11218
11219         log "Read again; it should not be satisfied from the cache."
11220         BEFORE=$AFTER
11221         cancel_lru_locks osc
11222         cat $file >/dev/null
11223         AFTER=$(roc_hit)
11224         if ! let "AFTER - BEFORE == 0"; then
11225                 error "IN CACHE: before: $BEFORE, after: $AFTER"
11226         else
11227                 log "cache hits:: before: $BEFORE, after: $AFTER"
11228         fi
11229
11230         log "Write data and read it back."
11231         log "Read should be satisfied from the cache."
11232         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11233         BEFORE=$(roc_hit)
11234         cancel_lru_locks osc
11235         cat $file >/dev/null
11236         AFTER=$(roc_hit)
11237         if ! let "AFTER - BEFORE == CPAGES"; then
11238                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11239         else
11240                 log "cache hits:: before: $BEFORE, after: $AFTER"
11241         fi
11242
11243         log "Read again; it should not be satisfied from the cache."
11244         BEFORE=$AFTER
11245         cancel_lru_locks osc
11246         cat $file >/dev/null
11247         AFTER=$(roc_hit)
11248         if ! let "AFTER - BEFORE == 0"; then
11249                 error "IN CACHE: before: $BEFORE, after: $AFTER"
11250         else
11251                 log "cache hits:: before: $BEFORE, after: $AFTER"
11252         fi
11253
11254         log "Turn off read and write cache"
11255         set_cache read off
11256         set_cache writethrough off
11257
11258         log "Write data and read it back"
11259         log "It should not be satisfied from the cache."
11260         rm -f $file
11261         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11262         cancel_lru_locks osc
11263         BEFORE=$(roc_hit)
11264         cat $file >/dev/null
11265         AFTER=$(roc_hit)
11266         if ! let "AFTER - BEFORE == 0"; then
11267                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
11268         else
11269                 log "cache hits:: before: $BEFORE, after: $AFTER"
11270         fi
11271
11272         log "Turn on the read cache and turn off the write cache"
11273         set_cache read on
11274         set_cache writethrough off
11275
11276         log "Write data and read it back"
11277         log "It should not be satisfied from the cache."
11278         rm -f $file
11279         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
11280         BEFORE=$(roc_hit)
11281         cancel_lru_locks osc
11282         cat $file >/dev/null
11283         AFTER=$(roc_hit)
11284         if ! let "AFTER - BEFORE == 0"; then
11285                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
11286         else
11287                 log "cache hits:: before: $BEFORE, after: $AFTER"
11288         fi
11289
11290         log "Read again; it should be satisfied from the cache."
11291         BEFORE=$(roc_hit)
11292         cancel_lru_locks osc
11293         cat $file >/dev/null
11294         AFTER=$(roc_hit)
11295         if ! let "AFTER - BEFORE == CPAGES"; then
11296                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
11297         else
11298                 log "cache hits:: before: $BEFORE, after: $AFTER"
11299         fi
11300
11301         rm -f $file
11302         restore_lustre_params < $p
11303         rm -f $p
11304 }
11305 run_test 156 "Verification of tunables"
11306
11307 #Changelogs
11308 cleanup_changelog () {
11309         trap 0
11310         echo "Deregistering changelog client $CL_USER"
11311         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $CL_USER
11312 }
11313
11314 err17935 () {
11315         if [[ $MDSCOUNT -gt 1 ]]; then
11316                 error_ignore bz17935 $*
11317         else
11318                 error $*
11319         fi
11320 }
11321
11322 changelog_chmask()
11323 {
11324         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
11325
11326         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
11327
11328         if [ $MASK -eq 1 ]; then
11329                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
11330         else
11331                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
11332         fi
11333 }
11334
11335 changelog_extract_field() {
11336         local mdt=$1
11337         local cltype=$2
11338         local file=$3
11339         local identifier=$4
11340
11341         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
11342                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
11343                 tail -1
11344 }
11345
11346 test_160a() {
11347         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11348         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11349         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
11350                 { skip "Need MDS version at least 2.2.0"; return; }
11351
11352         local CL_USERS="mdd.$MDT0.changelog_users"
11353         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
11354         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11355                 changelog_register -n)
11356         echo "Registered as changelog user $CL_USER"
11357         trap cleanup_changelog EXIT
11358         $GET_CL_USERS | grep -q $CL_USER ||
11359                 error "User $CL_USER not found in changelog_users"
11360
11361         # change something
11362         test_mkdir -p $DIR/$tdir/pics/2008/zachy
11363         touch $DIR/$tdir/pics/2008/zachy/timestamp
11364         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
11365         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
11366         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
11367         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
11368         rm $DIR/$tdir/pics/desktop.jpg
11369
11370         $LFS changelog $MDT0 | tail -5
11371
11372         echo "verifying changelog mask"
11373         changelog_chmask "MKDIR"
11374         changelog_chmask "CLOSE"
11375
11376         test_mkdir -p $DIR/$tdir/pics/zach/sofia
11377         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
11378
11379         changelog_chmask "MKDIR"
11380         changelog_chmask "CLOSE"
11381
11382         test_mkdir -p $DIR/$tdir/pics/2008/sofia
11383         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
11384
11385         $LFS changelog $MDT0
11386         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
11387         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
11388         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
11389         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
11390
11391         # verify contents
11392         echo "verifying target fid"
11393         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
11394         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
11395         [ "$fidc" == "$fidf" ] ||
11396                 err17935 "fid in changelog $fidc != file fid $fidf"
11397         echo "verifying parent fid"
11398         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
11399         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
11400         [ "$fidc" == "$fidf" ] ||
11401                 err17935 "pfid in changelog $fidc != dir fid $fidf"
11402
11403         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
11404         $LFS changelog_clear $MDT0 $CL_USER $(($USER_REC1 + 5))
11405         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$CL_USER\" {print \$2}")
11406         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
11407         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
11408                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
11409
11410         MIN_REC=$($GET_CL_USERS |
11411                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
11412         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
11413         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
11414         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
11415                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
11416
11417         # LU-3446 changelog index reset on MDT restart
11418         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
11419         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11420         $LFS changelog_clear $MDT0 $CL_USER 0
11421         stop $SINGLEMDS || error "Fail to stop MDT."
11422         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
11423         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11424         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
11425         [ $CUR_REC1 == $CUR_REC2 ] ||
11426                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
11427
11428         echo "verifying user deregister"
11429         cleanup_changelog
11430         $GET_CL_USERS | grep -q $CL_USER &&
11431                 error "User $CL_USER still in changelog_users"
11432
11433         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
11434         if [ $CL_USER -eq 0 ]; then
11435                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11436                 touch $DIR/$tdir/chloe
11437                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
11438                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
11439                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
11440         else
11441                 echo "$CL_USER other changelog users; can't verify off"
11442         fi
11443 }
11444 run_test 160a "changelog sanity"
11445
11446 test_160b() { # LU-3587
11447         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11448         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11449         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
11450                 { skip "Need MDS version at least 2.2.0"; return; }
11451
11452         local CL_USERS="mdd.$MDT0.changelog_users"
11453         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
11454         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11455                 changelog_register -n)
11456         echo "Registered as changelog user $CL_USER"
11457         trap cleanup_changelog EXIT
11458         $GET_CL_USERS | grep -q $CL_USER ||
11459                 error "User $CL_USER not found in changelog_users"
11460
11461         local LONGNAME1=$(str_repeat a 255)
11462         local LONGNAME2=$(str_repeat b 255)
11463
11464         cd $DIR
11465         echo "creating very long named file"
11466         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
11467         echo "moving very long named file"
11468         mv $LONGNAME1 $LONGNAME2
11469
11470         $LFS changelog $MDT0 | grep RENME
11471         rm -f $LONGNAME2
11472         cleanup_changelog
11473 }
11474 run_test 160b "Verify that very long rename doesn't crash in changelog"
11475
11476 test_160c() {
11477         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11478
11479         local rc=0
11480         local server_version=$(lustre_version_code $SINGLEMDS)
11481
11482         [[ $server_version -gt $(version_code 2.5.57) ]] ||
11483                 [[ $server_version -gt $(version_code 2.5.1) &&
11484                    $server_version -lt $(version_code 2.5.50) ]] ||
11485                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
11486         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11487
11488         # Registration step
11489         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11490                 changelog_register -n)
11491         trap cleanup_changelog EXIT
11492
11493         rm -rf $DIR/$tdir
11494         mkdir -p $DIR/$tdir
11495         $MCREATE $DIR/$tdir/foo_160c
11496         changelog_chmask "TRUNC"
11497         $TRUNCATE $DIR/$tdir/foo_160c 200
11498         changelog_chmask "TRUNC"
11499         $TRUNCATE $DIR/$tdir/foo_160c 199
11500         $LFS changelog $MDT0
11501         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
11502         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
11503         $LFS changelog_clear $MDT0 $CL_USER 0
11504
11505         # Deregistration step
11506         cleanup_changelog
11507 }
11508 run_test 160c "verify that changelog log catch the truncate event"
11509
11510 test_160d() {
11511         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11512         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11513
11514         local server_version=$(lustre_version_code mds1)
11515         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
11516
11517         [[ $server_version -ge $(version_code 2.7.60) ]] ||
11518                 { skip "Need MDS version at least 2.7.60+"; return; }
11519         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11520
11521         # Registration step
11522         CL_USER=$(do_facet mds1 $LCTL --device $MDT0 \
11523                 changelog_register -n)
11524
11525         trap cleanup_changelog EXIT
11526         mkdir -p $DIR/$tdir/migrate_dir
11527         $LFS changelog_clear $MDT0 $CL_USER 0
11528
11529         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
11530         $LFS changelog $MDT0
11531         MIGRATES=$($LFS changelog $MDT0 | tail -5 | grep -c "MIGRT")
11532         $LFS changelog_clear $MDT0 $CL_USER 0
11533         [ $MIGRATES -eq 1 ] ||
11534                 error "MIGRATE changelog mask count $MIGRATES != 1"
11535
11536         # Deregistration step
11537         cleanup_changelog
11538 }
11539 run_test 160d "verify that changelog log catch the migrate event"
11540
11541 test_160e() {
11542         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11543
11544         # Create a user
11545         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11546                 changelog_register -n)
11547         echo "Registered as changelog user $CL_USER"
11548         trap cleanup_changelog EXIT
11549
11550         # Delete a future user (expect fail)
11551         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister cl77
11552         local rc=$?
11553
11554         if [ $rc -eq 0 ]; then
11555                 error "Deleted non-existant user cl77"
11556         elif [ $rc -ne 2 ]; then
11557                 error "changelog_deregister failed with $rc, " \
11558                         "expected 2 (ENOENT)"
11559         fi
11560
11561         # Clear to a bad index (1 billion should be safe)
11562         $LFS changelog_clear $MDT0 $CL_USER 1000000000
11563         rc=$?
11564
11565         if [ $rc -eq 0 ]; then
11566                 error "Successfully cleared to invalid CL index"
11567         elif [ $rc -ne 22 ]; then
11568                 error "changelog_clear failed with $rc, expected 22 (EINVAL)"
11569         fi
11570 }
11571 run_test 160e "changelog negative testing"
11572
11573 test_161a() {
11574         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11575         test_mkdir -p -c1 $DIR/$tdir
11576         cp /etc/hosts $DIR/$tdir/$tfile
11577         test_mkdir -c1 $DIR/$tdir/foo1
11578         test_mkdir -c1 $DIR/$tdir/foo2
11579         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
11580         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
11581         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
11582         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
11583         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
11584         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
11585                 $LFS fid2path $DIR $FID
11586                 err17935 "bad link ea"
11587         fi
11588     # middle
11589     rm $DIR/$tdir/foo2/zachary
11590     # last
11591     rm $DIR/$tdir/foo2/thor
11592     # first
11593     rm $DIR/$tdir/$tfile
11594     # rename
11595     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
11596     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
11597         then
11598         $LFS fid2path $DIR $FID
11599         err17935 "bad link rename"
11600     fi
11601     rm $DIR/$tdir/foo2/maggie
11602
11603         # overflow the EA
11604         local longname=filename_avg_len_is_thirty_two_
11605         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
11606                 error "failed to hardlink many files"
11607         links=$($LFS fid2path $DIR $FID | wc -l)
11608         echo -n "${links}/1000 links in link EA"
11609         [[ $links -gt 60 ]] ||
11610                 err17935 "expected at least 60 links in link EA"
11611         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
11612                 error "failed to unlink many hardlinks"
11613 }
11614 run_test 161a "link ea sanity"
11615
11616 test_161b() {
11617         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11618         [ $MDSCOUNT -lt 2 ] && skip "skipping remote directory test" && return
11619         local MDTIDX=1
11620         local remote_dir=$DIR/$tdir/remote_dir
11621
11622         mkdir -p $DIR/$tdir
11623         $LFS mkdir -i $MDTIDX $remote_dir ||
11624                 error "create remote directory failed"
11625
11626         cp /etc/hosts $remote_dir/$tfile
11627         mkdir -p $remote_dir/foo1
11628         mkdir -p $remote_dir/foo2
11629         ln $remote_dir/$tfile $remote_dir/foo1/sofia
11630         ln $remote_dir/$tfile $remote_dir/foo2/zachary
11631         ln $remote_dir/$tfile $remote_dir/foo1/luna
11632         ln $remote_dir/$tfile $remote_dir/foo2/thor
11633
11634         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
11635                      tr -d ']')
11636         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
11637                 $LFS fid2path $DIR $FID
11638                 err17935 "bad link ea"
11639         fi
11640         # middle
11641         rm $remote_dir/foo2/zachary
11642         # last
11643         rm $remote_dir/foo2/thor
11644         # first
11645         rm $remote_dir/$tfile
11646         # rename
11647         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
11648         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
11649         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
11650                 $LFS fid2path $DIR $FID
11651                 err17935 "bad link rename"
11652         fi
11653         rm $remote_dir/foo2/maggie
11654
11655         # overflow the EA
11656         local longname=filename_avg_len_is_thirty_two_
11657         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
11658                 error "failed to hardlink many files"
11659         links=$($LFS fid2path $DIR $FID | wc -l)
11660         echo -n "${links}/1000 links in link EA"
11661         [[ ${links} -gt 60 ]] ||
11662                 err17935 "expected at least 60 links in link EA"
11663         unlinkmany $remote_dir/foo2/$longname 1000 ||
11664         error "failed to unlink many hardlinks"
11665 }
11666 run_test 161b "link ea sanity under remote directory"
11667
11668 test_161c() {
11669         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11670         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11671         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
11672                 skip "Need MDS version at least 2.1.5" && return
11673
11674         # define CLF_RENAME_LAST 0x0001
11675         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
11676         CL_USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11677                 changelog_register -n)
11678
11679         trap cleanup_changelog EXIT
11680         rm -rf $DIR/$tdir
11681         mkdir -p $DIR/$tdir
11682         touch $DIR/$tdir/foo_161c
11683         touch $DIR/$tdir/bar_161c
11684         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
11685         $LFS changelog $MDT0 | grep RENME
11686         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
11687                 cut -f5 -d' ')
11688         $LFS changelog_clear $MDT0 $CL_USER 0
11689         if [ x$flags != "x0x1" ]; then
11690                 error "flag $flags is not 0x1"
11691         fi
11692         echo "rename overwrite a target having nlink = 1," \
11693                 "changelog record has flags of $flags"
11694
11695         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
11696         touch $DIR/$tdir/foo_161c
11697         touch $DIR/$tdir/bar_161c
11698         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
11699         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
11700         $LFS changelog $MDT0 | grep RENME
11701         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
11702         $LFS changelog_clear $MDT0 $CL_USER 0
11703         if [ x$flags != "x0x0" ]; then
11704                 error "flag $flags is not 0x0"
11705         fi
11706         echo "rename overwrite a target having nlink > 1," \
11707                 "changelog record has flags of $flags"
11708
11709         # rename doesn't overwrite a target (changelog flag 0x0)
11710         touch $DIR/$tdir/foo_161c
11711         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
11712         $LFS changelog $MDT0 | grep RENME
11713         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
11714         $LFS changelog_clear $MDT0 $CL_USER 0
11715         if [ x$flags != "x0x0" ]; then
11716                 error "flag $flags is not 0x0"
11717         fi
11718         echo "rename doesn't overwrite a target," \
11719                 "changelog record has flags of $flags"
11720
11721         # define CLF_UNLINK_LAST 0x0001
11722         # unlink a file having nlink = 1 (changelog flag 0x1)
11723         rm -f $DIR/$tdir/foo2_161c
11724         $LFS changelog $MDT0 | grep UNLNK
11725         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
11726         $LFS changelog_clear $MDT0 $CL_USER 0
11727         if [ x$flags != "x0x1" ]; then
11728                 error "flag $flags is not 0x1"
11729         fi
11730         echo "unlink a file having nlink = 1," \
11731                 "changelog record has flags of $flags"
11732
11733         # unlink a file having nlink > 1 (changelog flag 0x0)
11734         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
11735         rm -f $DIR/$tdir/foobar_161c
11736         $LFS changelog $MDT0 | grep UNLNK
11737         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
11738         $LFS changelog_clear $MDT0 $CL_USER 0
11739         if [ x$flags != "x0x0" ]; then
11740                 error "flag $flags is not 0x0"
11741         fi
11742         echo "unlink a file having nlink > 1," \
11743                 "changelog record has flags of $flags"
11744         cleanup_changelog
11745 }
11746 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
11747
11748 test_161d() {
11749         local user
11750         local pid
11751         local fid
11752
11753         # cleanup previous run
11754         rm -rf $DIR/$tdir/$tfile
11755
11756         user=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
11757                 changelog_register -n)
11758         [[ $? -eq 0 ]] || error "changelog_register failed"
11759
11760         # work in a standalone dir to avoid locking on $DIR/$MOUNT to
11761         # interfer with $MOUNT/.lustre/fid/ access
11762         mkdir $DIR/$tdir
11763         [[ $? -eq 0 ]] || error "mkdir failed"
11764
11765         #define OBD_FAIL_LLITE_CREATE_NODE_PAUSE 0x140c | OBD_FAIL_ONCE
11766         $LCTL set_param fail_loc=0x8000140c
11767         # 5s pause
11768         $LCTL set_param fail_val=5
11769
11770         # create file
11771         echo foofoo > $DIR/$tdir/$tfile &
11772         pid=$!
11773
11774         # wait for create to be delayed
11775         sleep 2
11776
11777         ps -p $pid
11778         [[ $? -eq 0 ]] || error "create should be blocked"
11779
11780         local tempfile=$(mktemp)
11781         fid=$(changelog_extract_field $MDT0 "CREAT" "$tfile" "t=")
11782         cat $MOUNT/.lustre/fid/$fid 2>/dev/null >$tempfile || error "cat failed"
11783         # some delay may occur during ChangeLog publishing and file read just
11784         # above, that could allow file write to happen finally
11785         [[ -s $tempfile ]] && echo "file should be empty"
11786
11787         $LCTL set_param fail_loc=0
11788
11789         wait $pid
11790         [[ $? -eq 0 ]] || error "create failed"
11791
11792         $LFS changelog_clear $MDT0 $user 0
11793         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $user
11794 }
11795 run_test 161d "create with concurrent .lustre/fid access"
11796
11797 check_path() {
11798     local expected=$1
11799     shift
11800     local fid=$2
11801
11802     local path=$(${LFS} fid2path $*)
11803     # Remove the '//' indicating a remote directory
11804     path=$(echo $path | sed 's#//#/#g')
11805     RC=$?
11806
11807     if [ $RC -ne 0 ]; then
11808         err17935 "path looked up of $expected failed. Error $RC"
11809         return $RC
11810     elif [ "${path}" != "${expected}" ]; then
11811         err17935 "path looked up \"${path}\" instead of \"${expected}\""
11812         return 2
11813     fi
11814     echo "fid $fid resolves to path $path (expected $expected)"
11815 }
11816
11817 test_162a() { # was test_162
11818         # Make changes to filesystem
11819         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11820         test_mkdir -p -c1 $DIR/$tdir/d2
11821         touch $DIR/$tdir/d2/$tfile
11822         touch $DIR/$tdir/d2/x1
11823         touch $DIR/$tdir/d2/x2
11824         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
11825         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
11826         # regular file
11827         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
11828         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
11829                 error "check path $tdir/d2/$tfile failed"
11830
11831         # softlink
11832         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
11833         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
11834         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
11835                 error "check path $tdir/d2/p/q/r/slink failed"
11836
11837         # softlink to wrong file
11838         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
11839         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
11840         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
11841                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
11842
11843         # hardlink
11844         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
11845         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
11846         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
11847         # fid2path dir/fsname should both work
11848         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
11849                 error "check path $tdir/d2/a/b/c/new_file failed"
11850         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
11851                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
11852
11853         # hardlink count: check that there are 2 links
11854         # Doesnt work with CMD yet: 17935
11855         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
11856                 err17935 "expected 2 links"
11857
11858         # hardlink indexing: remove the first link
11859         rm $DIR/$tdir/d2/p/q/r/hlink
11860         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
11861                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
11862
11863         return 0
11864 }
11865 run_test 162a "path lookup sanity"
11866
11867 test_162b() {
11868         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11869         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11870
11871         mkdir $DIR/$tdir
11872         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
11873                                 error "create striped dir failed"
11874
11875         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
11876                                         tail -n 1 | awk '{print $2}')
11877         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
11878
11879         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
11880         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
11881
11882         # regular file
11883         for ((i=0;i<5;i++)); do
11884                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
11885                         error "get fid for f$i failed"
11886                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
11887                         error "check path $tdir/striped_dir/f$i failed"
11888
11889                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
11890                         error "get fid for d$i failed"
11891                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
11892                         error "check path $tdir/striped_dir/d$i failed"
11893         done
11894
11895         return 0
11896 }
11897 run_test 162b "striped directory path lookup sanity"
11898
11899 # LU-4239: Verify fid2path works with paths 100 or more directories deep
11900 test_162c() {
11901         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.51) ]] &&
11902                 skip "Need MDS version at least 2.7.51" && return
11903         test_mkdir $DIR/$tdir.local
11904         test_mkdir $DIR/$tdir.remote
11905         local lpath=$tdir.local
11906         local rpath=$tdir.remote
11907
11908         for ((i = 0; i <= 101; i++)); do
11909                 lpath="$lpath/$i"
11910                 mkdir $DIR/$lpath
11911                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
11912                         error "get fid for local directory $DIR/$lpath failed"
11913                 check_path "$DIR/$lpath" $MOUNT $FID --link 0 ||
11914                         error "check path for local directory $DIR/$lpath failed"
11915
11916                 rpath="$rpath/$i"
11917                 test_mkdir $DIR/$rpath
11918                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
11919                         error "get fid for remote directory $DIR/$rpath failed"
11920                 check_path "$DIR/$rpath" $MOUNT $FID --link 0 ||
11921                         error "check path for remote directory $DIR/$rpath failed"
11922         done
11923
11924         return 0
11925 }
11926 run_test 162c "fid2path works with paths 100 or more directories deep"
11927
11928 test_169() {
11929         # do directio so as not to populate the page cache
11930         log "creating a 10 Mb file"
11931         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11932         log "starting reads"
11933         dd if=$DIR/$tfile of=/dev/null bs=4096 &
11934         log "truncating the file"
11935         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11936         log "killing dd"
11937         kill %+ || true # reads might have finished
11938         echo "wait until dd is finished"
11939         wait
11940         log "removing the temporary file"
11941         rm -rf $DIR/$tfile || error "tmp file removal failed"
11942 }
11943 run_test 169 "parallel read and truncate should not deadlock"
11944
11945 test_170() {
11946         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11947         $LCTL clear     # bug 18514
11948         $LCTL debug_daemon start $TMP/${tfile}_log_good
11949         touch $DIR/$tfile
11950         $LCTL debug_daemon stop
11951         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
11952                error "sed failed to read log_good"
11953
11954         $LCTL debug_daemon start $TMP/${tfile}_log_good
11955         rm -rf $DIR/$tfile
11956         $LCTL debug_daemon stop
11957
11958         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
11959                error "lctl df log_bad failed"
11960
11961         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
11962         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
11963
11964         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
11965         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
11966
11967         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
11968                 error "bad_line good_line1 good_line2 are empty"
11969
11970         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11971         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
11972         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11973
11974         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
11975         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
11976         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
11977
11978         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
11979                 error "bad_line_new good_line_new are empty"
11980
11981         local expected_good=$((good_line1 + good_line2*2))
11982
11983         rm -f $TMP/${tfile}*
11984         # LU-231, short malformed line may not be counted into bad lines
11985         if [ $bad_line -ne $bad_line_new ] &&
11986                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
11987                 error "expected $bad_line bad lines, but got $bad_line_new"
11988                 return 1
11989         fi
11990
11991         if [ $expected_good -ne $good_line_new ]; then
11992                 error "expected $expected_good good lines, but got $good_line_new"
11993                 return 2
11994         fi
11995         true
11996 }
11997 run_test 170 "test lctl df to handle corrupted log ====================="
11998
11999 test_171() { # bug20592
12000         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12001 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
12002         $LCTL set_param fail_loc=0x50e
12003         $LCTL set_param fail_val=3000
12004         multiop_bg_pause $DIR/$tfile O_s || true
12005         local MULTIPID=$!
12006         kill -USR1 $MULTIPID
12007         # cause log dump
12008         sleep 3
12009         wait $MULTIPID
12010         if dmesg | grep "recursive fault"; then
12011                 error "caught a recursive fault"
12012         fi
12013         $LCTL set_param fail_loc=0
12014         true
12015 }
12016 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
12017
12018 # it would be good to share it with obdfilter-survey/iokit-libecho code
12019 setup_obdecho_osc () {
12020         local rc=0
12021         local ost_nid=$1
12022         local obdfilter_name=$2
12023         echo "Creating new osc for $obdfilter_name on $ost_nid"
12024         # make sure we can find loopback nid
12025         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
12026
12027         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
12028                            ${obdfilter_name}_osc_UUID || rc=2; }
12029         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
12030                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
12031         return $rc
12032 }
12033
12034 cleanup_obdecho_osc () {
12035         local obdfilter_name=$1
12036         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
12037         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
12038         return 0
12039 }
12040
12041 obdecho_test() {
12042         local OBD=$1
12043         local node=$2
12044         local pages=${3:-64}
12045         local rc=0
12046         local id
12047
12048         local count=10
12049         local obd_size=$(get_obd_size $node $OBD)
12050         local page_size=$(get_page_size $node)
12051         if [[ -n "$obd_size" ]]; then
12052                 local new_count=$((obd_size / (pages * page_size / 1024)))
12053                 [[ $new_count -ge $count ]] || count=$new_count
12054         fi
12055
12056         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
12057         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
12058                            rc=2; }
12059         if [ $rc -eq 0 ]; then
12060             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
12061             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
12062         fi
12063         echo "New object id is $id"
12064         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
12065                            rc=4; }
12066         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
12067                            "test_brw $count w v $pages $id" || rc=4; }
12068         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
12069                            rc=4; }
12070         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
12071                                         "cleanup" || rc=5; }
12072         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
12073                                         "detach" || rc=6; }
12074         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
12075         return $rc
12076 }
12077
12078 test_180a() {
12079         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12080         remote_ost_nodsh && skip "remote OST with nodsh" && return
12081         local rc=0
12082         local rmmod_local=0
12083
12084         if ! module_loaded obdecho; then
12085             load_module obdecho/obdecho
12086             rmmod_local=1
12087         fi
12088
12089         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
12090         local host=$(lctl get_param -n osc.$osc.import |
12091                              awk '/current_connection:/ {print $2}' )
12092         local target=$(lctl get_param -n osc.$osc.import |
12093                              awk '/target:/ {print $2}' )
12094         target=${target%_UUID}
12095
12096         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
12097         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
12098         [[ -n $target ]] && cleanup_obdecho_osc $target
12099         [ $rmmod_local -eq 1 ] && rmmod obdecho
12100         return $rc
12101 }
12102 run_test 180a "test obdecho on osc"
12103
12104 test_180b() {
12105         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12106         remote_ost_nodsh && skip "remote OST with nodsh" && return
12107         local rc=0
12108         local rmmod_remote=0
12109
12110         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
12111                 rmmod_remote=true || error "failed to load module obdecho"
12112         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
12113         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
12114         $rmmod_remote && do_facet ost1 "rmmod obdecho"
12115         return $rc
12116 }
12117 run_test 180b "test obdecho directly on obdfilter"
12118
12119 test_180c() { # LU-2598
12120         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12121         remote_ost_nodsh && skip "remote OST with nodsh" && return
12122         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
12123                 skip "Need MDS version at least 2.4.0" && return
12124
12125         local rc=0
12126         local rmmod_remote=false
12127         local pages=16384 # 64MB bulk I/O RPC size
12128         local target
12129
12130         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
12131                 rmmod_remote=true || error "failed to load module obdecho"
12132
12133         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
12134                 head -n1)
12135         if [ -n "$target" ]; then
12136                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
12137         else
12138                 echo "there is no obdfilter target on ost1"
12139                 rc=2
12140         fi
12141         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
12142         return $rc
12143 }
12144 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
12145
12146 test_181() { # bug 22177
12147         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12148         # create enough files to index the directory
12149         createmany -o $DIR/$tdir/foobar 4000
12150         # print attributes for debug purpose
12151         lsattr -d .
12152         # open dir
12153         multiop_bg_pause $DIR/$tdir D_Sc || return 1
12154         MULTIPID=$!
12155         # remove the files & current working dir
12156         unlinkmany $DIR/$tdir/foobar 4000
12157         rmdir $DIR/$tdir
12158         kill -USR1 $MULTIPID
12159         wait $MULTIPID
12160         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
12161         return 0
12162 }
12163 run_test 181 "Test open-unlinked dir ========================"
12164
12165 test_182() {
12166         local fcount=1000
12167         local tcount=10
12168
12169         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12170
12171         $LCTL set_param mdc.*.rpc_stats=clear
12172
12173         for (( i = 0; i < $tcount; i++ )) ; do
12174                 mkdir $DIR/$tdir/$i
12175         done
12176
12177         for (( i = 0; i < $tcount; i++ )) ; do
12178                 createmany -o $DIR/$tdir/$i/f- $fcount &
12179         done
12180         wait
12181
12182         for (( i = 0; i < $tcount; i++ )) ; do
12183                 unlinkmany $DIR/$tdir/$i/f- $fcount &
12184         done
12185         wait
12186
12187         $LCTL get_param mdc.*.rpc_stats
12188
12189         rm -rf $DIR/$tdir
12190 }
12191 run_test 182 "Test parallel modify metadata operations ================"
12192
12193 test_183() { # LU-2275
12194         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12195         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
12196                 skip "Need MDS version at least 2.3.56" && return
12197
12198         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12199         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12200         echo aaa > $DIR/$tdir/$tfile
12201
12202 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
12203         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
12204
12205         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
12206         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
12207
12208         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
12209
12210         # Flush negative dentry cache
12211         touch $DIR/$tdir/$tfile
12212
12213         # We are not checking for any leaked references here, they'll
12214         # become evident next time we do cleanup with module unload.
12215         rm -rf $DIR/$tdir
12216 }
12217 run_test 183 "No crash or request leak in case of strange dispositions ========"
12218
12219 # test suite 184 is for LU-2016, LU-2017
12220 test_184a() {
12221         check_swap_layouts_support && return 0
12222
12223         dir0=$DIR/$tdir/$testnum
12224         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
12225         ref1=/etc/passwd
12226         ref2=/etc/group
12227         file1=$dir0/f1
12228         file2=$dir0/f2
12229         $SETSTRIPE -c1 $file1
12230         cp $ref1 $file1
12231         $SETSTRIPE -c2 $file2
12232         cp $ref2 $file2
12233         gen1=$($GETSTRIPE -g $file1)
12234         gen2=$($GETSTRIPE -g $file2)
12235
12236         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
12237         gen=$($GETSTRIPE -g $file1)
12238         [[ $gen1 != $gen ]] ||
12239                 "Layout generation on $file1 does not change"
12240         gen=$($GETSTRIPE -g $file2)
12241         [[ $gen2 != $gen ]] ||
12242                 "Layout generation on $file2 does not change"
12243
12244         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
12245         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12246 }
12247 run_test 184a "Basic layout swap"
12248
12249 test_184b() {
12250         check_swap_layouts_support && return 0
12251
12252         dir0=$DIR/$tdir/$testnum
12253         mkdir -p $dir0 || error "creating dir $dir0"
12254         file1=$dir0/f1
12255         file2=$dir0/f2
12256         file3=$dir0/f3
12257         dir1=$dir0/d1
12258         dir2=$dir0/d2
12259         mkdir $dir1 $dir2
12260         $SETSTRIPE -c1 $file1
12261         $SETSTRIPE -c2 $file2
12262         $SETSTRIPE -c1 $file3
12263         chown $RUNAS_ID $file3
12264         gen1=$($GETSTRIPE -g $file1)
12265         gen2=$($GETSTRIPE -g $file2)
12266
12267         $LFS swap_layouts $dir1 $dir2 &&
12268                 error "swap of directories layouts should fail"
12269         $LFS swap_layouts $dir1 $file1 &&
12270                 error "swap of directory and file layouts should fail"
12271         $RUNAS $LFS swap_layouts $file1 $file2 &&
12272                 error "swap of file we cannot write should fail"
12273         $LFS swap_layouts $file1 $file3 &&
12274                 error "swap of file with different owner should fail"
12275         /bin/true # to clear error code
12276 }
12277 run_test 184b "Forbidden layout swap (will generate errors)"
12278
12279 test_184c() {
12280         local cmpn_arg=$(cmp -n 2>&1 | grep "invalid option")
12281         [ -n "$cmpn_arg" ] && skip_env "cmp does not support -n" && return
12282         check_swap_layouts_support && return 0
12283
12284         local dir0=$DIR/$tdir/$testnum
12285         mkdir -p $dir0 || error "creating dir $dir0"
12286
12287         local ref1=$dir0/ref1
12288         local ref2=$dir0/ref2
12289         local file1=$dir0/file1
12290         local file2=$dir0/file2
12291         # create a file large enough for the concurrent test
12292         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
12293         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
12294         echo "ref file size: ref1($(stat -c %s $ref1))," \
12295              "ref2($(stat -c %s $ref2))"
12296
12297         cp $ref2 $file2
12298         dd if=$ref1 of=$file1 bs=16k &
12299         local DD_PID=$!
12300
12301         # Make sure dd starts to copy file
12302         while [ ! -f $file1 ]; do sleep 0.1; done
12303
12304         $LFS swap_layouts $file1 $file2
12305         local rc=$?
12306         wait $DD_PID
12307         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
12308         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
12309
12310         # how many bytes copied before swapping layout
12311         local copied=$(stat -c %s $file2)
12312         local remaining=$(stat -c %s $ref1)
12313         remaining=$((remaining - copied))
12314         echo "Copied $copied bytes before swapping layout..."
12315
12316         cmp -n $copied $file1 $ref2 | grep differ &&
12317                 error "Content mismatch [0, $copied) of ref2 and file1"
12318         cmp -n $copied $file2 $ref1 ||
12319                 error "Content mismatch [0, $copied) of ref1 and file2"
12320         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
12321                 error "Content mismatch [$copied, EOF) of ref1 and file1"
12322
12323         # clean up
12324         rm -f $ref1 $ref2 $file1 $file2
12325 }
12326 run_test 184c "Concurrent write and layout swap"
12327
12328 test_184d() {
12329         check_swap_layouts_support && return 0
12330         [ -z "$(which getfattr 2>/dev/null)" ] &&
12331                 skip "no getfattr command" && return 0
12332
12333         local file1=$DIR/$tdir/$tfile-1
12334         local file2=$DIR/$tdir/$tfile-2
12335         local file3=$DIR/$tdir/$tfile-3
12336         local lovea1
12337         local lovea2
12338
12339         mkdir -p $DIR/$tdir
12340         touch $file1 || error "create $file1 failed"
12341         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
12342                 error "create $file2 failed"
12343         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
12344                 error "create $file3 failed"
12345         lovea1=$(get_layout_param $file1)
12346
12347         $LFS swap_layouts $file2 $file3 ||
12348                 error "swap $file2 $file3 layouts failed"
12349         $LFS swap_layouts $file1 $file2 ||
12350                 error "swap $file1 $file2 layouts failed"
12351
12352         lovea2=$(get_layout_param $file2)
12353         echo "$lovea1"
12354         echo "$lovea2"
12355         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
12356
12357         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
12358         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
12359 }
12360 run_test 184d "allow stripeless layouts swap"
12361
12362 test_184e() {
12363         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
12364                 { skip "Need MDS version at least 2.6.94"; return 0; }
12365         check_swap_layouts_support && return 0
12366         [ -z "$(which getfattr 2>/dev/null)" ] &&
12367                 skip "no getfattr command" && return 0
12368
12369         local file1=$DIR/$tdir/$tfile-1
12370         local file2=$DIR/$tdir/$tfile-2
12371         local file3=$DIR/$tdir/$tfile-3
12372         local lovea
12373
12374         mkdir -p $DIR/$tdir
12375         touch $file1 || error "create $file1 failed"
12376         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
12377                 error "create $file2 failed"
12378         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
12379                 error "create $file3 failed"
12380
12381         $LFS swap_layouts $file1 $file2 ||
12382                 error "swap $file1 $file2 layouts failed"
12383
12384         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
12385         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
12386
12387         echo 123 > $file1 || error "Should be able to write into $file1"
12388
12389         $LFS swap_layouts $file1 $file3 ||
12390                 error "swap $file1 $file3 layouts failed"
12391
12392         echo 123 > $file1 || error "Should be able to write into $file1"
12393
12394         rm -rf $file1 $file2 $file3
12395 }
12396 run_test 184e "Recreate layout after stripeless layout swaps"
12397
12398 test_185() { # LU-2441
12399         # LU-3553 - no volatile file support in old servers
12400         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
12401                 { skip "Need MDS version at least 2.3.60"; return 0; }
12402
12403         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
12404         touch $DIR/$tdir/spoo
12405         local mtime1=$(stat -c "%Y" $DIR/$tdir)
12406         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
12407                 error "cannot create/write a volatile file"
12408         [ "$FILESET" == "" ] &&
12409         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
12410                 error "FID is still valid after close"
12411
12412         multiop_bg_pause $DIR/$tdir vVw4096_c
12413         local multi_pid=$!
12414
12415         local OLD_IFS=$IFS
12416         IFS=":"
12417         local fidv=($fid)
12418         IFS=$OLD_IFS
12419         # assume that the next FID for this client is sequential, since stdout
12420         # is unfortunately eaten by multiop_bg_pause
12421         local n=$((${fidv[1]} + 1))
12422         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
12423         if [ "$FILESET" == "" ]; then
12424                 $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
12425                         error "FID is missing before close"
12426         fi
12427         kill -USR1 $multi_pid
12428         # 1 second delay, so if mtime change we will see it
12429         sleep 1
12430         local mtime2=$(stat -c "%Y" $DIR/$tdir)
12431         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
12432 }
12433 run_test 185 "Volatile file support"
12434
12435 test_187a() {
12436         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12437         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
12438                 skip "Need MDS version at least 2.3.0" && return
12439
12440         local dir0=$DIR/$tdir/$testnum
12441         mkdir -p $dir0 || error "creating dir $dir0"
12442
12443         local file=$dir0/file1
12444         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
12445         local dv1=$($LFS data_version $file)
12446         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
12447         local dv2=$($LFS data_version $file)
12448         [[ $dv1 != $dv2 ]] ||
12449                 error "data version did not change on write $dv1 == $dv2"
12450
12451         # clean up
12452         rm -f $file1
12453 }
12454 run_test 187a "Test data version change"
12455
12456 test_187b() {
12457         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12458         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
12459                 skip "Need MDS version at least 2.3.0" && return
12460
12461         local dir0=$DIR/$tdir/$testnum
12462         mkdir -p $dir0 || error "creating dir $dir0"
12463
12464         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
12465         [[ ${DV[0]} != ${DV[1]} ]] ||
12466                 error "data version did not change on write"\
12467                       " ${DV[0]} == ${DV[1]}"
12468
12469         # clean up
12470         rm -f $file1
12471 }
12472 run_test 187b "Test data version change on volatile file"
12473
12474 test_200() {
12475         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12476         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12477         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
12478
12479         local POOL=${POOL:-cea1}
12480         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
12481         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
12482         # Pool OST targets
12483         local first_ost=0
12484         local last_ost=$(($OSTCOUNT - 1))
12485         local ost_step=2
12486         local ost_list=$(seq $first_ost $ost_step $last_ost)
12487         local ost_range="$first_ost $last_ost $ost_step"
12488         local test_path=$POOL_ROOT/$POOL_DIR_NAME
12489         local file_dir=$POOL_ROOT/file_tst
12490         local subdir=$test_path/subdir
12491         local rc=0
12492
12493         if ! combined_mgs_mds ; then
12494                 mount_mgs_client
12495         fi
12496
12497         while : ; do
12498                 # former test_200a test_200b
12499                 pool_add $POOL                          || { rc=$? ; break; }
12500                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
12501                 # former test_200c test_200d
12502                 mkdir -p $test_path
12503                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
12504                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
12505                 mkdir -p $subdir
12506                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
12507                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
12508                                                         || { rc=$? ; break; }
12509                 # former test_200e test_200f
12510                 local files=$((OSTCOUNT*3))
12511                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
12512                                                         || { rc=$? ; break; }
12513                 pool_create_files $POOL $file_dir $files "$ost_list" \
12514                                                         || { rc=$? ; break; }
12515                 # former test_200g test_200h
12516                 pool_lfs_df $POOL                       || { rc=$? ; break; }
12517                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
12518
12519                 # former test_201a test_201b test_201c
12520                 pool_remove_first_target $POOL          || { rc=$? ; break; }
12521
12522                 local f=$test_path/$tfile
12523                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
12524                 pool_remove $POOL $f                    || { rc=$? ; break; }
12525                 break
12526         done
12527
12528         destroy_test_pools
12529
12530         if ! combined_mgs_mds ; then
12531                 umount_mgs_client
12532         fi
12533         return $rc
12534 }
12535 run_test 200 "OST pools"
12536
12537 # usage: default_attr <count | size | offset>
12538 default_attr() {
12539         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
12540 }
12541
12542 # usage: check_default_stripe_attr
12543 check_default_stripe_attr() {
12544         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
12545         case $1 in
12546         --stripe-count|-c)
12547                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
12548         --stripe-size|-S)
12549                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
12550         --stripe-index|-i)
12551                 EXPECTED=-1;;
12552         *)
12553                 error "unknown getstripe attr '$1'"
12554         esac
12555
12556         [ $ACTUAL != $EXPECTED ] &&
12557                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
12558 }
12559
12560 test_204a() {
12561         test_mkdir -p $DIR/$tdir
12562         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
12563
12564         check_default_stripe_attr --stripe-count
12565         check_default_stripe_attr --stripe-size
12566         check_default_stripe_attr --stripe-index
12567
12568         return 0
12569 }
12570 run_test 204a "Print default stripe attributes ================="
12571
12572 test_204b() {
12573         test_mkdir -p $DIR/$tdir
12574         $SETSTRIPE --stripe-count 1 $DIR/$tdir
12575
12576         check_default_stripe_attr --stripe-size
12577         check_default_stripe_attr --stripe-index
12578
12579         return 0
12580 }
12581 run_test 204b "Print default stripe size and offset  ==========="
12582
12583 test_204c() {
12584         test_mkdir -p $DIR/$tdir
12585         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
12586
12587         check_default_stripe_attr --stripe-count
12588         check_default_stripe_attr --stripe-index
12589
12590         return 0
12591 }
12592 run_test 204c "Print default stripe count and offset ==========="
12593
12594 test_204d() {
12595         test_mkdir -p $DIR/$tdir
12596         $SETSTRIPE --stripe-index 0 $DIR/$tdir
12597
12598         check_default_stripe_attr --stripe-count
12599         check_default_stripe_attr --stripe-size
12600
12601         return 0
12602 }
12603 run_test 204d "Print default stripe count and size ============="
12604
12605 test_204e() {
12606         test_mkdir -p $DIR/$tdir
12607         $SETSTRIPE -d $DIR/$tdir
12608
12609         check_default_stripe_attr --stripe-count --raw
12610         check_default_stripe_attr --stripe-size --raw
12611         check_default_stripe_attr --stripe-index --raw
12612
12613         return 0
12614 }
12615 run_test 204e "Print raw stripe attributes ================="
12616
12617 test_204f() {
12618         test_mkdir -p $DIR/$tdir
12619         $SETSTRIPE --stripe-count 1 $DIR/$tdir
12620
12621         check_default_stripe_attr --stripe-size --raw
12622         check_default_stripe_attr --stripe-index --raw
12623
12624         return 0
12625 }
12626 run_test 204f "Print raw stripe size and offset  ==========="
12627
12628 test_204g() {
12629         test_mkdir -p $DIR/$tdir
12630         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
12631
12632         check_default_stripe_attr --stripe-count --raw
12633         check_default_stripe_attr --stripe-index --raw
12634
12635         return 0
12636 }
12637 run_test 204g "Print raw stripe count and offset ==========="
12638
12639 test_204h() {
12640         test_mkdir -p $DIR/$tdir
12641         $SETSTRIPE --stripe-index 0 $DIR/$tdir
12642
12643         check_default_stripe_attr --stripe-count --raw
12644         check_default_stripe_attr --stripe-size --raw
12645
12646         return 0
12647 }
12648 run_test 204h "Print raw stripe count and size ============="
12649
12650 # Figure out which job scheduler is being used, if any,
12651 # or use a fake one
12652 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
12653         JOBENV=SLURM_JOB_ID
12654 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
12655         JOBENV=LSB_JOBID
12656 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
12657         JOBENV=PBS_JOBID
12658 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
12659         JOBENV=LOADL_STEP_ID
12660 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
12661         JOBENV=JOB_ID
12662 else
12663         $LCTL list_param jobid_name > /dev/null 2>&1
12664         if [ $? -eq 0 ]; then
12665                 JOBENV=nodelocal
12666         else
12667                 JOBENV=FAKE_JOBID
12668         fi
12669 fi
12670
12671 verify_jobstats() {
12672         local cmd=($1)
12673         shift
12674         local facets="$@"
12675
12676 # we don't really need to clear the stats for this test to work, since each
12677 # command has a unique jobid, but it makes debugging easier if needed.
12678 #       for facet in $facets; do
12679 #               local dev=$(convert_facet2label $facet)
12680 #               # clear old jobstats
12681 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
12682 #       done
12683
12684         # use a new JobID for each test, or we might see an old one
12685         [ "$JOBENV" = "FAKE_JOBID" ] &&
12686                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
12687
12688         JOBVAL=${!JOBENV}
12689
12690         [ "$JOBENV" = "nodelocal" ] && {
12691                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
12692                 $LCTL set_param jobid_name=$FAKE_JOBID
12693                 JOBVAL=$FAKE_JOBID
12694         }
12695
12696         log "Test: ${cmd[*]}"
12697         log "Using JobID environment variable $JOBENV=$JOBVAL"
12698
12699         if [ $JOBENV = "FAKE_JOBID" ]; then
12700                 FAKE_JOBID=$JOBVAL ${cmd[*]}
12701         else
12702                 ${cmd[*]}
12703         fi
12704
12705         # all files are created on OST0000
12706         for facet in $facets; do
12707                 local stats="*.$(convert_facet2label $facet).job_stats"
12708                 if [ $(do_facet $facet lctl get_param $stats |
12709                        grep -c $JOBVAL) -ne 1 ]; then
12710                         do_facet $facet lctl get_param $stats
12711                         error "No jobstats for $JOBVAL found on $facet::$stats"
12712                 fi
12713         done
12714 }
12715
12716 jobstats_set() {
12717         trap 0
12718         NEW_JOBENV=${1:-$OLD_JOBENV}
12719         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
12720         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
12721 }
12722
12723 cleanup_205() {
12724         trap 0
12725         do_facet $SINGLEMDS \
12726                 $LCTL set_param mdt.*.job_cleanup_interval=$OLD_INTERVAL
12727         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
12728         cleanup_changelog
12729 }
12730
12731 test_205() { # Job stats
12732         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.1) ]] ||
12733                 { skip "Need MDS version with at least 2.7.1"; return 0; }
12734
12735         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12736         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12737         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12738         remote_ost_nodsh && skip "remote OST with nodsh" && return
12739
12740         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
12741                 skip "Server doesn't support jobstats" && return 0
12742         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
12743
12744         OLD_JOBENV=$($LCTL get_param -n jobid_var)
12745         if [ $OLD_JOBENV != $JOBENV ]; then
12746                 jobstats_set $JOBENV
12747                 trap cleanup_205 EXIT
12748         fi
12749
12750         CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
12751         echo "Registered as changelog user $CL_USER"
12752
12753         OLD_INTERVAL=$(do_facet $SINGLEMDS \
12754                        lctl get_param -n mdt.*.job_cleanup_interval)
12755         local interval_new=5
12756         do_facet $SINGLEMDS \
12757                 $LCTL set_param mdt.*.job_cleanup_interval=$interval_new
12758         local start=$SECONDS
12759
12760         local cmd
12761         # mkdir
12762         cmd="mkdir $DIR/$tdir"
12763         verify_jobstats "$cmd" "$SINGLEMDS"
12764         # rmdir
12765         cmd="rmdir $DIR/$tdir"
12766         verify_jobstats "$cmd" "$SINGLEMDS"
12767         # mkdir on secondary MDT
12768         if [ $MDSCOUNT -gt 1 ]; then
12769                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
12770                 verify_jobstats "$cmd" "mds2"
12771         fi
12772         # mknod
12773         cmd="mknod $DIR/$tfile c 1 3"
12774         verify_jobstats "$cmd" "$SINGLEMDS"
12775         # unlink
12776         cmd="rm -f $DIR/$tfile"
12777         verify_jobstats "$cmd" "$SINGLEMDS"
12778         # create all files on OST0000 so verify_jobstats can find OST stats
12779         # open & close
12780         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
12781         verify_jobstats "$cmd" "$SINGLEMDS"
12782         # setattr
12783         cmd="touch $DIR/$tfile"
12784         verify_jobstats "$cmd" "$SINGLEMDS ost1"
12785         # write
12786         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
12787         verify_jobstats "$cmd" "ost1"
12788         # read
12789         cancel_lru_locks osc
12790         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
12791         verify_jobstats "$cmd" "ost1"
12792         # truncate
12793         cmd="$TRUNCATE $DIR/$tfile 0"
12794         verify_jobstats "$cmd" "$SINGLEMDS ost1"
12795         # rename
12796         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
12797         verify_jobstats "$cmd" "$SINGLEMDS"
12798         # jobstats expiry - sleep until old stats should be expired
12799         local left=$((interval_new + 5 - (SECONDS - start)))
12800         [ $left -ge 0 ] && wait_update_facet $SINGLEMDS \
12801                 "lctl get_param *.*.job_stats | grep -c 'job_id.*mkdir'" \
12802                         "0" $left
12803         cmd="mkdir $DIR/$tdir.expire"
12804         verify_jobstats "$cmd" "$SINGLEMDS"
12805         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
12806             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
12807
12808         # Ensure that jobid are present in changelog (if supported by MDS)
12809         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
12810         then
12811                 $LFS changelog $MDT0 | tail -9
12812                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
12813                 [ $jobids -eq 9 ] ||
12814                         error "Wrong changelog jobid count $jobids != 9"
12815
12816                 # LU-5862
12817                 JOBENV="disable"
12818                 jobstats_set $JOBENV
12819                 touch $DIR/$tfile
12820                 $LFS changelog $MDT0 | tail -1
12821                 jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
12822                 [ $jobids -eq 0 ] ||
12823                         error "Unexpected jobids when jobid_var=$JOBENV"
12824         fi
12825
12826         cleanup_205
12827 }
12828 run_test 205 "Verify job stats"
12829
12830 # LU-1480, LU-1773 and LU-1657
12831 test_206() {
12832         mkdir -p $DIR/$tdir
12833         $SETSTRIPE -c -1 $DIR/$tdir
12834 #define OBD_FAIL_LOV_INIT 0x1403
12835         $LCTL set_param fail_loc=0xa0001403
12836         $LCTL set_param fail_val=1
12837         touch $DIR/$tdir/$tfile || true
12838 }
12839 run_test 206 "fail lov_init_raid0() doesn't lbug"
12840
12841 test_207a() {
12842         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
12843         local fsz=`stat -c %s $DIR/$tfile`
12844         cancel_lru_locks mdc
12845
12846         # do not return layout in getattr intent
12847 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
12848         $LCTL set_param fail_loc=0x170
12849         local sz=`stat -c %s $DIR/$tfile`
12850
12851         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
12852
12853         rm -rf $DIR/$tfile
12854 }
12855 run_test 207a "can refresh layout at glimpse"
12856
12857 test_207b() {
12858         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
12859         local cksum=`md5sum $DIR/$tfile`
12860         local fsz=`stat -c %s $DIR/$tfile`
12861         cancel_lru_locks mdc
12862         cancel_lru_locks osc
12863
12864         # do not return layout in getattr intent
12865 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
12866         $LCTL set_param fail_loc=0x171
12867
12868         # it will refresh layout after the file is opened but before read issues
12869         echo checksum is "$cksum"
12870         echo "$cksum" |md5sum -c --quiet || error "file differs"
12871
12872         rm -rf $DIR/$tfile
12873 }
12874 run_test 207b "can refresh layout at open"
12875
12876 test_208() {
12877         # FIXME: in this test suite, only RD lease is used. This is okay
12878         # for now as only exclusive open is supported. After generic lease
12879         # is done, this test suite should be revised. - Jinshan
12880
12881         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12882         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
12883                 { skip "Need MDS version at least 2.4.52"; return 0; }
12884
12885         echo "==== test 1: verify get lease work"
12886         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
12887
12888         echo "==== test 2: verify lease can be broken by upcoming open"
12889         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
12890         local PID=$!
12891         sleep 1
12892
12893         $MULTIOP $DIR/$tfile oO_RDONLY:c
12894         kill -USR1 $PID && wait $PID || error "break lease error"
12895
12896         echo "==== test 3: verify lease can't be granted if an open already exists"
12897         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
12898         local PID=$!
12899         sleep 1
12900
12901         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
12902         kill -USR1 $PID && wait $PID || error "open file error"
12903
12904         echo "==== test 4: lease can sustain over recovery"
12905         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
12906         PID=$!
12907         sleep 1
12908
12909         fail mds1
12910
12911         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
12912
12913         echo "==== test 5: lease broken can't be regained by replay"
12914         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
12915         PID=$!
12916         sleep 1
12917
12918         # open file to break lease and then recovery
12919         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
12920         fail mds1
12921
12922         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
12923
12924         rm -f $DIR/$tfile
12925 }
12926 run_test 208 "Exclusive open"
12927
12928 test_209() {
12929         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
12930                 skip_env "must have disp_stripe" && return
12931
12932         touch $DIR/$tfile
12933         sync; sleep 5; sync;
12934
12935         echo 3 > /proc/sys/vm/drop_caches
12936         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
12937
12938         # open/close 500 times
12939         for i in $(seq 500); do
12940                 cat $DIR/$tfile
12941         done
12942
12943         echo 3 > /proc/sys/vm/drop_caches
12944         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
12945
12946         echo "before: $req_before, after: $req_after"
12947         [ $((req_after - req_before)) -ge 300 ] &&
12948                 error "open/close requests are not freed"
12949         return 0
12950 }
12951 run_test 209 "read-only open/close requests should be freed promptly"
12952
12953 test_212() {
12954         size=`date +%s`
12955         size=$((size % 8192 + 1))
12956         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
12957         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
12958         rm -f $DIR/f212 $DIR/f212.xyz
12959 }
12960 run_test 212 "Sendfile test ============================================"
12961
12962 test_213() {
12963         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
12964         cancel_lru_locks osc
12965         lctl set_param fail_loc=0x8000040f
12966         # generate a read lock
12967         cat $DIR/$tfile > /dev/null
12968         # write to the file, it will try to cancel the above read lock.
12969         cat /etc/hosts >> $DIR/$tfile
12970 }
12971 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
12972
12973 test_214() { # for bug 20133
12974         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
12975         for (( i=0; i < 340; i++ )) ; do
12976                 touch $DIR/$tdir/d214c/a$i
12977         done
12978
12979         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
12980         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
12981         ls $DIR/d214c || error "ls $DIR/d214c failed"
12982         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
12983         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
12984 }
12985 run_test 214 "hash-indexed directory test - bug 20133"
12986
12987 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
12988 create_lnet_proc_files() {
12989         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
12990         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
12991
12992         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
12993         rm -f "$TMP/lnet_$1.sys_tmp"
12994 }
12995
12996 # counterpart of create_lnet_proc_files
12997 remove_lnet_proc_files() {
12998         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
12999 }
13000
13001 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
13002 # 3rd arg as regexp for body
13003 check_lnet_proc_stats() {
13004         local l=$(cat "$TMP/lnet_$1" |wc -l)
13005         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
13006
13007         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
13008 }
13009
13010 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
13011 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
13012 # optional and can be regexp for 2nd line (lnet.routes case)
13013 check_lnet_proc_entry() {
13014         local blp=2          # blp stands for 'position of 1st line of body'
13015         [ -z "$5" ] || blp=3 # lnet.routes case
13016
13017         local l=$(cat "$TMP/lnet_$1" |wc -l)
13018         # subtracting one from $blp because the body can be empty
13019         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
13020
13021         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
13022                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
13023
13024         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
13025                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
13026
13027         # bail out if any unexpected line happened
13028         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
13029         [ "$?" != 0 ] || error "$2 misformatted"
13030 }
13031
13032 test_215() { # for bugs 18102, 21079, 21517
13033         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13034         local N='(0|[1-9][0-9]*)'       # non-negative numeric
13035         local P='[1-9][0-9]*'           # positive numeric
13036         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
13037         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
13038         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
13039         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
13040
13041         local L1 # regexp for 1st line
13042         local L2 # regexp for 2nd line (optional)
13043         local BR # regexp for the rest (body)
13044
13045         # lnet.stats should look as 11 space-separated non-negative numerics
13046         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
13047         create_lnet_proc_files "stats"
13048         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
13049         remove_lnet_proc_files "stats"
13050
13051         # lnet.routes should look like this:
13052         # Routing disabled/enabled
13053         # net hops priority state router
13054         # where net is a string like tcp0, hops > 0, priority >= 0,
13055         # state is up/down,
13056         # router is a string like 192.168.1.1@tcp2
13057         L1="^Routing (disabled|enabled)$"
13058         L2="^net +hops +priority +state +router$"
13059         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
13060         create_lnet_proc_files "routes"
13061         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
13062         remove_lnet_proc_files "routes"
13063
13064         # lnet.routers should look like this:
13065         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
13066         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
13067         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
13068         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
13069         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
13070         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
13071         create_lnet_proc_files "routers"
13072         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
13073         remove_lnet_proc_files "routers"
13074
13075         # lnet.peers should look like this:
13076         # nid refs state last max rtr min tx min queue
13077         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
13078         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
13079         # numeric (0 or >0 or <0), queue >= 0.
13080         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
13081         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
13082         create_lnet_proc_files "peers"
13083         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
13084         remove_lnet_proc_files "peers"
13085
13086         # lnet.buffers  should look like this:
13087         # pages count credits min
13088         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
13089         L1="^pages +count +credits +min$"
13090         BR="^ +$N +$N +$I +$I$"
13091         create_lnet_proc_files "buffers"
13092         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
13093         remove_lnet_proc_files "buffers"
13094
13095         # lnet.nis should look like this:
13096         # nid status alive refs peer rtr max tx min
13097         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
13098         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
13099         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
13100         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
13101         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
13102         create_lnet_proc_files "nis"
13103         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
13104         remove_lnet_proc_files "nis"
13105
13106         # can we successfully write to lnet.stats?
13107         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
13108         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
13109 }
13110 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
13111
13112 test_216() { # bug 20317
13113         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13114         remote_ost_nodsh && skip "remote OST with nodsh" && return
13115
13116         local node
13117         local facets=$(get_facets OST)
13118         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13119
13120         save_lustre_params client "osc.*.contention_seconds" > $p
13121         save_lustre_params $facets \
13122                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
13123         save_lustre_params $facets \
13124                 "ldlm.namespaces.filter-*.contended_locks" >> $p
13125         save_lustre_params $facets \
13126                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
13127         clear_stats osc.*.osc_stats
13128
13129         # agressive lockless i/o settings
13130         do_nodes $(comma_list $(osts_nodes)) \
13131                 "lctl set_param -n ldlm.namespaces.*.max_nolock_bytes=2000000 \
13132                         ldlm.namespaces.filter-*.contended_locks=0 \
13133                         ldlm.namespaces.filter-*.contention_seconds=60"
13134         lctl set_param -n osc.*.contention_seconds=60
13135
13136         $DIRECTIO write $DIR/$tfile 0 10 4096
13137         $CHECKSTAT -s 40960 $DIR/$tfile
13138
13139         # disable lockless i/o
13140         do_nodes $(comma_list $(osts_nodes)) \
13141                 "lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes=0 \
13142                         ldlm.namespaces.filter-*.contended_locks=32 \
13143                         ldlm.namespaces.filter-*.contention_seconds=0"
13144         lctl set_param -n osc.*.contention_seconds=0
13145         clear_stats osc.*.osc_stats
13146
13147         dd if=/dev/zero of=$DIR/$tfile count=0
13148         $CHECKSTAT -s 0 $DIR/$tfile
13149
13150         restore_lustre_params <$p
13151         rm -f $p
13152         rm $DIR/$tfile
13153 }
13154 run_test 216 "check lockless direct write updates file size and kms correctly"
13155
13156 test_217() { # bug 22430
13157         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13158         local node
13159         local nid
13160
13161         for node in $(nodes_list); do
13162                 nid=$(host_nids_address $node $NETTYPE)
13163                 if [[ $nid = *-* ]] ; then
13164                         echo "lctl ping $(h2nettype $nid)"
13165                         lctl ping $(h2nettype $nid)
13166                 else
13167                         echo "skipping $node (no hyphen detected)"
13168                 fi
13169         done
13170 }
13171 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
13172
13173 test_218() {
13174        # do directio so as not to populate the page cache
13175        log "creating a 10 Mb file"
13176        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
13177        log "starting reads"
13178        dd if=$DIR/$tfile of=/dev/null bs=4096 &
13179        log "truncating the file"
13180        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
13181        log "killing dd"
13182        kill %+ || true # reads might have finished
13183        echo "wait until dd is finished"
13184        wait
13185        log "removing the temporary file"
13186        rm -rf $DIR/$tfile || error "tmp file removal failed"
13187 }
13188 run_test 218 "parallel read and truncate should not deadlock ======================="
13189
13190 test_219() {
13191         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13192         # write one partial page
13193         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
13194         # set no grant so vvp_io_commit_write will do sync write
13195         $LCTL set_param fail_loc=0x411
13196         # write a full page at the end of file
13197         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
13198
13199         $LCTL set_param fail_loc=0
13200         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
13201         $LCTL set_param fail_loc=0x411
13202         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
13203
13204         # LU-4201
13205         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
13206         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
13207 }
13208 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
13209
13210 test_220() { #LU-325
13211         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13212         remote_ost_nodsh && skip "remote OST with nodsh" && return
13213         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13214         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
13215         local OSTIDX=0
13216
13217         # create on MDT0000 so the last_id and next_id are correct
13218         mkdir $DIR/$tdir
13219         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
13220         OST=${OST%_UUID}
13221
13222         # on the mdt's osc
13223         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
13224         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
13225                         osc.$mdtosc_proc1.prealloc_last_id)
13226         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
13227                         osc.$mdtosc_proc1.prealloc_next_id)
13228
13229         $LFS df -i
13230
13231         if ! combined_mgs_mds ; then
13232                 mount_mgs_client
13233         fi
13234
13235         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
13236         #define OBD_FAIL_OST_ENOINO              0x229
13237         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
13238         create_pool $FSNAME.$TESTNAME || return 1
13239         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
13240
13241         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
13242
13243         MDSOBJS=$((last_id - next_id))
13244         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
13245
13246         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
13247         echo "OST still has $count kbytes free"
13248
13249         echo "create $MDSOBJS files @next_id..."
13250         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
13251
13252         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
13253                         osc.$mdtosc_proc1.prealloc_last_id)
13254         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
13255                         osc.$mdtosc_proc1.prealloc_next_id)
13256
13257         echo "after creation, last_id=$last_id2, next_id=$next_id2"
13258         $LFS df -i
13259
13260         echo "cleanup..."
13261
13262         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
13263         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
13264
13265         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST ||
13266                 error "$LCTL pool_remove $FSNAME.$TESTNAME $OST failed"
13267         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
13268                 error "$LCTL pool_destroy $FSNAME.$TESTNAME failed"
13269         echo "unlink $MDSOBJS files @$next_id..."
13270         unlinkmany $DIR/$tdir/f $MDSOBJS || error "unlinkmany failed"
13271
13272         if ! combined_mgs_mds ; then
13273                 umount_mgs_client
13274         fi
13275 }
13276 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
13277
13278 test_221() {
13279         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13280         dd if=`which date` of=$MOUNT/date oflag=sync
13281         chmod +x $MOUNT/date
13282
13283         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
13284         $LCTL set_param fail_loc=0x80001401
13285
13286         $MOUNT/date > /dev/null
13287         rm -f $MOUNT/date
13288 }
13289 run_test 221 "make sure fault and truncate race to not cause OOM"
13290
13291 test_222a () {
13292         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13293        rm -rf $DIR/$tdir
13294        test_mkdir -p $DIR/$tdir
13295        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
13296        createmany -o $DIR/$tdir/$tfile 10
13297        cancel_lru_locks mdc
13298        cancel_lru_locks osc
13299        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
13300        $LCTL set_param fail_loc=0x31a
13301        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
13302        $LCTL set_param fail_loc=0
13303        rm -r $DIR/$tdir
13304 }
13305 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
13306
13307 test_222b () {
13308         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13309         rm -rf $DIR/$tdir
13310         test_mkdir -p $DIR/$tdir
13311         $SETSTRIPE -c 1 -i 0 $DIR/$tdir
13312         createmany -o $DIR/$tdir/$tfile 10
13313         cancel_lru_locks mdc
13314         cancel_lru_locks osc
13315         #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
13316         $LCTL set_param fail_loc=0x31a
13317         rm -r $DIR/$tdir || error "AGL for rmdir failed"
13318         $LCTL set_param fail_loc=0
13319 }
13320 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
13321
13322 test_223 () {
13323         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13324        rm -rf $DIR/$tdir
13325        test_mkdir -p $DIR/$tdir
13326        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
13327        createmany -o $DIR/$tdir/$tfile 10
13328        cancel_lru_locks mdc
13329        cancel_lru_locks osc
13330        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
13331        $LCTL set_param fail_loc=0x31b
13332        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
13333        $LCTL set_param fail_loc=0
13334        rm -r $DIR/$tdir
13335 }
13336 run_test 223 "osc reenqueue if without AGL lock granted ======================="
13337
13338 test_224a() { # LU-1039, MRP-303
13339         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13340         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
13341         $LCTL set_param fail_loc=0x508
13342         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
13343         $LCTL set_param fail_loc=0
13344         df $DIR
13345 }
13346 run_test 224a "Don't panic on bulk IO failure"
13347
13348 test_224b() { # LU-1039, MRP-303
13349         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13350         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
13351         cancel_lru_locks osc
13352         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
13353         $LCTL set_param fail_loc=0x515
13354         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
13355         $LCTL set_param fail_loc=0
13356         df $DIR
13357 }
13358 run_test 224b "Don't panic on bulk IO failure"
13359
13360 test_224c() { # LU-6441
13361         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13362         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13363
13364         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
13365         save_writethrough $p
13366         set_cache writethrough on
13367
13368         local pages_per_rpc=$($LCTL get_param \
13369                                 osc.*.max_pages_per_rpc)
13370         local at_max=$($LCTL get_param -n at_max)
13371         local timeout=$($LCTL get_param -n timeout)
13372         local test_at="$LCTL get_param -n at_max"
13373         local param_at="$FSNAME.sys.at_max"
13374         local test_timeout="$LCTL get_param -n timeout"
13375         local param_timeout="$FSNAME.sys.timeout"
13376
13377         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
13378
13379         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
13380                 error "conf_param at_max=0 failed"
13381         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
13382                 error "conf_param timeout=5 failed"
13383
13384         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
13385         do_facet ost1 $LCTL set_param fail_loc=0x520
13386         $LFS setstripe -c 1 -i 0 $DIR/$tfile
13387         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
13388         sync
13389         do_facet ost1 $LCTL set_param fail_loc=0
13390
13391         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
13392                 error "conf_param at_max=$at_max failed"
13393         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
13394                 $timeout || error "conf_param timeout=$timeout failed"
13395
13396         $LCTL set_param -n $pages_per_rpc
13397         restore_lustre_params < $p
13398         rm -f $p
13399 }
13400 run_test 224c "Don't hang if one of md lost during large bulk RPC"
13401
13402 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
13403 test_225a () {
13404         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13405         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13406         if [ -z ${MDSSURVEY} ]; then
13407               skip_env "mds-survey not found" && return
13408         fi
13409
13410         [ $MDSCOUNT -ge 2 ] &&
13411                 skip "skipping now for more than one MDT" && return
13412
13413        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
13414             { skip "Need MDS version at least 2.2.51"; return; }
13415
13416        local mds=$(facet_host $SINGLEMDS)
13417        local target=$(do_nodes $mds 'lctl dl' | \
13418                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
13419
13420        local cmd1="file_count=1000 thrhi=4"
13421        local cmd2="dir_count=2 layer=mdd stripe_count=0"
13422        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
13423        local cmd="$cmd1 $cmd2 $cmd3"
13424
13425        rm -f ${TMP}/mds_survey*
13426        echo + $cmd
13427        eval $cmd || error "mds-survey with zero-stripe failed"
13428        cat ${TMP}/mds_survey*
13429        rm -f ${TMP}/mds_survey*
13430 }
13431 run_test 225a "Metadata survey sanity with zero-stripe"
13432
13433 test_225b () {
13434         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13435         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13436         if [ -z ${MDSSURVEY} ]; then
13437               skip_env "mds-survey not found" && return
13438         fi
13439         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
13440             { skip "Need MDS version at least 2.2.51"; return; }
13441
13442         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
13443               skip_env "Need to mount OST to test" && return
13444         fi
13445
13446        local mds=$(facet_host $SINGLEMDS)
13447        local target=$(do_nodes $mds 'lctl dl' | \
13448                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
13449
13450        local cmd1="file_count=1000 thrhi=4"
13451        local cmd2="dir_count=2 layer=mdd stripe_count=1"
13452        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
13453        local cmd="$cmd1 $cmd2 $cmd3"
13454
13455        rm -f ${TMP}/mds_survey*
13456        echo + $cmd
13457        eval $cmd || error "mds-survey with stripe_count failed"
13458        cat ${TMP}/mds_survey*
13459        rm -f ${TMP}/mds_survey*
13460 }
13461 run_test 225b "Metadata survey sanity with stripe_count = 1"
13462
13463 mcreate_path2fid () {
13464         local mode=$1
13465         local major=$2
13466         local minor=$3
13467         local name=$4
13468         local desc=$5
13469         local path=$DIR/$tdir/$name
13470         local fid
13471         local rc
13472         local fid_path
13473
13474         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
13475                 error "cannot create $desc"
13476
13477         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
13478         rc=$?
13479         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
13480
13481         fid_path=$($LFS fid2path $MOUNT $fid)
13482         rc=$?
13483         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
13484
13485         [ "$path" == "$fid_path" ] ||
13486                 error "fid2path returned $fid_path, expected $path"
13487
13488         echo "pass with $path and $fid"
13489 }
13490
13491 test_226a () {
13492         rm -rf $DIR/$tdir
13493         mkdir -p $DIR/$tdir
13494
13495         mcreate_path2fid 0010666 0 0 fifo "FIFO"
13496         mcreate_path2fid 0020666 1 3 null "character special file (null)"
13497         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
13498         mcreate_path2fid 0040666 0 0 dir "directory"
13499         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
13500         mcreate_path2fid 0100666 0 0 file "regular file"
13501         mcreate_path2fid 0120666 0 0 link "symbolic link"
13502         mcreate_path2fid 0140666 0 0 sock "socket"
13503 }
13504 run_test 226a "call path2fid and fid2path on files of all type"
13505
13506 test_226b () {
13507         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13508         rm -rf $DIR/$tdir
13509         local MDTIDX=1
13510
13511         mkdir -p $DIR/$tdir
13512         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
13513                 error "create remote directory failed"
13514         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
13515         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
13516                                 "character special file (null)"
13517         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
13518                                 "character special file (no device)"
13519         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
13520         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
13521                                 "block special file (loop)"
13522         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
13523         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
13524         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
13525 }
13526 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
13527
13528 # LU-1299 Executing or running ldd on a truncated executable does not
13529 # cause an out-of-memory condition.
13530 test_227() {
13531         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13532         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
13533         dd if=$(which date) of=$MOUNT/date bs=1k count=1
13534         chmod +x $MOUNT/date
13535
13536         $MOUNT/date > /dev/null
13537         ldd $MOUNT/date > /dev/null
13538         rm -f $MOUNT/date
13539 }
13540 run_test 227 "running truncated executable does not cause OOM"
13541
13542 # LU-1512 try to reuse idle OI blocks
13543 test_228a() {
13544         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13545         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13546         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13547                 skip "ldiskfs only test" && return
13548
13549         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13550         local myDIR=$DIR/$tdir
13551
13552         mkdir -p $myDIR
13553         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13554         $LCTL set_param fail_loc=0x80001002
13555         createmany -o $myDIR/t- 10000
13556         $LCTL set_param fail_loc=0
13557         # The guard is current the largest FID holder
13558         touch $myDIR/guard
13559         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13560                     tr -d '[')
13561         local IDX=$(($SEQ % 64))
13562
13563         do_facet $SINGLEMDS sync
13564         # Make sure journal flushed.
13565         sleep 6
13566         local blk1=$(do_facet $SINGLEMDS \
13567                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13568                      grep Blockcount | awk '{print $4}')
13569
13570         # Remove old files, some OI blocks will become idle.
13571         unlinkmany $myDIR/t- 10000
13572         # Create new files, idle OI blocks should be reused.
13573         createmany -o $myDIR/t- 2000
13574         do_facet $SINGLEMDS sync
13575         # Make sure journal flushed.
13576         sleep 6
13577         local blk2=$(do_facet $SINGLEMDS \
13578                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13579                      grep Blockcount | awk '{print $4}')
13580
13581         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13582 }
13583 run_test 228a "try to reuse idle OI blocks"
13584
13585 test_228b() {
13586         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13587         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13588         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13589                 skip "ldiskfs only test" && return
13590
13591         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13592         local myDIR=$DIR/$tdir
13593
13594         mkdir -p $myDIR
13595         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13596         $LCTL set_param fail_loc=0x80001002
13597         createmany -o $myDIR/t- 10000
13598         $LCTL set_param fail_loc=0
13599         # The guard is current the largest FID holder
13600         touch $myDIR/guard
13601         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13602                     tr -d '[')
13603         local IDX=$(($SEQ % 64))
13604
13605         do_facet $SINGLEMDS sync
13606         # Make sure journal flushed.
13607         sleep 6
13608         local blk1=$(do_facet $SINGLEMDS \
13609                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13610                      grep Blockcount | awk '{print $4}')
13611
13612         # Remove old files, some OI blocks will become idle.
13613         unlinkmany $myDIR/t- 10000
13614
13615         # stop the MDT
13616         stop $SINGLEMDS || error "Fail to stop MDT."
13617         # remount the MDT
13618         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
13619
13620         df $MOUNT || error "Fail to df."
13621         # Create new files, idle OI blocks should be reused.
13622         createmany -o $myDIR/t- 2000
13623         do_facet $SINGLEMDS sync
13624         # Make sure journal flushed.
13625         sleep 6
13626         local blk2=$(do_facet $SINGLEMDS \
13627                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13628                      grep Blockcount | awk '{print $4}')
13629
13630         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13631 }
13632 run_test 228b "idle OI blocks can be reused after MDT restart"
13633
13634 #LU-1881
13635 test_228c() {
13636         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13637         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13638         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
13639                 skip "ldiskfs only test" && return
13640
13641         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
13642         local myDIR=$DIR/$tdir
13643
13644         mkdir -p $myDIR
13645         #define OBD_FAIL_SEQ_EXHAUST             0x1002
13646         $LCTL set_param fail_loc=0x80001002
13647         # 20000 files can guarantee there are index nodes in the OI file
13648         createmany -o $myDIR/t- 20000
13649         $LCTL set_param fail_loc=0
13650         # The guard is current the largest FID holder
13651         touch $myDIR/guard
13652         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
13653                     tr -d '[')
13654         local IDX=$(($SEQ % 64))
13655
13656         do_facet $SINGLEMDS sync
13657         # Make sure journal flushed.
13658         sleep 6
13659         local blk1=$(do_facet $SINGLEMDS \
13660                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13661                      grep Blockcount | awk '{print $4}')
13662
13663         # Remove old files, some OI blocks will become idle.
13664         unlinkmany $myDIR/t- 20000
13665         rm -f $myDIR/guard
13666         # The OI file should become empty now
13667
13668         # Create new files, idle OI blocks should be reused.
13669         createmany -o $myDIR/t- 2000
13670         do_facet $SINGLEMDS sync
13671         # Make sure journal flushed.
13672         sleep 6
13673         local blk2=$(do_facet $SINGLEMDS \
13674                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
13675                      grep Blockcount | awk '{print $4}')
13676
13677         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
13678 }
13679 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
13680
13681 test_229() { # LU-2482, LU-3448
13682         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
13683                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
13684                 return
13685         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13686         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
13687
13688         rm -f $DIR/$tfile
13689
13690         # Create a file with a released layout and stripe count 2.
13691         $MULTIOP $DIR/$tfile H2c ||
13692                 error "failed to create file with released layout"
13693
13694         $GETSTRIPE -v $DIR/$tfile
13695
13696         local pattern=$($GETSTRIPE -L $DIR/$tfile)
13697         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
13698
13699         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
13700         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
13701         stat $DIR/$tfile || error "failed to stat released file"
13702
13703         chown $RUNAS_ID $DIR/$tfile ||
13704                 error "chown $RUNAS_ID $DIR/$tfile failed"
13705
13706         chgrp $RUNAS_ID $DIR/$tfile ||
13707                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
13708
13709         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
13710         rm $DIR/$tfile || error "failed to remove released file"
13711 }
13712 run_test 229 "getstripe/stat/rm/attr changes work on released files"
13713
13714 test_230a() {
13715         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13716         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13717         local MDTIDX=1
13718
13719         test_mkdir $DIR/$tdir
13720         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
13721         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
13722         [ $mdt_idx -ne 0 ] &&
13723                 error "create local directory on wrong MDT $mdt_idx"
13724
13725         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
13726                         error "create remote directory failed"
13727         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
13728         [ $mdt_idx -ne $MDTIDX ] &&
13729                 error "create remote directory on wrong MDT $mdt_idx"
13730
13731         createmany -o $DIR/$tdir/test_230/t- 10 ||
13732                 error "create files on remote directory failed"
13733         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
13734         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
13735         rm -r $DIR/$tdir || error "unlink remote directory failed"
13736 }
13737 run_test 230a "Create remote directory and files under the remote directory"
13738
13739 test_230b() {
13740         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13741         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13742         local MDTIDX=1
13743         local mdt_index
13744         local i
13745         local file
13746         local pid
13747         local stripe_count
13748         local migrate_dir=$DIR/$tdir/migrate_dir
13749         local other_dir=$DIR/$tdir/other_dir
13750
13751         test_mkdir $DIR/$tdir
13752         test_mkdir -i0 -c1 $migrate_dir
13753         test_mkdir -i0 -c1 $other_dir
13754         for ((i=0; i<10; i++)); do
13755                 mkdir -p $migrate_dir/dir_${i}
13756                 createmany -o $migrate_dir/dir_${i}/f 10 ||
13757                         error "create files under remote dir failed $i"
13758         done
13759
13760         cp /etc/passwd $migrate_dir/$tfile
13761         cp /etc/passwd $other_dir/$tfile
13762         chattr +SAD $migrate_dir
13763         chattr +SAD $migrate_dir/$tfile
13764
13765         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13766         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13767         local old_dir_mode=$(stat -c%f $migrate_dir)
13768         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
13769
13770         mkdir -p $migrate_dir/dir_default_stripe2
13771         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
13772         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
13773
13774         mkdir -p $other_dir
13775         ln $migrate_dir/$tfile $other_dir/luna
13776         ln $migrate_dir/$tfile $migrate_dir/sofia
13777         ln $other_dir/$tfile $migrate_dir/david
13778         ln -s $migrate_dir/$tfile $other_dir/zachary
13779         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
13780         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
13781
13782         $LFS migrate -m $MDTIDX $migrate_dir ||
13783                 error "fails on migrating remote dir to MDT1"
13784
13785         echo "migratate to MDT1, then checking.."
13786         for ((i = 0; i < 10; i++)); do
13787                 for file in $(find $migrate_dir/dir_${i}); do
13788                         mdt_index=$($LFS getstripe -M $file)
13789                         [ $mdt_index == $MDTIDX ] ||
13790                                 error "$file is not on MDT${MDTIDX}"
13791                 done
13792         done
13793
13794         # the multiple link file should still in MDT0
13795         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
13796         [ $mdt_index == 0 ] ||
13797                 error "$file is not on MDT${MDTIDX}"
13798
13799         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13800         [ "$old_dir_flag" = "$new_dir_flag" ] ||
13801                 error " expect $old_dir_flag get $new_dir_flag"
13802
13803         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13804         [ "$old_file_flag" = "$new_file_flag" ] ||
13805                 error " expect $old_file_flag get $new_file_flag"
13806
13807         local new_dir_mode=$(stat -c%f $migrate_dir)
13808         [ "$old_dir_mode" = "$new_dir_mode" ] ||
13809                 error "expect mode $old_dir_mode get $new_dir_mode"
13810
13811         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
13812         [ "$old_file_mode" = "$new_file_mode" ] ||
13813                 error "expect mode $old_file_mode get $new_file_mode"
13814
13815         diff /etc/passwd $migrate_dir/$tfile ||
13816                 error "$tfile different after migration"
13817
13818         diff /etc/passwd $other_dir/luna ||
13819                 error "luna different after migration"
13820
13821         diff /etc/passwd $migrate_dir/sofia ||
13822                 error "sofia different after migration"
13823
13824         diff /etc/passwd $migrate_dir/david ||
13825                 error "david different after migration"
13826
13827         diff /etc/passwd $other_dir/zachary ||
13828                 error "zachary different after migration"
13829
13830         diff /etc/passwd $migrate_dir/${tfile}_ln ||
13831                 error "${tfile}_ln different after migration"
13832
13833         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
13834                 error "${tfile}_ln_other different after migration"
13835
13836         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
13837         [ $stripe_count = 2 ] ||
13838                 error "dir strpe_count $d != 2 after migration."
13839
13840         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
13841         [ $stripe_count = 2 ] ||
13842                 error "file strpe_count $d != 2 after migration."
13843
13844         #migrate back to MDT0
13845         MDTIDX=0
13846
13847         $LFS migrate -m $MDTIDX $migrate_dir ||
13848                 error "fails on migrating remote dir to MDT0"
13849
13850         echo "migrate back to MDT0, checking.."
13851         for file in $(find $migrate_dir); do
13852                 mdt_index=$($LFS getstripe -M $file)
13853                 [ $mdt_index == $MDTIDX ] ||
13854                         error "$file is not on MDT${MDTIDX}"
13855         done
13856
13857         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
13858         [ "$old_dir_flag" = "$new_dir_flag" ] ||
13859                 error " expect $old_dir_flag get $new_dir_flag"
13860
13861         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
13862         [ "$old_file_flag" = "$new_file_flag" ] ||
13863                 error " expect $old_file_flag get $new_file_flag"
13864
13865         local new_dir_mode=$(stat -c%f $migrate_dir)
13866         [ "$old_dir_mode" = "$new_dir_mode" ] ||
13867                 error "expect mode $old_dir_mode get $new_dir_mode"
13868
13869         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
13870         [ "$old_file_mode" = "$new_file_mode" ] ||
13871                 error "expect mode $old_file_mode get $new_file_mode"
13872
13873         diff /etc/passwd ${migrate_dir}/$tfile ||
13874                 error "$tfile different after migration"
13875
13876         diff /etc/passwd ${other_dir}/luna ||
13877                 error "luna different after migration"
13878
13879         diff /etc/passwd ${migrate_dir}/sofia ||
13880                 error "sofia different after migration"
13881
13882         diff /etc/passwd ${other_dir}/zachary ||
13883                 error "zachary different after migration"
13884
13885         diff /etc/passwd $migrate_dir/${tfile}_ln ||
13886                 error "${tfile}_ln different after migration"
13887
13888         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
13889                 error "${tfile}_ln_other different after migration"
13890
13891         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
13892         [ $stripe_count = 2 ] ||
13893                 error "dir strpe_count $d != 2 after migration."
13894
13895         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
13896         [ $stripe_count = 2 ] ||
13897                 error "file strpe_count $d != 2 after migration."
13898
13899         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13900 }
13901 run_test 230b "migrate directory"
13902
13903 test_230c() {
13904         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13905         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13906         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13907         local MDTIDX=1
13908         local mdt_index
13909         local file
13910         local migrate_dir=$DIR/$tdir/migrate_dir
13911
13912         #If migrating directory fails in the middle, all entries of
13913         #the directory is still accessiable.
13914         test_mkdir $DIR/$tdir
13915         test_mkdir -i0 -c1 $migrate_dir
13916         stat $migrate_dir
13917         createmany -o $migrate_dir/f 10 ||
13918                 error "create files under ${migrate_dir} failed"
13919
13920         #failed after migrating 5 entries
13921         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
13922         do_facet mds1 lctl set_param fail_loc=0x20001801
13923         do_facet mds1 lctl  set_param fail_val=5
13924         local t=$(ls $migrate_dir | wc -l)
13925         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
13926                 error "migrate should fail after 5 entries"
13927
13928         mkdir $migrate_dir/dir &&
13929                 error "mkdir succeeds under migrating directory"
13930         touch $migrate_dir/file &&
13931                 error "touch file succeeds under migrating directory"
13932
13933         local u=$(ls $migrate_dir | wc -l)
13934         [ "$u" == "$t" ] || error "$u != $t during migration"
13935
13936         for file in $(find $migrate_dir); do
13937                 stat $file || error "stat $file failed"
13938         done
13939
13940         do_facet mds1 lctl set_param fail_loc=0
13941         do_facet mds1 lctl set_param fail_val=0
13942
13943         $LFS migrate -m $MDTIDX $migrate_dir ||
13944                 error "migrate open files should failed with open files"
13945
13946         echo "Finish migration, then checking.."
13947         for file in $(find $migrate_dir); do
13948                 mdt_index=$($LFS getstripe -M $file)
13949                 [ $mdt_index == $MDTIDX ] ||
13950                         error "$file is not on MDT${MDTIDX}"
13951         done
13952
13953         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13954 }
13955 run_test 230c "check directory accessiblity if migration is failed"
13956
13957 test_230d() {
13958         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13959         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13960         local MDTIDX=1
13961         local mdt_index
13962         local migrate_dir=$DIR/$tdir/migrate_dir
13963         local i
13964         local j
13965
13966         test_mkdir $DIR/$tdir
13967         test_mkdir -i0 -c1 $migrate_dir
13968
13969         for ((i=0; i<100; i++)); do
13970                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
13971                 createmany -o $migrate_dir/dir_${i}/f 100 ||
13972                         error "create files under remote dir failed $i"
13973         done
13974
13975         $LFS migrate -m $MDTIDX $migrate_dir ||
13976                 error "migrate remote dir error"
13977
13978         echo "Finish migration, then checking.."
13979         for file in $(find $migrate_dir); do
13980                 mdt_index=$($LFS getstripe -M $file)
13981                 [ $mdt_index == $MDTIDX ] ||
13982                         error "$file is not on MDT${MDTIDX}"
13983         done
13984
13985         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13986 }
13987 run_test 230d "check migrate big directory"
13988
13989 test_230e() {
13990         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13991         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13992         local i
13993         local j
13994         local a_fid
13995         local b_fid
13996
13997         mkdir -p $DIR/$tdir
13998         mkdir $DIR/$tdir/migrate_dir
13999         mkdir $DIR/$tdir/other_dir
14000         touch $DIR/$tdir/migrate_dir/a
14001         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
14002         ls $DIR/$tdir/other_dir
14003
14004         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
14005                 error "migrate dir fails"
14006
14007         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
14008         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
14009
14010         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
14011         [ $mdt_index == 0 ] || error "a is not on MDT0"
14012
14013         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
14014                 error "migrate dir fails"
14015
14016         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir)
14017         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
14018
14019         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
14020         [ $mdt_index == 1 ] || error "a is not on MDT1"
14021
14022         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir/b)
14023         [ $mdt_index == 1 ] || error "b is not on MDT1"
14024
14025         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
14026         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
14027
14028         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
14029
14030         rm -rf $DIR/$tdir || error "rm dir failed after migration"
14031 }
14032 run_test 230e "migrate mulitple local link files"
14033
14034 test_230f() {
14035         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14036         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14037         local a_fid
14038         local ln_fid
14039
14040         mkdir -p $DIR/$tdir
14041         mkdir $DIR/$tdir/migrate_dir
14042         $LFS mkdir -i1 $DIR/$tdir/other_dir
14043         touch $DIR/$tdir/migrate_dir/a
14044         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
14045         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
14046         ls $DIR/$tdir/other_dir
14047
14048         # a should be migrated to MDT1, since no other links on MDT0
14049         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
14050                 error "#1 migrate dir fails"
14051         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
14052         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
14053         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
14054         [ $mdt_index == 1 ] || error "a is not on MDT1"
14055
14056         # a should stay on MDT1, because it is a mulitple link file
14057         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
14058                 error "#2 migrate dir fails"
14059         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
14060         [ $mdt_index == 1 ] || error "a is not on MDT1"
14061
14062         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
14063                 error "#3 migrate dir fails"
14064
14065         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
14066         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
14067         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
14068
14069         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
14070         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
14071
14072         # a should be migrated to MDT0, since no other links on MDT1
14073         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
14074                 error "#4 migrate dir fails"
14075         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
14076         [ $mdt_index == 0 ] || error "a is not on MDT0"
14077
14078         rm -rf $DIR/$tdir || error "rm dir failed after migration"
14079 }
14080 run_test 230f "migrate mulitple remote link files"
14081
14082 test_230g() {
14083         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14084         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14085
14086         mkdir -p $DIR/$tdir/migrate_dir
14087
14088         $LFS migrate -m 1000 $DIR/$tdir/migrate_dir &&
14089                 error "migrating dir to non-exist MDT succeeds"
14090         true
14091 }
14092 run_test 230g "migrate dir to non-exist MDT"
14093
14094 test_230h() {
14095         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14096         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14097         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
14098                 skip "Need MDS version at least 2.7.64" && return
14099         local mdt_index
14100
14101         mkdir -p $DIR/$tdir/migrate_dir
14102
14103         $LFS migrate -m1 $DIR &&
14104                 error "migrating mountpoint1 should fail"
14105
14106         $LFS migrate -m1 $DIR/$tdir/.. &&
14107                 error "migrating mountpoint2 should fail"
14108
14109         $LFS migrate -m1 $DIR/$tdir/migrate_dir/.. ||
14110                 error "migrating $tdir fail"
14111
14112         mdt_index=$($LFS getstripe -M $DIR/$tdir)
14113         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
14114
14115         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
14116         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
14117
14118 }
14119 run_test 230h "migrate .. and root"
14120
14121 test_230i() {
14122         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14123         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14124
14125         mkdir -p $DIR/$tdir/migrate_dir
14126
14127         $LFS migrate -m 1 $DIR/$tdir/migrate_dir/ ||
14128                 error "migration fails with a tailing slash"
14129
14130         $LFS migrate -m 0 $DIR/$tdir/migrate_dir// ||
14131                 error "migration fails with two tailing slashes"
14132 }
14133 run_test 230i "lfs migrate -m tolerates trailing slashes"
14134
14135 test_231a()
14136 {
14137         # For simplicity this test assumes that max_pages_per_rpc
14138         # is the same across all OSCs
14139         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
14140         local bulk_size=$((max_pages * 4096))
14141         local brw_size=$(do_facet ost1 $LCTL get_param -n obdfilter.*.brw_size |
14142                                        head -n 1)
14143
14144         mkdir -p $DIR/$tdir
14145         $LFS setstripe -S ${brw_size}M $DIR/$tdir ||
14146                 error "failed to set stripe with -S ${brw_size}M option"
14147
14148         # clear the OSC stats
14149         $LCTL set_param osc.*.stats=0 &>/dev/null
14150         stop_writeback
14151
14152         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
14153         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
14154                 oflag=direct &>/dev/null || error "dd failed"
14155
14156         sync; sleep 1; sync # just to be safe
14157         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
14158         if [ x$nrpcs != "x1" ]; then
14159                 $LCTL get_param osc.*.stats
14160                 error "found $nrpcs ost_write RPCs, not 1 as expected"
14161         fi
14162
14163         start_writeback
14164         # Drop the OSC cache, otherwise we will read from it
14165         cancel_lru_locks osc
14166
14167         # clear the OSC stats
14168         $LCTL set_param osc.*.stats=0 &>/dev/null
14169
14170         # Client reads $bulk_size.
14171         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
14172                 iflag=direct &>/dev/null || error "dd failed"
14173
14174         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
14175         if [ x$nrpcs != "x1" ]; then
14176                 $LCTL get_param osc.*.stats
14177                 error "found $nrpcs ost_read RPCs, not 1 as expected"
14178         fi
14179 }
14180 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
14181
14182 test_231b() {
14183         mkdir -p $DIR/$tdir
14184         local i
14185         for i in {0..1023}; do
14186                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
14187                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
14188                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
14189         done
14190         sync
14191 }
14192 run_test 231b "must not assert on fully utilized OST request buffer"
14193
14194 test_232() {
14195         mkdir -p $DIR/$tdir
14196         #define OBD_FAIL_LDLM_OST_LVB            0x31c
14197         $LCTL set_param fail_loc=0x31c
14198
14199         # ignore dd failure
14200         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
14201
14202         $LCTL set_param fail_loc=0
14203         umount_client $MOUNT || error "umount failed"
14204         mount_client $MOUNT || error "mount failed"
14205 }
14206 run_test 232 "failed lock should not block umount"
14207
14208 test_233a() {
14209         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
14210         { skip "Need MDS version at least 2.3.64"; return; }
14211         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
14212
14213         local fid=$($LFS path2fid $MOUNT)
14214         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
14215                 error "cannot access $MOUNT using its FID '$fid'"
14216 }
14217 run_test 233a "checking that OBF of the FS root succeeds"
14218
14219 test_233b() {
14220         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
14221         { skip "Need MDS version at least 2.5.90"; return; }
14222         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
14223
14224         local fid=$($LFS path2fid $MOUNT/.lustre)
14225         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
14226                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
14227
14228         fid=$($LFS path2fid $MOUNT/.lustre/fid)
14229         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
14230                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
14231 }
14232 run_test 233b "checking that OBF of the FS .lustre succeeds"
14233
14234 test_234() {
14235         local p="$TMP/sanityN-$TESTNAME.parameters"
14236         save_lustre_params client "llite.*.xattr_cache" > $p
14237         lctl set_param llite.*.xattr_cache 1 ||
14238                 { skip "xattr cache is not supported"; return 0; }
14239
14240         mkdir -p $DIR/$tdir || error "mkdir failed"
14241         touch $DIR/$tdir/$tfile || error "touch failed"
14242         # OBD_FAIL_LLITE_XATTR_ENOMEM
14243         $LCTL set_param fail_loc=0x1405
14244         # output of the form: attr 2 4 44 3 fc13 x86_64
14245         V=($(IFS=".-" rpm -q attr))
14246         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
14247               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
14248                 # attr pre-2.4.44-7 had a bug with rc
14249                 # LU-3703 - SLES 11 and FC13 clients have older attr
14250                 getfattr -n user.attr $DIR/$tdir/$tfile &&
14251                         error "getfattr should have failed with ENOMEM"
14252         else
14253                 skip "LU-3703: attr version $(getfattr --version) too old"
14254         fi
14255         $LCTL set_param fail_loc=0x0
14256         rm -rf $DIR/$tdir
14257
14258         restore_lustre_params < $p
14259         rm -f $p
14260 }
14261 run_test 234 "xattr cache should not crash on ENOMEM"
14262
14263 test_235() {
14264         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
14265                 skip "Need MDS version at least 2.4.52" && return
14266         flock_deadlock $DIR/$tfile
14267         local RC=$?
14268         case $RC in
14269                 0)
14270                 ;;
14271                 124) error "process hangs on a deadlock"
14272                 ;;
14273                 *) error "error executing flock_deadlock $DIR/$tfile"
14274                 ;;
14275         esac
14276 }
14277 run_test 235 "LU-1715: flock deadlock detection does not work properly"
14278
14279 #LU-2935
14280 test_236() {
14281         check_swap_layouts_support && return 0
14282         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
14283
14284         local ref1=/etc/passwd
14285         local ref2=/etc/group
14286         local file1=$DIR/$tdir/f1
14287         local file2=$DIR/$tdir/f2
14288
14289         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
14290         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
14291         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
14292         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
14293         local fd=$(free_fd)
14294         local cmd="exec $fd<>$file2"
14295         eval $cmd
14296         rm $file2
14297         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
14298                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
14299         cmd="exec $fd>&-"
14300         eval $cmd
14301         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
14302
14303         #cleanup
14304         rm -rf $DIR/$tdir
14305 }
14306 run_test 236 "Layout swap on open unlinked file"
14307
14308 # test to verify file handle related system calls
14309 # (name_to_handle_at/open_by_handle_at)
14310 # The new system calls are supported in glibc >= 2.14.
14311
14312 test_237() {
14313         echo "Test file_handle syscalls" > $DIR/$tfile ||
14314                 error "write failed"
14315         check_fhandle_syscalls $DIR/$tfile ||
14316                 error "check_fhandle_syscalls failed"
14317 }
14318 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
14319
14320 # LU-4659 linkea consistency
14321 test_238() {
14322         local server_version=$(lustre_version_code $SINGLEMDS)
14323
14324         [[ $server_version -gt $(version_code 2.5.57) ]] ||
14325                 [[ $server_version -gt $(version_code 2.5.1) &&
14326                    $server_version -lt $(version_code 2.5.50) ]] ||
14327                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
14328
14329         touch $DIR/$tfile
14330         ln $DIR/$tfile $DIR/$tfile.lnk
14331         touch $DIR/$tfile.new
14332         mv $DIR/$tfile.new $DIR/$tfile
14333         local fid1=$($LFS path2fid $DIR/$tfile)
14334         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
14335         local path1=$($LFS fid2path $FSNAME "$fid1")
14336         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
14337         local path2=$($LFS fid2path $FSNAME "$fid2")
14338         [ $tfile.lnk == $path2 ] ||
14339                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
14340         rm -f $DIR/$tfile*
14341 }
14342 run_test 238 "Verify linkea consistency"
14343
14344 test_239() {
14345         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
14346                 skip "Need MDS version at least 2.5.60" && return
14347         local list=$(comma_list $(mdts_nodes))
14348
14349         mkdir -p $DIR/$tdir
14350         createmany -o $DIR/$tdir/f- 5000
14351         unlinkmany $DIR/$tdir/f- 5000
14352         [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.10.1) ] &&
14353                 do_nodes $list "lctl set_param -n osp.*.force_sync=1"
14354         changes=$(do_nodes $list "lctl get_param -n osp.*MDT*.sync_changes \
14355                         osp.*MDT*.sync_in_flight" | calc_sum)
14356         [ "$changes" -eq 0 ] || error "$changes not synced"
14357 }
14358 run_test 239 "osp_sync test"
14359
14360 test_239a() { #LU-5297
14361         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14362         touch $DIR/$tfile
14363         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
14364         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
14365         chgrp $RUNAS_GID $DIR/$tfile
14366         wait_delete_completed
14367 }
14368 run_test 239a "process invalid osp sync record correctly"
14369
14370 test_239b() { #LU-5297
14371         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14372         touch $DIR/$tfile1
14373         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
14374         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
14375         chgrp $RUNAS_GID $DIR/$tfile1
14376         wait_delete_completed
14377         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
14378         touch $DIR/$tfile2
14379         chgrp $RUNAS_GID $DIR/$tfile2
14380         wait_delete_completed
14381 }
14382 run_test 239b "process osp sync record with ENOMEM error correctly"
14383
14384 test_240() {
14385         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14386         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14387
14388         mkdir -p $DIR/$tdir
14389
14390         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
14391                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
14392         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
14393                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
14394
14395         umount_client $MOUNT || error "umount failed"
14396         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
14397         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
14398         mount_client $MOUNT || error "failed to mount client"
14399
14400         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
14401         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
14402 }
14403 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
14404
14405 test_241_bio() {
14406         for LOOP in $(seq $1); do
14407                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
14408                 cancel_lru_locks osc || true
14409         done
14410 }
14411
14412 test_241_dio() {
14413         for LOOP in $(seq $1); do
14414                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
14415                                                 iflag=direct 2>/dev/null
14416         done
14417 }
14418
14419 test_241a() { # was test_241
14420         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
14421         ls -la $DIR/$tfile
14422         cancel_lru_locks osc
14423         test_241_bio 1000 &
14424         PID=$!
14425         test_241_dio 1000
14426         wait $PID
14427 }
14428 run_test 241a "bio vs dio"
14429
14430 test_241b() {
14431         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
14432         ls -la $DIR/$tfile
14433         test_241_dio 1000 &
14434         PID=$!
14435         test_241_dio 1000
14436         wait $PID
14437 }
14438 run_test 241b "dio vs dio"
14439
14440 test_242() {
14441         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14442         mkdir -p $DIR/$tdir
14443         touch $DIR/$tdir/$tfile
14444
14445         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
14446         do_facet mds1 lctl set_param fail_loc=0x105
14447         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
14448
14449         do_facet mds1 lctl set_param fail_loc=0
14450         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
14451 }
14452 run_test 242 "mdt_readpage failure should not cause directory unreadable"
14453
14454 test_243()
14455 {
14456         test_mkdir -p $DIR/$tdir
14457         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
14458 }
14459 run_test 243 "various group lock tests"
14460
14461 test_244()
14462 {
14463         test_mkdir -p $DIR/$tdir
14464         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
14465         sendfile_grouplock $DIR/$tdir/$tfile || \
14466                 error "sendfile+grouplock failed"
14467         rm -rf $DIR/$tdir
14468 }
14469 run_test 244 "sendfile with group lock tests"
14470
14471 test_245() {
14472         local flagname="multi_mod_rpcs"
14473         local connect_data_name="max_mod_rpcs"
14474         local out
14475
14476         # check if multiple modify RPCs flag is set
14477         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
14478                 grep "connect_flags:")
14479         echo "$out"
14480
14481         echo "$out" | grep -qw $flagname
14482         if [ $? -ne 0 ]; then
14483                 echo "connect flag $flagname is not set"
14484                 return
14485         fi
14486
14487         # check if multiple modify RPCs data is set
14488         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
14489         echo "$out"
14490
14491         echo "$out" | grep -qw $connect_data_name ||
14492                 error "import should have connect data $connect_data_name"
14493 }
14494 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
14495
14496 test_246() { # LU-7371
14497         remote_ost_nodsh && skip "remote OST with nodsh" && return
14498         [ $(lustre_version_code ost1) -lt $(version_code 2.7.62) ] &&
14499                 skip "Need OST version >= 2.7.62" && return 0
14500         do_facet ost1 $LCTL set_param fail_val=4095
14501 #define OBD_FAIL_OST_READ_SIZE          0x234
14502         do_facet ost1 $LCTL set_param fail_loc=0x234
14503         $LFS setstripe $DIR/$tfile -i 0 -c 1
14504         dd if=/dev/zero of=$DIR/$tfile bs=4095 count=1 > /dev/null 2>&1
14505         cancel_lru_locks $FSNAME-OST0000
14506         dd if=$DIR/$tfile of=/dev/null bs=1048576 || error "Read failed"
14507 }
14508 run_test 246 "Read file of size 4095 should return right length"
14509
14510 test_247a() {
14511         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
14512                 grep -q subtree ||
14513                 { skip "Fileset feature is not supported"; return; }
14514
14515         local submount=${MOUNT}_$tdir
14516
14517         mkdir $MOUNT/$tdir
14518         mkdir -p $submount || error "mkdir $submount failed"
14519         FILESET="$FILESET/$tdir" mount_client $submount ||
14520                 error "mount $submount failed"
14521         echo foo > $submount/$tfile || error "write $submount/$tfile failed"
14522         [ $(cat $MOUNT/$tdir/$tfile) = "foo" ] ||
14523                 error "read $MOUNT/$tdir/$tfile failed"
14524         umount_client $submount || error "umount $submount failed"
14525         rmdir $submount
14526 }
14527 run_test 247a "mount subdir as fileset"
14528
14529 test_247b() {
14530         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14531                 { skip "Fileset feature is not supported"; return; }
14532
14533         local submount=${MOUNT}_$tdir
14534
14535         rm -rf $MOUNT/$tdir
14536         mkdir -p $submount || error "mkdir $submount failed"
14537         SKIP_FILESET=1
14538         FILESET="$FILESET/$tdir" mount_client $submount &&
14539                 error "mount $submount should fail"
14540         rmdir $submount
14541 }
14542 run_test 247b "mount subdir that dose not exist"
14543
14544 test_247c() {
14545         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14546                 { skip "Fileset feature is not supported"; return; }
14547
14548         local submount=${MOUNT}_$tdir
14549
14550         mkdir -p $MOUNT/$tdir/dir1
14551         mkdir -p $submount || error "mkdir $submount failed"
14552         FILESET="$FILESET/$tdir" mount_client $submount ||
14553                 error "mount $submount failed"
14554         local fid=$($LFS path2fid $MOUNT/)
14555         $LFS fid2path $submount $fid && error "fid2path should fail"
14556         umount_client $submount || error "umount $submount failed"
14557         rmdir $submount
14558 }
14559 run_test 247c "running fid2path outside root"
14560
14561 test_247d() {
14562         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
14563                 { skip "Fileset feature is not supported"; return; }
14564
14565         local submount=${MOUNT}_$tdir
14566
14567         mkdir -p $MOUNT/$tdir/dir1
14568         mkdir -p $submount || error "mkdir $submount failed"
14569         FILESET="$FILESET/$tdir" mount_client $submount ||
14570                 error "mount $submount failed"
14571         local fid=$($LFS path2fid $submount/dir1)
14572         $LFS fid2path $submount $fid || error "fid2path should succeed"
14573         umount_client $submount || error "umount $submount failed"
14574         rmdir $submount
14575 }
14576 run_test 247d "running fid2path inside root"
14577
14578 # LU-8037
14579 test_247e() {
14580         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
14581                 grep -q subtree ||
14582                 { skip "Fileset feature is not supported"; return; }
14583
14584         local submount=${MOUNT}_$tdir
14585
14586         mkdir $MOUNT/$tdir
14587         mkdir -p $submount || error "mkdir $submount failed"
14588         FILESET="$FILESET/.." mount_client $submount &&
14589                 error "mount $submount should fail"
14590         rmdir $submount
14591 }
14592 run_test 247e "mount .. as fileset"
14593
14594 test_248() {
14595         local fast_read_sav=$($LCTL get_param -n llite.*.fast_read 2>/dev/null)
14596         [ -z "$fast_read_sav" ] && skip "no fast read support" && return
14597
14598         # create a large file for fast read verification
14599         dd if=/dev/zero of=$DIR/$tfile bs=1M count=128 > /dev/null 2>&1
14600
14601         # make sure the file is created correctly
14602         $CHECKSTAT -s $((128*1024*1024)) $DIR/$tfile ||
14603                 { rm -f $DIR/$tfile; skip "file creation error" && return; }
14604
14605         echo "Test 1: verify that fast read is 4 times faster on cache read"
14606
14607         # small read with fast read enabled
14608         $LCTL set_param -n llite.*.fast_read=1
14609         local t_fast=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
14610                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
14611                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
14612         # small read with fast read disabled
14613         $LCTL set_param -n llite.*.fast_read=0
14614         local t_slow=$(dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
14615                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
14616                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
14617
14618         # verify that fast read is 4 times faster for cache read
14619         [ $(bc <<< "4 * $t_fast < $t_slow") -eq 1 ] ||
14620                 error_not_in_vm "fast read was not 4 times faster: " \
14621                            "$t_fast vs $t_slow"
14622
14623         echo "Test 2: verify the performance between big and small read"
14624         $LCTL set_param -n llite.*.fast_read=1
14625
14626         # 1k non-cache read
14627         cancel_lru_locks osc
14628         local t_1k=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
14629                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
14630                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
14631
14632         # 1M non-cache read
14633         cancel_lru_locks osc
14634         local t_1m=$(dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
14635                 egrep -o '([[:digit:]\.\,e-]+) s' | cut -d's' -f1 |
14636                 sed -e 's/,/./' -e 's/[eE]+*/\*10\^/')
14637
14638         # verify that big IO is not 4 times faster than small IO
14639         [ $(bc <<< "4 * $t_1k >= $t_1m") -eq 1 ] ||
14640                 error_not_in_vm "bigger IO is way too fast: $t_1k vs $t_1m"
14641
14642         $LCTL set_param -n llite.*.fast_read=$fast_read_sav
14643         rm -f $DIR/$tfile
14644 }
14645 run_test 248 "fast read verification"
14646
14647 test_249() { # LU-7890
14648         rm -f $DIR/$tfile
14649         $SETSTRIPE -c 1 $DIR/$tfile
14650
14651         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
14652         skip "Need at least version 2.8.54"
14653
14654         # Offset 2T == 4k * 512M
14655         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 seek=512M ||
14656                 error "dd to 2T offset failed"
14657 }
14658 run_test 249 "Write above 2T file size"
14659
14660 test_250() {
14661         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
14662          && skip "no 16TB file size limit on ZFS" && return
14663
14664         $SETSTRIPE -c 1 $DIR/$tfile
14665         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
14666         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
14667         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
14668         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
14669                 conv=notrunc,fsync && error "append succeeded"
14670         return 0
14671 }
14672 run_test 250 "Write above 16T limit"
14673
14674 test_251() {
14675         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
14676
14677         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
14678         #Skip once - writing the first stripe will succeed
14679         $LCTL set_param fail_loc=0xa0001407 fail_val=1
14680         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
14681                 error "short write happened"
14682
14683         $LCTL set_param fail_loc=0xa0001407 fail_val=1
14684         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
14685                 error "short read happened"
14686
14687         rm -f $DIR/$tfile
14688 }
14689 run_test 251 "Handling short read and write correctly"
14690
14691 test_252() {
14692         local tgt
14693         local dev
14694         local out
14695         local uuid
14696         local num
14697         local gen
14698
14699         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14700         remote_ost_nodsh && skip "remote OST with nodsh" && return
14701         if [ "$(facet_fstype ost1)" != "ldiskfs" -o \
14702              "$(facet_fstype mds1)" != "ldiskfs" ]; then
14703                 skip "ldiskfs only test"
14704                 return
14705         fi
14706
14707         # check lr_reader on OST0000
14708         tgt=ost1
14709         dev=$(facet_device $tgt)
14710         out=$(do_facet $tgt $LR_READER $dev)
14711         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14712         echo "$out"
14713         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
14714         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
14715                 error "Invalid uuid returned by $LR_READER on target $tgt"
14716         echo -e "uuid returned by $LR_READER is '$uuid'\n"
14717
14718         # check lr_reader -c on MDT0000
14719         tgt=mds1
14720         dev=$(facet_device $tgt)
14721         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
14722                 echo "$LR_READER does not support additional options"
14723                 return 0
14724         fi
14725         out=$(do_facet $tgt $LR_READER -c $dev)
14726         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14727         echo "$out"
14728         num=$(echo "$out" | grep -c "mdtlov")
14729         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
14730                 error "Invalid number of mdtlov clients returned by $LR_READER"
14731         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
14732
14733         # check lr_reader -cr on MDT0000
14734         out=$(do_facet $tgt $LR_READER -cr $dev)
14735         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
14736         echo "$out"
14737         echo "$out" | grep -q "^reply_data:$" ||
14738                 error "$LR_READER should have returned 'reply_data' section"
14739         num=$(echo "$out" | grep -c "client_generation")
14740         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
14741 }
14742 run_test 252 "check lr_reader tool"
14743
14744 test_253_fill_ost() {
14745         local size_mb #how many MB should we write to pass watermark
14746         local lwm=$3  #low watermark
14747         local free_10mb #10% of free space
14748
14749         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
14750         size_mb=$((free_kb / 1024 - lwm))
14751         free_10mb=$((free_kb / 10240))
14752         #If 10% of free space cross low watermark use it
14753         if (( free_10mb > size_mb )); then
14754                 size_mb=$free_10mb
14755         else
14756                 #At least we need to store 1.1 of difference between
14757                 #free space and low watermark
14758                 size_mb=$((size_mb + size_mb / 10))
14759         fi
14760         if (( lwm <= $((free_kb / 1024)) )) || [ ! -f $DIR/$tdir/1 ]; then
14761                 dd if=/dev/zero of=$DIR/$tdir/1 bs=1M count=$size_mb \
14762                          oflag=append conv=notrunc
14763         fi
14764
14765         sleep_maxage
14766
14767         free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
14768         echo "OST still has $((free_kb / 1024)) mbytes free"
14769 }
14770
14771 test_253() {
14772         local ostidx=0
14773         local rc=0
14774
14775         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14776         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14777         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
14778
14779         local ost_name=$($LFS osts |
14780                 sed -n 's/^'$ostidx': \(.*\)_UUID .*/\1/p')
14781         # on the mdt's osc
14782         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
14783         do_facet $SINGLEMDS $LCTL get_param -n \
14784                 osp.$mdtosc_proc1.reserved_mb_high ||
14785                 { skip  "remote MDS does not support reserved_mb_high" &&
14786                   return; }
14787
14788         rm -rf $DIR/$tdir
14789         wait_mds_ost_sync
14790         wait_delete_completed
14791         mkdir $DIR/$tdir
14792
14793         local last_wm_h=$(do_facet $SINGLEMDS $LCTL get_param -n \
14794                         osp.$mdtosc_proc1.reserved_mb_high)
14795         local last_wm_l=$(do_facet $SINGLEMDS $LCTL get_param -n \
14796                         osp.$mdtosc_proc1.reserved_mb_low)
14797         echo "prev high watermark $last_wm_h, prev low watermark $last_wm_l"
14798
14799         if ! combined_mgs_mds ; then
14800                 mount_mgs_client
14801         fi
14802         create_pool $FSNAME.$TESTNAME || error "Pool creation failed"
14803         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $ost_name ||
14804                 error "Adding $ost_name to pool failed"
14805
14806         # Wait for client to see a OST at pool
14807         wait_update $HOSTNAME "$LCTL get_param -n
14808                 lov.$FSNAME-*.pools.$TESTNAME | sort -u |
14809                 grep $ost_name" "$ost_name""_UUID" $((TIMEOUT/2)) ||
14810                 error "Client can not see the pool"
14811         $SETSTRIPE $DIR/$tdir -i $ostidx -c 1 -p $FSNAME.$TESTNAME ||
14812                 error "Setstripe failed"
14813
14814         dd if=/dev/zero of=$DIR/$tdir/0 bs=1M count=10
14815         local blocks=$($LFS df $MOUNT | grep $ost_name | awk '{ print $4 }')
14816         echo "OST still has $((blocks/1024)) mbytes free"
14817
14818         local new_lwm=$((blocks/1024-10))
14819         do_facet $SINGLEMDS $LCTL set_param \
14820                         osp.$mdtosc_proc1.reserved_mb_high=$((new_lwm+5))
14821         do_facet $SINGLEMDS $LCTL set_param \
14822                         osp.$mdtosc_proc1.reserved_mb_low=$new_lwm
14823
14824         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
14825
14826         #First enospc could execute orphan deletion so repeat.
14827         test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
14828
14829         local oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
14830                         osp.$mdtosc_proc1.prealloc_status)
14831         echo "prealloc_status $oa_status"
14832
14833         dd if=/dev/zero of=$DIR/$tdir/2 bs=1M count=1 &&
14834                 error "File creation should fail"
14835         #object allocation was stopped, but we still able to append files
14836         dd if=/dev/zero of=$DIR/$tdir/1 bs=1M seek=6 count=5 oflag=append ||
14837                 error "Append failed"
14838         rm -f $DIR/$tdir/1 $DIR/$tdir/0 $DIR/$tdir/r*
14839
14840         wait_delete_completed
14841
14842         sleep_maxage
14843
14844         for i in $(seq 10 12); do
14845                 dd if=/dev/zero of=$DIR/$tdir/$i bs=1M count=1 2>/dev/null ||
14846                         error "File creation failed after rm";
14847         done
14848
14849         oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
14850                         osp.$mdtosc_proc1.prealloc_status)
14851         echo "prealloc_status $oa_status"
14852
14853         if (( oa_status != 0 )); then
14854                 error "Object allocation still disable after rm"
14855         fi
14856         do_facet $SINGLEMDS $LCTL set_param \
14857                         osp.$mdtosc_proc1.reserved_mb_high=$last_wm_h
14858         do_facet $SINGLEMDS $LCTL set_param \
14859                         osp.$mdtosc_proc1.reserved_mb_low=$last_wm_l
14860
14861
14862         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $ost_name ||
14863                 error "Remove $ost_name from pool failed"
14864         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
14865                 error "Pool destroy fialed"
14866
14867         if ! combined_mgs_mds ; then
14868                 umount_mgs_client
14869         fi
14870 }
14871 run_test 253 "Check object allocation limit"
14872
14873 test_254() {
14874         local cl_user
14875
14876         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14877         remote_mds_nodsh && skip "remote MDS with nodsh" && return
14878         do_facet mds1 $LCTL get_param -n mdd.$MDT0.changelog_size ||
14879                 { skip "MDS does not support changelog_size" && return; }
14880
14881         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
14882         echo "Registered as changelog user $cl_user"
14883
14884         $LFS changelog_clear $MDT0 $cl_user 0
14885
14886         local size1=$(do_facet mds1 \
14887                       $LCTL get_param -n mdd.$MDT0.changelog_size)
14888         echo "Changelog size $size1"
14889
14890         rm -rf $DIR/$tdir
14891         $LFS mkdir -i 0 $DIR/$tdir
14892         # change something
14893         mkdir -p $DIR/$tdir/pics/2008/zachy
14894         touch $DIR/$tdir/pics/2008/zachy/timestamp
14895         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
14896         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
14897         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
14898         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
14899         rm $DIR/$tdir/pics/desktop.jpg
14900
14901         local size2=$(do_facet mds1 \
14902                       $LCTL get_param -n mdd.$MDT0.changelog_size)
14903         echo "Changelog size after work $size2"
14904
14905         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
14906
14907         if (( size2 <= size1 )); then
14908                 error "Changelog size after work should be greater than original"
14909         fi
14910         return 0
14911 }
14912 run_test 254 "Check changelog size"
14913
14914 ladvise_no_type()
14915 {
14916         local type=$1
14917         local file=$2
14918
14919         lfs ladvise -a invalid $file 2>&1 | grep "Valid types" |
14920                 awk -F: '{print $2}' | grep $type > /dev/null
14921         if [ $? -ne 0 ]; then
14922                 return 0
14923         fi
14924         return 1
14925 }
14926
14927 ladvise_no_ioctl()
14928 {
14929         local file=$1
14930
14931         lfs ladvise -a willread $file > /dev/null 2>&1
14932         if [ $? -eq 0 ]; then
14933                 return 1
14934         fi
14935
14936         lfs ladvise -a willread $file 2>&1 |
14937                 grep "Inappropriate ioctl for device" > /dev/null
14938         if [ $? -eq 0 ]; then
14939                 return 0
14940         fi
14941         return 1
14942 }
14943
14944 percent() {
14945         bc <<<"scale=2; ($1 - $2) * 100 / $2"
14946 }
14947
14948 # run a random read IO workload
14949 # usage: random_read_iops <filename> <filesize> <iosize>
14950 random_read_iops() {
14951         local file=$1
14952         local fsize=$2
14953         local iosize=${3:-4096}
14954
14955         $READS -f $file -s $fsize -b $iosize -n $((fsize / iosize)) -t 60 |
14956                 sed -e '/^$/d' -e 's#.*s, ##' -e 's#MB/s##'
14957 }
14958
14959 drop_file_oss_cache() {
14960         local file="$1"
14961         local nodes="$2"
14962
14963         $LFS ladvise -a dontneed $file 2>/dev/null ||
14964                 do_nodes $nodes "echo 3 > /proc/sys/vm/drop_caches"
14965 }
14966
14967 ladvise_willread_performance()
14968 {
14969         local repeat=10
14970         local average_origin=0
14971         local average_cache=0
14972         local average_ladvise=0
14973
14974         for ((i = 1; i <= $repeat; i++)); do
14975                 echo "Iter $i/$repeat: reading without willread hint"
14976                 cancel_lru_locks osc
14977                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
14978                 local speed_origin=$(random_read_iops $DIR/$tfile $size)
14979                 echo "Iter $i/$repeat: uncached speed: $speed_origin"
14980                 average_origin=$(bc <<<"$average_origin + $speed_origin")
14981
14982                 cancel_lru_locks osc
14983                 local speed_cache=$(random_read_iops $DIR/$tfile $size)
14984                 echo "Iter $i/$repeat: OSS cache speed: $speed_cache"
14985                 average_cache=$(bc <<<"$average_cache + $speed_cache")
14986
14987                 cancel_lru_locks osc
14988                 drop_file_oss_cache $DIR/$tfile $(comma_list $(osts_nodes))
14989                 $LFS ladvise -a willread $DIR/$tfile || error "ladvise failed"
14990                 local speed_ladvise=$(random_read_iops $DIR/$tfile $size)
14991                 echo "Iter $i/$repeat: ladvise speed: $speed_ladvise"
14992                 average_ladvise=$(bc <<<"$average_ladvise + $speed_ladvise")
14993         done
14994         average_origin=$(bc <<<"scale=2; $average_origin / $repeat")
14995         average_cache=$(bc <<<"scale=2; $average_cache / $repeat")
14996         average_ladvise=$(bc <<<"scale=2; $average_ladvise / $repeat")
14997
14998         speedup_cache=$(percent $average_cache $average_origin)
14999         speedup_ladvise=$(percent $average_ladvise $average_origin)
15000
15001         echo "Average uncached read: $average_origin"
15002         echo "Average speedup with OSS cached read: " \
15003                 "$average_cache = +$speedup_cache%"
15004         echo "Average speedup with ladvise willread: " \
15005                 "$average_ladvise = +$speedup_ladvise%"
15006
15007         local lowest_speedup=20
15008         if [ ${average_cache%.*} -lt $lowest_speedup ]; then
15009                 echo "Speedup with OSS cached read less than $lowest_speedup%, " \
15010                         "got $average_cache%. Skipping ladvise willread check."
15011                 return 0
15012         fi
15013
15014         # the test won't work on ZFS until it supports 'ladvise dontneed', but
15015         # it is still good to run until then to exercise 'ladvise willread'
15016         ! $LFS ladvise -a dontneed $DIR/$tfile &&
15017                 [ "$(facet_fstype ost1)" = "zfs" ] &&
15018                 echo "osd-zfs does not support dontneed or drop_caches" &&
15019                 return 0
15020
15021         lowest_speedup=$(bc <<<"scale=2; $average_cache / 2")
15022         [ ${average_ladvise%.*} -gt $lowest_speedup ] ||
15023                 error_not_in_vm "Speedup with willread is less than " \
15024                         "$lowest_speedup%, got $average_ladvise%"
15025 }
15026
15027 test_255a() {
15028         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
15029                 skip "lustre < 2.8.54 does not support ladvise " && return
15030         remote_ost_nodsh && skip "remote OST with nodsh" && return
15031
15032         lfs setstripe -c -1 -i 0 $DIR/$tfile || error "$tfile failed"
15033
15034         ladvise_no_type willread $DIR/$tfile &&
15035                 skip "willread ladvise is not supported" && return
15036
15037         ladvise_no_ioctl $DIR/$tfile &&
15038                 skip "ladvise ioctl is not supported" && return
15039
15040         local size_mb=100
15041         local size=$((size_mb * 1048576))
15042         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
15043                 error "dd to $DIR/$tfile failed"
15044
15045         lfs ladvise -a willread $DIR/$tfile ||
15046                 error "Ladvise failed with no range argument"
15047
15048         lfs ladvise -a willread -s 0 $DIR/$tfile ||
15049                 error "Ladvise failed with no -l or -e argument"
15050
15051         lfs ladvise -a willread -e 1 $DIR/$tfile ||
15052                 error "Ladvise failed with only -e argument"
15053
15054         lfs ladvise -a willread -l 1 $DIR/$tfile ||
15055                 error "Ladvise failed with only -l argument"
15056
15057         lfs ladvise -a willread -s 2 -e 1 $DIR/$tfile &&
15058                 error "End offset should not be smaller than start offset"
15059
15060         lfs ladvise -a willread -s 2 -e 2 $DIR/$tfile &&
15061                 error "End offset should not be equal to start offset"
15062
15063         lfs ladvise -a willread -s $size -l 1 $DIR/$tfile ||
15064                 error "Ladvise failed with overflowing -s argument"
15065
15066         lfs ladvise -a willread -s 1 -e $((size + 1)) $DIR/$tfile ||
15067                 error "Ladvise failed with overflowing -e argument"
15068
15069         lfs ladvise -a willread -s 1 -l $size $DIR/$tfile ||
15070                 error "Ladvise failed with overflowing -l argument"
15071
15072         lfs ladvise -a willread -l 1 -e 2 $DIR/$tfile &&
15073                 error "Ladvise succeeded with conflicting -l and -e arguments"
15074
15075         echo "Synchronous ladvise should wait"
15076         local delay=4
15077 #define OBD_FAIL_OST_LADVISE_PAUSE       0x237
15078         do_nodes $(comma_list $(osts_nodes)) \
15079                 $LCTL set_param fail_val=$delay fail_loc=0x237
15080
15081         local start_ts=$SECONDS
15082         lfs ladvise -a willread $DIR/$tfile ||
15083                 error "Ladvise failed with no range argument"
15084         local end_ts=$SECONDS
15085         local inteval_ts=$((end_ts - start_ts))
15086
15087         if [ $inteval_ts -lt $(($delay - 1)) ]; then
15088                 error "Synchronous advice didn't wait reply"
15089         fi
15090
15091         echo "Asynchronous ladvise shouldn't wait"
15092         local start_ts=$SECONDS
15093         lfs ladvise -a willread -b $DIR/$tfile ||
15094                 error "Ladvise failed with no range argument"
15095         local end_ts=$SECONDS
15096         local inteval_ts=$((end_ts - start_ts))
15097
15098         if [ $inteval_ts -gt $(($delay / 2)) ]; then
15099                 error "Asynchronous advice blocked"
15100         fi
15101
15102         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param fail_loc=0
15103         ladvise_willread_performance
15104 }
15105 run_test 255a "check 'lfs ladvise -a willread'"
15106
15107 facet_meminfo() {
15108         local facet=$1
15109         local info=$2
15110
15111         do_facet $facet "cat /proc/meminfo | grep ^${info}:" | awk '{print $2}'
15112 }
15113
15114 test_255b() {
15115         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
15116                 skip "lustre < 2.8.54 does not support ladvise " && return
15117         remote_ost_nodsh && skip "remote OST with nodsh" && return
15118
15119         lfs setstripe -c 1 -i 0 $DIR/$tfile
15120
15121         ladvise_no_type dontneed $DIR/$tfile &&
15122                 skip "dontneed ladvise is not supported" && return
15123
15124         ladvise_no_ioctl $DIR/$tfile &&
15125                 skip "ladvise ioctl is not supported" && return
15126
15127         [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
15128                 skip "lustre < 2.8.54 does not support ladvise" && return
15129
15130         ! $LFS ladvise -a dontneed $DIR/$tfile &&
15131                 [ "$(facet_fstype ost1)" = "zfs" ] &&
15132                 skip "zfs-osd does not support 'ladvise dontneed'" && return
15133
15134         local size_mb=100
15135         local size=$((size_mb * 1048576))
15136         # In order to prevent disturbance of other processes, only check 3/4
15137         # of the memory usage
15138         local kibibytes=$((size_mb * 1024 * 3 / 4))
15139
15140         dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
15141                 error "dd to $DIR/$tfile failed"
15142
15143         local total=$(facet_meminfo ost1 MemTotal)
15144         echo "Total memory: $total KiB"
15145
15146         do_facet ost1 "sync && echo 3 > /proc/sys/vm/drop_caches"
15147         local before_read=$(facet_meminfo ost1 Cached)
15148         echo "Cache used before read: $before_read KiB"
15149
15150         lfs ladvise -a willread $DIR/$tfile ||
15151                 error "Ladvise willread failed"
15152         local after_read=$(facet_meminfo ost1 Cached)
15153         echo "Cache used after read: $after_read KiB"
15154
15155         lfs ladvise -a dontneed $DIR/$tfile ||
15156                 error "Ladvise dontneed again failed"
15157         local no_read=$(facet_meminfo ost1 Cached)
15158         echo "Cache used after dontneed ladvise: $no_read KiB"
15159
15160         if [ $total -lt $((before_read + kibibytes)) ]; then
15161                 echo "Memory is too small, abort checking"
15162                 return 0
15163         fi
15164
15165         if [ $((before_read + kibibytes)) -gt $after_read ]; then
15166                 error "Ladvise willread should use more memory" \
15167                         "than $kibibytes KiB"
15168         fi
15169
15170         if [ $((no_read + kibibytes)) -gt $after_read ]; then
15171                 error "Ladvise dontneed should release more memory" \
15172                         "than $kibibytes KiB"
15173         fi
15174 }
15175 run_test 255b "check 'lfs ladvise -a dontneed'"
15176
15177 test_256() {
15178         local cl_user
15179         local cat_sl
15180         local mdt_dev
15181
15182         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15183         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15184         [ "$(facet_fstype mds1)" != "ldiskfs" ] &&
15185                 skip "ldiskfs only test" && return
15186
15187         mdt_dev=$(mdsdevname 1)
15188         echo $mdt_dev
15189         cl_user=$(do_facet mds1 \
15190         "$LCTL get_param -n mdd.$MDT0.changelog_users | grep cl")
15191         if [[ -n $cl_user ]]; then
15192                 skip "active changelog user"
15193                 return
15194         fi
15195
15196         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
15197         echo "Registered as changelog user $cl_user"
15198
15199         rm -rf $DIR/$tdir
15200         mkdir -p $DIR/$tdir
15201
15202         $LFS changelog_clear $MDT0 $cl_user 0
15203
15204         # change something
15205         touch $DIR/$tdir/{1..10}
15206
15207         # stop the MDT
15208         stop mds1 || error "Fail to stop MDT."
15209
15210         # remount the MDT
15211         start mds1 $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT."
15212
15213         #after mount new plainllog is used
15214         touch $DIR/$tdir/{11..19}
15215         local TEMP256FILE=$(mktemp TEMP256XXXXXX)
15216         cat_sl=$(do_facet mds1 \
15217         "$DEBUGFS -R \\\"dump changelog_catalog $TEMP256FILE\\\" $mdt_dev; \
15218          llog_reader $TEMP256FILE | grep \\\"type=1064553b\\\" | wc -l")
15219         rm $TEMP256FILE
15220
15221         if (( cat_sl != 2 )); then
15222                 do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
15223                 error "Changelog catalog has wrong number of slots $cat_sl"
15224         fi
15225
15226         $LFS changelog_clear $MDT0 $cl_user 0
15227
15228         TEMP256FILE=$(mktemp TEMP256XXXXXX)
15229         cat_sl=$(do_facet mds1 \
15230         "$DEBUGFS -R \\\"dump changelog_catalog $TEMP256FILE\\\" $mdt_dev; \
15231          llog_reader $TEMP256FILE | grep \\\"type=1064553b\\\" | wc -l")
15232         rm $TEMP256FILE
15233
15234         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
15235
15236         if (( cat_sl == 2 )); then
15237                 error "Empty plain llog was not deleted from changelog catalog"
15238         fi
15239         if (( cat_sl != 1 )); then
15240                 error "Active plain llog shouldn\`t be deleted from catalog"
15241         fi
15242 }
15243 run_test 256 "Check llog delete for empty and not full state"
15244
15245 test_257() {
15246         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15247         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
15248                 skip "Need MDS version at least 2.8.55" && return
15249
15250         test_mkdir -p $DIR/$tdir
15251
15252         setfattr -n trusted.name1 -v value1 $DIR/$tdir ||
15253                 error "setfattr -n trusted.name1=value1 $DIR/$tdir failed"
15254         stat $DIR/$tdir
15255
15256 #define OBD_FAIL_MDS_XATTR_REP                  0x161
15257         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
15258         local facet=mds$((mdtidx + 1))
15259         set_nodes_failloc $(facet_active_host $facet) 0x80000161
15260         getfattr -n trusted.name1 $DIR/$tdir 2> /dev/null
15261
15262         stop $facet || error "stop MDS failed"
15263         start $facet $(mdsdevname $((mdtidx + 1))) $MDS_MOUNT_OPTS ||
15264                 error "start MDS fail"
15265 }
15266 run_test 257 "xattr locks are not lost"
15267
15268 # Verify we take the i_mutex when security requires it
15269 test_258a() {
15270 #define OBD_FAIL_IMUTEX_SEC 0x141c
15271         $LCTL set_param fail_loc=0x141c
15272         touch $DIR/$tfile
15273         chmod u+s $DIR/$tfile
15274         chmod a+rwx $DIR/$tfile
15275         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
15276         RC=$?
15277         if [ $RC -ne 0 ]; then
15278                 error "error, failed to take i_mutex, rc=$?"
15279         fi
15280         rm -f $DIR/$tfile
15281 }
15282 run_test 258a
15283
15284 # Verify we do NOT take the i_mutex in the normal case
15285 test_258b() {
15286 #define OBD_FAIL_IMUTEX_NOSEC 0x141d
15287         $LCTL set_param fail_loc=0x141d
15288         touch $DIR/$tfile
15289         chmod a+rwx $DIR
15290         chmod a+rw $DIR/$tfile
15291         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 oflag=append
15292         RC=$?
15293         if [ $RC -ne 0 ]; then
15294                 error "error, took i_mutex unnecessarily, rc=$?"
15295         fi
15296         rm -f $DIR/$tfile
15297
15298 }
15299 run_test 258b "verify i_mutex security behavior"
15300
15301 test_260() {
15302 #define OBD_FAIL_MDC_CLOSE               0x806
15303         $LCTL set_param fail_loc=0x80000806
15304         touch $DIR/$tfile
15305
15306 }
15307 run_test 260 "Check mdc_close fail"
15308
15309 test_275() {
15310         remote_ost_nodsh && skip "remote OST with nodsh" && return
15311         [ $(lustre_version_code ost1) -lt $(version_code 2.10.1) ] &&
15312                 skip "Need OST version >= 2.10.1" && return 0
15313
15314         local file=$DIR/$tfile
15315         local oss
15316
15317         oss=$(comma_list $(osts_nodes))
15318
15319         dd if=/dev/urandom of=$file bs=1M count=2 ||
15320                 error "failed to create a file"
15321         cancel_lru_locks osc
15322
15323         #lock 1
15324         dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
15325                 error "failed to read a file"
15326
15327 #define OBD_FAIL_LDLM_PAUSE_CANCEL2      0x31f
15328         $LCTL set_param fail_loc=0x8000031f
15329
15330         cancel_lru_locks osc &
15331         sleep 1
15332
15333 #define OBD_FAIL_LDLM_PROLONG_PAUSE      0x32b
15334         do_nodes $oss $LCTL set_param fail_loc=0x8000032b
15335         #IO takes another lock, but matches the PENDING one
15336         #and places it to the IO RPC
15337         dd if=$file of=/dev/null bs=1M count=1 iflag=direct ||
15338                 error "failed to read a file with PENDING lock"
15339 }
15340 run_test 275 "Read on a canceled duplicate lock"
15341
15342 test_276() {
15343         remote_ost_nodsh && skip "remote OST with nodsh" && return
15344         local pid
15345
15346         do_facet ost1 "(while true; do \
15347                 $LCTL get_param obdfilter.*.filesfree > /dev/null 2>&1; \
15348                 done) & pid=\\\$!; echo \\\$pid > $TMP/sanity_276_pid" &
15349         pid=$!
15350
15351         for LOOP in $(seq 20); do
15352                 stop ost1
15353                 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
15354         done
15355         kill -9 $pid
15356         do_facet ost1 "pid=\\\$(cat $TMP/sanity_276_pid); kill -9 \\\$pid; \
15357                 rm $TMP/sanity_276_pid"
15358 }
15359 run_test 276 "Race between mount and obd_statfs"
15360
15361 cleanup_test_300() {
15362         trap 0
15363         umask $SAVE_UMASK
15364 }
15365 test_striped_dir() {
15366         local mdt_index=$1
15367         local stripe_count
15368         local stripe_index
15369
15370         mkdir -p $DIR/$tdir
15371
15372         SAVE_UMASK=$(umask)
15373         trap cleanup_test_300 RETURN EXIT
15374
15375         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
15376                                                 $DIR/$tdir/striped_dir ||
15377                 error "set striped dir error"
15378
15379         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
15380         [ "$mode" = "755" ] || error "expect 755 got $mode"
15381
15382         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
15383                 error "getdirstripe failed"
15384         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
15385         if [ "$stripe_count" != "2" ]; then
15386                 error "1:stripe_count is $stripe_count, expect 2"
15387         fi
15388         stripe_count=$($LFS getdirstripe -T $DIR/$tdir/striped_dir)
15389         if [ "$stripe_count" != "2" ]; then
15390                 error "2:stripe_count is $stripe_count, expect 2"
15391         fi
15392
15393         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
15394         if [ "$stripe_index" != "$mdt_index" ]; then
15395                 error "stripe_index is $stripe_index, expect $mdt_index"
15396         fi
15397
15398         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
15399                 error "nlink error after create striped dir"
15400
15401         mkdir $DIR/$tdir/striped_dir/a
15402         mkdir $DIR/$tdir/striped_dir/b
15403
15404         stat $DIR/$tdir/striped_dir/a ||
15405                 error "create dir under striped dir failed"
15406         stat $DIR/$tdir/striped_dir/b ||
15407                 error "create dir under striped dir failed"
15408
15409         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
15410                 error "nlink error after mkdir"
15411
15412         rmdir $DIR/$tdir/striped_dir/a
15413         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
15414                 error "nlink error after rmdir"
15415
15416         rmdir $DIR/$tdir/striped_dir/b
15417         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
15418                 error "nlink error after rmdir"
15419
15420         chattr +i $DIR/$tdir/striped_dir
15421         createmany -o $DIR/$tdir/striped_dir/f 10 &&
15422                 error "immutable flags not working under striped dir!"
15423         chattr -i $DIR/$tdir/striped_dir
15424
15425         rmdir $DIR/$tdir/striped_dir ||
15426                 error "rmdir striped dir error"
15427
15428         cleanup_test_300
15429
15430         true
15431 }
15432
15433 test_300a() {
15434         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15435                 skip "skipped for lustre < 2.7.0" && return
15436         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15437         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15438
15439         test_striped_dir 0 || error "failed on striped dir on MDT0"
15440         test_striped_dir 1 || error "failed on striped dir on MDT0"
15441 }
15442 run_test 300a "basic striped dir sanity test"
15443
15444 test_300b() {
15445         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15446                 skip "skipped for lustre < 2.7.0" && return
15447         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15448         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15449         local i
15450         local mtime1
15451         local mtime2
15452         local mtime3
15453
15454         test_mkdir $DIR/$tdir || error "mkdir fail"
15455         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15456                 error "set striped dir error"
15457         for ((i=0; i<10; i++)); do
15458                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
15459                 sleep 1
15460                 touch $DIR/$tdir/striped_dir/file_$i ||
15461                                         error "touch error $i"
15462                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
15463                 [ $mtime1 -eq $mtime2 ] &&
15464                         error "mtime not change after create"
15465                 sleep 1
15466                 rm -f $DIR/$tdir/striped_dir/file_$i ||
15467                                         error "unlink error $i"
15468                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
15469                 [ $mtime2 -eq $mtime3 ] &&
15470                         error "mtime did not change after unlink"
15471         done
15472         true
15473 }
15474 run_test 300b "check ctime/mtime for striped dir"
15475
15476 test_300c() {
15477         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15478                 skip "skipped for lustre < 2.7.0" && return
15479         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15480         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15481         local file_count
15482
15483         mkdir -p $DIR/$tdir
15484         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
15485                 error "set striped dir error"
15486
15487         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
15488                 error "chown striped dir failed"
15489
15490         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
15491                 error "create 5k files failed"
15492
15493         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
15494
15495         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
15496
15497         rm -rf $DIR/$tdir
15498 }
15499 run_test 300c "chown && check ls under striped directory"
15500
15501 test_300d() {
15502         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
15503                 skip "skipped for lustre < 2.7.0" && return
15504         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15505         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15506         local stripe_count
15507         local file
15508
15509         mkdir -p $DIR/$tdir
15510         $SETSTRIPE -c 2 $DIR/$tdir
15511
15512         #local striped directory
15513         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15514                 error "set striped dir error"
15515         createmany -o $DIR/$tdir/striped_dir/f 10 ||
15516                 error "create 10 files failed"
15517
15518         #remote striped directory
15519         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
15520                 error "set striped dir error"
15521         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
15522                 error "create 10 files failed"
15523
15524         for file in $(find $DIR/$tdir); do
15525                 stripe_count=$($GETSTRIPE -c $file)
15526                 [ $stripe_count -eq 2 ] ||
15527                         error "wrong stripe $stripe_count for $file"
15528         done
15529
15530         rm -rf $DIR/$tdir
15531 }
15532 run_test 300d "check default stripe under striped directory"
15533
15534 test_300e() {
15535         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15536                 skip "Need MDS version at least 2.7.55" && return
15537         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15538         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15539         local stripe_count
15540         local file
15541
15542         mkdir -p $DIR/$tdir
15543
15544         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15545                 error "set striped dir error"
15546
15547         touch $DIR/$tdir/striped_dir/a
15548         touch $DIR/$tdir/striped_dir/b
15549         touch $DIR/$tdir/striped_dir/c
15550
15551         mkdir $DIR/$tdir/striped_dir/dir_a
15552         mkdir $DIR/$tdir/striped_dir/dir_b
15553         mkdir $DIR/$tdir/striped_dir/dir_c
15554
15555         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
15556                 error "set striped adir under striped dir error"
15557
15558         $LFS setdirstripe -i 0 -c 2 -H all_char $DIR/$tdir/striped_dir/stp_b ||
15559                 error "set striped bdir under striped dir error"
15560
15561         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
15562                 error "set striped cdir under striped dir error"
15563
15564         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
15565                 error "rename dir under striped dir fails"
15566
15567         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
15568                 error "rename dir under different stripes fails"
15569
15570         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
15571                 error "rename file under striped dir should succeed"
15572
15573         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
15574                 error "rename dir under striped dir should succeed"
15575
15576         rm -rf $DIR/$tdir
15577 }
15578 run_test 300e "check rename under striped directory"
15579
15580 test_300f() {
15581         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15582                 skip "Need MDS version at least 2.7.55" && return
15583         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15584         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15585         local stripe_count
15586         local file
15587
15588         rm -rf $DIR/$tdir
15589         mkdir -p $DIR/$tdir
15590
15591         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
15592                 error "set striped dir error"
15593
15594         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
15595                 error "set striped dir error"
15596
15597         touch $DIR/$tdir/striped_dir/a
15598         mkdir $DIR/$tdir/striped_dir/dir_a
15599         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
15600                 error "create striped dir under striped dir fails"
15601
15602         touch $DIR/$tdir/striped_dir1/b
15603         mkdir $DIR/$tdir/striped_dir1/dir_b
15604         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
15605                 error "create striped dir under striped dir fails"
15606
15607         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
15608                 error "rename dir under different striped dir should fail"
15609
15610         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
15611                 error "rename striped dir under diff striped dir should fail"
15612
15613         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
15614                 error "rename file under diff striped dirs fails"
15615
15616         rm -rf $DIR/$tdir
15617 }
15618 run_test 300f "check rename cross striped directory"
15619
15620 test_300_check_default_striped_dir()
15621 {
15622         local dirname=$1
15623         local default_count=$2
15624         local default_index=$3
15625         local stripe_count
15626         local stripe_index
15627         local dir_stripe_index
15628         local dir
15629
15630         echo "checking $dirname $default_count $default_index"
15631         $LFS setdirstripe -D -c $default_count -i $default_index \
15632                                 -t all_char $DIR/$tdir/$dirname ||
15633                 error "set default stripe on striped dir error"
15634         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
15635         [ $stripe_count -eq $default_count ] ||
15636                 error "expect $default_count get $stripe_count for $dirname"
15637
15638         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
15639         [ $stripe_index -eq $default_index ] ||
15640                 error "expect $default_index get $stripe_index for $dirname"
15641
15642         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
15643                                                 error "create dirs failed"
15644
15645         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
15646         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
15647         for dir in $(find $DIR/$tdir/$dirname/*); do
15648                 stripe_count=$($LFS getdirstripe -c $dir)
15649                 [ $stripe_count -eq $default_count ] ||
15650                 [ $stripe_count -eq 0 -o $default_count -eq 1 ] ||
15651                 error "stripe count $default_count != $stripe_count for $dir"
15652
15653                 stripe_index=$($LFS getdirstripe -i $dir)
15654                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
15655                         error "$stripe_index != $default_index for $dir"
15656
15657                 #check default stripe
15658                 stripe_count=$($LFS getdirstripe -D -c $dir)
15659                 [ $stripe_count -eq $default_count ] ||
15660                 error "default count $default_count != $stripe_count for $dir"
15661
15662                 stripe_index=$($LFS getdirstripe -D -i $dir)
15663                 [ $stripe_index -eq $default_index ] ||
15664                 error "default index $default_index != $stripe_index for $dir"
15665         done
15666         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
15667 }
15668
15669 test_300g() {
15670         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15671                 skip "Need MDS version at least 2.7.55" && return
15672         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15673         local dir
15674         local stripe_count
15675         local stripe_index
15676
15677         mkdir $DIR/$tdir
15678         mkdir $DIR/$tdir/normal_dir
15679
15680         #Checking when client cache stripe index
15681         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
15682         $LFS setdirstripe -D -i1 $DIR/$tdir/striped_dir ||
15683                 error "create striped_dir failed"
15684
15685         mkdir $DIR/$tdir/striped_dir/dir1 ||
15686                 error "create dir1 fails"
15687         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir1)
15688         [ $stripe_index -eq 1 ] ||
15689                 error "dir1 expect 1 got $stripe_index"
15690
15691         $LFS setdirstripe -i2 $DIR/$tdir/striped_dir/dir2 ||
15692                 error "create dir2 fails"
15693         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/dir2)
15694         [ $stripe_index -eq 2 ] ||
15695                 error "dir2 expect 2 got $stripe_index"
15696
15697         #check default stripe count/stripe index
15698         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
15699         test_300_check_default_striped_dir normal_dir 1 0
15700         test_300_check_default_striped_dir normal_dir 2 1
15701         test_300_check_default_striped_dir normal_dir 2 -1
15702
15703         #delete default stripe information
15704         echo "delete default stripeEA"
15705         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
15706                 error "set default stripe on striped dir error"
15707
15708         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
15709         for dir in $(find $DIR/$tdir/normal_dir/*); do
15710                 stripe_count=$($LFS getdirstripe -c $dir)
15711                 [ $stripe_count -eq 0 ] ||
15712                         error "expect 1 get $stripe_count for $dir"
15713                 stripe_index=$($LFS getdirstripe -i $dir)
15714                 [ $stripe_index -eq 0 ] ||
15715                         error "expect 0 get $stripe_index for $dir"
15716         done
15717 }
15718 run_test 300g "check default striped directory for normal directory"
15719
15720 test_300h() {
15721         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15722                 skip "Need MDS version at least 2.7.55" && return
15723         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15724         local dir
15725         local stripe_count
15726
15727         mkdir $DIR/$tdir
15728         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
15729                                         $DIR/$tdir/striped_dir ||
15730                 error "set striped dir error"
15731
15732         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
15733         test_300_check_default_striped_dir striped_dir 1 0
15734         test_300_check_default_striped_dir striped_dir 2 1
15735         test_300_check_default_striped_dir striped_dir 2 -1
15736
15737         #delete default stripe information
15738         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
15739                 error "set default stripe on striped dir error"
15740
15741         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
15742         for dir in $(find $DIR/$tdir/striped_dir/*); do
15743                 stripe_count=$($LFS getdirstripe -c $dir)
15744                 [ $stripe_count -eq 0 ] ||
15745                         error "expect 1 get $stripe_count for $dir"
15746         done
15747 }
15748 run_test 300h "check default striped directory for striped directory"
15749
15750 test_300i() {
15751         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15752                 skip "Need MDS version at least 2.7.55" && return
15753         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15754         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15755         local stripe_count
15756         local file
15757
15758         mkdir $DIR/$tdir
15759
15760         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
15761                 error "set striped dir error"
15762
15763         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
15764                 error "create files under striped dir failed"
15765
15766         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir ||
15767                 error "set striped hashdir error"
15768
15769         $LFS setdirstripe -i0 -c$MDSCOUNT -H all_char $DIR/$tdir/hashdir/d0 ||
15770                 error "create dir0 under hash dir failed"
15771         $LFS setdirstripe -i0 -c$MDSCOUNT -H fnv_1a_64 $DIR/$tdir/hashdir/d1 ||
15772                 error "create dir1 under hash dir failed"
15773
15774         # unfortunately, we need to umount to clear dir layout cache for now
15775         # once we fully implement dir layout, we can drop this
15776         umount_client $MOUNT || error "umount failed"
15777         mount_client $MOUNT || error "mount failed"
15778
15779         $LFS find -H fnv_1a_64 $DIR/$tdir/hashdir
15780         local dircnt=$($LFS find -H fnv_1a_64 $DIR/$tdir/hashdir | wc -l)
15781         [ $dircnt -eq 1 ] || error "lfs find striped dir got:$dircnt,except:1"
15782
15783         #set the stripe to be unknown hash type
15784         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
15785         $LCTL set_param fail_loc=0x1901
15786         for ((i = 0; i < 10; i++)); do
15787                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
15788                         error "stat f-$i failed"
15789                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
15790         done
15791
15792         touch $DIR/$tdir/striped_dir/f0 &&
15793                 error "create under striped dir with unknown hash should fail"
15794
15795         $LCTL set_param fail_loc=0
15796
15797         umount_client $MOUNT || error "umount failed"
15798         mount_client $MOUNT || error "mount failed"
15799
15800         return 0
15801 }
15802 run_test 300i "client handle unknown hash type striped directory"
15803
15804 test_300j() {
15805         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15806         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15807                 skip "Need MDS version at least 2.7.55" && return
15808         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15809         local stripe_count
15810         local file
15811
15812         mkdir $DIR/$tdir
15813
15814         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
15815         $LCTL set_param fail_loc=0x1702
15816         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
15817                 error "set striped dir error"
15818
15819         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
15820                 error "create files under striped dir failed"
15821
15822         $LCTL set_param fail_loc=0
15823
15824         rm -rf $DIR/$tdir || error "unlink striped dir fails"
15825
15826         return 0
15827 }
15828 run_test 300j "test large update record"
15829
15830 test_300k() {
15831         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15832                 skip "Need MDS version at least 2.7.55" && return
15833         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15834         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15835         local stripe_count
15836         local file
15837
15838         mkdir $DIR/$tdir
15839
15840         #define OBD_FAIL_LARGE_STRIPE   0x1703
15841         $LCTL set_param fail_loc=0x1703
15842         $LFS setdirstripe -i 0 -c512 $DIR/$tdir/striped_dir ||
15843                 error "set striped dir error"
15844         $LCTL set_param fail_loc=0
15845
15846         $LFS getdirstripe $DIR/$tdir/striped_dir ||
15847                 error "getstripeddir fails"
15848         rm -rf $DIR/$tdir/striped_dir ||
15849                 error "unlink striped dir fails"
15850
15851         return 0
15852 }
15853 run_test 300k "test large striped directory"
15854
15855 test_300l() {
15856         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15857                 skip "Need MDS version at least 2.7.55" && return
15858         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15859         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15860         local stripe_index
15861
15862         test_mkdir -p $DIR/$tdir/striped_dir
15863         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
15864                         error "chown $RUNAS_ID failed"
15865         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
15866                 error "set default striped dir failed"
15867
15868         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
15869         $LCTL set_param fail_loc=0x80000158
15870         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
15871
15872         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
15873         [ $stripe_index -eq 1 ] ||
15874                 error "expect 1 get $stripe_index for $dir"
15875 }
15876 run_test 300l "non-root user to create dir under striped dir with stale layout"
15877
15878 test_300m() {
15879         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15880                 skip "Need MDS version at least 2.7.55" && return
15881         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15882         [ $MDSCOUNT -ge 2 ] && skip "Only for single MDT" && return
15883
15884         mkdir -p $DIR/$tdir/striped_dir
15885         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
15886                 error "set default stripes dir error"
15887
15888         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
15889
15890         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
15891         [ $stripe_count -eq 0 ] ||
15892                         error "expect 0 get $stripe_count for a"
15893
15894         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
15895                 error "set default stripes dir error"
15896
15897         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
15898
15899         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
15900         [ $stripe_count -eq 0 ] ||
15901                         error "expect 0 get $stripe_count for b"
15902
15903         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
15904                 error "set default stripes dir error"
15905
15906         mkdir $DIR/$tdir/striped_dir/c &&
15907                 error "default stripe_index is invalid, mkdir c should fails"
15908
15909         rm -rf $DIR/$tdir || error "rmdir fails"
15910 }
15911 run_test 300m "setstriped directory on single MDT FS"
15912
15913 cleanup_300n() {
15914         local list=$(comma_list $(mdts_nodes))
15915
15916         trap 0
15917         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
15918 }
15919
15920 test_300n() {
15921         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15922                 skip "Need MDS version at least 2.7.55" && return
15923         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15924         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15925         remote_mds_nodsh && skip "remote MDS with nodsh" && return
15926
15927         local stripe_index
15928         local list=$(comma_list $(mdts_nodes))
15929
15930         trap cleanup_300n RETURN EXIT
15931         mkdir -p $DIR/$tdir
15932         chmod 777 $DIR/$tdir
15933         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
15934                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
15935                 error "create striped dir succeeds with gid=0"
15936
15937         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
15938         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
15939                 error "create striped dir fails with gid=-1"
15940
15941         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
15942         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
15943                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
15944                 error "set default striped dir succeeds with gid=0"
15945
15946
15947         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
15948         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
15949                 error "set default striped dir fails with gid=-1"
15950
15951
15952         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
15953         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
15954                                         error "create test_dir fails"
15955         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
15956                                         error "create test_dir1 fails"
15957         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
15958                                         error "create test_dir2 fails"
15959         cleanup_300n
15960 }
15961 run_test 300n "non-root user to create dir under striped dir with default EA"
15962
15963 test_300o() {
15964         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
15965                 skip "Need MDS version at least 2.7.55" && return
15966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
15967         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
15968         local numfree1
15969         local numfree2
15970
15971         mkdir -p $DIR/$tdir
15972
15973         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
15974         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
15975         if [ $numfree1 -lt 66000 -o $numfree2 -lt 66000 ]; then
15976                 skip "not enough free inodes $numfree1 $numfree2"
15977                 return
15978         fi
15979
15980         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
15981         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
15982         if [ $numfree1 -lt 300000 -o $numfree2 -lt 300000 ]; then
15983                 skip "not enough free space $numfree1 $numfree2"
15984                 return
15985         fi
15986
15987         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
15988                 error "setdirstripe fails"
15989
15990         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
15991                 error "create dirs fails"
15992
15993         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
15994         ls $DIR/$tdir/striped_dir > /dev/null ||
15995                 error "ls striped dir fails"
15996         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
15997                 error "unlink big striped dir fails"
15998 }
15999 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
16000
16001 test_300p() {
16002         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16003         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16004         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16005
16006         mkdir -p $DIR/$tdir
16007
16008         #define OBD_FAIL_OUT_ENOSPC     0x1704
16009         do_facet mds2 lctl set_param fail_loc=0x80001704
16010         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 &&
16011                         error "create striped directory should fail"
16012
16013         [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
16014
16015         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir
16016         true
16017 }
16018 run_test 300p "create striped directory without space"
16019
16020 test_300q() {
16021         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16022         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16023
16024         local fd=$(free_fd)
16025         local cmd="exec $fd<$tdir"
16026         cd $DIR
16027         $LFS mkdir -c $MDSCOUNT $tdir || error "create $tdir fails"
16028         eval $cmd
16029         cmd="exec $fd<&-"
16030         trap "eval $cmd" EXIT
16031         cd $tdir || error "cd $tdir fails"
16032         rmdir  ../$tdir || error "rmdir $tdir fails"
16033         mkdir local_dir && error "create dir succeeds"
16034         $LFS setdirstripe -i1 remote_dir && error "create remote dir succeeds"
16035         eval $cmd
16036         return 0
16037 }
16038 run_test 300q "create remote directory under orphan directory"
16039
16040 test_300r() {
16041         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
16042                 skip "Need MDS version at least 2.7.55" && return
16043         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16044
16045         mkdir $DIR/$tdir
16046
16047         $LFS setdirstripe -i 0 -c -1 $DIR/$tdir/striped_dir ||
16048                 error "set striped dir error"
16049
16050         $LFS getdirstripe $DIR/$tdir/striped_dir ||
16051                 error "getstripeddir fails"
16052
16053         local stripe_count
16054         stripe_count=$($LFS getdirstripe $DIR/$tdir/striped_dir |
16055                       awk '/lmv_stripe_count:/ { print $2 }')
16056
16057         [ $MDSCOUNT -ne $stripe_count ] &&
16058                 error "wrong stripe count $stripe_count expected $MDSCOUNT"
16059
16060         rm -rf $DIR/$tdir/striped_dir ||
16061                 error "unlink striped dir fails"
16062 }
16063 run_test 300r "test -1 striped directory"
16064
16065 prepare_remote_file() {
16066         mkdir $DIR/$tdir/src_dir ||
16067                 error "create remote source failed"
16068
16069         cp /etc/hosts $DIR/$tdir/src_dir/a || error
16070         touch $DIR/$tdir/src_dir/a
16071
16072         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
16073                 error "create remote target dir failed"
16074
16075         touch $DIR/$tdir/tgt_dir/b
16076
16077         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
16078                 error "rename dir cross MDT failed!"
16079
16080         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
16081                 error "src_child still exists after rename"
16082
16083         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
16084                 error "missing file(a) after rename"
16085
16086         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
16087                 error "diff after rename"
16088 }
16089
16090 test_310a() {
16091         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
16092         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16093         local remote_file=$DIR/$tdir/tgt_dir/b
16094
16095         mkdir -p $DIR/$tdir
16096
16097         prepare_remote_file || error "prepare remote file failed"
16098
16099         #open-unlink file
16100         $OPENUNLINK $remote_file $remote_file || error
16101         $CHECKSTAT -a $remote_file || error
16102 }
16103 run_test 310a "open unlink remote file"
16104
16105 test_310b() {
16106         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
16107         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16108         local remote_file=$DIR/$tdir/tgt_dir/b
16109
16110         mkdir -p $DIR/$tdir
16111
16112         prepare_remote_file || error "prepare remote file failed"
16113
16114         ln $remote_file $DIR/$tfile || error "link failed for remote file"
16115         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
16116         $CHECKSTAT -t file $remote_file || error "check file failed"
16117 }
16118 run_test 310b "unlink remote file with multiple links while open"
16119
16120 test_310c() {
16121         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
16122         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16123         local remote_file=$DIR/$tdir/tgt_dir/b
16124
16125         mkdir -p $DIR/$tdir
16126
16127         prepare_remote_file || error "prepare remote file failed"
16128
16129         ln $remote_file $DIR/$tfile || error "link failed for remote file"
16130         multiop_bg_pause $remote_file O_uc ||
16131                         error "mulitop failed for remote file"
16132         MULTIPID=$!
16133         $MULTIOP $DIR/$tfile Ouc
16134         kill -USR1 $MULTIPID
16135         wait $MULTIPID
16136 }
16137 run_test 310c "open-unlink remote file with multiple links"
16138
16139 #LU-4825
16140 test_311() {
16141         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
16142         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.54) ] &&
16143                 skip "lustre < 2.8.54 does not contain LU-4825 fix" && return
16144         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16145         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16146
16147         local old_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
16148
16149         mkdir -p $DIR/$tdir
16150         $SETSTRIPE -i 0 -c 1 $DIR/$tdir
16151         createmany -o $DIR/$tdir/$tfile. 1000
16152
16153         # statfs data is not real time, let's just calculate it
16154         old_iused=$((old_iused + 1000))
16155
16156         local count=$(do_facet $SINGLEMDS "lctl get_param -n \
16157                         osp.*OST0000*MDT0000.create_count")
16158         local max_count=$(do_facet $SINGLEMDS "lctl get_param -n \
16159                                 osp.*OST0000*MDT0000.max_create_count")
16160         for idx in $(seq $MDSCOUNT); do
16161                 do_facet mds$idx "lctl set_param -n \
16162                         osp.*OST0000*MDT000?.max_create_count=0"
16163         done
16164
16165         $SETSTRIPE -i 0 $DIR/$tdir/$tfile || error "setstripe failed"
16166         local index=$($GETSTRIPE -i $DIR/$tdir/$tfile)
16167         [ $index -ne 0 ] || error "$tfile stripe index is 0"
16168
16169         unlinkmany $DIR/$tdir/$tfile. 1000
16170
16171         for idx in $(seq $MDSCOUNT); do
16172                 do_facet mds$idx "lctl set_param -n \
16173                         osp.*OST0000*MDT000?.max_create_count=$max_count"
16174                 do_facet mds$idx "lctl set_param -n \
16175                         osp.*OST0000*MDT000?.create_count=$count"
16176         done
16177
16178         local new_iused
16179         for i in $(seq 120); do
16180                 new_iused=$($LFS df -i | grep OST0000 | awk '{ print $3 }')
16181                 # system may be too busy to destroy all objs in time, use
16182                 # a somewhat small value to not fail autotest
16183                 [ $((old_iused - new_iused)) -gt 400 ] && break
16184                 sleep 1
16185         done
16186
16187         echo "waited $i sec, old Iused $old_iused, new Iused $new_iused"
16188         [ $((old_iused - new_iused)) -gt 400 ] ||
16189                 error "objs not destroyed after unlink"
16190 }
16191 run_test 311 "disable OSP precreate, and unlink should destroy objs"
16192
16193 zfs_oid_to_objid()
16194 {
16195         local ost=$1
16196         local objid=$2
16197
16198         local vdevdir=$(dirname $(facet_vdevice $ost))
16199         local cmd="$ZDB -e -p $vdevdir -ddddd $(facet_device $ost)"
16200         local zfs_zapid=$(do_facet $ost $cmd |
16201                           grep -w "/O/0/d$((objid%32))" -C 5 |
16202                           awk '/Object/{getline; print $1}')
16203         local zfs_objid=$(do_facet $ost $cmd $zfs_zapid |
16204                           awk "/$objid = /"'{printf $3}')
16205
16206         echo $zfs_objid
16207 }
16208
16209 zfs_object_blksz() {
16210         local ost=$1
16211         local objid=$2
16212
16213         local vdevdir=$(dirname $(facet_vdevice $ost))
16214         local cmd="$ZDB -e -p $vdevdir -dddd $(facet_device $ost)"
16215         local blksz=$(do_facet $ost $cmd $objid |
16216                       awk '/dblk/{getline; printf $4}')
16217
16218         case "${blksz: -1}" in
16219                 k|K) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024)) ;;
16220                 m|M) blksz=$((${blksz:0:$((${#blksz} - 1))}*1024*1024)) ;;
16221                 *) ;;
16222         esac
16223
16224         echo $blksz
16225 }
16226
16227 test_312() { # LU-4856
16228         remote_ost_nodsh && skip "remote OST with nodsh" && return
16229
16230         [ $(facet_fstype ost1) = "zfs" ] ||
16231                 { skip "the test only applies to zfs" && return; }
16232
16233         local max_blksz=$(do_facet ost1 \
16234                           $ZFS get -p recordsize $(facet_device ost1) |
16235                           awk '!/VALUE/{print $3}')
16236         local min_blksz=$(getconf PAGE_SIZE)
16237
16238         # to make life a little bit easier
16239         $LFS mkdir -c 1 -i 0 $DIR/$tdir
16240         $LFS setstripe -c 1 -i 0 $DIR/$tdir
16241
16242         local tf=$DIR/$tdir/$tfile
16243         touch $tf
16244         local oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
16245
16246         # Get ZFS object id
16247         local zfs_objid=$(zfs_oid_to_objid ost1 $oid)
16248
16249         # block size change by sequential over write
16250         local blksz
16251         for ((bs=$min_blksz; bs <= max_blksz; bs <<= 2)); do
16252                 dd if=/dev/zero of=$tf bs=$bs count=1 oflag=sync conv=notrunc
16253
16254                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
16255                 [ $blksz -eq $bs ] || error "blksz error: $blksz, expected: $bs"
16256         done
16257         rm -f $tf
16258
16259         # block size change by sequential append write
16260         dd if=/dev/zero of=$tf bs=$min_blksz count=1 oflag=sync conv=notrunc
16261         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
16262         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
16263
16264         for ((count = 1; count < $((max_blksz / min_blksz)); count *= 2)); do
16265                 dd if=/dev/zero of=$tf bs=$min_blksz count=$count seek=$count \
16266                         oflag=sync conv=notrunc
16267
16268                 blksz=$(zfs_object_blksz ost1 $zfs_objid)
16269                 [ $blksz -eq $((2 * count * min_blksz)) ] ||
16270                         error "blksz error, actual $blksz, "    \
16271                                 "expected: 2 * $count * $min_blksz"
16272         done
16273         rm -f $tf
16274
16275         # random write
16276         touch $tf
16277         oid=$($LFS getstripe $tf | awk '/obdidx/{getline; print $2}')
16278         zfs_objid=$(zfs_oid_to_objid ost1 $oid)
16279
16280         dd if=/dev/zero of=$tf bs=1K count=1 oflag=sync conv=notrunc
16281         blksz=$(zfs_object_blksz ost1 $zfs_objid)
16282         [ $blksz -eq $min_blksz ] ||
16283                 error "blksz error: $blksz, expected: $min_blksz"
16284
16285         dd if=/dev/zero of=$tf bs=64K count=1 oflag=sync conv=notrunc seek=128
16286         blksz=$(zfs_object_blksz ost1 $zfs_objid)
16287         [ $blksz -eq 65536 ] || error "blksz error: $blksz, expected: 64k"
16288
16289         dd if=/dev/zero of=$tf bs=1M count=1 oflag=sync conv=notrunc
16290         blksz=$(zfs_object_blksz ost1 $zfs_objid)
16291         [ $blksz -eq 65536 ] || error "rewrite error: $blksz, expected: 64k"
16292 }
16293 run_test 312 "make sure ZFS adjusts its block size by write pattern"
16294
16295 test_313() {
16296         remote_ost_nodsh && skip "remote OST with nodsh" && return
16297
16298         local file=$DIR/$tfile
16299         rm -f $file
16300         $SETSTRIPE -c 1 -i 0 $file || error "setstripe failed"
16301
16302         # define OBD_FAIL_TGT_RCVD_EIO           0x720
16303         do_facet ost1 "$LCTL set_param fail_loc=0x720"
16304         dd if=/dev/zero of=$file bs=4096 oflag=direct count=1 &&
16305                 error "write should failed"
16306         do_facet ost1 "$LCTL set_param fail_loc=0"
16307         rm -f $file
16308 }
16309 run_test 313 "io should fail after last_rcvd update fail"
16310
16311 test_314() {
16312         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
16313
16314         $SETSTRIPE -c 2 -i 0 $DIR/$tfile || error "setstripe failed"
16315         do_facet ost1 "$LCTL set_param fail_loc=0x720"
16316         rm -f $DIR/$tfile
16317         wait_delete_completed
16318         do_facet ost1 "$LCTL set_param fail_loc=0"
16319 }
16320 run_test 314 "OSP shouldn't fail after last_rcvd update failure"
16321
16322 test_315() { # LU-618
16323         local file=$DIR/$tfile
16324         rm -f $file
16325
16326         $MULTIOP $file oO_CREAT:O_DIRECT:O_RDWR:w4096000c
16327         $MULTIOP $file oO_RDONLY:r4096000_c &
16328         PID=$!
16329
16330         sleep 2
16331
16332         local rbytes=$(awk '/read_bytes/ { print $2 }' /proc/$PID/io)
16333         kill -USR1 $PID
16334
16335         [ $rbytes -gt 4000000 ] || error "read is not accounted ($rbytes)"
16336         rm -f $file
16337 }
16338 run_test 315 "read should be accounted"
16339
16340 test_fake_rw() {
16341         local read_write=$1
16342         if [ "$read_write" = "write" ]; then
16343                 local dd_cmd="dd if=/dev/zero of=$DIR/$tfile"
16344         elif [ "$read_write" = "read" ]; then
16345                 local dd_cmd="dd of=/dev/null if=$DIR/$tfile"
16346         else
16347                 error "argument error"
16348         fi
16349
16350         # turn off debug for performance testing
16351         local saved_debug=$($LCTL get_param -n debug)
16352         $LCTL set_param debug=0
16353
16354         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
16355
16356         # get ost1 size - lustre-OST0000
16357         local ost1_avail_size=$($LFS df | awk /${ost1_svc}/'{ print $4 }')
16358         local blocks=$((ost1_avail_size/2/1024)) # half avail space by megabytes
16359         [ $blocks -gt 1000 ] && blocks=1000 # 1G in maximum
16360
16361         if [ "$read_write" = "read" ]; then
16362                 truncate -s $(expr 1048576 \* $blocks) $DIR/$tfile
16363         fi
16364
16365         local start_time=$(date +%s.%N)
16366         $dd_cmd bs=1M count=$blocks oflag=sync ||
16367                 error "real dd $read_write error"
16368         local duration=$(bc <<< "$(date +%s.%N) - $start_time")
16369
16370         if [ "$read_write" = "write" ]; then
16371                 rm -f $DIR/$tfile
16372         fi
16373
16374         # define OBD_FAIL_OST_FAKE_RW           0x238
16375         do_facet ost1 $LCTL set_param fail_loc=0x238
16376
16377         local start_time=$(date +%s.%N)
16378         $dd_cmd bs=1M count=$blocks oflag=sync ||
16379                 error "fake dd $read_write error"
16380         local duration_fake=$(bc <<< "$(date +%s.%N) - $start_time")
16381
16382         if [ "$read_write" = "write" ]; then
16383                 # verify file size
16384                 cancel_lru_locks osc
16385                 $CHECKSTAT -t file -s $((blocks * 1024 * 1024)) $DIR/$tfile ||
16386                         error "$tfile size not $blocks MB"
16387         fi
16388         do_facet ost1 $LCTL set_param fail_loc=0
16389
16390         echo "fake $read_write $duration_fake vs. normal $read_write" \
16391                 "$duration in seconds"
16392         [ $(bc <<< "$duration_fake < $duration") -eq 1 ] ||
16393                 error_not_in_vm "fake write is slower"
16394
16395         $LCTL set_param -n debug="$saved_debug"
16396         rm -f $DIR/$tfile
16397 }
16398 test_399a() { # LU-7655 for OST fake write
16399         remote_ost_nodsh && skip "remote OST with nodsh" && return
16400
16401         test_fake_rw write
16402 }
16403 run_test 399a "fake write should not be slower than normal write"
16404
16405 test_399b() { # LU-8726 for OST fake read
16406         remote_ost_nodsh && skip "remote OST with nodsh" && return
16407
16408         if [ "$(facet_fstype ost1)" != "ldiskfs" ]; then
16409                 skip "ldiskfs only test" && return 0
16410         fi
16411         test_fake_rw read
16412 }
16413 run_test 399b "fake read should not be slower than normal read"
16414
16415 test_400a() { # LU-1606, was conf-sanity test_74
16416         local extra_flags=''
16417         local out=$TMP/$tfile
16418         local prefix=/usr/include/lustre
16419         local prog
16420
16421         if ! which $CC > /dev/null 2>&1; then
16422                 skip_env "$CC is not installed"
16423                 return 0
16424         fi
16425
16426         if ! [[ -d $prefix ]]; then
16427                 # Assume we're running in tree and fixup the include path.
16428                 extra_flags+=" -I$LUSTRE/../libcfs/include"
16429                 extra_flags+=" -I$LUSTRE/include"
16430                 extra_flags+=" -L$LUSTRE/utils"
16431         fi
16432
16433         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
16434                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
16435                         error "client api broken"
16436         done
16437         rm -f $out
16438 }
16439 run_test 400a "Lustre client api program can compile and link"
16440
16441 test_400b() { # LU-1606, LU-5011
16442         local header
16443         local out=$TMP/$tfile
16444         local prefix=/usr/include/lustre
16445
16446         # We use a hard coded prefix so that this test will not fail
16447         # when run in tree. There are headers in lustre/include/lustre/
16448         # that are not packaged (like lustre_idl.h) and have more
16449         # complicated include dependencies (like config.h and lnet/types.h).
16450         # Since this test about correct packaging we just skip them when
16451         # they don't exist (see below) rather than try to fixup cppflags.
16452
16453         if ! which $CC > /dev/null 2>&1; then
16454                 skip_env "$CC is not installed"
16455                 return 0
16456         fi
16457
16458         for header in $prefix/*.h; do
16459                 if ! [[ -f "$header" ]]; then
16460                         continue
16461                 fi
16462
16463                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
16464                         continue # liblustreapi.h is deprecated.
16465                 fi
16466
16467                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
16468                         error "cannot compile '$header'"
16469         done
16470         rm -f $out
16471 }
16472 run_test 400b "packaged headers can be compiled"
16473
16474 test_401a() { #LU-7437
16475         local printf_arg=$(find -printf 2>&1 | grep "unrecognized:")
16476         [ -n "$printf_arg" ] && skip_env "find does not support -printf" &&
16477                 return
16478         #count the number of parameters by "list_param -R"
16479         local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
16480         #count the number of parameters by listing proc files
16481         local proc_dirs=$(eval \ls -d $proc_regexp 2>/dev/null)
16482         echo "proc_dirs='$proc_dirs'"
16483         [ -n "$proc_dirs" ] || error "no proc_dirs on $HOSTNAME"
16484         local procs=$(find -L $proc_dirs -mindepth 1 -printf '%P\n' 2>/dev/null|
16485                       sort -u | wc -l)
16486
16487         [ $params -eq $procs ] ||
16488                 error "found $params parameters vs. $procs proc files"
16489
16490         # test the list_param -D option only returns directories
16491         params=$($LCTL list_param -R -D '*' 2>/dev/null | wc -l)
16492         #count the number of parameters by listing proc directories
16493         procs=$(find -L $proc_dirs -mindepth 1 -type d -printf '%P\n' 2>/dev/null |
16494                 sort -u | wc -l)
16495
16496         [ $params -eq $procs ] ||
16497                 error "found $params parameters vs. $procs proc files"
16498 }
16499 run_test 401a "Verify if 'lctl list_param -R' can list parameters recursively"
16500
16501 test_401b() {
16502         local save=$($LCTL get_param -n jobid_var)
16503         local tmp=testing
16504
16505         $LCTL set_param foo=bar jobid_var=$tmp bar=baz &&
16506                 error "no error returned when setting bad parameters"
16507
16508         local jobid_new=$($LCTL get_param -n foe jobid_var baz)
16509         [[ "$jobid_new" == "$tmp" ]] || error "jobid tmp $jobid_new != $tmp"
16510
16511         $LCTL set_param -n fog=bam jobid_var=$save bat=fog
16512         local jobid_old=$($LCTL get_param -n foe jobid_var bag)
16513         [[ "$jobid_old" == "$save" ]] || error "jobid new $jobid_old != $save"
16514 }
16515 run_test 401b "Verify 'lctl {get,set}_param' continue after error"
16516
16517 test_401c() {
16518         local jobid_var_old=$($LCTL get_param -n jobid_var)
16519         local jobid_var_new
16520
16521         $LCTL set_param jobid_var= &&
16522                 error "no error returned for 'set_param a='"
16523
16524         jobid_var_new=$($LCTL get_param -n jobid_var)
16525         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
16526                 error "jobid_var was changed by setting without value"
16527
16528         $LCTL set_param jobid_var &&
16529                 error "no error returned for 'set_param a'"
16530
16531         jobid_var_new=$($LCTL get_param -n jobid_var)
16532         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
16533                 error "jobid_var was changed by setting without value"
16534 }
16535 run_test 401c "Verify 'lctl set_param' without value fails in either format."
16536
16537 test_401d() {
16538         local jobid_var_old=$($LCTL get_param -n jobid_var)
16539         local jobid_var_new
16540         local new_value="foo=bar"
16541
16542         $LCTL set_param jobid_var=$new_value ||
16543                 error "'set_param a=b' did not accept a value containing '='"
16544
16545         jobid_var_new=$($LCTL get_param -n jobid_var)
16546         [[ "$jobid_var_new" == "$new_value" ]] ||
16547                 error "'set_param a=b' failed on a value containing '='"
16548
16549         # Reset the jobid_var to test the other format
16550         $LCTL set_param jobid_var=$jobid_var_old
16551         jobid_var_new=$($LCTL get_param -n jobid_var)
16552         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
16553                 error "failed to reset jobid_var"
16554
16555         $LCTL set_param jobid_var $new_value ||
16556                 error "'set_param a b' did not accept a value containing '='"
16557
16558         jobid_var_new=$($LCTL get_param -n jobid_var)
16559         [[ "$jobid_var_new" == "$new_value" ]] ||
16560                 error "'set_param a b' failed on a value containing '='"
16561
16562         $LCTL set_param jobid_var $jobid_var_old
16563         jobid_var_new=$($LCTL get_param -n jobid_var)
16564         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
16565                 error "failed to reset jobid_var"
16566 }
16567 run_test 401d "Verify 'lctl set_param' accepts values containing '='"
16568
16569 test_402() {
16570         local server_version=$(lustre_version_code $SINGLEMDS)
16571         [[ $server_version -ge $(version_code 2.7.66) ]] ||
16572         [[ $server_version -ge $(version_code 2.7.18.4) &&
16573                 $server_version -lt $(version_code 2.7.50) ]] ||
16574         [[ $server_version -ge $(version_code 2.7.2) &&
16575                 $server_version -lt $(version_code 2.7.11) ]] ||
16576                 { skip "Need MDS version 2.7.2+ or 2.7.18.4+ or 2.7.66+";
16577                         return; }
16578         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16579         $LFS setdirstripe -i 0 $DIR/$tdir || error "setdirstripe -i 0 failed"
16580 #define OBD_FAIL_MDS_FLD_LOOKUP 0x15c
16581         do_facet mds1 "lctl set_param fail_loc=0x8000015c"
16582         touch $DIR/$tdir/$tfile && error "touch should fail with ENOENT" ||
16583                 echo "Touch failed - OK"
16584 }
16585 run_test 402 "Return ENOENT to lod_generate_and_set_lovea"
16586
16587 test_403() {
16588         local file1=$DIR/$tfile.1
16589         local file2=$DIR/$tfile.2
16590         local tfile=$TMP/$tfile
16591
16592         rm -f $file1 $file2 $tfile
16593
16594         touch $file1
16595         ln $file1 $file2
16596
16597         # 30 sec OBD_TIMEOUT in ll_getattr()
16598         # right before populating st_nlink
16599         $LCTL set_param fail_loc=0x80001409
16600         stat -c %h $file1 > $tfile &
16601
16602         # create an alias, drop all locks and reclaim the dentry
16603         < $file2
16604         cancel_lru_locks mdc
16605         cancel_lru_locks osc
16606         sysctl -w vm.drop_caches=2
16607
16608         wait
16609
16610         [ `cat $tfile` -gt 0 ] || error "wrong nlink count: `cat $tfile`"
16611
16612         rm -f $tfile $file1 $file2
16613 }
16614 run_test 403 "i_nlink should not drop to zero due to aliasing"
16615
16616 test_404() { # LU-6601
16617         local server_version=$(lustre_version_code $SINGLEMDS)
16618         [[ $server_version -ge $(version_code 2.8.53) ]] ||
16619                 { skip "Need server version newer than 2.8.52"; return 0; }
16620
16621         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16622         local mosps=$(do_facet $SINGLEMDS $LCTL dl |
16623                 awk '/osp .*-osc-MDT/ { print $4}')
16624
16625         local osp
16626         for osp in $mosps; do
16627                 echo "Deactivate: " $osp
16628                 do_facet $SINGLEMDS $LCTL --device %$osp deactivate
16629                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
16630                         awk -vp=$osp '$4 == p { print $2 }')
16631                 [ $stat = IN ] || {
16632                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
16633                         error "deactivate error"
16634                 }
16635                 echo "Activate: " $osp
16636                 do_facet $SINGLEMDS $LCTL --device %$osp activate
16637                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
16638                         awk -vp=$osp '$4 == p { print $2 }')
16639                 [ $stat = UP ] || {
16640                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
16641                         error "activate error"
16642                 }
16643         done
16644 }
16645 run_test 404 "validate manual {de}activated works properly for OSPs"
16646
16647 test_405() {
16648         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) -o \
16649         [ $(lustre_version_code client) -lt $(version_code 2.6.99) ] &&
16650                 skip "Layout swap lock is not supported" && return
16651
16652         check_swap_layouts_support && return 0
16653
16654         test_mkdir -p $DIR/$tdir
16655         swap_lock_test -d $DIR/$tdir ||
16656                 error "One layout swap locked test failed"
16657 }
16658 run_test 405 "Various layout swap lock tests"
16659
16660 test_406() {
16661         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16662         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
16663         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
16664         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
16665         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.50) ] &&
16666                 skip "Need MDS version at least 2.8.50" && return
16667
16668         local def_stripe_count=$($GETSTRIPE -c $MOUNT)
16669         local def_stripe_size=$($GETSTRIPE -S $MOUNT)
16670         local def_stripe_offset=$($GETSTRIPE -i $MOUNT)
16671         local def_pool=$($GETSTRIPE -p $MOUNT)
16672         local test_pool=$TESTNAME
16673
16674         if ! combined_mgs_mds ; then
16675                 mount_mgs_client
16676         fi
16677         pool_add $test_pool || error "pool_add failed"
16678         pool_add_targets $test_pool 0 $(($OSTCOUNT - 1)) 1 ||
16679                 error "pool_add_targets failed"
16680
16681         # parent set default stripe count only, child will stripe from both
16682         # parent and fs default
16683         $SETSTRIPE -c 1 -i 1 -S $((def_stripe_size * 2)) -p $test_pool $MOUNT ||
16684                 error "setstripe $MOUNT failed"
16685         $LFS mkdir -c $MDSCOUNT $DIR/$tdir || error "mkdir $tdir failed"
16686         $SETSTRIPE -c $OSTCOUNT $DIR/$tdir || error "setstripe $tdir failed"
16687         for i in $(seq 10); do
16688                 local f=$DIR/$tdir/$tfile.$i
16689                 touch $f || error "touch failed"
16690                 local count=$($GETSTRIPE -c $f)
16691                 [ $count -eq $OSTCOUNT ] ||
16692                         error "$f stripe count $count != $OSTCOUNT"
16693                 local offset=$($GETSTRIPE -i $f)
16694                 [ $offset -eq 1 ] || error "$f stripe offset $offset != 1"
16695                 local size=$($GETSTRIPE -S $f)
16696                 [ $size -eq $((def_stripe_size * 2)) ] ||
16697                         error "$f stripe size $size != $((def_stripe_size * 2))"
16698                 local pool=$($GETSTRIPE -p $f)
16699                 [ $pool == $test_pool ] || error "$f pool $pool != $test_pool"
16700         done
16701
16702         # change fs default striping, delete parent default striping, now child
16703         # will stripe from new fs default striping only
16704         $SETSTRIPE -c 1 -S $def_stripe_size -i 0 $MOUNT ||
16705                 error "change $MOUNT default stripe failed"
16706         $SETSTRIPE -c 0 $DIR/$tdir || error "delete $tdir default stripe failed"
16707         for i in $(seq 11 20); do
16708                 local f=$DIR/$tdir/$tfile.$i
16709                 touch $f || error "touch $f failed"
16710                 local count=$($GETSTRIPE -c $f)
16711                 [ $count -eq 1 ] || error "$f stripe count $count != 1"
16712                 local offset=$($GETSTRIPE -i $f)
16713                 [ $offset -eq 0 ] || error "$f stripe offset $offset != 0"
16714                 local size=$($GETSTRIPE -S $f)
16715                 [ $size -eq $def_stripe_size ] ||
16716                         error "$f stripe size $size != $def_stripe_size"
16717                 local pool=$($GETSTRIPE -p $f)
16718                 [ $pool == $test_pool ] || error "$f pool $pool isn't set"
16719
16720         done
16721
16722         unlinkmany $DIR/$tdir/$tfile. 1 20
16723
16724         # restore FS default striping
16725         if [ -z $def_pool ]; then
16726                 $SETSTRIPE -c $def_stripe_count -S $def_stripe_size \
16727                         -i $def_stripe_offset $MOUNT ||
16728                         error "restore default striping failed"
16729         else
16730                 $SETSTRIPE -c $def_stripe_count -S $def_stripe_size \
16731                         -i $def_stripe_offset -p $def_pool $MOUNT ||
16732                         error "restore default striping with $def_pool failed"
16733         fi
16734
16735         local f=$DIR/$tdir/$tfile
16736         pool_remove_all_targets $test_pool $f
16737         pool_remove $test_pool $f
16738
16739         if ! combined_mgs_mds ; then
16740                 umount_mgs_client
16741         fi
16742 }
16743 run_test 406 "DNE support fs default striping"
16744
16745 test_407() {
16746         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
16747         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.55) ]] &&
16748                 skip "Need MDS version at least 2.8.55" && return
16749         remote_mds_nodsh && skip "remote MDS with nodsh" && return
16750
16751         $LFS mkdir -i 0 -c 1 $DIR/$tdir.0 ||
16752                 error "$LFS mkdir -i 0 -c 1 $tdir.0 failed"
16753         $LFS mkdir -i 1 -c 1 $DIR/$tdir.1 ||
16754                 error "$LFS mkdir -i 1 -c 1 $tdir.1 failed"
16755         touch $DIR/$tdir.0/$tfile.0 || error "touch $tdir.0/$tfile.0 failed"
16756
16757         #define OBD_FAIL_DT_TXN_STOP    0x2019
16758         for idx in $(seq $MDSCOUNT); do
16759                 do_facet mds$idx "lctl set_param fail_loc=0x2019"
16760         done
16761         $LFS mkdir -c 2 $DIR/$tdir && error "$LFS mkdir -c 2 $tdir should fail"
16762         mv $DIR/$tdir.0/$tfile.0 $DIR/$tdir.1/$tfile.1 &&
16763                 error "mv $tdir.0/$tfile.0 $tdir.1/$tfile.1 should fail"
16764         true
16765 }
16766 run_test 407 "transaction fail should cause operation fail"
16767
16768 test_408() {
16769         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 oflag=direct
16770
16771         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
16772         lctl set_param fail_loc=0x8000040a
16773         # let ll_prepare_partial_page() fail
16774         dd if=/dev/zero of=$DIR/$tfile bs=2048 count=1 conv=notrunc || true
16775
16776         rm -f $DIR/$tfile
16777
16778         # create at least 100 unused inodes so that
16779         # shrink_icache_memory(0) should not return 0
16780         touch $DIR/$tfile-{0..100}
16781         rm -f $DIR/$tfile-{0..100}
16782         sync
16783
16784         echo 2 > /proc/sys/vm/drop_caches
16785 }
16786 run_test 408 "drop_caches should not hang due to page leaks"
16787
16788 test_409()
16789 {
16790         [ $MDSCOUNT -lt 2 ] &&
16791                 skip "We need at least 2 MDTs for this test" && return
16792
16793         check_mount_and_prep
16794
16795         mkdir -p $DIR/$tdir || error "(0) Fail to mkdir"
16796         $LFS mkdir -i 1 -c 2 $DIR/$tdir/foo || error "(1) Fail to mkdir"
16797         touch $DIR/$tdir/guard || error "(2) Fail to create"
16798
16799         local PREFIX=$(str_repeat 'A' 128)
16800         echo "Create 1K hard links start at $(date)"
16801         createmany -l $DIR/$tdir/guard $DIR/$tdir/foo/${PREFIX}_ 1000 ||
16802                 error "(3) Fail to hard link"
16803
16804         echo "Links count should be right although linkEA overflow"
16805         stat $DIR/$tdir/guard || error "(4) Fail to stat"
16806         local linkcount=$(stat --format=%h $DIR/$tdir/guard)
16807         [ $linkcount -eq 1001 ] ||
16808                 error "(5) Unexpected hard links count: $linkcount"
16809
16810         echo "List all links start at $(date)"
16811         ls -l $DIR/$tdir/foo > /dev/null ||
16812                 error "(6) Fail to list $DIR/$tdir/foo"
16813
16814         echo "Unlink hard links start at $(date)"
16815         unlinkmany $DIR/$tdir/foo/${PREFIX}_ 1000 ||
16816                 error "(7) Fail to unlink"
16817 }
16818 run_test 409 "Large amount of cross-MDTs hard links on the same file"
16819
16820 test_410()
16821 {
16822         [[ $(lustre_version_code client) -lt $(version_code 2.9.59) ]] &&
16823                 skip "Need client version at least 2.9.59" && return
16824
16825         # Create a file, and stat it from the kernel
16826         local testfile=$DIR/$tfile
16827         touch $testfile
16828
16829         local run_id=$RANDOM
16830         local my_ino=$(stat --format "%i" $testfile)
16831
16832         # Try to insert the module. This will always fail as the
16833         # module is designed to not be inserted.
16834         insmod $LUSTRE/tests/kernel/kinode.ko run_id=$run_id fname=$testfile \
16835             &> /dev/null
16836
16837         # Anything but success is a test failure
16838         dmesg | grep -q \
16839             "lustre_kinode_$run_id: inode numbers are identical: $my_ino" ||
16840             error "no inode match"
16841 }
16842 run_test 410 "Test inode number returned from kernel thread"
16843
16844 prep_801() {
16845         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
16846         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
16847                 skip "Need server version at least 2.9.55" & exit 0
16848         start_full_debug_logging
16849 }
16850
16851 post_801() {
16852         stop_full_debug_logging
16853 }
16854
16855 barrier_stat() {
16856         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
16857                 local st=$(do_facet mgs $LCTL barrier_stat $FSNAME |
16858                            awk '/The barrier for/ { print $7 }')
16859                 echo $st
16860         else
16861                 local st=$(do_facet mgs $LCTL barrier_stat -s $FSNAME)
16862                 echo \'$st\'
16863         fi
16864 }
16865
16866 barrier_expired() {
16867         local expired
16868
16869         if [ $(lustre_version_code mgs) -le $(version_code 2.10.0) ]; then
16870                 expired=$(do_facet mgs $LCTL barrier_stat $FSNAME |
16871                           awk '/will be expired/ { print $7 }')
16872         else
16873                 expired=$(do_facet mgs $LCTL barrier_stat -t $FSNAME)
16874         fi
16875
16876         echo $expired
16877 }
16878
16879 test_801a() {
16880         prep_801
16881
16882         echo "Start barrier_freeze at: $(date)"
16883         #define OBD_FAIL_BARRIER_DELAY          0x2202
16884         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
16885         do_facet mgs $LCTL barrier_freeze $FSNAME 10 &
16886
16887         sleep 2
16888         local b_status=$(barrier_stat)
16889         echo "Got barrier status at: $(date)"
16890         [ "$b_status" = "'freezing_p1'" ] ||
16891                 error "(1) unexpected barrier status $b_status"
16892
16893         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
16894         wait
16895         b_status=$(barrier_stat)
16896         [ "$b_status" = "'frozen'" ] ||
16897                 error "(2) unexpected barrier status $b_status"
16898
16899         local expired=$(barrier_expired)
16900         echo "sleep $((expired + 3)) seconds, then the barrier will be expired"
16901         sleep $((expired + 3))
16902
16903         b_status=$(barrier_stat)
16904         [ "$b_status" = "'expired'" ] ||
16905                 error "(3) unexpected barrier status $b_status"
16906
16907         do_facet mgs $LCTL barrier_freeze $FSNAME 10 ||
16908                 error "(4) fail to freeze barrier"
16909
16910         b_status=$(barrier_stat)
16911         [ "$b_status" = "'frozen'" ] ||
16912                 error "(5) unexpected barrier status $b_status"
16913
16914         echo "Start barrier_thaw at: $(date)"
16915         #define OBD_FAIL_BARRIER_DELAY          0x2202
16916         do_facet mgs $LCTL set_param fail_val=5 fail_loc=0x2202
16917         do_facet mgs $LCTL barrier_thaw $FSNAME &
16918
16919         sleep 2
16920         b_status=$(barrier_stat)
16921         echo "Got barrier status at: $(date)"
16922         [ "$b_status" = "'thawing'" ] ||
16923                 error "(6) unexpected barrier status $b_status"
16924
16925         do_facet mgs $LCTL set_param fail_val=0 fail_loc=0
16926         wait
16927         b_status=$(barrier_stat)
16928         [ "$b_status" = "'thawed'" ] ||
16929                 error "(7) unexpected barrier status $b_status"
16930
16931         #define OBD_FAIL_BARRIER_FAILURE        0x2203
16932         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2203
16933         do_facet mgs $LCTL barrier_freeze $FSNAME
16934
16935         b_status=$(barrier_stat)
16936         [ "$b_status" = "'failed'" ] ||
16937                 error "(8) unexpected barrier status $b_status"
16938
16939         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
16940         do_facet mgs $LCTL barrier_thaw $FSNAME
16941
16942         post_801
16943 }
16944 run_test 801a "write barrier user interfaces and stat machine"
16945
16946 test_801b() {
16947         prep_801
16948
16949         mkdir $DIR/$tdir || error "(1) fail to mkdir"
16950         createmany -d $DIR/$tdir/d 6 || "(2) fail to mkdir"
16951         touch $DIR/$tdir/d2/f10 || error "(3) fail to touch"
16952         touch $DIR/$tdir/d3/f11 || error "(4) fail to touch"
16953         touch $DIR/$tdir/d4/f12 || error "(5) fail to touch"
16954
16955         cancel_lru_locks mdc
16956
16957         # 180 seconds should be long enough
16958         do_facet mgs $LCTL barrier_freeze $FSNAME 180
16959
16960         local b_status=$(barrier_stat)
16961         [ "$b_status" = "'frozen'" ] ||
16962                 error "(6) unexpected barrier status $b_status"
16963
16964         mkdir $DIR/$tdir/d0/d10 &
16965         mkdir_pid=$!
16966
16967         touch $DIR/$tdir/d1/f13 &
16968         touch_pid=$!
16969
16970         ln $DIR/$tdir/d2/f10 $DIR/$tdir/d2/f14 &
16971         ln_pid=$!
16972
16973         mv $DIR/$tdir/d3/f11 $DIR/$tdir/d3/f15 &
16974         mv_pid=$!
16975
16976         rm -f $DIR/$tdir/d4/f12 &
16977         rm_pid=$!
16978
16979         stat $DIR/$tdir/d5 || error "(7) stat should succeed"
16980
16981         # To guarantee taht the 'stat' is not blocked
16982         b_status=$(barrier_stat)
16983         [ "$b_status" = "'frozen'" ] ||
16984                 error "(8) unexpected barrier status $b_status"
16985
16986         # let above commands to run at background
16987         sleep 5
16988
16989         ps -p $mkdir_pid || error "(9) mkdir should be blocked"
16990         ps -p $touch_pid || error "(10) touch should be blocked"
16991         ps -p $ln_pid || error "(11) link should be blocked"
16992         ps -p $mv_pid || error "(12) rename should be blocked"
16993         ps -p $rm_pid || error "(13) unlink should be blocked"
16994
16995         b_status=$(barrier_stat)
16996         [ "$b_status" = "'frozen'" ] ||
16997                 error "(14) unexpected barrier status $b_status"
16998
16999         do_facet mgs $LCTL barrier_thaw $FSNAME
17000         b_status=$(barrier_stat)
17001         [ "$b_status" = "'thawed'" ] ||
17002                 error "(15) unexpected barrier status $b_status"
17003
17004         wait $mkdir_pid || error "(16) mkdir should succeed"
17005         wait $touch_pid || error "(17) touch should succeed"
17006         wait $ln_pid || error "(18) link should succeed"
17007         wait $mv_pid || error "(19) rename should succeed"
17008         wait $rm_pid || error "(20) unlink should succeed"
17009
17010         post_801
17011 }
17012 run_test 801b "modification will be blocked by write barrier"
17013
17014 test_801c() {
17015         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
17016
17017         prep_801
17018
17019         stop mds2 || error "(1) Fail to stop mds2"
17020
17021         do_facet mgs $LCTL barrier_freeze $FSNAME 30
17022
17023         local b_status=$(barrier_stat)
17024         [ "$b_status" = "'expired'" -o "$b_status" = "'failed'" ] || {
17025                 do_facet mgs $LCTL barrier_thaw $FSNAME
17026                 error "(2) unexpected barrier status $b_status"
17027         }
17028
17029         do_facet mgs $LCTL barrier_rescan $FSNAME ||
17030                 error "(3) Fail to rescan barrier bitmap"
17031
17032         do_facet mgs $LCTL barrier_freeze $FSNAME 10
17033
17034         b_status=$(barrier_stat)
17035         [ "$b_status" = "'frozen'" ] ||
17036                 error "(4) unexpected barrier status $b_status"
17037
17038         do_facet mgs $LCTL barrier_thaw $FSNAME
17039         b_status=$(barrier_stat)
17040         [ "$b_status" = "'thawed'" ] ||
17041                 error "(5) unexpected barrier status $b_status"
17042
17043         local devname=$(mdsdevname 2)
17044
17045         start mds2 $devname $MDS_MOUNT_OPTS || error "(6) Fail to start mds2"
17046
17047         do_facet mgs $LCTL barrier_rescan $FSNAME ||
17048                 error "(7) Fail to rescan barrier bitmap"
17049
17050         post_801
17051 }
17052 run_test 801c "rescan barrier bitmap"
17053
17054 saved_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
17055 saved_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
17056 saved_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
17057
17058 cleanup_802() {
17059         trap 0
17060
17061         stopall
17062         MGS_MOUNT_OPTS=$saved_MGS_MOUNT_OPTS
17063         MDS_MOUNT_OPTS=$saved_MDS_MOUNT_OPTS
17064         OST_MOUNT_OPTS=$saved_OST_MOUNT_OPTS
17065         setupall
17066 }
17067
17068 test_802() {
17069
17070         [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] ||
17071         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] &&
17072                 skip "Need server version at least 2.9.55" & exit 0
17073
17074         mkdir $DIR/$tdir || error "(1) fail to mkdir"
17075
17076         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
17077                 error "(2) Fail to copy"
17078
17079         trap cleanup_802 EXIT
17080
17081         # sync by force before remount as readonly
17082         sync; sync_all_data; sleep 3; sync_all_data
17083
17084         stopall
17085
17086         MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
17087         MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
17088         OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
17089
17090         echo "Mount the server as read only"
17091         setupall server_only || error "(3) Fail to start servers"
17092
17093         echo "Mount client without ro should fail"
17094         mount_client $MOUNT &&
17095                 error "(4) Mount client without 'ro' should fail"
17096
17097         echo "Mount client with ro should succeed"
17098         mount_client $MOUNT ro ||
17099                 error "(5) Mount client with 'ro' should succeed"
17100
17101         echo "Modify should be refused"
17102         touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
17103
17104         echo "Read should be allowed"
17105         diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
17106                 error "(7) Read should succeed under ro mode"
17107
17108         cleanup_802
17109 }
17110 run_test 802 "simulate readonly device"
17111
17112 cleanup_805() {
17113         do_facet $SINGLEMDS zfs set quota=$old $fsset
17114         unlinkmany $DIR/$tdir/f- 1000000
17115         trap 0
17116 }
17117
17118 test_805() {
17119         local zfs_version=$(do_node $SINGLEMDS cat /sys/module/zfs/version)
17120         [ "$(facet_fstype mds1)" != "zfs" ] &&
17121                 skip "ZFS specific test" && return
17122         [ $(version_code $zfs_version) -lt $(version_code 0.7.2) ] &&
17123                 skip "netfree not implemented before 0.7" && return
17124         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.57) ]] ||
17125                 { skip "Need MDS version at least 2.10.57" && return 0; }
17126
17127         local fsset
17128         local freekb
17129         local usedkb
17130         local old
17131         local quota
17132         local pref="osd-zfs.lustre-MDT0000."
17133
17134         # limit available space on MDS dataset to meet nospace issue
17135         # quickly. then ZFS 0.7.2 can use reserved space if asked
17136         # properly (using netfree flag in osd_declare_destroy()
17137         fsset=$(do_facet $SINGLEMDS lctl get_param -n $pref.mntdev)
17138         old=$(do_facet $SINGLEMDS zfs get -H quota $fsset | \
17139                 gawk '{print $3}')
17140         freekb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytesfree)
17141         usedkb=$(do_facet $SINGLEMDS lctl get_param -n $pref.kbytestotal)
17142         let "usedkb=usedkb-freekb"
17143         let "freekb=freekb/2"
17144         if let "freekb > 5000"; then
17145                 let "freekb=5000"
17146         fi
17147         do_facet $SINGLEMDS zfs set quota=$(((usedkb+freekb)*1024)) $fsset
17148         trap cleanup_805 EXIT
17149         mkdir $DIR/$tdir
17150         $LFS setstripe -E 1M -L mdt $DIR/$tdir || error "DoM not working"
17151         createmany -m $DIR/$tdir/f- 1000000 && error "ENOSPC wasn't met"
17152         rm -rf $DIR/$tdir || error "not able to remove"
17153         do_facet $SINGLEMDS zfs set quota=$old $fsset
17154         trap 0
17155 }
17156 run_test 805 "ZFS can remove from full fs"
17157
17158 test_810() {
17159         local ORIG
17160         local CSUM
17161
17162         lctl set_param fail_loc=0x411
17163         dd if=/dev/urandom of=$DIR/$tfile bs=10240 count=2
17164         ORIG=$(md5sum $DIR/$tfile)
17165         lctl set_param ldlm.namespaces.*osc*.lru_size=clear
17166         CSUM=$(md5sum $DIR/$tfile)
17167         if [ "$ORIG" != "$CSUM" ]; then
17168                 error "$ORIG != $CSUM"
17169         fi
17170 }
17171 run_test 810 "partial page writes on ZFS (LU-11663)"
17172
17173 #
17174 # tests that do cleanup/setup should be run at the end
17175 #
17176
17177 test_900() {
17178         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
17179         local ls
17180         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
17181         $LCTL set_param fail_loc=0x903
17182
17183         cancel_lru_locks MGC
17184
17185         FAIL_ON_ERROR=true cleanup
17186         FAIL_ON_ERROR=true setup
17187 }
17188 run_test 900 "umount should not race with any mgc requeue thread"
17189
17190 complete $SECONDS
17191 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
17192 check_and_cleanup_lustre
17193 if [ "$I_MOUNTED" != "yes" ]; then
17194         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
17195 fi
17196 exit_status