Whamcloud - gitweb
2174b5db80ec1366eefd767fc768356600b9f67f
[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         [ $(lustre_version_code client) -lt $(version_code 2.5.57) ] &&
2044                 skip "client does not have LU-3338 fix" && return
2045
2046         # 72 bytes is the minimum space required to store striping
2047         # information for a file striped across one OST:
2048         # (sizeof(struct lov_user_md_v3) +
2049         #  sizeof(struct lov_user_ost_data_v1))
2050         local min_easize=72
2051         $LCTL set_param -n llite.*.default_easize $min_easize ||
2052                 error "lctl set_param failed"
2053         local easize=$($LCTL get_param -n llite.*.default_easize)
2054
2055         [ $easize -eq $min_easize ] ||
2056                 error "failed to set default_easize"
2057
2058         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2059                 error "setstripe failed"
2060         cat $DIR/$tfile
2061         rm $DIR/$tfile
2062
2063         easize=$($LCTL get_param -n llite.*.default_easize)
2064
2065         [ $easize -gt $min_easize ] ||
2066                 error "default_easize not updated"
2067 }
2068 run_test 27E "check that default extended attribute size properly increases"
2069
2070 # createtest also checks that device nodes are created and
2071 # then visible correctly (#2091)
2072 test_28() { # bug 2091
2073         test_mkdir $DIR/d28
2074         $CREATETEST $DIR/d28/ct || error
2075 }
2076 run_test 28 "create/mknod/mkdir with bad file types ============"
2077
2078 test_29() {
2079         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
2080         cancel_lru_locks mdc
2081         test_mkdir $DIR/d29
2082         touch $DIR/d29/foo
2083         log 'first d29'
2084         ls -l $DIR/d29
2085
2086         declare -i LOCKCOUNTORIG=0
2087         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2088                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2089         done
2090         [ $LOCKCOUNTORIG -eq 0 ] && error "No mdc lock count" && return 1
2091
2092         declare -i LOCKUNUSEDCOUNTORIG=0
2093         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2094                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2095         done
2096
2097         log 'second d29'
2098         ls -l $DIR/d29
2099         log 'done'
2100
2101         declare -i LOCKCOUNTCURRENT=0
2102         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2103                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2104         done
2105
2106         declare -i LOCKUNUSEDCOUNTCURRENT=0
2107         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2108                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2109         done
2110
2111         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2112                 $LCTL set_param -n ldlm.dump_namespaces ""
2113                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2114                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2115                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2116                 return 2
2117         fi
2118         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2119                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2120                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2121                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2122                 return 3
2123         fi
2124 }
2125 run_test 29 "IT_GETATTR regression  ============================"
2126
2127 test_30a() { # was test_30
2128         cp $(which ls) $DIR || cp /bin/ls $DIR
2129         $DIR/ls / || error
2130         rm $DIR/ls
2131 }
2132 run_test 30a "execute binary from Lustre (execve) =============="
2133
2134 test_30b() {
2135         cp `which ls` $DIR || cp /bin/ls $DIR
2136         chmod go+rx $DIR/ls
2137         $RUNAS $DIR/ls / || error
2138         rm $DIR/ls
2139 }
2140 run_test 30b "execute binary from Lustre as non-root ==========="
2141
2142 test_30c() { # b=22376
2143         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2144         cp `which ls` $DIR || cp /bin/ls $DIR
2145         chmod a-rw $DIR/ls
2146         cancel_lru_locks mdc
2147         cancel_lru_locks osc
2148         $RUNAS $DIR/ls / || error
2149         rm -f $DIR/ls
2150 }
2151 run_test 30c "execute binary from Lustre without read perms ===="
2152
2153 test_31a() {
2154         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2155         $CHECKSTAT -a $DIR/f31 || error
2156 }
2157 run_test 31a "open-unlink file =================================="
2158
2159 test_31b() {
2160         touch $DIR/f31 || error
2161         ln $DIR/f31 $DIR/f31b || error
2162         $MULTIOP $DIR/f31b Ouc || error
2163         $CHECKSTAT -t file $DIR/f31 || error
2164 }
2165 run_test 31b "unlink file with multiple links while open ======="
2166
2167 test_31c() {
2168         touch $DIR/f31 || error
2169         ln $DIR/f31 $DIR/f31c || error
2170         multiop_bg_pause $DIR/f31 O_uc || return 1
2171         MULTIPID=$!
2172         $MULTIOP $DIR/f31c Ouc
2173         kill -USR1 $MULTIPID
2174         wait $MULTIPID
2175 }
2176 run_test 31c "open-unlink file with multiple links ============="
2177
2178 test_31d() {
2179         opendirunlink $DIR/d31d $DIR/d31d || error
2180         $CHECKSTAT -a $DIR/d31d || error
2181 }
2182 run_test 31d "remove of open directory ========================="
2183
2184 test_31e() { # bug 2904
2185         openfilleddirunlink $DIR/d31e || error
2186 }
2187 run_test 31e "remove of open non-empty directory ==============="
2188
2189 test_31f() { # bug 4554
2190         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2191         set -vx
2192         test_mkdir $DIR/d31f
2193         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2194         cp /etc/hosts $DIR/d31f
2195         ls -l $DIR/d31f
2196         $GETSTRIPE $DIR/d31f/hosts
2197         multiop_bg_pause $DIR/d31f D_c || return 1
2198         MULTIPID=$!
2199
2200         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2201         test_mkdir $DIR/d31f
2202         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2203         cp /etc/hosts $DIR/d31f
2204         ls -l $DIR/d31f
2205         $GETSTRIPE $DIR/d31f/hosts
2206         multiop_bg_pause $DIR/d31f D_c || return 1
2207         MULTIPID2=$!
2208
2209         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2210         wait $MULTIPID || error "first opendir $MULTIPID failed"
2211
2212         sleep 6
2213
2214         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2215         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2216         set +vx
2217 }
2218 run_test 31f "remove of open directory with open-unlink file ==="
2219
2220 test_31g() {
2221         echo "-- cross directory link --"
2222         test_mkdir -c1 $DIR/${tdir}ga
2223         test_mkdir -c1 $DIR/${tdir}gb
2224         touch $DIR/${tdir}ga/f
2225         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2226         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2227         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2228         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2229         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2230 }
2231 run_test 31g "cross directory link==============="
2232
2233 test_31h() {
2234         echo "-- cross directory link --"
2235         test_mkdir -c1 $DIR/${tdir}
2236         test_mkdir -c1 $DIR/${tdir}/dir
2237         touch $DIR/${tdir}/f
2238         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2239         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2240         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2241         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2242         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2243 }
2244 run_test 31h "cross directory link under child==============="
2245
2246 test_31i() {
2247         echo "-- cross directory link --"
2248         test_mkdir -c1 $DIR/$tdir
2249         test_mkdir -c1 $DIR/$tdir/dir
2250         touch $DIR/$tdir/dir/f
2251         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2252         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2253         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2254         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2255         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2256 }
2257 run_test 31i "cross directory link under parent==============="
2258
2259 test_31j() {
2260         test_mkdir -c1 -p $DIR/$tdir
2261         test_mkdir -c1 -p $DIR/$tdir/dir1
2262         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2263         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2264         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2265         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2266         return 0
2267 }
2268 run_test 31j "link for directory==============="
2269
2270 test_31k() {
2271         test_mkdir -c1 -p $DIR/$tdir
2272         touch $DIR/$tdir/s
2273         touch $DIR/$tdir/exist
2274         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2275         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2276         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2277         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2278         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2279         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2280         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2281         return 0
2282 }
2283 run_test 31k "link to file: the same, non-existing, dir==============="
2284
2285 test_31m() {
2286         mkdir $DIR/d31m
2287         touch $DIR/d31m/s
2288         mkdir $DIR/d31m2
2289         touch $DIR/d31m2/exist
2290         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2291         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2292         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2293         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2294         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2295         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2296         return 0
2297 }
2298 run_test 31m "link to file: the same, non-existing, dir==============="
2299
2300 test_31n() {
2301         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2302         nlink=$(stat --format=%h $DIR/$tfile)
2303         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2304         local fd=$(free_fd)
2305         local cmd="exec $fd<$DIR/$tfile"
2306         eval $cmd
2307         cmd="exec $fd<&-"
2308         trap "eval $cmd" EXIT
2309         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2310         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2311         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2312         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2313         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2314         eval $cmd
2315 }
2316 run_test 31n "check link count of unlinked file"
2317
2318 link_one() {
2319         local TEMPNAME=$(mktemp $1_XXXXXX)
2320         mlink $TEMPNAME $1 2> /dev/null &&
2321                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2322         munlink $TEMPNAME
2323 }
2324
2325 test_31o() { # LU-2901
2326         test_mkdir -p $DIR/$tdir
2327         for LOOP in $(seq 100); do
2328                 rm -f $DIR/$tdir/$tfile*
2329                 for THREAD in $(seq 8); do
2330                         link_one $DIR/$tdir/$tfile.$LOOP &
2331                 done
2332                 wait
2333                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2334                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2335                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2336                         break || true
2337         done
2338 }
2339 run_test 31o "duplicate hard links with same filename"
2340
2341 test_31p() {
2342         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2343
2344         test_mkdir $DIR/$tdir
2345         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2346         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2347
2348         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2349                 error "open unlink test1 failed"
2350         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2351                 error "open unlink test2 failed"
2352
2353         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2354                 error "test1 still exists"
2355         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2356                 error "test2 still exists"
2357 }
2358 run_test 31p "remove of open striped directory"
2359
2360 cleanup_test32_mount() {
2361         trap 0
2362         $UMOUNT $DIR/$tdir/ext2-mountpoint
2363 }
2364
2365 test_32a() {
2366         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2367         echo "== more mountpoints and symlinks ================="
2368         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2369         trap cleanup_test32_mount EXIT
2370         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2371         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2372         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2373         cleanup_test32_mount
2374 }
2375 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2376
2377 test_32b() {
2378         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2379         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2380         trap cleanup_test32_mount EXIT
2381         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2382         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2383         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2384         cleanup_test32_mount
2385 }
2386 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2387
2388 test_32c() {
2389         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2390         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2391         trap cleanup_test32_mount EXIT
2392         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2393         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2394         test_mkdir -p $DIR/$tdir/d2/test_dir
2395         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2396         cleanup_test32_mount
2397 }
2398 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2399
2400 test_32d() {
2401         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2402         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2403         trap cleanup_test32_mount EXIT
2404         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2405         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2406         test_mkdir -p $DIR/$tdir/d2/test_dir
2407         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2408         cleanup_test32_mount
2409 }
2410 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2411
2412 test_32e() {
2413         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2414         test_mkdir -p $DIR/d32e/tmp
2415         TMP_DIR=$DIR/d32e/tmp
2416         ln -s $DIR/d32e $TMP_DIR/symlink11
2417         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2418         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2419         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2420 }
2421 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2422
2423 test_32f() {
2424         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2425         test_mkdir -p $DIR/d32f/tmp
2426         TMP_DIR=$DIR/d32f/tmp
2427         ln -s $DIR/d32f $TMP_DIR/symlink11
2428         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2429         ls $DIR/d32f/tmp/symlink11  || error
2430         ls $DIR/d32f/symlink01 || error
2431 }
2432 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2433
2434 test_32g() {
2435         TMP_DIR=$DIR/$tdir/tmp
2436         test_mkdir -p $DIR/$tdir/tmp
2437         test_mkdir $DIR/${tdir}2
2438         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2439         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2440         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2441         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2442         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2443         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2444 }
2445 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2446
2447 test_32h() {
2448         rm -fr $DIR/$tdir $DIR/${tdir}2
2449         TMP_DIR=$DIR/$tdir/tmp
2450         test_mkdir -p $DIR/$tdir/tmp
2451         test_mkdir $DIR/${tdir}2
2452         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2453         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2454         ls $TMP_DIR/symlink12 || error
2455         ls $DIR/$tdir/symlink02  || error
2456 }
2457 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2458
2459 test_32i() {
2460         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2461         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2462         trap cleanup_test32_mount EXIT
2463         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2464         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2465         touch $DIR/$tdir/test_file
2466         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2467         cleanup_test32_mount
2468 }
2469 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2470
2471 test_32j() {
2472         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2473         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2474         trap cleanup_test32_mount EXIT
2475         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2476         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2477         touch $DIR/$tdir/test_file
2478         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2479         cleanup_test32_mount
2480 }
2481 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2482
2483 test_32k() {
2484         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2485         rm -fr $DIR/$tdir
2486         trap cleanup_test32_mount EXIT
2487         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2488         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2489         test_mkdir -p $DIR/$tdir/d2
2490         touch $DIR/$tdir/d2/test_file || error
2491         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2492         cleanup_test32_mount
2493 }
2494 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2495
2496 test_32l() {
2497         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2498         rm -fr $DIR/$tdir
2499         trap cleanup_test32_mount EXIT
2500         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2501         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2502         test_mkdir -p $DIR/$tdir/d2
2503         touch $DIR/$tdir/d2/test_file
2504         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2505         cleanup_test32_mount
2506 }
2507 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2508
2509 test_32m() {
2510         rm -fr $DIR/d32m
2511         test_mkdir -p $DIR/d32m/tmp
2512         TMP_DIR=$DIR/d32m/tmp
2513         ln -s $DIR $TMP_DIR/symlink11
2514         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2515         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2516         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2517 }
2518 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2519
2520 test_32n() {
2521         rm -fr $DIR/d32n
2522         test_mkdir -p $DIR/d32n/tmp
2523         TMP_DIR=$DIR/d32n/tmp
2524         ln -s $DIR $TMP_DIR/symlink11
2525         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2526         ls -l $DIR/d32n/tmp/symlink11  || error
2527         ls -l $DIR/d32n/symlink01 || error
2528 }
2529 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2530
2531 test_32o() {
2532         touch $DIR/$tfile
2533         test_mkdir -p $DIR/d32o/tmp
2534         TMP_DIR=$DIR/d32o/tmp
2535         ln -s $DIR/$tfile $TMP_DIR/symlink12
2536         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2537         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2538         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2539         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2540         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2541 }
2542 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2543
2544 test_32p() {
2545     log 32p_1
2546         rm -fr $DIR/d32p
2547     log 32p_2
2548         rm -f $DIR/$tfile
2549     log 32p_3
2550         touch $DIR/$tfile
2551     log 32p_4
2552         test_mkdir -p $DIR/d32p/tmp
2553     log 32p_5
2554         TMP_DIR=$DIR/d32p/tmp
2555     log 32p_6
2556         ln -s $DIR/$tfile $TMP_DIR/symlink12
2557     log 32p_7
2558         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2559     log 32p_8
2560         cat $DIR/d32p/tmp/symlink12 || error
2561     log 32p_9
2562         cat $DIR/d32p/symlink02 || error
2563     log 32p_10
2564 }
2565 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2566
2567 cleanup_testdir_mount() {
2568         trap 0
2569         $UMOUNT $DIR/$tdir
2570 }
2571
2572 test_32q() {
2573         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2574         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2575         trap cleanup_testdir_mount EXIT
2576         test_mkdir -p $DIR/$tdir
2577         touch $DIR/$tdir/under_the_mount
2578         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2579         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2580         cleanup_testdir_mount
2581 }
2582 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2583
2584 test_32r() {
2585         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2586         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2587         trap cleanup_testdir_mount EXIT
2588         test_mkdir -p $DIR/$tdir
2589         touch $DIR/$tdir/under_the_mount
2590         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2591         ls $DIR/$tdir | grep -q under_the_mount && error || true
2592         cleanup_testdir_mount
2593 }
2594 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2595
2596 test_33aa() {
2597         rm -f $DIR/$tfile
2598         touch $DIR/$tfile
2599         chmod 444 $DIR/$tfile
2600         chown $RUNAS_ID $DIR/$tfile
2601         log 33_1
2602         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2603         log 33_2
2604 }
2605 run_test 33aa "write file with mode 444 (should return error) ===="
2606
2607 test_33a() {
2608         rm -fr $DIR/d33
2609         test_mkdir -p $DIR/d33
2610         chown $RUNAS_ID $DIR/d33
2611         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2612         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2613                 error "open RDWR" || true
2614 }
2615 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2616
2617 test_33b() {
2618         rm -fr $DIR/d33
2619         test_mkdir -p $DIR/d33
2620         chown $RUNAS_ID $DIR/d33
2621         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 || true
2622 }
2623 run_test 33b "test open file with malformed flags (No panic)"
2624
2625 test_33c() {
2626         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2627         local ostnum
2628         local ostname
2629         local write_bytes
2630         local all_zeros
2631
2632         remote_ost_nodsh && skip "remote OST with nodsh" && return
2633         all_zeros=:
2634         rm -fr $DIR/d33
2635         test_mkdir -p $DIR/d33
2636         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2637
2638         sync
2639         for ostnum in $(seq $OSTCOUNT); do
2640                 # test-framework's OST numbering is one-based, while Lustre's
2641                 # is zero-based
2642                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2643                 # Parsing llobdstat's output sucks; we could grep the /proc
2644                 # path, but that's likely to not be as portable as using the
2645                 # llobdstat utility.  So we parse lctl output instead.
2646                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2647                         obdfilter/$ostname/stats |
2648                         awk '/^write_bytes/ {print $7}' )
2649                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2650                 if (( ${write_bytes:-0} > 0 ))
2651                 then
2652                         all_zeros=false
2653                         break;
2654                 fi
2655         done
2656
2657         $all_zeros || return 0
2658
2659         # Write four bytes
2660         echo foo > $DIR/d33/bar
2661         # Really write them
2662         sync
2663
2664         # Total up write_bytes after writing.  We'd better find non-zeros.
2665         for ostnum in $(seq $OSTCOUNT); do
2666                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2667                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2668                         obdfilter/$ostname/stats |
2669                         awk '/^write_bytes/ {print $7}' )
2670                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2671                 if (( ${write_bytes:-0} > 0 ))
2672                 then
2673                         all_zeros=false
2674                         break;
2675                 fi
2676         done
2677
2678         if $all_zeros
2679         then
2680                 for ostnum in $(seq $OSTCOUNT); do
2681                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2682                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2683                         do_facet ost$ostnum lctl get_param -n \
2684                                 obdfilter/$ostname/stats
2685                 done
2686                 error "OST not keeping write_bytes stats (b22312)"
2687         fi
2688 }
2689 run_test 33c "test llobdstat and write_bytes"
2690
2691 test_33d() {
2692         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2693         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2694         local MDTIDX=1
2695         local remote_dir=$DIR/$tdir/remote_dir
2696
2697         test_mkdir -p $DIR/$tdir
2698         $LFS mkdir -i $MDTIDX $remote_dir ||
2699                 error "create remote directory failed"
2700
2701         touch $remote_dir/$tfile
2702         chmod 444 $remote_dir/$tfile
2703         chown $RUNAS_ID $remote_dir/$tfile
2704
2705         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2706
2707         chown $RUNAS_ID $remote_dir
2708         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2709                                         error "create" || true
2710         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2711                                     error "open RDWR" || true
2712         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 || true
2713 }
2714 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2715
2716 test_33e() {
2717         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2718
2719         mkdir $DIR/$tdir
2720
2721         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2722         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2723         mkdir $DIR/$tdir/local_dir
2724
2725         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2726         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2727         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2728
2729         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2730                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2731
2732         rmdir $DIR/$tdir/* || error "rmdir failed"
2733
2734         umask 777
2735         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2736         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2737         mkdir $DIR/$tdir/local_dir
2738
2739         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2740         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2741         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2742
2743         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2744                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2745
2746         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2747
2748         umask 000
2749         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2750         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2751         mkdir $DIR/$tdir/local_dir
2752
2753         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2754         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2755         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2756
2757         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2758                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2759 }
2760 run_test 33e "mkdir and striped directory should have same mode"
2761
2762 cleanup_33f() {
2763         trap 0
2764         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
2765 }
2766
2767 test_33f() {
2768         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2769
2770         mkdir $DIR/$tdir
2771         chmod go+rwx $DIR/$tdir
2772         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
2773         trap cleanup_33f EXIT
2774
2775         $RUNAS lfs mkdir -c$MDSCOUNT $DIR/$tdir/striped_dir ||
2776                 error "cannot create striped directory"
2777
2778         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
2779                 error "cannot create files in striped directory"
2780
2781         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
2782                 error "cannot remove files in striped directory"
2783
2784         $RUNAS rmdir $DIR/$tdir/striped_dir ||
2785                 error "cannot remove striped directory"
2786
2787         cleanup_33f
2788 }
2789 run_test 33f "nonroot user can create, access, and remove a striped directory"
2790
2791 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2792 test_34a() {
2793         rm -f $DIR/f34
2794         $MCREATE $DIR/f34 || error
2795         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2796         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2797         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2798         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2799 }
2800 run_test 34a "truncate file that has not been opened ==========="
2801
2802 test_34b() {
2803         [ ! -f $DIR/f34 ] && test_34a
2804         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2805         $OPENFILE -f O_RDONLY $DIR/f34
2806         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2807         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2808 }
2809 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2810
2811 test_34c() {
2812         [ ! -f $DIR/f34 ] && test_34a
2813         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2814         $OPENFILE -f O_RDWR $DIR/f34
2815         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2816         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2817 }
2818 run_test 34c "O_RDWR opening file-with-size works =============="
2819
2820 test_34d() {
2821         [ ! -f $DIR/f34 ] && test_34a
2822         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2823         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2824         rm $DIR/f34
2825 }
2826 run_test 34d "write to sparse file ============================="
2827
2828 test_34e() {
2829         rm -f $DIR/f34e
2830         $MCREATE $DIR/f34e || error
2831         $TRUNCATE $DIR/f34e 1000 || error
2832         $CHECKSTAT -s 1000 $DIR/f34e || error
2833         $OPENFILE -f O_RDWR $DIR/f34e
2834         $CHECKSTAT -s 1000 $DIR/f34e || error
2835 }
2836 run_test 34e "create objects, some with size and some without =="
2837
2838 test_34f() { # bug 6242, 6243
2839         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2840         SIZE34F=48000
2841         rm -f $DIR/f34f
2842         $MCREATE $DIR/f34f || error
2843         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2844         dd if=$DIR/f34f of=$TMP/f34f
2845         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2846         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2847         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2848         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2849         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2850 }
2851 run_test 34f "read from a file with no objects until EOF ======="
2852
2853 test_34g() {
2854         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2855         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2856         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2857         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2858         cancel_lru_locks osc
2859         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2860                 error "wrong size after lock cancel"
2861
2862         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2863         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2864                 error "expanding truncate failed"
2865         cancel_lru_locks osc
2866         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2867                 error "wrong expanded size after lock cancel"
2868 }
2869 run_test 34g "truncate long file ==============================="
2870
2871 test_34h() {
2872         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2873         local gid=10
2874         local sz=1000
2875
2876         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2877         sync # Flush the cache so that multiop below does not block on cache
2878              # flush when getting the group lock
2879         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2880         MULTIPID=$!
2881
2882         # Since just timed wait is not good enough, let's do a sync write
2883         # that way we are sure enough time for a roundtrip + processing
2884         # passed + 2 seconds of extra margin.
2885         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2886         rm $DIR/${tfile}-1
2887         sleep 2
2888
2889         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2890                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2891                 kill -9 $MULTIPID
2892         fi
2893         wait $MULTIPID
2894         local nsz=`stat -c %s $DIR/$tfile`
2895         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2896 }
2897 run_test 34h "ftruncate file under grouplock should not block"
2898
2899 test_35a() {
2900         cp /bin/sh $DIR/f35a
2901         chmod 444 $DIR/f35a
2902         chown $RUNAS_ID $DIR/f35a
2903         $RUNAS $DIR/f35a && error || true
2904         rm $DIR/f35a
2905 }
2906 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2907
2908 test_36a() {
2909         rm -f $DIR/f36
2910         utime $DIR/f36 || error
2911 }
2912 run_test 36a "MDS utime check (mknod, utime) ==================="
2913
2914 test_36b() {
2915         echo "" > $DIR/f36
2916         utime $DIR/f36 || error
2917 }
2918 run_test 36b "OST utime check (open, utime) ===================="
2919
2920 test_36c() {
2921         rm -f $DIR/d36/f36
2922         test_mkdir $DIR/d36
2923         chown $RUNAS_ID $DIR/d36
2924         $RUNAS utime $DIR/d36/f36 || error
2925 }
2926 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2927
2928 test_36d() {
2929         [ ! -d $DIR/d36 ] && test_36c
2930         echo "" > $DIR/d36/f36
2931         $RUNAS utime $DIR/d36/f36 || error
2932 }
2933 run_test 36d "non-root OST utime check (open, utime) ==========="
2934
2935 test_36e() {
2936         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2937         test_mkdir -p $DIR/$tdir
2938         touch $DIR/$tdir/$tfile
2939         $RUNAS utime $DIR/$tdir/$tfile && \
2940                 error "utime worked, expected failure" || true
2941 }
2942 run_test 36e "utime on non-owned file (should return error) ===="
2943
2944 subr_36fh() {
2945         local fl="$1"
2946         local LANG_SAVE=$LANG
2947         local LC_LANG_SAVE=$LC_LANG
2948         export LANG=C LC_LANG=C # for date language
2949
2950         DATESTR="Dec 20  2000"
2951         test_mkdir -p $DIR/$tdir
2952         lctl set_param fail_loc=$fl
2953         date; date +%s
2954         cp /etc/hosts $DIR/$tdir/$tfile
2955         sync & # write RPC generated with "current" inode timestamp, but delayed
2956         sleep 1
2957         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2958         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2959         cancel_lru_locks osc
2960         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2961         date; date +%s
2962         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2963                 echo "BEFORE: $LS_BEFORE" && \
2964                 echo "AFTER : $LS_AFTER" && \
2965                 echo "WANT  : $DATESTR" && \
2966                 error "$DIR/$tdir/$tfile timestamps changed" || true
2967
2968         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2969 }
2970
2971 test_36f() {
2972         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2973         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2974         subr_36fh "0x80000214"
2975 }
2976 run_test 36f "utime on file racing with OST BRW write =========="
2977
2978 test_36g() {
2979         remote_ost_nodsh && skip "remote OST with nodsh" && return
2980         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2981         local fmd_max_age
2982         local fmd_before
2983         local fmd_after
2984
2985         test_mkdir -p $DIR/$tdir
2986         fmd_max_age=$(do_facet ost1 \
2987                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2988                 head -n 1")
2989
2990         fmd_before=$(do_facet ost1 \
2991                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2992         touch $DIR/$tdir/$tfile
2993         sleep $((fmd_max_age + 12))
2994         fmd_after=$(do_facet ost1 \
2995                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2996
2997         echo "fmd_before: $fmd_before"
2998         echo "fmd_after: $fmd_after"
2999         [[ $fmd_after -gt $fmd_before ]] &&
3000                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
3001                 error "fmd didn't expire after ping" || true
3002 }
3003 run_test 36g "filter mod data cache expiry ====================="
3004
3005 test_36h() {
3006         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3007         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
3008         subr_36fh "0x80000227"
3009 }
3010 run_test 36h "utime on file racing with OST BRW write =========="
3011
3012 test_36i() {
3013         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3014
3015         test_mkdir $DIR/$tdir
3016         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
3017
3018         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3019         local new_mtime=$((mtime + 200))
3020
3021         #change Modify time of striped dir
3022         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3023                         error "change mtime failed"
3024
3025         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3026
3027         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3028 }
3029 run_test 36i "change mtime on striped directory"
3030
3031 # test_37 - duplicate with tests 32q 32r
3032
3033 test_38() {
3034         local file=$DIR/$tfile
3035         touch $file
3036         openfile -f O_DIRECTORY $file
3037         local RC=$?
3038         local ENOTDIR=20
3039         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3040         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3041 }
3042 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3043
3044 test_39() {
3045         touch $DIR/$tfile
3046         touch $DIR/${tfile}2
3047 #       ls -l  $DIR/$tfile $DIR/${tfile}2
3048 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
3049 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
3050         sleep 2
3051         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3052         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3053                 echo "mtime"
3054                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3055                 echo "atime"
3056                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3057                 echo "ctime"
3058                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3059                 error "O_TRUNC didn't change timestamps"
3060         fi
3061 }
3062 run_test 39 "mtime changed on create ==========================="
3063
3064 test_39b() {
3065         test_mkdir -p -c1 $DIR/$tdir
3066         cp -p /etc/passwd $DIR/$tdir/fopen
3067         cp -p /etc/passwd $DIR/$tdir/flink
3068         cp -p /etc/passwd $DIR/$tdir/funlink
3069         cp -p /etc/passwd $DIR/$tdir/frename
3070         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3071
3072         sleep 1
3073         echo "aaaaaa" >> $DIR/$tdir/fopen
3074         echo "aaaaaa" >> $DIR/$tdir/flink
3075         echo "aaaaaa" >> $DIR/$tdir/funlink
3076         echo "aaaaaa" >> $DIR/$tdir/frename
3077
3078         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3079         local link_new=`stat -c %Y $DIR/$tdir/flink`
3080         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3081         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3082
3083         cat $DIR/$tdir/fopen > /dev/null
3084         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3085         rm -f $DIR/$tdir/funlink2
3086         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3087
3088         for (( i=0; i < 2; i++ )) ; do
3089                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3090                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3091                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3092                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3093
3094                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3095                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3096                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3097                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3098
3099                 cancel_lru_locks osc
3100                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3101         done
3102 }
3103 run_test 39b "mtime change on open, link, unlink, rename  ======"
3104
3105 # this should be set to past
3106 TEST_39_MTIME=`date -d "1 year ago" +%s`
3107
3108 # bug 11063
3109 test_39c() {
3110         touch $DIR1/$tfile
3111         sleep 2
3112         local mtime0=`stat -c %Y $DIR1/$tfile`
3113
3114         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3115         local mtime1=`stat -c %Y $DIR1/$tfile`
3116         [ "$mtime1" = $TEST_39_MTIME ] || \
3117                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3118
3119         local d1=`date +%s`
3120         echo hello >> $DIR1/$tfile
3121         local d2=`date +%s`
3122         local mtime2=`stat -c %Y $DIR1/$tfile`
3123         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3124                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3125
3126         mv $DIR1/$tfile $DIR1/$tfile-1
3127
3128         for (( i=0; i < 2; i++ )) ; do
3129                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3130                 [ "$mtime2" = "$mtime3" ] || \
3131                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3132
3133                 cancel_lru_locks osc
3134                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3135         done
3136 }
3137 run_test 39c "mtime change on rename ==========================="
3138
3139 # bug 21114
3140 test_39d() {
3141         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3142         touch $DIR1/$tfile
3143
3144         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3145
3146         for (( i=0; i < 2; i++ )) ; do
3147                 local mtime=`stat -c %Y $DIR1/$tfile`
3148                 [ $mtime = $TEST_39_MTIME ] || \
3149                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3150
3151                 cancel_lru_locks osc
3152                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3153         done
3154 }
3155 run_test 39d "create, utime, stat =============================="
3156
3157 # bug 21114
3158 test_39e() {
3159         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3160         touch $DIR1/$tfile
3161         local mtime1=`stat -c %Y $DIR1/$tfile`
3162
3163         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3164
3165         for (( i=0; i < 2; i++ )) ; do
3166                 local mtime2=`stat -c %Y $DIR1/$tfile`
3167                 [ $mtime2 = $TEST_39_MTIME ] || \
3168                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3169
3170                 cancel_lru_locks osc
3171                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3172         done
3173 }
3174 run_test 39e "create, stat, utime, stat ========================"
3175
3176 # bug 21114
3177 test_39f() {
3178         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3179         touch $DIR1/$tfile
3180         mtime1=`stat -c %Y $DIR1/$tfile`
3181
3182         sleep 2
3183         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3184
3185         for (( i=0; i < 2; i++ )) ; do
3186                 local mtime2=`stat -c %Y $DIR1/$tfile`
3187                 [ $mtime2 = $TEST_39_MTIME ] || \
3188                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3189
3190                 cancel_lru_locks osc
3191                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3192         done
3193 }
3194 run_test 39f "create, stat, sleep, utime, stat ================="
3195
3196 # bug 11063
3197 test_39g() {
3198         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3199         echo hello >> $DIR1/$tfile
3200         local mtime1=`stat -c %Y $DIR1/$tfile`
3201
3202         sleep 2
3203         chmod o+r $DIR1/$tfile
3204
3205         for (( i=0; i < 2; i++ )) ; do
3206                 local mtime2=`stat -c %Y $DIR1/$tfile`
3207                 [ "$mtime1" = "$mtime2" ] || \
3208                         error "lost mtime: $mtime2, should be $mtime1"
3209
3210                 cancel_lru_locks osc
3211                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3212         done
3213 }
3214 run_test 39g "write, chmod, stat ==============================="
3215
3216 # bug 11063
3217 test_39h() {
3218         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3219         touch $DIR1/$tfile
3220         sleep 1
3221
3222         local d1=`date`
3223         echo hello >> $DIR1/$tfile
3224         local mtime1=`stat -c %Y $DIR1/$tfile`
3225
3226         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3227         local d2=`date`
3228         if [ "$d1" != "$d2" ]; then
3229                 echo "write and touch not within one second"
3230         else
3231                 for (( i=0; i < 2; i++ )) ; do
3232                         local mtime2=`stat -c %Y $DIR1/$tfile`
3233                         [ "$mtime2" = $TEST_39_MTIME ] || \
3234                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3235
3236                         cancel_lru_locks osc
3237                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3238                 done
3239         fi
3240 }
3241 run_test 39h "write, utime within one second, stat ============="
3242
3243 test_39i() {
3244         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3245         touch $DIR1/$tfile
3246         sleep 1
3247
3248         echo hello >> $DIR1/$tfile
3249         local mtime1=`stat -c %Y $DIR1/$tfile`
3250
3251         mv $DIR1/$tfile $DIR1/$tfile-1
3252
3253         for (( i=0; i < 2; i++ )) ; do
3254                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3255
3256                 [ "$mtime1" = "$mtime2" ] || \
3257                         error "lost mtime: $mtime2, should be $mtime1"
3258
3259                 cancel_lru_locks osc
3260                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3261         done
3262 }
3263 run_test 39i "write, rename, stat =============================="
3264
3265 test_39j() {
3266         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3267         start_full_debug_logging
3268         touch $DIR1/$tfile
3269         sleep 1
3270
3271         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3272         lctl set_param fail_loc=0x80000412
3273         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3274                 error "multiop failed"
3275         local multipid=$!
3276         local mtime1=`stat -c %Y $DIR1/$tfile`
3277
3278         mv $DIR1/$tfile $DIR1/$tfile-1
3279
3280         kill -USR1 $multipid
3281         wait $multipid || error "multiop close failed"
3282
3283         for (( i=0; i < 2; i++ )) ; do
3284                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3285                 [ "$mtime1" = "$mtime2" ] ||
3286                         error "mtime is lost on close: $mtime2, " \
3287                               "should be $mtime1"
3288
3289                 cancel_lru_locks osc
3290                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3291         done
3292         lctl set_param fail_loc=0
3293         stop_full_debug_logging
3294 }
3295 run_test 39j "write, rename, close, stat ======================="
3296
3297 test_39k() {
3298         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3299         touch $DIR1/$tfile
3300         sleep 1
3301
3302         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3303         local multipid=$!
3304         local mtime1=`stat -c %Y $DIR1/$tfile`
3305
3306         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3307
3308         kill -USR1 $multipid
3309         wait $multipid || error "multiop close failed"
3310
3311         for (( i=0; i < 2; i++ )) ; do
3312                 local mtime2=`stat -c %Y $DIR1/$tfile`
3313
3314                 [ "$mtime2" = $TEST_39_MTIME ] || \
3315                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3316
3317                 cancel_lru_locks osc
3318                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3319         done
3320 }
3321 run_test 39k "write, utime, close, stat ========================"
3322
3323 # this should be set to future
3324 TEST_39_ATIME=`date -d "1 year" +%s`
3325
3326 test_39l() {
3327         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3328         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3329         local atime_diff=$(do_facet $SINGLEMDS \
3330                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3331         rm -rf $DIR/$tdir
3332         mkdir -p $DIR/$tdir
3333
3334         # test setting directory atime to future
3335         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3336         local atime=$(stat -c %X $DIR/$tdir)
3337         [ "$atime" = $TEST_39_ATIME ] ||
3338                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3339
3340         # test setting directory atime from future to now
3341         local now=$(date +%s)
3342         touch -a -d @$now $DIR/$tdir
3343
3344         atime=$(stat -c %X $DIR/$tdir)
3345         [ "$atime" -eq "$now"  ] ||
3346                 error "atime is not updated from future: $atime, $now"
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         local d1=$(date +%s)
3353         ls $DIR/$tdir
3354         local 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_39p() { # LU-8041
3472         local testdir=$DIR/$tdir
3473         mkdir -p $testdir
3474         multiop_bg_pause $testdir D_c || error "multiop failed"
3475         local multipid=$!
3476         cancel_lru_locks mdc
3477         kill -USR1 $multipid
3478         local atime=$(stat -c %X $testdir)
3479         [ "$atime" -ne 0 ] || error "atime is zero"
3480 }
3481 run_test 39p "close won't zero out atime"
3482
3483 test_40() {
3484         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3485         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3486                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3487         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3488                 error "$tfile is not 4096 bytes in size"
3489 }
3490 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3491
3492 test_41() {
3493         # bug 1553
3494         small_write $DIR/f41 18
3495 }
3496 run_test 41 "test small file write + fstat ====================="
3497
3498 count_ost_writes() {
3499         lctl get_param -n osc.*.stats |
3500                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3501                         END { printf("%0.0f", writes) }'
3502 }
3503
3504 # decent default
3505 WRITEBACK_SAVE=500
3506 DIRTY_RATIO_SAVE=40
3507 MAX_DIRTY_RATIO=50
3508 BG_DIRTY_RATIO_SAVE=10
3509 MAX_BG_DIRTY_RATIO=25
3510
3511 start_writeback() {
3512         trap 0
3513         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3514         # dirty_ratio, dirty_background_ratio
3515         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3516                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3517                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3518                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3519         else
3520                 # if file not here, we are a 2.4 kernel
3521                 kill -CONT `pidof kupdated`
3522         fi
3523 }
3524
3525 stop_writeback() {
3526         # setup the trap first, so someone cannot exit the test at the
3527         # exact wrong time and mess up a machine
3528         trap start_writeback EXIT
3529         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3530         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3531                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3532                 sysctl -w vm.dirty_writeback_centisecs=0
3533                 sysctl -w vm.dirty_writeback_centisecs=0
3534                 # save and increase /proc/sys/vm/dirty_ratio
3535                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3536                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3537                 # save and increase /proc/sys/vm/dirty_background_ratio
3538                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3539                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3540         else
3541                 # if file not here, we are a 2.4 kernel
3542                 kill -STOP `pidof kupdated`
3543         fi
3544 }
3545
3546 # ensure that all stripes have some grant before we test client-side cache
3547 setup_test42() {
3548         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3549                 dd if=/dev/zero of=$i bs=4k count=1
3550                 rm $i
3551         done
3552 }
3553
3554 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3555 # file truncation, and file removal.
3556 test_42a() {
3557         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3558         setup_test42
3559         cancel_lru_locks osc
3560         stop_writeback
3561         sync; sleep 1; sync # just to be safe
3562         BEFOREWRITES=`count_ost_writes`
3563         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3564         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3565         AFTERWRITES=`count_ost_writes`
3566         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3567                 error "$BEFOREWRITES < $AFTERWRITES"
3568         start_writeback
3569 }
3570 run_test 42a "ensure that we don't flush on close =============="
3571
3572 test_42b() {
3573         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3574         setup_test42
3575         cancel_lru_locks osc
3576         stop_writeback
3577         sync
3578         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3579         BEFOREWRITES=$(count_ost_writes)
3580         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3581         AFTERWRITES=$(count_ost_writes)
3582         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3583                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3584         fi
3585         BEFOREWRITES=$(count_ost_writes)
3586         sync || error "sync: $?"
3587         AFTERWRITES=$(count_ost_writes)
3588         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3589                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3590         fi
3591         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3592         start_writeback
3593         return 0
3594 }
3595 run_test 42b "test destroy of file with cached dirty data ======"
3596
3597 # if these tests just want to test the effect of truncation,
3598 # they have to be very careful.  consider:
3599 # - the first open gets a {0,EOF}PR lock
3600 # - the first write conflicts and gets a {0, count-1}PW
3601 # - the rest of the writes are under {count,EOF}PW
3602 # - the open for truncate tries to match a {0,EOF}PR
3603 #   for the filesize and cancels the PWs.
3604 # any number of fixes (don't get {0,EOF} on open, match
3605 # composite locks, do smarter file size management) fix
3606 # this, but for now we want these tests to verify that
3607 # the cancellation with truncate intent works, so we
3608 # start the file with a full-file pw lock to match against
3609 # until the truncate.
3610 trunc_test() {
3611         test=$1
3612         file=$DIR/$test
3613         offset=$2
3614         cancel_lru_locks osc
3615         stop_writeback
3616         # prime the file with 0,EOF PW to match
3617         touch $file
3618         $TRUNCATE $file 0
3619         sync; sync
3620         # now the real test..
3621         dd if=/dev/zero of=$file bs=1024 count=100
3622         BEFOREWRITES=`count_ost_writes`
3623         $TRUNCATE $file $offset
3624         cancel_lru_locks osc
3625         AFTERWRITES=`count_ost_writes`
3626         start_writeback
3627 }
3628
3629 test_42c() {
3630         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3631         trunc_test 42c 1024
3632         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3633             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3634         rm $file
3635 }
3636 run_test 42c "test partial truncate of file with cached dirty data"
3637
3638 test_42d() {
3639         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3640         trunc_test 42d 0
3641         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3642             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3643         rm $file
3644 }
3645 run_test 42d "test complete truncate of file with cached dirty data"
3646
3647 test_42e() { # bug22074
3648         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3649         local TDIR=$DIR/${tdir}e
3650         local pagesz=$(page_size)
3651         local pages=16 # hardcoded 16 pages, don't change it.
3652         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3653         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3654         local max_dirty_mb
3655         local warmup_files
3656
3657         test_mkdir -p $DIR/${tdir}e
3658         $SETSTRIPE -c 1 $TDIR
3659         createmany -o $TDIR/f $files
3660
3661         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3662
3663         # we assume that with $OSTCOUNT files, at least one of them will
3664         # be allocated on OST0.
3665         warmup_files=$((OSTCOUNT * max_dirty_mb))
3666         createmany -o $TDIR/w $warmup_files
3667
3668         # write a large amount of data into one file and sync, to get good
3669         # avail_grant number from OST.
3670         for ((i=0; i<$warmup_files; i++)); do
3671                 idx=$($GETSTRIPE -i $TDIR/w$i)
3672                 [ $idx -ne 0 ] && continue
3673                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3674                 break
3675         done
3676         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3677         sync
3678         $LCTL get_param $proc_osc0/cur_dirty_bytes
3679         $LCTL get_param $proc_osc0/cur_grant_bytes
3680
3681         # create as much dirty pages as we can while not to trigger the actual
3682         # RPCs directly. but depends on the env, VFS may trigger flush during this
3683         # period, hopefully we are good.
3684         for ((i=0; i<$warmup_files; i++)); do
3685                 idx=$($GETSTRIPE -i $TDIR/w$i)
3686                 [ $idx -ne 0 ] && continue
3687                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3688         done
3689         $LCTL get_param $proc_osc0/cur_dirty_bytes
3690         $LCTL get_param $proc_osc0/cur_grant_bytes
3691
3692         # perform the real test
3693         $LCTL set_param $proc_osc0/rpc_stats 0
3694         for ((;i<$files; i++)); do
3695                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3696                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3697         done
3698         sync
3699         $LCTL get_param $proc_osc0/rpc_stats
3700
3701         local percent=0
3702         local have_ppr=false
3703         $LCTL get_param $proc_osc0/rpc_stats |
3704                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3705                         # skip lines until we are at the RPC histogram data
3706                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3707                         $have_ppr || continue
3708
3709                         # we only want the percent stat for < 16 pages
3710                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3711
3712                         percent=$((percent + WPCT))
3713                         if [[ $percent -gt 15 ]]; then
3714                                 error "less than 16-pages write RPCs" \
3715                                       "$percent% > 15%"
3716                                 break
3717                         fi
3718                 done
3719         rm -rf $TDIR
3720 }
3721 run_test 42e "verify sub-RPC writes are not done synchronously"
3722
3723 test_43() {
3724         test_mkdir -p $DIR/$tdir
3725         cp -p /bin/ls $DIR/$tdir/$tfile
3726         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3727         pid=$!
3728         # give multiop a chance to open
3729         sleep 1
3730
3731         $DIR/$tdir/$tfile && error || true
3732         kill -USR1 $pid
3733 }
3734 run_test 43 "execution of file opened for write should return -ETXTBSY"
3735
3736 test_43a() {
3737         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3738         test_mkdir -p $DIR/$tdir
3739         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3740                         cp -p multiop $DIR/$tdir/multiop
3741         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3742                         return 1
3743         MULTIOP_PID=$!
3744         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3745         kill -USR1 $MULTIOP_PID || return 2
3746         wait $MULTIOP_PID || return 3
3747         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3748 }
3749 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3750
3751 test_43b() {
3752         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3753         test_mkdir -p $DIR/$tdir
3754         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3755                         cp -p multiop $DIR/$tdir/multiop
3756         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3757                         return 1
3758         MULTIOP_PID=$!
3759         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3760         kill -USR1 $MULTIOP_PID || return 2
3761         wait $MULTIOP_PID || return 3
3762         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3763 }
3764 run_test 43b "truncate of file being executed should return -ETXTBSY"
3765
3766 test_43c() {
3767         local testdir="$DIR/$tdir"
3768         test_mkdir -p $DIR/$tdir
3769         cp $SHELL $testdir/
3770         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3771                 ( cd $testdir && md5sum -c)
3772 }
3773 run_test 43c "md5sum of copy into lustre========================"
3774
3775 test_44() {
3776         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3777         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3778         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3779 }
3780 run_test 44 "zero length read from a sparse stripe ============="
3781
3782 test_44a() {
3783         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3784                 awk '{ print $2 }')
3785         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3786         [[ $nstripe -gt $OSTCOUNT ]] &&
3787             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3788             return
3789         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3790                 awk '{ print $2 }')
3791         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3792                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3793                         awk '{ print $2 }')
3794         fi
3795
3796         OFFSETS="0 $((stride/2)) $((stride-1))"
3797         for offset in $OFFSETS; do
3798                 for i in $(seq 0 $((nstripe-1))); do
3799                         local GLOBALOFFSETS=""
3800                         # size in Bytes
3801                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3802                         local myfn=$DIR/d44a-$size
3803                         echo "--------writing $myfn at $size"
3804                         ll_sparseness_write $myfn $size ||
3805                                 error "ll_sparseness_write"
3806                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3807                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3808                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3809
3810                         for j in $(seq 0 $((nstripe-1))); do
3811                                 # size in Bytes
3812                                 size=$((((j + $nstripe )*$stride + $offset)))
3813                                 ll_sparseness_write $myfn $size ||
3814                                         error "ll_sparseness_write"
3815                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3816                         done
3817                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3818                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3819                         rm -f $myfn
3820                 done
3821         done
3822 }
3823 run_test 44a "test sparse pwrite ==============================="
3824
3825 dirty_osc_total() {
3826         tot=0
3827         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3828                 tot=$(($tot + $d))
3829         done
3830         echo $tot
3831 }
3832 do_dirty_record() {
3833         before=`dirty_osc_total`
3834         echo executing "\"$*\""
3835         eval $*
3836         after=`dirty_osc_total`
3837         echo before $before, after $after
3838 }
3839 test_45() {
3840         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3841         f="$DIR/f45"
3842         # Obtain grants from OST if it supports it
3843         echo blah > ${f}_grant
3844         stop_writeback
3845         sync
3846         do_dirty_record "echo blah > $f"
3847         [[ $before -eq $after ]] && error "write wasn't cached"
3848         do_dirty_record "> $f"
3849         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3850         do_dirty_record "echo blah > $f"
3851         [[ $before -eq $after ]] && error "write wasn't cached"
3852         do_dirty_record "sync"
3853         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3854         do_dirty_record "echo blah > $f"
3855         [[ $before -eq $after ]] && error "write wasn't cached"
3856         do_dirty_record "cancel_lru_locks osc"
3857         [[ $before -gt $after ]] ||
3858                 error "lock cancellation didn't lower dirty count"
3859         start_writeback
3860 }
3861 run_test 45 "osc io page accounting ============================"
3862
3863 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3864 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3865 # objects offset and an assert hit when an rpc was built with 1023's mapped
3866 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3867 test_46() {
3868         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3869         f="$DIR/f46"
3870         stop_writeback
3871         sync
3872         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3873         sync
3874         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3875         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3876         sync
3877         start_writeback
3878 }
3879 run_test 46 "dirtying a previously written page ================"
3880
3881 # test_47 is removed "Device nodes check" is moved to test_28
3882
3883 test_48a() { # bug 2399
3884         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
3885         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
3886                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly" &&
3887                 return
3888         test_mkdir $DIR/$tdir
3889         cd $DIR/$tdir
3890         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
3891         test_mkdir $DIR/$tdir || error "recreate directory failed"
3892         touch foo || error "'touch foo' failed after recreating cwd"
3893         test_mkdir bar || error "'mkdir foo' failed after recreating cwd"
3894         touch .foo || error "'touch .foo' failed after recreating cwd"
3895         test_mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
3896         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3897         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3898         cd . || error "'cd .' failed after recreating cwd"
3899         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3900         rmdir . && error "'rmdir .' worked after recreating cwd"
3901         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3902         cd .. || error "'cd ..' failed after recreating cwd"
3903 }
3904 run_test 48a "Access renamed working dir (should return errors)="
3905
3906 test_48b() { # bug 2399
3907         rm -rf $DIR/$tdir
3908         test_mkdir $DIR/$tdir
3909         cd $DIR/$tdir
3910         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3911         touch foo && error "'touch foo' worked after removing cwd"
3912         test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3913         touch .foo && error "'touch .foo' worked after removing cwd"
3914         test_mkdir .foo && error "'mkdir .foo' worked after removing cwd"
3915         ls . > /dev/null && error "'ls .' worked after removing cwd"
3916         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3917         test_mkdir . && error "'mkdir .' worked after removing cwd"
3918         rmdir . && error "'rmdir .' worked after removing cwd"
3919         ln -s . foo && error "'ln -s .' worked after removing cwd"
3920         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3921 }
3922 run_test 48b "Access removed working dir (should return errors)="
3923
3924 test_48c() { # bug 2350
3925         #lctl set_param debug=-1
3926         #set -vx
3927         rm -rf $DIR/$tdir
3928         test_mkdir -p $DIR/$tdir/dir
3929         cd $DIR/$tdir/dir
3930         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3931         $TRACE touch foo && error "touch foo worked after removing cwd"
3932         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3933         touch .foo && error "touch .foo worked after removing cwd"
3934         test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3935         $TRACE ls . && error "'ls .' worked after removing cwd"
3936         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3937         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3938         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3939         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3940         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3941 }
3942 run_test 48c "Access removed working subdir (should return errors)"
3943
3944 test_48d() { # bug 2350
3945         #lctl set_param debug=-1
3946         #set -vx
3947         rm -rf $DIR/$tdir
3948         test_mkdir -p $DIR/$tdir/dir
3949         cd $DIR/$tdir/dir
3950         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3951         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3952         $TRACE touch foo && error "'touch foo' worked after removing parent"
3953         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3954         touch .foo && error "'touch .foo' worked after removing parent"
3955         test_mkdir .foo && error "mkdir .foo worked after removing parent"
3956         $TRACE ls . && error "'ls .' worked after removing parent"
3957         $TRACE ls .. && error "'ls ..' worked after removing parent"
3958         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3959         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3960         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3961         true
3962 }
3963 run_test 48d "Access removed parent subdir (should return errors)"
3964
3965 test_48e() { # bug 4134
3966         #lctl set_param debug=-1
3967         #set -vx
3968         rm -rf $DIR/$tdir
3969         test_mkdir -p $DIR/$tdir/dir
3970         cd $DIR/$tdir/dir
3971         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3972         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3973         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3974         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3975         # On a buggy kernel addition of "touch foo" after cd .. will
3976         # produce kernel oops in lookup_hash_it
3977         touch ../foo && error "'cd ..' worked after recreate parent"
3978         cd $DIR
3979         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3980 }
3981 run_test 48e "Access to recreated parent subdir (should return errors)"
3982
3983 test_49() { # LU-1030
3984         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3985         # get ost1 size - lustre-OST0000
3986         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3987                 awk '{ print $4 }')
3988         # write 800M at maximum
3989         [[ $ost1_size -lt 2 ]] && ost1_size=2
3990         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3991
3992         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3993         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3994         local dd_pid=$!
3995
3996         # change max_pages_per_rpc while writing the file
3997         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3998         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3999         # loop until dd process exits
4000         while ps ax -opid | grep -wq $dd_pid; do
4001                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
4002                 sleep $((RANDOM % 5 + 1))
4003         done
4004         # restore original max_pages_per_rpc
4005         $LCTL set_param $osc1_mppc=$orig_mppc
4006         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
4007 }
4008 run_test 49 "Change max_pages_per_rpc won't break osc extent"
4009
4010 test_50() {
4011         # bug 1485
4012         test_mkdir $DIR/$tdir
4013         cd $DIR/$tdir
4014         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
4015 }
4016 run_test 50 "special situations: /proc symlinks  ==============="
4017
4018 test_51a() {    # was test_51
4019         # bug 1516 - create an empty entry right after ".." then split dir
4020         test_mkdir -c1 $DIR/$tdir
4021         touch $DIR/$tdir/foo
4022         $MCREATE $DIR/$tdir/bar
4023         rm $DIR/$tdir/foo
4024         createmany -m $DIR/$tdir/longfile 201
4025         FNUM=202
4026         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
4027                 $MCREATE $DIR/$tdir/longfile$FNUM
4028                 FNUM=$(($FNUM + 1))
4029                 echo -n "+"
4030         done
4031         echo
4032         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
4033 }
4034 run_test 51a "special situations: split htree with empty entry =="
4035
4036 export NUMTEST=70000
4037 test_51b() {
4038         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4039         local BASE=$DIR/d${base}.${TESTSUITE}
4040
4041         # cleanup the directory
4042         rm -fr $BASE
4043
4044         test_mkdir -p -c1 $BASE
4045
4046         $LFS df
4047         $LFS df -i
4048         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
4049         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
4050         [[ $numfree -lt 21000 ]] &&
4051                 skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
4052                 return
4053
4054         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
4055                 echo "reduced count to $NUMTEST due to inodes on MDT$mdtidx"
4056
4057         # need to check free space for the directories as well
4058         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
4059         numfree=$((blkfree / 4))
4060         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$((numfree - 50)) &&
4061                 echo "reduced count to $NUMTEST due to blocks on MDT$mdtidx"
4062
4063         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
4064         {
4065                 $LFS df
4066                 $LFS df -i
4067                 echo "failed" > $BASE/fnum
4068                 error "failed to create $NUMTEST subdirs in MDT$mdtidx:$BASE"
4069         }
4070 }
4071 run_test 51b "exceed 64k subdirectory nlink limit"
4072
4073 test_51ba() { # LU-993
4074         local BASE=$DIR/d${base}.${TESTSUITE}
4075         # unlink all but 100 subdirectories, then check it still works
4076         local LEFT=100
4077         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
4078
4079         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
4080         local DELETE=$((NUMTEST - LEFT))
4081
4082         # continue on to run this test even if 51b didn't finish,
4083         # just to delete the many subdirectories created.
4084         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
4085
4086         # for ldiskfs the nlink count should be 1, but this is OSD specific
4087         # and so this is listed for informational purposes only
4088         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
4089         unlinkmany -d $BASE/d $DELETE
4090         RC=$?
4091
4092         if [ $RC -ne 0 ]; then
4093                 if [ "$NUMPREV" == "failed" ]; then
4094                         skip "previous setup failed"
4095                         return 0
4096                 else
4097                         error "unlink of first $DELETE subdirs failed"
4098                         return $RC
4099                 fi
4100         fi
4101
4102         echo "nlink between: $(stat -c %h $BASE)"
4103         # trim the first line of ls output
4104         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
4105         [ $FOUND -ne $LEFT ] &&
4106                 error "can't find subdirs: found only $FOUND/$LEFT"
4107
4108         unlinkmany -d $BASE/d $DELETE $LEFT ||
4109                 error "unlink of second $LEFT subdirs failed"
4110         # regardless of whether the backing filesystem tracks nlink accurately
4111         # or not, the nlink count shouldn't be more than "." and ".." here
4112         local AFTER=$(stat -c %h $BASE)
4113         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
4114                 echo "nlink after: $AFTER"
4115 }
4116 run_test 51ba "verify nlink for many subdirectory cleanup"
4117
4118 test_51d() {
4119         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4120         [[ $OSTCOUNT -lt 3 ]] &&
4121                 skip_env "skipping test with few OSTs" && return
4122         test_mkdir -p $DIR/$tdir
4123         createmany -o $DIR/$tdir/t- 1000
4124         $GETSTRIPE $DIR/$tdir > $TMP/files
4125         for N in $(seq 0 $((OSTCOUNT - 1))); do
4126                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4127                         END { printf("%0.0f", objs) }' $TMP/files)
4128                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
4129                         '($1 == '$N') { objs += 1 } \
4130                         END { printf("%0.0f", objs) }')
4131                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4132         done
4133         unlinkmany $DIR/$tdir/t- 1000
4134
4135         NLAST=0
4136         for N in $(seq 1 $((OSTCOUNT - 1))); do
4137                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4138                         error "OST $N has less objects vs OST $NLAST" \
4139                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4140                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4141                         error "OST $N has less objects vs OST $NLAST" \
4142                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4143
4144                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4145                         error "OST $N has less #0 objects vs OST $NLAST" \
4146                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4147                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4148                         error "OST $N has less #0 objects vs OST $NLAST" \
4149                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4150                 NLAST=$N
4151         done
4152 }
4153 run_test 51d "check object distribution ===================="
4154
4155 test_51e() {
4156         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4157                 skip "Only applicable to ldiskfs-based MDTs"
4158                 return
4159         fi
4160
4161         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4162         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4163
4164         touch $DIR/$tdir/d0/foo
4165         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4166                 error "file exceed 65000 nlink limit!"
4167         unlinkmany $DIR/$tdir/d0/f- 65001
4168         return 0
4169 }
4170 run_test 51e "check file nlink limit"
4171
4172 test_52a() {
4173         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4174         test_mkdir -p $DIR/$tdir
4175         touch $DIR/$tdir/foo
4176         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4177         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4178         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4179         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4180         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4181                                         error "link worked"
4182         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4183         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4184         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4185                                                      error "lsattr"
4186         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4187         cp -r $DIR/$tdir /tmp/
4188         rm -fr $DIR/$tdir || error "cleanup rm failed"
4189 }
4190 run_test 52a "append-only flag test (should return errors) ====="
4191
4192 test_52b() {
4193         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4194         test_mkdir -p $DIR/$tdir
4195         touch $DIR/$tdir/foo
4196         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4197         cat test > $DIR/$tdir/foo && error "cat test worked"
4198         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4199         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4200         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4201                                         error "link worked"
4202         echo foo >> $DIR/$tdir/foo && error "echo worked"
4203         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4204         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4205         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4206         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4207                                                         error "lsattr"
4208         chattr -i $DIR/$tdir/foo || error "chattr failed"
4209
4210         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4211 }
4212 run_test 52b "immutable flag test (should return errors) ======="
4213
4214 test_53() {
4215         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4216         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4217         remote_ost_nodsh && skip "remote OST with nodsh" && return
4218
4219         local param
4220         local param_seq
4221         local ostname
4222         local mds_last
4223         local mds_last_seq
4224         local ost_last
4225         local ost_last_seq
4226         local ost_last_id
4227         local ostnum
4228         local node
4229         local found=false
4230         local support_last_seq=true
4231
4232         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4233                 support_last_seq=false
4234
4235         # only test MDT0000
4236         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4237         local value
4238         for value in $(do_facet $SINGLEMDS \
4239                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4240                 param=$(echo ${value[0]} | cut -d "=" -f1)
4241                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4242
4243                 if $support_last_seq; then
4244                         param_seq=$(echo $param |
4245                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4246                         mds_last_seq=$(do_facet $SINGLEMDS \
4247                                        $LCTL get_param -n $param_seq)
4248                 fi
4249                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4250
4251                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4252                 node=$(facet_active_host ost$((ostnum+1)))
4253                 param="obdfilter.$ostname.last_id"
4254                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4255                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4256                         ost_last_id=$ost_last
4257
4258                         if $support_last_seq; then
4259                                 ost_last_id=$(echo $ost_last |
4260                                               awk -F':' '{print $2}' |
4261                                               sed -e "s/^0x//g")
4262                                 ost_last_seq=$(echo $ost_last |
4263                                                awk -F':' '{print $1}')
4264                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4265                         fi
4266
4267                         if [[ $ost_last_id != $mds_last ]]; then
4268                                 error "$ost_last_id != $mds_last"
4269                         else
4270                                 found=true
4271                                 break
4272                         fi
4273                 done
4274         done
4275         $found || error "can not match last_seq/last_id for $mdtosc"
4276         return 0
4277 }
4278 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4279
4280 test_54a() {
4281         $SOCKETSERVER $DIR/socket ||
4282                 error "$SOCKETSERVER $DIR/socket failed: $?"
4283         $SOCKETCLIENT $DIR/socket ||
4284                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4285         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4286 }
4287 run_test 54a "unix domain socket test =========================="
4288
4289 test_54b() {
4290         f="$DIR/f54b"
4291         mknod $f c 1 3
4292         chmod 0666 $f
4293         dd if=/dev/zero of=$f bs=$(page_size) count=1
4294 }
4295 run_test 54b "char device works in lustre ======================"
4296
4297 find_loop_dev() {
4298         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4299         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4300         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4301
4302         for i in $(seq 3 7); do
4303                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4304                 LOOPDEV=$LOOPBASE$i
4305                 LOOPNUM=$i
4306                 break
4307         done
4308 }
4309
4310 cleanup_54c() {
4311         loopdev="$DIR/loop54c"
4312
4313         trap 0
4314         $UMOUNT $DIR/$tdir || rc=$?
4315         losetup -d $loopdev || true
4316         losetup -d $LOOPDEV || true
4317         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4318         return $rc
4319 }
4320
4321 test_54c() {
4322         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4323         loopdev="$DIR/loop54c"
4324
4325         find_loop_dev
4326         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4327         trap cleanup_54c EXIT
4328         mknod $loopdev b 7 $LOOPNUM
4329         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4330         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4331         losetup $loopdev $DIR/$tfile ||
4332                 error "can't set up $loopdev for $DIR/$tfile"
4333         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4334         test_mkdir -p $DIR/$tdir
4335         mount -t ext2 $loopdev $DIR/$tdir ||
4336                 error "error mounting $loopdev on $DIR/$tdir"
4337         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4338                 error "dd write"
4339         df $DIR/$tdir
4340         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4341                 error "dd read"
4342         cleanup_54c
4343 }
4344 run_test 54c "block device works in lustre ====================="
4345
4346 test_54d() {
4347         f="$DIR/f54d"
4348         string="aaaaaa"
4349         mknod $f p
4350         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4351 }
4352 run_test 54d "fifo device works in lustre ======================"
4353
4354 test_54e() {
4355         f="$DIR/f54e"
4356         string="aaaaaa"
4357         cp -aL /dev/console $f
4358         echo $string > $f || error "echo $string to $f failed"
4359 }
4360 run_test 54e "console/tty device works in lustre ======================"
4361
4362 #The test_55 used to be iopen test and it was removed by bz#24037.
4363 #run_test 55 "check iopen_connect_dentry() ======================"
4364
4365 test_56a() {    # was test_56
4366         rm -rf $DIR/$tdir
4367         $SETSTRIPE -d $DIR
4368         test_mkdir -p $DIR/$tdir/dir
4369         NUMFILES=3
4370         NUMFILESx2=$(($NUMFILES * 2))
4371         for i in $(seq 1 $NUMFILES); do
4372                 touch $DIR/$tdir/file$i
4373                 touch $DIR/$tdir/dir/file$i
4374         done
4375
4376         # test lfs getstripe with --recursive
4377         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4378         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4379                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4380         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4381         [[ $FILENUM -eq $NUMFILES ]] ||
4382                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4383         echo "$GETSTRIPE --recursive passed."
4384
4385         # test lfs getstripe with file instead of dir
4386         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4387         [[ $FILENUM -eq 1 ]] ||
4388                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4389         echo "$GETSTRIPE file1 passed."
4390
4391         #test lfs getstripe with --verbose
4392         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4393                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4394                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4395         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4396                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4397         echo "$GETSTRIPE --verbose passed."
4398
4399         #test lfs getstripe with --obd
4400         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4401                 grep -q "unknown obduuid" ||
4402                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4403
4404         [[ $OSTCOUNT -lt 2 ]] &&
4405                 skip_env "skipping other $GETSTRIPE --obd test" && return
4406
4407         OSTIDX=1
4408         OBDUUID=$(ostuuid_from_index $OSTIDX)
4409         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4410         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4411         [[ $FOUND -eq $FILENUM ]] ||
4412                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4413         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4414                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4415                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4416                 error "$GETSTRIPE --obd: should not show file on other obd"
4417         echo "$GETSTRIPE --obd passed"
4418 }
4419 run_test 56a "check $GETSTRIPE"
4420
4421 NUMFILES=3
4422 NUMDIRS=3
4423 setup_56() {
4424         local LOCAL_NUMFILES="$1"
4425         local LOCAL_NUMDIRS="$2"
4426         local MKDIR_PARAMS="$3"
4427         local DIR_STRIPE_PARAMS="$4"
4428
4429         if [ ! -d "$TDIR" ] ; then
4430                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4431                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4432                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4433                         touch $TDIR/file$i
4434                 done
4435                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4436                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4437                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4438                                 touch $TDIR/dir$i/file$j
4439                         done
4440                 done
4441         fi
4442 }
4443
4444 setup_56_special() {
4445         LOCAL_NUMFILES=$1
4446         LOCAL_NUMDIRS=$2
4447         setup_56 $1 $2
4448         if [ ! -e "$TDIR/loop1b" ] ; then
4449                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4450                         mknod $TDIR/loop${i}b b 7 $i
4451                         mknod $TDIR/null${i}c c 1 3
4452                         ln -s $TDIR/file1 $TDIR/link${i}l
4453                 done
4454                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4455                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4456                         mknod $TDIR/dir$i/null${i}c c 1 3
4457                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4458                 done
4459         fi
4460 }
4461
4462 test_56g() {
4463         $SETSTRIPE -d $DIR
4464
4465         TDIR=$DIR/${tdir}g
4466         setup_56 $NUMFILES $NUMDIRS
4467
4468         EXPECTED=$(($NUMDIRS + 2))
4469         # test lfs find with -name
4470         for i in $(seq 1 $NUMFILES) ; do
4471                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4472                 [ $NUMS -eq $EXPECTED ] ||
4473                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4474                               "found $NUMS, expected $EXPECTED"
4475         done
4476 }
4477 run_test 56g "check lfs find -name ============================="
4478
4479 test_56h() {
4480         $SETSTRIPE -d $DIR
4481
4482         TDIR=$DIR/${tdir}g
4483         setup_56 $NUMFILES $NUMDIRS
4484
4485         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4486         # test lfs find with ! -name
4487         for i in $(seq 1 $NUMFILES) ; do
4488                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4489                 [ $NUMS -eq $EXPECTED ] ||
4490                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4491                               "found $NUMS, expected $EXPECTED"
4492         done
4493 }
4494 run_test 56h "check lfs find ! -name ============================="
4495
4496 test_56i() {
4497        tdir=${tdir}i
4498        test_mkdir -p $DIR/$tdir
4499        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4500        CMD="$LFIND -ost $UUID $DIR/$tdir"
4501        OUT=$($CMD)
4502        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4503 }
4504 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4505
4506 test_56j() {
4507         TDIR=$DIR/${tdir}g
4508         setup_56_special $NUMFILES $NUMDIRS
4509
4510         EXPECTED=$((NUMDIRS + 1))
4511         CMD="$LFIND -type d $TDIR"
4512         NUMS=$($CMD | wc -l)
4513         [ $NUMS -eq $EXPECTED ] ||
4514                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4515 }
4516 run_test 56j "check lfs find -type d ============================="
4517
4518 test_56k() {
4519         TDIR=$DIR/${tdir}g
4520         setup_56_special $NUMFILES $NUMDIRS
4521
4522         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4523         CMD="$LFIND -type f $TDIR"
4524         NUMS=$($CMD | wc -l)
4525         [ $NUMS -eq $EXPECTED ] ||
4526                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4527 }
4528 run_test 56k "check lfs find -type f ============================="
4529
4530 test_56l() {
4531         TDIR=$DIR/${tdir}g
4532         setup_56_special $NUMFILES $NUMDIRS
4533
4534         EXPECTED=$((NUMDIRS + NUMFILES))
4535         CMD="$LFIND -type b $TDIR"
4536         NUMS=$($CMD | wc -l)
4537         [ $NUMS -eq $EXPECTED ] ||
4538                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4539 }
4540 run_test 56l "check lfs find -type b ============================="
4541
4542 test_56m() {
4543         TDIR=$DIR/${tdir}g
4544         setup_56_special $NUMFILES $NUMDIRS
4545
4546         EXPECTED=$((NUMDIRS + NUMFILES))
4547         CMD="$LFIND -type c $TDIR"
4548         NUMS=$($CMD | wc -l)
4549         [ $NUMS -eq $EXPECTED ] ||
4550                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4551 }
4552 run_test 56m "check lfs find -type c ============================="
4553
4554 test_56n() {
4555         TDIR=$DIR/${tdir}g
4556         setup_56_special $NUMFILES $NUMDIRS
4557
4558         EXPECTED=$((NUMDIRS + NUMFILES))
4559         CMD="$LFIND -type l $TDIR"
4560         NUMS=$($CMD | wc -l)
4561         [ $NUMS -eq $EXPECTED ] ||
4562                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4563 }
4564 run_test 56n "check lfs find -type l ============================="
4565
4566 test_56o() {
4567         TDIR=$DIR/${tdir}o
4568         setup_56 $NUMFILES $NUMDIRS
4569         utime $TDIR/file1 > /dev/null || error "utime (1)"
4570         utime $TDIR/file2 > /dev/null || error "utime (2)"
4571         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4572         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4573         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4574         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4575
4576         EXPECTED=4
4577         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4578         [ $NUMS -eq $EXPECTED ] || \
4579                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4580
4581         EXPECTED=12
4582         CMD="$LFIND -mtime 0 $TDIR"
4583         NUMS=$($CMD | wc -l)
4584         [ $NUMS -eq $EXPECTED ] ||
4585                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4586 }
4587 run_test 56o "check lfs find -mtime for old files =========================="
4588
4589 test_56p() {
4590         [ $RUNAS_ID -eq $UID ] &&
4591                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4592
4593         TDIR=$DIR/${tdir}p
4594         setup_56 $NUMFILES $NUMDIRS
4595
4596         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4597         EXPECTED=$NUMFILES
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         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4604         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4605         NUMS=$($CMD | wc -l)
4606         [ $NUMS -eq $EXPECTED ] || \
4607                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4608 }
4609 run_test 56p "check lfs find -uid and ! -uid ==============================="
4610
4611 test_56q() {
4612         [ $RUNAS_ID -eq $UID ] &&
4613                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4614
4615         TDIR=$DIR/${tdir}q
4616         setup_56 $NUMFILES $NUMDIRS
4617
4618         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4619
4620         EXPECTED=$NUMFILES
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         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4627         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4628         NUMS=$($CMD | wc -l)
4629         [ $NUMS -eq $EXPECTED ] ||
4630                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4631 }
4632 run_test 56q "check lfs find -gid and ! -gid ==============================="
4633
4634 test_56r() {
4635         TDIR=$DIR/${tdir}r
4636         setup_56 $NUMFILES $NUMDIRS
4637
4638         EXPECTED=12
4639         CMD="$LFIND -size 0 -type f $TDIR"
4640         NUMS=$($CMD | wc -l)
4641         [ $NUMS -eq $EXPECTED ] ||
4642                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4643         EXPECTED=0
4644         CMD="$LFIND ! -size 0 -type f $TDIR"
4645         NUMS=$($CMD | wc -l)
4646         [ $NUMS -eq $EXPECTED ] ||
4647                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4648         echo "test" > $TDIR/$tfile
4649         echo "test2" > $TDIR/$tfile.2 && sync
4650         EXPECTED=1
4651         CMD="$LFIND -size 5 -type f $TDIR"
4652         NUMS=$($CMD | wc -l)
4653         [ $NUMS -eq $EXPECTED ] ||
4654                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4655         EXPECTED=1
4656         CMD="$LFIND -size +5 -type f $TDIR"
4657         NUMS=$($CMD | wc -l)
4658         [ $NUMS -eq $EXPECTED ] ||
4659                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4660         EXPECTED=2
4661         CMD="$LFIND -size +0 -type f $TDIR"
4662         NUMS=$($CMD | wc -l)
4663         [ $NUMS -eq $EXPECTED ] ||
4664                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4665         EXPECTED=2
4666         CMD="$LFIND ! -size -5 -type f $TDIR"
4667         NUMS=$($CMD | wc -l)
4668         [ $NUMS -eq $EXPECTED ] ||
4669                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4670         EXPECTED=12
4671         CMD="$LFIND -size -5 -type f $TDIR"
4672         NUMS=$($CMD | wc -l)
4673         [ $NUMS -eq $EXPECTED ] ||
4674                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4675 }
4676 run_test 56r "check lfs find -size works =========================="
4677
4678 test_56s() { # LU-611
4679         TDIR=$DIR/${tdir}s
4680         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4681
4682         if [[ $OSTCOUNT -gt 1 ]]; then
4683                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4684                 ONESTRIPE=4
4685                 EXTRA=4
4686         else
4687                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4688                 EXTRA=0
4689         fi
4690
4691         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4692         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4693         NUMS=$($CMD | wc -l)
4694         [ $NUMS -eq $EXPECTED ] || {
4695                 $GETSTRIPE -R $TDIR
4696                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4697         }
4698
4699         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4700         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4701         NUMS=$($CMD | wc -l)
4702         [ $NUMS -eq $EXPECTED ] || {
4703                 $GETSTRIPE -R $TDIR
4704                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4705         }
4706
4707         EXPECTED=$ONESTRIPE
4708         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4709         NUMS=$($CMD | wc -l)
4710         [ $NUMS -eq $EXPECTED ] || {
4711                 $GETSTRIPE -R $TDIR
4712                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4713         }
4714
4715         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4716         NUMS=$($CMD | wc -l)
4717         [ $NUMS -eq $EXPECTED ] || {
4718                 $GETSTRIPE -R $TDIR
4719                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4720         }
4721
4722         EXPECTED=0
4723         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4724         NUMS=$($CMD | wc -l)
4725         [ $NUMS -eq $EXPECTED ] || {
4726                 $GETSTRIPE -R $TDIR
4727                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4728         }
4729 }
4730 run_test 56s "check lfs find -stripe-count works"
4731
4732 test_56t() { # LU-611
4733         TDIR=$DIR/${tdir}t
4734         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4735
4736         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4737
4738         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4739         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4740         NUMS=$($CMD | wc -l)
4741         [ $NUMS -eq $EXPECTED ] ||
4742                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4743
4744         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4745         NUMS=$($CMD | wc -l)
4746         [ $NUMS -eq $EXPECTED ] ||
4747                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4748
4749         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4750         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4751         NUMS=$($CMD | wc -l)
4752         [ $NUMS -eq $EXPECTED ] ||
4753                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4754
4755         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4756         NUMS=$($CMD | wc -l)
4757         [ $NUMS -eq $EXPECTED ] ||
4758                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4759
4760         EXPECTED=4
4761         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4762         NUMS=$($CMD | wc -l)
4763         [ $NUMS -eq $EXPECTED ] ||
4764                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4765
4766         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4767         NUMS=$($CMD | wc -l)
4768         [ $NUMS -eq $EXPECTED ] ||
4769                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4770
4771         EXPECTED=0
4772         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4773         NUMS=$($CMD | wc -l)
4774         [ $NUMS -eq $EXPECTED ] ||
4775                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4776 }
4777 run_test 56t "check lfs find -stripe-size works"
4778
4779 test_56u() { # LU-611
4780         TDIR=$DIR/${tdir}u
4781         setup_56 $NUMFILES $NUMDIRS "-i 0"
4782
4783         if [[ $OSTCOUNT -gt 1 ]]; then
4784                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4785                 ONESTRIPE=4
4786         else
4787                 ONESTRIPE=0
4788         fi
4789
4790         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4791         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4792         NUMS=$($CMD | wc -l)
4793         [ $NUMS -eq $EXPECTED ] ||
4794                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4795
4796         EXPECTED=$ONESTRIPE
4797         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4798         NUMS=$($CMD | wc -l)
4799         [ $NUMS -eq $EXPECTED ] ||
4800                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4801
4802         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4803         NUMS=$($CMD | wc -l)
4804         [ $NUMS -eq $EXPECTED ] ||
4805                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4806
4807         EXPECTED=0
4808         # This should produce an error and not return any files
4809         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4810         NUMS=$($CMD 2>/dev/null | wc -l)
4811         [ $NUMS -eq $EXPECTED ] ||
4812                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4813
4814         if [[ $OSTCOUNT -gt 1 ]]; then
4815                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4816                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4817                 NUMS=$($CMD | wc -l)
4818                 [ $NUMS -eq $EXPECTED ] ||
4819                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4820         fi
4821 }
4822 run_test 56u "check lfs find -stripe-index works"
4823
4824 test_56v() {
4825     local MDT_IDX=0
4826
4827     TDIR=$DIR/${tdir}v
4828     rm -rf $TDIR
4829     setup_56 $NUMFILES $NUMDIRS
4830
4831     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4832     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4833
4834     for file in $($LFIND -mdt $UUID $TDIR); do
4835         file_mdt_idx=$($GETSTRIPE -M $file)
4836         [ $file_mdt_idx -eq $MDT_IDX ] ||
4837             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4838     done
4839 }
4840 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4841
4842 test_56w() {
4843         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
4844                 return
4845         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4846         TDIR=$DIR/${tdir}w
4847
4848     rm -rf $TDIR || error "remove $TDIR failed"
4849     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4850
4851     local stripe_size
4852     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4853         error "$GETSTRIPE -S -d $TDIR failed"
4854     stripe_size=${stripe_size%% *}
4855
4856     local file_size=$((stripe_size * OSTCOUNT))
4857     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4858     local required_space=$((file_num * file_size))
4859
4860     local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
4861                         head -n1)
4862     [[ $free_space -le $((required_space / 1024)) ]] &&
4863         skip_env "need at least $required_space bytes free space," \
4864                  "have $free_space kbytes" && return
4865
4866     local dd_bs=65536
4867     local dd_count=$((file_size / dd_bs))
4868
4869     # write data into the files
4870     local i
4871     local j
4872     local file
4873     for i in $(seq 1 $NUMFILES); do
4874         file=$TDIR/file$i
4875         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4876             error "write data into $file failed"
4877     done
4878     for i in $(seq 1 $NUMDIRS); do
4879         for j in $(seq 1 $NUMFILES); do
4880             file=$TDIR/dir$i/file$j
4881             yes | dd bs=$dd_bs count=$dd_count of=$file \
4882                 >/dev/null 2>&1 ||
4883                 error "write data into $file failed"
4884         done
4885     done
4886
4887     local expected=-1
4888     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4889
4890     # lfs_migrate file
4891     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4892     echo "$cmd"
4893     eval $cmd || error "$cmd failed"
4894
4895     check_stripe_count $TDIR/file1 $expected
4896
4897         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
4898         then
4899                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
4900                 # OST 1 if it is on OST 0. This file is small enough to
4901                 # be on only one stripe.
4902                 file=$TDIR/migr_1_ost
4903                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
4904                         error "write data into $file failed"
4905                 local obdidx=$($LFS getstripe -i $file)
4906                 local oldmd5=$(md5sum $file)
4907                 local newobdidx=0
4908                 [[ $obdidx -eq 0 ]] && newobdidx=1
4909                 cmd="$LFS migrate -i $newobdidx $file"
4910                 echo $cmd
4911                 eval $cmd || error "$cmd failed"
4912                 local realobdix=$($LFS getstripe -i $file)
4913                 local newmd5=$(md5sum $file)
4914                 [[ $newobdidx -ne $realobdix ]] &&
4915                         error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
4916                 [[ "$oldmd5" != "$newmd5" ]] &&
4917                         error "md5sum differ: $oldmd5, $newmd5"
4918         fi
4919
4920     # lfs_migrate dir
4921     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4922     echo "$cmd"
4923     eval $cmd || error "$cmd failed"
4924
4925     for j in $(seq 1 $NUMFILES); do
4926         check_stripe_count $TDIR/dir1/file$j $expected
4927     done
4928
4929     # lfs_migrate works with lfs find
4930     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4931          $LFS_MIGRATE -y -c $expected"
4932     echo "$cmd"
4933     eval $cmd || error "$cmd failed"
4934
4935     for i in $(seq 2 $NUMFILES); do
4936         check_stripe_count $TDIR/file$i $expected
4937     done
4938     for i in $(seq 2 $NUMDIRS); do
4939         for j in $(seq 1 $NUMFILES); do
4940             check_stripe_count $TDIR/dir$i/file$j $expected
4941         done
4942     done
4943 }
4944 run_test 56w "check lfs_migrate -c stripe_count works"
4945
4946 test_56x() {
4947         check_swap_layouts_support && return 0
4948         [[ $OSTCOUNT -lt 2 ]] &&
4949                 skip_env "need 2 OST, skipping test" && return
4950
4951         local dir0=$DIR/$tdir/$testnum
4952         test_mkdir -p $dir0 || error "creating dir $dir0"
4953
4954         local ref1=/etc/passwd
4955         local file1=$dir0/file1
4956
4957         $SETSTRIPE -c 2 $file1
4958         cp $ref1 $file1
4959         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4960         stripe=$($GETSTRIPE -c $file1)
4961         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4962         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4963
4964         # clean up
4965         rm -f $file1
4966 }
4967 run_test 56x "lfs migration support"
4968
4969 test_56xa() {
4970         check_swap_layouts_support && return 0
4971         [[ $OSTCOUNT -lt 2 ]] &&
4972                 skip_env "need 2 OST, skipping test" && return
4973
4974         local dir0=$DIR/$tdir/$testnum
4975         test_mkdir -p $dir0 || error "creating dir $dir0"
4976
4977         local ref1=/etc/passwd
4978         local file1=$dir0/file1
4979
4980         $SETSTRIPE -c 2 $file1
4981         cp $ref1 $file1
4982         $LFS migrate --block -c 1 $file1 || error "migrate failed rc = $?"
4983         local stripe=$($GETSTRIPE -c $file1)
4984         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4985         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4986
4987         # clean up
4988         rm -f $file1
4989 }
4990 run_test 56xa "lfs migration --block support"
4991
4992 test_56y() {
4993         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4994                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
4995                 return
4996
4997         local res=""
4998         local dir0=$DIR/$tdir/$testnum
4999         test_mkdir -p $dir0 || error "creating dir $dir0"
5000         local f1=$dir0/file1
5001         local f2=$dir0/file2
5002
5003         touch $f1 || error "creating std file $f1"
5004         $MULTIOP $f2 H2c || error "creating released file $f2"
5005
5006         # a directory can be raid0, so ask only for files
5007         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
5008         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
5009
5010         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
5011         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
5012
5013         # only files can be released, so no need to force file search
5014         res=$($LFIND $dir0 -L released)
5015         [[ $res == $f2 ]] || error "search released: found $res != $f2"
5016
5017         res=$($LFIND $dir0 \! -L released)
5018         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
5019
5020 }
5021 run_test 56y "lfs find -L raid0|released"
5022
5023 test_56z() { # LU-4824
5024         # This checks to make sure 'lfs find' continues after errors
5025         # There are two classes of errors that should be caught:
5026         # - If multiple paths are provided, all should be searched even if one
5027         #   errors out
5028         # - If errors are encountered during the search, it should not terminate
5029         #   early
5030         local i
5031         test_mkdir $DIR/$tdir
5032         for i in d{0..9}; do
5033                 test_mkdir $DIR/$tdir/$i
5034         done
5035         touch $DIR/$tdir/d{0..9}/$tfile
5036         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
5037                 error "$LFS find did not return an error"
5038         # Make a directory unsearchable. This should NOT be the last entry in
5039         # directory order.  Arbitrarily pick the 6th entry
5040         chmod 700 $($LFS find $DIR/$tdir -type d | sed '6!d')
5041         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
5042         # The user should be able to see 10 directories and 9 files
5043         [ $count == 19 ] || error "$LFS find did not continue after error"
5044 }
5045 run_test 56z "lfs find should continue after an error"
5046
5047 test_56aa() { # LU-5937
5048         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5049
5050         mkdir $DIR/$tdir
5051         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
5052
5053         createmany -o $DIR/$tdir/striped_dir/${tfile}- 1024
5054         local dirs=$(lfs find --size +8k $DIR/$tdir/)
5055
5056         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5057 }
5058 run_test 56aa "lfs find --size under striped dir"
5059
5060 test_57a() {
5061         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5062         # note test will not do anything if MDS is not local
5063         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5064                 skip "Only applicable to ldiskfs-based MDTs"
5065                 return
5066         fi
5067
5068         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5069         local MNTDEV="osd*.*MDT*.mntdev"
5070         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
5071         [ -z "$DEV" ] && error "can't access $MNTDEV"
5072         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
5073                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
5074                         error "can't access $DEV"
5075                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
5076                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
5077                 rm $TMP/t57a.dump
5078         done
5079 }
5080 run_test 57a "verify MDS filesystem created with large inodes =="
5081
5082 test_57b() {
5083         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5084         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5085                 skip "Only applicable to ldiskfs-based MDTs"
5086                 return
5087         fi
5088
5089         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5090         local dir=$DIR/$tdir
5091
5092         local FILECOUNT=100
5093         local FILE1=$dir/f1
5094         local FILEN=$dir/f$FILECOUNT
5095
5096         rm -rf $dir || error "removing $dir"
5097         test_mkdir -p -c1 $dir || error "creating $dir"
5098         local mdtidx=$($LFS getstripe -M $dir)
5099         local mdtname=MDT$(printf %04x $mdtidx)
5100         local facet=mds$((mdtidx + 1))
5101
5102         echo "mcreating $FILECOUNT files"
5103         createmany -m $dir/f 1 $FILECOUNT || \
5104                 error "creating files in $dir"
5105
5106         # verify that files do not have EAs yet
5107         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5108         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5109
5110         sync
5111         sleep 1
5112         df $dir  #make sure we get new statfs data
5113         local MDSFREE=$(do_facet $facet \
5114                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5115         local MDCFREE=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5116         echo "opening files to create objects/EAs"
5117         local FILE
5118         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5119                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5120         done
5121
5122         # verify that files have EAs now
5123         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5124         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5125
5126         sleep 1  #make sure we get new statfs data
5127         df $dir
5128         local MDSFREE2=$(do_facet $facet \
5129                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5130         local MDCFREE2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5131         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5132                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5133                         error "MDC before $MDCFREE != after $MDCFREE2"
5134                 else
5135                         echo "MDC before $MDCFREE != after $MDCFREE2"
5136                         echo "unable to confirm if MDS has large inodes"
5137                 fi
5138         fi
5139         rm -rf $dir
5140 }
5141 run_test 57b "default LOV EAs are stored inside large inodes ==="
5142
5143 test_58() {
5144         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5145         [ -z "$(which wiretest 2>/dev/null)" ] &&
5146                         skip_env "could not find wiretest" && return
5147         wiretest
5148 }
5149 run_test 58 "verify cross-platform wire constants =============="
5150
5151 test_59() {
5152         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5153         echo "touch 130 files"
5154         createmany -o $DIR/f59- 130
5155         echo "rm 130 files"
5156         unlinkmany $DIR/f59- 130
5157         sync
5158         # wait for commitment of removal
5159         wait_delete_completed
5160 }
5161 run_test 59 "verify cancellation of llog records async ========="
5162
5163 TEST60_HEAD="test_60 run $RANDOM"
5164 test_60a() {
5165         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5166         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5167         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5168                 do_facet mgs "! ls run-llog.sh &> /dev/null" &&
5169                         skip_env "missing subtest run-llog.sh" && return
5170
5171         log "$TEST60_HEAD - from kernel mode"
5172         do_facet mgs "$LCTL set_param debug=warning; $LCTL dk > /dev/null"
5173         do_facet mgs sh run-llog.sh
5174         do_facet mgs $LCTL dk > $TMP/$tfile
5175
5176         # LU-6388: test llog_reader
5177         local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5178         llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5179         [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5180                         skip_env "missing llog_reader" && return
5181         local fstype=$(facet_fstype mgs)
5182         [ $fstype != ldiskfs -a $fstype != zfs ] &&
5183                 skip_env "Only for ldiskfs or zfs type mgs" && return
5184
5185         local mntpt=$(facet_mntpt mgs)
5186         local mgsdev=$(mgsdevname 1)
5187         local fid_list
5188         local fid
5189         local rec_list
5190         local rec
5191         local rec_type
5192         local obj_file
5193         local path
5194         local seq
5195         local oid
5196         local pass=true
5197
5198         #get fid and record list
5199         fid_list=($(awk '/9_sub.*record/ { print $NF }' /$TMP/$tfile |
5200                 tail -n 4))
5201         rec_list=($(awk '/9_sub.*record/ { print $((NF-3)) }' /$TMP/$tfile |
5202                 tail -n 4))
5203         #remount mgs as ldiskfs or zfs type
5204         stop mgs || error "stop mgs failed"
5205         mount_fstype mgs || error "remount mgs failed"
5206         for ((i = 0; i < ${#fid_list[@]}; i++)); do
5207                 fid=${fid_list[i]}
5208                 rec=${rec_list[i]}
5209                 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
5210                 oid=$(echo $fid | awk -F ':' '{ print $2 }' | sed -e "s/^0x//g")
5211                 oid=$((16#$oid))
5212
5213                 case $fstype in
5214                         ldiskfs )
5215                                 obj_file=$mntpt/O/$seq/d$((oid%32))/$oid ;;
5216                         zfs )
5217                                 obj_file=$mntpt/oi.$(($((16#$seq))&127))/$fid ;;
5218                 esac
5219                 echo "obj_file is $obj_file"
5220                 do_facet mgs $llog_reader $obj_file
5221
5222                 rec_type=$(do_facet mgs $llog_reader $obj_file | grep "type=" |
5223                         awk '{ print $3 }' | sed -e "s/^type=//g")
5224                 if [ $rec_type != $rec ]; then
5225                         echo "FAILED test_60a wrong record type $rec_type," \
5226                               "should be $rec"
5227                         pass=false
5228                         break
5229                 fi
5230
5231                 #check obj path if record type is LLOG_LOGID_MAGIC
5232                 if [ "$rec" == "1064553b" ]; then
5233                         path=$(do_facet mgs $llog_reader $obj_file |
5234                                 grep "path=" | awk '{ print $NF }' |
5235                                 sed -e "s/^path=//g")
5236                         if [ $obj_file != $mntpt/$path ]; then
5237                                 echo "FAILED test_60a wrong obj path" \
5238                                       "$montpt/$path, should be $obj_file"
5239                                 pass=false
5240                                 break
5241                         fi
5242                 fi
5243         done
5244         rm -f $TMP/$tfile
5245         #restart mgs before "error", otherwise it will block the next test
5246         stop mgs || error "stop mgs failed"
5247         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
5248         $pass || error "test failed, see FAILED test_60a messages for specifics"
5249 }
5250 run_test 60a "llog_test run from kernel module and test llog_reader =========="
5251
5252 test_60b() { # bug 6411
5253         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5254         dmesg > $DIR/$tfile
5255         LLOG_COUNT=$(dmesg | awk "/$TEST60_HEAD/ { marker = 1; from_marker = 0; }
5256                                 /llog.test/ {
5257                                         if (marker)
5258                                                 from_marker++
5259                                         from_begin++
5260                                 }
5261                                 END {
5262                                         if (marker)
5263                                                 print from_marker
5264                                         else
5265                                                 print from_begin
5266                                 }")
5267         [[ $LLOG_COUNT -gt 100 ]] &&
5268                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5269 }
5270 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5271
5272 test_60c() {
5273         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5274         echo "create 5000 files"
5275         createmany -o $DIR/f60c- 5000
5276 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5277         lctl set_param fail_loc=0x80000137
5278         unlinkmany $DIR/f60c- 5000
5279         lctl set_param fail_loc=0
5280 }
5281 run_test 60c "unlink file when mds full"
5282
5283 test_60d() {
5284         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5285         SAVEPRINTK=$(lctl get_param -n printk)
5286
5287         # verify "lctl mark" is even working"
5288         MESSAGE="test message ID $RANDOM $$"
5289         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5290         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5291
5292         lctl set_param printk=0 || error "set lnet.printk failed"
5293         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5294         MESSAGE="new test message ID $RANDOM $$"
5295         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5296         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5297         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5298
5299         lctl set_param -n printk="$SAVEPRINTK"
5300 }
5301 run_test 60d "test printk console message masking"
5302
5303 test_60e() {
5304         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5305         touch $DIR/$tfile
5306 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED2  0x15b
5307         do_facet mds1 lctl set_param fail_loc=0x15b
5308         rm $DIR/$tfile
5309 }
5310 run_test 60e "no space while new llog is being created"
5311
5312 test_61() {
5313         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5314         f="$DIR/f61"
5315         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5316         cancel_lru_locks osc
5317         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5318         sync
5319 }
5320 run_test 61 "mmap() writes don't make sync hang ================"
5321
5322 # bug 2330 - insufficient obd_match error checking causes LBUG
5323 test_62() {
5324         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5325         f="$DIR/f62"
5326         echo foo > $f
5327         cancel_lru_locks osc
5328         lctl set_param fail_loc=0x405
5329         cat $f && error "cat succeeded, expect -EIO"
5330         lctl set_param fail_loc=0
5331 }
5332 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5333 # match every page all of the time.
5334 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5335
5336 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5337 # Though this test is irrelevant anymore, it helped to reveal some
5338 # other grant bugs (LU-4482), let's keep it.
5339 test_63a() {   # was test_63
5340         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5341         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5342         for i in `seq 10` ; do
5343                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5344                 sleep 5
5345                 kill $!
5346                 sleep 1
5347         done
5348
5349         rm -f $DIR/f63 || true
5350 }
5351 run_test 63a "Verify oig_wait interruption does not crash ======="
5352
5353 # bug 2248 - async write errors didn't return to application on sync
5354 # bug 3677 - async write errors left page locked
5355 test_63b() {
5356         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5357         debugsave
5358         lctl set_param debug=-1
5359
5360         # ensure we have a grant to do async writes
5361         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5362         rm $DIR/$tfile
5363
5364         sync    # sync lest earlier test intercept the fail_loc
5365
5366         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5367         lctl set_param fail_loc=0x80000406
5368         $MULTIOP $DIR/$tfile Owy && \
5369                 error "sync didn't return ENOMEM"
5370         sync; sleep 2; sync     # do a real sync this time to flush page
5371         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5372                 error "locked page left in cache after async error" || true
5373         debugrestore
5374 }
5375 run_test 63b "async write errors should be returned to fsync ==="
5376
5377 test_64a () {
5378         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5379         df $DIR
5380         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5381 }
5382 run_test 64a "verify filter grant calculations (in kernel) ====="
5383
5384 test_64b () {
5385         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5386         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5387 }
5388 run_test 64b "check out-of-space detection on client ==========="
5389
5390 test_64c() {
5391         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5392 }
5393 run_test 64c "verify grant shrink ========================------"
5394
5395 # bug 1414 - set/get directories' stripe info
5396 test_65a() {
5397         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5398         test_mkdir -p $DIR/$tdir
5399         touch $DIR/$tdir/f1
5400         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5401 }
5402 run_test 65a "directory with no stripe info ===================="
5403
5404 test_65b() {
5405         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5406         test_mkdir -p $DIR/$tdir
5407         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5408
5409         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5410                                                 error "setstripe"
5411         touch $DIR/$tdir/f2
5412         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5413 }
5414 run_test 65b "directory setstripe -S stripe_size*2 -i 0 -c 1"
5415
5416 test_65c() {
5417         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5418         if [[ $OSTCOUNT -gt 1 ]]; then
5419                 test_mkdir -p $DIR/$tdir
5420                 local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5421
5422                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5423                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5424                 touch $DIR/$tdir/f3
5425                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5426         fi
5427 }
5428 run_test 65c "directory setstripe -S stripe_size*4 -i 1 -c $((OSTCOUNT-1))"
5429
5430 test_65d() {
5431         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5432         test_mkdir -p $DIR/$tdir
5433         local STRIPECOUNT=$($GETSTRIPE -c $DIR/$tdir)
5434         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5435
5436         if [[ $STRIPECOUNT -le 0 ]]; then
5437                 sc=1
5438         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5439 #LOV_MAX_STRIPE_COUNT is 2000
5440                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5441         else
5442                 sc=$(($STRIPECOUNT - 1))
5443         fi
5444         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5445         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5446         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5447                 error "lverify failed"
5448 }
5449 run_test 65d "directory setstripe -S stripe_size -c stripe_count"
5450
5451 test_65e() {
5452         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5453         test_mkdir -p $DIR/$tdir
5454
5455         $SETSTRIPE $DIR/$tdir || error "setstripe"
5456         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5457                                         error "no stripe info failed"
5458         touch $DIR/$tdir/f6
5459         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5460 }
5461 run_test 65e "directory setstripe defaults ======================="
5462
5463 test_65f() {
5464         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5465         test_mkdir -p $DIR/${tdir}f
5466         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5467 }
5468 run_test 65f "dir setstripe permission (should return error) ==="
5469
5470 test_65g() {
5471         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5472         test_mkdir -p $DIR/$tdir
5473         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5474
5475         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5476                                                         error "setstripe"
5477         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5478         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5479                 error "delete default stripe failed"
5480 }
5481 run_test 65g "directory setstripe -d ==========================="
5482
5483 test_65h() {
5484         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5485         test_mkdir -p $DIR/$tdir
5486         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5487
5488         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5489                                                         error "setstripe"
5490         test_mkdir -p $DIR/$tdir/dd1
5491         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5492                 error "stripe info inherit failed"
5493 }
5494 run_test 65h "directory stripe info inherit ===================="
5495
5496 test_65i() { # bug6367
5497         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5498         $SETSTRIPE -S 65536 -c -1 $MOUNT
5499 }
5500 run_test 65i "set non-default striping on root directory (bug 6367)="
5501
5502 test_65ia() { # bug12836
5503         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5504         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5505 }
5506 run_test 65ia "getstripe on -1 default directory striping"
5507
5508 test_65ib() { # bug12836
5509         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5510         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5511 }
5512 run_test 65ib "getstripe -v on -1 default directory striping"
5513
5514 test_65ic() { # bug12836
5515         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5516         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5517 }
5518 run_test 65ic "new find on -1 default directory striping"
5519
5520 test_65j() { # bug6367
5521         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5522         sync; sleep 1
5523         # if we aren't already remounting for each test, do so for this test
5524         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5525                 cleanup || error "failed to unmount"
5526                 setup
5527         fi
5528         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5529 }
5530 run_test 65j "set default striping on root directory (bug 6367)="
5531
5532 test_65k() { # bug11679
5533         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5534         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5535         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5536
5537     echo "Check OST status: "
5538     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5539               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5540
5541     for OSC in $MDS_OSCS; do
5542         echo $OSC "is activate"
5543         do_facet $SINGLEMDS lctl --device %$OSC activate
5544     done
5545
5546     mkdir -p $DIR/$tdir
5547     for INACTIVE_OSC in $MDS_OSCS; do
5548         echo "Deactivate: " $INACTIVE_OSC
5549         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5550         for STRIPE_OSC in $MDS_OSCS; do
5551             OST=`osc_to_ost $STRIPE_OSC`
5552             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5553                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5554
5555             [ -f $DIR/$tdir/$IDX ] && continue
5556             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5557             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5558             RC=$?
5559             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5560         done
5561         rm -f $DIR/$tdir/*
5562         echo $INACTIVE_OSC "is Activate."
5563         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5564     done
5565 }
5566 run_test 65k "validate manual striping works properly with deactivated OSCs"
5567
5568 test_65l() { # bug 12836
5569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5570         test_mkdir -p $DIR/$tdir/test_dir
5571         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5572         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5573 }
5574 run_test 65l "lfs find on -1 stripe dir ========================"
5575
5576 # bug 2543 - update blocks count on client
5577 test_66() {
5578         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5579         COUNT=${COUNT:-8}
5580         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5581         sync; sync_all_data; sync; sync_all_data
5582         cancel_lru_locks osc
5583         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5584         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5585 }
5586 run_test 66 "update inode blocks count on client ==============="
5587
5588 LLOOP=
5589 LLITELOOPLOAD=
5590 cleanup_68() {
5591         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5592         trap 0
5593         if [ ! -z "$LLOOP" ]; then
5594                 if swapon -s | grep -q $LLOOP; then
5595                         swapoff $LLOOP || error "swapoff failed"
5596                 fi
5597
5598                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5599                 rm -f $LLOOP
5600                 unset LLOOP
5601         fi
5602         if [ ! -z "$LLITELOOPLOAD" ]; then
5603                 rmmod llite_lloop
5604                 unset LLITELOOPLOAD
5605         fi
5606         rm -f $DIR/f68*
5607 }
5608
5609 meminfo() {
5610         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5611 }
5612
5613 swap_used() {
5614         swapon -s | awk '($1 == "'$1'") { print $4 }'
5615 }
5616
5617 # test case for lloop driver, basic function
5618 test_68a() {
5619         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5620         [ "$UID" != 0 ] && skip_env "must run as root" && return
5621         llite_lloop_enabled || \
5622                 { skip_env "llite_lloop module disabled" && return; }
5623
5624         trap cleanup_68 EXIT
5625
5626         if ! module_loaded llite_lloop; then
5627                 if load_module llite/llite_lloop; then
5628                         LLITELOOPLOAD=yes
5629                 else
5630                         skip_env "can't find module llite_lloop"
5631                         return
5632                 fi
5633         fi
5634
5635         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5636         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5637         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5638
5639         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5640         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5641
5642         cleanup_68
5643 }
5644 run_test 68a "lloop driver - basic test ========================"
5645
5646 # excercise swapping to lustre by adding a high priority swapfile entry
5647 # and then consuming memory until it is used.
5648 test_68b() {  # was test_68
5649         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5650         [ "$UID" != 0 ] && skip_env "must run as root" && return
5651         lctl get_param -n devices | grep -q obdfilter && \
5652                 skip "local OST" && return
5653
5654         grep -q llite_lloop /proc/modules
5655         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5656
5657         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5658                 skip "can't reliably test swap with TCP" && return
5659
5660         MEMTOTAL=`meminfo MemTotal`
5661         NR_BLOCKS=$((MEMTOTAL>>8))
5662         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5663
5664         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5665         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5666         mkswap $DIR/f68b
5667
5668         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5669
5670         trap cleanup_68 EXIT
5671
5672         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5673
5674         echo "before: `swapon -s | grep $LLOOP`"
5675         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5676         echo "after: `swapon -s | grep $LLOOP`"
5677         SWAPUSED=`swap_used $LLOOP`
5678
5679         cleanup_68
5680
5681         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5682 }
5683 run_test 68b "support swapping to Lustre ========================"
5684
5685 # bug5265, obdfilter oa2dentry return -ENOENT
5686 # #define OBD_FAIL_SRV_ENOENT 0x217
5687 test_69() {
5688         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5689         remote_ost_nodsh && skip "remote OST with nodsh" && return
5690
5691         f="$DIR/$tfile"
5692         $SETSTRIPE -c 1 -i 0 $f
5693
5694         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5695
5696         do_facet ost1 lctl set_param fail_loc=0x217
5697         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5698         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5699
5700         do_facet ost1 lctl set_param fail_loc=0
5701         $DIRECTIO write $f 0 2 || error "write error"
5702
5703         cancel_lru_locks osc
5704         $DIRECTIO read $f 0 1 || error "read error"
5705
5706         do_facet ost1 lctl set_param fail_loc=0x217
5707         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5708
5709         do_facet ost1 lctl set_param fail_loc=0
5710         rm -f $f
5711 }
5712 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5713
5714 test_71() {
5715         test_mkdir -p $DIR/$tdir
5716         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
5717         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5718 }
5719 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5720
5721 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5722         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5723         [ "$RUNAS_ID" = "$UID" ] &&
5724                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5725
5726         # Check that testing environment is properly set up. Skip if not
5727         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5728                 skip_env "User $RUNAS_ID does not exist - skipping"
5729                 return 0
5730         }
5731         touch $DIR/$tfile
5732         chmod 777 $DIR/$tfile
5733         chmod ug+s $DIR/$tfile
5734         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5735                 error "$RUNAS dd $DIR/$tfile failed"
5736         # See if we are still setuid/sgid
5737         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5738                 error "S/gid is not dropped on write"
5739         # Now test that MDS is updated too
5740         cancel_lru_locks mdc
5741         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5742                 error "S/gid is not dropped on MDS"
5743         rm -f $DIR/$tfile
5744 }
5745 run_test 72a "Test that remove suid works properly (bug5695) ===="
5746
5747 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5748         local perm
5749
5750         [ "$RUNAS_ID" = "$UID" ] && \
5751                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5752         [ "$RUNAS_ID" -eq 0 ] && \
5753                 skip_env "RUNAS_ID = 0 -- skipping" && return
5754
5755         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5756         # Check that testing environment is properly set up. Skip if not
5757         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5758                 skip_env "User $RUNAS_ID does not exist - skipping"
5759                 return 0
5760         }
5761         touch $DIR/${tfile}-f{g,u}
5762         test_mkdir $DIR/${tfile}-dg
5763         test_mkdir $DIR/${tfile}-du
5764         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5765         chmod g+s $DIR/${tfile}-{f,d}g
5766         chmod u+s $DIR/${tfile}-{f,d}u
5767         for perm in 777 2777 4777; do
5768                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5769                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5770                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5771                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5772         done
5773         true
5774 }
5775 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5776
5777 # bug 3462 - multiple simultaneous MDC requests
5778 test_73() {
5779         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5780         test_mkdir $DIR/d73-1
5781         test_mkdir $DIR/d73-2
5782         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5783         pid1=$!
5784
5785         lctl set_param fail_loc=0x80000129
5786         $MULTIOP $DIR/d73-1/f73-2 Oc &
5787         sleep 1
5788         lctl set_param fail_loc=0
5789
5790         $MULTIOP $DIR/d73-2/f73-3 Oc &
5791         pid3=$!
5792
5793         kill -USR1 $pid1
5794         wait $pid1 || return 1
5795
5796         sleep 25
5797
5798         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5799         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5800         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5801
5802         rm -rf $DIR/d73-*
5803 }
5804 run_test 73 "multiple MDC requests (should not deadlock)"
5805
5806 test_74a() { # bug 6149, 6184
5807         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5808         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5809         #
5810         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5811         # will spin in a tight reconnection loop
5812         touch $DIR/f74a
5813         $LCTL set_param fail_loc=0x8000030e
5814         # get any lock that won't be difficult - lookup works.
5815         ls $DIR/f74a
5816         $LCTL set_param fail_loc=0
5817         rm -f $DIR/f74a
5818         true
5819 }
5820 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5821
5822 test_74b() { # bug 13310
5823         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5824         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5825         #
5826         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5827         # will spin in a tight reconnection loop
5828         $LCTL set_param fail_loc=0x8000030e
5829         # get a "difficult" lock
5830         touch $DIR/f74b
5831         $LCTL set_param fail_loc=0
5832         rm -f $DIR/f74b
5833         true
5834 }
5835 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5836
5837 test_74c() {
5838         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5839         #define OBD_FAIL_LDLM_NEW_LOCK
5840         $LCTL set_param fail_loc=0x319
5841         touch $DIR/$tfile && error "touch successful"
5842         $LCTL set_param fail_loc=0
5843         true
5844 }
5845 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5846
5847 num_inodes() {
5848         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5849 }
5850
5851 get_inode_slab_tunables() {
5852         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5853 }
5854
5855 set_inode_slab_tunables() {
5856         echo "lustre_inode_cache $1" > /proc/slabinfo
5857 }
5858
5859 test_76() { # Now for bug 20433, added originally in bug 1443
5860         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5861         local SLAB_SETTINGS=`get_inode_slab_tunables`
5862         local CPUS=`getconf _NPROCESSORS_ONLN`
5863         # we cannot set limit below 1 which means 1 inode in each
5864         # per-cpu cache is still allowed
5865         set_inode_slab_tunables "1 1 0"
5866         cancel_lru_locks osc
5867         BEFORE_INODES=$(num_inodes)
5868         echo "before inodes: $BEFORE_INODES"
5869         local COUNT=1000
5870         [ "$SLOW" = "no" ] && COUNT=100
5871         for i in $(seq $COUNT); do
5872                 touch $DIR/$tfile
5873                 rm -f $DIR/$tfile
5874         done
5875         cancel_lru_locks osc
5876         AFTER_INODES=$(num_inodes)
5877         echo "after inodes: $AFTER_INODES"
5878         local wait=0
5879         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5880                 sleep 2
5881                 AFTER_INODES=$(num_inodes)
5882                 wait=$((wait+2))
5883                 echo "wait $wait seconds inodes: $AFTER_INODES"
5884                 if [ $wait -gt 30 ]; then
5885                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5886                 fi
5887         done
5888         set_inode_slab_tunables "$SLAB_SETTINGS"
5889 }
5890 run_test 76 "confirm clients recycle inodes properly ===="
5891
5892
5893 export ORIG_CSUM=""
5894 set_checksums()
5895 {
5896         # Note: in sptlrpc modes which enable its own bulk checksum, the
5897         # original crc32_le bulk checksum will be automatically disabled,
5898         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5899         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5900         # In this case set_checksums() will not be no-op, because sptlrpc
5901         # bulk checksum will be enabled all through the test.
5902
5903         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5904         lctl set_param -n osc.*.checksums $1
5905         return 0
5906 }
5907
5908 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5909                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5910 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5911 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5912 set_checksum_type()
5913 {
5914         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5915         log "set checksum type to $1"
5916         return 0
5917 }
5918 F77_TMP=$TMP/f77-temp
5919 F77SZ=8
5920 setup_f77() {
5921         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5922                 error "error writing to $F77_TMP"
5923 }
5924
5925 test_77a() { # bug 10889
5926         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5927         $GSS && skip "could not run with gss" && return
5928         [ ! -f $F77_TMP ] && setup_f77
5929         set_checksums 1
5930         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5931         set_checksums 0
5932         rm -f $DIR/$tfile
5933 }
5934 run_test 77a "normal checksum read/write operation"
5935
5936 test_77b() { # bug 10889
5937         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5938         $GSS && skip "could not run with gss" && return
5939         [ ! -f $F77_TMP ] && setup_f77
5940         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5941         $LCTL set_param fail_loc=0x80000409
5942         set_checksums 1
5943
5944         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5945                 error "dd error: $?"
5946         $LCTL set_param fail_loc=0
5947
5948         for algo in $CKSUM_TYPES; do
5949                 cancel_lru_locks osc
5950                 set_checksum_type $algo
5951                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5952                 $LCTL set_param fail_loc=0x80000408
5953                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5954                 $LCTL set_param fail_loc=0
5955         done
5956         set_checksums 0
5957         set_checksum_type $ORIG_CSUM_TYPE
5958         rm -f $DIR/$tfile
5959 }
5960 run_test 77b "checksum error on client write, read"
5961
5962 test_77d() { # bug 10889
5963         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5964         $GSS && skip "could not run with gss" && return
5965         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5966         $LCTL set_param fail_loc=0x80000409
5967         set_checksums 1
5968         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5969                 error "direct write: rc=$?"
5970         $LCTL set_param fail_loc=0
5971         set_checksums 0
5972
5973         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5974         $LCTL set_param fail_loc=0x80000408
5975         set_checksums 1
5976         cancel_lru_locks osc
5977         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5978                 error "direct read: rc=$?"
5979         $LCTL set_param fail_loc=0
5980         set_checksums 0
5981 }
5982 run_test 77d "checksum error on OST direct write, read"
5983
5984 test_77f() { # bug 10889
5985         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5986         $GSS && skip "could not run with gss" && return
5987         set_checksums 1
5988         for algo in $CKSUM_TYPES; do
5989                 cancel_lru_locks osc
5990                 set_checksum_type $algo
5991                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5992                 $LCTL set_param fail_loc=0x409
5993                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5994                         error "direct write succeeded"
5995                 $LCTL set_param fail_loc=0
5996         done
5997         set_checksum_type $ORIG_CSUM_TYPE
5998         set_checksums 0
5999 }
6000 run_test 77f "repeat checksum error on write (expect error)"
6001
6002 test_77g() { # bug 10889
6003         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6004         $GSS && skip "could not run with gss" && return
6005         remote_ost_nodsh && skip "remote OST with nodsh" && return
6006
6007         [ ! -f $F77_TMP ] && setup_f77
6008
6009         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
6010         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
6011         do_facet ost1 lctl set_param fail_loc=0x8000021a
6012         set_checksums 1
6013         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
6014                 error "write error: rc=$?"
6015         do_facet ost1 lctl set_param fail_loc=0
6016         set_checksums 0
6017
6018         cancel_lru_locks osc
6019         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
6020         do_facet ost1 lctl set_param fail_loc=0x8000021b
6021         set_checksums 1
6022         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
6023         do_facet ost1 lctl set_param fail_loc=0
6024         set_checksums 0
6025 }
6026 run_test 77g "checksum error on OST write, read"
6027
6028 test_77i() { # bug 13805
6029         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6030         $GSS && skip "could not run with gss" && return
6031         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
6032         lctl set_param fail_loc=0x40b
6033         remount_client $MOUNT
6034         lctl set_param fail_loc=0
6035         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
6036                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
6037                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
6038                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
6039         done
6040         remount_client $MOUNT
6041 }
6042 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
6043
6044 test_77j() { # bug 13805
6045         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6046         $GSS && skip "could not run with gss" && return
6047         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
6048         lctl set_param fail_loc=0x40c
6049         remount_client $MOUNT
6050         lctl set_param fail_loc=0
6051         sleep 2 # wait async osc connect to finish
6052         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
6053                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
6054                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
6055                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
6056         done
6057         remount_client $MOUNT
6058 }
6059 run_test 77j "client only supporting ADLER32"
6060
6061 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
6062 rm -f $F77_TMP
6063 unset F77_TMP
6064
6065 test_78() { # bug 10901
6066         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6067         remote_ost || { skip_env "local OST" && return; }
6068
6069         NSEQ=5
6070         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
6071         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
6072         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
6073         echo "MemTotal: $MEMTOTAL"
6074
6075         # reserve 256MB of memory for the kernel and other running processes,
6076         # and then take 1/2 of the remaining memory for the read/write buffers.
6077         if [ $MEMTOTAL -gt 512 ] ;then
6078                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
6079         else
6080                 # for those poor memory-starved high-end clusters...
6081                 MEMTOTAL=$((MEMTOTAL / 2))
6082         fi
6083         echo "Mem to use for directio: $MEMTOTAL"
6084
6085         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
6086         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
6087         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
6088         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
6089                 head -n1)
6090         echo "Smallest OST: $SMALLESTOST"
6091         [[ $SMALLESTOST -lt 10240 ]] &&
6092                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
6093
6094         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
6095                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
6096
6097         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
6098         echo "File size: $F78SIZE"
6099         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
6100         for i in $(seq 1 $NSEQ); do
6101                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
6102                 echo directIO rdwr round $i of $NSEQ
6103                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
6104         done
6105
6106         rm -f $DIR/$tfile
6107 }
6108 run_test 78 "handle large O_DIRECT writes correctly ============"
6109
6110 test_79() { # bug 12743
6111         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6112         wait_delete_completed
6113
6114         BKTOTAL=$(calc_osc_kbytes kbytestotal)
6115         BKFREE=$(calc_osc_kbytes kbytesfree)
6116         BKAVAIL=$(calc_osc_kbytes kbytesavail)
6117
6118         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
6119         DFTOTAL=`echo $STRING | cut -d, -f1`
6120         DFUSED=`echo $STRING  | cut -d, -f2`
6121         DFAVAIL=`echo $STRING | cut -d, -f3`
6122         DFFREE=$(($DFTOTAL - $DFUSED))
6123
6124         ALLOWANCE=$((64 * $OSTCOUNT))
6125
6126         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
6127            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
6128                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
6129         fi
6130         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
6131            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
6132                 error "df free($DFFREE) mismatch OST free($BKFREE)"
6133         fi
6134         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
6135            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
6136                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
6137         fi
6138 }
6139 run_test 79 "df report consistency check ======================="
6140
6141 test_80() { # bug 10718
6142         remote_ost_nodsh && skip "remote OST with nodsh" && return
6143         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6144         # relax strong synchronous semantics for slow backends like ZFS
6145         local soc="obdfilter.*.sync_on_lock_cancel"
6146         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
6147         local hosts=
6148         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
6149                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
6150                           facet_active_host $host; done | sort -u)
6151                 do_nodes $hosts lctl set_param $soc=never
6152         fi
6153
6154         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
6155         sync; sleep 1; sync
6156         local BEFORE=`date +%s`
6157         cancel_lru_locks osc
6158         local AFTER=`date +%s`
6159         local DIFF=$((AFTER-BEFORE))
6160         if [ $DIFF -gt 1 ] ; then
6161                 error "elapsed for 1M@1T = $DIFF"
6162         fi
6163
6164         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
6165
6166         rm -f $DIR/$tfile
6167 }
6168 run_test 80 "Page eviction is equally fast at high offsets too  ===="
6169
6170 test_81a() { # LU-456
6171         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6172         remote_ost_nodsh && skip "remote OST with nodsh" && return
6173         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6174         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
6175         do_facet ost1 lctl set_param fail_loc=0x80000228
6176
6177         # write should trigger a retry and success
6178         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6179         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6180         RC=$?
6181         if [ $RC -ne 0 ] ; then
6182                 error "write should success, but failed for $RC"
6183         fi
6184 }
6185 run_test 81a "OST should retry write when get -ENOSPC ==============="
6186
6187 test_81b() { # LU-456
6188         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6189         remote_ost_nodsh && skip "remote OST with nodsh" && return
6190         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6191         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
6192         do_facet ost1 lctl set_param fail_loc=0x228
6193
6194         # write should retry several times and return -ENOSPC finally
6195         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6196         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6197         RC=$?
6198         ENOSPC=28
6199         if [ $RC -ne $ENOSPC ] ; then
6200                 error "dd should fail for -ENOSPC, but succeed."
6201         fi
6202 }
6203 run_test 81b "OST should return -ENOSPC when retry still fails ======="
6204
6205 test_82() { # LU-1031
6206         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
6207         local gid1=14091995
6208         local gid2=16022000
6209
6210         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
6211         local MULTIPID1=$!
6212         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
6213         local MULTIPID2=$!
6214         kill -USR1 $MULTIPID2
6215         sleep 2
6216         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6217                 error "First grouplock does not block second one"
6218         else
6219                 echo "Second grouplock blocks first one"
6220         fi
6221         kill -USR1 $MULTIPID1
6222         wait $MULTIPID1
6223         wait $MULTIPID2
6224 }
6225 run_test 82 "Basic grouplock test ==============================="
6226
6227 test_99a() {
6228         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6229                 return
6230         test_mkdir -p $DIR/d99cvsroot
6231         chown $RUNAS_ID $DIR/d99cvsroot
6232         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6233         cd $TMP
6234
6235         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6236         cd $oldPWD
6237 }
6238 run_test 99a "cvs init ========================================="
6239
6240 test_99b() {
6241         [ -z "$(which cvs 2>/dev/null)" ] &&
6242                 skip_env "could not find cvs" && return
6243         [ ! -d $DIR/d99cvsroot ] && test_99a
6244         cd /etc/init.d
6245         # some versions of cvs import exit(1) when asked to import links or
6246         # files they can't read.  ignore those files.
6247         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6248                         ! -perm /4 -printf '-I %f\n')
6249         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6250                 d99reposname vtag rtag
6251 }
6252 run_test 99b "cvs import ======================================="
6253
6254 test_99c() {
6255         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6256         [ ! -d $DIR/d99cvsroot ] && test_99b
6257         cd $DIR
6258         test_mkdir -p $DIR/d99reposname
6259         chown $RUNAS_ID $DIR/d99reposname
6260         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6261 }
6262 run_test 99c "cvs checkout ====================================="
6263
6264 test_99d() {
6265         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6266         [ ! -d $DIR/d99cvsroot ] && test_99c
6267         cd $DIR/d99reposname
6268         $RUNAS touch foo99
6269         $RUNAS cvs add -m 'addmsg' foo99
6270 }
6271 run_test 99d "cvs add =========================================="
6272
6273 test_99e() {
6274         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6275         [ ! -d $DIR/d99cvsroot ] && test_99c
6276         cd $DIR/d99reposname
6277         $RUNAS cvs update
6278 }
6279 run_test 99e "cvs update ======================================="
6280
6281 test_99f() {
6282         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6283         [ ! -d $DIR/d99cvsroot ] && test_99d
6284         cd $DIR/d99reposname
6285         $RUNAS cvs commit -m 'nomsg' foo99
6286     rm -fr $DIR/d99cvsroot
6287 }
6288 run_test 99f "cvs commit ======================================="
6289
6290 test_100() {
6291         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6292         [ "$NETTYPE" = tcp ] || \
6293                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
6294                         return ; }
6295
6296         remote_ost_nodsh && skip "remote OST with nodsh" && return
6297         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6298         remote_servers || \
6299                 { skip "useless for local single node setup" && return; }
6300
6301         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6302                 [ "$PROT" != "tcp" ] && continue
6303                 RPORT=$(echo $REMOTE | cut -d: -f2)
6304                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6305
6306                 rc=0
6307                 LPORT=`echo $LOCAL | cut -d: -f2`
6308                 if [ $LPORT -ge 1024 ]; then
6309                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6310                         netstat -tna
6311                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6312                 fi
6313         done
6314         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6315 }
6316 run_test 100 "check local port using privileged port ==========="
6317
6318 function get_named_value()
6319 {
6320     local tag
6321
6322     tag=$1
6323     while read ;do
6324         line=$REPLY
6325         case $line in
6326         $tag*)
6327             echo $line | sed "s/^$tag[ ]*//"
6328             break
6329             ;;
6330         esac
6331     done
6332 }
6333
6334 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6335                    awk '/^max_cached_mb/ { print $2 }')
6336
6337 cleanup_101a() {
6338         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6339         trap 0
6340 }
6341
6342 test_101a() {
6343         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6344         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
6345         local s
6346         local discard
6347         local nreads=10000
6348         local cache_limit=32
6349
6350         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6351         trap cleanup_101a EXIT
6352         $LCTL set_param -n llite.*.read_ahead_stats 0
6353         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6354
6355         #
6356         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6357         #
6358         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6359         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6360
6361         discard=0
6362         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6363                 get_named_value 'read but discarded' | cut -d" " -f1); do
6364                         discard=$(($discard + $s))
6365         done
6366         cleanup_101a
6367
6368         if [[ $(($discard * 10)) -gt $nreads ]]; then
6369                 $LCTL get_param osc.*-osc*.rpc_stats
6370                 $LCTL get_param llite.*.read_ahead_stats
6371                 error "too many ($discard) discarded pages"
6372         fi
6373         rm -f $DIR/$tfile || true
6374 }
6375 run_test 101a "check read-ahead for random reads ================"
6376
6377 setup_test101bc() {
6378         test_mkdir -p $DIR/$tdir
6379         local STRIPE_SIZE=$1
6380         local FILE_LENGTH=$2
6381         STRIPE_OFFSET=0
6382
6383         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6384
6385         local list=$(comma_list $(osts_nodes))
6386         set_osd_param $list '' read_cache_enable 0
6387         set_osd_param $list '' writethrough_cache_enable 0
6388
6389         trap cleanup_test101bc EXIT
6390         # prepare the read-ahead file
6391         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6392
6393         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6394                                 count=$FILE_SIZE_MB 2> /dev/null
6395
6396 }
6397
6398 cleanup_test101bc() {
6399         trap 0
6400         rm -rf $DIR/$tdir
6401         rm -f $DIR/$tfile
6402
6403         local list=$(comma_list $(osts_nodes))
6404         set_osd_param $list '' read_cache_enable 1
6405         set_osd_param $list '' writethrough_cache_enable 1
6406 }
6407
6408 calc_total() {
6409         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6410 }
6411
6412 ra_check_101() {
6413         local READ_SIZE=$1
6414         local STRIPE_SIZE=$2
6415         local FILE_LENGTH=$3
6416         local RA_INC=1048576
6417         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6418         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6419                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6420         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6421                         get_named_value 'read but discarded' |
6422                         cut -d" " -f1 | calc_total)
6423         if [[ $DISCARD -gt $discard_limit ]]; then
6424                 $LCTL get_param llite.*.read_ahead_stats
6425                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6426         else
6427                 echo "Read-ahead success for size ${READ_SIZE}"
6428         fi
6429 }
6430
6431 test_101b() {
6432         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6433         [[ $OSTCOUNT -lt 2 ]] &&
6434                 skip_env "skipping stride IO stride-ahead test" && return
6435         local STRIPE_SIZE=1048576
6436         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6437         if [ $SLOW == "yes" ]; then
6438                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6439         else
6440                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6441         fi
6442
6443         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6444
6445         # prepare the read-ahead file
6446         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6447         cancel_lru_locks osc
6448         for BIDX in 2 4 8 16 32 64 128 256
6449         do
6450                 local BSIZE=$((BIDX*4096))
6451                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6452                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6453                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6454                 $LCTL set_param -n llite.*.read_ahead_stats 0
6455                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6456                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6457                 cancel_lru_locks osc
6458                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6459         done
6460         cleanup_test101bc
6461         true
6462 }
6463 run_test 101b "check stride-io mode read-ahead ================="
6464
6465 test_101c() {
6466         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6467         local STRIPE_SIZE=1048576
6468         local FILE_LENGTH=$((STRIPE_SIZE*100))
6469         local nreads=10000
6470         local osc_rpc_stats
6471
6472         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6473
6474         cancel_lru_locks osc
6475         $LCTL set_param osc.*.rpc_stats 0
6476         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6477         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6478                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6479                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6480                 local size
6481
6482                 if [ $lines -le 20 ]; then
6483                         continue
6484                 fi
6485                 for size in 1 2 4 8; do
6486                         local rpc=$(echo "$stats" |
6487                                     awk '($1 == "'$size':") {print $2; exit; }')
6488                         [ $rpc != 0 ] &&
6489                                 error "Small $((size*4))k read IO $rpc !"
6490                 done
6491                 echo "$osc_rpc_stats check passed!"
6492         done
6493         cleanup_test101bc
6494         true
6495 }
6496 run_test 101c "check stripe_size aligned read-ahead ================="
6497
6498 set_read_ahead() {
6499         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6500         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6501 }
6502
6503 test_101d() {
6504         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6505         local file=$DIR/$tfile
6506         local sz_MB=${FILESIZE_101d:-500}
6507         local ra_MB=${READAHEAD_MB:-40}
6508
6509         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6510         [ $free_MB -lt $sz_MB ] &&
6511                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6512
6513         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6514         $SETSTRIPE -c -1 $file || error "setstripe failed"
6515
6516         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6517         echo Cancel LRU locks on lustre client to flush the client cache
6518         cancel_lru_locks osc
6519
6520         echo Disable read-ahead
6521         local old_READAHEAD=$(set_read_ahead 0)
6522
6523         echo Reading the test file $file with read-ahead disabled
6524         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6525
6526         echo Cancel LRU locks on lustre client to flush the client cache
6527         cancel_lru_locks osc
6528         echo Enable read-ahead with ${ra_MB}MB
6529         set_read_ahead $ra_MB
6530
6531         echo Reading the test file $file with read-ahead enabled
6532         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6533
6534         echo "read-ahead disabled time read $raOFF"
6535         echo "read-ahead enabled  time read $raON"
6536
6537         set_read_ahead $old_READAHEAD
6538         rm -f $file
6539         wait_delete_completed
6540
6541         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6542                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6543 }
6544 run_test 101d "file read with and without read-ahead enabled"
6545
6546 test_101e() {
6547         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6548         local file=$DIR/$tfile
6549         local size_KB=500  #KB
6550         local count=100
6551         local bsize=1024
6552
6553         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6554         local need_KB=$((count * size_KB))
6555         [[ $free_KB -le $need_KB ]] &&
6556                 skip_env "Need free space $need_KB, have $free_KB" && return
6557
6558         echo "Creating $count ${size_KB}K test files"
6559         for ((i = 0; i < $count; i++)); do
6560                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6561         done
6562
6563         echo "Cancel LRU locks on lustre client to flush the client cache"
6564         cancel_lru_locks osc
6565
6566         echo "Reset readahead stats"
6567         $LCTL set_param -n llite.*.read_ahead_stats 0
6568
6569         for ((i = 0; i < $count; i++)); do
6570                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6571         done
6572
6573         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6574                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6575
6576         for ((i = 0; i < $count; i++)); do
6577                 rm -rf $file.$i 2>/dev/null
6578         done
6579
6580         #10000 means 20% reads are missing in readahead
6581         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6582 }
6583 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6584
6585 test_101f() {
6586         which iozone || { skip "no iozone installed" && return; }
6587
6588         # create a test file
6589         iozone -i 0 -+n -r 1m -s 128m -w -f $DIR/$tfile > /dev/null 2>&1
6590
6591         echo Cancel LRU locks on lustre client to flush the client cache
6592         cancel_lru_locks osc
6593
6594         echo Reset readahead stats
6595         $LCTL set_param -n llite.*.read_ahead_stats 0
6596
6597         echo mmap read the file with small block size
6598         iozone -i 1 -+n -r 32k -s 128m -B -f $DIR/$tfile > /dev/null 2>&1
6599
6600         echo checking missing pages
6601         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6602                         get_named_value 'misses' | cut -d" " -f1 | calc_total)
6603
6604         [ $miss -lt 3 ] || error "misses too much pages!"
6605         rm -f $DIR/$tfile
6606 }
6607 run_test 101f "check mmap read performance"
6608
6609 test_101g() {
6610         local rpcs
6611         local osts=$(get_facets OST)
6612         local list=$(comma_list $(osts_nodes))
6613         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
6614
6615         save_lustre_params $osts "obdfilter.*.brw_size" > $p
6616
6617         $LFS setstripe -c 1 $DIR/$tfile
6618
6619         if [ $(lustre_version_code ost1) -ge $(version_code 2.8.52) ]; then
6620                 set_osd_param $list '' brw_size 16M
6621
6622                 echo "remount client to enable large RPC size"
6623                 remount_client $MOUNT || error "remount_client failed"
6624
6625                 for mp in $($LCTL get_param -n osc.*.max_pages_per_rpc); do
6626                         [ "$mp" -eq 4096 ] ||
6627                                 error "max_pages_per_rpc not correctly set"
6628                 done
6629
6630                 $LCTL set_param -n osc.*.rpc_stats=0
6631
6632                 # 10*16 MiB should be enough for the test
6633                 dd if=/dev/zero of=$DIR/$tfile bs=16M count=10
6634                 cancel_lru_locks osc
6635                 dd of=/dev/null if=$DIR/$tfile bs=16M count=10
6636
6637                 # calculate 16 MiB RPCs
6638                 rpcs=$($LCTL get_param 'osc.*.rpc_stats' |
6639                        sed -n '/pages per rpc/,/^$/p' |
6640                        awk 'BEGIN { sum = 0 }; /4096:/ { sum += $2 };
6641                             END { print sum }')
6642                 echo $rpcs RPCs
6643                 [ "$rpcs" -eq 10 ] || error "not all RPCs are 16 MiB BRW rpcs"
6644         fi
6645
6646         echo "set RPC size to 4MB"
6647
6648         $LCTL set_param -n osc.*.max_pages_per_rpc=4M osc.*.rpc_stats=0
6649         dd if=/dev/zero of=$DIR/$tfile bs=4M count=25
6650         cancel_lru_locks osc
6651         dd of=/dev/null if=$DIR/$tfile bs=4M count=25
6652
6653         # calculate 4 MiB RPCs
6654         rpcs=$($LCTL get_param 'osc.*.rpc_stats' |
6655                 sed -n '/pages per rpc/,/^$/p' |
6656                 awk 'BEGIN { sum = 0 }; /1024:/ { sum += $2 };
6657                      END { print sum }')
6658         echo $rpcs RPCs
6659         [ "$rpcs" -eq 25 ] || error "not all RPCs are 4 MiB BRW rpcs"
6660
6661         restore_lustre_params < $p
6662         remount_client $MOUNT || error "remount_client failed"
6663
6664         rm -f $p $DIR/$tfile
6665 }
6666 run_test 101g "Big bulk(4/16 MiB) readahead"
6667
6668 setup_test102() {
6669         test_mkdir -p $DIR/$tdir
6670         chown $RUNAS_ID $DIR/$tdir
6671         STRIPE_SIZE=65536
6672         STRIPE_OFFSET=1
6673         STRIPE_COUNT=$OSTCOUNT
6674         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6675
6676         trap cleanup_test102 EXIT
6677         cd $DIR
6678         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6679         cd $DIR/$tdir
6680         for num in 1 2 3 4; do
6681                 for count in $(seq 1 $STRIPE_COUNT); do
6682                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6683                                 local size=`expr $STRIPE_SIZE \* $num`
6684                                 local file=file"$num-$idx-$count"
6685                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6686                         done
6687                 done
6688         done
6689
6690         cd $DIR
6691         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6692 }
6693
6694 cleanup_test102() {
6695         trap 0
6696         rm -f $TMP/f102.tar
6697         rm -rf $DIR/d0.sanity/d102
6698 }
6699
6700 test_102a() {
6701         local testfile=$DIR/$tfile
6702
6703         touch $testfile
6704
6705         [ "$UID" != 0 ] && skip_env "must run as root" && return
6706         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6707                 skip_env "must have user_xattr" && return
6708
6709         [ -z "$(which setfattr 2>/dev/null)" ] &&
6710                 skip_env "could not find setfattr" && return
6711
6712         echo "set/get xattr..."
6713         setfattr -n trusted.name1 -v value1 $testfile ||
6714                 error "setfattr -n trusted.name1=value1 $testfile failed"
6715         getfattr -n trusted.name1 $testfile 2> /dev/null |
6716           grep "trusted.name1=.value1" ||
6717                 error "$testfile missing trusted.name1=value1"
6718
6719         setfattr -n user.author1 -v author1 $testfile ||
6720                 error "setfattr -n user.author1=author1 $testfile failed"
6721         getfattr -n user.author1 $testfile 2> /dev/null |
6722           grep "user.author1=.author1" ||
6723                 error "$testfile missing trusted.author1=author1"
6724
6725         echo "listxattr..."
6726         setfattr -n trusted.name2 -v value2 $testfile ||
6727                 error "$testfile unable to set trusted.name2"
6728         setfattr -n trusted.name3 -v value3 $testfile ||
6729                 error "$testfile unable to set trusted.name3"
6730         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6731             grep "trusted.name" | wc -l) -eq 3 ] ||
6732                 error "$testfile missing 3 trusted.name xattrs"
6733
6734         setfattr -n user.author2 -v author2 $testfile ||
6735                 error "$testfile unable to set user.author2"
6736         setfattr -n user.author3 -v author3 $testfile ||
6737                 error "$testfile unable to set user.author3"
6738         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6739             grep "user.author" | wc -l) -eq 3 ] ||
6740                 error "$testfile missing 3 user.author xattrs"
6741
6742         echo "remove xattr..."
6743         setfattr -x trusted.name1 $testfile ||
6744                 error "$testfile error deleting trusted.name1"
6745         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6746                 error "$testfile did not delete trusted.name1 xattr"
6747
6748         setfattr -x user.author1 $testfile ||
6749                 error "$testfile error deleting user.author1"
6750         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6751                 error "$testfile did not delete trusted.name1 xattr"
6752
6753         # b10667: setting lustre special xattr be silently discarded
6754         echo "set lustre special xattr ..."
6755         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6756                 error "$testfile allowed setting trusted.lov"
6757 }
6758 run_test 102a "user xattr test =================================="
6759
6760 test_102b() {
6761         [ -z "$(which setfattr 2>/dev/null)" ] &&
6762                 skip_env "could not find setfattr" && return
6763
6764         # b10930: get/set/list trusted.lov xattr
6765         echo "get/set/list trusted.lov xattr ..."
6766         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6767         local testfile=$DIR/$tfile
6768         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6769                 error "setstripe failed"
6770         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6771                 error "getstripe failed"
6772         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6773                 error "can't get trusted.lov from $testfile"
6774
6775         local testfile2=${testfile}2
6776         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6777                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6778
6779         $MCREATE $testfile2
6780         setfattr -n trusted.lov -v $value $testfile2
6781         local stripe_size=$($GETSTRIPE -S $testfile2)
6782         local stripe_count=$($GETSTRIPE -c $testfile2)
6783         [[ $stripe_size -eq 65536 ]] ||
6784                 error "stripe size $stripe_size != 65536"
6785         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6786                 error "stripe count $stripe_count != $STRIPECOUNT"
6787         rm -f $DIR/$tfile
6788 }
6789 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6790
6791 test_102c() {
6792         [ -z "$(which setfattr 2>/dev/null)" ] &&
6793                 skip_env "could not find setfattr" && return
6794
6795         # b10930: get/set/list lustre.lov xattr
6796         echo "get/set/list lustre.lov xattr ..."
6797         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6798         test_mkdir -p $DIR/$tdir
6799         chown $RUNAS_ID $DIR/$tdir
6800         local testfile=$DIR/$tdir/$tfile
6801         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6802                 error "setstripe failed"
6803         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6804                 error "getstripe failed"
6805         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6806         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6807
6808         local testfile2=${testfile}2
6809         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6810                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6811
6812         $RUNAS $MCREATE $testfile2
6813         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6814         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6815         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6816         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6817         [ $stripe_count -eq $STRIPECOUNT ] ||
6818                 error "stripe count $stripe_count != $STRIPECOUNT"
6819 }
6820 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6821
6822 compare_stripe_info1() {
6823         local stripe_index_all_zero=true
6824
6825         for num in 1 2 3 4; do
6826                 for count in $(seq 1 $STRIPE_COUNT); do
6827                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6828                                 local size=$((STRIPE_SIZE * num))
6829                                 local file=file"$num-$offset-$count"
6830                                 stripe_size=$($LFS getstripe -S $PWD/$file)
6831                                 [[ $stripe_size -ne $size ]] &&
6832                                     error "$file: size $stripe_size != $size"
6833                                 stripe_count=$($LFS getstripe -c $PWD/$file)
6834                                 # allow fewer stripes to be created, ORI-601
6835                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6836                                     error "$file: count $stripe_count != $count"
6837                                 stripe_index=$($LFS getstripe -i $PWD/$file)
6838                                 [[ $stripe_index -ne 0 ]] &&
6839                                         stripe_index_all_zero=false
6840                         done
6841                 done
6842         done
6843         $stripe_index_all_zero &&
6844                 error "all files are being extracted starting from OST index 0"
6845         return 0
6846 }
6847
6848 find_lustre_tar() {
6849         [ -n "$(which tar 2>/dev/null)" ] &&
6850                 strings $(which tar) | grep -q "lustre" && echo tar
6851 }
6852
6853 test_102d() {
6854         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6855         # b10930: tar test for trusted.lov xattr
6856         TAR=$(find_lustre_tar)
6857         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6858         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6859         setup_test102
6860         test_mkdir -p $DIR/d102d
6861         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6862         cd $DIR/d102d/$tdir
6863         compare_stripe_info1
6864 }
6865 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6866
6867 test_102f() {
6868         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6869         # b10930: tar test for trusted.lov xattr
6870         TAR=$(find_lustre_tar)
6871         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6872         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6873         setup_test102
6874         test_mkdir -p $DIR/d102f
6875         cd $DIR
6876         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6877         cd $DIR/d102f/$tdir
6878         compare_stripe_info1
6879 }
6880 run_test 102f "tar copy files, not keep osts ==========="
6881
6882 grow_xattr() {
6883         local xsize=${1:-1024}  # in bytes
6884         local file=$DIR/$tfile
6885
6886         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep xattr)" ] &&
6887                 skip "must have user_xattr" && return 0
6888         [ -z "$(which setfattr 2>/dev/null)" ] &&
6889                 skip_env "could not find setfattr" && return 0
6890         [ -z "$(which getfattr 2>/dev/null)" ] &&
6891                 skip_env "could not find getfattr" && return 0
6892
6893         touch $file
6894
6895         local value="$(generate_string $xsize)"
6896
6897         local xbig=trusted.big
6898         log "save $xbig on $file"
6899         setfattr -n $xbig -v $value $file ||
6900                 error "saving $xbig on $file failed"
6901
6902         local orig=$(get_xattr_value $xbig $file)
6903         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6904
6905         local xsml=trusted.sml
6906         log "save $xsml on $file"
6907         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6908
6909         local new=$(get_xattr_value $xbig $file)
6910         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6911
6912         log "grow $xsml on $file"
6913         setfattr -n $xsml -v "$value" $file ||
6914                 error "growing $xsml on $file failed"
6915
6916         new=$(get_xattr_value $xbig $file)
6917         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6918         log "$xbig still valid after growing $xsml"
6919
6920         rm -f $file
6921 }
6922
6923 test_102h() { # bug 15777
6924         grow_xattr 1024
6925 }
6926 run_test 102h "grow xattr from inside inode to external block"
6927
6928 test_102ha() {
6929         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6930         grow_xattr $(max_xattr_size)
6931 }
6932 run_test 102ha "grow xattr from inside inode to external inode"
6933
6934 test_102i() { # bug 17038
6935         [ -z "$(which getfattr 2>/dev/null)" ] &&
6936                 skip "could not find getfattr" && return
6937         touch $DIR/$tfile
6938         ln -s $DIR/$tfile $DIR/${tfile}link
6939         getfattr -n trusted.lov $DIR/$tfile ||
6940                 error "lgetxattr on $DIR/$tfile failed"
6941         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6942                 grep -i "no such attr" ||
6943                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6944         rm -f $DIR/$tfile $DIR/${tfile}link
6945 }
6946 run_test 102i "lgetxattr test on symbolic link ============"
6947
6948 test_102j() {
6949         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6950         TAR=$(find_lustre_tar)
6951         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6952         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6953         setup_test102 "$RUNAS"
6954         test_mkdir -p $DIR/d102j
6955         chown $RUNAS_ID $DIR/d102j
6956         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6957         cd $DIR/d102j/$tdir
6958         compare_stripe_info1 "$RUNAS"
6959 }
6960 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6961
6962 test_102k() {
6963         [ -z "$(which setfattr 2>/dev/null)" ] &&
6964                 skip "could not find setfattr" && return
6965         touch $DIR/$tfile
6966         # b22187 just check that does not crash for regular file.
6967         setfattr -n trusted.lov $DIR/$tfile
6968         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6969         local test_kdir=$DIR/d102k
6970         test_mkdir $test_kdir
6971         local default_size=`$GETSTRIPE -S $test_kdir`
6972         local default_count=`$GETSTRIPE -c $test_kdir`
6973         local default_offset=`$GETSTRIPE -i $test_kdir`
6974         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6975                 error 'dir setstripe failed'
6976         setfattr -n trusted.lov $test_kdir
6977         local stripe_size=`$GETSTRIPE -S $test_kdir`
6978         local stripe_count=`$GETSTRIPE -c $test_kdir`
6979         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6980         [ $stripe_size -eq $default_size ] ||
6981                 error "stripe size $stripe_size != $default_size"
6982         [ $stripe_count -eq $default_count ] ||
6983                 error "stripe count $stripe_count != $default_count"
6984         [ $stripe_offset -eq $default_offset ] ||
6985                 error "stripe offset $stripe_offset != $default_offset"
6986         rm -rf $DIR/$tfile $test_kdir
6987 }
6988 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6989
6990 test_102l() {
6991         [ -z "$(which getfattr 2>/dev/null)" ] &&
6992                 skip "could not find getfattr" && return
6993
6994         # LU-532 trusted. xattr is invisible to non-root
6995         local testfile=$DIR/$tfile
6996
6997         touch $testfile
6998
6999         echo "listxattr as user..."
7000         chown $RUNAS_ID $testfile
7001         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
7002             grep -q "trusted" &&
7003                 error "$testfile trusted xattrs are user visible"
7004
7005         return 0;
7006 }
7007 run_test 102l "listxattr size test =================================="
7008
7009 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
7010         local path=$DIR/$tfile
7011         touch $path
7012
7013         listxattr_size_check $path || error "listattr_size_check $path failed"
7014 }
7015 run_test 102m "Ensure listxattr fails on small bufffer ========"
7016
7017 cleanup_test102
7018
7019 getxattr() { # getxattr path name
7020         # Return the base64 encoding of the value of xattr name on path.
7021         local path=$1
7022         local name=$2
7023
7024         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
7025         # file: $path
7026         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
7027         #
7028         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
7029
7030         getfattr --absolute-names --encoding=base64 --name=$name $path |
7031                 awk -F= -v name=$name '$1 == name {
7032                         print substr($0, index($0, "=") + 1);
7033         }'
7034 }
7035
7036 test_102n() { # LU-4101 mdt: protect internal xattrs
7037         local file0=$DIR/$tfile.0
7038         local file1=$DIR/$tfile.1
7039         local xattr0=$TMP/$tfile.0
7040         local xattr1=$TMP/$tfile.1
7041         local name
7042         local value
7043
7044         [ -z "$(which setfattr 2>/dev/null)" ] &&
7045                 skip "could not find setfattr" && return
7046
7047         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
7048         then
7049                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
7050                 return
7051         fi
7052
7053         rm -rf $file0 $file1 $xattr0 $xattr1
7054         touch $file0 $file1
7055
7056         # Get 'before' xattrs of $file1.
7057         getfattr --absolute-names --dump --match=- $file1 > $xattr0
7058
7059         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
7060                 # Try to copy xattr from $file0 to $file1.
7061                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7062
7063                 setfattr --name=trusted.$name --value="$value" $file1 ||
7064                         error "setxattr 'trusted.$name' failed"
7065
7066                 # Try to set a garbage xattr.
7067                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7068
7069                 setfattr --name=trusted.$name --value="$value" $file1 ||
7070                         error "setxattr 'trusted.$name' failed"
7071
7072                 # Try to remove the xattr from $file1. We don't care if this
7073                 # appears to succeed or fail, we just don't want there to be
7074                 # any changes or crashes.
7075                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7076         done
7077
7078         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
7079         then
7080                 name="lfsck_ns"
7081                 # Try to copy xattr from $file0 to $file1.
7082                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7083
7084                 setfattr --name=trusted.$name --value="$value" $file1 ||
7085                         error "setxattr 'trusted.$name' failed"
7086
7087                 # Try to set a garbage xattr.
7088                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7089
7090                 setfattr --name=trusted.$name --value="$value" $file1 ||
7091                         error "setxattr 'trusted.$name' failed"
7092
7093                 # Try to remove the xattr from $file1. We don't care if this
7094                 # appears to succeed or fail, we just don't want there to be
7095                 # any changes or crashes.
7096                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7097         fi
7098
7099         # Get 'after' xattrs of file1.
7100         getfattr --absolute-names --dump --match=- $file1 > $xattr1
7101
7102         if ! diff $xattr0 $xattr1; then
7103                 error "before and after xattrs of '$file1' differ"
7104         fi
7105
7106         rm -rf $file0 $file1 $xattr0 $xattr1
7107
7108         return 0
7109 }
7110 run_test 102n "silently ignore setxattr on internal trusted xattrs"
7111
7112 test_102p() { # LU-4703 setxattr did not check ownership
7113         local testfile=$DIR/$tfile
7114
7115         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
7116                 skip "MDS needs to be at least 2.5.56" && return
7117
7118         touch $testfile
7119
7120         echo "setfacl as user..."
7121         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
7122         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
7123
7124         echo "setfattr as user..."
7125         setfacl -m "u:$RUNAS_ID:---" $testfile
7126         $RUNAS setfattr -x system.posix_acl_access $testfile
7127         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
7128 }
7129 run_test 102p "check setxattr(2) correctly fails without permission"
7130
7131 test_102q() {
7132         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
7133                 skip "MDS needs to be at least 2.6.92" && return
7134         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
7135 }
7136 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
7137
7138 test_102r() {
7139         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
7140                 skip "MDS needs to be at least 2.6.93" && return
7141         touch $DIR/$tfile || error "touch"
7142         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
7143         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
7144         rm $DIR/$tfile || error "rm"
7145
7146         #normal directory
7147         mkdir -p $DIR/$tdir || error "mkdir"
7148         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7149         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7150         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7151                 error "$testfile error deleting user.author1"
7152         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7153                 grep "user.$(basename $tdir)" &&
7154                 error "$tdir did not delete user.$(basename $tdir)"
7155         rmdir $DIR/$tdir || error "rmdir"
7156
7157         #striped directory
7158         test_mkdir -p $DIR/$tdir || error "make striped dir"
7159         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7160         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7161         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7162                 error "$testfile error deleting user.author1"
7163         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7164                 grep "user.$(basename $tdir)" &&
7165                 error "$tdir did not delete user.$(basename $tdir)"
7166         rmdir $DIR/$tdir || error "rm striped dir"
7167 }
7168 run_test 102r "set EAs with empty values"
7169
7170 run_acl_subtest()
7171 {
7172     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
7173     return $?
7174 }
7175
7176 test_103a() {
7177         [ "$UID" != 0 ] && skip_env "must run as root" && return
7178         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
7179                 skip "must have acl enabled" && return
7180         [ -z "$(which setfacl 2>/dev/null)" ] &&
7181                 skip_env "could not find setfacl" && return
7182         $GSS && skip "could not run under gss" && return
7183
7184         gpasswd -a daemon bin                           # LU-5641
7185         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
7186
7187         declare -a identity_old
7188
7189         for num in $(seq $MDSCOUNT); do
7190                 switch_identity $num true || identity_old[$num]=$?
7191         done
7192
7193         SAVE_UMASK=$(umask)
7194         umask 0022
7195         cd $DIR
7196
7197         echo "performing cp ..."
7198         run_acl_subtest cp || error "run_acl_subtest cp failed"
7199         echo "performing getfacl-noacl..."
7200         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
7201         echo "performing misc..."
7202         run_acl_subtest misc || error  "misc test failed"
7203         echo "performing permissions..."
7204         run_acl_subtest permissions || error "permissions failed"
7205         echo "performing setfacl..."
7206         run_acl_subtest setfacl || error  "setfacl test failed"
7207
7208         # inheritance test got from HP
7209         echo "performing inheritance..."
7210         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
7211         chmod +x make-tree || error "chmod +x failed"
7212         run_acl_subtest inheritance || error "inheritance test failed"
7213         rm -f make-tree
7214
7215         echo "LU-974 ignore umask when acl is enabled..."
7216         run_acl_subtest 974 || error "LU-974 umask test failed"
7217         if [ $MDSCOUNT -ge 2 ]; then
7218                 run_acl_subtest 974_remote ||
7219                         error "LU-974 umask test failed under remote dir"
7220         fi
7221
7222         echo "LU-2561 newly created file is same size as directory..."
7223         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
7224                 run_acl_subtest 2561 || error "LU-2561 test failed"
7225         else
7226                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
7227         fi
7228
7229         run_acl_subtest 4924 || error "LU-4924 test failed"
7230
7231         cd $SAVE_PWD
7232         umask $SAVE_UMASK
7233
7234         for num in $(seq $MDSCOUNT); do
7235                 if [ "${identity_old[$num]}" = 1 ]; then
7236                         switch_identity $num false || identity_old[$num]=$?
7237                 fi
7238         done
7239 }
7240 run_test 103a "acl test ========================================="
7241
7242 test_103b() {
7243         local noacl=false
7244         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
7245         local mountopts=$MDS_MOUNT_OPTS
7246
7247         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
7248                 noacl=true
7249         else
7250                 # stop the MDT
7251                 stop $SINGLEMDS || error "failed to stop MDT."
7252                 # remount the MDT
7253                 if [ -z "$MDS_MOUNT_OPTS" ]; then
7254                         MDS_MOUNT_OPTS="-o noacl"
7255                 else
7256                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
7257                 fi
7258                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7259                         error "failed to start MDT."
7260                 MDS_MOUNT_OPTS=$mountopts
7261         fi
7262
7263         touch $DIR/$tfile
7264         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
7265
7266         if ! $noacl; then
7267                 # stop the MDT
7268                 stop $SINGLEMDS || error "failed to stop MDT."
7269                 # remount the MDT
7270                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7271                         error "failed to start MDT."
7272         fi
7273
7274         true
7275 }
7276 run_test 103b "MDS mount option 'noacl'"
7277
7278 test_103c() {
7279         mkdir -p $DIR/$tdir
7280         cp -rp $DIR/$tdir $DIR/$tdir.bak
7281
7282         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
7283                 error "$DIR/$tdir shouldn't contain default ACL"
7284         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
7285                 error "$DIR/$tdir.bak shouldn't contain default ACL"
7286         true
7287 }
7288 run_test 103c "'cp -rp' won't set empty acl"
7289
7290 test_104a() {
7291         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7292         touch $DIR/$tfile
7293         lfs df || error "lfs df failed"
7294         lfs df -ih || error "lfs df -ih failed"
7295         lfs df -h $DIR || error "lfs df -h $DIR failed"
7296         lfs df -i $DIR || error "lfs df -i $DIR failed"
7297         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
7298         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
7299
7300         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
7301         lctl --device %$OSC deactivate
7302         lfs df || error "lfs df with deactivated OSC failed"
7303         lctl --device %$OSC activate
7304         # wait the osc back to normal
7305         wait_osc_import_state client ost FULL
7306
7307         lfs df || error "lfs df with reactivated OSC failed"
7308         rm -f $DIR/$tfile
7309 }
7310 run_test 104a "lfs df [-ih] [path] test ========================="
7311
7312 test_104b() {
7313         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7314         [ $RUNAS_ID -eq $UID ] &&
7315                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
7316         chmod 666 /dev/obd
7317         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
7318                         grep "Permission denied" | wc -l)))
7319         if [ $denied_cnt -ne 0 ]; then
7320                 error "lfs check servers test failed"
7321         fi
7322 }
7323 run_test 104b "$RUNAS lfs check servers test ===================="
7324
7325 test_105a() {
7326         # doesn't work on 2.4 kernels
7327         touch $DIR/$tfile
7328         if $(flock_is_enabled); then
7329                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7330         else
7331                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7332         fi
7333         rm -f $DIR/$tfile
7334 }
7335 run_test 105a "flock when mounted without -o flock test ========"
7336
7337 test_105b() {
7338         touch $DIR/$tfile
7339         if $(flock_is_enabled); then
7340                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7341         else
7342                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7343         fi
7344         rm -f $DIR/$tfile
7345 }
7346 run_test 105b "fcntl when mounted without -o flock test ========"
7347
7348 test_105c() {
7349         touch $DIR/$tfile
7350         if $(flock_is_enabled); then
7351                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7352         else
7353                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7354         fi
7355         rm -f $DIR/$tfile
7356 }
7357 run_test 105c "lockf when mounted without -o flock test ========"
7358
7359 test_105d() { # bug 15924
7360         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7361         test_mkdir -p $DIR/$tdir
7362         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7363         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7364         $LCTL set_param fail_loc=0x80000315
7365         flocks_test 2 $DIR/$tdir
7366 }
7367 run_test 105d "flock race (should not freeze) ========"
7368
7369 test_105e() { # bug 22660 && 22040
7370         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7371         touch $DIR/$tfile
7372         flocks_test 3 $DIR/$tfile
7373 }
7374 run_test 105e "Two conflicting flocks from same process ======="
7375
7376 test_106() { #bug 10921
7377         test_mkdir -p $DIR/$tdir
7378         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7379         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7380 }
7381 run_test 106 "attempt exec of dir followed by chown of that dir"
7382
7383 test_107() {
7384         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7385         CDIR=`pwd`
7386         cd $DIR
7387
7388         local file=core
7389         rm -f $file
7390
7391         local save_pattern=$(sysctl -n kernel.core_pattern)
7392         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7393         sysctl -w kernel.core_pattern=$file
7394         sysctl -w kernel.core_uses_pid=0
7395
7396         ulimit -c unlimited
7397         sleep 60 &
7398         SLEEPPID=$!
7399
7400         sleep 1
7401
7402         kill -s 11 $SLEEPPID
7403         wait $SLEEPPID
7404         if [ -e $file ]; then
7405                 size=`stat -c%s $file`
7406                 [ $size -eq 0 ] && error "Fail to create core file $file"
7407         else
7408                 error "Fail to create core file $file"
7409         fi
7410         rm -f $file
7411         sysctl -w kernel.core_pattern=$save_pattern
7412         sysctl -w kernel.core_uses_pid=$save_uses_pid
7413         cd $CDIR
7414 }
7415 run_test 107 "Coredump on SIG"
7416
7417 test_110() {
7418         test_mkdir -p $DIR/$tdir
7419         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7420                 error "mkdir with 255 char failed"
7421         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7422                 error "mkdir with 256 char should fail, but did not"
7423         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7424                 error "create with 255 char failed"
7425         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7426                 error "create with 256 char should fail, but did not"
7427
7428         ls -l $DIR/$tdir
7429         rm -rf $DIR/$tdir
7430 }
7431 run_test 110 "filename length checking"
7432
7433 test_115() {
7434         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7435         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
7436                 tail -1 | cut -c11-20)
7437         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
7438         echo "Starting with $OSTIO_pre threads"
7439
7440         NUMTEST=20000
7441         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7442         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
7443         echo "$NUMTEST creates/unlinks"
7444         test_mkdir -p $DIR/$tdir
7445         createmany -o $DIR/$tdir/$tfile $NUMTEST
7446         unlinkmany $DIR/$tdir/$tfile $NUMTEST
7447
7448         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
7449                 tail -1 | cut -c11-20)
7450
7451         # don't return an error
7452         [ $OSTIO_post == $OSTIO_pre ] && echo \
7453             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
7454             echo "This may be fine, depending on what ran before this test" &&
7455             echo "and how fast this system is." && return
7456
7457         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
7458 }
7459 run_test 115 "verify dynamic thread creation===================="
7460
7461 free_min_max () {
7462         wait_delete_completed
7463         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7464         echo OST kbytes available: ${AVAIL[@]}
7465         MAXI=0; MAXV=${AVAIL[0]}
7466         MINI=0; MINV=${AVAIL[0]}
7467         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7468                 #echo OST $i: ${AVAIL[i]}kb
7469                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7470                         MAXV=${AVAIL[i]}; MAXI=$i
7471                 fi
7472                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7473                         MINV=${AVAIL[i]}; MINI=$i
7474                 fi
7475         done
7476         echo Min free space: OST $MINI: $MINV
7477         echo Max free space: OST $MAXI: $MAXV
7478 }
7479
7480 test_116a() { # was previously test_116()
7481         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7482         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7483
7484         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
7485
7486         echo -n "Free space priority "
7487         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7488                 head -n1
7489         declare -a AVAIL
7490         free_min_max
7491
7492         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7493         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7494                 && return
7495         trap simple_cleanup_common EXIT
7496
7497
7498         # Check if we need to generate uneven OSTs
7499         test_mkdir -p $DIR/$tdir/OST${MINI}
7500         local FILL=$(($MINV / 4))
7501         local DIFF=$(($MAXV - $MINV))
7502         local DIFF2=$(($DIFF * 100 / $MINV))
7503
7504         local threshold=$(do_facet $SINGLEMDS \
7505                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7506         threshold=${threshold%%%}
7507         echo -n "Check for uneven OSTs: "
7508         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7509
7510         if [[ $DIFF2 -gt $threshold ]]; then
7511                 echo "ok"
7512                 echo "Don't need to fill OST$MINI"
7513         else
7514                 # generate uneven OSTs. Write 2% over the QOS threshold value
7515                 echo "no"
7516                 DIFF=$(($threshold - $DIFF2 + 2))
7517                 DIFF2=$(( ($MINV * $DIFF)/100 ))
7518                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
7519                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7520                         error "setstripe failed"
7521                 DIFF=$(($DIFF2 / 2048))
7522                 i=0
7523                 while [ $i -lt $DIFF ]; do
7524                         i=$(($i + 1))
7525                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7526                                 bs=2M count=1 2>/dev/null
7527                         echo -n .
7528                 done
7529                 echo .
7530                 sync
7531                 sleep_maxage
7532                 free_min_max
7533         fi
7534
7535         DIFF=$(($MAXV - $MINV))
7536         DIFF2=$(($DIFF * 100 / $MINV))
7537         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
7538         if [[ $DIFF2 -gt $threshold ]]; then
7539                 echo "ok"
7540         else
7541                 echo "failed - QOS mode won't be used"
7542                 skip "QOS imbalance criteria not met"
7543                 simple_cleanup_common
7544                 return
7545         fi
7546
7547         MINI1=$MINI; MINV1=$MINV
7548         MAXI1=$MAXI; MAXV1=$MAXV
7549
7550         # now fill using QOS
7551         $SETSTRIPE -c 1 $DIR/$tdir
7552         FILL=$(($FILL / 200))
7553         if [ $FILL -gt 600 ]; then
7554                 FILL=600
7555         fi
7556         echo "writing $FILL files to QOS-assigned OSTs"
7557         i=0
7558         while [ $i -lt $FILL ]; do
7559                 i=$((i + 1))
7560                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7561                         count=1 2>/dev/null
7562                 echo -n .
7563         done
7564         echo "wrote $i 200k files"
7565         sync
7566         sleep_maxage
7567
7568         echo "Note: free space may not be updated, so measurements might be off"
7569         free_min_max
7570         DIFF2=$(($MAXV - $MINV))
7571         echo "free space delta: orig $DIFF final $DIFF2"
7572         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7573         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
7574         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7575         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
7576         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7577         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7578         [ $DIFF -gt 0 ] &&
7579                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7580
7581         # Figure out which files were written where
7582         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7583                   awk '/'$MINI1': / {print $2; exit}')
7584         echo $UUID
7585         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7586         echo "$MINC files created on smaller OST $MINI1"
7587         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7588                   awk '/'$MAXI1': / {print $2; exit}')
7589         echo $UUID
7590         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7591         echo "$MAXC files created on larger OST $MAXI1"
7592         FILL=$(($MAXC * 100 / $MINC - 100))
7593         [[ $MINC -gt 0 ]] &&
7594                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7595         [[ $MAXC -gt $MINC ]] ||
7596                 error_ignore LU-9 "stripe QOS didn't balance free space"
7597         simple_cleanup_common
7598 }
7599 run_test 116a "stripe QOS: free space balance ==================="
7600
7601 test_116b() { # LU-2093
7602         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7603         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7604
7605 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7606         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7607                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7608         [ -z "$old_rr" ] && skip "no QOS" && return 0
7609         do_facet $SINGLEMDS lctl set_param \
7610                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7611         mkdir -p $DIR/$tdir
7612         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7613         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7614         do_facet $SINGLEMDS lctl set_param fail_loc=0
7615         rm -rf $DIR/$tdir
7616         do_facet $SINGLEMDS lctl set_param \
7617                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7618 }
7619 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7620
7621 test_117() # bug 10891
7622 {
7623         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7624         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7625         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7626         lctl set_param fail_loc=0x21e
7627         > $DIR/$tfile || error "truncate failed"
7628         lctl set_param fail_loc=0
7629         echo "Truncate succeeded."
7630         rm -f $DIR/$tfile
7631 }
7632 run_test 117 "verify osd extend =========="
7633
7634 NO_SLOW_RESENDCOUNT=4
7635 export OLD_RESENDCOUNT=""
7636 set_resend_count () {
7637         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7638         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7639         lctl set_param -n $PROC_RESENDCOUNT $1
7640         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7641 }
7642
7643 # for reduce test_118* time (b=14842)
7644 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7645
7646 # Reset async IO behavior after error case
7647 reset_async() {
7648         FILE=$DIR/reset_async
7649
7650         # Ensure all OSCs are cleared
7651         $SETSTRIPE -c -1 $FILE
7652         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7653         sync
7654         rm $FILE
7655 }
7656
7657 test_118a() #bug 11710
7658 {
7659         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7660         reset_async
7661
7662         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7663         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7664         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7665
7666         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7667                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7668                 return 1;
7669         fi
7670         rm -f $DIR/$tfile
7671 }
7672 run_test 118a "verify O_SYNC works =========="
7673
7674 test_118b()
7675 {
7676         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7677         remote_ost_nodsh && skip "remote OST with nodsh" && return
7678
7679         reset_async
7680
7681         #define OBD_FAIL_SRV_ENOENT 0x217
7682         set_nodes_failloc "$(osts_nodes)" 0x217
7683         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7684         RC=$?
7685         set_nodes_failloc "$(osts_nodes)" 0
7686         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7687         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7688                     grep -c writeback)
7689
7690         if [[ $RC -eq 0 ]]; then
7691                 error "Must return error due to dropped pages, rc=$RC"
7692                 return 1;
7693         fi
7694
7695         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7696                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7697                 return 1;
7698         fi
7699
7700         echo "Dirty pages not leaked on ENOENT"
7701
7702         # Due to the above error the OSC will issue all RPCs syncronously
7703         # until a subsequent RPC completes successfully without error.
7704         $MULTIOP $DIR/$tfile Ow4096yc
7705         rm -f $DIR/$tfile
7706
7707         return 0
7708 }
7709 run_test 118b "Reclaim dirty pages on fatal error =========="
7710
7711 test_118c()
7712 {
7713         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7714
7715         # for 118c, restore the original resend count, LU-1940
7716         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7717                                 set_resend_count $OLD_RESENDCOUNT
7718         remote_ost_nodsh && skip "remote OST with nodsh" && return
7719
7720         reset_async
7721
7722         #define OBD_FAIL_OST_EROFS               0x216
7723         set_nodes_failloc "$(osts_nodes)" 0x216
7724
7725         # multiop should block due to fsync until pages are written
7726         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7727         MULTIPID=$!
7728         sleep 1
7729
7730         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7731                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7732         fi
7733
7734         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7735                     grep -c writeback)
7736         if [[ $WRITEBACK -eq 0 ]]; then
7737                 error "No page in writeback, writeback=$WRITEBACK"
7738         fi
7739
7740         set_nodes_failloc "$(osts_nodes)" 0
7741         wait $MULTIPID
7742         RC=$?
7743         if [[ $RC -ne 0 ]]; then
7744                 error "Multiop fsync failed, rc=$RC"
7745         fi
7746
7747         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7748         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7749                     grep -c writeback)
7750         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7751                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7752         fi
7753
7754         rm -f $DIR/$tfile
7755         echo "Dirty pages flushed via fsync on EROFS"
7756         return 0
7757 }
7758 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7759
7760 # continue to use small resend count to reduce test_118* time (b=14842)
7761 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7762
7763 test_118d()
7764 {
7765         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7766         remote_ost_nodsh && skip "remote OST with nodsh" && return
7767
7768         reset_async
7769
7770         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7771         set_nodes_failloc "$(osts_nodes)" 0x214
7772         # multiop should block due to fsync until pages are written
7773         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7774         MULTIPID=$!
7775         sleep 1
7776
7777         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7778                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7779         fi
7780
7781         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7782                     grep -c writeback)
7783         if [[ $WRITEBACK -eq 0 ]]; then
7784                 error "No page in writeback, writeback=$WRITEBACK"
7785         fi
7786
7787         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7788         set_nodes_failloc "$(osts_nodes)" 0
7789
7790         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7791         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7792                     grep -c writeback)
7793         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7794                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7795         fi
7796
7797         rm -f $DIR/$tfile
7798         echo "Dirty pages gaurenteed flushed via fsync"
7799         return 0
7800 }
7801 run_test 118d "Fsync validation inject a delay of the bulk =========="
7802
7803 test_118f() {
7804         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7805         reset_async
7806
7807         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7808         lctl set_param fail_loc=0x8000040a
7809
7810         # Should simulate EINVAL error which is fatal
7811         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7812         RC=$?
7813         if [[ $RC -eq 0 ]]; then
7814                 error "Must return error due to dropped pages, rc=$RC"
7815         fi
7816
7817         lctl set_param fail_loc=0x0
7818
7819         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7820         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7821         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7822                     grep -c writeback)
7823         if [[ $LOCKED -ne 0 ]]; then
7824                 error "Locked pages remain in cache, locked=$LOCKED"
7825         fi
7826
7827         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7828                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7829         fi
7830
7831         rm -f $DIR/$tfile
7832         echo "No pages locked after fsync"
7833
7834         reset_async
7835         return 0
7836 }
7837 run_test 118f "Simulate unrecoverable OSC side error =========="
7838
7839 test_118g() {
7840         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7841         reset_async
7842
7843         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7844         lctl set_param fail_loc=0x406
7845
7846         # simulate local -ENOMEM
7847         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7848         RC=$?
7849
7850         lctl set_param fail_loc=0
7851         if [[ $RC -eq 0 ]]; then
7852                 error "Must return error due to dropped pages, rc=$RC"
7853         fi
7854
7855         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7856         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7857         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7858                         grep -c writeback)
7859         if [[ $LOCKED -ne 0 ]]; then
7860                 error "Locked pages remain in cache, locked=$LOCKED"
7861         fi
7862
7863         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7864                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7865         fi
7866
7867         rm -f $DIR/$tfile
7868         echo "No pages locked after fsync"
7869
7870         reset_async
7871         return 0
7872 }
7873 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7874
7875 test_118h() {
7876         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7877         remote_ost_nodsh && skip "remote OST with nodsh" && return
7878
7879         reset_async
7880
7881         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7882         set_nodes_failloc "$(osts_nodes)" 0x20e
7883         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7884         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7885         RC=$?
7886
7887         set_nodes_failloc "$(osts_nodes)" 0
7888         if [[ $RC -eq 0 ]]; then
7889                 error "Must return error due to dropped pages, rc=$RC"
7890         fi
7891
7892         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7893         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7894         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7895                     grep -c writeback)
7896         if [[ $LOCKED -ne 0 ]]; then
7897                 error "Locked pages remain in cache, locked=$LOCKED"
7898         fi
7899
7900         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7901                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7902         fi
7903
7904         rm -f $DIR/$tfile
7905         echo "No pages locked after fsync"
7906
7907         return 0
7908 }
7909 run_test 118h "Verify timeout in handling recoverables errors  =========="
7910
7911 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7912
7913 test_118i() {
7914         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7915         remote_ost_nodsh && skip "remote OST with nodsh" && return
7916
7917         reset_async
7918
7919         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7920         set_nodes_failloc "$(osts_nodes)" 0x20e
7921
7922         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7923         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7924         PID=$!
7925         sleep 5
7926         set_nodes_failloc "$(osts_nodes)" 0
7927
7928         wait $PID
7929         RC=$?
7930         if [[ $RC -ne 0 ]]; then
7931                 error "got error, but should be not, rc=$RC"
7932         fi
7933
7934         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7935         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7936         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7937         if [[ $LOCKED -ne 0 ]]; then
7938                 error "Locked pages remain in cache, locked=$LOCKED"
7939         fi
7940
7941         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7942                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7943         fi
7944
7945         rm -f $DIR/$tfile
7946         echo "No pages locked after fsync"
7947
7948         return 0
7949 }
7950 run_test 118i "Fix error before timeout in recoverable error  =========="
7951
7952 [ "$SLOW" = "no" ] && set_resend_count 4
7953
7954 test_118j() {
7955         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7956         remote_ost_nodsh && skip "remote OST with nodsh" && return
7957
7958         reset_async
7959
7960         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7961         set_nodes_failloc "$(osts_nodes)" 0x220
7962
7963         # return -EIO from OST
7964         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7965         RC=$?
7966         set_nodes_failloc "$(osts_nodes)" 0x0
7967         if [[ $RC -eq 0 ]]; then
7968                 error "Must return error due to dropped pages, rc=$RC"
7969         fi
7970
7971         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7972         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7973         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7974         if [[ $LOCKED -ne 0 ]]; then
7975                 error "Locked pages remain in cache, locked=$LOCKED"
7976         fi
7977
7978         # in recoverable error on OST we want resend and stay until it finished
7979         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7980                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7981         fi
7982
7983         rm -f $DIR/$tfile
7984         echo "No pages locked after fsync"
7985
7986         return 0
7987 }
7988 run_test 118j "Simulate unrecoverable OST side error =========="
7989
7990 test_118k()
7991 {
7992         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7993         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7994
7995         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7996         set_nodes_failloc "$(osts_nodes)" 0x20e
7997         test_mkdir -p $DIR/$tdir
7998
7999         for ((i=0;i<10;i++)); do
8000                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
8001                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
8002                 SLEEPPID=$!
8003                 sleep 0.500s
8004                 kill $SLEEPPID
8005                 wait $SLEEPPID
8006         done
8007
8008         set_nodes_failloc "$(osts_nodes)" 0
8009         rm -rf $DIR/$tdir
8010 }
8011 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
8012
8013 test_118l()
8014 {
8015         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8016         # LU-646
8017         test_mkdir -p $DIR/$tdir
8018         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
8019         rm -rf $DIR/$tdir
8020 }
8021 run_test 118l "fsync dir ========="
8022
8023 test_118m() # LU-3066
8024 {
8025         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8026         test_mkdir -p $DIR/$tdir
8027         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
8028         rm -rf $DIR/$tdir
8029 }
8030 run_test 118m "fdatasync dir ========="
8031
8032 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
8033
8034 test_119a() # bug 11737
8035 {
8036         BSIZE=$((512 * 1024))
8037         directio write $DIR/$tfile 0 1 $BSIZE
8038         # We ask to read two blocks, which is more than a file size.
8039         # directio will indicate an error when requested and actual
8040         # sizes aren't equeal (a normal situation in this case) and
8041         # print actual read amount.
8042         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
8043         if [ "$NOB" != "$BSIZE" ]; then
8044                 error "read $NOB bytes instead of $BSIZE"
8045         fi
8046         rm -f $DIR/$tfile
8047 }
8048 run_test 119a "Short directIO read must return actual read amount"
8049
8050 test_119b() # bug 11737
8051 {
8052         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
8053
8054         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
8055         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
8056         sync
8057         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
8058                 error "direct read failed"
8059         rm -f $DIR/$tfile
8060 }
8061 run_test 119b "Sparse directIO read must return actual read amount"
8062
8063 test_119c() # bug 13099
8064 {
8065         BSIZE=1048576
8066         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
8067         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
8068         rm -f $DIR/$tfile
8069 }
8070 run_test 119c "Testing for direct read hitting hole"
8071
8072 test_119d() # bug 15950
8073 {
8074         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8075         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
8076         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
8077         BSIZE=1048576
8078         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
8079         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
8080         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
8081         lctl set_param fail_loc=0x40d
8082         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
8083         pid_dio=$!
8084         sleep 1
8085         cat $DIR/$tfile > /dev/null &
8086         lctl set_param fail_loc=0
8087         pid_reads=$!
8088         wait $pid_dio
8089         log "the DIO writes have completed, now wait for the reads (should not block very long)"
8090         sleep 2
8091         [ -n "`ps h -p $pid_reads -o comm`" ] && \
8092         error "the read rpcs have not completed in 2s"
8093         rm -f $DIR/$tfile
8094         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
8095 }
8096 run_test 119d "The DIO path should try to send a new rpc once one is completed"
8097
8098 test_120a() {
8099         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8100         test_mkdir -p $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
8104         lru_resize_disable mdc
8105         lru_resize_disable osc
8106         cancel_lru_locks mdc
8107         # asynchronous object destroy at MDT could cause bl ast to client
8108         cancel_lru_locks osc
8109
8110         stat $DIR/$tdir > /dev/null
8111         can1=$(do_facet $SINGLEMDS \
8112                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8113                awk '/ldlm_cancel/ {print $2}')
8114         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8115                awk '/ldlm_bl_callback/ {print $2}')
8116         test_mkdir -c1 $DIR/$tdir/d1
8117         can2=$(do_facet $SINGLEMDS \
8118                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8119                awk '/ldlm_cancel/ {print $2}')
8120         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8121                awk '/ldlm_bl_callback/ {print $2}')
8122         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8123         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8124         lru_resize_enable mdc
8125         lru_resize_enable osc
8126 }
8127 run_test 120a "Early Lock Cancel: mkdir test"
8128
8129 test_120b() {
8130         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8131         test_mkdir $DIR/$tdir
8132         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8133                skip "no early lock cancel on server" && return 0
8134         lru_resize_disable mdc
8135         lru_resize_disable osc
8136         cancel_lru_locks mdc
8137         stat $DIR/$tdir > /dev/null
8138         can1=$(do_facet $SINGLEMDS \
8139                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8140                awk '/ldlm_cancel/ {print $2}')
8141         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8142                awk '/ldlm_bl_callback/ {print $2}')
8143         touch $DIR/$tdir/f1
8144         can2=$(do_facet $SINGLEMDS \
8145                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8146                awk '/ldlm_cancel/ {print $2}')
8147         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8148                awk '/ldlm_bl_callback/ {print $2}')
8149         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8150         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8151         lru_resize_enable mdc
8152         lru_resize_enable osc
8153 }
8154 run_test 120b "Early Lock Cancel: create test"
8155
8156 test_120c() {
8157         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8158         test_mkdir -c1 $DIR/$tdir
8159         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8160                skip "no early lock cancel on server" && return 0
8161         lru_resize_disable mdc
8162         lru_resize_disable osc
8163         test_mkdir -p -c1 $DIR/$tdir/d1
8164         test_mkdir -p -c1 $DIR/$tdir/d2
8165         touch $DIR/$tdir/d1/f1
8166         cancel_lru_locks mdc
8167         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
8168         can1=$(do_facet $SINGLEMDS \
8169                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8170                awk '/ldlm_cancel/ {print $2}')
8171         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8172                awk '/ldlm_bl_callback/ {print $2}')
8173         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8174         can2=$(do_facet $SINGLEMDS \
8175                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8176                awk '/ldlm_cancel/ {print $2}')
8177         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8178                awk '/ldlm_bl_callback/ {print $2}')
8179         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8180         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8181         lru_resize_enable mdc
8182         lru_resize_enable osc
8183 }
8184 run_test 120c "Early Lock Cancel: link test"
8185
8186 test_120d() {
8187         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8188         test_mkdir -p -c1 $DIR/$tdir
8189         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8190                skip "no early lock cancel on server" && return 0
8191         lru_resize_disable mdc
8192         lru_resize_disable osc
8193         touch $DIR/$tdir
8194         cancel_lru_locks mdc
8195         stat $DIR/$tdir > /dev/null
8196         can1=$(do_facet $SINGLEMDS \
8197                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8198                awk '/ldlm_cancel/ {print $2}')
8199         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8200                awk '/ldlm_bl_callback/ {print $2}')
8201         chmod a+x $DIR/$tdir
8202         can2=$(do_facet $SINGLEMDS \
8203                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8204                awk '/ldlm_cancel/ {print $2}')
8205         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8206                awk '/ldlm_bl_callback/ {print $2}')
8207         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8208         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8209         lru_resize_enable mdc
8210         lru_resize_enable osc
8211 }
8212 run_test 120d "Early Lock Cancel: setattr test"
8213
8214 test_120e() {
8215         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8216         ! $($LCTL get_param -n mdc.*.connect_flags | grep -q early_lock_can) &&
8217                 skip "no early lock cancel on server" && return 0
8218         local dlmtrace_set=false
8219
8220         test_mkdir -p -c1 $DIR/$tdir
8221         lru_resize_disable mdc
8222         lru_resize_disable osc
8223         ! $LCTL get_param debug | grep -q dlmtrace &&
8224                 $LCTL set_param debug=+dlmtrace && dlmtrace_set=true
8225         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
8226         cancel_lru_locks mdc
8227         cancel_lru_locks osc
8228         dd if=$DIR/$tdir/f1 of=/dev/null
8229         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
8230         # XXX client can not do early lock cancel of OST lock
8231         # during unlink (LU-4206), so cancel osc lock now.
8232         cancel_lru_locks osc
8233         can1=$(do_facet $SINGLEMDS \
8234                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8235                awk '/ldlm_cancel/ {print $2}')
8236         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8237                awk '/ldlm_bl_callback/ {print $2}')
8238         unlink $DIR/$tdir/f1
8239         sleep 5
8240         can2=$(do_facet $SINGLEMDS \
8241                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8242                awk '/ldlm_cancel/ {print $2}')
8243         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8244                awk '/ldlm_bl_callback/ {print $2}')
8245         [ $can1 -ne $can2 ] && error "$((can2 - can1)) cancel RPC occured" &&
8246                 $LCTL dk $TMP/cancel.debug.txt
8247         [ $blk1 -ne $blk2 ] && error "$((blk2 - blk1)) blocking RPC occured" &&
8248                 $LCTL dk $TMP/blocking.debug.txt
8249         $dlmtrace_set && $LCTL set_param debug=-dlmtrace
8250         lru_resize_enable mdc
8251         lru_resize_enable osc
8252 }
8253 run_test 120e "Early Lock Cancel: unlink test"
8254
8255 test_120f() {
8256         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8257         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8258                skip "no early lock cancel on server" && return 0
8259         test_mkdir -p -c1 $DIR/$tdir
8260         lru_resize_disable mdc
8261         lru_resize_disable osc
8262         test_mkdir -p -c1 $DIR/$tdir/d1
8263         test_mkdir -p -c1 $DIR/$tdir/d2
8264         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
8265         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
8266         cancel_lru_locks mdc
8267         cancel_lru_locks osc
8268         dd if=$DIR/$tdir/d1/f1 of=/dev/null
8269         dd if=$DIR/$tdir/d2/f2 of=/dev/null
8270         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
8271         # XXX client can not do early lock cancel of OST lock
8272         # during rename (LU-4206), so cancel osc lock now.
8273         cancel_lru_locks osc
8274         can1=$(do_facet $SINGLEMDS \
8275                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8276                awk '/ldlm_cancel/ {print $2}')
8277         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8278                awk '/ldlm_bl_callback/ {print $2}')
8279         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8280         sleep 5
8281         can2=$(do_facet $SINGLEMDS \
8282                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8283                awk '/ldlm_cancel/ {print $2}')
8284         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8285                awk '/ldlm_bl_callback/ {print $2}')
8286         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8287         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8288         lru_resize_enable mdc
8289         lru_resize_enable osc
8290 }
8291 run_test 120f "Early Lock Cancel: rename test"
8292
8293 test_120g() {
8294         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8295         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8296                skip "no early lock cancel on server" && return 0
8297         lru_resize_disable mdc
8298         lru_resize_disable osc
8299         count=10000
8300         echo create $count files
8301         test_mkdir -p $DIR/$tdir
8302         cancel_lru_locks mdc
8303         cancel_lru_locks osc
8304         t0=`date +%s`
8305
8306         can0=$(do_facet $SINGLEMDS \
8307                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8308                awk '/ldlm_cancel/ {print $2}')
8309         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8310                awk '/ldlm_bl_callback/ {print $2}')
8311         createmany -o $DIR/$tdir/f $count
8312         sync
8313         can1=$(do_facet $SINGLEMDS \
8314                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8315                awk '/ldlm_cancel/ {print $2}')
8316         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8317                awk '/ldlm_bl_callback/ {print $2}')
8318         t1=$(date +%s)
8319         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
8320         echo rm $count files
8321         rm -r $DIR/$tdir
8322         sync
8323         can2=$(do_facet $SINGLEMDS \
8324                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8325                awk '/ldlm_cancel/ {print $2}')
8326         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8327                awk '/ldlm_bl_callback/ {print $2}')
8328         t2=$(date +%s)
8329         echo total: $count removes in $((t2-t1))
8330         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
8331         sleep 2
8332         # wait for commitment of removal
8333         lru_resize_enable mdc
8334         lru_resize_enable osc
8335 }
8336 run_test 120g "Early Lock Cancel: performance test"
8337
8338 test_121() { #bug #10589
8339         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8340         rm -rf $DIR/$tfile
8341         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8342 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8343         lctl set_param fail_loc=0x310
8344         cancel_lru_locks osc > /dev/null
8345         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8346         lctl set_param fail_loc=0
8347         [[ $reads -eq $writes ]] ||
8348                 error "read $reads blocks, must be $writes blocks"
8349 }
8350 run_test 121 "read cancel race ========="
8351
8352 test_123a() { # was test 123, statahead(bug 11401)
8353         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8354         SLOWOK=0
8355         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8356             log "testing on UP system. Performance may be not as good as expected."
8357                         SLOWOK=1
8358         fi
8359
8360         rm -rf $DIR/$tdir
8361         test_mkdir -p $DIR/$tdir
8362         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8363         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8364         MULT=10
8365         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8366                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8367
8368                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8369                 lctl set_param -n llite.*.statahead_max 0
8370                 lctl get_param llite.*.statahead_max
8371                 cancel_lru_locks mdc
8372                 cancel_lru_locks osc
8373                 stime=`date +%s`
8374                 time ls -l $DIR/$tdir | wc -l
8375                 etime=`date +%s`
8376                 delta=$((etime - stime))
8377                 log "ls $i files without statahead: $delta sec"
8378                 lctl set_param llite.*.statahead_max=$max
8379
8380                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8381                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8382                 cancel_lru_locks mdc
8383                 cancel_lru_locks osc
8384                 stime=`date +%s`
8385                 time ls -l $DIR/$tdir | wc -l
8386                 etime=`date +%s`
8387                 delta_sa=$((etime - stime))
8388                 log "ls $i files with statahead: $delta_sa sec"
8389                 lctl get_param -n llite.*.statahead_stats
8390                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8391
8392                 [[ $swrong -lt $ewrong ]] &&
8393                         log "statahead was stopped, maybe too many locks held!"
8394                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8395
8396                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8397                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8398                     lctl set_param -n llite.*.statahead_max 0
8399                     lctl get_param llite.*.statahead_max
8400                     cancel_lru_locks mdc
8401                     cancel_lru_locks osc
8402                     stime=`date +%s`
8403                     time ls -l $DIR/$tdir | wc -l
8404                     etime=`date +%s`
8405                     delta=$((etime - stime))
8406                     log "ls $i files again without statahead: $delta sec"
8407                     lctl set_param llite.*.statahead_max=$max
8408                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8409                         if [  $SLOWOK -eq 0 ]; then
8410                                 error "ls $i files is slower with statahead!"
8411                         else
8412                                 log "ls $i files is slower with statahead!"
8413                         fi
8414                         break
8415                     fi
8416                 fi
8417
8418                 [ $delta -gt 20 ] && break
8419                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8420                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8421         done
8422         log "ls done"
8423
8424         stime=`date +%s`
8425         rm -r $DIR/$tdir
8426         sync
8427         etime=`date +%s`
8428         delta=$((etime - stime))
8429         log "rm -r $DIR/$tdir/: $delta seconds"
8430         log "rm done"
8431         lctl get_param -n llite.*.statahead_stats
8432 }
8433 run_test 123a "verify statahead work"
8434
8435 test_123b () { # statahead(bug 15027)
8436         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8437         test_mkdir -p $DIR/$tdir
8438         createmany -o $DIR/$tdir/$tfile-%d 1000
8439
8440         cancel_lru_locks mdc
8441         cancel_lru_locks osc
8442
8443 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8444         lctl set_param fail_loc=0x80000803
8445         ls -lR $DIR/$tdir > /dev/null
8446         log "ls done"
8447         lctl set_param fail_loc=0x0
8448         lctl get_param -n llite.*.statahead_stats
8449         rm -r $DIR/$tdir
8450         sync
8451
8452 }
8453 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8454
8455 test_124a() {
8456         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8457         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8458                 skip "no lru resize on server" && return 0
8459         local NR=2000
8460         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8461
8462         log "create $NR files at $DIR/$tdir"
8463         createmany -o $DIR/$tdir/f $NR ||
8464                 error "failed to create $NR files in $DIR/$tdir"
8465
8466         cancel_lru_locks mdc
8467         ls -l $DIR/$tdir > /dev/null
8468
8469         local NSDIR=""
8470         local LRU_SIZE=0
8471         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8472                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8473                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8474                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8475                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8476                         log "NSDIR=$NSDIR"
8477                         log "NS=$(basename $NSDIR)"
8478                         break
8479                 fi
8480         done
8481
8482         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8483                 skip "Not enough cached locks created!"
8484                 return 0
8485         fi
8486         log "LRU=$LRU_SIZE"
8487
8488         local SLEEP=30
8489
8490         # We know that lru resize allows one client to hold $LIMIT locks
8491         # for 10h. After that locks begin to be killed by client.
8492         local MAX_HRS=10
8493         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8494         log "LIMIT=$LIMIT"
8495         if [ $LIMIT -lt $LRU_SIZE ]; then
8496             skip "Limit is too small $LIMIT"
8497             return 0
8498         fi
8499
8500         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8501         # killing locks. Some time was spent for creating locks. This means
8502         # that up to the moment of sleep finish we must have killed some of
8503         # them (10-100 locks). This depends on how fast ther were created.
8504         # Many of them were touched in almost the same moment and thus will
8505         # be killed in groups.
8506         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8507
8508         # Use $LRU_SIZE_B here to take into account real number of locks
8509         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8510         local LRU_SIZE_B=$LRU_SIZE
8511         log "LVF=$LVF"
8512         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8513         log "OLD_LVF=$OLD_LVF"
8514         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8515
8516         # Let's make sure that we really have some margin. Client checks
8517         # cached locks every 10 sec.
8518         SLEEP=$((SLEEP+20))
8519         log "Sleep ${SLEEP} sec"
8520         local SEC=0
8521         while ((SEC<$SLEEP)); do
8522                 echo -n "..."
8523                 sleep 5
8524                 SEC=$((SEC+5))
8525                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8526                 echo -n "$LRU_SIZE"
8527         done
8528         echo ""
8529         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8530         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8531
8532         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8533                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8534                 unlinkmany $DIR/$tdir/f $NR
8535                 return
8536         }
8537
8538         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8539         log "unlink $NR files at $DIR/$tdir"
8540         unlinkmany $DIR/$tdir/f $NR
8541 }
8542 run_test 124a "lru resize ======================================="
8543
8544 get_max_pool_limit()
8545 {
8546         local limit=$($LCTL get_param \
8547                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8548         local max=0
8549         for l in $limit; do
8550                 if [[ $l -gt $max ]]; then
8551                         max=$l
8552                 fi
8553         done
8554         echo $max
8555 }
8556
8557 test_124b() {
8558         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8559         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8560                 skip "no lru resize on server" && return 0
8561
8562         LIMIT=$(get_max_pool_limit)
8563
8564         NR=$(($(default_lru_size)*20))
8565         if [[ $NR -gt $LIMIT ]]; then
8566                 log "Limit lock number by $LIMIT locks"
8567                 NR=$LIMIT
8568         fi
8569         lru_resize_disable mdc
8570         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8571                 error "failed to create $DIR/$tdir/disable_lru_resize"
8572
8573         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8574         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8575         cancel_lru_locks mdc
8576         stime=`date +%s`
8577         PID=""
8578         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8579         PID="$PID $!"
8580         sleep 2
8581         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8582         PID="$PID $!"
8583         sleep 2
8584         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8585         PID="$PID $!"
8586         wait $PID
8587         etime=`date +%s`
8588         nolruresize_delta=$((etime-stime))
8589         log "ls -la time: $nolruresize_delta seconds"
8590         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8591         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8592
8593         lru_resize_enable mdc
8594         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8595                 error "failed to create $DIR/$tdir/enable_lru_resize"
8596
8597         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8598         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8599         cancel_lru_locks mdc
8600         stime=`date +%s`
8601         PID=""
8602         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8603         PID="$PID $!"
8604         sleep 2
8605         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8606         PID="$PID $!"
8607         sleep 2
8608         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8609         PID="$PID $!"
8610         wait $PID
8611         etime=`date +%s`
8612         lruresize_delta=$((etime-stime))
8613         log "ls -la time: $lruresize_delta seconds"
8614         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8615
8616         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8617                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8618         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8619                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8620         else
8621                 log "lru resize performs the same with no lru resize"
8622         fi
8623         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8624 }
8625 run_test 124b "lru resize (performance test) ======================="
8626
8627 test_124c() {
8628         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8629         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8630                 skip "no lru resize on server" && return 0
8631
8632         # cache ununsed locks on client
8633         local nr=100
8634         cancel_lru_locks mdc
8635         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8636         createmany -o $DIR/$tdir/f $nr ||
8637                 error "failed to create $nr files in $DIR/$tdir"
8638         ls -l $DIR/$tdir > /dev/null
8639
8640         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
8641         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
8642         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
8643         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
8644         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
8645
8646         # set lru_max_age to 1 sec
8647         $LCTL set_param $nsdir.lru_max_age=1000 # jiffies
8648         echo "sleep $((recalc_p * 2)) seconds..."
8649         sleep $((recalc_p * 2))
8650
8651         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
8652         # restore lru_max_age
8653         $LCTL set_param -n $nsdir.lru_max_age $max_age
8654         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
8655         unlinkmany $DIR/$tdir/f $nr
8656 }
8657 run_test 124c "LRUR cancel very aged locks"
8658
8659 test_125() { # 13358
8660         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8661         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8662         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8663         test_mkdir -p $DIR/d125 || error "mkdir failed"
8664         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8665         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8666         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8667 }
8668 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8669
8670 test_126() { # bug 12829/13455
8671         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8672         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8673         $GSS && skip "must run as gss disabled" && return
8674
8675         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8676         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8677         rm -f $DIR/$tfile
8678         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8679 }
8680 run_test 126 "check that the fsgid provided by the client is taken into account"
8681
8682 test_127a() { # bug 15521
8683         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8684         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8685         $LCTL set_param osc.*.stats=0
8686         FSIZE=$((2048 * 1024))
8687         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8688         cancel_lru_locks osc
8689         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8690
8691         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8692         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8693                 echo "got $COUNT $NAME"
8694                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8695                 eval $NAME=$COUNT || error "Wrong proc format"
8696
8697                 case $NAME in
8698                         read_bytes|write_bytes)
8699                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8700                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8701                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8702                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8703                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8704                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8705                                 error "sumsquare is too small: $SUMSQ"
8706                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8707                                 error "sumsquare is too big: $SUMSQ"
8708                         ;;
8709                         *) ;;
8710                 esac
8711         done < $DIR/${tfile}.tmp
8712
8713         #check that we actually got some stats
8714         [ "$read_bytes" ] || error "Missing read_bytes stats"
8715         [ "$write_bytes" ] || error "Missing write_bytes stats"
8716         [ "$read_bytes" != 0 ] || error "no read done"
8717         [ "$write_bytes" != 0 ] || error "no write done"
8718 }
8719 run_test 127a "verify the client stats are sane"
8720
8721 test_127b() { # bug LU-333
8722         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8723         $LCTL set_param llite.*.stats=0
8724         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8725         # perform 2 reads and writes so MAX is different from SUM.
8726         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8727         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8728         cancel_lru_locks osc
8729         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8730         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8731
8732         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8733         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8734                 echo "got $COUNT $NAME"
8735                 eval $NAME=$COUNT || error "Wrong proc format"
8736
8737         case $NAME in
8738                 read_bytes)
8739                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8740                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8741                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8742                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8743                         ;;
8744                 write_bytes)
8745                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8746                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8747                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8748                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8749                         ;;
8750                         *) ;;
8751                 esac
8752         done < $TMP/${tfile}.tmp
8753
8754         #check that we actually got some stats
8755         [ "$read_bytes" ] || error "Missing read_bytes stats"
8756         [ "$write_bytes" ] || error "Missing write_bytes stats"
8757         [ "$read_bytes" != 0 ] || error "no read done"
8758         [ "$write_bytes" != 0 ] || error "no write done"
8759 }
8760 run_test 127b "verify the llite client stats are sane"
8761
8762 test_128() { # bug 15212
8763         touch $DIR/$tfile
8764         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8765                 find $DIR/$tfile
8766                 find $DIR/$tfile
8767         EOF
8768
8769         result=$(grep error $TMP/$tfile.log)
8770         rm -f $DIR/$tfile
8771         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8772 }
8773 run_test 128 "interactive lfs for 2 consecutive find's"
8774
8775 set_dir_limits () {
8776         local mntdev
8777         local canondev
8778         local node
8779
8780         local LDPROC=/proc/fs/ldiskfs
8781         local facets=$(get_facets MDS)
8782
8783         for facet in ${facets//,/ }; do
8784                 canondev=$(ldiskfs_canon \
8785                            *.$(convert_facet2label $facet).mntdev $facet)
8786                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8787                                                 LDPROC=/sys/fs/ldiskfs
8788                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8789                 do_facet $facet "test -e $LDPROC/$canondev/warning_dir_size" ||
8790                                                 LDPROC=/sys/fs/ldiskfs
8791                 do_facet $facet "echo $2 >$LDPROC/$canondev/warning_dir_size"
8792         done
8793 }
8794
8795 check_mds_dmesg() {
8796         local facets=$(get_facets MDS)
8797         for facet in ${facets//,/ }; do
8798                 do_facet $facet "dmesg | tail -3 | grep -q $1" && return 0
8799         done
8800         return 1
8801 }
8802
8803 test_129() {
8804         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8805         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8806                 skip "Only applicable to ldiskfs-based MDTs"
8807                 return
8808         fi
8809         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8810         ENOSPC=28
8811         EFBIG=27
8812         has_warning=0
8813
8814         rm -rf $DIR/$tdir
8815         mkdir -p $DIR/$tdir
8816
8817         # block size of mds1
8818         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8819         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8820         local MAX=$((MDSBLOCKSIZE * 5))
8821         set_dir_limits $MAX $MAX
8822         local I=$(stat -c%s "$DIR/$tdir")
8823         local J=0
8824         while [[ $I -le $MAX ]]; do
8825                 $MULTIOP $DIR/$tdir/$J Oc
8826                 rc=$?
8827                 if [ $has_warning -eq 0 ]; then
8828                         check_mds_dmesg '"is approaching"' &&
8829                                 has_warning=1
8830                 fi
8831                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8832                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8833                 #and EFBIG for previous versions
8834                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8835                         set_dir_limits 0 0
8836                         echo "return code $rc received as expected"
8837
8838                         createmany -o $DIR/$tdir/$J_file_ 1000 ||
8839                                 error_exit "create failed w/o dir size limit"
8840
8841                         check_mds_dmesg '"has reached"' ||
8842                                 error_exit "has reached message should be output"
8843
8844                         [ $has_warning ] ||
8845                                 error_exit "warning message should be output"
8846
8847                         I=$(stat -c%s "$DIR/$tdir")
8848
8849                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8850                                         $(version_code 2.4.51) ]
8851                         then
8852                                 [[ $I -eq $MAX ]] && return 0
8853                         else
8854                                 [[ $I -gt $MAX ]] && return 0
8855                         fi
8856                         error_exit "current dir size $I, previous limit $MAX"
8857                 elif [ $rc -ne 0 ]; then
8858                         set_dir_limits 0 0
8859                         error_exit "return code $rc received instead of expected " \
8860                                    "$EFBIG or $ENOSPC, files in dir $I"
8861                 fi
8862                 J=$((J+1))
8863                 I=$(stat -c%s "$DIR/$tdir")
8864         done
8865
8866         set_dir_limits 0 0
8867         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8868 }
8869 run_test 129 "test directory size limit ========================"
8870
8871 OLDIFS="$IFS"
8872 cleanup_130() {
8873         trap 0
8874         IFS="$OLDIFS"
8875 }
8876
8877 test_130a() {
8878         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8879         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8880                 return
8881
8882         trap cleanup_130 EXIT RETURN
8883
8884         local fm_file=$DIR/$tfile
8885         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8886         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8887                 error "dd failed for $fm_file"
8888
8889         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8890         filefrag -ves $fm_file
8891         RC=$?
8892         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8893                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8894         [ $RC != 0 ] && error "filefrag $fm_file failed"
8895
8896         filefrag_op=$(filefrag -ve $fm_file |
8897                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
8898         lun=$($GETSTRIPE -i $fm_file)
8899
8900         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8901         IFS=$'\n'
8902         tot_len=0
8903         for line in $filefrag_op
8904         do
8905                 frag_lun=`echo $line | cut -d: -f5`
8906                 ext_len=`echo $line | cut -d: -f4`
8907                 if (( $frag_lun != $lun )); then
8908                         cleanup_130
8909                         error "FIEMAP on 1-stripe file($fm_file) failed"
8910                         return
8911                 fi
8912                 (( tot_len += ext_len ))
8913         done
8914
8915         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8916                 cleanup_130
8917                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8918                 return
8919         fi
8920
8921         cleanup_130
8922
8923         echo "FIEMAP on single striped file succeeded"
8924 }
8925 run_test 130a "FIEMAP (1-stripe file)"
8926
8927 test_130b() {
8928         [ "$OSTCOUNT" -lt "2" ] &&
8929                 skip_env "skipping FIEMAP on $OSTCOUNT-stripe file" && return
8930
8931         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8932         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8933                 return
8934
8935         trap cleanup_130 EXIT RETURN
8936
8937         local fm_file=$DIR/$tfile
8938         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
8939                         error "setstripe on $fm_file"
8940         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8941                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8942
8943         dd if=/dev/zero of=$fm_file bs=1M count=$OSTCOUNT ||
8944                 error "dd failed on $fm_file"
8945
8946         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8947         filefrag_op=$(filefrag -ve $fm_file |
8948                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
8949
8950         last_lun=$(echo $filefrag_op | cut -d: -f5 |
8951                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
8952
8953         IFS=$'\n'
8954         tot_len=0
8955         num_luns=1
8956         for line in $filefrag_op
8957         do
8958                 frag_lun=$(echo $line | cut -d: -f5 |
8959                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
8960                 ext_len=$(echo $line | cut -d: -f4)
8961                 if (( $frag_lun != $last_lun )); then
8962                         if (( tot_len != 1024 )); then
8963                                 cleanup_130
8964                                 error "FIEMAP on $fm_file failed; returned " \
8965                                 "len $tot_len for OST $last_lun instead of 1024"
8966                                 return
8967                         else
8968                                 (( num_luns += 1 ))
8969                                 tot_len=0
8970                         fi
8971                 fi
8972                 (( tot_len += ext_len ))
8973                 last_lun=$frag_lun
8974         done
8975         if (( num_luns != $OSTCOUNT || tot_len != 1024 )); then
8976                 cleanup_130
8977                 error "FIEMAP on $fm_file failed; returned wrong number of " \
8978                         "luns or wrong len for OST $last_lun"
8979                 return
8980         fi
8981
8982         cleanup_130
8983
8984         echo "FIEMAP on $OSTCOUNT-stripe file succeeded"
8985 }
8986 run_test 130b "FIEMAP ($OSTCOUNT-stripe file)"
8987
8988 test_130c() {
8989         [ "$OSTCOUNT" -lt "2" ] &&
8990                 skip_env "skipping FIEMAP on 2-stripe file" && return
8991
8992         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8993         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8994                 return
8995
8996         trap cleanup_130 EXIT RETURN
8997
8998         local fm_file=$DIR/$tfile
8999         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
9000         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9001                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9002
9003         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 ||
9004                         error "dd failed on $fm_file"
9005
9006         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9007         filefrag_op=$(filefrag -ve $fm_file |
9008                 sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9009
9010         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9011                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9012
9013         IFS=$'\n'
9014         tot_len=0
9015         num_luns=1
9016         for line in $filefrag_op
9017         do
9018                 frag_lun=$(echo $line | cut -d: -f5 |
9019                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9020                 ext_len=$(echo $line | cut -d: -f4)
9021                 if (( $frag_lun != $last_lun )); then
9022                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
9023                         if (( logical != 512 )); then
9024                                 cleanup_130
9025                                 error "FIEMAP on $fm_file failed; returned " \
9026                                 "logical start for lun $logical instead of 512"
9027                                 return
9028                         fi
9029                         if (( tot_len != 512 )); then
9030                                 cleanup_130
9031                                 error "FIEMAP on $fm_file failed; returned " \
9032                                 "len $tot_len for OST $last_lun instead of 1024"
9033                                 return
9034                         else
9035                                 (( num_luns += 1 ))
9036                                 tot_len=0
9037                         fi
9038                 fi
9039                 (( tot_len += ext_len ))
9040                 last_lun=$frag_lun
9041         done
9042         if (( num_luns != 2 || tot_len != 512 )); then
9043                 cleanup_130
9044                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9045                         "luns or wrong len for OST $last_lun"
9046                 return
9047         fi
9048
9049         cleanup_130
9050
9051         echo "FIEMAP on 2-stripe file with hole succeeded"
9052 }
9053 run_test 130c "FIEMAP (2-stripe file with hole)"
9054
9055 test_130d() {
9056         [ "$OSTCOUNT" -lt "3" ] &&
9057                 skip_env "skipping FIEMAP on N-stripe file test" && return
9058
9059         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9060         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
9061                 return
9062
9063         trap cleanup_130 EXIT RETURN
9064
9065         local fm_file=$DIR/$tfile
9066         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file ||
9067                         error "setstripe on $fm_file"
9068         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9069                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9070
9071         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
9072         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
9073                 error "dd failed on $fm_file"
9074
9075         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9076         filefrag_op=$(filefrag -ve $fm_file |
9077                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9078
9079         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9080                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9081
9082         IFS=$'\n'
9083         tot_len=0
9084         num_luns=1
9085         for line in $filefrag_op
9086         do
9087                 frag_lun=$(echo $line | cut -d: -f5 |
9088                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9089                 ext_len=$(echo $line | cut -d: -f4)
9090                 if (( $frag_lun != $last_lun )); then
9091                         if (( tot_len != 1024 )); then
9092                                 cleanup_130
9093                                 error "FIEMAP on $fm_file failed; returned " \
9094                                 "len $tot_len for OST $last_lun instead of 1024"
9095                                 return
9096                         else
9097                                 (( num_luns += 1 ))
9098                                 tot_len=0
9099                         fi
9100                 fi
9101                 (( tot_len += ext_len ))
9102                 last_lun=$frag_lun
9103         done
9104         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
9105                 cleanup_130
9106                 error "FIEMAP on $fm_file failed; returned wrong number of " \
9107                         "luns or wrong len for OST $last_lun"
9108                 return
9109         fi
9110
9111         cleanup_130
9112
9113         echo "FIEMAP on N-stripe file succeeded"
9114 }
9115 run_test 130d "FIEMAP (N-stripe file)"
9116
9117 test_130e() {
9118         [ "$OSTCOUNT" -lt "2" ] &&
9119                 skip_env "skipping continuation FIEMAP test" && return
9120
9121         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9122         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
9123
9124         trap cleanup_130 EXIT RETURN
9125
9126         local fm_file=$DIR/$tfile
9127         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
9128         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9129                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9130
9131         NUM_BLKS=512
9132         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
9133         for ((i = 0; i < $NUM_BLKS; i++))
9134         do
9135                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
9136         done
9137
9138         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9139         filefrag_op=$(filefrag -ve $fm_file |
9140                         sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
9141
9142         last_lun=$(echo $filefrag_op | cut -d: -f5 |
9143                 sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9144
9145         IFS=$'\n'
9146         tot_len=0
9147         num_luns=1
9148         for line in $filefrag_op
9149         do
9150                 frag_lun=$(echo $line | cut -d: -f5 |
9151                         sed -e 's/^[ \t]*/0x/' | sed -e 's/0x0x/0x/')
9152                 ext_len=$(echo $line | cut -d: -f4)
9153                 if (( $frag_lun != $last_lun )); then
9154                         if (( tot_len != $EXPECTED_LEN )); then
9155                                 cleanup_130
9156                                 error "FIEMAP on $fm_file failed; returned " \
9157                                 "len $tot_len for OST $last_lun instead " \
9158                                 "of $EXPECTED_LEN"
9159                                 return
9160                         else
9161                                 (( num_luns += 1 ))
9162                                 tot_len=0
9163                         fi
9164                 fi
9165                 (( tot_len += ext_len ))
9166                 last_lun=$frag_lun
9167         done
9168         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
9169                 cleanup_130
9170                 error "FIEMAP on $fm_file failed; returned wrong number " \
9171                         "of luns or wrong len for OST $last_lun"
9172                 return
9173         fi
9174
9175         cleanup_130
9176
9177         echo "FIEMAP with continuation calls succeeded"
9178 }
9179 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
9180
9181 # Test for writev/readv
9182 test_131a() {
9183         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
9184         error "writev test failed"
9185         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
9186         error "readv failed"
9187         rm -f $DIR/$tfile
9188 }
9189 run_test 131a "test iov's crossing stripe boundary for writev/readv"
9190
9191 test_131b() {
9192         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
9193         error "append writev test failed"
9194         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
9195         error "append writev test failed"
9196         rm -f $DIR/$tfile
9197 }
9198 run_test 131b "test append writev"
9199
9200 test_131c() {
9201         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
9202         error "NOT PASS"
9203 }
9204 run_test 131c "test read/write on file w/o objects"
9205
9206 test_131d() {
9207         rwv -f $DIR/$tfile -w -n 1 1572864
9208         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
9209         if [ "$NOB" != 1572864 ]; then
9210                 error "Short read filed: read $NOB bytes instead of 1572864"
9211         fi
9212         rm -f $DIR/$tfile
9213 }
9214 run_test 131d "test short read"
9215
9216 test_131e() {
9217         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
9218         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
9219         error "read hitting hole failed"
9220         rm -f $DIR/$tfile
9221 }
9222 run_test 131e "test read hitting hole"
9223
9224 check_stats() {
9225         local res
9226         local count
9227         case $1 in
9228         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
9229                  ;;
9230         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
9231                  ;;
9232         *) error "Wrong argument $1" ;;
9233         esac
9234         echo $res
9235         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
9236         # if the argument $3 is zero, it means any stat increment is ok.
9237         if [[ $3 -gt 0 ]]; then
9238                 count=$(echo $res | awk '{ print $2 }')
9239                 [[ $count -ne $3 ]] &&
9240                         error "The $2 counter on $1 is wrong - expected $3"
9241         fi
9242 }
9243
9244 test_133a() {
9245         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9246         remote_ost_nodsh && skip "remote OST with nodsh" && return
9247         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9248
9249         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9250                 { skip "MDS doesn't support rename stats"; return; }
9251         local testdir=$DIR/${tdir}/stats_testdir
9252         mkdir -p $DIR/${tdir}
9253
9254         # clear stats.
9255         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9256         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9257
9258         # verify mdt stats first.
9259         mkdir ${testdir} || error "mkdir failed"
9260         check_stats $SINGLEMDS "mkdir" 1
9261         touch ${testdir}/${tfile} || "touch failed"
9262         check_stats $SINGLEMDS "open" 1
9263         check_stats $SINGLEMDS "close" 1
9264         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
9265         check_stats $SINGLEMDS "mknod" 1
9266         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
9267         check_stats $SINGLEMDS "unlink" 1
9268         rm -f ${testdir}/${tfile} || error "file remove failed"
9269         check_stats $SINGLEMDS "unlink" 2
9270
9271         # remove working dir and check mdt stats again.
9272         rmdir ${testdir} || error "rmdir failed"
9273         check_stats $SINGLEMDS "rmdir" 1
9274
9275         local testdir1=$DIR/${tdir}/stats_testdir1
9276         mkdir -p ${testdir}
9277         mkdir -p ${testdir1}
9278         touch ${testdir1}/test1
9279         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
9280         check_stats $SINGLEMDS "crossdir_rename" 1
9281
9282         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
9283         check_stats $SINGLEMDS "samedir_rename" 1
9284
9285         rm -rf $DIR/${tdir}
9286 }
9287 run_test 133a "Verifying MDT stats ========================================"
9288
9289 test_133b() {
9290         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9291         remote_ost_nodsh && skip "remote OST with nodsh" && return
9292         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9293         local testdir=$DIR/${tdir}/stats_testdir
9294         mkdir -p ${testdir} || error "mkdir failed"
9295         touch ${testdir}/${tfile} || "touch failed"
9296         cancel_lru_locks mdc
9297
9298         # clear stats.
9299         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9300         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9301
9302         # extra mdt stats verification.
9303         chmod 444 ${testdir}/${tfile} || error "chmod failed"
9304         check_stats $SINGLEMDS "setattr" 1
9305         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9306         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
9307         then            # LU-1740
9308                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
9309                 check_stats $SINGLEMDS "getattr" 1
9310         fi
9311         $LFS df || error "lfs failed"
9312         check_stats $SINGLEMDS "statfs" 1
9313
9314         rm -rf $DIR/${tdir}
9315 }
9316 run_test 133b "Verifying extra MDT stats =================================="
9317
9318 test_133c() {
9319         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9320         remote_ost_nodsh && skip "remote OST with nodsh" && return
9321         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9322         local testdir=$DIR/${tdir}/stats_testdir
9323         test_mkdir -p ${testdir} || error "mkdir failed"
9324
9325         # verify obdfilter stats.
9326         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9327         sync
9328         cancel_lru_locks osc
9329         wait_delete_completed
9330
9331         # clear stats.
9332         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9333         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9334
9335         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
9336         sync
9337         cancel_lru_locks osc
9338         check_stats ost "write" 1
9339
9340         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9341         check_stats ost "read" 1
9342
9343         > ${testdir}/${tfile} || error "truncate failed"
9344         check_stats ost "punch" 1
9345
9346         rm -f ${testdir}/${tfile} || error "file remove failed"
9347         wait_delete_completed
9348         check_stats ost "destroy" 1
9349
9350         rm -rf $DIR/${tdir}
9351 }
9352 run_test 133c "Verifying OST stats ========================================"
9353
9354 order_2() {
9355         local value=$1
9356         local orig=$value
9357         local order=1
9358
9359         while [ $value -ge 2 ]; do
9360                 order=$((order*2))
9361                 value=$((value/2))
9362         done
9363
9364         if [ $orig -gt $order ]; then
9365                 order=$((order*2))
9366         fi
9367         echo $order
9368 }
9369
9370 size_in_KMGT() {
9371     local value=$1
9372     local size=('K' 'M' 'G' 'T');
9373     local i=0
9374     local size_string=$value
9375
9376     while [ $value -ge 1024 ]; do
9377         if [ $i -gt 3 ]; then
9378             #T is the biggest unit we get here, if that is bigger,
9379             #just return XXXT
9380             size_string=${value}T
9381             break
9382         fi
9383         value=$((value >> 10))
9384         if [ $value -lt 1024 ]; then
9385             size_string=${value}${size[$i]}
9386             break
9387         fi
9388         i=$((i + 1))
9389     done
9390
9391     echo $size_string
9392 }
9393
9394 get_rename_size() {
9395     local size=$1
9396     local context=${2:-.}
9397     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9398                 grep -A1 $context |
9399                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9400     echo $sample
9401 }
9402
9403 test_133d() {
9404         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9405         remote_ost_nodsh && skip "remote OST with nodsh" && return
9406         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9407         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9408         { skip "MDS doesn't support rename stats"; return; }
9409
9410         local testdir1=$DIR/${tdir}/stats_testdir1
9411         local testdir2=$DIR/${tdir}/stats_testdir2
9412
9413         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9414
9415         mkdir -p ${testdir1} || error "mkdir failed"
9416         mkdir -p ${testdir2} || error "mkdir failed"
9417
9418         createmany -o $testdir1/test 512 || error "createmany failed"
9419
9420         # check samedir rename size
9421         mv ${testdir1}/test0 ${testdir1}/test_0
9422
9423         local testdir1_size=$(ls -l $DIR/${tdir} |
9424                 awk '/stats_testdir1/ {print $5}')
9425         local testdir2_size=$(ls -l $DIR/${tdir} |
9426                 awk '/stats_testdir2/ {print $5}')
9427
9428         testdir1_size=$(order_2 $testdir1_size)
9429         testdir2_size=$(order_2 $testdir2_size)
9430
9431         testdir1_size=$(size_in_KMGT $testdir1_size)
9432         testdir2_size=$(size_in_KMGT $testdir2_size)
9433
9434         echo "source rename dir size: ${testdir1_size}"
9435         echo "target rename dir size: ${testdir2_size}"
9436
9437         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9438         eval $cmd || error "$cmd failed"
9439         local samedir=$($cmd | grep 'same_dir')
9440         local same_sample=$(get_rename_size $testdir1_size)
9441         [ -z "$samedir" ] && error "samedir_rename_size count error"
9442         [[ $same_sample -eq 1 ]] ||
9443                 error "samedir_rename_size error $same_sample"
9444         echo "Check same dir rename stats success"
9445
9446         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9447
9448         # check crossdir rename size
9449         mv ${testdir1}/test_0 ${testdir2}/test_0
9450
9451         testdir1_size=$(ls -l $DIR/${tdir} |
9452                 awk '/stats_testdir1/ {print $5}')
9453         testdir2_size=$(ls -l $DIR/${tdir} |
9454                 awk '/stats_testdir2/ {print $5}')
9455
9456         testdir1_size=$(order_2 $testdir1_size)
9457         testdir2_size=$(order_2 $testdir2_size)
9458
9459         testdir1_size=$(size_in_KMGT $testdir1_size)
9460         testdir2_size=$(size_in_KMGT $testdir2_size)
9461
9462         echo "source rename dir size: ${testdir1_size}"
9463         echo "target rename dir size: ${testdir2_size}"
9464
9465         eval $cmd || error "$cmd failed"
9466         local crossdir=$($cmd | grep 'crossdir')
9467         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9468         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9469         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9470         [[ $src_sample -eq 1 ]] ||
9471                 error "crossdir_rename_size error $src_sample"
9472         [[ $tgt_sample -eq 1 ]] ||
9473                 error "crossdir_rename_size error $tgt_sample"
9474         echo "Check cross dir rename stats success"
9475         rm -rf $DIR/${tdir}
9476 }
9477 run_test 133d "Verifying rename_stats ========================================"
9478
9479 test_133e() {
9480         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9481         remote_ost_nodsh && skip "remote OST with nodsh" && return
9482         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9483         local testdir=$DIR/${tdir}/stats_testdir
9484         local ctr f0 f1 bs=32768 count=42 sum
9485
9486         mkdir -p ${testdir} || error "mkdir failed"
9487
9488         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9489
9490         for ctr in {write,read}_bytes; do
9491                 sync
9492                 cancel_lru_locks osc
9493
9494                 do_facet ost1 $LCTL set_param -n \
9495                         "obdfilter.*.exports.clear=clear"
9496
9497                 if [ $ctr = write_bytes ]; then
9498                         f0=/dev/zero
9499                         f1=${testdir}/${tfile}
9500                 else
9501                         f0=${testdir}/${tfile}
9502                         f1=/dev/null
9503                 fi
9504
9505                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9506                         error "dd failed"
9507                 sync
9508                 cancel_lru_locks osc
9509
9510                 sum=$(do_facet ost1 $LCTL get_param \
9511                         "obdfilter.*.exports.*.stats" |
9512                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9513                                 $1 == ctr { sum += $7 }
9514                                 END { printf("%0.0f", sum) }')
9515
9516                 if ((sum != bs * count)); then
9517                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9518                 fi
9519         done
9520
9521         rm -rf $DIR/${tdir}
9522 }
9523 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9524
9525 proc_dirs=""
9526 for dir in /proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9527            /sys/fs/lustre/ /sys/fs/lnet/ /sys/kernel/debug/lnet/ \
9528            /sys/kernel/debug/lustre/; do
9529         [[ -d $dir ]] && proc_dirs+=" $dir"
9530 done
9531
9532 test_133f() {
9533         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9534         remote_ost_nodsh && skip "remote OST with nodsh" && return
9535         # First without trusting modes.
9536         find $proc_dirs -exec cat '{}' \; &> /dev/null
9537
9538         # Second verifying readability.
9539         $LCTL get_param -R '*' &> /dev/null || error "proc file read failed"
9540
9541         # eventually, this can also be replaced with "lctl get_param -R",
9542         # but not until that option is always available on the server
9543         local facet
9544         for facet in $SINGLEMDS ost1; do
9545                 do_facet $facet find $proc_dirs \
9546                         ! -name req_history \
9547                         -exec cat '{}' \\\; &> /dev/null
9548
9549                 do_facet $facet find $proc_dirs \
9550                         ! -name req_history \
9551                         -type f \
9552                         -exec cat '{}' \\\; &> /dev/null ||
9553                                 error "proc file read failed"
9554         done
9555 }
9556 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9557
9558 test_133g() {
9559         # Second verifying writability.
9560         find $proc_dirs \
9561                 -type f \
9562                 -not -name force_lbug \
9563                 -not -name changelog_mask \
9564                 -exec badarea_io '{}' \; &> /dev/null ||
9565                 error "find $proc_dirs failed"
9566
9567         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
9568                 skip "Too old lustre on MDS" && return
9569
9570         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
9571                 skip "Too old lustre on ost1" && return
9572
9573         local facet
9574         for facet in $SINGLEMDS ost1; do
9575                 do_facet $facet find $proc_dirs \
9576                         -type f \
9577                         -not -name force_lbug \
9578                         -not -name changelog_mask \
9579                         -exec badarea_io '{}' \\\; &> /dev/null ||
9580                 error "$facet find $proc_dirs failed"
9581
9582         done
9583
9584         # remount the FS in case writes/reads /proc break the FS
9585         cleanup || error "failed to unmount"
9586         setup || error "failed to setup"
9587         true
9588 }
9589 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9590
9591 test_134a() {
9592         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
9593                 skip "Need MDS version at least 2.7.54" && return
9594
9595         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9596         cancel_lru_locks mdc
9597
9598         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
9599         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9600         [ $unused -eq 0 ] || "$unused locks are not cleared"
9601
9602         local nr=1000
9603         createmany -o $DIR/$tdir/f $nr ||
9604                 error "failed to create $nr files in $DIR/$tdir"
9605         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9606
9607         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
9608         do_facet mds1 $LCTL set_param fail_loc=0x327
9609         do_facet mds1 $LCTL set_param fail_val=500
9610         touch $DIR/$tdir/m
9611
9612         echo "sleep 10 seconds ..."
9613         sleep 10
9614         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
9615
9616         do_facet mds1 $LCTL set_param fail_loc=0
9617         do_facet mds1 $LCTL set_param fail_val=0
9618         [ $lck_cnt -lt $unused ] ||
9619                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
9620
9621         rm $DIR/$tdir/m
9622         unlinkmany $DIR/$tdir/f $nr
9623 }
9624 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
9625
9626 test_134b() {
9627         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
9628                 skip "Need MDS version at least 2.7.54" && return
9629
9630         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9631         cancel_lru_locks mdc
9632
9633         local low_wm=$(do_facet mds1 $LCTL get_param -n \
9634                         ldlm.lock_reclaim_threshold_mb)
9635         # disable reclaim temporarily
9636         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
9637
9638         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
9639         do_facet mds1 $LCTL set_param fail_loc=0x328
9640         do_facet mds1 $LCTL set_param fail_val=500
9641
9642         $LCTL set_param debug=+trace
9643
9644         local nr=600
9645         createmany -o $DIR/$tdir/f $nr &
9646         local create_pid=$!
9647
9648         echo "Sleep $TIMEOUT seconds ..."
9649         sleep $TIMEOUT
9650         if ! ps -p $create_pid  > /dev/null 2>&1; then
9651                 do_facet mds1 $LCTL set_param fail_loc=0
9652                 do_facet mds1 $LCTL set_param fail_val=0
9653                 do_facet mds1 $LCTL set_param \
9654                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
9655                 error "createmany finished incorrectly!"
9656         fi
9657         do_facet mds1 $LCTL set_param fail_loc=0
9658         do_facet mds1 $LCTL set_param fail_val=0
9659         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
9660         wait $create_pid || return 1
9661
9662         unlinkmany $DIR/$tdir/f $nr
9663 }
9664 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
9665
9666 test_140() { #bug-17379
9667         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9668         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
9669         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
9670         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
9671
9672         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9673         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9674         local i=0
9675         while i=`expr $i + 1`; do
9676                 test_mkdir -p $i || error "Creating dir $i"
9677                 cd $i || error "Changing to $i"
9678                 ln -s ../stat stat || error "Creating stat symlink"
9679                 # Read the symlink until ELOOP present,
9680                 # not LBUGing the system is considered success,
9681                 # we didn't overrun the stack.
9682                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9683                 [ $ret -ne 0 ] && {
9684                         if [ $ret -eq 40 ]; then
9685                                 break  # -ELOOP
9686                         else
9687                                 error "Open stat symlink"
9688                                 return
9689                         fi
9690                 }
9691         done
9692         i=`expr $i - 1`
9693         echo "The symlink depth = $i"
9694         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9695                                         error "Invalid symlink depth"
9696
9697         # Test recursive symlink
9698         ln -s symlink_self symlink_self
9699         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9700         echo "open symlink_self returns $ret"
9701         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9702 }
9703 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9704
9705 test_150() {
9706         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9707         local TF="$TMP/$tfile"
9708
9709         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9710         cp $TF $DIR/$tfile
9711         cancel_lru_locks osc
9712         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9713         remount_client $MOUNT
9714         df -P $MOUNT
9715         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9716
9717         $TRUNCATE $TF 6000
9718         $TRUNCATE $DIR/$tfile 6000
9719         cancel_lru_locks osc
9720         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9721
9722         echo "12345" >>$TF
9723         echo "12345" >>$DIR/$tfile
9724         cancel_lru_locks osc
9725         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9726
9727         echo "12345" >>$TF
9728         echo "12345" >>$DIR/$tfile
9729         cancel_lru_locks osc
9730         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9731
9732         rm -f $TF
9733         true
9734 }
9735 run_test 150 "truncate/append tests"
9736
9737 #LU-2902 roc_hit was not able to read all values from lproc
9738 function roc_hit_init() {
9739         local list=$(comma_list $(osts_nodes))
9740         local dir=$DIR/$tdir-check
9741         local file=$dir/file
9742         local BEFORE
9743         local AFTER
9744         local idx
9745
9746         test_mkdir -p $dir
9747         #use setstripe to do a write to every ost
9748         for i in $(seq 0 $((OSTCOUNT-1))); do
9749                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9750                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9751                 idx=$(printf %04x $i)
9752                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9753                         awk '$1 == "cache_access" {sum += $7}
9754                                 END { printf("%0.0f", sum) }')
9755
9756                 cancel_lru_locks osc
9757                 cat $file >/dev/null
9758
9759                 AFTER=$(get_osd_param $list *OST*$idx stats |
9760                         awk '$1 == "cache_access" {sum += $7}
9761                                 END { printf("%0.0f", sum) }')
9762
9763                 echo BEFORE:$BEFORE AFTER:$AFTER
9764                 if ! let "AFTER - BEFORE == 4"; then
9765                         rm -rf $dir
9766                         error "roc_hit is not safe to use"
9767                 fi
9768                 rm $file
9769         done
9770
9771         rm -rf $dir
9772 }
9773
9774 function roc_hit() {
9775         local list=$(comma_list $(osts_nodes))
9776         echo $(get_osd_param $list '' stats |
9777                 awk '$1 == "cache_hit" {sum += $7}
9778                         END { printf("%0.0f", sum) }')
9779 }
9780
9781 function set_cache() {
9782         local on=1
9783
9784         if [ "$2" == "off" ]; then
9785                 on=0;
9786         fi
9787         local list=$(comma_list $(osts_nodes))
9788         set_osd_param $list '' $1_cache_enable $on
9789
9790         cancel_lru_locks osc
9791 }
9792
9793 test_151() {
9794         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9795         remote_ost_nodsh && skip "remote OST with nodsh" && return
9796
9797         local CPAGES=3
9798         local list=$(comma_list $(osts_nodes))
9799
9800         # check whether obdfilter is cache capable at all
9801         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9802                 echo "not cache-capable obdfilter"
9803                 return 0
9804         fi
9805
9806         # check cache is enabled on all obdfilters
9807         if get_osd_param $list '' read_cache_enable | grep 0; then
9808                 echo "oss cache is disabled"
9809                 return 0
9810         fi
9811
9812         set_osd_param $list '' writethrough_cache_enable 1
9813
9814         # check write cache is enabled on all obdfilters
9815         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9816                 echo "oss write cache is NOT enabled"
9817                 return 0
9818         fi
9819
9820         roc_hit_init
9821
9822         #define OBD_FAIL_OBD_NO_LRU  0x609
9823         do_nodes $list $LCTL set_param fail_loc=0x609
9824
9825         # pages should be in the case right after write
9826         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9827                 error "dd failed"
9828
9829         local BEFORE=$(roc_hit)
9830         cancel_lru_locks osc
9831         cat $DIR/$tfile >/dev/null
9832         local AFTER=$(roc_hit)
9833
9834         do_nodes $list $LCTL set_param fail_loc=0
9835
9836         if ! let "AFTER - BEFORE == CPAGES"; then
9837                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9838         fi
9839
9840         # the following read invalidates the cache
9841         cancel_lru_locks osc
9842         set_osd_param $list '' read_cache_enable 0
9843         cat $DIR/$tfile >/dev/null
9844
9845         # now data shouldn't be found in the cache
9846         BEFORE=$(roc_hit)
9847         cancel_lru_locks osc
9848         cat $DIR/$tfile >/dev/null
9849         AFTER=$(roc_hit)
9850         if let "AFTER - BEFORE != 0"; then
9851                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9852         fi
9853
9854         set_osd_param $list '' read_cache_enable 1
9855         rm -f $DIR/$tfile
9856 }
9857 run_test 151 "test cache on oss and controls ==============================="
9858
9859 test_152() {
9860         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9861         local TF="$TMP/$tfile"
9862
9863         # simulate ENOMEM during write
9864 #define OBD_FAIL_OST_NOMEM      0x226
9865         lctl set_param fail_loc=0x80000226
9866         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9867         cp $TF $DIR/$tfile
9868         sync || error "sync failed"
9869         lctl set_param fail_loc=0
9870
9871         # discard client's cache
9872         cancel_lru_locks osc
9873
9874         # simulate ENOMEM during read
9875         lctl set_param fail_loc=0x80000226
9876         cmp $TF $DIR/$tfile || error "cmp failed"
9877         lctl set_param fail_loc=0
9878
9879         rm -f $TF
9880 }
9881 run_test 152 "test read/write with enomem ============================"
9882
9883 test_153() {
9884         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9885 }
9886 run_test 153 "test if fdatasync does not crash ======================="
9887
9888 dot_lustre_fid_permission_check() {
9889         local fid=$1
9890         local ffid=$MOUNT/.lustre/fid/$fid
9891         local test_dir=$2
9892
9893         echo "stat fid $fid"
9894         stat $ffid > /dev/null || error "stat $ffid failed."
9895         echo "touch fid $fid"
9896         touch $ffid || error "touch $ffid failed."
9897         echo "write to fid $fid"
9898         cat /etc/hosts > $ffid || error "write $ffid failed."
9899         echo "read fid $fid"
9900         diff /etc/hosts $ffid || error "read $ffid failed."
9901         echo "append write to fid $fid"
9902         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9903         echo "rename fid $fid"
9904         mv $ffid $test_dir/$tfile.1 &&
9905                 error "rename $ffid to $tfile.1 should fail."
9906         touch $test_dir/$tfile.1
9907         mv $test_dir/$tfile.1 $ffid &&
9908                 error "rename $tfile.1 to $ffid should fail."
9909         rm -f $test_dir/$tfile.1
9910         echo "truncate fid $fid"
9911         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9912         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9913                 echo "link fid $fid"
9914                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9915         fi
9916         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9917                 echo "setfacl fid $fid"
9918                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9919                 echo "getfacl fid $fid"
9920                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9921         fi
9922         echo "unlink fid $fid"
9923         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9924         echo "mknod fid $fid"
9925         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9926
9927         fid=[0xf00000400:0x1:0x0]
9928         ffid=$MOUNT/.lustre/fid/$fid
9929
9930         echo "stat non-exist fid $fid"
9931         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9932         echo "write to non-exist fid $fid"
9933         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9934         echo "link new fid $fid"
9935         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9936
9937         mkdir -p $test_dir/$tdir
9938         touch $test_dir/$tdir/$tfile
9939         fid=$($LFS path2fid $test_dir/$tdir)
9940         rc=$?
9941         [ $rc -ne 0 ] &&
9942                 error "error: could not get fid for $test_dir/$dir/$tfile."
9943
9944         ffid=$MOUNT/.lustre/fid/$fid
9945
9946         echo "ls $fid"
9947         ls $ffid > /dev/null || error "ls $ffid failed."
9948         echo "touch $fid/$tfile.1"
9949         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9950
9951         echo "touch $MOUNT/.lustre/fid/$tfile"
9952         touch $MOUNT/.lustre/fid/$tfile && \
9953                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9954
9955         echo "setxattr to $MOUNT/.lustre/fid"
9956         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9957
9958         echo "listxattr for $MOUNT/.lustre/fid"
9959         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9960
9961         echo "delxattr from $MOUNT/.lustre/fid"
9962         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9963
9964         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9965         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9966                 error "touch invalid fid should fail."
9967
9968         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9969         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9970                 error "touch non-normal fid should fail."
9971
9972         echo "rename $tdir to $MOUNT/.lustre/fid"
9973         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9974                 error "rename to $MOUNT/.lustre/fid should fail."
9975
9976         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9977         then            # LU-3547
9978                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9979                 local new_obf_mode=777
9980
9981                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9982                 chmod $new_obf_mode $DIR/.lustre/fid ||
9983                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9984
9985                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9986                 [ $obf_mode -eq $new_obf_mode ] ||
9987                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9988
9989                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9990                 chmod $old_obf_mode $DIR/.lustre/fid ||
9991                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9992         fi
9993
9994         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9995         fid=$($LFS path2fid $test_dir/$tfile-2)
9996
9997         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
9998         then # LU-5424
9999                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
10000                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
10001                         error "create lov data thru .lustre failed"
10002         fi
10003         echo "cp /etc/passwd $test_dir/$tfile-2"
10004         cp /etc/passwd $test_dir/$tfile-2 ||
10005                 error "copy to $test_dir/$tfile-2 failed."
10006         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
10007         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
10008                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
10009
10010         rm -rf $test_dir/tfile.lnk
10011         rm -rf $test_dir/$tfile-2
10012 }
10013
10014 test_154A() {
10015         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10016                 skip "Need MDS version at least 2.4.1" && return
10017
10018         touch $DIR/$tfile
10019         local FID=$($LFS path2fid $DIR/$tfile)
10020         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
10021
10022         # check that we get the same pathname back
10023         local FOUND=$($LFS fid2path $MOUNT "$FID")
10024         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
10025         [ "$FOUND" != "$DIR/$tfile" ] &&
10026                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
10027
10028         rm -rf $DIR/$tfile
10029 }
10030 run_test 154A "lfs path2fid and fid2path basic checks"
10031
10032 test_154a() {
10033         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10034         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
10035                 { skip "Need MDS version at least 2.2.51"; return 0; }
10036         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
10037         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10038
10039         cp /etc/hosts $DIR/$tfile
10040
10041         fid=$($LFS path2fid $DIR/$tfile)
10042         rc=$?
10043         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
10044
10045         dot_lustre_fid_permission_check "$fid" $DIR ||
10046                 error "dot lustre permission check $fid failed"
10047
10048         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
10049
10050         touch $MOUNT/.lustre/file &&
10051                 error "creation is not allowed under .lustre"
10052
10053         mkdir $MOUNT/.lustre/dir &&
10054                 error "mkdir is not allowed under .lustre"
10055
10056         rm -rf $DIR/$tfile
10057 }
10058 run_test 154a "Open-by-FID"
10059
10060 test_154b() {
10061         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10062         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
10063                 { skip "Need MDS version at least 2.2.51"; return 0; }
10064         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10065
10066         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10067
10068         local remote_dir=$DIR/$tdir/remote_dir
10069         local MDTIDX=1
10070         local rc=0
10071
10072         mkdir -p $DIR/$tdir
10073         $LFS mkdir -i $MDTIDX $remote_dir ||
10074                 error "create remote directory failed"
10075
10076         cp /etc/hosts $remote_dir/$tfile
10077
10078         fid=$($LFS path2fid $remote_dir/$tfile)
10079         rc=$?
10080         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
10081
10082         dot_lustre_fid_permission_check "$fid" $remote_dir ||
10083                 error "dot lustre permission check $fid failed"
10084         rm -rf $DIR/$tdir
10085 }
10086 run_test 154b "Open-by-FID for remote directory"
10087
10088 test_154c() {
10089         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
10090                 skip "Need MDS version at least 2.4.1" && return
10091
10092         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
10093         local FID1=$($LFS path2fid $DIR/$tfile.1)
10094         local FID2=$($LFS path2fid $DIR/$tfile.2)
10095         local FID3=$($LFS path2fid $DIR/$tfile.3)
10096
10097         local N=1
10098         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
10099                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
10100                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
10101                 local want=FID$N
10102                 [ "$FID" = "${!want}" ] ||
10103                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
10104                 N=$((N + 1))
10105         done
10106
10107         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
10108         do
10109                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
10110                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
10111                 N=$((N + 1))
10112         done
10113 }
10114 run_test 154c "lfs path2fid and fid2path multiple arguments"
10115
10116 test_154d() {
10117         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
10118                 skip "Need MDS version at least 2.5.53" && return
10119
10120         if remote_mds; then
10121                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
10122         else
10123                 nid="0@lo"
10124         fi
10125         local proc_ofile="mdt.*.exports.'$nid'.open_files"
10126         local fd
10127         local cmd
10128
10129         rm -f $DIR/$tfile
10130         touch $DIR/$tfile
10131
10132         local fid=$($LFS path2fid $DIR/$tfile)
10133         # Open the file
10134         fd=$(free_fd)
10135         cmd="exec $fd<$DIR/$tfile"
10136         eval $cmd
10137         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
10138         echo "$fid_list" | grep "$fid"
10139         rc=$?
10140
10141         cmd="exec $fd>/dev/null"
10142         eval $cmd
10143         if [ $rc -ne 0 ]; then
10144                 error "FID $fid not found in open files list $fid_list"
10145         fi
10146 }
10147 run_test 154d "Verify open file fid"
10148
10149 test_154e()
10150 {
10151         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
10152                 skip "Need MDS version at least 2.6.50" && return
10153
10154         if ls -a $MOUNT | grep -q '^\.lustre$'; then
10155                 error ".lustre returned by readdir"
10156         fi
10157 }
10158 run_test 154e ".lustre is not returned by readdir"
10159
10160 test_154f() {
10161         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10162         # create parent directory on a single MDT to avoid cross-MDT hardlinks
10163         test_mkdir -p -c1 $DIR/$tdir/d
10164         # test dirs inherit from its stripe
10165         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
10166         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
10167         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
10168         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
10169         touch $DIR/f
10170
10171         # get fid of parents
10172         local FID0=$($LFS path2fid $DIR/$tdir/d)
10173         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
10174         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
10175         local FID3=$($LFS path2fid $DIR)
10176
10177         # check that path2fid --parents returns expected <parent_fid>/name
10178         # 1) test for a directory (single parent)
10179         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
10180         [ "$parent" == "$FID0/foo1" ] ||
10181                 error "expected parent: $FID0/foo1, got: $parent"
10182
10183         # 2) test for a file with nlink > 1 (multiple parents)
10184         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
10185         echo "$parent" | grep -F "$FID1/$tfile" ||
10186                 error "$FID1/$tfile not returned in parent list"
10187         echo "$parent" | grep -F "$FID2/link" ||
10188                 error "$FID2/link not returned in parent list"
10189
10190         # 3) get parent by fid
10191         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
10192         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10193         echo "$parent" | grep -F "$FID1/$tfile" ||
10194                 error "$FID1/$tfile not returned in parent list (by fid)"
10195         echo "$parent" | grep -F "$FID2/link" ||
10196                 error "$FID2/link not returned in parent list (by fid)"
10197
10198         # 4) test for entry in root directory
10199         parent=$($LFS path2fid --parents $DIR/f)
10200         echo "$parent" | grep -F "$FID3/f" ||
10201                 error "$FID3/f not returned in parent list"
10202
10203         # 5) test it on root directory
10204         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
10205                 error "$MOUNT should not have parents"
10206
10207         # enable xattr caching and check that linkea is correctly updated
10208         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
10209         save_lustre_params client "llite.*.xattr_cache" > $save
10210         lctl set_param llite.*.xattr_cache 1
10211
10212         # 6.1) linkea update on rename
10213         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
10214
10215         # get parents by fid
10216         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10217         # foo1 should no longer be returned in parent list
10218         echo "$parent" | grep -F "$FID1" &&
10219                 error "$FID1 should no longer be in parent list"
10220         # the new path should appear
10221         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
10222                 error "$FID2/$tfile.moved is not in parent list"
10223
10224         # 6.2) linkea update on unlink
10225         rm -f $DIR/$tdir/d/foo2/link
10226         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10227         # foo2/link should no longer be returned in parent list
10228         echo "$parent" | grep -F "$FID2/link" &&
10229                 error "$FID2/link should no longer be in parent list"
10230         true
10231
10232         rm -f $DIR/f
10233         restore_lustre_params < $save
10234 }
10235 run_test 154f "get parent fids by reading link ea"
10236
10237 test_154g()
10238 {
10239         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) ]] ||
10240                 { skip "Need MDS version at least 2.6.92"; return 0; }
10241         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
10242
10243         mkdir -p $DIR/$tdir
10244         llapi_fid_test -d $DIR/$tdir
10245 }
10246 run_test 154g "various llapi FID tests"
10247
10248 test_155_small_load() {
10249     local temp=$TMP/$tfile
10250     local file=$DIR/$tfile
10251
10252     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
10253         error "dd of=$temp bs=6096 count=1 failed"
10254     cp $temp $file
10255     cancel_lru_locks osc
10256     cmp $temp $file || error "$temp $file differ"
10257
10258     $TRUNCATE $temp 6000
10259     $TRUNCATE $file 6000
10260     cmp $temp $file || error "$temp $file differ (truncate1)"
10261
10262     echo "12345" >>$temp
10263     echo "12345" >>$file
10264     cmp $temp $file || error "$temp $file differ (append1)"
10265
10266     echo "12345" >>$temp
10267     echo "12345" >>$file
10268     cmp $temp $file || error "$temp $file differ (append2)"
10269
10270     rm -f $temp $file
10271     true
10272 }
10273
10274 test_155_big_load() {
10275     remote_ost_nodsh && skip "remote OST with nodsh" && return
10276     local temp=$TMP/$tfile
10277     local file=$DIR/$tfile
10278
10279     free_min_max
10280     local cache_size=$(do_facet ost$((MAXI+1)) \
10281         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
10282     local large_file_size=$((cache_size * 2))
10283
10284     echo "OSS cache size: $cache_size KB"
10285     echo "Large file size: $large_file_size KB"
10286
10287     [ $MAXV -le $large_file_size ] && \
10288         skip_env "max available OST size needs > $large_file_size KB" && \
10289         return 0
10290
10291     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
10292
10293     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
10294         error "dd of=$temp bs=$large_file_size count=1k failed"
10295     cp $temp $file
10296     ls -lh $temp $file
10297     cancel_lru_locks osc
10298     cmp $temp $file || error "$temp $file differ"
10299
10300     rm -f $temp $file
10301     true
10302 }
10303
10304 test_155a() {
10305         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10306         set_cache read on
10307         set_cache writethrough on
10308         test_155_small_load
10309 }
10310 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
10311
10312 test_155b() {
10313         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10314         set_cache read on
10315         set_cache writethrough off
10316         test_155_small_load
10317 }
10318 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
10319
10320 test_155c() {
10321         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10322         set_cache read off
10323         set_cache writethrough on
10324         test_155_small_load
10325 }
10326 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
10327
10328 test_155d() {
10329         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10330         set_cache read off
10331         set_cache writethrough off
10332         test_155_small_load
10333 }
10334 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
10335
10336 test_155e() {
10337         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10338         set_cache read on
10339         set_cache writethrough on
10340         test_155_big_load
10341 }
10342 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
10343
10344 test_155f() {
10345         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10346         set_cache read on
10347         set_cache writethrough off
10348         test_155_big_load
10349 }
10350 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
10351
10352 test_155g() {
10353         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10354         set_cache read off
10355         set_cache writethrough on
10356         test_155_big_load
10357 }
10358 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
10359
10360 test_155h() {
10361         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10362         set_cache read off
10363         set_cache writethrough off
10364         test_155_big_load
10365 }
10366 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
10367
10368 test_156() {
10369         remote_ost_nodsh && skip "remote OST with nodsh" && return
10370         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10371         local CPAGES=3
10372         local BEFORE
10373         local AFTER
10374         local file="$DIR/$tfile"
10375
10376         [ "$(facet_fstype ost1)" = "zfs" -a \
10377            $(lustre_version_code ost1 -lt $(version_code 2.6.93)) ] &&
10378                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS" &&
10379                 return
10380
10381         roc_hit_init
10382
10383         log "Turn on read and write cache"
10384         set_cache read on
10385         set_cache writethrough on
10386
10387         log "Write data and read it back."
10388         log "Read should be satisfied from the cache."
10389         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10390         BEFORE=$(roc_hit)
10391         cancel_lru_locks osc
10392         cat $file >/dev/null
10393         AFTER=$(roc_hit)
10394         if ! let "AFTER - BEFORE == CPAGES"; then
10395                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10396         else
10397                 log "cache hits:: before: $BEFORE, after: $AFTER"
10398         fi
10399
10400         log "Read again; it should be satisfied from the cache."
10401         BEFORE=$AFTER
10402         cancel_lru_locks osc
10403         cat $file >/dev/null
10404         AFTER=$(roc_hit)
10405         if ! let "AFTER - BEFORE == CPAGES"; then
10406                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10407         else
10408                 log "cache hits:: before: $BEFORE, after: $AFTER"
10409         fi
10410
10411         log "Turn off the read cache and turn on the write cache"
10412         set_cache read off
10413         set_cache writethrough on
10414
10415         log "Read again; it should be satisfied from the cache."
10416         BEFORE=$(roc_hit)
10417         cancel_lru_locks osc
10418         cat $file >/dev/null
10419         AFTER=$(roc_hit)
10420         if ! let "AFTER - BEFORE == CPAGES"; then
10421                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10422         else
10423                 log "cache hits:: before: $BEFORE, after: $AFTER"
10424         fi
10425
10426         log "Read again; it should not be satisfied from the cache."
10427         BEFORE=$AFTER
10428         cancel_lru_locks osc
10429         cat $file >/dev/null
10430         AFTER=$(roc_hit)
10431         if ! let "AFTER - BEFORE == 0"; then
10432                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10433         else
10434                 log "cache hits:: before: $BEFORE, after: $AFTER"
10435         fi
10436
10437         log "Write data and read it back."
10438         log "Read should be satisfied from the cache."
10439         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10440         BEFORE=$(roc_hit)
10441         cancel_lru_locks osc
10442         cat $file >/dev/null
10443         AFTER=$(roc_hit)
10444         if ! let "AFTER - BEFORE == CPAGES"; then
10445                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10446         else
10447                 log "cache hits:: before: $BEFORE, after: $AFTER"
10448         fi
10449
10450         log "Read again; it should not be satisfied from the cache."
10451         BEFORE=$AFTER
10452         cancel_lru_locks osc
10453         cat $file >/dev/null
10454         AFTER=$(roc_hit)
10455         if ! let "AFTER - BEFORE == 0"; then
10456                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10457         else
10458                 log "cache hits:: before: $BEFORE, after: $AFTER"
10459         fi
10460
10461         log "Turn off read and write cache"
10462         set_cache read off
10463         set_cache writethrough off
10464
10465         log "Write data and read it back"
10466         log "It should not be satisfied from the cache."
10467         rm -f $file
10468         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10469         cancel_lru_locks osc
10470         BEFORE=$(roc_hit)
10471         cat $file >/dev/null
10472         AFTER=$(roc_hit)
10473         if ! let "AFTER - BEFORE == 0"; then
10474                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10475         else
10476                 log "cache hits:: before: $BEFORE, after: $AFTER"
10477         fi
10478
10479         log "Turn on the read cache and turn off the write cache"
10480         set_cache read on
10481         set_cache writethrough off
10482
10483         log "Write data and read it back"
10484         log "It should not be satisfied from the cache."
10485         rm -f $file
10486         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10487         BEFORE=$(roc_hit)
10488         cancel_lru_locks osc
10489         cat $file >/dev/null
10490         AFTER=$(roc_hit)
10491         if ! let "AFTER - BEFORE == 0"; then
10492                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10493         else
10494                 log "cache hits:: before: $BEFORE, after: $AFTER"
10495         fi
10496
10497         log "Read again; it should be satisfied from the cache."
10498         BEFORE=$(roc_hit)
10499         cancel_lru_locks osc
10500         cat $file >/dev/null
10501         AFTER=$(roc_hit)
10502         if ! let "AFTER - BEFORE == CPAGES"; then
10503                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10504         else
10505                 log "cache hits:: before: $BEFORE, after: $AFTER"
10506         fi
10507
10508         rm -f $file
10509 }
10510 run_test 156 "Verification of tunables"
10511
10512 #Changelogs
10513 err17935 () {
10514         if [[ $MDSCOUNT -gt 1 ]]; then
10515                 error_ignore bz17935 $*
10516         else
10517                 error $*
10518         fi
10519 }
10520
10521 changelog_chmask()
10522 {
10523         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10524
10525         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
10526
10527         if [ $MASK -eq 1 ]; then
10528                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
10529         else
10530                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
10531         fi
10532 }
10533
10534 changelog_extract_field() {
10535         local mdt=$1
10536         local cltype=$2
10537         local file=$3
10538         local identifier=$4
10539
10540         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
10541                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10542                 tail -1
10543 }
10544
10545 test_160a() {
10546         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10547         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10548         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10549                 { skip "Need MDS version at least 2.2.0"; return; }
10550
10551         local CL_USERS="mdd.$MDT0.changelog_users"
10552         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10553         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10554         echo "Registered as changelog user $USER"
10555         $GET_CL_USERS | grep -q $USER ||
10556                 error "User $USER not found in changelog_users"
10557
10558         # change something
10559         test_mkdir -p $DIR/$tdir/pics/2008/zachy
10560         touch $DIR/$tdir/pics/2008/zachy/timestamp
10561         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
10562         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
10563         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
10564         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
10565         rm $DIR/$tdir/pics/desktop.jpg
10566
10567         $LFS changelog $MDT0 | tail -5
10568
10569         echo "verifying changelog mask"
10570         changelog_chmask "MKDIR"
10571         changelog_chmask "CLOSE"
10572
10573         test_mkdir -p $DIR/$tdir/pics/zach/sofia
10574         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10575
10576         changelog_chmask "MKDIR"
10577         changelog_chmask "CLOSE"
10578
10579         test_mkdir -p $DIR/$tdir/pics/2008/sofia
10580         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10581
10582         $LFS changelog $MDT0
10583         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
10584         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
10585         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
10586         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
10587
10588         # verify contents
10589         echo "verifying target fid"
10590         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
10591         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
10592         [ "$fidc" == "$fidf" ] ||
10593                 err17935 "fid in changelog $fidc != file fid $fidf"
10594         echo "verifying parent fid"
10595         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
10596         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
10597         [ "$fidc" == "$fidf" ] ||
10598                 err17935 "pfid in changelog $fidc != dir fid $fidf"
10599
10600         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10601         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
10602         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10603         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
10604         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
10605                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
10606
10607         MIN_REC=$($GET_CL_USERS |
10608                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
10609         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
10610         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
10611         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
10612                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
10613
10614         # LU-3446 changelog index reset on MDT restart
10615         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10616         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10617         $LFS changelog_clear $MDT0 $USER 0
10618         stop $SINGLEMDS || error "Fail to stop MDT."
10619         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10620         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10621         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
10622         [ $CUR_REC1 == $CUR_REC2 ] ||
10623                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
10624
10625         echo "verifying user deregister"
10626         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10627         $GET_CL_USERS | grep -q $USER &&
10628                 error "User $USER still in changelog_users"
10629
10630         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
10631         if [ $USERS -eq 0 ]; then
10632                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10633                 touch $DIR/$tdir/chloe
10634                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10635                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
10636                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
10637         else
10638                 echo "$USERS other changelog users; can't verify off"
10639         fi
10640 }
10641 run_test 160a "changelog sanity"
10642
10643 test_160b() { # LU-3587
10644         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10645         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10646         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10647                 { skip "Need MDS version at least 2.2.0"; return; }
10648
10649         local CL_USERS="mdd.$MDT0.changelog_users"
10650         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10651         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10652         echo "Registered as changelog user $USER"
10653         $GET_CL_USERS | grep -q $USER ||
10654                 error "User $USER not found in changelog_users"
10655
10656         local LONGNAME1=$(str_repeat a 255)
10657         local LONGNAME2=$(str_repeat b 255)
10658
10659         cd $DIR
10660         echo "creating very long named file"
10661         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
10662         echo "moving very long named file"
10663         mv $LONGNAME1 $LONGNAME2
10664
10665         $LFS changelog $MDT0 | grep RENME
10666
10667         echo "deregistering $USER"
10668         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10669
10670         rm -f $LONGNAME2
10671 }
10672 run_test 160b "Verify that very long rename doesn't crash in changelog"
10673
10674 test_160c() {
10675         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10676
10677         local rc=0
10678         local server_version=$(lustre_version_code $SINGLEMDS)
10679
10680         [[ $server_version -gt $(version_code 2.5.57) ]] ||
10681                 [[ $server_version -gt $(version_code 2.5.1) &&
10682                    $server_version -lt $(version_code 2.5.50) ]] ||
10683                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
10684         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10685
10686         # Registration step
10687         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10688                 changelog_register -n)
10689
10690         rm -rf $DIR/$tdir
10691         mkdir -p $DIR/$tdir
10692         $MCREATE $DIR/$tdir/foo_160c
10693         changelog_chmask "TRUNC"
10694         $TRUNCATE $DIR/$tdir/foo_160c 200
10695         changelog_chmask "TRUNC"
10696         $TRUNCATE $DIR/$tdir/foo_160c 199
10697         $LFS changelog $MDT0
10698         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
10699         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
10700         $LFS changelog_clear $MDT0 $USER 0
10701
10702         # Deregistration step
10703         echo "deregistering $USER"
10704         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10705 }
10706 run_test 160c "verify that changelog log catch the truncate event"
10707
10708 test_160d() {
10709         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10710         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10711
10712         local server_version=$(lustre_version_code mds1)
10713         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10714
10715         [[ $server_version -ge $(version_code 2.7.60) ]] ||
10716                 { skip "Need MDS version at least 2.7.60+"; return; }
10717         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10718
10719         # Registration step
10720         local USER=$(do_facet mds1 $LCTL --device $MDT0 \
10721                 changelog_register -n)
10722
10723         mkdir -p $DIR/$tdir/migrate_dir
10724         $LFS changelog_clear $MDT0 $USER 0
10725
10726         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
10727         $LFS changelog $MDT0
10728         MIGRATES=$($LFS changelog $MDT0 | tail -5 | grep -c "MIGRT")
10729         $LFS changelog_clear $MDT0 $USER 0
10730         [ $MIGRATES -eq 1 ] ||
10731                 error "MIGRATE changelog mask count $MIGRATES != 1"
10732
10733         # Deregistration step
10734         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $USER
10735 }
10736 run_test 160d "verify that changelog log catch the migrate event"
10737
10738 test_161a() {
10739         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10740         test_mkdir -p -c1 $DIR/$tdir
10741         cp /etc/hosts $DIR/$tdir/$tfile
10742         test_mkdir -c1 $DIR/$tdir/foo1
10743         test_mkdir -c1 $DIR/$tdir/foo2
10744         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
10745         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
10746         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
10747         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
10748         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
10749         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10750                 $LFS fid2path $DIR $FID
10751                 err17935 "bad link ea"
10752         fi
10753     # middle
10754     rm $DIR/$tdir/foo2/zachary
10755     # last
10756     rm $DIR/$tdir/foo2/thor
10757     # first
10758     rm $DIR/$tdir/$tfile
10759     # rename
10760     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
10761     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
10762         then
10763         $LFS fid2path $DIR $FID
10764         err17935 "bad link rename"
10765     fi
10766     rm $DIR/$tdir/foo2/maggie
10767
10768         # overflow the EA
10769         local longname=filename_avg_len_is_thirty_two_
10770         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
10771                 error "failed to hardlink many files"
10772         links=$($LFS fid2path $DIR $FID | wc -l)
10773         echo -n "${links}/1000 links in link EA"
10774         [[ $links -gt 60 ]] ||
10775                 err17935 "expected at least 60 links in link EA"
10776         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
10777                 error "failed to unlink many hardlinks"
10778 }
10779 run_test 161a "link ea sanity"
10780
10781 test_161b() {
10782         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10783         [ $MDSCOUNT -lt 2 ] && skip "skipping remote directory test" && return
10784         local MDTIDX=1
10785         local remote_dir=$DIR/$tdir/remote_dir
10786
10787         mkdir -p $DIR/$tdir
10788         $LFS mkdir -i $MDTIDX $remote_dir ||
10789                 error "create remote directory failed"
10790
10791         cp /etc/hosts $remote_dir/$tfile
10792         mkdir -p $remote_dir/foo1
10793         mkdir -p $remote_dir/foo2
10794         ln $remote_dir/$tfile $remote_dir/foo1/sofia
10795         ln $remote_dir/$tfile $remote_dir/foo2/zachary
10796         ln $remote_dir/$tfile $remote_dir/foo1/luna
10797         ln $remote_dir/$tfile $remote_dir/foo2/thor
10798
10799         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
10800                      tr -d ']')
10801         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10802                 $LFS fid2path $DIR $FID
10803                 err17935 "bad link ea"
10804         fi
10805         # middle
10806         rm $remote_dir/foo2/zachary
10807         # last
10808         rm $remote_dir/foo2/thor
10809         # first
10810         rm $remote_dir/$tfile
10811         # rename
10812         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
10813         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
10814         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
10815                 $LFS fid2path $DIR $FID
10816                 err17935 "bad link rename"
10817         fi
10818         rm $remote_dir/foo2/maggie
10819
10820         # overflow the EA
10821         local longname=filename_avg_len_is_thirty_two_
10822         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10823                 error "failed to hardlink many files"
10824         links=$($LFS fid2path $DIR $FID | wc -l)
10825         echo -n "${links}/1000 links in link EA"
10826         [[ ${links} -gt 60 ]] ||
10827                 err17935 "expected at least 60 links in link EA"
10828         unlinkmany $remote_dir/foo2/$longname 1000 ||
10829         error "failed to unlink many hardlinks"
10830 }
10831 run_test 161b "link ea sanity under remote directory"
10832
10833 test_161c() {
10834         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10835         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10836         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10837                 skip "Need MDS version at least 2.1.5" && return
10838
10839         # define CLF_RENAME_LAST 0x0001
10840         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10841         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10842                 changelog_register -n)
10843         rm -rf $DIR/$tdir
10844         mkdir -p $DIR/$tdir
10845         touch $DIR/$tdir/foo_161c
10846         touch $DIR/$tdir/bar_161c
10847         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10848         $LFS changelog $MDT0 | grep RENME
10849         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10850                 cut -f5 -d' ')
10851         $LFS changelog_clear $MDT0 $USER 0
10852         if [ x$flags != "x0x1" ]; then
10853                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10854                         $USER
10855                 error "flag $flags is not 0x1"
10856         fi
10857         echo "rename overwrite a target having nlink = 1," \
10858                 "changelog record has flags of $flags"
10859
10860         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10861         touch $DIR/$tdir/foo_161c
10862         touch $DIR/$tdir/bar_161c
10863         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10864         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10865         $LFS changelog $MDT0 | grep RENME
10866         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10867         $LFS changelog_clear $MDT0 $USER 0
10868         if [ x$flags != "x0x0" ]; then
10869                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10870                         $USER
10871                 error "flag $flags is not 0x0"
10872         fi
10873         echo "rename overwrite a target having nlink > 1," \
10874                 "changelog record has flags of $flags"
10875
10876         # rename doesn't overwrite a target (changelog flag 0x0)
10877         touch $DIR/$tdir/foo_161c
10878         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10879         $LFS changelog $MDT0 | grep RENME
10880         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10881         $LFS changelog_clear $MDT0 $USER 0
10882         if [ x$flags != "x0x0" ]; then
10883                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10884                         $USER
10885                 error "flag $flags is not 0x0"
10886         fi
10887         echo "rename doesn't overwrite a target," \
10888                 "changelog record has flags of $flags"
10889
10890         # define CLF_UNLINK_LAST 0x0001
10891         # unlink a file having nlink = 1 (changelog flag 0x1)
10892         rm -f $DIR/$tdir/foo2_161c
10893         $LFS changelog $MDT0 | grep UNLNK
10894         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10895         $LFS changelog_clear $MDT0 $USER 0
10896         if [ x$flags != "x0x1" ]; then
10897                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10898                         $USER
10899                 error "flag $flags is not 0x1"
10900         fi
10901         echo "unlink a file having nlink = 1," \
10902                 "changelog record has flags of $flags"
10903
10904         # unlink a file having nlink > 1 (changelog flag 0x0)
10905         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10906         rm -f $DIR/$tdir/foobar_161c
10907         $LFS changelog $MDT0 | grep UNLNK
10908         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10909         $LFS changelog_clear $MDT0 $USER 0
10910         if [ x$flags != "x0x0" ]; then
10911                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10912                         $USER
10913                 error "flag $flags is not 0x0"
10914         fi
10915         echo "unlink a file having nlink > 1," \
10916                 "changelog record has flags of $flags"
10917         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10918 }
10919 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10920
10921 check_path() {
10922     local expected=$1
10923     shift
10924     local fid=$2
10925
10926     local path=$(${LFS} fid2path $*)
10927     # Remove the '//' indicating a remote directory
10928     path=$(echo $path | sed 's#//#/#g')
10929     RC=$?
10930
10931     if [ $RC -ne 0 ]; then
10932         err17935 "path looked up of $expected failed. Error $RC"
10933         return $RC
10934     elif [ "${path}" != "${expected}" ]; then
10935         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10936         return 2
10937     fi
10938     echo "fid $fid resolves to path $path (expected $expected)"
10939 }
10940
10941 test_162a() { # was test_162
10942         # Make changes to filesystem
10943         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10944         test_mkdir -p -c1 $DIR/$tdir/d2
10945         touch $DIR/$tdir/d2/$tfile
10946         touch $DIR/$tdir/d2/x1
10947         touch $DIR/$tdir/d2/x2
10948         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
10949         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
10950         # regular file
10951         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10952         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
10953                 error "check path $tdir/d2/$tfile failed"
10954
10955         # softlink
10956         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10957         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10958         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
10959                 error "check path $tdir/d2/p/q/r/slink failed"
10960
10961         # softlink to wrong file
10962         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10963         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10964         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
10965                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
10966
10967         # hardlink
10968         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10969         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10970         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10971         # fid2path dir/fsname should both work
10972         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
10973                 error "check path $tdir/d2/a/b/c/new_file failed"
10974         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
10975                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
10976
10977         # hardlink count: check that there are 2 links
10978         # Doesnt work with CMD yet: 17935
10979         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10980                 err17935 "expected 2 links"
10981
10982         # hardlink indexing: remove the first link
10983         rm $DIR/$tdir/d2/p/q/r/hlink
10984         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
10985                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
10986
10987         return 0
10988 }
10989 run_test 162a "path lookup sanity"
10990
10991 test_162b() {
10992         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10993         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10994
10995         mkdir $DIR/$tdir
10996         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
10997                                 error "create striped dir failed"
10998
10999         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
11000                                         tail -n 1 | awk '{print $2}')
11001         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
11002
11003         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
11004         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
11005
11006         # regular file
11007         for ((i=0;i<5;i++)); do
11008                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
11009                         error "get fid for f$i failed"
11010                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
11011                         error "check path $tdir/striped_dir/f$i failed"
11012
11013                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
11014                         error "get fid for d$i failed"
11015                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
11016                         error "check path $tdir/striped_dir/d$i failed"
11017         done
11018
11019         return 0
11020 }
11021 run_test 162b "striped directory path lookup sanity"
11022
11023 # LU-4239: Verify fid2path works with paths 100 or more directories deep
11024 test_162c() {
11025         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.51) ]] &&
11026                 skip "Need MDS version at least 2.7.51" && return
11027         test_mkdir $DIR/$tdir.local
11028         test_mkdir $DIR/$tdir.remote
11029         local lpath=$tdir.local
11030         local rpath=$tdir.remote
11031
11032         for ((i = 0; i <= 101; i++)); do
11033                 lpath="$lpath/$i"
11034                 mkdir $DIR/$lpath
11035                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
11036                         error "get fid for local directory $DIR/$lpath failed"
11037                 check_path "$DIR/$lpath" $MOUNT $FID --link 0 ||
11038                         error "check path for local directory $DIR/$lpath failed"
11039
11040                 rpath="$rpath/$i"
11041                 test_mkdir $DIR/$rpath
11042                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
11043                         error "get fid for remote directory $DIR/$rpath failed"
11044                 check_path "$DIR/$rpath" $MOUNT $FID --link 0 ||
11045                         error "check path for remote directory $DIR/$rpath failed"
11046         done
11047
11048         return 0
11049 }
11050 run_test 162c "fid2path works with paths 100 or more directories deep"
11051
11052 test_169() {
11053         # do directio so as not to populate the page cache
11054         log "creating a 10 Mb file"
11055         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11056         log "starting reads"
11057         dd if=$DIR/$tfile of=/dev/null bs=4096 &
11058         log "truncating the file"
11059         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11060         log "killing dd"
11061         kill %+ || true # reads might have finished
11062         echo "wait until dd is finished"
11063         wait
11064         log "removing the temporary file"
11065         rm -rf $DIR/$tfile || error "tmp file removal failed"
11066 }
11067 run_test 169 "parallel read and truncate should not deadlock"
11068
11069 test_170() {
11070         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11071         $LCTL clear     # bug 18514
11072         $LCTL debug_daemon start $TMP/${tfile}_log_good
11073         touch $DIR/$tfile
11074         $LCTL debug_daemon stop
11075         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
11076                error "sed failed to read log_good"
11077
11078         $LCTL debug_daemon start $TMP/${tfile}_log_good
11079         rm -rf $DIR/$tfile
11080         $LCTL debug_daemon stop
11081
11082         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
11083                error "lctl df log_bad failed"
11084
11085         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
11086         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
11087
11088         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
11089         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
11090
11091         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
11092                 error "bad_line good_line1 good_line2 are empty"
11093
11094         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11095         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
11096         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11097
11098         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
11099         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
11100         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
11101
11102         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
11103                 error "bad_line_new good_line_new are empty"
11104
11105         local expected_good=$((good_line1 + good_line2*2))
11106
11107         rm -f $TMP/${tfile}*
11108         # LU-231, short malformed line may not be counted into bad lines
11109         if [ $bad_line -ne $bad_line_new ] &&
11110                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
11111                 error "expected $bad_line bad lines, but got $bad_line_new"
11112                 return 1
11113         fi
11114
11115         if [ $expected_good -ne $good_line_new ]; then
11116                 error "expected $expected_good good lines, but got $good_line_new"
11117                 return 2
11118         fi
11119         true
11120 }
11121 run_test 170 "test lctl df to handle corrupted log ====================="
11122
11123 test_171() { # bug20592
11124         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11125 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
11126         $LCTL set_param fail_loc=0x50e
11127         $LCTL set_param fail_val=3000
11128         multiop_bg_pause $DIR/$tfile O_s || true
11129         local MULTIPID=$!
11130         kill -USR1 $MULTIPID
11131         # cause log dump
11132         sleep 3
11133         wait $MULTIPID
11134         if dmesg | grep "recursive fault"; then
11135                 error "caught a recursive fault"
11136         fi
11137         $LCTL set_param fail_loc=0
11138         true
11139 }
11140 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
11141
11142 # it would be good to share it with obdfilter-survey/iokit-libecho code
11143 setup_obdecho_osc () {
11144         local rc=0
11145         local ost_nid=$1
11146         local obdfilter_name=$2
11147         echo "Creating new osc for $obdfilter_name on $ost_nid"
11148         # make sure we can find loopback nid
11149         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
11150
11151         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
11152                            ${obdfilter_name}_osc_UUID || rc=2; }
11153         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
11154                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
11155         return $rc
11156 }
11157
11158 cleanup_obdecho_osc () {
11159         local obdfilter_name=$1
11160         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
11161         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
11162         return 0
11163 }
11164
11165 obdecho_test() {
11166         local OBD=$1
11167         local node=$2
11168         local pages=${3:-64}
11169         local rc=0
11170         local id
11171
11172         local count=10
11173         local obd_size=$(get_obd_size $node $OBD)
11174         local page_size=$(get_page_size $node)
11175         if [[ -n "$obd_size" ]]; then
11176                 local new_count=$((obd_size / (pages * page_size / 1024)))
11177                 [[ $new_count -ge $count ]] || count=$new_count
11178         fi
11179
11180         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
11181         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
11182                            rc=2; }
11183         if [ $rc -eq 0 ]; then
11184             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
11185             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
11186         fi
11187         echo "New object id is $id"
11188         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
11189                            rc=4; }
11190         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
11191                            "test_brw $count w v $pages $id" || rc=4; }
11192         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
11193                            rc=4; }
11194         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
11195                                         "cleanup" || rc=5; }
11196         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
11197                                         "detach" || rc=6; }
11198         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
11199         return $rc
11200 }
11201
11202 test_180a() {
11203         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11204         remote_ost_nodsh && skip "remote OST with nodsh" && return
11205         local rc=0
11206         local rmmod_local=0
11207
11208         if ! module_loaded obdecho; then
11209             load_module obdecho/obdecho
11210             rmmod_local=1
11211         fi
11212
11213         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
11214         local host=$(lctl get_param -n osc.$osc.import |
11215                              awk '/current_connection:/ {print $2}' )
11216         local target=$(lctl get_param -n osc.$osc.import |
11217                              awk '/target:/ {print $2}' )
11218         target=${target%_UUID}
11219
11220         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
11221         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
11222         [[ -n $target ]] && cleanup_obdecho_osc $target
11223         [ $rmmod_local -eq 1 ] && rmmod obdecho
11224         return $rc
11225 }
11226 run_test 180a "test obdecho on osc"
11227
11228 test_180b() {
11229         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11230         remote_ost_nodsh && skip "remote OST with nodsh" && return
11231         local rc=0
11232         local rmmod_remote=0
11233
11234         do_facet ost1 "lsmod | grep -q obdecho || "                      \
11235                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
11236                       "modprobe obdecho; }" && rmmod_remote=1
11237         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
11238         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
11239         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
11240         return $rc
11241 }
11242 run_test 180b "test obdecho directly on obdfilter"
11243
11244 test_180c() { # LU-2598
11245         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11246         remote_ost_nodsh && skip "remote OST with nodsh" && return
11247         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
11248                 skip "Need MDS version at least 2.4.0" && return
11249
11250         local rc=0
11251         local rmmod_remote=false
11252         local pages=16384 # 64MB bulk I/O RPC size
11253         local target
11254
11255         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
11256                 rmmod_remote=true || error "failed to load module obdecho"
11257
11258         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
11259                 head -n1)
11260         if [ -n "$target" ]; then
11261                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
11262         else
11263                 echo "there is no obdfilter target on ost1"
11264                 rc=2
11265         fi
11266         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
11267         return $rc
11268 }
11269 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
11270
11271 test_181() { # bug 22177
11272         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11273         # create enough files to index the directory
11274         createmany -o $DIR/$tdir/foobar 4000
11275         # print attributes for debug purpose
11276         lsattr -d .
11277         # open dir
11278         multiop_bg_pause $DIR/$tdir D_Sc || return 1
11279         MULTIPID=$!
11280         # remove the files & current working dir
11281         unlinkmany $DIR/$tdir/foobar 4000
11282         rmdir $DIR/$tdir
11283         kill -USR1 $MULTIPID
11284         wait $MULTIPID
11285         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
11286         return 0
11287 }
11288 run_test 181 "Test open-unlinked dir ========================"
11289
11290 test_182() {
11291         local fcount=1000
11292         local tcount=10
11293
11294         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11295
11296         $LCTL set_param mdc.*.rpc_stats=clear
11297
11298         for (( i = 0; i < $tcount; i++ )) ; do
11299                 mkdir $DIR/$tdir/$i
11300         done
11301
11302         for (( i = 0; i < $tcount; i++ )) ; do
11303                 createmany -o $DIR/$tdir/$i/f- $fcount &
11304         done
11305         wait
11306
11307         for (( i = 0; i < $tcount; i++ )) ; do
11308                 unlinkmany $DIR/$tdir/$i/f- $fcount &
11309         done
11310         wait
11311
11312         $LCTL get_param mdc.*.rpc_stats
11313
11314         rm -rf $DIR/$tdir
11315 }
11316 run_test 182 "Test parallel modify metadata operations ================"
11317
11318 test_183() { # LU-2275
11319         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11320         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
11321                 skip "Need MDS version at least 2.3.56" && return
11322
11323         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11324         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11325         echo aaa > $DIR/$tdir/$tfile
11326
11327 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
11328         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
11329
11330         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
11331         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
11332
11333         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
11334
11335         # Flush negative dentry cache
11336         touch $DIR/$tdir/$tfile
11337
11338         # We are not checking for any leaked references here, they'll
11339         # become evident next time we do cleanup with module unload.
11340         rm -rf $DIR/$tdir
11341 }
11342 run_test 183 "No crash or request leak in case of strange dispositions ========"
11343
11344 # test suite 184 is for LU-2016, LU-2017
11345 test_184a() {
11346         check_swap_layouts_support && return 0
11347
11348         dir0=$DIR/$tdir/$testnum
11349         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
11350         ref1=/etc/passwd
11351         ref2=/etc/group
11352         file1=$dir0/f1
11353         file2=$dir0/f2
11354         $SETSTRIPE -c1 $file1
11355         cp $ref1 $file1
11356         $SETSTRIPE -c2 $file2
11357         cp $ref2 $file2
11358         gen1=$($GETSTRIPE -g $file1)
11359         gen2=$($GETSTRIPE -g $file2)
11360
11361         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
11362         gen=$($GETSTRIPE -g $file1)
11363         [[ $gen1 != $gen ]] ||
11364                 "Layout generation on $file1 does not change"
11365         gen=$($GETSTRIPE -g $file2)
11366         [[ $gen2 != $gen ]] ||
11367                 "Layout generation on $file2 does not change"
11368
11369         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
11370         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
11371 }
11372 run_test 184a "Basic layout swap"
11373
11374 test_184b() {
11375         check_swap_layouts_support && return 0
11376
11377         dir0=$DIR/$tdir/$testnum
11378         mkdir -p $dir0 || error "creating dir $dir0"
11379         file1=$dir0/f1
11380         file2=$dir0/f2
11381         file3=$dir0/f3
11382         dir1=$dir0/d1
11383         dir2=$dir0/d2
11384         mkdir $dir1 $dir2
11385         $SETSTRIPE -c1 $file1
11386         $SETSTRIPE -c2 $file2
11387         $SETSTRIPE -c1 $file3
11388         chown $RUNAS_ID $file3
11389         gen1=$($GETSTRIPE -g $file1)
11390         gen2=$($GETSTRIPE -g $file2)
11391
11392         $LFS swap_layouts $dir1 $dir2 &&
11393                 error "swap of directories layouts should fail"
11394         $LFS swap_layouts $dir1 $file1 &&
11395                 error "swap of directory and file layouts should fail"
11396         $RUNAS $LFS swap_layouts $file1 $file2 &&
11397                 error "swap of file we cannot write should fail"
11398         $LFS swap_layouts $file1 $file3 &&
11399                 error "swap of file with different owner should fail"
11400         /bin/true # to clear error code
11401 }
11402 run_test 184b "Forbidden layout swap (will generate errors)"
11403
11404 test_184c() {
11405         check_swap_layouts_support && return 0
11406
11407         local dir0=$DIR/$tdir/$testnum
11408         mkdir -p $dir0 || error "creating dir $dir0"
11409
11410         local ref1=$dir0/ref1
11411         local ref2=$dir0/ref2
11412         local file1=$dir0/file1
11413         local file2=$dir0/file2
11414         # create a file large enough for the concurrent test
11415         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
11416         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
11417         echo "ref file size: ref1($(stat -c %s $ref1))," \
11418              "ref2($(stat -c %s $ref2))"
11419
11420         cp $ref2 $file2
11421         dd if=$ref1 of=$file1 bs=16k &
11422         local DD_PID=$!
11423
11424         # Make sure dd starts to copy file
11425         while [ ! -f $file1 ]; do sleep 0.1; done
11426
11427         $LFS swap_layouts $file1 $file2
11428         local rc=$?
11429         wait $DD_PID
11430         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
11431         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
11432
11433         # how many bytes copied before swapping layout
11434         local copied=$(stat -c %s $file2)
11435         local remaining=$(stat -c %s $ref1)
11436         remaining=$((remaining - copied))
11437         echo "Copied $copied bytes before swapping layout..."
11438
11439         cmp -n $copied $file1 $ref2 | grep differ &&
11440                 error "Content mismatch [0, $copied) of ref2 and file1"
11441         cmp -n $copied $file2 $ref1 ||
11442                 error "Content mismatch [0, $copied) of ref1 and file2"
11443         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
11444                 error "Content mismatch [$copied, EOF) of ref1 and file1"
11445
11446         # clean up
11447         rm -f $ref1 $ref2 $file1 $file2
11448 }
11449 run_test 184c "Concurrent write and layout swap"
11450
11451 test_184d() {
11452         check_swap_layouts_support && return 0
11453         [ -z "$(which getfattr 2>/dev/null)" ] &&
11454                 skip "no getfattr command" && return 0
11455
11456         local file1=$DIR/$tdir/$tfile-1
11457         local file2=$DIR/$tdir/$tfile-2
11458         local file3=$DIR/$tdir/$tfile-3
11459         local lovea1
11460         local lovea2
11461
11462         mkdir -p $DIR/$tdir
11463         touch $file1 || error "create $file1 failed"
11464         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11465                 error "create $file2 failed"
11466         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11467                 error "create $file3 failed"
11468         lovea1=$($LFS getstripe $file1 | sed 1d)
11469
11470         $LFS swap_layouts $file2 $file3 ||
11471                 error "swap $file2 $file3 layouts failed"
11472         $LFS swap_layouts $file1 $file2 ||
11473                 error "swap $file1 $file2 layouts failed"
11474
11475         lovea2=$($LFS getstripe $file2 | sed 1d)
11476         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
11477
11478         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11479         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
11480 }
11481 run_test 184d "allow stripeless layouts swap"
11482
11483 test_184e() {
11484         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
11485                 { skip "Need MDS version at least 2.6.94"; return 0; }
11486         check_swap_layouts_support && return 0
11487         [ -z "$(which getfattr 2>/dev/null)" ] &&
11488                 skip "no getfattr command" && return 0
11489
11490         local file1=$DIR/$tdir/$tfile-1
11491         local file2=$DIR/$tdir/$tfile-2
11492         local file3=$DIR/$tdir/$tfile-3
11493         local lovea
11494
11495         mkdir -p $DIR/$tdir
11496         touch $file1 || error "create $file1 failed"
11497         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11498                 error "create $file2 failed"
11499         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11500                 error "create $file3 failed"
11501
11502         $LFS swap_layouts $file1 $file2 ||
11503                 error "swap $file1 $file2 layouts failed"
11504
11505         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11506         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
11507
11508         echo 123 > $file1 || error "Should be able to write into $file1"
11509
11510         $LFS swap_layouts $file1 $file3 ||
11511                 error "swap $file1 $file3 layouts failed"
11512
11513         echo 123 > $file1 || error "Should be able to write into $file1"
11514
11515         rm -rf $file1 $file2 $file3
11516 }
11517 run_test 184e "Recreate layout after stripeless layout swaps"
11518
11519 test_185() { # LU-2441
11520         # LU-3553 - no volatile file support in old servers
11521         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
11522                 { skip "Need MDS version at least 2.3.60"; return 0; }
11523
11524         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11525         touch $DIR/$tdir/spoo
11526         local mtime1=$(stat -c "%Y" $DIR/$tdir)
11527         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
11528                 error "cannot create/write a volatile file"
11529         [ "$FILESET" == "" ] &&
11530         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
11531                 error "FID is still valid after close"
11532
11533         multiop_bg_pause $DIR/$tdir vVw4096_c
11534         local multi_pid=$!
11535
11536         local OLD_IFS=$IFS
11537         IFS=":"
11538         local fidv=($fid)
11539         IFS=$OLD_IFS
11540         # assume that the next FID for this client is sequential, since stdout
11541         # is unfortunately eaten by multiop_bg_pause
11542         local n=$((${fidv[1]} + 1))
11543         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
11544         if [ "$FILESET" == "" ]; then
11545                 $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
11546                         error "FID is missing before close"
11547         fi
11548         kill -USR1 $multi_pid
11549         # 1 second delay, so if mtime change we will see it
11550         sleep 1
11551         local mtime2=$(stat -c "%Y" $DIR/$tdir)
11552         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
11553 }
11554 run_test 185 "Volatile file support"
11555
11556 test_187a() {
11557         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11558         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
11559                 skip "Need MDS version at least 2.3.0" && return
11560
11561         local dir0=$DIR/$tdir/$testnum
11562         mkdir -p $dir0 || error "creating dir $dir0"
11563
11564         local file=$dir0/file1
11565         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
11566         local dv1=$($LFS data_version $file)
11567         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
11568         local dv2=$($LFS data_version $file)
11569         [[ $dv1 != $dv2 ]] ||
11570                 error "data version did not change on write $dv1 == $dv2"
11571
11572         # clean up
11573         rm -f $file1
11574 }
11575 run_test 187a "Test data version change"
11576
11577 test_187b() {
11578         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11579         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
11580                 skip "Need MDS version at least 2.3.0" && return
11581
11582         local dir0=$DIR/$tdir/$testnum
11583         mkdir -p $dir0 || error "creating dir $dir0"
11584
11585         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
11586         [[ ${DV[0]} != ${DV[1]} ]] ||
11587                 error "data version did not change on write"\
11588                       " ${DV[0]} == ${DV[1]}"
11589
11590         # clean up
11591         rm -f $file1
11592 }
11593 run_test 187b "Test data version change on volatile file"
11594
11595 test_200() {
11596         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11597         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11598         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
11599
11600         local POOL=${POOL:-cea1}
11601         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
11602         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
11603         # Pool OST targets
11604         local first_ost=0
11605         local last_ost=$(($OSTCOUNT - 1))
11606         local ost_step=2
11607         local ost_list=$(seq $first_ost $ost_step $last_ost)
11608         local ost_range="$first_ost $last_ost $ost_step"
11609         local test_path=$POOL_ROOT/$POOL_DIR_NAME
11610         local file_dir=$POOL_ROOT/file_tst
11611         local subdir=$test_path/subdir
11612
11613         local rc=0
11614         while : ; do
11615                 # former test_200a test_200b
11616                 pool_add $POOL                          || { rc=$? ; break; }
11617                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
11618                 # former test_200c test_200d
11619                 mkdir -p $test_path
11620                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
11621                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
11622                 mkdir -p $subdir
11623                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
11624                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
11625                                                         || { rc=$? ; break; }
11626                 # former test_200e test_200f
11627                 local files=$((OSTCOUNT*3))
11628                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
11629                                                         || { rc=$? ; break; }
11630                 pool_create_files $POOL $file_dir $files "$ost_list" \
11631                                                         || { rc=$? ; break; }
11632                 # former test_200g test_200h
11633                 pool_lfs_df $POOL                       || { rc=$? ; break; }
11634                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
11635
11636                 # former test_201a test_201b test_201c
11637                 pool_remove_first_target $POOL          || { rc=$? ; break; }
11638
11639                 local f=$test_path/$tfile
11640                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
11641                 pool_remove $POOL $f                    || { rc=$? ; break; }
11642                 break
11643         done
11644
11645         cleanup_pools
11646         return $rc
11647 }
11648 run_test 200 "OST pools"
11649
11650 # usage: default_attr <count | size | offset>
11651 default_attr() {
11652         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
11653 }
11654
11655 # usage: check_default_stripe_attr
11656 check_default_stripe_attr() {
11657         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
11658         case $1 in
11659         --stripe-count|--count)
11660                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
11661         --stripe-size|--size)
11662                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
11663         --stripe-index|--index)
11664                 EXPECTED=-1;;
11665         *)
11666                 error "unknown getstripe attr '$1'"
11667         esac
11668
11669         [ $ACTUAL != $EXPECTED ] &&
11670                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
11671 }
11672
11673 test_204a() {
11674         test_mkdir -p $DIR/$tdir
11675         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
11676
11677         check_default_stripe_attr --stripe-count
11678         check_default_stripe_attr --stripe-size
11679         check_default_stripe_attr --stripe-index
11680
11681         return 0
11682 }
11683 run_test 204a "Print default stripe attributes ================="
11684
11685 test_204b() {
11686         test_mkdir -p $DIR/$tdir
11687         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11688
11689         check_default_stripe_attr --stripe-size
11690         check_default_stripe_attr --stripe-index
11691
11692         return 0
11693 }
11694 run_test 204b "Print default stripe size and offset  ==========="
11695
11696 test_204c() {
11697         test_mkdir -p $DIR/$tdir
11698         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11699
11700         check_default_stripe_attr --stripe-count
11701         check_default_stripe_attr --stripe-index
11702
11703         return 0
11704 }
11705 run_test 204c "Print default stripe count and offset ==========="
11706
11707 test_204d() {
11708         test_mkdir -p $DIR/$tdir
11709         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11710
11711         check_default_stripe_attr --stripe-count
11712         check_default_stripe_attr --stripe-size
11713
11714         return 0
11715 }
11716 run_test 204d "Print default stripe count and size ============="
11717
11718 test_204e() {
11719         test_mkdir -p $DIR/$tdir
11720         $SETSTRIPE -d $DIR/$tdir
11721
11722         check_default_stripe_attr --stripe-count --raw
11723         check_default_stripe_attr --stripe-size --raw
11724         check_default_stripe_attr --stripe-index --raw
11725
11726         return 0
11727 }
11728 run_test 204e "Print raw stripe attributes ================="
11729
11730 test_204f() {
11731         test_mkdir -p $DIR/$tdir
11732         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11733
11734         check_default_stripe_attr --stripe-size --raw
11735         check_default_stripe_attr --stripe-index --raw
11736
11737         return 0
11738 }
11739 run_test 204f "Print raw stripe size and offset  ==========="
11740
11741 test_204g() {
11742         test_mkdir -p $DIR/$tdir
11743         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11744
11745         check_default_stripe_attr --stripe-count --raw
11746         check_default_stripe_attr --stripe-index --raw
11747
11748         return 0
11749 }
11750 run_test 204g "Print raw stripe count and offset ==========="
11751
11752 test_204h() {
11753         test_mkdir -p $DIR/$tdir
11754         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11755
11756         check_default_stripe_attr --stripe-count --raw
11757         check_default_stripe_attr --stripe-size --raw
11758
11759         return 0
11760 }
11761 run_test 204h "Print raw stripe count and size ============="
11762
11763 # Figure out which job scheduler is being used, if any,
11764 # or use a fake one
11765 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11766         JOBENV=SLURM_JOB_ID
11767 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11768         JOBENV=LSB_JOBID
11769 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11770         JOBENV=PBS_JOBID
11771 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11772         JOBENV=LOADL_STEP_ID
11773 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11774         JOBENV=JOB_ID
11775 else
11776         $LCTL list_param jobid_name > /dev/null 2>&1
11777         if [ $? -eq 0 ]; then
11778                 JOBENV=nodelocal
11779         else
11780                 JOBENV=FAKE_JOBID
11781         fi
11782 fi
11783
11784 verify_jobstats() {
11785         local cmd=($1)
11786         shift
11787         local facets="$@"
11788
11789 # we don't really need to clear the stats for this test to work, since each
11790 # command has a unique jobid, but it makes debugging easier if needed.
11791 #       for facet in $facets; do
11792 #               local dev=$(convert_facet2label $facet)
11793 #               # clear old jobstats
11794 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
11795 #       done
11796
11797         # use a new JobID for each test, or we might see an old one
11798         [ "$JOBENV" = "FAKE_JOBID" ] &&
11799                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
11800
11801         JOBVAL=${!JOBENV}
11802
11803         [ "$JOBENV" = "nodelocal" ] && {
11804                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
11805                 $LCTL set_param jobid_name=$FAKE_JOBID
11806                 JOBVAL=$FAKE_JOBID
11807         }
11808
11809         log "Test: ${cmd[*]}"
11810         log "Using JobID environment variable $JOBENV=$JOBVAL"
11811
11812         if [ $JOBENV = "FAKE_JOBID" ]; then
11813                 FAKE_JOBID=$JOBVAL ${cmd[*]}
11814         else
11815                 ${cmd[*]}
11816         fi
11817
11818         # all files are created on OST0000
11819         for facet in $facets; do
11820                 local stats="*.$(convert_facet2label $facet).job_stats"
11821                 if [ $(do_facet $facet lctl get_param $stats |
11822                        grep -c $JOBVAL) -ne 1 ]; then
11823                         do_facet $facet lctl get_param $stats
11824                         error "No jobstats for $JOBVAL found on $facet::$stats"
11825                 fi
11826         done
11827 }
11828
11829 jobstats_set() {
11830         trap 0
11831         NEW_JOBENV=${1:-$OLD_JOBENV}
11832         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11833         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11834 }
11835
11836 cleanup_205() {
11837         do_facet $SINGLEMDS \
11838                 $LCTL set_param mdt.*.job_cleanup_interval=$OLD_INTERVAL
11839         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11840         do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
11841 }
11842
11843 test_205() { # Job stats
11844         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11845         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11846         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11847         remote_ost_nodsh && skip "remote OST with nodsh" && return
11848
11849         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11850                 skip "Server doesn't support jobstats" && return 0
11851         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11852
11853         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11854         if [ $OLD_JOBENV != $JOBENV ]; then
11855                 jobstats_set $JOBENV
11856                 trap cleanup_205 EXIT
11857         fi
11858
11859         CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
11860         echo "Registered as changelog user $CL_USER"
11861
11862         OLD_INTERVAL=$(do_facet $SINGLEMDS \
11863                        lctl get_param -n mdt.*.job_cleanup_interval)
11864         local interval_new=5
11865         do_facet $SINGLEMDS \
11866                 $LCTL set_param mdt.*.job_cleanup_interval=$interval_new
11867         local start=$SECONDS
11868
11869         local cmd
11870         # mkdir
11871         cmd="mkdir $DIR/$tdir"
11872         verify_jobstats "$cmd" "$SINGLEMDS"
11873         # rmdir
11874         cmd="rmdir $DIR/$tdir"
11875         verify_jobstats "$cmd" "$SINGLEMDS"
11876         # mkdir on secondary MDT
11877         if [ $MDSCOUNT -gt 1 ]; then
11878                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
11879                 verify_jobstats "$cmd" "mds2"
11880         fi
11881         # mknod
11882         cmd="mknod $DIR/$tfile c 1 3"
11883         verify_jobstats "$cmd" "$SINGLEMDS"
11884         # unlink
11885         cmd="rm -f $DIR/$tfile"
11886         verify_jobstats "$cmd" "$SINGLEMDS"
11887         # create all files on OST0000 so verify_jobstats can find OST stats
11888         # open & close
11889         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11890         verify_jobstats "$cmd" "$SINGLEMDS"
11891         # setattr
11892         cmd="touch $DIR/$tfile"
11893         verify_jobstats "$cmd" "$SINGLEMDS ost1"
11894         # write
11895         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11896         verify_jobstats "$cmd" "ost1"
11897         # read
11898         cancel_lru_locks osc
11899         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11900         verify_jobstats "$cmd" "ost1"
11901         # truncate
11902         cmd="$TRUNCATE $DIR/$tfile 0"
11903         verify_jobstats "$cmd" "$SINGLEMDS ost1"
11904         # rename
11905         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
11906         verify_jobstats "$cmd" "$SINGLEMDS"
11907         # jobstats expiry - sleep until old stats should be expired
11908         local left=$((interval_new + 2 - (SECONDS - start)))
11909         [ $left -ge 0 ] && echo "sleep $left for expiry" && sleep $((left + 1))
11910         cmd="mkdir $DIR/$tdir.expire"
11911         verify_jobstats "$cmd" "$SINGLEMDS"
11912         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
11913             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
11914
11915         # Ensure that jobid are present in changelog (if supported by MDS)
11916         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
11917         then
11918                 $LFS changelog $MDT0 | tail -9
11919                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
11920                 [ $jobids -eq 9 ] ||
11921                         error "Wrong changelog jobid count $jobids != 9"
11922
11923                 # LU-5862
11924                 JOBENV="disable"
11925                 jobstats_set $JOBENV
11926                 touch $DIR/$tfile
11927                 $LFS changelog $MDT0 | tail -1
11928                 jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
11929                 [ $jobids -eq 0 ] ||
11930                         error "Unexpected jobids when jobid_var=$JOBENV"
11931         fi
11932
11933         cleanup_205
11934 }
11935 run_test 205 "Verify job stats"
11936
11937 # LU-1480, LU-1773 and LU-1657
11938 test_206() {
11939         mkdir -p $DIR/$tdir
11940         $SETSTRIPE -c -1 $DIR/$tdir
11941 #define OBD_FAIL_LOV_INIT 0x1403
11942         $LCTL set_param fail_loc=0xa0001403
11943         $LCTL set_param fail_val=1
11944         touch $DIR/$tdir/$tfile || true
11945 }
11946 run_test 206 "fail lov_init_raid0() doesn't lbug"
11947
11948 test_207a() {
11949         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11950         local fsz=`stat -c %s $DIR/$tfile`
11951         cancel_lru_locks mdc
11952
11953         # do not return layout in getattr intent
11954 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11955         $LCTL set_param fail_loc=0x170
11956         local sz=`stat -c %s $DIR/$tfile`
11957
11958         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11959
11960         rm -rf $DIR/$tfile
11961 }
11962 run_test 207a "can refresh layout at glimpse"
11963
11964 test_207b() {
11965         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11966         local cksum=`md5sum $DIR/$tfile`
11967         local fsz=`stat -c %s $DIR/$tfile`
11968         cancel_lru_locks mdc
11969         cancel_lru_locks osc
11970
11971         # do not return layout in getattr intent
11972 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11973         $LCTL set_param fail_loc=0x171
11974
11975         # it will refresh layout after the file is opened but before read issues
11976         echo checksum is "$cksum"
11977         echo "$cksum" |md5sum -c --quiet || error "file differs"
11978
11979         rm -rf $DIR/$tfile
11980 }
11981 run_test 207b "can refresh layout at open"
11982
11983 test_208() {
11984         # FIXME: in this test suite, only RD lease is used. This is okay
11985         # for now as only exclusive open is supported. After generic lease
11986         # is done, this test suite should be revised. - Jinshan
11987
11988         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11989         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11990                 { skip "Need MDS version at least 2.4.52"; return 0; }
11991
11992         echo "==== test 1: verify get lease work"
11993         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11994
11995         echo "==== test 2: verify lease can be broken by upcoming open"
11996         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11997         local PID=$!
11998         sleep 1
11999
12000         $MULTIOP $DIR/$tfile oO_RDONLY:c
12001         kill -USR1 $PID && wait $PID || error "break lease error"
12002
12003         echo "==== test 3: verify lease can't be granted if an open already exists"
12004         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
12005         local PID=$!
12006         sleep 1
12007
12008         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
12009         kill -USR1 $PID && wait $PID || error "open file error"
12010
12011         echo "==== test 4: lease can sustain over recovery"
12012         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
12013         PID=$!
12014         sleep 1
12015
12016         fail mds1
12017
12018         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
12019
12020         echo "==== test 5: lease broken can't be regained by replay"
12021         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
12022         PID=$!
12023         sleep 1
12024
12025         # open file to break lease and then recovery
12026         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
12027         fail mds1
12028
12029         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
12030
12031         rm -f $DIR/$tfile
12032 }
12033 run_test 208 "Exclusive open"
12034
12035 test_209() {
12036         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
12037                 skip_env "must have disp_stripe" && return
12038
12039         touch $DIR/$tfile
12040         sync; sleep 5; sync;
12041
12042         echo 3 > /proc/sys/vm/drop_caches
12043         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
12044
12045         # open/close 500 times
12046         for i in $(seq 500); do
12047                 cat $DIR/$tfile
12048         done
12049
12050         echo 3 > /proc/sys/vm/drop_caches
12051         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
12052
12053         echo "before: $req_before, after: $req_after"
12054         [ $((req_after - req_before)) -ge 300 ] &&
12055                 error "open/close requests are not freed"
12056         return 0
12057 }
12058 run_test 209 "read-only open/close requests should be freed promptly"
12059
12060 test_212() {
12061         size=`date +%s`
12062         size=$((size % 8192 + 1))
12063         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
12064         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
12065         rm -f $DIR/f212 $DIR/f212.xyz
12066 }
12067 run_test 212 "Sendfile test ============================================"
12068
12069 test_213() {
12070         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
12071         cancel_lru_locks osc
12072         lctl set_param fail_loc=0x8000040f
12073         # generate a read lock
12074         cat $DIR/$tfile > /dev/null
12075         # write to the file, it will try to cancel the above read lock.
12076         cat /etc/hosts >> $DIR/$tfile
12077 }
12078 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
12079
12080 test_214() { # for bug 20133
12081         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
12082         for (( i=0; i < 340; i++ )) ; do
12083                 touch $DIR/$tdir/d214c/a$i
12084         done
12085
12086         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
12087         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
12088         ls $DIR/d214c || error "ls $DIR/d214c failed"
12089         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
12090         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
12091 }
12092 run_test 214 "hash-indexed directory test - bug 20133"
12093
12094 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
12095 create_lnet_proc_files() {
12096         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
12097         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
12098
12099         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
12100         rm -f "$TMP/lnet_$1.sys_tmp"
12101 }
12102
12103 # counterpart of create_lnet_proc_files
12104 remove_lnet_proc_files() {
12105         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
12106 }
12107
12108 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12109 # 3rd arg as regexp for body
12110 check_lnet_proc_stats() {
12111         local l=$(cat "$TMP/lnet_$1" |wc -l)
12112         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
12113
12114         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
12115 }
12116
12117 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12118 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
12119 # optional and can be regexp for 2nd line (lnet.routes case)
12120 check_lnet_proc_entry() {
12121         local blp=2          # blp stands for 'position of 1st line of body'
12122         [ -z "$5" ] || blp=3 # lnet.routes case
12123
12124         local l=$(cat "$TMP/lnet_$1" |wc -l)
12125         # subtracting one from $blp because the body can be empty
12126         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
12127
12128         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
12129                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
12130
12131         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
12132                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
12133
12134         # bail out if any unexpected line happened
12135         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
12136         [ "$?" != 0 ] || error "$2 misformatted"
12137 }
12138
12139 test_215() { # for bugs 18102, 21079, 21517
12140         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12141         local N='(0|[1-9][0-9]*)'       # non-negative numeric
12142         local P='[1-9][0-9]*'           # positive numeric
12143         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
12144         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
12145         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
12146         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
12147
12148         local L1 # regexp for 1st line
12149         local L2 # regexp for 2nd line (optional)
12150         local BR # regexp for the rest (body)
12151
12152         # lnet.stats should look as 11 space-separated non-negative numerics
12153         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
12154         create_lnet_proc_files "stats"
12155         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
12156         remove_lnet_proc_files "stats"
12157
12158         # lnet.routes should look like this:
12159         # Routing disabled/enabled
12160         # net hops priority state router
12161         # where net is a string like tcp0, hops > 0, priority >= 0,
12162         # state is up/down,
12163         # router is a string like 192.168.1.1@tcp2
12164         L1="^Routing (disabled|enabled)$"
12165         L2="^net +hops +priority +state +router$"
12166         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
12167         create_lnet_proc_files "routes"
12168         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
12169         remove_lnet_proc_files "routes"
12170
12171         # lnet.routers should look like this:
12172         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
12173         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
12174         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
12175         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
12176         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
12177         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
12178         create_lnet_proc_files "routers"
12179         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
12180         remove_lnet_proc_files "routers"
12181
12182         # lnet.peers should look like this:
12183         # nid refs state last max rtr min tx min queue
12184         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
12185         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
12186         # numeric (0 or >0 or <0), queue >= 0.
12187         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
12188         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
12189         create_lnet_proc_files "peers"
12190         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
12191         remove_lnet_proc_files "peers"
12192
12193         # lnet.buffers  should look like this:
12194         # pages count credits min
12195         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
12196         L1="^pages +count +credits +min$"
12197         BR="^ +$N +$N +$I +$I$"
12198         create_lnet_proc_files "buffers"
12199         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
12200         remove_lnet_proc_files "buffers"
12201
12202         # lnet.nis should look like this:
12203         # nid status alive refs peer rtr max tx min
12204         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
12205         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
12206         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
12207         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
12208         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
12209         create_lnet_proc_files "nis"
12210         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
12211         remove_lnet_proc_files "nis"
12212
12213         # can we successfully write to lnet.stats?
12214         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
12215         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
12216 }
12217 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
12218
12219 test_216() { # bug 20317
12220         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12221         remote_ost_nodsh && skip "remote OST with nodsh" && return
12222
12223         local node
12224         local facets=$(get_facets OST)
12225         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
12226
12227         save_lustre_params client "osc.*.contention_seconds" > $p
12228         save_lustre_params $facets \
12229                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
12230         save_lustre_params $facets \
12231                 "ldlm.namespaces.filter-*.contended_locks" >> $p
12232         save_lustre_params $facets \
12233                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
12234         clear_osc_stats
12235
12236         # agressive lockless i/o settings
12237         for node in $(osts_nodes); do
12238                 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'
12239         done
12240         lctl set_param -n osc.*.contention_seconds 60
12241
12242         $DIRECTIO write $DIR/$tfile 0 10 4096
12243         $CHECKSTAT -s 40960 $DIR/$tfile
12244
12245         # disable lockless i/o
12246         for node in $(osts_nodes); do
12247                 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'
12248         done
12249         lctl set_param -n osc.*.contention_seconds 0
12250         clear_osc_stats
12251
12252         dd if=/dev/zero of=$DIR/$tfile count=0
12253         $CHECKSTAT -s 0 $DIR/$tfile
12254
12255         restore_lustre_params <$p
12256         rm -f $p
12257         rm $DIR/$tfile
12258 }
12259 run_test 216 "check lockless direct write works and updates file size and kms correctly"
12260
12261 test_217() { # bug 22430
12262         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12263         local node
12264         local nid
12265
12266         for node in $(nodes_list); do
12267                 nid=$(host_nids_address $node $NETTYPE)
12268                 if [[ $nid = *-* ]] ; then
12269                         echo "lctl ping $nid@$NETTYPE"
12270                         lctl ping $nid@$NETTYPE
12271                 else
12272                         echo "skipping $node (no hyphen detected)"
12273                 fi
12274         done
12275 }
12276 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
12277
12278 test_218() {
12279        # do directio so as not to populate the page cache
12280        log "creating a 10 Mb file"
12281        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
12282        log "starting reads"
12283        dd if=$DIR/$tfile of=/dev/null bs=4096 &
12284        log "truncating the file"
12285        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
12286        log "killing dd"
12287        kill %+ || true # reads might have finished
12288        echo "wait until dd is finished"
12289        wait
12290        log "removing the temporary file"
12291        rm -rf $DIR/$tfile || error "tmp file removal failed"
12292 }
12293 run_test 218 "parallel read and truncate should not deadlock ======================="
12294
12295 test_219() {
12296         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12297         # write one partial page
12298         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
12299         # set no grant so vvp_io_commit_write will do sync write
12300         $LCTL set_param fail_loc=0x411
12301         # write a full page at the end of file
12302         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
12303
12304         $LCTL set_param fail_loc=0
12305         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
12306         $LCTL set_param fail_loc=0x411
12307         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
12308
12309         # LU-4201
12310         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
12311         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
12312 }
12313 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
12314
12315 test_220() { #LU-325
12316         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12317         remote_ost_nodsh && skip "remote OST with nodsh" && return
12318         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12319         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12320         local OSTIDX=0
12321
12322         # create on MDT0000 so the last_id and next_id are correct
12323         mkdir $DIR/$tdir
12324         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
12325         OST=${OST%_UUID}
12326
12327         # on the mdt's osc
12328         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
12329         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
12330                         osc.$mdtosc_proc1.prealloc_last_id)
12331         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
12332                         osc.$mdtosc_proc1.prealloc_next_id)
12333
12334         $LFS df -i
12335
12336         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
12337         #define OBD_FAIL_OST_ENOINO              0x229
12338         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
12339         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
12340         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
12341
12342         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
12343
12344         MDSOBJS=$((last_id - next_id))
12345         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
12346
12347         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
12348         echo "OST still has $count kbytes free"
12349
12350         echo "create $MDSOBJS files @next_id..."
12351         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
12352
12353         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12354                         osc.$mdtosc_proc1.prealloc_last_id)
12355         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12356                         osc.$mdtosc_proc1.prealloc_next_id)
12357
12358         echo "after creation, last_id=$last_id2, next_id=$next_id2"
12359         $LFS df -i
12360
12361         echo "cleanup..."
12362
12363         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
12364         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
12365
12366         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
12367         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
12368         echo "unlink $MDSOBJS files @$next_id..."
12369         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
12370 }
12371 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
12372
12373 test_221() {
12374         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12375         dd if=`which date` of=$MOUNT/date oflag=sync
12376         chmod +x $MOUNT/date
12377
12378         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
12379         $LCTL set_param fail_loc=0x80001401
12380
12381         $MOUNT/date > /dev/null
12382         rm -f $MOUNT/date
12383 }
12384 run_test 221 "make sure fault and truncate race to not cause OOM"
12385
12386 test_222a () {
12387         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12388        rm -rf $DIR/$tdir
12389        test_mkdir -p $DIR/$tdir
12390        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12391        createmany -o $DIR/$tdir/$tfile 10
12392        cancel_lru_locks mdc
12393        cancel_lru_locks osc
12394        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12395        $LCTL set_param fail_loc=0x31a
12396        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
12397        $LCTL set_param fail_loc=0
12398        rm -r $DIR/$tdir
12399 }
12400 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
12401
12402 test_222b () {
12403         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12404        rm -rf $DIR/$tdir
12405        test_mkdir -p $DIR/$tdir
12406        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12407        createmany -o $DIR/$tdir/$tfile 10
12408        cancel_lru_locks mdc
12409        cancel_lru_locks osc
12410        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12411        $LCTL set_param fail_loc=0x31a
12412        rm -r $DIR/$tdir || "AGL for rmdir failed"
12413        $LCTL set_param fail_loc=0
12414 }
12415 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
12416
12417 test_223 () {
12418         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12419        rm -rf $DIR/$tdir
12420        test_mkdir -p $DIR/$tdir
12421        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12422        createmany -o $DIR/$tdir/$tfile 10
12423        cancel_lru_locks mdc
12424        cancel_lru_locks osc
12425        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
12426        $LCTL set_param fail_loc=0x31b
12427        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
12428        $LCTL set_param fail_loc=0
12429        rm -r $DIR/$tdir
12430 }
12431 run_test 223 "osc reenqueue if without AGL lock granted ======================="
12432
12433 test_224a() { # LU-1039, MRP-303
12434         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12435         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
12436         $LCTL set_param fail_loc=0x508
12437         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
12438         $LCTL set_param fail_loc=0
12439         df $DIR
12440 }
12441 run_test 224a "Don't panic on bulk IO failure"
12442
12443 test_224b() { # LU-1039, MRP-303
12444         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12445         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
12446         cancel_lru_locks osc
12447         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
12448         $LCTL set_param fail_loc=0x515
12449         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
12450         $LCTL set_param fail_loc=0
12451         df $DIR
12452 }
12453 run_test 224b "Don't panic on bulk IO failure"
12454
12455 test_224c() { # LU-6441
12456         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12457         local pages_per_rpc=$($LCTL get_param \
12458                                 osc.*.max_pages_per_rpc)
12459         local at_max=$($LCTL get_param -n at_max)
12460         local timeout=$($LCTL get_param -n timeout)
12461         local test_at="$LCTL get_param -n at_max"
12462         local param_at="$FSNAME.sys.at_max"
12463         local test_timeout="$LCTL get_param -n timeout"
12464         local param_timeout="$FSNAME.sys.timeout"
12465
12466         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
12467
12468         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
12469                 error "conf_param at_max=0 failed"
12470         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
12471                 error "conf_param timeout=5 failed"
12472
12473         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
12474         $LCTL set_param fail_loc=0x520
12475         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
12476         sync
12477         $LCTL set_param fail_loc=0
12478
12479         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
12480                 error "conf_param at_max=$at_max failed"
12481         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
12482                 $timeout || error "conf_param timeout=$timeout failed"
12483
12484         $LCTL set_param -n $pages_per_rpc
12485 }
12486 run_test 224c "Don't hang if one of md lost during large bulk RPC"
12487
12488 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
12489 test_225a () {
12490         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12491         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12492         if [ -z ${MDSSURVEY} ]; then
12493               skip_env "mds-survey not found" && return
12494         fi
12495
12496         [ $MDSCOUNT -ge 2 ] &&
12497                 skip "skipping now for more than one MDT" && return
12498
12499        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12500             { skip "Need MDS version at least 2.2.51"; return; }
12501
12502        local mds=$(facet_host $SINGLEMDS)
12503        local target=$(do_nodes $mds 'lctl dl' | \
12504                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12505
12506        local cmd1="file_count=1000 thrhi=4"
12507        local cmd2="dir_count=2 layer=mdd stripe_count=0"
12508        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12509        local cmd="$cmd1 $cmd2 $cmd3"
12510
12511        rm -f ${TMP}/mds_survey*
12512        echo + $cmd
12513        eval $cmd || error "mds-survey with zero-stripe failed"
12514        cat ${TMP}/mds_survey*
12515        rm -f ${TMP}/mds_survey*
12516 }
12517 run_test 225a "Metadata survey sanity with zero-stripe"
12518
12519 test_225b () {
12520         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12521         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12522         if [ -z ${MDSSURVEY} ]; then
12523               skip_env "mds-survey not found" && return
12524         fi
12525         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12526             { skip "Need MDS version at least 2.2.51"; return; }
12527
12528         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
12529               skip_env "Need to mount OST to test" && return
12530         fi
12531
12532         [ $MDSCOUNT -ge 2 ] &&
12533                 skip "skipping now for more than one MDT" && return
12534        local mds=$(facet_host $SINGLEMDS)
12535        local target=$(do_nodes $mds 'lctl dl' | \
12536                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12537
12538        local cmd1="file_count=1000 thrhi=4"
12539        local cmd2="dir_count=2 layer=mdd stripe_count=1"
12540        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12541        local cmd="$cmd1 $cmd2 $cmd3"
12542
12543        rm -f ${TMP}/mds_survey*
12544        echo + $cmd
12545        eval $cmd || error "mds-survey with stripe_count failed"
12546        cat ${TMP}/mds_survey*
12547        rm -f ${TMP}/mds_survey*
12548 }
12549 run_test 225b "Metadata survey sanity with stripe_count = 1"
12550
12551 mcreate_path2fid () {
12552         local mode=$1
12553         local major=$2
12554         local minor=$3
12555         local name=$4
12556         local desc=$5
12557         local path=$DIR/$tdir/$name
12558         local fid
12559         local rc
12560         local fid_path
12561
12562         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
12563                 error "cannot create $desc"
12564
12565         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
12566         rc=$?
12567         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
12568
12569         fid_path=$($LFS fid2path $MOUNT $fid)
12570         rc=$?
12571         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
12572
12573         [ "$path" == "$fid_path" ] ||
12574                 error "fid2path returned $fid_path, expected $path"
12575
12576         echo "pass with $path and $fid"
12577 }
12578
12579 test_226a () {
12580         rm -rf $DIR/$tdir
12581         mkdir -p $DIR/$tdir
12582
12583         mcreate_path2fid 0010666 0 0 fifo "FIFO"
12584         mcreate_path2fid 0020666 1 3 null "character special file (null)"
12585         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
12586         mcreate_path2fid 0040666 0 0 dir "directory"
12587         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
12588         mcreate_path2fid 0100666 0 0 file "regular file"
12589         mcreate_path2fid 0120666 0 0 link "symbolic link"
12590         mcreate_path2fid 0140666 0 0 sock "socket"
12591 }
12592 run_test 226a "call path2fid and fid2path on files of all type"
12593
12594 test_226b () {
12595         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12596         rm -rf $DIR/$tdir
12597         local MDTIDX=1
12598
12599         mkdir -p $DIR/$tdir
12600         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
12601                 error "create remote directory failed"
12602         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
12603         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
12604                                 "character special file (null)"
12605         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
12606                                 "character special file (no device)"
12607         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
12608         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
12609                                 "block special file (loop)"
12610         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
12611         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
12612         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
12613 }
12614 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
12615
12616 # LU-1299 Executing or running ldd on a truncated executable does not
12617 # cause an out-of-memory condition.
12618 test_227() {
12619         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12620         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
12621         dd if=$(which date) of=$MOUNT/date bs=1k count=1
12622         chmod +x $MOUNT/date
12623
12624         $MOUNT/date > /dev/null
12625         ldd $MOUNT/date > /dev/null
12626         rm -f $MOUNT/date
12627 }
12628 run_test 227 "running truncated executable does not cause OOM"
12629
12630 # LU-1512 try to reuse idle OI blocks
12631 test_228a() {
12632         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12633         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12634         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12635                 skip "non-ldiskfs backend" && return
12636
12637         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12638         local myDIR=$DIR/$tdir
12639
12640         mkdir -p $myDIR
12641         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12642         $LCTL set_param fail_loc=0x80001002
12643         createmany -o $myDIR/t- 10000
12644         $LCTL set_param fail_loc=0
12645         # The guard is current the largest FID holder
12646         touch $myDIR/guard
12647         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12648                     tr -d '[')
12649         local IDX=$(($SEQ % 64))
12650
12651         do_facet $SINGLEMDS sync
12652         # Make sure journal flushed.
12653         sleep 6
12654         local blk1=$(do_facet $SINGLEMDS \
12655                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12656                      grep Blockcount | awk '{print $4}')
12657
12658         # Remove old files, some OI blocks will become idle.
12659         unlinkmany $myDIR/t- 10000
12660         # Create new files, idle OI blocks should be reused.
12661         createmany -o $myDIR/t- 2000
12662         do_facet $SINGLEMDS sync
12663         # Make sure journal flushed.
12664         sleep 6
12665         local blk2=$(do_facet $SINGLEMDS \
12666                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12667                      grep Blockcount | awk '{print $4}')
12668
12669         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12670 }
12671 run_test 228a "try to reuse idle OI blocks"
12672
12673 test_228b() {
12674         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12675         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12676         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12677                 skip "non-ldiskfs backend" && return
12678
12679         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12680         local myDIR=$DIR/$tdir
12681
12682         mkdir -p $myDIR
12683         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12684         $LCTL set_param fail_loc=0x80001002
12685         createmany -o $myDIR/t- 10000
12686         $LCTL set_param fail_loc=0
12687         # The guard is current the largest FID holder
12688         touch $myDIR/guard
12689         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12690                     tr -d '[')
12691         local IDX=$(($SEQ % 64))
12692
12693         do_facet $SINGLEMDS sync
12694         # Make sure journal flushed.
12695         sleep 6
12696         local blk1=$(do_facet $SINGLEMDS \
12697                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12698                      grep Blockcount | awk '{print $4}')
12699
12700         # Remove old files, some OI blocks will become idle.
12701         unlinkmany $myDIR/t- 10000
12702
12703         # stop the MDT
12704         stop $SINGLEMDS || error "Fail to stop MDT."
12705         # remount the MDT
12706         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
12707
12708         df $MOUNT || error "Fail to df."
12709         # Create new files, idle OI blocks should be reused.
12710         createmany -o $myDIR/t- 2000
12711         do_facet $SINGLEMDS sync
12712         # Make sure journal flushed.
12713         sleep 6
12714         local blk2=$(do_facet $SINGLEMDS \
12715                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12716                      grep Blockcount | awk '{print $4}')
12717
12718         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12719 }
12720 run_test 228b "idle OI blocks can be reused after MDT restart"
12721
12722 #LU-1881
12723 test_228c() {
12724         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12725         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12726         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12727                 skip "non-ldiskfs backend" && return
12728
12729         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12730         local myDIR=$DIR/$tdir
12731
12732         mkdir -p $myDIR
12733         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12734         $LCTL set_param fail_loc=0x80001002
12735         # 20000 files can guarantee there are index nodes in the OI file
12736         createmany -o $myDIR/t- 20000
12737         $LCTL set_param fail_loc=0
12738         # The guard is current the largest FID holder
12739         touch $myDIR/guard
12740         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12741                     tr -d '[')
12742         local IDX=$(($SEQ % 64))
12743
12744         do_facet $SINGLEMDS sync
12745         # Make sure journal flushed.
12746         sleep 6
12747         local blk1=$(do_facet $SINGLEMDS \
12748                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12749                      grep Blockcount | awk '{print $4}')
12750
12751         # Remove old files, some OI blocks will become idle.
12752         unlinkmany $myDIR/t- 20000
12753         rm -f $myDIR/guard
12754         # The OI file should become empty now
12755
12756         # Create new files, idle OI blocks should be reused.
12757         createmany -o $myDIR/t- 2000
12758         do_facet $SINGLEMDS sync
12759         # Make sure journal flushed.
12760         sleep 6
12761         local blk2=$(do_facet $SINGLEMDS \
12762                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12763                      grep Blockcount | awk '{print $4}')
12764
12765         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12766 }
12767 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
12768
12769 test_229() { # LU-2482, LU-3448
12770         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
12771                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
12772                 return
12773         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12774         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
12775
12776         rm -f $DIR/$tfile
12777
12778         # Create a file with a released layout and stripe count 2.
12779         $MULTIOP $DIR/$tfile H2c ||
12780                 error "failed to create file with released layout"
12781
12782         $GETSTRIPE -v $DIR/$tfile
12783
12784         local pattern=$($GETSTRIPE -L $DIR/$tfile)
12785         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
12786
12787         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
12788         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
12789         stat $DIR/$tfile || error "failed to stat released file"
12790
12791         chown $RUNAS_ID $DIR/$tfile ||
12792                 error "chown $RUNAS_ID $DIR/$tfile failed"
12793
12794         chgrp $RUNAS_ID $DIR/$tfile ||
12795                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12796
12797         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12798         rm $DIR/$tfile || error "failed to remove released file"
12799 }
12800 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12801
12802 test_230a() {
12803         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12804         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12805         local MDTIDX=1
12806
12807         test_mkdir $DIR/$tdir
12808         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
12809         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12810         [ $mdt_idx -ne 0 ] &&
12811                 error "create local directory on wrong MDT $mdt_idx"
12812
12813         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12814                         error "create remote directory failed"
12815         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12816         [ $mdt_idx -ne $MDTIDX ] &&
12817                 error "create remote directory on wrong MDT $mdt_idx"
12818
12819         createmany -o $DIR/$tdir/test_230/t- 10 ||
12820                 error "create files on remote directory failed"
12821         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12822         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12823         rm -r $DIR/$tdir || error "unlink remote directory failed"
12824 }
12825 run_test 230a "Create remote directory and files under the remote directory"
12826
12827 test_230b() {
12828         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12829         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12830         local MDTIDX=1
12831         local mdt_index
12832         local i
12833         local file
12834         local pid
12835         local stripe_count
12836         local migrate_dir=$DIR/$tdir/migrate_dir
12837         local other_dir=$DIR/$tdir/other_dir
12838
12839         test_mkdir $DIR/$tdir
12840         test_mkdir -i0 -c1 $migrate_dir
12841         test_mkdir -i0 -c1 $other_dir
12842         for ((i=0; i<10; i++)); do
12843                 mkdir -p $migrate_dir/dir_${i}
12844                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12845                         error "create files under remote dir failed $i"
12846         done
12847
12848         cp /etc/passwd $migrate_dir/$tfile
12849         cp /etc/passwd $other_dir/$tfile
12850         chattr +SAD $migrate_dir
12851         chattr +SAD $migrate_dir/$tfile
12852
12853         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12854         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12855         local old_dir_mode=$(stat -c%f $migrate_dir)
12856         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
12857
12858         mkdir -p $migrate_dir/dir_default_stripe2
12859         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12860         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12861
12862         mkdir -p $other_dir
12863         ln $migrate_dir/$tfile $other_dir/luna
12864         ln $migrate_dir/$tfile $migrate_dir/sofia
12865         ln $other_dir/$tfile $migrate_dir/david
12866         ln -s $migrate_dir/$tfile $other_dir/zachary
12867         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12868         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12869
12870         $LFS migrate -m $MDTIDX $migrate_dir ||
12871                 error "fails on migrating remote dir to MDT1"
12872
12873         echo "migratate to MDT1, then checking.."
12874         for ((i = 0; i < 10; i++)); do
12875                 for file in $(find $migrate_dir/dir_${i}); do
12876                         mdt_index=$($LFS getstripe -M $file)
12877                         [ $mdt_index == $MDTIDX ] ||
12878                                 error "$file is not on MDT${MDTIDX}"
12879                 done
12880         done
12881
12882         # the multiple link file should still in MDT0
12883         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12884         [ $mdt_index == 0 ] ||
12885                 error "$file is not on MDT${MDTIDX}"
12886
12887         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12888         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12889                 error " expect $old_dir_flag get $new_dir_flag"
12890
12891         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12892         [ "$old_file_flag" = "$new_file_flag" ] ||
12893                 error " expect $old_file_flag get $new_file_flag"
12894
12895         local new_dir_mode=$(stat -c%f $migrate_dir)
12896         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12897                 error "expect mode $old_dir_mode get $new_dir_mode"
12898
12899         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12900         [ "$old_file_mode" = "$new_file_mode" ] ||
12901                 error "expect mode $old_file_mode get $new_file_mode"
12902
12903         diff /etc/passwd $migrate_dir/$tfile ||
12904                 error "$tfile different after migration"
12905
12906         diff /etc/passwd $other_dir/luna ||
12907                 error "luna different after migration"
12908
12909         diff /etc/passwd $migrate_dir/sofia ||
12910                 error "sofia different after migration"
12911
12912         diff /etc/passwd $migrate_dir/david ||
12913                 error "david different after migration"
12914
12915         diff /etc/passwd $other_dir/zachary ||
12916                 error "zachary different after migration"
12917
12918         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12919                 error "${tfile}_ln different after migration"
12920
12921         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12922                 error "${tfile}_ln_other different after migration"
12923
12924         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12925         [ $stripe_count = 2 ] ||
12926                 error "dir strpe_count $d != 2 after migration."
12927
12928         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12929         [ $stripe_count = 2 ] ||
12930                 error "file strpe_count $d != 2 after migration."
12931
12932         #migrate back to MDT0
12933         MDTIDX=0
12934
12935         $LFS migrate -m $MDTIDX $migrate_dir ||
12936                 error "fails on migrating remote dir to MDT0"
12937
12938         echo "migrate back to MDT0, checking.."
12939         for file in $(find $migrate_dir); do
12940                 mdt_index=$($LFS getstripe -M $file)
12941                 [ $mdt_index == $MDTIDX ] ||
12942                         error "$file is not on MDT${MDTIDX}"
12943         done
12944
12945         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12946         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12947                 error " expect $old_dir_flag get $new_dir_flag"
12948
12949         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12950         [ "$old_file_flag" = "$new_file_flag" ] ||
12951                 error " expect $old_file_flag get $new_file_flag"
12952
12953         local new_dir_mode=$(stat -c%f $migrate_dir)
12954         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12955                 error "expect mode $old_dir_mode get $new_dir_mode"
12956
12957         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12958         [ "$old_file_mode" = "$new_file_mode" ] ||
12959                 error "expect mode $old_file_mode get $new_file_mode"
12960
12961         diff /etc/passwd ${migrate_dir}/$tfile ||
12962                 error "$tfile different after migration"
12963
12964         diff /etc/passwd ${other_dir}/luna ||
12965                 error "luna different after migration"
12966
12967         diff /etc/passwd ${migrate_dir}/sofia ||
12968                 error "sofia different after migration"
12969
12970         diff /etc/passwd ${other_dir}/zachary ||
12971                 error "zachary different after migration"
12972
12973         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12974                 error "${tfile}_ln different after migration"
12975
12976         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12977                 error "${tfile}_ln_other different after migration"
12978
12979         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12980         [ $stripe_count = 2 ] ||
12981                 error "dir strpe_count $d != 2 after migration."
12982
12983         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12984         [ $stripe_count = 2 ] ||
12985                 error "file strpe_count $d != 2 after migration."
12986
12987         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12988 }
12989 run_test 230b "migrate directory"
12990
12991 test_230c() {
12992         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12993         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12994         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12995         local MDTIDX=1
12996         local mdt_index
12997         local file
12998         local migrate_dir=$DIR/$tdir/migrate_dir
12999
13000         #If migrating directory fails in the middle, all entries of
13001         #the directory is still accessiable.
13002         test_mkdir $DIR/$tdir
13003         test_mkdir -i0 -c1 $migrate_dir
13004         stat $migrate_dir
13005         createmany -o $migrate_dir/f 10 ||
13006                 error "create files under ${migrate_dir} failed"
13007
13008         #failed after migrating 5 entries
13009         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
13010         do_facet mds1 lctl set_param fail_loc=0x20001801
13011         do_facet mds1 lctl  set_param fail_val=5
13012         local t=$(ls $migrate_dir | wc -l)
13013         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
13014                 error "migrate should fail after 5 entries"
13015
13016         mkdir $migrate_dir/dir &&
13017                 error "mkdir succeeds under migrating directory"
13018         touch $migrate_dir/file &&
13019                 error "touch file succeeds under migrating directory"
13020
13021         local u=$(ls $migrate_dir | wc -l)
13022         [ "$u" == "$t" ] || error "$u != $t during migration"
13023
13024         for file in $(find $migrate_dir); do
13025                 stat $file || error "stat $file failed"
13026         done
13027
13028         do_facet mds1 lctl set_param fail_loc=0
13029         do_facet mds1 lctl set_param fail_val=0
13030
13031         $LFS migrate -m $MDTIDX $migrate_dir ||
13032                 error "migrate open files should failed with open files"
13033
13034         echo "Finish migration, then checking.."
13035         for file in $(find $migrate_dir); do
13036                 mdt_index=$($LFS getstripe -M $file)
13037                 [ $mdt_index == $MDTIDX ] ||
13038                         error "$file is not on MDT${MDTIDX}"
13039         done
13040
13041         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13042 }
13043 run_test 230c "check directory accessiblity if migration is failed"
13044
13045 test_230d() {
13046         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13047         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13048         local MDTIDX=1
13049         local mdt_index
13050         local migrate_dir=$DIR/$tdir/migrate_dir
13051         local i
13052         local j
13053
13054         test_mkdir $DIR/$tdir
13055         test_mkdir -i0 -c1 $migrate_dir
13056
13057         for ((i=0; i<100; i++)); do
13058                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
13059                 createmany -o $migrate_dir/dir_${i}/f 100 ||
13060                         error "create files under remote dir failed $i"
13061         done
13062
13063         $LFS migrate -m $MDTIDX $migrate_dir ||
13064                 error "migrate remote dir error"
13065
13066         echo "Finish migration, then checking.."
13067         for file in $(find $migrate_dir); do
13068                 mdt_index=$($LFS getstripe -M $file)
13069                 [ $mdt_index == $MDTIDX ] ||
13070                         error "$file is not on MDT${MDTIDX}"
13071         done
13072
13073         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13074 }
13075 run_test 230d "check migrate big directory"
13076
13077 test_230e() {
13078         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13079         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13080         local i
13081         local j
13082         local a_fid
13083         local b_fid
13084
13085         mkdir -p $DIR/$tdir
13086         mkdir $DIR/$tdir/migrate_dir
13087         mkdir $DIR/$tdir/other_dir
13088         touch $DIR/$tdir/migrate_dir/a
13089         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
13090         ls $DIR/$tdir/other_dir
13091
13092         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13093                 error "migrate dir fails"
13094
13095         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13096         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
13097
13098         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13099         [ $mdt_index == 0 ] || error "a is not on MDT0"
13100
13101         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
13102                 error "migrate dir fails"
13103
13104         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir)
13105         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
13106
13107         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13108         [ $mdt_index == 1 ] || error "a is not on MDT1"
13109
13110         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir/b)
13111         [ $mdt_index == 1 ] || error "b is not on MDT1"
13112
13113         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13114         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
13115
13116         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
13117
13118         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13119 }
13120 run_test 230e "migrate mulitple local link files"
13121
13122 test_230f() {
13123         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13124         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13125         local a_fid
13126         local ln_fid
13127
13128         mkdir -p $DIR/$tdir
13129         mkdir $DIR/$tdir/migrate_dir
13130         $LFS mkdir -i1 $DIR/$tdir/other_dir
13131         touch $DIR/$tdir/migrate_dir/a
13132         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
13133         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
13134         ls $DIR/$tdir/other_dir
13135
13136         # a should be migrated to MDT1, since no other links on MDT0
13137         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13138                 error "migrate dir fails"
13139         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13140         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
13141         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13142         [ $mdt_index == 1 ] || error "a is not on MDT1"
13143
13144         # a should stay on MDT1, because it is a mulitple link file
13145         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13146                 error "migrate dir fails"
13147         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13148         [ $mdt_index == 1 ] || error "a is not on MDT1"
13149
13150         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13151                 error "migrate dir fails"
13152
13153         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13154         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
13155         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
13156
13157         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
13158         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
13159
13160         # a should be migrated to MDT0, since no other links on MDT1
13161         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13162                 error "migrate dir fails"
13163         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13164         [ $mdt_index == 0 ] || error "a is not on MDT0"
13165
13166         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13167 }
13168 run_test 230f "migrate mulitple remote link files"
13169
13170 test_230g() {
13171         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13172         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13173
13174         mkdir -p $DIR/$tdir/migrate_dir
13175
13176         $LFS migrate -m 1000 $DIR/$tdir/migrate_dir &&
13177                 error "migrating dir to non-exist MDT succeeds"
13178         true
13179 }
13180 run_test 230g "migrate dir to non-exist MDT"
13181
13182 test_230h() {
13183         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13184         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13185         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
13186                 skip "Need MDS version at least 2.7.64" && return
13187         local mdt_index
13188
13189         mkdir -p $DIR/$tdir/migrate_dir
13190
13191         $LFS migrate -m1 $DIR &&
13192                 error "migrating mountpoint1 should fail"
13193
13194         $LFS migrate -m1 $DIR/$tdir/.. &&
13195                 error "migrating mountpoint2 should fail"
13196
13197         $LFS migrate -m1 $DIR/$tdir/migrate_dir/.. ||
13198                 error "migrating $tdir fail"
13199
13200         mdt_index=$($LFS getstripe -M $DIR/$tdir)
13201         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13202
13203         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13204         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13205
13206 }
13207 run_test 230h "migrate .. and root"
13208
13209 test_230i() {
13210         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13211         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13212
13213         mkdir -p $DIR/$tdir/migrate_dir
13214
13215         $LFS migrate -m 1 $DIR/$tdir/migrate_dir/ ||
13216                 error "migration fails with a tailing slash"
13217
13218         $LFS migrate -m 0 $DIR/$tdir/migrate_dir// ||
13219                 error "migration fails with two tailing slashes"
13220 }
13221 run_test 230i "lfs migrate -m tolerates trailing slashes"
13222
13223 test_231a()
13224 {
13225         # For simplicity this test assumes that max_pages_per_rpc
13226         # is the same across all OSCs
13227         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
13228         local bulk_size=$((max_pages * 4096))
13229
13230         mkdir -p $DIR/$tdir
13231
13232         # clear the OSC stats
13233         $LCTL set_param osc.*.stats=0 &>/dev/null
13234         stop_writeback
13235
13236         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
13237         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
13238                 oflag=direct &>/dev/null || error "dd failed"
13239
13240         sync; sleep 1; sync # just to be safe
13241         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
13242         if [ x$nrpcs != "x1" ]; then
13243                 $LCTL get_param osc.*.stats
13244                 error "found $nrpcs ost_write RPCs, not 1 as expected"
13245         fi
13246
13247         start_writeback
13248         # Drop the OSC cache, otherwise we will read from it
13249         cancel_lru_locks osc
13250
13251         # clear the OSC stats
13252         $LCTL set_param osc.*.stats=0 &>/dev/null
13253
13254         # Client reads $bulk_size.
13255         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
13256                 iflag=direct &>/dev/null || error "dd failed"
13257
13258         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
13259         if [ x$nrpcs != "x1" ]; then
13260                 $LCTL get_param osc.*.stats
13261                 error "found $nrpcs ost_read RPCs, not 1 as expected"
13262         fi
13263 }
13264 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
13265
13266 test_231b() {
13267         mkdir -p $DIR/$tdir
13268         local i
13269         for i in {0..1023}; do
13270                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
13271                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
13272                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
13273         done
13274         sync
13275 }
13276 run_test 231b "must not assert on fully utilized OST request buffer"
13277
13278 test_232() {
13279         mkdir -p $DIR/$tdir
13280         #define OBD_FAIL_LDLM_OST_LVB            0x31c
13281         $LCTL set_param fail_loc=0x31c
13282
13283         # ignore dd failure
13284         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
13285
13286         $LCTL set_param fail_loc=0
13287         umount_client $MOUNT || error "umount failed"
13288         mount_client $MOUNT || error "mount failed"
13289 }
13290 run_test 232 "failed lock should not block umount"
13291
13292 test_233a() {
13293         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
13294         { skip "Need MDS version at least 2.3.64"; return; }
13295         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
13296
13297         local fid=$($LFS path2fid $MOUNT)
13298         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13299                 error "cannot access $MOUNT using its FID '$fid'"
13300 }
13301 run_test 233a "checking that OBF of the FS root succeeds"
13302
13303 test_233b() {
13304         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
13305         { skip "Need MDS version at least 2.5.90"; return; }
13306         [ -n "$FILESET" ] && skip "SKIP due to FILESET set" && return
13307
13308         local fid=$($LFS path2fid $MOUNT/.lustre)
13309         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13310                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
13311
13312         fid=$($LFS path2fid $MOUNT/.lustre/fid)
13313         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13314                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
13315 }
13316 run_test 233b "checking that OBF of the FS .lustre succeeds"
13317
13318 test_234() {
13319         local p="$TMP/sanityN-$TESTNAME.parameters"
13320         save_lustre_params client "llite.*.xattr_cache" > $p
13321         lctl set_param llite.*.xattr_cache 1 ||
13322                 { skip "xattr cache is not supported"; return 0; }
13323
13324         mkdir -p $DIR/$tdir || error "mkdir failed"
13325         touch $DIR/$tdir/$tfile || error "touch failed"
13326         # OBD_FAIL_LLITE_XATTR_ENOMEM
13327         $LCTL set_param fail_loc=0x1405
13328         # output of the form: attr 2 4 44 3 fc13 x86_64
13329         V=($(IFS=".-" rpm -q attr))
13330         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
13331               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
13332                 # attr pre-2.4.44-7 had a bug with rc
13333                 # LU-3703 - SLES 11 and FC13 clients have older attr
13334                 getfattr -n user.attr $DIR/$tdir/$tfile &&
13335                         error "getfattr should have failed with ENOMEM"
13336         else
13337                 skip "LU-3703: attr version $(getfattr --version) too old"
13338         fi
13339         $LCTL set_param fail_loc=0x0
13340         rm -rf $DIR/$tdir
13341
13342         restore_lustre_params < $p
13343         rm -f $p
13344 }
13345 run_test 234 "xattr cache should not crash on ENOMEM"
13346
13347 test_235() {
13348         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
13349                 skip "Need MDS version at least 2.4.52" && return
13350         flock_deadlock $DIR/$tfile
13351         local RC=$?
13352         case $RC in
13353                 0)
13354                 ;;
13355                 124) error "process hangs on a deadlock"
13356                 ;;
13357                 *) error "error executing flock_deadlock $DIR/$tfile"
13358                 ;;
13359         esac
13360 }
13361 run_test 235 "LU-1715: flock deadlock detection does not work properly"
13362
13363 #LU-2935
13364 test_236() {
13365         check_swap_layouts_support && return 0
13366         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
13367
13368         local ref1=/etc/passwd
13369         local ref2=/etc/group
13370         local file1=$DIR/$tdir/f1
13371         local file2=$DIR/$tdir/f2
13372
13373         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
13374         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
13375         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
13376         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
13377         local fd=$(free_fd)
13378         local cmd="exec $fd<>$file2"
13379         eval $cmd
13380         rm $file2
13381         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
13382                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
13383         cmd="exec $fd>&-"
13384         eval $cmd
13385         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
13386
13387         #cleanup
13388         rm -rf $DIR/$tdir
13389 }
13390 run_test 236 "Layout swap on open unlinked file"
13391
13392 # test to verify file handle related system calls
13393 # (name_to_handle_at/open_by_handle_at)
13394 # The new system calls are supported in glibc >= 2.14.
13395
13396 test_237() {
13397         echo "Test file_handle syscalls" > $DIR/$tfile ||
13398                 error "write failed"
13399         check_fhandle_syscalls $DIR/$tfile ||
13400                 error "check_fhandle_syscalls failed"
13401 }
13402 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
13403
13404 # LU-4659 linkea consistency
13405 test_238() {
13406         local server_version=$(lustre_version_code $SINGLEMDS)
13407
13408         [[ $server_version -gt $(version_code 2.5.57) ]] ||
13409                 [[ $server_version -gt $(version_code 2.5.1) &&
13410                    $server_version -lt $(version_code 2.5.50) ]] ||
13411                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
13412
13413         touch $DIR/$tfile
13414         ln $DIR/$tfile $DIR/$tfile.lnk
13415         touch $DIR/$tfile.new
13416         mv $DIR/$tfile.new $DIR/$tfile
13417         local fid1=$($LFS path2fid $DIR/$tfile)
13418         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
13419         local path1=$($LFS fid2path $FSNAME "$fid1")
13420         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
13421         local path2=$($LFS fid2path $FSNAME "$fid2")
13422         [ $tfile.lnk == $path2 ] ||
13423                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
13424         rm -f $DIR/$tfile*
13425 }
13426 run_test 238 "Verify linkea consistency"
13427
13428 test_239() {
13429         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
13430                 skip "Need MDS version at least 2.5.60" && return
13431         local list=$(comma_list $(mdts_nodes))
13432
13433         mkdir -p $DIR/$tdir
13434         createmany -o $DIR/$tdir/f- 5000
13435         unlinkmany $DIR/$tdir/f- 5000
13436         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
13437         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
13438                         osc.*MDT*.sync_in_flight" | calc_sum)
13439         [ "$changes" -eq 0 ] || error "$changes not synced"
13440 }
13441 run_test 239 "osp_sync test"
13442
13443 test_239a() { #LU-5297
13444         touch $DIR/$tfile
13445         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
13446         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
13447         chgrp $RUNAS_GID $DIR/$tfile
13448         wait_delete_completed
13449 }
13450 run_test 239a "process invalid osp sync record correctly"
13451
13452 test_239b() { #LU-5297
13453         touch $DIR/$tfile1
13454         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
13455         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
13456         chgrp $RUNAS_GID $DIR/$tfile1
13457         wait_delete_completed
13458         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
13459         touch $DIR/$tfile2
13460         chgrp $RUNAS_GID $DIR/$tfile2
13461         wait_delete_completed
13462 }
13463 run_test 239b "process osp sync record with ENOMEM error correctly"
13464
13465 test_240() {
13466         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13467
13468         mkdir -p $DIR/$tdir
13469
13470         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
13471                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
13472         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
13473                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
13474
13475         umount_client $MOUNT || error "umount failed"
13476         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
13477         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
13478         mount_client $MOUNT || error "failed to mount client"
13479
13480         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
13481         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
13482 }
13483 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
13484
13485 test_241_bio() {
13486         for LOOP in $(seq $1); do
13487                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
13488                 cancel_lru_locks osc || true
13489         done
13490 }
13491
13492 test_241_dio() {
13493         for LOOP in $(seq $1); do
13494                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
13495                                                 iflag=direct 2>/dev/null
13496         done
13497 }
13498
13499 test_241() {
13500         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
13501         ls -la $DIR/$tfile
13502         cancel_lru_locks osc
13503         test_241_bio 1000 &
13504         PID=$!
13505         test_241_dio 1000
13506         wait $PID
13507 }
13508 run_test 241 "bio vs dio"
13509
13510 test_241b() {
13511         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
13512         ls -la $DIR/$tfile
13513         test_241_dio 1000 &
13514         PID=$!
13515         test_241_dio 1000
13516         wait $PID
13517 }
13518 run_test 241b "dio vs dio"
13519
13520 test_242() {
13521         mkdir -p $DIR/$tdir
13522         touch $DIR/$tdir/$tfile
13523
13524         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
13525         do_facet mds1 lctl set_param fail_loc=0x105
13526         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
13527
13528         do_facet mds1 lctl set_param fail_loc=0
13529         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
13530 }
13531 run_test 242 "mdt_readpage failure should not cause directory unreadable"
13532
13533 test_243()
13534 {
13535         test_mkdir -p $DIR/$tdir
13536         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
13537 }
13538 run_test 243 "various group lock tests"
13539
13540 test_244()
13541 {
13542         test_mkdir -p $DIR/$tdir
13543         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
13544         sendfile_grouplock $DIR/$tdir/$tfile || \
13545                 error "sendfile+grouplock failed"
13546         rm -rf $DIR/$tdir
13547 }
13548 run_test 244 "sendfile with group lock tests"
13549
13550 test_245() {
13551         local flagname="multi_mod_rpcs"
13552         local connect_data_name="max_mod_rpcs"
13553         local out
13554
13555         # check if multiple modify RPCs flag is set
13556         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
13557                 grep "connect_flags:")
13558         echo "$out"
13559
13560         echo "$out" | grep -qw $flagname
13561         if [ $? -ne 0 ]; then
13562                 echo "connect flag $flagname is not set"
13563                 return
13564         fi
13565
13566         # check if multiple modify RPCs data is set
13567         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
13568         echo "$out"
13569
13570         echo "$out" | grep -qw $connect_data_name ||
13571                 error "import should have connect data $connect_data_name"
13572 }
13573 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
13574
13575 test_246() { # LU-7371
13576         [ $(lustre_version_code ost1) -lt $(version_code 2.7.62) ] &&
13577                 skip "Need OST version >= 2.7.62" && return 0
13578         do_facet ost1 $LCTL set_param fail_val=4095
13579 #define OBD_FAIL_OST_READ_SIZE          0x234
13580         do_facet ost1 $LCTL set_param fail_loc=0x234
13581         $LFS setstripe $DIR/$tfile -i 0 -c 1
13582         dd if=/dev/zero of=$DIR/$tfile bs=4095 count=1 > /dev/null 2>&1
13583         cancel_lru_locks $FSNAME-OST0000
13584         dd if=$DIR/$tfile of=/dev/null bs=1048576 || error "Read failed"
13585 }
13586 run_test 246 "Read file of size 4095 should return right length"
13587
13588 test_247a() {
13589         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
13590                 grep -q subtree ||
13591                 { skip "Fileset feature is not supported"; return; }
13592
13593         local submount=${MOUNT}_$tdir
13594
13595         mkdir $MOUNT/$tdir
13596         mkdir -p $submount || error "mkdir $submount failed"
13597         FILESET="$FILESET/$tdir" mount_client $submount ||
13598                 error "mount $submount failed"
13599         echo foo > $submount/$tfile || error "write $submount/$tfile failed"
13600         [ $(cat $MOUNT/$tdir/$tfile) = "foo" ] ||
13601                 error "read $MOUNT/$tdir/$tfile failed"
13602         umount_client $submount || error "umount $submount failed"
13603         rmdir $submount
13604 }
13605 run_test 247a "mount subdir as fileset"
13606
13607 test_247b() {
13608         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
13609                 { skip "Fileset feature is not supported"; return; }
13610
13611         local submount=${MOUNT}_$tdir
13612
13613         rm -rf $MOUNT/$tdir
13614         mkdir -p $submount || error "mkdir $submount failed"
13615         SKIP_FILESET=1
13616         FILESET="$FILESET/$tdir" mount_client $submount &&
13617                 error "mount $submount should fail"
13618         rmdir $submount
13619 }
13620 run_test 247b "mount subdir that dose not exist"
13621
13622 test_247c() {
13623         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
13624                 { skip "Fileset feature is not supported"; return; }
13625
13626         local submount=${MOUNT}_$tdir
13627
13628         mkdir -p $MOUNT/$tdir/dir1
13629         mkdir -p $submount || error "mkdir $submount failed"
13630         FILESET="$FILESET/$tdir" mount_client $submount ||
13631                 error "mount $submount failed"
13632         local fid=$($LFS path2fid $MOUNT/)
13633         $LFS fid2path $submount $fid && error "fid2path should fail"
13634         umount_client $submount || error "umount $submount failed"
13635         rmdir $submount
13636 }
13637 run_test 247c "running fid2path outside root"
13638
13639 test_247d() {
13640         lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
13641                 { skip "Fileset feature is not supported"; return; }
13642
13643         local submount=${MOUNT}_$tdir
13644
13645         mkdir -p $MOUNT/$tdir/dir1
13646         mkdir -p $submount || error "mkdir $submount failed"
13647         FILESET="$FILESET/$tdir" mount_client $submount ||
13648                 error "mount $submount failed"
13649         local fid=$($LFS path2fid $submount/dir1)
13650         $LFS fid2path $submount $fid || error "fid2path should succeed"
13651         umount_client $submount || error "umount $submount failed"
13652         rmdir $submount
13653 }
13654 run_test 247d "running fid2path inside root"
13655
13656 # LU-8037
13657 test_247e() {
13658         lctl get_param -n mdc.$FSNAME-MDT0000*.import |
13659                 grep -q subtree ||
13660                 { skip "Fileset feature is not supported"; return; }
13661
13662         local submount=${MOUNT}_$tdir
13663
13664         mkdir $MOUNT/$tdir
13665         mkdir -p $submount || error "mkdir $submount failed"
13666         FILESET="$FILESET/.." mount_client $submount &&
13667                 error "mount $submount should fail"
13668         rmdir $submount
13669 }
13670 run_test 247e "mount .. as fileset"
13671
13672 test_250() {
13673         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
13674          && skip "no 16TB file size limit on ZFS" && return
13675
13676         $SETSTRIPE -c 1 $DIR/$tfile
13677         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
13678         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
13679         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
13680         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
13681                 conv=notrunc,fsync && error "append succeeded"
13682         return 0
13683 }
13684 run_test 250 "Write above 16T limit"
13685
13686 test_251() {
13687         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
13688
13689         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
13690         #Skip once - writing the first stripe will succeed
13691         $LCTL set_param fail_loc=0xa0001407 fail_val=1
13692         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
13693                 error "short write happened"
13694
13695         $LCTL set_param fail_loc=0xa0001407 fail_val=1
13696         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
13697                 error "short read happened"
13698
13699         rm -f $DIR/$tfile
13700 }
13701 run_test 251 "Handling short read and write correctly"
13702
13703 test_252() {
13704         local tgt
13705         local dev
13706         local out
13707         local uuid
13708         local num
13709         local gen
13710
13711         if [ "$(facet_fstype ost1)" != "ldiskfs" -o \
13712              "$(facet_fstype mds1)" != "ldiskfs" ]; then
13713                 skip "can only run lr_reader on ldiskfs target"
13714                 return
13715         fi
13716
13717         # check lr_reader on OST0000
13718         tgt=ost1
13719         dev=$(facet_device $tgt)
13720         out=$(do_facet $tgt $LR_READER $dev)
13721         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
13722         echo "$out"
13723         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
13724         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
13725                 error "Invalid uuid returned by $LR_READER on target $tgt"
13726         echo -e "uuid returned by $LR_READER is '$uuid'\n"
13727
13728         # check lr_reader -c on MDT0000
13729         tgt=mds1
13730         dev=$(facet_device $tgt)
13731         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
13732                 echo "$LR_READER does not support additional options"
13733                 return 0
13734         fi
13735         out=$(do_facet $tgt $LR_READER -c $dev)
13736         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
13737         echo "$out"
13738         num=$(echo "$out" | grep -c "mdtlov")
13739         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
13740                 error "Invalid number of mdtlov clients returned by $LR_READER"
13741         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
13742
13743         # check lr_reader -cr on MDT0000
13744         out=$(do_facet $tgt $LR_READER -cr $dev)
13745         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
13746         echo "$out"
13747         echo "$out" | grep -q "^reply_data:$" ||
13748                 error "$LR_READER should have returned 'reply_data' section"
13749         num=$(echo "$out" | grep -c "client_generation")
13750         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
13751 }
13752 run_test 252 "check lr_reader tool"
13753
13754 test_254() {
13755         local cl_user
13756
13757         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13758         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13759         do_facet mds1 $LCTL get_param -n mdd.$MDT0.changelog_size ||
13760                 { skip "MDS does not support changelog_size" && return; }
13761
13762         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
13763         echo "Registered as changelog user $cl_user"
13764
13765         $LFS changelog_clear $MDT0 $cl_user 0
13766
13767         local size1=$(do_facet mds1 \
13768                       $LCTL get_param -n mdd.$MDT0.changelog_size)
13769         echo "Changelog size $size1"
13770
13771         rm -rf $DIR/$tdir
13772         $LFS mkdir -i 0 $DIR/$tdir
13773         # change something
13774         mkdir -p $DIR/$tdir/pics/2008/zachy
13775         touch $DIR/$tdir/pics/2008/zachy/timestamp
13776         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
13777         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
13778         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
13779         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
13780         rm $DIR/$tdir/pics/desktop.jpg
13781
13782         local size2=$(do_facet mds1 \
13783                       $LCTL get_param -n mdd.$MDT0.changelog_size)
13784         echo "Changelog size after work $size2"
13785
13786         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
13787
13788         if (( size2 <= size1 )); then
13789                 error "Changelog size after work should be greater than original"
13790         fi
13791         return 0
13792 }
13793 run_test 254 "Check changelog size"
13794
13795 test_256() {
13796         local cl_user
13797         local cat_sl
13798         local mdt_dev
13799
13800         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13801         remote_mds_nodsh && skip "remote MDS with nodsh" && return
13802         [ "$(facet_fstype mds1)" != "ldiskfs" ] &&
13803                 skip "non-ldiskfs backend" && return
13804
13805         mdt_dev=$(mdsdevname 1)
13806         echo $mdt_dev
13807         cl_user=$(do_facet mds1 \
13808         "$LCTL get_param -n mdd.$MDT0.changelog_users | grep cl")
13809         if [[ -n $cl_user ]]; then
13810                 skip "active changelog user"
13811                 return
13812         fi
13813
13814         cl_user=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
13815         echo "Registered as changelog user $cl_user"
13816
13817         rm -rf $DIR/$tdir
13818         mkdir -p $DIR/$tdir
13819
13820         $LFS changelog_clear $MDT0 $cl_user 0
13821
13822         # change something
13823         touch $DIR/$tdir/{1..10}
13824
13825         # stop the MDT
13826         stop mds1 || error "Fail to stop MDT."
13827
13828         # remount the MDT
13829         start mds1 $mdt_dev $MDS_MOUNT_OPTS || error "Fail to start MDT."
13830
13831         #after mount new plainllog is used
13832         touch $DIR/$tdir/{11..19}
13833         cat_sl=$(do_facet mds1 \
13834         "$DEBUGFS -R \\\"dump changelog_catalog cat.dmp\\\" $mdt_dev; \
13835          llog_reader cat.dmp | grep \\\"type=1064553b\\\" | wc -l")
13836
13837         if (( cat_sl != 2 )); then
13838                 do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
13839                 error "Changelog catalog has wrong number of slots $cat_sl"
13840         fi
13841
13842         $LFS changelog_clear $MDT0 $cl_user 0
13843
13844         cat_sl=$(do_facet mds1 \
13845         "$DEBUGFS -R \\\"dump changelog_catalog cat.dmp\\\" $mdt_dev; \
13846          llog_reader cat.dmp | grep \\\"type=1064553b\\\" | wc -l")
13847
13848         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $cl_user
13849
13850         if (( cat_sl == 2 )); then
13851                 error "Empty plain llog was not deleted from changelog catalog"
13852         fi
13853         if (( cat_sl != 1 )); then
13854                 error "Active plain llog shouldn\`t be deleted from catalog"
13855         fi
13856 }
13857 run_test 256 "Check llog delete for empty and not full state"
13858
13859 cleanup_test_300() {
13860         trap 0
13861         umask $SAVE_UMASK
13862 }
13863 test_striped_dir() {
13864         local mdt_index=$1
13865         local stripe_count
13866         local stripe_index
13867
13868         mkdir -p $DIR/$tdir
13869
13870         SAVE_UMASK=$(umask)
13871         trap cleanup_test_300 RETURN EXIT
13872
13873         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
13874                                                 $DIR/$tdir/striped_dir ||
13875                 error "set striped dir error"
13876
13877         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
13878         [ "$mode" = "755" ] || error "expect 755 got $mode"
13879
13880         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
13881                 error "getdirstripe failed"
13882         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
13883         if [ "$stripe_count" != "2" ]; then
13884                 error "stripe_count is $stripe_count, expect 2"
13885         fi
13886
13887         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
13888         if [ "$stripe_index" != "$mdt_index" ]; then
13889                 error "stripe_index is $stripe_index, expect $mdt_index"
13890         fi
13891
13892         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13893                 error "nlink error after create striped dir"
13894
13895         mkdir $DIR/$tdir/striped_dir/a
13896         mkdir $DIR/$tdir/striped_dir/b
13897
13898         stat $DIR/$tdir/striped_dir/a ||
13899                 error "create dir under striped dir failed"
13900         stat $DIR/$tdir/striped_dir/b ||
13901                 error "create dir under striped dir failed"
13902
13903         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
13904                 error "nlink error after mkdir"
13905
13906         rmdir $DIR/$tdir/striped_dir/a
13907         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
13908                 error "nlink error after rmdir"
13909
13910         rmdir $DIR/$tdir/striped_dir/b
13911         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13912                 error "nlink error after rmdir"
13913
13914         chattr +i $DIR/$tdir/striped_dir
13915         createmany -o $DIR/$tdir/striped_dir/f 10 &&
13916                 error "immutable flags not working under striped dir!"
13917         chattr -i $DIR/$tdir/striped_dir
13918
13919         rmdir $DIR/$tdir/striped_dir ||
13920                 error "rmdir striped dir error"
13921
13922         cleanup_test_300
13923
13924         true
13925 }
13926
13927 test_300a() {
13928         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
13929                 skip "skipped for lustre < 2.7.0" && return
13930         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13931         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13932
13933         test_striped_dir 0 || error "failed on striped dir on MDT0"
13934         test_striped_dir 1 || error "failed on striped dir on MDT0"
13935 }
13936 run_test 300a "basic striped dir sanity test"
13937
13938 test_300b() {
13939         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
13940                 skip "skipped for lustre < 2.7.0" && return
13941         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13942         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13943         local i
13944         local mtime1
13945         local mtime2
13946         local mtime3
13947
13948         test_mkdir $DIR/$tdir || error "mkdir fail"
13949         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13950                 error "set striped dir error"
13951         for ((i=0; i<10; i++)); do
13952                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
13953                 sleep 1
13954                 touch $DIR/$tdir/striped_dir/file_$i ||
13955                                         error "touch error $i"
13956                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
13957                 [ $mtime1 -eq $mtime2 ] &&
13958                         error "mtime not change after create"
13959                 sleep 1
13960                 rm -f $DIR/$tdir/striped_dir/file_$i ||
13961                                         error "unlink error $i"
13962                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
13963                 [ $mtime2 -eq $mtime3 ] &&
13964                         error "mtime did not change after unlink"
13965         done
13966         true
13967 }
13968 run_test 300b "check ctime/mtime for striped dir"
13969
13970 test_300c() {
13971         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
13972                 skip "skipped for lustre < 2.7.0" && return
13973         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13974         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13975         local file_count
13976
13977         mkdir -p $DIR/$tdir
13978         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
13979                 error "set striped dir error"
13980
13981         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
13982                 error "chown striped dir failed"
13983
13984         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
13985                 error "create 5k files failed"
13986
13987         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
13988
13989         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
13990
13991         rm -rf $DIR/$tdir
13992 }
13993 run_test 300c "chown && check ls under striped directory"
13994
13995 test_300d() {
13996         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.0) ] &&
13997                 skip "skipped for lustre < 2.7.0" && return
13998         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13999         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14000         local stripe_count
14001         local file
14002
14003         mkdir -p $DIR/$tdir
14004         $SETSTRIPE -c 2 $DIR/$tdir
14005
14006         #local striped directory
14007         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
14008                 error "set striped dir error"
14009         createmany -o $DIR/$tdir/striped_dir/f 10 ||
14010                 error "create 10 files failed"
14011
14012         #remote striped directory
14013         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
14014                 error "set striped dir error"
14015         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
14016                 error "create 10 files failed"
14017
14018         for file in $(find $DIR/$tdir); do
14019                 stripe_count=$($GETSTRIPE -c $file)
14020                 [ $stripe_count -eq 2 ] ||
14021                         error "wrong stripe $stripe_count for $file"
14022         done
14023
14024         rm -rf $DIR/$tdir
14025 }
14026 run_test 300d "check default stripe under striped directory"
14027
14028 test_300e() {
14029         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14030                 skip "Need MDS version at least 2.7.55" && return
14031         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14032         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14033         local stripe_count
14034         local file
14035
14036         mkdir -p $DIR/$tdir
14037
14038         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
14039                 error "set striped dir error"
14040
14041         touch $DIR/$tdir/striped_dir/a
14042         touch $DIR/$tdir/striped_dir/b
14043         touch $DIR/$tdir/striped_dir/c
14044
14045         mkdir $DIR/$tdir/striped_dir/dir_a
14046         mkdir $DIR/$tdir/striped_dir/dir_b
14047         mkdir $DIR/$tdir/striped_dir/dir_c
14048
14049         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
14050                 error "set striped dir under striped dir error"
14051
14052         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
14053                 error "set striped dir under striped dir error"
14054
14055         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
14056                 error "set striped dir under striped dir error"
14057
14058         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
14059                 error "rename dir under striped dir fails"
14060
14061         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
14062                 error "rename dir under different stripes fails"
14063
14064         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
14065                 error "rename file under striped dir should succeed"
14066
14067         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
14068                 error "rename dir under striped dir should succeed"
14069
14070         rm -rf $DIR/$tdir
14071 }
14072 run_test 300e "check rename under striped directory"
14073
14074 test_300f() {
14075         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14076                 skip "Need MDS version at least 2.7.55" && return
14077         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14078         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14079         local stripe_count
14080         local file
14081
14082         rm -rf $DIR/$tdir
14083         mkdir -p $DIR/$tdir
14084
14085         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
14086                 error "set striped dir error"
14087
14088         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
14089                 error "set striped dir error"
14090
14091         touch $DIR/$tdir/striped_dir/a
14092         mkdir $DIR/$tdir/striped_dir/dir_a
14093         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
14094                 error "create striped dir under striped dir fails"
14095
14096         touch $DIR/$tdir/striped_dir1/b
14097         mkdir $DIR/$tdir/striped_dir1/dir_b
14098         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
14099                 error "create striped dir under striped dir fails"
14100
14101         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
14102                 error "rename dir under different striped dir should fail"
14103
14104         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
14105                 error "rename striped dir under diff striped dir should fail"
14106
14107         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
14108                 error "rename file under diff striped dirs fails"
14109
14110         rm -rf $DIR/$tdir
14111 }
14112 run_test 300f "check rename cross striped directory"
14113
14114 test_300_check_default_striped_dir()
14115 {
14116         local dirname=$1
14117         local default_count=$2
14118         local default_index=$3
14119         local stripe_count
14120         local stripe_index
14121         local dir_stripe_index
14122         local dir
14123
14124         echo "checking $dirname $default_count $default_index"
14125         $LFS setdirstripe -D -c $default_count -i $default_index \
14126                                 -t all_char $DIR/$tdir/$dirname ||
14127                 error "set default stripe on striped dir error"
14128         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
14129         [ $stripe_count -eq $default_count ] ||
14130                 error "expect $default_count get $stripe_count for $dirname"
14131
14132         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
14133         [ $stripe_index -eq $default_index ] ||
14134                 error "expect $default_index get $stripe_index for $dirname"
14135
14136         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
14137                                                 error "create dirs failed"
14138
14139         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
14140         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
14141         for dir in $(find $DIR/$tdir/$dirname/*); do
14142                 stripe_count=$($LFS getdirstripe -c $dir)
14143                 [ $stripe_count -eq $default_count ] ||
14144                 [ $stripe_count -eq 0 -o $default_count -eq 1 ] ||
14145                 error "stripe count $default_count != $stripe_count for $dir"
14146
14147                 stripe_index=$($LFS getdirstripe -i $dir)
14148                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
14149                         error "$stripe_index != $default_index for $dir"
14150
14151                 #check default stripe
14152                 stripe_count=$($LFS getdirstripe -D -c $dir)
14153                 [ $stripe_count -eq $default_count ] ||
14154                 error "default count $default_count != $stripe_count for $dir"
14155
14156                 stripe_index=$($LFS getdirstripe -D -i $dir)
14157                 [ $stripe_index -eq $default_index ] ||
14158                 error "default index $default_index != $stripe_index for $dir"
14159         done
14160         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
14161 }
14162
14163 test_300g() {
14164         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14165                 skip "Need MDS version at least 2.7.55" && return
14166         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14167         local dir
14168         local stripe_count
14169         local stripe_index
14170
14171         mkdir $DIR/$tdir
14172         mkdir $DIR/$tdir/normal_dir
14173
14174         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
14175         test_300_check_default_striped_dir normal_dir 1 0
14176         test_300_check_default_striped_dir normal_dir 2 1
14177         test_300_check_default_striped_dir normal_dir 2 -1
14178
14179         #delete default stripe information
14180         echo "delete default stripeEA"
14181         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
14182                 error "set default stripe on striped dir error"
14183
14184         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
14185         for dir in $(find $DIR/$tdir/normal_dir/*); do
14186                 stripe_count=$($LFS getdirstripe -c $dir)
14187                 [ $stripe_count -eq 0 ] ||
14188                         error "expect 1 get $stripe_count for $dir"
14189                 stripe_index=$($LFS getdirstripe -i $dir)
14190                 [ $stripe_index -eq 0 ] ||
14191                         error "expect 0 get $stripe_index for $dir"
14192         done
14193 }
14194 run_test 300g "check default striped directory for normal directory"
14195
14196 test_300h() {
14197         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14198                 skip "Need MDS version at least 2.7.55" && return
14199         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14200         local dir
14201         local stripe_count
14202
14203         mkdir $DIR/$tdir
14204         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
14205                                         $DIR/$tdir/striped_dir ||
14206                 error "set striped dir error"
14207
14208         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
14209         test_300_check_default_striped_dir striped_dir 1 0
14210         test_300_check_default_striped_dir striped_dir 2 1
14211         test_300_check_default_striped_dir striped_dir 2 -1
14212
14213         #delete default stripe information
14214         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
14215                 error "set default stripe on striped dir error"
14216
14217         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
14218         for dir in $(find $DIR/$tdir/striped_dir/*); do
14219                 stripe_count=$($LFS getdirstripe -c $dir)
14220                 [ $stripe_count -eq 0 ] ||
14221                         error "expect 1 get $stripe_count for $dir"
14222         done
14223 }
14224 run_test 300h "check default striped directory for striped directory"
14225
14226 test_300i() {
14227         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14228                 skip "Need MDS version at least 2.7.55" && return
14229         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14230         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14231         local stripe_count
14232         local file
14233
14234         mkdir $DIR/$tdir
14235
14236         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
14237                 error "set striped dir error"
14238
14239         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
14240                 error "create files under striped dir failed"
14241
14242         # unfortunately, we need to umount to clear dir layout cache for now
14243         # once we fully implement dir layout, we can drop this
14244         umount_client $MOUNT || error "umount failed"
14245         mount_client $MOUNT || error "mount failed"
14246
14247         #set the stripe to be unknown hash type
14248         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
14249         $LCTL set_param fail_loc=0x1901
14250         for ((i = 0; i < 10; i++)); do
14251                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
14252                         error "stat f-$i failed"
14253                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
14254         done
14255
14256         touch $DIR/$tdir/striped_dir/f0 &&
14257                 error "create under striped dir with unknown hash should fail"
14258
14259         $LCTL set_param fail_loc=0
14260
14261         umount_client $MOUNT || error "umount failed"
14262         mount_client $MOUNT || error "mount failed"
14263
14264         return 0
14265 }
14266 run_test 300i "client handle unknown hash type striped directory"
14267
14268 test_300j() {
14269         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14270         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14271                 skip "Need MDS version at least 2.7.55" && return
14272         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14273         local stripe_count
14274         local file
14275
14276         mkdir $DIR/$tdir
14277
14278         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
14279         $LCTL set_param fail_loc=0x1702
14280         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
14281                 error "set striped dir error"
14282
14283         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
14284                 error "create files under striped dir failed"
14285
14286         $LCTL set_param fail_loc=0
14287
14288         rm -rf $DIR/$tdir || error "unlink striped dir fails"
14289
14290         return 0
14291 }
14292 run_test 300j "test large update record"
14293
14294 test_300k() {
14295         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14296                 skip "Need MDS version at least 2.7.55" && return
14297         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14298         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14299         local stripe_count
14300         local file
14301
14302         mkdir $DIR/$tdir
14303
14304         #define OBD_FAIL_LARGE_STRIPE   0x1703
14305         $LCTL set_param fail_loc=0x1703
14306         $LFS setdirstripe -i 0 -c512 $DIR/$tdir/striped_dir ||
14307                 error "set striped dir error"
14308         $LCTL set_param fail_loc=0
14309
14310         $LFS getdirstripe $DIR/$tdir/striped_dir ||
14311                 error "getstripeddir fails"
14312         rm -rf $DIR/$tdir/striped_dir ||
14313                 error "unlink striped dir fails"
14314
14315         return 0
14316 }
14317 run_test 300k "test large striped directory"
14318
14319 test_300l() {
14320         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14321                 skip "Need MDS version at least 2.7.55" && return
14322         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14323         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14324         local stripe_index
14325
14326         test_mkdir -p $DIR/$tdir/striped_dir
14327         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
14328                         error "chown $RUNAS_ID failed"
14329         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
14330                 error "set default striped dir failed"
14331
14332         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
14333         $LCTL set_param fail_loc=0x80000158
14334         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
14335
14336         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
14337         [ $stripe_index -eq 1 ] ||
14338                 error "expect 1 get $stripe_index for $dir"
14339 }
14340 run_test 300l "non-root user to create dir under striped dir with stale layout"
14341
14342 test_300m() {
14343         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14344                 skip "Need MDS version at least 2.7.55" && return
14345         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14346         [ $MDSCOUNT -ge 2 ] && skip "Only for single MDT" && return
14347
14348         mkdir -p $DIR/$tdir/striped_dir
14349         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
14350                 error "set default stripes dir error"
14351
14352         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
14353
14354         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
14355         [ $stripe_count -eq 0 ] ||
14356                         error "expect 0 get $stripe_count for a"
14357
14358         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
14359                 error "set default stripes dir error"
14360
14361         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
14362
14363         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
14364         [ $stripe_count -eq 0 ] ||
14365                         error "expect 0 get $stripe_count for b"
14366
14367         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
14368                 error "set default stripes dir error"
14369
14370         mkdir $DIR/$tdir/striped_dir/c &&
14371                 error "default stripe_index is invalid, mkdir c should fails"
14372
14373         rm -rf $DIR/$tdir || error "rmdir fails"
14374 }
14375 run_test 300m "setstriped directory on single MDT FS"
14376
14377 cleanup_300n() {
14378         local list=$(comma_list $(mdts_nodes))
14379
14380         trap 0
14381         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
14382 }
14383
14384 test_300n() {
14385         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14386                 skip "Need MDS version at least 2.7.55" && return
14387         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14388         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14389         local stripe_index
14390         local list=$(comma_list $(mdts_nodes))
14391
14392         trap cleanup_300n RETURN EXIT
14393         mkdir -p $DIR/$tdir
14394         chmod 777 $DIR/$tdir
14395         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
14396                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
14397                 error "create striped dir succeeds with gid=0"
14398
14399         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
14400         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
14401                 error "create striped dir fails with gid=-1"
14402
14403         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
14404         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
14405                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
14406                 error "set default striped dir succeeds with gid=0"
14407
14408
14409         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
14410         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
14411                 error "set default striped dir fails with gid=-1"
14412
14413
14414         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
14415         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
14416                                         error "create test_dir fails"
14417         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
14418                                         error "create test_dir1 fails"
14419         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
14420                                         error "create test_dir2 fails"
14421         cleanup_300n
14422 }
14423 run_test 300n "non-root user to create dir under striped dir with default EA"
14424
14425 test_300o() {
14426         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14427                 skip "Need MDS version at least 2.7.55" && return
14428         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14429         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14430         local numfree1
14431         local numfree2
14432
14433         mkdir -p $DIR/$tdir
14434
14435         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
14436         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
14437         if [ $numfree1 -lt 66000 -o $numfree2 -lt 66000 ]; then
14438                 skip "not enough free inodes $numfree1 $numfree2"
14439                 return
14440         fi
14441
14442         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
14443         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
14444         if [ $numfree1 -lt 300000 -o $numfree2 -lt 300000 ]; then
14445                 skip "not enough free space $numfree1 $numfree2"
14446                 return
14447         fi
14448
14449         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
14450                 error "setdirstripe fails"
14451
14452         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
14453                 error "create dirs fails"
14454
14455         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
14456         ls $DIR/$tdir/striped_dir > /dev/null ||
14457                 error "ls striped dir fails"
14458         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
14459                 error "unlink big striped dir fails"
14460 }
14461 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
14462
14463 test_300p() {
14464         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14465         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14466
14467         mkdir -p $DIR/$tdir
14468
14469         #define OBD_FAIL_OUT_ENOSPC     0x1704
14470         do_facet mds2 lctl set_param fail_loc=0x80001704
14471         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 &&
14472                         error "create striped directory should fail"
14473
14474         [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
14475
14476         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir
14477         true
14478 }
14479 run_test 300p "create striped directory without space"
14480
14481 test_300q() {
14482         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14483         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14484
14485         local fd=$(free_fd)
14486         local cmd="exec $fd<$tdir"
14487         cd $DIR
14488         $LFS mkdir -c $MDSCOUNT $tdir || error "create $tdir fails"
14489         eval $cmd
14490         cmd="exec $fd<&-"
14491         trap "eval $cmd" EXIT
14492         cd $tdir || error "cd $tdir fails"
14493         rmdir  ../$tdir || error "rmdir $tdir fails"
14494         mkdir local_dir && error "create dir succeeds"
14495         $LFS setdirstripe -i1 remote_dir && error "create remote dir succeeds"
14496         eval $cmd
14497         return 0
14498 }
14499 run_test 300q "create remote directory under orphan directory"
14500
14501 prepare_remote_file() {
14502         mkdir $DIR/$tdir/src_dir ||
14503                 error "create remote source failed"
14504
14505         cp /etc/hosts $DIR/$tdir/src_dir/a || error
14506         touch $DIR/$tdir/src_dir/a
14507
14508         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
14509                 error "create remote target dir failed"
14510
14511         touch $DIR/$tdir/tgt_dir/b
14512
14513         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
14514                 error "rename dir cross MDT failed!"
14515
14516         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
14517                 error "src_child still exists after rename"
14518
14519         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
14520                 error "missing file(a) after rename"
14521
14522         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
14523                 error "diff after rename"
14524 }
14525
14526 test_310a() {
14527         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
14528         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14529         local remote_file=$DIR/$tdir/tgt_dir/b
14530
14531         mkdir -p $DIR/$tdir
14532
14533         prepare_remote_file || error "prepare remote file failed"
14534
14535         #open-unlink file
14536         $OPENUNLINK $remote_file $remote_file || error
14537         $CHECKSTAT -a $remote_file || error
14538 }
14539 run_test 310a "open unlink remote file"
14540
14541 test_310b() {
14542         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
14543         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14544         local remote_file=$DIR/$tdir/tgt_dir/b
14545
14546         mkdir -p $DIR/$tdir
14547
14548         prepare_remote_file || error "prepare remote file failed"
14549
14550         ln $remote_file $DIR/$tfile || error "link failed for remote file"
14551         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
14552         $CHECKSTAT -t file $remote_file || error "check file failed"
14553 }
14554 run_test 310b "unlink remote file with multiple links while open"
14555
14556 test_310c() {
14557         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
14558         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14559         local remote_file=$DIR/$tdir/tgt_dir/b
14560
14561         mkdir -p $DIR/$tdir
14562
14563         prepare_remote_file || error "prepare remote file failed"
14564
14565         ln $remote_file $DIR/$tfile || error "link failed for remote file"
14566         multiop_bg_pause $remote_file O_uc ||
14567                         error "mulitop failed for remote file"
14568         MULTIPID=$!
14569         $MULTIOP $DIR/$tfile Ouc
14570         kill -USR1 $MULTIPID
14571         wait $MULTIPID
14572 }
14573 run_test 310c "open-unlink remote file with multiple links"
14574
14575 test_400a() { # LU-1606, was conf-sanity test_74
14576         local extra_flags=''
14577         local out=$TMP/$tfile
14578         local prefix=/usr/include/lustre
14579         local prog
14580
14581         if ! which $CC > /dev/null 2>&1; then
14582                 skip_env "$CC is not installed"
14583                 return 0
14584         fi
14585
14586         if ! [[ -d $prefix ]]; then
14587                 # Assume we're running in tree and fixup the include path.
14588                 extra_flags+=" -I$LUSTRE/../libcfs/include"
14589                 extra_flags+=" -I$LUSTRE/include"
14590                 extra_flags+=" -L$LUSTRE/utils"
14591         fi
14592
14593         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
14594                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
14595                         error "client api broken"
14596         done
14597 }
14598 run_test 400a "Lustre client api program can compile and link"
14599
14600 test_400b() { # LU-1606, LU-5011
14601         local header
14602         local out=$TMP/$tfile
14603         local prefix=/usr/include/lustre
14604
14605         # We use a hard coded prefix so that this test will not fail
14606         # when run in tree. There are headers in lustre/include/lustre/
14607         # that are not packaged (like lustre_idl.h) and have more
14608         # complicated include dependencies (like config.h and lnet/types.h).
14609         # Since this test about correct packaging we just skip them when
14610         # they don't exist (see below) rather than try to fixup cppflags.
14611
14612         if ! which $CC > /dev/null 2>&1; then
14613                 skip_env "$CC is not installed"
14614                 return 0
14615         fi
14616
14617         for header in $prefix/*.h; do
14618                 if ! [[ -f "$header" ]]; then
14619                         continue
14620                 fi
14621
14622                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
14623                         continue # liblustreapi.h is deprecated.
14624                 fi
14625
14626                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
14627                         error "cannot compile '$header'"
14628         done
14629 }
14630 run_test 400b "packaged headers can be compiled"
14631
14632 test_401a() { #LU-7437
14633         #count the number of parameters by "list_param -R"
14634         local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
14635         #count the number of parameters by listing proc files
14636         local procs=$(find -L $proc_dirs -mindepth 1 -printf '%P\n' 2>/dev/null|
14637                       sort -u | wc -l)
14638
14639         [ $params -eq $procs ] ||
14640                 error "found $params parameters vs. $procs proc files"
14641
14642         # test the list_param -D option only returns directories
14643         params=$($LCTL list_param -R -D '*' 2>/dev/null | wc -l)
14644         #count the number of parameters by listing proc directories
14645         procs=$(find -L $proc_dirs -mindepth 1 -type d -printf '%P\n' 2>/dev/null |
14646                 sort -u | wc -l)
14647
14648         [ $params -eq $procs ] ||
14649                 error "found $params parameters vs. $procs proc files"
14650 }
14651 run_test 401a "Verify if 'lctl list_param -R' can list parameters recursively"
14652
14653 test_401b() {
14654         local save=$($LCTL get_param -n jobid_var)
14655         local tmp=testing
14656
14657         $LCTL set_param foo=bar jobid_var=$tmp bar=baz &&
14658                 error "no error returned when setting bad parameters"
14659
14660         local jobid_new=$($LCTL get_param -n foe jobid_var baz)
14661         [[ "$jobid_new" == "$tmp" ]] || error "jobid tmp $jobid_new != $tmp"
14662
14663         $LCTL set_param -n fog=bam jobid_var=$save bat=fog
14664         local jobid_old=$($LCTL get_param -n foe jobid_var bag)
14665         [[ "$jobid_old" == "$save" ]] || error "jobid new $jobid_old != $save"
14666 }
14667 run_test 401b "Verify 'lctl {get,set}_param' continue after error"
14668
14669 test_401c() {
14670         local jobid_var_old=$($LCTL get_param -n jobid_var)
14671         local jobid_var_new
14672
14673         $LCTL set_param jobid_var= &&
14674                 error "no error returned for 'set_param a='"
14675
14676         jobid_var_new=$($LCTL get_param -n jobid_var)
14677         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
14678                 error "jobid_var was changed by setting without value"
14679
14680         $LCTL set_param jobid_var &&
14681                 error "no error returned for 'set_param a'"
14682
14683         jobid_var_new=$($LCTL get_param -n jobid_var)
14684         [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
14685                 error "jobid_var was changed by setting without value"
14686 }
14687 run_test 401c "Verify 'lctl set_param' without value fails in either format."
14688
14689 test_401d() {
14690         local jobid_var_old=$($LCTL get_param -n jobid_var)
14691         local jobid_var_new
14692         local new_value="foo=bar"
14693
14694         $LCTL set_param jobid_var=$new_value ||
14695                 error "'set_param a=b' did not accept a value containing '='"
14696
14697         jobid_var_new=$($LCTL get_param -n jobid_var)
14698         [[ "$jobid_var_new" == "$new_value" ]] ||
14699                 error "'set_param a=b' failed on a value containing '='"
14700
14701         # Reset the jobid_var to test the other format
14702         $LCTL set_param jobid_var=$jobid_var_old
14703         jobid_var_new=$($LCTL get_param -n jobid_var)
14704         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
14705                 error "failed to reset jobid_var"
14706
14707         $LCTL set_param jobid_var $new_value ||
14708                 error "'set_param a b' did not accept a value containing '='"
14709
14710         jobid_var_new=$($LCTL get_param -n jobid_var)
14711         [[ "$jobid_var_new" == "$new_value" ]] ||
14712                 error "'set_param a b' failed on a value containing '='"
14713
14714         $LCTL set_param jobid_var $jobid_var_old
14715         jobid_var_new=$($LCTL get_param -n jobid_var)
14716         [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
14717                 error "failed to reset jobid_var"
14718 }
14719 run_test 401d "Verify 'lctl set_param' accepts values containing '='"
14720
14721 test_402() {
14722         $LFS setdirstripe -i 0 $DIR/$tdir || error "setdirstripe -i 0 failed"
14723 #define OBD_FAIL_MDS_FLD_LOOKUP 0x15c
14724         do_facet mds1 "lctl set_param fail_loc=0x8000015c"
14725         touch $DIR/$tdir/$tfile && error "touch should fail with ENOENT" ||
14726                 echo "Touch failed - OK"
14727 }
14728 run_test 402 "Return ENOENT to lod_generate_and_set_lovea"
14729
14730 test_403() {
14731         local file1=$DIR/$tfile.1
14732         local file2=$DIR/$tfile.2
14733         local tfile=$TMP/$tfile
14734
14735         rm -f $file1 $file2 $tfile
14736
14737         touch $file1
14738         ln $file1 $file2
14739
14740         # 30 sec OBD_TIMEOUT in ll_getattr()
14741         # right before populating st_nlink
14742         $LCTL set_param fail_loc=0x80001409
14743         stat -c %h $file1 > $tfile &
14744
14745         # create an alias, drop all locks and reclaim the dentry
14746         < $file2
14747         cancel_lru_locks mdc
14748         cancel_lru_locks osc
14749         sysctl -w vm.drop_caches=2
14750
14751         wait
14752
14753         [ `cat $tfile` -gt 0 ] || error "wrong nlink count: `cat $tfile`"
14754
14755         rm -f $tfile $file1 $file2
14756 }
14757 run_test 403 "i_nlink should not drop to zero due to aliasing"
14758
14759 test_404() { # LU-6601
14760         local mosps=$(do_facet $SINGLEMDS $LCTL dl |
14761                 awk '/osp .*-osc-MDT/ { print $4}')
14762
14763         local osp
14764         for osp in $mosps; do
14765                 echo "Deactivate: " $osp
14766                 do_facet $SINGLEMDS $LCTL --device %$osp deactivate
14767                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
14768                         awk -vp=$osp '$4 == p { print $2 }')
14769                 [ $stat = IN ] || {
14770                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
14771                         error "deactivate error"
14772                 }
14773                 echo "Activate: " $osp
14774                 do_facet $SINGLEMDS $LCTL --device %$osp activate
14775                 local stat=$(do_facet $SINGLEMDS $LCTL dl |
14776                         awk -vp=$osp '$4 == p { print $2 }')
14777                 [ $stat = UP ] || {
14778                         do_facet $SINGLEMDS $LCTL dl | grep -w $osp
14779                         error "activate error"
14780                 }
14781         done
14782 }
14783 run_test 404 "validate manual {de}activated works properly for OSPs"
14784
14785 #
14786 # tests that do cleanup/setup should be run at the end
14787 #
14788
14789 test_900() {
14790         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14791         local ls
14792         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
14793         $LCTL set_param fail_loc=0x903
14794
14795         cancel_lru_locks MGC
14796
14797         FAIL_ON_ERROR=true cleanup
14798         FAIL_ON_ERROR=true setup
14799 }
14800 run_test 900 "umount should not race with any mgc requeue thread"
14801
14802 complete $SECONDS
14803 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
14804 check_and_cleanup_lustre
14805 if [ "$I_MOUNTED" != "yes" ]; then
14806         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
14807 fi
14808 exit_status