Whamcloud - gitweb
8a96be677c6dbb24abd3c4cf35444378b147149a
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 # -*- tab-width: 8; indent-tabs-mode: t; -*-
3 #
4 # Run select tests by setting ONLY, or as arguments to the script.
5 # Skip specific tests by setting EXCEPT.
6 #
7 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11 # bug number for skipped test: 13297 2108 9789 3637 9789 3561 12622 5188
12 ALWAYS_EXCEPT="                42a  42b  42c  42d  45   51d   68b   $SANITY_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # with LOD/OSP landing
16 # bug number for skipped tests: LU-2036
17 ALWAYS_EXCEPT="                 76     $ALWAYS_EXCEPT"
18
19 is_sles11()                                             # LU-4341
20 {
21         if [ -r /etc/SuSE-release ]
22         then
23                 local vers=$(grep VERSION /etc/SuSE-release | awk '{print $3}')
24                 local patchlev=$(grep PATCHLEVEL /etc/SuSE-release |
25                         awk '{ print $3 }')
26                 if [ $vers -eq 11 ] && [ $patchlev -ge 3 ]; then
27                         return 0
28                 fi
29         fi
30         return 1
31 }
32
33 if is_sles11; then                                      # LU-4341
34         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 170"
35 fi
36
37 SRCDIR=$(cd $(dirname $0); echo $PWD)
38 export PATH=$PATH:/sbin
39
40 TMP=${TMP:-/tmp}
41
42 CC=${CC:-cc}
43 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
44 CREATETEST=${CREATETEST:-createtest}
45 LFS=${LFS:-lfs}
46 LFIND=${LFIND:-"$LFS find"}
47 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
48 LCTL=${LCTL:-lctl}
49 OPENFILE=${OPENFILE:-openfile}
50 OPENUNLINK=${OPENUNLINK:-openunlink}
51 export MULTIOP=${MULTIOP:-multiop}
52 READS=${READS:-"reads"}
53 MUNLINK=${MUNLINK:-munlink}
54 SOCKETSERVER=${SOCKETSERVER:-socketserver}
55 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
56 MEMHOG=${MEMHOG:-memhog}
57 DIRECTIO=${DIRECTIO:-directio}
58 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
59 STRIPES_PER_OBJ=-1
60 CHECK_GRANT=${CHECK_GRANT:-"yes"}
61 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
62 export PARALLEL=${PARALLEL:-"no"}
63
64 export NAME=${NAME:-local}
65
66 SAVE_PWD=$PWD
67
68 CLEANUP=${CLEANUP:-:}
69 SETUP=${SETUP:-:}
70 TRACE=${TRACE:-""}
71 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
72 LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
73 . $LUSTRE/tests/test-framework.sh
74 init_test_env $@
75 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
76 init_logging
77
78 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 24D 27m 64b 68 71 77f 78 115 124b 300o"
79
80 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
81         # bug number for skipped test: LU-4536 LU-1957 LU-2805
82         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  65ic    180     184c"
83         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b 51ba"
84 fi
85
86 FAIL_ON_ERROR=false
87
88 cleanup() {
89         echo -n "cln.."
90         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
91         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
92 }
93 setup() {
94         echo -n "mnt.."
95         load_modules
96         setupall || exit 10
97         echo "done"
98 }
99
100 check_swap_layouts_support()
101 {
102         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
103                 { skip "Does not support layout lock."; return 0; }
104         return 1
105 }
106
107 check_and_setup_lustre
108 DIR=${DIR:-$MOUNT}
109 assert_DIR
110
111 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
112         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
113 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
114
115 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
116 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
117 rm -rf $DIR/[Rdfs][0-9]*
118
119 # $RUNAS_ID may get set incorrectly somewhere else
120 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
121
122 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
123
124 build_test_filter
125
126 if [ "${ONLY}" = "MOUNT" ] ; then
127         echo "Lustre is up, please go on"
128         exit
129 fi
130
131 echo "preparing for tests involving mounts"
132 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
133 touch $EXT2_DEV
134 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
135 echo # add a newline after mke2fs.
136
137 umask 077
138
139 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
140 lctl set_param debug=-1 2> /dev/null || true
141 test_0a() {
142         touch $DIR/$tfile
143         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
144         rm $DIR/$tfile
145         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
146 }
147 run_test 0a "touch; rm ====================="
148
149 test_0b() {
150         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
151         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
152 }
153 run_test 0b "chmod 0755 $DIR ============================="
154
155 test_0c() {
156         $LCTL get_param mdc.*.import | grep "state: FULL" ||
157                 error "import not FULL"
158         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
159                 error "bad target"
160 }
161 run_test 0c "check import proc ============================="
162
163 test_1() {
164         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
165         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
166         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
167         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
168         rmdir $DIR/$tdir/d2
169         rmdir $DIR/$tdir
170         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
171 }
172 run_test 1 "mkdir; remkdir; rmdir =============================="
173
174 test_2() {
175         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
176         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
177         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
178         rm -r $DIR/$tdir
179         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
180 }
181 run_test 2 "mkdir; touch; rmdir; check file ===================="
182
183 test_3() {
184         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
185         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
186         touch $DIR/$tdir/$tfile
187         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
188         rm -r $DIR/$tdir
189         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
190 }
191 run_test 3 "mkdir; touch; rmdir; check dir ====================="
192
193 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
194 test_4() {
195         local MDTIDX=1
196
197         test_mkdir $DIR/$tdir ||
198                 error "Create remote directory failed"
199
200         touch $DIR/$tdir/$tfile ||
201                 error "Create file under remote directory failed"
202
203         rmdir $DIR/$tdir &&
204                 error "Expect error removing in-use dir $DIR/$tdir"
205
206         test -d $DIR/$tdir || error "Remote directory disappeared"
207
208         rm -rf $DIR/$tdir || error "remove remote dir error"
209 }
210 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
211
212 test_5() {
213         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
214         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
215         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
216         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
217         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
218 }
219 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
220
221 test_6a() {
222         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
223         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
224         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
225                 error "$tfile does not have perm 0666 or UID $UID"
226         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
227         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
228                 error "$tfile should be 0666 and owned by UID $UID"
229 }
230 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
231
232 test_6c() {
233         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
234         touch $DIR/$tfile
235         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
236         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
237                 error "$tfile should be owned by UID $RUNAS_ID"
238         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
239         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
240                 error "$tfile should be owned by UID $RUNAS_ID"
241 }
242 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
243
244 test_6e() {
245         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
246         touch $DIR/$tfile
247         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
248         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
249                 error "$tfile should be owned by GID $UID"
250         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
251         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
252                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
253 }
254 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
255
256 test_6g() {
257         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
258         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
259         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
260         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
261         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
262         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
263         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
264                 error "$tdir/d/subdir should be GID $RUNAS_GID"
265 }
266 run_test 6g "Is new dir in sgid dir inheriting group?"
267
268 test_6h() { # bug 7331
269         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
270         touch $DIR/$tfile || error "touch failed"
271         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
272         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
273                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
274         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
275                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
276 }
277 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
278
279 test_7a() {
280         test_mkdir $DIR/$tdir
281         $MCREATE $DIR/$tdir/$tfile
282         chmod 0666 $DIR/$tdir/$tfile
283         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
284                 error "$tdir/$tfile should be mode 0666"
285 }
286 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
287
288 test_7b() {
289         if [ ! -d $DIR/$tdir ]; then
290                 test_mkdir $DIR/$tdir
291         fi
292         $MCREATE $DIR/$tdir/$tfile
293         echo -n foo > $DIR/$tdir/$tfile
294         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
295         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
296 }
297 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
298
299 test_8() {
300         test_mkdir $DIR/$tdir
301         touch $DIR/$tdir/$tfile
302         chmod 0666 $DIR/$tdir/$tfile
303         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
304                 error "$tfile mode not 0666"
305 }
306 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
307
308 test_9() {
309         test_mkdir $DIR/$tdir
310         test_mkdir $DIR/$tdir/d2
311         test_mkdir $DIR/$tdir/d2/d3
312         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
313 }
314 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
315
316 test_10() {
317         test_mkdir $DIR/$tdir
318         test_mkdir $DIR/$tdir/d2
319         touch $DIR/$tdir/d2/$tfile
320         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
321                 error "$tdir/d2/$tfile not a file"
322 }
323 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
324
325 test_11() {
326         test_mkdir $DIR/$tdir
327         test_mkdir $DIR/$tdir/d2
328         chmod 0666 $DIR/$tdir/d2
329         chmod 0705 $DIR/$tdir/d2
330         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
331                 error "$tdir/d2 mode not 0705"
332 }
333 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
334
335 test_12() {
336         test_mkdir $DIR/$tdir
337         touch $DIR/$tdir/$tfile
338         chmod 0666 $DIR/$tdir/$tfile
339         chmod 0654 $DIR/$tdir/$tfile
340         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
341                 error "$tdir/d2 mode not 0654"
342 }
343 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
344
345 test_13() {
346         test_mkdir $DIR/$tdir
347         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
348         >  $DIR/$tdir/$tfile
349         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
350                 error "$tdir/$tfile size not 0 after truncate"
351 }
352 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
353
354 test_14() {
355         test_mkdir $DIR/$tdir
356         touch $DIR/$tdir/$tfile
357         rm $DIR/$tdir/$tfile
358         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
359 }
360 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
361
362 test_15() {
363         test_mkdir $DIR/$tdir
364         touch $DIR/$tdir/$tfile
365         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
366         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
367                 error "$tdir/${tfile_2} not a file after rename"
368         rm $DIR/$tdir/${tfile}_2 || error "unlink failed after rename"
369 }
370 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
371
372 test_16() {
373         test_mkdir $DIR/$tdir
374         touch $DIR/$tdir/$tfile
375         rm -rf $DIR/$tdir/$tfile
376         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
377 }
378 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
379
380 test_17a() {
381         test_mkdir -p $DIR/$tdir
382         touch $DIR/$tdir/$tfile
383         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
384         ls -l $DIR/$tdir
385         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
386                 error "$tdir/l-exist not a symlink"
387         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
388                 error "$tdir/l-exist not referencing a file"
389         rm -f $DIR/$tdir/l-exist
390         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
391 }
392 run_test 17a "symlinks: create, remove (real) =================="
393
394 test_17b() {
395         test_mkdir -p $DIR/$tdir
396         ln -s no-such-file $DIR/$tdir/l-dangle
397         ls -l $DIR/$tdir
398         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
399                 error "$tdir/l-dangle not referencing no-such-file"
400         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
401                 error "$tdir/l-dangle not referencing non-existent file"
402         rm -f $DIR/$tdir/l-dangle
403         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
404 }
405 run_test 17b "symlinks: create, remove (dangling) =============="
406
407 test_17c() { # bug 3440 - don't save failed open RPC for replay
408         test_mkdir -p $DIR/$tdir
409         ln -s foo $DIR/$tdir/$tfile
410         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
411 }
412 run_test 17c "symlinks: open dangling (should return error) ===="
413
414 test_17d() {
415         test_mkdir -p $DIR/$tdir
416         ln -s foo $DIR/$tdir/$tfile
417         touch $DIR/$tdir/$tfile || error "creating to new symlink"
418 }
419 run_test 17d "symlinks: create dangling ========================"
420
421 test_17e() {
422         test_mkdir -p $DIR/$tdir
423         local foo=$DIR/$tdir/$tfile
424         ln -s $foo $foo || error "create symlink failed"
425         ls -l $foo || error "ls -l failed"
426         ls $foo && error "ls not failed" || true
427 }
428 run_test 17e "symlinks: create recursive symlink (should return error) ===="
429
430 test_17f() {
431         test_mkdir -p $DIR/$tdir
432         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
433         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
434         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
435         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
436         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
437         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
438         ls -l  $DIR/$tdir
439 }
440 run_test 17f "symlinks: long and very long symlink name ========================"
441
442 # str_repeat(S, N) generate a string that is string S repeated N times
443 str_repeat() {
444         local s=$1
445         local n=$2
446         local ret=''
447         while [ $((n -= 1)) -ge 0 ]; do
448                 ret=$ret$s
449         done
450         echo $ret
451 }
452
453 # Long symlinks and LU-2241
454 test_17g() {
455         test_mkdir -p $DIR/$tdir
456         local TESTS="59 60 61 4094 4095"
457
458         # Fix for inode size boundary in 2.1.4
459         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
460                 TESTS="4094 4095"
461
462         # Patch not applied to 2.2 or 2.3 branches
463         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
464         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
465                 TESTS="4094 4095"
466
467         # skip long symlink name for rhel6.5.
468         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
469         grep -q '6.5' /etc/redhat-release &>/dev/null &&
470                 TESTS="59 60 61 4062 4063"
471
472         for i in $TESTS; do
473                 local SYMNAME=$(str_repeat 'x' $i)
474                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
475                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
476         done
477 }
478 run_test 17g "symlinks: really long symlink name and inode boundaries"
479
480 test_17h() { #bug 17378
481         remote_mds_nodsh && skip "remote MDS with nodsh" && return
482         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
483         local mdt_idx
484         test_mkdir -p $DIR/$tdir
485         if [[ $MDSCOUNT -gt 1 ]]; then
486                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
487         else
488                 mdt_idx=0
489         fi
490         $SETSTRIPE -c -1 $DIR/$tdir
491 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
492         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
493         touch $DIR/$tdir/$tfile || true
494 }
495 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
496
497 test_17i() { #bug 20018
498         remote_mds_nodsh && skip "remote MDS with nodsh" && return
499         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
500         test_mkdir -c1 $DIR/$tdir
501         local foo=$DIR/$tdir/$tfile
502         local mdt_idx
503         if [[ $MDSCOUNT -gt 1 ]]; then
504                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
505         else
506                 mdt_idx=0
507         fi
508         ln -s $foo $foo || error "create symlink failed"
509 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
510         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
511         ls -l $foo && error "error not detected"
512         return 0
513 }
514 run_test 17i "don't panic on short symlink"
515
516 test_17k() { #bug 22301
517         [[ -z "$(which rsync 2>/dev/null)" ]] &&
518                 skip "no rsync command" && return 0
519         rsync --help | grep -q xattr ||
520                 skip_env "$(rsync --version | head -n1) does not support xattrs"
521         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
522         test_mkdir -p $DIR/$tdir
523         test_mkdir -p $DIR/$tdir.new
524         touch $DIR/$tdir/$tfile
525         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
526         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
527                 error "rsync failed with xattrs enabled"
528 }
529 run_test 17k "symlinks: rsync with xattrs enabled ========================="
530
531 test_17l() { # LU-279
532         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
533                 skip "no getfattr command" && return 0
534         test_mkdir -p $DIR/$tdir
535         touch $DIR/$tdir/$tfile
536         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
537         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
538                 # -h to not follow symlinks. -m '' to list all the xattrs.
539                 # grep to remove first line: '# file: $path'.
540                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
541                 do
542                         lgetxattr_size_check $path $xattr ||
543                                 error "lgetxattr_size_check $path $xattr failed"
544                 done
545         done
546 }
547 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
548
549 # LU-1540
550 test_17m() {
551         local short_sym="0123456789"
552         local WDIR=$DIR/${tdir}m
553         local i
554
555         remote_mds_nodsh && skip "remote MDS with nodsh" && return
556         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
557         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
558                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
559
560         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
561                 skip "only for ldiskfs MDT" && return 0
562
563         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
564
565         test_mkdir -p $WDIR
566         long_sym=$short_sym
567         # create a long symlink file
568         for ((i = 0; i < 4; ++i)); do
569                 long_sym=${long_sym}${long_sym}
570         done
571
572         echo "create 512 short and long symlink files under $WDIR"
573         for ((i = 0; i < 256; ++i)); do
574                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
575                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
576         done
577
578         echo "erase them"
579         rm -f $WDIR/*
580         sync
581         wait_delete_completed
582
583         echo "recreate the 512 symlink files with a shorter string"
584         for ((i = 0; i < 512; ++i)); do
585                 # rewrite the symlink file with a shorter string
586                 ln -sf ${long_sym} $WDIR/long-$i || error "long_sym failed"
587                 ln -sf ${short_sym} $WDIR/short-$i || error "short_sym failed"
588         done
589
590         local mds_index=$(($($LFS getstripe -M $WDIR) + 1))
591         local devname=$(mdsdevname $mds_index)
592
593         echo "stop and checking mds${mds_index}:"
594         # e2fsck should not return error
595         stop mds${mds_index}
596         run_e2fsck $(facet_active_host mds${mds_index}) $devname -n
597         rc=$?
598
599         start mds${mds_index} $devname $MDS_MOUNT_OPTS || error "start failed"
600         df $MOUNT > /dev/null 2>&1
601         [ $rc -eq 0 ] ||
602                 error "e2fsck detected error for short/long symlink: rc=$rc"
603 }
604 run_test 17m "run e2fsck against MDT which contains short/long symlink"
605
606 check_fs_consistency_17n() {
607         local mdt_index
608         local rc=0
609
610         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
611         # so it only check MDT1/MDT2 instead of all of MDTs.
612         for mdt_index in 1 2; do
613                 local devname=$(mdsdevname $mdt_index)
614                 # e2fsck should not return error
615                 stop mds${mdt_index}
616                 run_e2fsck $(facet_active_host mds$mdt_index) $devname -n ||
617                         rc=$((rc + $?))
618
619                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
620                         error "mount mds$mdt_index failed"
621                 df $MOUNT > /dev/null 2>&1
622         done
623         return $rc
624 }
625
626 test_17n() {
627         local i
628
629         remote_mds_nodsh && skip "remote MDS with nodsh" && return
630         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
631         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
632                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
633
634         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
635                 skip "only for ldiskfs MDT" && return 0
636
637         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
638
639         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
640
641         test_mkdir $DIR/$tdir
642         for ((i=0; i<10; i++)); do
643                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
644                         error "create remote dir error $i"
645                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
646                         error "create files under remote dir failed $i"
647         done
648
649         check_fs_consistency_17n ||
650                 error "e2fsck report error after create files under remote dir"
651
652         for ((i = 0; i < 10; i++)); do
653                 rm -rf $DIR/$tdir/remote_dir_${i} ||
654                         error "destroy remote dir error $i"
655         done
656
657         check_fs_consistency_17n ||
658                 error "e2fsck report error after unlink files under remote dir"
659
660         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
661                 skip "lustre < 2.4.50 does not support migrate mv " && return
662
663         for ((i = 0; i < 10; i++)); do
664                 mkdir -p $DIR/$tdir/remote_dir_${i}
665                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
666                         error "create files under remote dir failed $i"
667                 $LFS migrate --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
668                         error "migrate remote dir error $i"
669         done
670         check_fs_consistency_17n || error "e2fsck report error after migration"
671
672         for ((i = 0; i < 10; i++)); do
673                 rm -rf $DIR/$tdir/remote_dir_${i} ||
674                         error "destroy remote dir error $i"
675         done
676
677         check_fs_consistency_17n || error "e2fsck report error after unlink"
678 }
679 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
680
681 test_17o() {
682         remote_mds_nodsh && skip "remote MDS with nodsh" && return
683         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
684                 skip "Need MDS version at least 2.3.64" && return
685
686         local WDIR=$DIR/${tdir}o
687         local mdt_index
688         local rc=0
689
690         test_mkdir -p $WDIR
691         mdt_index=$($LFS getstripe -M $WDIR)
692         mdt_index=$((mdt_index+1))
693
694         touch $WDIR/$tfile
695
696         #fail mds will wait the failover finish then set
697         #following fail_loc to avoid interfer the recovery process.
698         fail mds${mdt_index}
699
700         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
701         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
702         ls -l $WDIR/$tfile && rc=1
703         do_facet mds${mdt_index} lctl set_param fail_loc=0
704         [[ $rc -ne 0 ]] && error "stat file should fail"
705         true
706 }
707 run_test 17o "stat file with incompat LMA feature"
708
709 test_18() {
710         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
711         ls $DIR || error "Failed to ls $DIR: $?"
712 }
713 run_test 18 "touch .../f ; ls ... =============================="
714
715 test_19a() {
716         touch $DIR/$tfile
717         ls -l $DIR
718         rm $DIR/$tfile
719         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
720 }
721 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
722
723 test_19b() {
724         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
725 }
726 run_test 19b "ls -l .../f19 (should return error) =============="
727
728 test_19c() {
729         [ $RUNAS_ID -eq $UID ] &&
730                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
731         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
732 }
733 run_test 19c "$RUNAS touch .../f19 (should return error) =="
734
735 test_19d() {
736         cat $DIR/f19 && error || true
737 }
738 run_test 19d "cat .../f19 (should return error) =============="
739
740 test_20() {
741         touch $DIR/$tfile
742         rm $DIR/$tfile
743         log "1 done"
744         touch $DIR/$tfile
745         rm $DIR/$tfile
746         log "2 done"
747         touch $DIR/$tfile
748         rm $DIR/$tfile
749         log "3 done"
750         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
751 }
752 run_test 20 "touch .../f ; ls -l ... ==========================="
753
754 test_21() {
755         test_mkdir -p $DIR/$tdir
756         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
757         ln -s dangle $DIR/$tdir/link
758         echo foo >> $DIR/$tdir/link
759         cat $DIR/$tdir/dangle
760         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
761         $CHECKSTAT -f -t file $DIR/$tdir/link ||
762                 error "$tdir/link not linked to a file"
763 }
764 run_test 21 "write to dangling link ============================"
765
766 test_22() {
767         WDIR=$DIR/$tdir
768         test_mkdir -p $DIR/$tdir
769         chown $RUNAS_ID:$RUNAS_GID $WDIR
770         (cd $WDIR || error "cd $WDIR failed";
771         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
772         $RUNAS tar xf -)
773         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
774         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
775         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
776 }
777 run_test 22 "unpack tar archive as non-root user ==============="
778
779 # was test_23
780 test_23a() {
781         test_mkdir -p $DIR/$tdir
782         local file=$DIR/$tdir/$tfile
783
784         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
785         openfile -f O_CREAT:O_EXCL $file &&
786                 error "$file recreate succeeded" || true
787 }
788 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
789
790 test_23b() { # bug 18988
791         test_mkdir -p $DIR/$tdir
792         local file=$DIR/$tdir/$tfile
793
794         rm -f $file
795         echo foo > $file || error "write filed"
796         echo bar >> $file || error "append filed"
797         $CHECKSTAT -s 8 $file || error "wrong size"
798         rm $file
799 }
800 run_test 23b "O_APPEND check =========================="
801
802 # rename sanity
803 test_24a() {
804         echo '-- same directory rename'
805         test_mkdir $DIR/$tdir
806         touch $DIR/$tdir/$tfile.1
807         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
808         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
809 }
810 run_test 24a "rename file to non-existent target"
811
812 test_24b() {
813         test_mkdir $DIR/$tdir
814         touch $DIR/$tdir/$tfile.{1,2}
815         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
816         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
817         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
818 }
819 run_test 24b "rename file to existing target"
820
821 test_24c() {
822         test_mkdir $DIR/$tdir
823         test_mkdir $DIR/$tdir/d$testnum.1
824         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
825         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
826         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
827 }
828 run_test 24c "rename directory to non-existent target"
829
830 test_24d() {
831         test_mkdir -c1 $DIR/$tdir
832         test_mkdir -c1 $DIR/$tdir/d$testnum.1
833         test_mkdir -c1 $DIR/$tdir/d$testnum.2
834         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
835         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
836         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
837 }
838 run_test 24d "rename directory to existing target"
839
840 test_24e() {
841         echo '-- cross directory renames --'
842         test_mkdir $DIR/R5a
843         test_mkdir $DIR/R5b
844         touch $DIR/R5a/f
845         mv $DIR/R5a/f $DIR/R5b/g
846         $CHECKSTAT -a $DIR/R5a/f || error
847         $CHECKSTAT -t file $DIR/R5b/g || error
848 }
849 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
850
851 test_24f() {
852         test_mkdir $DIR/R6a
853         test_mkdir $DIR/R6b
854         touch $DIR/R6a/f $DIR/R6b/g
855         mv $DIR/R6a/f $DIR/R6b/g
856         $CHECKSTAT -a $DIR/R6a/f || error
857         $CHECKSTAT -t file $DIR/R6b/g || error
858 }
859 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
860
861 test_24g() {
862         test_mkdir $DIR/R7a
863         test_mkdir $DIR/R7b
864         test_mkdir $DIR/R7a/d
865         mv $DIR/R7a/d $DIR/R7b/e
866         $CHECKSTAT -a $DIR/R7a/d || error
867         $CHECKSTAT -t dir $DIR/R7b/e || error
868 }
869 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
870
871 test_24h() {
872         test_mkdir -c1 $DIR/R8a
873         test_mkdir -c1 $DIR/R8b
874         test_mkdir -c1 $DIR/R8a/d
875         test_mkdir -c1 $DIR/R8b/e
876         mrename $DIR/R8a/d $DIR/R8b/e
877         $CHECKSTAT -a $DIR/R8a/d || error
878         $CHECKSTAT -t dir $DIR/R8b/e || error
879 }
880 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
881
882 test_24i() {
883         echo "-- rename error cases"
884         test_mkdir $DIR/R9
885         test_mkdir $DIR/R9/a
886         touch $DIR/R9/f
887         mrename $DIR/R9/f $DIR/R9/a
888         $CHECKSTAT -t file $DIR/R9/f || error
889         $CHECKSTAT -t dir  $DIR/R9/a || error
890         $CHECKSTAT -a $DIR/R9/a/f || error
891 }
892 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
893
894 test_24j() {
895         test_mkdir $DIR/R10
896         mrename $DIR/R10/f $DIR/R10/g
897         $CHECKSTAT -t dir $DIR/R10 || error
898         $CHECKSTAT -a $DIR/R10/f || error
899         $CHECKSTAT -a $DIR/R10/g || error
900 }
901 run_test 24j "source does not exist ============================"
902
903 test_24k() {
904         test_mkdir $DIR/R11a
905         test_mkdir $DIR/R11a/d
906         touch $DIR/R11a/f
907         mv $DIR/R11a/f $DIR/R11a/d
908         $CHECKSTAT -a $DIR/R11a/f || error
909         $CHECKSTAT -t file $DIR/R11a/d/f || error
910 }
911 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
912
913 # bug 2429 - rename foo foo foo creates invalid file
914 test_24l() {
915         f="$DIR/f24l"
916         $MULTIOP $f OcNs || error
917 }
918 run_test 24l "Renaming a file to itself ========================"
919
920 test_24m() {
921         f="$DIR/f24m"
922         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
923         # on ext3 this does not remove either the source or target files
924         # though the "expected" operation would be to remove the source
925         $CHECKSTAT -t file ${f} || error "${f} missing"
926         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
927 }
928 run_test 24m "Renaming a file to a hard link to itself ========="
929
930 test_24n() {
931     f="$DIR/f24n"
932     # this stats the old file after it was renamed, so it should fail
933     touch ${f}
934     $CHECKSTAT ${f}
935     mv ${f} ${f}.rename
936     $CHECKSTAT ${f}.rename
937     $CHECKSTAT -a ${f}
938 }
939 run_test 24n "Statting the old file after renaming (Posix rename 2)"
940
941 test_24o() {
942         test_mkdir -p $DIR/d24o
943         rename_many -s random -v -n 10 $DIR/d24o
944 }
945 run_test 24o "rename of files during htree split ==============="
946
947 test_24p() {
948         test_mkdir $DIR/R12a
949         test_mkdir $DIR/R12b
950         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
951         mrename $DIR/R12a $DIR/R12b
952         $CHECKSTAT -a $DIR/R12a || error
953         $CHECKSTAT -t dir $DIR/R12b || error
954         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
955         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
956 }
957 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
958
959 cleanup_multiop_pause() {
960         trap 0
961         kill -USR1 $MULTIPID
962 }
963
964 test_24q() {
965         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
966         test_mkdir $DIR/R13a
967         test_mkdir $DIR/R13b
968         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
969         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
970         MULTIPID=$!
971
972         trap cleanup_multiop_pause EXIT
973         mrename $DIR/R13a $DIR/R13b
974         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
975         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
976         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
977         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
978         cleanup_multiop_pause
979         wait $MULTIPID || error "multiop close failed"
980 }
981 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
982
983 test_24r() { #bug 3789
984         test_mkdir $DIR/R14a
985         test_mkdir $DIR/R14a/b
986         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
987         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
988         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
989 }
990 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
991
992 test_24s() {
993         test_mkdir $DIR/R15a
994         test_mkdir $DIR/R15a/b
995         test_mkdir $DIR/R15a/b/c
996         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
997         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
998         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
999 }
1000 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1001 test_24t() {
1002         test_mkdir $DIR/R16a
1003         test_mkdir $DIR/R16a/b
1004         test_mkdir $DIR/R16a/b/c
1005         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1006         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1007         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1008 }
1009 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1010
1011 test_24u() { # bug12192
1012         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1013         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1014 }
1015 run_test 24u "create stripe file"
1016
1017 page_size() {
1018         getconf PAGE_SIZE
1019 }
1020
1021 simple_cleanup_common() {
1022         trap 0
1023         rm -rf $DIR/$tdir
1024         wait_delete_completed
1025 }
1026
1027 max_pages_per_rpc() {
1028         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1029 }
1030
1031 test_24v() {
1032         local NRFILES=100000
1033         local FREE_INODES=$(mdt_free_inodes 0)
1034         [[ $FREE_INODES -lt $NRFILES ]] &&
1035                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1036                 return
1037
1038         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1039         trap simple_cleanup_common EXIT
1040
1041         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1042         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1043
1044         test_mkdir -p $DIR/$tdir
1045         createmany -m $DIR/$tdir/$tfile $NRFILES
1046
1047         cancel_lru_locks mdc
1048         lctl set_param mdc.*.stats clear
1049
1050         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1051
1052         # LU-5 large readdir
1053         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1054         #               8 bytes for name(filename is mostly 5 in this test) +
1055         #               8 bytes for luda_type
1056         # take into account of overhead in lu_dirpage header and end mark in
1057         # each page, plus one in RPC_NUM calculation.
1058         DIRENT_SIZE=48
1059         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1060         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1061         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1062                                 awk '/^mds_readpage/ {print $2}')
1063         [[ $mds_readpage -gt $RPC_NUM ]] &&
1064                 error "large readdir doesn't take effect"
1065
1066         simple_cleanup_common
1067 }
1068 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1069
1070 test_24w() { # bug21506
1071         SZ1=234852
1072         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1073         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1074         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1075         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1076         [[ "$SZ1" -eq "$SZ2" ]] ||
1077                 error "Error reading at the end of the file $tfile"
1078 }
1079 run_test 24w "Reading a file larger than 4Gb"
1080
1081 test_24x() {
1082         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1083
1084         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1085                 skip "Need MDS version at least 2.7.56" && return
1086
1087         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1088         local MDTIDX=1
1089         local remote_dir=$DIR/$tdir/remote_dir
1090
1091         test_mkdir -p $DIR/$tdir
1092         $LFS mkdir -i $MDTIDX $remote_dir ||
1093                 error "create remote directory failed"
1094
1095         test_mkdir -p $DIR/$tdir/src_dir
1096         touch $DIR/$tdir/src_file
1097         test_mkdir -p $remote_dir/tgt_dir
1098         touch $remote_dir/tgt_file
1099
1100         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir ||
1101                 error "rename dir cross MDT failed!"
1102
1103         mrename $DIR/$tdir/src_file $remote_dir/tgt_file ||
1104                 error "rename file cross MDT failed!"
1105
1106         touch $DIR/$tdir/ln_file
1107         ln $DIR/$tdir/ln_file $remote_dir/ln_name ||
1108                 error "ln file cross MDT failed"
1109
1110         rm -rf $DIR/$tdir || error "Can not delete directories"
1111 }
1112 run_test 24x "cross MDT rename/link"
1113
1114 test_24y() {
1115         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1116         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1117         local MDTIDX=1
1118         local remote_dir=$DIR/$tdir/remote_dir
1119
1120         test_mkdir -p $DIR/$tdir
1121         $LFS mkdir -i $MDTIDX $remote_dir ||
1122                    error "create remote directory failed"
1123
1124         test_mkdir -p $remote_dir/src_dir
1125         touch $remote_dir/src_file
1126         test_mkdir -p $remote_dir/tgt_dir
1127         touch $remote_dir/tgt_file
1128
1129         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1130                 error "rename subdir in the same remote dir failed!"
1131
1132         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1133                 error "rename files in the same remote dir failed!"
1134
1135         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1136                 error "link files in the same remote dir failed!"
1137
1138         rm -rf $DIR/$tdir || error "Can not delete directories"
1139 }
1140 run_test 24y "rename/link on the same dir should succeed"
1141
1142 test_24A() { # LU-3182
1143         local NFILES=5000
1144
1145         rm -rf $DIR/$tdir
1146         test_mkdir -p $DIR/$tdir
1147         createmany -m $DIR/$tdir/$tfile $NFILES
1148         local t=$(ls $DIR/$tdir | wc -l)
1149         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1150         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1151         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1152                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1153         fi
1154
1155         rm -rf $DIR/$tdir || error "Can not delete directories"
1156 }
1157 run_test 24A "readdir() returns correct number of entries."
1158
1159 test_24B() { # LU-4805
1160         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1161         local count
1162
1163         test_mkdir $DIR/$tdir
1164         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1165                 error "create striped dir failed"
1166
1167         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1168         [ $count -eq 2 ] || error "Expected 2, got $count"
1169
1170         touch $DIR/$tdir/striped_dir/a
1171
1172         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1173         [ $count -eq 3 ] || error "Expected 3, got $count"
1174
1175         touch $DIR/$tdir/striped_dir/.f
1176
1177         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1178         [ $count -eq 4 ] || error "Expected 4, got $count"
1179
1180         rm -rf $DIR/$tdir || error "Can not delete directories"
1181 }
1182 run_test 24B "readdir for striped dir return correct number of entries"
1183
1184 test_24C() {
1185         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1186
1187         mkdir $DIR/$tdir
1188         mkdir $DIR/$tdir/d0
1189         mkdir $DIR/$tdir/d1
1190
1191         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1192                 error "create striped dir failed"
1193
1194         cd $DIR/$tdir/d0/striped_dir
1195
1196         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1197         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1198         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1199
1200         [ "$d0_ino" = "$parent_ino" ] ||
1201                 error ".. wrong, expect $d0_ino, get $parent_ino"
1202
1203         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1204                 error "mv striped dir failed"
1205
1206         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1207
1208         [ "$d1_ino" = "$parent_ino" ] ||
1209                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1210 }
1211 run_test 24C "check .. in striped dir"
1212
1213 test_24D() { # LU-6101
1214         local NFILES=50000
1215
1216         rm -rf $DIR/$tdir
1217         mkdir -p $DIR/$tdir
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         rm -rf $DIR/$tdir || error "Can not delete directories"
1227 }
1228 run_test 24D "readdir() returns correct number of entries after cursor reload"
1229
1230 test_24E() {
1231         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
1232         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1233
1234         mkdir -p $DIR/$tdir
1235         mkdir $DIR/$tdir/src_dir
1236         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
1237                 error "create remote source failed"
1238
1239         touch $DIR/$tdir/src_dir/src_child/a
1240
1241         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
1242                 error "create remote target dir failed"
1243
1244         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
1245                 error "create remote target child failed"
1246
1247         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
1248                 error "rename dir cross MDT failed!"
1249
1250         find $DIR/$tdir
1251
1252         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
1253                 error "src_child still exists after rename"
1254
1255         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
1256                 error "missing file(a) after rename"
1257
1258         rm -rf $DIR/$tdir || error "Can not delete directories"
1259 }
1260 run_test 24E "cross MDT rename/link"
1261
1262 test_25a() {
1263         echo '== symlink sanity ============================================='
1264
1265         test_mkdir $DIR/d25
1266         ln -s d25 $DIR/s25
1267         touch $DIR/s25/foo || error
1268 }
1269 run_test 25a "create file in symlinked directory ==============="
1270
1271 test_25b() {
1272         [ ! -d $DIR/d25 ] && test_25a
1273         $CHECKSTAT -t file $DIR/s25/foo || error
1274 }
1275 run_test 25b "lookup file in symlinked directory ==============="
1276
1277 test_26a() {
1278         test_mkdir $DIR/d26
1279         test_mkdir $DIR/d26/d26-2
1280         ln -s d26/d26-2 $DIR/s26
1281         touch $DIR/s26/foo || error
1282 }
1283 run_test 26a "multiple component symlink ======================="
1284
1285 test_26b() {
1286         test_mkdir -p $DIR/d26b/d26-2
1287         ln -s d26b/d26-2/foo $DIR/s26-2
1288         touch $DIR/s26-2 || error
1289 }
1290 run_test 26b "multiple component symlink at end of lookup ======"
1291
1292 test_26c() {
1293         test_mkdir $DIR/d26.2
1294         touch $DIR/d26.2/foo
1295         ln -s d26.2 $DIR/s26.2-1
1296         ln -s s26.2-1 $DIR/s26.2-2
1297         ln -s s26.2-2 $DIR/s26.2-3
1298         chmod 0666 $DIR/s26.2-3/foo
1299 }
1300 run_test 26c "chain of symlinks ================================"
1301
1302 # recursive symlinks (bug 439)
1303 test_26d() {
1304         ln -s d26-3/foo $DIR/d26-3
1305 }
1306 run_test 26d "create multiple component recursive symlink ======"
1307
1308 test_26e() {
1309         [ ! -h $DIR/d26-3 ] && test_26d
1310         rm $DIR/d26-3
1311 }
1312 run_test 26e "unlink multiple component recursive symlink ======"
1313
1314 # recursive symlinks (bug 7022)
1315 test_26f() {
1316         test_mkdir -p $DIR/$tdir
1317         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1318         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1319         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1320         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1321         cd $tfile                || error "cd $tfile failed"
1322         ln -s .. dotdot          || error "ln dotdot failed"
1323         ln -s dotdot/lndir lndir || error "ln lndir failed"
1324         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1325         output=`ls $tfile/$tfile/lndir/bar1`
1326         [ "$output" = bar1 ] && error "unexpected output"
1327         rm -r $tfile             || error "rm $tfile failed"
1328         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1329 }
1330 run_test 26f "rm -r of a directory which has recursive symlink ="
1331
1332 test_27a() {
1333         echo '== stripe sanity =============================================='
1334         test_mkdir -p $DIR/d27 || error "mkdir failed"
1335         $GETSTRIPE $DIR/d27
1336         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1337         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1338         log "== test_27a: write to one stripe file ========================="
1339         cp /etc/hosts $DIR/d27/f0 || error
1340 }
1341 run_test 27a "one stripe file =================================="
1342
1343 test_27b() {
1344         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1345         test_mkdir -p $DIR/d27
1346         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1347         $GETSTRIPE -c $DIR/d27/f01
1348         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1349                 error "two-stripe file doesn't have two stripes"
1350
1351         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1352 }
1353 run_test 27b "create and write to two stripe file"
1354
1355 test_27d() {
1356         test_mkdir -p $DIR/d27
1357         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1358         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1359         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1360 }
1361 run_test 27d "create file with default settings ================"
1362
1363 test_27e() {
1364         # LU-5839 adds check for existed layout before setting it
1365         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1366                 skip "Need MDS version at least 2.7.56" && return
1367         test_mkdir -p $DIR/d27
1368         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1369         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1370         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1371 }
1372 run_test 27e "setstripe existing file (should return error) ======"
1373
1374 test_27f() {
1375         test_mkdir $DIR/$tdir
1376         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1377                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1378         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1379                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1380         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1381         $GETSTRIPE $DIR/$tdir/$tfile || error "$GETSTRIPE failed"
1382 }
1383 run_test 27f "setstripe with bad stripe size (should return error)"
1384
1385 test_27g() {
1386         test_mkdir -p $DIR/d27
1387         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1388         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1389                 error "$DIR/d27/fnone has object"
1390 }
1391 run_test 27g "$GETSTRIPE with no objects"
1392
1393 test_27i() {
1394         test_mkdir $DIR/$tdir
1395         touch $DIR/$tdir/$tfile || error "touch failed"
1396         [[ $($GETSTRIPE -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1397                 error "missing objects"
1398 }
1399 run_test 27i "$GETSTRIPE with some objects"
1400
1401 test_27j() {
1402         test_mkdir -p $DIR/d27
1403         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1404 }
1405 run_test 27j "setstripe with bad stripe offset (should return error)"
1406
1407 test_27k() { # bug 2844
1408         test_mkdir -p $DIR/d27
1409         FILE=$DIR/d27/f27k
1410         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1411         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1412         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1413         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1414         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1415         dd if=/dev/zero of=$FILE bs=4k count=1
1416         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1417         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1418 }
1419 run_test 27k "limit i_blksize for broken user apps ============="
1420
1421 test_27l() {
1422         test_mkdir -p $DIR/d27
1423         mcreate $DIR/f27l || error "creating file"
1424         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1425                 error "setstripe should have failed" || true
1426 }
1427 run_test 27l "check setstripe permissions (should return error)"
1428
1429 test_27m() {
1430         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1431                 return
1432
1433         ORIGFREE=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
1434                    head -n1)
1435         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1436                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1437                 return
1438         fi
1439         trap simple_cleanup_common EXIT
1440         test_mkdir -p $DIR/$tdir
1441         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1442         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1443                 error "dd should fill OST0"
1444         i=2
1445         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1446                 i=$((i + 1))
1447                 [ $i -gt 256 ] && break
1448         done
1449         i=$((i + 1))
1450         touch $DIR/$tdir/f27m_$i
1451         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1452                 error "OST0 was full but new created file still use it"
1453         i=$((i + 1))
1454         touch $DIR/$tdir/f27m_$i
1455         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1456                 error "OST0 was full but new created file still use it"
1457         simple_cleanup_common
1458 }
1459 run_test 27m "create file while OST0 was full =================="
1460
1461 sleep_maxage() {
1462         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1463         sleep $DELAY
1464 }
1465
1466 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1467 # if the OST isn't full anymore.
1468 reset_enospc() {
1469         local OSTIDX=${1:-""}
1470
1471         local list=$(comma_list $(osts_nodes))
1472         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1473
1474         do_nodes $list lctl set_param fail_loc=0
1475         sync    # initiate all OST_DESTROYs from MDS to OST
1476         sleep_maxage
1477 }
1478
1479 exhaust_precreations() {
1480         local OSTIDX=$1
1481         local FAILLOC=$2
1482         local FAILIDX=${3:-$OSTIDX}
1483         local ofacet=ost$((OSTIDX + 1))
1484
1485         test_mkdir -p -c1 $DIR/$tdir
1486         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
1487         local mfacet=mds$((mdtidx + 1))
1488         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1489
1490         local OST=$(ostname_from_index $OSTIDX)
1491
1492         # on the mdt's osc
1493         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1494         local last_id=$(do_facet $mfacet lctl get_param -n \
1495                         osc.$mdtosc_proc1.prealloc_last_id)
1496         local next_id=$(do_facet $mfacet lctl get_param -n \
1497                         osc.$mdtosc_proc1.prealloc_next_id)
1498
1499         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1500         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1501
1502         test_mkdir -p $DIR/$tdir/${OST}
1503         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1504 #define OBD_FAIL_OST_ENOSPC              0x215
1505         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1506         echo "Creating to objid $last_id on ost $OST..."
1507         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1508         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1509         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1510         sleep_maxage
1511 }
1512
1513 exhaust_all_precreations() {
1514         local i
1515         for (( i=0; i < OSTCOUNT; i++ )) ; do
1516                 exhaust_precreations $i $1 -1
1517         done
1518 }
1519
1520 test_27n() {
1521         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1522         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1523         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1524         remote_ost_nodsh && skip "remote OST with nodsh" && return
1525
1526         reset_enospc
1527         rm -f $DIR/$tdir/$tfile
1528         exhaust_precreations 0 0x80000215
1529         $SETSTRIPE -c -1 $DIR/$tdir
1530         touch $DIR/$tdir/$tfile || error
1531         $GETSTRIPE $DIR/$tdir/$tfile
1532         reset_enospc
1533 }
1534 run_test 27n "create file with some full OSTs =================="
1535
1536 test_27o() {
1537         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1538         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1539         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1540         remote_ost_nodsh && skip "remote OST with nodsh" && return
1541
1542         reset_enospc
1543         rm -f $DIR/$tdir/$tfile
1544         exhaust_all_precreations 0x215
1545
1546         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1547
1548         reset_enospc
1549         rm -rf $DIR/$tdir/*
1550 }
1551 run_test 27o "create file with all full OSTs (should error) ===="
1552
1553 test_27p() {
1554         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1555         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1556         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1557         remote_ost_nodsh && skip "remote OST with nodsh" && return
1558
1559         reset_enospc
1560         rm -f $DIR/$tdir/$tfile
1561         test_mkdir -p $DIR/$tdir
1562
1563         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1564         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1565         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1566
1567         exhaust_precreations 0 0x80000215
1568         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1569         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1570         $GETSTRIPE $DIR/$tdir/$tfile
1571
1572         reset_enospc
1573 }
1574 run_test 27p "append to a truncated file with some full OSTs ==="
1575
1576 test_27q() {
1577         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1578         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1579         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1580         remote_ost_nodsh && skip "remote OST with nodsh" && return
1581
1582         reset_enospc
1583         rm -f $DIR/$tdir/$tfile
1584
1585         test_mkdir -p $DIR/$tdir
1586         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1587         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1588         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1589
1590         exhaust_all_precreations 0x215
1591
1592         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1593         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1594
1595         reset_enospc
1596 }
1597 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1598
1599 test_27r() {
1600         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1601         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1602         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1603         remote_ost_nodsh && skip "remote OST with nodsh" && return
1604
1605         reset_enospc
1606         rm -f $DIR/$tdir/$tfile
1607         exhaust_precreations 0 0x80000215
1608
1609         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1610
1611         reset_enospc
1612 }
1613 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1614
1615 test_27s() { # bug 10725
1616         test_mkdir -p $DIR/$tdir
1617         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1618         local stripe_count=0
1619         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1620         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1621                 error "stripe width >= 2^32 succeeded" || true
1622
1623 }
1624 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1625
1626 test_27t() { # bug 10864
1627         WDIR=$(pwd)
1628         WLFS=$(which lfs)
1629         cd $DIR
1630         touch $tfile
1631         $WLFS getstripe $tfile
1632         cd $WDIR
1633 }
1634 run_test 27t "check that utils parse path correctly"
1635
1636 test_27u() { # bug 4900
1637         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1638         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1639         local index
1640         local list=$(comma_list $(mdts_nodes))
1641
1642 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1643         do_nodes $list $LCTL set_param fail_loc=0x139
1644         test_mkdir -p $DIR/$tdir
1645         rm -rf $DIR/$tdir/*
1646         createmany -o $DIR/$tdir/t- 1000
1647         do_nodes $list $LCTL set_param fail_loc=0
1648
1649         TLOG=$DIR/$tfile.getstripe
1650         $GETSTRIPE $DIR/$tdir > $TLOG
1651         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1652         unlinkmany $DIR/$tdir/t- 1000
1653         [[ $OBJS -gt 0 ]] &&
1654                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1655 }
1656 run_test 27u "skip object creation on OSC w/o objects =========="
1657
1658 test_27v() { # bug 4900
1659         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1660         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1661         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1662         remote_ost_nodsh && skip "remote OST with nodsh" && return
1663
1664         exhaust_all_precreations 0x215
1665         reset_enospc
1666
1667         test_mkdir -p $DIR/$tdir
1668         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1669
1670         touch $DIR/$tdir/$tfile
1671         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1672         # all except ost1
1673         for (( i=1; i < OSTCOUNT; i++ )); do
1674                 do_facet ost$i lctl set_param fail_loc=0x705
1675         done
1676         local START=`date +%s`
1677         createmany -o $DIR/$tdir/$tfile 32
1678
1679         local FINISH=`date +%s`
1680         local TIMEOUT=`lctl get_param -n timeout`
1681         local PROCESS=$((FINISH - START))
1682         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1683                error "$FINISH - $START >= $TIMEOUT / 2"
1684         sleep $((TIMEOUT / 2 - PROCESS))
1685         reset_enospc
1686 }
1687 run_test 27v "skip object creation on slow OST ================="
1688
1689 test_27w() { # bug 10997
1690         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1691         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1692         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1693                 error "stripe size $size != 65536" || true
1694         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1695                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1696 }
1697 run_test 27w "check $SETSTRIPE -S option"
1698
1699 test_27wa() {
1700         [[ $OSTCOUNT -lt 2 ]] &&
1701                 skip_env "skipping multiple stripe count/offset test" && return
1702
1703         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1704         for i in $(seq 1 $OSTCOUNT); do
1705                 offset=$((i - 1))
1706                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1707                         error "setstripe -c $i -i $offset failed"
1708                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1709                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1710                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1711                 [ $index -ne $offset ] &&
1712                         error "stripe offset $index != $offset" || true
1713         done
1714 }
1715 run_test 27wa "check $SETSTRIPE -c -i options"
1716
1717 test_27x() {
1718         remote_ost_nodsh && skip "remote OST with nodsh" && return
1719         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1720         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1721         OFFSET=$(($OSTCOUNT - 1))
1722         OSTIDX=0
1723         local OST=$(ostname_from_index $OSTIDX)
1724
1725         test_mkdir -p $DIR/$tdir
1726         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1727         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1728         sleep_maxage
1729         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1730         for i in `seq 0 $OFFSET`; do
1731                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1732                 error "OST0 was degraded but new created file still use it"
1733         done
1734         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1735 }
1736 run_test 27x "create files while OST0 is degraded"
1737
1738 test_27y() {
1739         [[ $OSTCOUNT -lt 2 ]] &&
1740                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1741         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1742         remote_ost_nodsh && skip "remote OST with nodsh" && return
1743         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1744
1745         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1746         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1747             osc.$mdtosc.prealloc_last_id)
1748         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1749             osc.$mdtosc.prealloc_next_id)
1750         local fcount=$((last_id - next_id))
1751         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1752         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1753
1754         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1755                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1756         local OST_DEACTIVE_IDX=-1
1757         local OSC
1758         local OSTIDX
1759         local OST
1760
1761         for OSC in $MDS_OSCS; do
1762                 OST=$(osc_to_ost $OSC)
1763                 OSTIDX=$(index_from_ostuuid $OST)
1764                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1765                         OST_DEACTIVE_IDX=$OSTIDX
1766                 fi
1767                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1768                         echo $OSC "is Deactivated:"
1769                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1770                 fi
1771         done
1772
1773         OSTIDX=$(index_from_ostuuid $OST)
1774         test_mkdir -p $DIR/$tdir
1775         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1776
1777         for OSC in $MDS_OSCS; do
1778                 OST=$(osc_to_ost $OSC)
1779                 OSTIDX=$(index_from_ostuuid $OST)
1780                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1781                         echo $OST "is degraded:"
1782                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1783                                                 obdfilter.$OST.degraded=1
1784                 fi
1785         done
1786
1787         sleep_maxage
1788         createmany -o $DIR/$tdir/$tfile $fcount
1789
1790         for OSC in $MDS_OSCS; do
1791                 OST=$(osc_to_ost $OSC)
1792                 OSTIDX=$(index_from_ostuuid $OST)
1793                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1794                         echo $OST "is recovered from degraded:"
1795                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1796                                                 obdfilter.$OST.degraded=0
1797                 else
1798                         do_facet $SINGLEMDS lctl --device %$OSC activate
1799                 fi
1800         done
1801
1802         # all osp devices get activated, hence -1 stripe count restored
1803         local stripecnt=0
1804
1805         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1806         # devices get activated.
1807         sleep_maxage
1808         $SETSTRIPE -c -1 $DIR/$tfile
1809         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1810         rm -f $DIR/$tfile
1811         [ $stripecnt -ne $OSTCOUNT ] &&
1812                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1813         return 0
1814 }
1815 run_test 27y "create files while OST0 is degraded and the rest inactive"
1816
1817 check_seq_oid()
1818 {
1819         log "check file $1"
1820
1821         lmm_count=$($GETSTRIPE -c $1)
1822         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1823         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1824
1825         local old_ifs="$IFS"
1826         IFS=$'[:]'
1827         fid=($($LFS path2fid $1))
1828         IFS="$old_ifs"
1829
1830         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1831         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1832
1833         # compare lmm_seq and lu_fid->f_seq
1834         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1835         # compare lmm_object_id and lu_fid->oid
1836         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1837
1838         # check the trusted.fid attribute of the OST objects of the file
1839         local have_obdidx=false
1840         local stripe_nr=0
1841         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1842                 # skip lines up to and including "obdidx"
1843                 [ -z "$obdidx" ] && break
1844                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1845                 $have_obdidx || continue
1846
1847                 local ost=$((obdidx + 1))
1848                 local dev=$(ostdevname $ost)
1849                 local oid_hex
1850
1851                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1852
1853                 seq=$(echo $seq | sed -e "s/^0x//g")
1854                 if [ $seq == 0 ] || [ $(facet_fstype ost$ost) == zfs ]; then
1855                         oid_hex=$(echo $oid)
1856                 else
1857                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1858                 fi
1859                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1860
1861                 local ff
1862                 #
1863                 # Don't unmount/remount the OSTs if we don't need to do that.
1864                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1865                 # update too, until that use mount/ll_decode_filter_fid/mount.
1866                 # Re-enable when debugfs will understand new filter_fid.
1867                 #
1868                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1869                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1870                                 $dev 2>/dev/null" | grep "parent=")
1871                 else
1872                         stop ost$ost
1873                         mount_fstype ost$ost
1874                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1875                                 $(facet_mntpt ost$ost)/$obj_file)
1876                         unmount_fstype ost$ost
1877                         start ost$ost $dev $OST_MOUNT_OPTS
1878                         clients_up
1879                 fi
1880
1881                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1882
1883                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1884
1885                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1886                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1887                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1888                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1889                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1890                 local ff_pstripe
1891                 if echo $ff_parent | grep -q 'stripe='; then
1892                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1893                 else
1894                         #
1895                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1896                         # into f_ver in this case.  See the comment on
1897                         # ff_parent.
1898                         #
1899                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1900                                 sed -e 's/\]//')
1901                 fi
1902
1903                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1904                 [ $ff_pseq = $lmm_seq ] ||
1905                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1906                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1907                 [ $ff_poid = $lmm_oid ] ||
1908                         error "FF parent OID $ff_poid != $lmm_oid"
1909                 (($ff_pstripe == $stripe_nr)) ||
1910                         error "FF stripe $ff_pstripe != $stripe_nr"
1911
1912                 stripe_nr=$((stripe_nr + 1))
1913         done
1914 }
1915
1916 test_27z() {
1917         remote_ost_nodsh && skip "remote OST with nodsh" && return
1918         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1919         test_mkdir -p $DIR/$tdir
1920
1921         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1922                 { error "setstripe -c -1 failed"; return 1; }
1923         # We need to send a write to every object to get parent FID info set.
1924         # This _should_ also work for setattr, but does not currently.
1925         # touch $DIR/$tdir/$tfile-1 ||
1926         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1927                 { error "dd $tfile-1 failed"; return 2; }
1928         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1929                 { error "setstripe -c -1 failed"; return 3; }
1930         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1931                 { error "dd $tfile-2 failed"; return 4; }
1932
1933         # make sure write RPCs have been sent to OSTs
1934         sync; sleep 5; sync
1935
1936         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1937         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1938 }
1939 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1940
1941 test_27A() { # b=19102
1942         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1943         local restore_size=$($GETSTRIPE -S $MOUNT)
1944         local restore_count=$($GETSTRIPE -c $MOUNT)
1945         local restore_offset=$($GETSTRIPE -i $MOUNT)
1946         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1947         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1948                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1949         local default_size=$($GETSTRIPE -S $MOUNT)
1950         local default_offset=$($GETSTRIPE -i $MOUNT)
1951         local dsize=$((1024 * 1024))
1952         [ $default_size -eq $dsize ] ||
1953                 error "stripe size $default_size != $dsize"
1954         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1955         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1956 }
1957 run_test 27A "check filesystem-wide default LOV EA values"
1958
1959 test_27B() { # LU-2523
1960         test_mkdir -p $DIR/$tdir
1961         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1962         touch $DIR/$tdir/f0
1963         # open f1 with O_LOV_DELAY_CREATE
1964         # rename f0 onto f1
1965         # call setstripe ioctl on open file descriptor for f1
1966         # close
1967         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1968                 $DIR/$tdir/f0
1969
1970         rm -f $DIR/$tdir/f1
1971         # open f1 with O_LOV_DELAY_CREATE
1972         # unlink f1
1973         # call setstripe ioctl on open file descriptor for f1
1974         # close
1975         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1976
1977         # Allow multiop to fail in imitation of NFS's busted semantics.
1978         true
1979 }
1980 run_test 27B "call setstripe on open unlinked file/rename victim"
1981
1982 test_27C() { #LU-2871
1983         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1984
1985         declare -a ost_idx
1986         local index
1987         local found
1988         local i
1989         local j
1990
1991         test_mkdir -p $DIR/$tdir
1992         cd $DIR/$tdir
1993         for i in $(seq 0 $((OSTCOUNT - 1))); do
1994                 # set stripe across all OSTs starting from OST$i
1995                 $SETSTRIPE -i $i -c -1 $tfile$i
1996                 # get striping information
1997                 ost_idx=($($GETSTRIPE $tfile$i |
1998                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1999                 echo ${ost_idx[@]}
2000
2001                 # check the layout
2002                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
2003                         error "${#ost_idx[@]} != $OSTCOUNT"
2004
2005                 for index in $(seq 0 $((OSTCOUNT - 1))); do
2006                         found=0
2007                         for j in $(echo ${ost_idx[@]}); do
2008                                 if [ $index -eq $j ]; then
2009                                         found=1
2010                                         break
2011                                 fi
2012                         done
2013                         [ $found = 1 ] ||
2014                                 error "Can not find $index in ${ost_idx[@]}"
2015                 done
2016         done
2017 }
2018 run_test 27C "check full striping across all OSTs"
2019
2020 test_27D() {
2021         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2022         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
2023         local POOL=${POOL:-testpool}
2024         local first_ost=0
2025         local last_ost=$(($OSTCOUNT - 1))
2026         local ost_step=1
2027         local ost_list=$(seq $first_ost $ost_step $last_ost)
2028         local ost_range="$first_ost $last_ost $ost_step"
2029
2030         test_mkdir -p $DIR/$tdir
2031         pool_add $POOL || error "pool_add failed"
2032         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2033         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT ||
2034                 error "llapi_layout_test failed"
2035         cleanup_pools || error "cleanup_pools failed"
2036 }
2037 run_test 27D "validate llapi_layout API"
2038
2039 # Verify that default_easize is increased from its initial value after
2040 # accessing a widely striped file.
2041 test_27E() {
2042         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2043
2044         # 72 bytes is the minimum space required to store striping
2045         # information for a file striped across one OST:
2046         # (sizeof(struct lov_user_md_v3) +
2047         #  sizeof(struct lov_user_ost_data_v1))
2048         local min_easize=72
2049         $LCTL set_param -n llite.*.default_easize $min_easize ||
2050                 error "lctl set_param failed"
2051         local easize=$($LCTL get_param -n llite.*.default_easize)
2052
2053         [ $easize -eq $min_easize ] ||
2054                 error "failed to set default_easize"
2055
2056         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2057                 error "setstripe failed"
2058         cat $DIR/$tfile
2059         rm $DIR/$tfile
2060
2061         easize=$($LCTL get_param -n llite.*.default_easize)
2062
2063         [ $easize -gt $min_easize ] ||
2064                 error "default_easize not updated"
2065 }
2066 run_test 27E "check that default extended attribute size properly increases"
2067
2068 # createtest also checks that device nodes are created and
2069 # then visible correctly (#2091)
2070 test_28() { # bug 2091
2071         test_mkdir $DIR/d28
2072         $CREATETEST $DIR/d28/ct || error
2073 }
2074 run_test 28 "create/mknod/mkdir with bad file types ============"
2075
2076 test_29() {
2077         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2078         cancel_lru_locks mdc
2079         test_mkdir $DIR/d29
2080         touch $DIR/d29/foo
2081         log 'first d29'
2082         ls -l $DIR/d29
2083
2084         declare -i LOCKCOUNTORIG=0
2085         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2086                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2087         done
2088         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
2089
2090         declare -i LOCKUNUSEDCOUNTORIG=0
2091         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2092                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2093         done
2094
2095         log 'second d29'
2096         ls -l $DIR/d29
2097         log 'done'
2098
2099         declare -i LOCKCOUNTCURRENT=0
2100         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2101                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2102         done
2103
2104         declare -i LOCKUNUSEDCOUNTCURRENT=0
2105         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2106                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2107         done
2108
2109         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2110                 $LCTL set_param -n ldlm.dump_namespaces ""
2111                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2112                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2113                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2114                 return 2
2115         fi
2116         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2117                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2118                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2119                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2120                 return 3
2121         fi
2122 }
2123 run_test 29 "IT_GETATTR regression  ============================"
2124
2125 test_30a() { # was test_30
2126         cp $(which ls) $DIR || cp /bin/ls $DIR
2127         $DIR/ls / || error
2128         rm $DIR/ls
2129 }
2130 run_test 30a "execute binary from Lustre (execve) =============="
2131
2132 test_30b() {
2133         cp `which ls` $DIR || cp /bin/ls $DIR
2134         chmod go+rx $DIR/ls
2135         $RUNAS $DIR/ls / || error
2136         rm $DIR/ls
2137 }
2138 run_test 30b "execute binary from Lustre as non-root ==========="
2139
2140 test_30c() { # b=22376
2141         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2142         cp `which ls` $DIR || cp /bin/ls $DIR
2143         chmod a-rw $DIR/ls
2144         cancel_lru_locks mdc
2145         cancel_lru_locks osc
2146         $RUNAS $DIR/ls / || error
2147         rm -f $DIR/ls
2148 }
2149 run_test 30c "execute binary from Lustre without read perms ===="
2150
2151 test_31a() {
2152         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2153         $CHECKSTAT -a $DIR/f31 || error
2154 }
2155 run_test 31a "open-unlink file =================================="
2156
2157 test_31b() {
2158         touch $DIR/f31 || error
2159         ln $DIR/f31 $DIR/f31b || error
2160         $MULTIOP $DIR/f31b Ouc || error
2161         $CHECKSTAT -t file $DIR/f31 || error
2162 }
2163 run_test 31b "unlink file with multiple links while open ======="
2164
2165 test_31c() {
2166         touch $DIR/f31 || error
2167         ln $DIR/f31 $DIR/f31c || error
2168         multiop_bg_pause $DIR/f31 O_uc || return 1
2169         MULTIPID=$!
2170         $MULTIOP $DIR/f31c Ouc
2171         kill -USR1 $MULTIPID
2172         wait $MULTIPID
2173 }
2174 run_test 31c "open-unlink file with multiple links ============="
2175
2176 test_31d() {
2177         opendirunlink $DIR/d31d $DIR/d31d || error
2178         $CHECKSTAT -a $DIR/d31d || error
2179 }
2180 run_test 31d "remove of open directory ========================="
2181
2182 test_31e() { # bug 2904
2183         openfilleddirunlink $DIR/d31e || error
2184 }
2185 run_test 31e "remove of open non-empty directory ==============="
2186
2187 test_31f() { # bug 4554
2188         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2189         set -vx
2190         test_mkdir $DIR/d31f
2191         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2192         cp /etc/hosts $DIR/d31f
2193         ls -l $DIR/d31f
2194         $GETSTRIPE $DIR/d31f/hosts
2195         multiop_bg_pause $DIR/d31f D_c || return 1
2196         MULTIPID=$!
2197
2198         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2199         test_mkdir $DIR/d31f
2200         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2201         cp /etc/hosts $DIR/d31f
2202         ls -l $DIR/d31f
2203         $GETSTRIPE $DIR/d31f/hosts
2204         multiop_bg_pause $DIR/d31f D_c || return 1
2205         MULTIPID2=$!
2206
2207         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2208         wait $MULTIPID || error "first opendir $MULTIPID failed"
2209
2210         sleep 6
2211
2212         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2213         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2214         set +vx
2215 }
2216 run_test 31f "remove of open directory with open-unlink file ==="
2217
2218 test_31g() {
2219         echo "-- cross directory link --"
2220         test_mkdir -c1 $DIR/${tdir}ga
2221         test_mkdir -c1 $DIR/${tdir}gb
2222         touch $DIR/${tdir}ga/f
2223         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2224         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2225         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2226         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2227         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2228 }
2229 run_test 31g "cross directory link==============="
2230
2231 test_31h() {
2232         echo "-- cross directory link --"
2233         test_mkdir -c1 $DIR/${tdir}
2234         test_mkdir -c1 $DIR/${tdir}/dir
2235         touch $DIR/${tdir}/f
2236         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2237         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2238         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2239         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2240         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2241 }
2242 run_test 31h "cross directory link under child==============="
2243
2244 test_31i() {
2245         echo "-- cross directory link --"
2246         test_mkdir -c1 $DIR/$tdir
2247         test_mkdir -c1 $DIR/$tdir/dir
2248         touch $DIR/$tdir/dir/f
2249         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2250         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2251         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2252         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2253         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2254 }
2255 run_test 31i "cross directory link under parent==============="
2256
2257 test_31j() {
2258         test_mkdir -c1 -p $DIR/$tdir
2259         test_mkdir -c1 -p $DIR/$tdir/dir1
2260         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2261         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2262         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2263         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2264         return 0
2265 }
2266 run_test 31j "link for directory==============="
2267
2268 test_31k() {
2269         test_mkdir -c1 -p $DIR/$tdir
2270         touch $DIR/$tdir/s
2271         touch $DIR/$tdir/exist
2272         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2273         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2274         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2275         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2276         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2277         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2278         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2279         return 0
2280 }
2281 run_test 31k "link to file: the same, non-existing, dir==============="
2282
2283 test_31m() {
2284         mkdir $DIR/d31m
2285         touch $DIR/d31m/s
2286         mkdir $DIR/d31m2
2287         touch $DIR/d31m2/exist
2288         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2289         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2290         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2291         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2292         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2293         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2294         return 0
2295 }
2296 run_test 31m "link to file: the same, non-existing, dir==============="
2297
2298 test_31n() {
2299         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2300         nlink=$(stat --format=%h $DIR/$tfile)
2301         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2302         local fd=$(free_fd)
2303         local cmd="exec $fd<$DIR/$tfile"
2304         eval $cmd
2305         cmd="exec $fd<&-"
2306         trap "eval $cmd" EXIT
2307         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2308         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2309         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2310         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2311         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2312         eval $cmd
2313 }
2314 run_test 31n "check link count of unlinked file"
2315
2316 link_one() {
2317         local TEMPNAME=$(mktemp $1_XXXXXX)
2318         mlink $TEMPNAME $1 2> /dev/null &&
2319                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2320         munlink $TEMPNAME
2321 }
2322
2323 test_31o() { # LU-2901
2324         test_mkdir -p $DIR/$tdir
2325         for LOOP in $(seq 100); do
2326                 rm -f $DIR/$tdir/$tfile*
2327                 for THREAD in $(seq 8); do
2328                         link_one $DIR/$tdir/$tfile.$LOOP &
2329                 done
2330                 wait
2331                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2332                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2333                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2334                         break || true
2335         done
2336 }
2337 run_test 31o "duplicate hard links with same filename"
2338
2339 test_31p() {
2340         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2341
2342         test_mkdir $DIR/$tdir
2343         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2344         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2345
2346         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2347                 error "open unlink test1 failed"
2348         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2349                 error "open unlink test2 failed"
2350
2351         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2352                 error "test1 still exists"
2353         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2354                 error "test2 still exists"
2355 }
2356 run_test 31p "remove of open striped directory"
2357
2358 cleanup_test32_mount() {
2359         trap 0
2360         $UMOUNT $DIR/$tdir/ext2-mountpoint
2361 }
2362
2363 test_32a() {
2364         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2365         echo "== more mountpoints and symlinks ================="
2366         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2367         trap cleanup_test32_mount EXIT
2368         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2369         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2370         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2371         cleanup_test32_mount
2372 }
2373 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2374
2375 test_32b() {
2376         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2377         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2378         trap cleanup_test32_mount EXIT
2379         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2380         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2381         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2382         cleanup_test32_mount
2383 }
2384 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2385
2386 test_32c() {
2387         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2388         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2389         trap cleanup_test32_mount EXIT
2390         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2391         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2392         test_mkdir -p $DIR/$tdir/d2/test_dir
2393         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2394         cleanup_test32_mount
2395 }
2396 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2397
2398 test_32d() {
2399         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2400         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2401         trap cleanup_test32_mount EXIT
2402         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2403         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2404         test_mkdir -p $DIR/$tdir/d2/test_dir
2405         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2406         cleanup_test32_mount
2407 }
2408 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2409
2410 test_32e() {
2411         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2412         test_mkdir -p $DIR/d32e/tmp
2413         TMP_DIR=$DIR/d32e/tmp
2414         ln -s $DIR/d32e $TMP_DIR/symlink11
2415         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2416         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2417         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2418 }
2419 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2420
2421 test_32f() {
2422         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2423         test_mkdir -p $DIR/d32f/tmp
2424         TMP_DIR=$DIR/d32f/tmp
2425         ln -s $DIR/d32f $TMP_DIR/symlink11
2426         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2427         ls $DIR/d32f/tmp/symlink11  || error
2428         ls $DIR/d32f/symlink01 || error
2429 }
2430 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2431
2432 test_32g() {
2433         TMP_DIR=$DIR/$tdir/tmp
2434         test_mkdir -p $DIR/$tdir/tmp
2435         test_mkdir $DIR/${tdir}2
2436         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2437         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2438         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2439         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2440         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2441         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2442 }
2443 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2444
2445 test_32h() {
2446         rm -fr $DIR/$tdir $DIR/${tdir}2
2447         TMP_DIR=$DIR/$tdir/tmp
2448         test_mkdir -p $DIR/$tdir/tmp
2449         test_mkdir $DIR/${tdir}2
2450         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2451         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2452         ls $TMP_DIR/symlink12 || error
2453         ls $DIR/$tdir/symlink02  || error
2454 }
2455 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2456
2457 test_32i() {
2458         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2459         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2460         trap cleanup_test32_mount EXIT
2461         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2462         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2463         touch $DIR/$tdir/test_file
2464         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2465         cleanup_test32_mount
2466 }
2467 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2468
2469 test_32j() {
2470         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2471         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2472         trap cleanup_test32_mount EXIT
2473         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2474         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2475         touch $DIR/$tdir/test_file
2476         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2477         cleanup_test32_mount
2478 }
2479 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2480
2481 test_32k() {
2482         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2483         rm -fr $DIR/$tdir
2484         trap cleanup_test32_mount EXIT
2485         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2486         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2487         test_mkdir -p $DIR/$tdir/d2
2488         touch $DIR/$tdir/d2/test_file || error
2489         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2490         cleanup_test32_mount
2491 }
2492 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2493
2494 test_32l() {
2495         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2496         rm -fr $DIR/$tdir
2497         trap cleanup_test32_mount EXIT
2498         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2499         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2500         test_mkdir -p $DIR/$tdir/d2
2501         touch $DIR/$tdir/d2/test_file
2502         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2503         cleanup_test32_mount
2504 }
2505 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2506
2507 test_32m() {
2508         rm -fr $DIR/d32m
2509         test_mkdir -p $DIR/d32m/tmp
2510         TMP_DIR=$DIR/d32m/tmp
2511         ln -s $DIR $TMP_DIR/symlink11
2512         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2513         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2514         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2515 }
2516 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2517
2518 test_32n() {
2519         rm -fr $DIR/d32n
2520         test_mkdir -p $DIR/d32n/tmp
2521         TMP_DIR=$DIR/d32n/tmp
2522         ln -s $DIR $TMP_DIR/symlink11
2523         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2524         ls -l $DIR/d32n/tmp/symlink11  || error
2525         ls -l $DIR/d32n/symlink01 || error
2526 }
2527 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2528
2529 test_32o() {
2530         touch $DIR/$tfile
2531         test_mkdir -p $DIR/d32o/tmp
2532         TMP_DIR=$DIR/d32o/tmp
2533         ln -s $DIR/$tfile $TMP_DIR/symlink12
2534         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2535         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2536         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2537         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2538         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2539 }
2540 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2541
2542 test_32p() {
2543     log 32p_1
2544         rm -fr $DIR/d32p
2545     log 32p_2
2546         rm -f $DIR/$tfile
2547     log 32p_3
2548         touch $DIR/$tfile
2549     log 32p_4
2550         test_mkdir -p $DIR/d32p/tmp
2551     log 32p_5
2552         TMP_DIR=$DIR/d32p/tmp
2553     log 32p_6
2554         ln -s $DIR/$tfile $TMP_DIR/symlink12
2555     log 32p_7
2556         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2557     log 32p_8
2558         cat $DIR/d32p/tmp/symlink12 || error
2559     log 32p_9
2560         cat $DIR/d32p/symlink02 || error
2561     log 32p_10
2562 }
2563 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2564
2565 cleanup_testdir_mount() {
2566         trap 0
2567         $UMOUNT $DIR/$tdir
2568 }
2569
2570 test_32q() {
2571         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2572         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2573         trap cleanup_testdir_mount EXIT
2574         test_mkdir -p $DIR/$tdir
2575         touch $DIR/$tdir/under_the_mount
2576         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2577         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2578         cleanup_testdir_mount
2579 }
2580 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2581
2582 test_32r() {
2583         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2584         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2585         trap cleanup_testdir_mount EXIT
2586         test_mkdir -p $DIR/$tdir
2587         touch $DIR/$tdir/under_the_mount
2588         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2589         ls $DIR/$tdir | grep -q under_the_mount && error || true
2590         cleanup_testdir_mount
2591 }
2592 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2593
2594 test_33aa() {
2595         rm -f $DIR/$tfile
2596         touch $DIR/$tfile
2597         chmod 444 $DIR/$tfile
2598         chown $RUNAS_ID $DIR/$tfile
2599         log 33_1
2600         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2601         log 33_2
2602 }
2603 run_test 33aa "write file with mode 444 (should return error) ===="
2604
2605 test_33a() {
2606         rm -fr $DIR/d33
2607         test_mkdir -p $DIR/d33
2608         chown $RUNAS_ID $DIR/d33
2609         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2610         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2611                 error "open RDWR" || true
2612 }
2613 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2614
2615 test_33b() {
2616         rm -fr $DIR/d33
2617         test_mkdir -p $DIR/d33
2618         chown $RUNAS_ID $DIR/d33
2619         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 || true
2620 }
2621 run_test 33b "test open file with malformed flags (No panic)"
2622
2623 test_33c() {
2624         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2625         local ostnum
2626         local ostname
2627         local write_bytes
2628         local all_zeros
2629
2630         remote_ost_nodsh && skip "remote OST with nodsh" && return
2631         all_zeros=:
2632         rm -fr $DIR/d33
2633         test_mkdir -p $DIR/d33
2634         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2635
2636         sync
2637         for ostnum in $(seq $OSTCOUNT); do
2638                 # test-framework's OST numbering is one-based, while Lustre's
2639                 # is zero-based
2640                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2641                 # Parsing llobdstat's output sucks; we could grep the /proc
2642                 # path, but that's likely to not be as portable as using the
2643                 # llobdstat utility.  So we parse lctl output instead.
2644                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2645                         obdfilter/$ostname/stats |
2646                         awk '/^write_bytes/ {print $7}' )
2647                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2648                 if (( ${write_bytes:-0} > 0 ))
2649                 then
2650                         all_zeros=false
2651                         break;
2652                 fi
2653         done
2654
2655         $all_zeros || return 0
2656
2657         # Write four bytes
2658         echo foo > $DIR/d33/bar
2659         # Really write them
2660         sync
2661
2662         # Total up write_bytes after writing.  We'd better find non-zeros.
2663         for ostnum in $(seq $OSTCOUNT); do
2664                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2665                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2666                         obdfilter/$ostname/stats |
2667                         awk '/^write_bytes/ {print $7}' )
2668                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2669                 if (( ${write_bytes:-0} > 0 ))
2670                 then
2671                         all_zeros=false
2672                         break;
2673                 fi
2674         done
2675
2676         if $all_zeros
2677         then
2678                 for ostnum in $(seq $OSTCOUNT); do
2679                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2680                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2681                         do_facet ost$ostnum lctl get_param -n \
2682                                 obdfilter/$ostname/stats
2683                 done
2684                 error "OST not keeping write_bytes stats (b22312)"
2685         fi
2686 }
2687 run_test 33c "test llobdstat and write_bytes"
2688
2689 test_33d() {
2690         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2691         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2692         local MDTIDX=1
2693         local remote_dir=$DIR/$tdir/remote_dir
2694
2695         test_mkdir -p $DIR/$tdir
2696         $LFS mkdir -i $MDTIDX $remote_dir ||
2697                 error "create remote directory failed"
2698
2699         touch $remote_dir/$tfile
2700         chmod 444 $remote_dir/$tfile
2701         chown $RUNAS_ID $remote_dir/$tfile
2702
2703         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2704
2705         chown $RUNAS_ID $remote_dir
2706         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2707                                         error "create" || true
2708         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2709                                     error "open RDWR" || true
2710         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 || true
2711 }
2712 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2713
2714 test_33e() {
2715         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2716
2717         mkdir $DIR/$tdir
2718
2719         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2720         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2721         mkdir $DIR/$tdir/local_dir
2722
2723         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2724         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2725         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2726
2727         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2728                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2729
2730         rmdir $DIR/$tdir/* || error "rmdir failed"
2731
2732         umask 777
2733         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2734         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2735         mkdir $DIR/$tdir/local_dir
2736
2737         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2738         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2739         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2740
2741         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2742                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2743
2744         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2745
2746         umask 000
2747         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2748         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2749         mkdir $DIR/$tdir/local_dir
2750
2751         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2752         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2753         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2754
2755         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2756                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2757 }
2758 run_test 33e "mkdir and striped directory should have same mode"
2759
2760 cleanup_33f() {
2761         trap 0
2762         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
2763 }
2764
2765 test_33f() {
2766         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2767
2768         mkdir $DIR/$tdir
2769         chmod go+rwx $DIR/$tdir
2770         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
2771         trap cleanup_33f EXIT
2772
2773         $RUNAS lfs mkdir -c$MDSCOUNT $DIR/$tdir/striped_dir ||
2774                 error "cannot create striped directory"
2775
2776         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
2777                 error "cannot create files in striped directory"
2778
2779         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
2780                 error "cannot remove files in striped directory"
2781
2782         $RUNAS rmdir $DIR/$tdir/striped_dir ||
2783                 error "cannot remove striped directory"
2784
2785         cleanup_33f
2786 }
2787 run_test 33f "nonroot user can create, access, and remove a striped directory"
2788
2789 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2790 test_34a() {
2791         rm -f $DIR/f34
2792         $MCREATE $DIR/f34 || error
2793         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2794         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2795         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2796         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2797 }
2798 run_test 34a "truncate file that has not been opened ==========="
2799
2800 test_34b() {
2801         [ ! -f $DIR/f34 ] && test_34a
2802         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2803         $OPENFILE -f O_RDONLY $DIR/f34
2804         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2805         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2806 }
2807 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2808
2809 test_34c() {
2810         [ ! -f $DIR/f34 ] && test_34a
2811         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2812         $OPENFILE -f O_RDWR $DIR/f34
2813         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2814         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2815 }
2816 run_test 34c "O_RDWR opening file-with-size works =============="
2817
2818 test_34d() {
2819         [ ! -f $DIR/f34 ] && test_34a
2820         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2821         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2822         rm $DIR/f34
2823 }
2824 run_test 34d "write to sparse file ============================="
2825
2826 test_34e() {
2827         rm -f $DIR/f34e
2828         $MCREATE $DIR/f34e || error
2829         $TRUNCATE $DIR/f34e 1000 || error
2830         $CHECKSTAT -s 1000 $DIR/f34e || error
2831         $OPENFILE -f O_RDWR $DIR/f34e
2832         $CHECKSTAT -s 1000 $DIR/f34e || error
2833 }
2834 run_test 34e "create objects, some with size and some without =="
2835
2836 test_34f() { # bug 6242, 6243
2837         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2838         SIZE34F=48000
2839         rm -f $DIR/f34f
2840         $MCREATE $DIR/f34f || error
2841         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2842         dd if=$DIR/f34f of=$TMP/f34f
2843         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2844         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2845         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2846         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2847         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2848 }
2849 run_test 34f "read from a file with no objects until EOF ======="
2850
2851 test_34g() {
2852         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2853         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2854         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2855         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2856         cancel_lru_locks osc
2857         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2858                 error "wrong size after lock cancel"
2859
2860         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2861         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2862                 error "expanding truncate failed"
2863         cancel_lru_locks osc
2864         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2865                 error "wrong expanded size after lock cancel"
2866 }
2867 run_test 34g "truncate long file ==============================="
2868
2869 test_34h() {
2870         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2871         local gid=10
2872         local sz=1000
2873
2874         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2875         sync # Flush the cache so that multiop below does not block on cache
2876              # flush when getting the group lock
2877         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2878         MULTIPID=$!
2879
2880         # Since just timed wait is not good enough, let's do a sync write
2881         # that way we are sure enough time for a roundtrip + processing
2882         # passed + 2 seconds of extra margin.
2883         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2884         rm $DIR/${tfile}-1
2885         sleep 2
2886
2887         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2888                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2889                 kill -9 $MULTIPID
2890         fi
2891         wait $MULTIPID
2892         local nsz=`stat -c %s $DIR/$tfile`
2893         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2894 }
2895 run_test 34h "ftruncate file under grouplock should not block"
2896
2897 test_35a() {
2898         cp /bin/sh $DIR/f35a
2899         chmod 444 $DIR/f35a
2900         chown $RUNAS_ID $DIR/f35a
2901         $RUNAS $DIR/f35a && error || true
2902         rm $DIR/f35a
2903 }
2904 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2905
2906 test_36a() {
2907         rm -f $DIR/f36
2908         utime $DIR/f36 || error
2909 }
2910 run_test 36a "MDS utime check (mknod, utime) ==================="
2911
2912 test_36b() {
2913         echo "" > $DIR/f36
2914         utime $DIR/f36 || error
2915 }
2916 run_test 36b "OST utime check (open, utime) ===================="
2917
2918 test_36c() {
2919         rm -f $DIR/d36/f36
2920         test_mkdir $DIR/d36
2921         chown $RUNAS_ID $DIR/d36
2922         $RUNAS utime $DIR/d36/f36 || error
2923 }
2924 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2925
2926 test_36d() {
2927         [ ! -d $DIR/d36 ] && test_36c
2928         echo "" > $DIR/d36/f36
2929         $RUNAS utime $DIR/d36/f36 || error
2930 }
2931 run_test 36d "non-root OST utime check (open, utime) ==========="
2932
2933 test_36e() {
2934         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2935         test_mkdir -p $DIR/$tdir
2936         touch $DIR/$tdir/$tfile
2937         $RUNAS utime $DIR/$tdir/$tfile && \
2938                 error "utime worked, expected failure" || true
2939 }
2940 run_test 36e "utime on non-owned file (should return error) ===="
2941
2942 subr_36fh() {
2943         local fl="$1"
2944         local LANG_SAVE=$LANG
2945         local LC_LANG_SAVE=$LC_LANG
2946         export LANG=C LC_LANG=C # for date language
2947
2948         DATESTR="Dec 20  2000"
2949         test_mkdir -p $DIR/$tdir
2950         lctl set_param fail_loc=$fl
2951         date; date +%s
2952         cp /etc/hosts $DIR/$tdir/$tfile
2953         sync & # write RPC generated with "current" inode timestamp, but delayed
2954         sleep 1
2955         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2956         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2957         cancel_lru_locks osc
2958         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2959         date; date +%s
2960         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2961                 echo "BEFORE: $LS_BEFORE" && \
2962                 echo "AFTER : $LS_AFTER" && \
2963                 echo "WANT  : $DATESTR" && \
2964                 error "$DIR/$tdir/$tfile timestamps changed" || true
2965
2966         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2967 }
2968
2969 test_36f() {
2970         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2971         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2972         subr_36fh "0x80000214"
2973 }
2974 run_test 36f "utime on file racing with OST BRW write =========="
2975
2976 test_36g() {
2977         remote_ost_nodsh && skip "remote OST with nodsh" && return
2978         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2979         local fmd_max_age
2980         local fmd_before
2981         local fmd_after
2982
2983         test_mkdir -p $DIR/$tdir
2984         fmd_max_age=$(do_facet ost1 \
2985                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2986                 head -n 1")
2987
2988         fmd_before=$(do_facet ost1 \
2989                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2990         touch $DIR/$tdir/$tfile
2991         sleep $((fmd_max_age + 12))
2992         fmd_after=$(do_facet ost1 \
2993                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2994
2995         echo "fmd_before: $fmd_before"
2996         echo "fmd_after: $fmd_after"
2997         [[ $fmd_after -gt $fmd_before ]] &&
2998                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
2999                 error "fmd didn't expire after ping" || true
3000 }
3001 run_test 36g "filter mod data cache expiry ====================="
3002
3003 test_36h() {
3004         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3005         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
3006         subr_36fh "0x80000227"
3007 }
3008 run_test 36h "utime on file racing with OST BRW write =========="
3009
3010 test_36i() {
3011         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3012
3013         test_mkdir $DIR/$tdir
3014         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
3015
3016         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3017         local new_mtime=$((mtime + 200))
3018
3019         #change Modify time of striped dir
3020         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3021                         error "change mtime failed"
3022
3023         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3024
3025         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3026 }
3027 run_test 36i "change mtime on striped directory"
3028
3029 # test_37 - duplicate with tests 32q 32r
3030
3031 test_38() {
3032         local file=$DIR/$tfile
3033         touch $file
3034         openfile -f O_DIRECTORY $file
3035         local RC=$?
3036         local ENOTDIR=20
3037         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3038         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3039 }
3040 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3041
3042 test_39() {
3043         touch $DIR/$tfile
3044         touch $DIR/${tfile}2
3045 #       ls -l  $DIR/$tfile $DIR/${tfile}2
3046 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
3047 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
3048         sleep 2
3049         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3050         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3051                 echo "mtime"
3052                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3053                 echo "atime"
3054                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3055                 echo "ctime"
3056                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3057                 error "O_TRUNC didn't change timestamps"
3058         fi
3059 }
3060 run_test 39 "mtime changed on create ==========================="
3061
3062 test_39b() {
3063         test_mkdir -p -c1 $DIR/$tdir
3064         cp -p /etc/passwd $DIR/$tdir/fopen
3065         cp -p /etc/passwd $DIR/$tdir/flink
3066         cp -p /etc/passwd $DIR/$tdir/funlink
3067         cp -p /etc/passwd $DIR/$tdir/frename
3068         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3069
3070         sleep 1
3071         echo "aaaaaa" >> $DIR/$tdir/fopen
3072         echo "aaaaaa" >> $DIR/$tdir/flink
3073         echo "aaaaaa" >> $DIR/$tdir/funlink
3074         echo "aaaaaa" >> $DIR/$tdir/frename
3075
3076         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3077         local link_new=`stat -c %Y $DIR/$tdir/flink`
3078         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3079         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3080
3081         cat $DIR/$tdir/fopen > /dev/null
3082         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3083         rm -f $DIR/$tdir/funlink2
3084         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3085
3086         for (( i=0; i < 2; i++ )) ; do
3087                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3088                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3089                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3090                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3091
3092                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3093                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3094                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3095                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3096
3097                 cancel_lru_locks osc
3098                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3099         done
3100 }
3101 run_test 39b "mtime change on open, link, unlink, rename  ======"
3102
3103 # this should be set to past
3104 TEST_39_MTIME=`date -d "1 year ago" +%s`
3105
3106 # bug 11063
3107 test_39c() {
3108         touch $DIR1/$tfile
3109         sleep 2
3110         local mtime0=`stat -c %Y $DIR1/$tfile`
3111
3112         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3113         local mtime1=`stat -c %Y $DIR1/$tfile`
3114         [ "$mtime1" = $TEST_39_MTIME ] || \
3115                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3116
3117         local d1=`date +%s`
3118         echo hello >> $DIR1/$tfile
3119         local d2=`date +%s`
3120         local mtime2=`stat -c %Y $DIR1/$tfile`
3121         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3122                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3123
3124         mv $DIR1/$tfile $DIR1/$tfile-1
3125
3126         for (( i=0; i < 2; i++ )) ; do
3127                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3128                 [ "$mtime2" = "$mtime3" ] || \
3129                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3130
3131                 cancel_lru_locks osc
3132                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3133         done
3134 }
3135 run_test 39c "mtime change on rename ==========================="
3136
3137 # bug 21114
3138 test_39d() {
3139         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3140         touch $DIR1/$tfile
3141
3142         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3143
3144         for (( i=0; i < 2; i++ )) ; do
3145                 local mtime=`stat -c %Y $DIR1/$tfile`
3146                 [ $mtime = $TEST_39_MTIME ] || \
3147                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3148
3149                 cancel_lru_locks osc
3150                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3151         done
3152 }
3153 run_test 39d "create, utime, stat =============================="
3154
3155 # bug 21114
3156 test_39e() {
3157         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3158         touch $DIR1/$tfile
3159         local mtime1=`stat -c %Y $DIR1/$tfile`
3160
3161         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3162
3163         for (( i=0; i < 2; i++ )) ; do
3164                 local mtime2=`stat -c %Y $DIR1/$tfile`
3165                 [ $mtime2 = $TEST_39_MTIME ] || \
3166                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3167
3168                 cancel_lru_locks osc
3169                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3170         done
3171 }
3172 run_test 39e "create, stat, utime, stat ========================"
3173
3174 # bug 21114
3175 test_39f() {
3176         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3177         touch $DIR1/$tfile
3178         mtime1=`stat -c %Y $DIR1/$tfile`
3179
3180         sleep 2
3181         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3182
3183         for (( i=0; i < 2; i++ )) ; do
3184                 local mtime2=`stat -c %Y $DIR1/$tfile`
3185                 [ $mtime2 = $TEST_39_MTIME ] || \
3186                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3187
3188                 cancel_lru_locks osc
3189                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3190         done
3191 }
3192 run_test 39f "create, stat, sleep, utime, stat ================="
3193
3194 # bug 11063
3195 test_39g() {
3196         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3197         echo hello >> $DIR1/$tfile
3198         local mtime1=`stat -c %Y $DIR1/$tfile`
3199
3200         sleep 2
3201         chmod o+r $DIR1/$tfile
3202
3203         for (( i=0; i < 2; i++ )) ; do
3204                 local mtime2=`stat -c %Y $DIR1/$tfile`
3205                 [ "$mtime1" = "$mtime2" ] || \
3206                         error "lost mtime: $mtime2, should be $mtime1"
3207
3208                 cancel_lru_locks osc
3209                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3210         done
3211 }
3212 run_test 39g "write, chmod, stat ==============================="
3213
3214 # bug 11063
3215 test_39h() {
3216         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3217         touch $DIR1/$tfile
3218         sleep 1
3219
3220         local d1=`date`
3221         echo hello >> $DIR1/$tfile
3222         local mtime1=`stat -c %Y $DIR1/$tfile`
3223
3224         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3225         local d2=`date`
3226         if [ "$d1" != "$d2" ]; then
3227                 echo "write and touch not within one second"
3228         else
3229                 for (( i=0; i < 2; i++ )) ; do
3230                         local mtime2=`stat -c %Y $DIR1/$tfile`
3231                         [ "$mtime2" = $TEST_39_MTIME ] || \
3232                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3233
3234                         cancel_lru_locks osc
3235                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3236                 done
3237         fi
3238 }
3239 run_test 39h "write, utime within one second, stat ============="
3240
3241 test_39i() {
3242         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3243         touch $DIR1/$tfile
3244         sleep 1
3245
3246         echo hello >> $DIR1/$tfile
3247         local mtime1=`stat -c %Y $DIR1/$tfile`
3248
3249         mv $DIR1/$tfile $DIR1/$tfile-1
3250
3251         for (( i=0; i < 2; i++ )) ; do
3252                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3253
3254                 [ "$mtime1" = "$mtime2" ] || \
3255                         error "lost mtime: $mtime2, should be $mtime1"
3256
3257                 cancel_lru_locks osc
3258                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3259         done
3260 }
3261 run_test 39i "write, rename, stat =============================="
3262
3263 test_39j() {
3264         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3265         start_full_debug_logging
3266         touch $DIR1/$tfile
3267         sleep 1
3268
3269         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3270         lctl set_param fail_loc=0x80000412
3271         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3272                 error "multiop failed"
3273         local multipid=$!
3274         local mtime1=`stat -c %Y $DIR1/$tfile`
3275
3276         mv $DIR1/$tfile $DIR1/$tfile-1
3277
3278         kill -USR1 $multipid
3279         wait $multipid || error "multiop close failed"
3280
3281         for (( i=0; i < 2; i++ )) ; do
3282                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3283                 [ "$mtime1" = "$mtime2" ] ||
3284                         error "mtime is lost on close: $mtime2, " \
3285                               "should be $mtime1"
3286
3287                 cancel_lru_locks osc
3288                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3289         done
3290         lctl set_param fail_loc=0
3291         stop_full_debug_logging
3292 }
3293 run_test 39j "write, rename, close, stat ======================="
3294
3295 test_39k() {
3296         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3297         touch $DIR1/$tfile
3298         sleep 1
3299
3300         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3301         local multipid=$!
3302         local mtime1=`stat -c %Y $DIR1/$tfile`
3303
3304         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3305
3306         kill -USR1 $multipid
3307         wait $multipid || error "multiop close failed"
3308
3309         for (( i=0; i < 2; i++ )) ; do
3310                 local mtime2=`stat -c %Y $DIR1/$tfile`
3311
3312                 [ "$mtime2" = $TEST_39_MTIME ] || \
3313                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3314
3315                 cancel_lru_locks osc
3316                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3317         done
3318 }
3319 run_test 39k "write, utime, close, stat ========================"
3320
3321 # this should be set to future
3322 TEST_39_ATIME=`date -d "1 year" +%s`
3323
3324 test_39l() {
3325         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3326         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3327         local atime_diff=$(do_facet $SINGLEMDS \
3328                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3329         rm -rf $DIR/$tdir
3330         mkdir -p $DIR/$tdir
3331
3332         # test setting directory atime to future
3333         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3334         local atime=$(stat -c %X $DIR/$tdir)
3335         [ "$atime" = $TEST_39_ATIME ] || \
3336                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3337
3338         # test setting directory atime from future to now
3339         local d1=$(date +%s)
3340         ls $DIR/$tdir
3341         local d2=$(date +%s)
3342
3343         cancel_lru_locks mdc
3344         atime=$(stat -c %X $DIR/$tdir)
3345         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3346                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3347
3348         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3349         sleep 3
3350
3351         # test setting directory atime when now > dir atime + atime_diff
3352         d1=$(date +%s)
3353         ls $DIR/$tdir
3354         d2=$(date +%s)
3355         cancel_lru_locks mdc
3356         atime=$(stat -c %X $DIR/$tdir)
3357         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3358                 error "atime is not updated  : $atime, should be $d2"
3359
3360         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3361         sleep 3
3362
3363         # test not setting directory atime when now < dir atime + atime_diff
3364         ls $DIR/$tdir
3365         cancel_lru_locks mdc
3366         atime=$(stat -c %X $DIR/$tdir)
3367         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3368                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3369
3370         do_facet $SINGLEMDS \
3371                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3372 }
3373 run_test 39l "directory atime update ==========================="
3374
3375 test_39m() {
3376         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3377         touch $DIR1/$tfile
3378         sleep 2
3379         local far_past_mtime=$(date -d "May 29 1953" +%s)
3380         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3381
3382         touch -m -d @$far_past_mtime $DIR1/$tfile
3383         touch -a -d @$far_past_atime $DIR1/$tfile
3384
3385         for (( i=0; i < 2; i++ )) ; do
3386                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3387                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3388                         error "atime or mtime set incorrectly"
3389
3390                 cancel_lru_locks osc
3391                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3392         done
3393 }
3394 run_test 39m "test atime and mtime before 1970"
3395
3396 test_39n() { # LU-3832
3397         local atime_diff=$(do_facet $SINGLEMDS \
3398                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3399         local atime0
3400         local atime1
3401         local atime2
3402
3403         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3404
3405         rm -rf $DIR/$tfile
3406         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3407         atime0=$(stat -c %X $DIR/$tfile)
3408
3409         sleep 5
3410         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3411         atime1=$(stat -c %X $DIR/$tfile)
3412
3413         sleep 5
3414         cancel_lru_locks mdc
3415         cancel_lru_locks osc
3416         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3417         atime2=$(stat -c %X $DIR/$tfile)
3418
3419         do_facet $SINGLEMDS \
3420                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3421
3422         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3423         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3424 }
3425 run_test 39n "check that O_NOATIME is honored"
3426
3427 test_39o() {
3428         TESTDIR=$DIR/$tdir/$tfile
3429         [ -e $TESTDIR ] && rm -rf $TESTDIR
3430         mkdir -p $TESTDIR
3431         cd $TESTDIR
3432         links1=2
3433         ls
3434         mkdir a b
3435         ls
3436         links2=$(stat -c %h .)
3437         [ $(($links1 + 2)) != $links2 ] &&
3438                 error "wrong links count $(($links1 + 2)) != $links2"
3439         rmdir b
3440         links3=$(stat -c %h .)
3441         [ $(($links1 + 1)) != $links3 ] &&
3442                 error "wrong links count $links1 != $links3"
3443         return 0
3444 }
3445 run_test 39o "directory cached attributes updated after create ========"
3446
3447 test_39p() {
3448         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3449         local MDTIDX=1
3450         TESTDIR=$DIR/$tdir/$tfile
3451         [ -e $TESTDIR ] && rm -rf $TESTDIR
3452         test_mkdir -p $TESTDIR
3453         cd $TESTDIR
3454         links1=2
3455         ls
3456         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3457         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3458         ls
3459         links2=$(stat -c %h .)
3460         [ $(($links1 + 2)) != $links2 ] &&
3461                 error "wrong links count $(($links1 + 2)) != $links2"
3462         rmdir remote_dir2
3463         links3=$(stat -c %h .)
3464         [ $(($links1 + 1)) != $links3 ] &&
3465                 error "wrong links count $links1 != $links3"
3466         return 0
3467 }
3468 run_test 39p "remote directory cached attributes updated after create ========"
3469
3470
3471 test_40() {
3472         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3473         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3474                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3475         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3476                 error "$tfile is not 4096 bytes in size"
3477 }
3478 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3479
3480 test_41() {
3481         # bug 1553
3482         small_write $DIR/f41 18
3483 }
3484 run_test 41 "test small file write + fstat ====================="
3485
3486 count_ost_writes() {
3487         lctl get_param -n osc.*.stats |
3488                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3489                         END { printf("%0.0f", writes) }'
3490 }
3491
3492 # decent default
3493 WRITEBACK_SAVE=500
3494 DIRTY_RATIO_SAVE=40
3495 MAX_DIRTY_RATIO=50
3496 BG_DIRTY_RATIO_SAVE=10
3497 MAX_BG_DIRTY_RATIO=25
3498
3499 start_writeback() {
3500         trap 0
3501         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3502         # dirty_ratio, dirty_background_ratio
3503         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3504                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3505                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3506                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3507         else
3508                 # if file not here, we are a 2.4 kernel
3509                 kill -CONT `pidof kupdated`
3510         fi
3511 }
3512
3513 stop_writeback() {
3514         # setup the trap first, so someone cannot exit the test at the
3515         # exact wrong time and mess up a machine
3516         trap start_writeback EXIT
3517         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3518         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3519                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3520                 sysctl -w vm.dirty_writeback_centisecs=0
3521                 sysctl -w vm.dirty_writeback_centisecs=0
3522                 # save and increase /proc/sys/vm/dirty_ratio
3523                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3524                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3525                 # save and increase /proc/sys/vm/dirty_background_ratio
3526                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3527                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3528         else
3529                 # if file not here, we are a 2.4 kernel
3530                 kill -STOP `pidof kupdated`
3531         fi
3532 }
3533
3534 # ensure that all stripes have some grant before we test client-side cache
3535 setup_test42() {
3536         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3537                 dd if=/dev/zero of=$i bs=4k count=1
3538                 rm $i
3539         done
3540 }
3541
3542 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3543 # file truncation, and file removal.
3544 test_42a() {
3545         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3546         setup_test42
3547         cancel_lru_locks osc
3548         stop_writeback
3549         sync; sleep 1; sync # just to be safe
3550         BEFOREWRITES=`count_ost_writes`
3551         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3552         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3553         AFTERWRITES=`count_ost_writes`
3554         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3555                 error "$BEFOREWRITES < $AFTERWRITES"
3556         start_writeback
3557 }
3558 run_test 42a "ensure that we don't flush on close =============="
3559
3560 test_42b() {
3561         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3562         setup_test42
3563         cancel_lru_locks osc
3564         stop_writeback
3565         sync
3566         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3567         BEFOREWRITES=$(count_ost_writes)
3568         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3569         AFTERWRITES=$(count_ost_writes)
3570         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3571                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3572         fi
3573         BEFOREWRITES=$(count_ost_writes)
3574         sync || error "sync: $?"
3575         AFTERWRITES=$(count_ost_writes)
3576         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3577                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3578         fi
3579         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3580         start_writeback
3581         return 0
3582 }
3583 run_test 42b "test destroy of file with cached dirty data ======"
3584
3585 # if these tests just want to test the effect of truncation,
3586 # they have to be very careful.  consider:
3587 # - the first open gets a {0,EOF}PR lock
3588 # - the first write conflicts and gets a {0, count-1}PW
3589 # - the rest of the writes are under {count,EOF}PW
3590 # - the open for truncate tries to match a {0,EOF}PR
3591 #   for the filesize and cancels the PWs.
3592 # any number of fixes (don't get {0,EOF} on open, match
3593 # composite locks, do smarter file size management) fix
3594 # this, but for now we want these tests to verify that
3595 # the cancellation with truncate intent works, so we
3596 # start the file with a full-file pw lock to match against
3597 # until the truncate.
3598 trunc_test() {
3599         test=$1
3600         file=$DIR/$test
3601         offset=$2
3602         cancel_lru_locks osc
3603         stop_writeback
3604         # prime the file with 0,EOF PW to match
3605         touch $file
3606         $TRUNCATE $file 0
3607         sync; sync
3608         # now the real test..
3609         dd if=/dev/zero of=$file bs=1024 count=100
3610         BEFOREWRITES=`count_ost_writes`
3611         $TRUNCATE $file $offset
3612         cancel_lru_locks osc
3613         AFTERWRITES=`count_ost_writes`
3614         start_writeback
3615 }
3616
3617 test_42c() {
3618         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3619         trunc_test 42c 1024
3620         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3621             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3622         rm $file
3623 }
3624 run_test 42c "test partial truncate of file with cached dirty data"
3625
3626 test_42d() {
3627         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3628         trunc_test 42d 0
3629         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3630             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3631         rm $file
3632 }
3633 run_test 42d "test complete truncate of file with cached dirty data"
3634
3635 test_42e() { # bug22074
3636         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3637         local TDIR=$DIR/${tdir}e
3638         local pagesz=$(page_size)
3639         local pages=16 # hardcoded 16 pages, don't change it.
3640         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3641         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3642         local max_dirty_mb
3643         local warmup_files
3644
3645         test_mkdir -p $DIR/${tdir}e
3646         $SETSTRIPE -c 1 $TDIR
3647         createmany -o $TDIR/f $files
3648
3649         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3650
3651         # we assume that with $OSTCOUNT files, at least one of them will
3652         # be allocated on OST0.
3653         warmup_files=$((OSTCOUNT * max_dirty_mb))
3654         createmany -o $TDIR/w $warmup_files
3655
3656         # write a large amount of data into one file and sync, to get good
3657         # avail_grant number from OST.
3658         for ((i=0; i<$warmup_files; i++)); do
3659                 idx=$($GETSTRIPE -i $TDIR/w$i)
3660                 [ $idx -ne 0 ] && continue
3661                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3662                 break
3663         done
3664         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3665         sync
3666         $LCTL get_param $proc_osc0/cur_dirty_bytes
3667         $LCTL get_param $proc_osc0/cur_grant_bytes
3668
3669         # create as much dirty pages as we can while not to trigger the actual
3670         # RPCs directly. but depends on the env, VFS may trigger flush during this
3671         # period, hopefully we are good.
3672         for ((i=0; i<$warmup_files; i++)); do
3673                 idx=$($GETSTRIPE -i $TDIR/w$i)
3674                 [ $idx -ne 0 ] && continue
3675                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3676         done
3677         $LCTL get_param $proc_osc0/cur_dirty_bytes
3678         $LCTL get_param $proc_osc0/cur_grant_bytes
3679
3680         # perform the real test
3681         $LCTL set_param $proc_osc0/rpc_stats 0
3682         for ((;i<$files; i++)); do
3683                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3684                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3685         done
3686         sync
3687         $LCTL get_param $proc_osc0/rpc_stats
3688
3689         local percent=0
3690         local have_ppr=false
3691         $LCTL get_param $proc_osc0/rpc_stats |
3692                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3693                         # skip lines until we are at the RPC histogram data
3694                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3695                         $have_ppr || continue
3696
3697                         # we only want the percent stat for < 16 pages
3698                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3699
3700                         percent=$((percent + WPCT))
3701                         if [[ $percent -gt 15 ]]; then
3702                                 error "less than 16-pages write RPCs" \
3703                                       "$percent% > 15%"
3704                                 break
3705                         fi
3706                 done
3707         rm -rf $TDIR
3708 }
3709 run_test 42e "verify sub-RPC writes are not done synchronously"
3710
3711 test_43() {
3712         test_mkdir -p $DIR/$tdir
3713         cp -p /bin/ls $DIR/$tdir/$tfile
3714         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3715         pid=$!
3716         # give multiop a chance to open
3717         sleep 1
3718
3719         $DIR/$tdir/$tfile && error || true
3720         kill -USR1 $pid
3721 }
3722 run_test 43 "execution of file opened for write should return -ETXTBSY"
3723
3724 test_43a() {
3725         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3726         test_mkdir -p $DIR/$tdir
3727         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3728                         cp -p multiop $DIR/$tdir/multiop
3729         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3730                         return 1
3731         MULTIOP_PID=$!
3732         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3733         kill -USR1 $MULTIOP_PID || return 2
3734         wait $MULTIOP_PID || return 3
3735         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3736 }
3737 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3738
3739 test_43b() {
3740         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3741         test_mkdir -p $DIR/$tdir
3742         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3743                         cp -p multiop $DIR/$tdir/multiop
3744         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3745                         return 1
3746         MULTIOP_PID=$!
3747         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3748         kill -USR1 $MULTIOP_PID || return 2
3749         wait $MULTIOP_PID || return 3
3750         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3751 }
3752 run_test 43b "truncate of file being executed should return -ETXTBSY"
3753
3754 test_43c() {
3755         local testdir="$DIR/$tdir"
3756         test_mkdir -p $DIR/$tdir
3757         cp $SHELL $testdir/
3758         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3759                 ( cd $testdir && md5sum -c)
3760 }
3761 run_test 43c "md5sum of copy into lustre========================"
3762
3763 test_44() {
3764         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3765         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3766         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3767 }
3768 run_test 44 "zero length read from a sparse stripe ============="
3769
3770 test_44a() {
3771         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3772                 awk '{ print $2 }')
3773         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3774         [[ $nstripe -gt $OSTCOUNT ]] &&
3775             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3776             return
3777         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3778                 awk '{ print $2 }')
3779         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3780                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3781                         awk '{ print $2 }')
3782         fi
3783
3784         OFFSETS="0 $((stride/2)) $((stride-1))"
3785         for offset in $OFFSETS; do
3786                 for i in $(seq 0 $((nstripe-1))); do
3787                         local GLOBALOFFSETS=""
3788                         # size in Bytes
3789                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3790                         local myfn=$DIR/d44a-$size
3791                         echo "--------writing $myfn at $size"
3792                         ll_sparseness_write $myfn $size ||
3793                                 error "ll_sparseness_write"
3794                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3795                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3796                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3797
3798                         for j in $(seq 0 $((nstripe-1))); do
3799                                 # size in Bytes
3800                                 size=$((((j + $nstripe )*$stride + $offset)))
3801                                 ll_sparseness_write $myfn $size ||
3802                                         error "ll_sparseness_write"
3803                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3804                         done
3805                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3806                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3807                         rm -f $myfn
3808                 done
3809         done
3810 }
3811 run_test 44a "test sparse pwrite ==============================="
3812
3813 dirty_osc_total() {
3814         tot=0
3815         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3816                 tot=$(($tot + $d))
3817         done
3818         echo $tot
3819 }
3820 do_dirty_record() {
3821         before=`dirty_osc_total`
3822         echo executing "\"$*\""
3823         eval $*
3824         after=`dirty_osc_total`
3825         echo before $before, after $after
3826 }
3827 test_45() {
3828         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3829         f="$DIR/f45"
3830         # Obtain grants from OST if it supports it
3831         echo blah > ${f}_grant
3832         stop_writeback
3833         sync
3834         do_dirty_record "echo blah > $f"
3835         [[ $before -eq $after ]] && error "write wasn't cached"
3836         do_dirty_record "> $f"
3837         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3838         do_dirty_record "echo blah > $f"
3839         [[ $before -eq $after ]] && error "write wasn't cached"
3840         do_dirty_record "sync"
3841         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3842         do_dirty_record "echo blah > $f"
3843         [[ $before -eq $after ]] && error "write wasn't cached"
3844         do_dirty_record "cancel_lru_locks osc"
3845         [[ $before -gt $after ]] ||
3846                 error "lock cancellation didn't lower dirty count"
3847         start_writeback
3848 }
3849 run_test 45 "osc io page accounting ============================"
3850
3851 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3852 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3853 # objects offset and an assert hit when an rpc was built with 1023's mapped
3854 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3855 test_46() {
3856         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3857         f="$DIR/f46"
3858         stop_writeback
3859         sync
3860         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3861         sync
3862         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3863         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3864         sync
3865         start_writeback
3866 }
3867 run_test 46 "dirtying a previously written page ================"
3868
3869 # test_47 is removed "Device nodes check" is moved to test_28
3870
3871 test_48a() { # bug 2399
3872         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
3873         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
3874                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly" &&
3875                 return
3876         test_mkdir $DIR/$tdir
3877         cd $DIR/$tdir
3878         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
3879         test_mkdir $DIR/$tdir || error "recreate directory failed"
3880         touch foo || error "'touch foo' failed after recreating cwd"
3881         test_mkdir bar || error "'mkdir foo' failed after recreating cwd"
3882         touch .foo || error "'touch .foo' failed after recreating cwd"
3883         test_mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
3884         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3885         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3886         cd . || error "'cd .' failed after recreating cwd"
3887         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3888         rmdir . && error "'rmdir .' worked after recreating cwd"
3889         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3890         cd .. || error "'cd ..' failed after recreating cwd"
3891 }
3892 run_test 48a "Access renamed working dir (should return errors)="
3893
3894 test_48b() { # bug 2399
3895         rm -rf $DIR/$tdir
3896         test_mkdir $DIR/$tdir
3897         cd $DIR/$tdir
3898         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3899         touch foo && error "'touch foo' worked after removing cwd"
3900         test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3901         touch .foo && error "'touch .foo' worked after removing cwd"
3902         test_mkdir .foo && error "'mkdir .foo' worked after removing cwd"
3903         ls . > /dev/null && error "'ls .' worked after removing cwd"
3904         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3905         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3906         test_mkdir . && error "'mkdir .' worked after removing cwd"
3907         rmdir . && error "'rmdir .' worked after removing cwd"
3908         ln -s . foo && error "'ln -s .' worked after removing cwd"
3909         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3910 }
3911 run_test 48b "Access removed working dir (should return errors)="
3912
3913 test_48c() { # bug 2350
3914         #lctl set_param debug=-1
3915         #set -vx
3916         rm -rf $DIR/$tdir
3917         test_mkdir -p $DIR/$tdir/dir
3918         cd $DIR/$tdir/dir
3919         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3920         $TRACE touch foo && error "touch foo worked after removing cwd"
3921         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3922         touch .foo && error "touch .foo worked after removing cwd"
3923         test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3924         $TRACE ls . && error "'ls .' worked after removing cwd"
3925         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3926         is_patchless || ( $TRACE cd . &&
3927                         error "'cd .' worked after removing cwd" )
3928         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3929         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3930         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3931         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3932 }
3933 run_test 48c "Access removed working subdir (should return errors)"
3934
3935 test_48d() { # bug 2350
3936         #lctl set_param debug=-1
3937         #set -vx
3938         rm -rf $DIR/$tdir
3939         test_mkdir -p $DIR/$tdir/dir
3940         cd $DIR/$tdir/dir
3941         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3942         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3943         $TRACE touch foo && error "'touch foo' worked after removing parent"
3944         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3945         touch .foo && error "'touch .foo' worked after removing parent"
3946         test_mkdir .foo && error "mkdir .foo worked after removing parent"
3947         $TRACE ls . && error "'ls .' worked after removing parent"
3948         $TRACE ls .. && error "'ls ..' worked after removing parent"
3949         is_patchless || ( $TRACE cd . &&
3950                         error "'cd .' worked after recreate parent" )
3951         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3952         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3953         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3954         is_patchless || ( $TRACE cd .. &&
3955                         error "'cd ..' worked after removing parent" || true )
3956 }
3957 run_test 48d "Access removed parent subdir (should return errors)"
3958
3959 test_48e() { # bug 4134
3960         #lctl set_param debug=-1
3961         #set -vx
3962         rm -rf $DIR/$tdir
3963         test_mkdir -p $DIR/$tdir/dir
3964         cd $DIR/$tdir/dir
3965         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3966         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3967         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3968         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3969         # On a buggy kernel addition of "touch foo" after cd .. will
3970         # produce kernel oops in lookup_hash_it
3971         touch ../foo && error "'cd ..' worked after recreate parent"
3972         cd $DIR
3973         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3974 }
3975 run_test 48e "Access to recreated parent subdir (should return errors)"
3976
3977 test_49() { # LU-1030
3978         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3979         # get ost1 size - lustre-OST0000
3980         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3981                 awk '{ print $4 }')
3982         # write 800M at maximum
3983         [[ $ost1_size -lt 2 ]] && ost1_size=2
3984         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3985
3986         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3987         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3988         local dd_pid=$!
3989
3990         # change max_pages_per_rpc while writing the file
3991         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3992         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3993         # loop until dd process exits
3994         while ps ax -opid | grep -wq $dd_pid; do
3995                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3996                 sleep $((RANDOM % 5 + 1))
3997         done
3998         # restore original max_pages_per_rpc
3999         $LCTL set_param $osc1_mppc=$orig_mppc
4000         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
4001 }
4002 run_test 49 "Change max_pages_per_rpc won't break osc extent"
4003
4004 test_50() {
4005         # bug 1485
4006         test_mkdir $DIR/$tdir
4007         cd $DIR/$tdir
4008         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
4009 }
4010 run_test 50 "special situations: /proc symlinks  ==============="
4011
4012 test_51a() {    # was test_51
4013         # bug 1516 - create an empty entry right after ".." then split dir
4014         test_mkdir -c1 $DIR/$tdir
4015         touch $DIR/$tdir/foo
4016         $MCREATE $DIR/$tdir/bar
4017         rm $DIR/$tdir/foo
4018         createmany -m $DIR/$tdir/longfile 201
4019         FNUM=202
4020         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
4021                 $MCREATE $DIR/$tdir/longfile$FNUM
4022                 FNUM=$(($FNUM + 1))
4023                 echo -n "+"
4024         done
4025         echo
4026         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
4027 }
4028 run_test 51a "special situations: split htree with empty entry =="
4029
4030 export NUMTEST=70000
4031 test_51b() {
4032         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4033         local BASE=$DIR/d${base}.${TESTSUITE}
4034
4035         # cleanup the directory
4036         rm -fr $BASE
4037
4038         test_mkdir -p -c1 $BASE
4039
4040         $LFS df
4041         $LFS df -i
4042         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
4043         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
4044         [[ $numfree -lt 21000 ]] &&
4045                 skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
4046                 return
4047
4048         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
4049                 echo "reduced count to $NUMTEST due to inodes on MDT$mdtidx"
4050
4051         # need to check free space for the directories as well
4052         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
4053         numfree=$((blkfree / 4))
4054         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$((numfree - 50)) &&
4055                 echo "reduced count to $NUMTEST due to blocks on MDT$mdtidx"
4056
4057         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
4058         {
4059                 $LFS df
4060                 $LFS df -i
4061                 echo "failed" > $BASE/fnum
4062                 error "failed to create $NUMTEST subdirs in MDT$mdtidx:$BASE"
4063         }
4064 }
4065 run_test 51b "exceed 64k subdirectory nlink limit"
4066
4067 test_51ba() { # LU-993
4068         local BASE=$DIR/d${base}.${TESTSUITE}
4069         # unlink all but 100 subdirectories, then check it still works
4070         local LEFT=100
4071         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
4072
4073         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
4074         local DELETE=$((NUMTEST - LEFT))
4075
4076         # continue on to run this test even if 51b didn't finish,
4077         # just to delete the many subdirectories created.
4078         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
4079
4080         # for ldiskfs the nlink count should be 1, but this is OSD specific
4081         # and so this is listed for informational purposes only
4082         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
4083         unlinkmany -d $BASE/d $DELETE
4084         RC=$?
4085
4086         if [ $RC -ne 0 ]; then
4087                 if [ "$NUMPREV" == "failed" ]; then
4088                         skip "previous setup failed"
4089                         return 0
4090                 else
4091                         error "unlink of first $DELETE subdirs failed"
4092                         return $RC
4093                 fi
4094         fi
4095
4096         echo "nlink between: $(stat -c %h $BASE)"
4097         # trim the first line of ls output
4098         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
4099         [ $FOUND -ne $LEFT ] &&
4100                 error "can't find subdirs: found only $FOUND/$LEFT"
4101
4102         unlinkmany -d $BASE/d $DELETE $LEFT ||
4103                 error "unlink of second $LEFT subdirs failed"
4104         # regardless of whether the backing filesystem tracks nlink accurately
4105         # or not, the nlink count shouldn't be more than "." and ".." here
4106         local AFTER=$(stat -c %h $BASE)
4107         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
4108                 echo "nlink after: $AFTER"
4109 }
4110 run_test 51ba "verify nlink for many subdirectory cleanup"
4111
4112 test_51d() {
4113         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4114         [[ $OSTCOUNT -lt 3 ]] &&
4115                 skip_env "skipping test with few OSTs" && return
4116         test_mkdir -p $DIR/$tdir
4117         createmany -o $DIR/$tdir/t- 1000
4118         $GETSTRIPE $DIR/$tdir > $TMP/files
4119         for N in $(seq 0 $((OSTCOUNT - 1))); do
4120                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4121                         END { printf("%0.0f", objs) }' $TMP/files)
4122                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
4123                         '($1 == '$N') { objs += 1 } \
4124                         END { printf("%0.0f", objs) }')
4125                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4126         done
4127         unlinkmany $DIR/$tdir/t- 1000
4128
4129         NLAST=0
4130         for N in $(seq 1 $((OSTCOUNT - 1))); do
4131                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4132                         error "OST $N has less objects vs OST $NLAST" \
4133                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4134                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4135                         error "OST $N has less objects vs OST $NLAST" \
4136                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4137
4138                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4139                         error "OST $N has less #0 objects vs OST $NLAST" \
4140                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4141                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4142                         error "OST $N has less #0 objects vs OST $NLAST" \
4143                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4144                 NLAST=$N
4145         done
4146 }
4147 run_test 51d "check object distribution ===================="
4148
4149 test_51e() {
4150         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4151                 skip "Only applicable to ldiskfs-based MDTs"
4152                 return
4153         fi
4154
4155         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4156         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4157
4158         touch $DIR/$tdir/d0/foo
4159         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4160                 error "file exceed 65000 nlink limit!"
4161         unlinkmany $DIR/$tdir/d0/f- 65001
4162         return 0
4163 }
4164 run_test 51e "check file nlink limit"
4165
4166 test_52a() {
4167         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4168         test_mkdir -p $DIR/$tdir
4169         touch $DIR/$tdir/foo
4170         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4171         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4172         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4173         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4174         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4175                                         error "link worked"
4176         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4177         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4178         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4179                                                      error "lsattr"
4180         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4181         cp -r $DIR/$tdir /tmp/
4182         rm -fr $DIR/$tdir || error "cleanup rm failed"
4183 }
4184 run_test 52a "append-only flag test (should return errors) ====="
4185
4186 test_52b() {
4187         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4188         test_mkdir -p $DIR/$tdir
4189         touch $DIR/$tdir/foo
4190         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4191         cat test > $DIR/$tdir/foo && error "cat test worked"
4192         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4193         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4194         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4195                                         error "link worked"
4196         echo foo >> $DIR/$tdir/foo && error "echo worked"
4197         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4198         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4199         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4200         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4201                                                         error "lsattr"
4202         chattr -i $DIR/$tdir/foo || error "chattr failed"
4203
4204         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4205 }
4206 run_test 52b "immutable flag test (should return errors) ======="
4207
4208 test_53() {
4209         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4210         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4211         remote_ost_nodsh && skip "remote OST with nodsh" && return
4212
4213         local param
4214         local param_seq
4215         local ostname
4216         local mds_last
4217         local mds_last_seq
4218         local ost_last
4219         local ost_last_seq
4220         local ost_last_id
4221         local ostnum
4222         local node
4223         local found=false
4224         local support_last_seq=true
4225
4226         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4227                 support_last_seq=false
4228
4229         # only test MDT0000
4230         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4231         local value
4232         for value in $(do_facet $SINGLEMDS \
4233                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4234                 param=$(echo ${value[0]} | cut -d "=" -f1)
4235                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4236
4237                 if $support_last_seq; then
4238                         param_seq=$(echo $param |
4239                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4240                         mds_last_seq=$(do_facet $SINGLEMDS \
4241                                        $LCTL get_param -n $param_seq)
4242                 fi
4243                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4244
4245                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4246                 node=$(facet_active_host ost$((ostnum+1)))
4247                 param="obdfilter.$ostname.last_id"
4248                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4249                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4250                         ost_last_id=$ost_last
4251
4252                         if $support_last_seq; then
4253                                 ost_last_id=$(echo $ost_last |
4254                                               awk -F':' '{print $2}' |
4255                                               sed -e "s/^0x//g")
4256                                 ost_last_seq=$(echo $ost_last |
4257                                                awk -F':' '{print $1}')
4258                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4259                         fi
4260
4261                         if [[ $ost_last_id != $mds_last ]]; then
4262                                 error "$ost_last_id != $mds_last"
4263                         else
4264                                 found=true
4265                                 break
4266                         fi
4267                 done
4268         done
4269         $found || error "can not match last_seq/last_id for $mdtosc"
4270         return 0
4271 }
4272 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4273
4274 test_54a() {
4275         $SOCKETSERVER $DIR/socket ||
4276                 error "$SOCKETSERVER $DIR/socket failed: $?"
4277         $SOCKETCLIENT $DIR/socket ||
4278                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4279         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4280 }
4281 run_test 54a "unix domain socket test =========================="
4282
4283 test_54b() {
4284         f="$DIR/f54b"
4285         mknod $f c 1 3
4286         chmod 0666 $f
4287         dd if=/dev/zero of=$f bs=$(page_size) count=1
4288 }
4289 run_test 54b "char device works in lustre ======================"
4290
4291 find_loop_dev() {
4292         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4293         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4294         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4295
4296         for i in $(seq 3 7); do
4297                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4298                 LOOPDEV=$LOOPBASE$i
4299                 LOOPNUM=$i
4300                 break
4301         done
4302 }
4303
4304 cleanup_54c() {
4305         loopdev="$DIR/loop54c"
4306
4307         trap 0
4308         $UMOUNT $DIR/$tdir || rc=$?
4309         losetup -d $loopdev || true
4310         losetup -d $LOOPDEV || true
4311         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4312         return $rc
4313 }
4314
4315 test_54c() {
4316         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4317         loopdev="$DIR/loop54c"
4318
4319         find_loop_dev
4320         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4321         trap cleanup_54c EXIT
4322         mknod $loopdev b 7 $LOOPNUM
4323         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4324         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4325         losetup $loopdev $DIR/$tfile ||
4326                 error "can't set up $loopdev for $DIR/$tfile"
4327         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4328         test_mkdir -p $DIR/$tdir
4329         mount -t ext2 $loopdev $DIR/$tdir ||
4330                 error "error mounting $loopdev on $DIR/$tdir"
4331         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4332                 error "dd write"
4333         df $DIR/$tdir
4334         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4335                 error "dd read"
4336         cleanup_54c
4337 }
4338 run_test 54c "block device works in lustre ====================="
4339
4340 test_54d() {
4341         f="$DIR/f54d"
4342         string="aaaaaa"
4343         mknod $f p
4344         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4345 }
4346 run_test 54d "fifo device works in lustre ======================"
4347
4348 test_54e() {
4349         f="$DIR/f54e"
4350         string="aaaaaa"
4351         cp -aL /dev/console $f
4352         echo $string > $f || error "echo $string to $f failed"
4353 }
4354 run_test 54e "console/tty device works in lustre ======================"
4355
4356 #The test_55 used to be iopen test and it was removed by bz#24037.
4357 #run_test 55 "check iopen_connect_dentry() ======================"
4358
4359 test_56a() {    # was test_56
4360         rm -rf $DIR/$tdir
4361         $SETSTRIPE -d $DIR
4362         test_mkdir -p $DIR/$tdir/dir
4363         NUMFILES=3
4364         NUMFILESx2=$(($NUMFILES * 2))
4365         for i in $(seq 1 $NUMFILES); do
4366                 touch $DIR/$tdir/file$i
4367                 touch $DIR/$tdir/dir/file$i
4368         done
4369
4370         # test lfs getstripe with --recursive
4371         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4372         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4373                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4374         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4375         [[ $FILENUM -eq $NUMFILES ]] ||
4376                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4377         echo "$GETSTRIPE --recursive passed."
4378
4379         # test lfs getstripe with file instead of dir
4380         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4381         [[ $FILENUM -eq 1 ]] ||
4382                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4383         echo "$GETSTRIPE file1 passed."
4384
4385         #test lfs getstripe with --verbose
4386         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4387                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4388                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4389         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4390                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4391         echo "$GETSTRIPE --verbose passed."
4392
4393         #test lfs getstripe with --obd
4394         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4395                 grep -q "unknown obduuid" ||
4396                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4397
4398         [[ $OSTCOUNT -lt 2 ]] &&
4399                 skip_env "skipping other $GETSTRIPE --obd test" && return
4400
4401         OSTIDX=1
4402         OBDUUID=$(ostuuid_from_index $OSTIDX)
4403         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4404         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4405         [[ $FOUND -eq $FILENUM ]] ||
4406                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4407         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4408                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4409                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4410                 error "$GETSTRIPE --obd: should not show file on other obd"
4411         echo "$GETSTRIPE --obd passed"
4412 }
4413 run_test 56a "check $GETSTRIPE"
4414
4415 NUMFILES=3
4416 NUMDIRS=3
4417 setup_56() {
4418         local LOCAL_NUMFILES="$1"
4419         local LOCAL_NUMDIRS="$2"
4420         local MKDIR_PARAMS="$3"
4421         local DIR_STRIPE_PARAMS="$4"
4422
4423         if [ ! -d "$TDIR" ] ; then
4424                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4425                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4426                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4427                         touch $TDIR/file$i
4428                 done
4429                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4430                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4431                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4432                                 touch $TDIR/dir$i/file$j
4433                         done
4434                 done
4435         fi
4436 }
4437
4438 setup_56_special() {
4439         LOCAL_NUMFILES=$1
4440         LOCAL_NUMDIRS=$2
4441         setup_56 $1 $2
4442         if [ ! -e "$TDIR/loop1b" ] ; then
4443                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4444                         mknod $TDIR/loop${i}b b 7 $i
4445                         mknod $TDIR/null${i}c c 1 3
4446                         ln -s $TDIR/file1 $TDIR/link${i}l
4447                 done
4448                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4449                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4450                         mknod $TDIR/dir$i/null${i}c c 1 3
4451                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4452                 done
4453         fi
4454 }
4455
4456 test_56g() {
4457         $SETSTRIPE -d $DIR
4458
4459         TDIR=$DIR/${tdir}g
4460         setup_56 $NUMFILES $NUMDIRS
4461
4462         EXPECTED=$(($NUMDIRS + 2))
4463         # test lfs find with -name
4464         for i in $(seq 1 $NUMFILES) ; do
4465                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4466                 [ $NUMS -eq $EXPECTED ] ||
4467                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4468                               "found $NUMS, expected $EXPECTED"
4469         done
4470 }
4471 run_test 56g "check lfs find -name ============================="
4472
4473 test_56h() {
4474         $SETSTRIPE -d $DIR
4475
4476         TDIR=$DIR/${tdir}g
4477         setup_56 $NUMFILES $NUMDIRS
4478
4479         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4480         # test lfs find with ! -name
4481         for i in $(seq 1 $NUMFILES) ; do
4482                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4483                 [ $NUMS -eq $EXPECTED ] ||
4484                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4485                               "found $NUMS, expected $EXPECTED"
4486         done
4487 }
4488 run_test 56h "check lfs find ! -name ============================="
4489
4490 test_56i() {
4491        tdir=${tdir}i
4492        test_mkdir -p $DIR/$tdir
4493        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4494        CMD="$LFIND -ost $UUID $DIR/$tdir"
4495        OUT=$($CMD)
4496        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4497 }
4498 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4499
4500 test_56j() {
4501         TDIR=$DIR/${tdir}g
4502         setup_56_special $NUMFILES $NUMDIRS
4503
4504         EXPECTED=$((NUMDIRS + 1))
4505         CMD="$LFIND -type d $TDIR"
4506         NUMS=$($CMD | wc -l)
4507         [ $NUMS -eq $EXPECTED ] ||
4508                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4509 }
4510 run_test 56j "check lfs find -type d ============================="
4511
4512 test_56k() {
4513         TDIR=$DIR/${tdir}g
4514         setup_56_special $NUMFILES $NUMDIRS
4515
4516         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4517         CMD="$LFIND -type f $TDIR"
4518         NUMS=$($CMD | wc -l)
4519         [ $NUMS -eq $EXPECTED ] ||
4520                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4521 }
4522 run_test 56k "check lfs find -type f ============================="
4523
4524 test_56l() {
4525         TDIR=$DIR/${tdir}g
4526         setup_56_special $NUMFILES $NUMDIRS
4527
4528         EXPECTED=$((NUMDIRS + NUMFILES))
4529         CMD="$LFIND -type b $TDIR"
4530         NUMS=$($CMD | wc -l)
4531         [ $NUMS -eq $EXPECTED ] ||
4532                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4533 }
4534 run_test 56l "check lfs find -type b ============================="
4535
4536 test_56m() {
4537         TDIR=$DIR/${tdir}g
4538         setup_56_special $NUMFILES $NUMDIRS
4539
4540         EXPECTED=$((NUMDIRS + NUMFILES))
4541         CMD="$LFIND -type c $TDIR"
4542         NUMS=$($CMD | wc -l)
4543         [ $NUMS -eq $EXPECTED ] ||
4544                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4545 }
4546 run_test 56m "check lfs find -type c ============================="
4547
4548 test_56n() {
4549         TDIR=$DIR/${tdir}g
4550         setup_56_special $NUMFILES $NUMDIRS
4551
4552         EXPECTED=$((NUMDIRS + NUMFILES))
4553         CMD="$LFIND -type l $TDIR"
4554         NUMS=$($CMD | wc -l)
4555         [ $NUMS -eq $EXPECTED ] ||
4556                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4557 }
4558 run_test 56n "check lfs find -type l ============================="
4559
4560 test_56o() {
4561         TDIR=$DIR/${tdir}o
4562         setup_56 $NUMFILES $NUMDIRS
4563         utime $TDIR/file1 > /dev/null || error "utime (1)"
4564         utime $TDIR/file2 > /dev/null || error "utime (2)"
4565         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4566         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4567         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4568         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4569
4570         EXPECTED=4
4571         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4572         [ $NUMS -eq $EXPECTED ] || \
4573                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4574
4575         EXPECTED=12
4576         CMD="$LFIND -mtime 0 $TDIR"
4577         NUMS=$($CMD | wc -l)
4578         [ $NUMS -eq $EXPECTED ] ||
4579                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4580 }
4581 run_test 56o "check lfs find -mtime for old files =========================="
4582
4583 test_56p() {
4584         [ $RUNAS_ID -eq $UID ] &&
4585                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4586
4587         TDIR=$DIR/${tdir}p
4588         setup_56 $NUMFILES $NUMDIRS
4589
4590         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4591         EXPECTED=$NUMFILES
4592         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4593         NUMS=$($CMD | wc -l)
4594         [ $NUMS -eq $EXPECTED ] || \
4595                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4596
4597         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4598         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4599         NUMS=$($CMD | wc -l)
4600         [ $NUMS -eq $EXPECTED ] || \
4601                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4602 }
4603 run_test 56p "check lfs find -uid and ! -uid ==============================="
4604
4605 test_56q() {
4606         [ $RUNAS_ID -eq $UID ] &&
4607                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4608
4609         TDIR=$DIR/${tdir}q
4610         setup_56 $NUMFILES $NUMDIRS
4611
4612         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4613
4614         EXPECTED=$NUMFILES
4615         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4616         NUMS=$($CMD | wc -l)
4617         [ $NUMS -eq $EXPECTED ] ||
4618                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4619
4620         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4621         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4622         NUMS=$($CMD | wc -l)
4623         [ $NUMS -eq $EXPECTED ] ||
4624                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4625 }
4626 run_test 56q "check lfs find -gid and ! -gid ==============================="
4627
4628 test_56r() {
4629         TDIR=$DIR/${tdir}r
4630         setup_56 $NUMFILES $NUMDIRS
4631
4632         EXPECTED=12
4633         CMD="$LFIND -size 0 -type f $TDIR"
4634         NUMS=$($CMD | wc -l)
4635         [ $NUMS -eq $EXPECTED ] ||
4636                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4637         EXPECTED=0
4638         CMD="$LFIND ! -size 0 -type f $TDIR"
4639         NUMS=$($CMD | wc -l)
4640         [ $NUMS -eq $EXPECTED ] ||
4641                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4642         echo "test" > $TDIR/$tfile
4643         echo "test2" > $TDIR/$tfile.2 && sync
4644         EXPECTED=1
4645         CMD="$LFIND -size 5 -type f $TDIR"
4646         NUMS=$($CMD | wc -l)
4647         [ $NUMS -eq $EXPECTED ] ||
4648                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4649         EXPECTED=1
4650         CMD="$LFIND -size +5 -type f $TDIR"
4651         NUMS=$($CMD | wc -l)
4652         [ $NUMS -eq $EXPECTED ] ||
4653                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4654         EXPECTED=2
4655         CMD="$LFIND -size +0 -type f $TDIR"
4656         NUMS=$($CMD | wc -l)
4657         [ $NUMS -eq $EXPECTED ] ||
4658                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4659         EXPECTED=2
4660         CMD="$LFIND ! -size -5 -type f $TDIR"
4661         NUMS=$($CMD | wc -l)
4662         [ $NUMS -eq $EXPECTED ] ||
4663                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4664         EXPECTED=12
4665         CMD="$LFIND -size -5 -type f $TDIR"
4666         NUMS=$($CMD | wc -l)
4667         [ $NUMS -eq $EXPECTED ] ||
4668                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4669 }
4670 run_test 56r "check lfs find -size works =========================="
4671
4672 test_56s() { # LU-611
4673         TDIR=$DIR/${tdir}s
4674         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4675
4676         if [[ $OSTCOUNT -gt 1 ]]; then
4677                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4678                 ONESTRIPE=4
4679                 EXTRA=4
4680         else
4681                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4682                 EXTRA=0
4683         fi
4684
4685         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4686         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4687         NUMS=$($CMD | wc -l)
4688         [ $NUMS -eq $EXPECTED ] || {
4689                 $GETSTRIPE -R $TDIR
4690                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4691         }
4692
4693         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4694         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4695         NUMS=$($CMD | wc -l)
4696         [ $NUMS -eq $EXPECTED ] || {
4697                 $GETSTRIPE -R $TDIR
4698                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4699         }
4700
4701         EXPECTED=$ONESTRIPE
4702         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4703         NUMS=$($CMD | wc -l)
4704         [ $NUMS -eq $EXPECTED ] || {
4705                 $GETSTRIPE -R $TDIR
4706                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4707         }
4708
4709         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4710         NUMS=$($CMD | wc -l)
4711         [ $NUMS -eq $EXPECTED ] || {
4712                 $GETSTRIPE -R $TDIR
4713                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4714         }
4715
4716         EXPECTED=0
4717         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4718         NUMS=$($CMD | wc -l)
4719         [ $NUMS -eq $EXPECTED ] || {
4720                 $GETSTRIPE -R $TDIR
4721                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4722         }
4723 }
4724 run_test 56s "check lfs find -stripe-count works"
4725
4726 test_56t() { # LU-611
4727         TDIR=$DIR/${tdir}t
4728         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4729
4730         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4731
4732         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4733         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4734         NUMS=$($CMD | wc -l)
4735         [ $NUMS -eq $EXPECTED ] ||
4736                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4737
4738         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4739         NUMS=$($CMD | wc -l)
4740         [ $NUMS -eq $EXPECTED ] ||
4741                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4742
4743         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4744         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4745         NUMS=$($CMD | wc -l)
4746         [ $NUMS -eq $EXPECTED ] ||
4747                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4748
4749         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4750         NUMS=$($CMD | wc -l)
4751         [ $NUMS -eq $EXPECTED ] ||
4752                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4753
4754         EXPECTED=4
4755         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4756         NUMS=$($CMD | wc -l)
4757         [ $NUMS -eq $EXPECTED ] ||
4758                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4759
4760         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4761         NUMS=$($CMD | wc -l)
4762         [ $NUMS -eq $EXPECTED ] ||
4763                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4764
4765         EXPECTED=0
4766         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4767         NUMS=$($CMD | wc -l)
4768         [ $NUMS -eq $EXPECTED ] ||
4769                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4770 }
4771 run_test 56t "check lfs find -stripe-size works"
4772
4773 test_56u() { # LU-611
4774         TDIR=$DIR/${tdir}u
4775         setup_56 $NUMFILES $NUMDIRS "-i 0"
4776
4777         if [[ $OSTCOUNT -gt 1 ]]; then
4778                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4779                 ONESTRIPE=4
4780         else
4781                 ONESTRIPE=0
4782         fi
4783
4784         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4785         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4786         NUMS=$($CMD | wc -l)
4787         [ $NUMS -eq $EXPECTED ] ||
4788                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4789
4790         EXPECTED=$ONESTRIPE
4791         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4792         NUMS=$($CMD | wc -l)
4793         [ $NUMS -eq $EXPECTED ] ||
4794                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4795
4796         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4797         NUMS=$($CMD | wc -l)
4798         [ $NUMS -eq $EXPECTED ] ||
4799                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4800
4801         EXPECTED=0
4802         # This should produce an error and not return any files
4803         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4804         NUMS=$($CMD 2>/dev/null | wc -l)
4805         [ $NUMS -eq $EXPECTED ] ||
4806                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4807
4808         if [[ $OSTCOUNT -gt 1 ]]; then
4809                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4810                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4811                 NUMS=$($CMD | wc -l)
4812                 [ $NUMS -eq $EXPECTED ] ||
4813                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4814         fi
4815 }
4816 run_test 56u "check lfs find -stripe-index works"
4817
4818 test_56v() {
4819     local MDT_IDX=0
4820
4821     TDIR=$DIR/${tdir}v
4822     rm -rf $TDIR
4823     setup_56 $NUMFILES $NUMDIRS
4824
4825     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4826     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4827
4828     for file in $($LFIND -mdt $UUID $TDIR); do
4829         file_mdt_idx=$($GETSTRIPE -M $file)
4830         [ $file_mdt_idx -eq $MDT_IDX ] ||
4831             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4832     done
4833 }
4834 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4835
4836 test_56w() {
4837         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
4838                 return
4839         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4840         TDIR=$DIR/${tdir}w
4841
4842     rm -rf $TDIR || error "remove $TDIR failed"
4843     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4844
4845     local stripe_size
4846     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4847         error "$GETSTRIPE -S -d $TDIR failed"
4848     stripe_size=${stripe_size%% *}
4849
4850     local file_size=$((stripe_size * OSTCOUNT))
4851     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4852     local required_space=$((file_num * file_size))
4853
4854     local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
4855                         head -n1)
4856     [[ $free_space -le $((required_space / 1024)) ]] &&
4857         skip_env "need at least $required_space bytes free space," \
4858                  "have $free_space kbytes" && return
4859
4860     local dd_bs=65536
4861     local dd_count=$((file_size / dd_bs))
4862
4863     # write data into the files
4864     local i
4865     local j
4866     local file
4867     for i in $(seq 1 $NUMFILES); do
4868         file=$TDIR/file$i
4869         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4870             error "write data into $file failed"
4871     done
4872     for i in $(seq 1 $NUMDIRS); do
4873         for j in $(seq 1 $NUMFILES); do
4874             file=$TDIR/dir$i/file$j
4875             yes | dd bs=$dd_bs count=$dd_count of=$file \
4876                 >/dev/null 2>&1 ||
4877                 error "write data into $file failed"
4878         done
4879     done
4880
4881     local expected=-1
4882     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4883
4884     # lfs_migrate file
4885     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4886     echo "$cmd"
4887     eval $cmd || error "$cmd failed"
4888
4889     check_stripe_count $TDIR/file1 $expected
4890
4891         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
4892         then
4893                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
4894                 # OST 1 if it is on OST 0. This file is small enough to
4895                 # be on only one stripe.
4896                 file=$TDIR/migr_1_ost
4897                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
4898                         error "write data into $file failed"
4899                 local obdidx=$($LFS getstripe -i $file)
4900                 local oldmd5=$(md5sum $file)
4901                 local newobdidx=0
4902                 [[ $obdidx -eq 0 ]] && newobdidx=1
4903                 cmd="$LFS migrate -i $newobdidx $file"
4904                 echo $cmd
4905                 eval $cmd || error "$cmd failed"
4906                 local realobdix=$($LFS getstripe -i $file)
4907                 local newmd5=$(md5sum $file)
4908                 [[ $newobdidx -ne $realobdix ]] &&
4909                         error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
4910                 [[ "$oldmd5" != "$newmd5" ]] &&
4911                         error "md5sum differ: $oldmd5, $newmd5"
4912         fi
4913
4914     # lfs_migrate dir
4915     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4916     echo "$cmd"
4917     eval $cmd || error "$cmd failed"
4918
4919     for j in $(seq 1 $NUMFILES); do
4920         check_stripe_count $TDIR/dir1/file$j $expected
4921     done
4922
4923     # lfs_migrate works with lfs find
4924     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4925          $LFS_MIGRATE -y -c $expected"
4926     echo "$cmd"
4927     eval $cmd || error "$cmd failed"
4928
4929     for i in $(seq 2 $NUMFILES); do
4930         check_stripe_count $TDIR/file$i $expected
4931     done
4932     for i in $(seq 2 $NUMDIRS); do
4933         for j in $(seq 1 $NUMFILES); do
4934             check_stripe_count $TDIR/dir$i/file$j $expected
4935         done
4936     done
4937 }
4938 run_test 56w "check lfs_migrate -c stripe_count works"
4939
4940 test_56x() {
4941         check_swap_layouts_support && return 0
4942         [[ $OSTCOUNT -lt 2 ]] &&
4943                 skip_env "need 2 OST, skipping test" && return
4944
4945         local dir0=$DIR/$tdir/$testnum
4946         test_mkdir -p $dir0 || error "creating dir $dir0"
4947
4948         local ref1=/etc/passwd
4949         local file1=$dir0/file1
4950
4951         $SETSTRIPE -c 2 $file1
4952         cp $ref1 $file1
4953         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4954         stripe=$($GETSTRIPE -c $file1)
4955         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4956         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4957
4958         # clean up
4959         rm -f $file1
4960 }
4961 run_test 56x "lfs migration support"
4962
4963 test_56y() {
4964         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4965                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
4966                 return
4967
4968         local res=""
4969         local dir0=$DIR/$tdir/$testnum
4970         test_mkdir -p $dir0 || error "creating dir $dir0"
4971         local f1=$dir0/file1
4972         local f2=$dir0/file2
4973
4974         touch $f1 || error "creating std file $f1"
4975         $MULTIOP $f2 H2c || error "creating released file $f2"
4976
4977         # a directory can be raid0, so ask only for files
4978         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4979         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4980
4981         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4982         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4983
4984         # only files can be released, so no need to force file search
4985         res=$($LFIND $dir0 -L released)
4986         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4987
4988         res=$($LFIND $dir0 \! -L released)
4989         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4990
4991 }
4992 run_test 56y "lfs find -L raid0|released"
4993
4994 test_56z() { # LU-4824
4995         # This checks to make sure 'lfs find' continues after errors
4996         # There are two classes of errors that should be caught:
4997         # - If multiple paths are provided, all should be searched even if one
4998         #   errors out
4999         # - If errors are encountered during the search, it should not terminate
5000         #   early
5001         local i
5002         test_mkdir $DIR/$tdir
5003         for i in d{0..9}; do
5004                 test_mkdir $DIR/$tdir/$i
5005         done
5006         touch $DIR/$tdir/d{0..9}/$tfile
5007         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
5008                 error "$LFS find did not return an error"
5009         # Make a directory unsearchable. This should NOT be the last entry in
5010         # directory order.  Arbitrarily pick the 6th entry
5011         chmod 700 $($LFS find $DIR/$tdir -type d | sed '6!d')
5012         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
5013         # The user should be able to see 10 directories and 9 files
5014         [ $count == 19 ] || error "$LFS find did not continue after error"
5015 }
5016 run_test 56z "lfs find should continue after an error"
5017
5018 test_56aa() { # LU-5937
5019         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5020
5021         mkdir $DIR/$tdir
5022         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
5023
5024         createmany -o $DIR/$tdir/striped_dir/${tfile}- 1024
5025         local dirs=$(lfs find --size +8k $DIR/$tdir/)
5026
5027         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5028 }
5029 run_test 56aa "lfs find --size under striped dir"
5030
5031 test_57a() {
5032         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5033         # note test will not do anything if MDS is not local
5034         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5035                 skip "Only applicable to ldiskfs-based MDTs"
5036                 return
5037         fi
5038
5039         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5040         local MNTDEV="osd*.*MDT*.mntdev"
5041         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
5042         [ -z "$DEV" ] && error "can't access $MNTDEV"
5043         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
5044                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
5045                         error "can't access $DEV"
5046                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
5047                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
5048                 rm $TMP/t57a.dump
5049         done
5050 }
5051 run_test 57a "verify MDS filesystem created with large inodes =="
5052
5053 test_57b() {
5054         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5055         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5056                 skip "Only applicable to ldiskfs-based MDTs"
5057                 return
5058         fi
5059
5060         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5061         local dir=$DIR/$tdir
5062
5063         local FILECOUNT=100
5064         local FILE1=$dir/f1
5065         local FILEN=$dir/f$FILECOUNT
5066
5067         rm -rf $dir || error "removing $dir"
5068         test_mkdir -p -c1 $dir || error "creating $dir"
5069         local mdtidx=$($LFS getstripe -M $dir)
5070         local mdtname=MDT$(printf %04x $mdtidx)
5071         local facet=mds$((mdtidx + 1))
5072
5073         echo "mcreating $FILECOUNT files"
5074         createmany -m $dir/f 1 $FILECOUNT || \
5075                 error "creating files in $dir"
5076
5077         # verify that files do not have EAs yet
5078         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5079         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5080
5081         sync
5082         sleep 1
5083         df $dir  #make sure we get new statfs data
5084         local MDSFREE=$(do_facet $facet \
5085                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5086         local MDCFREE=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5087         echo "opening files to create objects/EAs"
5088         local FILE
5089         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5090                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5091         done
5092
5093         # verify that files have EAs now
5094         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5095         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5096
5097         sleep 1  #make sure we get new statfs data
5098         df $dir
5099         local MDSFREE2=$(do_facet $facet \
5100                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5101         local MDCFREE2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5102         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5103                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5104                         error "MDC before $MDCFREE != after $MDCFREE2"
5105                 else
5106                         echo "MDC before $MDCFREE != after $MDCFREE2"
5107                         echo "unable to confirm if MDS has large inodes"
5108                 fi
5109         fi
5110         rm -rf $dir
5111 }
5112 run_test 57b "default LOV EAs are stored inside large inodes ==="
5113
5114 test_58() {
5115         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5116         [ -z "$(which wiretest 2>/dev/null)" ] &&
5117                         skip_env "could not find wiretest" && return
5118         wiretest
5119 }
5120 run_test 58 "verify cross-platform wire constants =============="
5121
5122 test_59() {
5123         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5124         echo "touch 130 files"
5125         createmany -o $DIR/f59- 130
5126         echo "rm 130 files"
5127         unlinkmany $DIR/f59- 130
5128         sync
5129         # wait for commitment of removal
5130         wait_delete_completed
5131 }
5132 run_test 59 "verify cancellation of llog records async ========="
5133
5134 TEST60_HEAD="test_60 run $RANDOM"
5135 test_60a() {
5136         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5137         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5138         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5139                 do_facet mgs "! ls run-llog.sh &> /dev/null" &&
5140                         skip_env "missing subtest run-llog.sh" && return
5141
5142         log "$TEST60_HEAD - from kernel mode"
5143         do_facet mgs "$LCTL set_param debug=warning; $LCTL dk > /dev/null"
5144         do_facet mgs sh run-llog.sh
5145         do_facet mgs $LCTL dk > $TMP/$tfile
5146
5147         # LU-6388: test llog_reader
5148         local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5149         llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5150         [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5151                         skip_env "missing llog_reader" && return
5152         local fstype=$(facet_fstype mgs)
5153         [ $fstype != ldiskfs -a $fstype != zfs ] &&
5154                 skip_env "Only for ldiskfs or zfs type mgs" && return
5155
5156         local mntpt=$(facet_mntpt mgs)
5157         local mgsdev=$(mgsdevname 1)
5158         local fid_list
5159         local fid
5160         local rec_list
5161         local rec
5162         local rec_type
5163         local obj_file
5164         local path
5165         local seq
5166         local oid
5167         local pass=true
5168
5169         #get fid and record list
5170         fid_list=($(awk '/9_sub.*record/ { print $NF }' /$TMP/$tfile |
5171                 tail -n 4))
5172         rec_list=($(awk '/9_sub.*record/ { print $((NF-3)) }' /$TMP/$tfile |
5173                 tail -n 4))
5174         #remount mgs as ldiskfs or zfs type
5175         stop mgs || error "stop mgs failed"
5176         mount_fstype mgs || error "remount mgs failed"
5177         for ((i = 0; i < ${#fid_list[@]}; i++)); do
5178                 fid=${fid_list[i]}
5179                 rec=${rec_list[i]}
5180                 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
5181                 oid=$(echo $fid | awk -F ':' '{ print $2 }' | sed -e "s/^0x//g")
5182                 oid=$((16#$oid))
5183
5184                 case $fstype in
5185                         ldiskfs )
5186                                 obj_file=$mntpt/O/$seq/d$((oid%32))/$oid ;;
5187                         zfs )
5188                                 obj_file=$mntpt/oi.$(($((16#$seq))&127))/$fid ;;
5189                 esac
5190                 echo "obj_file is $obj_file"
5191                 do_facet mgs $llog_reader $obj_file
5192
5193                 rec_type=$(do_facet mgs $llog_reader $obj_file | grep "type=" |
5194                         awk '{ print $3 }' | sed -e "s/^type=//g")
5195                 if [ $rec_type != $rec ]; then
5196                         echo "FAILED test_60a wrong record type $rec_type," \
5197                               "should be $rec"
5198                         pass=false
5199                         break
5200                 fi
5201
5202                 #check obj path if record type is LLOG_LOGID_MAGIC
5203                 if [ "$rec" == "1064553b" ]; then
5204                         path=$(do_facet mgs $llog_reader $obj_file |
5205                                 grep "path=" | awk '{ print $NF }' |
5206                                 sed -e "s/^path=//g")
5207                         if [ $obj_file != $mntpt/$path ]; then
5208                                 echo "FAILED test_60a wrong obj path" \
5209                                       "$montpt/$path, should be $obj_file"
5210                                 pass=false
5211                                 break
5212                         fi
5213                 fi
5214         done
5215         rm -f $TMP/$tfile
5216         #restart mgs before "error", otherwise it will block the next test
5217         stop mgs || error "stop mgs failed"
5218         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
5219         $pass || error "test failed, see FAILED test_60a messages for specifics"
5220 }
5221 run_test 60a "llog_test run from kernel module and test llog_reader =========="
5222
5223 test_60b() { # bug 6411
5224         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5225         dmesg > $DIR/$tfile
5226         LLOG_COUNT=$(dmesg | awk "/$TEST60_HEAD/ { marker = 1; from_marker = 0; }
5227                                 /llog.test/ {
5228                                         if (marker)
5229                                                 from_marker++
5230                                         from_begin++
5231                                 }
5232                                 END {
5233                                         if (marker)
5234                                                 print from_marker
5235                                         else
5236                                                 print from_begin
5237                                 }")
5238         [[ $LLOG_COUNT -gt 100 ]] &&
5239                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5240 }
5241 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5242
5243 test_60c() {
5244         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5245         echo "create 5000 files"
5246         createmany -o $DIR/f60c- 5000
5247 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5248         lctl set_param fail_loc=0x80000137
5249         unlinkmany $DIR/f60c- 5000
5250         lctl set_param fail_loc=0
5251 }
5252 run_test 60c "unlink file when mds full"
5253
5254 test_60d() {
5255         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5256         SAVEPRINTK=$(lctl get_param -n printk)
5257
5258         # verify "lctl mark" is even working"
5259         MESSAGE="test message ID $RANDOM $$"
5260         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5261         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5262
5263         lctl set_param printk=0 || error "set lnet.printk failed"
5264         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5265         MESSAGE="new test message ID $RANDOM $$"
5266         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5267         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5268         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5269
5270         lctl set_param -n printk="$SAVEPRINTK"
5271 }
5272 run_test 60d "test printk console message masking"
5273
5274 test_60e() {
5275         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5276         touch $DIR/$tfile
5277 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED2  0x15b
5278         do_facet mds1 lctl set_param fail_loc=0x15b
5279         rm $DIR/$tfile
5280 }
5281 run_test 60e "no space while new llog is being created"
5282
5283 test_61() {
5284         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5285         f="$DIR/f61"
5286         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5287         cancel_lru_locks osc
5288         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5289         sync
5290 }
5291 run_test 61 "mmap() writes don't make sync hang ================"
5292
5293 # bug 2330 - insufficient obd_match error checking causes LBUG
5294 test_62() {
5295         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5296         f="$DIR/f62"
5297         echo foo > $f
5298         cancel_lru_locks osc
5299         lctl set_param fail_loc=0x405
5300         cat $f && error "cat succeeded, expect -EIO"
5301         lctl set_param fail_loc=0
5302 }
5303 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5304 # match every page all of the time.
5305 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5306
5307 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5308 # Though this test is irrelevant anymore, it helped to reveal some
5309 # other grant bugs (LU-4482), let's keep it.
5310 test_63a() {   # was test_63
5311         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5312         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5313         for i in `seq 10` ; do
5314                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5315                 sleep 5
5316                 kill $!
5317                 sleep 1
5318         done
5319
5320         rm -f $DIR/f63 || true
5321 }
5322 run_test 63a "Verify oig_wait interruption does not crash ======="
5323
5324 # bug 2248 - async write errors didn't return to application on sync
5325 # bug 3677 - async write errors left page locked
5326 test_63b() {
5327         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5328         debugsave
5329         lctl set_param debug=-1
5330
5331         # ensure we have a grant to do async writes
5332         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5333         rm $DIR/$tfile
5334
5335         sync    # sync lest earlier test intercept the fail_loc
5336
5337         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5338         lctl set_param fail_loc=0x80000406
5339         $MULTIOP $DIR/$tfile Owy && \
5340                 error "sync didn't return ENOMEM"
5341         sync; sleep 2; sync     # do a real sync this time to flush page
5342         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5343                 error "locked page left in cache after async error" || true
5344         debugrestore
5345 }
5346 run_test 63b "async write errors should be returned to fsync ==="
5347
5348 test_64a () {
5349         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5350         df $DIR
5351         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5352 }
5353 run_test 64a "verify filter grant calculations (in kernel) ====="
5354
5355 test_64b () {
5356         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5357         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5358 }
5359 run_test 64b "check out-of-space detection on client ==========="
5360
5361 test_64c() {
5362         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5363 }
5364 run_test 64c "verify grant shrink ========================------"
5365
5366 # bug 1414 - set/get directories' stripe info
5367 test_65a() {
5368         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5369         test_mkdir -p $DIR/$tdir
5370         touch $DIR/$tdir/f1
5371         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5372 }
5373 run_test 65a "directory with no stripe info ===================="
5374
5375 test_65b() {
5376         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5377         test_mkdir -p $DIR/$tdir
5378         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5379
5380         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5381                                                 error "setstripe"
5382         touch $DIR/$tdir/f2
5383         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5384 }
5385 run_test 65b "directory setstripe -S stripe_size*2 -i 0 -c 1"
5386
5387 test_65c() {
5388         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5389         if [[ $OSTCOUNT -gt 1 ]]; then
5390                 test_mkdir -p $DIR/$tdir
5391                 local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5392
5393                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5394                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5395                 touch $DIR/$tdir/f3
5396                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5397         fi
5398 }
5399 run_test 65c "directory setstripe -S stripe_size*4 -i 1 -c $((OSTCOUNT-1))"
5400
5401 test_65d() {
5402         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5403         test_mkdir -p $DIR/$tdir
5404         local STRIPECOUNT=$($GETSTRIPE -c $DIR/$tdir)
5405         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5406
5407         if [[ $STRIPECOUNT -le 0 ]]; then
5408                 sc=1
5409         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5410 #LOV_MAX_STRIPE_COUNT is 2000
5411                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5412         else
5413                 sc=$(($STRIPECOUNT - 1))
5414         fi
5415         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5416         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5417         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5418                 error "lverify failed"
5419 }
5420 run_test 65d "directory setstripe -S stripe_size -c stripe_count"
5421
5422 test_65e() {
5423         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5424         test_mkdir -p $DIR/$tdir
5425
5426         $SETSTRIPE $DIR/$tdir || error "setstripe"
5427         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5428                                         error "no stripe info failed"
5429         touch $DIR/$tdir/f6
5430         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5431 }
5432 run_test 65e "directory setstripe defaults ======================="
5433
5434 test_65f() {
5435         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5436         test_mkdir -p $DIR/${tdir}f
5437         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5438 }
5439 run_test 65f "dir setstripe permission (should return error) ==="
5440
5441 test_65g() {
5442         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5443         test_mkdir -p $DIR/$tdir
5444         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5445
5446         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5447                                                         error "setstripe"
5448         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5449         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5450                 error "delete default stripe failed"
5451 }
5452 run_test 65g "directory setstripe -d ==========================="
5453
5454 test_65h() {
5455         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5456         test_mkdir -p $DIR/$tdir
5457         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5458
5459         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5460                                                         error "setstripe"
5461         test_mkdir -p $DIR/$tdir/dd1
5462         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5463                 error "stripe info inherit failed"
5464 }
5465 run_test 65h "directory stripe info inherit ===================="
5466
5467 test_65i() { # bug6367
5468         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5469         $SETSTRIPE -S 65536 -c -1 $MOUNT
5470 }
5471 run_test 65i "set non-default striping on root directory (bug 6367)="
5472
5473 test_65ia() { # bug12836
5474         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5475         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5476 }
5477 run_test 65ia "getstripe on -1 default directory striping"
5478
5479 test_65ib() { # bug12836
5480         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5481         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5482 }
5483 run_test 65ib "getstripe -v on -1 default directory striping"
5484
5485 test_65ic() { # bug12836
5486         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5487         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5488 }
5489 run_test 65ic "new find on -1 default directory striping"
5490
5491 test_65j() { # bug6367
5492         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5493         sync; sleep 1
5494         # if we aren't already remounting for each test, do so for this test
5495         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5496                 cleanup || error "failed to unmount"
5497                 setup
5498         fi
5499         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5500 }
5501 run_test 65j "set default striping on root directory (bug 6367)="
5502
5503 test_65k() { # bug11679
5504         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5505         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5506         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5507
5508     echo "Check OST status: "
5509     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5510               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5511
5512     for OSC in $MDS_OSCS; do
5513         echo $OSC "is activate"
5514         do_facet $SINGLEMDS lctl --device %$OSC activate
5515     done
5516
5517     mkdir -p $DIR/$tdir
5518     for INACTIVE_OSC in $MDS_OSCS; do
5519         echo "Deactivate: " $INACTIVE_OSC
5520         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5521         for STRIPE_OSC in $MDS_OSCS; do
5522             OST=`osc_to_ost $STRIPE_OSC`
5523             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5524                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5525
5526             [ -f $DIR/$tdir/$IDX ] && continue
5527             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5528             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5529             RC=$?
5530             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5531         done
5532         rm -f $DIR/$tdir/*
5533         echo $INACTIVE_OSC "is Activate."
5534         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5535     done
5536 }
5537 run_test 65k "validate manual striping works properly with deactivated OSCs"
5538
5539 test_65l() { # bug 12836
5540         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5541         test_mkdir -p $DIR/$tdir/test_dir
5542         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5543         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5544 }
5545 run_test 65l "lfs find on -1 stripe dir ========================"
5546
5547 # bug 2543 - update blocks count on client
5548 test_66() {
5549         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5550         COUNT=${COUNT:-8}
5551         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5552         sync; sync_all_data; sync; sync_all_data
5553         cancel_lru_locks osc
5554         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5555         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5556 }
5557 run_test 66 "update inode blocks count on client ==============="
5558
5559 LLOOP=
5560 LLITELOOPLOAD=
5561 cleanup_68() {
5562         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5563         trap 0
5564         if [ ! -z "$LLOOP" ]; then
5565                 if swapon -s | grep -q $LLOOP; then
5566                         swapoff $LLOOP || error "swapoff failed"
5567                 fi
5568
5569                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5570                 rm -f $LLOOP
5571                 unset LLOOP
5572         fi
5573         if [ ! -z "$LLITELOOPLOAD" ]; then
5574                 rmmod llite_lloop
5575                 unset LLITELOOPLOAD
5576         fi
5577         rm -f $DIR/f68*
5578 }
5579
5580 meminfo() {
5581         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5582 }
5583
5584 swap_used() {
5585         swapon -s | awk '($1 == "'$1'") { print $4 }'
5586 }
5587
5588 # test case for lloop driver, basic function
5589 test_68a() {
5590         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5591         [ "$UID" != 0 ] && skip_env "must run as root" && return
5592         llite_lloop_enabled || \
5593                 { skip_env "llite_lloop module disabled" && return; }
5594
5595         trap cleanup_68 EXIT
5596
5597         if ! module_loaded llite_lloop; then
5598                 if load_module llite/llite_lloop; then
5599                         LLITELOOPLOAD=yes
5600                 else
5601                         skip_env "can't find module llite_lloop"
5602                         return
5603                 fi
5604         fi
5605
5606         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5607         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5608         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5609
5610         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5611         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5612
5613         cleanup_68
5614 }
5615 run_test 68a "lloop driver - basic test ========================"
5616
5617 # excercise swapping to lustre by adding a high priority swapfile entry
5618 # and then consuming memory until it is used.
5619 test_68b() {  # was test_68
5620         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5621         [ "$UID" != 0 ] && skip_env "must run as root" && return
5622         lctl get_param -n devices | grep -q obdfilter && \
5623                 skip "local OST" && return
5624
5625         grep -q llite_lloop /proc/modules
5626         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5627
5628         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5629                 skip "can't reliably test swap with TCP" && return
5630
5631         MEMTOTAL=`meminfo MemTotal`
5632         NR_BLOCKS=$((MEMTOTAL>>8))
5633         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5634
5635         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5636         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5637         mkswap $DIR/f68b
5638
5639         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5640
5641         trap cleanup_68 EXIT
5642
5643         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5644
5645         echo "before: `swapon -s | grep $LLOOP`"
5646         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5647         echo "after: `swapon -s | grep $LLOOP`"
5648         SWAPUSED=`swap_used $LLOOP`
5649
5650         cleanup_68
5651
5652         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5653 }
5654 run_test 68b "support swapping to Lustre ========================"
5655
5656 # bug5265, obdfilter oa2dentry return -ENOENT
5657 # #define OBD_FAIL_SRV_ENOENT 0x217
5658 test_69() {
5659         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5660         remote_ost_nodsh && skip "remote OST with nodsh" && return
5661
5662         f="$DIR/$tfile"
5663         $SETSTRIPE -c 1 -i 0 $f
5664
5665         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5666
5667         do_facet ost1 lctl set_param fail_loc=0x217
5668         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5669         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5670
5671         do_facet ost1 lctl set_param fail_loc=0
5672         $DIRECTIO write $f 0 2 || error "write error"
5673
5674         cancel_lru_locks osc
5675         $DIRECTIO read $f 0 1 || error "read error"
5676
5677         do_facet ost1 lctl set_param fail_loc=0x217
5678         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5679
5680         do_facet ost1 lctl set_param fail_loc=0
5681         rm -f $f
5682 }
5683 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5684
5685 test_71() {
5686         test_mkdir -p $DIR/$tdir
5687         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
5688         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5689 }
5690 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5691
5692 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5693         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5694         [ "$RUNAS_ID" = "$UID" ] &&
5695                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5696
5697         # Check that testing environment is properly set up. Skip if not
5698         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5699                 skip_env "User $RUNAS_ID does not exist - skipping"
5700                 return 0
5701         }
5702         touch $DIR/$tfile
5703         chmod 777 $DIR/$tfile
5704         chmod ug+s $DIR/$tfile
5705         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5706                 error "$RUNAS dd $DIR/$tfile failed"
5707         # See if we are still setuid/sgid
5708         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5709                 error "S/gid is not dropped on write"
5710         # Now test that MDS is updated too
5711         cancel_lru_locks mdc
5712         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5713                 error "S/gid is not dropped on MDS"
5714         rm -f $DIR/$tfile
5715 }
5716 run_test 72a "Test that remove suid works properly (bug5695) ===="
5717
5718 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5719         local perm
5720
5721         [ "$RUNAS_ID" = "$UID" ] && \
5722                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5723         [ "$RUNAS_ID" -eq 0 ] && \
5724                 skip_env "RUNAS_ID = 0 -- skipping" && return
5725
5726         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5727         # Check that testing environment is properly set up. Skip if not
5728         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5729                 skip_env "User $RUNAS_ID does not exist - skipping"
5730                 return 0
5731         }
5732         touch $DIR/${tfile}-f{g,u}
5733         test_mkdir $DIR/${tfile}-dg
5734         test_mkdir $DIR/${tfile}-du
5735         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5736         chmod g+s $DIR/${tfile}-{f,d}g
5737         chmod u+s $DIR/${tfile}-{f,d}u
5738         for perm in 777 2777 4777; do
5739                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5740                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5741                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5742                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5743         done
5744         true
5745 }
5746 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5747
5748 # bug 3462 - multiple simultaneous MDC requests
5749 test_73() {
5750         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5751         test_mkdir $DIR/d73-1
5752         test_mkdir $DIR/d73-2
5753         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5754         pid1=$!
5755
5756         lctl set_param fail_loc=0x80000129
5757         $MULTIOP $DIR/d73-1/f73-2 Oc &
5758         sleep 1
5759         lctl set_param fail_loc=0
5760
5761         $MULTIOP $DIR/d73-2/f73-3 Oc &
5762         pid3=$!
5763
5764         kill -USR1 $pid1
5765         wait $pid1 || return 1
5766
5767         sleep 25
5768
5769         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5770         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5771         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5772
5773         rm -rf $DIR/d73-*
5774 }
5775 run_test 73 "multiple MDC requests (should not deadlock)"
5776
5777 test_74a() { # bug 6149, 6184
5778         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5779         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5780         #
5781         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5782         # will spin in a tight reconnection loop
5783         touch $DIR/f74a
5784         $LCTL set_param fail_loc=0x8000030e
5785         # get any lock that won't be difficult - lookup works.
5786         ls $DIR/f74a
5787         $LCTL set_param fail_loc=0
5788         rm -f $DIR/f74a
5789         true
5790 }
5791 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5792
5793 test_74b() { # bug 13310
5794         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5795         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5796         #
5797         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5798         # will spin in a tight reconnection loop
5799         $LCTL set_param fail_loc=0x8000030e
5800         # get a "difficult" lock
5801         touch $DIR/f74b
5802         $LCTL set_param fail_loc=0
5803         rm -f $DIR/f74b
5804         true
5805 }
5806 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5807
5808 test_74c() {
5809         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5810         #define OBD_FAIL_LDLM_NEW_LOCK
5811         $LCTL set_param fail_loc=0x319
5812         touch $DIR/$tfile && error "touch successful"
5813         $LCTL set_param fail_loc=0
5814         true
5815 }
5816 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5817
5818 num_inodes() {
5819         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5820 }
5821
5822 get_inode_slab_tunables() {
5823         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5824 }
5825
5826 set_inode_slab_tunables() {
5827         echo "lustre_inode_cache $1" > /proc/slabinfo
5828 }
5829
5830 test_76() { # Now for bug 20433, added originally in bug 1443
5831         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5832         local SLAB_SETTINGS=`get_inode_slab_tunables`
5833         local CPUS=`getconf _NPROCESSORS_ONLN`
5834         # we cannot set limit below 1 which means 1 inode in each
5835         # per-cpu cache is still allowed
5836         set_inode_slab_tunables "1 1 0"
5837         cancel_lru_locks osc
5838         BEFORE_INODES=$(num_inodes)
5839         echo "before inodes: $BEFORE_INODES"
5840         local COUNT=1000
5841         [ "$SLOW" = "no" ] && COUNT=100
5842         for i in $(seq $COUNT); do
5843                 touch $DIR/$tfile
5844                 rm -f $DIR/$tfile
5845         done
5846         cancel_lru_locks osc
5847         AFTER_INODES=$(num_inodes)
5848         echo "after inodes: $AFTER_INODES"
5849         local wait=0
5850         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5851                 sleep 2
5852                 AFTER_INODES=$(num_inodes)
5853                 wait=$((wait+2))
5854                 echo "wait $wait seconds inodes: $AFTER_INODES"
5855                 if [ $wait -gt 30 ]; then
5856                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5857                 fi
5858         done
5859         set_inode_slab_tunables "$SLAB_SETTINGS"
5860 }
5861 run_test 76 "confirm clients recycle inodes properly ===="
5862
5863
5864 export ORIG_CSUM=""
5865 set_checksums()
5866 {
5867         # Note: in sptlrpc modes which enable its own bulk checksum, the
5868         # original crc32_le bulk checksum will be automatically disabled,
5869         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5870         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5871         # In this case set_checksums() will not be no-op, because sptlrpc
5872         # bulk checksum will be enabled all through the test.
5873
5874         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5875         lctl set_param -n osc.*.checksums $1
5876         return 0
5877 }
5878
5879 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5880                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5881 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5882 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5883 set_checksum_type()
5884 {
5885         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5886         log "set checksum type to $1"
5887         return 0
5888 }
5889 F77_TMP=$TMP/f77-temp
5890 F77SZ=8
5891 setup_f77() {
5892         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5893                 error "error writing to $F77_TMP"
5894 }
5895
5896 test_77a() { # bug 10889
5897         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5898         $GSS && skip "could not run with gss" && return
5899         [ ! -f $F77_TMP ] && setup_f77
5900         set_checksums 1
5901         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5902         set_checksums 0
5903         rm -f $DIR/$tfile
5904 }
5905 run_test 77a "normal checksum read/write operation"
5906
5907 test_77b() { # bug 10889
5908         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5909         $GSS && skip "could not run with gss" && return
5910         [ ! -f $F77_TMP ] && setup_f77
5911         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5912         $LCTL set_param fail_loc=0x80000409
5913         set_checksums 1
5914
5915         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5916                 error "dd error: $?"
5917         $LCTL set_param fail_loc=0
5918
5919         for algo in $CKSUM_TYPES; do
5920                 cancel_lru_locks osc
5921                 set_checksum_type $algo
5922                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5923                 $LCTL set_param fail_loc=0x80000408
5924                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5925                 $LCTL set_param fail_loc=0
5926         done
5927         set_checksums 0
5928         set_checksum_type $ORIG_CSUM_TYPE
5929         rm -f $DIR/$tfile
5930 }
5931 run_test 77b "checksum error on client write, read"
5932
5933 test_77d() { # bug 10889
5934         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5935         $GSS && skip "could not run with gss" && return
5936         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5937         $LCTL set_param fail_loc=0x80000409
5938         set_checksums 1
5939         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5940                 error "direct write: rc=$?"
5941         $LCTL set_param fail_loc=0
5942         set_checksums 0
5943
5944         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5945         $LCTL set_param fail_loc=0x80000408
5946         set_checksums 1
5947         cancel_lru_locks osc
5948         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5949                 error "direct read: rc=$?"
5950         $LCTL set_param fail_loc=0
5951         set_checksums 0
5952 }
5953 run_test 77d "checksum error on OST direct write, read"
5954
5955 test_77f() { # bug 10889
5956         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5957         $GSS && skip "could not run with gss" && return
5958         set_checksums 1
5959         for algo in $CKSUM_TYPES; do
5960                 cancel_lru_locks osc
5961                 set_checksum_type $algo
5962                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5963                 $LCTL set_param fail_loc=0x409
5964                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5965                         error "direct write succeeded"
5966                 $LCTL set_param fail_loc=0
5967         done
5968         set_checksum_type $ORIG_CSUM_TYPE
5969         set_checksums 0
5970 }
5971 run_test 77f "repeat checksum error on write (expect error)"
5972
5973 test_77g() { # bug 10889
5974         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5975         $GSS && skip "could not run with gss" && return
5976         remote_ost_nodsh && skip "remote OST with nodsh" && return
5977
5978         [ ! -f $F77_TMP ] && setup_f77
5979
5980         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5981         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5982         do_facet ost1 lctl set_param fail_loc=0x8000021a
5983         set_checksums 1
5984         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5985                 error "write error: rc=$?"
5986         do_facet ost1 lctl set_param fail_loc=0
5987         set_checksums 0
5988
5989         cancel_lru_locks osc
5990         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5991         do_facet ost1 lctl set_param fail_loc=0x8000021b
5992         set_checksums 1
5993         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5994         do_facet ost1 lctl set_param fail_loc=0
5995         set_checksums 0
5996 }
5997 run_test 77g "checksum error on OST write, read"
5998
5999 test_77i() { # bug 13805
6000         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6001         $GSS && skip "could not run with gss" && return
6002         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
6003         lctl set_param fail_loc=0x40b
6004         remount_client $MOUNT
6005         lctl set_param fail_loc=0
6006         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
6007                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
6008                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
6009                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
6010         done
6011         remount_client $MOUNT
6012 }
6013 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
6014
6015 test_77j() { # bug 13805
6016         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6017         $GSS && skip "could not run with gss" && return
6018         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
6019         lctl set_param fail_loc=0x40c
6020         remount_client $MOUNT
6021         lctl set_param fail_loc=0
6022         sleep 2 # wait async osc connect to finish
6023         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
6024                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
6025                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
6026                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
6027         done
6028         remount_client $MOUNT
6029 }
6030 run_test 77j "client only supporting ADLER32"
6031
6032 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
6033 rm -f $F77_TMP
6034 unset F77_TMP
6035
6036 test_78() { # bug 10901
6037         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6038         remote_ost || { skip_env "local OST" && return; }
6039
6040         NSEQ=5
6041         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
6042         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
6043         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
6044         echo "MemTotal: $MEMTOTAL"
6045
6046         # reserve 256MB of memory for the kernel and other running processes,
6047         # and then take 1/2 of the remaining memory for the read/write buffers.
6048         if [ $MEMTOTAL -gt 512 ] ;then
6049                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
6050         else
6051                 # for those poor memory-starved high-end clusters...
6052                 MEMTOTAL=$((MEMTOTAL / 2))
6053         fi
6054         echo "Mem to use for directio: $MEMTOTAL"
6055
6056         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
6057         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
6058         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
6059         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
6060                 head -n1)
6061         echo "Smallest OST: $SMALLESTOST"
6062         [[ $SMALLESTOST -lt 10240 ]] &&
6063                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
6064
6065         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
6066                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
6067
6068         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
6069         echo "File size: $F78SIZE"
6070         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
6071         for i in $(seq 1 $NSEQ); do
6072                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
6073                 echo directIO rdwr round $i of $NSEQ
6074                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
6075         done
6076
6077         rm -f $DIR/$tfile
6078 }
6079 run_test 78 "handle large O_DIRECT writes correctly ============"
6080
6081 test_79() { # bug 12743
6082         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6083         wait_delete_completed
6084
6085         BKTOTAL=$(calc_osc_kbytes kbytestotal)
6086         BKFREE=$(calc_osc_kbytes kbytesfree)
6087         BKAVAIL=$(calc_osc_kbytes kbytesavail)
6088
6089         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
6090         DFTOTAL=`echo $STRING | cut -d, -f1`
6091         DFUSED=`echo $STRING  | cut -d, -f2`
6092         DFAVAIL=`echo $STRING | cut -d, -f3`
6093         DFFREE=$(($DFTOTAL - $DFUSED))
6094
6095         ALLOWANCE=$((64 * $OSTCOUNT))
6096
6097         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
6098            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
6099                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
6100         fi
6101         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
6102            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
6103                 error "df free($DFFREE) mismatch OST free($BKFREE)"
6104         fi
6105         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
6106            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
6107                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
6108         fi
6109 }
6110 run_test 79 "df report consistency check ======================="
6111
6112 test_80() { # bug 10718
6113         remote_ost_nodsh && skip "remote OST with nodsh" && return
6114         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6115         # relax strong synchronous semantics for slow backends like ZFS
6116         local soc="obdfilter.*.sync_on_lock_cancel"
6117         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
6118         local hosts=
6119         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
6120                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
6121                           facet_active_host $host; done | sort -u)
6122                 do_nodes $hosts lctl set_param $soc=never
6123         fi
6124
6125         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
6126         sync; sleep 1; sync
6127         local BEFORE=`date +%s`
6128         cancel_lru_locks osc
6129         local AFTER=`date +%s`
6130         local DIFF=$((AFTER-BEFORE))
6131         if [ $DIFF -gt 1 ] ; then
6132                 error "elapsed for 1M@1T = $DIFF"
6133         fi
6134
6135         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
6136
6137         rm -f $DIR/$tfile
6138 }
6139 run_test 80 "Page eviction is equally fast at high offsets too  ===="
6140
6141 test_81a() { # LU-456
6142         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6143         remote_ost_nodsh && skip "remote OST with nodsh" && return
6144         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6145         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
6146         do_facet ost1 lctl set_param fail_loc=0x80000228
6147
6148         # write should trigger a retry and success
6149         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6150         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6151         RC=$?
6152         if [ $RC -ne 0 ] ; then
6153                 error "write should success, but failed for $RC"
6154         fi
6155 }
6156 run_test 81a "OST should retry write when get -ENOSPC ==============="
6157
6158 test_81b() { # LU-456
6159         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6160         remote_ost_nodsh && skip "remote OST with nodsh" && return
6161         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6162         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
6163         do_facet ost1 lctl set_param fail_loc=0x228
6164
6165         # write should retry several times and return -ENOSPC finally
6166         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6167         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6168         RC=$?
6169         ENOSPC=28
6170         if [ $RC -ne $ENOSPC ] ; then
6171                 error "dd should fail for -ENOSPC, but succeed."
6172         fi
6173 }
6174 run_test 81b "OST should return -ENOSPC when retry still fails ======="
6175
6176 test_82() { # LU-1031
6177         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
6178         local gid1=14091995
6179         local gid2=16022000
6180
6181         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
6182         local MULTIPID1=$!
6183         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
6184         local MULTIPID2=$!
6185         kill -USR1 $MULTIPID2
6186         sleep 2
6187         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6188                 error "First grouplock does not block second one"
6189         else
6190                 echo "Second grouplock blocks first one"
6191         fi
6192         kill -USR1 $MULTIPID1
6193         wait $MULTIPID1
6194         wait $MULTIPID2
6195 }
6196 run_test 82 "Basic grouplock test ==============================="
6197
6198 test_99a() {
6199         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6200                 return
6201         test_mkdir -p $DIR/d99cvsroot
6202         chown $RUNAS_ID $DIR/d99cvsroot
6203         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6204         cd $TMP
6205
6206         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6207         cd $oldPWD
6208 }
6209 run_test 99a "cvs init ========================================="
6210
6211 test_99b() {
6212         [ -z "$(which cvs 2>/dev/null)" ] &&
6213                 skip_env "could not find cvs" && return
6214         [ ! -d $DIR/d99cvsroot ] && test_99a
6215         cd /etc/init.d
6216         # some versions of cvs import exit(1) when asked to import links or
6217         # files they can't read.  ignore those files.
6218         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6219                         ! -perm /4 -printf '-I %f\n')
6220         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6221                 d99reposname vtag rtag
6222 }
6223 run_test 99b "cvs import ======================================="
6224
6225 test_99c() {
6226         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6227         [ ! -d $DIR/d99cvsroot ] && test_99b
6228         cd $DIR
6229         test_mkdir -p $DIR/d99reposname
6230         chown $RUNAS_ID $DIR/d99reposname
6231         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6232 }
6233 run_test 99c "cvs checkout ====================================="
6234
6235 test_99d() {
6236         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6237         [ ! -d $DIR/d99cvsroot ] && test_99c
6238         cd $DIR/d99reposname
6239         $RUNAS touch foo99
6240         $RUNAS cvs add -m 'addmsg' foo99
6241 }
6242 run_test 99d "cvs add =========================================="
6243
6244 test_99e() {
6245         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6246         [ ! -d $DIR/d99cvsroot ] && test_99c
6247         cd $DIR/d99reposname
6248         $RUNAS cvs update
6249 }
6250 run_test 99e "cvs update ======================================="
6251
6252 test_99f() {
6253         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6254         [ ! -d $DIR/d99cvsroot ] && test_99d
6255         cd $DIR/d99reposname
6256         $RUNAS cvs commit -m 'nomsg' foo99
6257     rm -fr $DIR/d99cvsroot
6258 }
6259 run_test 99f "cvs commit ======================================="
6260
6261 test_100() {
6262         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6263         [ "$NETTYPE" = tcp ] || \
6264                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
6265                         return ; }
6266
6267         remote_ost_nodsh && skip "remote OST with nodsh" && return
6268         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6269         remote_servers || \
6270                 { skip "useless for local single node setup" && return; }
6271
6272         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6273                 [ "$PROT" != "tcp" ] && continue
6274                 RPORT=$(echo $REMOTE | cut -d: -f2)
6275                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6276
6277                 rc=0
6278                 LPORT=`echo $LOCAL | cut -d: -f2`
6279                 if [ $LPORT -ge 1024 ]; then
6280                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6281                         netstat -tna
6282                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6283                 fi
6284         done
6285         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6286 }
6287 run_test 100 "check local port using privileged port ==========="
6288
6289 function get_named_value()
6290 {
6291     local tag
6292
6293     tag=$1
6294     while read ;do
6295         line=$REPLY
6296         case $line in
6297         $tag*)
6298             echo $line | sed "s/^$tag[ ]*//"
6299             break
6300             ;;
6301         esac
6302     done
6303 }
6304
6305 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6306                    awk '/^max_cached_mb/ { print $2 }')
6307
6308 cleanup_101a() {
6309         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6310         trap 0
6311 }
6312
6313 test_101a() {
6314         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6315         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
6316         local s
6317         local discard
6318         local nreads=10000
6319         local cache_limit=32
6320
6321         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6322         trap cleanup_101a EXIT
6323         $LCTL set_param -n llite.*.read_ahead_stats 0
6324         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6325
6326         #
6327         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6328         #
6329         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6330         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6331
6332         discard=0
6333         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6334                 get_named_value 'read but discarded' | cut -d" " -f1); do
6335                         discard=$(($discard + $s))
6336         done
6337         cleanup_101a
6338
6339         if [[ $(($discard * 10)) -gt $nreads ]]; then
6340                 $LCTL get_param osc.*-osc*.rpc_stats
6341                 $LCTL get_param llite.*.read_ahead_stats
6342                 error "too many ($discard) discarded pages"
6343         fi
6344         rm -f $DIR/$tfile || true
6345 }
6346 run_test 101a "check read-ahead for random reads ================"
6347
6348 setup_test101bc() {
6349         test_mkdir -p $DIR/$tdir
6350         local STRIPE_SIZE=$1
6351         local FILE_LENGTH=$2
6352         STRIPE_OFFSET=0
6353
6354         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6355
6356         local list=$(comma_list $(osts_nodes))
6357         set_osd_param $list '' read_cache_enable 0
6358         set_osd_param $list '' writethrough_cache_enable 0
6359
6360         trap cleanup_test101bc EXIT
6361         # prepare the read-ahead file
6362         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6363
6364         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6365                                 count=$FILE_SIZE_MB 2> /dev/null
6366
6367 }
6368
6369 cleanup_test101bc() {
6370         trap 0
6371         rm -rf $DIR/$tdir
6372         rm -f $DIR/$tfile
6373
6374         local list=$(comma_list $(osts_nodes))
6375         set_osd_param $list '' read_cache_enable 1
6376         set_osd_param $list '' writethrough_cache_enable 1
6377 }
6378
6379 calc_total() {
6380         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6381 }
6382
6383 ra_check_101() {
6384         local READ_SIZE=$1
6385         local STRIPE_SIZE=$2
6386         local FILE_LENGTH=$3
6387         local RA_INC=1048576
6388         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6389         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6390                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6391         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6392                         get_named_value 'read but discarded' |
6393                         cut -d" " -f1 | calc_total)
6394         if [[ $DISCARD -gt $discard_limit ]]; then
6395                 $LCTL get_param llite.*.read_ahead_stats
6396                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6397         else
6398                 echo "Read-ahead success for size ${READ_SIZE}"
6399         fi
6400 }
6401
6402 test_101b() {
6403         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6404         [[ $OSTCOUNT -lt 2 ]] &&
6405                 skip_env "skipping stride IO stride-ahead test" && return
6406         local STRIPE_SIZE=1048576
6407         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6408         if [ $SLOW == "yes" ]; then
6409                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6410         else
6411                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6412         fi
6413
6414         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6415
6416         # prepare the read-ahead file
6417         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6418         cancel_lru_locks osc
6419         for BIDX in 2 4 8 16 32 64 128 256
6420         do
6421                 local BSIZE=$((BIDX*4096))
6422                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6423                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6424                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6425                 $LCTL set_param -n llite.*.read_ahead_stats 0
6426                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6427                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6428                 cancel_lru_locks osc
6429                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6430         done
6431         cleanup_test101bc
6432         true
6433 }
6434 run_test 101b "check stride-io mode read-ahead ================="
6435
6436 test_101c() {
6437         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6438         local STRIPE_SIZE=1048576
6439         local FILE_LENGTH=$((STRIPE_SIZE*100))
6440         local nreads=10000
6441         local osc_rpc_stats
6442
6443         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6444
6445         cancel_lru_locks osc
6446         $LCTL set_param osc.*.rpc_stats 0
6447         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6448         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6449                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6450                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6451                 local size
6452
6453                 if [ $lines -le 20 ]; then
6454                         continue
6455                 fi
6456                 for size in 1 2 4 8; do
6457                         local rpc=$(echo "$stats" |
6458                                     awk '($1 == "'$size':") {print $2; exit; }')
6459                         [ $rpc != 0 ] &&
6460                                 error "Small $((size*4))k read IO $rpc !"
6461                 done
6462                 echo "$osc_rpc_stats check passed!"
6463         done
6464         cleanup_test101bc
6465         true
6466 }
6467 run_test 101c "check stripe_size aligned read-ahead ================="
6468
6469 set_read_ahead() {
6470         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6471         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6472 }
6473
6474 test_101d() {
6475         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6476         local file=$DIR/$tfile
6477         local sz_MB=${FILESIZE_101d:-500}
6478         local ra_MB=${READAHEAD_MB:-40}
6479
6480         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6481         [ $free_MB -lt $sz_MB ] &&
6482                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6483
6484         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6485         $SETSTRIPE -c -1 $file || error "setstripe failed"
6486
6487         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6488         echo Cancel LRU locks on lustre client to flush the client cache
6489         cancel_lru_locks osc
6490
6491         echo Disable read-ahead
6492         local old_READAHEAD=$(set_read_ahead 0)
6493
6494         echo Reading the test file $file with read-ahead disabled
6495         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6496
6497         echo Cancel LRU locks on lustre client to flush the client cache
6498         cancel_lru_locks osc
6499         echo Enable read-ahead with ${ra_MB}MB
6500         set_read_ahead $ra_MB
6501
6502         echo Reading the test file $file with read-ahead enabled
6503         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6504
6505         echo "read-ahead disabled time read $raOFF"
6506         echo "read-ahead enabled  time read $raON"
6507
6508         set_read_ahead $old_READAHEAD
6509         rm -f $file
6510         wait_delete_completed
6511
6512         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6513                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6514 }
6515 run_test 101d "file read with and without read-ahead enabled"
6516
6517 test_101e() {
6518         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6519         local file=$DIR/$tfile
6520         local size_KB=500  #KB
6521         local count=100
6522         local bsize=1024
6523
6524         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6525         local need_KB=$((count * size_KB))
6526         [[ $free_KB -le $need_KB ]] &&
6527                 skip_env "Need free space $need_KB, have $free_KB" && return
6528
6529         echo "Creating $count ${size_KB}K test files"
6530         for ((i = 0; i < $count; i++)); do
6531                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6532         done
6533
6534         echo "Cancel LRU locks on lustre client to flush the client cache"
6535         cancel_lru_locks osc
6536
6537         echo "Reset readahead stats"
6538         $LCTL set_param -n llite.*.read_ahead_stats 0
6539
6540         for ((i = 0; i < $count; i++)); do
6541                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6542         done
6543
6544         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6545                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6546
6547         for ((i = 0; i < $count; i++)); do
6548                 rm -rf $file.$i 2>/dev/null
6549         done
6550
6551         #10000 means 20% reads are missing in readahead
6552         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6553 }
6554 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6555
6556 test_101f() {
6557         which iozone || { skip "no iozone installed" && return; }
6558
6559         # create a test file
6560         iozone -i 0 -+n -r 1m -s 128m -w -f $DIR/$tfile > /dev/null 2>&1
6561
6562         echo Cancel LRU locks on lustre client to flush the client cache
6563         cancel_lru_locks osc
6564
6565         echo Reset readahead stats
6566         $LCTL set_param -n llite.*.read_ahead_stats 0
6567
6568         echo mmap read the file with small block size
6569         iozone -i 1 -+n -r 32k -s 128m -B -f $DIR/$tfile > /dev/null 2>&1
6570
6571         echo checking missing pages
6572         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6573                         get_named_value 'misses' | cut -d" " -f1 | calc_total)
6574
6575         [ $miss -lt 3 ] || error "misses too much pages!"
6576         rm -f $DIR/$tfile
6577 }
6578 run_test 101f "check mmap read performance"
6579
6580 setup_test102() {
6581         test_mkdir -p $DIR/$tdir
6582         chown $RUNAS_ID $DIR/$tdir
6583         STRIPE_SIZE=65536
6584         STRIPE_OFFSET=1
6585         STRIPE_COUNT=$OSTCOUNT
6586         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6587
6588         trap cleanup_test102 EXIT
6589         cd $DIR
6590         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6591         cd $DIR/$tdir
6592         for num in 1 2 3 4; do
6593                 for count in $(seq 1 $STRIPE_COUNT); do
6594                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6595                                 local size=`expr $STRIPE_SIZE \* $num`
6596                                 local file=file"$num-$idx-$count"
6597                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6598                         done
6599                 done
6600         done
6601
6602         cd $DIR
6603         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6604 }
6605
6606 cleanup_test102() {
6607         trap 0
6608         rm -f $TMP/f102.tar
6609         rm -rf $DIR/d0.sanity/d102
6610 }
6611
6612 test_102a() {
6613         local testfile=$DIR/$tfile
6614
6615         touch $testfile
6616
6617         [ "$UID" != 0 ] && skip_env "must run as root" && return
6618         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6619                 skip_env "must have user_xattr" && return
6620
6621         [ -z "$(which setfattr 2>/dev/null)" ] &&
6622                 skip_env "could not find setfattr" && return
6623
6624         echo "set/get xattr..."
6625         setfattr -n trusted.name1 -v value1 $testfile ||
6626                 error "setfattr -n trusted.name1=value1 $testfile failed"
6627         getfattr -n trusted.name1 $testfile 2> /dev/null |
6628           grep "trusted.name1=.value1" ||
6629                 error "$testfile missing trusted.name1=value1"
6630
6631         setfattr -n user.author1 -v author1 $testfile ||
6632                 error "setfattr -n user.author1=author1 $testfile failed"
6633         getfattr -n user.author1 $testfile 2> /dev/null |
6634           grep "user.author1=.author1" ||
6635                 error "$testfile missing trusted.author1=author1"
6636
6637         echo "listxattr..."
6638         setfattr -n trusted.name2 -v value2 $testfile ||
6639                 error "$testfile unable to set trusted.name2"
6640         setfattr -n trusted.name3 -v value3 $testfile ||
6641                 error "$testfile unable to set trusted.name3"
6642         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6643             grep "trusted.name" | wc -l) -eq 3 ] ||
6644                 error "$testfile missing 3 trusted.name xattrs"
6645
6646         setfattr -n user.author2 -v author2 $testfile ||
6647                 error "$testfile unable to set user.author2"
6648         setfattr -n user.author3 -v author3 $testfile ||
6649                 error "$testfile unable to set user.author3"
6650         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6651             grep "user.author" | wc -l) -eq 3 ] ||
6652                 error "$testfile missing 3 user.author xattrs"
6653
6654         echo "remove xattr..."
6655         setfattr -x trusted.name1 $testfile ||
6656                 error "$testfile error deleting trusted.name1"
6657         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6658                 error "$testfile did not delete trusted.name1 xattr"
6659
6660         setfattr -x user.author1 $testfile ||
6661                 error "$testfile error deleting user.author1"
6662         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6663                 error "$testfile did not delete trusted.name1 xattr"
6664
6665         # b10667: setting lustre special xattr be silently discarded
6666         echo "set lustre special xattr ..."
6667         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6668                 error "$testfile allowed setting trusted.lov"
6669 }
6670 run_test 102a "user xattr test =================================="
6671
6672 test_102b() {
6673         [ -z "$(which setfattr 2>/dev/null)" ] &&
6674                 skip_env "could not find setfattr" && return
6675
6676         # b10930: get/set/list trusted.lov xattr
6677         echo "get/set/list trusted.lov xattr ..."
6678         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6679         local testfile=$DIR/$tfile
6680         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6681                 error "setstripe failed"
6682         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6683                 error "getstripe failed"
6684         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6685                 error "can't get trusted.lov from $testfile"
6686
6687         local testfile2=${testfile}2
6688         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6689                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6690
6691         $MCREATE $testfile2
6692         setfattr -n trusted.lov -v $value $testfile2
6693         local stripe_size=$($GETSTRIPE -S $testfile2)
6694         local stripe_count=$($GETSTRIPE -c $testfile2)
6695         [[ $stripe_size -eq 65536 ]] ||
6696                 error "stripe size $stripe_size != 65536"
6697         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6698                 error "stripe count $stripe_count != $STRIPECOUNT"
6699         rm -f $DIR/$tfile
6700 }
6701 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6702
6703 test_102c() {
6704         [ -z "$(which setfattr 2>/dev/null)" ] &&
6705                 skip_env "could not find setfattr" && return
6706
6707         # b10930: get/set/list lustre.lov xattr
6708         echo "get/set/list lustre.lov xattr ..."
6709         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6710         test_mkdir -p $DIR/$tdir
6711         chown $RUNAS_ID $DIR/$tdir
6712         local testfile=$DIR/$tdir/$tfile
6713         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6714                 error "setstripe failed"
6715         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6716                 error "getstripe failed"
6717         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6718         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6719
6720         local testfile2=${testfile}2
6721         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6722                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6723
6724         $RUNAS $MCREATE $testfile2
6725         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6726         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6727         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6728         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6729         [ $stripe_count -eq $STRIPECOUNT ] ||
6730                 error "stripe count $stripe_count != $STRIPECOUNT"
6731 }
6732 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6733
6734 compare_stripe_info1() {
6735         local stripe_index_all_zero=true
6736
6737         for num in 1 2 3 4; do
6738                 for count in $(seq 1 $STRIPE_COUNT); do
6739                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6740                                 local size=$((STRIPE_SIZE * num))
6741                                 local file=file"$num-$offset-$count"
6742                                 stripe_size=$($LFS getstripe -S $PWD/$file)
6743                                 [[ $stripe_size -ne $size ]] &&
6744                                     error "$file: size $stripe_size != $size"
6745                                 stripe_count=$($LFS getstripe -c $PWD/$file)
6746                                 # allow fewer stripes to be created, ORI-601
6747                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6748                                     error "$file: count $stripe_count != $count"
6749                                 stripe_index=$($LFS getstripe -i $PWD/$file)
6750                                 [[ $stripe_index -ne 0 ]] &&
6751                                         stripe_index_all_zero=false
6752                         done
6753                 done
6754         done
6755         $stripe_index_all_zero &&
6756                 error "all files are being extracted starting from OST index 0"
6757         return 0
6758 }
6759
6760 find_lustre_tar() {
6761         [ -n "$(which tar 2>/dev/null)" ] &&
6762                 strings $(which tar) | grep -q "lustre" && echo tar
6763 }
6764
6765 test_102d() {
6766         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6767         # b10930: tar test for trusted.lov xattr
6768         TAR=$(find_lustre_tar)
6769         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6770         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6771         setup_test102
6772         test_mkdir -p $DIR/d102d
6773         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6774         cd $DIR/d102d/$tdir
6775         compare_stripe_info1
6776 }
6777 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6778
6779 test_102f() {
6780         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6781         # b10930: tar test for trusted.lov xattr
6782         TAR=$(find_lustre_tar)
6783         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6784         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6785         setup_test102
6786         test_mkdir -p $DIR/d102f
6787         cd $DIR
6788         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6789         cd $DIR/d102f/$tdir
6790         compare_stripe_info1
6791 }
6792 run_test 102f "tar copy files, not keep osts ==========="
6793
6794 grow_xattr() {
6795         local xsize=${1:-1024}  # in bytes
6796         local file=$DIR/$tfile
6797
6798         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep xattr)" ] &&
6799                 skip "must have user_xattr" && return 0
6800         [ -z "$(which setfattr 2>/dev/null)" ] &&
6801                 skip_env "could not find setfattr" && return 0
6802         [ -z "$(which getfattr 2>/dev/null)" ] &&
6803                 skip_env "could not find getfattr" && return 0
6804
6805         touch $file
6806
6807         local value="$(generate_string $xsize)"
6808
6809         local xbig=trusted.big
6810         log "save $xbig on $file"
6811         setfattr -n $xbig -v $value $file ||
6812                 error "saving $xbig on $file failed"
6813
6814         local orig=$(get_xattr_value $xbig $file)
6815         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6816
6817         local xsml=trusted.sml
6818         log "save $xsml on $file"
6819         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6820
6821         local new=$(get_xattr_value $xbig $file)
6822         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6823
6824         log "grow $xsml on $file"
6825         setfattr -n $xsml -v "$value" $file ||
6826                 error "growing $xsml on $file failed"
6827
6828         new=$(get_xattr_value $xbig $file)
6829         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6830         log "$xbig still valid after growing $xsml"
6831
6832         rm -f $file
6833 }
6834
6835 test_102h() { # bug 15777
6836         grow_xattr 1024
6837 }
6838 run_test 102h "grow xattr from inside inode to external block"
6839
6840 test_102ha() {
6841         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6842         grow_xattr $(max_xattr_size)
6843 }
6844 run_test 102ha "grow xattr from inside inode to external inode"
6845
6846 test_102i() { # bug 17038
6847         [ -z "$(which getfattr 2>/dev/null)" ] &&
6848                 skip "could not find getfattr" && return
6849         touch $DIR/$tfile
6850         ln -s $DIR/$tfile $DIR/${tfile}link
6851         getfattr -n trusted.lov $DIR/$tfile ||
6852                 error "lgetxattr on $DIR/$tfile failed"
6853         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6854                 grep -i "no such attr" ||
6855                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6856         rm -f $DIR/$tfile $DIR/${tfile}link
6857 }
6858 run_test 102i "lgetxattr test on symbolic link ============"
6859
6860 test_102j() {
6861         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6862         TAR=$(find_lustre_tar)
6863         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6864         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6865         setup_test102 "$RUNAS"
6866         test_mkdir -p $DIR/d102j
6867         chown $RUNAS_ID $DIR/d102j
6868         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6869         cd $DIR/d102j/$tdir
6870         compare_stripe_info1 "$RUNAS"
6871 }
6872 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6873
6874 test_102k() {
6875         [ -z "$(which setfattr 2>/dev/null)" ] &&
6876                 skip "could not find setfattr" && return
6877         touch $DIR/$tfile
6878         # b22187 just check that does not crash for regular file.
6879         setfattr -n trusted.lov $DIR/$tfile
6880         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6881         local test_kdir=$DIR/d102k
6882         test_mkdir $test_kdir
6883         local default_size=`$GETSTRIPE -S $test_kdir`
6884         local default_count=`$GETSTRIPE -c $test_kdir`
6885         local default_offset=`$GETSTRIPE -i $test_kdir`
6886         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6887                 error 'dir setstripe failed'
6888         setfattr -n trusted.lov $test_kdir
6889         local stripe_size=`$GETSTRIPE -S $test_kdir`
6890         local stripe_count=`$GETSTRIPE -c $test_kdir`
6891         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6892         [ $stripe_size -eq $default_size ] ||
6893                 error "stripe size $stripe_size != $default_size"
6894         [ $stripe_count -eq $default_count ] ||
6895                 error "stripe count $stripe_count != $default_count"
6896         [ $stripe_offset -eq $default_offset ] ||
6897                 error "stripe offset $stripe_offset != $default_offset"
6898         rm -rf $DIR/$tfile $test_kdir
6899 }
6900 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6901
6902 test_102l() {
6903         [ -z "$(which getfattr 2>/dev/null)" ] &&
6904                 skip "could not find getfattr" && return
6905
6906         # LU-532 trusted. xattr is invisible to non-root
6907         local testfile=$DIR/$tfile
6908
6909         touch $testfile
6910
6911         echo "listxattr as user..."
6912         chown $RUNAS_ID $testfile
6913         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6914             grep -q "trusted" &&
6915                 error "$testfile trusted xattrs are user visible"
6916
6917         return 0;
6918 }
6919 run_test 102l "listxattr size test =================================="
6920
6921 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6922         local path=$DIR/$tfile
6923         touch $path
6924
6925         listxattr_size_check $path || error "listattr_size_check $path failed"
6926 }
6927 run_test 102m "Ensure listxattr fails on small bufffer ========"
6928
6929 cleanup_test102
6930
6931 getxattr() { # getxattr path name
6932         # Return the base64 encoding of the value of xattr name on path.
6933         local path=$1
6934         local name=$2
6935
6936         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6937         # file: $path
6938         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6939         #
6940         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6941
6942         getfattr --absolute-names --encoding=base64 --name=$name $path |
6943                 awk -F= -v name=$name '$1 == name {
6944                         print substr($0, index($0, "=") + 1);
6945         }'
6946 }
6947
6948 test_102n() { # LU-4101 mdt: protect internal xattrs
6949         local file0=$DIR/$tfile.0
6950         local file1=$DIR/$tfile.1
6951         local xattr0=$TMP/$tfile.0
6952         local xattr1=$TMP/$tfile.1
6953         local name
6954         local value
6955
6956         [ -z "$(which setfattr 2>/dev/null)" ] &&
6957                 skip "could not find setfattr" && return
6958
6959         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6960         then
6961                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6962                 return
6963         fi
6964
6965         rm -rf $file0 $file1 $xattr0 $xattr1
6966         touch $file0 $file1
6967
6968         # Get 'before' xattrs of $file1.
6969         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6970
6971         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6972                 # Try to copy xattr from $file0 to $file1.
6973                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6974
6975                 setfattr --name=trusted.$name --value="$value" $file1 ||
6976                         error "setxattr 'trusted.$name' failed"
6977
6978                 # Try to set a garbage xattr.
6979                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6980
6981                 setfattr --name=trusted.$name --value="$value" $file1 ||
6982                         error "setxattr 'trusted.$name' failed"
6983
6984                 # Try to remove the xattr from $file1. We don't care if this
6985                 # appears to succeed or fail, we just don't want there to be
6986                 # any changes or crashes.
6987                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6988         done
6989
6990         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
6991         then
6992                 name="lfsck_ns"
6993                 # Try to copy xattr from $file0 to $file1.
6994                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6995
6996                 setfattr --name=trusted.$name --value="$value" $file1 ||
6997                         error "setxattr 'trusted.$name' failed"
6998
6999                 # Try to set a garbage xattr.
7000                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7001
7002                 setfattr --name=trusted.$name --value="$value" $file1 ||
7003                         error "setxattr 'trusted.$name' failed"
7004
7005                 # Try to remove the xattr from $file1. We don't care if this
7006                 # appears to succeed or fail, we just don't want there to be
7007                 # any changes or crashes.
7008                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7009         fi
7010
7011         # Get 'after' xattrs of file1.
7012         getfattr --absolute-names --dump --match=- $file1 > $xattr1
7013
7014         if ! diff $xattr0 $xattr1; then
7015                 error "before and after xattrs of '$file1' differ"
7016         fi
7017
7018         rm -rf $file0 $file1 $xattr0 $xattr1
7019
7020         return 0
7021 }
7022 run_test 102n "silently ignore setxattr on internal trusted xattrs"
7023
7024 test_102p() { # LU-4703 setxattr did not check ownership
7025         local testfile=$DIR/$tfile
7026
7027         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
7028                 skip "MDS needs to be at least 2.5.56" && return
7029
7030         touch $testfile
7031
7032         echo "setfacl as user..."
7033         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
7034         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
7035
7036         echo "setfattr as user..."
7037         setfacl -m "u:$RUNAS_ID:---" $testfile
7038         $RUNAS setfattr -x system.posix_acl_access $testfile
7039         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
7040 }
7041 run_test 102p "check setxattr(2) correctly fails without permission"
7042
7043 test_102q() {
7044         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
7045                 skip "MDS needs to be at least 2.6.92" && return
7046         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
7047 }
7048 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
7049
7050 test_102r() {
7051         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
7052                 skip "MDS needs to be at least 2.6.93" && return
7053         touch $DIR/$tfile || error "touch"
7054         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
7055         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
7056         rm $DIR/$tfile || error "rm"
7057
7058         #normal directory
7059         mkdir -p $DIR/$tdir || error "mkdir"
7060         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7061         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7062         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7063                 error "$testfile error deleting user.author1"
7064         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7065                 grep "user.$(basename $tdir)" &&
7066                 error "$tdir did not delete user.$(basename $tdir)"
7067         rmdir $DIR/$tdir || error "rmdir"
7068
7069         #striped directory
7070         test_mkdir -p $DIR/$tdir || error "make striped dir"
7071         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7072         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7073         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7074                 error "$testfile error deleting user.author1"
7075         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7076                 grep "user.$(basename $tdir)" &&
7077                 error "$tdir did not delete user.$(basename $tdir)"
7078         rmdir $DIR/$tdir || error "rm striped dir"
7079 }
7080 run_test 102r "set EAs with empty values"
7081
7082 run_acl_subtest()
7083 {
7084     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
7085     return $?
7086 }
7087
7088 test_103a() {
7089         [ "$UID" != 0 ] && skip_env "must run as root" && return
7090         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
7091                 skip "must have acl enabled" && return
7092         [ -z "$(which setfacl 2>/dev/null)" ] &&
7093                 skip_env "could not find setfacl" && return
7094         $GSS && skip "could not run under gss" && return
7095
7096         gpasswd -a daemon bin                           # LU-5641
7097         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
7098
7099         declare -a identity_old
7100
7101         for num in $(seq $MDSCOUNT); do
7102                 switch_identity $num true || identity_old[$num]=$?
7103         done
7104
7105         SAVE_UMASK=$(umask)
7106         umask 0022
7107         cd $DIR
7108
7109         echo "performing cp ..."
7110         run_acl_subtest cp || error "run_acl_subtest cp failed"
7111         echo "performing getfacl-noacl..."
7112         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
7113         echo "performing misc..."
7114         run_acl_subtest misc || error  "misc test failed"
7115         echo "performing permissions..."
7116         run_acl_subtest permissions || error "permissions failed"
7117         echo "performing setfacl..."
7118         run_acl_subtest setfacl || error  "setfacl test failed"
7119
7120         # inheritance test got from HP
7121         echo "performing inheritance..."
7122         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
7123         chmod +x make-tree || error "chmod +x failed"
7124         run_acl_subtest inheritance || error "inheritance test failed"
7125         rm -f make-tree
7126
7127         echo "LU-974 ignore umask when acl is enabled..."
7128         run_acl_subtest 974 || error "LU-974 umask test failed"
7129         if [ $MDSCOUNT -ge 2 ]; then
7130                 run_acl_subtest 974_remote ||
7131                         error "LU-974 umask test failed under remote dir"
7132         fi
7133
7134         echo "LU-2561 newly created file is same size as directory..."
7135         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
7136                 run_acl_subtest 2561 || error "LU-2561 test failed"
7137         else
7138                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
7139         fi
7140
7141         run_acl_subtest 4924 || error "LU-4924 test failed"
7142
7143         cd $SAVE_PWD
7144         umask $SAVE_UMASK
7145
7146         for num in $(seq $MDSCOUNT); do
7147                 if [ "${identity_old[$num]}" = 1 ]; then
7148                         switch_identity $num false || identity_old[$num]=$?
7149                 fi
7150         done
7151 }
7152 run_test 103a "acl test ========================================="
7153
7154 test_103b() {
7155         local noacl=false
7156         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
7157         local mountopts=$MDS_MOUNT_OPTS
7158
7159         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
7160                 noacl=true
7161         else
7162                 # stop the MDT
7163                 stop $SINGLEMDS || error "failed to stop MDT."
7164                 # remount the MDT
7165                 if [ -z "$MDS_MOUNT_OPTS" ]; then
7166                         MDS_MOUNT_OPTS="-o noacl"
7167                 else
7168                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
7169                 fi
7170                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7171                         error "failed to start MDT."
7172                 MDS_MOUNT_OPTS=$mountopts
7173         fi
7174
7175         touch $DIR/$tfile
7176         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
7177
7178         if ! $noacl; then
7179                 # stop the MDT
7180                 stop $SINGLEMDS || error "failed to stop MDT."
7181                 # remount the MDT
7182                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7183                         error "failed to start MDT."
7184         fi
7185
7186         true
7187 }
7188 run_test 103b "MDS mount option 'noacl'"
7189
7190 test_103c() {
7191         mkdir -p $DIR/$tdir
7192         cp -rp $DIR/$tdir $DIR/$tdir.bak
7193
7194         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
7195                 error "$DIR/$tdir shouldn't contain default ACL"
7196         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
7197                 error "$DIR/$tdir.bak shouldn't contain default ACL"
7198         true
7199 }
7200 run_test 103c "'cp -rp' won't set empty acl"
7201
7202 test_104a() {
7203         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7204         touch $DIR/$tfile
7205         lfs df || error "lfs df failed"
7206         lfs df -ih || error "lfs df -ih failed"
7207         lfs df -h $DIR || error "lfs df -h $DIR failed"
7208         lfs df -i $DIR || error "lfs df -i $DIR failed"
7209         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
7210         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
7211
7212         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
7213         lctl --device %$OSC deactivate
7214         lfs df || error "lfs df with deactivated OSC failed"
7215         lctl --device %$OSC activate
7216         # wait the osc back to normal
7217         wait_osc_import_state client ost FULL
7218
7219         lfs df || error "lfs df with reactivated OSC failed"
7220         rm -f $DIR/$tfile
7221 }
7222 run_test 104a "lfs df [-ih] [path] test ========================="
7223
7224 test_104b() {
7225         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7226         [ $RUNAS_ID -eq $UID ] &&
7227                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
7228         chmod 666 /dev/obd
7229         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
7230                         grep "Permission denied" | wc -l)))
7231         if [ $denied_cnt -ne 0 ]; then
7232                 error "lfs check servers test failed"
7233         fi
7234 }
7235 run_test 104b "$RUNAS lfs check servers test ===================="
7236
7237 test_105a() {
7238         # doesn't work on 2.4 kernels
7239         touch $DIR/$tfile
7240         if $(flock_is_enabled); then
7241                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7242         else
7243                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7244         fi
7245         rm -f $DIR/$tfile
7246 }
7247 run_test 105a "flock when mounted without -o flock test ========"
7248
7249 test_105b() {
7250         touch $DIR/$tfile
7251         if $(flock_is_enabled); then
7252                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7253         else
7254                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7255         fi
7256         rm -f $DIR/$tfile
7257 }
7258 run_test 105b "fcntl when mounted without -o flock test ========"
7259
7260 test_105c() {
7261         touch $DIR/$tfile
7262         if $(flock_is_enabled); then
7263                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7264         else
7265                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7266         fi
7267         rm -f $DIR/$tfile
7268 }
7269 run_test 105c "lockf when mounted without -o flock test ========"
7270
7271 test_105d() { # bug 15924
7272         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7273         test_mkdir -p $DIR/$tdir
7274         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7275         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7276         $LCTL set_param fail_loc=0x80000315
7277         flocks_test 2 $DIR/$tdir
7278 }
7279 run_test 105d "flock race (should not freeze) ========"
7280
7281 test_105e() { # bug 22660 && 22040
7282         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7283         touch $DIR/$tfile
7284         flocks_test 3 $DIR/$tfile
7285 }
7286 run_test 105e "Two conflicting flocks from same process ======="
7287
7288 test_106() { #bug 10921
7289         test_mkdir -p $DIR/$tdir
7290         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7291         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7292 }
7293 run_test 106 "attempt exec of dir followed by chown of that dir"
7294
7295 test_107() {
7296         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7297         CDIR=`pwd`
7298         cd $DIR
7299
7300         local file=core
7301         rm -f $file
7302
7303         local save_pattern=$(sysctl -n kernel.core_pattern)
7304         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7305         sysctl -w kernel.core_pattern=$file
7306         sysctl -w kernel.core_uses_pid=0
7307
7308         ulimit -c unlimited
7309         sleep 60 &
7310         SLEEPPID=$!
7311
7312         sleep 1
7313
7314         kill -s 11 $SLEEPPID
7315         wait $SLEEPPID
7316         if [ -e $file ]; then
7317                 size=`stat -c%s $file`
7318                 [ $size -eq 0 ] && error "Fail to create core file $file"
7319         else
7320                 error "Fail to create core file $file"
7321         fi
7322         rm -f $file
7323         sysctl -w kernel.core_pattern=$save_pattern
7324         sysctl -w kernel.core_uses_pid=$save_uses_pid
7325         cd $CDIR
7326 }
7327 run_test 107 "Coredump on SIG"
7328
7329 test_110() {
7330         test_mkdir -p $DIR/$tdir
7331         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7332                 error "mkdir with 255 char failed"
7333         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7334                 error "mkdir with 256 char should fail, but did not"
7335         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7336                 error "create with 255 char failed"
7337         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7338                 error "create with 256 char should fail, but did not"
7339
7340         ls -l $DIR/$tdir
7341         rm -rf $DIR/$tdir
7342 }
7343 run_test 110 "filename length checking"
7344
7345 test_115() {
7346         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7347         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
7348                 tail -1 | cut -c11-20)
7349         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
7350         echo "Starting with $OSTIO_pre threads"
7351
7352         NUMTEST=20000
7353         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7354         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
7355         echo "$NUMTEST creates/unlinks"
7356         test_mkdir -p $DIR/$tdir
7357         createmany -o $DIR/$tdir/$tfile $NUMTEST
7358         unlinkmany $DIR/$tdir/$tfile $NUMTEST
7359
7360         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
7361                 tail -1 | cut -c11-20)
7362
7363         # don't return an error
7364         [ $OSTIO_post == $OSTIO_pre ] && echo \
7365             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
7366             echo "This may be fine, depending on what ran before this test" &&
7367             echo "and how fast this system is." && return
7368
7369         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
7370 }
7371 run_test 115 "verify dynamic thread creation===================="
7372
7373 free_min_max () {
7374         wait_delete_completed
7375         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7376         echo OST kbytes available: ${AVAIL[@]}
7377         MAXI=0; MAXV=${AVAIL[0]}
7378         MINI=0; MINV=${AVAIL[0]}
7379         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7380                 #echo OST $i: ${AVAIL[i]}kb
7381                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7382                         MAXV=${AVAIL[i]}; MAXI=$i
7383                 fi
7384                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7385                         MINV=${AVAIL[i]}; MINI=$i
7386                 fi
7387         done
7388         echo Min free space: OST $MINI: $MINV
7389         echo Max free space: OST $MAXI: $MAXV
7390 }
7391
7392 test_116a() { # was previously test_116()
7393         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7394         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7395
7396         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
7397
7398         echo -n "Free space priority "
7399         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7400                 head -n1
7401         declare -a AVAIL
7402         free_min_max
7403
7404         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7405         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7406                 && return
7407         trap simple_cleanup_common EXIT
7408
7409
7410         # Check if we need to generate uneven OSTs
7411         test_mkdir -p $DIR/$tdir/OST${MINI}
7412         local FILL=$(($MINV / 4))
7413         local DIFF=$(($MAXV - $MINV))
7414         local DIFF2=$(($DIFF * 100 / $MINV))
7415
7416         local threshold=$(do_facet $SINGLEMDS \
7417                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7418         threshold=${threshold%%%}
7419         echo -n "Check for uneven OSTs: "
7420         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7421
7422         if [[ $DIFF2 -gt $threshold ]]; then
7423                 echo "ok"
7424                 echo "Don't need to fill OST$MINI"
7425         else
7426                 # generate uneven OSTs. Write 2% over the QOS threshold value
7427                 echo "no"
7428                 DIFF=$(($threshold - $DIFF2 + 2))
7429                 DIFF2=$(( ($MINV * $DIFF)/100 ))
7430                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
7431                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7432                         error "setstripe failed"
7433                 DIFF=$(($DIFF2 / 2048))
7434                 i=0
7435                 while [ $i -lt $DIFF ]; do
7436                         i=$(($i + 1))
7437                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7438                                 bs=2M count=1 2>/dev/null
7439                         echo -n .
7440                 done
7441                 echo .
7442                 sync
7443                 sleep_maxage
7444                 free_min_max
7445         fi
7446
7447         DIFF=$(($MAXV - $MINV))
7448         DIFF2=$(($DIFF * 100 / $MINV))
7449         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
7450         if [[ $DIFF2 -gt $threshold ]]; then
7451                 echo "ok"
7452         else
7453                 echo "failed - QOS mode won't be used"
7454                 skip "QOS imbalance criteria not met"
7455                 simple_cleanup_common
7456                 return
7457         fi
7458
7459         MINI1=$MINI; MINV1=$MINV
7460         MAXI1=$MAXI; MAXV1=$MAXV
7461
7462         # now fill using QOS
7463         $SETSTRIPE -c 1 $DIR/$tdir
7464         FILL=$(($FILL / 200))
7465         if [ $FILL -gt 600 ]; then
7466                 FILL=600
7467         fi
7468         echo "writing $FILL files to QOS-assigned OSTs"
7469         i=0
7470         while [ $i -lt $FILL ]; do
7471                 i=$((i + 1))
7472                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7473                         count=1 2>/dev/null
7474                 echo -n .
7475         done
7476         echo "wrote $i 200k files"
7477         sync
7478         sleep_maxage
7479
7480         echo "Note: free space may not be updated, so measurements might be off"
7481         free_min_max
7482         DIFF2=$(($MAXV - $MINV))
7483         echo "free space delta: orig $DIFF final $DIFF2"
7484         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7485         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
7486         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7487         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
7488         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7489         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7490         [ $DIFF -gt 0 ] &&
7491                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7492
7493         # Figure out which files were written where
7494         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7495                   awk '/'$MINI1': / {print $2; exit}')
7496         echo $UUID
7497         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7498         echo "$MINC files created on smaller OST $MINI1"
7499         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7500                   awk '/'$MAXI1': / {print $2; exit}')
7501         echo $UUID
7502         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7503         echo "$MAXC files created on larger OST $MAXI1"
7504         FILL=$(($MAXC * 100 / $MINC - 100))
7505         [[ $MINC -gt 0 ]] &&
7506                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7507         [[ $MAXC -gt $MINC ]] ||
7508                 error_ignore LU-9 "stripe QOS didn't balance free space"
7509         simple_cleanup_common
7510 }
7511 run_test 116a "stripe QOS: free space balance ==================="
7512
7513 test_116b() { # LU-2093
7514         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7515         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7516
7517 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7518         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7519                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7520         [ -z "$old_rr" ] && skip "no QOS" && return 0
7521         do_facet $SINGLEMDS lctl set_param \
7522                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7523         mkdir -p $DIR/$tdir
7524         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7525         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7526         do_facet $SINGLEMDS lctl set_param fail_loc=0
7527         rm -rf $DIR/$tdir
7528         do_facet $SINGLEMDS lctl set_param \
7529                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7530 }
7531 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7532
7533 test_117() # bug 10891
7534 {
7535         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7536         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7537         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7538         lctl set_param fail_loc=0x21e
7539         > $DIR/$tfile || error "truncate failed"
7540         lctl set_param fail_loc=0
7541         echo "Truncate succeeded."
7542         rm -f $DIR/$tfile
7543 }
7544 run_test 117 "verify osd extend =========="
7545
7546 NO_SLOW_RESENDCOUNT=4
7547 export OLD_RESENDCOUNT=""
7548 set_resend_count () {
7549         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7550         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7551         lctl set_param -n $PROC_RESENDCOUNT $1
7552         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7553 }
7554
7555 # for reduce test_118* time (b=14842)
7556 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7557
7558 # Reset async IO behavior after error case
7559 reset_async() {
7560         FILE=$DIR/reset_async
7561
7562         # Ensure all OSCs are cleared
7563         $SETSTRIPE -c -1 $FILE
7564         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7565         sync
7566         rm $FILE
7567 }
7568
7569 test_118a() #bug 11710
7570 {
7571         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7572         reset_async
7573
7574         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7575         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7576         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7577
7578         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7579                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7580                 return 1;
7581         fi
7582         rm -f $DIR/$tfile
7583 }
7584 run_test 118a "verify O_SYNC works =========="
7585
7586 test_118b()
7587 {
7588         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7589         remote_ost_nodsh && skip "remote OST with nodsh" && return
7590
7591         reset_async
7592
7593         #define OBD_FAIL_SRV_ENOENT 0x217
7594         set_nodes_failloc "$(osts_nodes)" 0x217
7595         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7596         RC=$?
7597         set_nodes_failloc "$(osts_nodes)" 0
7598         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7599         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7600                     grep -c writeback)
7601
7602         if [[ $RC -eq 0 ]]; then
7603                 error "Must return error due to dropped pages, rc=$RC"
7604                 return 1;
7605         fi
7606
7607         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7608                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7609                 return 1;
7610         fi
7611
7612         echo "Dirty pages not leaked on ENOENT"
7613
7614         # Due to the above error the OSC will issue all RPCs syncronously
7615         # until a subsequent RPC completes successfully without error.
7616         $MULTIOP $DIR/$tfile Ow4096yc
7617         rm -f $DIR/$tfile
7618
7619         return 0
7620 }
7621 run_test 118b "Reclaim dirty pages on fatal error =========="
7622
7623 test_118c()
7624 {
7625         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7626
7627         # for 118c, restore the original resend count, LU-1940
7628         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7629                                 set_resend_count $OLD_RESENDCOUNT
7630         remote_ost_nodsh && skip "remote OST with nodsh" && return
7631
7632         reset_async
7633
7634         #define OBD_FAIL_OST_EROFS               0x216
7635         set_nodes_failloc "$(osts_nodes)" 0x216
7636
7637         # multiop should block due to fsync until pages are written
7638         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7639         MULTIPID=$!
7640         sleep 1
7641
7642         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7643                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7644         fi
7645
7646         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7647                     grep -c writeback)
7648         if [[ $WRITEBACK -eq 0 ]]; then
7649                 error "No page in writeback, writeback=$WRITEBACK"
7650         fi
7651
7652         set_nodes_failloc "$(osts_nodes)" 0
7653         wait $MULTIPID
7654         RC=$?
7655         if [[ $RC -ne 0 ]]; then
7656                 error "Multiop fsync failed, rc=$RC"
7657         fi
7658
7659         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7660         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7661                     grep -c writeback)
7662         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7663                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7664         fi
7665
7666         rm -f $DIR/$tfile
7667         echo "Dirty pages flushed via fsync on EROFS"
7668         return 0
7669 }
7670 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7671
7672 # continue to use small resend count to reduce test_118* time (b=14842)
7673 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7674
7675 test_118d()
7676 {
7677         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7678         remote_ost_nodsh && skip "remote OST with nodsh" && return
7679
7680         reset_async
7681
7682         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7683         set_nodes_failloc "$(osts_nodes)" 0x214
7684         # multiop should block due to fsync until pages are written
7685         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7686         MULTIPID=$!
7687         sleep 1
7688
7689         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7690                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7691         fi
7692
7693         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7694                     grep -c writeback)
7695         if [[ $WRITEBACK -eq 0 ]]; then
7696                 error "No page in writeback, writeback=$WRITEBACK"
7697         fi
7698
7699         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7700         set_nodes_failloc "$(osts_nodes)" 0
7701
7702         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7703         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7704                     grep -c writeback)
7705         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7706                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7707         fi
7708
7709         rm -f $DIR/$tfile
7710         echo "Dirty pages gaurenteed flushed via fsync"
7711         return 0
7712 }
7713 run_test 118d "Fsync validation inject a delay of the bulk =========="
7714
7715 test_118f() {
7716         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7717         reset_async
7718
7719         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7720         lctl set_param fail_loc=0x8000040a
7721
7722         # Should simulate EINVAL error which is fatal
7723         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7724         RC=$?
7725         if [[ $RC -eq 0 ]]; then
7726                 error "Must return error due to dropped pages, rc=$RC"
7727         fi
7728
7729         lctl set_param fail_loc=0x0
7730
7731         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7732         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7733         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7734                     grep -c writeback)
7735         if [[ $LOCKED -ne 0 ]]; then
7736                 error "Locked pages remain in cache, locked=$LOCKED"
7737         fi
7738
7739         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7740                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7741         fi
7742
7743         rm -f $DIR/$tfile
7744         echo "No pages locked after fsync"
7745
7746         reset_async
7747         return 0
7748 }
7749 run_test 118f "Simulate unrecoverable OSC side error =========="
7750
7751 test_118g() {
7752         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7753         reset_async
7754
7755         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7756         lctl set_param fail_loc=0x406
7757
7758         # simulate local -ENOMEM
7759         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7760         RC=$?
7761
7762         lctl set_param fail_loc=0
7763         if [[ $RC -eq 0 ]]; then
7764                 error "Must return error due to dropped pages, rc=$RC"
7765         fi
7766
7767         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7768         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7769         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7770                         grep -c writeback)
7771         if [[ $LOCKED -ne 0 ]]; then
7772                 error "Locked pages remain in cache, locked=$LOCKED"
7773         fi
7774
7775         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7776                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7777         fi
7778
7779         rm -f $DIR/$tfile
7780         echo "No pages locked after fsync"
7781
7782         reset_async
7783         return 0
7784 }
7785 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7786
7787 test_118h() {
7788         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7789         remote_ost_nodsh && skip "remote OST with nodsh" && return
7790
7791         reset_async
7792
7793         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7794         set_nodes_failloc "$(osts_nodes)" 0x20e
7795         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7796         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7797         RC=$?
7798
7799         set_nodes_failloc "$(osts_nodes)" 0
7800         if [[ $RC -eq 0 ]]; then
7801                 error "Must return error due to dropped pages, rc=$RC"
7802         fi
7803
7804         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7805         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7806         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7807                     grep -c writeback)
7808         if [[ $LOCKED -ne 0 ]]; then
7809                 error "Locked pages remain in cache, locked=$LOCKED"
7810         fi
7811
7812         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7813                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7814         fi
7815
7816         rm -f $DIR/$tfile
7817         echo "No pages locked after fsync"
7818
7819         return 0
7820 }
7821 run_test 118h "Verify timeout in handling recoverables errors  =========="
7822
7823 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7824
7825 test_118i() {
7826         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7827         remote_ost_nodsh && skip "remote OST with nodsh" && return
7828
7829         reset_async
7830
7831         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7832         set_nodes_failloc "$(osts_nodes)" 0x20e
7833
7834         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7835         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7836         PID=$!
7837         sleep 5
7838         set_nodes_failloc "$(osts_nodes)" 0
7839
7840         wait $PID
7841         RC=$?
7842         if [[ $RC -ne 0 ]]; then
7843                 error "got error, but should be not, rc=$RC"
7844         fi
7845
7846         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7847         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7848         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7849         if [[ $LOCKED -ne 0 ]]; then
7850                 error "Locked pages remain in cache, locked=$LOCKED"
7851         fi
7852
7853         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7854                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7855         fi
7856
7857         rm -f $DIR/$tfile
7858         echo "No pages locked after fsync"
7859
7860         return 0
7861 }
7862 run_test 118i "Fix error before timeout in recoverable error  =========="
7863
7864 [ "$SLOW" = "no" ] && set_resend_count 4
7865
7866 test_118j() {
7867         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7868         remote_ost_nodsh && skip "remote OST with nodsh" && return
7869
7870         reset_async
7871
7872         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7873         set_nodes_failloc "$(osts_nodes)" 0x220
7874
7875         # return -EIO from OST
7876         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7877         RC=$?
7878         set_nodes_failloc "$(osts_nodes)" 0x0
7879         if [[ $RC -eq 0 ]]; then
7880                 error "Must return error due to dropped pages, rc=$RC"
7881         fi
7882
7883         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7884         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7885         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7886         if [[ $LOCKED -ne 0 ]]; then
7887                 error "Locked pages remain in cache, locked=$LOCKED"
7888         fi
7889
7890         # in recoverable error on OST we want resend and stay until it finished
7891         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7892                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7893         fi
7894
7895         rm -f $DIR/$tfile
7896         echo "No pages locked after fsync"
7897
7898         return 0
7899 }
7900 run_test 118j "Simulate unrecoverable OST side error =========="
7901
7902 test_118k()
7903 {
7904         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7905         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7906
7907         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7908         set_nodes_failloc "$(osts_nodes)" 0x20e
7909         test_mkdir -p $DIR/$tdir
7910
7911         for ((i=0;i<10;i++)); do
7912                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7913                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7914                 SLEEPPID=$!
7915                 sleep 0.500s
7916                 kill $SLEEPPID
7917                 wait $SLEEPPID
7918         done
7919
7920         set_nodes_failloc "$(osts_nodes)" 0
7921         rm -rf $DIR/$tdir
7922 }
7923 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7924
7925 test_118l()
7926 {
7927         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7928         # LU-646
7929         test_mkdir -p $DIR/$tdir
7930         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7931         rm -rf $DIR/$tdir
7932 }
7933 run_test 118l "fsync dir ========="
7934
7935 test_118m() # LU-3066
7936 {
7937         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7938         test_mkdir -p $DIR/$tdir
7939         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7940         rm -rf $DIR/$tdir
7941 }
7942 run_test 118m "fdatasync dir ========="
7943
7944 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7945
7946 test_119a() # bug 11737
7947 {
7948         BSIZE=$((512 * 1024))
7949         directio write $DIR/$tfile 0 1 $BSIZE
7950         # We ask to read two blocks, which is more than a file size.
7951         # directio will indicate an error when requested and actual
7952         # sizes aren't equeal (a normal situation in this case) and
7953         # print actual read amount.
7954         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7955         if [ "$NOB" != "$BSIZE" ]; then
7956                 error "read $NOB bytes instead of $BSIZE"
7957         fi
7958         rm -f $DIR/$tfile
7959 }
7960 run_test 119a "Short directIO read must return actual read amount"
7961
7962 test_119b() # bug 11737
7963 {
7964         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7965
7966         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7967         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7968         sync
7969         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7970                 error "direct read failed"
7971         rm -f $DIR/$tfile
7972 }
7973 run_test 119b "Sparse directIO read must return actual read amount"
7974
7975 test_119c() # bug 13099
7976 {
7977         BSIZE=1048576
7978         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7979         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7980         rm -f $DIR/$tfile
7981 }
7982 run_test 119c "Testing for direct read hitting hole"
7983
7984 test_119d() # bug 15950
7985 {
7986         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7987         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7988         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7989         BSIZE=1048576
7990         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7991         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7992         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7993         lctl set_param fail_loc=0x40d
7994         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7995         pid_dio=$!
7996         sleep 1
7997         cat $DIR/$tfile > /dev/null &
7998         lctl set_param fail_loc=0
7999         pid_reads=$!
8000         wait $pid_dio
8001         log "the DIO writes have completed, now wait for the reads (should not block very long)"
8002         sleep 2
8003         [ -n "`ps h -p $pid_reads -o comm`" ] && \
8004         error "the read rpcs have not completed in 2s"
8005         rm -f $DIR/$tfile
8006         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
8007 }
8008 run_test 119d "The DIO path should try to send a new rpc once one is completed"
8009
8010 test_120a() {
8011         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8012         test_mkdir -p $DIR/$tdir
8013         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8014                skip "no early lock cancel on server" && return 0
8015
8016         lru_resize_disable mdc
8017         lru_resize_disable osc
8018         cancel_lru_locks mdc
8019         # asynchronous object destroy at MDT could cause bl ast to client
8020         cancel_lru_locks osc
8021
8022         stat $DIR/$tdir > /dev/null
8023         can1=$(do_facet $SINGLEMDS \
8024                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8025                awk '/ldlm_cancel/ {print $2}')
8026         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8027                awk '/ldlm_bl_callback/ {print $2}')
8028         test_mkdir -c1 $DIR/$tdir/d1
8029         can2=$(do_facet $SINGLEMDS \
8030                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8031                awk '/ldlm_cancel/ {print $2}')
8032         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8033                awk '/ldlm_bl_callback/ {print $2}')
8034         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8035         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8036         lru_resize_enable mdc
8037         lru_resize_enable osc
8038 }
8039 run_test 120a "Early Lock Cancel: mkdir test"
8040
8041 test_120b() {
8042         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8043         test_mkdir $DIR/$tdir
8044         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8045                skip "no early lock cancel on server" && return 0
8046         lru_resize_disable mdc
8047         lru_resize_disable osc
8048         cancel_lru_locks mdc
8049         stat $DIR/$tdir > /dev/null
8050         can1=$(do_facet $SINGLEMDS \
8051                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8052                awk '/ldlm_cancel/ {print $2}')
8053         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8054                awk '/ldlm_bl_callback/ {print $2}')
8055         touch $DIR/$tdir/f1
8056         can2=$(do_facet $SINGLEMDS \
8057                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8058                awk '/ldlm_cancel/ {print $2}')
8059         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8060                awk '/ldlm_bl_callback/ {print $2}')
8061         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8062         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8063         lru_resize_enable mdc
8064         lru_resize_enable osc
8065 }
8066 run_test 120b "Early Lock Cancel: create test"
8067
8068 test_120c() {
8069         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8070         test_mkdir -c1 $DIR/$tdir
8071         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8072                skip "no early lock cancel on server" && return 0
8073         lru_resize_disable mdc
8074         lru_resize_disable osc
8075         test_mkdir -p -c1 $DIR/$tdir/d1
8076         test_mkdir -p -c1 $DIR/$tdir/d2
8077         touch $DIR/$tdir/d1/f1
8078         cancel_lru_locks mdc
8079         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
8080         can1=$(do_facet $SINGLEMDS \
8081                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8082                awk '/ldlm_cancel/ {print $2}')
8083         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8084                awk '/ldlm_bl_callback/ {print $2}')
8085         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8086         can2=$(do_facet $SINGLEMDS \
8087                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8088                awk '/ldlm_cancel/ {print $2}')
8089         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8090                awk '/ldlm_bl_callback/ {print $2}')
8091         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8092         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8093         lru_resize_enable mdc
8094         lru_resize_enable osc
8095 }
8096 run_test 120c "Early Lock Cancel: link test"
8097
8098 test_120d() {
8099         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8100         test_mkdir -p -c1 $DIR/$tdir
8101         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8102                skip "no early lock cancel on server" && return 0
8103         lru_resize_disable mdc
8104         lru_resize_disable osc
8105         touch $DIR/$tdir
8106         cancel_lru_locks mdc
8107         stat $DIR/$tdir > /dev/null
8108         can1=$(do_facet $SINGLEMDS \
8109                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8110                awk '/ldlm_cancel/ {print $2}')
8111         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8112                awk '/ldlm_bl_callback/ {print $2}')
8113         chmod a+x $DIR/$tdir
8114         can2=$(do_facet $SINGLEMDS \
8115                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8116                awk '/ldlm_cancel/ {print $2}')
8117         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8118                awk '/ldlm_bl_callback/ {print $2}')
8119         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8120         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8121         lru_resize_enable mdc
8122         lru_resize_enable osc
8123 }
8124 run_test 120d "Early Lock Cancel: setattr test"
8125
8126 test_120e() {
8127         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8128         ! $($LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_can) &&
8129                 skip "no early lock cancel on server" && return 0
8130         local dlmtrace_set=false
8131
8132         test_mkdir -p -c1 $DIR/$tdir
8133         lru_resize_disable mdc
8134         lru_resize_disable osc
8135         ! $LCTL get_param debug | grep -q dlmtrace &&
8136                 $LCTL set_param debug=+dlmtrace && dlmtrace_set=true
8137         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
8138         cancel_lru_locks mdc
8139         cancel_lru_locks osc
8140         dd if=$DIR/$tdir/f1 of=/dev/null
8141         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
8142         # XXX client can not do early lock cancel of OST lock
8143         # during unlink (LU-4206), so cancel osc lock now.
8144         cancel_lru_locks osc
8145         can1=$(do_facet $SINGLEMDS \
8146                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8147                awk '/ldlm_cancel/ {print $2}')
8148         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8149                awk '/ldlm_bl_callback/ {print $2}')
8150         unlink $DIR/$tdir/f1
8151         sleep 5
8152         can2=$(do_facet $SINGLEMDS \
8153                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8154                awk '/ldlm_cancel/ {print $2}')
8155         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8156                awk '/ldlm_bl_callback/ {print $2}')
8157         [ $can1 -ne $can2 ] && error "$((can2 - can1)) cancel RPC occured" &&
8158                 $LCTL dk $TMP/cancel.debug.txt
8159         [ $blk1 -ne $blk2 ] && error "$((blk2 - blk1)) blocking RPC occured" &&
8160                 $LCTL dk $TMP/blocking.debug.txt
8161         $dlmtrace_set && $LCTL set_param debug=-dlmtrace
8162         lru_resize_enable mdc
8163         lru_resize_enable osc
8164 }
8165 run_test 120e "Early Lock Cancel: unlink test"
8166
8167 test_120f() {
8168         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8169         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8170                skip "no early lock cancel on server" && return 0
8171         test_mkdir -p -c1 $DIR/$tdir
8172         lru_resize_disable mdc
8173         lru_resize_disable osc
8174         test_mkdir -p -c1 $DIR/$tdir/d1
8175         test_mkdir -p -c1 $DIR/$tdir/d2
8176         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
8177         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
8178         cancel_lru_locks mdc
8179         cancel_lru_locks osc
8180         dd if=$DIR/$tdir/d1/f1 of=/dev/null
8181         dd if=$DIR/$tdir/d2/f2 of=/dev/null
8182         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
8183         # XXX client can not do early lock cancel of OST lock
8184         # during rename (LU-4206), so cancel osc lock now.
8185         cancel_lru_locks osc
8186         can1=$(do_facet $SINGLEMDS \
8187                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8188                awk '/ldlm_cancel/ {print $2}')
8189         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8190                awk '/ldlm_bl_callback/ {print $2}')
8191         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8192         sleep 5
8193         can2=$(do_facet $SINGLEMDS \
8194                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8195                awk '/ldlm_cancel/ {print $2}')
8196         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8197                awk '/ldlm_bl_callback/ {print $2}')
8198         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8199         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8200         lru_resize_enable mdc
8201         lru_resize_enable osc
8202 }
8203 run_test 120f "Early Lock Cancel: rename test"
8204
8205 test_120g() {
8206         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8207         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8208                skip "no early lock cancel on server" && return 0
8209         lru_resize_disable mdc
8210         lru_resize_disable osc
8211         count=10000
8212         echo create $count files
8213         test_mkdir -p $DIR/$tdir
8214         cancel_lru_locks mdc
8215         cancel_lru_locks osc
8216         t0=`date +%s`
8217
8218         can0=$(do_facet $SINGLEMDS \
8219                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8220                awk '/ldlm_cancel/ {print $2}')
8221         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8222                awk '/ldlm_bl_callback/ {print $2}')
8223         createmany -o $DIR/$tdir/f $count
8224         sync
8225         can1=$(do_facet $SINGLEMDS \
8226                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8227                awk '/ldlm_cancel/ {print $2}')
8228         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8229                awk '/ldlm_bl_callback/ {print $2}')
8230         t1=$(date +%s)
8231         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
8232         echo rm $count files
8233         rm -r $DIR/$tdir
8234         sync
8235         can2=$(do_facet $SINGLEMDS \
8236                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8237                awk '/ldlm_cancel/ {print $2}')
8238         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8239                awk '/ldlm_bl_callback/ {print $2}')
8240         t2=$(date +%s)
8241         echo total: $count removes in $((t2-t1))
8242         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
8243         sleep 2
8244         # wait for commitment of removal
8245         lru_resize_enable mdc
8246         lru_resize_enable osc
8247 }
8248 run_test 120g "Early Lock Cancel: performance test"
8249
8250 test_121() { #bug #10589
8251         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8252         rm -rf $DIR/$tfile
8253         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8254 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8255         lctl set_param fail_loc=0x310
8256         cancel_lru_locks osc > /dev/null
8257         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8258         lctl set_param fail_loc=0
8259         [[ $reads -eq $writes ]] ||
8260                 error "read $reads blocks, must be $writes blocks"
8261 }
8262 run_test 121 "read cancel race ========="
8263
8264 test_123a() { # was test 123, statahead(bug 11401)
8265         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8266         SLOWOK=0
8267         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8268             log "testing on UP system. Performance may be not as good as expected."
8269                         SLOWOK=1
8270         fi
8271
8272         rm -rf $DIR/$tdir
8273         test_mkdir -p $DIR/$tdir
8274         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8275         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8276         MULT=10
8277         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8278                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8279
8280                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8281                 lctl set_param -n llite.*.statahead_max 0
8282                 lctl get_param llite.*.statahead_max
8283                 cancel_lru_locks mdc
8284                 cancel_lru_locks osc
8285                 stime=`date +%s`
8286                 time ls -l $DIR/$tdir | wc -l
8287                 etime=`date +%s`
8288                 delta=$((etime - stime))
8289                 log "ls $i files without statahead: $delta sec"
8290                 lctl set_param llite.*.statahead_max=$max
8291
8292                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8293                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8294                 cancel_lru_locks mdc
8295                 cancel_lru_locks osc
8296                 stime=`date +%s`
8297                 time ls -l $DIR/$tdir | wc -l
8298                 etime=`date +%s`
8299                 delta_sa=$((etime - stime))
8300                 log "ls $i files with statahead: $delta_sa sec"
8301                 lctl get_param -n llite.*.statahead_stats
8302                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8303
8304                 [[ $swrong -lt $ewrong ]] &&
8305                         log "statahead was stopped, maybe too many locks held!"
8306                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8307
8308                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8309                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8310                     lctl set_param -n llite.*.statahead_max 0
8311                     lctl get_param llite.*.statahead_max
8312                     cancel_lru_locks mdc
8313                     cancel_lru_locks osc
8314                     stime=`date +%s`
8315                     time ls -l $DIR/$tdir | wc -l
8316                     etime=`date +%s`
8317                     delta=$((etime - stime))
8318                     log "ls $i files again without statahead: $delta sec"
8319                     lctl set_param llite.*.statahead_max=$max
8320                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8321                         if [  $SLOWOK -eq 0 ]; then
8322                                 error "ls $i files is slower with statahead!"
8323                         else
8324                                 log "ls $i files is slower with statahead!"
8325                         fi
8326                         break
8327                     fi
8328                 fi
8329
8330                 [ $delta -gt 20 ] && break
8331                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8332                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8333         done
8334         log "ls done"
8335
8336         stime=`date +%s`
8337         rm -r $DIR/$tdir
8338         sync
8339         etime=`date +%s`
8340         delta=$((etime - stime))
8341         log "rm -r $DIR/$tdir/: $delta seconds"
8342         log "rm done"
8343         lctl get_param -n llite.*.statahead_stats
8344 }
8345 run_test 123a "verify statahead work"
8346
8347 test_123b () { # statahead(bug 15027)
8348         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8349         test_mkdir -p $DIR/$tdir
8350         createmany -o $DIR/$tdir/$tfile-%d 1000
8351
8352         cancel_lru_locks mdc
8353         cancel_lru_locks osc
8354
8355 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8356         lctl set_param fail_loc=0x80000803
8357         ls -lR $DIR/$tdir > /dev/null
8358         log "ls done"
8359         lctl set_param fail_loc=0x0
8360         lctl get_param -n llite.*.statahead_stats
8361         rm -r $DIR/$tdir
8362         sync
8363
8364 }
8365 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8366
8367 test_124a() {
8368         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8369         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8370                 skip "no lru resize on server" && return 0
8371         local NR=2000
8372         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8373
8374         log "create $NR files at $DIR/$tdir"
8375         createmany -o $DIR/$tdir/f $NR ||
8376                 error "failed to create $NR files in $DIR/$tdir"
8377
8378         cancel_lru_locks mdc
8379         ls -l $DIR/$tdir > /dev/null
8380
8381         local NSDIR=""
8382         local LRU_SIZE=0
8383         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8384                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8385                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8386                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8387                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8388                         log "NSDIR=$NSDIR"
8389                         log "NS=$(basename $NSDIR)"
8390                         break
8391                 fi
8392         done
8393
8394         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8395                 skip "Not enough cached locks created!"
8396                 return 0
8397         fi
8398         log "LRU=$LRU_SIZE"
8399
8400         local SLEEP=30
8401
8402         # We know that lru resize allows one client to hold $LIMIT locks
8403         # for 10h. After that locks begin to be killed by client.
8404         local MAX_HRS=10
8405         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8406         log "LIMIT=$LIMIT"
8407         if [ $LIMIT -lt $LRU_SIZE ]; then
8408             skip "Limit is too small $LIMIT"
8409             return 0
8410         fi
8411
8412         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8413         # killing locks. Some time was spent for creating locks. This means
8414         # that up to the moment of sleep finish we must have killed some of
8415         # them (10-100 locks). This depends on how fast ther were created.
8416         # Many of them were touched in almost the same moment and thus will
8417         # be killed in groups.
8418         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8419
8420         # Use $LRU_SIZE_B here to take into account real number of locks
8421         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8422         local LRU_SIZE_B=$LRU_SIZE
8423         log "LVF=$LVF"
8424         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8425         log "OLD_LVF=$OLD_LVF"
8426         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8427
8428         # Let's make sure that we really have some margin. Client checks
8429         # cached locks every 10 sec.
8430         SLEEP=$((SLEEP+20))
8431         log "Sleep ${SLEEP} sec"
8432         local SEC=0
8433         while ((SEC<$SLEEP)); do
8434                 echo -n "..."
8435                 sleep 5
8436                 SEC=$((SEC+5))
8437                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8438                 echo -n "$LRU_SIZE"
8439         done
8440         echo ""
8441         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8442         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8443
8444         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8445                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8446                 unlinkmany $DIR/$tdir/f $NR
8447                 return
8448         }
8449
8450         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8451         log "unlink $NR files at $DIR/$tdir"
8452         unlinkmany $DIR/$tdir/f $NR
8453 }
8454 run_test 124a "lru resize ======================================="
8455
8456 get_max_pool_limit()
8457 {
8458         local limit=$($LCTL get_param \
8459                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8460         local max=0
8461         for l in $limit; do
8462                 if [[ $l -gt $max ]]; then
8463                         max=$l
8464                 fi
8465         done
8466         echo $max
8467 }
8468
8469 test_124b() {
8470         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8471         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8472                 skip "no lru resize on server" && return 0
8473
8474         LIMIT=$(get_max_pool_limit)
8475
8476         NR=$(($(default_lru_size)*20))
8477         if [[ $NR -gt $LIMIT ]]; then
8478                 log "Limit lock number by $LIMIT locks"
8479                 NR=$LIMIT
8480         fi
8481         lru_resize_disable mdc
8482         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8483                 error "failed to create $DIR/$tdir/disable_lru_resize"
8484
8485         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8486         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8487         cancel_lru_locks mdc
8488         stime=`date +%s`
8489         PID=""
8490         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8491         PID="$PID $!"
8492         sleep 2
8493         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8494         PID="$PID $!"
8495         sleep 2
8496         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8497         PID="$PID $!"
8498         wait $PID
8499         etime=`date +%s`
8500         nolruresize_delta=$((etime-stime))
8501         log "ls -la time: $nolruresize_delta seconds"
8502         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8503         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8504
8505         lru_resize_enable mdc
8506         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8507                 error "failed to create $DIR/$tdir/enable_lru_resize"
8508
8509         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8510         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8511         cancel_lru_locks mdc
8512         stime=`date +%s`
8513         PID=""
8514         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8515         PID="$PID $!"
8516         sleep 2
8517         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8518         PID="$PID $!"
8519         sleep 2
8520         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8521         PID="$PID $!"
8522         wait $PID
8523         etime=`date +%s`
8524         lruresize_delta=$((etime-stime))
8525         log "ls -la time: $lruresize_delta seconds"
8526         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8527
8528         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8529                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8530         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8531                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8532         else
8533                 log "lru resize performs the same with no lru resize"
8534         fi
8535         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8536 }
8537 run_test 124b "lru resize (performance test) ======================="
8538
8539 test_124c() {
8540         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8541         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8542                 skip "no lru resize on server" && return 0
8543
8544         # cache ununsed locks on client
8545         local nr=100
8546         cancel_lru_locks mdc
8547         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8548         createmany -o $DIR/$tdir/f $nr ||
8549                 error "failed to create $nr files in $DIR/$tdir"
8550         ls -l $DIR/$tdir > /dev/null
8551
8552         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
8553         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
8554         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
8555         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
8556         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
8557
8558         # set lru_max_age to 1 sec
8559         $LCTL set_param $nsdir.lru_max_age=1000 # jiffies
8560         echo "sleep $((recalc_p * 2)) seconds..."
8561         sleep $((recalc_p * 2))
8562
8563         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
8564         # restore lru_max_age
8565         $LCTL set_param -n $nsdir.lru_max_age $max_age
8566         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
8567         unlinkmany $DIR/$tdir/f $nr
8568 }
8569 run_test 124c "LRUR cancel very aged locks"
8570
8571 test_125() { # 13358
8572         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8573         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8574         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8575         test_mkdir -p $DIR/d125 || error "mkdir failed"
8576         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8577         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8578         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8579 }
8580 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8581
8582 test_126() { # bug 12829/13455
8583         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8584         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8585         $GSS && skip "must run as gss disabled" && return
8586
8587         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8588         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8589         rm -f $DIR/$tfile
8590         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8591 }
8592 run_test 126 "check that the fsgid provided by the client is taken into account"
8593
8594 test_127a() { # bug 15521
8595         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8596         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8597         $LCTL set_param osc.*.stats=0
8598         FSIZE=$((2048 * 1024))
8599         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8600         cancel_lru_locks osc
8601         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8602
8603         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8604         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8605                 echo "got $COUNT $NAME"
8606                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8607                 eval $NAME=$COUNT || error "Wrong proc format"
8608
8609                 case $NAME in
8610                         read_bytes|write_bytes)
8611                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8612                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8613                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8614                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8615                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8616                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8617                                 error "sumsquare is too small: $SUMSQ"
8618                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8619                                 error "sumsquare is too big: $SUMSQ"
8620                         ;;
8621                         *) ;;
8622                 esac
8623         done < $DIR/${tfile}.tmp
8624
8625         #check that we actually got some stats
8626         [ "$read_bytes" ] || error "Missing read_bytes stats"
8627         [ "$write_bytes" ] || error "Missing write_bytes stats"
8628         [ "$read_bytes" != 0 ] || error "no read done"
8629         [ "$write_bytes" != 0 ] || error "no write done"
8630 }
8631 run_test 127a "verify the client stats are sane"
8632
8633 test_127b() { # bug LU-333
8634         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8635         $LCTL set_param llite.*.stats=0
8636         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8637         # perform 2 reads and writes so MAX is different from SUM.
8638         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8639         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8640         cancel_lru_locks osc
8641         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8642         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8643
8644         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8645         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8646                 echo "got $COUNT $NAME"
8647                 eval $NAME=$COUNT || error "Wrong proc format"
8648
8649         case $NAME in
8650                 read_bytes)
8651                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8652                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8653                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8654                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8655                         ;;
8656                 write_bytes)
8657                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8658                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8659                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8660                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8661                         ;;
8662                         *) ;;
8663                 esac
8664         done < $TMP/${tfile}.tmp
8665
8666         #check that we actually got some stats
8667         [ "$read_bytes" ] || error "Missing read_bytes stats"
8668         [ "$write_bytes" ] || error "Missing write_bytes stats"
8669         [ "$read_bytes" != 0 ] || error "no read done"
8670         [ "$write_bytes" != 0 ] || error "no write done"
8671 }
8672 run_test 127b "verify the llite client stats are sane"
8673
8674 test_128() { # bug 15212
8675         touch $DIR/$tfile
8676         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8677                 find $DIR/$tfile
8678                 find $DIR/$tfile
8679         EOF
8680
8681         result=$(grep error $TMP/$tfile.log)
8682         rm -f $DIR/$tfile
8683         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8684 }
8685 run_test 128 "interactive lfs for 2 consecutive find's"
8686
8687 set_dir_limits () {
8688         local mntdev
8689         local canondev
8690         local node
8691
8692         local LDPROC=/proc/fs/ldiskfs
8693         local facets=$(get_facets MDS)
8694
8695         for facet in ${facets//,/ }; do
8696                 canondev=$(ldiskfs_canon \
8697                            *.$(convert_facet2label $facet).mntdev $facet)
8698                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8699                                                 LDPROC=/sys/fs/ldiskfs
8700                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8701                 do_facet $facet "test -e $LDPROC/$canondev/warning_dir_size" ||
8702                                                 LDPROC=/sys/fs/ldiskfs
8703                 do_facet $facet "echo $2 >$LDPROC/$canondev/warning_dir_size"
8704         done
8705 }
8706
8707 check_mds_dmesg() {
8708         local facets=$(get_facets MDS)
8709         for facet in ${facets//,/ }; do
8710                 do_facet $facet "dmesg | tail -3 | grep -q $1" && return 0
8711         done
8712         return 1
8713 }
8714
8715 test_129() {
8716         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8717         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8718                 skip "Only applicable to ldiskfs-based MDTs"
8719                 return
8720         fi
8721         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8722         ENOSPC=28
8723         EFBIG=27
8724         has_warning=0
8725
8726         rm -rf $DIR/$tdir
8727         mkdir -p $DIR/$tdir
8728
8729         # block size of mds1
8730         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8731         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8732         local MAX=$((MDSBLOCKSIZE * 5))
8733         set_dir_limits $MAX $MAX
8734         local I=$(stat -c%s "$DIR/$tdir")
8735         local J=0
8736         while [[ $I -le $MAX ]]; do
8737                 $MULTIOP $DIR/$tdir/$J Oc
8738                 rc=$?
8739                 if [ $has_warning -eq 0 ]; then
8740                         check_mds_dmesg '"is approaching"' &&
8741                                 has_warning=1
8742                 fi
8743                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8744                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8745                 #and EFBIG for previous versions
8746                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8747                         set_dir_limits 0 0
8748                         echo "return code $rc received as expected"
8749
8750                         createmany -o $DIR/$tdir/$J_file_ 1000 ||
8751                                 error_exit "create failed w/o dir size limit"
8752
8753                         check_mds_dmesg '"has reached"' ||
8754                                 error_exit "has reached message should be output"
8755
8756                         [ $has_warning ] ||
8757                                 error_exit "warning message should be output"
8758
8759                         I=$(stat -c%s "$DIR/$tdir")
8760
8761                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8762                                         $(version_code 2.4.51) ]
8763                         then
8764                                 [[ $I -eq $MAX ]] && return 0
8765                         else
8766                                 [[ $I -gt $MAX ]] && return 0
8767                         fi
8768                         error_exit "current dir size $I, previous limit $MAX"
8769                 elif [ $rc -ne 0 ]; then
8770                         set_dir_limits 0 0
8771                         error_exit "return code $rc received instead of expected " \
8772                                    "$EFBIG or $ENOSPC, files in dir $I"
8773                 fi
8774                 J=$((J+1))
8775                 I=$(stat -c%s "$DIR/$tdir")
8776         done
8777
8778         set_dir_limits 0 0
8779         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8780 }
8781 run_test 129 "test directory size limit ========================"
8782
8783 OLDIFS="$IFS"
8784 cleanup_130() {
8785         trap 0
8786         IFS="$OLDIFS"
8787 }
8788
8789 test_130a() {
8790         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8791         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8792                 return
8793
8794         trap cleanup_130 EXIT RETURN
8795
8796         local fm_file=$DIR/$tfile
8797         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8798         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8799                 error "dd failed for $fm_file"
8800
8801         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8802         filefrag -ves $fm_file
8803         RC=$?
8804         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8805                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8806         [ $RC != 0 ] && error "filefrag $fm_file failed"
8807
8808         filefrag_op=$(filefrag -ve $fm_file |
8809                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
8810         lun=$($GETSTRIPE -i $fm_file)
8811
8812         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8813         IFS=$'\n'
8814         tot_len=0
8815         for line in $filefrag_op
8816         do
8817                 frag_lun=`echo $line | cut -d: -f5`
8818                 ext_len=`echo $line | cut -d: -f4`
8819                 if (( $frag_lun != $lun )); then
8820                         cleanup_130
8821                         error "FIEMAP on 1-stripe file($fm_file) failed"
8822                         return
8823                 fi
8824                 (( tot_len += ext_len ))
8825         done
8826
8827         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8828                 cleanup_130
8829                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8830                 return
8831         fi
8832
8833         cleanup_130
8834
8835         echo "FIEMAP on single striped file succeeded"
8836 }
8837 run_test 130a "FIEMAP (1-stripe file)"
8838
8839 test_130b() {
8840         [ "$OSTCOUNT" -lt "2" ] &&
8841                 skip_env "skipping FIEMAP on $OSTCOUNT-stripe file" && return
8842
8843         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8844         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8845                 return
8846
8847         trap cleanup_130 EXIT RETURN
8848
8849         local fm_file=$DIR/$tfile
8850         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
8851                         error "setstripe on $fm_file"
8852         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8853                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8854
8855         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT ||
8856                 error "dd failed on $fm_file"
8857
8858         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8859         filefrag_op=$(filefrag -ve $fm_file |
8860                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
8861
8862         last_lun=$(echo $filefrag_op | cut -d: -f5 |
8863                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
8864
8865         IFS=$'\n'
8866         tot_len=0
8867         num_luns=1
8868         for line in $filefrag_op
8869         do
8870                 frag_lun=$(echo $line | cut -d: -f5 |
8871                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
8872                 ext_len=$(echo $line | cut -d: -f4)
8873                 if (( $frag_lun != $last_lun )); then
8874                         if (( tot_len != 1024 )); then
8875                                 cleanup_130
8876                                 error "FIEMAP on $fm_file failed; returned " \
8877                                 "len $tot_len for OST $last_lun instead of 1024"
8878                                 return
8879                         else
8880                                 (( num_luns += 1 ))
8881                                 tot_len=0
8882                         fi
8883                 fi
8884                 (( tot_len += ext_len ))
8885                 last_lun=$frag_lun
8886         done
8887         if (( num_luns != $OSTCOUNT || tot_len != 1024 )); then
8888                 cleanup_130
8889                 error "FIEMAP on $fm_file failed; returned wrong number of " \
8890                         "luns or wrong len for OST $last_lun"
8891                 return
8892         fi
8893
8894         cleanup_130
8895
8896         echo "FIEMAP on $OSTCOUNT-stripe file succeeded"
8897 }
8898 run_test 130b "FIEMAP ($OSTCOUNT-stripe file)"
8899
8900 test_130c() {
8901         [ "$OSTCOUNT" -lt "2" ] &&
8902                 skip_env "skipping FIEMAP on 2-stripe file" && return
8903
8904         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8905         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8906                 return
8907
8908         trap cleanup_130 EXIT RETURN
8909
8910         local fm_file=$DIR/$tfile
8911         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8912         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8913                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8914
8915         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 ||
8916                         error "dd failed on $fm_file"
8917
8918         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8919         filefrag_op=$(filefrag -ve $fm_file |
8920                 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
8921
8922         last_lun=$(echo $filefrag_op | cut -d: -f5 |
8923                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
8924
8925         IFS=$'\n'
8926         tot_len=0
8927         num_luns=1
8928         for line in $filefrag_op
8929         do
8930                 frag_lun=$(echo $line | cut -d: -f5 |
8931                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
8932                 ext_len=$(echo $line | cut -d: -f4)
8933                 if (( $frag_lun != $last_lun )); then
8934                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8935                         if (( logical != 512 )); then
8936                                 cleanup_130
8937                                 error "FIEMAP on $fm_file failed; returned " \
8938                                 "logical start for lun $logical instead of 512"
8939                                 return
8940                         fi
8941                         if (( tot_len != 512 )); then
8942                                 cleanup_130
8943                                 error "FIEMAP on $fm_file failed; returned " \
8944                                 "len $tot_len for OST $last_lun instead of 1024"
8945                                 return
8946                         else
8947                                 (( num_luns += 1 ))
8948                                 tot_len=0
8949                         fi
8950                 fi
8951                 (( tot_len += ext_len ))
8952                 last_lun=$frag_lun
8953         done
8954         if (( num_luns != 2 || tot_len != 512 )); then
8955                 cleanup_130
8956                 error "FIEMAP on $fm_file failed; returned wrong number of " \
8957                         "luns or wrong len for OST $last_lun"
8958                 return
8959         fi
8960
8961         cleanup_130
8962
8963         echo "FIEMAP on 2-stripe file with hole succeeded"
8964 }
8965 run_test 130c "FIEMAP (2-stripe file with hole)"
8966
8967 test_130d() {
8968         [ "$OSTCOUNT" -lt "3" ] &&
8969                 skip_env "skipping FIEMAP on N-stripe file test" && return
8970
8971         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8972         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8973                 return
8974
8975         trap cleanup_130 EXIT RETURN
8976
8977         local fm_file=$DIR/$tfile
8978         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
8979                         error "setstripe on $fm_file"
8980         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8981                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8982
8983         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8984         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8985                 error "dd failed on $fm_file"
8986
8987         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8988         filefrag_op=$(filefrag -ve $fm_file |
8989                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
8990
8991         last_lun=$(echo $filefrag_op | cut -d: -f5 |
8992                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
8993
8994         IFS=$'\n'
8995         tot_len=0
8996         num_luns=1
8997         for line in $filefrag_op
8998         do
8999                 frag_lun=$(echo $line | cut -d: -f5 |
9000                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9001                 ext_len=$(echo $line | cut -d: -f4)
9002                 if (( $frag_lun != $last_lun )); then
9003                         if (( tot_len != 1024 )); then
9004                                 cleanup_130
9005                                 error "FIEMAP on $fm_file failed; returned " \
9006                                 "len $tot_len for OST $last_lun instead of 1024"
9007                                 return
9008                         else
9009                                 (( num_luns += 1 ))
9010                                 tot_len=0
9011                         fi
9012                 fi
9013                 (( tot_len += ext_len ))
9014                 last_lun=$frag_lun
9015         done
9016         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
9017                 cleanup_130
9018                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9019                         "luns or wrong len for OST $last_lun"
9020                 return
9021         fi
9022
9023         cleanup_130
9024
9025         echo "FIEMAP on N-stripe file succeeded"
9026 }
9027 run_test 130d "FIEMAP (N-stripe file)"
9028
9029 test_130e() {
9030         [ "$OSTCOUNT" -lt "2" ] &&
9031                 skip_env "skipping continuation FIEMAP test" && return
9032
9033         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9034         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
9035
9036         trap cleanup_130 EXIT RETURN
9037
9038         local fm_file=$DIR/$tfile
9039         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
9040         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9041                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9042
9043         NUM_BLKS=512
9044         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
9045         for ((i = 0; i < $NUM_BLKS; i++))
9046         do
9047                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
9048         done
9049
9050         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9051         filefrag_op=$(filefrag -ve $fm_file |
9052                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9053
9054         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9055                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9056
9057         IFS=$'\n'
9058         tot_len=0
9059         num_luns=1
9060         for line in $filefrag_op
9061         do
9062                 frag_lun=$(echo $line | cut -d: -f5 |
9063                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9064                 ext_len=$(echo $line | cut -d: -f4)
9065                 if (( $frag_lun != $last_lun )); then
9066                         if (( tot_len != $EXPECTED_LEN )); then
9067                                 cleanup_130
9068                                 error "FIEMAP on $fm_file failed; returned " \
9069                                 "len $tot_len for OST $last_lun instead " \
9070                                 "of $EXPECTED_LEN"
9071                                 return
9072                         else
9073                                 (( num_luns += 1 ))
9074                                 tot_len=0
9075                         fi
9076                 fi
9077                 (( tot_len += ext_len ))
9078                 last_lun=$frag_lun
9079         done
9080         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
9081                 cleanup_130
9082                 error "FIEMAP on $fm_file failed; returned wrong number " \
9083                         "of luns or wrong len for OST $last_lun"
9084                 return
9085         fi
9086
9087         cleanup_130
9088
9089         echo "FIEMAP with continuation calls succeeded"
9090 }
9091 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
9092
9093 # Test for writev/readv
9094 test_131a() {
9095         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
9096         error "writev test failed"
9097         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
9098         error "readv failed"
9099         rm -f $DIR/$tfile
9100 }
9101 run_test 131a "test iov's crossing stripe boundary for writev/readv"
9102
9103 test_131b() {
9104         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
9105         error "append writev test failed"
9106         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
9107         error "append writev test failed"
9108         rm -f $DIR/$tfile
9109 }
9110 run_test 131b "test append writev"
9111
9112 test_131c() {
9113         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
9114         error "NOT PASS"
9115 }
9116 run_test 131c "test read/write on file w/o objects"
9117
9118 test_131d() {
9119         rwv -f $DIR/$tfile -w -n 1 1572864
9120         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
9121         if [ "$NOB" != 1572864 ]; then
9122                 error "Short read filed: read $NOB bytes instead of 1572864"
9123         fi
9124         rm -f $DIR/$tfile
9125 }
9126 run_test 131d "test short read"
9127
9128 test_131e() {
9129         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
9130         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
9131         error "read hitting hole failed"
9132         rm -f $DIR/$tfile
9133 }
9134 run_test 131e "test read hitting hole"
9135
9136 check_stats() {
9137         local res
9138         local count
9139         case $1 in
9140         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
9141                  ;;
9142         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
9143                  ;;
9144         *) error "Wrong argument $1" ;;
9145         esac
9146         echo $res
9147         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
9148         # if the argument $3 is zero, it means any stat increment is ok.
9149         if [[ $3 -gt 0 ]]; then
9150                 count=$(echo $res | awk '{ print $2 }')
9151                 [[ $count -ne $3 ]] &&
9152                         error "The $2 counter on $1 is wrong - expected $3"
9153         fi
9154 }
9155
9156 test_133a() {
9157         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9158         remote_ost_nodsh && skip "remote OST with nodsh" && return
9159         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9160
9161         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9162                 { skip "MDS doesn't support rename stats"; return; }
9163         local testdir=$DIR/${tdir}/stats_testdir
9164         mkdir -p $DIR/${tdir}
9165
9166         # clear stats.
9167         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9168         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9169
9170         # verify mdt stats first.
9171         mkdir ${testdir} || error "mkdir failed"
9172         check_stats $SINGLEMDS "mkdir" 1
9173         touch ${testdir}/${tfile} || "touch failed"
9174         check_stats $SINGLEMDS "open" 1
9175         check_stats $SINGLEMDS "close" 1
9176         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
9177         check_stats $SINGLEMDS "mknod" 1
9178         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
9179         check_stats $SINGLEMDS "unlink" 1
9180         rm -f ${testdir}/${tfile} || error "file remove failed"
9181         check_stats $SINGLEMDS "unlink" 2
9182
9183         # remove working dir and check mdt stats again.
9184         rmdir ${testdir} || error "rmdir failed"
9185         check_stats $SINGLEMDS "rmdir" 1
9186
9187         local testdir1=$DIR/${tdir}/stats_testdir1
9188         mkdir -p ${testdir}
9189         mkdir -p ${testdir1}
9190         touch ${testdir1}/test1
9191         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
9192         check_stats $SINGLEMDS "crossdir_rename" 1
9193
9194         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
9195         check_stats $SINGLEMDS "samedir_rename" 1
9196
9197         rm -rf $DIR/${tdir}
9198 }
9199 run_test 133a "Verifying MDT stats ========================================"
9200
9201 test_133b() {
9202         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9203         remote_ost_nodsh && skip "remote OST with nodsh" && return
9204         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9205         local testdir=$DIR/${tdir}/stats_testdir
9206         mkdir -p ${testdir} || error "mkdir failed"
9207         touch ${testdir}/${tfile} || "touch failed"
9208         cancel_lru_locks mdc
9209
9210         # clear stats.
9211         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9212         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9213
9214         # extra mdt stats verification.
9215         chmod 444 ${testdir}/${tfile} || error "chmod failed"
9216         check_stats $SINGLEMDS "setattr" 1
9217         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9218         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
9219         then            # LU-1740
9220                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
9221                 check_stats $SINGLEMDS "getattr" 1
9222         fi
9223         $LFS df || error "lfs failed"
9224         check_stats $SINGLEMDS "statfs" 1
9225
9226         rm -rf $DIR/${tdir}
9227 }
9228 run_test 133b "Verifying extra MDT stats =================================="
9229
9230 test_133c() {
9231         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9232         remote_ost_nodsh && skip "remote OST with nodsh" && return
9233         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9234         local testdir=$DIR/${tdir}/stats_testdir
9235         test_mkdir -p ${testdir} || error "mkdir failed"
9236
9237         # verify obdfilter stats.
9238         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9239         sync
9240         cancel_lru_locks osc
9241         wait_delete_completed
9242
9243         # clear stats.
9244         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9245         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9246
9247         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
9248         sync
9249         cancel_lru_locks osc
9250         check_stats ost "write" 1
9251
9252         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9253         check_stats ost "read" 1
9254
9255         > ${testdir}/${tfile} || error "truncate failed"
9256         check_stats ost "punch" 1
9257
9258         rm -f ${testdir}/${tfile} || error "file remove failed"
9259         wait_delete_completed
9260         check_stats ost "destroy" 1
9261
9262         rm -rf $DIR/${tdir}
9263 }
9264 run_test 133c "Verifying OST stats ========================================"
9265
9266 order_2() {
9267         local value=$1
9268         local orig=$value
9269         local order=1
9270
9271         while [ $value -ge 2 ]; do
9272                 order=$((order*2))
9273                 value=$((value/2))
9274         done
9275
9276         if [ $orig -gt $order ]; then
9277                 order=$((order*2))
9278         fi
9279         echo $order
9280 }
9281
9282 size_in_KMGT() {
9283     local value=$1
9284     local size=('K' 'M' 'G' 'T');
9285     local i=0
9286     local size_string=$value
9287
9288     while [ $value -ge 1024 ]; do
9289         if [ $i -gt 3 ]; then
9290             #T is the biggest unit we get here, if that is bigger,
9291             #just return XXXT
9292             size_string=${value}T
9293             break
9294         fi
9295         value=$((value >> 10))
9296         if [ $value -lt 1024 ]; then
9297             size_string=${value}${size[$i]}
9298             break
9299         fi
9300         i=$((i + 1))
9301     done
9302
9303     echo $size_string
9304 }
9305
9306 get_rename_size() {
9307     local size=$1
9308     local context=${2:-.}
9309     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9310                 grep -A1 $context |
9311                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9312     echo $sample
9313 }
9314
9315 test_133d() {
9316         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9317         remote_ost_nodsh && skip "remote OST with nodsh" && return
9318         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9319         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9320         { skip "MDS doesn't support rename stats"; return; }
9321
9322         local testdir1=$DIR/${tdir}/stats_testdir1
9323         local testdir2=$DIR/${tdir}/stats_testdir2
9324
9325         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9326
9327         mkdir -p ${testdir1} || error "mkdir failed"
9328         mkdir -p ${testdir2} || error "mkdir failed"
9329
9330         createmany -o $testdir1/test 512 || error "createmany failed"
9331
9332         # check samedir rename size
9333         mv ${testdir1}/test0 ${testdir1}/test_0
9334
9335         local testdir1_size=$(ls -l $DIR/${tdir} |
9336                 awk '/stats_testdir1/ {print $5}')
9337         local testdir2_size=$(ls -l $DIR/${tdir} |
9338                 awk '/stats_testdir2/ {print $5}')
9339
9340         testdir1_size=$(order_2 $testdir1_size)
9341         testdir2_size=$(order_2 $testdir2_size)
9342
9343         testdir1_size=$(size_in_KMGT $testdir1_size)
9344         testdir2_size=$(size_in_KMGT $testdir2_size)
9345
9346         echo "source rename dir size: ${testdir1_size}"
9347         echo "target rename dir size: ${testdir2_size}"
9348
9349         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9350         eval $cmd || error "$cmd failed"
9351         local samedir=$($cmd | grep 'same_dir')
9352         local same_sample=$(get_rename_size $testdir1_size)
9353         [ -z "$samedir" ] && error "samedir_rename_size count error"
9354         [[ $same_sample -eq 1 ]] ||
9355                 error "samedir_rename_size error $same_sample"
9356         echo "Check same dir rename stats success"
9357
9358         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9359
9360         # check crossdir rename size
9361         mv ${testdir1}/test_0 ${testdir2}/test_0
9362
9363         testdir1_size=$(ls -l $DIR/${tdir} |
9364                 awk '/stats_testdir1/ {print $5}')
9365         testdir2_size=$(ls -l $DIR/${tdir} |
9366                 awk '/stats_testdir2/ {print $5}')
9367
9368         testdir1_size=$(order_2 $testdir1_size)
9369         testdir2_size=$(order_2 $testdir2_size)
9370
9371         testdir1_size=$(size_in_KMGT $testdir1_size)
9372         testdir2_size=$(size_in_KMGT $testdir2_size)
9373
9374         echo "source rename dir size: ${testdir1_size}"
9375         echo "target rename dir size: ${testdir2_size}"
9376
9377         eval $cmd || error "$cmd failed"
9378         local crossdir=$($cmd | grep 'crossdir')
9379         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9380         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9381         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9382         [[ $src_sample -eq 1 ]] ||
9383                 error "crossdir_rename_size error $src_sample"
9384         [[ $tgt_sample -eq 1 ]] ||
9385                 error "crossdir_rename_size error $tgt_sample"
9386         echo "Check cross dir rename stats success"
9387         rm -rf $DIR/${tdir}
9388 }
9389 run_test 133d "Verifying rename_stats ========================================"
9390
9391 test_133e() {
9392         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9393         remote_ost_nodsh && skip "remote OST with nodsh" && return
9394         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9395         local testdir=$DIR/${tdir}/stats_testdir
9396         local ctr f0 f1 bs=32768 count=42 sum
9397
9398         mkdir -p ${testdir} || error "mkdir failed"
9399
9400         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9401
9402         for ctr in {write,read}_bytes; do
9403                 sync
9404                 cancel_lru_locks osc
9405
9406                 do_facet ost1 $LCTL set_param -n \
9407                         "obdfilter.*.exports.clear=clear"
9408
9409                 if [ $ctr = write_bytes ]; then
9410                         f0=/dev/zero
9411                         f1=${testdir}/${tfile}
9412                 else
9413                         f0=${testdir}/${tfile}
9414                         f1=/dev/null
9415                 fi
9416
9417                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9418                         error "dd failed"
9419                 sync
9420                 cancel_lru_locks osc
9421
9422                 sum=$(do_facet ost1 $LCTL get_param \
9423                         "obdfilter.*.exports.*.stats" |
9424                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9425                                 $1 == ctr { sum += $7 }
9426                                 END { printf("%0.0f", sum) }')
9427
9428                 if ((sum != bs * count)); then
9429                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9430                 fi
9431         done
9432
9433         rm -rf $DIR/${tdir}
9434 }
9435 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9436
9437 proc_dirs=""
9438 for dir in /proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9439            /sys/fs/lustre/ /sys/fs/lnet/ /sys/kernel/debug/lnet/ \
9440            /sys/kernel/debug/lustre/; do
9441         [[ -d $dir ]] && proc_dirs+=" $dir"
9442 done
9443
9444 test_133f() {
9445         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9446         remote_ost_nodsh && skip "remote OST with nodsh" && return
9447         # First without trusting modes.
9448         find $proc_dirs -exec cat '{}' \; &> /dev/null
9449
9450         # Second verifying readability.
9451         $LCTL get_param -R '*' &> /dev/null || error "proc file read failed"
9452
9453         # eventually, this can also be replaced with "lctl get_param -R",
9454         # but not until that option is always available on the server
9455         local facet
9456         for facet in $SINGLEMDS ost1; do
9457                 do_facet $facet find $proc_dirs \
9458                         ! -name req_history \
9459                         -exec cat '{}' \\\; &> /dev/null
9460
9461                 do_facet $facet find $proc_dirs \
9462                         ! -name req_history \
9463                         -type f \
9464                         -exec cat '{}' \\\; &> /dev/null ||
9465                                 error "proc file read failed"
9466         done
9467 }
9468 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9469
9470 test_133g() {
9471         # Second verifying writability.
9472         find $proc_dirs \
9473                 -type f \
9474                 -not -name force_lbug \
9475                 -not -name changelog_mask \
9476                 -exec badarea_io '{}' \; &> /dev/null ||
9477                 error "find $proc_dirs failed"
9478
9479         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
9480                 skip "Too old lustre on MDS" && return
9481
9482         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
9483                 skip "Too old lustre on ost1" && return
9484
9485         local facet
9486         for facet in $SINGLEMDS ost1; do
9487                 do_facet $facet find $proc_dirs \
9488                         -type f \
9489                         -not -name force_lbug \
9490                         -not -name changelog_mask \
9491                         -exec badarea_io '{}' \\\; &> /dev/null ||
9492                 error "$facet find $proc_dirs failed"
9493
9494         done
9495
9496         # remount the FS in case writes/reads /proc break the FS
9497         cleanup || error "failed to unmount"
9498         setup || error "failed to setup"
9499         true
9500 }
9501 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9502
9503 test_134a() {
9504         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
9505                 skip "Need MDS version at least 2.7.54" && return
9506
9507         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9508         cancel_lru_locks mdc
9509
9510         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
9511         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9512         [ $unused -eq 0 ] || "$unused locks are not cleared"
9513
9514         local nr=1000
9515         createmany -o $DIR/$tdir/f $nr ||
9516                 error "failed to create $nr files in $DIR/$tdir"
9517         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9518
9519         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
9520         do_facet mds1 $LCTL set_param fail_loc=0x327
9521         do_facet mds1 $LCTL set_param fail_val=500
9522         touch $DIR/$tdir/m
9523
9524         echo "sleep 10 seconds ..."
9525         sleep 10
9526         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
9527
9528         do_facet mds1 $LCTL set_param fail_loc=0
9529         do_facet mds1 $LCTL set_param fail_val=0
9530         [ $lck_cnt -lt $unused ] ||
9531                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
9532
9533         rm $DIR/$tdir/m
9534         unlinkmany $DIR/$tdir/f $nr
9535 }
9536 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
9537
9538 test_134b() {
9539         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
9540                 skip "Need MDS version at least 2.7.54" && return
9541
9542         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9543         cancel_lru_locks mdc
9544
9545         local low_wm=$(do_facet mds1 $LCTL get_param -n \
9546                         ldlm.lock_reclaim_threshold_mb)
9547         # disable reclaim temporarily
9548         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
9549
9550         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
9551         do_facet mds1 $LCTL set_param fail_loc=0x328
9552         do_facet mds1 $LCTL set_param fail_val=500
9553
9554         $LCTL set_param debug=+trace
9555
9556         local nr=600
9557         createmany -o $DIR/$tdir/f $nr &
9558         local create_pid=$!
9559
9560         echo "Sleep $TIMEOUT seconds ..."
9561         sleep $TIMEOUT
9562         if ! ps -p $create_pid  > /dev/null 2>&1; then
9563                 do_facet mds1 $LCTL set_param fail_loc=0
9564                 do_facet mds1 $LCTL set_param fail_val=0
9565                 do_facet mds1 $LCTL set_param \
9566                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
9567                 error "createmany finished incorrectly!"
9568         fi
9569         do_facet mds1 $LCTL set_param fail_loc=0
9570         do_facet mds1 $LCTL set_param fail_val=0
9571         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
9572         wait $create_pid || return 1
9573
9574         unlinkmany $DIR/$tdir/f $nr
9575 }
9576 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
9577
9578 test_140() { #bug-17379
9579         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9580         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
9581         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
9582         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
9583
9584         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9585         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9586         local i=0
9587         while i=`expr $i + 1`; do
9588                 test_mkdir -p $i || error "Creating dir $i"
9589                 cd $i || error "Changing to $i"
9590                 ln -s ../stat stat || error "Creating stat symlink"
9591                 # Read the symlink until ELOOP present,
9592                 # not LBUGing the system is considered success,
9593                 # we didn't overrun the stack.
9594                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9595                 [ $ret -ne 0 ] && {
9596                         if [ $ret -eq 40 ]; then
9597                                 break  # -ELOOP
9598                         else
9599                                 error "Open stat symlink"
9600                                 return
9601                         fi
9602                 }
9603         done
9604         i=`expr $i - 1`
9605         echo "The symlink depth = $i"
9606         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9607                                         error "Invalid symlink depth"
9608
9609         # Test recursive symlink
9610         ln -s symlink_self symlink_self
9611         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9612         echo "open symlink_self returns $ret"
9613         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9614 }
9615 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9616
9617 test_150() {
9618         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9619         local TF="$TMP/$tfile"
9620
9621         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9622         cp $TF $DIR/$tfile
9623         cancel_lru_locks osc
9624         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9625         remount_client $MOUNT
9626         df -P $MOUNT
9627         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9628
9629         $TRUNCATE $TF 6000
9630         $TRUNCATE $DIR/$tfile 6000
9631         cancel_lru_locks osc
9632         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9633
9634         echo "12345" >>$TF
9635         echo "12345" >>$DIR/$tfile
9636         cancel_lru_locks osc
9637         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9638
9639         echo "12345" >>$TF
9640         echo "12345" >>$DIR/$tfile
9641         cancel_lru_locks osc
9642         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9643
9644         rm -f $TF
9645         true
9646 }
9647 run_test 150 "truncate/append tests"
9648
9649 #LU-2902 roc_hit was not able to read all values from lproc
9650 function roc_hit_init() {
9651         local list=$(comma_list $(osts_nodes))
9652         local dir=$DIR/$tdir-check
9653         local file=$dir/file
9654         local BEFORE
9655         local AFTER
9656         local idx
9657
9658         test_mkdir -p $dir
9659         #use setstripe to do a write to every ost
9660         for i in $(seq 0 $((OSTCOUNT-1))); do
9661                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9662                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9663                 idx=$(printf %04x $i)
9664                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9665                         awk '$1 == "cache_access" {sum += $7}
9666                                 END { printf("%0.0f", sum) }')
9667
9668                 cancel_lru_locks osc
9669                 cat $file >/dev/null
9670
9671                 AFTER=$(get_osd_param $list *OST*$idx stats |
9672                         awk '$1 == "cache_access" {sum += $7}
9673                                 END { printf("%0.0f", sum) }')
9674
9675                 echo BEFORE:$BEFORE AFTER:$AFTER
9676                 if ! let "AFTER - BEFORE == 4"; then
9677                         rm -rf $dir
9678                         error "roc_hit is not safe to use"
9679                 fi
9680                 rm $file
9681         done
9682
9683         rm -rf $dir
9684 }
9685
9686 function roc_hit() {
9687         local list=$(comma_list $(osts_nodes))
9688         echo $(get_osd_param $list '' stats |
9689                 awk '$1 == "cache_hit" {sum += $7}
9690                         END { printf("%0.0f", sum) }')
9691 }
9692
9693 function set_cache() {
9694         local on=1
9695
9696         if [ "$2" == "off" ]; then
9697                 on=0;
9698         fi
9699         local list=$(comma_list $(osts_nodes))
9700         set_osd_param $list '' $1_cache_enable $on
9701
9702         cancel_lru_locks osc
9703 }
9704
9705 test_151() {
9706         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9707         remote_ost_nodsh && skip "remote OST with nodsh" && return
9708
9709         local CPAGES=3
9710         local list=$(comma_list $(osts_nodes))
9711
9712         # check whether obdfilter is cache capable at all
9713         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9714                 echo "not cache-capable obdfilter"
9715                 return 0
9716         fi
9717
9718         # check cache is enabled on all obdfilters
9719         if get_osd_param $list '' read_cache_enable | grep 0; then
9720                 echo "oss cache is disabled"
9721                 return 0
9722         fi
9723
9724         set_osd_param $list '' writethrough_cache_enable 1
9725
9726         # check write cache is enabled on all obdfilters
9727         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9728                 echo "oss write cache is NOT enabled"
9729                 return 0
9730         fi
9731
9732         roc_hit_init
9733
9734         #define OBD_FAIL_OBD_NO_LRU  0x609
9735         do_nodes $list $LCTL set_param fail_loc=0x609
9736
9737         # pages should be in the case right after write
9738         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9739                 error "dd failed"
9740
9741         local BEFORE=$(roc_hit)
9742         cancel_lru_locks osc
9743         cat $DIR/$tfile >/dev/null
9744         local AFTER=$(roc_hit)
9745
9746         do_nodes $list $LCTL set_param fail_loc=0
9747
9748         if ! let "AFTER - BEFORE == CPAGES"; then
9749                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9750         fi
9751
9752         # the following read invalidates the cache
9753         cancel_lru_locks osc
9754         set_osd_param $list '' read_cache_enable 0
9755         cat $DIR/$tfile >/dev/null
9756
9757         # now data shouldn't be found in the cache
9758         BEFORE=$(roc_hit)
9759         cancel_lru_locks osc
9760         cat $DIR/$tfile >/dev/null
9761         AFTER=$(roc_hit)
9762         if let "AFTER - BEFORE != 0"; then
9763                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9764         fi
9765
9766         set_osd_param $list '' read_cache_enable 1
9767         rm -f $DIR/$tfile
9768 }
9769 run_test 151 "test cache on oss and controls ==============================="
9770
9771 test_152() {
9772         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9773         local TF="$TMP/$tfile"
9774
9775         # simulate ENOMEM during write
9776 #define OBD_FAIL_OST_NOMEM      0x226
9777         lctl set_param fail_loc=0x80000226
9778         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9779         cp $TF $DIR/$tfile
9780         sync || error "sync failed"
9781         lctl set_param fail_loc=0
9782
9783         # discard client's cache
9784         cancel_lru_locks osc
9785
9786         # simulate ENOMEM during read
9787         lctl set_param fail_loc=0x80000226
9788         cmp $TF $DIR/$tfile || error "cmp failed"
9789         lctl set_param fail_loc=0
9790
9791         rm -f $TF
9792 }
9793 run_test 152 "test read/write with enomem ============================"
9794
9795 test_153() {
9796         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9797 }
9798 run_test 153 "test if fdatasync does not crash ======================="
9799
9800 dot_lustre_fid_permission_check() {
9801         local fid=$1
9802         local ffid=$MOUNT/.lustre/fid/$fid
9803         local test_dir=$2
9804
9805         echo "stat fid $fid"
9806         stat $ffid > /dev/null || error "stat $ffid failed."
9807         echo "touch fid $fid"
9808         touch $ffid || error "touch $ffid failed."
9809         echo "write to fid $fid"
9810         cat /etc/hosts > $ffid || error "write $ffid failed."
9811         echo "read fid $fid"
9812         diff /etc/hosts $ffid || error "read $ffid failed."
9813         echo "append write to fid $fid"
9814         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9815         echo "rename fid $fid"
9816         mv $ffid $test_dir/$tfile.1 &&
9817                 error "rename $ffid to $tfile.1 should fail."
9818         touch $test_dir/$tfile.1
9819         mv $test_dir/$tfile.1 $ffid &&
9820                 error "rename $tfile.1 to $ffid should fail."
9821         rm -f $test_dir/$tfile.1
9822         echo "truncate fid $fid"
9823         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9824         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9825                 echo "link fid $fid"
9826                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9827         fi
9828         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9829                 echo "setfacl fid $fid"
9830                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9831                 echo "getfacl fid $fid"
9832                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9833         fi
9834         echo "unlink fid $fid"
9835         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9836         echo "mknod fid $fid"
9837         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9838
9839         fid=[0xf00000400:0x1:0x0]
9840         ffid=$MOUNT/.lustre/fid/$fid
9841
9842         echo "stat non-exist fid $fid"
9843         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9844         echo "write to non-exist fid $fid"
9845         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9846         echo "link new fid $fid"
9847         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9848
9849         mkdir -p $test_dir/$tdir
9850         touch $test_dir/$tdir/$tfile
9851         fid=$($LFS path2fid $test_dir/$tdir)
9852         rc=$?
9853         [ $rc -ne 0 ] &&
9854                 error "error: could not get fid for $test_dir/$dir/$tfile."
9855
9856         ffid=$MOUNT/.lustre/fid/$fid
9857
9858         echo "ls $fid"
9859         ls $ffid > /dev/null || error "ls $ffid failed."
9860         echo "touch $fid/$tfile.1"
9861         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9862
9863         echo "touch $MOUNT/.lustre/fid/$tfile"
9864         touch $MOUNT/.lustre/fid/$tfile && \
9865                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9866
9867         echo "setxattr to $MOUNT/.lustre/fid"
9868         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9869
9870         echo "listxattr for $MOUNT/.lustre/fid"
9871         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9872
9873         echo "delxattr from $MOUNT/.lustre/fid"
9874         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9875
9876         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9877         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9878                 error "touch invalid fid should fail."
9879
9880         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9881         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9882                 error "touch non-normal fid should fail."
9883
9884         echo "rename $tdir to $MOUNT/.lustre/fid"
9885         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9886                 error "rename to $MOUNT/.lustre/fid should fail."
9887
9888         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9889         then            # LU-3547
9890                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9891                 local new_obf_mode=777
9892
9893                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9894                 chmod $new_obf_mode $DIR/.lustre/fid ||
9895                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9896
9897                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9898                 [ $obf_mode -eq $new_obf_mode ] ||
9899                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9900
9901                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9902                 chmod $old_obf_mode $DIR/.lustre/fid ||
9903                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9904         fi
9905
9906         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9907         fid=$($LFS path2fid $test_dir/$tfile-2)
9908
9909         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
9910         then # LU-5424
9911                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9912                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
9913                         error "create lov data thru .lustre failed"
9914         fi
9915         echo "cp /etc/passwd $test_dir/$tfile-2"
9916         cp /etc/passwd $test_dir/$tfile-2 ||
9917                 error "copy to $test_dir/$tfile-2 failed."
9918         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9919         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9920                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9921
9922         rm -rf $test_dir/tfile.lnk
9923         rm -rf $test_dir/$tfile-2
9924 }
9925
9926 test_154A() {
9927         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9928                 skip "Need MDS version at least 2.4.1" && return
9929
9930         touch $DIR/$tfile
9931         local FID=$($LFS path2fid $DIR/$tfile)
9932         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9933
9934         # check that we get the same pathname back
9935         local FOUND=$($LFS fid2path $MOUNT "$FID")
9936         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9937         [ "$FOUND" != "$DIR/$tfile" ] &&
9938                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9939
9940         rm -rf $DIR/$tfile
9941 }
9942 run_test 154A "lfs path2fid and fid2path basic checks"
9943
9944 test_154a() {
9945         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9946         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9947                 { skip "Need MDS version at least 2.2.51"; return 0; }
9948         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9949         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
9950
9951         cp /etc/hosts $DIR/$tfile
9952
9953         fid=$($LFS path2fid $DIR/$tfile)
9954         rc=$?
9955         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9956
9957         dot_lustre_fid_permission_check "$fid" $DIR ||
9958                 error "dot lustre permission check $fid failed"
9959
9960         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9961
9962         touch $MOUNT/.lustre/file &&
9963                 error "creation is not allowed under .lustre"
9964
9965         mkdir $MOUNT/.lustre/dir &&
9966                 error "mkdir is not allowed under .lustre"
9967
9968         rm -rf $DIR/$tfile
9969 }
9970 run_test 154a "Open-by-FID"
9971
9972 test_154b() {
9973         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9974         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9975                 { skip "Need MDS version at least 2.2.51"; return 0; }
9976         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
9977
9978         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9979
9980         local remote_dir=$DIR/$tdir/remote_dir
9981         local MDTIDX=1
9982         local rc=0
9983
9984         mkdir -p $DIR/$tdir
9985         $LFS mkdir -i $MDTIDX $remote_dir ||
9986                 error "create remote directory failed"
9987
9988         cp /etc/hosts $remote_dir/$tfile
9989
9990         fid=$($LFS path2fid $remote_dir/$tfile)
9991         rc=$?
9992         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9993
9994         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9995                 error "dot lustre permission check $fid failed"
9996         rm -rf $DIR/$tdir
9997 }
9998 run_test 154b "Open-by-FID for remote directory"
9999
10000 test_154c() {
10001         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10002                 skip "Need MDS version at least 2.4.1" && return
10003
10004         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
10005         local FID1=$($LFS path2fid $DIR/$tfile.1)
10006         local FID2=$($LFS path2fid $DIR/$tfile.2)
10007         local FID3=$($LFS path2fid $DIR/$tfile.3)
10008
10009         local N=1
10010         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
10011                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
10012                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
10013                 local want=FID$N
10014                 [ "$FID" = "${!want}" ] ||
10015                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
10016                 N=$((N + 1))
10017         done
10018
10019         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
10020         do
10021                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
10022                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
10023                 N=$((N + 1))
10024         done
10025 }
10026 run_test 154c "lfs path2fid and fid2path multiple arguments"
10027
10028 test_154d() {
10029         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
10030                 skip "Need MDS version at least 2.5.53" && return
10031
10032         if remote_mds; then
10033                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
10034         else
10035                 nid="0@lo"
10036         fi
10037         local proc_ofile="mdt.*.exports.'$nid'.open_files"
10038         local fd
10039         local cmd
10040
10041         rm -f $DIR/$tfile
10042         touch $DIR/$tfile
10043
10044         local fid=$($LFS path2fid $DIR/$tfile)
10045         # Open the file
10046         fd=$(free_fd)
10047         cmd="exec $fd<$DIR/$tfile"
10048         eval $cmd
10049         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
10050         echo "$fid_list" | grep "$fid"
10051         rc=$?
10052
10053         cmd="exec $fd>/dev/null"
10054         eval $cmd
10055         if [ $rc -ne 0 ]; then
10056                 error "FID $fid not found in open files list $fid_list"
10057         fi
10058 }
10059 run_test 154d "Verify open file fid"
10060
10061 test_154e()
10062 {
10063         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
10064                 skip "Need MDS version at least 2.6.50" && return
10065
10066         if ls -a $MOUNT | grep -q '^\.lustre$'; then
10067                 error ".lustre returned by readdir"
10068         fi
10069 }
10070 run_test 154e ".lustre is not returned by readdir"
10071
10072 test_154f() {
10073         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10074         # create parent directory on a single MDT to avoid cross-MDT hardlinks
10075         test_mkdir -p -c1 $DIR/$tdir/d
10076         # test dirs inherit from its stripe
10077         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
10078         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
10079         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
10080         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
10081         touch $DIR/f
10082
10083         # get fid of parents
10084         local FID0=$($LFS path2fid $DIR/$tdir/d)
10085         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
10086         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
10087         local FID3=$($LFS path2fid $DIR)
10088
10089         # check that path2fid --parents returns expected <parent_fid>/name
10090         # 1) test for a directory (single parent)
10091         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
10092         [ "$parent" == "$FID0/foo1" ] ||
10093                 error "expected parent: $FID0/foo1, got: $parent"
10094
10095         # 2) test for a file with nlink > 1 (multiple parents)
10096         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
10097         echo "$parent" | grep -F "$FID1/$tfile" ||
10098                 error "$FID1/$tfile not returned in parent list"
10099         echo "$parent" | grep -F "$FID2/link" ||
10100                 error "$FID2/link not returned in parent list"
10101
10102         # 3) get parent by fid
10103         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
10104         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10105         echo "$parent" | grep -F "$FID1/$tfile" ||
10106                 error "$FID1/$tfile not returned in parent list (by fid)"
10107         echo "$parent" | grep -F "$FID2/link" ||
10108                 error "$FID2/link not returned in parent list (by fid)"
10109
10110         # 4) test for entry in root directory
10111         parent=$($LFS path2fid --parents $DIR/f)
10112         echo "$parent" | grep -F "$FID3/f" ||
10113                 error "$FID3/f not returned in parent list"
10114
10115         # 5) test it on root directory
10116         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
10117                 error "$MOUNT should not have parents"
10118
10119         # enable xattr caching and check that linkea is correctly updated
10120         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
10121         save_lustre_params client "llite.*.xattr_cache" > $save
10122         lctl set_param llite.*.xattr_cache 1
10123
10124         # 6.1) linkea update on rename
10125         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
10126
10127         # get parents by fid
10128         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10129         # foo1 should no longer be returned in parent list
10130         echo "$parent" | grep -F "$FID1" &&
10131                 error "$FID1 should no longer be in parent list"
10132         # the new path should appear
10133         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
10134                 error "$FID2/$tfile.moved is not in parent list"
10135
10136         # 6.2) linkea update on unlink
10137         rm -f $DIR/$tdir/d/foo2/link
10138         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10139         # foo2/link should no longer be returned in parent list
10140         echo "$parent" | grep -F "$FID2/link" &&
10141                 error "$FID2/link should no longer be in parent list"
10142         true
10143
10144         rm -f $DIR/f
10145         restore_lustre_params < $save
10146 }
10147 run_test 154f "get parent fids by reading link ea"
10148
10149 test_154g()
10150 {
10151         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) ]] ||
10152                 { skip "Need MDS version at least 2.6.92"; return 0; }
10153         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10154
10155         mkdir -p $DIR/$tdir
10156         llapi_fid_test -d $DIR/$tdir
10157 }
10158 run_test 154g "various llapi FID tests"
10159
10160 test_155_small_load() {
10161     local temp=$TMP/$tfile
10162     local file=$DIR/$tfile
10163
10164     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
10165         error "dd of=$temp bs=6096 count=1 failed"
10166     cp $temp $file
10167     cancel_lru_locks osc
10168     cmp $temp $file || error "$temp $file differ"
10169
10170     $TRUNCATE $temp 6000
10171     $TRUNCATE $file 6000
10172     cmp $temp $file || error "$temp $file differ (truncate1)"
10173
10174     echo "12345" >>$temp
10175     echo "12345" >>$file
10176     cmp $temp $file || error "$temp $file differ (append1)"
10177
10178     echo "12345" >>$temp
10179     echo "12345" >>$file
10180     cmp $temp $file || error "$temp $file differ (append2)"
10181
10182     rm -f $temp $file
10183     true
10184 }
10185
10186 test_155_big_load() {
10187     remote_ost_nodsh && skip "remote OST with nodsh" && return
10188     local temp=$TMP/$tfile
10189     local file=$DIR/$tfile
10190
10191     free_min_max
10192     local cache_size=$(do_facet ost$((MAXI+1)) \
10193         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
10194     local large_file_size=$((cache_size * 2))
10195
10196     echo "OSS cache size: $cache_size KB"
10197     echo "Large file size: $large_file_size KB"
10198
10199     [ $MAXV -le $large_file_size ] && \
10200         skip_env "max available OST size needs > $large_file_size KB" && \
10201         return 0
10202
10203     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
10204
10205     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
10206         error "dd of=$temp bs=$large_file_size count=1k failed"
10207     cp $temp $file
10208     ls -lh $temp $file
10209     cancel_lru_locks osc
10210     cmp $temp $file || error "$temp $file differ"
10211
10212     rm -f $temp $file
10213     true
10214 }
10215
10216 test_155a() {
10217         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10218         set_cache read on
10219         set_cache writethrough on
10220         test_155_small_load
10221 }
10222 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
10223
10224 test_155b() {
10225         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10226         set_cache read on
10227         set_cache writethrough off
10228         test_155_small_load
10229 }
10230 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
10231
10232 test_155c() {
10233         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10234         set_cache read off
10235         set_cache writethrough on
10236         test_155_small_load
10237 }
10238 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
10239
10240 test_155d() {
10241         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10242         set_cache read off
10243         set_cache writethrough off
10244         test_155_small_load
10245 }
10246 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
10247
10248 test_155e() {
10249         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10250         set_cache read on
10251         set_cache writethrough on
10252         test_155_big_load
10253 }
10254 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
10255
10256 test_155f() {
10257         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10258         set_cache read on
10259         set_cache writethrough off
10260         test_155_big_load
10261 }
10262 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
10263
10264 test_155g() {
10265         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10266         set_cache read off
10267         set_cache writethrough on
10268         test_155_big_load
10269 }
10270 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
10271
10272 test_155h() {
10273         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10274         set_cache read off
10275         set_cache writethrough off
10276         test_155_big_load
10277 }
10278 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
10279
10280 test_156() {
10281         remote_ost_nodsh && skip "remote OST with nodsh" && return
10282         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10283         local CPAGES=3
10284         local BEFORE
10285         local AFTER
10286         local file="$DIR/$tfile"
10287
10288         [ "$(facet_fstype ost1)" = "zfs" -a \
10289            $(lustre_version_code ost1 -lt $(version_code 2.6.93)) ] &&
10290                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS" &&
10291                 return
10292
10293         roc_hit_init
10294
10295         log "Turn on read and write cache"
10296         set_cache read on
10297         set_cache writethrough on
10298
10299         log "Write data and read it back."
10300         log "Read should be satisfied from the cache."
10301         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10302         BEFORE=$(roc_hit)
10303         cancel_lru_locks osc
10304         cat $file >/dev/null
10305         AFTER=$(roc_hit)
10306         if ! let "AFTER - BEFORE == CPAGES"; then
10307                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10308         else
10309                 log "cache hits:: before: $BEFORE, after: $AFTER"
10310         fi
10311
10312         log "Read again; it should be satisfied from the cache."
10313         BEFORE=$AFTER
10314         cancel_lru_locks osc
10315         cat $file >/dev/null
10316         AFTER=$(roc_hit)
10317         if ! let "AFTER - BEFORE == CPAGES"; then
10318                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10319         else
10320                 log "cache hits:: before: $BEFORE, after: $AFTER"
10321         fi
10322
10323         log "Turn off the read cache and turn on the write cache"
10324         set_cache read off
10325         set_cache writethrough on
10326
10327         log "Read again; it should be satisfied from the cache."
10328         BEFORE=$(roc_hit)
10329         cancel_lru_locks osc
10330         cat $file >/dev/null
10331         AFTER=$(roc_hit)
10332         if ! let "AFTER - BEFORE == CPAGES"; then
10333                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10334         else
10335                 log "cache hits:: before: $BEFORE, after: $AFTER"
10336         fi
10337
10338         log "Read again; it should not be satisfied from the cache."
10339         BEFORE=$AFTER
10340         cancel_lru_locks osc
10341         cat $file >/dev/null
10342         AFTER=$(roc_hit)
10343         if ! let "AFTER - BEFORE == 0"; then
10344                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10345         else
10346                 log "cache hits:: before: $BEFORE, after: $AFTER"
10347         fi
10348
10349         log "Write data and read it back."
10350         log "Read should be satisfied from the cache."
10351         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10352         BEFORE=$(roc_hit)
10353         cancel_lru_locks osc
10354         cat $file >/dev/null
10355         AFTER=$(roc_hit)
10356         if ! let "AFTER - BEFORE == CPAGES"; then
10357                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10358         else
10359                 log "cache hits:: before: $BEFORE, after: $AFTER"
10360         fi
10361
10362         log "Read again; it should not be satisfied from the cache."
10363         BEFORE=$AFTER
10364         cancel_lru_locks osc
10365         cat $file >/dev/null
10366         AFTER=$(roc_hit)
10367         if ! let "AFTER - BEFORE == 0"; then
10368                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10369         else
10370                 log "cache hits:: before: $BEFORE, after: $AFTER"
10371         fi
10372
10373         log "Turn off read and write cache"
10374         set_cache read off
10375         set_cache writethrough off
10376
10377         log "Write data and read it back"
10378         log "It should not be satisfied from the cache."
10379         rm -f $file
10380         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10381         cancel_lru_locks osc
10382         BEFORE=$(roc_hit)
10383         cat $file >/dev/null
10384         AFTER=$(roc_hit)
10385         if ! let "AFTER - BEFORE == 0"; then
10386                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10387         else
10388                 log "cache hits:: before: $BEFORE, after: $AFTER"
10389         fi
10390
10391         log "Turn on the read cache and turn off the write cache"
10392         set_cache read on
10393         set_cache writethrough off
10394
10395         log "Write data and read it back"
10396         log "It should not be satisfied from the cache."
10397         rm -f $file
10398         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10399         BEFORE=$(roc_hit)
10400         cancel_lru_locks osc
10401         cat $file >/dev/null
10402         AFTER=$(roc_hit)
10403         if ! let "AFTER - BEFORE == 0"; then
10404                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10405         else
10406                 log "cache hits:: before: $BEFORE, after: $AFTER"
10407         fi
10408
10409         log "Read again; it should be satisfied from the cache."
10410         BEFORE=$(roc_hit)
10411         cancel_lru_locks osc
10412         cat $file >/dev/null
10413         AFTER=$(roc_hit)
10414         if ! let "AFTER - BEFORE == CPAGES"; then
10415                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10416         else
10417                 log "cache hits:: before: $BEFORE, after: $AFTER"
10418         fi
10419
10420         rm -f $file
10421 }
10422 run_test 156 "Verification of tunables"
10423
10424 #Changelogs
10425 err17935 () {
10426         if [[ $MDSCOUNT -gt 1 ]]; then
10427                 error_ignore bz17935 $*
10428         else
10429                 error $*
10430         fi
10431 }
10432
10433 changelog_chmask()
10434 {
10435         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10436
10437         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
10438
10439         if [ $MASK -eq 1 ]; then
10440                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
10441         else
10442                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
10443         fi
10444 }
10445
10446 changelog_extract_field() {
10447         local mdt=$1
10448         local cltype=$2
10449         local file=$3
10450         local identifier=$4
10451
10452         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
10453                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10454                 tail -1
10455 }
10456
10457 test_160a() {
10458         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10459         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10460         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10461                 { skip "Need MDS version at least 2.2.0"; return; }
10462
10463         local CL_USERS="mdd.$MDT0.changelog_users"
10464         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10465         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10466         echo "Registered as changelog user $USER"
10467         $GET_CL_USERS | grep -q $USER ||
10468                 error "User $USER not found in changelog_users"
10469
10470         # change something
10471         test_mkdir -p $DIR/$tdir/pics/2008/zachy
10472         touch $DIR/$tdir/pics/2008/zachy/timestamp
10473         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
10474         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
10475         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
10476         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
10477         rm $DIR/$tdir/pics/desktop.jpg
10478
10479         $LFS changelog $MDT0 | tail -5
10480
10481         echo "verifying changelog mask"
10482         changelog_chmask "MKDIR"
10483         changelog_chmask "CLOSE"
10484
10485         test_mkdir -p $DIR/$tdir/pics/zach/sofia
10486         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10487
10488         changelog_chmask "MKDIR"
10489         changelog_chmask "CLOSE"
10490
10491         test_mkdir -p $DIR/$tdir/pics/2008/sofia
10492         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10493
10494         $LFS changelog $MDT0
10495         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
10496         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
10497         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
10498         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
10499
10500         # verify contents
10501         echo "verifying target fid"
10502         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
10503         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
10504         [ "$fidc" == "$fidf" ] ||
10505                 err17935 "fid in changelog $fidc != file fid $fidf"
10506         echo "verifying parent fid"
10507         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
10508         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
10509         [ "$fidc" == "$fidf" ] ||
10510                 err17935 "pfid in changelog $fidc != dir fid $fidf"
10511
10512         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10513         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
10514         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10515         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
10516         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
10517                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
10518
10519         MIN_REC=$($GET_CL_USERS |
10520                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
10521         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
10522         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
10523         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
10524                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
10525
10526         # LU-3446 changelog index reset on MDT restart
10527         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10528         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10529         $LFS changelog_clear $MDT0 $USER 0
10530         stop $SINGLEMDS || error "Fail to stop MDT."
10531         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10532         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10533         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
10534         [ $CUR_REC1 == $CUR_REC2 ] ||
10535                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
10536
10537         echo "verifying user deregister"
10538         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10539         $GET_CL_USERS | grep -q $USER &&
10540                 error "User $USER still in changelog_users"
10541
10542         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
10543         if [ $USERS -eq 0 ]; then
10544                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10545                 touch $DIR/$tdir/chloe
10546                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10547                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
10548                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
10549         else
10550                 echo "$USERS other changelog users; can't verify off"
10551         fi
10552 }
10553 run_test 160a "changelog sanity"
10554
10555 test_160b() { # LU-3587
10556         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10557         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10558         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10559                 { skip "Need MDS version at least 2.2.0"; return; }
10560
10561         local CL_USERS="mdd.$MDT0.changelog_users"
10562         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10563         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10564         echo "Registered as changelog user $USER"
10565         $GET_CL_USERS | grep -q $USER ||
10566                 error "User $USER not found in changelog_users"
10567
10568         local LONGNAME1=$(str_repeat a 255)
10569         local LONGNAME2=$(str_repeat b 255)
10570
10571         cd $DIR
10572         echo "creating very long named file"
10573         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
10574         echo "moving very long named file"
10575         mv $LONGNAME1 $LONGNAME2
10576
10577         $LFS changelog $MDT0 | grep RENME
10578
10579         echo "deregistering $USER"
10580         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10581
10582         rm -f $LONGNAME2
10583 }
10584 run_test 160b "Verify that very long rename doesn't crash in changelog"
10585
10586 test_160c() {
10587         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10588
10589         local rc=0
10590         local server_version=$(lustre_version_code $SINGLEMDS)
10591
10592         [[ $server_version -gt $(version_code 2.5.57) ]] ||
10593                 [[ $server_version -gt $(version_code 2.5.1) &&
10594                    $server_version -lt $(version_code 2.5.50) ]] ||
10595                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
10596         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10597
10598         # Registration step
10599         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10600                 changelog_register -n)
10601
10602         rm -rf $DIR/$tdir
10603         mkdir -p $DIR/$tdir
10604         $MCREATE $DIR/$tdir/foo_160c
10605         changelog_chmask "TRUNC"
10606         $TRUNCATE $DIR/$tdir/foo_160c 200
10607         changelog_chmask "TRUNC"
10608         $TRUNCATE $DIR/$tdir/foo_160c 199
10609         $LFS changelog $MDT0
10610         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
10611         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
10612         $LFS changelog_clear $MDT0 $USER 0
10613
10614         # Deregistration step
10615         echo "deregistering $USER"
10616         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10617 }
10618 run_test 160c "verify that changelog log catch the truncate event"
10619
10620 test_160d() {
10621         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10622         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10623
10624         local server_version=$(lustre_version_code mds1)
10625         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10626
10627         [[ $server_version -ge $(version_code 2.7.60) ]] ||
10628                 { skip "Need MDS version at least 2.7.60+"; return; }
10629         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10630
10631         # Registration step
10632         local USER=$(do_facet mds1 $LCTL --device $MDT0 \
10633                 changelog_register -n)
10634
10635         mkdir -p $DIR/$tdir/migrate_dir
10636         $LFS changelog_clear $MDT0 $USER 0
10637
10638         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
10639         $LFS changelog $MDT0
10640         MIGRATES=$($LFS changelog $MDT0 | tail -5 | grep -c "MIGRT")
10641         $LFS changelog_clear $MDT0 $USER 0
10642         [ $MIGRATES -eq 1 ] ||
10643                 error "MIGRATE changelog mask count $MIGRATES != 1"
10644
10645         # Deregistration step
10646         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $USER
10647 }
10648 run_test 160d "verify that changelog log catch the migrate event"
10649
10650 test_161a() {
10651         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10652         test_mkdir -p -c1 $DIR/$tdir
10653         cp /etc/hosts $DIR/$tdir/$tfile
10654         test_mkdir -c1 $DIR/$tdir/foo1
10655         test_mkdir -c1 $DIR/$tdir/foo2
10656         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
10657         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
10658         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
10659         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
10660         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
10661         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10662                 $LFS fid2path $DIR $FID
10663                 err17935 "bad link ea"
10664         fi
10665     # middle
10666     rm $DIR/$tdir/foo2/zachary
10667     # last
10668     rm $DIR/$tdir/foo2/thor
10669     # first
10670     rm $DIR/$tdir/$tfile
10671     # rename
10672     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
10673     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
10674         then
10675         $LFS fid2path $DIR $FID
10676         err17935 "bad link rename"
10677     fi
10678     rm $DIR/$tdir/foo2/maggie
10679
10680         # overflow the EA
10681         local longname=filename_avg_len_is_thirty_two_
10682         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
10683                 error "failed to hardlink many files"
10684         links=$($LFS fid2path $DIR $FID | wc -l)
10685         echo -n "${links}/1000 links in link EA"
10686         [[ $links -gt 60 ]] ||
10687                 err17935 "expected at least 60 links in link EA"
10688         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
10689                 error "failed to unlink many hardlinks"
10690 }
10691 run_test 161a "link ea sanity"
10692
10693 test_161b() {
10694         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10695         [ $MDSCOUNT -lt 2 ] &&
10696                 skip "skipping remote directory test" && return
10697         local MDTIDX=1
10698         local remote_dir=$DIR/$tdir/remote_dir
10699
10700         mkdir -p $DIR/$tdir
10701         $LFS mkdir -i $MDTIDX $remote_dir ||
10702                 error "create remote directory failed"
10703
10704         cp /etc/hosts $remote_dir/$tfile
10705         mkdir -p $remote_dir/foo1
10706         mkdir -p $remote_dir/foo2
10707         ln $remote_dir/$tfile $remote_dir/foo1/sofia
10708         ln $remote_dir/$tfile $remote_dir/foo2/zachary
10709         ln $remote_dir/$tfile $remote_dir/foo1/luna
10710         ln $remote_dir/$tfile $remote_dir/foo2/thor
10711
10712         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
10713                      tr -d ']')
10714         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10715                 $LFS fid2path $DIR $FID
10716                 err17935 "bad link ea"
10717         fi
10718         # middle
10719         rm $remote_dir/foo2/zachary
10720         # last
10721         rm $remote_dir/foo2/thor
10722         # first
10723         rm $remote_dir/$tfile
10724         # rename
10725         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
10726         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
10727         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
10728                 $LFS fid2path $DIR $FID
10729                 err17935 "bad link rename"
10730         fi
10731         rm $remote_dir/foo2/maggie
10732
10733         # overflow the EA
10734         local longname=filename_avg_len_is_thirty_two_
10735         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10736                 error "failed to hardlink many files"
10737         links=$($LFS fid2path $DIR $FID | wc -l)
10738         echo -n "${links}/1000 links in link EA"
10739         [[ ${links} -gt 60 ]] ||
10740                 err17935 "expected at least 60 links in link EA"
10741         unlinkmany $remote_dir/foo2/$longname 1000 ||
10742         error "failed to unlink many hardlinks"
10743 }
10744 run_test 161b "link ea sanity under remote directory"
10745
10746 test_161c() {
10747         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10748         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10749         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10750                 skip "Need MDS version at least 2.1.5" && return
10751
10752         # define CLF_RENAME_LAST 0x0001
10753         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10754         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10755                 changelog_register -n)
10756         rm -rf $DIR/$tdir
10757         mkdir -p $DIR/$tdir
10758         touch $DIR/$tdir/foo_161c
10759         touch $DIR/$tdir/bar_161c
10760         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10761         $LFS changelog $MDT0 | grep RENME
10762         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10763                 cut -f5 -d' ')
10764         $LFS changelog_clear $MDT0 $USER 0
10765         if [ x$flags != "x0x1" ]; then
10766                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10767                         $USER
10768                 error "flag $flags is not 0x1"
10769         fi
10770         echo "rename overwrite a target having nlink = 1," \
10771                 "changelog record has flags of $flags"
10772
10773         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10774         touch $DIR/$tdir/foo_161c
10775         touch $DIR/$tdir/bar_161c
10776         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10777         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10778         $LFS changelog $MDT0 | grep RENME
10779         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10780         $LFS changelog_clear $MDT0 $USER 0
10781         if [ x$flags != "x0x0" ]; then
10782                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10783                         $USER
10784                 error "flag $flags is not 0x0"
10785         fi
10786         echo "rename overwrite a target having nlink > 1," \
10787                 "changelog record has flags of $flags"
10788
10789         # rename doesn't overwrite a target (changelog flag 0x0)
10790         touch $DIR/$tdir/foo_161c
10791         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10792         $LFS changelog $MDT0 | grep RENME
10793         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10794         $LFS changelog_clear $MDT0 $USER 0
10795         if [ x$flags != "x0x0" ]; then
10796                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10797                         $USER
10798                 error "flag $flags is not 0x0"
10799         fi
10800         echo "rename doesn't overwrite a target," \
10801                 "changelog record has flags of $flags"
10802
10803         # define CLF_UNLINK_LAST 0x0001
10804         # unlink a file having nlink = 1 (changelog flag 0x1)
10805         rm -f $DIR/$tdir/foo2_161c
10806         $LFS changelog $MDT0 | grep UNLNK
10807         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10808         $LFS changelog_clear $MDT0 $USER 0
10809         if [ x$flags != "x0x1" ]; then
10810                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10811                         $USER
10812                 error "flag $flags is not 0x1"
10813         fi
10814         echo "unlink a file having nlink = 1," \
10815                 "changelog record has flags of $flags"
10816
10817         # unlink a file having nlink > 1 (changelog flag 0x0)
10818         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10819         rm -f $DIR/$tdir/foobar_161c
10820         $LFS changelog $MDT0 | grep UNLNK
10821         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10822         $LFS changelog_clear $MDT0 $USER 0
10823         if [ x$flags != "x0x0" ]; then
10824                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10825                         $USER
10826                 error "flag $flags is not 0x0"
10827         fi
10828         echo "unlink a file having nlink > 1," \
10829                 "changelog record has flags of $flags"
10830         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10831 }
10832 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10833
10834 check_path() {
10835     local expected=$1
10836     shift
10837     local fid=$2
10838
10839     local path=$(${LFS} fid2path $*)
10840     # Remove the '//' indicating a remote directory
10841     path=$(echo $path | sed 's#//#/#g')
10842     RC=$?
10843
10844     if [ $RC -ne 0 ]; then
10845         err17935 "path looked up of $expected failed. Error $RC"
10846         return $RC
10847     elif [ "${path}" != "${expected}" ]; then
10848         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10849         return 2
10850     fi
10851     echo "fid $fid resolves to path $path (expected $expected)"
10852 }
10853
10854 test_162a() { # was test_162
10855         # Make changes to filesystem
10856         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10857         test_mkdir -p -c1 $DIR/$tdir/d2
10858         touch $DIR/$tdir/d2/$tfile
10859         touch $DIR/$tdir/d2/x1
10860         touch $DIR/$tdir/d2/x2
10861         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
10862         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
10863         # regular file
10864         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10865         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
10866                 error "check path $tdir/d2/$tfile failed"
10867
10868         # softlink
10869         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10870         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10871         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
10872                 error "check path $tdir/d2/p/q/r/slink failed"
10873
10874         # softlink to wrong file
10875         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10876         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10877         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
10878                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
10879
10880         # hardlink
10881         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10882         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10883         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10884         # fid2path dir/fsname should both work
10885         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
10886                 error "check path $tdir/d2/a/b/c/new_file failed"
10887         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
10888                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
10889
10890         # hardlink count: check that there are 2 links
10891         # Doesnt work with CMD yet: 17935
10892         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10893                 err17935 "expected 2 links"
10894
10895         # hardlink indexing: remove the first link
10896         rm $DIR/$tdir/d2/p/q/r/hlink
10897         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
10898                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
10899
10900         return 0
10901 }
10902 run_test 162a "path lookup sanity"
10903
10904 test_162b() {
10905         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10906         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10907
10908         mkdir $DIR/$tdir
10909         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
10910                                 error "create striped dir failed"
10911
10912         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
10913                                         tail -n 1 | awk '{print $2}')
10914         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
10915
10916         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
10917         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
10918
10919         # regular file
10920         for ((i=0;i<5;i++)); do
10921                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
10922                         error "get fid for f$i failed"
10923                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
10924                         error "check path $tdir/striped_dir/f$i failed"
10925
10926                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
10927                         error "get fid for d$i failed"
10928                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
10929                         error "check path $tdir/striped_dir/d$i failed"
10930         done
10931
10932         return 0
10933 }
10934 run_test 162b "striped directory path lookup sanity"
10935
10936 # LU-4239: Verify fid2path works with paths 100 or more directories deep
10937 test_162c() {
10938         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.51) ]] &&
10939                 skip "Need MDS version at least 2.7.51" && return
10940         test_mkdir $DIR/$tdir.local
10941         test_mkdir $DIR/$tdir.remote
10942         local lpath=$tdir.local
10943         local rpath=$tdir.remote
10944
10945         for ((i = 0; i <= 101; i++)); do
10946                 lpath="$lpath/$i"
10947                 mkdir $DIR/$lpath
10948                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
10949                         error "get fid for local directory $DIR/$lpath failed"
10950                 check_path "$DIR/$lpath" $MOUNT $FID --link 0 ||
10951                         error "check path for local directory $DIR/$lpath failed"
10952
10953                 rpath="$rpath/$i"
10954                 test_mkdir $DIR/$rpath
10955                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
10956                         error "get fid for remote directory $DIR/$rpath failed"
10957                 check_path "$DIR/$rpath" $MOUNT $FID --link 0 ||
10958                         error "check path for remote directory $DIR/$rpath failed"
10959         done
10960
10961         return 0
10962 }
10963 run_test 162c "fid2path works with paths 100 or more directories deep"
10964
10965 test_169() {
10966         # do directio so as not to populate the page cache
10967         log "creating a 10 Mb file"
10968         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10969         log "starting reads"
10970         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10971         log "truncating the file"
10972         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10973         log "killing dd"
10974         kill %+ || true # reads might have finished
10975         echo "wait until dd is finished"
10976         wait
10977         log "removing the temporary file"
10978         rm -rf $DIR/$tfile || error "tmp file removal failed"
10979 }
10980 run_test 169 "parallel read and truncate should not deadlock"
10981
10982 test_170() {
10983         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10984         $LCTL clear     # bug 18514
10985         $LCTL debug_daemon start $TMP/${tfile}_log_good
10986         touch $DIR/$tfile
10987         $LCTL debug_daemon stop
10988         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10989                error "sed failed to read log_good"
10990
10991         $LCTL debug_daemon start $TMP/${tfile}_log_good
10992         rm -rf $DIR/$tfile
10993         $LCTL debug_daemon stop
10994
10995         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10996                error "lctl df log_bad failed"
10997
10998         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10999         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
11000
11001         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
11002         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
11003
11004         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
11005                 error "bad_line good_line1 good_line2 are empty"
11006
11007         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11008         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
11009         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11010
11011         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
11012         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
11013         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
11014
11015         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
11016                 error "bad_line_new good_line_new are empty"
11017
11018         local expected_good=$((good_line1 + good_line2*2))
11019
11020         rm -f $TMP/${tfile}*
11021         # LU-231, short malformed line may not be counted into bad lines
11022         if [ $bad_line -ne $bad_line_new ] &&
11023                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
11024                 error "expected $bad_line bad lines, but got $bad_line_new"
11025                 return 1
11026         fi
11027
11028         if [ $expected_good -ne $good_line_new ]; then
11029                 error "expected $expected_good good lines, but got $good_line_new"
11030                 return 2
11031         fi
11032         true
11033 }
11034 run_test 170 "test lctl df to handle corrupted log ====================="
11035
11036 test_171() { # bug20592
11037         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11038 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
11039         $LCTL set_param fail_loc=0x50e
11040         $LCTL set_param fail_val=3000
11041         multiop_bg_pause $DIR/$tfile O_s || true
11042         local MULTIPID=$!
11043         kill -USR1 $MULTIPID
11044         # cause log dump
11045         sleep 3
11046         wait $MULTIPID
11047         if dmesg | grep "recursive fault"; then
11048                 error "caught a recursive fault"
11049         fi
11050         $LCTL set_param fail_loc=0
11051         true
11052 }
11053 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
11054
11055 # it would be good to share it with obdfilter-survey/iokit-libecho code
11056 setup_obdecho_osc () {
11057         local rc=0
11058         local ost_nid=$1
11059         local obdfilter_name=$2
11060         echo "Creating new osc for $obdfilter_name on $ost_nid"
11061         # make sure we can find loopback nid
11062         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
11063
11064         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
11065                            ${obdfilter_name}_osc_UUID || rc=2; }
11066         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
11067                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
11068         return $rc
11069 }
11070
11071 cleanup_obdecho_osc () {
11072         local obdfilter_name=$1
11073         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
11074         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
11075         return 0
11076 }
11077
11078 obdecho_test() {
11079         local OBD=$1
11080         local node=$2
11081         local pages=${3:-64}
11082         local rc=0
11083         local id
11084
11085         local count=10
11086         local obd_size=$(get_obd_size $node $OBD)
11087         local page_size=$(get_page_size $node)
11088         if [[ -n "$obd_size" ]]; then
11089                 local new_count=$((obd_size / (pages * page_size / 1024)))
11090                 [[ $new_count -ge $count ]] || count=$new_count
11091         fi
11092
11093         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
11094         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
11095                            rc=2; }
11096         if [ $rc -eq 0 ]; then
11097             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
11098             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
11099         fi
11100         echo "New object id is $id"
11101         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
11102                            rc=4; }
11103         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
11104                            "test_brw $count w v $pages $id" || rc=4; }
11105         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
11106                            rc=4; }
11107         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
11108                                         "cleanup" || rc=5; }
11109         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
11110                                         "detach" || rc=6; }
11111         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
11112         return $rc
11113 }
11114
11115 test_180a() {
11116         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11117         remote_ost_nodsh && skip "remote OST with nodsh" && return
11118         local rc=0
11119         local rmmod_local=0
11120
11121         if ! module_loaded obdecho; then
11122             load_module obdecho/obdecho
11123             rmmod_local=1
11124         fi
11125
11126         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
11127         local host=$(lctl get_param -n osc.$osc.import |
11128                              awk '/current_connection:/ {print $2}' )
11129         local target=$(lctl get_param -n osc.$osc.import |
11130                              awk '/target:/ {print $2}' )
11131         target=${target%_UUID}
11132
11133         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
11134         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
11135         [[ -n $target ]] && cleanup_obdecho_osc $target
11136         [ $rmmod_local -eq 1 ] && rmmod obdecho
11137         return $rc
11138 }
11139 run_test 180a "test obdecho on osc"
11140
11141 test_180b() {
11142         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11143         remote_ost_nodsh && skip "remote OST with nodsh" && return
11144         local rc=0
11145         local rmmod_remote=0
11146
11147         do_facet ost1 "lsmod | grep -q obdecho || "                      \
11148                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
11149                       "modprobe obdecho; }" && rmmod_remote=1
11150         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
11151         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
11152         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
11153         return $rc
11154 }
11155 run_test 180b "test obdecho directly on obdfilter"
11156
11157 test_180c() { # LU-2598
11158         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11159         remote_ost_nodsh && skip "remote OST with nodsh" && return
11160         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
11161                 skip "Need MDS version at least 2.4.0" && return
11162
11163         local rc=0
11164         local rmmod_remote=false
11165         local pages=16384 # 64MB bulk I/O RPC size
11166         local target
11167
11168         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
11169                 rmmod_remote=true || error "failed to load module obdecho"
11170
11171         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
11172                 head -n1)
11173         if [ -n "$target" ]; then
11174                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
11175         else
11176                 echo "there is no obdfilter target on ost1"
11177                 rc=2
11178         fi
11179         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
11180         return $rc
11181 }
11182 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
11183
11184 test_181() { # bug 22177
11185         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11186         # create enough files to index the directory
11187         createmany -o $DIR/$tdir/foobar 4000
11188         # print attributes for debug purpose
11189         lsattr -d .
11190         # open dir
11191         multiop_bg_pause $DIR/$tdir D_Sc || return 1
11192         MULTIPID=$!
11193         # remove the files & current working dir
11194         unlinkmany $DIR/$tdir/foobar 4000
11195         rmdir $DIR/$tdir
11196         kill -USR1 $MULTIPID
11197         wait $MULTIPID
11198         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
11199         return 0
11200 }
11201 run_test 181 "Test open-unlinked dir ========================"
11202
11203 test_182() {
11204         local fcount=1000
11205         local tcount=10
11206
11207         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11208
11209         $LCTL set_param mdc.*.rpc_stats=clear
11210
11211         for (( i = 0; i < $tcount; i++ )) ; do
11212                 mkdir $DIR/$tdir/$i
11213         done
11214
11215         for (( i = 0; i < $tcount; i++ )) ; do
11216                 createmany -o $DIR/$tdir/$i/f- $fcount &
11217         done
11218         wait
11219
11220         for (( i = 0; i < $tcount; i++ )) ; do
11221                 unlinkmany $DIR/$tdir/$i/f- $fcount &
11222         done
11223         wait
11224
11225         $LCTL get_param mdc.*.rpc_stats
11226
11227         rm -rf $DIR/$tdir
11228 }
11229 run_test 182 "Test parallel modify metadata operations ================"
11230
11231 test_183() { # LU-2275
11232         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11233         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
11234                 skip "Need MDS version at least 2.3.56" && return
11235
11236         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11237         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11238         echo aaa > $DIR/$tdir/$tfile
11239
11240 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
11241         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
11242
11243         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
11244         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
11245
11246         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
11247
11248         # Flush negative dentry cache
11249         touch $DIR/$tdir/$tfile
11250
11251         # We are not checking for any leaked references here, they'll
11252         # become evident next time we do cleanup with module unload.
11253         rm -rf $DIR/$tdir
11254 }
11255 run_test 183 "No crash or request leak in case of strange dispositions ========"
11256
11257 # test suite 184 is for LU-2016, LU-2017
11258 test_184a() {
11259         check_swap_layouts_support && return 0
11260
11261         dir0=$DIR/$tdir/$testnum
11262         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
11263         ref1=/etc/passwd
11264         ref2=/etc/group
11265         file1=$dir0/f1
11266         file2=$dir0/f2
11267         $SETSTRIPE -c1 $file1
11268         cp $ref1 $file1
11269         $SETSTRIPE -c2 $file2
11270         cp $ref2 $file2
11271         gen1=$($GETSTRIPE -g $file1)
11272         gen2=$($GETSTRIPE -g $file2)
11273
11274         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
11275         gen=$($GETSTRIPE -g $file1)
11276         [[ $gen1 != $gen ]] ||
11277                 "Layout generation on $file1 does not change"
11278         gen=$($GETSTRIPE -g $file2)
11279         [[ $gen2 != $gen ]] ||
11280                 "Layout generation on $file2 does not change"
11281
11282         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
11283         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
11284 }
11285 run_test 184a "Basic layout swap"
11286
11287 test_184b() {
11288         check_swap_layouts_support && return 0
11289
11290         dir0=$DIR/$tdir/$testnum
11291         mkdir -p $dir0 || error "creating dir $dir0"
11292         file1=$dir0/f1
11293         file2=$dir0/f2
11294         file3=$dir0/f3
11295         dir1=$dir0/d1
11296         dir2=$dir0/d2
11297         mkdir $dir1 $dir2
11298         $SETSTRIPE -c1 $file1
11299         $SETSTRIPE -c2 $file2
11300         $SETSTRIPE -c1 $file3
11301         chown $RUNAS_ID $file3
11302         gen1=$($GETSTRIPE -g $file1)
11303         gen2=$($GETSTRIPE -g $file2)
11304
11305         $LFS swap_layouts $dir1 $dir2 &&
11306                 error "swap of directories layouts should fail"
11307         $LFS swap_layouts $dir1 $file1 &&
11308                 error "swap of directory and file layouts should fail"
11309         $RUNAS $LFS swap_layouts $file1 $file2 &&
11310                 error "swap of file we cannot write should fail"
11311         $LFS swap_layouts $file1 $file3 &&
11312                 error "swap of file with different owner should fail"
11313         /bin/true # to clear error code
11314 }
11315 run_test 184b "Forbidden layout swap (will generate errors)"
11316
11317 test_184c() {
11318         check_swap_layouts_support && return 0
11319
11320         local dir0=$DIR/$tdir/$testnum
11321         mkdir -p $dir0 || error "creating dir $dir0"
11322
11323         local ref1=$dir0/ref1
11324         local ref2=$dir0/ref2
11325         local file1=$dir0/file1
11326         local file2=$dir0/file2
11327         # create a file large enough for the concurrent test
11328         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
11329         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
11330         echo "ref file size: ref1($(stat -c %s $ref1))," \
11331              "ref2($(stat -c %s $ref2))"
11332
11333         cp $ref2 $file2
11334         dd if=$ref1 of=$file1 bs=16k &
11335         local DD_PID=$!
11336
11337         # Make sure dd starts to copy file
11338         while [ ! -f $file1 ]; do sleep 0.1; done
11339
11340         $LFS swap_layouts $file1 $file2
11341         local rc=$?
11342         wait $DD_PID
11343         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
11344         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
11345
11346         # how many bytes copied before swapping layout
11347         local copied=$(stat -c %s $file2)
11348         local remaining=$(stat -c %s $ref1)
11349         remaining=$((remaining - copied))
11350         echo "Copied $copied bytes before swapping layout..."
11351
11352         cmp -n $copied $file1 $ref2 | grep differ &&
11353                 error "Content mismatch [0, $copied) of ref2 and file1"
11354         cmp -n $copied $file2 $ref1 ||
11355                 error "Content mismatch [0, $copied) of ref1 and file2"
11356         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
11357                 error "Content mismatch [$copied, EOF) of ref1 and file1"
11358
11359         # clean up
11360         rm -f $ref1 $ref2 $file1 $file2
11361 }
11362 run_test 184c "Concurrent write and layout swap"
11363
11364 test_184d() {
11365         check_swap_layouts_support && return 0
11366         [ -z "$(which getfattr 2>/dev/null)" ] &&
11367                 skip "no getfattr command" && return 0
11368
11369         local file1=$DIR/$tdir/$tfile-1
11370         local file2=$DIR/$tdir/$tfile-2
11371         local file3=$DIR/$tdir/$tfile-3
11372         local lovea1
11373         local lovea2
11374
11375         mkdir -p $DIR/$tdir
11376         touch $file1 || error "create $file1 failed"
11377         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11378                 error "create $file2 failed"
11379         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11380                 error "create $file3 failed"
11381         lovea1=$($LFS getstripe $file1 | sed 1d)
11382
11383         $LFS swap_layouts $file2 $file3 ||
11384                 error "swap $file2 $file3 layouts failed"
11385         $LFS swap_layouts $file1 $file2 ||
11386                 error "swap $file1 $file2 layouts failed"
11387
11388         lovea2=$($LFS getstripe $file2 | sed 1d)
11389         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
11390
11391         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11392         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
11393 }
11394 run_test 184d "allow stripeless layouts swap"
11395
11396 test_184e() {
11397         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
11398                 { skip "Need MDS version at least 2.6.94"; return 0; }
11399         check_swap_layouts_support && return 0
11400         [ -z "$(which getfattr 2>/dev/null)" ] &&
11401                 skip "no getfattr command" && return 0
11402
11403         local file1=$DIR/$tdir/$tfile-1
11404         local file2=$DIR/$tdir/$tfile-2
11405         local file3=$DIR/$tdir/$tfile-3
11406         local lovea
11407
11408         mkdir -p $DIR/$tdir
11409         touch $file1 || error "create $file1 failed"
11410         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11411                 error "create $file2 failed"
11412         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11413                 error "create $file3 failed"
11414
11415         $LFS swap_layouts $file1 $file2 ||
11416                 error "swap $file1 $file2 layouts failed"
11417
11418         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11419         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
11420
11421         echo 123 > $file1 || error "Should be able to write into $file1"
11422
11423         $LFS swap_layouts $file1 $file3 ||
11424                 error "swap $file1 $file3 layouts failed"
11425
11426         echo 123 > $file1 || error "Should be able to write into $file1"
11427
11428         rm -rf $file1 $file2 $file3
11429 }
11430 run_test 184e "Recreate layout after stripeless layout swaps"
11431
11432 test_185() { # LU-2441
11433         # LU-3553 - no volatile file support in old servers
11434         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
11435                 { skip "Need MDS version at least 2.3.60"; return 0; }
11436
11437         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11438         touch $DIR/$tdir/spoo
11439         local mtime1=$(stat -c "%Y" $DIR/$tdir)
11440         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
11441                 error "cannot create/write a volatile file"
11442         [ "$FILESET" == "" ] &&
11443         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
11444                 error "FID is still valid after close"
11445
11446         multiop_bg_pause $DIR/$tdir vVw4096_c
11447         local multi_pid=$!
11448
11449         local OLD_IFS=$IFS
11450         IFS=":"
11451         local fidv=($fid)
11452         IFS=$OLD_IFS
11453         # assume that the next FID for this client is sequential, since stdout
11454         # is unfortunately eaten by multiop_bg_pause
11455         local n=$((${fidv[1]} + 1))
11456         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
11457         if [ "$FILESET" == "" ]; then
11458                 $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
11459                         error "FID is missing before close"
11460         fi
11461         kill -USR1 $multi_pid
11462         # 1 second delay, so if mtime change we will see it
11463         sleep 1
11464         local mtime2=$(stat -c "%Y" $DIR/$tdir)
11465         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
11466 }
11467 run_test 185 "Volatile file support"
11468
11469 test_187a() {
11470         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11471         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
11472                 skip "Need MDS version at least 2.3.0" && return
11473
11474         local dir0=$DIR/$tdir/$testnum
11475         mkdir -p $dir0 || error "creating dir $dir0"
11476
11477         local file=$dir0/file1
11478         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
11479         local dv1=$($LFS data_version $file)
11480         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
11481         local dv2=$($LFS data_version $file)
11482         [[ $dv1 != $dv2 ]] ||
11483                 error "data version did not change on write $dv1 == $dv2"
11484
11485         # clean up
11486         rm -f $file1
11487 }
11488 run_test 187a "Test data version change"
11489
11490 test_187b() {
11491         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11492         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
11493                 skip "Need MDS version at least 2.3.0" && return
11494
11495         local dir0=$DIR/$tdir/$testnum
11496         mkdir -p $dir0 || error "creating dir $dir0"
11497
11498         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
11499         [[ ${DV[0]} != ${DV[1]} ]] ||
11500                 error "data version did not change on write"\
11501                       " ${DV[0]} == ${DV[1]}"
11502
11503         # clean up
11504         rm -f $file1
11505 }
11506 run_test 187b "Test data version change on volatile file"
11507
11508 test_200() {
11509         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11510         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11511         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
11512
11513         local POOL=${POOL:-cea1}
11514         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
11515         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
11516         # Pool OST targets
11517         local first_ost=0
11518         local last_ost=$(($OSTCOUNT - 1))
11519         local ost_step=2
11520         local ost_list=$(seq $first_ost $ost_step $last_ost)
11521         local ost_range="$first_ost $last_ost $ost_step"
11522         local test_path=$POOL_ROOT/$POOL_DIR_NAME
11523         local file_dir=$POOL_ROOT/file_tst
11524         local subdir=$test_path/subdir
11525
11526         local rc=0
11527         while : ; do
11528                 # former test_200a test_200b
11529                 pool_add $POOL                          || { rc=$? ; break; }
11530                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
11531                 # former test_200c test_200d
11532                 mkdir -p $test_path
11533                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
11534                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
11535                 mkdir -p $subdir
11536                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
11537                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
11538                                                         || { rc=$? ; break; }
11539                 # former test_200e test_200f
11540                 local files=$((OSTCOUNT*3))
11541                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
11542                                                         || { rc=$? ; break; }
11543                 pool_create_files $POOL $file_dir $files "$ost_list" \
11544                                                         || { rc=$? ; break; }
11545                 # former test_200g test_200h
11546                 pool_lfs_df $POOL                       || { rc=$? ; break; }
11547                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
11548
11549                 # former test_201a test_201b test_201c
11550                 pool_remove_first_target $POOL          || { rc=$? ; break; }
11551
11552                 local f=$test_path/$tfile
11553                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
11554                 pool_remove $POOL $f                    || { rc=$? ; break; }
11555                 break
11556         done
11557
11558         cleanup_pools
11559         return $rc
11560 }
11561 run_test 200 "OST pools"
11562
11563 # usage: default_attr <count | size | offset>
11564 default_attr() {
11565         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
11566 }
11567
11568 # usage: check_default_stripe_attr
11569 check_default_stripe_attr() {
11570         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
11571         case $1 in
11572         --stripe-count|--count)
11573                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
11574         --stripe-size|--size)
11575                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
11576         --stripe-index|--index)
11577                 EXPECTED=-1;;
11578         *)
11579                 error "unknown getstripe attr '$1'"
11580         esac
11581
11582         [ $ACTUAL != $EXPECTED ] &&
11583                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
11584 }
11585
11586 test_204a() {
11587         test_mkdir -p $DIR/$tdir
11588         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
11589
11590         check_default_stripe_attr --stripe-count
11591         check_default_stripe_attr --stripe-size
11592         check_default_stripe_attr --stripe-index
11593
11594         return 0
11595 }
11596 run_test 204a "Print default stripe attributes ================="
11597
11598 test_204b() {
11599         test_mkdir -p $DIR/$tdir
11600         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11601
11602         check_default_stripe_attr --stripe-size
11603         check_default_stripe_attr --stripe-index
11604
11605         return 0
11606 }
11607 run_test 204b "Print default stripe size and offset  ==========="
11608
11609 test_204c() {
11610         test_mkdir -p $DIR/$tdir
11611         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11612
11613         check_default_stripe_attr --stripe-count
11614         check_default_stripe_attr --stripe-index
11615
11616         return 0
11617 }
11618 run_test 204c "Print default stripe count and offset ==========="
11619
11620 test_204d() {
11621         test_mkdir -p $DIR/$tdir
11622         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11623
11624         check_default_stripe_attr --stripe-count
11625         check_default_stripe_attr --stripe-size
11626
11627         return 0
11628 }
11629 run_test 204d "Print default stripe count and size ============="
11630
11631 test_204e() {
11632         test_mkdir -p $DIR/$tdir
11633         $SETSTRIPE -d $DIR/$tdir
11634
11635         check_default_stripe_attr --stripe-count --raw
11636         check_default_stripe_attr --stripe-size --raw
11637         check_default_stripe_attr --stripe-index --raw
11638
11639         return 0
11640 }
11641 run_test 204e "Print raw stripe attributes ================="
11642
11643 test_204f() {
11644         test_mkdir -p $DIR/$tdir
11645         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11646
11647         check_default_stripe_attr --stripe-size --raw
11648         check_default_stripe_attr --stripe-index --raw
11649
11650         return 0
11651 }
11652 run_test 204f "Print raw stripe size and offset  ==========="
11653
11654 test_204g() {
11655         test_mkdir -p $DIR/$tdir
11656         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11657
11658         check_default_stripe_attr --stripe-count --raw
11659         check_default_stripe_attr --stripe-index --raw
11660
11661         return 0
11662 }
11663 run_test 204g "Print raw stripe count and offset ==========="
11664
11665 test_204h() {
11666         test_mkdir -p $DIR/$tdir
11667         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11668
11669         check_default_stripe_attr --stripe-count --raw
11670         check_default_stripe_attr --stripe-size --raw
11671
11672         return 0
11673 }
11674 run_test 204h "Print raw stripe count and size ============="
11675
11676 # Figure out which job scheduler is being used, if any,
11677 # or use a fake one
11678 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11679         JOBENV=SLURM_JOB_ID
11680 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11681         JOBENV=LSB_JOBID
11682 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11683         JOBENV=PBS_JOBID
11684 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11685         JOBENV=LOADL_STEP_ID
11686 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11687         JOBENV=JOB_ID
11688 else
11689         $LCTL list_param jobid_name > /dev/null 2>&1
11690         if [ $? -eq 0 ]; then
11691                 JOBENV=nodelocal
11692         else
11693                 JOBENV=FAKE_JOBID
11694         fi
11695 fi
11696
11697 verify_jobstats() {
11698         local cmd=($1)
11699         shift
11700         local facets="$@"
11701
11702 # we don't really need to clear the stats for this test to work, since each
11703 # command has a unique jobid, but it makes debugging easier if needed.
11704 #       for facet in $facets; do
11705 #               local dev=$(convert_facet2label $facet)
11706 #               # clear old jobstats
11707 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
11708 #       done
11709
11710         # use a new JobID for each test, or we might see an old one
11711         [ "$JOBENV" = "FAKE_JOBID" ] &&
11712                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
11713
11714         JOBVAL=${!JOBENV}
11715
11716         [ "$JOBENV" = "nodelocal" ] && {
11717                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
11718                 $LCTL set_param jobid_name=$FAKE_JOBID
11719                 JOBVAL=$FAKE_JOBID
11720         }
11721
11722         log "Test: ${cmd[*]}"
11723         log "Using JobID environment variable $JOBENV=$JOBVAL"
11724
11725         if [ $JOBENV = "FAKE_JOBID" ]; then
11726                 FAKE_JOBID=$JOBVAL ${cmd[*]}
11727         else
11728                 ${cmd[*]}
11729         fi
11730
11731         # all files are created on OST0000
11732         for facet in $facets; do
11733                 local stats="*.$(convert_facet2label $facet).job_stats"
11734                 if [ $(do_facet $facet lctl get_param $stats |
11735                        grep -c $JOBVAL) -ne 1 ]; then
11736                         do_facet $facet lctl get_param $stats
11737                         error "No jobstats for $JOBVAL found on $facet::$stats"
11738                 fi
11739         done
11740 }
11741
11742 jobstats_set() {
11743         trap 0
11744         NEW_JOBENV=${1:-$OLD_JOBENV}
11745         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11746         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11747 }
11748
11749 cleanup_205() {
11750         do_facet $SINGLEMDS \
11751                 $LCTL set_param mdt.*.job_cleanup_interval=$OLD_INTERVAL
11752         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11753         do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
11754 }
11755
11756 test_205() { # Job stats
11757         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11758         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11759         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11760         remote_ost_nodsh && skip "remote OST with nodsh" && return
11761
11762         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11763                 skip "Server doesn't support jobstats" && return 0
11764         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11765
11766         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11767         if [ $OLD_JOBENV != $JOBENV ]; then
11768                 jobstats_set $JOBENV
11769                 trap cleanup_205 EXIT
11770         fi
11771
11772         CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
11773         echo "Registered as changelog user $CL_USER"
11774
11775         OLD_INTERVAL=$(do_facet $SINGLEMDS \
11776                        lctl get_param -n mdt.*.job_cleanup_interval)
11777         local interval_new=5
11778         do_facet $SINGLEMDS \
11779                 $LCTL set_param mdt.*.job_cleanup_interval=$interval_new
11780         local start=$SECONDS
11781
11782         local cmd
11783         # mkdir
11784         cmd="mkdir $DIR/$tdir"
11785         verify_jobstats "$cmd" "$SINGLEMDS"
11786         # rmdir
11787         cmd="rmdir $DIR/$tdir"
11788         verify_jobstats "$cmd" "$SINGLEMDS"
11789         # mkdir on secondary MDT
11790         if [ $MDSCOUNT -gt 1 ]; then
11791                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
11792                 verify_jobstats "$cmd" "mds2"
11793         fi
11794         # mknod
11795         cmd="mknod $DIR/$tfile c 1 3"
11796         verify_jobstats "$cmd" "$SINGLEMDS"
11797         # unlink
11798         cmd="rm -f $DIR/$tfile"
11799         verify_jobstats "$cmd" "$SINGLEMDS"
11800         # create all files on OST0000 so verify_jobstats can find OST stats
11801         # open & close
11802         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11803         verify_jobstats "$cmd" "$SINGLEMDS"
11804         # setattr
11805         cmd="touch $DIR/$tfile"
11806         verify_jobstats "$cmd" "$SINGLEMDS ost1"
11807         # write
11808         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11809         verify_jobstats "$cmd" "ost1"
11810         # read
11811         cancel_lru_locks osc
11812         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11813         verify_jobstats "$cmd" "ost1"
11814         # truncate
11815         cmd="$TRUNCATE $DIR/$tfile 0"
11816         verify_jobstats "$cmd" "$SINGLEMDS ost1"
11817         # rename
11818         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
11819         verify_jobstats "$cmd" "$SINGLEMDS"
11820         # jobstats expiry - sleep until old stats should be expired
11821         local left=$((interval_new + 2 - (SECONDS - start)))
11822         [ $left -ge 0 ] && echo "sleep $left for expiry" && sleep $((left + 1))
11823         cmd="mkdir $DIR/$tdir.expire"
11824         verify_jobstats "$cmd" "$SINGLEMDS"
11825         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
11826             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
11827
11828         # Ensure that jobid are present in changelog (if supported by MDS)
11829         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
11830         then
11831                 $LFS changelog $MDT0 | tail -9
11832                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
11833                 [ $jobids -eq 9 ] ||
11834                         error "Wrong changelog jobid count $jobids != 9"
11835
11836                 # LU-5862
11837                 JOBENV="disable"
11838                 jobstats_set $JOBENV
11839                 touch $DIR/$tfile
11840                 $LFS changelog $MDT0 | tail -1
11841                 jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
11842                 [ $jobids -eq 0 ] ||
11843                         error "Unexpected jobids when jobid_var=$JOBENV"
11844         fi
11845
11846         cleanup_205
11847 }
11848 run_test 205 "Verify job stats"
11849
11850 # LU-1480, LU-1773 and LU-1657
11851 test_206() {
11852         mkdir -p $DIR/$tdir
11853         $SETSTRIPE -c -1 $DIR/$tdir
11854 #define OBD_FAIL_LOV_INIT 0x1403
11855         $LCTL set_param fail_loc=0xa0001403
11856         $LCTL set_param fail_val=1
11857         touch $DIR/$tdir/$tfile || true
11858 }
11859 run_test 206 "fail lov_init_raid0() doesn't lbug"
11860
11861 test_207a() {
11862         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11863         local fsz=`stat -c %s $DIR/$tfile`
11864         cancel_lru_locks mdc
11865
11866         # do not return layout in getattr intent
11867 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11868         $LCTL set_param fail_loc=0x170
11869         local sz=`stat -c %s $DIR/$tfile`
11870
11871         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11872
11873         rm -rf $DIR/$tfile
11874 }
11875 run_test 207a "can refresh layout at glimpse"
11876
11877 test_207b() {
11878         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11879         local cksum=`md5sum $DIR/$tfile`
11880         local fsz=`stat -c %s $DIR/$tfile`
11881         cancel_lru_locks mdc
11882         cancel_lru_locks osc
11883
11884         # do not return layout in getattr intent
11885 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11886         $LCTL set_param fail_loc=0x171
11887
11888         # it will refresh layout after the file is opened but before read issues
11889         echo checksum is "$cksum"
11890         echo "$cksum" |md5sum -c --quiet || error "file differs"
11891
11892         rm -rf $DIR/$tfile
11893 }
11894 run_test 207b "can refresh layout at open"
11895
11896 test_208() {
11897         # FIXME: in this test suite, only RD lease is used. This is okay
11898         # for now as only exclusive open is supported. After generic lease
11899         # is done, this test suite should be revised. - Jinshan
11900
11901         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11902         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11903                 { skip "Need MDS version at least 2.4.52"; return 0; }
11904
11905         echo "==== test 1: verify get lease work"
11906         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11907
11908         echo "==== test 2: verify lease can be broken by upcoming open"
11909         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11910         local PID=$!
11911         sleep 1
11912
11913         $MULTIOP $DIR/$tfile oO_RDONLY:c
11914         kill -USR1 $PID && wait $PID || error "break lease error"
11915
11916         echo "==== test 3: verify lease can't be granted if an open already exists"
11917         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11918         local PID=$!
11919         sleep 1
11920
11921         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11922         kill -USR1 $PID && wait $PID || error "open file error"
11923
11924         echo "==== test 4: lease can sustain over recovery"
11925         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11926         PID=$!
11927         sleep 1
11928
11929         fail mds1
11930
11931         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11932
11933         echo "==== test 5: lease broken can't be regained by replay"
11934         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11935         PID=$!
11936         sleep 1
11937
11938         # open file to break lease and then recovery
11939         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11940         fail mds1
11941
11942         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11943
11944         rm -f $DIR/$tfile
11945 }
11946 run_test 208 "Exclusive open"
11947
11948 test_209() {
11949         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11950                 skip_env "must have disp_stripe" && return
11951
11952         touch $DIR/$tfile
11953         sync; sleep 5; sync;
11954
11955         echo 3 > /proc/sys/vm/drop_caches
11956         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11957
11958         # open/close 500 times
11959         for i in $(seq 500); do
11960                 cat $DIR/$tfile
11961         done
11962
11963         echo 3 > /proc/sys/vm/drop_caches
11964         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11965
11966         echo "before: $req_before, after: $req_after"
11967         [ $((req_after - req_before)) -ge 300 ] &&
11968                 error "open/close requests are not freed"
11969         return 0
11970 }
11971 run_test 209 "read-only open/close requests should be freed promptly"
11972
11973 test_212() {
11974         size=`date +%s`
11975         size=$((size % 8192 + 1))
11976         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11977         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11978         rm -f $DIR/f212 $DIR/f212.xyz
11979 }
11980 run_test 212 "Sendfile test ============================================"
11981
11982 test_213() {
11983         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11984         cancel_lru_locks osc
11985         lctl set_param fail_loc=0x8000040f
11986         # generate a read lock
11987         cat $DIR/$tfile > /dev/null
11988         # write to the file, it will try to cancel the above read lock.
11989         cat /etc/hosts >> $DIR/$tfile
11990 }
11991 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11992
11993 test_214() { # for bug 20133
11994         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11995         for (( i=0; i < 340; i++ )) ; do
11996                 touch $DIR/$tdir/d214c/a$i
11997         done
11998
11999         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
12000         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
12001         ls $DIR/d214c || error "ls $DIR/d214c failed"
12002         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
12003         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
12004 }
12005 run_test 214 "hash-indexed directory test - bug 20133"
12006
12007 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
12008 create_lnet_proc_files() {
12009         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
12010         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
12011
12012         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
12013         rm -f "$TMP/lnet_$1.sys_tmp"
12014 }
12015
12016 # counterpart of create_lnet_proc_files
12017 remove_lnet_proc_files() {
12018         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
12019 }
12020
12021 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12022 # 3rd arg as regexp for body
12023 check_lnet_proc_stats() {
12024         local l=$(cat "$TMP/lnet_$1" |wc -l)
12025         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
12026
12027         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
12028 }
12029
12030 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12031 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
12032 # optional and can be regexp for 2nd line (lnet.routes case)
12033 check_lnet_proc_entry() {
12034         local blp=2          # blp stands for 'position of 1st line of body'
12035         [ -z "$5" ] || blp=3 # lnet.routes case
12036
12037         local l=$(cat "$TMP/lnet_$1" |wc -l)
12038         # subtracting one from $blp because the body can be empty
12039         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
12040
12041         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
12042                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
12043
12044         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
12045                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
12046
12047         # bail out if any unexpected line happened
12048         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
12049         [ "$?" != 0 ] || error "$2 misformatted"
12050 }
12051
12052 test_215() { # for bugs 18102, 21079, 21517
12053         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12054         local N='(0|[1-9][0-9]*)'       # non-negative numeric
12055         local P='[1-9][0-9]*'           # positive numeric
12056         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
12057         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
12058         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
12059         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
12060
12061         local L1 # regexp for 1st line
12062         local L2 # regexp for 2nd line (optional)
12063         local BR # regexp for the rest (body)
12064
12065         # lnet.stats should look as 11 space-separated non-negative numerics
12066         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
12067         create_lnet_proc_files "stats"
12068         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
12069         remove_lnet_proc_files "stats"
12070
12071         # lnet.routes should look like this:
12072         # Routing disabled/enabled
12073         # net hops priority state router
12074         # where net is a string like tcp0, hops > 0, priority >= 0,
12075         # state is up/down,
12076         # router is a string like 192.168.1.1@tcp2
12077         L1="^Routing (disabled|enabled)$"
12078         L2="^net +hops +priority +state +router$"
12079         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
12080         create_lnet_proc_files "routes"
12081         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
12082         remove_lnet_proc_files "routes"
12083
12084         # lnet.routers should look like this:
12085         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
12086         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
12087         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
12088         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
12089         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
12090         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
12091         create_lnet_proc_files "routers"
12092         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
12093         remove_lnet_proc_files "routers"
12094
12095         # lnet.peers should look like this:
12096         # nid refs state last max rtr min tx min queue
12097         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
12098         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
12099         # numeric (0 or >0 or <0), queue >= 0.
12100         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
12101         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
12102         create_lnet_proc_files "peers"
12103         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
12104         remove_lnet_proc_files "peers"
12105
12106         # lnet.buffers  should look like this:
12107         # pages count credits min
12108         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
12109         L1="^pages +count +credits +min$"
12110         BR="^ +$N +$N +$I +$I$"
12111         create_lnet_proc_files "buffers"
12112         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
12113         remove_lnet_proc_files "buffers"
12114
12115         # lnet.nis should look like this:
12116         # nid status alive refs peer rtr max tx min
12117         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
12118         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
12119         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
12120         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
12121         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
12122         create_lnet_proc_files "nis"
12123         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
12124         remove_lnet_proc_files "nis"
12125
12126         # can we successfully write to lnet.stats?
12127         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
12128         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
12129 }
12130 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
12131
12132 test_216() { # bug 20317
12133         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12134         remote_ost_nodsh && skip "remote OST with nodsh" && return
12135
12136         local node
12137         local facets=$(get_facets OST)
12138         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
12139
12140         save_lustre_params client "osc.*.contention_seconds" > $p
12141         save_lustre_params $facets \
12142                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
12143         save_lustre_params $facets \
12144                 "ldlm.namespaces.filter-*.contended_locks" >> $p
12145         save_lustre_params $facets \
12146                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
12147         clear_osc_stats
12148
12149         # agressive lockless i/o settings
12150         for node in $(osts_nodes); do
12151                 do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 2000000; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 0; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 60'
12152         done
12153         lctl set_param -n osc.*.contention_seconds 60
12154
12155         $DIRECTIO write $DIR/$tfile 0 10 4096
12156         $CHECKSTAT -s 40960 $DIR/$tfile
12157
12158         # disable lockless i/o
12159         for node in $(osts_nodes); do
12160                 do_node $node 'lctl set_param -n ldlm.namespaces.filter-*.max_nolock_bytes 0; lctl set_param -n ldlm.namespaces.filter-*.contended_locks 32; lctl set_param -n ldlm.namespaces.filter-*.contention_seconds 0'
12161         done
12162         lctl set_param -n osc.*.contention_seconds 0
12163         clear_osc_stats
12164
12165         dd if=/dev/zero of=$DIR/$tfile count=0
12166         $CHECKSTAT -s 0 $DIR/$tfile
12167
12168         restore_lustre_params <$p
12169         rm -f $p
12170         rm $DIR/$tfile
12171 }
12172 run_test 216 "check lockless direct write works and updates file size and kms correctly"
12173
12174 test_217() { # bug 22430
12175         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12176         local node
12177         local nid
12178
12179         for node in $(nodes_list); do
12180                 nid=$(host_nids_address $node $NETTYPE)
12181                 if [[ $nid = *-* ]] ; then
12182                         echo "lctl ping $nid@$NETTYPE"
12183                         lctl ping $nid@$NETTYPE
12184                 else
12185                         echo "skipping $node (no hyphen detected)"
12186                 fi
12187         done
12188 }
12189 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
12190
12191 test_218() {
12192        # do directio so as not to populate the page cache
12193        log "creating a 10 Mb file"
12194        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
12195        log "starting reads"
12196        dd if=$DIR/$tfile of=/dev/null bs=4096 &
12197        log "truncating the file"
12198        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
12199        log "killing dd"
12200        kill %+ || true # reads might have finished
12201        echo "wait until dd is finished"
12202        wait
12203        log "removing the temporary file"
12204        rm -rf $DIR/$tfile || error "tmp file removal failed"
12205 }
12206 run_test 218 "parallel read and truncate should not deadlock ======================="
12207
12208 test_219() {
12209         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12210         # write one partial page
12211         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
12212         # set no grant so vvp_io_commit_write will do sync write
12213         $LCTL set_param fail_loc=0x411
12214         # write a full page at the end of file
12215         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
12216
12217         $LCTL set_param fail_loc=0
12218         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
12219         $LCTL set_param fail_loc=0x411
12220         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
12221
12222         # LU-4201
12223         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
12224         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
12225 }
12226 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
12227
12228 test_220() { #LU-325
12229         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12230         remote_ost_nodsh && skip "remote OST with nodsh" && return
12231         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12232         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12233         local OSTIDX=0
12234
12235         # create on MDT0000 so the last_id and next_id are correct
12236         mkdir $DIR/$tdir
12237         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
12238         OST=${OST%_UUID}
12239
12240         # on the mdt's osc
12241         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
12242         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
12243                         osc.$mdtosc_proc1.prealloc_last_id)
12244         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
12245                         osc.$mdtosc_proc1.prealloc_next_id)
12246
12247         $LFS df -i
12248
12249         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
12250         #define OBD_FAIL_OST_ENOINO              0x229
12251         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
12252         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
12253         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
12254
12255         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
12256
12257         MDSOBJS=$((last_id - next_id))
12258         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
12259
12260         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
12261         echo "OST still has $count kbytes free"
12262
12263         echo "create $MDSOBJS files @next_id..."
12264         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
12265
12266         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12267                         osc.$mdtosc_proc1.prealloc_last_id)
12268         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12269                         osc.$mdtosc_proc1.prealloc_next_id)
12270
12271         echo "after creation, last_id=$last_id2, next_id=$next_id2"
12272         $LFS df -i
12273
12274         echo "cleanup..."
12275
12276         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
12277         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
12278
12279         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
12280         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
12281         echo "unlink $MDSOBJS files @$next_id..."
12282         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
12283 }
12284 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
12285
12286 test_221() {
12287         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12288         dd if=`which date` of=$MOUNT/date oflag=sync
12289         chmod +x $MOUNT/date
12290
12291         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
12292         $LCTL set_param fail_loc=0x80001401
12293
12294         $MOUNT/date > /dev/null
12295         rm -f $MOUNT/date
12296 }
12297 run_test 221 "make sure fault and truncate race to not cause OOM"
12298
12299 test_222a () {
12300         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12301        rm -rf $DIR/$tdir
12302        test_mkdir -p $DIR/$tdir
12303        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12304        createmany -o $DIR/$tdir/$tfile 10
12305        cancel_lru_locks mdc
12306        cancel_lru_locks osc
12307        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12308        $LCTL set_param fail_loc=0x31a
12309        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
12310        $LCTL set_param fail_loc=0
12311        rm -r $DIR/$tdir
12312 }
12313 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
12314
12315 test_222b () {
12316         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12317        rm -rf $DIR/$tdir
12318        test_mkdir -p $DIR/$tdir
12319        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12320        createmany -o $DIR/$tdir/$tfile 10
12321        cancel_lru_locks mdc
12322        cancel_lru_locks osc
12323        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12324        $LCTL set_param fail_loc=0x31a
12325        rm -r $DIR/$tdir || "AGL for rmdir failed"
12326        $LCTL set_param fail_loc=0
12327 }
12328 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
12329
12330 test_223 () {
12331         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12332        rm -rf $DIR/$tdir
12333        test_mkdir -p $DIR/$tdir
12334        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12335        createmany -o $DIR/$tdir/$tfile 10
12336        cancel_lru_locks mdc
12337        cancel_lru_locks osc
12338        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
12339        $LCTL set_param fail_loc=0x31b
12340        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
12341        $LCTL set_param fail_loc=0
12342        rm -r $DIR/$tdir
12343 }
12344 run_test 223 "osc reenqueue if without AGL lock granted ======================="
12345
12346 test_224a() { # LU-1039, MRP-303
12347         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12348         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
12349         $LCTL set_param fail_loc=0x508
12350         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
12351         $LCTL set_param fail_loc=0
12352         df $DIR
12353 }
12354 run_test 224a "Don't panic on bulk IO failure"
12355
12356 test_224b() { # LU-1039, MRP-303
12357         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12358         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
12359         cancel_lru_locks osc
12360         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
12361         $LCTL set_param fail_loc=0x515
12362         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
12363         $LCTL set_param fail_loc=0
12364         df $DIR
12365 }
12366 run_test 224b "Don't panic on bulk IO failure"
12367
12368 test_224c() { # LU-6441
12369         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12370         local pages_per_rpc=$($LCTL get_param \
12371                                 osc.*.max_pages_per_rpc)
12372         local at_max=$($LCTL get_param -n at_max)
12373         local timeout=$($LCTL get_param -n timeout)
12374         local test_at="$LCTL get_param -n at_max"
12375         local param_at="$FSNAME.sys.at_max"
12376         local test_timeout="$LCTL get_param -n timeout"
12377         local param_timeout="$FSNAME.sys.timeout"
12378
12379         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
12380
12381         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
12382                 error "conf_param at_max=0 failed"
12383         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
12384                 error "conf_param timeout=5 failed"
12385
12386         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
12387         $LCTL set_param fail_loc=0x520
12388         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
12389         sync
12390         $LCTL set_param fail_loc=0
12391
12392         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
12393                 error "conf_param at_max=$at_max failed"
12394         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
12395                 $timeout || error "conf_param timeout=$timeout failed"
12396
12397         $LCTL set_param -n $pages_per_rpc
12398 }
12399 run_test 224c "Don't hang if one of md lost during large bulk RPC"
12400
12401 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
12402 test_225a () {
12403         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12404         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12405         if [ -z ${MDSSURVEY} ]; then
12406               skip_env "mds-survey not found" && return
12407         fi
12408
12409         [ $MDSCOUNT -ge 2 ] &&
12410                 skip "skipping now for more than one MDT" && return
12411
12412        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12413             { skip "Need MDS version at least 2.2.51"; return; }
12414
12415        local mds=$(facet_host $SINGLEMDS)
12416        local target=$(do_nodes $mds 'lctl dl' | \
12417                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12418
12419        local cmd1="file_count=1000 thrhi=4"
12420        local cmd2="dir_count=2 layer=mdd stripe_count=0"
12421        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12422        local cmd="$cmd1 $cmd2 $cmd3"
12423
12424        rm -f ${TMP}/mds_survey*
12425        echo + $cmd
12426        eval $cmd || error "mds-survey with zero-stripe failed"
12427        cat ${TMP}/mds_survey*
12428        rm -f ${TMP}/mds_survey*
12429 }
12430 run_test 225a "Metadata survey sanity with zero-stripe"
12431
12432 test_225b () {
12433         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12434         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12435         if [ -z ${MDSSURVEY} ]; then
12436               skip_env "mds-survey not found" && return
12437         fi
12438         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12439             { skip "Need MDS version at least 2.2.51"; return; }
12440
12441         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
12442               skip_env "Need to mount OST to test" && return
12443         fi
12444
12445         [ $MDSCOUNT -ge 2 ] &&
12446                 skip "skipping now for more than one MDT" && return
12447        local mds=$(facet_host $SINGLEMDS)
12448        local target=$(do_nodes $mds 'lctl dl' | \
12449                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12450
12451        local cmd1="file_count=1000 thrhi=4"
12452        local cmd2="dir_count=2 layer=mdd stripe_count=1"
12453        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12454        local cmd="$cmd1 $cmd2 $cmd3"
12455
12456        rm -f ${TMP}/mds_survey*
12457        echo + $cmd
12458        eval $cmd || error "mds-survey with stripe_count failed"
12459        cat ${TMP}/mds_survey*
12460        rm -f ${TMP}/mds_survey*
12461 }
12462 run_test 225b "Metadata survey sanity with stripe_count = 1"
12463
12464 mcreate_path2fid () {
12465         local mode=$1
12466         local major=$2
12467         local minor=$3
12468         local name=$4
12469         local desc=$5
12470         local path=$DIR/$tdir/$name
12471         local fid
12472         local rc
12473         local fid_path
12474
12475         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
12476                 error "cannot create $desc"
12477
12478         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
12479         rc=$?
12480         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
12481
12482         fid_path=$($LFS fid2path $MOUNT $fid)
12483         rc=$?
12484         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
12485
12486         [ "$path" == "$fid_path" ] ||
12487                 error "fid2path returned $fid_path, expected $path"
12488
12489         echo "pass with $path and $fid"
12490 }
12491
12492 test_226a () {
12493         rm -rf $DIR/$tdir
12494         mkdir -p $DIR/$tdir
12495
12496         mcreate_path2fid 0010666 0 0 fifo "FIFO"
12497         mcreate_path2fid 0020666 1 3 null "character special file (null)"
12498         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
12499         mcreate_path2fid 0040666 0 0 dir "directory"
12500         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
12501         mcreate_path2fid 0100666 0 0 file "regular file"
12502         mcreate_path2fid 0120666 0 0 link "symbolic link"
12503         mcreate_path2fid 0140666 0 0 sock "socket"
12504 }
12505 run_test 226a "call path2fid and fid2path on files of all type"
12506
12507 test_226b () {
12508         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12509         rm -rf $DIR/$tdir
12510         local MDTIDX=1
12511
12512         mkdir -p $DIR/$tdir
12513         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
12514                 error "create remote directory failed"
12515         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
12516         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
12517                                 "character special file (null)"
12518         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
12519                                 "character special file (no device)"
12520         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
12521         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
12522                                 "block special file (loop)"
12523         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
12524         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
12525         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
12526 }
12527 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
12528
12529 # LU-1299 Executing or running ldd on a truncated executable does not
12530 # cause an out-of-memory condition.
12531 test_227() {
12532         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12533         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
12534         dd if=$(which date) of=$MOUNT/date bs=1k count=1
12535         chmod +x $MOUNT/date
12536
12537         $MOUNT/date > /dev/null
12538         ldd $MOUNT/date > /dev/null
12539         rm -f $MOUNT/date
12540 }
12541 run_test 227 "running truncated executable does not cause OOM"
12542
12543 # LU-1512 try to reuse idle OI blocks
12544 test_228a() {
12545         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12546         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12547         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12548                 skip "non-ldiskfs backend" && return
12549
12550         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12551         local myDIR=$DIR/$tdir
12552
12553         mkdir -p $myDIR
12554         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12555         $LCTL set_param fail_loc=0x80001002
12556         createmany -o $myDIR/t- 10000
12557         $LCTL set_param fail_loc=0
12558         # The guard is current the largest FID holder
12559         touch $myDIR/guard
12560         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12561                     tr -d '[')
12562         local IDX=$(($SEQ % 64))
12563
12564         do_facet $SINGLEMDS sync
12565         # Make sure journal flushed.
12566         sleep 6
12567         local blk1=$(do_facet $SINGLEMDS \
12568                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12569                      grep Blockcount | awk '{print $4}')
12570
12571         # Remove old files, some OI blocks will become idle.
12572         unlinkmany $myDIR/t- 10000
12573         # Create new files, idle OI blocks should be reused.
12574         createmany -o $myDIR/t- 2000
12575         do_facet $SINGLEMDS sync
12576         # Make sure journal flushed.
12577         sleep 6
12578         local blk2=$(do_facet $SINGLEMDS \
12579                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12580                      grep Blockcount | awk '{print $4}')
12581
12582         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12583 }
12584 run_test 228a "try to reuse idle OI blocks"
12585
12586 test_228b() {
12587         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12588         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12589         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12590                 skip "non-ldiskfs backend" && return
12591
12592         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12593         local myDIR=$DIR/$tdir
12594
12595         mkdir -p $myDIR
12596         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12597         $LCTL set_param fail_loc=0x80001002
12598         createmany -o $myDIR/t- 10000
12599         $LCTL set_param fail_loc=0
12600         # The guard is current the largest FID holder
12601         touch $myDIR/guard
12602         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12603                     tr -d '[')
12604         local IDX=$(($SEQ % 64))
12605
12606         do_facet $SINGLEMDS sync
12607         # Make sure journal flushed.
12608         sleep 6
12609         local blk1=$(do_facet $SINGLEMDS \
12610                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12611                      grep Blockcount | awk '{print $4}')
12612
12613         # Remove old files, some OI blocks will become idle.
12614         unlinkmany $myDIR/t- 10000
12615
12616         # stop the MDT
12617         stop $SINGLEMDS || error "Fail to stop MDT."
12618         # remount the MDT
12619         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
12620
12621         df $MOUNT || error "Fail to df."
12622         # Create new files, idle OI blocks should be reused.
12623         createmany -o $myDIR/t- 2000
12624         do_facet $SINGLEMDS sync
12625         # Make sure journal flushed.
12626         sleep 6
12627         local blk2=$(do_facet $SINGLEMDS \
12628                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12629                      grep Blockcount | awk '{print $4}')
12630
12631         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12632 }
12633 run_test 228b "idle OI blocks can be reused after MDT restart"
12634
12635 #LU-1881
12636 test_228c() {
12637         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12638         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12639         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12640                 skip "non-ldiskfs backend" && return
12641
12642         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12643         local myDIR=$DIR/$tdir
12644
12645         mkdir -p $myDIR
12646         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12647         $LCTL set_param fail_loc=0x80001002
12648         # 20000 files can guarantee there are index nodes in the OI file
12649         createmany -o $myDIR/t- 20000
12650         $LCTL set_param fail_loc=0
12651         # The guard is current the largest FID holder
12652         touch $myDIR/guard
12653         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12654                     tr -d '[')
12655         local IDX=$(($SEQ % 64))
12656
12657         do_facet $SINGLEMDS sync
12658         # Make sure journal flushed.
12659         sleep 6
12660         local blk1=$(do_facet $SINGLEMDS \
12661                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12662                      grep Blockcount | awk '{print $4}')
12663
12664         # Remove old files, some OI blocks will become idle.
12665         unlinkmany $myDIR/t- 20000
12666         rm -f $myDIR/guard
12667         # The OI file should become empty now
12668
12669         # Create new files, idle OI blocks should be reused.
12670         createmany -o $myDIR/t- 2000
12671         do_facet $SINGLEMDS sync
12672         # Make sure journal flushed.
12673         sleep 6
12674         local blk2=$(do_facet $SINGLEMDS \
12675                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12676                      grep Blockcount | awk '{print $4}')
12677
12678         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12679 }
12680 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
12681
12682 test_229() { # LU-2482, LU-3448
12683         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
12684                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
12685                 return
12686         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12687         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
12688
12689         rm -f $DIR/$tfile
12690
12691         # Create a file with a released layout and stripe count 2.
12692         $MULTIOP $DIR/$tfile H2c ||
12693                 error "failed to create file with released layout"
12694
12695         $GETSTRIPE -v $DIR/$tfile
12696
12697         local pattern=$($GETSTRIPE -L $DIR/$tfile)
12698         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
12699
12700         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
12701         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
12702         stat $DIR/$tfile || error "failed to stat released file"
12703
12704         chown $RUNAS_ID $DIR/$tfile ||
12705                 error "chown $RUNAS_ID $DIR/$tfile failed"
12706
12707         chgrp $RUNAS_ID $DIR/$tfile ||
12708                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12709
12710         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12711         rm $DIR/$tfile || error "failed to remove released file"
12712 }
12713 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12714
12715 test_230a() {
12716         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12717         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12718         local MDTIDX=1
12719
12720         test_mkdir $DIR/$tdir
12721         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
12722         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12723         [ $mdt_idx -ne 0 ] &&
12724                 error "create local directory on wrong MDT $mdt_idx"
12725
12726         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12727                         error "create remote directory failed"
12728         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12729         [ $mdt_idx -ne $MDTIDX ] &&
12730                 error "create remote directory on wrong MDT $mdt_idx"
12731
12732         createmany -o $DIR/$tdir/test_230/t- 10 ||
12733                 error "create files on remote directory failed"
12734         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12735         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12736         rm -r $DIR/$tdir || error "unlink remote directory failed"
12737 }
12738 run_test 230a "Create remote directory and files under the remote directory"
12739
12740 test_230b() {
12741         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12742         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12743         local MDTIDX=1
12744         local mdt_index
12745         local i
12746         local file
12747         local pid
12748         local stripe_count
12749         local migrate_dir=$DIR/$tdir/migrate_dir
12750         local other_dir=$DIR/$tdir/other_dir
12751
12752         test_mkdir $DIR/$tdir
12753         test_mkdir -i0 -c1 $migrate_dir
12754         test_mkdir -i0 -c1 $other_dir
12755         for ((i=0; i<10; i++)); do
12756                 mkdir -p $migrate_dir/dir_${i}
12757                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12758                         error "create files under remote dir failed $i"
12759         done
12760
12761         cp /etc/passwd $migrate_dir/$tfile
12762         cp /etc/passwd $other_dir/$tfile
12763         chattr +SAD $migrate_dir
12764         chattr +SAD $migrate_dir/$tfile
12765
12766         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12767         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12768         local old_dir_mode=$(stat -c%f $migrate_dir)
12769         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
12770
12771         mkdir -p $migrate_dir/dir_default_stripe2
12772         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12773         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12774
12775         mkdir -p $other_dir
12776         ln $migrate_dir/$tfile $other_dir/luna
12777         ln $migrate_dir/$tfile $migrate_dir/sofia
12778         ln $other_dir/$tfile $migrate_dir/david
12779         ln -s $migrate_dir/$tfile $other_dir/zachary
12780         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12781         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12782
12783         $LFS migrate -m $MDTIDX $migrate_dir ||
12784                 error "fails on migrating remote dir to MDT1"
12785
12786         echo "migratate to MDT1, then checking.."
12787         for ((i = 0; i < 10; i++)); do
12788                 for file in $(find $migrate_dir/dir_${i}); do
12789                         mdt_index=$($LFS getstripe -M $file)
12790                         [ $mdt_index == $MDTIDX ] ||
12791                                 error "$file is not on MDT${MDTIDX}"
12792                 done
12793         done
12794
12795         # the multiple link file should still in MDT0
12796         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12797         [ $mdt_index == 0 ] ||
12798                 error "$file is not on MDT${MDTIDX}"
12799
12800         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12801         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12802                 error " expect $old_dir_flag get $new_dir_flag"
12803
12804         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12805         [ "$old_file_flag" = "$new_file_flag" ] ||
12806                 error " expect $old_file_flag get $new_file_flag"
12807
12808         local new_dir_mode=$(stat -c%f $migrate_dir)
12809         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12810                 error "expect mode $old_dir_mode get $new_dir_mode"
12811
12812         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12813         [ "$old_file_mode" = "$new_file_mode" ] ||
12814                 error "expect mode $old_file_mode get $new_file_mode"
12815
12816         diff /etc/passwd $migrate_dir/$tfile ||
12817                 error "$tfile different after migration"
12818
12819         diff /etc/passwd $other_dir/luna ||
12820                 error "luna different after migration"
12821
12822         diff /etc/passwd $migrate_dir/sofia ||
12823                 error "sofia different after migration"
12824
12825         diff /etc/passwd $migrate_dir/david ||
12826                 error "david different after migration"
12827
12828         diff /etc/passwd $other_dir/zachary ||
12829                 error "zachary different after migration"
12830
12831         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12832                 error "${tfile}_ln different after migration"
12833
12834         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12835                 error "${tfile}_ln_other different after migration"
12836
12837         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12838         [ $stripe_count = 2 ] ||
12839                 error "dir strpe_count $d != 2 after migration."
12840
12841         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12842         [ $stripe_count = 2 ] ||
12843                 error "file strpe_count $d != 2 after migration."
12844
12845         #migrate back to MDT0
12846         MDTIDX=0
12847
12848         $LFS migrate -m $MDTIDX $migrate_dir ||
12849                 error "fails on migrating remote dir to MDT0"
12850
12851         echo "migrate back to MDT0, checking.."
12852         for file in $(find $migrate_dir); do
12853                 mdt_index=$($LFS getstripe -M $file)
12854                 [ $mdt_index == $MDTIDX ] ||
12855                         error "$file is not on MDT${MDTIDX}"
12856         done
12857
12858         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12859         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12860                 error " expect $old_dir_flag get $new_dir_flag"
12861
12862         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12863         [ "$old_file_flag" = "$new_file_flag" ] ||
12864                 error " expect $old_file_flag get $new_file_flag"
12865
12866         local new_dir_mode=$(stat -c%f $migrate_dir)
12867         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12868                 error "expect mode $old_dir_mode get $new_dir_mode"
12869
12870         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12871         [ "$old_file_mode" = "$new_file_mode" ] ||
12872                 error "expect mode $old_file_mode get $new_file_mode"
12873
12874         diff /etc/passwd ${migrate_dir}/$tfile ||
12875                 error "$tfile different after migration"
12876
12877         diff /etc/passwd ${other_dir}/luna ||
12878                 error "luna different after migration"
12879
12880         diff /etc/passwd ${migrate_dir}/sofia ||
12881                 error "sofia different after migration"
12882
12883         diff /etc/passwd ${other_dir}/zachary ||
12884                 error "zachary different after migration"
12885
12886         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12887                 error "${tfile}_ln different after migration"
12888
12889         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12890                 error "${tfile}_ln_other different after migration"
12891
12892         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12893         [ $stripe_count = 2 ] ||
12894                 error "dir strpe_count $d != 2 after migration."
12895
12896         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12897         [ $stripe_count = 2 ] ||
12898                 error "file strpe_count $d != 2 after migration."
12899
12900         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12901 }
12902 run_test 230b "migrate directory"
12903
12904 test_230c() {
12905         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12906         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12907         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12908         local MDTIDX=1
12909         local mdt_index
12910         local file
12911         local migrate_dir=$DIR/$tdir/migrate_dir
12912
12913         #If migrating directory fails in the middle, all entries of
12914         #the directory is still accessiable.
12915         test_mkdir $DIR/$tdir
12916         test_mkdir -i0 -c1 $migrate_dir
12917         stat $migrate_dir
12918         createmany -o $migrate_dir/f 10 ||
12919                 error "create files under ${migrate_dir} failed"
12920
12921         #failed after migrating 5 entries
12922         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12923         do_facet mds1 lctl set_param fail_loc=0x20001801
12924         do_facet mds1 lctl  set_param fail_val=5
12925         local t=$(ls $migrate_dir | wc -l)
12926         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
12927                 error "migrate should fail after 5 entries"
12928
12929         mkdir $migrate_dir/dir &&
12930                 error "mkdir succeeds under migrating directory"
12931         touch $migrate_dir/file &&
12932                 error "touch file succeeds under migrating directory"
12933
12934         local u=$(ls $migrate_dir | wc -l)
12935         [ "$u" == "$t" ] || error "$u != $t during migration"
12936
12937         for file in $(find $migrate_dir); do
12938                 stat $file || error "stat $file failed"
12939         done
12940
12941         do_facet mds1 lctl set_param fail_loc=0
12942         do_facet mds1 lctl set_param fail_val=0
12943
12944         $LFS migrate -m $MDTIDX $migrate_dir ||
12945                 error "migrate open files should failed with open files"
12946
12947         echo "Finish migration, then checking.."
12948         for file in $(find $migrate_dir); do
12949                 mdt_index=$($LFS getstripe -M $file)
12950                 [ $mdt_index == $MDTIDX ] ||
12951                         error "$file is not on MDT${MDTIDX}"
12952         done
12953
12954         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12955 }
12956 run_test 230c "check directory accessiblity if migration is failed"
12957
12958 test_230d() {
12959         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12960         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12961         local MDTIDX=1
12962         local mdt_index
12963         local migrate_dir=$DIR/$tdir/migrate_dir
12964         local i
12965         local j
12966
12967         test_mkdir $DIR/$tdir
12968         test_mkdir -i0 -c1 $migrate_dir
12969
12970         for ((i=0; i<100; i++)); do
12971                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
12972                 createmany -o $migrate_dir/dir_${i}/f 100 ||
12973                         error "create files under remote dir failed $i"
12974         done
12975
12976         $LFS migrate -m $MDTIDX $migrate_dir ||
12977                 error "migrate remote dir error"
12978
12979         echo "Finish migration, then checking.."
12980         for file in $(find $migrate_dir); do
12981                 mdt_index=$($LFS getstripe -M $file)
12982                 [ $mdt_index == $MDTIDX ] ||
12983                         error "$file is not on MDT${MDTIDX}"
12984         done
12985
12986         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12987 }
12988 run_test 230d "check migrate big directory"
12989
12990 test_230e() {
12991         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12992         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12993         local i
12994         local j
12995         local a_fid
12996         local b_fid
12997
12998         mkdir -p $DIR/$tdir
12999         mkdir $DIR/$tdir/migrate_dir
13000         mkdir $DIR/$tdir/other_dir
13001         touch $DIR/$tdir/migrate_dir/a
13002         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
13003         ls $DIR/$tdir/other_dir
13004
13005         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13006                 error "migrate dir fails"
13007
13008         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13009         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
13010
13011         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13012         [ $mdt_index == 0 ] || error "a is not on MDT0"
13013
13014         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
13015                 error "migrate dir fails"
13016
13017         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir)
13018         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
13019
13020         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13021         [ $mdt_index == 1 ] || error "a is not on MDT1"
13022
13023         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir/b)
13024         [ $mdt_index == 1 ] || error "b is not on MDT1"
13025
13026         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13027         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
13028
13029         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
13030
13031         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13032 }
13033 run_test 230e "migrate mulitple local link files"
13034
13035 test_230f() {
13036         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13037         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13038         local a_fid
13039         local ln_fid
13040
13041         mkdir -p $DIR/$tdir
13042         mkdir $DIR/$tdir/migrate_dir
13043         $LFS mkdir -i1 $DIR/$tdir/other_dir
13044         touch $DIR/$tdir/migrate_dir/a
13045         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
13046         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
13047         ls $DIR/$tdir/other_dir
13048
13049         # a should be migrated to MDT1, since no other links on MDT0
13050         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13051                 error "migrate dir fails"
13052         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13053         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
13054         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13055         [ $mdt_index == 1 ] || error "a is not on MDT1"
13056
13057         # a should stay on MDT1, because it is a mulitple link file
13058         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13059                 error "migrate dir fails"
13060         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13061         [ $mdt_index == 1 ] || error "a is not on MDT1"
13062
13063         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13064                 error "migrate dir fails"
13065
13066         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13067         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
13068         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
13069
13070         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
13071         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
13072
13073         # a should be migrated to MDT0, since no other links on MDT1
13074         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13075                 error "migrate dir fails"
13076         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13077         [ $mdt_index == 0 ] || error "a is not on MDT0"
13078
13079         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13080 }
13081 run_test 230f "migrate mulitple remote link files"
13082
13083 test_230g() {
13084         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13085         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13086
13087         mkdir -p $DIR/$tdir/migrate_dir
13088
13089         $LFS migrate -m 1000 $DIR/$tdir/migrate_dir &&
13090                 error "migrating dir to non-exist MDT succeeds"
13091         true
13092 }
13093 run_test 230g "migrate dir to non-exist MDT"
13094
13095 test_230h() {
13096         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13097         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13098         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
13099                 skip "Need MDS version at least 2.7.64" && return
13100         local mdt_index
13101
13102         mkdir -p $DIR/$tdir/migrate_dir
13103
13104         $LFS migrate -m1 $DIR &&
13105                 error "migrating mountpoint1 should fail"
13106
13107         $LFS migrate -m1 $DIR/$tdir/.. &&
13108                 error "migrating mountpoint2 should fail"
13109
13110         $LFS migrate -m1 $DIR/$tdir/migrate_dir/.. ||
13111                 error "migrating $tdir fail"
13112
13113         mdt_index=$($LFS getstripe -M $DIR/$tdir)
13114         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13115
13116         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13117         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13118
13119 }
13120 run_test 230h "migrate .. and root"
13121
13122 test_230i() {
13123         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13124         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13125
13126         mkdir -p $DIR/$tdir/migrate_dir
13127
13128         $LFS migrate -m 1 $DIR/$tdir/migrate_dir/ ||
13129                 error "migration fails with a tailing slash"
13130
13131         $LFS migrate -m 0 $DIR/$tdir/migrate_dir// ||
13132                 error "migration fails with two tailing slashes"
13133 }
13134 run_test 230i "lfs migrate -m tolerates trailing slashes"
13135
13136 test_231a()
13137 {
13138         # For simplicity this test assumes that max_pages_per_rpc
13139         # is the same across all OSCs
13140         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
13141         local bulk_size=$((max_pages * 4096))
13142
13143         mkdir -p $DIR/$tdir
13144
13145         # clear the OSC stats
13146         $LCTL set_param osc.*.stats=0 &>/dev/null
13147         stop_writeback
13148
13149         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
13150         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
13151                 oflag=direct &>/dev/null || error "dd failed"
13152
13153         sync; sleep 1; sync # just to be safe
13154         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
13155         if [ x$nrpcs != "x1" ]; then
13156                 $LCTL get_param osc.*.stats
13157                 error "found $nrpcs ost_write RPCs, not 1 as expected"
13158         fi
13159
13160         start_writeback
13161         # Drop the OSC cache, otherwise we will read from it
13162         cancel_lru_locks osc
13163
13164         # clear the OSC stats
13165         $LCTL set_param osc.*.stats=0 &>/dev/null
13166
13167         # Client reads $bulk_size.
13168         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
13169                 iflag=direct &>/dev/null || error "dd failed"
13170
13171         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
13172         if [ x$nrpcs != "x1" ]; then
13173                 $LCTL get_param osc.*.stats
13174                 error "found $nrpcs ost_read RPCs, not 1 as expected"
13175         fi
13176 }
13177 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
13178
13179 test_231b() {
13180         mkdir -p $DIR/$tdir
13181         local i
13182         for i in {0..1023}; do
13183                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
13184                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
13185                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
13186         done
13187         sync
13188 }
13189 run_test 231b "must not assert on fully utilized OST request buffer"
13190
13191 test_232() {
13192         mkdir -p $DIR/$tdir
13193         #define OBD_FAIL_LDLM_OST_LVB            0x31c
13194         $LCTL set_param fail_loc=0x31c
13195
13196         # ignore dd failure
13197         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
13198
13199         $LCTL set_param fail_loc=0
13200         umount_client $MOUNT || error "umount failed"
13201         mount_client $MOUNT || error "mount failed"
13202 }
13203 run_test 232 "failed lock should not block umount"
13204
13205 test_233a() {
13206         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
13207         { skip "Need MDS version at least 2.3.64"; return; }
13208         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
13209
13210         local fid=$($LFS path2fid $MOUNT)
13211         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13212                 error "cannot access $MOUNT using its FID '$fid'"
13213 }
13214 run_test 233a "checking that OBF of the FS root succeeds"
13215
13216 test_233b() {
13217         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
13218         { skip "Need MDS version at least 2.5.90"; return; }
13219         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
13220
13221         local fid=$($LFS path2fid $MOUNT/.lustre)
13222         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13223                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
13224
13225         fid=$($LFS path2fid $MOUNT/.lustre/fid)
13226         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13227                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
13228 }
13229 run_test 233b "checking that OBF of the FS .lustre succeeds"
13230
13231 test_234() {
13232         local p="$TMP/sanityN-$TESTNAME.parameters"
13233         save_lustre_params client "llite.*.xattr_cache" > $p
13234         lctl set_param llite.*.xattr_cache 1 ||
13235                 { skip "xattr cache is not supported"; return 0; }
13236
13237         mkdir -p $DIR/$tdir || error "mkdir failed"
13238         touch $DIR/$tdir/$tfile || error "touch failed"
13239         # OBD_FAIL_LLITE_XATTR_ENOMEM
13240         $LCTL set_param fail_loc=0x1405
13241         # output of the form: attr 2 4 44 3 fc13 x86_64
13242         V=($(IFS=".-" rpm -q attr))
13243         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
13244               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
13245                 # attr pre-2.4.44-7 had a bug with rc
13246                 # LU-3703 - SLES 11 and FC13 clients have older attr
13247                 getfattr -n user.attr $DIR/$tdir/$tfile &&
13248                         error "getfattr should have failed with ENOMEM"
13249         else
13250                 skip "LU-3703: attr version $(getfattr --version) too old"
13251         fi
13252         $LCTL set_param fail_loc=0x0
13253         rm -rf $DIR/$tdir
13254
13255         restore_lustre_params < $p
13256         rm -f $p
13257 }
13258 run_test 234 "xattr cache should not crash on ENOMEM"
13259
13260 test_235() {
13261         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
13262                 skip "Need MDS version at least 2.4.52" && return
13263         flock_deadlock $DIR/$tfile
13264         local RC=$?
13265         case $RC in
13266                 0)
13267                 ;;
13268                 124) error "process hangs on a deadlock"
13269                 ;;
13270                 *) error "error executing flock_deadlock $DIR/$tfile"
13271                 ;;
13272         esac
13273 }
13274 run_test 235 "LU-1715: flock deadlock detection does not work properly"
13275
13276 #LU-2935
13277 test_236() {
13278         check_swap_layouts_support && return 0
13279         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
13280
13281         local ref1=/etc/passwd
13282         local ref2=/etc/group
13283         local file1=$DIR/$tdir/f1
13284         local file2=$DIR/$tdir/f2
13285
13286         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
13287         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
13288         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
13289         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
13290         local fd=$(free_fd)
13291         local cmd="exec $fd<>$file2"
13292         eval $cmd
13293         rm $file2
13294         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
13295                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
13296         cmd="exec $fd>&-"
13297         eval $cmd
13298         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
13299
13300         #cleanup
13301         rm -rf $DIR/$tdir
13302 }
13303 run_test 236 "Layout swap on open unlinked file"
13304
13305 # test to verify file handle related system calls
13306 # (name_to_handle_at/open_by_handle_at)
13307 # The new system calls are supported in glibc >= 2.14.
13308
13309 test_237() {
13310         echo "Test file_handle syscalls" > $DIR/$tfile ||
13311                 error "write failed"
13312         check_fhandle_syscalls $DIR/$tfile ||
13313                 error "check_fhandle_syscalls failed"
13314 }
13315 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
13316
13317 # LU-4659 linkea consistency
13318 test_238() {
13319         local server_version=$(lustre_version_code $SINGLEMDS)
13320
13321         [[ $server_version -gt $(version_code 2.5.57) ]] ||
13322                 [[ $server_version -gt $(version_code 2.5.1) &&
13323                    $server_version -lt $(version_code 2.5.50) ]] ||
13324                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
13325
13326         touch $DIR/$tfile
13327         ln $DIR/$tfile $DIR/$tfile.lnk
13328         touch $DIR/$tfile.new
13329         mv $DIR/$tfile.new $DIR/$tfile
13330         local fid1=$($LFS path2fid $DIR/$tfile)
13331         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
13332         local path1=$($LFS fid2path $FSNAME "$fid1")
13333         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
13334         local path2=$($LFS fid2path $FSNAME "$fid2")
13335         [ $tfile.lnk == $path2 ] ||
13336                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
13337         rm -f $DIR/$tfile*
13338 }
13339 run_test 238 "Verify linkea consistency"
13340
13341 test_239() {
13342         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
13343                 skip "Need MDS version at least 2.5.60" && return
13344         local list=$(comma_list $(mdts_nodes))
13345
13346         mkdir -p $DIR/$tdir
13347         createmany -o $DIR/$tdir/f- 5000
13348         unlinkmany $DIR/$tdir/f- 5000
13349         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
13350         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
13351                         osc.*MDT*.sync_in_flight" | calc_sum)
13352         [ "$changes" -eq 0 ] || error "$changes not synced"
13353 }
13354 run_test 239 "osp_sync test"
13355
13356 test_239a() { #LU-5297
13357         touch $DIR/$tfile
13358         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
13359         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
13360         chgrp $RUNAS_GID $DIR/$tfile
13361         wait_delete_completed
13362 }
13363 run_test 239a "process invalid osp sync record correctly"
13364
13365 test_239b() { #LU-5297
13366         touch $DIR/$tfile1
13367         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
13368         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
13369         chgrp $RUNAS_GID $DIR/$tfile1
13370         wait_delete_completed
13371         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
13372         touch $DIR/$tfile2
13373         chgrp $RUNAS_GID $DIR/$tfile2
13374         wait_delete_completed
13375 }
13376 run_test 239b "process osp sync record with ENOMEM error correctly"
13377
13378 test_240() {
13379         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13380
13381         mkdir -p $DIR/$tdir
13382
13383         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
13384                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
13385         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
13386                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
13387
13388         umount_client $MOUNT || error "umount failed"
13389         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
13390         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
13391         mount_client $MOUNT || error "failed to mount client"
13392
13393         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
13394         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
13395 }
13396 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
13397
13398 test_241_bio() {
13399         for LOOP in $(seq $1); do
13400                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
13401                 cancel_lru_locks osc || true
13402         done
13403 }
13404
13405 test_241_dio() {
13406         for LOOP in $(seq $1); do
13407                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
13408                                                 iflag=direct 2>/dev/null
13409         done
13410 }
13411
13412 test_241() {
13413         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
13414         ls -la $DIR/$tfile
13415         cancel_lru_locks osc
13416         test_241_bio 1000 &
13417         PID=$!
13418         test_241_dio 1000
13419         wait $PID
13420 }
13421 run_test 241 "bio vs dio"
13422
13423 test_241b() {
13424         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
13425         ls -la $DIR/$tfile
13426         test_241_dio 1000 &
13427         PID=$!
13428         test_241_dio 1000
13429         wait $PID
13430 }
13431 run_test 241b "dio vs dio"
13432
13433 test_242() {
13434         mkdir -p $DIR/$tdir
13435         touch $DIR/$tdir/$tfile
13436
13437         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
13438         do_facet mds1 lctl set_param fail_loc=0x105
13439         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
13440
13441         do_facet mds1 lctl set_param fail_loc=0
13442         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
13443 }
13444 run_test 242 "mdt_readpage failure should not cause directory unreadable"
13445
13446 test_243()
13447 {
13448         test_mkdir -p $DIR/$tdir
13449         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
13450 }
13451 run_test 243 "various group lock tests"
13452
13453 test_244()
13454 {
13455         test_mkdir -p $DIR/$tdir
13456         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
13457         sendfile_grouplock $DIR/$tdir/$tfile || \
13458                 error "sendfile+grouplock failed"
13459         rm -rf $DIR/$tdir
13460 }
13461 run_test 244 "sendfile with group lock tests"
13462
13463 test_245() {
13464         local flagname="multi_mod_rpcs"
13465         local connect_data_name="max_mod_rpcs"
13466         local out
13467
13468         # check if multiple modify RPCs flag is set
13469         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
13470                 grep "connect_flags:")
13471         echo "$out"
13472
13473         echo "$out" | grep -qw $flagname
13474         if [ $? -ne 0 ]; then
13475                 echo "connect flag $flagname is not set"
13476                 return
13477         fi
13478
13479         # check if multiple modify RPCs data is set
13480         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
13481         echo "$out"
13482
13483         echo "$out" | grep -qw $connect_data_name ||
13484                 error "import should have connect data $connect_data_name"
13485 }
13486 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
13487
13488 test_246() { # LU-7371
13489         [ $(lustre_version_code ost1) -lt $(version_code 2.7.62) ] &&
13490                 skip "Need OST version >= 2.7.62" && return 0
13491         do_facet ost1 $LCTL set_param fail_val=4095
13492 #define OBD_FAIL_OST_READ_SIZE          0x234
13493         do_facet ost1 $LCTL set_param fail_loc=0x234
13494         $LFS setstripe $DIR/$tfile -i 0 -c 1
13495         dd if=/dev/zero of=$DIR/$tfile bs=4095 count=1 > /dev/null 2>&1
13496         cancel_lru_locks $FSNAME-OST0000
13497         dd if=$DIR/$tfile of=/dev/null bs=1048576 || error "Read failed"
13498 }
13499 run_test 246 "Read file of size 4095 should return right length"
13500
13501 test_247a() {
13502         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
13503                 grep -q subtree ||
13504                 { skip "Fileset feature is not supported"; return; }
13505
13506         local submount=${MOUNT}_$tdir
13507
13508         mkdir $MOUNT/$tdir
13509         mkdir -p $submount || error "mkdir $submount failed"
13510         FILESET="$FILESET/$tdir" mount_client $submount ||
13511                 error "mount $submount failed"
13512         echo foo > $submount/$tfile || error "write $submount/$tfile failed"
13513         [ $(cat $MOUNT/$tdir/$tfile) = "foo" ] ||
13514                 error "read $MOUNT/$tdir/$tfile failed"
13515         umount_client $submount || error "umount $submount failed"
13516         rmdir $submount
13517 }
13518 run_test 247a "mount subdir as fileset"
13519
13520 test_247b() {
13521         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
13522                 { skip "Fileset feature is not supported"; return; }
13523
13524         local submount=${MOUNT}_$tdir
13525
13526         rm -rf $MOUNT/$tdir
13527         mkdir -p $submount || error "mkdir $submount failed"
13528         SKIP_FILESET=1
13529         FILESET="$FILESET/$tdir" mount_client $submount &&
13530                 error "mount $submount should fail"
13531         rmdir $submount
13532 }
13533 run_test 247b "mount subdir that dose not exist"
13534
13535 test_247c() {
13536         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
13537                 { skip "Fileset feature is not supported"; return; }
13538
13539         local submount=${MOUNT}_$tdir
13540
13541         mkdir -p $MOUNT/$tdir/dir1
13542         mkdir -p $submount || error "mkdir $submount failed"
13543         FILESET="$FILESET/$tdir" mount_client $submount ||
13544                 error "mount $submount failed"
13545         local fid=$($LFS path2fid $MOUNT/)
13546         $LFS fid2path $submount $fid && error "fid2path should fail"
13547         umount_client $submount || error "umount $submount failed"
13548         rmdir $submount
13549 }
13550 run_test 247c "running fid2path outside root"
13551
13552 test_247d() {
13553         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
13554                 { skip "Fileset feature is not supported"; return; }
13555
13556         local submount=${MOUNT}_$tdir
13557
13558         mkdir -p $MOUNT/$tdir/dir1
13559         mkdir -p $submount || error "mkdir $submount failed"
13560         FILESET="$FILESET/$tdir" mount_client $submount ||
13561                 error "mount $submount failed"
13562         local fid=$($LFS path2fid $submount/dir1)
13563         $LFS fid2path $submount $fid || error "fid2path should succeed"
13564         umount_client $submount || error "umount $submount failed"
13565         rmdir $submount
13566 }
13567 run_test 247d "running fid2path inside root"
13568
13569 test_250() {
13570         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
13571          && skip "no 16TB file size limit on ZFS" && return
13572
13573         $SETSTRIPE -c 1 $DIR/$tfile
13574         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
13575         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
13576         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
13577         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
13578                 conv=notrunc,fsync && error "append succeeded"
13579         return 0
13580 }
13581 run_test 250 "Write above 16T limit"
13582
13583 test_251() {
13584         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
13585
13586         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
13587         #Skip once - writing the first stripe will succeed
13588         $LCTL set_param fail_loc=0xa0001407 fail_val=1
13589         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
13590                 error "short write happened"
13591
13592         $LCTL set_param fail_loc=0xa0001407 fail_val=1
13593         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
13594                 error "short read happened"
13595
13596         rm -f $DIR/$tfile
13597 }
13598 run_test 251 "Handling short read and write correctly"
13599
13600 test_252() {
13601         local tgt
13602         local dev
13603         local out
13604         local uuid
13605         local num
13606         local gen
13607
13608         if [ "$(facet_fstype ost1)" != "ldiskfs" -o \
13609              "$(facet_fstype mds1)" != "ldiskfs" ]; then
13610                 skip "can only run lr_reader on ldiskfs target"
13611                 return
13612         fi
13613
13614         # check lr_reader on OST0000
13615         tgt=ost1
13616         dev=$(facet_device $tgt)
13617         out=$(do_facet $tgt $LR_READER $dev)
13618         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
13619         echo "$out"
13620         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
13621         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
13622                 error "Invalid uuid returned by $LR_READER on target $tgt"
13623         echo -e "uuid returned by $LR_READER is '$uuid'\n"
13624
13625         # check lr_reader -c on MDT0000
13626         tgt=mds1
13627         dev=$(facet_device $tgt)
13628         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
13629                 echo "$LR_READER does not support additional options"
13630                 return 0
13631         fi
13632         out=$(do_facet $tgt $LR_READER -c $dev)
13633         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
13634         echo "$out"
13635         num=$(echo "$out" | grep -c "mdtlov")
13636         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
13637                 error "Invalid number of mdtlov clients returned by $LR_READER"
13638         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
13639
13640         # check lr_reader -cr on MDT0000
13641         out=$(do_facet $tgt $LR_READER -cr $dev)
13642         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
13643         echo "$out"
13644         echo "$out" | grep -q "^reply_data:$" ||
13645                 error "$LR_READER should have returned 'reply_data' section"
13646         num=$(echo "$out" | grep -c "client_generation")
13647         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
13648 }
13649 run_test 252 "check lr_reader tool"
13650
13651 test_254() {
13652         local cl_user
13653
13654         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13655         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13656         do_facet mds1 $LCTL get_param -n mdd.$MDT0.changelog_size ||
13657                 { skip "MDS does not support changelog_size" && return; }
13658
13659         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
13660         echo "Registered as changelog user $cl_user"
13661
13662         $LFS changelog_clear $MDT0 $cl_user 0
13663
13664         local size1=$(do_facet mds1 \
13665                       $LCTL get_param -n mdd.$MDT0.changelog_size)
13666         echo "Changelog size $size1"
13667
13668         rm -rf $DIR/$tdir
13669         $LFS mkdir -i 0 $DIR/$tdir
13670         # change something
13671         mkdir -p $DIR/$tdir/pics/2008/zachy
13672         touch $DIR/$tdir/pics/2008/zachy/timestamp
13673         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
13674         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
13675         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
13676         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
13677         rm $DIR/$tdir/pics/desktop.jpg
13678
13679         local size2=$(do_facet mds1 \
13680                       $LCTL get_param -n mdd.$MDT0.changelog_size)
13681         echo "Changelog size after work $size2"
13682
13683         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
13684
13685         if (( size2 <= size1 )); then
13686                 error "Changelog size after work should be greater than original"
13687         fi
13688         return 0
13689 }
13690 run_test 254 "Check changelog size"
13691
13692 test_256() {
13693         local cl_user
13694         local cat_sl
13695         local mdt_dev
13696
13697         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13698         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13699         [ "$(facet_fstype mds1)" != "ldiskfs" ] &&
13700                 skip "non-ldiskfs backend" && return
13701
13702         mdt_dev=$(mdsdevname 1)
13703         echo $mdt_dev
13704         cl_user=$(do_facet mds1 \
13705         "$LCTL get_param -n mdd.$MDT0.changelog_users | grep cl")
13706         if [[ -n $cl_user ]]; then
13707                 skip "active changelog user"
13708                 return
13709         fi
13710
13711         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
13712         echo "Registered as changelog user $cl_user"
13713
13714         rm -rf $DIR/$tdir
13715         mkdir -p $DIR/$tdir
13716
13717         $LFS changelog_clear $MDT0 $cl_user 0
13718
13719         # change something
13720         touch $DIR/$tdir/{1..10}
13721
13722         # stop the MDT
13723         stop mds1 || error "Fail to stop MDT."
13724
13725         # remount the MDT
13726         start mds1 $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT."
13727
13728         #after mount new plainllog is used
13729         touch $DIR/$tdir/{11..19}
13730         cat_sl=$(do_facet mds1 \
13731         "$DEBUGFS -R \\\"dump changelog_catalog cat.dmp\\\" $mdt_dev; \
13732          llog_reader cat.dmp | grep \\\"type=1064553b\\\" | wc -l")
13733
13734         if (( cat_sl != 2 )); then
13735                 do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
13736                 error "Changelog catalog has wrong number of slots $cat_sl"
13737         fi
13738
13739         $LFS changelog_clear $MDT0 $cl_user 0
13740
13741         cat_sl=$(do_facet mds1 \
13742         "$DEBUGFS -R \\\"dump changelog_catalog cat.dmp\\\" $mdt_dev; \
13743          llog_reader cat.dmp | grep \\\"type=1064553b\\\" | wc -l")
13744
13745         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
13746
13747         if (( cat_sl == 2 )); then
13748                 error "Empty plain llog was not deleted from changelog catalog"
13749         fi
13750         if (( cat_sl != 1 )); then
13751                 error "Active plain llog shouldn\`t be deleted from catalog"
13752         fi
13753 }
13754 run_test 256 "Check llog delete for empty and not full state"
13755
13756 cleanup_test_300() {
13757         trap 0
13758         umask $SAVE_UMASK
13759 }
13760 test_striped_dir() {
13761         local mdt_index=$1
13762         local stripe_count
13763         local stripe_index
13764
13765         mkdir -p $DIR/$tdir
13766
13767         SAVE_UMASK=$(umask)
13768         trap cleanup_test_300 RETURN EXIT
13769
13770         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
13771                                                 $DIR/$tdir/striped_dir ||
13772                 error "set striped dir error"
13773
13774         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
13775         [ "$mode" = "755" ] || error "expect 755 got $mode"
13776
13777         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
13778                 error "getdirstripe failed"
13779         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
13780         if [ "$stripe_count" != "2" ]; then
13781                 error "stripe_count is $stripe_count, expect 2"
13782         fi
13783
13784         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
13785         if [ "$stripe_index" != "$mdt_index" ]; then
13786                 error "stripe_index is $stripe_index, expect $mdt_index"
13787         fi
13788
13789         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13790                 error "nlink error after create striped dir"
13791
13792         mkdir $DIR/$tdir/striped_dir/a
13793         mkdir $DIR/$tdir/striped_dir/b
13794
13795         stat $DIR/$tdir/striped_dir/a ||
13796                 error "create dir under striped dir failed"
13797         stat $DIR/$tdir/striped_dir/b ||
13798                 error "create dir under striped dir failed"
13799
13800         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
13801                 error "nlink error after mkdir"
13802
13803         rmdir $DIR/$tdir/striped_dir/a
13804         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
13805                 error "nlink error after rmdir"
13806
13807         rmdir $DIR/$tdir/striped_dir/b
13808         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13809                 error "nlink error after rmdir"
13810
13811         chattr +i $DIR/$tdir/striped_dir
13812         createmany -o $DIR/$tdir/striped_dir/f 10 &&
13813                 error "immutable flags not working under striped dir!"
13814         chattr -i $DIR/$tdir/striped_dir
13815
13816         rmdir $DIR/$tdir/striped_dir ||
13817                 error "rmdir striped dir error"
13818
13819         cleanup_test_300
13820
13821         true
13822 }
13823
13824 test_300a() {
13825         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13826         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13827
13828         test_striped_dir 0 || error "failed on striped dir on MDT0"
13829         test_striped_dir 1 || error "failed on striped dir on MDT0"
13830 }
13831 run_test 300a "basic striped dir sanity test"
13832
13833 test_300b() {
13834         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13835         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13836         local i
13837         local mtime1
13838         local mtime2
13839         local mtime3
13840
13841         test_mkdir $DIR/$tdir || error "mkdir fail"
13842         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13843                 error "set striped dir error"
13844         for ((i=0; i<10; i++)); do
13845                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
13846                 sleep 1
13847                 touch $DIR/$tdir/striped_dir/file_$i ||
13848                                         error "touch error $i"
13849                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
13850                 [ $mtime1 -eq $mtime2 ] &&
13851                         error "mtime not change after create"
13852                 sleep 1
13853                 rm -f $DIR/$tdir/striped_dir/file_$i ||
13854                                         error "unlink error $i"
13855                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
13856                 [ $mtime2 -eq $mtime3 ] &&
13857                         error "mtime did not change after unlink"
13858         done
13859         true
13860 }
13861 run_test 300b "check ctime/mtime for striped dir"
13862
13863 test_300c() {
13864         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13865         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13866         local file_count
13867
13868         mkdir -p $DIR/$tdir
13869         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
13870                 error "set striped dir error"
13871
13872         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
13873                 error "chown striped dir failed"
13874
13875         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
13876                 error "create 5k files failed"
13877
13878         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
13879
13880         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
13881
13882         rm -rf $DIR/$tdir
13883 }
13884 run_test 300c "chown && check ls under striped directory"
13885
13886 test_300d() {
13887         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13888         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13889         local stripe_count
13890         local file
13891
13892         mkdir -p $DIR/$tdir
13893         $SETSTRIPE -c 2 $DIR/$tdir
13894
13895         #local striped directory
13896         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13897                 error "set striped dir error"
13898         createmany -o $DIR/$tdir/striped_dir/f 10 ||
13899                 error "create 10 files failed"
13900
13901         #remote striped directory
13902         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
13903                 error "set striped dir error"
13904         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
13905                 error "create 10 files failed"
13906
13907         for file in $(find $DIR/$tdir); do
13908                 stripe_count=$($GETSTRIPE -c $file)
13909                 [ $stripe_count -eq 2 ] ||
13910                         error "wrong stripe $stripe_count for $file"
13911         done
13912
13913         rm -rf $DIR/$tdir
13914 }
13915 run_test 300d "check default stripe under striped directory"
13916
13917 test_300e() {
13918         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13919                 skip "Need MDS version at least 2.7.55" && return
13920         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13921         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13922         local stripe_count
13923         local file
13924
13925         mkdir -p $DIR/$tdir
13926
13927         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13928                 error "set striped dir error"
13929
13930         touch $DIR/$tdir/striped_dir/a
13931         touch $DIR/$tdir/striped_dir/b
13932         touch $DIR/$tdir/striped_dir/c
13933
13934         mkdir $DIR/$tdir/striped_dir/dir_a
13935         mkdir $DIR/$tdir/striped_dir/dir_b
13936         mkdir $DIR/$tdir/striped_dir/dir_c
13937
13938         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
13939                 error "set striped dir under striped dir error"
13940
13941         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
13942                 error "set striped dir under striped dir error"
13943
13944         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
13945                 error "set striped dir under striped dir error"
13946
13947         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
13948                 error "rename dir under striped dir fails"
13949
13950         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
13951                 error "rename dir under different stripes fails"
13952
13953         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
13954                 error "rename file under striped dir should succeed"
13955
13956         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
13957                 error "rename dir under striped dir should succeed"
13958
13959         rm -rf $DIR/$tdir
13960 }
13961 run_test 300e "check rename under striped directory"
13962
13963 test_300f() {
13964         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13965                 skip "Need MDS version at least 2.7.55" && return
13966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13967         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13968         local stripe_count
13969         local file
13970
13971         rm -rf $DIR/$tdir
13972         mkdir -p $DIR/$tdir
13973
13974         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13975                 error "set striped dir error"
13976
13977         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
13978                 error "set striped dir error"
13979
13980         touch $DIR/$tdir/striped_dir/a
13981         mkdir $DIR/$tdir/striped_dir/dir_a
13982         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
13983                 error "create striped dir under striped dir fails"
13984
13985         touch $DIR/$tdir/striped_dir1/b
13986         mkdir $DIR/$tdir/striped_dir1/dir_b
13987         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
13988                 error "create striped dir under striped dir fails"
13989
13990         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
13991                 error "rename dir under different striped dir should fail"
13992
13993         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
13994                 error "rename striped dir under diff striped dir should fail"
13995
13996         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
13997                 error "rename file under diff striped dirs fails"
13998
13999         rm -rf $DIR/$tdir
14000 }
14001 run_test 300f "check rename cross striped directory"
14002
14003 test_300_check_default_striped_dir()
14004 {
14005         local dirname=$1
14006         local default_count=$2
14007         local default_index=$3
14008         local stripe_count
14009         local stripe_index
14010         local dir_stripe_index
14011         local dir
14012
14013         echo "checking $dirname $default_count $default_index"
14014         $LFS setdirstripe -D -c $default_count -i $default_index \
14015                                 -t all_char $DIR/$tdir/$dirname ||
14016                 error "set default stripe on striped dir error"
14017         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
14018         [ $stripe_count -eq $default_count ] ||
14019                 error "expect $default_count get $stripe_count for $dirname"
14020
14021         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
14022         [ $stripe_index -eq $default_index ] ||
14023                 error "expect $default_index get $stripe_index for $dirname"
14024
14025         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
14026                                                 error "create dirs failed"
14027
14028         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
14029         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
14030         for dir in $(find $DIR/$tdir/$dirname/*); do
14031                 stripe_count=$($LFS getdirstripe -c $dir)
14032                 [ $stripe_count -eq $default_count ] ||
14033                 [ $stripe_count -eq 0 -o $default_count -eq 1 ] ||
14034                 error "stripe count $default_count != $stripe_count for $dir"
14035
14036                 stripe_index=$($LFS getdirstripe -i $dir)
14037                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
14038                         error "$stripe_index != $default_index for $dir"
14039
14040                 #check default stripe
14041                 stripe_count=$($LFS getdirstripe -D -c $dir)
14042                 [ $stripe_count -eq $default_count ] ||
14043                 error "default count $default_count != $stripe_count for $dir"
14044
14045                 stripe_index=$($LFS getdirstripe -D -i $dir)
14046                 [ $stripe_index -eq $default_index ] ||
14047                 error "default index $default_index != $stripe_index for $dir"
14048         done
14049         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
14050 }
14051
14052 test_300g() {
14053         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14054                 skip "Need MDS version at least 2.7.55" && return
14055         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14056         local dir
14057         local stripe_count
14058         local stripe_index
14059
14060         mkdir $DIR/$tdir
14061         mkdir $DIR/$tdir/normal_dir
14062
14063         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
14064         test_300_check_default_striped_dir normal_dir 1 0
14065         test_300_check_default_striped_dir normal_dir 2 1
14066         test_300_check_default_striped_dir normal_dir 2 -1
14067
14068         #delete default stripe information
14069         echo "delete default stripeEA"
14070         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
14071                 error "set default stripe on striped dir error"
14072
14073         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
14074         for dir in $(find $DIR/$tdir/normal_dir/*); do
14075                 stripe_count=$($LFS getdirstripe -c $dir)
14076                 [ $stripe_count -eq 0 ] ||
14077                         error "expect 1 get $stripe_count for $dir"
14078                 stripe_index=$($LFS getdirstripe -i $dir)
14079                 [ $stripe_index -eq 0 ] ||
14080                         error "expect 0 get $stripe_index for $dir"
14081         done
14082 }
14083 run_test 300g "check default striped directory for normal directory"
14084
14085 test_300h() {
14086         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14087                 skip "Need MDS version at least 2.7.55" && return
14088         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14089         local dir
14090         local stripe_count
14091
14092         mkdir $DIR/$tdir
14093         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
14094                                         $DIR/$tdir/striped_dir ||
14095                 error "set striped dir error"
14096
14097         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
14098         test_300_check_default_striped_dir striped_dir 1 0
14099         test_300_check_default_striped_dir striped_dir 2 1
14100         test_300_check_default_striped_dir striped_dir 2 -1
14101
14102         #delete default stripe information
14103         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
14104                 error "set default stripe on striped dir error"
14105
14106         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
14107         for dir in $(find $DIR/$tdir/striped_dir/*); do
14108                 stripe_count=$($LFS getdirstripe -c $dir)
14109                 [ $stripe_count -eq 0 ] ||
14110                         error "expect 1 get $stripe_count for $dir"
14111         done
14112 }
14113 run_test 300h "check default striped directory for striped directory"
14114
14115 test_300i() {
14116         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14117                 skip "Need MDS version at least 2.7.55" && return
14118         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14119         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14120         local stripe_count
14121         local file
14122
14123         mkdir $DIR/$tdir
14124
14125         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
14126                 error "set striped dir error"
14127
14128         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
14129                 error "create files under striped dir failed"
14130
14131         # unfortunately, we need to umount to clear dir layout cache for now
14132         # once we fully implement dir layout, we can drop this
14133         umount_client $MOUNT || error "umount failed"
14134         mount_client $MOUNT || error "mount failed"
14135
14136         #set the stripe to be unknown hash type
14137         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
14138         $LCTL set_param fail_loc=0x1901
14139         for ((i = 0; i < 10; i++)); do
14140                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
14141                         error "stat f-$i failed"
14142                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
14143         done
14144
14145         touch $DIR/$tdir/striped_dir/f0 &&
14146                 error "create under striped dir with unknown hash should fail"
14147
14148         $LCTL set_param fail_loc=0
14149
14150         umount_client $MOUNT || error "umount failed"
14151         mount_client $MOUNT || error "mount failed"
14152
14153         return 0
14154 }
14155 run_test 300i "client handle unknown hash type striped directory"
14156
14157 test_300j() {
14158         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14159         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14160                 skip "Need MDS version at least 2.7.55" && return
14161         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14162         local stripe_count
14163         local file
14164
14165         mkdir $DIR/$tdir
14166
14167         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
14168         $LCTL set_param fail_loc=0x1702
14169         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
14170                 error "set striped dir error"
14171
14172         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
14173                 error "create files under striped dir failed"
14174
14175         $LCTL set_param fail_loc=0
14176
14177         rm -rf $DIR/$tdir || error "unlink striped dir fails"
14178
14179         return 0
14180 }
14181 run_test 300j "test large update record"
14182
14183 test_300k() {
14184         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14185                 skip "Need MDS version at least 2.7.55" && return
14186         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14187         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14188         local stripe_count
14189         local file
14190
14191         mkdir $DIR/$tdir
14192
14193         #define OBD_FAIL_LARGE_STRIPE   0x1703
14194         $LCTL set_param fail_loc=0x1703
14195         $LFS setdirstripe -i 0 -c512 $DIR/$tdir/striped_dir ||
14196                 error "set striped dir error"
14197         $LCTL set_param fail_loc=0
14198
14199         $LFS getdirstripe $DIR/$tdir/striped_dir ||
14200                 error "getstripeddir fails"
14201         rm -rf $DIR/$tdir/striped_dir ||
14202                 error "unlink striped dir fails"
14203
14204         return 0
14205 }
14206 run_test 300k "test large striped directory"
14207
14208 test_300l() {
14209         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14210                 skip "Need MDS version at least 2.7.55" && return
14211         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14212         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14213         local stripe_index
14214
14215         test_mkdir -p $DIR/$tdir/striped_dir
14216         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
14217                         error "chown $RUNAS_ID failed"
14218         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
14219                 error "set default striped dir failed"
14220
14221         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
14222         $LCTL set_param fail_loc=0x80000158
14223         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
14224
14225         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
14226         [ $stripe_index -eq 1 ] ||
14227                 error "expect 1 get $stripe_index for $dir"
14228 }
14229 run_test 300l "non-root user to create dir under striped dir with stale layout"
14230
14231 test_300m() {
14232         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14233                 skip "Need MDS version at least 2.7.55" && return
14234         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14235         [ $MDSCOUNT -ge 2 ] && skip "Only for single MDT" && return
14236
14237         mkdir -p $DIR/$tdir/striped_dir
14238         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
14239                 error "set default stripes dir error"
14240
14241         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
14242
14243         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
14244         [ $stripe_count -eq 0 ] ||
14245                         error "expect 0 get $stripe_count for a"
14246
14247         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
14248                 error "set default stripes dir error"
14249
14250         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
14251
14252         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
14253         [ $stripe_count -eq 0 ] ||
14254                         error "expect 0 get $stripe_count for b"
14255
14256         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
14257                 error "set default stripes dir error"
14258
14259         mkdir $DIR/$tdir/striped_dir/c &&
14260                 error "default stripe_index is invalid, mkdir c should fails"
14261
14262         rm -rf $DIR/$tdir || error "rmdir fails"
14263 }
14264 run_test 300m "setstriped directory on single MDT FS"
14265
14266 cleanup_300n() {
14267         local list=$(comma_list $(mdts_nodes))
14268
14269         trap 0
14270         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
14271 }
14272
14273 test_300n() {
14274         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14275                 skip "Need MDS version at least 2.7.55" && return
14276         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14277         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14278         local stripe_index
14279         local list=$(comma_list $(mdts_nodes))
14280
14281         trap cleanup_300n RETURN EXIT
14282         mkdir -p $DIR/$tdir
14283         chmod 777 $DIR/$tdir
14284         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
14285                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
14286                 error "create striped dir succeeds with gid=0"
14287
14288         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
14289         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
14290                 error "create striped dir fails with gid=-1"
14291
14292         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
14293         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
14294                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
14295                 error "set default striped dir succeeds with gid=0"
14296
14297
14298         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
14299         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
14300                 error "set default striped dir fails with gid=-1"
14301
14302
14303         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
14304         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
14305                                         error "create test_dir fails"
14306         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
14307                                         error "create test_dir1 fails"
14308         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
14309                                         error "create test_dir2 fails"
14310         cleanup_300n
14311 }
14312 run_test 300n "non-root user to create dir under striped dir with default EA"
14313
14314 test_300o() {
14315         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14316                 skip "Need MDS version at least 2.7.55" && return
14317         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14318         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14319         local numfree1
14320         local numfree2
14321
14322         mkdir -p $DIR/$tdir
14323
14324         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
14325         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
14326         if [ $numfree1 -lt 66000 -o $numfree2 -lt 66000 ]; then
14327                 skip "not enough free inodes $numfree1 $numfree2"
14328                 return
14329         fi
14330
14331         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
14332         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
14333         if [ $numfree1 -lt 300000 -o $numfree2 -lt 300000 ]; then
14334                 skip "not enough free space $numfree1 $numfree2"
14335                 return
14336         fi
14337
14338         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
14339                 error "setdirstripe fails"
14340
14341         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
14342                 error "create dirs fails"
14343
14344         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
14345         ls $DIR/$tdir/striped_dir > /dev/null ||
14346                 error "ls striped dir fails"
14347         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
14348                 error "unlink big striped dir fails"
14349 }
14350 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
14351
14352 test_300p() {
14353         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14354         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14355
14356         mkdir -p $DIR/$tdir
14357
14358         #define OBD_FAIL_OUT_ENOSPC     0x1704
14359         do_facet mds2 lctl set_param fail_loc=0x80001704
14360         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 &&
14361                         error "create striped directory should fail"
14362
14363         [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
14364
14365         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir
14366         true
14367 }
14368 run_test 300p "create striped directory without space"
14369
14370 test_300q() {
14371         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14372         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14373
14374         local fd=$(free_fd)
14375         local cmd="exec $fd<$tdir"
14376         cd $DIR
14377         $LFS mkdir -c $MDSCOUNT $tdir || error "create $tdir fails"
14378         eval $cmd
14379         cmd="exec $fd<&-"
14380         trap "eval $cmd" EXIT
14381         cd $tdir || error "cd $tdir fails"
14382         rmdir  ../$tdir || error "rmdir $tdir fails"
14383         mkdir local_dir && error "create dir succeeds"
14384         $LFS setdirstripe -i1 remote_dir && error "create remote dir succeeds"
14385         eval $cmd
14386         return 0
14387 }
14388 run_test 300q "create remote directory under orphan directory"
14389
14390 prepare_remote_file() {
14391         mkdir $DIR/$tdir/src_dir ||
14392                 error "create remote source failed"
14393
14394         cp /etc/hosts $DIR/$tdir/src_dir/a || error
14395         touch $DIR/$tdir/src_dir/a
14396
14397         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
14398                 error "create remote target dir failed"
14399
14400         touch $DIR/$tdir/tgt_dir/b
14401
14402         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
14403                 error "rename dir cross MDT failed!"
14404
14405         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
14406                 error "src_child still exists after rename"
14407
14408         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
14409                 error "missing file(a) after rename"
14410
14411         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
14412                 error "diff after rename"
14413 }
14414
14415 test_310a() {
14416         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
14417         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14418         local remote_file=$DIR/$tdir/tgt_dir/b
14419
14420         mkdir -p $DIR/$tdir
14421
14422         prepare_remote_file || error "prepare remote file failed"
14423
14424         #open-unlink file
14425         $OPENUNLINK $remote_file $remote_file || error
14426         $CHECKSTAT -a $remote_file || error
14427 }
14428 run_test 310a "open unlink remote file"
14429
14430 test_310b() {
14431         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
14432         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14433         local remote_file=$DIR/$tdir/tgt_dir/b
14434
14435         mkdir -p $DIR/$tdir
14436
14437         prepare_remote_file || error "prepare remote file failed"
14438
14439         ln $remote_file $DIR/$tfile || error "link failed for remote file"
14440         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
14441         $CHECKSTAT -t file $remote_file || error "check file failed"
14442 }
14443 run_test 310b "unlink remote file with multiple links while open"
14444
14445 test_310c() {
14446         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
14447         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14448         local remote_file=$DIR/$tdir/tgt_dir/b
14449
14450         mkdir -p $DIR/$tdir
14451
14452         prepare_remote_file || error "prepare remote file failed"
14453
14454         ln $remote_file $DIR/$tfile || error "link failed for remote file"
14455         multiop_bg_pause $remote_file O_uc ||
14456                         error "mulitop failed for remote file"
14457         MULTIPID=$!
14458         $MULTIOP $DIR/$tfile Ouc
14459         kill -USR1 $MULTIPID
14460         wait $MULTIPID
14461 }
14462 run_test 310c "open-unlink remote file with multiple links"
14463
14464 test_400a() { # LU-1606, was conf-sanity test_74
14465         local extra_flags=''
14466         local out=$TMP/$tfile
14467         local prefix=/usr/include/lustre
14468         local prog
14469
14470         if ! which $CC > /dev/null 2>&1; then
14471                 skip_env "$CC is not installed"
14472                 return 0
14473         fi
14474
14475         if ! [[ -d $prefix ]]; then
14476                 # Assume we're running in tree and fixup the include path.
14477                 extra_flags+=" -I$LUSTRE/../libcfs/include"
14478                 extra_flags+=" -I$LUSTRE/include"
14479                 extra_flags+=" -L$LUSTRE/utils"
14480         fi
14481
14482         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
14483                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
14484                         error "client api broken"
14485         done
14486 }
14487 run_test 400a "Lustre client api program can compile and link"
14488
14489 test_400b() { # LU-1606, LU-5011
14490         local header
14491         local out=$TMP/$tfile
14492         local prefix=/usr/include/lustre
14493
14494         # We use a hard coded prefix so that this test will not fail
14495         # when run in tree. There are headers in lustre/include/lustre/
14496         # that are not packaged (like lustre_idl.h) and have more
14497         # complicated include dependencies (like config.h and lnet/types.h).
14498         # Since this test about correct packaging we just skip them when
14499         # they don't exist (see below) rather than try to fixup cppflags.
14500
14501         if ! which $CC > /dev/null 2>&1; then
14502                 skip_env "$CC is not installed"
14503                 return 0
14504         fi
14505
14506         for header in $prefix/*.h; do
14507                 if ! [[ -f "$header" ]]; then
14508                         continue
14509                 fi
14510
14511                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
14512                         continue # liblustreapi.h is deprecated.
14513                 fi
14514
14515                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
14516                         error "cannot compile '$header'"
14517         done
14518 }
14519 run_test 400b "packaged headers can be compiled"
14520
14521 test_401a() { #LU-7437
14522         #count the number of parameters by "list_param -R"
14523         local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
14524         #count the number of parameters by listing proc files
14525         local procs=$(find -L $proc_dirs -mindepth 1 -printf '%P\n' 2>/dev/null|
14526                       sort -u | wc -l)
14527
14528         [ $params -eq $procs ] ||
14529                 error "found $params parameters vs. $procs proc files"
14530
14531         # test the list_param -D option only returns directories
14532         params=$($LCTL list_param -R -D '*' 2>/dev/null | wc -l)
14533         #count the number of parameters by listing proc directories
14534         procs=$(find -L $proc_dirs -mindepth 1 -type d -printf '%P\n' 2>/dev/null |
14535                 sort -u | wc -l)
14536
14537         [ $params -eq $procs ] ||
14538                 error "found $params parameters vs. $procs proc files"
14539 }
14540 run_test 401a "Verify if 'lctl list_param -R' can list parameters recursively"
14541
14542 test_401b() {
14543         local save=$($LCTL get_param -n jobid_var)
14544         local tmp=testing
14545
14546         $LCTL set_param foo=bar jobid_var=$tmp bar=baz &&
14547                 error "no error returned when setting bad parameters"
14548
14549         local jobid_new=$($LCTL get_param -n foe jobid_var baz)
14550         [[ "$jobid_new" == "$tmp" ]] || error "jobid tmp $jobid_new != $tmp"
14551
14552         $LCTL set_param -n fog=bam jobid_var=$save bat=fog
14553         local jobid_old=$($LCTL get_param -n foe jobid_var bag)
14554         [[ "$jobid_old" == "$save" ]] || error "jobid new $jobid_old != $save"
14555 }
14556 run_test 401b "Verify 'lctl {get,set}_param' continue after error"
14557
14558 test_401c() {
14559         local jobid_var_old=$($LCTL get_param -n jobid_var)
14560         local jobid_var_new
14561
14562         $LCTL set_param jobid_var= &&
14563                 error "no error returned for 'set_param a='"
14564
14565         jobid_var_new=$($LCTL get_param -n jobid_var)
14566         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
14567                 error "jobid_var was changed by setting without value"
14568
14569         $LCTL set_param jobid_var &&
14570                 error "no error returned for 'set_param a'"
14571
14572         jobid_var_new=$($LCTL get_param -n jobid_var)
14573         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
14574                 error "jobid_var was changed by setting without value"
14575 }
14576 run_test 401c "Verify 'lctl set_param' without value fails in either format."
14577
14578 test_401d() {
14579         local jobid_var_old=$($LCTL get_param -n jobid_var)
14580         local jobid_var_new
14581         local new_value="foo=bar"
14582
14583         $LCTL set_param jobid_var=$new_value ||
14584                 error "'set_param a=b' did not accept a value containing '='"
14585
14586         jobid_var_new=$($LCTL get_param -n jobid_var)
14587         [[ "$jobid_var_new" == "$new_value" ]] ||
14588                 error "'set_param a=b' failed on a value containing '='"
14589
14590         # Reset the jobid_var to test the other format
14591         $LCTL set_param jobid_var=$jobid_var_old
14592         jobid_var_new=$($LCTL get_param -n jobid_var)
14593         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
14594                 error "failed to reset jobid_var"
14595
14596         $LCTL set_param jobid_var $new_value ||
14597                 error "'set_param a b' did not accept a value containing '='"
14598
14599         jobid_var_new=$($LCTL get_param -n jobid_var)
14600         [[ "$jobid_var_new" == "$new_value" ]] ||
14601                 error "'set_param a b' failed on a value containing '='"
14602
14603         $LCTL set_param jobid_var $jobid_var_old
14604         jobid_var_new=$($LCTL get_param -n jobid_var)
14605         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
14606                 error "failed to reset jobid_var"
14607 }
14608 run_test 401d "Verify 'lctl set_param' accepts values containing '='"
14609
14610 test_402() {
14611         $LFS setdirstripe -i 0 $DIR/$tdir || error "setdirstripe -i 0 failed"
14612 #define OBD_FAIL_MDS_FLD_LOOKUP 0x15c
14613         do_facet mds1 "lctl set_param fail_loc=0x8000015c"
14614         touch $DIR/$tdir/$tfile && error "touch should fail with ENOENT" ||
14615                 echo "Touch failed - OK"
14616 }
14617 run_test 402 "Return ENOENT to lod_generate_and_set_lovea"
14618
14619 test_403() {
14620         local file1=$DIR/$tfile.1
14621         local file2=$DIR/$tfile.2
14622         local tfile=$TMP/$tfile
14623
14624         rm -f $file1 $file2 $tfile
14625
14626         touch $file1
14627         ln $file1 $file2
14628
14629         # 30 sec OBD_TIMEOUT in ll_getattr()
14630         # right before populating st_nlink
14631         $LCTL set_param fail_loc=0x80001409
14632         stat -c %h $file1 > $tfile &
14633
14634         # create an alias, drop all locks and reclaim the dentry
14635         < $file2
14636         cancel_lru_locks mdc
14637         cancel_lru_locks osc
14638         sysctl -w vm.drop_caches=2
14639
14640         wait
14641
14642         [ `cat $tfile` -gt 0 ] || error "wrong nlink count: `cat $tfile`"
14643
14644         rm -f $tfile $file1 $file2
14645 }
14646 run_test 403 "i_nlink should not drop to zero due to aliasing"
14647
14648 #
14649 # tests that do cleanup/setup should be run at the end
14650 #
14651
14652 test_900() {
14653         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14654         local ls
14655         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
14656         $LCTL set_param fail_loc=0x903
14657
14658         cancel_lru_locks MGC
14659
14660         FAIL_ON_ERROR=true cleanup
14661         FAIL_ON_ERROR=true setup
14662 }
14663 run_test 900 "umount should not race with any mgc requeue thread"
14664
14665 complete $SECONDS
14666 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
14667 check_and_cleanup_lustre
14668 if [ "$I_MOUNTED" != "yes" ]; then
14669         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
14670 fi
14671 exit_status