Whamcloud - gitweb
LU-7039 llog: update llog header and size
[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
109 DIR=${DIR:-$MOUNT}
110 assert_DIR
111
112 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
113         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
114 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
115
116 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
117 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
118 rm -rf $DIR/[Rdfs][0-9]*
119
120 # $RUNAS_ID may get set incorrectly somewhere else
121 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
122
123 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
124
125 build_test_filter
126
127 if [ "${ONLY}" = "MOUNT" ] ; then
128         echo "Lustre is up, please go on"
129         exit
130 fi
131
132 echo "preparing for tests involving mounts"
133 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
134 touch $EXT2_DEV
135 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
136 echo # add a newline after mke2fs.
137
138 umask 077
139
140 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
141 lctl set_param debug=-1 2> /dev/null || true
142 test_0a() {
143         touch $DIR/$tfile
144         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
145         rm $DIR/$tfile
146         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
147 }
148 run_test 0a "touch; rm ====================="
149
150 test_0b() {
151         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
152         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
153 }
154 run_test 0b "chmod 0755 $DIR ============================="
155
156 test_0c() {
157         $LCTL get_param mdc.*.import | grep "state: FULL" ||
158                 error "import not FULL"
159         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
160                 error "bad target"
161 }
162 run_test 0c "check import proc ============================="
163
164 test_1() {
165         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
166         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
167         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
168         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
169         rmdir $DIR/$tdir/d2
170         rmdir $DIR/$tdir
171         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
172 }
173 run_test 1 "mkdir; remkdir; rmdir =============================="
174
175 test_2() {
176         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
177         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
178         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
179         rm -r $DIR/$tdir
180         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
181 }
182 run_test 2 "mkdir; touch; rmdir; check file ===================="
183
184 test_3() {
185         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
186         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
187         touch $DIR/$tdir/$tfile
188         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
189         rm -r $DIR/$tdir
190         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
191 }
192 run_test 3 "mkdir; touch; rmdir; check dir ====================="
193
194 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
195 test_4() {
196         local MDTIDX=1
197
198         test_mkdir $DIR/$tdir ||
199                 error "Create remote directory failed"
200
201         touch $DIR/$tdir/$tfile ||
202                 error "Create file under remote directory failed"
203
204         rmdir $DIR/$tdir &&
205                 error "Expect error removing in-use dir $DIR/$tdir"
206
207         test -d $DIR/$tdir || error "Remote directory disappeared"
208
209         rm -rf $DIR/$tdir || error "remove remote dir error"
210 }
211 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
212
213 test_5() {
214         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
215         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
216         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
217         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
218         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
219 }
220 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
221
222 test_6a() {
223         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
224         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
225         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
226                 error "$tfile does not have perm 0666 or UID $UID"
227         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
228         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
229                 error "$tfile should be 0666 and owned by UID $UID"
230 }
231 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
232
233 test_6c() {
234         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
235         touch $DIR/$tfile
236         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
237         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
238                 error "$tfile should be owned by UID $RUNAS_ID"
239         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
240         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
241                 error "$tfile should be owned by UID $RUNAS_ID"
242 }
243 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
244
245 test_6e() {
246         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
247         touch $DIR/$tfile
248         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
249         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
250                 error "$tfile should be owned by GID $UID"
251         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
252         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
253                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
254 }
255 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
256
257 test_6g() {
258         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
259         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
260         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
261         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
262         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
263         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
264         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
265                 error "$tdir/d/subdir should be GID $RUNAS_GID"
266 }
267 run_test 6g "Is new dir in sgid dir inheriting group?"
268
269 test_6h() { # bug 7331
270         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
271         touch $DIR/$tfile || error "touch failed"
272         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
273         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
274                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
275         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
276                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
277 }
278 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
279
280 test_7a() {
281         test_mkdir $DIR/$tdir
282         $MCREATE $DIR/$tdir/$tfile
283         chmod 0666 $DIR/$tdir/$tfile
284         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
285                 error "$tdir/$tfile should be mode 0666"
286 }
287 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
288
289 test_7b() {
290         if [ ! -d $DIR/$tdir ]; then
291                 test_mkdir $DIR/$tdir
292         fi
293         $MCREATE $DIR/$tdir/$tfile
294         echo -n foo > $DIR/$tdir/$tfile
295         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
296         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
297 }
298 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
299
300 test_8() {
301         test_mkdir $DIR/$tdir
302         touch $DIR/$tdir/$tfile
303         chmod 0666 $DIR/$tdir/$tfile
304         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
305                 error "$tfile mode not 0666"
306 }
307 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
308
309 test_9() {
310         test_mkdir $DIR/$tdir
311         test_mkdir $DIR/$tdir/d2
312         test_mkdir $DIR/$tdir/d2/d3
313         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
314 }
315 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
316
317 test_10() {
318         test_mkdir $DIR/$tdir
319         test_mkdir $DIR/$tdir/d2
320         touch $DIR/$tdir/d2/$tfile
321         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
322                 error "$tdir/d2/$tfile not a file"
323 }
324 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
325
326 test_11() {
327         test_mkdir $DIR/$tdir
328         test_mkdir $DIR/$tdir/d2
329         chmod 0666 $DIR/$tdir/d2
330         chmod 0705 $DIR/$tdir/d2
331         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
332                 error "$tdir/d2 mode not 0705"
333 }
334 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
335
336 test_12() {
337         test_mkdir $DIR/$tdir
338         touch $DIR/$tdir/$tfile
339         chmod 0666 $DIR/$tdir/$tfile
340         chmod 0654 $DIR/$tdir/$tfile
341         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
342                 error "$tdir/d2 mode not 0654"
343 }
344 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
345
346 test_13() {
347         test_mkdir $DIR/$tdir
348         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
349         >  $DIR/$tdir/$tfile
350         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
351                 error "$tdir/$tfile size not 0 after truncate"
352 }
353 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
354
355 test_14() {
356         test_mkdir $DIR/$tdir
357         touch $DIR/$tdir/$tfile
358         rm $DIR/$tdir/$tfile
359         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
360 }
361 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
362
363 test_15() {
364         test_mkdir $DIR/$tdir
365         touch $DIR/$tdir/$tfile
366         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
367         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
368                 error "$tdir/${tfile_2} not a file after rename"
369         rm $DIR/$tdir/${tfile}_2 || error "unlink failed after rename"
370 }
371 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
372
373 test_16() {
374         test_mkdir $DIR/$tdir
375         touch $DIR/$tdir/$tfile
376         rm -rf $DIR/$tdir/$tfile
377         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
378 }
379 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
380
381 test_17a() {
382         test_mkdir -p $DIR/$tdir
383         touch $DIR/$tdir/$tfile
384         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
385         ls -l $DIR/$tdir
386         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
387                 error "$tdir/l-exist not a symlink"
388         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
389                 error "$tdir/l-exist not referencing a file"
390         rm -f $DIR/$tdir/l-exist
391         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
392 }
393 run_test 17a "symlinks: create, remove (real) =================="
394
395 test_17b() {
396         test_mkdir -p $DIR/$tdir
397         ln -s no-such-file $DIR/$tdir/l-dangle
398         ls -l $DIR/$tdir
399         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
400                 error "$tdir/l-dangle not referencing no-such-file"
401         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
402                 error "$tdir/l-dangle not referencing non-existent file"
403         rm -f $DIR/$tdir/l-dangle
404         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
405 }
406 run_test 17b "symlinks: create, remove (dangling) =============="
407
408 test_17c() { # bug 3440 - don't save failed open RPC for replay
409         test_mkdir -p $DIR/$tdir
410         ln -s foo $DIR/$tdir/$tfile
411         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
412 }
413 run_test 17c "symlinks: open dangling (should return error) ===="
414
415 test_17d() {
416         test_mkdir -p $DIR/$tdir
417         ln -s foo $DIR/$tdir/$tfile
418         touch $DIR/$tdir/$tfile || error "creating to new symlink"
419 }
420 run_test 17d "symlinks: create dangling ========================"
421
422 test_17e() {
423         test_mkdir -p $DIR/$tdir
424         local foo=$DIR/$tdir/$tfile
425         ln -s $foo $foo || error "create symlink failed"
426         ls -l $foo || error "ls -l failed"
427         ls $foo && error "ls not failed" || true
428 }
429 run_test 17e "symlinks: create recursive symlink (should return error) ===="
430
431 test_17f() {
432         test_mkdir -p $DIR/$tdir
433         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
434         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
435         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
436         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
437         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
438         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
439         ls -l  $DIR/$tdir
440 }
441 run_test 17f "symlinks: long and very long symlink name ========================"
442
443 # str_repeat(S, N) generate a string that is string S repeated N times
444 str_repeat() {
445         local s=$1
446         local n=$2
447         local ret=''
448         while [ $((n -= 1)) -ge 0 ]; do
449                 ret=$ret$s
450         done
451         echo $ret
452 }
453
454 # Long symlinks and LU-2241
455 test_17g() {
456         test_mkdir -p $DIR/$tdir
457         local TESTS="59 60 61 4094 4095"
458
459         # Fix for inode size boundary in 2.1.4
460         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
461                 TESTS="4094 4095"
462
463         # Patch not applied to 2.2 or 2.3 branches
464         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
465         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
466                 TESTS="4094 4095"
467
468         # skip long symlink name for rhel6.5.
469         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
470         grep -q '6.5' /etc/redhat-release &>/dev/null &&
471                 TESTS="59 60 61 4062 4063"
472
473         for i in $TESTS; do
474                 local SYMNAME=$(str_repeat 'x' $i)
475                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
476                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
477         done
478 }
479 run_test 17g "symlinks: really long symlink name and inode boundaries"
480
481 test_17h() { #bug 17378
482         remote_mds_nodsh && skip "remote MDS with nodsh" && return
483         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
484         local mdt_idx
485         test_mkdir -p $DIR/$tdir
486         if [[ $MDSCOUNT -gt 1 ]]; then
487                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
488         else
489                 mdt_idx=0
490         fi
491         $SETSTRIPE -c -1 $DIR/$tdir
492 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
493         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
494         touch $DIR/$tdir/$tfile || true
495 }
496 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
497
498 test_17i() { #bug 20018
499         remote_mds_nodsh && skip "remote MDS with nodsh" && return
500         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
501         test_mkdir -c1 $DIR/$tdir
502         local foo=$DIR/$tdir/$tfile
503         local mdt_idx
504         if [[ $MDSCOUNT -gt 1 ]]; then
505                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
506         else
507                 mdt_idx=0
508         fi
509         ln -s $foo $foo || error "create symlink failed"
510 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
511         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
512         ls -l $foo && error "error not detected"
513         return 0
514 }
515 run_test 17i "don't panic on short symlink"
516
517 test_17k() { #bug 22301
518         [[ -z "$(which rsync 2>/dev/null)" ]] &&
519                 skip "no rsync command" && return 0
520         rsync --help | grep -q xattr ||
521                 skip_env "$(rsync --version | head -n1) does not support xattrs"
522         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
523         test_mkdir -p $DIR/$tdir
524         test_mkdir -p $DIR/$tdir.new
525         touch $DIR/$tdir/$tfile
526         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
527         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
528                 error "rsync failed with xattrs enabled"
529 }
530 run_test 17k "symlinks: rsync with xattrs enabled ========================="
531
532 test_17l() { # LU-279
533         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
534                 skip "no getfattr command" && return 0
535         test_mkdir -p $DIR/$tdir
536         touch $DIR/$tdir/$tfile
537         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
538         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
539                 # -h to not follow symlinks. -m '' to list all the xattrs.
540                 # grep to remove first line: '# file: $path'.
541                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
542                 do
543                         lgetxattr_size_check $path $xattr ||
544                                 error "lgetxattr_size_check $path $xattr failed"
545                 done
546         done
547 }
548 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
549
550 # LU-1540
551 test_17m() {
552         local short_sym="0123456789"
553         local WDIR=$DIR/${tdir}m
554         local i
555
556         remote_mds_nodsh && skip "remote MDS with nodsh" && return
557         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
558         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
559                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
560
561         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
562                 skip "only for ldiskfs MDT" && return 0
563
564         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
565
566         test_mkdir -p $WDIR
567         long_sym=$short_sym
568         # create a long symlink file
569         for ((i = 0; i < 4; ++i)); do
570                 long_sym=${long_sym}${long_sym}
571         done
572
573         echo "create 512 short and long symlink files under $WDIR"
574         for ((i = 0; i < 256; ++i)); do
575                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
576                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
577         done
578
579         echo "erase them"
580         rm -f $WDIR/*
581         sync
582         wait_delete_completed
583
584         echo "recreate the 512 symlink files with a shorter string"
585         for ((i = 0; i < 512; ++i)); do
586                 # rewrite the symlink file with a shorter string
587                 ln -sf ${long_sym} $WDIR/long-$i || error "long_sym failed"
588                 ln -sf ${short_sym} $WDIR/short-$i || error "short_sym failed"
589         done
590
591         local mds_index=$(($($LFS getstripe -M $WDIR) + 1))
592         local devname=$(mdsdevname $mds_index)
593
594         echo "stop and checking mds${mds_index}:"
595         # e2fsck should not return error
596         stop mds${mds_index}
597         run_e2fsck $(facet_active_host mds${mds_index}) $devname -n
598         rc=$?
599
600         start mds${mds_index} $devname $MDS_MOUNT_OPTS || error "start failed"
601         df $MOUNT > /dev/null 2>&1
602         [ $rc -eq 0 ] ||
603                 error "e2fsck detected error for short/long symlink: rc=$rc"
604 }
605 run_test 17m "run e2fsck against MDT which contains short/long symlink"
606
607 check_fs_consistency_17n() {
608         local mdt_index
609         local rc=0
610
611         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
612         # so it only check MDT1/MDT2 instead of all of MDTs.
613         for mdt_index in 1 2; do
614                 local devname=$(mdsdevname $mdt_index)
615                 # e2fsck should not return error
616                 stop mds${mdt_index}
617                 run_e2fsck $(facet_active_host mds$mdt_index) $devname -n ||
618                         rc=$((rc + $?))
619
620                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
621                         error "mount mds$mdt_index failed"
622                 df $MOUNT > /dev/null 2>&1
623         done
624         return $rc
625 }
626
627 test_17n() {
628         local i
629
630         remote_mds_nodsh && skip "remote MDS with nodsh" && return
631         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
632         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
633                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
634
635         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
636                 skip "only for ldiskfs MDT" && return 0
637
638         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
639
640         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
641
642         test_mkdir $DIR/$tdir
643         for ((i=0; i<10; i++)); do
644                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
645                         error "create remote dir error $i"
646                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
647                         error "create files under remote dir failed $i"
648         done
649
650         check_fs_consistency_17n ||
651                 error "e2fsck report error after create files under remote dir"
652
653         for ((i = 0; i < 10; i++)); do
654                 rm -rf $DIR/$tdir/remote_dir_${i} ||
655                         error "destroy remote dir error $i"
656         done
657
658         check_fs_consistency_17n ||
659                 error "e2fsck report error after unlink files under remote dir"
660
661         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
662                 skip "lustre < 2.4.50 does not support migrate mv " && return
663
664         for ((i = 0; i < 10; i++)); do
665                 mkdir -p $DIR/$tdir/remote_dir_${i}
666                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
667                         error "create files under remote dir failed $i"
668                 $LFS migrate --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
669                         error "migrate remote dir error $i"
670         done
671         check_fs_consistency_17n || error "e2fsck report error after migration"
672
673         for ((i = 0; i < 10; i++)); do
674                 rm -rf $DIR/$tdir/remote_dir_${i} ||
675                         error "destroy remote dir error $i"
676         done
677
678         check_fs_consistency_17n || error "e2fsck report error after unlink"
679 }
680 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
681
682 test_17o() {
683         remote_mds_nodsh && skip "remote MDS with nodsh" && return
684         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
685                 skip "Need MDS version at least 2.3.64" && return
686
687         local WDIR=$DIR/${tdir}o
688         local mdt_index
689         local rc=0
690
691         test_mkdir -p $WDIR
692         mdt_index=$($LFS getstripe -M $WDIR)
693         mdt_index=$((mdt_index+1))
694
695         touch $WDIR/$tfile
696
697         #fail mds will wait the failover finish then set
698         #following fail_loc to avoid interfer the recovery process.
699         fail mds${mdt_index}
700
701         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
702         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
703         ls -l $WDIR/$tfile && rc=1
704         do_facet mds${mdt_index} lctl set_param fail_loc=0
705         [[ $rc -ne 0 ]] && error "stat file should fail"
706         true
707 }
708 run_test 17o "stat file with incompat LMA feature"
709
710 test_18() {
711         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
712         ls $DIR || error "Failed to ls $DIR: $?"
713 }
714 run_test 18 "touch .../f ; ls ... =============================="
715
716 test_19a() {
717         touch $DIR/$tfile
718         ls -l $DIR
719         rm $DIR/$tfile
720         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
721 }
722 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
723
724 test_19b() {
725         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
726 }
727 run_test 19b "ls -l .../f19 (should return error) =============="
728
729 test_19c() {
730         [ $RUNAS_ID -eq $UID ] &&
731                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
732         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
733 }
734 run_test 19c "$RUNAS touch .../f19 (should return error) =="
735
736 test_19d() {
737         cat $DIR/f19 && error || true
738 }
739 run_test 19d "cat .../f19 (should return error) =============="
740
741 test_20() {
742         touch $DIR/$tfile
743         rm $DIR/$tfile
744         log "1 done"
745         touch $DIR/$tfile
746         rm $DIR/$tfile
747         log "2 done"
748         touch $DIR/$tfile
749         rm $DIR/$tfile
750         log "3 done"
751         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
752 }
753 run_test 20 "touch .../f ; ls -l ... ==========================="
754
755 test_21() {
756         test_mkdir -p $DIR/$tdir
757         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
758         ln -s dangle $DIR/$tdir/link
759         echo foo >> $DIR/$tdir/link
760         cat $DIR/$tdir/dangle
761         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
762         $CHECKSTAT -f -t file $DIR/$tdir/link ||
763                 error "$tdir/link not linked to a file"
764 }
765 run_test 21 "write to dangling link ============================"
766
767 test_22() {
768         WDIR=$DIR/$tdir
769         test_mkdir -p $DIR/$tdir
770         chown $RUNAS_ID:$RUNAS_GID $WDIR
771         (cd $WDIR || error "cd $WDIR failed";
772         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
773         $RUNAS tar xf -)
774         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
775         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
776         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
777 }
778 run_test 22 "unpack tar archive as non-root user ==============="
779
780 # was test_23
781 test_23a() {
782         test_mkdir -p $DIR/$tdir
783         local file=$DIR/$tdir/$tfile
784
785         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
786         openfile -f O_CREAT:O_EXCL $file &&
787                 error "$file recreate succeeded" || true
788 }
789 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
790
791 test_23b() { # bug 18988
792         test_mkdir -p $DIR/$tdir
793         local file=$DIR/$tdir/$tfile
794
795         rm -f $file
796         echo foo > $file || error "write filed"
797         echo bar >> $file || error "append filed"
798         $CHECKSTAT -s 8 $file || error "wrong size"
799         rm $file
800 }
801 run_test 23b "O_APPEND check =========================="
802
803 # rename sanity
804 test_24a() {
805         echo '-- same directory rename'
806         test_mkdir $DIR/$tdir
807         touch $DIR/$tdir/$tfile.1
808         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
809         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
810 }
811 run_test 24a "rename file to non-existent target"
812
813 test_24b() {
814         test_mkdir $DIR/$tdir
815         touch $DIR/$tdir/$tfile.{1,2}
816         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
817         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
818         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
819 }
820 run_test 24b "rename file to existing target"
821
822 test_24c() {
823         test_mkdir $DIR/$tdir
824         test_mkdir $DIR/$tdir/d$testnum.1
825         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
826         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
827         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
828 }
829 run_test 24c "rename directory to non-existent target"
830
831 test_24d() {
832         test_mkdir -c1 $DIR/$tdir
833         test_mkdir -c1 $DIR/$tdir/d$testnum.1
834         test_mkdir -c1 $DIR/$tdir/d$testnum.2
835         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
836         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
837         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
838 }
839 run_test 24d "rename directory to existing target"
840
841 test_24e() {
842         echo '-- cross directory renames --'
843         test_mkdir $DIR/R5a
844         test_mkdir $DIR/R5b
845         touch $DIR/R5a/f
846         mv $DIR/R5a/f $DIR/R5b/g
847         $CHECKSTAT -a $DIR/R5a/f || error
848         $CHECKSTAT -t file $DIR/R5b/g || error
849 }
850 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
851
852 test_24f() {
853         test_mkdir $DIR/R6a
854         test_mkdir $DIR/R6b
855         touch $DIR/R6a/f $DIR/R6b/g
856         mv $DIR/R6a/f $DIR/R6b/g
857         $CHECKSTAT -a $DIR/R6a/f || error
858         $CHECKSTAT -t file $DIR/R6b/g || error
859 }
860 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
861
862 test_24g() {
863         test_mkdir $DIR/R7a
864         test_mkdir $DIR/R7b
865         test_mkdir $DIR/R7a/d
866         mv $DIR/R7a/d $DIR/R7b/e
867         $CHECKSTAT -a $DIR/R7a/d || error
868         $CHECKSTAT -t dir $DIR/R7b/e || error
869 }
870 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
871
872 test_24h() {
873         test_mkdir -c1 $DIR/R8a
874         test_mkdir -c1 $DIR/R8b
875         test_mkdir -c1 $DIR/R8a/d
876         test_mkdir -c1 $DIR/R8b/e
877         mrename $DIR/R8a/d $DIR/R8b/e
878         $CHECKSTAT -a $DIR/R8a/d || error
879         $CHECKSTAT -t dir $DIR/R8b/e || error
880 }
881 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
882
883 test_24i() {
884         echo "-- rename error cases"
885         test_mkdir $DIR/R9
886         test_mkdir $DIR/R9/a
887         touch $DIR/R9/f
888         mrename $DIR/R9/f $DIR/R9/a
889         $CHECKSTAT -t file $DIR/R9/f || error
890         $CHECKSTAT -t dir  $DIR/R9/a || error
891         $CHECKSTAT -a $DIR/R9/a/f || error
892 }
893 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
894
895 test_24j() {
896         test_mkdir $DIR/R10
897         mrename $DIR/R10/f $DIR/R10/g
898         $CHECKSTAT -t dir $DIR/R10 || error
899         $CHECKSTAT -a $DIR/R10/f || error
900         $CHECKSTAT -a $DIR/R10/g || error
901 }
902 run_test 24j "source does not exist ============================"
903
904 test_24k() {
905         test_mkdir $DIR/R11a
906         test_mkdir $DIR/R11a/d
907         touch $DIR/R11a/f
908         mv $DIR/R11a/f $DIR/R11a/d
909         $CHECKSTAT -a $DIR/R11a/f || error
910         $CHECKSTAT -t file $DIR/R11a/d/f || error
911 }
912 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
913
914 # bug 2429 - rename foo foo foo creates invalid file
915 test_24l() {
916         f="$DIR/f24l"
917         $MULTIOP $f OcNs || error
918 }
919 run_test 24l "Renaming a file to itself ========================"
920
921 test_24m() {
922         f="$DIR/f24m"
923         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
924         # on ext3 this does not remove either the source or target files
925         # though the "expected" operation would be to remove the source
926         $CHECKSTAT -t file ${f} || error "${f} missing"
927         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
928 }
929 run_test 24m "Renaming a file to a hard link to itself ========="
930
931 test_24n() {
932     f="$DIR/f24n"
933     # this stats the old file after it was renamed, so it should fail
934     touch ${f}
935     $CHECKSTAT ${f}
936     mv ${f} ${f}.rename
937     $CHECKSTAT ${f}.rename
938     $CHECKSTAT -a ${f}
939 }
940 run_test 24n "Statting the old file after renaming (Posix rename 2)"
941
942 test_24o() {
943         test_mkdir -p $DIR/d24o
944         rename_many -s random -v -n 10 $DIR/d24o
945 }
946 run_test 24o "rename of files during htree split ==============="
947
948 test_24p() {
949         test_mkdir $DIR/R12a
950         test_mkdir $DIR/R12b
951         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
952         mrename $DIR/R12a $DIR/R12b
953         $CHECKSTAT -a $DIR/R12a || error
954         $CHECKSTAT -t dir $DIR/R12b || error
955         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
956         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
957 }
958 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
959
960 cleanup_multiop_pause() {
961         trap 0
962         kill -USR1 $MULTIPID
963 }
964
965 test_24q() {
966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
967         test_mkdir $DIR/R13a
968         test_mkdir $DIR/R13b
969         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
970         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
971         MULTIPID=$!
972
973         trap cleanup_multiop_pause EXIT
974         mrename $DIR/R13a $DIR/R13b
975         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
976         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
977         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
978         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
979         cleanup_multiop_pause
980         wait $MULTIPID || error "multiop close failed"
981 }
982 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
983
984 test_24r() { #bug 3789
985         test_mkdir $DIR/R14a
986         test_mkdir $DIR/R14a/b
987         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
988         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
989         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
990 }
991 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
992
993 test_24s() {
994         test_mkdir $DIR/R15a
995         test_mkdir $DIR/R15a/b
996         test_mkdir $DIR/R15a/b/c
997         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
998         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
999         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1000 }
1001 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1002 test_24t() {
1003         test_mkdir $DIR/R16a
1004         test_mkdir $DIR/R16a/b
1005         test_mkdir $DIR/R16a/b/c
1006         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1007         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1008         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1009 }
1010 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1011
1012 test_24u() { # bug12192
1013         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1014         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1015 }
1016 run_test 24u "create stripe file"
1017
1018 page_size() {
1019         getconf PAGE_SIZE
1020 }
1021
1022 simple_cleanup_common() {
1023         trap 0
1024         rm -rf $DIR/$tdir
1025         wait_delete_completed
1026 }
1027
1028 max_pages_per_rpc() {
1029         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1030 }
1031
1032 test_24v() {
1033         local NRFILES=100000
1034         local FREE_INODES=$(mdt_free_inodes 0)
1035         [[ $FREE_INODES -lt $NRFILES ]] &&
1036                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1037                 return
1038
1039         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1040         trap simple_cleanup_common EXIT
1041
1042         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1043         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1044
1045         test_mkdir -p $DIR/$tdir
1046         createmany -m $DIR/$tdir/$tfile $NRFILES
1047
1048         cancel_lru_locks mdc
1049         lctl set_param mdc.*.stats clear
1050
1051         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1052
1053         # LU-5 large readdir
1054         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1055         #               8 bytes for name(filename is mostly 5 in this test) +
1056         #               8 bytes for luda_type
1057         # take into account of overhead in lu_dirpage header and end mark in
1058         # each page, plus one in RPC_NUM calculation.
1059         DIRENT_SIZE=48
1060         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1061         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1062         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1063                                 awk '/^mds_readpage/ {print $2}')
1064         [[ $mds_readpage -gt $RPC_NUM ]] &&
1065                 error "large readdir doesn't take effect"
1066
1067         simple_cleanup_common
1068 }
1069 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1070
1071 test_24w() { # bug21506
1072         SZ1=234852
1073         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1074         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1075         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1076         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1077         [[ "$SZ1" -eq "$SZ2" ]] ||
1078                 error "Error reading at the end of the file $tfile"
1079 }
1080 run_test 24w "Reading a file larger than 4Gb"
1081
1082 test_24x() {
1083         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1084         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1085         local MDTIDX=1
1086         local remote_dir=$DIR/$tdir/remote_dir
1087
1088         test_mkdir -p $DIR/$tdir
1089         $LFS mkdir -i $MDTIDX $remote_dir ||
1090                 error "create remote directory failed"
1091
1092         test_mkdir -p $DIR/$tdir/src_dir
1093         touch $DIR/$tdir/src_file
1094         test_mkdir -p $remote_dir/tgt_dir
1095         touch $remote_dir/tgt_file
1096
1097         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir ||
1098                 error "rename dir cross MDT failed!"
1099
1100         mrename $DIR/$tdir/src_file $remote_dir/tgt_file ||
1101                 error "rename file cross MDT failed!"
1102
1103         touch $DIR/$tdir/ln_file
1104         ln $DIR/$tdir/ln_file $remote_dir/ln_name ||
1105                 error "ln file cross MDT failed"
1106
1107         rm -rf $DIR/$tdir || error "Can not delete directories"
1108 }
1109 run_test 24x "cross MDT rename/link"
1110
1111 test_24y() {
1112         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1113         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1114         local MDTIDX=1
1115         local remote_dir=$DIR/$tdir/remote_dir
1116
1117         test_mkdir -p $DIR/$tdir
1118         $LFS mkdir -i $MDTIDX $remote_dir ||
1119                    error "create remote directory failed"
1120
1121         test_mkdir -p $remote_dir/src_dir
1122         touch $remote_dir/src_file
1123         test_mkdir -p $remote_dir/tgt_dir
1124         touch $remote_dir/tgt_file
1125
1126         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1127                 error "rename subdir in the same remote dir failed!"
1128
1129         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1130                 error "rename files in the same remote dir failed!"
1131
1132         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1133                 error "link files in the same remote dir failed!"
1134
1135         rm -rf $DIR/$tdir || error "Can not delete directories"
1136 }
1137 run_test 24y "rename/link on the same dir should succeed"
1138
1139 test_24A() { # LU-3182
1140         local NFILES=5000
1141
1142         rm -rf $DIR/$tdir
1143         test_mkdir -p $DIR/$tdir
1144         createmany -m $DIR/$tdir/$tfile $NFILES
1145         local t=$(ls $DIR/$tdir | wc -l)
1146         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1147         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1148         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1149                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1150         fi
1151
1152         rm -rf $DIR/$tdir || error "Can not delete directories"
1153 }
1154 run_test 24A "readdir() returns correct number of entries."
1155
1156 test_24B() { # LU-4805
1157         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1158         local count
1159
1160         test_mkdir $DIR/$tdir
1161         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1162                 error "create striped dir failed"
1163
1164         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1165         [ $count -eq 2 ] || error "Expected 2, got $count"
1166
1167         touch $DIR/$tdir/striped_dir/a
1168
1169         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1170         [ $count -eq 3 ] || error "Expected 3, got $count"
1171
1172         touch $DIR/$tdir/striped_dir/.f
1173
1174         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1175         [ $count -eq 4 ] || error "Expected 4, got $count"
1176
1177         rm -rf $DIR/$tdir || error "Can not delete directories"
1178 }
1179 run_test 24B "readdir for striped dir return correct number of entries"
1180
1181 test_24C() {
1182         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1183
1184         mkdir $DIR/$tdir
1185         mkdir $DIR/$tdir/d0
1186         mkdir $DIR/$tdir/d1
1187
1188         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1189                 error "create striped dir failed"
1190
1191         cd $DIR/$tdir/d0/striped_dir
1192
1193         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1194         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1195         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1196
1197         [ "$d0_ino" = "$parent_ino" ] ||
1198                 error ".. wrong, expect $d0_ino, get $parent_ino"
1199
1200         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1201                 error "mv striped dir failed"
1202
1203         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1204
1205         [ "$d1_ino" = "$parent_ino" ] ||
1206                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1207 }
1208 run_test 24C "check .. in striped dir"
1209
1210 test_24D() { # LU-6101
1211         local NFILES=50000
1212
1213         rm -rf $DIR/$tdir
1214         mkdir -p $DIR/$tdir
1215         createmany -m $DIR/$tdir/$tfile $NFILES
1216         local t=$(ls $DIR/$tdir | wc -l)
1217         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1218         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1219         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1220                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1221         fi
1222
1223         rm -rf $DIR/$tdir || error "Can not delete directories"
1224 }
1225 run_test 24D "readdir() returns correct number of entries after cursor reload"
1226
1227 test_24E() {
1228         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
1229         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1230
1231         mkdir -p $DIR/$tdir
1232         mkdir $DIR/$tdir/src_dir
1233         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
1234                 error "create remote source failed"
1235
1236         touch $DIR/$tdir/src_dir/src_child/a
1237
1238         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
1239                 error "create remote target dir failed"
1240
1241         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
1242                 error "create remote target child failed"
1243
1244         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
1245                 error "rename dir cross MDT failed!"
1246
1247         find $DIR/$tdir
1248
1249         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
1250                 error "src_child still exists after rename"
1251
1252         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
1253                 error "missing file(a) after rename"
1254
1255         rm -rf $DIR/$tdir || error "Can not delete directories"
1256 }
1257 run_test 24E "cross MDT rename/link"
1258
1259 test_25a() {
1260         echo '== symlink sanity ============================================='
1261
1262         test_mkdir $DIR/d25
1263         ln -s d25 $DIR/s25
1264         touch $DIR/s25/foo || error
1265 }
1266 run_test 25a "create file in symlinked directory ==============="
1267
1268 test_25b() {
1269         [ ! -d $DIR/d25 ] && test_25a
1270         $CHECKSTAT -t file $DIR/s25/foo || error
1271 }
1272 run_test 25b "lookup file in symlinked directory ==============="
1273
1274 test_26a() {
1275         test_mkdir $DIR/d26
1276         test_mkdir $DIR/d26/d26-2
1277         ln -s d26/d26-2 $DIR/s26
1278         touch $DIR/s26/foo || error
1279 }
1280 run_test 26a "multiple component symlink ======================="
1281
1282 test_26b() {
1283         test_mkdir -p $DIR/d26b/d26-2
1284         ln -s d26b/d26-2/foo $DIR/s26-2
1285         touch $DIR/s26-2 || error
1286 }
1287 run_test 26b "multiple component symlink at end of lookup ======"
1288
1289 test_26c() {
1290         test_mkdir $DIR/d26.2
1291         touch $DIR/d26.2/foo
1292         ln -s d26.2 $DIR/s26.2-1
1293         ln -s s26.2-1 $DIR/s26.2-2
1294         ln -s s26.2-2 $DIR/s26.2-3
1295         chmod 0666 $DIR/s26.2-3/foo
1296 }
1297 run_test 26c "chain of symlinks ================================"
1298
1299 # recursive symlinks (bug 439)
1300 test_26d() {
1301         ln -s d26-3/foo $DIR/d26-3
1302 }
1303 run_test 26d "create multiple component recursive symlink ======"
1304
1305 test_26e() {
1306         [ ! -h $DIR/d26-3 ] && test_26d
1307         rm $DIR/d26-3
1308 }
1309 run_test 26e "unlink multiple component recursive symlink ======"
1310
1311 # recursive symlinks (bug 7022)
1312 test_26f() {
1313         test_mkdir -p $DIR/$tdir
1314         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1315         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1316         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1317         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1318         cd $tfile                || error "cd $tfile failed"
1319         ln -s .. dotdot          || error "ln dotdot failed"
1320         ln -s dotdot/lndir lndir || error "ln lndir failed"
1321         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1322         output=`ls $tfile/$tfile/lndir/bar1`
1323         [ "$output" = bar1 ] && error "unexpected output"
1324         rm -r $tfile             || error "rm $tfile failed"
1325         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1326 }
1327 run_test 26f "rm -r of a directory which has recursive symlink ="
1328
1329 test_27a() {
1330         echo '== stripe sanity =============================================='
1331         test_mkdir -p $DIR/d27 || error "mkdir failed"
1332         $GETSTRIPE $DIR/d27
1333         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1334         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1335         log "== test_27a: write to one stripe file ========================="
1336         cp /etc/hosts $DIR/d27/f0 || error
1337 }
1338 run_test 27a "one stripe file =================================="
1339
1340 test_27b() {
1341         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1342         test_mkdir -p $DIR/d27
1343         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1344         $GETSTRIPE -c $DIR/d27/f01
1345         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1346                 error "two-stripe file doesn't have two stripes"
1347
1348         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1349 }
1350 run_test 27b "create and write to two stripe file"
1351
1352 test_27d() {
1353         test_mkdir -p $DIR/d27
1354         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1355         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1356         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1357 }
1358 run_test 27d "create file with default settings ================"
1359
1360 test_27e() {
1361         # LU-5839 adds check for existed layout before setting it
1362         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1363                 skip "Need MDS version at least 2.7.56" && return
1364         test_mkdir -p $DIR/d27
1365         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1366         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1367         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1368 }
1369 run_test 27e "setstripe existing file (should return error) ======"
1370
1371 test_27f() {
1372         test_mkdir $DIR/$tdir
1373         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1374                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1375         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1376                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1377         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1378         $GETSTRIPE $DIR/$tdir/$tfile || error "$GETSTRIPE failed"
1379 }
1380 run_test 27f "setstripe with bad stripe size (should return error)"
1381
1382 test_27g() {
1383         test_mkdir -p $DIR/d27
1384         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1385         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1386                 error "$DIR/d27/fnone has object"
1387 }
1388 run_test 27g "$GETSTRIPE with no objects"
1389
1390 test_27i() {
1391         test_mkdir $DIR/$tdir
1392         touch $DIR/$tdir/$tfile || error "touch failed"
1393         [[ $($GETSTRIPE -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1394                 error "missing objects"
1395 }
1396 run_test 27i "$GETSTRIPE with some objects"
1397
1398 test_27j() {
1399         test_mkdir -p $DIR/d27
1400         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1401 }
1402 run_test 27j "setstripe with bad stripe offset (should return error)"
1403
1404 test_27k() { # bug 2844
1405         test_mkdir -p $DIR/d27
1406         FILE=$DIR/d27/f27k
1407         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1408         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1409         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1410         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1411         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1412         dd if=/dev/zero of=$FILE bs=4k count=1
1413         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1414         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1415 }
1416 run_test 27k "limit i_blksize for broken user apps ============="
1417
1418 test_27l() {
1419         test_mkdir -p $DIR/d27
1420         mcreate $DIR/f27l || error "creating file"
1421         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1422                 error "setstripe should have failed" || true
1423 }
1424 run_test 27l "check setstripe permissions (should return error)"
1425
1426 test_27m() {
1427         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1428                 return
1429
1430         ORIGFREE=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
1431                    head -n1)
1432         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1433                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1434                 return
1435         fi
1436         trap simple_cleanup_common EXIT
1437         test_mkdir -p $DIR/$tdir
1438         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1439         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1440                 error "dd should fill OST0"
1441         i=2
1442         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1443                 i=$((i + 1))
1444                 [ $i -gt 256 ] && break
1445         done
1446         i=$((i + 1))
1447         touch $DIR/$tdir/f27m_$i
1448         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1449                 error "OST0 was full but new created file still use it"
1450         i=$((i + 1))
1451         touch $DIR/$tdir/f27m_$i
1452         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1453                 error "OST0 was full but new created file still use it"
1454         simple_cleanup_common
1455 }
1456 run_test 27m "create file while OST0 was full =================="
1457
1458 sleep_maxage() {
1459         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1460         sleep $DELAY
1461 }
1462
1463 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1464 # if the OST isn't full anymore.
1465 reset_enospc() {
1466         local OSTIDX=${1:-""}
1467
1468         local list=$(comma_list $(osts_nodes))
1469         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1470
1471         do_nodes $list lctl set_param fail_loc=0
1472         sync    # initiate all OST_DESTROYs from MDS to OST
1473         sleep_maxage
1474 }
1475
1476 exhaust_precreations() {
1477         local OSTIDX=$1
1478         local FAILLOC=$2
1479         local FAILIDX=${3:-$OSTIDX}
1480         local ofacet=ost$((OSTIDX + 1))
1481
1482         test_mkdir -p -c1 $DIR/$tdir
1483         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
1484         local mfacet=mds$((mdtidx + 1))
1485         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1486
1487         local OST=$(ostname_from_index $OSTIDX)
1488
1489         # on the mdt's osc
1490         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1491         local last_id=$(do_facet $mfacet lctl get_param -n \
1492                         osc.$mdtosc_proc1.prealloc_last_id)
1493         local next_id=$(do_facet $mfacet lctl get_param -n \
1494                         osc.$mdtosc_proc1.prealloc_next_id)
1495
1496         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1497         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1498
1499         test_mkdir -p $DIR/$tdir/${OST}
1500         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1501 #define OBD_FAIL_OST_ENOSPC              0x215
1502         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1503         echo "Creating to objid $last_id on ost $OST..."
1504         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1505         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1506         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1507         sleep_maxage
1508 }
1509
1510 exhaust_all_precreations() {
1511         local i
1512         for (( i=0; i < OSTCOUNT; i++ )) ; do
1513                 exhaust_precreations $i $1 -1
1514         done
1515 }
1516
1517 test_27n() {
1518         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1519         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1520         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1521         remote_ost_nodsh && skip "remote OST with nodsh" && return
1522
1523         reset_enospc
1524         rm -f $DIR/$tdir/$tfile
1525         exhaust_precreations 0 0x80000215
1526         $SETSTRIPE -c -1 $DIR/$tdir
1527         touch $DIR/$tdir/$tfile || error
1528         $GETSTRIPE $DIR/$tdir/$tfile
1529         reset_enospc
1530 }
1531 run_test 27n "create file with some full OSTs =================="
1532
1533 test_27o() {
1534         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1535         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1536         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1537         remote_ost_nodsh && skip "remote OST with nodsh" && return
1538
1539         reset_enospc
1540         rm -f $DIR/$tdir/$tfile
1541         exhaust_all_precreations 0x215
1542
1543         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1544
1545         reset_enospc
1546         rm -rf $DIR/$tdir/*
1547 }
1548 run_test 27o "create file with all full OSTs (should error) ===="
1549
1550 test_27p() {
1551         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1552         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1553         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1554         remote_ost_nodsh && skip "remote OST with nodsh" && return
1555
1556         reset_enospc
1557         rm -f $DIR/$tdir/$tfile
1558         test_mkdir -p $DIR/$tdir
1559
1560         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1561         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1562         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1563
1564         exhaust_precreations 0 0x80000215
1565         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1566         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1567         $GETSTRIPE $DIR/$tdir/$tfile
1568
1569         reset_enospc
1570 }
1571 run_test 27p "append to a truncated file with some full OSTs ==="
1572
1573 test_27q() {
1574         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1575         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1576         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1577         remote_ost_nodsh && skip "remote OST with nodsh" && return
1578
1579         reset_enospc
1580         rm -f $DIR/$tdir/$tfile
1581
1582         test_mkdir -p $DIR/$tdir
1583         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1584         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1585         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1586
1587         exhaust_all_precreations 0x215
1588
1589         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1590         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1591
1592         reset_enospc
1593 }
1594 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1595
1596 test_27r() {
1597         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1598         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1599         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1600         remote_ost_nodsh && skip "remote OST with nodsh" && return
1601
1602         reset_enospc
1603         rm -f $DIR/$tdir/$tfile
1604         exhaust_precreations 0 0x80000215
1605
1606         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1607
1608         reset_enospc
1609 }
1610 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1611
1612 test_27s() { # bug 10725
1613         test_mkdir -p $DIR/$tdir
1614         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1615         local stripe_count=0
1616         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1617         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1618                 error "stripe width >= 2^32 succeeded" || true
1619
1620 }
1621 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1622
1623 test_27t() { # bug 10864
1624         WDIR=$(pwd)
1625         WLFS=$(which lfs)
1626         cd $DIR
1627         touch $tfile
1628         $WLFS getstripe $tfile
1629         cd $WDIR
1630 }
1631 run_test 27t "check that utils parse path correctly"
1632
1633 test_27u() { # bug 4900
1634         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1635         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1636         local index
1637         local list=$(comma_list $(mdts_nodes))
1638
1639 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1640         do_nodes $list $LCTL set_param fail_loc=0x139
1641         test_mkdir -p $DIR/$tdir
1642         rm -rf $DIR/$tdir/*
1643         createmany -o $DIR/$tdir/t- 1000
1644         do_nodes $list $LCTL set_param fail_loc=0
1645
1646         TLOG=$DIR/$tfile.getstripe
1647         $GETSTRIPE $DIR/$tdir > $TLOG
1648         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1649         unlinkmany $DIR/$tdir/t- 1000
1650         [[ $OBJS -gt 0 ]] &&
1651                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1652 }
1653 run_test 27u "skip object creation on OSC w/o objects =========="
1654
1655 test_27v() { # bug 4900
1656         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1657         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1658         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1659         remote_ost_nodsh && skip "remote OST with nodsh" && return
1660
1661         exhaust_all_precreations 0x215
1662         reset_enospc
1663
1664         test_mkdir -p $DIR/$tdir
1665         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1666
1667         touch $DIR/$tdir/$tfile
1668         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1669         # all except ost1
1670         for (( i=1; i < OSTCOUNT; i++ )); do
1671                 do_facet ost$i lctl set_param fail_loc=0x705
1672         done
1673         local START=`date +%s`
1674         createmany -o $DIR/$tdir/$tfile 32
1675
1676         local FINISH=`date +%s`
1677         local TIMEOUT=`lctl get_param -n timeout`
1678         local PROCESS=$((FINISH - START))
1679         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1680                error "$FINISH - $START >= $TIMEOUT / 2"
1681         sleep $((TIMEOUT / 2 - PROCESS))
1682         reset_enospc
1683 }
1684 run_test 27v "skip object creation on slow OST ================="
1685
1686 test_27w() { # bug 10997
1687         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1688         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1689         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1690                 error "stripe size $size != 65536" || true
1691         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1692                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1693 }
1694 run_test 27w "check $SETSTRIPE -S option"
1695
1696 test_27wa() {
1697         [[ $OSTCOUNT -lt 2 ]] &&
1698                 skip_env "skipping multiple stripe count/offset test" && return
1699
1700         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1701         for i in $(seq 1 $OSTCOUNT); do
1702                 offset=$((i - 1))
1703                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1704                         error "setstripe -c $i -i $offset failed"
1705                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1706                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1707                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1708                 [ $index -ne $offset ] &&
1709                         error "stripe offset $index != $offset" || true
1710         done
1711 }
1712 run_test 27wa "check $SETSTRIPE -c -i options"
1713
1714 test_27x() {
1715         remote_ost_nodsh && skip "remote OST with nodsh" && return
1716         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1717         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1718         OFFSET=$(($OSTCOUNT - 1))
1719         OSTIDX=0
1720         local OST=$(ostname_from_index $OSTIDX)
1721
1722         test_mkdir -p $DIR/$tdir
1723         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1724         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1725         sleep_maxage
1726         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1727         for i in `seq 0 $OFFSET`; do
1728                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1729                 error "OST0 was degraded but new created file still use it"
1730         done
1731         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1732 }
1733 run_test 27x "create files while OST0 is degraded"
1734
1735 test_27y() {
1736         [[ $OSTCOUNT -lt 2 ]] &&
1737                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1738         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1739         remote_ost_nodsh && skip "remote OST with nodsh" && return
1740         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1741
1742         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1743         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1744             osc.$mdtosc.prealloc_last_id)
1745         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1746             osc.$mdtosc.prealloc_next_id)
1747         local fcount=$((last_id - next_id))
1748         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1749         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1750
1751         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1752                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1753         local OST_DEACTIVE_IDX=-1
1754         local OSC
1755         local OSTIDX
1756         local OST
1757
1758         for OSC in $MDS_OSCS; do
1759                 OST=$(osc_to_ost $OSC)
1760                 OSTIDX=$(index_from_ostuuid $OST)
1761                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1762                         OST_DEACTIVE_IDX=$OSTIDX
1763                 fi
1764                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1765                         echo $OSC "is Deactivated:"
1766                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1767                 fi
1768         done
1769
1770         OSTIDX=$(index_from_ostuuid $OST)
1771         test_mkdir -p $DIR/$tdir
1772         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1773
1774         for OSC in $MDS_OSCS; do
1775                 OST=$(osc_to_ost $OSC)
1776                 OSTIDX=$(index_from_ostuuid $OST)
1777                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1778                         echo $OST "is degraded:"
1779                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1780                                                 obdfilter.$OST.degraded=1
1781                 fi
1782         done
1783
1784         sleep_maxage
1785         createmany -o $DIR/$tdir/$tfile $fcount
1786
1787         for OSC in $MDS_OSCS; do
1788                 OST=$(osc_to_ost $OSC)
1789                 OSTIDX=$(index_from_ostuuid $OST)
1790                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1791                         echo $OST "is recovered from degraded:"
1792                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1793                                                 obdfilter.$OST.degraded=0
1794                 else
1795                         do_facet $SINGLEMDS lctl --device %$OSC activate
1796                 fi
1797         done
1798
1799         # all osp devices get activated, hence -1 stripe count restored
1800         local stripecnt=0
1801
1802         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1803         # devices get activated.
1804         sleep_maxage
1805         $SETSTRIPE -c -1 $DIR/$tfile
1806         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1807         rm -f $DIR/$tfile
1808         [ $stripecnt -ne $OSTCOUNT ] &&
1809                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1810         return 0
1811 }
1812 run_test 27y "create files while OST0 is degraded and the rest inactive"
1813
1814 check_seq_oid()
1815 {
1816         log "check file $1"
1817
1818         lmm_count=$($GETSTRIPE -c $1)
1819         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1820         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1821
1822         local old_ifs="$IFS"
1823         IFS=$'[:]'
1824         fid=($($LFS path2fid $1))
1825         IFS="$old_ifs"
1826
1827         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1828         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1829
1830         # compare lmm_seq and lu_fid->f_seq
1831         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1832         # compare lmm_object_id and lu_fid->oid
1833         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1834
1835         # check the trusted.fid attribute of the OST objects of the file
1836         local have_obdidx=false
1837         local stripe_nr=0
1838         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1839                 # skip lines up to and including "obdidx"
1840                 [ -z "$obdidx" ] && break
1841                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1842                 $have_obdidx || continue
1843
1844                 local ost=$((obdidx + 1))
1845                 local dev=$(ostdevname $ost)
1846                 local oid_hex
1847
1848                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1849
1850                 seq=$(echo $seq | sed -e "s/^0x//g")
1851                 if [ $seq == 0 ] || [ $(facet_fstype ost$ost) == zfs ]; then
1852                         oid_hex=$(echo $oid)
1853                 else
1854                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1855                 fi
1856                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1857
1858                 local ff
1859                 #
1860                 # Don't unmount/remount the OSTs if we don't need to do that.
1861                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1862                 # update too, until that use mount/ll_decode_filter_fid/mount.
1863                 # Re-enable when debugfs will understand new filter_fid.
1864                 #
1865                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1866                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1867                                 $dev 2>/dev/null" | grep "parent=")
1868                 else
1869                         stop ost$ost
1870                         mount_fstype ost$ost
1871                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1872                                 $(facet_mntpt ost$ost)/$obj_file)
1873                         unmount_fstype ost$ost
1874                         start ost$ost $dev $OST_MOUNT_OPTS
1875                         clients_up
1876                 fi
1877
1878                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1879
1880                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1881
1882                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1883                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1884                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1885                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1886                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1887                 local ff_pstripe
1888                 if echo $ff_parent | grep -q 'stripe='; then
1889                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1890                 else
1891                         #
1892                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1893                         # into f_ver in this case.  See the comment on
1894                         # ff_parent.
1895                         #
1896                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1897                                 sed -e 's/\]//')
1898                 fi
1899
1900                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1901                 [ $ff_pseq = $lmm_seq ] ||
1902                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1903                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1904                 [ $ff_poid = $lmm_oid ] ||
1905                         error "FF parent OID $ff_poid != $lmm_oid"
1906                 (($ff_pstripe == $stripe_nr)) ||
1907                         error "FF stripe $ff_pstripe != $stripe_nr"
1908
1909                 stripe_nr=$((stripe_nr + 1))
1910         done
1911 }
1912
1913 test_27z() {
1914         remote_ost_nodsh && skip "remote OST with nodsh" && return
1915         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1916         test_mkdir -p $DIR/$tdir
1917
1918         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1919                 { error "setstripe -c -1 failed"; return 1; }
1920         # We need to send a write to every object to get parent FID info set.
1921         # This _should_ also work for setattr, but does not currently.
1922         # touch $DIR/$tdir/$tfile-1 ||
1923         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1924                 { error "dd $tfile-1 failed"; return 2; }
1925         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1926                 { error "setstripe -c -1 failed"; return 3; }
1927         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1928                 { error "dd $tfile-2 failed"; return 4; }
1929
1930         # make sure write RPCs have been sent to OSTs
1931         sync; sleep 5; sync
1932
1933         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1934         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1935 }
1936 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1937
1938 test_27A() { # b=19102
1939         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1940         local restore_size=$($GETSTRIPE -S $MOUNT)
1941         local restore_count=$($GETSTRIPE -c $MOUNT)
1942         local restore_offset=$($GETSTRIPE -i $MOUNT)
1943         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1944         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1945                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1946         local default_size=$($GETSTRIPE -S $MOUNT)
1947         local default_offset=$($GETSTRIPE -i $MOUNT)
1948         local dsize=$((1024 * 1024))
1949         [ $default_size -eq $dsize ] ||
1950                 error "stripe size $default_size != $dsize"
1951         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1952         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1953 }
1954 run_test 27A "check filesystem-wide default LOV EA values"
1955
1956 test_27B() { # LU-2523
1957         test_mkdir -p $DIR/$tdir
1958         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1959         touch $DIR/$tdir/f0
1960         # open f1 with O_LOV_DELAY_CREATE
1961         # rename f0 onto f1
1962         # call setstripe ioctl on open file descriptor for f1
1963         # close
1964         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1965                 $DIR/$tdir/f0
1966
1967         rm -f $DIR/$tdir/f1
1968         # open f1 with O_LOV_DELAY_CREATE
1969         # unlink f1
1970         # call setstripe ioctl on open file descriptor for f1
1971         # close
1972         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1973
1974         # Allow multiop to fail in imitation of NFS's busted semantics.
1975         true
1976 }
1977 run_test 27B "call setstripe on open unlinked file/rename victim"
1978
1979 test_27C() { #LU-2871
1980         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1981
1982         declare -a ost_idx
1983         local index
1984         local found
1985         local i
1986         local j
1987
1988         test_mkdir -p $DIR/$tdir
1989         cd $DIR/$tdir
1990         for i in $(seq 0 $((OSTCOUNT - 1))); do
1991                 # set stripe across all OSTs starting from OST$i
1992                 $SETSTRIPE -i $i -c -1 $tfile$i
1993                 # get striping information
1994                 ost_idx=($($GETSTRIPE $tfile$i |
1995                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1996                 echo ${ost_idx[@]}
1997
1998                 # check the layout
1999                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
2000                         error "${#ost_idx[@]} != $OSTCOUNT"
2001
2002                 for index in $(seq 0 $((OSTCOUNT - 1))); do
2003                         found=0
2004                         for j in $(echo ${ost_idx[@]}); do
2005                                 if [ $index -eq $j ]; then
2006                                         found=1
2007                                         break
2008                                 fi
2009                         done
2010                         [ $found = 1 ] ||
2011                                 error "Can not find $index in ${ost_idx[@]}"
2012                 done
2013         done
2014 }
2015 run_test 27C "check full striping across all OSTs"
2016
2017 test_27D() {
2018         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2019         local POOL=${POOL:-testpool}
2020         local first_ost=0
2021         local last_ost=$(($OSTCOUNT - 1))
2022         local ost_step=1
2023         local ost_list=$(seq $first_ost $ost_step $last_ost)
2024         local ost_range="$first_ost $last_ost $ost_step"
2025
2026         test_mkdir -p $DIR/$tdir
2027         pool_add $POOL || error "pool_add failed"
2028         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2029         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT ||
2030                 error "llapi_layout_test failed"
2031         cleanup_pools || error "cleanup_pools failed"
2032 }
2033 run_test 27D "validate llapi_layout API"
2034
2035 # Verify that default_easize is increased from its initial value after
2036 # accessing a widely striped file.
2037 test_27E() {
2038         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2039
2040         # 72 bytes is the minimum space required to store striping
2041         # information for a file striped across one OST:
2042         # (sizeof(struct lov_user_md_v3) +
2043         #  sizeof(struct lov_user_ost_data_v1))
2044         local min_easize=72
2045         $LCTL set_param -n llite.*.default_easize $min_easize ||
2046                 error "lctl set_param failed"
2047         local easize=$($LCTL get_param -n llite.*.default_easize)
2048
2049         [ $easize -eq $min_easize ] ||
2050                 error "failed to set default_easize"
2051
2052         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2053                 error "setstripe failed"
2054         cat $DIR/$tfile
2055         rm $DIR/$tfile
2056
2057         easize=$($LCTL get_param -n llite.*.default_easize)
2058
2059         [ $easize -gt $min_easize ] ||
2060                 error "default_easize not updated"
2061 }
2062 run_test 27E "check that default extended attribute size properly increases"
2063
2064 # createtest also checks that device nodes are created and
2065 # then visible correctly (#2091)
2066 test_28() { # bug 2091
2067         test_mkdir $DIR/d28
2068         $CREATETEST $DIR/d28/ct || error
2069 }
2070 run_test 28 "create/mknod/mkdir with bad file types ============"
2071
2072 test_29() {
2073         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2074         cancel_lru_locks mdc
2075         test_mkdir $DIR/d29
2076         touch $DIR/d29/foo
2077         log 'first d29'
2078         ls -l $DIR/d29
2079
2080         declare -i LOCKCOUNTORIG=0
2081         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2082                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2083         done
2084         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
2085
2086         declare -i LOCKUNUSEDCOUNTORIG=0
2087         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2088                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2089         done
2090
2091         log 'second d29'
2092         ls -l $DIR/d29
2093         log 'done'
2094
2095         declare -i LOCKCOUNTCURRENT=0
2096         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2097                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2098         done
2099
2100         declare -i LOCKUNUSEDCOUNTCURRENT=0
2101         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2102                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2103         done
2104
2105         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2106                 $LCTL set_param -n ldlm.dump_namespaces ""
2107                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2108                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2109                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2110                 return 2
2111         fi
2112         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2113                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2114                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2115                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2116                 return 3
2117         fi
2118 }
2119 run_test 29 "IT_GETATTR regression  ============================"
2120
2121 test_30a() { # was test_30
2122         cp $(which ls) $DIR || cp /bin/ls $DIR
2123         $DIR/ls / || error
2124         rm $DIR/ls
2125 }
2126 run_test 30a "execute binary from Lustre (execve) =============="
2127
2128 test_30b() {
2129         cp `which ls` $DIR || cp /bin/ls $DIR
2130         chmod go+rx $DIR/ls
2131         $RUNAS $DIR/ls / || error
2132         rm $DIR/ls
2133 }
2134 run_test 30b "execute binary from Lustre as non-root ==========="
2135
2136 test_30c() { # b=22376
2137         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2138         cp `which ls` $DIR || cp /bin/ls $DIR
2139         chmod a-rw $DIR/ls
2140         cancel_lru_locks mdc
2141         cancel_lru_locks osc
2142         $RUNAS $DIR/ls / || error
2143         rm -f $DIR/ls
2144 }
2145 run_test 30c "execute binary from Lustre without read perms ===="
2146
2147 test_31a() {
2148         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2149         $CHECKSTAT -a $DIR/f31 || error
2150 }
2151 run_test 31a "open-unlink file =================================="
2152
2153 test_31b() {
2154         touch $DIR/f31 || error
2155         ln $DIR/f31 $DIR/f31b || error
2156         $MULTIOP $DIR/f31b Ouc || error
2157         $CHECKSTAT -t file $DIR/f31 || error
2158 }
2159 run_test 31b "unlink file with multiple links while open ======="
2160
2161 test_31c() {
2162         touch $DIR/f31 || error
2163         ln $DIR/f31 $DIR/f31c || error
2164         multiop_bg_pause $DIR/f31 O_uc || return 1
2165         MULTIPID=$!
2166         $MULTIOP $DIR/f31c Ouc
2167         kill -USR1 $MULTIPID
2168         wait $MULTIPID
2169 }
2170 run_test 31c "open-unlink file with multiple links ============="
2171
2172 test_31d() {
2173         opendirunlink $DIR/d31d $DIR/d31d || error
2174         $CHECKSTAT -a $DIR/d31d || error
2175 }
2176 run_test 31d "remove of open directory ========================="
2177
2178 test_31e() { # bug 2904
2179         openfilleddirunlink $DIR/d31e || error
2180 }
2181 run_test 31e "remove of open non-empty directory ==============="
2182
2183 test_31f() { # bug 4554
2184         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2185         set -vx
2186         test_mkdir $DIR/d31f
2187         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2188         cp /etc/hosts $DIR/d31f
2189         ls -l $DIR/d31f
2190         $GETSTRIPE $DIR/d31f/hosts
2191         multiop_bg_pause $DIR/d31f D_c || return 1
2192         MULTIPID=$!
2193
2194         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2195         test_mkdir $DIR/d31f
2196         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2197         cp /etc/hosts $DIR/d31f
2198         ls -l $DIR/d31f
2199         $GETSTRIPE $DIR/d31f/hosts
2200         multiop_bg_pause $DIR/d31f D_c || return 1
2201         MULTIPID2=$!
2202
2203         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2204         wait $MULTIPID || error "first opendir $MULTIPID failed"
2205
2206         sleep 6
2207
2208         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2209         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2210         set +vx
2211 }
2212 run_test 31f "remove of open directory with open-unlink file ==="
2213
2214 test_31g() {
2215         echo "-- cross directory link --"
2216         test_mkdir -c1 $DIR/${tdir}ga
2217         test_mkdir -c1 $DIR/${tdir}gb
2218         touch $DIR/${tdir}ga/f
2219         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2220         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2221         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2222         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2223         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2224 }
2225 run_test 31g "cross directory link==============="
2226
2227 test_31h() {
2228         echo "-- cross directory link --"
2229         test_mkdir -c1 $DIR/${tdir}
2230         test_mkdir -c1 $DIR/${tdir}/dir
2231         touch $DIR/${tdir}/f
2232         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2233         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2234         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2235         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2236         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2237 }
2238 run_test 31h "cross directory link under child==============="
2239
2240 test_31i() {
2241         echo "-- cross directory link --"
2242         test_mkdir -c1 $DIR/$tdir
2243         test_mkdir -c1 $DIR/$tdir/dir
2244         touch $DIR/$tdir/dir/f
2245         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2246         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2247         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2248         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2249         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2250 }
2251 run_test 31i "cross directory link under parent==============="
2252
2253 test_31j() {
2254         test_mkdir -c1 -p $DIR/$tdir
2255         test_mkdir -c1 -p $DIR/$tdir/dir1
2256         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2257         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2258         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2259         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2260         return 0
2261 }
2262 run_test 31j "link for directory==============="
2263
2264 test_31k() {
2265         test_mkdir -c1 -p $DIR/$tdir
2266         touch $DIR/$tdir/s
2267         touch $DIR/$tdir/exist
2268         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2269         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2270         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2271         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2272         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2273         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2274         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2275         return 0
2276 }
2277 run_test 31k "link to file: the same, non-existing, dir==============="
2278
2279 test_31m() {
2280         mkdir $DIR/d31m
2281         touch $DIR/d31m/s
2282         mkdir $DIR/d31m2
2283         touch $DIR/d31m2/exist
2284         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2285         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2286         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2287         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2288         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2289         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2290         return 0
2291 }
2292 run_test 31m "link to file: the same, non-existing, dir==============="
2293
2294 test_31n() {
2295         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2296         nlink=$(stat --format=%h $DIR/$tfile)
2297         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2298         local fd=$(free_fd)
2299         local cmd="exec $fd<$DIR/$tfile"
2300         eval $cmd
2301         cmd="exec $fd<&-"
2302         trap "eval $cmd" EXIT
2303         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2304         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2305         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2306         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2307         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2308         eval $cmd
2309 }
2310 run_test 31n "check link count of unlinked file"
2311
2312 link_one() {
2313         local TEMPNAME=$(mktemp $1_XXXXXX)
2314         mlink $TEMPNAME $1 2> /dev/null &&
2315                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2316         munlink $TEMPNAME
2317 }
2318
2319 test_31o() { # LU-2901
2320         test_mkdir -p $DIR/$tdir
2321         for LOOP in $(seq 100); do
2322                 rm -f $DIR/$tdir/$tfile*
2323                 for THREAD in $(seq 8); do
2324                         link_one $DIR/$tdir/$tfile.$LOOP &
2325                 done
2326                 wait
2327                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2328                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2329                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2330                         break || true
2331         done
2332 }
2333 run_test 31o "duplicate hard links with same filename"
2334
2335 test_31p() {
2336         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2337
2338         test_mkdir $DIR/$tdir
2339         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2340         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2341
2342         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2343                 error "open unlink test1 failed"
2344         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2345                 error "open unlink test2 failed"
2346
2347         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2348                 error "test1 still exists"
2349         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2350                 error "test2 still exists"
2351 }
2352 run_test 31p "remove of open striped directory"
2353
2354 cleanup_test32_mount() {
2355         trap 0
2356         $UMOUNT $DIR/$tdir/ext2-mountpoint
2357 }
2358
2359 test_32a() {
2360         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2361         echo "== more mountpoints and symlinks ================="
2362         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2363         trap cleanup_test32_mount EXIT
2364         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2365         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2366         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2367         cleanup_test32_mount
2368 }
2369 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2370
2371 test_32b() {
2372         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2373         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2374         trap cleanup_test32_mount EXIT
2375         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2376         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2377         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2378         cleanup_test32_mount
2379 }
2380 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2381
2382 test_32c() {
2383         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2384         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2385         trap cleanup_test32_mount EXIT
2386         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2387         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2388         test_mkdir -p $DIR/$tdir/d2/test_dir
2389         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2390         cleanup_test32_mount
2391 }
2392 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2393
2394 test_32d() {
2395         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2396         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2397         trap cleanup_test32_mount EXIT
2398         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2399         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2400         test_mkdir -p $DIR/$tdir/d2/test_dir
2401         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2402         cleanup_test32_mount
2403 }
2404 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2405
2406 test_32e() {
2407         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2408         test_mkdir -p $DIR/d32e/tmp
2409         TMP_DIR=$DIR/d32e/tmp
2410         ln -s $DIR/d32e $TMP_DIR/symlink11
2411         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2412         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2413         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2414 }
2415 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2416
2417 test_32f() {
2418         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2419         test_mkdir -p $DIR/d32f/tmp
2420         TMP_DIR=$DIR/d32f/tmp
2421         ln -s $DIR/d32f $TMP_DIR/symlink11
2422         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2423         ls $DIR/d32f/tmp/symlink11  || error
2424         ls $DIR/d32f/symlink01 || error
2425 }
2426 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2427
2428 test_32g() {
2429         TMP_DIR=$DIR/$tdir/tmp
2430         test_mkdir -p $DIR/$tdir/tmp
2431         test_mkdir $DIR/${tdir}2
2432         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2433         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2434         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2435         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2436         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2437         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2438 }
2439 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2440
2441 test_32h() {
2442         rm -fr $DIR/$tdir $DIR/${tdir}2
2443         TMP_DIR=$DIR/$tdir/tmp
2444         test_mkdir -p $DIR/$tdir/tmp
2445         test_mkdir $DIR/${tdir}2
2446         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2447         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2448         ls $TMP_DIR/symlink12 || error
2449         ls $DIR/$tdir/symlink02  || error
2450 }
2451 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2452
2453 test_32i() {
2454         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2455         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2456         trap cleanup_test32_mount EXIT
2457         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2458         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2459         touch $DIR/$tdir/test_file
2460         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2461         cleanup_test32_mount
2462 }
2463 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2464
2465 test_32j() {
2466         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2467         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2468         trap cleanup_test32_mount EXIT
2469         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2470         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2471         touch $DIR/$tdir/test_file
2472         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2473         cleanup_test32_mount
2474 }
2475 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2476
2477 test_32k() {
2478         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2479         rm -fr $DIR/$tdir
2480         trap cleanup_test32_mount EXIT
2481         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2482         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2483         test_mkdir -p $DIR/$tdir/d2
2484         touch $DIR/$tdir/d2/test_file || error
2485         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2486         cleanup_test32_mount
2487 }
2488 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2489
2490 test_32l() {
2491         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2492         rm -fr $DIR/$tdir
2493         trap cleanup_test32_mount EXIT
2494         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2495         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2496         test_mkdir -p $DIR/$tdir/d2
2497         touch $DIR/$tdir/d2/test_file
2498         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2499         cleanup_test32_mount
2500 }
2501 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2502
2503 test_32m() {
2504         rm -fr $DIR/d32m
2505         test_mkdir -p $DIR/d32m/tmp
2506         TMP_DIR=$DIR/d32m/tmp
2507         ln -s $DIR $TMP_DIR/symlink11
2508         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2509         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2510         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2511 }
2512 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2513
2514 test_32n() {
2515         rm -fr $DIR/d32n
2516         test_mkdir -p $DIR/d32n/tmp
2517         TMP_DIR=$DIR/d32n/tmp
2518         ln -s $DIR $TMP_DIR/symlink11
2519         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2520         ls -l $DIR/d32n/tmp/symlink11  || error
2521         ls -l $DIR/d32n/symlink01 || error
2522 }
2523 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2524
2525 test_32o() {
2526         touch $DIR/$tfile
2527         test_mkdir -p $DIR/d32o/tmp
2528         TMP_DIR=$DIR/d32o/tmp
2529         ln -s $DIR/$tfile $TMP_DIR/symlink12
2530         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2531         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2532         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2533         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2534         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2535 }
2536 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2537
2538 test_32p() {
2539     log 32p_1
2540         rm -fr $DIR/d32p
2541     log 32p_2
2542         rm -f $DIR/$tfile
2543     log 32p_3
2544         touch $DIR/$tfile
2545     log 32p_4
2546         test_mkdir -p $DIR/d32p/tmp
2547     log 32p_5
2548         TMP_DIR=$DIR/d32p/tmp
2549     log 32p_6
2550         ln -s $DIR/$tfile $TMP_DIR/symlink12
2551     log 32p_7
2552         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2553     log 32p_8
2554         cat $DIR/d32p/tmp/symlink12 || error
2555     log 32p_9
2556         cat $DIR/d32p/symlink02 || error
2557     log 32p_10
2558 }
2559 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2560
2561 cleanup_testdir_mount() {
2562         trap 0
2563         $UMOUNT $DIR/$tdir
2564 }
2565
2566 test_32q() {
2567         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2568         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2569         trap cleanup_testdir_mount EXIT
2570         test_mkdir -p $DIR/$tdir
2571         touch $DIR/$tdir/under_the_mount
2572         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2573         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2574         cleanup_testdir_mount
2575 }
2576 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2577
2578 test_32r() {
2579         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2580         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2581         trap cleanup_testdir_mount EXIT
2582         test_mkdir -p $DIR/$tdir
2583         touch $DIR/$tdir/under_the_mount
2584         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2585         ls $DIR/$tdir | grep -q under_the_mount && error || true
2586         cleanup_testdir_mount
2587 }
2588 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2589
2590 test_33aa() {
2591         rm -f $DIR/$tfile
2592         touch $DIR/$tfile
2593         chmod 444 $DIR/$tfile
2594         chown $RUNAS_ID $DIR/$tfile
2595         log 33_1
2596         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2597         log 33_2
2598 }
2599 run_test 33aa "write file with mode 444 (should return error) ===="
2600
2601 test_33a() {
2602         rm -fr $DIR/d33
2603         test_mkdir -p $DIR/d33
2604         chown $RUNAS_ID $DIR/d33
2605         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2606         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2607                 error "open RDWR" || true
2608 }
2609 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2610
2611 test_33b() {
2612         rm -fr $DIR/d33
2613         test_mkdir -p $DIR/d33
2614         chown $RUNAS_ID $DIR/d33
2615         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 || true
2616 }
2617 run_test 33b "test open file with malformed flags (No panic)"
2618
2619 test_33c() {
2620         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2621         local ostnum
2622         local ostname
2623         local write_bytes
2624         local all_zeros
2625
2626         remote_ost_nodsh && skip "remote OST with nodsh" && return
2627         all_zeros=:
2628         rm -fr $DIR/d33
2629         test_mkdir -p $DIR/d33
2630         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2631
2632         sync
2633         for ostnum in $(seq $OSTCOUNT); do
2634                 # test-framework's OST numbering is one-based, while Lustre's
2635                 # is zero-based
2636                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2637                 # Parsing llobdstat's output sucks; we could grep the /proc
2638                 # path, but that's likely to not be as portable as using the
2639                 # llobdstat utility.  So we parse lctl output instead.
2640                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2641                         obdfilter/$ostname/stats |
2642                         awk '/^write_bytes/ {print $7}' )
2643                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2644                 if (( ${write_bytes:-0} > 0 ))
2645                 then
2646                         all_zeros=false
2647                         break;
2648                 fi
2649         done
2650
2651         $all_zeros || return 0
2652
2653         # Write four bytes
2654         echo foo > $DIR/d33/bar
2655         # Really write them
2656         sync
2657
2658         # Total up write_bytes after writing.  We'd better find non-zeros.
2659         for ostnum in $(seq $OSTCOUNT); do
2660                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2661                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2662                         obdfilter/$ostname/stats |
2663                         awk '/^write_bytes/ {print $7}' )
2664                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2665                 if (( ${write_bytes:-0} > 0 ))
2666                 then
2667                         all_zeros=false
2668                         break;
2669                 fi
2670         done
2671
2672         if $all_zeros
2673         then
2674                 for ostnum in $(seq $OSTCOUNT); do
2675                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2676                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2677                         do_facet ost$ostnum lctl get_param -n \
2678                                 obdfilter/$ostname/stats
2679                 done
2680                 error "OST not keeping write_bytes stats (b22312)"
2681         fi
2682 }
2683 run_test 33c "test llobdstat and write_bytes"
2684
2685 test_33d() {
2686         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2687         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2688         local MDTIDX=1
2689         local remote_dir=$DIR/$tdir/remote_dir
2690
2691         test_mkdir -p $DIR/$tdir
2692         $LFS mkdir -i $MDTIDX $remote_dir ||
2693                 error "create remote directory failed"
2694
2695         touch $remote_dir/$tfile
2696         chmod 444 $remote_dir/$tfile
2697         chown $RUNAS_ID $remote_dir/$tfile
2698
2699         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2700
2701         chown $RUNAS_ID $remote_dir
2702         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2703                                         error "create" || true
2704         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2705                                     error "open RDWR" || true
2706         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 || true
2707 }
2708 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2709
2710 test_33e() {
2711         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2712
2713         mkdir $DIR/$tdir
2714
2715         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2716         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2717         mkdir $DIR/$tdir/local_dir
2718
2719         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2720         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2721         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2722
2723         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2724                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2725
2726         rmdir $DIR/$tdir/* || error "rmdir failed"
2727
2728         umask 777
2729         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2730         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2731         mkdir $DIR/$tdir/local_dir
2732
2733         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2734         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2735         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2736
2737         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2738                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2739
2740         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2741
2742         umask 000
2743         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2744         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2745         mkdir $DIR/$tdir/local_dir
2746
2747         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2748         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2749         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2750
2751         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2752                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2753 }
2754 run_test 33e "mkdir and striped directory should have same mode"
2755
2756 cleanup_33f() {
2757         trap 0
2758         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
2759 }
2760
2761 test_33f() {
2762         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2763
2764         mkdir $DIR/$tdir
2765         chmod go+rwx $DIR/$tdir
2766         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
2767         trap cleanup_33f EXIT
2768
2769         $RUNAS lfs mkdir -c$MDSCOUNT $DIR/$tdir/striped_dir ||
2770                 error "cannot create striped directory"
2771
2772         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
2773                 error "cannot create files in striped directory"
2774
2775         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
2776                 error "cannot remove files in striped directory"
2777
2778         $RUNAS rmdir $DIR/$tdir/striped_dir ||
2779                 error "cannot remove striped directory"
2780
2781         cleanup_33f
2782 }
2783 run_test 33f "nonroot user can create, access, and remove a striped directory"
2784
2785 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2786 test_34a() {
2787         rm -f $DIR/f34
2788         $MCREATE $DIR/f34 || error
2789         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2790         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2791         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2792         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2793 }
2794 run_test 34a "truncate file that has not been opened ==========="
2795
2796 test_34b() {
2797         [ ! -f $DIR/f34 ] && test_34a
2798         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2799         $OPENFILE -f O_RDONLY $DIR/f34
2800         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2801         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2802 }
2803 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2804
2805 test_34c() {
2806         [ ! -f $DIR/f34 ] && test_34a
2807         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2808         $OPENFILE -f O_RDWR $DIR/f34
2809         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2810         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2811 }
2812 run_test 34c "O_RDWR opening file-with-size works =============="
2813
2814 test_34d() {
2815         [ ! -f $DIR/f34 ] && test_34a
2816         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2817         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2818         rm $DIR/f34
2819 }
2820 run_test 34d "write to sparse file ============================="
2821
2822 test_34e() {
2823         rm -f $DIR/f34e
2824         $MCREATE $DIR/f34e || error
2825         $TRUNCATE $DIR/f34e 1000 || error
2826         $CHECKSTAT -s 1000 $DIR/f34e || error
2827         $OPENFILE -f O_RDWR $DIR/f34e
2828         $CHECKSTAT -s 1000 $DIR/f34e || error
2829 }
2830 run_test 34e "create objects, some with size and some without =="
2831
2832 test_34f() { # bug 6242, 6243
2833         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2834         SIZE34F=48000
2835         rm -f $DIR/f34f
2836         $MCREATE $DIR/f34f || error
2837         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2838         dd if=$DIR/f34f of=$TMP/f34f
2839         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2840         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2841         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2842         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2843         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2844 }
2845 run_test 34f "read from a file with no objects until EOF ======="
2846
2847 test_34g() {
2848         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2849         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2850         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2851         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2852         cancel_lru_locks osc
2853         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2854                 error "wrong size after lock cancel"
2855
2856         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2857         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2858                 error "expanding truncate failed"
2859         cancel_lru_locks osc
2860         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2861                 error "wrong expanded size after lock cancel"
2862 }
2863 run_test 34g "truncate long file ==============================="
2864
2865 test_34h() {
2866         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2867         local gid=10
2868         local sz=1000
2869
2870         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2871         sync # Flush the cache so that multiop below does not block on cache
2872              # flush when getting the group lock
2873         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2874         MULTIPID=$!
2875
2876         # Since just timed wait is not good enough, let's do a sync write
2877         # that way we are sure enough time for a roundtrip + processing
2878         # passed + 2 seconds of extra margin.
2879         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2880         rm $DIR/${tfile}-1
2881         sleep 2
2882
2883         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2884                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2885                 kill -9 $MULTIPID
2886         fi
2887         wait $MULTIPID
2888         local nsz=`stat -c %s $DIR/$tfile`
2889         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2890 }
2891 run_test 34h "ftruncate file under grouplock should not block"
2892
2893 test_35a() {
2894         cp /bin/sh $DIR/f35a
2895         chmod 444 $DIR/f35a
2896         chown $RUNAS_ID $DIR/f35a
2897         $RUNAS $DIR/f35a && error || true
2898         rm $DIR/f35a
2899 }
2900 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2901
2902 test_36a() {
2903         rm -f $DIR/f36
2904         utime $DIR/f36 || error
2905 }
2906 run_test 36a "MDS utime check (mknod, utime) ==================="
2907
2908 test_36b() {
2909         echo "" > $DIR/f36
2910         utime $DIR/f36 || error
2911 }
2912 run_test 36b "OST utime check (open, utime) ===================="
2913
2914 test_36c() {
2915         rm -f $DIR/d36/f36
2916         test_mkdir $DIR/d36
2917         chown $RUNAS_ID $DIR/d36
2918         $RUNAS utime $DIR/d36/f36 || error
2919 }
2920 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2921
2922 test_36d() {
2923         [ ! -d $DIR/d36 ] && test_36c
2924         echo "" > $DIR/d36/f36
2925         $RUNAS utime $DIR/d36/f36 || error
2926 }
2927 run_test 36d "non-root OST utime check (open, utime) ==========="
2928
2929 test_36e() {
2930         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2931         test_mkdir -p $DIR/$tdir
2932         touch $DIR/$tdir/$tfile
2933         $RUNAS utime $DIR/$tdir/$tfile && \
2934                 error "utime worked, expected failure" || true
2935 }
2936 run_test 36e "utime on non-owned file (should return error) ===="
2937
2938 subr_36fh() {
2939         local fl="$1"
2940         local LANG_SAVE=$LANG
2941         local LC_LANG_SAVE=$LC_LANG
2942         export LANG=C LC_LANG=C # for date language
2943
2944         DATESTR="Dec 20  2000"
2945         test_mkdir -p $DIR/$tdir
2946         lctl set_param fail_loc=$fl
2947         date; date +%s
2948         cp /etc/hosts $DIR/$tdir/$tfile
2949         sync & # write RPC generated with "current" inode timestamp, but delayed
2950         sleep 1
2951         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2952         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2953         cancel_lru_locks osc
2954         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2955         date; date +%s
2956         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2957                 echo "BEFORE: $LS_BEFORE" && \
2958                 echo "AFTER : $LS_AFTER" && \
2959                 echo "WANT  : $DATESTR" && \
2960                 error "$DIR/$tdir/$tfile timestamps changed" || true
2961
2962         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2963 }
2964
2965 test_36f() {
2966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2967         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2968         subr_36fh "0x80000214"
2969 }
2970 run_test 36f "utime on file racing with OST BRW write =========="
2971
2972 test_36g() {
2973         remote_ost_nodsh && skip "remote OST with nodsh" && return
2974         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2975         local fmd_max_age
2976         local fmd_before
2977         local fmd_after
2978
2979         test_mkdir -p $DIR/$tdir
2980         fmd_max_age=$(do_facet ost1 \
2981                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2982                 head -n 1")
2983
2984         fmd_before=$(do_facet ost1 \
2985                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2986         touch $DIR/$tdir/$tfile
2987         sleep $((fmd_max_age + 12))
2988         fmd_after=$(do_facet ost1 \
2989                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2990
2991         echo "fmd_before: $fmd_before"
2992         echo "fmd_after: $fmd_after"
2993         [[ $fmd_after -gt $fmd_before ]] &&
2994                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
2995                 error "fmd didn't expire after ping" || true
2996 }
2997 run_test 36g "filter mod data cache expiry ====================="
2998
2999 test_36h() {
3000         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3001         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
3002         subr_36fh "0x80000227"
3003 }
3004 run_test 36h "utime on file racing with OST BRW write =========="
3005
3006 test_36i() {
3007         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3008
3009         test_mkdir $DIR/$tdir
3010         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
3011
3012         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3013         local new_mtime=$((mtime + 200))
3014
3015         #change Modify time of striped dir
3016         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3017                         error "change mtime failed"
3018
3019         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3020
3021         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3022 }
3023 run_test 36i "change mtime on striped directory"
3024
3025 # test_37 - duplicate with tests 32q 32r
3026
3027 test_38() {
3028         local file=$DIR/$tfile
3029         touch $file
3030         openfile -f O_DIRECTORY $file
3031         local RC=$?
3032         local ENOTDIR=20
3033         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3034         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3035 }
3036 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3037
3038 test_39() {
3039         touch $DIR/$tfile
3040         touch $DIR/${tfile}2
3041 #       ls -l  $DIR/$tfile $DIR/${tfile}2
3042 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
3043 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
3044         sleep 2
3045         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3046         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3047                 echo "mtime"
3048                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3049                 echo "atime"
3050                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3051                 echo "ctime"
3052                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3053                 error "O_TRUNC didn't change timestamps"
3054         fi
3055 }
3056 run_test 39 "mtime changed on create ==========================="
3057
3058 test_39b() {
3059         test_mkdir -p -c1 $DIR/$tdir
3060         cp -p /etc/passwd $DIR/$tdir/fopen
3061         cp -p /etc/passwd $DIR/$tdir/flink
3062         cp -p /etc/passwd $DIR/$tdir/funlink
3063         cp -p /etc/passwd $DIR/$tdir/frename
3064         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3065
3066         sleep 1
3067         echo "aaaaaa" >> $DIR/$tdir/fopen
3068         echo "aaaaaa" >> $DIR/$tdir/flink
3069         echo "aaaaaa" >> $DIR/$tdir/funlink
3070         echo "aaaaaa" >> $DIR/$tdir/frename
3071
3072         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3073         local link_new=`stat -c %Y $DIR/$tdir/flink`
3074         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3075         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3076
3077         cat $DIR/$tdir/fopen > /dev/null
3078         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3079         rm -f $DIR/$tdir/funlink2
3080         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3081
3082         for (( i=0; i < 2; i++ )) ; do
3083                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3084                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3085                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3086                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3087
3088                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3089                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3090                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3091                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3092
3093                 cancel_lru_locks osc
3094                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3095         done
3096 }
3097 run_test 39b "mtime change on open, link, unlink, rename  ======"
3098
3099 # this should be set to past
3100 TEST_39_MTIME=`date -d "1 year ago" +%s`
3101
3102 # bug 11063
3103 test_39c() {
3104         touch $DIR1/$tfile
3105         sleep 2
3106         local mtime0=`stat -c %Y $DIR1/$tfile`
3107
3108         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3109         local mtime1=`stat -c %Y $DIR1/$tfile`
3110         [ "$mtime1" = $TEST_39_MTIME ] || \
3111                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3112
3113         local d1=`date +%s`
3114         echo hello >> $DIR1/$tfile
3115         local d2=`date +%s`
3116         local mtime2=`stat -c %Y $DIR1/$tfile`
3117         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3118                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3119
3120         mv $DIR1/$tfile $DIR1/$tfile-1
3121
3122         for (( i=0; i < 2; i++ )) ; do
3123                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3124                 [ "$mtime2" = "$mtime3" ] || \
3125                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3126
3127                 cancel_lru_locks osc
3128                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3129         done
3130 }
3131 run_test 39c "mtime change on rename ==========================="
3132
3133 # bug 21114
3134 test_39d() {
3135         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3136         touch $DIR1/$tfile
3137
3138         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3139
3140         for (( i=0; i < 2; i++ )) ; do
3141                 local mtime=`stat -c %Y $DIR1/$tfile`
3142                 [ $mtime = $TEST_39_MTIME ] || \
3143                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3144
3145                 cancel_lru_locks osc
3146                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3147         done
3148 }
3149 run_test 39d "create, utime, stat =============================="
3150
3151 # bug 21114
3152 test_39e() {
3153         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3154         touch $DIR1/$tfile
3155         local mtime1=`stat -c %Y $DIR1/$tfile`
3156
3157         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3158
3159         for (( i=0; i < 2; i++ )) ; do
3160                 local mtime2=`stat -c %Y $DIR1/$tfile`
3161                 [ $mtime2 = $TEST_39_MTIME ] || \
3162                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3163
3164                 cancel_lru_locks osc
3165                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3166         done
3167 }
3168 run_test 39e "create, stat, utime, stat ========================"
3169
3170 # bug 21114
3171 test_39f() {
3172         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3173         touch $DIR1/$tfile
3174         mtime1=`stat -c %Y $DIR1/$tfile`
3175
3176         sleep 2
3177         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3178
3179         for (( i=0; i < 2; i++ )) ; do
3180                 local mtime2=`stat -c %Y $DIR1/$tfile`
3181                 [ $mtime2 = $TEST_39_MTIME ] || \
3182                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3183
3184                 cancel_lru_locks osc
3185                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3186         done
3187 }
3188 run_test 39f "create, stat, sleep, utime, stat ================="
3189
3190 # bug 11063
3191 test_39g() {
3192         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3193         echo hello >> $DIR1/$tfile
3194         local mtime1=`stat -c %Y $DIR1/$tfile`
3195
3196         sleep 2
3197         chmod o+r $DIR1/$tfile
3198
3199         for (( i=0; i < 2; i++ )) ; do
3200                 local mtime2=`stat -c %Y $DIR1/$tfile`
3201                 [ "$mtime1" = "$mtime2" ] || \
3202                         error "lost mtime: $mtime2, should be $mtime1"
3203
3204                 cancel_lru_locks osc
3205                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3206         done
3207 }
3208 run_test 39g "write, chmod, stat ==============================="
3209
3210 # bug 11063
3211 test_39h() {
3212         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3213         touch $DIR1/$tfile
3214         sleep 1
3215
3216         local d1=`date`
3217         echo hello >> $DIR1/$tfile
3218         local mtime1=`stat -c %Y $DIR1/$tfile`
3219
3220         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3221         local d2=`date`
3222         if [ "$d1" != "$d2" ]; then
3223                 echo "write and touch not within one second"
3224         else
3225                 for (( i=0; i < 2; i++ )) ; do
3226                         local mtime2=`stat -c %Y $DIR1/$tfile`
3227                         [ "$mtime2" = $TEST_39_MTIME ] || \
3228                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3229
3230                         cancel_lru_locks osc
3231                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3232                 done
3233         fi
3234 }
3235 run_test 39h "write, utime within one second, stat ============="
3236
3237 test_39i() {
3238         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3239         touch $DIR1/$tfile
3240         sleep 1
3241
3242         echo hello >> $DIR1/$tfile
3243         local mtime1=`stat -c %Y $DIR1/$tfile`
3244
3245         mv $DIR1/$tfile $DIR1/$tfile-1
3246
3247         for (( i=0; i < 2; i++ )) ; do
3248                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3249
3250                 [ "$mtime1" = "$mtime2" ] || \
3251                         error "lost mtime: $mtime2, should be $mtime1"
3252
3253                 cancel_lru_locks osc
3254                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3255         done
3256 }
3257 run_test 39i "write, rename, stat =============================="
3258
3259 test_39j() {
3260         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3261         start_full_debug_logging
3262         touch $DIR1/$tfile
3263         sleep 1
3264
3265         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3266         lctl set_param fail_loc=0x80000412
3267         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3268                 error "multiop failed"
3269         local multipid=$!
3270         local mtime1=`stat -c %Y $DIR1/$tfile`
3271
3272         mv $DIR1/$tfile $DIR1/$tfile-1
3273
3274         kill -USR1 $multipid
3275         wait $multipid || error "multiop close failed"
3276
3277         for (( i=0; i < 2; i++ )) ; do
3278                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3279                 [ "$mtime1" = "$mtime2" ] ||
3280                         error "mtime is lost on close: $mtime2, " \
3281                               "should be $mtime1"
3282
3283                 cancel_lru_locks osc
3284                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3285         done
3286         lctl set_param fail_loc=0
3287         stop_full_debug_logging
3288 }
3289 run_test 39j "write, rename, close, stat ======================="
3290
3291 test_39k() {
3292         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3293         touch $DIR1/$tfile
3294         sleep 1
3295
3296         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3297         local multipid=$!
3298         local mtime1=`stat -c %Y $DIR1/$tfile`
3299
3300         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3301
3302         kill -USR1 $multipid
3303         wait $multipid || error "multiop close failed"
3304
3305         for (( i=0; i < 2; i++ )) ; do
3306                 local mtime2=`stat -c %Y $DIR1/$tfile`
3307
3308                 [ "$mtime2" = $TEST_39_MTIME ] || \
3309                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3310
3311                 cancel_lru_locks osc
3312                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3313         done
3314 }
3315 run_test 39k "write, utime, close, stat ========================"
3316
3317 # this should be set to future
3318 TEST_39_ATIME=`date -d "1 year" +%s`
3319
3320 test_39l() {
3321         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3322         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3323         local atime_diff=$(do_facet $SINGLEMDS \
3324                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3325         rm -rf $DIR/$tdir
3326         mkdir -p $DIR/$tdir
3327
3328         # test setting directory atime to future
3329         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3330         local atime=$(stat -c %X $DIR/$tdir)
3331         [ "$atime" = $TEST_39_ATIME ] || \
3332                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3333
3334         # test setting directory atime from future to now
3335         local d1=$(date +%s)
3336         ls $DIR/$tdir
3337         local d2=$(date +%s)
3338
3339         cancel_lru_locks mdc
3340         atime=$(stat -c %X $DIR/$tdir)
3341         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3342                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3343
3344         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3345         sleep 3
3346
3347         # test setting directory atime when now > dir atime + atime_diff
3348         d1=$(date +%s)
3349         ls $DIR/$tdir
3350         d2=$(date +%s)
3351         cancel_lru_locks mdc
3352         atime=$(stat -c %X $DIR/$tdir)
3353         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3354                 error "atime is not updated  : $atime, should be $d2"
3355
3356         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3357         sleep 3
3358
3359         # test not setting directory atime when now < dir atime + atime_diff
3360         ls $DIR/$tdir
3361         cancel_lru_locks mdc
3362         atime=$(stat -c %X $DIR/$tdir)
3363         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3364                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3365
3366         do_facet $SINGLEMDS \
3367                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3368 }
3369 run_test 39l "directory atime update ==========================="
3370
3371 test_39m() {
3372         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3373         touch $DIR1/$tfile
3374         sleep 2
3375         local far_past_mtime=$(date -d "May 29 1953" +%s)
3376         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3377
3378         touch -m -d @$far_past_mtime $DIR1/$tfile
3379         touch -a -d @$far_past_atime $DIR1/$tfile
3380
3381         for (( i=0; i < 2; i++ )) ; do
3382                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3383                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3384                         error "atime or mtime set incorrectly"
3385
3386                 cancel_lru_locks osc
3387                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3388         done
3389 }
3390 run_test 39m "test atime and mtime before 1970"
3391
3392 test_39n() { # LU-3832
3393         local atime_diff=$(do_facet $SINGLEMDS \
3394                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3395         local atime0
3396         local atime1
3397         local atime2
3398
3399         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3400
3401         rm -rf $DIR/$tfile
3402         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3403         atime0=$(stat -c %X $DIR/$tfile)
3404
3405         sleep 5
3406         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3407         atime1=$(stat -c %X $DIR/$tfile)
3408
3409         sleep 5
3410         cancel_lru_locks mdc
3411         cancel_lru_locks osc
3412         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3413         atime2=$(stat -c %X $DIR/$tfile)
3414
3415         do_facet $SINGLEMDS \
3416                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3417
3418         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3419         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3420 }
3421 run_test 39n "check that O_NOATIME is honored"
3422
3423 test_39o() {
3424         TESTDIR=$DIR/$tdir/$tfile
3425         [ -e $TESTDIR ] && rm -rf $TESTDIR
3426         mkdir -p $TESTDIR
3427         cd $TESTDIR
3428         links1=2
3429         ls
3430         mkdir a b
3431         ls
3432         links2=$(stat -c %h .)
3433         [ $(($links1 + 2)) != $links2 ] &&
3434                 error "wrong links count $(($links1 + 2)) != $links2"
3435         rmdir b
3436         links3=$(stat -c %h .)
3437         [ $(($links1 + 1)) != $links3 ] &&
3438                 error "wrong links count $links1 != $links3"
3439         return 0
3440 }
3441 run_test 39o "directory cached attributes updated after create ========"
3442
3443 test_39p() {
3444         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3445         local MDTIDX=1
3446         TESTDIR=$DIR/$tdir/$tfile
3447         [ -e $TESTDIR ] && rm -rf $TESTDIR
3448         test_mkdir -p $TESTDIR
3449         cd $TESTDIR
3450         links1=2
3451         ls
3452         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3453         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3454         ls
3455         links2=$(stat -c %h .)
3456         [ $(($links1 + 2)) != $links2 ] &&
3457                 error "wrong links count $(($links1 + 2)) != $links2"
3458         rmdir remote_dir2
3459         links3=$(stat -c %h .)
3460         [ $(($links1 + 1)) != $links3 ] &&
3461                 error "wrong links count $links1 != $links3"
3462         return 0
3463 }
3464 run_test 39p "remote directory cached attributes updated after create ========"
3465
3466
3467 test_40() {
3468         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3469         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3470                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3471         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3472                 error "$tfile is not 4096 bytes in size"
3473 }
3474 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3475
3476 test_41() {
3477         # bug 1553
3478         small_write $DIR/f41 18
3479 }
3480 run_test 41 "test small file write + fstat ====================="
3481
3482 count_ost_writes() {
3483         lctl get_param -n osc.*.stats |
3484                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3485                         END { printf("%0.0f", writes) }'
3486 }
3487
3488 # decent default
3489 WRITEBACK_SAVE=500
3490 DIRTY_RATIO_SAVE=40
3491 MAX_DIRTY_RATIO=50
3492 BG_DIRTY_RATIO_SAVE=10
3493 MAX_BG_DIRTY_RATIO=25
3494
3495 start_writeback() {
3496         trap 0
3497         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3498         # dirty_ratio, dirty_background_ratio
3499         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3500                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3501                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3502                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3503         else
3504                 # if file not here, we are a 2.4 kernel
3505                 kill -CONT `pidof kupdated`
3506         fi
3507 }
3508
3509 stop_writeback() {
3510         # setup the trap first, so someone cannot exit the test at the
3511         # exact wrong time and mess up a machine
3512         trap start_writeback EXIT
3513         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3514         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3515                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3516                 sysctl -w vm.dirty_writeback_centisecs=0
3517                 sysctl -w vm.dirty_writeback_centisecs=0
3518                 # save and increase /proc/sys/vm/dirty_ratio
3519                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3520                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3521                 # save and increase /proc/sys/vm/dirty_background_ratio
3522                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3523                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3524         else
3525                 # if file not here, we are a 2.4 kernel
3526                 kill -STOP `pidof kupdated`
3527         fi
3528 }
3529
3530 # ensure that all stripes have some grant before we test client-side cache
3531 setup_test42() {
3532         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3533                 dd if=/dev/zero of=$i bs=4k count=1
3534                 rm $i
3535         done
3536 }
3537
3538 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3539 # file truncation, and file removal.
3540 test_42a() {
3541         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3542         setup_test42
3543         cancel_lru_locks osc
3544         stop_writeback
3545         sync; sleep 1; sync # just to be safe
3546         BEFOREWRITES=`count_ost_writes`
3547         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3548         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3549         AFTERWRITES=`count_ost_writes`
3550         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3551                 error "$BEFOREWRITES < $AFTERWRITES"
3552         start_writeback
3553 }
3554 run_test 42a "ensure that we don't flush on close =============="
3555
3556 test_42b() {
3557         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3558         setup_test42
3559         cancel_lru_locks osc
3560         stop_writeback
3561         sync
3562         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3563         BEFOREWRITES=$(count_ost_writes)
3564         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3565         AFTERWRITES=$(count_ost_writes)
3566         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3567                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3568         fi
3569         BEFOREWRITES=$(count_ost_writes)
3570         sync || error "sync: $?"
3571         AFTERWRITES=$(count_ost_writes)
3572         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3573                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3574         fi
3575         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3576         start_writeback
3577         return 0
3578 }
3579 run_test 42b "test destroy of file with cached dirty data ======"
3580
3581 # if these tests just want to test the effect of truncation,
3582 # they have to be very careful.  consider:
3583 # - the first open gets a {0,EOF}PR lock
3584 # - the first write conflicts and gets a {0, count-1}PW
3585 # - the rest of the writes are under {count,EOF}PW
3586 # - the open for truncate tries to match a {0,EOF}PR
3587 #   for the filesize and cancels the PWs.
3588 # any number of fixes (don't get {0,EOF} on open, match
3589 # composite locks, do smarter file size management) fix
3590 # this, but for now we want these tests to verify that
3591 # the cancellation with truncate intent works, so we
3592 # start the file with a full-file pw lock to match against
3593 # until the truncate.
3594 trunc_test() {
3595         test=$1
3596         file=$DIR/$test
3597         offset=$2
3598         cancel_lru_locks osc
3599         stop_writeback
3600         # prime the file with 0,EOF PW to match
3601         touch $file
3602         $TRUNCATE $file 0
3603         sync; sync
3604         # now the real test..
3605         dd if=/dev/zero of=$file bs=1024 count=100
3606         BEFOREWRITES=`count_ost_writes`
3607         $TRUNCATE $file $offset
3608         cancel_lru_locks osc
3609         AFTERWRITES=`count_ost_writes`
3610         start_writeback
3611 }
3612
3613 test_42c() {
3614         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3615         trunc_test 42c 1024
3616         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3617             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3618         rm $file
3619 }
3620 run_test 42c "test partial truncate of file with cached dirty data"
3621
3622 test_42d() {
3623         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3624         trunc_test 42d 0
3625         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3626             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3627         rm $file
3628 }
3629 run_test 42d "test complete truncate of file with cached dirty data"
3630
3631 test_42e() { # bug22074
3632         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3633         local TDIR=$DIR/${tdir}e
3634         local pagesz=$(page_size)
3635         local pages=16 # hardcoded 16 pages, don't change it.
3636         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3637         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3638         local max_dirty_mb
3639         local warmup_files
3640
3641         test_mkdir -p $DIR/${tdir}e
3642         $SETSTRIPE -c 1 $TDIR
3643         createmany -o $TDIR/f $files
3644
3645         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3646
3647         # we assume that with $OSTCOUNT files, at least one of them will
3648         # be allocated on OST0.
3649         warmup_files=$((OSTCOUNT * max_dirty_mb))
3650         createmany -o $TDIR/w $warmup_files
3651
3652         # write a large amount of data into one file and sync, to get good
3653         # avail_grant number from OST.
3654         for ((i=0; i<$warmup_files; i++)); do
3655                 idx=$($GETSTRIPE -i $TDIR/w$i)
3656                 [ $idx -ne 0 ] && continue
3657                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3658                 break
3659         done
3660         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3661         sync
3662         $LCTL get_param $proc_osc0/cur_dirty_bytes
3663         $LCTL get_param $proc_osc0/cur_grant_bytes
3664
3665         # create as much dirty pages as we can while not to trigger the actual
3666         # RPCs directly. but depends on the env, VFS may trigger flush during this
3667         # period, hopefully we are good.
3668         for ((i=0; i<$warmup_files; i++)); do
3669                 idx=$($GETSTRIPE -i $TDIR/w$i)
3670                 [ $idx -ne 0 ] && continue
3671                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3672         done
3673         $LCTL get_param $proc_osc0/cur_dirty_bytes
3674         $LCTL get_param $proc_osc0/cur_grant_bytes
3675
3676         # perform the real test
3677         $LCTL set_param $proc_osc0/rpc_stats 0
3678         for ((;i<$files; i++)); do
3679                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3680                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3681         done
3682         sync
3683         $LCTL get_param $proc_osc0/rpc_stats
3684
3685         local percent=0
3686         local have_ppr=false
3687         $LCTL get_param $proc_osc0/rpc_stats |
3688                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3689                         # skip lines until we are at the RPC histogram data
3690                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3691                         $have_ppr || continue
3692
3693                         # we only want the percent stat for < 16 pages
3694                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3695
3696                         percent=$((percent + WPCT))
3697                         if [[ $percent -gt 15 ]]; then
3698                                 error "less than 16-pages write RPCs" \
3699                                       "$percent% > 15%"
3700                                 break
3701                         fi
3702                 done
3703         rm -rf $TDIR
3704 }
3705 run_test 42e "verify sub-RPC writes are not done synchronously"
3706
3707 test_43() {
3708         test_mkdir -p $DIR/$tdir
3709         cp -p /bin/ls $DIR/$tdir/$tfile
3710         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3711         pid=$!
3712         # give multiop a chance to open
3713         sleep 1
3714
3715         $DIR/$tdir/$tfile && error || true
3716         kill -USR1 $pid
3717 }
3718 run_test 43 "execution of file opened for write should return -ETXTBSY"
3719
3720 test_43a() {
3721         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3722         test_mkdir -p $DIR/$tdir
3723         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3724                         cp -p multiop $DIR/$tdir/multiop
3725         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3726                         return 1
3727         MULTIOP_PID=$!
3728         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3729         kill -USR1 $MULTIOP_PID || return 2
3730         wait $MULTIOP_PID || return 3
3731         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3732 }
3733 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3734
3735 test_43b() {
3736         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3737         test_mkdir -p $DIR/$tdir
3738         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3739                         cp -p multiop $DIR/$tdir/multiop
3740         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3741                         return 1
3742         MULTIOP_PID=$!
3743         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3744         kill -USR1 $MULTIOP_PID || return 2
3745         wait $MULTIOP_PID || return 3
3746         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3747 }
3748 run_test 43b "truncate of file being executed should return -ETXTBSY"
3749
3750 test_43c() {
3751         local testdir="$DIR/$tdir"
3752         test_mkdir -p $DIR/$tdir
3753         cp $SHELL $testdir/
3754         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3755                 ( cd $testdir && md5sum -c)
3756 }
3757 run_test 43c "md5sum of copy into lustre========================"
3758
3759 test_44() {
3760         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3761         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3762         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3763 }
3764 run_test 44 "zero length read from a sparse stripe ============="
3765
3766 test_44a() {
3767         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3768                 awk '{ print $2 }')
3769         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3770         [[ $nstripe -gt $OSTCOUNT ]] &&
3771             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3772             return
3773         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3774                 awk '{ print $2 }')
3775         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3776                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3777                         awk '{ print $2 }')
3778         fi
3779
3780         OFFSETS="0 $((stride/2)) $((stride-1))"
3781         for offset in $OFFSETS; do
3782                 for i in $(seq 0 $((nstripe-1))); do
3783                         local GLOBALOFFSETS=""
3784                         # size in Bytes
3785                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3786                         local myfn=$DIR/d44a-$size
3787                         echo "--------writing $myfn at $size"
3788                         ll_sparseness_write $myfn $size ||
3789                                 error "ll_sparseness_write"
3790                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3791                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3792                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3793
3794                         for j in $(seq 0 $((nstripe-1))); do
3795                                 # size in Bytes
3796                                 size=$((((j + $nstripe )*$stride + $offset)))
3797                                 ll_sparseness_write $myfn $size ||
3798                                         error "ll_sparseness_write"
3799                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3800                         done
3801                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3802                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3803                         rm -f $myfn
3804                 done
3805         done
3806 }
3807 run_test 44a "test sparse pwrite ==============================="
3808
3809 dirty_osc_total() {
3810         tot=0
3811         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3812                 tot=$(($tot + $d))
3813         done
3814         echo $tot
3815 }
3816 do_dirty_record() {
3817         before=`dirty_osc_total`
3818         echo executing "\"$*\""
3819         eval $*
3820         after=`dirty_osc_total`
3821         echo before $before, after $after
3822 }
3823 test_45() {
3824         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3825         f="$DIR/f45"
3826         # Obtain grants from OST if it supports it
3827         echo blah > ${f}_grant
3828         stop_writeback
3829         sync
3830         do_dirty_record "echo blah > $f"
3831         [[ $before -eq $after ]] && error "write wasn't cached"
3832         do_dirty_record "> $f"
3833         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3834         do_dirty_record "echo blah > $f"
3835         [[ $before -eq $after ]] && error "write wasn't cached"
3836         do_dirty_record "sync"
3837         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3838         do_dirty_record "echo blah > $f"
3839         [[ $before -eq $after ]] && error "write wasn't cached"
3840         do_dirty_record "cancel_lru_locks osc"
3841         [[ $before -gt $after ]] ||
3842                 error "lock cancellation didn't lower dirty count"
3843         start_writeback
3844 }
3845 run_test 45 "osc io page accounting ============================"
3846
3847 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3848 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3849 # objects offset and an assert hit when an rpc was built with 1023's mapped
3850 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3851 test_46() {
3852         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3853         f="$DIR/f46"
3854         stop_writeback
3855         sync
3856         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3857         sync
3858         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3859         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3860         sync
3861         start_writeback
3862 }
3863 run_test 46 "dirtying a previously written page ================"
3864
3865 # test_47 is removed "Device nodes check" is moved to test_28
3866
3867 test_48a() { # bug 2399
3868         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
3869         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
3870                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly" &&
3871                 return
3872         test_mkdir $DIR/$tdir
3873         cd $DIR/$tdir
3874         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
3875         test_mkdir $DIR/$tdir || error "recreate directory failed"
3876         touch foo || error "'touch foo' failed after recreating cwd"
3877         test_mkdir bar || error "'mkdir foo' failed after recreating cwd"
3878         touch .foo || error "'touch .foo' failed after recreating cwd"
3879         test_mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
3880         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3881         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3882         cd . || error "'cd .' failed after recreating cwd"
3883         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3884         rmdir . && error "'rmdir .' worked after recreating cwd"
3885         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3886         cd .. || error "'cd ..' failed after recreating cwd"
3887 }
3888 run_test 48a "Access renamed working dir (should return errors)="
3889
3890 test_48b() { # bug 2399
3891         rm -rf $DIR/$tdir
3892         test_mkdir $DIR/$tdir
3893         cd $DIR/$tdir
3894         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3895         touch foo && error "'touch foo' worked after removing cwd"
3896         test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3897         touch .foo && error "'touch .foo' worked after removing cwd"
3898         test_mkdir .foo && error "'mkdir .foo' worked after removing cwd"
3899         ls . > /dev/null && error "'ls .' worked after removing cwd"
3900         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3901         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3902         test_mkdir . && error "'mkdir .' worked after removing cwd"
3903         rmdir . && error "'rmdir .' worked after removing cwd"
3904         ln -s . foo && error "'ln -s .' worked after removing cwd"
3905         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3906 }
3907 run_test 48b "Access removed working dir (should return errors)="
3908
3909 test_48c() { # bug 2350
3910         #lctl set_param debug=-1
3911         #set -vx
3912         rm -rf $DIR/$tdir
3913         test_mkdir -p $DIR/$tdir/dir
3914         cd $DIR/$tdir/dir
3915         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3916         $TRACE touch foo && error "touch foo worked after removing cwd"
3917         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3918         touch .foo && error "touch .foo worked after removing cwd"
3919         test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3920         $TRACE ls . && error "'ls .' worked after removing cwd"
3921         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3922         is_patchless || ( $TRACE cd . &&
3923                         error "'cd .' worked after removing cwd" )
3924         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3925         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3926         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3927         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3928 }
3929 run_test 48c "Access removed working subdir (should return errors)"
3930
3931 test_48d() { # bug 2350
3932         #lctl set_param debug=-1
3933         #set -vx
3934         rm -rf $DIR/$tdir
3935         test_mkdir -p $DIR/$tdir/dir
3936         cd $DIR/$tdir/dir
3937         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3938         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3939         $TRACE touch foo && error "'touch foo' worked after removing parent"
3940         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3941         touch .foo && error "'touch .foo' worked after removing parent"
3942         test_mkdir .foo && error "mkdir .foo worked after removing parent"
3943         $TRACE ls . && error "'ls .' worked after removing parent"
3944         $TRACE ls .. && error "'ls ..' worked after removing parent"
3945         is_patchless || ( $TRACE cd . &&
3946                         error "'cd .' worked after recreate parent" )
3947         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3948         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3949         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3950         is_patchless || ( $TRACE cd .. &&
3951                         error "'cd ..' worked after removing parent" || true )
3952 }
3953 run_test 48d "Access removed parent subdir (should return errors)"
3954
3955 test_48e() { # bug 4134
3956         #lctl set_param debug=-1
3957         #set -vx
3958         rm -rf $DIR/$tdir
3959         test_mkdir -p $DIR/$tdir/dir
3960         cd $DIR/$tdir/dir
3961         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3962         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3963         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3964         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3965         # On a buggy kernel addition of "touch foo" after cd .. will
3966         # produce kernel oops in lookup_hash_it
3967         touch ../foo && error "'cd ..' worked after recreate parent"
3968         cd $DIR
3969         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3970 }
3971 run_test 48e "Access to recreated parent subdir (should return errors)"
3972
3973 test_49() { # LU-1030
3974         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3975         # get ost1 size - lustre-OST0000
3976         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3977                 awk '{ print $4 }')
3978         # write 800M at maximum
3979         [[ $ost1_size -lt 2 ]] && ost1_size=2
3980         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3981
3982         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3983         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3984         local dd_pid=$!
3985
3986         # change max_pages_per_rpc while writing the file
3987         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3988         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3989         # loop until dd process exits
3990         while ps ax -opid | grep -wq $dd_pid; do
3991                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3992                 sleep $((RANDOM % 5 + 1))
3993         done
3994         # restore original max_pages_per_rpc
3995         $LCTL set_param $osc1_mppc=$orig_mppc
3996         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3997 }
3998 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3999
4000 test_50() {
4001         # bug 1485
4002         test_mkdir $DIR/$tdir
4003         cd $DIR/$tdir
4004         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
4005 }
4006 run_test 50 "special situations: /proc symlinks  ==============="
4007
4008 test_51a() {    # was test_51
4009         # bug 1516 - create an empty entry right after ".." then split dir
4010         test_mkdir -c1 $DIR/$tdir
4011         touch $DIR/$tdir/foo
4012         $MCREATE $DIR/$tdir/bar
4013         rm $DIR/$tdir/foo
4014         createmany -m $DIR/$tdir/longfile 201
4015         FNUM=202
4016         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
4017                 $MCREATE $DIR/$tdir/longfile$FNUM
4018                 FNUM=$(($FNUM + 1))
4019                 echo -n "+"
4020         done
4021         echo
4022         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
4023 }
4024 run_test 51a "special situations: split htree with empty entry =="
4025
4026 export NUMTEST=70000
4027 test_51b() {
4028         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4029         local BASE=$DIR/d${base}.${TESTSUITE}
4030
4031         # cleanup the directory
4032         rm -fr $BASE
4033
4034         test_mkdir -p -c1 $BASE
4035
4036         $LFS df
4037         $LFS df -i
4038         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
4039         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
4040         [[ $numfree -lt 21000 ]] &&
4041                 skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
4042                 return
4043
4044         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
4045                 echo "reduced count to $NUMTEST due to inodes on MDT$mdtidx"
4046
4047         # need to check free space for the directories as well
4048         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
4049         numfree=$((blkfree / 4))
4050         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$((numfree - 50)) &&
4051                 echo "reduced count to $NUMTEST due to blocks on MDT$mdtidx"
4052
4053         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
4054         {
4055                 $LFS df
4056                 $LFS df -i
4057                 echo "failed" > $BASE/fnum
4058                 error "failed to create $NUMTEST subdirs in MDT$mdtidx:$BASE"
4059         }
4060 }
4061 run_test 51b "exceed 64k subdirectory nlink limit"
4062
4063 test_51ba() { # LU-993
4064         local BASE=$DIR/d${base}.${TESTSUITE}
4065         # unlink all but 100 subdirectories, then check it still works
4066         local LEFT=100
4067         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
4068
4069         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
4070         local DELETE=$((NUMTEST - LEFT))
4071
4072         # continue on to run this test even if 51b didn't finish,
4073         # just to delete the many subdirectories created.
4074         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
4075
4076         # for ldiskfs the nlink count should be 1, but this is OSD specific
4077         # and so this is listed for informational purposes only
4078         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
4079         unlinkmany -d $BASE/d $DELETE
4080         RC=$?
4081
4082         if [ $RC -ne 0 ]; then
4083                 if [ "$NUMPREV" == "failed" ]; then
4084                         skip "previous setup failed"
4085                         return 0
4086                 else
4087                         error "unlink of first $DELETE subdirs failed"
4088                         return $RC
4089                 fi
4090         fi
4091
4092         echo "nlink between: $(stat -c %h $BASE)"
4093         # trim the first line of ls output
4094         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
4095         [ $FOUND -ne $LEFT ] &&
4096                 error "can't find subdirs: found only $FOUND/$LEFT"
4097
4098         unlinkmany -d $BASE/d $DELETE $LEFT ||
4099                 error "unlink of second $LEFT subdirs failed"
4100         # regardless of whether the backing filesystem tracks nlink accurately
4101         # or not, the nlink count shouldn't be more than "." and ".." here
4102         local AFTER=$(stat -c %h $BASE)
4103         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
4104                 echo "nlink after: $AFTER"
4105 }
4106 run_test 51ba "verify nlink for many subdirectory cleanup"
4107
4108 test_51d() {
4109         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4110         [[ $OSTCOUNT -lt 3 ]] &&
4111                 skip_env "skipping test with few OSTs" && return
4112         test_mkdir -p $DIR/$tdir
4113         createmany -o $DIR/$tdir/t- 1000
4114         $GETSTRIPE $DIR/$tdir > $TMP/files
4115         for N in $(seq 0 $((OSTCOUNT - 1))); do
4116                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4117                         END { printf("%0.0f", objs) }' $TMP/files)
4118                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
4119                         '($1 == '$N') { objs += 1 } \
4120                         END { printf("%0.0f", objs) }')
4121                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4122         done
4123         unlinkmany $DIR/$tdir/t- 1000
4124
4125         NLAST=0
4126         for N in $(seq 1 $((OSTCOUNT - 1))); do
4127                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4128                         error "OST $N has less objects vs OST $NLAST" \
4129                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4130                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4131                         error "OST $N has less objects vs OST $NLAST" \
4132                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4133
4134                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4135                         error "OST $N has less #0 objects vs OST $NLAST" \
4136                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4137                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4138                         error "OST $N has less #0 objects vs OST $NLAST" \
4139                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4140                 NLAST=$N
4141         done
4142 }
4143 run_test 51d "check object distribution ===================="
4144
4145 test_51e() {
4146         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4147                 skip "Only applicable to ldiskfs-based MDTs"
4148                 return
4149         fi
4150
4151         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4152         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4153
4154         touch $DIR/$tdir/d0/foo
4155         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4156                 error "file exceed 65000 nlink limit!"
4157         unlinkmany $DIR/$tdir/d0/f- 65001
4158         return 0
4159 }
4160 run_test 51e "check file nlink limit"
4161
4162 test_52a() {
4163         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4164         test_mkdir -p $DIR/$tdir
4165         touch $DIR/$tdir/foo
4166         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4167         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4168         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4169         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4170         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4171                                         error "link worked"
4172         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4173         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4174         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4175                                                      error "lsattr"
4176         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4177         cp -r $DIR/$tdir /tmp/
4178         rm -fr $DIR/$tdir || error "cleanup rm failed"
4179 }
4180 run_test 52a "append-only flag test (should return errors) ====="
4181
4182 test_52b() {
4183         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4184         test_mkdir -p $DIR/$tdir
4185         touch $DIR/$tdir/foo
4186         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4187         cat test > $DIR/$tdir/foo && error "cat test worked"
4188         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4189         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4190         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4191                                         error "link worked"
4192         echo foo >> $DIR/$tdir/foo && error "echo worked"
4193         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4194         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4195         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4196         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4197                                                         error "lsattr"
4198         chattr -i $DIR/$tdir/foo || error "chattr failed"
4199
4200         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4201 }
4202 run_test 52b "immutable flag test (should return errors) ======="
4203
4204 test_53() {
4205         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4206         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4207         remote_ost_nodsh && skip "remote OST with nodsh" && return
4208
4209         local param
4210         local param_seq
4211         local ostname
4212         local mds_last
4213         local mds_last_seq
4214         local ost_last
4215         local ost_last_seq
4216         local ost_last_id
4217         local ostnum
4218         local node
4219         local found=false
4220         local support_last_seq=true
4221
4222         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4223                 support_last_seq=false
4224
4225         # only test MDT0000
4226         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4227         local value
4228         for value in $(do_facet $SINGLEMDS \
4229                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4230                 param=$(echo ${value[0]} | cut -d "=" -f1)
4231                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4232
4233                 if $support_last_seq; then
4234                         param_seq=$(echo $param |
4235                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4236                         mds_last_seq=$(do_facet $SINGLEMDS \
4237                                        $LCTL get_param -n $param_seq)
4238                 fi
4239                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4240
4241                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4242                 node=$(facet_active_host ost$((ostnum+1)))
4243                 param="obdfilter.$ostname.last_id"
4244                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4245                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4246                         ost_last_id=$ost_last
4247
4248                         if $support_last_seq; then
4249                                 ost_last_id=$(echo $ost_last |
4250                                               awk -F':' '{print $2}' |
4251                                               sed -e "s/^0x//g")
4252                                 ost_last_seq=$(echo $ost_last |
4253                                                awk -F':' '{print $1}')
4254                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4255                         fi
4256
4257                         if [[ $ost_last_id != $mds_last ]]; then
4258                                 error "$ost_last_id != $mds_last"
4259                         else
4260                                 found=true
4261                                 break
4262                         fi
4263                 done
4264         done
4265         $found || error "can not match last_seq/last_id for $mdtosc"
4266         return 0
4267 }
4268 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4269
4270 test_54a() {
4271         $SOCKETSERVER $DIR/socket ||
4272                 error "$SOCKETSERVER $DIR/socket failed: $?"
4273         $SOCKETCLIENT $DIR/socket ||
4274                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4275         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4276 }
4277 run_test 54a "unix domain socket test =========================="
4278
4279 test_54b() {
4280         f="$DIR/f54b"
4281         mknod $f c 1 3
4282         chmod 0666 $f
4283         dd if=/dev/zero of=$f bs=$(page_size) count=1
4284 }
4285 run_test 54b "char device works in lustre ======================"
4286
4287 find_loop_dev() {
4288         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4289         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4290         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4291
4292         for i in $(seq 3 7); do
4293                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4294                 LOOPDEV=$LOOPBASE$i
4295                 LOOPNUM=$i
4296                 break
4297         done
4298 }
4299
4300 cleanup_54c() {
4301         loopdev="$DIR/loop54c"
4302
4303         trap 0
4304         $UMOUNT $DIR/$tdir || rc=$?
4305         losetup -d $loopdev || true
4306         losetup -d $LOOPDEV || true
4307         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4308         return $rc
4309 }
4310
4311 test_54c() {
4312         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4313         loopdev="$DIR/loop54c"
4314
4315         find_loop_dev
4316         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4317         trap cleanup_54c EXIT
4318         mknod $loopdev b 7 $LOOPNUM
4319         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4320         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4321         losetup $loopdev $DIR/$tfile ||
4322                 error "can't set up $loopdev for $DIR/$tfile"
4323         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4324         test_mkdir -p $DIR/$tdir
4325         mount -t ext2 $loopdev $DIR/$tdir ||
4326                 error "error mounting $loopdev on $DIR/$tdir"
4327         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4328                 error "dd write"
4329         df $DIR/$tdir
4330         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4331                 error "dd read"
4332         cleanup_54c
4333 }
4334 run_test 54c "block device works in lustre ====================="
4335
4336 test_54d() {
4337         f="$DIR/f54d"
4338         string="aaaaaa"
4339         mknod $f p
4340         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4341 }
4342 run_test 54d "fifo device works in lustre ======================"
4343
4344 test_54e() {
4345         f="$DIR/f54e"
4346         string="aaaaaa"
4347         cp -aL /dev/console $f
4348         echo $string > $f || error "echo $string to $f failed"
4349 }
4350 run_test 54e "console/tty device works in lustre ======================"
4351
4352 #The test_55 used to be iopen test and it was removed by bz#24037.
4353 #run_test 55 "check iopen_connect_dentry() ======================"
4354
4355 test_56a() {    # was test_56
4356         rm -rf $DIR/$tdir
4357         $SETSTRIPE -d $DIR
4358         test_mkdir -p $DIR/$tdir/dir
4359         NUMFILES=3
4360         NUMFILESx2=$(($NUMFILES * 2))
4361         for i in $(seq 1 $NUMFILES); do
4362                 touch $DIR/$tdir/file$i
4363                 touch $DIR/$tdir/dir/file$i
4364         done
4365
4366         # test lfs getstripe with --recursive
4367         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4368         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4369                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4370         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4371         [[ $FILENUM -eq $NUMFILES ]] ||
4372                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4373         echo "$GETSTRIPE --recursive passed."
4374
4375         # test lfs getstripe with file instead of dir
4376         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4377         [[ $FILENUM -eq 1 ]] ||
4378                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4379         echo "$GETSTRIPE file1 passed."
4380
4381         #test lfs getstripe with --verbose
4382         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4383                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4384                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4385         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4386                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4387         echo "$GETSTRIPE --verbose passed."
4388
4389         #test lfs getstripe with --obd
4390         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4391                 grep -q "unknown obduuid" ||
4392                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4393
4394         [[ $OSTCOUNT -lt 2 ]] &&
4395                 skip_env "skipping other $GETSTRIPE --obd test" && return
4396
4397         OSTIDX=1
4398         OBDUUID=$(ostuuid_from_index $OSTIDX)
4399         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4400         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4401         [[ $FOUND -eq $FILENUM ]] ||
4402                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4403         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4404                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4405                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4406                 error "$GETSTRIPE --obd: should not show file on other obd"
4407         echo "$GETSTRIPE --obd passed"
4408 }
4409 run_test 56a "check $GETSTRIPE"
4410
4411 NUMFILES=3
4412 NUMDIRS=3
4413 setup_56() {
4414         local LOCAL_NUMFILES="$1"
4415         local LOCAL_NUMDIRS="$2"
4416         local MKDIR_PARAMS="$3"
4417         local DIR_STRIPE_PARAMS="$4"
4418
4419         if [ ! -d "$TDIR" ] ; then
4420                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4421                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4422                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4423                         touch $TDIR/file$i
4424                 done
4425                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4426                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4427                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4428                                 touch $TDIR/dir$i/file$j
4429                         done
4430                 done
4431         fi
4432 }
4433
4434 setup_56_special() {
4435         LOCAL_NUMFILES=$1
4436         LOCAL_NUMDIRS=$2
4437         setup_56 $1 $2
4438         if [ ! -e "$TDIR/loop1b" ] ; then
4439                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4440                         mknod $TDIR/loop${i}b b 7 $i
4441                         mknod $TDIR/null${i}c c 1 3
4442                         ln -s $TDIR/file1 $TDIR/link${i}l
4443                 done
4444                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4445                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4446                         mknod $TDIR/dir$i/null${i}c c 1 3
4447                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4448                 done
4449         fi
4450 }
4451
4452 test_56g() {
4453         $SETSTRIPE -d $DIR
4454
4455         TDIR=$DIR/${tdir}g
4456         setup_56 $NUMFILES $NUMDIRS
4457
4458         EXPECTED=$(($NUMDIRS + 2))
4459         # test lfs find with -name
4460         for i in $(seq 1 $NUMFILES) ; do
4461                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4462                 [ $NUMS -eq $EXPECTED ] ||
4463                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4464                               "found $NUMS, expected $EXPECTED"
4465         done
4466 }
4467 run_test 56g "check lfs find -name ============================="
4468
4469 test_56h() {
4470         $SETSTRIPE -d $DIR
4471
4472         TDIR=$DIR/${tdir}g
4473         setup_56 $NUMFILES $NUMDIRS
4474
4475         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4476         # test lfs find with ! -name
4477         for i in $(seq 1 $NUMFILES) ; do
4478                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4479                 [ $NUMS -eq $EXPECTED ] ||
4480                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4481                               "found $NUMS, expected $EXPECTED"
4482         done
4483 }
4484 run_test 56h "check lfs find ! -name ============================="
4485
4486 test_56i() {
4487        tdir=${tdir}i
4488        test_mkdir -p $DIR/$tdir
4489        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4490        CMD="$LFIND -ost $UUID $DIR/$tdir"
4491        OUT=$($CMD)
4492        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4493 }
4494 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4495
4496 test_56j() {
4497         TDIR=$DIR/${tdir}g
4498         setup_56_special $NUMFILES $NUMDIRS
4499
4500         EXPECTED=$((NUMDIRS + 1))
4501         CMD="$LFIND -type d $TDIR"
4502         NUMS=$($CMD | wc -l)
4503         [ $NUMS -eq $EXPECTED ] ||
4504                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4505 }
4506 run_test 56j "check lfs find -type d ============================="
4507
4508 test_56k() {
4509         TDIR=$DIR/${tdir}g
4510         setup_56_special $NUMFILES $NUMDIRS
4511
4512         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4513         CMD="$LFIND -type f $TDIR"
4514         NUMS=$($CMD | wc -l)
4515         [ $NUMS -eq $EXPECTED ] ||
4516                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4517 }
4518 run_test 56k "check lfs find -type f ============================="
4519
4520 test_56l() {
4521         TDIR=$DIR/${tdir}g
4522         setup_56_special $NUMFILES $NUMDIRS
4523
4524         EXPECTED=$((NUMDIRS + NUMFILES))
4525         CMD="$LFIND -type b $TDIR"
4526         NUMS=$($CMD | wc -l)
4527         [ $NUMS -eq $EXPECTED ] ||
4528                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4529 }
4530 run_test 56l "check lfs find -type b ============================="
4531
4532 test_56m() {
4533         TDIR=$DIR/${tdir}g
4534         setup_56_special $NUMFILES $NUMDIRS
4535
4536         EXPECTED=$((NUMDIRS + NUMFILES))
4537         CMD="$LFIND -type c $TDIR"
4538         NUMS=$($CMD | wc -l)
4539         [ $NUMS -eq $EXPECTED ] ||
4540                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4541 }
4542 run_test 56m "check lfs find -type c ============================="
4543
4544 test_56n() {
4545         TDIR=$DIR/${tdir}g
4546         setup_56_special $NUMFILES $NUMDIRS
4547
4548         EXPECTED=$((NUMDIRS + NUMFILES))
4549         CMD="$LFIND -type l $TDIR"
4550         NUMS=$($CMD | wc -l)
4551         [ $NUMS -eq $EXPECTED ] ||
4552                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4553 }
4554 run_test 56n "check lfs find -type l ============================="
4555
4556 test_56o() {
4557         TDIR=$DIR/${tdir}o
4558         setup_56 $NUMFILES $NUMDIRS
4559         utime $TDIR/file1 > /dev/null || error "utime (1)"
4560         utime $TDIR/file2 > /dev/null || error "utime (2)"
4561         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4562         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4563         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4564         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4565
4566         EXPECTED=4
4567         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4568         [ $NUMS -eq $EXPECTED ] || \
4569                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4570
4571         EXPECTED=12
4572         CMD="$LFIND -mtime 0 $TDIR"
4573         NUMS=$($CMD | wc -l)
4574         [ $NUMS -eq $EXPECTED ] ||
4575                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4576 }
4577 run_test 56o "check lfs find -mtime for old files =========================="
4578
4579 test_56p() {
4580         [ $RUNAS_ID -eq $UID ] &&
4581                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4582
4583         TDIR=$DIR/${tdir}p
4584         setup_56 $NUMFILES $NUMDIRS
4585
4586         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4587         EXPECTED=$NUMFILES
4588         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4589         NUMS=$($CMD | wc -l)
4590         [ $NUMS -eq $EXPECTED ] || \
4591                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4592
4593         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4594         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4595         NUMS=$($CMD | wc -l)
4596         [ $NUMS -eq $EXPECTED ] || \
4597                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4598 }
4599 run_test 56p "check lfs find -uid and ! -uid ==============================="
4600
4601 test_56q() {
4602         [ $RUNAS_ID -eq $UID ] &&
4603                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4604
4605         TDIR=$DIR/${tdir}q
4606         setup_56 $NUMFILES $NUMDIRS
4607
4608         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4609
4610         EXPECTED=$NUMFILES
4611         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4612         NUMS=$($CMD | wc -l)
4613         [ $NUMS -eq $EXPECTED ] ||
4614                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4615
4616         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4617         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4618         NUMS=$($CMD | wc -l)
4619         [ $NUMS -eq $EXPECTED ] ||
4620                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4621 }
4622 run_test 56q "check lfs find -gid and ! -gid ==============================="
4623
4624 test_56r() {
4625         TDIR=$DIR/${tdir}r
4626         setup_56 $NUMFILES $NUMDIRS
4627
4628         EXPECTED=12
4629         CMD="$LFIND -size 0 -type f $TDIR"
4630         NUMS=$($CMD | wc -l)
4631         [ $NUMS -eq $EXPECTED ] ||
4632                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4633         EXPECTED=0
4634         CMD="$LFIND ! -size 0 -type f $TDIR"
4635         NUMS=$($CMD | wc -l)
4636         [ $NUMS -eq $EXPECTED ] ||
4637                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4638         echo "test" > $TDIR/$tfile
4639         echo "test2" > $TDIR/$tfile.2 && sync
4640         EXPECTED=1
4641         CMD="$LFIND -size 5 -type f $TDIR"
4642         NUMS=$($CMD | wc -l)
4643         [ $NUMS -eq $EXPECTED ] ||
4644                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4645         EXPECTED=1
4646         CMD="$LFIND -size +5 -type f $TDIR"
4647         NUMS=$($CMD | wc -l)
4648         [ $NUMS -eq $EXPECTED ] ||
4649                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4650         EXPECTED=2
4651         CMD="$LFIND -size +0 -type f $TDIR"
4652         NUMS=$($CMD | wc -l)
4653         [ $NUMS -eq $EXPECTED ] ||
4654                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4655         EXPECTED=2
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=12
4661         CMD="$LFIND -size -5 -type f $TDIR"
4662         NUMS=$($CMD | wc -l)
4663         [ $NUMS -eq $EXPECTED ] ||
4664                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4665 }
4666 run_test 56r "check lfs find -size works =========================="
4667
4668 test_56s() { # LU-611
4669         TDIR=$DIR/${tdir}s
4670         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4671
4672         if [[ $OSTCOUNT -gt 1 ]]; then
4673                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4674                 ONESTRIPE=4
4675                 EXTRA=4
4676         else
4677                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4678                 EXTRA=0
4679         fi
4680
4681         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4682         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4683         NUMS=$($CMD | wc -l)
4684         [ $NUMS -eq $EXPECTED ] || {
4685                 $GETSTRIPE -R $TDIR
4686                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4687         }
4688
4689         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4690         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4691         NUMS=$($CMD | wc -l)
4692         [ $NUMS -eq $EXPECTED ] || {
4693                 $GETSTRIPE -R $TDIR
4694                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4695         }
4696
4697         EXPECTED=$ONESTRIPE
4698         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4699         NUMS=$($CMD | wc -l)
4700         [ $NUMS -eq $EXPECTED ] || {
4701                 $GETSTRIPE -R $TDIR
4702                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4703         }
4704
4705         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4706         NUMS=$($CMD | wc -l)
4707         [ $NUMS -eq $EXPECTED ] || {
4708                 $GETSTRIPE -R $TDIR
4709                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4710         }
4711
4712         EXPECTED=0
4713         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4714         NUMS=$($CMD | wc -l)
4715         [ $NUMS -eq $EXPECTED ] || {
4716                 $GETSTRIPE -R $TDIR
4717                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4718         }
4719 }
4720 run_test 56s "check lfs find -stripe-count works"
4721
4722 test_56t() { # LU-611
4723         TDIR=$DIR/${tdir}t
4724         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4725
4726         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4727
4728         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4729         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4730         NUMS=$($CMD | wc -l)
4731         [ $NUMS -eq $EXPECTED ] ||
4732                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4733
4734         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4735         NUMS=$($CMD | wc -l)
4736         [ $NUMS -eq $EXPECTED ] ||
4737                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4738
4739         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4740         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4741         NUMS=$($CMD | wc -l)
4742         [ $NUMS -eq $EXPECTED ] ||
4743                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4744
4745         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4746         NUMS=$($CMD | wc -l)
4747         [ $NUMS -eq $EXPECTED ] ||
4748                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4749
4750         EXPECTED=4
4751         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4752         NUMS=$($CMD | wc -l)
4753         [ $NUMS -eq $EXPECTED ] ||
4754                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4755
4756         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4757         NUMS=$($CMD | wc -l)
4758         [ $NUMS -eq $EXPECTED ] ||
4759                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4760
4761         EXPECTED=0
4762         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4763         NUMS=$($CMD | wc -l)
4764         [ $NUMS -eq $EXPECTED ] ||
4765                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4766 }
4767 run_test 56t "check lfs find -stripe-size works"
4768
4769 test_56u() { # LU-611
4770         TDIR=$DIR/${tdir}u
4771         setup_56 $NUMFILES $NUMDIRS "-i 0"
4772
4773         if [[ $OSTCOUNT -gt 1 ]]; then
4774                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4775                 ONESTRIPE=4
4776         else
4777                 ONESTRIPE=0
4778         fi
4779
4780         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4781         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4782         NUMS=$($CMD | wc -l)
4783         [ $NUMS -eq $EXPECTED ] ||
4784                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4785
4786         EXPECTED=$ONESTRIPE
4787         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4788         NUMS=$($CMD | wc -l)
4789         [ $NUMS -eq $EXPECTED ] ||
4790                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4791
4792         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4793         NUMS=$($CMD | wc -l)
4794         [ $NUMS -eq $EXPECTED ] ||
4795                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4796
4797         EXPECTED=0
4798         # This should produce an error and not return any files
4799         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4800         NUMS=$($CMD 2>/dev/null | wc -l)
4801         [ $NUMS -eq $EXPECTED ] ||
4802                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4803
4804         if [[ $OSTCOUNT -gt 1 ]]; then
4805                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4806                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4807                 NUMS=$($CMD | wc -l)
4808                 [ $NUMS -eq $EXPECTED ] ||
4809                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4810         fi
4811 }
4812 run_test 56u "check lfs find -stripe-index works"
4813
4814 test_56v() {
4815     local MDT_IDX=0
4816
4817     TDIR=$DIR/${tdir}v
4818     rm -rf $TDIR
4819     setup_56 $NUMFILES $NUMDIRS
4820
4821     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4822     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4823
4824     for file in $($LFIND -mdt $UUID $TDIR); do
4825         file_mdt_idx=$($GETSTRIPE -M $file)
4826         [ $file_mdt_idx -eq $MDT_IDX ] ||
4827             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4828     done
4829 }
4830 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4831
4832 test_56w() {
4833         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
4834                 return
4835         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4836         TDIR=$DIR/${tdir}w
4837
4838     rm -rf $TDIR || error "remove $TDIR failed"
4839     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4840
4841     local stripe_size
4842     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4843         error "$GETSTRIPE -S -d $TDIR failed"
4844     stripe_size=${stripe_size%% *}
4845
4846     local file_size=$((stripe_size * OSTCOUNT))
4847     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4848     local required_space=$((file_num * file_size))
4849
4850     local free_space=$($LCTL get_param -n lov.$FSNAME-clilov-*.kbytesavail |
4851                         head -n1)
4852     [[ $free_space -le $((required_space / 1024)) ]] &&
4853         skip_env "need at least $required_space bytes free space," \
4854                  "have $free_space kbytes" && return
4855
4856     local dd_bs=65536
4857     local dd_count=$((file_size / dd_bs))
4858
4859     # write data into the files
4860     local i
4861     local j
4862     local file
4863     for i in $(seq 1 $NUMFILES); do
4864         file=$TDIR/file$i
4865         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4866             error "write data into $file failed"
4867     done
4868     for i in $(seq 1 $NUMDIRS); do
4869         for j in $(seq 1 $NUMFILES); do
4870             file=$TDIR/dir$i/file$j
4871             yes | dd bs=$dd_bs count=$dd_count of=$file \
4872                 >/dev/null 2>&1 ||
4873                 error "write data into $file failed"
4874         done
4875     done
4876
4877     local expected=-1
4878     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4879
4880     # lfs_migrate file
4881     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4882     echo "$cmd"
4883     eval $cmd || error "$cmd failed"
4884
4885     check_stripe_count $TDIR/file1 $expected
4886
4887         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
4888         then
4889                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
4890                 # OST 1 if it is on OST 0. This file is small enough to
4891                 # be on only one stripe.
4892                 file=$TDIR/migr_1_ost
4893                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
4894                         error "write data into $file failed"
4895                 local obdidx=$($LFS getstripe -i $file)
4896                 local oldmd5=$(md5sum $file)
4897                 local newobdidx=0
4898                 [[ $obdidx -eq 0 ]] && newobdidx=1
4899                 cmd="$LFS migrate -i $newobdidx $file"
4900                 echo $cmd
4901                 eval $cmd || error "$cmd failed"
4902                 local realobdix=$($LFS getstripe -i $file)
4903                 local newmd5=$(md5sum $file)
4904                 [[ $newobdidx -ne $realobdix ]] &&
4905                         error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
4906                 [[ "$oldmd5" != "$newmd5" ]] &&
4907                         error "md5sum differ: $oldmd5, $newmd5"
4908         fi
4909
4910     # lfs_migrate dir
4911     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4912     echo "$cmd"
4913     eval $cmd || error "$cmd failed"
4914
4915     for j in $(seq 1 $NUMFILES); do
4916         check_stripe_count $TDIR/dir1/file$j $expected
4917     done
4918
4919     # lfs_migrate works with lfs find
4920     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4921          $LFS_MIGRATE -y -c $expected"
4922     echo "$cmd"
4923     eval $cmd || error "$cmd failed"
4924
4925     for i in $(seq 2 $NUMFILES); do
4926         check_stripe_count $TDIR/file$i $expected
4927     done
4928     for i in $(seq 2 $NUMDIRS); do
4929         for j in $(seq 1 $NUMFILES); do
4930             check_stripe_count $TDIR/dir$i/file$j $expected
4931         done
4932     done
4933 }
4934 run_test 56w "check lfs_migrate -c stripe_count works"
4935
4936 test_56x() {
4937         check_swap_layouts_support && return 0
4938         [[ $OSTCOUNT -lt 2 ]] &&
4939                 skip_env "need 2 OST, skipping test" && return
4940
4941         local dir0=$DIR/$tdir/$testnum
4942         test_mkdir -p $dir0 || error "creating dir $dir0"
4943
4944         local ref1=/etc/passwd
4945         local file1=$dir0/file1
4946
4947         $SETSTRIPE -c 2 $file1
4948         cp $ref1 $file1
4949         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4950         stripe=$($GETSTRIPE -c $file1)
4951         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4952         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4953
4954         # clean up
4955         rm -f $file1
4956 }
4957 run_test 56x "lfs migration support"
4958
4959 test_56y() {
4960         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4961                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
4962                 return
4963
4964         local res=""
4965         local dir0=$DIR/$tdir/$testnum
4966         test_mkdir -p $dir0 || error "creating dir $dir0"
4967         local f1=$dir0/file1
4968         local f2=$dir0/file2
4969
4970         touch $f1 || error "creating std file $f1"
4971         $MULTIOP $f2 H2c || error "creating released file $f2"
4972
4973         # a directory can be raid0, so ask only for files
4974         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4975         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4976
4977         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4978         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4979
4980         # only files can be released, so no need to force file search
4981         res=$($LFIND $dir0 -L released)
4982         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4983
4984         res=$($LFIND $dir0 \! -L released)
4985         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4986
4987 }
4988 run_test 56y "lfs find -L raid0|released"
4989
4990 test_56z() { # LU-4824
4991         # This checks to make sure 'lfs find' continues after errors
4992         # There are two classes of errors that should be caught:
4993         # - If multiple paths are provided, all should be searched even if one
4994         #   errors out
4995         # - If errors are encountered during the search, it should not terminate
4996         #   early
4997         local i
4998         test_mkdir $DIR/$tdir
4999         for i in d{0..9}; do
5000                 test_mkdir $DIR/$tdir/$i
5001         done
5002         touch $DIR/$tdir/d{0..9}/$tfile
5003         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
5004                 error "$LFS find did not return an error"
5005         # Make a directory unsearchable. This should NOT be the last entry in
5006         # directory order.  Arbitrarily pick the 6th entry
5007         chmod 700 $($LFS find $DIR/$tdir -type d | sed '6!d')
5008         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
5009         # The user should be able to see 10 directories and 9 files
5010         [ $count == 19 ] || error "$LFS find did not continue after error"
5011 }
5012 run_test 56z "lfs find should continue after an error"
5013
5014 test_56aa() { # LU-5937
5015         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5016
5017         mkdir $DIR/$tdir
5018         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
5019
5020         createmany -o $DIR/$tdir/striped_dir/${tfile}- 1024
5021         local dirs=$(lfs find --size +8k $DIR/$tdir/)
5022
5023         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5024 }
5025 run_test 56aa "lfs find --size under striped dir"
5026
5027 test_57a() {
5028         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5029         # note test will not do anything if MDS is not local
5030         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5031                 skip "Only applicable to ldiskfs-based MDTs"
5032                 return
5033         fi
5034
5035         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5036         local MNTDEV="osd*.*MDT*.mntdev"
5037         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
5038         [ -z "$DEV" ] && error "can't access $MNTDEV"
5039         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
5040                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
5041                         error "can't access $DEV"
5042                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
5043                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
5044                 rm $TMP/t57a.dump
5045         done
5046 }
5047 run_test 57a "verify MDS filesystem created with large inodes =="
5048
5049 test_57b() {
5050         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5051         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5052                 skip "Only applicable to ldiskfs-based MDTs"
5053                 return
5054         fi
5055
5056         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5057         local dir=$DIR/$tdir
5058
5059         local FILECOUNT=100
5060         local FILE1=$dir/f1
5061         local FILEN=$dir/f$FILECOUNT
5062
5063         rm -rf $dir || error "removing $dir"
5064         test_mkdir -p -c1 $dir || error "creating $dir"
5065         local mdtidx=$($LFS getstripe -M $dir)
5066         local mdtname=MDT$(printf %04x $mdtidx)
5067         local facet=mds$((mdtidx + 1))
5068
5069         echo "mcreating $FILECOUNT files"
5070         createmany -m $dir/f 1 $FILECOUNT || \
5071                 error "creating files in $dir"
5072
5073         # verify that files do not have EAs yet
5074         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5075         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5076
5077         sync
5078         sleep 1
5079         df $dir  #make sure we get new statfs data
5080         local MDSFREE=$(do_facet $facet \
5081                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5082         local MDCFREE=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5083         echo "opening files to create objects/EAs"
5084         local FILE
5085         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5086                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5087         done
5088
5089         # verify that files have EAs now
5090         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5091         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5092
5093         sleep 1  #make sure we get new statfs data
5094         df $dir
5095         local MDSFREE2=$(do_facet $facet \
5096                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5097         local MDCFREE2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5098         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5099                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5100                         error "MDC before $MDCFREE != after $MDCFREE2"
5101                 else
5102                         echo "MDC before $MDCFREE != after $MDCFREE2"
5103                         echo "unable to confirm if MDS has large inodes"
5104                 fi
5105         fi
5106         rm -rf $dir
5107 }
5108 run_test 57b "default LOV EAs are stored inside large inodes ==="
5109
5110 test_58() {
5111         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5112         [ -z "$(which wiretest 2>/dev/null)" ] &&
5113                         skip_env "could not find wiretest" && return
5114         wiretest
5115 }
5116 run_test 58 "verify cross-platform wire constants =============="
5117
5118 test_59() {
5119         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5120         echo "touch 130 files"
5121         createmany -o $DIR/f59- 130
5122         echo "rm 130 files"
5123         unlinkmany $DIR/f59- 130
5124         sync
5125         # wait for commitment of removal
5126         wait_delete_completed
5127 }
5128 run_test 59 "verify cancellation of llog records async ========="
5129
5130 TEST60_HEAD="test_60 run $RANDOM"
5131 test_60a() {
5132         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5133         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5134         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5135                 do_facet mgs "! ls run-llog.sh &> /dev/null" &&
5136                         skip_env "missing subtest run-llog.sh" && return
5137
5138         log "$TEST60_HEAD - from kernel mode"
5139         do_facet mgs "$LCTL set_param debug=warning; $LCTL dk > /dev/null"
5140         do_facet mgs sh run-llog.sh
5141         do_facet mgs $LCTL dk > $TMP/$tfile
5142
5143         # LU-6388: test llog_reader
5144         local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5145         llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5146         [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5147                         skip_env "missing llog_reader" && return
5148         local fstype=$(facet_fstype mgs)
5149         [ $fstype != ldiskfs -a $fstype != zfs ] &&
5150                 skip_env "Only for ldiskfs or zfs type mgs" && return
5151
5152         local mntpt=$(facet_mntpt mgs)
5153         local mgsdev=$(mgsdevname 1)
5154         local fid_list
5155         local fid
5156         local rec_list
5157         local rec
5158         local rec_type
5159         local obj_file
5160         local path
5161         local seq
5162         local oid
5163         local pass=true
5164
5165         #get fid and record list
5166         fid_list=($(awk '/9_sub.*record/ { print $NF }' /$TMP/$tfile |
5167                 tail -n 4))
5168         rec_list=($(awk '/9_sub.*record/ { print $((NF-3)) }' /$TMP/$tfile |
5169                 tail -n 4))
5170         #remount mgs as ldiskfs or zfs type
5171         stop mgs || error "stop mgs failed"
5172         mount_fstype mgs || error "remount mgs failed"
5173         for ((i = 0; i < ${#fid_list[@]}; i++)); do
5174                 fid=${fid_list[i]}
5175                 rec=${rec_list[i]}
5176                 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
5177                 oid=$(echo $fid | awk -F ':' '{ print $2 }' | sed -e "s/^0x//g")
5178                 oid=$((16#$oid))
5179
5180                 case $fstype in
5181                         ldiskfs )
5182                                 obj_file=$mntpt/O/$seq/d$((oid%32))/$oid ;;
5183                         zfs )
5184                                 obj_file=$mntpt/oi.$(($((16#$seq))&127))/$fid ;;
5185                 esac
5186                 echo "obj_file is $obj_file"
5187                 do_facet mgs $llog_reader $obj_file
5188
5189                 rec_type=$(do_facet mgs $llog_reader $obj_file | grep "type=" |
5190                         awk '{ print $3 }' | sed -e "s/^type=//g")
5191                 if [ $rec_type != $rec ]; then
5192                         echo "FAILED test_60a wrong record type $rec_type," \
5193                               "should be $rec"
5194                         pass=false
5195                         break
5196                 fi
5197
5198                 #check obj path if record type is LLOG_LOGID_MAGIC
5199                 if [ "$rec" == "1064553b" ]; then
5200                         path=$(do_facet mgs $llog_reader $obj_file |
5201                                 grep "path=" | awk '{ print $NF }' |
5202                                 sed -e "s/^path=//g")
5203                         if [ $obj_file != $mntpt/$path ]; then
5204                                 echo "FAILED test_60a wrong obj path" \
5205                                       "$montpt/$path, should be $obj_file"
5206                                 pass=false
5207                                 break
5208                         fi
5209                 fi
5210         done
5211         rm -f $TMP/$tfile
5212         #restart mgs before "error", otherwise it will block the next test
5213         stop mgs || error "stop mgs failed"
5214         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
5215         $pass || error "test failed, see FAILED test_60a messages for specifics"
5216 }
5217 run_test 60a "llog_test run from kernel module and test llog_reader =========="
5218
5219 test_60b() { # bug 6411
5220         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5221         dmesg > $DIR/$tfile
5222         LLOG_COUNT=$(dmesg | awk "/$TEST60_HEAD/ { marker = 1; from_marker = 0; }
5223                                 /llog.test/ {
5224                                         if (marker)
5225                                                 from_marker++
5226                                         from_begin++
5227                                 }
5228                                 END {
5229                                         if (marker)
5230                                                 print from_marker
5231                                         else
5232                                                 print from_begin
5233                                 }")
5234         [[ $LLOG_COUNT -gt 100 ]] &&
5235                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5236 }
5237 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5238
5239 test_60c() {
5240         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5241         echo "create 5000 files"
5242         createmany -o $DIR/f60c- 5000
5243 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5244         lctl set_param fail_loc=0x80000137
5245         unlinkmany $DIR/f60c- 5000
5246         lctl set_param fail_loc=0
5247 }
5248 run_test 60c "unlink file when mds full"
5249
5250 test_60d() {
5251         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5252         SAVEPRINTK=$(lctl get_param -n printk)
5253
5254         # verify "lctl mark" is even working"
5255         MESSAGE="test message ID $RANDOM $$"
5256         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5257         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5258
5259         lctl set_param printk=0 || error "set lnet.printk failed"
5260         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5261         MESSAGE="new test message ID $RANDOM $$"
5262         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5263         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5264         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5265
5266         lctl set_param -n printk="$SAVEPRINTK"
5267 }
5268 run_test 60d "test printk console message masking"
5269
5270 test_60e() {
5271         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5272         touch $DIR/$tfile
5273 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED2  0x15b
5274         do_facet mds1 lctl set_param fail_loc=0x15b
5275         rm $DIR/$tfile
5276 }
5277 run_test 60e "no space while new llog is being created"
5278
5279 test_61() {
5280         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5281         f="$DIR/f61"
5282         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5283         cancel_lru_locks osc
5284         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5285         sync
5286 }
5287 run_test 61 "mmap() writes don't make sync hang ================"
5288
5289 # bug 2330 - insufficient obd_match error checking causes LBUG
5290 test_62() {
5291         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5292         f="$DIR/f62"
5293         echo foo > $f
5294         cancel_lru_locks osc
5295         lctl set_param fail_loc=0x405
5296         cat $f && error "cat succeeded, expect -EIO"
5297         lctl set_param fail_loc=0
5298 }
5299 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5300 # match every page all of the time.
5301 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5302
5303 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5304 # Though this test is irrelevant anymore, it helped to reveal some
5305 # other grant bugs (LU-4482), let's keep it.
5306 test_63a() {   # was test_63
5307         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5308         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5309         for i in `seq 10` ; do
5310                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5311                 sleep 5
5312                 kill $!
5313                 sleep 1
5314         done
5315
5316         rm -f $DIR/f63 || true
5317 }
5318 run_test 63a "Verify oig_wait interruption does not crash ======="
5319
5320 # bug 2248 - async write errors didn't return to application on sync
5321 # bug 3677 - async write errors left page locked
5322 test_63b() {
5323         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5324         debugsave
5325         lctl set_param debug=-1
5326
5327         # ensure we have a grant to do async writes
5328         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5329         rm $DIR/$tfile
5330
5331         sync    # sync lest earlier test intercept the fail_loc
5332
5333         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5334         lctl set_param fail_loc=0x80000406
5335         $MULTIOP $DIR/$tfile Owy && \
5336                 error "sync didn't return ENOMEM"
5337         sync; sleep 2; sync     # do a real sync this time to flush page
5338         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5339                 error "locked page left in cache after async error" || true
5340         debugrestore
5341 }
5342 run_test 63b "async write errors should be returned to fsync ==="
5343
5344 test_64a () {
5345         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5346         df $DIR
5347         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5348 }
5349 run_test 64a "verify filter grant calculations (in kernel) ====="
5350
5351 test_64b () {
5352         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5353         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5354 }
5355 run_test 64b "check out-of-space detection on client ==========="
5356
5357 test_64c() {
5358         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5359 }
5360 run_test 64c "verify grant shrink ========================------"
5361
5362 # bug 1414 - set/get directories' stripe info
5363 test_65a() {
5364         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5365         test_mkdir -p $DIR/$tdir
5366         touch $DIR/$tdir/f1
5367         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5368 }
5369 run_test 65a "directory with no stripe info ===================="
5370
5371 test_65b() {
5372         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5373         test_mkdir -p $DIR/$tdir
5374         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5375
5376         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5377                                                 error "setstripe"
5378         touch $DIR/$tdir/f2
5379         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5380 }
5381 run_test 65b "directory setstripe -S stripe_size*2 -i 0 -c 1"
5382
5383 test_65c() {
5384         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5385         if [[ $OSTCOUNT -gt 1 ]]; then
5386                 test_mkdir -p $DIR/$tdir
5387                 local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5388
5389                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5390                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5391                 touch $DIR/$tdir/f3
5392                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5393         fi
5394 }
5395 run_test 65c "directory setstripe -S stripe_size*4 -i 1 -c $((OSTCOUNT-1))"
5396
5397 test_65d() {
5398         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5399         test_mkdir -p $DIR/$tdir
5400         local STRIPECOUNT=$($GETSTRIPE -c $DIR/$tdir)
5401         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5402
5403         if [[ $STRIPECOUNT -le 0 ]]; then
5404                 sc=1
5405         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5406 #LOV_MAX_STRIPE_COUNT is 2000
5407                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5408         else
5409                 sc=$(($STRIPECOUNT - 1))
5410         fi
5411         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5412         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5413         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5414                 error "lverify failed"
5415 }
5416 run_test 65d "directory setstripe -S stripe_size -c stripe_count"
5417
5418 test_65e() {
5419         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5420         test_mkdir -p $DIR/$tdir
5421
5422         $SETSTRIPE $DIR/$tdir || error "setstripe"
5423         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5424                                         error "no stripe info failed"
5425         touch $DIR/$tdir/f6
5426         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5427 }
5428 run_test 65e "directory setstripe defaults ======================="
5429
5430 test_65f() {
5431         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5432         test_mkdir -p $DIR/${tdir}f
5433         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5434 }
5435 run_test 65f "dir setstripe permission (should return error) ==="
5436
5437 test_65g() {
5438         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5439         test_mkdir -p $DIR/$tdir
5440         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5441
5442         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5443                                                         error "setstripe"
5444         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5445         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5446                 error "delete default stripe failed"
5447 }
5448 run_test 65g "directory setstripe -d ==========================="
5449
5450 test_65h() {
5451         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5452         test_mkdir -p $DIR/$tdir
5453         local STRIPESIZE=$($GETSTRIPE -S $DIR/$tdir)
5454
5455         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5456                                                         error "setstripe"
5457         test_mkdir -p $DIR/$tdir/dd1
5458         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5459                 error "stripe info inherit failed"
5460 }
5461 run_test 65h "directory stripe info inherit ===================="
5462
5463 test_65i() { # bug6367
5464         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5465         $SETSTRIPE -S 65536 -c -1 $MOUNT
5466 }
5467 run_test 65i "set non-default striping on root directory (bug 6367)="
5468
5469 test_65ia() { # bug12836
5470         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5471         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5472 }
5473 run_test 65ia "getstripe on -1 default directory striping"
5474
5475 test_65ib() { # bug12836
5476         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5477         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5478 }
5479 run_test 65ib "getstripe -v on -1 default directory striping"
5480
5481 test_65ic() { # bug12836
5482         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5483         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5484 }
5485 run_test 65ic "new find on -1 default directory striping"
5486
5487 test_65j() { # bug6367
5488         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5489         sync; sleep 1
5490         # if we aren't already remounting for each test, do so for this test
5491         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5492                 cleanup || error "failed to unmount"
5493                 setup
5494         fi
5495         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5496 }
5497 run_test 65j "set default striping on root directory (bug 6367)="
5498
5499 test_65k() { # bug11679
5500         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5501         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5502         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5503
5504     echo "Check OST status: "
5505     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5506               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5507
5508     for OSC in $MDS_OSCS; do
5509         echo $OSC "is activate"
5510         do_facet $SINGLEMDS lctl --device %$OSC activate
5511     done
5512
5513     mkdir -p $DIR/$tdir
5514     for INACTIVE_OSC in $MDS_OSCS; do
5515         echo "Deactivate: " $INACTIVE_OSC
5516         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5517         for STRIPE_OSC in $MDS_OSCS; do
5518             OST=`osc_to_ost $STRIPE_OSC`
5519             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5520                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5521
5522             [ -f $DIR/$tdir/$IDX ] && continue
5523             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5524             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5525             RC=$?
5526             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5527         done
5528         rm -f $DIR/$tdir/*
5529         echo $INACTIVE_OSC "is Activate."
5530         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5531     done
5532 }
5533 run_test 65k "validate manual striping works properly with deactivated OSCs"
5534
5535 test_65l() { # bug 12836
5536         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5537         test_mkdir -p $DIR/$tdir/test_dir
5538         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5539         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5540 }
5541 run_test 65l "lfs find on -1 stripe dir ========================"
5542
5543 # bug 2543 - update blocks count on client
5544 test_66() {
5545         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5546         COUNT=${COUNT:-8}
5547         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5548         sync; sync_all_data; sync; sync_all_data
5549         cancel_lru_locks osc
5550         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5551         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5552 }
5553 run_test 66 "update inode blocks count on client ==============="
5554
5555 LLOOP=
5556 LLITELOOPLOAD=
5557 cleanup_68() {
5558         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5559         trap 0
5560         if [ ! -z "$LLOOP" ]; then
5561                 if swapon -s | grep -q $LLOOP; then
5562                         swapoff $LLOOP || error "swapoff failed"
5563                 fi
5564
5565                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5566                 rm -f $LLOOP
5567                 unset LLOOP
5568         fi
5569         if [ ! -z "$LLITELOOPLOAD" ]; then
5570                 rmmod llite_lloop
5571                 unset LLITELOOPLOAD
5572         fi
5573         rm -f $DIR/f68*
5574 }
5575
5576 meminfo() {
5577         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5578 }
5579
5580 swap_used() {
5581         swapon -s | awk '($1 == "'$1'") { print $4 }'
5582 }
5583
5584 # test case for lloop driver, basic function
5585 test_68a() {
5586         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5587         [ "$UID" != 0 ] && skip_env "must run as root" && return
5588         llite_lloop_enabled || \
5589                 { skip_env "llite_lloop module disabled" && return; }
5590
5591         trap cleanup_68 EXIT
5592
5593         if ! module_loaded llite_lloop; then
5594                 if load_module llite/llite_lloop; then
5595                         LLITELOOPLOAD=yes
5596                 else
5597                         skip_env "can't find module llite_lloop"
5598                         return
5599                 fi
5600         fi
5601
5602         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5603         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5604         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5605
5606         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5607         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5608
5609         cleanup_68
5610 }
5611 run_test 68a "lloop driver - basic test ========================"
5612
5613 # excercise swapping to lustre by adding a high priority swapfile entry
5614 # and then consuming memory until it is used.
5615 test_68b() {  # was test_68
5616         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5617         [ "$UID" != 0 ] && skip_env "must run as root" && return
5618         lctl get_param -n devices | grep -q obdfilter && \
5619                 skip "local OST" && return
5620
5621         grep -q llite_lloop /proc/modules
5622         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5623
5624         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5625                 skip "can't reliably test swap with TCP" && return
5626
5627         MEMTOTAL=`meminfo MemTotal`
5628         NR_BLOCKS=$((MEMTOTAL>>8))
5629         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5630
5631         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5632         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5633         mkswap $DIR/f68b
5634
5635         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5636
5637         trap cleanup_68 EXIT
5638
5639         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5640
5641         echo "before: `swapon -s | grep $LLOOP`"
5642         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5643         echo "after: `swapon -s | grep $LLOOP`"
5644         SWAPUSED=`swap_used $LLOOP`
5645
5646         cleanup_68
5647
5648         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5649 }
5650 run_test 68b "support swapping to Lustre ========================"
5651
5652 # bug5265, obdfilter oa2dentry return -ENOENT
5653 # #define OBD_FAIL_SRV_ENOENT 0x217
5654 test_69() {
5655         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5656         remote_ost_nodsh && skip "remote OST with nodsh" && return
5657
5658         f="$DIR/$tfile"
5659         $SETSTRIPE -c 1 -i 0 $f
5660
5661         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5662
5663         do_facet ost1 lctl set_param fail_loc=0x217
5664         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5665         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5666
5667         do_facet ost1 lctl set_param fail_loc=0
5668         $DIRECTIO write $f 0 2 || error "write error"
5669
5670         cancel_lru_locks osc
5671         $DIRECTIO read $f 0 1 || error "read error"
5672
5673         do_facet ost1 lctl set_param fail_loc=0x217
5674         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5675
5676         do_facet ost1 lctl set_param fail_loc=0
5677         rm -f $f
5678 }
5679 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5680
5681 test_71() {
5682         test_mkdir -p $DIR/$tdir
5683         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
5684         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5685 }
5686 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5687
5688 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5689         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5690         [ "$RUNAS_ID" = "$UID" ] &&
5691                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5692
5693         # Check that testing environment is properly set up. Skip if not
5694         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5695                 skip_env "User $RUNAS_ID does not exist - skipping"
5696                 return 0
5697         }
5698         touch $DIR/$tfile
5699         chmod 777 $DIR/$tfile
5700         chmod ug+s $DIR/$tfile
5701         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5702                 error "$RUNAS dd $DIR/$tfile failed"
5703         # See if we are still setuid/sgid
5704         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5705                 error "S/gid is not dropped on write"
5706         # Now test that MDS is updated too
5707         cancel_lru_locks mdc
5708         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5709                 error "S/gid is not dropped on MDS"
5710         rm -f $DIR/$tfile
5711 }
5712 run_test 72a "Test that remove suid works properly (bug5695) ===="
5713
5714 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5715         local perm
5716
5717         [ "$RUNAS_ID" = "$UID" ] && \
5718                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5719         [ "$RUNAS_ID" -eq 0 ] && \
5720                 skip_env "RUNAS_ID = 0 -- skipping" && return
5721
5722         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5723         # Check that testing environment is properly set up. Skip if not
5724         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5725                 skip_env "User $RUNAS_ID does not exist - skipping"
5726                 return 0
5727         }
5728         touch $DIR/${tfile}-f{g,u}
5729         test_mkdir $DIR/${tfile}-dg
5730         test_mkdir $DIR/${tfile}-du
5731         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5732         chmod g+s $DIR/${tfile}-{f,d}g
5733         chmod u+s $DIR/${tfile}-{f,d}u
5734         for perm in 777 2777 4777; do
5735                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5736                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5737                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5738                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5739         done
5740         true
5741 }
5742 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5743
5744 # bug 3462 - multiple simultaneous MDC requests
5745 test_73() {
5746         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5747         test_mkdir $DIR/d73-1
5748         test_mkdir $DIR/d73-2
5749         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5750         pid1=$!
5751
5752         lctl set_param fail_loc=0x80000129
5753         $MULTIOP $DIR/d73-1/f73-2 Oc &
5754         sleep 1
5755         lctl set_param fail_loc=0
5756
5757         $MULTIOP $DIR/d73-2/f73-3 Oc &
5758         pid3=$!
5759
5760         kill -USR1 $pid1
5761         wait $pid1 || return 1
5762
5763         sleep 25
5764
5765         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5766         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5767         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5768
5769         rm -rf $DIR/d73-*
5770 }
5771 run_test 73 "multiple MDC requests (should not deadlock)"
5772
5773 test_74a() { # bug 6149, 6184
5774         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5775         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5776         #
5777         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5778         # will spin in a tight reconnection loop
5779         touch $DIR/f74a
5780         $LCTL set_param fail_loc=0x8000030e
5781         # get any lock that won't be difficult - lookup works.
5782         ls $DIR/f74a
5783         $LCTL set_param fail_loc=0
5784         rm -f $DIR/f74a
5785         true
5786 }
5787 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5788
5789 test_74b() { # bug 13310
5790         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5791         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5792         #
5793         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5794         # will spin in a tight reconnection loop
5795         $LCTL set_param fail_loc=0x8000030e
5796         # get a "difficult" lock
5797         touch $DIR/f74b
5798         $LCTL set_param fail_loc=0
5799         rm -f $DIR/f74b
5800         true
5801 }
5802 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5803
5804 test_74c() {
5805         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5806         #define OBD_FAIL_LDLM_NEW_LOCK
5807         $LCTL set_param fail_loc=0x319
5808         touch $DIR/$tfile && error "touch successful"
5809         $LCTL set_param fail_loc=0
5810         true
5811 }
5812 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5813
5814 num_inodes() {
5815         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5816 }
5817
5818 get_inode_slab_tunables() {
5819         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5820 }
5821
5822 set_inode_slab_tunables() {
5823         echo "lustre_inode_cache $1" > /proc/slabinfo
5824 }
5825
5826 test_76() { # Now for bug 20433, added originally in bug 1443
5827         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5828         local SLAB_SETTINGS=`get_inode_slab_tunables`
5829         local CPUS=`getconf _NPROCESSORS_ONLN`
5830         # we cannot set limit below 1 which means 1 inode in each
5831         # per-cpu cache is still allowed
5832         set_inode_slab_tunables "1 1 0"
5833         cancel_lru_locks osc
5834         BEFORE_INODES=$(num_inodes)
5835         echo "before inodes: $BEFORE_INODES"
5836         local COUNT=1000
5837         [ "$SLOW" = "no" ] && COUNT=100
5838         for i in $(seq $COUNT); do
5839                 touch $DIR/$tfile
5840                 rm -f $DIR/$tfile
5841         done
5842         cancel_lru_locks osc
5843         AFTER_INODES=$(num_inodes)
5844         echo "after inodes: $AFTER_INODES"
5845         local wait=0
5846         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5847                 sleep 2
5848                 AFTER_INODES=$(num_inodes)
5849                 wait=$((wait+2))
5850                 echo "wait $wait seconds inodes: $AFTER_INODES"
5851                 if [ $wait -gt 30 ]; then
5852                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5853                 fi
5854         done
5855         set_inode_slab_tunables "$SLAB_SETTINGS"
5856 }
5857 run_test 76 "confirm clients recycle inodes properly ===="
5858
5859
5860 export ORIG_CSUM=""
5861 set_checksums()
5862 {
5863         # Note: in sptlrpc modes which enable its own bulk checksum, the
5864         # original crc32_le bulk checksum will be automatically disabled,
5865         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5866         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5867         # In this case set_checksums() will not be no-op, because sptlrpc
5868         # bulk checksum will be enabled all through the test.
5869
5870         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5871         lctl set_param -n osc.*.checksums $1
5872         return 0
5873 }
5874
5875 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5876                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5877 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5878 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5879 set_checksum_type()
5880 {
5881         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5882         log "set checksum type to $1"
5883         return 0
5884 }
5885 F77_TMP=$TMP/f77-temp
5886 F77SZ=8
5887 setup_f77() {
5888         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5889                 error "error writing to $F77_TMP"
5890 }
5891
5892 test_77a() { # bug 10889
5893         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5894         $GSS && skip "could not run with gss" && return
5895         [ ! -f $F77_TMP ] && setup_f77
5896         set_checksums 1
5897         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5898         set_checksums 0
5899         rm -f $DIR/$tfile
5900 }
5901 run_test 77a "normal checksum read/write operation"
5902
5903 test_77b() { # bug 10889
5904         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5905         $GSS && skip "could not run with gss" && return
5906         [ ! -f $F77_TMP ] && setup_f77
5907         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5908         $LCTL set_param fail_loc=0x80000409
5909         set_checksums 1
5910
5911         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5912                 error "dd error: $?"
5913         $LCTL set_param fail_loc=0
5914
5915         for algo in $CKSUM_TYPES; do
5916                 cancel_lru_locks osc
5917                 set_checksum_type $algo
5918                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5919                 $LCTL set_param fail_loc=0x80000408
5920                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5921                 $LCTL set_param fail_loc=0
5922         done
5923         set_checksums 0
5924         set_checksum_type $ORIG_CSUM_TYPE
5925         rm -f $DIR/$tfile
5926 }
5927 run_test 77b "checksum error on client write, read"
5928
5929 test_77d() { # bug 10889
5930         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5931         $GSS && skip "could not run with gss" && return
5932         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5933         $LCTL set_param fail_loc=0x80000409
5934         set_checksums 1
5935         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5936                 error "direct write: rc=$?"
5937         $LCTL set_param fail_loc=0
5938         set_checksums 0
5939
5940         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5941         $LCTL set_param fail_loc=0x80000408
5942         set_checksums 1
5943         cancel_lru_locks osc
5944         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5945                 error "direct read: rc=$?"
5946         $LCTL set_param fail_loc=0
5947         set_checksums 0
5948 }
5949 run_test 77d "checksum error on OST direct write, read"
5950
5951 test_77f() { # bug 10889
5952         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5953         $GSS && skip "could not run with gss" && return
5954         set_checksums 1
5955         for algo in $CKSUM_TYPES; do
5956                 cancel_lru_locks osc
5957                 set_checksum_type $algo
5958                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5959                 $LCTL set_param fail_loc=0x409
5960                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5961                         error "direct write succeeded"
5962                 $LCTL set_param fail_loc=0
5963         done
5964         set_checksum_type $ORIG_CSUM_TYPE
5965         set_checksums 0
5966 }
5967 run_test 77f "repeat checksum error on write (expect error)"
5968
5969 test_77g() { # bug 10889
5970         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5971         $GSS && skip "could not run with gss" && return
5972         remote_ost_nodsh && skip "remote OST with nodsh" && return
5973
5974         [ ! -f $F77_TMP ] && setup_f77
5975
5976         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5977         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5978         do_facet ost1 lctl set_param fail_loc=0x8000021a
5979         set_checksums 1
5980         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5981                 error "write error: rc=$?"
5982         do_facet ost1 lctl set_param fail_loc=0
5983         set_checksums 0
5984
5985         cancel_lru_locks osc
5986         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5987         do_facet ost1 lctl set_param fail_loc=0x8000021b
5988         set_checksums 1
5989         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5990         do_facet ost1 lctl set_param fail_loc=0
5991         set_checksums 0
5992 }
5993 run_test 77g "checksum error on OST write, read"
5994
5995 test_77i() { # bug 13805
5996         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5997         $GSS && skip "could not run with gss" && return
5998         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5999         lctl set_param fail_loc=0x40b
6000         remount_client $MOUNT
6001         lctl set_param fail_loc=0
6002         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
6003                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
6004                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
6005                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
6006         done
6007         remount_client $MOUNT
6008 }
6009 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
6010
6011 test_77j() { # bug 13805
6012         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6013         $GSS && skip "could not run with gss" && return
6014         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
6015         lctl set_param fail_loc=0x40c
6016         remount_client $MOUNT
6017         lctl set_param fail_loc=0
6018         sleep 2 # wait async osc connect to finish
6019         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
6020                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
6021                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
6022                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
6023         done
6024         remount_client $MOUNT
6025 }
6026 run_test 77j "client only supporting ADLER32"
6027
6028 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
6029 rm -f $F77_TMP
6030 unset F77_TMP
6031
6032 test_78() { # bug 10901
6033         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6034         remote_ost || { skip_env "local OST" && return; }
6035
6036         NSEQ=5
6037         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
6038         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
6039         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
6040         echo "MemTotal: $MEMTOTAL"
6041
6042         # reserve 256MB of memory for the kernel and other running processes,
6043         # and then take 1/2 of the remaining memory for the read/write buffers.
6044         if [ $MEMTOTAL -gt 512 ] ;then
6045                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
6046         else
6047                 # for those poor memory-starved high-end clusters...
6048                 MEMTOTAL=$((MEMTOTAL / 2))
6049         fi
6050         echo "Mem to use for directio: $MEMTOTAL"
6051
6052         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
6053         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
6054         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
6055         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
6056                 head -n1)
6057         echo "Smallest OST: $SMALLESTOST"
6058         [[ $SMALLESTOST -lt 10240 ]] &&
6059                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
6060
6061         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
6062                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
6063
6064         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
6065         echo "File size: $F78SIZE"
6066         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
6067         for i in $(seq 1 $NSEQ); do
6068                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
6069                 echo directIO rdwr round $i of $NSEQ
6070                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
6071         done
6072
6073         rm -f $DIR/$tfile
6074 }
6075 run_test 78 "handle large O_DIRECT writes correctly ============"
6076
6077 test_79() { # bug 12743
6078         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6079         wait_delete_completed
6080
6081         BKTOTAL=$(calc_osc_kbytes kbytestotal)
6082         BKFREE=$(calc_osc_kbytes kbytesfree)
6083         BKAVAIL=$(calc_osc_kbytes kbytesavail)
6084
6085         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
6086         DFTOTAL=`echo $STRING | cut -d, -f1`
6087         DFUSED=`echo $STRING  | cut -d, -f2`
6088         DFAVAIL=`echo $STRING | cut -d, -f3`
6089         DFFREE=$(($DFTOTAL - $DFUSED))
6090
6091         ALLOWANCE=$((64 * $OSTCOUNT))
6092
6093         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
6094            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
6095                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
6096         fi
6097         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
6098            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
6099                 error "df free($DFFREE) mismatch OST free($BKFREE)"
6100         fi
6101         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
6102            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
6103                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
6104         fi
6105 }
6106 run_test 79 "df report consistency check ======================="
6107
6108 test_80() { # bug 10718
6109         remote_ost_nodsh && skip "remote OST with nodsh" && return
6110         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6111         # relax strong synchronous semantics for slow backends like ZFS
6112         local soc="obdfilter.*.sync_on_lock_cancel"
6113         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
6114         local hosts=
6115         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
6116                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
6117                           facet_active_host $host; done | sort -u)
6118                 do_nodes $hosts lctl set_param $soc=never
6119         fi
6120
6121         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
6122         sync; sleep 1; sync
6123         local BEFORE=`date +%s`
6124         cancel_lru_locks osc
6125         local AFTER=`date +%s`
6126         local DIFF=$((AFTER-BEFORE))
6127         if [ $DIFF -gt 1 ] ; then
6128                 error "elapsed for 1M@1T = $DIFF"
6129         fi
6130
6131         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
6132
6133         rm -f $DIR/$tfile
6134 }
6135 run_test 80 "Page eviction is equally fast at high offsets too  ===="
6136
6137 test_81a() { # LU-456
6138         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6139         remote_ost_nodsh && skip "remote OST with nodsh" && return
6140         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6141         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
6142         do_facet ost1 lctl set_param fail_loc=0x80000228
6143
6144         # write should trigger a retry and success
6145         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6146         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6147         RC=$?
6148         if [ $RC -ne 0 ] ; then
6149                 error "write should success, but failed for $RC"
6150         fi
6151 }
6152 run_test 81a "OST should retry write when get -ENOSPC ==============="
6153
6154 test_81b() { # LU-456
6155         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6156         remote_ost_nodsh && skip "remote OST with nodsh" && return
6157         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6158         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
6159         do_facet ost1 lctl set_param fail_loc=0x228
6160
6161         # write should retry several times and return -ENOSPC finally
6162         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6163         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6164         RC=$?
6165         ENOSPC=28
6166         if [ $RC -ne $ENOSPC ] ; then
6167                 error "dd should fail for -ENOSPC, but succeed."
6168         fi
6169 }
6170 run_test 81b "OST should return -ENOSPC when retry still fails ======="
6171
6172 test_82() { # LU-1031
6173         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
6174         local gid1=14091995
6175         local gid2=16022000
6176
6177         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
6178         local MULTIPID1=$!
6179         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
6180         local MULTIPID2=$!
6181         kill -USR1 $MULTIPID2
6182         sleep 2
6183         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6184                 error "First grouplock does not block second one"
6185         else
6186                 echo "Second grouplock blocks first one"
6187         fi
6188         kill -USR1 $MULTIPID1
6189         wait $MULTIPID1
6190         wait $MULTIPID2
6191 }
6192 run_test 82 "Basic grouplock test ==============================="
6193
6194 test_99a() {
6195         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6196                 return
6197         test_mkdir -p $DIR/d99cvsroot
6198         chown $RUNAS_ID $DIR/d99cvsroot
6199         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6200         cd $TMP
6201
6202         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6203         cd $oldPWD
6204 }
6205 run_test 99a "cvs init ========================================="
6206
6207 test_99b() {
6208         [ -z "$(which cvs 2>/dev/null)" ] &&
6209                 skip_env "could not find cvs" && return
6210         [ ! -d $DIR/d99cvsroot ] && test_99a
6211         cd /etc/init.d
6212         # some versions of cvs import exit(1) when asked to import links or
6213         # files they can't read.  ignore those files.
6214         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6215                         ! -perm /4 -printf '-I %f\n')
6216         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6217                 d99reposname vtag rtag
6218 }
6219 run_test 99b "cvs import ======================================="
6220
6221 test_99c() {
6222         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6223         [ ! -d $DIR/d99cvsroot ] && test_99b
6224         cd $DIR
6225         test_mkdir -p $DIR/d99reposname
6226         chown $RUNAS_ID $DIR/d99reposname
6227         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6228 }
6229 run_test 99c "cvs checkout ====================================="
6230
6231 test_99d() {
6232         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6233         [ ! -d $DIR/d99cvsroot ] && test_99c
6234         cd $DIR/d99reposname
6235         $RUNAS touch foo99
6236         $RUNAS cvs add -m 'addmsg' foo99
6237 }
6238 run_test 99d "cvs add =========================================="
6239
6240 test_99e() {
6241         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6242         [ ! -d $DIR/d99cvsroot ] && test_99c
6243         cd $DIR/d99reposname
6244         $RUNAS cvs update
6245 }
6246 run_test 99e "cvs update ======================================="
6247
6248 test_99f() {
6249         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6250         [ ! -d $DIR/d99cvsroot ] && test_99d
6251         cd $DIR/d99reposname
6252         $RUNAS cvs commit -m 'nomsg' foo99
6253     rm -fr $DIR/d99cvsroot
6254 }
6255 run_test 99f "cvs commit ======================================="
6256
6257 test_100() {
6258         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6259         [ "$NETTYPE" = tcp ] || \
6260                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
6261                         return ; }
6262
6263         remote_ost_nodsh && skip "remote OST with nodsh" && return
6264         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6265         remote_servers || \
6266                 { skip "useless for local single node setup" && return; }
6267
6268         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6269                 [ "$PROT" != "tcp" ] && continue
6270                 RPORT=$(echo $REMOTE | cut -d: -f2)
6271                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6272
6273                 rc=0
6274                 LPORT=`echo $LOCAL | cut -d: -f2`
6275                 if [ $LPORT -ge 1024 ]; then
6276                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6277                         netstat -tna
6278                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6279                 fi
6280         done
6281         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6282 }
6283 run_test 100 "check local port using privileged port ==========="
6284
6285 function get_named_value()
6286 {
6287     local tag
6288
6289     tag=$1
6290     while read ;do
6291         line=$REPLY
6292         case $line in
6293         $tag*)
6294             echo $line | sed "s/^$tag[ ]*//"
6295             break
6296             ;;
6297         esac
6298     done
6299 }
6300
6301 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6302                    awk '/^max_cached_mb/ { print $2 }')
6303
6304 cleanup_101a() {
6305         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6306         trap 0
6307 }
6308
6309 test_101a() {
6310         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6311         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
6312         local s
6313         local discard
6314         local nreads=10000
6315         local cache_limit=32
6316
6317         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6318         trap cleanup_101a EXIT
6319         $LCTL set_param -n llite.*.read_ahead_stats 0
6320         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6321
6322         #
6323         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6324         #
6325         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6326         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6327
6328         discard=0
6329         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6330                 get_named_value 'read but discarded' | cut -d" " -f1); do
6331                         discard=$(($discard + $s))
6332         done
6333         cleanup_101a
6334
6335         if [[ $(($discard * 10)) -gt $nreads ]]; then
6336                 $LCTL get_param osc.*-osc*.rpc_stats
6337                 $LCTL get_param llite.*.read_ahead_stats
6338                 error "too many ($discard) discarded pages"
6339         fi
6340         rm -f $DIR/$tfile || true
6341 }
6342 run_test 101a "check read-ahead for random reads ================"
6343
6344 setup_test101bc() {
6345         test_mkdir -p $DIR/$tdir
6346         local STRIPE_SIZE=$1
6347         local FILE_LENGTH=$2
6348         STRIPE_OFFSET=0
6349
6350         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6351
6352         local list=$(comma_list $(osts_nodes))
6353         set_osd_param $list '' read_cache_enable 0
6354         set_osd_param $list '' writethrough_cache_enable 0
6355
6356         trap cleanup_test101bc EXIT
6357         # prepare the read-ahead file
6358         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6359
6360         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6361                                 count=$FILE_SIZE_MB 2> /dev/null
6362
6363 }
6364
6365 cleanup_test101bc() {
6366         trap 0
6367         rm -rf $DIR/$tdir
6368         rm -f $DIR/$tfile
6369
6370         local list=$(comma_list $(osts_nodes))
6371         set_osd_param $list '' read_cache_enable 1
6372         set_osd_param $list '' writethrough_cache_enable 1
6373 }
6374
6375 calc_total() {
6376         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6377 }
6378
6379 ra_check_101() {
6380         local READ_SIZE=$1
6381         local STRIPE_SIZE=$2
6382         local FILE_LENGTH=$3
6383         local RA_INC=1048576
6384         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6385         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6386                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6387         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6388                         get_named_value 'read but discarded' |
6389                         cut -d" " -f1 | calc_total)
6390         if [[ $DISCARD -gt $discard_limit ]]; then
6391                 $LCTL get_param llite.*.read_ahead_stats
6392                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6393         else
6394                 echo "Read-ahead success for size ${READ_SIZE}"
6395         fi
6396 }
6397
6398 test_101b() {
6399         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6400         [[ $OSTCOUNT -lt 2 ]] &&
6401                 skip_env "skipping stride IO stride-ahead test" && return
6402         local STRIPE_SIZE=1048576
6403         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6404         if [ $SLOW == "yes" ]; then
6405                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6406         else
6407                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6408         fi
6409
6410         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6411
6412         # prepare the read-ahead file
6413         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6414         cancel_lru_locks osc
6415         for BIDX in 2 4 8 16 32 64 128 256
6416         do
6417                 local BSIZE=$((BIDX*4096))
6418                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6419                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6420                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6421                 $LCTL set_param -n llite.*.read_ahead_stats 0
6422                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6423                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6424                 cancel_lru_locks osc
6425                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6426         done
6427         cleanup_test101bc
6428         true
6429 }
6430 run_test 101b "check stride-io mode read-ahead ================="
6431
6432 test_101c() {
6433         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6434         local STRIPE_SIZE=1048576
6435         local FILE_LENGTH=$((STRIPE_SIZE*100))
6436         local nreads=10000
6437         local osc_rpc_stats
6438
6439         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6440
6441         cancel_lru_locks osc
6442         $LCTL set_param osc.*.rpc_stats 0
6443         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6444         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6445                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6446                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6447                 local size
6448
6449                 if [ $lines -le 20 ]; then
6450                         continue
6451                 fi
6452                 for size in 1 2 4 8; do
6453                         local rpc=$(echo "$stats" |
6454                                     awk '($1 == "'$size':") {print $2; exit; }')
6455                         [ $rpc != 0 ] &&
6456                                 error "Small $((size*4))k read IO $rpc !"
6457                 done
6458                 echo "$osc_rpc_stats check passed!"
6459         done
6460         cleanup_test101bc
6461         true
6462 }
6463 run_test 101c "check stripe_size aligned read-ahead ================="
6464
6465 set_read_ahead() {
6466         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6467         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6468 }
6469
6470 test_101d() {
6471         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6472         local file=$DIR/$tfile
6473         local sz_MB=${FILESIZE_101d:-500}
6474         local ra_MB=${READAHEAD_MB:-40}
6475
6476         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6477         [ $free_MB -lt $sz_MB ] &&
6478                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6479
6480         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6481         $SETSTRIPE -c -1 $file || error "setstripe failed"
6482
6483         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6484         echo Cancel LRU locks on lustre client to flush the client cache
6485         cancel_lru_locks osc
6486
6487         echo Disable read-ahead
6488         local old_READAHEAD=$(set_read_ahead 0)
6489
6490         echo Reading the test file $file with read-ahead disabled
6491         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6492
6493         echo Cancel LRU locks on lustre client to flush the client cache
6494         cancel_lru_locks osc
6495         echo Enable read-ahead with ${ra_MB}MB
6496         set_read_ahead $ra_MB
6497
6498         echo Reading the test file $file with read-ahead enabled
6499         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6500
6501         echo "read-ahead disabled time read $raOFF"
6502         echo "read-ahead enabled  time read $raON"
6503
6504         set_read_ahead $old_READAHEAD
6505         rm -f $file
6506         wait_delete_completed
6507
6508         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6509                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6510 }
6511 run_test 101d "file read with and without read-ahead enabled"
6512
6513 test_101e() {
6514         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6515         local file=$DIR/$tfile
6516         local size_KB=500  #KB
6517         local count=100
6518         local bsize=1024
6519
6520         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6521         local need_KB=$((count * size_KB))
6522         [[ $free_KB -le $need_KB ]] &&
6523                 skip_env "Need free space $need_KB, have $free_KB" && return
6524
6525         echo "Creating $count ${size_KB}K test files"
6526         for ((i = 0; i < $count; i++)); do
6527                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6528         done
6529
6530         echo "Cancel LRU locks on lustre client to flush the client cache"
6531         cancel_lru_locks osc
6532
6533         echo "Reset readahead stats"
6534         $LCTL set_param -n llite.*.read_ahead_stats 0
6535
6536         for ((i = 0; i < $count; i++)); do
6537                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6538         done
6539
6540         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6541                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6542
6543         for ((i = 0; i < $count; i++)); do
6544                 rm -rf $file.$i 2>/dev/null
6545         done
6546
6547         #10000 means 20% reads are missing in readahead
6548         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6549 }
6550 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6551
6552 cleanup_test101f() {
6553     trap 0
6554     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6555     rm -rf $DIR/$tfile 2>/dev/null
6556 }
6557
6558 test_101f() {
6559         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6560     local file=$DIR/$tfile
6561     local nreads=1000
6562
6563     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6564     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6565     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6566     trap cleanup_test101f EXIT
6567
6568     echo Cancel LRU locks on lustre client to flush the client cache
6569     cancel_lru_locks osc
6570
6571     echo Reset readahead stats
6572     $LCTL set_param -n llite.*.read_ahead_stats 0
6573     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6574     # readahead should read in 2M file on second read, so only miss
6575     # 2 pages.
6576     echo Random 4K reads on 2M file for 1000 times
6577     $READS -f $file -s 2097152 -b 4096 -n $nreads
6578
6579     echo checking missing pages
6580     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6581           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6582
6583     [ $miss -lt 3 ] || error "misses too much pages!"
6584     cleanup_test101f
6585 }
6586 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6587
6588 setup_test102() {
6589         test_mkdir -p $DIR/$tdir
6590         chown $RUNAS_ID $DIR/$tdir
6591         STRIPE_SIZE=65536
6592         STRIPE_OFFSET=1
6593         STRIPE_COUNT=$OSTCOUNT
6594         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6595
6596         trap cleanup_test102 EXIT
6597         cd $DIR
6598         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6599         cd $DIR/$tdir
6600         for num in 1 2 3 4; do
6601                 for count in $(seq 1 $STRIPE_COUNT); do
6602                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6603                                 local size=`expr $STRIPE_SIZE \* $num`
6604                                 local file=file"$num-$idx-$count"
6605                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6606                         done
6607                 done
6608         done
6609
6610         cd $DIR
6611         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6612 }
6613
6614 cleanup_test102() {
6615         trap 0
6616         rm -f $TMP/f102.tar
6617         rm -rf $DIR/d0.sanity/d102
6618 }
6619
6620 test_102a() {
6621         local testfile=$DIR/$tfile
6622
6623         touch $testfile
6624
6625         [ "$UID" != 0 ] && skip_env "must run as root" && return
6626         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6627                 skip_env "must have user_xattr" && return
6628
6629         [ -z "$(which setfattr 2>/dev/null)" ] &&
6630                 skip_env "could not find setfattr" && return
6631
6632         echo "set/get xattr..."
6633         setfattr -n trusted.name1 -v value1 $testfile ||
6634                 error "setfattr -n trusted.name1=value1 $testfile failed"
6635         getfattr -n trusted.name1 $testfile 2> /dev/null |
6636           grep "trusted.name1=.value1" ||
6637                 error "$testfile missing trusted.name1=value1"
6638
6639         setfattr -n user.author1 -v author1 $testfile ||
6640                 error "setfattr -n user.author1=author1 $testfile failed"
6641         getfattr -n user.author1 $testfile 2> /dev/null |
6642           grep "user.author1=.author1" ||
6643                 error "$testfile missing trusted.author1=author1"
6644
6645         echo "listxattr..."
6646         setfattr -n trusted.name2 -v value2 $testfile ||
6647                 error "$testfile unable to set trusted.name2"
6648         setfattr -n trusted.name3 -v value3 $testfile ||
6649                 error "$testfile unable to set trusted.name3"
6650         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6651             grep "trusted.name" | wc -l) -eq 3 ] ||
6652                 error "$testfile missing 3 trusted.name xattrs"
6653
6654         setfattr -n user.author2 -v author2 $testfile ||
6655                 error "$testfile unable to set user.author2"
6656         setfattr -n user.author3 -v author3 $testfile ||
6657                 error "$testfile unable to set user.author3"
6658         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6659             grep "user.author" | wc -l) -eq 3 ] ||
6660                 error "$testfile missing 3 user.author xattrs"
6661
6662         echo "remove xattr..."
6663         setfattr -x trusted.name1 $testfile ||
6664                 error "$testfile error deleting trusted.name1"
6665         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6666                 error "$testfile did not delete trusted.name1 xattr"
6667
6668         setfattr -x user.author1 $testfile ||
6669                 error "$testfile error deleting user.author1"
6670         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6671                 error "$testfile did not delete trusted.name1 xattr"
6672
6673         # b10667: setting lustre special xattr be silently discarded
6674         echo "set lustre special xattr ..."
6675         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6676                 error "$testfile allowed setting trusted.lov"
6677 }
6678 run_test 102a "user xattr test =================================="
6679
6680 test_102b() {
6681         [ -z "$(which setfattr 2>/dev/null)" ] &&
6682                 skip_env "could not find setfattr" && return
6683
6684         # b10930: get/set/list trusted.lov xattr
6685         echo "get/set/list trusted.lov xattr ..."
6686         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6687         local testfile=$DIR/$tfile
6688         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6689                 error "setstripe failed"
6690         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6691                 error "getstripe failed"
6692         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6693                 error "can't get trusted.lov from $testfile"
6694
6695         local testfile2=${testfile}2
6696         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6697                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6698
6699         $MCREATE $testfile2
6700         setfattr -n trusted.lov -v $value $testfile2
6701         local stripe_size=$($GETSTRIPE -S $testfile2)
6702         local stripe_count=$($GETSTRIPE -c $testfile2)
6703         [[ $stripe_size -eq 65536 ]] ||
6704                 error "stripe size $stripe_size != 65536"
6705         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6706                 error "stripe count $stripe_count != $STRIPECOUNT"
6707         rm -f $DIR/$tfile
6708 }
6709 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6710
6711 test_102c() {
6712         [ -z "$(which setfattr 2>/dev/null)" ] &&
6713                 skip_env "could not find setfattr" && return
6714
6715         # b10930: get/set/list lustre.lov xattr
6716         echo "get/set/list lustre.lov xattr ..."
6717         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6718         test_mkdir -p $DIR/$tdir
6719         chown $RUNAS_ID $DIR/$tdir
6720         local testfile=$DIR/$tdir/$tfile
6721         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6722                 error "setstripe failed"
6723         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6724                 error "getstripe failed"
6725         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6726         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6727
6728         local testfile2=${testfile}2
6729         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6730                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6731
6732         $RUNAS $MCREATE $testfile2
6733         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6734         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6735         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6736         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6737         [ $stripe_count -eq $STRIPECOUNT ] ||
6738                 error "stripe count $stripe_count != $STRIPECOUNT"
6739 }
6740 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6741
6742 compare_stripe_info1() {
6743         local stripe_index_all_zero=true
6744
6745         for num in 1 2 3 4; do
6746                 for count in $(seq 1 $STRIPE_COUNT); do
6747                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6748                                 local size=$((STRIPE_SIZE * num))
6749                                 local file=file"$num-$offset-$count"
6750                                 stripe_size=$($LFS getstripe -S $PWD/$file)
6751                                 [[ $stripe_size -ne $size ]] &&
6752                                     error "$file: size $stripe_size != $size"
6753                                 stripe_count=$($LFS getstripe -c $PWD/$file)
6754                                 # allow fewer stripes to be created, ORI-601
6755                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6756                                     error "$file: count $stripe_count != $count"
6757                                 stripe_index=$($LFS getstripe -i $PWD/$file)
6758                                 [[ $stripe_index -ne 0 ]] &&
6759                                         stripe_index_all_zero=false
6760                         done
6761                 done
6762         done
6763         $stripe_index_all_zero &&
6764                 error "all files are being extracted starting from OST index 0"
6765         return 0
6766 }
6767
6768 find_lustre_tar() {
6769         [ -n "$(which tar 2>/dev/null)" ] &&
6770                 strings $(which tar) | grep -q "lustre" && echo tar
6771 }
6772
6773 test_102d() {
6774         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6775         # b10930: tar test for trusted.lov xattr
6776         TAR=$(find_lustre_tar)
6777         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6778         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6779         setup_test102
6780         test_mkdir -p $DIR/d102d
6781         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6782         cd $DIR/d102d/$tdir
6783         compare_stripe_info1
6784 }
6785 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6786
6787 test_102f() {
6788         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6789         # b10930: tar test for trusted.lov xattr
6790         TAR=$(find_lustre_tar)
6791         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6792         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6793         setup_test102
6794         test_mkdir -p $DIR/d102f
6795         cd $DIR
6796         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6797         cd $DIR/d102f/$tdir
6798         compare_stripe_info1
6799 }
6800 run_test 102f "tar copy files, not keep osts ==========="
6801
6802 grow_xattr() {
6803         local xsize=${1:-1024}  # in bytes
6804         local file=$DIR/$tfile
6805
6806         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep xattr)" ] &&
6807                 skip "must have user_xattr" && return 0
6808         [ -z "$(which setfattr 2>/dev/null)" ] &&
6809                 skip_env "could not find setfattr" && return 0
6810         [ -z "$(which getfattr 2>/dev/null)" ] &&
6811                 skip_env "could not find getfattr" && return 0
6812
6813         touch $file
6814
6815         local value="$(generate_string $xsize)"
6816
6817         local xbig=trusted.big
6818         log "save $xbig on $file"
6819         setfattr -n $xbig -v $value $file ||
6820                 error "saving $xbig on $file failed"
6821
6822         local orig=$(get_xattr_value $xbig $file)
6823         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6824
6825         local xsml=trusted.sml
6826         log "save $xsml on $file"
6827         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6828
6829         local new=$(get_xattr_value $xbig $file)
6830         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6831
6832         log "grow $xsml on $file"
6833         setfattr -n $xsml -v "$value" $file ||
6834                 error "growing $xsml on $file failed"
6835
6836         new=$(get_xattr_value $xbig $file)
6837         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6838         log "$xbig still valid after growing $xsml"
6839
6840         rm -f $file
6841 }
6842
6843 test_102h() { # bug 15777
6844         grow_xattr 1024
6845 }
6846 run_test 102h "grow xattr from inside inode to external block"
6847
6848 test_102ha() {
6849         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6850         grow_xattr $(max_xattr_size)
6851 }
6852 run_test 102ha "grow xattr from inside inode to external inode"
6853
6854 test_102i() { # bug 17038
6855         [ -z "$(which getfattr 2>/dev/null)" ] &&
6856                 skip "could not find getfattr" && return
6857         touch $DIR/$tfile
6858         ln -s $DIR/$tfile $DIR/${tfile}link
6859         getfattr -n trusted.lov $DIR/$tfile ||
6860                 error "lgetxattr on $DIR/$tfile failed"
6861         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6862                 grep -i "no such attr" ||
6863                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6864         rm -f $DIR/$tfile $DIR/${tfile}link
6865 }
6866 run_test 102i "lgetxattr test on symbolic link ============"
6867
6868 test_102j() {
6869         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
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 "$RUNAS"
6874         test_mkdir -p $DIR/d102j
6875         chown $RUNAS_ID $DIR/d102j
6876         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6877         cd $DIR/d102j/$tdir
6878         compare_stripe_info1 "$RUNAS"
6879 }
6880 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6881
6882 test_102k() {
6883         [ -z "$(which setfattr 2>/dev/null)" ] &&
6884                 skip "could not find setfattr" && return
6885         touch $DIR/$tfile
6886         # b22187 just check that does not crash for regular file.
6887         setfattr -n trusted.lov $DIR/$tfile
6888         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6889         local test_kdir=$DIR/d102k
6890         test_mkdir $test_kdir
6891         local default_size=`$GETSTRIPE -S $test_kdir`
6892         local default_count=`$GETSTRIPE -c $test_kdir`
6893         local default_offset=`$GETSTRIPE -i $test_kdir`
6894         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6895                 error 'dir setstripe failed'
6896         setfattr -n trusted.lov $test_kdir
6897         local stripe_size=`$GETSTRIPE -S $test_kdir`
6898         local stripe_count=`$GETSTRIPE -c $test_kdir`
6899         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6900         [ $stripe_size -eq $default_size ] ||
6901                 error "stripe size $stripe_size != $default_size"
6902         [ $stripe_count -eq $default_count ] ||
6903                 error "stripe count $stripe_count != $default_count"
6904         [ $stripe_offset -eq $default_offset ] ||
6905                 error "stripe offset $stripe_offset != $default_offset"
6906         rm -rf $DIR/$tfile $test_kdir
6907 }
6908 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6909
6910 test_102l() {
6911         [ -z "$(which getfattr 2>/dev/null)" ] &&
6912                 skip "could not find getfattr" && return
6913
6914         # LU-532 trusted. xattr is invisible to non-root
6915         local testfile=$DIR/$tfile
6916
6917         touch $testfile
6918
6919         echo "listxattr as user..."
6920         chown $RUNAS_ID $testfile
6921         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6922             grep -q "trusted" &&
6923                 error "$testfile trusted xattrs are user visible"
6924
6925         return 0;
6926 }
6927 run_test 102l "listxattr size test =================================="
6928
6929 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6930         local path=$DIR/$tfile
6931         touch $path
6932
6933         listxattr_size_check $path || error "listattr_size_check $path failed"
6934 }
6935 run_test 102m "Ensure listxattr fails on small bufffer ========"
6936
6937 cleanup_test102
6938
6939 getxattr() { # getxattr path name
6940         # Return the base64 encoding of the value of xattr name on path.
6941         local path=$1
6942         local name=$2
6943
6944         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6945         # file: $path
6946         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6947         #
6948         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6949
6950         getfattr --absolute-names --encoding=base64 --name=$name $path |
6951                 awk -F= -v name=$name '$1 == name {
6952                         print substr($0, index($0, "=") + 1);
6953         }'
6954 }
6955
6956 test_102n() { # LU-4101 mdt: protect internal xattrs
6957         local file0=$DIR/$tfile.0
6958         local file1=$DIR/$tfile.1
6959         local xattr0=$TMP/$tfile.0
6960         local xattr1=$TMP/$tfile.1
6961         local name
6962         local value
6963
6964         [ -z "$(which setfattr 2>/dev/null)" ] &&
6965                 skip "could not find setfattr" && return
6966
6967         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6968         then
6969                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6970                 return
6971         fi
6972
6973         rm -rf $file0 $file1 $xattr0 $xattr1
6974         touch $file0 $file1
6975
6976         # Get 'before' xattrs of $file1.
6977         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6978
6979         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6980                 # Try to copy xattr from $file0 to $file1.
6981                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6982
6983                 setfattr --name=trusted.$name --value="$value" $file1 ||
6984                         error "setxattr 'trusted.$name' failed"
6985
6986                 # Try to set a garbage xattr.
6987                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6988
6989                 setfattr --name=trusted.$name --value="$value" $file1 ||
6990                         error "setxattr 'trusted.$name' failed"
6991
6992                 # Try to remove the xattr from $file1. We don't care if this
6993                 # appears to succeed or fail, we just don't want there to be
6994                 # any changes or crashes.
6995                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6996         done
6997
6998         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
6999         then
7000                 name="lfsck_ns"
7001                 # Try to copy xattr from $file0 to $file1.
7002                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7003
7004                 setfattr --name=trusted.$name --value="$value" $file1 ||
7005                         error "setxattr 'trusted.$name' failed"
7006
7007                 # Try to set a garbage xattr.
7008                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7009
7010                 setfattr --name=trusted.$name --value="$value" $file1 ||
7011                         error "setxattr 'trusted.$name' failed"
7012
7013                 # Try to remove the xattr from $file1. We don't care if this
7014                 # appears to succeed or fail, we just don't want there to be
7015                 # any changes or crashes.
7016                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7017         fi
7018
7019         # Get 'after' xattrs of file1.
7020         getfattr --absolute-names --dump --match=- $file1 > $xattr1
7021
7022         if ! diff $xattr0 $xattr1; then
7023                 error "before and after xattrs of '$file1' differ"
7024         fi
7025
7026         rm -rf $file0 $file1 $xattr0 $xattr1
7027
7028         return 0
7029 }
7030 run_test 102n "silently ignore setxattr on internal trusted xattrs"
7031
7032 test_102p() { # LU-4703 setxattr did not check ownership
7033         local testfile=$DIR/$tfile
7034
7035         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
7036                 skip "MDS needs to be at least 2.5.56" && return
7037
7038         touch $testfile
7039
7040         echo "setfacl as user..."
7041         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
7042         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
7043
7044         echo "setfattr as user..."
7045         setfacl -m "u:$RUNAS_ID:---" $testfile
7046         $RUNAS setfattr -x system.posix_acl_access $testfile
7047         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
7048 }
7049 run_test 102p "check setxattr(2) correctly fails without permission"
7050
7051 test_102q() {
7052         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
7053                 skip "MDS needs to be at least 2.6.92" && return
7054         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
7055 }
7056 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
7057
7058 test_102r() {
7059         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
7060                 skip "MDS needs to be at least 2.6.93" && return
7061         touch $DIR/$tfile || error "touch"
7062         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
7063         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
7064         rm $DIR/$tfile || error "rm"
7065
7066         #normal directory
7067         mkdir -p $DIR/$tdir || error "mkdir"
7068         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7069         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7070         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7071                 error "$testfile error deleting user.author1"
7072         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7073                 grep "user.$(basename $tdir)" &&
7074                 error "$tdir did not delete user.$(basename $tdir)"
7075         rmdir $DIR/$tdir || error "rmdir"
7076
7077         #striped directory
7078         test_mkdir -p $DIR/$tdir || error "make striped dir"
7079         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7080         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7081         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7082                 error "$testfile error deleting user.author1"
7083         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7084                 grep "user.$(basename $tdir)" &&
7085                 error "$tdir did not delete user.$(basename $tdir)"
7086         rmdir $DIR/$tdir || error "rm striped dir"
7087 }
7088 run_test 102r "set EAs with empty values"
7089
7090 run_acl_subtest()
7091 {
7092     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
7093     return $?
7094 }
7095
7096 test_103a() {
7097         [ "$UID" != 0 ] && skip_env "must run as root" && return
7098         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
7099                 skip "must have acl enabled" && return
7100         [ -z "$(which setfacl 2>/dev/null)" ] &&
7101                 skip_env "could not find setfacl" && return
7102         $GSS && skip "could not run under gss" && return
7103
7104         gpasswd -a daemon bin                           # LU-5641
7105         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
7106
7107         declare -a identity_old
7108
7109         for num in $(seq $MDSCOUNT); do
7110                 switch_identity $num true || identity_old[$num]=$?
7111         done
7112
7113         SAVE_UMASK=$(umask)
7114         umask 0022
7115         cd $DIR
7116
7117         echo "performing cp ..."
7118         run_acl_subtest cp || error "run_acl_subtest cp failed"
7119         echo "performing getfacl-noacl..."
7120         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
7121         echo "performing misc..."
7122         run_acl_subtest misc || error  "misc test failed"
7123         echo "performing permissions..."
7124         run_acl_subtest permissions || error "permissions failed"
7125         echo "performing setfacl..."
7126         run_acl_subtest setfacl || error  "setfacl test failed"
7127
7128         # inheritance test got from HP
7129         echo "performing inheritance..."
7130         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
7131         chmod +x make-tree || error "chmod +x failed"
7132         run_acl_subtest inheritance || error "inheritance test failed"
7133         rm -f make-tree
7134
7135         echo "LU-974 ignore umask when acl is enabled..."
7136         run_acl_subtest 974 || error "LU-974 umask test failed"
7137         if [ $MDSCOUNT -ge 2 ]; then
7138                 run_acl_subtest 974_remote ||
7139                         error "LU-974 umask test failed under remote dir"
7140         fi
7141
7142         echo "LU-2561 newly created file is same size as directory..."
7143         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
7144                 run_acl_subtest 2561 || error "LU-2561 test failed"
7145         else
7146                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
7147         fi
7148
7149         run_acl_subtest 4924 || error "LU-4924 test failed"
7150
7151         cd $SAVE_PWD
7152         umask $SAVE_UMASK
7153
7154         for num in $(seq $MDSCOUNT); do
7155                 if [ "${identity_old[$num]}" = 1 ]; then
7156                         switch_identity $num false || identity_old[$num]=$?
7157                 fi
7158         done
7159 }
7160 run_test 103a "acl test ========================================="
7161
7162 test_103b() {
7163         local noacl=false
7164         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
7165         local mountopts=$MDS_MOUNT_OPTS
7166
7167         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
7168                 noacl=true
7169         else
7170                 # stop the MDT
7171                 stop $SINGLEMDS || error "failed to stop MDT."
7172                 # remount the MDT
7173                 if [ -z "$MDS_MOUNT_OPTS" ]; then
7174                         MDS_MOUNT_OPTS="-o noacl"
7175                 else
7176                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
7177                 fi
7178                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7179                         error "failed to start MDT."
7180                 MDS_MOUNT_OPTS=$mountopts
7181         fi
7182
7183         touch $DIR/$tfile
7184         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
7185
7186         if ! $noacl; then
7187                 # stop the MDT
7188                 stop $SINGLEMDS || error "failed to stop MDT."
7189                 # remount the MDT
7190                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7191                         error "failed to start MDT."
7192         fi
7193
7194         true
7195 }
7196 run_test 103b "MDS mount option 'noacl'"
7197
7198 test_103c() {
7199         mkdir -p $DIR/$tdir
7200         cp -rp $DIR/$tdir $DIR/$tdir.bak
7201
7202         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
7203                 error "$DIR/$tdir shouldn't contain default ACL"
7204         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
7205                 error "$DIR/$tdir.bak shouldn't contain default ACL"
7206         true
7207 }
7208 run_test 103c "'cp -rp' won't set empty acl"
7209
7210 test_104a() {
7211         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7212         touch $DIR/$tfile
7213         lfs df || error "lfs df failed"
7214         lfs df -ih || error "lfs df -ih failed"
7215         lfs df -h $DIR || error "lfs df -h $DIR failed"
7216         lfs df -i $DIR || error "lfs df -i $DIR failed"
7217         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
7218         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
7219
7220         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
7221         lctl --device %$OSC deactivate
7222         lfs df || error "lfs df with deactivated OSC failed"
7223         lctl --device %$OSC activate
7224         # wait the osc back to normal
7225         wait_osc_import_state client ost FULL
7226
7227         lfs df || error "lfs df with reactivated OSC failed"
7228         rm -f $DIR/$tfile
7229 }
7230 run_test 104a "lfs df [-ih] [path] test ========================="
7231
7232 test_104b() {
7233         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7234         [ $RUNAS_ID -eq $UID ] &&
7235                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
7236         chmod 666 /dev/obd
7237         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
7238                         grep "Permission denied" | wc -l)))
7239         if [ $denied_cnt -ne 0 ]; then
7240                 error "lfs check servers test failed"
7241         fi
7242 }
7243 run_test 104b "$RUNAS lfs check servers test ===================="
7244
7245 test_105a() {
7246         # doesn't work on 2.4 kernels
7247         touch $DIR/$tfile
7248         if $(flock_is_enabled); then
7249                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7250         else
7251                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7252         fi
7253         rm -f $DIR/$tfile
7254 }
7255 run_test 105a "flock when mounted without -o flock test ========"
7256
7257 test_105b() {
7258         touch $DIR/$tfile
7259         if $(flock_is_enabled); then
7260                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7261         else
7262                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7263         fi
7264         rm -f $DIR/$tfile
7265 }
7266 run_test 105b "fcntl when mounted without -o flock test ========"
7267
7268 test_105c() {
7269         touch $DIR/$tfile
7270         if $(flock_is_enabled); then
7271                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7272         else
7273                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7274         fi
7275         rm -f $DIR/$tfile
7276 }
7277 run_test 105c "lockf when mounted without -o flock test ========"
7278
7279 test_105d() { # bug 15924
7280         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7281         test_mkdir -p $DIR/$tdir
7282         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7283         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7284         $LCTL set_param fail_loc=0x80000315
7285         flocks_test 2 $DIR/$tdir
7286 }
7287 run_test 105d "flock race (should not freeze) ========"
7288
7289 test_105e() { # bug 22660 && 22040
7290         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7291         touch $DIR/$tfile
7292         flocks_test 3 $DIR/$tfile
7293 }
7294 run_test 105e "Two conflicting flocks from same process ======="
7295
7296 test_106() { #bug 10921
7297         test_mkdir -p $DIR/$tdir
7298         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7299         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7300 }
7301 run_test 106 "attempt exec of dir followed by chown of that dir"
7302
7303 test_107() {
7304         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7305         CDIR=`pwd`
7306         cd $DIR
7307
7308         local file=core
7309         rm -f $file
7310
7311         local save_pattern=$(sysctl -n kernel.core_pattern)
7312         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7313         sysctl -w kernel.core_pattern=$file
7314         sysctl -w kernel.core_uses_pid=0
7315
7316         ulimit -c unlimited
7317         sleep 60 &
7318         SLEEPPID=$!
7319
7320         sleep 1
7321
7322         kill -s 11 $SLEEPPID
7323         wait $SLEEPPID
7324         if [ -e $file ]; then
7325                 size=`stat -c%s $file`
7326                 [ $size -eq 0 ] && error "Fail to create core file $file"
7327         else
7328                 error "Fail to create core file $file"
7329         fi
7330         rm -f $file
7331         sysctl -w kernel.core_pattern=$save_pattern
7332         sysctl -w kernel.core_uses_pid=$save_uses_pid
7333         cd $CDIR
7334 }
7335 run_test 107 "Coredump on SIG"
7336
7337 test_110() {
7338         test_mkdir -p $DIR/$tdir
7339         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7340                 error "mkdir with 255 char failed"
7341         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7342                 error "mkdir with 256 char should fail, but did not"
7343         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7344                 error "create with 255 char failed"
7345         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7346                 error "create with 256 char should fail, but did not"
7347
7348         ls -l $DIR/$tdir
7349         rm -rf $DIR/$tdir
7350 }
7351 run_test 110 "filename length checking"
7352
7353 test_115() {
7354         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7355         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
7356                 tail -1 | cut -c11-20)
7357         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
7358         echo "Starting with $OSTIO_pre threads"
7359
7360         NUMTEST=20000
7361         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7362         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
7363         echo "$NUMTEST creates/unlinks"
7364         test_mkdir -p $DIR/$tdir
7365         createmany -o $DIR/$tdir/$tfile $NUMTEST
7366         unlinkmany $DIR/$tdir/$tfile $NUMTEST
7367
7368         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
7369                 tail -1 | cut -c11-20)
7370
7371         # don't return an error
7372         [ $OSTIO_post == $OSTIO_pre ] && echo \
7373             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
7374             echo "This may be fine, depending on what ran before this test" &&
7375             echo "and how fast this system is." && return
7376
7377         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
7378 }
7379 run_test 115 "verify dynamic thread creation===================="
7380
7381 free_min_max () {
7382         wait_delete_completed
7383         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7384         echo OST kbytes available: ${AVAIL[@]}
7385         MAXI=0; MAXV=${AVAIL[0]}
7386         MINI=0; MINV=${AVAIL[0]}
7387         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7388                 #echo OST $i: ${AVAIL[i]}kb
7389                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7390                         MAXV=${AVAIL[i]}; MAXI=$i
7391                 fi
7392                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7393                         MINV=${AVAIL[i]}; MINI=$i
7394                 fi
7395         done
7396         echo Min free space: OST $MINI: $MINV
7397         echo Max free space: OST $MAXI: $MAXV
7398 }
7399
7400 test_116a() { # was previously test_116()
7401         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7402         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7403
7404         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
7405
7406         echo -n "Free space priority "
7407         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7408                 head -n1
7409         declare -a AVAIL
7410         free_min_max
7411
7412         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7413         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7414                 && return
7415         trap simple_cleanup_common EXIT
7416
7417
7418         # Check if we need to generate uneven OSTs
7419         test_mkdir -p $DIR/$tdir/OST${MINI}
7420         local FILL=$(($MINV / 4))
7421         local DIFF=$(($MAXV - $MINV))
7422         local DIFF2=$(($DIFF * 100 / $MINV))
7423
7424         local threshold=$(do_facet $SINGLEMDS \
7425                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7426         threshold=${threshold%%%}
7427         echo -n "Check for uneven OSTs: "
7428         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7429
7430         if [[ $DIFF2 -gt $threshold ]]; then
7431                 echo "ok"
7432                 echo "Don't need to fill OST$MINI"
7433         else
7434                 # generate uneven OSTs. Write 2% over the QOS threshold value
7435                 echo "no"
7436                 DIFF=$(($threshold - $DIFF2 + 2))
7437                 DIFF2=$(( ($MINV * $DIFF)/100 ))
7438                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
7439                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7440                         error "setstripe failed"
7441                 DIFF=$(($DIFF2 / 2048))
7442                 i=0
7443                 while [ $i -lt $DIFF ]; do
7444                         i=$(($i + 1))
7445                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7446                                 bs=2M count=1 2>/dev/null
7447                         echo -n .
7448                 done
7449                 echo .
7450                 sync
7451                 sleep_maxage
7452                 free_min_max
7453         fi
7454
7455         DIFF=$(($MAXV - $MINV))
7456         DIFF2=$(($DIFF * 100 / $MINV))
7457         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
7458         if [[ $DIFF2 -gt $threshold ]]; then
7459                 echo "ok"
7460         else
7461                 echo "failed - QOS mode won't be used"
7462                 skip "QOS imbalance criteria not met"
7463                 simple_cleanup_common
7464                 return
7465         fi
7466
7467         MINI1=$MINI; MINV1=$MINV
7468         MAXI1=$MAXI; MAXV1=$MAXV
7469
7470         # now fill using QOS
7471         $SETSTRIPE -c 1 $DIR/$tdir
7472         FILL=$(($FILL / 200))
7473         if [ $FILL -gt 600 ]; then
7474                 FILL=600
7475         fi
7476         echo "writing $FILL files to QOS-assigned OSTs"
7477         i=0
7478         while [ $i -lt $FILL ]; do
7479                 i=$((i + 1))
7480                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7481                         count=1 2>/dev/null
7482                 echo -n .
7483         done
7484         echo "wrote $i 200k files"
7485         sync
7486         sleep_maxage
7487
7488         echo "Note: free space may not be updated, so measurements might be off"
7489         free_min_max
7490         DIFF2=$(($MAXV - $MINV))
7491         echo "free space delta: orig $DIFF final $DIFF2"
7492         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7493         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
7494         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7495         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
7496         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7497         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7498         [ $DIFF -gt 0 ] &&
7499                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7500
7501         # Figure out which files were written where
7502         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7503                   awk '/'$MINI1': / {print $2; exit}')
7504         echo $UUID
7505         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7506         echo "$MINC files created on smaller OST $MINI1"
7507         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7508                   awk '/'$MAXI1': / {print $2; exit}')
7509         echo $UUID
7510         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7511         echo "$MAXC files created on larger OST $MAXI1"
7512         FILL=$(($MAXC * 100 / $MINC - 100))
7513         [[ $MINC -gt 0 ]] &&
7514                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7515         [[ $MAXC -gt $MINC ]] ||
7516                 error_ignore LU-9 "stripe QOS didn't balance free space"
7517         simple_cleanup_common
7518 }
7519 run_test 116a "stripe QOS: free space balance ==================="
7520
7521 test_116b() { # LU-2093
7522         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7523         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7524
7525 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7526         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7527                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7528         [ -z "$old_rr" ] && skip "no QOS" && return 0
7529         do_facet $SINGLEMDS lctl set_param \
7530                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7531         mkdir -p $DIR/$tdir
7532         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7533         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7534         do_facet $SINGLEMDS lctl set_param fail_loc=0
7535         rm -rf $DIR/$tdir
7536         do_facet $SINGLEMDS lctl set_param \
7537                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7538 }
7539 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7540
7541 test_117() # bug 10891
7542 {
7543         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7544         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7545         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7546         lctl set_param fail_loc=0x21e
7547         > $DIR/$tfile || error "truncate failed"
7548         lctl set_param fail_loc=0
7549         echo "Truncate succeeded."
7550         rm -f $DIR/$tfile
7551 }
7552 run_test 117 "verify osd extend =========="
7553
7554 NO_SLOW_RESENDCOUNT=4
7555 export OLD_RESENDCOUNT=""
7556 set_resend_count () {
7557         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7558         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7559         lctl set_param -n $PROC_RESENDCOUNT $1
7560         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7561 }
7562
7563 # for reduce test_118* time (b=14842)
7564 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7565
7566 # Reset async IO behavior after error case
7567 reset_async() {
7568         FILE=$DIR/reset_async
7569
7570         # Ensure all OSCs are cleared
7571         $SETSTRIPE -c -1 $FILE
7572         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7573         sync
7574         rm $FILE
7575 }
7576
7577 test_118a() #bug 11710
7578 {
7579         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7580         reset_async
7581
7582         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7583         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7584         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7585
7586         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7587                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7588                 return 1;
7589         fi
7590         rm -f $DIR/$tfile
7591 }
7592 run_test 118a "verify O_SYNC works =========="
7593
7594 test_118b()
7595 {
7596         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7597         remote_ost_nodsh && skip "remote OST with nodsh" && return
7598
7599         reset_async
7600
7601         #define OBD_FAIL_SRV_ENOENT 0x217
7602         set_nodes_failloc "$(osts_nodes)" 0x217
7603         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7604         RC=$?
7605         set_nodes_failloc "$(osts_nodes)" 0
7606         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7607         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7608                     grep -c writeback)
7609
7610         if [[ $RC -eq 0 ]]; then
7611                 error "Must return error due to dropped pages, rc=$RC"
7612                 return 1;
7613         fi
7614
7615         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7616                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7617                 return 1;
7618         fi
7619
7620         echo "Dirty pages not leaked on ENOENT"
7621
7622         # Due to the above error the OSC will issue all RPCs syncronously
7623         # until a subsequent RPC completes successfully without error.
7624         $MULTIOP $DIR/$tfile Ow4096yc
7625         rm -f $DIR/$tfile
7626
7627         return 0
7628 }
7629 run_test 118b "Reclaim dirty pages on fatal error =========="
7630
7631 test_118c()
7632 {
7633         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7634
7635         # for 118c, restore the original resend count, LU-1940
7636         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7637                                 set_resend_count $OLD_RESENDCOUNT
7638         remote_ost_nodsh && skip "remote OST with nodsh" && return
7639
7640         reset_async
7641
7642         #define OBD_FAIL_OST_EROFS               0x216
7643         set_nodes_failloc "$(osts_nodes)" 0x216
7644
7645         # multiop should block due to fsync until pages are written
7646         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7647         MULTIPID=$!
7648         sleep 1
7649
7650         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7651                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7652         fi
7653
7654         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7655                     grep -c writeback)
7656         if [[ $WRITEBACK -eq 0 ]]; then
7657                 error "No page in writeback, writeback=$WRITEBACK"
7658         fi
7659
7660         set_nodes_failloc "$(osts_nodes)" 0
7661         wait $MULTIPID
7662         RC=$?
7663         if [[ $RC -ne 0 ]]; then
7664                 error "Multiop fsync failed, rc=$RC"
7665         fi
7666
7667         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7668         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7669                     grep -c writeback)
7670         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7671                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7672         fi
7673
7674         rm -f $DIR/$tfile
7675         echo "Dirty pages flushed via fsync on EROFS"
7676         return 0
7677 }
7678 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7679
7680 # continue to use small resend count to reduce test_118* time (b=14842)
7681 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7682
7683 test_118d()
7684 {
7685         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7686         remote_ost_nodsh && skip "remote OST with nodsh" && return
7687
7688         reset_async
7689
7690         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7691         set_nodes_failloc "$(osts_nodes)" 0x214
7692         # multiop should block due to fsync until pages are written
7693         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7694         MULTIPID=$!
7695         sleep 1
7696
7697         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7698                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7699         fi
7700
7701         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7702                     grep -c writeback)
7703         if [[ $WRITEBACK -eq 0 ]]; then
7704                 error "No page in writeback, writeback=$WRITEBACK"
7705         fi
7706
7707         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7708         set_nodes_failloc "$(osts_nodes)" 0
7709
7710         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7711         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7712                     grep -c writeback)
7713         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7714                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7715         fi
7716
7717         rm -f $DIR/$tfile
7718         echo "Dirty pages gaurenteed flushed via fsync"
7719         return 0
7720 }
7721 run_test 118d "Fsync validation inject a delay of the bulk =========="
7722
7723 test_118f() {
7724         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7725         reset_async
7726
7727         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7728         lctl set_param fail_loc=0x8000040a
7729
7730         # Should simulate EINVAL error which is fatal
7731         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7732         RC=$?
7733         if [[ $RC -eq 0 ]]; then
7734                 error "Must return error due to dropped pages, rc=$RC"
7735         fi
7736
7737         lctl set_param fail_loc=0x0
7738
7739         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7740         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7741         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7742                     grep -c writeback)
7743         if [[ $LOCKED -ne 0 ]]; then
7744                 error "Locked pages remain in cache, locked=$LOCKED"
7745         fi
7746
7747         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7748                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7749         fi
7750
7751         rm -f $DIR/$tfile
7752         echo "No pages locked after fsync"
7753
7754         reset_async
7755         return 0
7756 }
7757 run_test 118f "Simulate unrecoverable OSC side error =========="
7758
7759 test_118g() {
7760         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7761         reset_async
7762
7763         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7764         lctl set_param fail_loc=0x406
7765
7766         # simulate local -ENOMEM
7767         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7768         RC=$?
7769
7770         lctl set_param fail_loc=0
7771         if [[ $RC -eq 0 ]]; then
7772                 error "Must return error due to dropped pages, rc=$RC"
7773         fi
7774
7775         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7776         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7777         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7778                         grep -c writeback)
7779         if [[ $LOCKED -ne 0 ]]; then
7780                 error "Locked pages remain in cache, locked=$LOCKED"
7781         fi
7782
7783         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7784                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7785         fi
7786
7787         rm -f $DIR/$tfile
7788         echo "No pages locked after fsync"
7789
7790         reset_async
7791         return 0
7792 }
7793 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7794
7795 test_118h() {
7796         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7797         remote_ost_nodsh && skip "remote OST with nodsh" && return
7798
7799         reset_async
7800
7801         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7802         set_nodes_failloc "$(osts_nodes)" 0x20e
7803         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7804         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7805         RC=$?
7806
7807         set_nodes_failloc "$(osts_nodes)" 0
7808         if [[ $RC -eq 0 ]]; then
7809                 error "Must return error due to dropped pages, rc=$RC"
7810         fi
7811
7812         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7813         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7814         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7815                     grep -c writeback)
7816         if [[ $LOCKED -ne 0 ]]; then
7817                 error "Locked pages remain in cache, locked=$LOCKED"
7818         fi
7819
7820         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7821                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7822         fi
7823
7824         rm -f $DIR/$tfile
7825         echo "No pages locked after fsync"
7826
7827         return 0
7828 }
7829 run_test 118h "Verify timeout in handling recoverables errors  =========="
7830
7831 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7832
7833 test_118i() {
7834         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7835         remote_ost_nodsh && skip "remote OST with nodsh" && return
7836
7837         reset_async
7838
7839         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7840         set_nodes_failloc "$(osts_nodes)" 0x20e
7841
7842         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7843         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7844         PID=$!
7845         sleep 5
7846         set_nodes_failloc "$(osts_nodes)" 0
7847
7848         wait $PID
7849         RC=$?
7850         if [[ $RC -ne 0 ]]; then
7851                 error "got error, but should be not, rc=$RC"
7852         fi
7853
7854         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7855         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7856         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7857         if [[ $LOCKED -ne 0 ]]; then
7858                 error "Locked pages remain in cache, locked=$LOCKED"
7859         fi
7860
7861         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7862                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7863         fi
7864
7865         rm -f $DIR/$tfile
7866         echo "No pages locked after fsync"
7867
7868         return 0
7869 }
7870 run_test 118i "Fix error before timeout in recoverable error  =========="
7871
7872 [ "$SLOW" = "no" ] && set_resend_count 4
7873
7874 test_118j() {
7875         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7876         remote_ost_nodsh && skip "remote OST with nodsh" && return
7877
7878         reset_async
7879
7880         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7881         set_nodes_failloc "$(osts_nodes)" 0x220
7882
7883         # return -EIO from OST
7884         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7885         RC=$?
7886         set_nodes_failloc "$(osts_nodes)" 0x0
7887         if [[ $RC -eq 0 ]]; then
7888                 error "Must return error due to dropped pages, rc=$RC"
7889         fi
7890
7891         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7892         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7893         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7894         if [[ $LOCKED -ne 0 ]]; then
7895                 error "Locked pages remain in cache, locked=$LOCKED"
7896         fi
7897
7898         # in recoverable error on OST we want resend and stay until it finished
7899         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7900                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7901         fi
7902
7903         rm -f $DIR/$tfile
7904         echo "No pages locked after fsync"
7905
7906         return 0
7907 }
7908 run_test 118j "Simulate unrecoverable OST side error =========="
7909
7910 test_118k()
7911 {
7912         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7913         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7914
7915         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7916         set_nodes_failloc "$(osts_nodes)" 0x20e
7917         test_mkdir -p $DIR/$tdir
7918
7919         for ((i=0;i<10;i++)); do
7920                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7921                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7922                 SLEEPPID=$!
7923                 sleep 0.500s
7924                 kill $SLEEPPID
7925                 wait $SLEEPPID
7926         done
7927
7928         set_nodes_failloc "$(osts_nodes)" 0
7929         rm -rf $DIR/$tdir
7930 }
7931 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7932
7933 test_118l()
7934 {
7935         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7936         # LU-646
7937         test_mkdir -p $DIR/$tdir
7938         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7939         rm -rf $DIR/$tdir
7940 }
7941 run_test 118l "fsync dir ========="
7942
7943 test_118m() # LU-3066
7944 {
7945         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7946         test_mkdir -p $DIR/$tdir
7947         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7948         rm -rf $DIR/$tdir
7949 }
7950 run_test 118m "fdatasync dir ========="
7951
7952 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7953
7954 test_119a() # bug 11737
7955 {
7956         BSIZE=$((512 * 1024))
7957         directio write $DIR/$tfile 0 1 $BSIZE
7958         # We ask to read two blocks, which is more than a file size.
7959         # directio will indicate an error when requested and actual
7960         # sizes aren't equeal (a normal situation in this case) and
7961         # print actual read amount.
7962         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7963         if [ "$NOB" != "$BSIZE" ]; then
7964                 error "read $NOB bytes instead of $BSIZE"
7965         fi
7966         rm -f $DIR/$tfile
7967 }
7968 run_test 119a "Short directIO read must return actual read amount"
7969
7970 test_119b() # bug 11737
7971 {
7972         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7973
7974         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7975         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7976         sync
7977         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7978                 error "direct read failed"
7979         rm -f $DIR/$tfile
7980 }
7981 run_test 119b "Sparse directIO read must return actual read amount"
7982
7983 test_119c() # bug 13099
7984 {
7985         BSIZE=1048576
7986         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7987         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7988         rm -f $DIR/$tfile
7989 }
7990 run_test 119c "Testing for direct read hitting hole"
7991
7992 test_119d() # bug 15950
7993 {
7994         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7995         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7996         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7997         BSIZE=1048576
7998         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7999         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
8000         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
8001         lctl set_param fail_loc=0x40d
8002         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
8003         pid_dio=$!
8004         sleep 1
8005         cat $DIR/$tfile > /dev/null &
8006         lctl set_param fail_loc=0
8007         pid_reads=$!
8008         wait $pid_dio
8009         log "the DIO writes have completed, now wait for the reads (should not block very long)"
8010         sleep 2
8011         [ -n "`ps h -p $pid_reads -o comm`" ] && \
8012         error "the read rpcs have not completed in 2s"
8013         rm -f $DIR/$tfile
8014         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
8015 }
8016 run_test 119d "The DIO path should try to send a new rpc once one is completed"
8017
8018 test_120a() {
8019         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8020         test_mkdir -p $DIR/$tdir
8021         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8022                skip "no early lock cancel on server" && return 0
8023
8024         lru_resize_disable mdc
8025         lru_resize_disable osc
8026         cancel_lru_locks mdc
8027         # asynchronous object destroy at MDT could cause bl ast to client
8028         cancel_lru_locks osc
8029
8030         stat $DIR/$tdir > /dev/null
8031         can1=$(do_facet $SINGLEMDS \
8032                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8033                awk '/ldlm_cancel/ {print $2}')
8034         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8035                awk '/ldlm_bl_callback/ {print $2}')
8036         test_mkdir -c1 $DIR/$tdir/d1
8037         can2=$(do_facet $SINGLEMDS \
8038                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8039                awk '/ldlm_cancel/ {print $2}')
8040         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8041                awk '/ldlm_bl_callback/ {print $2}')
8042         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8043         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8044         lru_resize_enable mdc
8045         lru_resize_enable osc
8046 }
8047 run_test 120a "Early Lock Cancel: mkdir test"
8048
8049 test_120b() {
8050         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8051         test_mkdir $DIR/$tdir
8052         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8053                skip "no early lock cancel on server" && return 0
8054         lru_resize_disable mdc
8055         lru_resize_disable osc
8056         cancel_lru_locks mdc
8057         stat $DIR/$tdir > /dev/null
8058         can1=$(do_facet $SINGLEMDS \
8059                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8060                awk '/ldlm_cancel/ {print $2}')
8061         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8062                awk '/ldlm_bl_callback/ {print $2}')
8063         touch $DIR/$tdir/f1
8064         can2=$(do_facet $SINGLEMDS \
8065                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8066                awk '/ldlm_cancel/ {print $2}')
8067         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8068                awk '/ldlm_bl_callback/ {print $2}')
8069         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8070         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8071         lru_resize_enable mdc
8072         lru_resize_enable osc
8073 }
8074 run_test 120b "Early Lock Cancel: create test"
8075
8076 test_120c() {
8077         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8078         test_mkdir -c1 $DIR/$tdir
8079         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8080                skip "no early lock cancel on server" && return 0
8081         lru_resize_disable mdc
8082         lru_resize_disable osc
8083         test_mkdir -p -c1 $DIR/$tdir/d1
8084         test_mkdir -p -c1 $DIR/$tdir/d2
8085         touch $DIR/$tdir/d1/f1
8086         cancel_lru_locks mdc
8087         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
8088         can1=$(do_facet $SINGLEMDS \
8089                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8090                awk '/ldlm_cancel/ {print $2}')
8091         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8092                awk '/ldlm_bl_callback/ {print $2}')
8093         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8094         can2=$(do_facet $SINGLEMDS \
8095                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8096                awk '/ldlm_cancel/ {print $2}')
8097         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8098                awk '/ldlm_bl_callback/ {print $2}')
8099         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8100         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8101         lru_resize_enable mdc
8102         lru_resize_enable osc
8103 }
8104 run_test 120c "Early Lock Cancel: link test"
8105
8106 test_120d() {
8107         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8108         test_mkdir -p -c1 $DIR/$tdir
8109         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8110                skip "no early lock cancel on server" && return 0
8111         lru_resize_disable mdc
8112         lru_resize_disable osc
8113         touch $DIR/$tdir
8114         cancel_lru_locks mdc
8115         stat $DIR/$tdir > /dev/null
8116         can1=$(do_facet $SINGLEMDS \
8117                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8118                awk '/ldlm_cancel/ {print $2}')
8119         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8120                awk '/ldlm_bl_callback/ {print $2}')
8121         chmod a+x $DIR/$tdir
8122         can2=$(do_facet $SINGLEMDS \
8123                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8124                awk '/ldlm_cancel/ {print $2}')
8125         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8126                awk '/ldlm_bl_callback/ {print $2}')
8127         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8128         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8129         lru_resize_enable mdc
8130         lru_resize_enable osc
8131 }
8132 run_test 120d "Early Lock Cancel: setattr test"
8133
8134 test_120e() {
8135         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8136         test_mkdir -p -c1 $DIR/$tdir
8137         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8138                skip "no early lock cancel on server" && return 0
8139         lru_resize_disable mdc
8140         lru_resize_disable osc
8141         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
8142         cancel_lru_locks mdc
8143         cancel_lru_locks osc
8144         dd if=$DIR/$tdir/f1 of=/dev/null
8145         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
8146         # XXX client can not do early lock cancel of OST lock
8147         # during unlink (LU-4206), so cancel osc lock now.
8148         cancel_lru_locks osc
8149         can1=$(do_facet $SINGLEMDS \
8150                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8151                awk '/ldlm_cancel/ {print $2}')
8152         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8153                awk '/ldlm_bl_callback/ {print $2}')
8154         unlink $DIR/$tdir/f1
8155         sleep 5
8156         can2=$(do_facet $SINGLEMDS \
8157                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8158                awk '/ldlm_cancel/ {print $2}')
8159         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8160                awk '/ldlm_bl_callback/ {print $2}')
8161         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8162         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8163         lru_resize_enable mdc
8164         lru_resize_enable osc
8165 }
8166 run_test 120e "Early Lock Cancel: unlink test"
8167
8168 test_120f() {
8169         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8170         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8171                skip "no early lock cancel on server" && return 0
8172         test_mkdir -p -c1 $DIR/$tdir
8173         lru_resize_disable mdc
8174         lru_resize_disable osc
8175         test_mkdir -p -c1 $DIR/$tdir/d1
8176         test_mkdir -p -c1 $DIR/$tdir/d2
8177         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
8178         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
8179         cancel_lru_locks mdc
8180         cancel_lru_locks osc
8181         dd if=$DIR/$tdir/d1/f1 of=/dev/null
8182         dd if=$DIR/$tdir/d2/f2 of=/dev/null
8183         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
8184         # XXX client can not do early lock cancel of OST lock
8185         # during rename (LU-4206), so cancel osc lock now.
8186         cancel_lru_locks osc
8187         can1=$(do_facet $SINGLEMDS \
8188                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8189                awk '/ldlm_cancel/ {print $2}')
8190         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8191                awk '/ldlm_bl_callback/ {print $2}')
8192         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8193         sleep 5
8194         can2=$(do_facet $SINGLEMDS \
8195                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8196                awk '/ldlm_cancel/ {print $2}')
8197         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8198                awk '/ldlm_bl_callback/ {print $2}')
8199         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8200         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8201         lru_resize_enable mdc
8202         lru_resize_enable osc
8203 }
8204 run_test 120f "Early Lock Cancel: rename test"
8205
8206 test_120g() {
8207         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8208         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8209                skip "no early lock cancel on server" && return 0
8210         lru_resize_disable mdc
8211         lru_resize_disable osc
8212         count=10000
8213         echo create $count files
8214         test_mkdir -p $DIR/$tdir
8215         cancel_lru_locks mdc
8216         cancel_lru_locks osc
8217         t0=`date +%s`
8218
8219         can0=$(do_facet $SINGLEMDS \
8220                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8221                awk '/ldlm_cancel/ {print $2}')
8222         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8223                awk '/ldlm_bl_callback/ {print $2}')
8224         createmany -o $DIR/$tdir/f $count
8225         sync
8226         can1=$(do_facet $SINGLEMDS \
8227                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8228                awk '/ldlm_cancel/ {print $2}')
8229         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8230                awk '/ldlm_bl_callback/ {print $2}')
8231         t1=$(date +%s)
8232         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
8233         echo rm $count files
8234         rm -r $DIR/$tdir
8235         sync
8236         can2=$(do_facet $SINGLEMDS \
8237                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8238                awk '/ldlm_cancel/ {print $2}')
8239         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8240                awk '/ldlm_bl_callback/ {print $2}')
8241         t2=$(date +%s)
8242         echo total: $count removes in $((t2-t1))
8243         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
8244         sleep 2
8245         # wait for commitment of removal
8246         lru_resize_enable mdc
8247         lru_resize_enable osc
8248 }
8249 run_test 120g "Early Lock Cancel: performance test"
8250
8251 test_121() { #bug #10589
8252         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8253         rm -rf $DIR/$tfile
8254         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8255 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8256         lctl set_param fail_loc=0x310
8257         cancel_lru_locks osc > /dev/null
8258         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8259         lctl set_param fail_loc=0
8260         [[ $reads -eq $writes ]] ||
8261                 error "read $reads blocks, must be $writes blocks"
8262 }
8263 run_test 121 "read cancel race ========="
8264
8265 test_123a() { # was test 123, statahead(bug 11401)
8266         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8267         SLOWOK=0
8268         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8269             log "testing on UP system. Performance may be not as good as expected."
8270                         SLOWOK=1
8271         fi
8272
8273         rm -rf $DIR/$tdir
8274         test_mkdir -p $DIR/$tdir
8275         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8276         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8277         MULT=10
8278         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8279                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8280
8281                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8282                 lctl set_param -n llite.*.statahead_max 0
8283                 lctl get_param llite.*.statahead_max
8284                 cancel_lru_locks mdc
8285                 cancel_lru_locks osc
8286                 stime=`date +%s`
8287                 time ls -l $DIR/$tdir | wc -l
8288                 etime=`date +%s`
8289                 delta=$((etime - stime))
8290                 log "ls $i files without statahead: $delta sec"
8291                 lctl set_param llite.*.statahead_max=$max
8292
8293                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8294                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8295                 cancel_lru_locks mdc
8296                 cancel_lru_locks osc
8297                 stime=`date +%s`
8298                 time ls -l $DIR/$tdir | wc -l
8299                 etime=`date +%s`
8300                 delta_sa=$((etime - stime))
8301                 log "ls $i files with statahead: $delta_sa sec"
8302                 lctl get_param -n llite.*.statahead_stats
8303                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8304
8305                 [[ $swrong -lt $ewrong ]] &&
8306                         log "statahead was stopped, maybe too many locks held!"
8307                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8308
8309                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8310                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8311                     lctl set_param -n llite.*.statahead_max 0
8312                     lctl get_param llite.*.statahead_max
8313                     cancel_lru_locks mdc
8314                     cancel_lru_locks osc
8315                     stime=`date +%s`
8316                     time ls -l $DIR/$tdir | wc -l
8317                     etime=`date +%s`
8318                     delta=$((etime - stime))
8319                     log "ls $i files again without statahead: $delta sec"
8320                     lctl set_param llite.*.statahead_max=$max
8321                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8322                         if [  $SLOWOK -eq 0 ]; then
8323                                 error "ls $i files is slower with statahead!"
8324                         else
8325                                 log "ls $i files is slower with statahead!"
8326                         fi
8327                         break
8328                     fi
8329                 fi
8330
8331                 [ $delta -gt 20 ] && break
8332                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8333                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8334         done
8335         log "ls done"
8336
8337         stime=`date +%s`
8338         rm -r $DIR/$tdir
8339         sync
8340         etime=`date +%s`
8341         delta=$((etime - stime))
8342         log "rm -r $DIR/$tdir/: $delta seconds"
8343         log "rm done"
8344         lctl get_param -n llite.*.statahead_stats
8345 }
8346 run_test 123a "verify statahead work"
8347
8348 test_123b () { # statahead(bug 15027)
8349         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8350         test_mkdir -p $DIR/$tdir
8351         createmany -o $DIR/$tdir/$tfile-%d 1000
8352
8353         cancel_lru_locks mdc
8354         cancel_lru_locks osc
8355
8356 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8357         lctl set_param fail_loc=0x80000803
8358         ls -lR $DIR/$tdir > /dev/null
8359         log "ls done"
8360         lctl set_param fail_loc=0x0
8361         lctl get_param -n llite.*.statahead_stats
8362         rm -r $DIR/$tdir
8363         sync
8364
8365 }
8366 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8367
8368 test_124a() {
8369         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8370         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8371                 skip "no lru resize on server" && return 0
8372         local NR=2000
8373         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8374
8375         log "create $NR files at $DIR/$tdir"
8376         createmany -o $DIR/$tdir/f $NR ||
8377                 error "failed to create $NR files in $DIR/$tdir"
8378
8379         cancel_lru_locks mdc
8380         ls -l $DIR/$tdir > /dev/null
8381
8382         local NSDIR=""
8383         local LRU_SIZE=0
8384         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8385                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8386                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8387                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8388                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8389                         log "NSDIR=$NSDIR"
8390                         log "NS=$(basename $NSDIR)"
8391                         break
8392                 fi
8393         done
8394
8395         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8396                 skip "Not enough cached locks created!"
8397                 return 0
8398         fi
8399         log "LRU=$LRU_SIZE"
8400
8401         local SLEEP=30
8402
8403         # We know that lru resize allows one client to hold $LIMIT locks
8404         # for 10h. After that locks begin to be killed by client.
8405         local MAX_HRS=10
8406         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8407         log "LIMIT=$LIMIT"
8408         if [ $LIMIT -lt $LRU_SIZE ]; then
8409             skip "Limit is too small $LIMIT"
8410             return 0
8411         fi
8412
8413         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8414         # killing locks. Some time was spent for creating locks. This means
8415         # that up to the moment of sleep finish we must have killed some of
8416         # them (10-100 locks). This depends on how fast ther were created.
8417         # Many of them were touched in almost the same moment and thus will
8418         # be killed in groups.
8419         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8420
8421         # Use $LRU_SIZE_B here to take into account real number of locks
8422         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8423         local LRU_SIZE_B=$LRU_SIZE
8424         log "LVF=$LVF"
8425         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8426         log "OLD_LVF=$OLD_LVF"
8427         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8428
8429         # Let's make sure that we really have some margin. Client checks
8430         # cached locks every 10 sec.
8431         SLEEP=$((SLEEP+20))
8432         log "Sleep ${SLEEP} sec"
8433         local SEC=0
8434         while ((SEC<$SLEEP)); do
8435                 echo -n "..."
8436                 sleep 5
8437                 SEC=$((SEC+5))
8438                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8439                 echo -n "$LRU_SIZE"
8440         done
8441         echo ""
8442         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8443         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8444
8445         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8446                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8447                 unlinkmany $DIR/$tdir/f $NR
8448                 return
8449         }
8450
8451         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8452         log "unlink $NR files at $DIR/$tdir"
8453         unlinkmany $DIR/$tdir/f $NR
8454 }
8455 run_test 124a "lru resize ======================================="
8456
8457 get_max_pool_limit()
8458 {
8459         local limit=$($LCTL get_param \
8460                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8461         local max=0
8462         for l in $limit; do
8463                 if [[ $l -gt $max ]]; then
8464                         max=$l
8465                 fi
8466         done
8467         echo $max
8468 }
8469
8470 test_124b() {
8471         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8472         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8473                 skip "no lru resize on server" && return 0
8474
8475         LIMIT=$(get_max_pool_limit)
8476
8477         NR=$(($(default_lru_size)*20))
8478         if [[ $NR -gt $LIMIT ]]; then
8479                 log "Limit lock number by $LIMIT locks"
8480                 NR=$LIMIT
8481         fi
8482         lru_resize_disable mdc
8483         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8484                 error "failed to create $DIR/$tdir/disable_lru_resize"
8485
8486         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8487         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8488         cancel_lru_locks mdc
8489         stime=`date +%s`
8490         PID=""
8491         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8492         PID="$PID $!"
8493         sleep 2
8494         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8495         PID="$PID $!"
8496         sleep 2
8497         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8498         PID="$PID $!"
8499         wait $PID
8500         etime=`date +%s`
8501         nolruresize_delta=$((etime-stime))
8502         log "ls -la time: $nolruresize_delta seconds"
8503         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8504         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8505
8506         lru_resize_enable mdc
8507         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8508                 error "failed to create $DIR/$tdir/enable_lru_resize"
8509
8510         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8511         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8512         cancel_lru_locks mdc
8513         stime=`date +%s`
8514         PID=""
8515         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8516         PID="$PID $!"
8517         sleep 2
8518         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8519         PID="$PID $!"
8520         sleep 2
8521         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8522         PID="$PID $!"
8523         wait $PID
8524         etime=`date +%s`
8525         lruresize_delta=$((etime-stime))
8526         log "ls -la time: $lruresize_delta seconds"
8527         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8528
8529         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8530                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8531         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8532                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8533         else
8534                 log "lru resize performs the same with no lru resize"
8535         fi
8536         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8537 }
8538 run_test 124b "lru resize (performance test) ======================="
8539
8540 test_124c() {
8541         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8542         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8543                 skip "no lru resize on server" && return 0
8544
8545         # cache ununsed locks on client
8546         local nr=100
8547         cancel_lru_locks mdc
8548         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8549         createmany -o $DIR/$tdir/f $nr ||
8550                 error "failed to create $nr files in $DIR/$tdir"
8551         ls -l $DIR/$tdir > /dev/null
8552
8553         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
8554         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
8555         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
8556         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
8557         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
8558
8559         # set lru_max_age to 1 sec
8560         $LCTL set_param $nsdir.lru_max_age=1000 # jiffies
8561         echo "sleep $((recalc_p * 2)) seconds..."
8562         sleep $((recalc_p * 2))
8563
8564         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
8565         # restore lru_max_age
8566         $LCTL set_param -n $nsdir.lru_max_age $max_age
8567         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
8568         unlinkmany $DIR/$tdir/f $nr
8569 }
8570 run_test 124c "LRUR cancel very aged locks"
8571
8572 test_125() { # 13358
8573         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8574         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8575         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8576         test_mkdir -p $DIR/d125 || error "mkdir failed"
8577         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8578         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8579         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8580 }
8581 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8582
8583 test_126() { # bug 12829/13455
8584         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8585         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8586         $GSS && skip "must run as gss disabled" && return
8587
8588         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8589         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8590         rm -f $DIR/$tfile
8591         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8592 }
8593 run_test 126 "check that the fsgid provided by the client is taken into account"
8594
8595 test_127a() { # bug 15521
8596         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8597         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8598         $LCTL set_param osc.*.stats=0
8599         FSIZE=$((2048 * 1024))
8600         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8601         cancel_lru_locks osc
8602         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8603
8604         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8605         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8606                 echo "got $COUNT $NAME"
8607                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8608                 eval $NAME=$COUNT || error "Wrong proc format"
8609
8610                 case $NAME in
8611                         read_bytes|write_bytes)
8612                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8613                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8614                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8615                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8616                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8617                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8618                                 error "sumsquare is too small: $SUMSQ"
8619                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8620                                 error "sumsquare is too big: $SUMSQ"
8621                         ;;
8622                         *) ;;
8623                 esac
8624         done < $DIR/${tfile}.tmp
8625
8626         #check that we actually got some stats
8627         [ "$read_bytes" ] || error "Missing read_bytes stats"
8628         [ "$write_bytes" ] || error "Missing write_bytes stats"
8629         [ "$read_bytes" != 0 ] || error "no read done"
8630         [ "$write_bytes" != 0 ] || error "no write done"
8631 }
8632 run_test 127a "verify the client stats are sane"
8633
8634 test_127b() { # bug LU-333
8635         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8636         $LCTL set_param llite.*.stats=0
8637         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8638         # perform 2 reads and writes so MAX is different from SUM.
8639         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8640         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8641         cancel_lru_locks osc
8642         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8643         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8644
8645         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8646         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8647                 echo "got $COUNT $NAME"
8648                 eval $NAME=$COUNT || error "Wrong proc format"
8649
8650         case $NAME in
8651                 read_bytes)
8652                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8653                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8654                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8655                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8656                         ;;
8657                 write_bytes)
8658                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8659                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8660                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8661                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8662                         ;;
8663                         *) ;;
8664                 esac
8665         done < $TMP/${tfile}.tmp
8666
8667         #check that we actually got some stats
8668         [ "$read_bytes" ] || error "Missing read_bytes stats"
8669         [ "$write_bytes" ] || error "Missing write_bytes stats"
8670         [ "$read_bytes" != 0 ] || error "no read done"
8671         [ "$write_bytes" != 0 ] || error "no write done"
8672 }
8673 run_test 127b "verify the llite client stats are sane"
8674
8675 test_128() { # bug 15212
8676         touch $DIR/$tfile
8677         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8678                 find $DIR/$tfile
8679                 find $DIR/$tfile
8680         EOF
8681
8682         result=$(grep error $TMP/$tfile.log)
8683         rm -f $DIR/$tfile
8684         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8685 }
8686 run_test 128 "interactive lfs for 2 consecutive find's"
8687
8688 set_dir_limits () {
8689         local mntdev
8690         local canondev
8691         local node
8692
8693         local LDPROC=/proc/fs/ldiskfs
8694         local facets=$(get_facets MDS)
8695
8696         for facet in ${facets//,/ }; do
8697                 canondev=$(ldiskfs_canon \
8698                            *.$(convert_facet2label $facet).mntdev $facet)
8699                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8700                                                 LDPROC=/sys/fs/ldiskfs
8701                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8702                 do_facet $facet "test -e $LDPROC/$canondev/warning_dir_size" ||
8703                                                 LDPROC=/sys/fs/ldiskfs
8704                 do_facet $facet "echo $2 >$LDPROC/$canondev/warning_dir_size"
8705         done
8706 }
8707
8708 check_mds_dmesg() {
8709         local facets=$(get_facets MDS)
8710         for facet in ${facets//,/ }; do
8711                 do_facet $facet "dmesg | tail -3 | grep -q $1" && return 0
8712         done
8713         return 1
8714 }
8715
8716 test_129() {
8717         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8718         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8719                 skip "Only applicable to ldiskfs-based MDTs"
8720                 return
8721         fi
8722         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8723         ENOSPC=28
8724         EFBIG=27
8725         has_warning=0
8726
8727         rm -rf $DIR/$tdir
8728         test_mkdir -p $DIR/$tdir
8729
8730         # block size of mds1
8731         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8732         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8733         local MAX=$((MDSBLOCKSIZE * 5))
8734         set_dir_limits $MAX $MAX
8735         local I=$(stat -c%s "$DIR/$tdir")
8736         local J=0
8737         local STRIPE_COUNT=1
8738         [[ $MDSCOUNT -ge 2 ]] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8739         MAX=$((MAX*STRIPE_COUNT))
8740         while [[ $I -le $MAX ]]; do
8741                 $MULTIOP $DIR/$tdir/$J Oc
8742                 rc=$?
8743                 if [ $has_warning -eq 0 ]; then
8744                         check_mds_dmesg '"is approaching"' &&
8745                                 has_warning=1
8746                 fi
8747                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8748                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8749                 #and EFBIG for previous versions
8750                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8751                         set_dir_limits 0 0
8752                         echo "return code $rc received as expected"
8753                         multiop $DIR/$tdir/$J Oc ||
8754                                 error_exit "multiop failed w/o dir size limit"
8755
8756                         check_mds_dmesg '"has reached"' ||
8757                                 error_exit "has reached message should be output"
8758
8759                         [ $has_warning ] ||
8760                                 error_exit "warning message should be output"
8761
8762                         I=$(stat -c%s "$DIR/$tdir")
8763
8764                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8765                                         $(version_code 2.4.51) ]
8766                         then
8767                                 [[ $I -eq $MAX ]] && return 0
8768                         else
8769                                 [[ $I -gt $MAX ]] && return 0
8770                         fi
8771                         error_exit "current dir size $I, previous limit $MAX"
8772                 elif [ $rc -ne 0 ]; then
8773                         set_dir_limits 0 0
8774                         error_exit "return code $rc received instead of expected " \
8775                                    "$EFBIG or $ENOSPC, files in dir $I"
8776                 fi
8777                 J=$((J+1))
8778                 I=$(stat -c%s "$DIR/$tdir")
8779         done
8780
8781         set_dir_limits 0 0
8782         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8783 }
8784 run_test 129 "test directory size limit ========================"
8785
8786 OLDIFS="$IFS"
8787 cleanup_130() {
8788         trap 0
8789         IFS="$OLDIFS"
8790 }
8791
8792 test_130a() {
8793         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8794         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8795                 return
8796
8797         trap cleanup_130 EXIT RETURN
8798
8799         local fm_file=$DIR/$tfile
8800         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8801         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8802                 error "dd failed for $fm_file"
8803
8804         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8805         filefrag -ves $fm_file
8806         RC=$?
8807         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8808                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8809         [ $RC != 0 ] && error "filefrag $fm_file failed"
8810
8811         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8812                       grep -v "ext:" | grep -v "found")
8813         lun=$($GETSTRIPE -i $fm_file)
8814
8815         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8816         IFS=$'\n'
8817         tot_len=0
8818         for line in $filefrag_op
8819         do
8820                 frag_lun=`echo $line | cut -d: -f5`
8821                 ext_len=`echo $line | cut -d: -f4`
8822                 if (( $frag_lun != $lun )); then
8823                         cleanup_130
8824                         error "FIEMAP on 1-stripe file($fm_file) failed"
8825                         return
8826                 fi
8827                 (( tot_len += ext_len ))
8828         done
8829
8830         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8831                 cleanup_130
8832                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8833                 return
8834         fi
8835
8836         cleanup_130
8837
8838         echo "FIEMAP on single striped file succeeded"
8839 }
8840 run_test 130a "FIEMAP (1-stripe file)"
8841
8842 test_130b() {
8843         [ "$OSTCOUNT" -lt "2" ] &&
8844                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8845
8846         [ "$OSTCOUNT" -ge "10" ] &&
8847                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8848
8849         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8850         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8851                 return
8852
8853         trap cleanup_130 EXIT RETURN
8854
8855         local fm_file=$DIR/$tfile
8856         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8857         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8858                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8859
8860         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8861                 error "dd failed on $fm_file"
8862
8863         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8864         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8865                       grep -v "ext:" | grep -v "found")
8866
8867         last_lun=$(echo $filefrag_op | cut -d: -f5)
8868
8869         IFS=$'\n'
8870         tot_len=0
8871         num_luns=1
8872         for line in $filefrag_op
8873         do
8874                 frag_lun=`echo $line | cut -d: -f5`
8875                 ext_len=`echo $line | cut -d: -f4`
8876                 if (( $frag_lun != $last_lun )); then
8877                         if (( tot_len != 1024 )); then
8878                                 cleanup_130
8879                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8880                                 return
8881                         else
8882                                 (( num_luns += 1 ))
8883                                 tot_len=0
8884                         fi
8885                 fi
8886                 (( tot_len += ext_len ))
8887                 last_lun=$frag_lun
8888         done
8889         if (( num_luns != 2 || tot_len != 1024 )); then
8890                 cleanup_130
8891                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8892                 return
8893         fi
8894
8895         cleanup_130
8896
8897         echo "FIEMAP on 2-stripe file succeeded"
8898 }
8899 run_test 130b "FIEMAP (2-stripe file)"
8900
8901 test_130c() {
8902         [ "$OSTCOUNT" -lt "2" ] &&
8903                 skip_env "skipping FIEMAP on 2-stripe file" && return
8904
8905         [ "$OSTCOUNT" -ge "10" ] &&
8906                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8907
8908         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8909         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8910                 return
8911
8912         trap cleanup_130 EXIT RETURN
8913
8914         local fm_file=$DIR/$tfile
8915         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8916         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8917                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8918
8919         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8920
8921         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8922         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8923
8924         last_lun=`echo $filefrag_op | cut -d: -f5`
8925
8926         IFS=$'\n'
8927         tot_len=0
8928         num_luns=1
8929         for line in $filefrag_op
8930         do
8931                 frag_lun=`echo $line | cut -d: -f5`
8932                 ext_len=`echo $line | cut -d: -f4`
8933                 if (( $frag_lun != $last_lun )); then
8934                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8935                         if (( logical != 512 )); then
8936                                 cleanup_130
8937                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8938                                 return
8939                         fi
8940                         if (( tot_len != 512 )); then
8941                                 cleanup_130
8942                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8943                                 return
8944                         else
8945                                 (( num_luns += 1 ))
8946                                 tot_len=0
8947                         fi
8948                 fi
8949                 (( tot_len += ext_len ))
8950                 last_lun=$frag_lun
8951         done
8952         if (( num_luns != 2 || tot_len != 512 )); then
8953                 cleanup_130
8954                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8955                 return
8956         fi
8957
8958         cleanup_130
8959
8960         echo "FIEMAP on 2-stripe file with hole succeeded"
8961 }
8962 run_test 130c "FIEMAP (2-stripe file with hole)"
8963
8964 test_130d() {
8965         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8966
8967         [ "$OSTCOUNT" -ge "10" ] &&
8968                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8969
8970         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8971         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8972
8973         trap cleanup_130 EXIT RETURN
8974
8975         local fm_file=$DIR/$tfile
8976         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8977         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8978                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8979
8980         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8981         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8982                 error "dd failed on $fm_file"
8983
8984         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8985         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8986                 grep -v "ext:" | grep -v "found"`
8987
8988         last_lun=`echo $filefrag_op | cut -d: -f5`
8989
8990         IFS=$'\n'
8991         tot_len=0
8992         num_luns=1
8993         for line in $filefrag_op
8994         do
8995                 frag_lun=`echo $line | cut -d: -f5`
8996                 ext_len=`echo $line | cut -d: -f4`
8997                 if (( $frag_lun != $last_lun )); then
8998                         if (( tot_len != 1024 )); then
8999                                 cleanup_130
9000                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
9001                                 return
9002                         else
9003                                 (( num_luns += 1 ))
9004                                 tot_len=0
9005                         fi
9006                 fi
9007                 (( tot_len += ext_len ))
9008                 last_lun=$frag_lun
9009         done
9010         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
9011                 cleanup_130
9012                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
9013                 return
9014         fi
9015
9016         cleanup_130
9017
9018         echo "FIEMAP on N-stripe file succeeded"
9019 }
9020 run_test 130d "FIEMAP (N-stripe file)"
9021
9022 test_130e() {
9023         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
9024
9025         [ "$OSTCOUNT" -ge "10" ] &&
9026                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
9027
9028         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9029         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
9030
9031         trap cleanup_130 EXIT RETURN
9032
9033         local fm_file=$DIR/$tfile
9034         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
9035         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9036                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9037
9038         NUM_BLKS=512
9039         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
9040         for ((i = 0; i < $NUM_BLKS; i++))
9041         do
9042                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
9043         done
9044
9045         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9046         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
9047
9048         last_lun=`echo $filefrag_op | cut -d: -f5`
9049
9050         IFS=$'\n'
9051         tot_len=0
9052         num_luns=1
9053         for line in $filefrag_op
9054         do
9055                 frag_lun=`echo $line | cut -d: -f5`
9056                 ext_len=`echo $line | cut -d: -f4`
9057                 if (( $frag_lun != $last_lun )); then
9058                         if (( tot_len != $EXPECTED_LEN )); then
9059                                 cleanup_130
9060                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
9061                                 return
9062                         else
9063                                 (( num_luns += 1 ))
9064                                 tot_len=0
9065                         fi
9066                 fi
9067                 (( tot_len += ext_len ))
9068                 last_lun=$frag_lun
9069         done
9070         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
9071                 cleanup_130
9072                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
9073                 return
9074         fi
9075
9076         cleanup_130
9077
9078         echo "FIEMAP with continuation calls succeeded"
9079 }
9080 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
9081
9082 # Test for writev/readv
9083 test_131a() {
9084         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
9085         error "writev test failed"
9086         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
9087         error "readv failed"
9088         rm -f $DIR/$tfile
9089 }
9090 run_test 131a "test iov's crossing stripe boundary for writev/readv"
9091
9092 test_131b() {
9093         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
9094         error "append writev test failed"
9095         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
9096         error "append writev test failed"
9097         rm -f $DIR/$tfile
9098 }
9099 run_test 131b "test append writev"
9100
9101 test_131c() {
9102         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
9103         error "NOT PASS"
9104 }
9105 run_test 131c "test read/write on file w/o objects"
9106
9107 test_131d() {
9108         rwv -f $DIR/$tfile -w -n 1 1572864
9109         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
9110         if [ "$NOB" != 1572864 ]; then
9111                 error "Short read filed: read $NOB bytes instead of 1572864"
9112         fi
9113         rm -f $DIR/$tfile
9114 }
9115 run_test 131d "test short read"
9116
9117 test_131e() {
9118         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
9119         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
9120         error "read hitting hole failed"
9121         rm -f $DIR/$tfile
9122 }
9123 run_test 131e "test read hitting hole"
9124
9125 check_stats() {
9126         local res
9127         local count
9128         case $1 in
9129         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
9130                  ;;
9131         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
9132                  ;;
9133         *) error "Wrong argument $1" ;;
9134         esac
9135         echo $res
9136         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
9137         # if the argument $3 is zero, it means any stat increment is ok.
9138         if [[ $3 -gt 0 ]]; then
9139                 count=$(echo $res | awk '{ print $2 }')
9140                 [[ $count -ne $3 ]] &&
9141                         error "The $2 counter on $1 is wrong - expected $3"
9142         fi
9143 }
9144
9145 test_133a() {
9146         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9147         remote_ost_nodsh && skip "remote OST with nodsh" && return
9148         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9149
9150         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9151                 { skip "MDS doesn't support rename stats"; return; }
9152         local testdir=$DIR/${tdir}/stats_testdir
9153         mkdir -p $DIR/${tdir}
9154
9155         # clear stats.
9156         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9157         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9158
9159         # verify mdt stats first.
9160         mkdir ${testdir} || error "mkdir failed"
9161         check_stats $SINGLEMDS "mkdir" 1
9162         touch ${testdir}/${tfile} || "touch failed"
9163         check_stats $SINGLEMDS "open" 1
9164         check_stats $SINGLEMDS "close" 1
9165         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
9166         check_stats $SINGLEMDS "mknod" 1
9167         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
9168         check_stats $SINGLEMDS "unlink" 1
9169         rm -f ${testdir}/${tfile} || error "file remove failed"
9170         check_stats $SINGLEMDS "unlink" 2
9171
9172         # remove working dir and check mdt stats again.
9173         rmdir ${testdir} || error "rmdir failed"
9174         check_stats $SINGLEMDS "rmdir" 1
9175
9176         local testdir1=$DIR/${tdir}/stats_testdir1
9177         mkdir -p ${testdir}
9178         mkdir -p ${testdir1}
9179         touch ${testdir1}/test1
9180         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
9181         check_stats $SINGLEMDS "crossdir_rename" 1
9182
9183         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
9184         check_stats $SINGLEMDS "samedir_rename" 1
9185
9186         rm -rf $DIR/${tdir}
9187 }
9188 run_test 133a "Verifying MDT stats ========================================"
9189
9190 test_133b() {
9191         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9192         remote_ost_nodsh && skip "remote OST with nodsh" && return
9193         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9194         local testdir=$DIR/${tdir}/stats_testdir
9195         mkdir -p ${testdir} || error "mkdir failed"
9196         touch ${testdir}/${tfile} || "touch failed"
9197         cancel_lru_locks mdc
9198
9199         # clear stats.
9200         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9201         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9202
9203         # extra mdt stats verification.
9204         chmod 444 ${testdir}/${tfile} || error "chmod failed"
9205         check_stats $SINGLEMDS "setattr" 1
9206         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9207         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
9208         then            # LU-1740
9209                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
9210                 check_stats $SINGLEMDS "getattr" 1
9211         fi
9212         $LFS df || error "lfs failed"
9213         check_stats $SINGLEMDS "statfs" 1
9214
9215         rm -rf $DIR/${tdir}
9216 }
9217 run_test 133b "Verifying extra MDT stats =================================="
9218
9219 test_133c() {
9220         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9221         remote_ost_nodsh && skip "remote OST with nodsh" && return
9222         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9223         local testdir=$DIR/${tdir}/stats_testdir
9224         test_mkdir -p ${testdir} || error "mkdir failed"
9225
9226         # verify obdfilter stats.
9227         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9228         sync
9229         cancel_lru_locks osc
9230         wait_delete_completed
9231
9232         # clear stats.
9233         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9234         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9235
9236         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
9237         sync
9238         cancel_lru_locks osc
9239         check_stats ost "write" 1
9240
9241         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9242         check_stats ost "read" 1
9243
9244         > ${testdir}/${tfile} || error "truncate failed"
9245         check_stats ost "punch" 1
9246
9247         rm -f ${testdir}/${tfile} || error "file remove failed"
9248         wait_delete_completed
9249         check_stats ost "destroy" 1
9250
9251         rm -rf $DIR/${tdir}
9252 }
9253 run_test 133c "Verifying OST stats ========================================"
9254
9255 order_2() {
9256         local value=$1
9257         local orig=$value
9258         local order=1
9259
9260         while [ $value -ge 2 ]; do
9261                 order=$((order*2))
9262                 value=$((value/2))
9263         done
9264
9265         if [ $orig -gt $order ]; then
9266                 order=$((order*2))
9267         fi
9268         echo $order
9269 }
9270
9271 size_in_KMGT() {
9272     local value=$1
9273     local size=('K' 'M' 'G' 'T');
9274     local i=0
9275     local size_string=$value
9276
9277     while [ $value -ge 1024 ]; do
9278         if [ $i -gt 3 ]; then
9279             #T is the biggest unit we get here, if that is bigger,
9280             #just return XXXT
9281             size_string=${value}T
9282             break
9283         fi
9284         value=$((value >> 10))
9285         if [ $value -lt 1024 ]; then
9286             size_string=${value}${size[$i]}
9287             break
9288         fi
9289         i=$((i + 1))
9290     done
9291
9292     echo $size_string
9293 }
9294
9295 get_rename_size() {
9296     local size=$1
9297     local context=${2:-.}
9298     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9299                 grep -A1 $context |
9300                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9301     echo $sample
9302 }
9303
9304 test_133d() {
9305         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9306         remote_ost_nodsh && skip "remote OST with nodsh" && return
9307         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9308         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9309         { skip "MDS doesn't support rename stats"; return; }
9310
9311         local testdir1=$DIR/${tdir}/stats_testdir1
9312         local testdir2=$DIR/${tdir}/stats_testdir2
9313
9314         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9315
9316         mkdir -p ${testdir1} || error "mkdir failed"
9317         mkdir -p ${testdir2} || error "mkdir failed"
9318
9319         createmany -o $testdir1/test 512 || error "createmany failed"
9320
9321         # check samedir rename size
9322         mv ${testdir1}/test0 ${testdir1}/test_0
9323
9324         local testdir1_size=$(ls -l $DIR/${tdir} |
9325                 awk '/stats_testdir1/ {print $5}')
9326         local testdir2_size=$(ls -l $DIR/${tdir} |
9327                 awk '/stats_testdir2/ {print $5}')
9328
9329         testdir1_size=$(order_2 $testdir1_size)
9330         testdir2_size=$(order_2 $testdir2_size)
9331
9332         testdir1_size=$(size_in_KMGT $testdir1_size)
9333         testdir2_size=$(size_in_KMGT $testdir2_size)
9334
9335         echo "source rename dir size: ${testdir1_size}"
9336         echo "target rename dir size: ${testdir2_size}"
9337
9338         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9339         eval $cmd || error "$cmd failed"
9340         local samedir=$($cmd | grep 'same_dir')
9341         local same_sample=$(get_rename_size $testdir1_size)
9342         [ -z "$samedir" ] && error "samedir_rename_size count error"
9343         [[ $same_sample -eq 1 ]] ||
9344                 error "samedir_rename_size error $same_sample"
9345         echo "Check same dir rename stats success"
9346
9347         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9348
9349         # check crossdir rename size
9350         mv ${testdir1}/test_0 ${testdir2}/test_0
9351
9352         testdir1_size=$(ls -l $DIR/${tdir} |
9353                 awk '/stats_testdir1/ {print $5}')
9354         testdir2_size=$(ls -l $DIR/${tdir} |
9355                 awk '/stats_testdir2/ {print $5}')
9356
9357         testdir1_size=$(order_2 $testdir1_size)
9358         testdir2_size=$(order_2 $testdir2_size)
9359
9360         testdir1_size=$(size_in_KMGT $testdir1_size)
9361         testdir2_size=$(size_in_KMGT $testdir2_size)
9362
9363         echo "source rename dir size: ${testdir1_size}"
9364         echo "target rename dir size: ${testdir2_size}"
9365
9366         eval $cmd || error "$cmd failed"
9367         local crossdir=$($cmd | grep 'crossdir')
9368         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9369         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9370         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9371         [[ $src_sample -eq 1 ]] ||
9372                 error "crossdir_rename_size error $src_sample"
9373         [[ $tgt_sample -eq 1 ]] ||
9374                 error "crossdir_rename_size error $tgt_sample"
9375         echo "Check cross dir rename stats success"
9376         rm -rf $DIR/${tdir}
9377 }
9378 run_test 133d "Verifying rename_stats ========================================"
9379
9380 test_133e() {
9381         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9382         remote_ost_nodsh && skip "remote OST with nodsh" && return
9383         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9384         local testdir=$DIR/${tdir}/stats_testdir
9385         local ctr f0 f1 bs=32768 count=42 sum
9386
9387         mkdir -p ${testdir} || error "mkdir failed"
9388
9389         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9390
9391         for ctr in {write,read}_bytes; do
9392                 sync
9393                 cancel_lru_locks osc
9394
9395                 do_facet ost1 $LCTL set_param -n \
9396                         "obdfilter.*.exports.clear=clear"
9397
9398                 if [ $ctr = write_bytes ]; then
9399                         f0=/dev/zero
9400                         f1=${testdir}/${tfile}
9401                 else
9402                         f0=${testdir}/${tfile}
9403                         f1=/dev/null
9404                 fi
9405
9406                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9407                         error "dd failed"
9408                 sync
9409                 cancel_lru_locks osc
9410
9411                 sum=$(do_facet ost1 $LCTL get_param \
9412                         "obdfilter.*.exports.*.stats" |
9413                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9414                                 $1 == ctr { sum += $7 }
9415                                 END { printf("%0.0f", sum) }')
9416
9417                 if ((sum != bs * count)); then
9418                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9419                 fi
9420         done
9421
9422         rm -rf $DIR/${tdir}
9423 }
9424 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9425
9426 proc_dirs=""
9427 for dir in /proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9428            /sys/fs/lustre/ /sys/fs/lnet/ /sys/kernel/debug/lustre/; do
9429         [[ -d $dir ]] && proc_dirs+=" $dir"
9430 done
9431
9432 test_133f() {
9433         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9434         remote_ost_nodsh && skip "remote OST with nodsh" && return
9435         # First without trusting modes.
9436         find $proc_dirs -exec cat '{}' \; &> /dev/null
9437
9438         # Second verifying readability.
9439         $LCTL get_param -R &> /dev/null || error "proc file read failed"
9440
9441         # eventually, this can also be replaced with "lctl get_param -R",
9442         # but not until that option is always available on the server
9443         local facet
9444         for facet in $SINGLEMDS ost1; do
9445                 do_facet $facet find $proc_dirs \
9446                         ! -name req_history \
9447                         -exec cat '{}' \\\; &> /dev/null
9448
9449                 do_facet $facet find $proc_dirs \
9450                         ! -name req_history \
9451                         -type f \
9452                         -exec cat '{}' \\\; &> /dev/null ||
9453                                 error "proc file read failed"
9454         done
9455 }
9456 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9457
9458 test_133g() {
9459         # Second verifying writability.
9460         find $proc_dirs \
9461                 -type f \
9462                 -not -name force_lbug \
9463                 -not -name changelog_mask \
9464                 -exec badarea_io '{}' \; &> /dev/null ||
9465                 error "find $proc_dirs failed"
9466
9467         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
9468                 skip "Too old lustre on MDS" && return
9469
9470         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
9471                 skip "Too old lustre on ost1" && return
9472
9473         local facet
9474         for facet in $SINGLEMDS ost1; do
9475                 do_facet $facet find $proc_dirs \
9476                         -type f \
9477                         -not -name force_lbug \
9478                         -not -name changelog_mask \
9479                         -exec badarea_io '{}' \\\; &> /dev/null ||
9480                 error "$facet find $proc_dirs failed"
9481
9482         done
9483
9484         # remount the FS in case writes/reads /proc break the FS
9485         cleanup || error "failed to unmount"
9486         setup || error "failed to setup"
9487         true
9488 }
9489 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9490
9491 test_134a() {
9492         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
9493                 skip "Need MDS version at least 2.7.54" && return
9494
9495         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9496         cancel_lru_locks mdc
9497
9498         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
9499         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9500         [ $unused -eq 0 ] || "$unused locks are not cleared"
9501
9502         local nr=1000
9503         createmany -o $DIR/$tdir/f $nr ||
9504                 error "failed to create $nr files in $DIR/$tdir"
9505         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9506
9507         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
9508         do_facet mds1 $LCTL set_param fail_loc=0x327
9509         do_facet mds1 $LCTL set_param fail_val=500
9510         touch $DIR/$tdir/m
9511
9512         echo "sleep 10 seconds ..."
9513         sleep 10
9514         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
9515
9516         do_facet mds1 $LCTL set_param fail_loc=0
9517         do_facet mds1 $LCTL set_param fail_val=0
9518         [ $lck_cnt -lt $unused ] ||
9519                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
9520
9521         rm $DIR/$tdir/m
9522         unlinkmany $DIR/$tdir/f $nr
9523 }
9524 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
9525
9526 test_134b() {
9527         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
9528                 skip "Need MDS version at least 2.7.54" && return
9529
9530         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9531         cancel_lru_locks mdc
9532
9533         local low_wm=$(do_facet mds1 $LCTL get_param -n \
9534                         ldlm.lock_reclaim_threshold_mb)
9535         # disable reclaim temporarily
9536         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
9537
9538         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
9539         do_facet mds1 $LCTL set_param fail_loc=0x328
9540         do_facet mds1 $LCTL set_param fail_val=500
9541
9542         $LCTL set_param debug=+trace
9543
9544         local nr=600
9545         createmany -o $DIR/$tdir/f $nr &
9546         local create_pid=$!
9547
9548         echo "Sleep $TIMEOUT seconds ..."
9549         sleep $TIMEOUT
9550         if ! ps -p $create_pid  > /dev/null 2>&1; then
9551                 do_facet mds1 $LCTL set_param fail_loc=0
9552                 do_facet mds1 $LCTL set_param fail_val=0
9553                 do_facet mds1 $LCTL set_param \
9554                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
9555                 error "createmany finished incorrectly!"
9556         fi
9557         do_facet mds1 $LCTL set_param fail_loc=0
9558         do_facet mds1 $LCTL set_param fail_val=0
9559         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
9560         wait $create_pid || return 1
9561
9562         unlinkmany $DIR/$tdir/f $nr
9563 }
9564 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
9565
9566 test_140() { #bug-17379
9567         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9568         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
9569         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
9570         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
9571
9572         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9573         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9574         local i=0
9575         while i=`expr $i + 1`; do
9576                 test_mkdir -p $i || error "Creating dir $i"
9577                 cd $i || error "Changing to $i"
9578                 ln -s ../stat stat || error "Creating stat symlink"
9579                 # Read the symlink until ELOOP present,
9580                 # not LBUGing the system is considered success,
9581                 # we didn't overrun the stack.
9582                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9583                 [ $ret -ne 0 ] && {
9584                         if [ $ret -eq 40 ]; then
9585                                 break  # -ELOOP
9586                         else
9587                                 error "Open stat symlink"
9588                                 return
9589                         fi
9590                 }
9591         done
9592         i=`expr $i - 1`
9593         echo "The symlink depth = $i"
9594         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9595                                         error "Invalid symlink depth"
9596
9597         # Test recursive symlink
9598         ln -s symlink_self symlink_self
9599         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9600         echo "open symlink_self returns $ret"
9601         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9602 }
9603 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9604
9605 test_150() {
9606         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9607         local TF="$TMP/$tfile"
9608
9609         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9610         cp $TF $DIR/$tfile
9611         cancel_lru_locks osc
9612         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9613         remount_client $MOUNT
9614         df -P $MOUNT
9615         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9616
9617         $TRUNCATE $TF 6000
9618         $TRUNCATE $DIR/$tfile 6000
9619         cancel_lru_locks osc
9620         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9621
9622         echo "12345" >>$TF
9623         echo "12345" >>$DIR/$tfile
9624         cancel_lru_locks osc
9625         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9626
9627         echo "12345" >>$TF
9628         echo "12345" >>$DIR/$tfile
9629         cancel_lru_locks osc
9630         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9631
9632         rm -f $TF
9633         true
9634 }
9635 run_test 150 "truncate/append tests"
9636
9637 #LU-2902 roc_hit was not able to read all values from lproc
9638 function roc_hit_init() {
9639         local list=$(comma_list $(osts_nodes))
9640         local dir=$DIR/$tdir-check
9641         local file=$dir/file
9642         local BEFORE
9643         local AFTER
9644         local idx
9645
9646         test_mkdir -p $dir
9647         #use setstripe to do a write to every ost
9648         for i in $(seq 0 $((OSTCOUNT-1))); do
9649                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9650                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9651                 idx=$(printf %04x $i)
9652                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9653                         awk '$1 == "cache_access" {sum += $7}
9654                                 END { printf("%0.0f", sum) }')
9655
9656                 cancel_lru_locks osc
9657                 cat $file >/dev/null
9658
9659                 AFTER=$(get_osd_param $list *OST*$idx stats |
9660                         awk '$1 == "cache_access" {sum += $7}
9661                                 END { printf("%0.0f", sum) }')
9662
9663                 echo BEFORE:$BEFORE AFTER:$AFTER
9664                 if ! let "AFTER - BEFORE == 4"; then
9665                         rm -rf $dir
9666                         error "roc_hit is not safe to use"
9667                 fi
9668                 rm $file
9669         done
9670
9671         rm -rf $dir
9672 }
9673
9674 function roc_hit() {
9675         local list=$(comma_list $(osts_nodes))
9676         echo $(get_osd_param $list '' stats |
9677                 awk '$1 == "cache_hit" {sum += $7}
9678                         END { printf("%0.0f", sum) }')
9679 }
9680
9681 function set_cache() {
9682         local on=1
9683
9684         if [ "$2" == "off" ]; then
9685                 on=0;
9686         fi
9687         local list=$(comma_list $(osts_nodes))
9688         set_osd_param $list '' $1_cache_enable $on
9689
9690         cancel_lru_locks osc
9691 }
9692
9693 test_151() {
9694         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9695         remote_ost_nodsh && skip "remote OST with nodsh" && return
9696
9697         local CPAGES=3
9698         local list=$(comma_list $(osts_nodes))
9699
9700         # check whether obdfilter is cache capable at all
9701         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9702                 echo "not cache-capable obdfilter"
9703                 return 0
9704         fi
9705
9706         # check cache is enabled on all obdfilters
9707         if get_osd_param $list '' read_cache_enable | grep 0; then
9708                 echo "oss cache is disabled"
9709                 return 0
9710         fi
9711
9712         set_osd_param $list '' writethrough_cache_enable 1
9713
9714         # check write cache is enabled on all obdfilters
9715         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9716                 echo "oss write cache is NOT enabled"
9717                 return 0
9718         fi
9719
9720         roc_hit_init
9721
9722         #define OBD_FAIL_OBD_NO_LRU  0x609
9723         do_nodes $list $LCTL set_param fail_loc=0x609
9724
9725         # pages should be in the case right after write
9726         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9727                 error "dd failed"
9728
9729         local BEFORE=$(roc_hit)
9730         cancel_lru_locks osc
9731         cat $DIR/$tfile >/dev/null
9732         local AFTER=$(roc_hit)
9733
9734         do_nodes $list $LCTL set_param fail_loc=0
9735
9736         if ! let "AFTER - BEFORE == CPAGES"; then
9737                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9738         fi
9739
9740         # the following read invalidates the cache
9741         cancel_lru_locks osc
9742         set_osd_param $list '' read_cache_enable 0
9743         cat $DIR/$tfile >/dev/null
9744
9745         # now data shouldn't be found in the cache
9746         BEFORE=$(roc_hit)
9747         cancel_lru_locks osc
9748         cat $DIR/$tfile >/dev/null
9749         AFTER=$(roc_hit)
9750         if let "AFTER - BEFORE != 0"; then
9751                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9752         fi
9753
9754         set_osd_param $list '' read_cache_enable 1
9755         rm -f $DIR/$tfile
9756 }
9757 run_test 151 "test cache on oss and controls ==============================="
9758
9759 test_152() {
9760         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9761         local TF="$TMP/$tfile"
9762
9763         # simulate ENOMEM during write
9764 #define OBD_FAIL_OST_NOMEM      0x226
9765         lctl set_param fail_loc=0x80000226
9766         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9767         cp $TF $DIR/$tfile
9768         sync || error "sync failed"
9769         lctl set_param fail_loc=0
9770
9771         # discard client's cache
9772         cancel_lru_locks osc
9773
9774         # simulate ENOMEM during read
9775         lctl set_param fail_loc=0x80000226
9776         cmp $TF $DIR/$tfile || error "cmp failed"
9777         lctl set_param fail_loc=0
9778
9779         rm -f $TF
9780 }
9781 run_test 152 "test read/write with enomem ============================"
9782
9783 test_153() {
9784         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9785 }
9786 run_test 153 "test if fdatasync does not crash ======================="
9787
9788 dot_lustre_fid_permission_check() {
9789         local fid=$1
9790         local ffid=$MOUNT/.lustre/fid/$fid
9791         local test_dir=$2
9792
9793         echo "stat fid $fid"
9794         stat $ffid > /dev/null || error "stat $ffid failed."
9795         echo "touch fid $fid"
9796         touch $ffid || error "touch $ffid failed."
9797         echo "write to fid $fid"
9798         cat /etc/hosts > $ffid || error "write $ffid failed."
9799         echo "read fid $fid"
9800         diff /etc/hosts $ffid || error "read $ffid failed."
9801         echo "append write to fid $fid"
9802         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9803         echo "rename fid $fid"
9804         mv $ffid $test_dir/$tfile.1 &&
9805                 error "rename $ffid to $tfile.1 should fail."
9806         touch $test_dir/$tfile.1
9807         mv $test_dir/$tfile.1 $ffid &&
9808                 error "rename $tfile.1 to $ffid should fail."
9809         rm -f $test_dir/$tfile.1
9810         echo "truncate fid $fid"
9811         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9812         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9813                 echo "link fid $fid"
9814                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9815         fi
9816         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9817                 echo "setfacl fid $fid"
9818                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9819                 echo "getfacl fid $fid"
9820                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9821         fi
9822         echo "unlink fid $fid"
9823         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9824         echo "mknod fid $fid"
9825         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9826
9827         fid=[0xf00000400:0x1:0x0]
9828         ffid=$MOUNT/.lustre/fid/$fid
9829
9830         echo "stat non-exist fid $fid"
9831         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9832         echo "write to non-exist fid $fid"
9833         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9834         echo "link new fid $fid"
9835         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9836
9837         mkdir -p $test_dir/$tdir
9838         touch $test_dir/$tdir/$tfile
9839         fid=$($LFS path2fid $test_dir/$tdir)
9840         rc=$?
9841         [ $rc -ne 0 ] &&
9842                 error "error: could not get fid for $test_dir/$dir/$tfile."
9843
9844         ffid=$MOUNT/.lustre/fid/$fid
9845
9846         echo "ls $fid"
9847         ls $ffid > /dev/null || error "ls $ffid failed."
9848         echo "touch $fid/$tfile.1"
9849         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9850
9851         echo "touch $MOUNT/.lustre/fid/$tfile"
9852         touch $MOUNT/.lustre/fid/$tfile && \
9853                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9854
9855         echo "setxattr to $MOUNT/.lustre/fid"
9856         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9857
9858         echo "listxattr for $MOUNT/.lustre/fid"
9859         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9860
9861         echo "delxattr from $MOUNT/.lustre/fid"
9862         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9863
9864         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9865         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9866                 error "touch invalid fid should fail."
9867
9868         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9869         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9870                 error "touch non-normal fid should fail."
9871
9872         echo "rename $tdir to $MOUNT/.lustre/fid"
9873         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9874                 error "rename to $MOUNT/.lustre/fid should fail."
9875
9876         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9877         then            # LU-3547
9878                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9879                 local new_obf_mode=777
9880
9881                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9882                 chmod $new_obf_mode $DIR/.lustre/fid ||
9883                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9884
9885                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9886                 [ $obf_mode -eq $new_obf_mode ] ||
9887                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9888
9889                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9890                 chmod $old_obf_mode $DIR/.lustre/fid ||
9891                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9892         fi
9893
9894         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9895         fid=$($LFS path2fid $test_dir/$tfile-2)
9896
9897         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
9898         then # LU-5424
9899                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9900                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
9901                         error "create lov data thru .lustre failed"
9902         fi
9903         echo "cp /etc/passwd $test_dir/$tfile-2"
9904         cp /etc/passwd $test_dir/$tfile-2 ||
9905                 error "copy to $test_dir/$tfile-2 failed."
9906         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9907         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9908                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9909
9910         rm -rf $test_dir/tfile.lnk
9911         rm -rf $test_dir/$tfile-2
9912 }
9913
9914 test_154A() {
9915         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9916                 skip "Need MDS version at least 2.4.1" && return
9917
9918         touch $DIR/$tfile
9919         local FID=$($LFS path2fid $DIR/$tfile)
9920         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9921
9922         # check that we get the same pathname back
9923         local FOUND=$($LFS fid2path $MOUNT "$FID")
9924         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9925         [ "$FOUND" != "$DIR/$tfile" ] &&
9926                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9927
9928         rm -rf $DIR/$tfile
9929 }
9930 run_test 154A "lfs path2fid and fid2path basic checks"
9931
9932 test_154a() {
9933         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9934         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9935                 { skip "Need MDS version at least 2.2.51"; return 0; }
9936         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9937
9938         cp /etc/hosts $DIR/$tfile
9939
9940         fid=$($LFS path2fid $DIR/$tfile)
9941         rc=$?
9942         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9943
9944         dot_lustre_fid_permission_check "$fid" $DIR ||
9945                 error "dot lustre permission check $fid failed"
9946
9947         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9948
9949         touch $MOUNT/.lustre/file &&
9950                 error "creation is not allowed under .lustre"
9951
9952         mkdir $MOUNT/.lustre/dir &&
9953                 error "mkdir is not allowed under .lustre"
9954
9955         rm -rf $DIR/$tfile
9956 }
9957 run_test 154a "Open-by-FID"
9958
9959 test_154b() {
9960         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9961         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9962                 { skip "Need MDS version at least 2.2.51"; return 0; }
9963
9964         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9965
9966         local remote_dir=$DIR/$tdir/remote_dir
9967         local MDTIDX=1
9968         local rc=0
9969
9970         mkdir -p $DIR/$tdir
9971         $LFS mkdir -i $MDTIDX $remote_dir ||
9972                 error "create remote directory failed"
9973
9974         cp /etc/hosts $remote_dir/$tfile
9975
9976         fid=$($LFS path2fid $remote_dir/$tfile)
9977         rc=$?
9978         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9979
9980         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9981                 error "dot lustre permission check $fid failed"
9982         rm -rf $DIR/$tdir
9983 }
9984 run_test 154b "Open-by-FID for remote directory"
9985
9986 test_154c() {
9987         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9988                 skip "Need MDS version at least 2.4.1" && return
9989
9990         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9991         local FID1=$($LFS path2fid $DIR/$tfile.1)
9992         local FID2=$($LFS path2fid $DIR/$tfile.2)
9993         local FID3=$($LFS path2fid $DIR/$tfile.3)
9994
9995         local N=1
9996         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9997                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9998                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9999                 local want=FID$N
10000                 [ "$FID" = "${!want}" ] ||
10001                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
10002                 N=$((N + 1))
10003         done
10004
10005         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
10006         do
10007                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
10008                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
10009                 N=$((N + 1))
10010         done
10011 }
10012 run_test 154c "lfs path2fid and fid2path multiple arguments"
10013
10014 test_154d() {
10015         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
10016                 skip "Need MDS version at least 2.5.53" && return
10017
10018         if remote_mds; then
10019                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
10020         else
10021                 nid="0@lo"
10022         fi
10023         local proc_ofile="mdt.*.exports.'$nid'.open_files"
10024         local fd
10025         local cmd
10026
10027         rm -f $DIR/$tfile
10028         touch $DIR/$tfile
10029
10030         local fid=$($LFS path2fid $DIR/$tfile)
10031         # Open the file
10032         fd=$(free_fd)
10033         cmd="exec $fd<$DIR/$tfile"
10034         eval $cmd
10035         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
10036         echo "$fid_list" | grep "$fid"
10037         rc=$?
10038
10039         cmd="exec $fd>/dev/null"
10040         eval $cmd
10041         if [ $rc -ne 0 ]; then
10042                 error "FID $fid not found in open files list $fid_list"
10043         fi
10044 }
10045 run_test 154d "Verify open file fid"
10046
10047 test_154e()
10048 {
10049         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
10050                 skip "Need MDS version at least 2.6.50" && return
10051
10052         if ls -a $MOUNT | grep -q '^\.lustre$'; then
10053                 error ".lustre returned by readdir"
10054         fi
10055 }
10056 run_test 154e ".lustre is not returned by readdir"
10057
10058 test_154f() {
10059         # create parent directory on a single MDT to avoid cross-MDT hardlinks
10060         test_mkdir -p -c1 $DIR/$tdir/d
10061         # test dirs inherit from its stripe
10062         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
10063         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
10064         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
10065         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
10066         touch $DIR/f
10067
10068         # get fid of parents
10069         local FID0=$($LFS path2fid $DIR/$tdir/d)
10070         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
10071         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
10072         local FID3=$($LFS path2fid $DIR)
10073
10074         # check that path2fid --parents returns expected <parent_fid>/name
10075         # 1) test for a directory (single parent)
10076         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
10077         [ "$parent" == "$FID0/foo1" ] ||
10078                 error "expected parent: $FID0/foo1, got: $parent"
10079
10080         # 2) test for a file with nlink > 1 (multiple parents)
10081         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
10082         echo "$parent" | grep -F "$FID1/$tfile" ||
10083                 error "$FID1/$tfile not returned in parent list"
10084         echo "$parent" | grep -F "$FID2/link" ||
10085                 error "$FID2/link not returned in parent list"
10086
10087         # 3) get parent by fid
10088         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
10089         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10090         echo "$parent" | grep -F "$FID1/$tfile" ||
10091                 error "$FID1/$tfile not returned in parent list (by fid)"
10092         echo "$parent" | grep -F "$FID2/link" ||
10093                 error "$FID2/link not returned in parent list (by fid)"
10094
10095         # 4) test for entry in root directory
10096         parent=$($LFS path2fid --parents $DIR/f)
10097         echo "$parent" | grep -F "$FID3/f" ||
10098                 error "$FID3/f not returned in parent list"
10099
10100         # 5) test it on root directory
10101         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
10102                 error "$MOUNT should not have parents"
10103
10104         # enable xattr caching and check that linkea is correctly updated
10105         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
10106         save_lustre_params client "llite.*.xattr_cache" > $save
10107         lctl set_param llite.*.xattr_cache 1
10108
10109         # 6.1) linkea update on rename
10110         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
10111
10112         # get parents by fid
10113         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10114         # foo1 should no longer be returned in parent list
10115         echo "$parent" | grep -F "$FID1" &&
10116                 error "$FID1 should no longer be in parent list"
10117         # the new path should appear
10118         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
10119                 error "$FID2/$tfile.moved is not in parent list"
10120
10121         # 6.2) linkea update on unlink
10122         rm -f $DIR/$tdir/d/foo2/link
10123         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10124         # foo2/link should no longer be returned in parent list
10125         echo "$parent" | grep -F "$FID2/link" &&
10126                 error "$FID2/link should no longer be in parent list"
10127         true
10128
10129         rm -f $DIR/f
10130         restore_lustre_params < $save
10131 }
10132 run_test 154f "get parent fids by reading link ea"
10133
10134 test_154g()
10135 {
10136         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) ]] ||
10137                 { skip "Need MDS version at least 2.6.92"; return 0; }
10138
10139         mkdir -p $DIR/$tdir
10140         llapi_fid_test -d $DIR/$tdir
10141 }
10142 run_test 154g "various llapi FID tests"
10143
10144 test_155_small_load() {
10145     local temp=$TMP/$tfile
10146     local file=$DIR/$tfile
10147
10148     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
10149         error "dd of=$temp bs=6096 count=1 failed"
10150     cp $temp $file
10151     cancel_lru_locks osc
10152     cmp $temp $file || error "$temp $file differ"
10153
10154     $TRUNCATE $temp 6000
10155     $TRUNCATE $file 6000
10156     cmp $temp $file || error "$temp $file differ (truncate1)"
10157
10158     echo "12345" >>$temp
10159     echo "12345" >>$file
10160     cmp $temp $file || error "$temp $file differ (append1)"
10161
10162     echo "12345" >>$temp
10163     echo "12345" >>$file
10164     cmp $temp $file || error "$temp $file differ (append2)"
10165
10166     rm -f $temp $file
10167     true
10168 }
10169
10170 test_155_big_load() {
10171     remote_ost_nodsh && skip "remote OST with nodsh" && return
10172     local temp=$TMP/$tfile
10173     local file=$DIR/$tfile
10174
10175     free_min_max
10176     local cache_size=$(do_facet ost$((MAXI+1)) \
10177         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
10178     local large_file_size=$((cache_size * 2))
10179
10180     echo "OSS cache size: $cache_size KB"
10181     echo "Large file size: $large_file_size KB"
10182
10183     [ $MAXV -le $large_file_size ] && \
10184         skip_env "max available OST size needs > $large_file_size KB" && \
10185         return 0
10186
10187     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
10188
10189     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
10190         error "dd of=$temp bs=$large_file_size count=1k failed"
10191     cp $temp $file
10192     ls -lh $temp $file
10193     cancel_lru_locks osc
10194     cmp $temp $file || error "$temp $file differ"
10195
10196     rm -f $temp $file
10197     true
10198 }
10199
10200 test_155a() {
10201         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10202         set_cache read on
10203         set_cache writethrough on
10204         test_155_small_load
10205 }
10206 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
10207
10208 test_155b() {
10209         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10210         set_cache read on
10211         set_cache writethrough off
10212         test_155_small_load
10213 }
10214 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
10215
10216 test_155c() {
10217         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10218         set_cache read off
10219         set_cache writethrough on
10220         test_155_small_load
10221 }
10222 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
10223
10224 test_155d() {
10225         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10226         set_cache read off
10227         set_cache writethrough off
10228         test_155_small_load
10229 }
10230 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
10231
10232 test_155e() {
10233         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10234         set_cache read on
10235         set_cache writethrough on
10236         test_155_big_load
10237 }
10238 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
10239
10240 test_155f() {
10241         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10242         set_cache read on
10243         set_cache writethrough off
10244         test_155_big_load
10245 }
10246 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
10247
10248 test_155g() {
10249         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10250         set_cache read off
10251         set_cache writethrough on
10252         test_155_big_load
10253 }
10254 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
10255
10256 test_155h() {
10257         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10258         set_cache read off
10259         set_cache writethrough off
10260         test_155_big_load
10261 }
10262 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
10263
10264 test_156() {
10265         remote_ost_nodsh && skip "remote OST with nodsh" && return
10266         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10267         local CPAGES=3
10268         local BEFORE
10269         local AFTER
10270         local file="$DIR/$tfile"
10271
10272         [ "$(facet_fstype ost1)" = "zfs" -a \
10273            $(lustre_version_code ost1 -lt $(version_code 2.6.93)) ] &&
10274                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS" &&
10275                 return
10276
10277         roc_hit_init
10278
10279         log "Turn on read and write cache"
10280         set_cache read on
10281         set_cache writethrough on
10282
10283         log "Write data and read it back."
10284         log "Read should be satisfied from the cache."
10285         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10286         BEFORE=$(roc_hit)
10287         cancel_lru_locks osc
10288         cat $file >/dev/null
10289         AFTER=$(roc_hit)
10290         if ! let "AFTER - BEFORE == CPAGES"; then
10291                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10292         else
10293                 log "cache hits:: before: $BEFORE, after: $AFTER"
10294         fi
10295
10296         log "Read again; it should be satisfied from the cache."
10297         BEFORE=$AFTER
10298         cancel_lru_locks osc
10299         cat $file >/dev/null
10300         AFTER=$(roc_hit)
10301         if ! let "AFTER - BEFORE == CPAGES"; then
10302                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10303         else
10304                 log "cache hits:: before: $BEFORE, after: $AFTER"
10305         fi
10306
10307         log "Turn off the read cache and turn on the write cache"
10308         set_cache read off
10309         set_cache writethrough on
10310
10311         log "Read again; it should be satisfied from the cache."
10312         BEFORE=$(roc_hit)
10313         cancel_lru_locks osc
10314         cat $file >/dev/null
10315         AFTER=$(roc_hit)
10316         if ! let "AFTER - BEFORE == CPAGES"; then
10317                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10318         else
10319                 log "cache hits:: before: $BEFORE, after: $AFTER"
10320         fi
10321
10322         log "Read again; it should not be satisfied from the cache."
10323         BEFORE=$AFTER
10324         cancel_lru_locks osc
10325         cat $file >/dev/null
10326         AFTER=$(roc_hit)
10327         if ! let "AFTER - BEFORE == 0"; then
10328                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10329         else
10330                 log "cache hits:: before: $BEFORE, after: $AFTER"
10331         fi
10332
10333         log "Write data and read it back."
10334         log "Read should be satisfied from the cache."
10335         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10336         BEFORE=$(roc_hit)
10337         cancel_lru_locks osc
10338         cat $file >/dev/null
10339         AFTER=$(roc_hit)
10340         if ! let "AFTER - BEFORE == CPAGES"; then
10341                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10342         else
10343                 log "cache hits:: before: $BEFORE, after: $AFTER"
10344         fi
10345
10346         log "Read again; it should not be satisfied from the cache."
10347         BEFORE=$AFTER
10348         cancel_lru_locks osc
10349         cat $file >/dev/null
10350         AFTER=$(roc_hit)
10351         if ! let "AFTER - BEFORE == 0"; then
10352                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10353         else
10354                 log "cache hits:: before: $BEFORE, after: $AFTER"
10355         fi
10356
10357         log "Turn off read and write cache"
10358         set_cache read off
10359         set_cache writethrough off
10360
10361         log "Write data and read it back"
10362         log "It should not be satisfied from the cache."
10363         rm -f $file
10364         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10365         cancel_lru_locks osc
10366         BEFORE=$(roc_hit)
10367         cat $file >/dev/null
10368         AFTER=$(roc_hit)
10369         if ! let "AFTER - BEFORE == 0"; then
10370                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10371         else
10372                 log "cache hits:: before: $BEFORE, after: $AFTER"
10373         fi
10374
10375         log "Turn on the read cache and turn off the write cache"
10376         set_cache read on
10377         set_cache writethrough off
10378
10379         log "Write data and read it back"
10380         log "It should not be satisfied from the cache."
10381         rm -f $file
10382         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10383         BEFORE=$(roc_hit)
10384         cancel_lru_locks osc
10385         cat $file >/dev/null
10386         AFTER=$(roc_hit)
10387         if ! let "AFTER - BEFORE == 0"; then
10388                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10389         else
10390                 log "cache hits:: before: $BEFORE, after: $AFTER"
10391         fi
10392
10393         log "Read again; it should be satisfied from the cache."
10394         BEFORE=$(roc_hit)
10395         cancel_lru_locks osc
10396         cat $file >/dev/null
10397         AFTER=$(roc_hit)
10398         if ! let "AFTER - BEFORE == CPAGES"; then
10399                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10400         else
10401                 log "cache hits:: before: $BEFORE, after: $AFTER"
10402         fi
10403
10404         rm -f $file
10405 }
10406 run_test 156 "Verification of tunables"
10407
10408 #Changelogs
10409 err17935 () {
10410         if [[ $MDSCOUNT -gt 1 ]]; then
10411                 error_ignore bz17935 $*
10412         else
10413                 error $*
10414         fi
10415 }
10416
10417 changelog_chmask()
10418 {
10419         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10420
10421         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
10422
10423         if [ $MASK -eq 1 ]; then
10424                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
10425         else
10426                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
10427         fi
10428 }
10429
10430 changelog_extract_field() {
10431         local mdt=$1
10432         local cltype=$2
10433         local file=$3
10434         local identifier=$4
10435
10436         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
10437                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10438                 tail -1
10439 }
10440
10441 test_160a() {
10442         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10443         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10444         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10445                 { skip "Need MDS version at least 2.2.0"; return; }
10446
10447         local CL_USERS="mdd.$MDT0.changelog_users"
10448         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10449         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10450         echo "Registered as changelog user $USER"
10451         $GET_CL_USERS | grep -q $USER ||
10452                 error "User $USER not found in changelog_users"
10453
10454         # change something
10455         test_mkdir -p $DIR/$tdir/pics/2008/zachy
10456         touch $DIR/$tdir/pics/2008/zachy/timestamp
10457         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
10458         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
10459         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
10460         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
10461         rm $DIR/$tdir/pics/desktop.jpg
10462
10463         $LFS changelog $MDT0 | tail -5
10464
10465         echo "verifying changelog mask"
10466         changelog_chmask "MKDIR"
10467         changelog_chmask "CLOSE"
10468
10469         test_mkdir -p $DIR/$tdir/pics/zach/sofia
10470         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10471
10472         changelog_chmask "MKDIR"
10473         changelog_chmask "CLOSE"
10474
10475         test_mkdir -p $DIR/$tdir/pics/2008/sofia
10476         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10477
10478         $LFS changelog $MDT0
10479         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
10480         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
10481         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
10482         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
10483
10484         # verify contents
10485         echo "verifying target fid"
10486         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
10487         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
10488         [ "$fidc" == "$fidf" ] ||
10489                 err17935 "fid in changelog $fidc != file fid $fidf"
10490         echo "verifying parent fid"
10491         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
10492         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
10493         [ "$fidc" == "$fidf" ] ||
10494                 err17935 "pfid in changelog $fidc != dir fid $fidf"
10495
10496         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10497         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
10498         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10499         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
10500         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
10501                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
10502
10503         MIN_REC=$($GET_CL_USERS |
10504                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
10505         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
10506         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
10507         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
10508                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
10509
10510         # LU-3446 changelog index reset on MDT restart
10511         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10512         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10513         $LFS changelog_clear $MDT0 $USER 0
10514         stop $SINGLEMDS || error "Fail to stop MDT."
10515         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10516         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10517         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
10518         [ $CUR_REC1 == $CUR_REC2 ] ||
10519                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
10520
10521         echo "verifying user deregister"
10522         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10523         $GET_CL_USERS | grep -q $USER &&
10524                 error "User $USER still in changelog_users"
10525
10526         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
10527         if [ $USERS -eq 0 ]; then
10528                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10529                 touch $DIR/$tdir/chloe
10530                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10531                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
10532                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
10533         else
10534                 echo "$USERS other changelog users; can't verify off"
10535         fi
10536 }
10537 run_test 160a "changelog sanity"
10538
10539 test_160b() { # LU-3587
10540         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10541         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10542         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10543                 { skip "Need MDS version at least 2.2.0"; return; }
10544
10545         local CL_USERS="mdd.$MDT0.changelog_users"
10546         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10547         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10548         echo "Registered as changelog user $USER"
10549         $GET_CL_USERS | grep -q $USER ||
10550                 error "User $USER not found in changelog_users"
10551
10552         local LONGNAME1=$(str_repeat a 255)
10553         local LONGNAME2=$(str_repeat b 255)
10554
10555         cd $DIR
10556         echo "creating very long named file"
10557         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
10558         echo "moving very long named file"
10559         mv $LONGNAME1 $LONGNAME2
10560
10561         $LFS changelog $MDT0 | grep RENME
10562
10563         echo "deregistering $USER"
10564         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10565
10566         rm -f $LONGNAME2
10567 }
10568 run_test 160b "Verify that very long rename doesn't crash in changelog"
10569
10570 test_160c() {
10571         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10572
10573         local rc=0
10574         local server_version=$(lustre_version_code $SINGLEMDS)
10575
10576         [[ $server_version -gt $(version_code 2.5.57) ]] ||
10577                 [[ $server_version -gt $(version_code 2.5.1) &&
10578                    $server_version -lt $(version_code 2.5.50) ]] ||
10579                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
10580         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10581
10582         # Registration step
10583         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10584                 changelog_register -n)
10585
10586         rm -rf $DIR/$tdir
10587         mkdir -p $DIR/$tdir
10588         $MCREATE $DIR/$tdir/foo_160c
10589         changelog_chmask "TRUNC"
10590         $TRUNCATE $DIR/$tdir/foo_160c 200
10591         changelog_chmask "TRUNC"
10592         $TRUNCATE $DIR/$tdir/foo_160c 199
10593         $LFS changelog $MDT0
10594         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
10595         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
10596         $LFS changelog_clear $MDT0 $USER 0
10597
10598         # Deregistration step
10599         echo "deregistering $USER"
10600         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10601 }
10602 run_test 160c "verify that changelog log catch the truncate event"
10603
10604 test_160d() {
10605         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10606         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10607
10608         local server_version=$(lustre_version_code mds1)
10609         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10610
10611         [[ $server_version -ge $(version_code 2.7.60) ]] ||
10612                 { skip "Need MDS version at least 2.7.60+"; return; }
10613         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10614
10615         # Registration step
10616         local USER=$(do_facet mds1 $LCTL --device $MDT0 \
10617                 changelog_register -n)
10618
10619         mkdir -p $DIR/$tdir/migrate_dir
10620         $LFS changelog_clear $MDT0 $USER 0
10621
10622         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
10623         $LFS changelog $MDT0
10624         MIGRATES=$($LFS changelog $MDT0 | tail -5 | grep -c "MIGRT")
10625         $LFS changelog_clear $MDT0 $USER 0
10626         [ $MIGRATES -eq 1 ] ||
10627                 error "MIGRATE changelog mask count $MIGRATES != 1"
10628
10629         # Deregistration step
10630         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $USER
10631 }
10632 run_test 160d "verify that changelog log catch the migrate event"
10633
10634 test_161a() {
10635         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10636         test_mkdir -p -c1 $DIR/$tdir
10637         cp /etc/hosts $DIR/$tdir/$tfile
10638         test_mkdir -c1 $DIR/$tdir/foo1
10639         test_mkdir -c1 $DIR/$tdir/foo2
10640         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
10641         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
10642         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
10643         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
10644         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
10645         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10646                 $LFS fid2path $DIR $FID
10647                 err17935 "bad link ea"
10648         fi
10649     # middle
10650     rm $DIR/$tdir/foo2/zachary
10651     # last
10652     rm $DIR/$tdir/foo2/thor
10653     # first
10654     rm $DIR/$tdir/$tfile
10655     # rename
10656     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
10657     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
10658         then
10659         $LFS fid2path $DIR $FID
10660         err17935 "bad link rename"
10661     fi
10662     rm $DIR/$tdir/foo2/maggie
10663
10664         # overflow the EA
10665         local longname=filename_avg_len_is_thirty_two_
10666         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
10667                 error "failed to hardlink many files"
10668         links=$($LFS fid2path $DIR $FID | wc -l)
10669         echo -n "${links}/1000 links in link EA"
10670         [[ $links -gt 60 ]] ||
10671                 err17935 "expected at least 60 links in link EA"
10672         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
10673                 error "failed to unlink many hardlinks"
10674 }
10675 run_test 161a "link ea sanity"
10676
10677 test_161b() {
10678         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10679         [ $MDSCOUNT -lt 2 ] &&
10680                 skip "skipping remote directory test" && return
10681         local MDTIDX=1
10682         local remote_dir=$DIR/$tdir/remote_dir
10683
10684         mkdir -p $DIR/$tdir
10685         $LFS mkdir -i $MDTIDX $remote_dir ||
10686                 error "create remote directory failed"
10687
10688         cp /etc/hosts $remote_dir/$tfile
10689         mkdir -p $remote_dir/foo1
10690         mkdir -p $remote_dir/foo2
10691         ln $remote_dir/$tfile $remote_dir/foo1/sofia
10692         ln $remote_dir/$tfile $remote_dir/foo2/zachary
10693         ln $remote_dir/$tfile $remote_dir/foo1/luna
10694         ln $remote_dir/$tfile $remote_dir/foo2/thor
10695
10696         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
10697                      tr -d ']')
10698         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10699                 $LFS fid2path $DIR $FID
10700                 err17935 "bad link ea"
10701         fi
10702         # middle
10703         rm $remote_dir/foo2/zachary
10704         # last
10705         rm $remote_dir/foo2/thor
10706         # first
10707         rm $remote_dir/$tfile
10708         # rename
10709         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
10710         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
10711         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
10712                 $LFS fid2path $DIR $FID
10713                 err17935 "bad link rename"
10714         fi
10715         rm $remote_dir/foo2/maggie
10716
10717         # overflow the EA
10718         local longname=filename_avg_len_is_thirty_two_
10719         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10720                 error "failed to hardlink many files"
10721         links=$($LFS fid2path $DIR $FID | wc -l)
10722         echo -n "${links}/1000 links in link EA"
10723         [[ ${links} -gt 60 ]] ||
10724                 err17935 "expected at least 60 links in link EA"
10725         unlinkmany $remote_dir/foo2/$longname 1000 ||
10726         error "failed to unlink many hardlinks"
10727 }
10728 run_test 161b "link ea sanity under remote directory"
10729
10730 test_161c() {
10731         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10732         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10733         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10734                 skip "Need MDS version at least 2.1.5" && return
10735
10736         # define CLF_RENAME_LAST 0x0001
10737         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10738         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10739                 changelog_register -n)
10740         rm -rf $DIR/$tdir
10741         mkdir -p $DIR/$tdir
10742         touch $DIR/$tdir/foo_161c
10743         touch $DIR/$tdir/bar_161c
10744         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10745         $LFS changelog $MDT0 | grep RENME
10746         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10747                 cut -f5 -d' ')
10748         $LFS changelog_clear $MDT0 $USER 0
10749         if [ x$flags != "x0x1" ]; then
10750                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10751                         $USER
10752                 error "flag $flags is not 0x1"
10753         fi
10754         echo "rename overwrite a target having nlink = 1," \
10755                 "changelog record has flags of $flags"
10756
10757         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10758         touch $DIR/$tdir/foo_161c
10759         touch $DIR/$tdir/bar_161c
10760         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10761         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10762         $LFS changelog $MDT0 | grep RENME
10763         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10764         $LFS changelog_clear $MDT0 $USER 0
10765         if [ x$flags != "x0x0" ]; then
10766                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10767                         $USER
10768                 error "flag $flags is not 0x0"
10769         fi
10770         echo "rename overwrite a target having nlink > 1," \
10771                 "changelog record has flags of $flags"
10772
10773         # rename doesn't overwrite a target (changelog flag 0x0)
10774         touch $DIR/$tdir/foo_161c
10775         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10776         $LFS changelog $MDT0 | grep RENME
10777         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10778         $LFS changelog_clear $MDT0 $USER 0
10779         if [ x$flags != "x0x0" ]; then
10780                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10781                         $USER
10782                 error "flag $flags is not 0x0"
10783         fi
10784         echo "rename doesn't overwrite a target," \
10785                 "changelog record has flags of $flags"
10786
10787         # define CLF_UNLINK_LAST 0x0001
10788         # unlink a file having nlink = 1 (changelog flag 0x1)
10789         rm -f $DIR/$tdir/foo2_161c
10790         $LFS changelog $MDT0 | grep UNLNK
10791         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10792         $LFS changelog_clear $MDT0 $USER 0
10793         if [ x$flags != "x0x1" ]; then
10794                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10795                         $USER
10796                 error "flag $flags is not 0x1"
10797         fi
10798         echo "unlink a file having nlink = 1," \
10799                 "changelog record has flags of $flags"
10800
10801         # unlink a file having nlink > 1 (changelog flag 0x0)
10802         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10803         rm -f $DIR/$tdir/foobar_161c
10804         $LFS changelog $MDT0 | grep UNLNK
10805         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10806         $LFS changelog_clear $MDT0 $USER 0
10807         if [ x$flags != "x0x0" ]; then
10808                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10809                         $USER
10810                 error "flag $flags is not 0x0"
10811         fi
10812         echo "unlink a file having nlink > 1," \
10813                 "changelog record has flags of $flags"
10814         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10815 }
10816 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10817
10818 check_path() {
10819     local expected=$1
10820     shift
10821     local fid=$2
10822
10823     local path=$(${LFS} fid2path $*)
10824     # Remove the '//' indicating a remote directory
10825     path=$(echo $path | sed 's#//#/#g')
10826     RC=$?
10827
10828     if [ $RC -ne 0 ]; then
10829         err17935 "path looked up of $expected failed. Error $RC"
10830         return $RC
10831     elif [ "${path}" != "${expected}" ]; then
10832         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10833         return 2
10834     fi
10835     echo "fid $fid resolves to path $path (expected $expected)"
10836 }
10837
10838 test_162a() { # was test_162
10839         # Make changes to filesystem
10840         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10841         test_mkdir -p -c1 $DIR/$tdir/d2
10842         touch $DIR/$tdir/d2/$tfile
10843         touch $DIR/$tdir/d2/x1
10844         touch $DIR/$tdir/d2/x2
10845         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
10846         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
10847         # regular file
10848         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10849         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
10850                 error "check path $tdir/d2/$tfile failed"
10851
10852         # softlink
10853         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10854         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10855         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
10856                 error "check path $tdir/d2/p/q/r/slink failed"
10857
10858         # softlink to wrong file
10859         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10860         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10861         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
10862                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
10863
10864         # hardlink
10865         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10866         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10867         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10868         # fid2path dir/fsname should both work
10869         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
10870                 error "check path $tdir/d2/a/b/c/new_file failed"
10871         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
10872                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
10873
10874         # hardlink count: check that there are 2 links
10875         # Doesnt work with CMD yet: 17935
10876         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10877                 err17935 "expected 2 links"
10878
10879         # hardlink indexing: remove the first link
10880         rm $DIR/$tdir/d2/p/q/r/hlink
10881         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
10882                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
10883
10884         return 0
10885 }
10886 run_test 162a "path lookup sanity"
10887
10888 test_162b() {
10889         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10890         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10891
10892         mkdir $DIR/$tdir
10893         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
10894                                 error "create striped dir failed"
10895
10896         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
10897                                         tail -n 1 | awk '{print $2}')
10898         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
10899
10900         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
10901         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
10902
10903         # regular file
10904         for ((i=0;i<5;i++)); do
10905                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
10906                         error "get fid for f$i failed"
10907                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
10908                         error "check path $tdir/striped_dir/f$i failed"
10909
10910                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
10911                         error "get fid for d$i failed"
10912                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
10913                         error "check path $tdir/striped_dir/d$i failed"
10914         done
10915
10916         return 0
10917 }
10918 run_test 162b "striped directory path lookup sanity"
10919
10920 # LU-4239: Verify fid2path works with paths 100 or more directories deep
10921 test_162c() {
10922         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.51) ]] &&
10923                 skip "Need MDS version at least 2.7.51" && return
10924         test_mkdir $DIR/$tdir.local
10925         test_mkdir $DIR/$tdir.remote
10926         local lpath=$tdir.local
10927         local rpath=$tdir.remote
10928
10929         for ((i = 0; i <= 101; i++)); do
10930                 lpath="$lpath/$i"
10931                 mkdir $DIR/$lpath
10932                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
10933                         error "get fid for local directory $DIR/$lpath failed"
10934                 check_path "$DIR/$lpath" $MOUNT $FID --link 0 ||
10935                         error "check path for local directory $DIR/$lpath failed"
10936
10937                 rpath="$rpath/$i"
10938                 test_mkdir $DIR/$rpath
10939                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
10940                         error "get fid for remote directory $DIR/$rpath failed"
10941                 check_path "$DIR/$rpath" $MOUNT $FID --link 0 ||
10942                         error "check path for remote directory $DIR/$rpath failed"
10943         done
10944
10945         return 0
10946 }
10947 run_test 162c "fid2path works with paths 100 or more directories deep"
10948
10949 test_169() {
10950         # do directio so as not to populate the page cache
10951         log "creating a 10 Mb file"
10952         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10953         log "starting reads"
10954         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10955         log "truncating the file"
10956         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10957         log "killing dd"
10958         kill %+ || true # reads might have finished
10959         echo "wait until dd is finished"
10960         wait
10961         log "removing the temporary file"
10962         rm -rf $DIR/$tfile || error "tmp file removal failed"
10963 }
10964 run_test 169 "parallel read and truncate should not deadlock"
10965
10966 test_170() {
10967         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10968         $LCTL clear     # bug 18514
10969         $LCTL debug_daemon start $TMP/${tfile}_log_good
10970         touch $DIR/$tfile
10971         $LCTL debug_daemon stop
10972         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10973                error "sed failed to read log_good"
10974
10975         $LCTL debug_daemon start $TMP/${tfile}_log_good
10976         rm -rf $DIR/$tfile
10977         $LCTL debug_daemon stop
10978
10979         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10980                error "lctl df log_bad failed"
10981
10982         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10983         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10984
10985         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10986         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10987
10988         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10989                 error "bad_line good_line1 good_line2 are empty"
10990
10991         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10992         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10993         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10994
10995         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10996         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10997         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10998
10999         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
11000                 error "bad_line_new good_line_new are empty"
11001
11002         local expected_good=$((good_line1 + good_line2*2))
11003
11004         rm -f $TMP/${tfile}*
11005         # LU-231, short malformed line may not be counted into bad lines
11006         if [ $bad_line -ne $bad_line_new ] &&
11007                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
11008                 error "expected $bad_line bad lines, but got $bad_line_new"
11009                 return 1
11010         fi
11011
11012         if [ $expected_good -ne $good_line_new ]; then
11013                 error "expected $expected_good good lines, but got $good_line_new"
11014                 return 2
11015         fi
11016         true
11017 }
11018 run_test 170 "test lctl df to handle corrupted log ====================="
11019
11020 test_171() { # bug20592
11021         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11022 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
11023         $LCTL set_param fail_loc=0x50e
11024         $LCTL set_param fail_val=3000
11025         multiop_bg_pause $DIR/$tfile O_s || true
11026         local MULTIPID=$!
11027         kill -USR1 $MULTIPID
11028         # cause log dump
11029         sleep 3
11030         wait $MULTIPID
11031         if dmesg | grep "recursive fault"; then
11032                 error "caught a recursive fault"
11033         fi
11034         $LCTL set_param fail_loc=0
11035         true
11036 }
11037 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
11038
11039 # it would be good to share it with obdfilter-survey/iokit-libecho code
11040 setup_obdecho_osc () {
11041         local rc=0
11042         local ost_nid=$1
11043         local obdfilter_name=$2
11044         echo "Creating new osc for $obdfilter_name on $ost_nid"
11045         # make sure we can find loopback nid
11046         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
11047
11048         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
11049                            ${obdfilter_name}_osc_UUID || rc=2; }
11050         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
11051                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
11052         return $rc
11053 }
11054
11055 cleanup_obdecho_osc () {
11056         local obdfilter_name=$1
11057         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
11058         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
11059         return 0
11060 }
11061
11062 obdecho_test() {
11063         local OBD=$1
11064         local node=$2
11065         local pages=${3:-64}
11066         local rc=0
11067         local id
11068
11069         local count=10
11070         local obd_size=$(get_obd_size $node $OBD)
11071         local page_size=$(get_page_size $node)
11072         if [[ -n "$obd_size" ]]; then
11073                 local new_count=$((obd_size / (pages * page_size / 1024)))
11074                 [[ $new_count -ge $count ]] || count=$new_count
11075         fi
11076
11077         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
11078         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
11079                            rc=2; }
11080         if [ $rc -eq 0 ]; then
11081             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
11082             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
11083         fi
11084         echo "New object id is $id"
11085         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
11086                            rc=4; }
11087         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
11088                            "test_brw $count w v $pages $id" || rc=4; }
11089         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
11090                            rc=4; }
11091         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
11092                                         "cleanup" || rc=5; }
11093         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
11094                                         "detach" || rc=6; }
11095         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
11096         return $rc
11097 }
11098
11099 test_180a() {
11100         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11101         remote_ost_nodsh && skip "remote OST with nodsh" && return
11102         local rc=0
11103         local rmmod_local=0
11104
11105         if ! module_loaded obdecho; then
11106             load_module obdecho/obdecho
11107             rmmod_local=1
11108         fi
11109
11110         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
11111         local host=$(lctl get_param -n osc.$osc.import |
11112                              awk '/current_connection:/ {print $2}' )
11113         local target=$(lctl get_param -n osc.$osc.import |
11114                              awk '/target:/ {print $2}' )
11115         target=${target%_UUID}
11116
11117         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
11118         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
11119         [[ -n $target ]] && cleanup_obdecho_osc $target
11120         [ $rmmod_local -eq 1 ] && rmmod obdecho
11121         return $rc
11122 }
11123 run_test 180a "test obdecho on osc"
11124
11125 test_180b() {
11126         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11127         remote_ost_nodsh && skip "remote OST with nodsh" && return
11128         local rc=0
11129         local rmmod_remote=0
11130
11131         do_facet ost1 "lsmod | grep -q obdecho || "                      \
11132                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
11133                       "modprobe obdecho; }" && rmmod_remote=1
11134         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
11135         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
11136         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
11137         return $rc
11138 }
11139 run_test 180b "test obdecho directly on obdfilter"
11140
11141 test_180c() { # LU-2598
11142         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11143         remote_ost_nodsh && skip "remote OST with nodsh" && return
11144         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
11145                 skip "Need MDS version at least 2.4.0" && return
11146
11147         local rc=0
11148         local rmmod_remote=false
11149         local pages=16384 # 64MB bulk I/O RPC size
11150         local target
11151
11152         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
11153                 rmmod_remote=true || error "failed to load module obdecho"
11154
11155         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
11156                 head -n1)
11157         if [ -n "$target" ]; then
11158                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
11159         else
11160                 echo "there is no obdfilter target on ost1"
11161                 rc=2
11162         fi
11163         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
11164         return $rc
11165 }
11166 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
11167
11168 test_181() { # bug 22177
11169         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11170         # create enough files to index the directory
11171         createmany -o $DIR/$tdir/foobar 4000
11172         # print attributes for debug purpose
11173         lsattr -d .
11174         # open dir
11175         multiop_bg_pause $DIR/$tdir D_Sc || return 1
11176         MULTIPID=$!
11177         # remove the files & current working dir
11178         unlinkmany $DIR/$tdir/foobar 4000
11179         rmdir $DIR/$tdir
11180         kill -USR1 $MULTIPID
11181         wait $MULTIPID
11182         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
11183         return 0
11184 }
11185 run_test 181 "Test open-unlinked dir ========================"
11186
11187 test_182() {
11188         local fcount=1000
11189         local tcount=10
11190
11191         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11192
11193         $LCTL set_param mdc.*.rpc_stats=clear
11194
11195         for (( i = 0; i < $tcount; i++ )) ; do
11196                 mkdir $DIR/$tdir/$i
11197         done
11198
11199         for (( i = 0; i < $tcount; i++ )) ; do
11200                 createmany -o $DIR/$tdir/$i/f- $fcount &
11201         done
11202         wait
11203
11204         for (( i = 0; i < $tcount; i++ )) ; do
11205                 unlinkmany $DIR/$tdir/$i/f- $fcount &
11206         done
11207         wait
11208
11209         $LCTL get_param mdc.*.rpc_stats
11210
11211         rm -rf $DIR/$tdir
11212 }
11213 run_test 182 "Test parallel modify metadata operations ================"
11214
11215 test_183() { # LU-2275
11216         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11217         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
11218                 skip "Need MDS version at least 2.3.56" && return
11219
11220         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11221         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11222         echo aaa > $DIR/$tdir/$tfile
11223
11224 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
11225         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
11226
11227         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
11228         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
11229
11230         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
11231
11232         # Flush negative dentry cache
11233         touch $DIR/$tdir/$tfile
11234
11235         # We are not checking for any leaked references here, they'll
11236         # become evident next time we do cleanup with module unload.
11237         rm -rf $DIR/$tdir
11238 }
11239 run_test 183 "No crash or request leak in case of strange dispositions ========"
11240
11241 # test suite 184 is for LU-2016, LU-2017
11242 test_184a() {
11243         check_swap_layouts_support && return 0
11244
11245         dir0=$DIR/$tdir/$testnum
11246         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
11247         ref1=/etc/passwd
11248         ref2=/etc/group
11249         file1=$dir0/f1
11250         file2=$dir0/f2
11251         $SETSTRIPE -c1 $file1
11252         cp $ref1 $file1
11253         $SETSTRIPE -c2 $file2
11254         cp $ref2 $file2
11255         gen1=$($GETSTRIPE -g $file1)
11256         gen2=$($GETSTRIPE -g $file2)
11257
11258         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
11259         gen=$($GETSTRIPE -g $file1)
11260         [[ $gen1 != $gen ]] ||
11261                 "Layout generation on $file1 does not change"
11262         gen=$($GETSTRIPE -g $file2)
11263         [[ $gen2 != $gen ]] ||
11264                 "Layout generation on $file2 does not change"
11265
11266         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
11267         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
11268 }
11269 run_test 184a "Basic layout swap"
11270
11271 test_184b() {
11272         check_swap_layouts_support && return 0
11273
11274         dir0=$DIR/$tdir/$testnum
11275         mkdir -p $dir0 || error "creating dir $dir0"
11276         file1=$dir0/f1
11277         file2=$dir0/f2
11278         file3=$dir0/f3
11279         dir1=$dir0/d1
11280         dir2=$dir0/d2
11281         mkdir $dir1 $dir2
11282         $SETSTRIPE -c1 $file1
11283         $SETSTRIPE -c2 $file2
11284         $SETSTRIPE -c1 $file3
11285         chown $RUNAS_ID $file3
11286         gen1=$($GETSTRIPE -g $file1)
11287         gen2=$($GETSTRIPE -g $file2)
11288
11289         $LFS swap_layouts $dir1 $dir2 &&
11290                 error "swap of directories layouts should fail"
11291         $LFS swap_layouts $dir1 $file1 &&
11292                 error "swap of directory and file layouts should fail"
11293         $RUNAS $LFS swap_layouts $file1 $file2 &&
11294                 error "swap of file we cannot write should fail"
11295         $LFS swap_layouts $file1 $file3 &&
11296                 error "swap of file with different owner should fail"
11297         /bin/true # to clear error code
11298 }
11299 run_test 184b "Forbidden layout swap (will generate errors)"
11300
11301 test_184c() {
11302         check_swap_layouts_support && return 0
11303
11304         local dir0=$DIR/$tdir/$testnum
11305         mkdir -p $dir0 || error "creating dir $dir0"
11306
11307         local ref1=$dir0/ref1
11308         local ref2=$dir0/ref2
11309         local file1=$dir0/file1
11310         local file2=$dir0/file2
11311         # create a file large enough for the concurrent test
11312         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
11313         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
11314         echo "ref file size: ref1($(stat -c %s $ref1))," \
11315              "ref2($(stat -c %s $ref2))"
11316
11317         cp $ref2 $file2
11318         dd if=$ref1 of=$file1 bs=16k &
11319         local DD_PID=$!
11320
11321         # Make sure dd starts to copy file
11322         while [ ! -f $file1 ]; do sleep 0.1; done
11323
11324         $LFS swap_layouts $file1 $file2
11325         local rc=$?
11326         wait $DD_PID
11327         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
11328         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
11329
11330         # how many bytes copied before swapping layout
11331         local copied=$(stat -c %s $file2)
11332         local remaining=$(stat -c %s $ref1)
11333         remaining=$((remaining - copied))
11334         echo "Copied $copied bytes before swapping layout..."
11335
11336         cmp -n $copied $file1 $ref2 | grep differ &&
11337                 error "Content mismatch [0, $copied) of ref2 and file1"
11338         cmp -n $copied $file2 $ref1 ||
11339                 error "Content mismatch [0, $copied) of ref1 and file2"
11340         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
11341                 error "Content mismatch [$copied, EOF) of ref1 and file1"
11342
11343         # clean up
11344         rm -f $ref1 $ref2 $file1 $file2
11345 }
11346 run_test 184c "Concurrent write and layout swap"
11347
11348 test_184d() {
11349         check_swap_layouts_support && return 0
11350         [ -z "$(which getfattr 2>/dev/null)" ] &&
11351                 skip "no getfattr command" && return 0
11352
11353         local file1=$DIR/$tdir/$tfile-1
11354         local file2=$DIR/$tdir/$tfile-2
11355         local file3=$DIR/$tdir/$tfile-3
11356         local lovea1
11357         local lovea2
11358
11359         mkdir -p $DIR/$tdir
11360         touch $file1 || error "create $file1 failed"
11361         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11362                 error "create $file2 failed"
11363         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11364                 error "create $file3 failed"
11365         lovea1=$($LFS getstripe $file1 | sed 1d)
11366
11367         $LFS swap_layouts $file2 $file3 ||
11368                 error "swap $file2 $file3 layouts failed"
11369         $LFS swap_layouts $file1 $file2 ||
11370                 error "swap $file1 $file2 layouts failed"
11371
11372         lovea2=$($LFS getstripe $file2 | sed 1d)
11373         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
11374
11375         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11376         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
11377 }
11378 run_test 184d "allow stripeless layouts swap"
11379
11380 test_184e() {
11381         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
11382                 { skip "Need MDS version at least 2.6.94"; return 0; }
11383         check_swap_layouts_support && return 0
11384         [ -z "$(which getfattr 2>/dev/null)" ] &&
11385                 skip "no getfattr command" && return 0
11386
11387         local file1=$DIR/$tdir/$tfile-1
11388         local file2=$DIR/$tdir/$tfile-2
11389         local file3=$DIR/$tdir/$tfile-3
11390         local lovea
11391
11392         mkdir -p $DIR/$tdir
11393         touch $file1 || error "create $file1 failed"
11394         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11395                 error "create $file2 failed"
11396         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11397                 error "create $file3 failed"
11398
11399         $LFS swap_layouts $file1 $file2 ||
11400                 error "swap $file1 $file2 layouts failed"
11401
11402         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11403         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
11404
11405         echo 123 > $file1 || error "Should be able to write into $file1"
11406
11407         $LFS swap_layouts $file1 $file3 ||
11408                 error "swap $file1 $file3 layouts failed"
11409
11410         echo 123 > $file1 || error "Should be able to write into $file1"
11411
11412         rm -rf $file1 $file2 $file3
11413 }
11414 run_test 184e "Recreate layout after stripeless layout swaps"
11415
11416 test_185() { # LU-2441
11417         # LU-3553 - no volatile file support in old servers
11418         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
11419                 { skip "Need MDS version at least 2.3.60"; return 0; }
11420
11421         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11422         touch $DIR/$tdir/spoo
11423         local mtime1=$(stat -c "%Y" $DIR/$tdir)
11424         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
11425                 error "cannot create/write a volatile file"
11426         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
11427                 error "FID is still valid after close"
11428
11429         multiop_bg_pause $DIR/$tdir vVw4096_c
11430         local multi_pid=$!
11431
11432         local OLD_IFS=$IFS
11433         IFS=":"
11434         local fidv=($fid)
11435         IFS=$OLD_IFS
11436         # assume that the next FID for this client is sequential, since stdout
11437         # is unfortunately eaten by multiop_bg_pause
11438         local n=$((${fidv[1]} + 1))
11439         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
11440         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
11441                 error "FID is missing before close"
11442         kill -USR1 $multi_pid
11443         # 1 second delay, so if mtime change we will see it
11444         sleep 1
11445         local mtime2=$(stat -c "%Y" $DIR/$tdir)
11446         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
11447 }
11448 run_test 185 "Volatile file support"
11449
11450 test_187a() {
11451         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11452         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
11453                 skip "Need MDS version at least 2.3.0" && return
11454
11455         local dir0=$DIR/$tdir/$testnum
11456         mkdir -p $dir0 || error "creating dir $dir0"
11457
11458         local file=$dir0/file1
11459         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
11460         local dv1=$($LFS data_version $file)
11461         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
11462         local dv2=$($LFS data_version $file)
11463         [[ $dv1 != $dv2 ]] ||
11464                 error "data version did not change on write $dv1 == $dv2"
11465
11466         # clean up
11467         rm -f $file1
11468 }
11469 run_test 187a "Test data version change"
11470
11471 test_187b() {
11472         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11473         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
11474                 skip "Need MDS version at least 2.3.0" && return
11475
11476         local dir0=$DIR/$tdir/$testnum
11477         mkdir -p $dir0 || error "creating dir $dir0"
11478
11479         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
11480         [[ ${DV[0]} != ${DV[1]} ]] ||
11481                 error "data version did not change on write"\
11482                       " ${DV[0]} == ${DV[1]}"
11483
11484         # clean up
11485         rm -f $file1
11486 }
11487 run_test 187b "Test data version change on volatile file"
11488
11489 test_200() {
11490         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11491         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11492
11493         local POOL=${POOL:-cea1}
11494         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
11495         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
11496         # Pool OST targets
11497         local first_ost=0
11498         local last_ost=$(($OSTCOUNT - 1))
11499         local ost_step=2
11500         local ost_list=$(seq $first_ost $ost_step $last_ost)
11501         local ost_range="$first_ost $last_ost $ost_step"
11502         local test_path=$POOL_ROOT/$POOL_DIR_NAME
11503         local file_dir=$POOL_ROOT/file_tst
11504         local subdir=$test_path/subdir
11505
11506         local rc=0
11507         while : ; do
11508                 # former test_200a test_200b
11509                 pool_add $POOL                          || { rc=$? ; break; }
11510                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
11511                 # former test_200c test_200d
11512                 mkdir -p $test_path
11513                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
11514                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
11515                 mkdir -p $subdir
11516                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
11517                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
11518                                                         || { rc=$? ; break; }
11519                 # former test_200e test_200f
11520                 local files=$((OSTCOUNT*3))
11521                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
11522                                                         || { rc=$? ; break; }
11523                 pool_create_files $POOL $file_dir $files "$ost_list" \
11524                                                         || { rc=$? ; break; }
11525                 # former test_200g test_200h
11526                 pool_lfs_df $POOL                       || { rc=$? ; break; }
11527                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
11528
11529                 # former test_201a test_201b test_201c
11530                 pool_remove_first_target $POOL          || { rc=$? ; break; }
11531
11532                 local f=$test_path/$tfile
11533                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
11534                 pool_remove $POOL $f                    || { rc=$? ; break; }
11535                 break
11536         done
11537
11538         cleanup_pools
11539         return $rc
11540 }
11541 run_test 200 "OST pools"
11542
11543 # usage: default_attr <count | size | offset>
11544 default_attr() {
11545         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
11546 }
11547
11548 # usage: check_default_stripe_attr
11549 check_default_stripe_attr() {
11550         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
11551         case $1 in
11552         --stripe-count|--count)
11553                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
11554         --stripe-size|--size)
11555                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
11556         --stripe-index|--index)
11557                 EXPECTED=-1;;
11558         *)
11559                 error "unknown getstripe attr '$1'"
11560         esac
11561
11562         [ $ACTUAL != $EXPECTED ] &&
11563                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
11564 }
11565
11566 test_204a() {
11567         test_mkdir -p $DIR/$tdir
11568         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
11569
11570         check_default_stripe_attr --stripe-count
11571         check_default_stripe_attr --stripe-size
11572         check_default_stripe_attr --stripe-index
11573
11574         return 0
11575 }
11576 run_test 204a "Print default stripe attributes ================="
11577
11578 test_204b() {
11579         test_mkdir -p $DIR/$tdir
11580         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11581
11582         check_default_stripe_attr --stripe-size
11583         check_default_stripe_attr --stripe-index
11584
11585         return 0
11586 }
11587 run_test 204b "Print default stripe size and offset  ==========="
11588
11589 test_204c() {
11590         test_mkdir -p $DIR/$tdir
11591         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11592
11593         check_default_stripe_attr --stripe-count
11594         check_default_stripe_attr --stripe-index
11595
11596         return 0
11597 }
11598 run_test 204c "Print default stripe count and offset ==========="
11599
11600 test_204d() {
11601         test_mkdir -p $DIR/$tdir
11602         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11603
11604         check_default_stripe_attr --stripe-count
11605         check_default_stripe_attr --stripe-size
11606
11607         return 0
11608 }
11609 run_test 204d "Print default stripe count and size ============="
11610
11611 test_204e() {
11612         test_mkdir -p $DIR/$tdir
11613         $SETSTRIPE -d $DIR/$tdir
11614
11615         check_default_stripe_attr --stripe-count --raw
11616         check_default_stripe_attr --stripe-size --raw
11617         check_default_stripe_attr --stripe-index --raw
11618
11619         return 0
11620 }
11621 run_test 204e "Print raw stripe attributes ================="
11622
11623 test_204f() {
11624         test_mkdir -p $DIR/$tdir
11625         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11626
11627         check_default_stripe_attr --stripe-size --raw
11628         check_default_stripe_attr --stripe-index --raw
11629
11630         return 0
11631 }
11632 run_test 204f "Print raw stripe size and offset  ==========="
11633
11634 test_204g() {
11635         test_mkdir -p $DIR/$tdir
11636         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11637
11638         check_default_stripe_attr --stripe-count --raw
11639         check_default_stripe_attr --stripe-index --raw
11640
11641         return 0
11642 }
11643 run_test 204g "Print raw stripe count and offset ==========="
11644
11645 test_204h() {
11646         test_mkdir -p $DIR/$tdir
11647         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11648
11649         check_default_stripe_attr --stripe-count --raw
11650         check_default_stripe_attr --stripe-size --raw
11651
11652         return 0
11653 }
11654 run_test 204h "Print raw stripe count and size ============="
11655
11656 # Figure out which job scheduler is being used, if any,
11657 # or use a fake one
11658 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11659         JOBENV=SLURM_JOB_ID
11660 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11661         JOBENV=LSB_JOBID
11662 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11663         JOBENV=PBS_JOBID
11664 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11665         JOBENV=LOADL_STEP_ID
11666 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11667         JOBENV=JOB_ID
11668 else
11669         $LCTL list_param jobid_name > /dev/null 2>&1
11670         if [ $? -eq 0 ]; then
11671                 JOBENV=nodelocal
11672         else
11673                 JOBENV=FAKE_JOBID
11674         fi
11675 fi
11676
11677 verify_jobstats() {
11678         local cmd=($1)
11679         shift
11680         local facets="$@"
11681
11682 # we don't really need to clear the stats for this test to work, since each
11683 # command has a unique jobid, but it makes debugging easier if needed.
11684 #       for facet in $facets; do
11685 #               local dev=$(convert_facet2label $facet)
11686 #               # clear old jobstats
11687 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
11688 #       done
11689
11690         # use a new JobID for each test, or we might see an old one
11691         [ "$JOBENV" = "FAKE_JOBID" ] &&
11692                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
11693
11694         JOBVAL=${!JOBENV}
11695
11696         [ "$JOBENV" = "nodelocal" ] && {
11697                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
11698                 $LCTL set_param jobid_name=$FAKE_JOBID
11699                 JOBVAL=$FAKE_JOBID
11700         }
11701
11702         log "Test: ${cmd[*]}"
11703         log "Using JobID environment variable $JOBENV=$JOBVAL"
11704
11705         if [ $JOBENV = "FAKE_JOBID" ]; then
11706                 FAKE_JOBID=$JOBVAL ${cmd[*]}
11707         else
11708                 ${cmd[*]}
11709         fi
11710
11711         # all files are created on OST0000
11712         for facet in $facets; do
11713                 local stats="*.$(convert_facet2label $facet).job_stats"
11714                 if [ $(do_facet $facet lctl get_param $stats |
11715                        grep -c $JOBVAL) -ne 1 ]; then
11716                         do_facet $facet lctl get_param $stats
11717                         error "No jobstats for $JOBVAL found on $facet::$stats"
11718                 fi
11719         done
11720 }
11721
11722 jobstats_set() {
11723         trap 0
11724         NEW_JOBENV=${1:-$OLD_JOBENV}
11725         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11726         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11727 }
11728
11729 cleanup_205() {
11730         do_facet $SINGLEMDS \
11731                 $LCTL set_param mdt.*.job_cleanup_interval=$OLD_INTERVAL
11732         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11733         do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
11734 }
11735
11736 test_205() { # Job stats
11737         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11738         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11739         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11740         remote_ost_nodsh && skip "remote OST with nodsh" && return
11741
11742         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11743                 skip "Server doesn't support jobstats" && return 0
11744         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11745
11746         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11747         if [ $OLD_JOBENV != $JOBENV ]; then
11748                 jobstats_set $JOBENV
11749                 trap cleanup_205 EXIT
11750         fi
11751
11752         CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
11753         echo "Registered as changelog user $CL_USER"
11754
11755         OLD_INTERVAL=$(do_facet $SINGLEMDS \
11756                        lctl get_param -n mdt.*.job_cleanup_interval)
11757         local interval_new=5
11758         do_facet $SINGLEMDS \
11759                 $LCTL set_param mdt.*.job_cleanup_interval=$interval_new
11760         local start=$SECONDS
11761
11762         local cmd
11763         # mkdir
11764         cmd="mkdir $DIR/$tdir"
11765         verify_jobstats "$cmd" "$SINGLEMDS"
11766         # rmdir
11767         cmd="rmdir $DIR/$tdir"
11768         verify_jobstats "$cmd" "$SINGLEMDS"
11769         # mkdir on secondary MDT
11770         if [ $MDSCOUNT -gt 1 ]; then
11771                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
11772                 verify_jobstats "$cmd" "mds2"
11773         fi
11774         # mknod
11775         cmd="mknod $DIR/$tfile c 1 3"
11776         verify_jobstats "$cmd" "$SINGLEMDS"
11777         # unlink
11778         cmd="rm -f $DIR/$tfile"
11779         verify_jobstats "$cmd" "$SINGLEMDS"
11780         # create all files on OST0000 so verify_jobstats can find OST stats
11781         # open & close
11782         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11783         verify_jobstats "$cmd" "$SINGLEMDS"
11784         # setattr
11785         cmd="touch $DIR/$tfile"
11786         verify_jobstats "$cmd" "$SINGLEMDS ost1"
11787         # write
11788         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11789         verify_jobstats "$cmd" "ost1"
11790         # read
11791         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11792         verify_jobstats "$cmd" "ost1"
11793         # truncate
11794         cmd="$TRUNCATE $DIR/$tfile 0"
11795         verify_jobstats "$cmd" "$SINGLEMDS ost1"
11796         # rename
11797         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
11798         verify_jobstats "$cmd" "$SINGLEMDS"
11799         # jobstats expiry - sleep until old stats should be expired
11800         local left=$((interval_new + 2 - (SECONDS - start)))
11801         [ $left -ge 0 ] && echo "sleep $left for expiry" && sleep $((left + 1))
11802         cmd="mkdir $DIR/$tdir.expire"
11803         verify_jobstats "$cmd" "$SINGLEMDS"
11804         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
11805             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
11806
11807         # Ensure that jobid are present in changelog (if supported by MDS)
11808         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
11809         then
11810                 $LFS changelog $MDT0 | tail -9
11811                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
11812                 [ $jobids -eq 9 ] ||
11813                         error "Wrong changelog jobid count $jobids != 9"
11814
11815                 # LU-5862
11816                 JOBENV="disable"
11817                 jobstats_set $JOBENV
11818                 touch $DIR/$tfile
11819                 $LFS changelog $MDT0 | tail -1
11820                 jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
11821                 [ $jobids -eq 0 ] ||
11822                         error "Unexpected jobids when jobid_var=$JOBENV"
11823         fi
11824
11825         cleanup_205
11826 }
11827 run_test 205 "Verify job stats"
11828
11829 # LU-1480, LU-1773 and LU-1657
11830 test_206() {
11831         mkdir -p $DIR/$tdir
11832         $SETSTRIPE -c -1 $DIR/$tdir
11833 #define OBD_FAIL_LOV_INIT 0x1403
11834         $LCTL set_param fail_loc=0xa0001403
11835         $LCTL set_param fail_val=1
11836         touch $DIR/$tdir/$tfile || true
11837 }
11838 run_test 206 "fail lov_init_raid0() doesn't lbug"
11839
11840 test_207a() {
11841         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11842         local fsz=`stat -c %s $DIR/$tfile`
11843         cancel_lru_locks mdc
11844
11845         # do not return layout in getattr intent
11846 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11847         $LCTL set_param fail_loc=0x170
11848         local sz=`stat -c %s $DIR/$tfile`
11849
11850         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11851
11852         rm -rf $DIR/$tfile
11853 }
11854 run_test 207a "can refresh layout at glimpse"
11855
11856 test_207b() {
11857         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11858         local cksum=`md5sum $DIR/$tfile`
11859         local fsz=`stat -c %s $DIR/$tfile`
11860         cancel_lru_locks mdc
11861         cancel_lru_locks osc
11862
11863         # do not return layout in getattr intent
11864 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11865         $LCTL set_param fail_loc=0x171
11866
11867         # it will refresh layout after the file is opened but before read issues
11868         echo checksum is "$cksum"
11869         echo "$cksum" |md5sum -c --quiet || error "file differs"
11870
11871         rm -rf $DIR/$tfile
11872 }
11873 run_test 207b "can refresh layout at open"
11874
11875 test_208() {
11876         # FIXME: in this test suite, only RD lease is used. This is okay
11877         # for now as only exclusive open is supported. After generic lease
11878         # is done, this test suite should be revised. - Jinshan
11879
11880         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11881         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11882                 { skip "Need MDS version at least 2.4.52"; return 0; }
11883
11884         echo "==== test 1: verify get lease work"
11885         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11886
11887         echo "==== test 2: verify lease can be broken by upcoming open"
11888         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11889         local PID=$!
11890         sleep 1
11891
11892         $MULTIOP $DIR/$tfile oO_RDONLY:c
11893         kill -USR1 $PID && wait $PID || error "break lease error"
11894
11895         echo "==== test 3: verify lease can't be granted if an open already exists"
11896         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11897         local PID=$!
11898         sleep 1
11899
11900         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11901         kill -USR1 $PID && wait $PID || error "open file error"
11902
11903         echo "==== test 4: lease can sustain over recovery"
11904         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11905         PID=$!
11906         sleep 1
11907
11908         fail mds1
11909
11910         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11911
11912         echo "==== test 5: lease broken can't be regained by replay"
11913         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11914         PID=$!
11915         sleep 1
11916
11917         # open file to break lease and then recovery
11918         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11919         fail mds1
11920
11921         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11922
11923         rm -f $DIR/$tfile
11924 }
11925 run_test 208 "Exclusive open"
11926
11927 test_209() {
11928         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11929                 skip_env "must have disp_stripe" && return
11930
11931         touch $DIR/$tfile
11932         sync; sleep 5; sync;
11933
11934         echo 3 > /proc/sys/vm/drop_caches
11935         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11936
11937         # open/close 500 times
11938         for i in $(seq 500); do
11939                 cat $DIR/$tfile
11940         done
11941
11942         echo 3 > /proc/sys/vm/drop_caches
11943         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11944
11945         echo "before: $req_before, after: $req_after"
11946         [ $((req_after - req_before)) -ge 300 ] &&
11947                 error "open/close requests are not freed"
11948         return 0
11949 }
11950 run_test 209 "read-only open/close requests should be freed promptly"
11951
11952 test_212() {
11953         size=`date +%s`
11954         size=$((size % 8192 + 1))
11955         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11956         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11957         rm -f $DIR/f212 $DIR/f212.xyz
11958 }
11959 run_test 212 "Sendfile test ============================================"
11960
11961 test_213() {
11962         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11963         cancel_lru_locks osc
11964         lctl set_param fail_loc=0x8000040f
11965         # generate a read lock
11966         cat $DIR/$tfile > /dev/null
11967         # write to the file, it will try to cancel the above read lock.
11968         cat /etc/hosts >> $DIR/$tfile
11969 }
11970 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11971
11972 test_214() { # for bug 20133
11973         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11974         for (( i=0; i < 340; i++ )) ; do
11975                 touch $DIR/$tdir/d214c/a$i
11976         done
11977
11978         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11979         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11980         ls $DIR/d214c || error "ls $DIR/d214c failed"
11981         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11982         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11983 }
11984 run_test 214 "hash-indexed directory test - bug 20133"
11985
11986 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11987 create_lnet_proc_files() {
11988         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
11989         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11990
11991         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11992         rm -f "$TMP/lnet_$1.sys_tmp"
11993 }
11994
11995 # counterpart of create_lnet_proc_files
11996 remove_lnet_proc_files() {
11997         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11998 }
11999
12000 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12001 # 3rd arg as regexp for body
12002 check_lnet_proc_stats() {
12003         local l=$(cat "$TMP/lnet_$1" |wc -l)
12004         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
12005
12006         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
12007 }
12008
12009 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12010 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
12011 # optional and can be regexp for 2nd line (lnet.routes case)
12012 check_lnet_proc_entry() {
12013         local blp=2          # blp stands for 'position of 1st line of body'
12014         [ -z "$5" ] || blp=3 # lnet.routes case
12015
12016         local l=$(cat "$TMP/lnet_$1" |wc -l)
12017         # subtracting one from $blp because the body can be empty
12018         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
12019
12020         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
12021                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
12022
12023         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
12024                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
12025
12026         # bail out if any unexpected line happened
12027         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
12028         [ "$?" != 0 ] || error "$2 misformatted"
12029 }
12030
12031 test_215() { # for bugs 18102, 21079, 21517
12032         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12033         local N='(0|[1-9][0-9]*)'       # non-negative numeric
12034         local P='[1-9][0-9]*'           # positive numeric
12035         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
12036         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
12037         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
12038         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
12039
12040         local L1 # regexp for 1st line
12041         local L2 # regexp for 2nd line (optional)
12042         local BR # regexp for the rest (body)
12043
12044         # lnet.stats should look as 11 space-separated non-negative numerics
12045         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
12046         create_lnet_proc_files "stats"
12047         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
12048         remove_lnet_proc_files "stats"
12049
12050         # lnet.routes should look like this:
12051         # Routing disabled/enabled
12052         # net hops priority state router
12053         # where net is a string like tcp0, hops > 0, priority >= 0,
12054         # state is up/down,
12055         # router is a string like 192.168.1.1@tcp2
12056         L1="^Routing (disabled|enabled)$"
12057         L2="^net +hops +priority +state +router$"
12058         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
12059         create_lnet_proc_files "routes"
12060         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
12061         remove_lnet_proc_files "routes"
12062
12063         # lnet.routers should look like this:
12064         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
12065         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
12066         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
12067         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
12068         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
12069         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
12070         create_lnet_proc_files "routers"
12071         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
12072         remove_lnet_proc_files "routers"
12073
12074         # lnet.peers should look like this:
12075         # nid refs state last max rtr min tx min queue
12076         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
12077         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
12078         # numeric (0 or >0 or <0), queue >= 0.
12079         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
12080         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
12081         create_lnet_proc_files "peers"
12082         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
12083         remove_lnet_proc_files "peers"
12084
12085         # lnet.buffers  should look like this:
12086         # pages count credits min
12087         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
12088         L1="^pages +count +credits +min$"
12089         BR="^ +$N +$N +$I +$I$"
12090         create_lnet_proc_files "buffers"
12091         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
12092         remove_lnet_proc_files "buffers"
12093
12094         # lnet.nis should look like this:
12095         # nid status alive refs peer rtr max tx min
12096         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
12097         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
12098         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
12099         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
12100         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
12101         create_lnet_proc_files "nis"
12102         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
12103         remove_lnet_proc_files "nis"
12104
12105         # can we successfully write to lnet.stats?
12106         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
12107         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
12108 }
12109 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
12110
12111 test_216() { # bug 20317
12112         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12113         remote_ost_nodsh && skip "remote OST with nodsh" && return
12114
12115         local node
12116         local facets=$(get_facets OST)
12117         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
12118
12119         save_lustre_params client "osc.*.contention_seconds" > $p
12120         save_lustre_params $facets \
12121                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
12122         save_lustre_params $facets \
12123                 "ldlm.namespaces.filter-*.contended_locks" >> $p
12124         save_lustre_params $facets \
12125                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
12126         clear_osc_stats
12127
12128         # agressive lockless i/o settings
12129         for node in $(osts_nodes); do
12130                 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'
12131         done
12132         lctl set_param -n osc.*.contention_seconds 60
12133
12134         $DIRECTIO write $DIR/$tfile 0 10 4096
12135         $CHECKSTAT -s 40960 $DIR/$tfile
12136
12137         # disable lockless i/o
12138         for node in $(osts_nodes); do
12139                 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'
12140         done
12141         lctl set_param -n osc.*.contention_seconds 0
12142         clear_osc_stats
12143
12144         dd if=/dev/zero of=$DIR/$tfile count=0
12145         $CHECKSTAT -s 0 $DIR/$tfile
12146
12147         restore_lustre_params <$p
12148         rm -f $p
12149         rm $DIR/$tfile
12150 }
12151 run_test 216 "check lockless direct write works and updates file size and kms correctly"
12152
12153 test_217() { # bug 22430
12154         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12155         local node
12156         local nid
12157
12158         for node in $(nodes_list); do
12159                 nid=$(host_nids_address $node $NETTYPE)
12160                 if [[ $nid = *-* ]] ; then
12161                         echo "lctl ping $nid@$NETTYPE"
12162                         lctl ping $nid@$NETTYPE
12163                 else
12164                         echo "skipping $node (no hyphen detected)"
12165                 fi
12166         done
12167 }
12168 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
12169
12170 test_218() {
12171        # do directio so as not to populate the page cache
12172        log "creating a 10 Mb file"
12173        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
12174        log "starting reads"
12175        dd if=$DIR/$tfile of=/dev/null bs=4096 &
12176        log "truncating the file"
12177        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
12178        log "killing dd"
12179        kill %+ || true # reads might have finished
12180        echo "wait until dd is finished"
12181        wait
12182        log "removing the temporary file"
12183        rm -rf $DIR/$tfile || error "tmp file removal failed"
12184 }
12185 run_test 218 "parallel read and truncate should not deadlock ======================="
12186
12187 test_219() {
12188         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12189         # write one partial page
12190         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
12191         # set no grant so vvp_io_commit_write will do sync write
12192         $LCTL set_param fail_loc=0x411
12193         # write a full page at the end of file
12194         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
12195
12196         $LCTL set_param fail_loc=0
12197         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
12198         $LCTL set_param fail_loc=0x411
12199         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
12200
12201         # LU-4201
12202         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
12203         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
12204 }
12205 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
12206
12207 test_220() { #LU-325
12208         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12209         remote_ost_nodsh && skip "remote OST with nodsh" && return
12210         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12211         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12212         local OSTIDX=0
12213
12214         # create on MDT0000 so the last_id and next_id are correct
12215         mkdir $DIR/$tdir
12216         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
12217         OST=${OST%_UUID}
12218
12219         # on the mdt's osc
12220         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
12221         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
12222                         osc.$mdtosc_proc1.prealloc_last_id)
12223         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
12224                         osc.$mdtosc_proc1.prealloc_next_id)
12225
12226         $LFS df -i
12227
12228         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
12229         #define OBD_FAIL_OST_ENOINO              0x229
12230         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
12231         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
12232         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
12233
12234         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
12235
12236         MDSOBJS=$((last_id - next_id))
12237         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
12238
12239         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
12240         echo "OST still has $count kbytes free"
12241
12242         echo "create $MDSOBJS files @next_id..."
12243         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
12244
12245         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12246                         osc.$mdtosc_proc1.prealloc_last_id)
12247         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12248                         osc.$mdtosc_proc1.prealloc_next_id)
12249
12250         echo "after creation, last_id=$last_id2, next_id=$next_id2"
12251         $LFS df -i
12252
12253         echo "cleanup..."
12254
12255         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
12256         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
12257
12258         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
12259         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
12260         echo "unlink $MDSOBJS files @$next_id..."
12261         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
12262 }
12263 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
12264
12265 test_221() {
12266         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12267         dd if=`which date` of=$MOUNT/date oflag=sync
12268         chmod +x $MOUNT/date
12269
12270         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
12271         $LCTL set_param fail_loc=0x80001401
12272
12273         $MOUNT/date > /dev/null
12274         rm -f $MOUNT/date
12275 }
12276 run_test 221 "make sure fault and truncate race to not cause OOM"
12277
12278 test_222a () {
12279         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12280        rm -rf $DIR/$tdir
12281        test_mkdir -p $DIR/$tdir
12282        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12283        createmany -o $DIR/$tdir/$tfile 10
12284        cancel_lru_locks mdc
12285        cancel_lru_locks osc
12286        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12287        $LCTL set_param fail_loc=0x31a
12288        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
12289        $LCTL set_param fail_loc=0
12290        rm -r $DIR/$tdir
12291 }
12292 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
12293
12294 test_222b () {
12295         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12296        rm -rf $DIR/$tdir
12297        test_mkdir -p $DIR/$tdir
12298        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12299        createmany -o $DIR/$tdir/$tfile 10
12300        cancel_lru_locks mdc
12301        cancel_lru_locks osc
12302        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12303        $LCTL set_param fail_loc=0x31a
12304        rm -r $DIR/$tdir || "AGL for rmdir failed"
12305        $LCTL set_param fail_loc=0
12306 }
12307 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
12308
12309 test_223 () {
12310         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12311        rm -rf $DIR/$tdir
12312        test_mkdir -p $DIR/$tdir
12313        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12314        createmany -o $DIR/$tdir/$tfile 10
12315        cancel_lru_locks mdc
12316        cancel_lru_locks osc
12317        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
12318        $LCTL set_param fail_loc=0x31b
12319        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
12320        $LCTL set_param fail_loc=0
12321        rm -r $DIR/$tdir
12322 }
12323 run_test 223 "osc reenqueue if without AGL lock granted ======================="
12324
12325 test_224a() { # LU-1039, MRP-303
12326         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12327         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
12328         $LCTL set_param fail_loc=0x508
12329         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
12330         $LCTL set_param fail_loc=0
12331         df $DIR
12332 }
12333 run_test 224a "Don't panic on bulk IO failure"
12334
12335 test_224b() { # LU-1039, MRP-303
12336         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12337         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
12338         cancel_lru_locks osc
12339         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
12340         $LCTL set_param fail_loc=0x515
12341         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
12342         $LCTL set_param fail_loc=0
12343         df $DIR
12344 }
12345 run_test 224b "Don't panic on bulk IO failure"
12346
12347 test_224c() { # LU-6441
12348         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12349         local pages_per_rpc=$($LCTL get_param \
12350                                 osc.*.max_pages_per_rpc)
12351         local at_max=$($LCTL get_param -n at_max)
12352         local timeout=$($LCTL get_param -n timeout)
12353         local test_at="$LCTL get_param -n at_max"
12354         local param_at="$FSNAME.sys.at_max"
12355         local test_timeout="$LCTL get_param -n timeout"
12356         local param_timeout="$FSNAME.sys.timeout"
12357
12358         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
12359
12360         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
12361                 error "conf_param at_max=0 failed"
12362         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
12363                 error "conf_param timeout=5 failed"
12364
12365         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
12366         $LCTL set_param fail_loc=0x520
12367         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
12368         sync
12369         $LCTL set_param fail_loc=0
12370
12371         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
12372                 error "conf_param at_max=$at_max failed"
12373         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
12374                 $timeout || error "conf_param timeout=$timeout failed"
12375
12376         $LCTL set_param -n $pages_per_rpc
12377 }
12378 run_test 224c "Don't hang if one of md lost during large bulk RPC"
12379
12380 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
12381 test_225a () {
12382         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12383         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12384         if [ -z ${MDSSURVEY} ]; then
12385               skip_env "mds-survey not found" && return
12386         fi
12387
12388         [ $MDSCOUNT -ge 2 ] &&
12389                 skip "skipping now for more than one MDT" && return
12390
12391        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12392             { skip "Need MDS version at least 2.2.51"; return; }
12393
12394        local mds=$(facet_host $SINGLEMDS)
12395        local target=$(do_nodes $mds 'lctl dl' | \
12396                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12397
12398        local cmd1="file_count=1000 thrhi=4"
12399        local cmd2="dir_count=2 layer=mdd stripe_count=0"
12400        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12401        local cmd="$cmd1 $cmd2 $cmd3"
12402
12403        rm -f ${TMP}/mds_survey*
12404        echo + $cmd
12405        eval $cmd || error "mds-survey with zero-stripe failed"
12406        cat ${TMP}/mds_survey*
12407        rm -f ${TMP}/mds_survey*
12408 }
12409 run_test 225a "Metadata survey sanity with zero-stripe"
12410
12411 test_225b () {
12412         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12413         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12414         if [ -z ${MDSSURVEY} ]; then
12415               skip_env "mds-survey not found" && return
12416         fi
12417         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12418             { skip "Need MDS version at least 2.2.51"; return; }
12419
12420         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
12421               skip_env "Need to mount OST to test" && return
12422         fi
12423
12424         [ $MDSCOUNT -ge 2 ] &&
12425                 skip "skipping now for more than one MDT" && return
12426        local mds=$(facet_host $SINGLEMDS)
12427        local target=$(do_nodes $mds 'lctl dl' | \
12428                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12429
12430        local cmd1="file_count=1000 thrhi=4"
12431        local cmd2="dir_count=2 layer=mdd stripe_count=1"
12432        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12433        local cmd="$cmd1 $cmd2 $cmd3"
12434
12435        rm -f ${TMP}/mds_survey*
12436        echo + $cmd
12437        eval $cmd || error "mds-survey with stripe_count failed"
12438        cat ${TMP}/mds_survey*
12439        rm -f ${TMP}/mds_survey*
12440 }
12441 run_test 225b "Metadata survey sanity with stripe_count = 1"
12442
12443 mcreate_path2fid () {
12444         local mode=$1
12445         local major=$2
12446         local minor=$3
12447         local name=$4
12448         local desc=$5
12449         local path=$DIR/$tdir/$name
12450         local fid
12451         local rc
12452         local fid_path
12453
12454         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
12455                 error "cannot create $desc"
12456
12457         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
12458         rc=$?
12459         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
12460
12461         fid_path=$($LFS fid2path $MOUNT $fid)
12462         rc=$?
12463         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
12464
12465         [ "$path" == "$fid_path" ] ||
12466                 error "fid2path returned $fid_path, expected $path"
12467
12468         echo "pass with $path and $fid"
12469 }
12470
12471 test_226a () {
12472         rm -rf $DIR/$tdir
12473         mkdir -p $DIR/$tdir
12474
12475         mcreate_path2fid 0010666 0 0 fifo "FIFO"
12476         mcreate_path2fid 0020666 1 3 null "character special file (null)"
12477         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
12478         mcreate_path2fid 0040666 0 0 dir "directory"
12479         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
12480         mcreate_path2fid 0100666 0 0 file "regular file"
12481         mcreate_path2fid 0120666 0 0 link "symbolic link"
12482         mcreate_path2fid 0140666 0 0 sock "socket"
12483 }
12484 run_test 226a "call path2fid and fid2path on files of all type"
12485
12486 test_226b () {
12487         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12488         rm -rf $DIR/$tdir
12489         local MDTIDX=1
12490
12491         mkdir -p $DIR/$tdir
12492         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
12493                 error "create remote directory failed"
12494         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
12495         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
12496                                 "character special file (null)"
12497         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
12498                                 "character special file (no device)"
12499         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
12500         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
12501                                 "block special file (loop)"
12502         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
12503         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
12504         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
12505 }
12506 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
12507
12508 # LU-1299 Executing or running ldd on a truncated executable does not
12509 # cause an out-of-memory condition.
12510 test_227() {
12511         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12512         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
12513         dd if=$(which date) of=$MOUNT/date bs=1k count=1
12514         chmod +x $MOUNT/date
12515
12516         $MOUNT/date > /dev/null
12517         ldd $MOUNT/date > /dev/null
12518         rm -f $MOUNT/date
12519 }
12520 run_test 227 "running truncated executable does not cause OOM"
12521
12522 # LU-1512 try to reuse idle OI blocks
12523 test_228a() {
12524         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12525         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12526         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12527                 skip "non-ldiskfs backend" && return
12528
12529         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12530         local myDIR=$DIR/$tdir
12531
12532         mkdir -p $myDIR
12533         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12534         $LCTL set_param fail_loc=0x80001002
12535         createmany -o $myDIR/t- 10000
12536         $LCTL set_param fail_loc=0
12537         # The guard is current the largest FID holder
12538         touch $myDIR/guard
12539         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12540                     tr -d '[')
12541         local IDX=$(($SEQ % 64))
12542
12543         do_facet $SINGLEMDS sync
12544         # Make sure journal flushed.
12545         sleep 6
12546         local blk1=$(do_facet $SINGLEMDS \
12547                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12548                      grep Blockcount | awk '{print $4}')
12549
12550         # Remove old files, some OI blocks will become idle.
12551         unlinkmany $myDIR/t- 10000
12552         # Create new files, idle OI blocks should be reused.
12553         createmany -o $myDIR/t- 2000
12554         do_facet $SINGLEMDS sync
12555         # Make sure journal flushed.
12556         sleep 6
12557         local blk2=$(do_facet $SINGLEMDS \
12558                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12559                      grep Blockcount | awk '{print $4}')
12560
12561         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12562 }
12563 run_test 228a "try to reuse idle OI blocks"
12564
12565 test_228b() {
12566         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12567         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12568         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12569                 skip "non-ldiskfs backend" && return
12570
12571         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12572         local myDIR=$DIR/$tdir
12573
12574         mkdir -p $myDIR
12575         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12576         $LCTL set_param fail_loc=0x80001002
12577         createmany -o $myDIR/t- 10000
12578         $LCTL set_param fail_loc=0
12579         # The guard is current the largest FID holder
12580         touch $myDIR/guard
12581         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12582                     tr -d '[')
12583         local IDX=$(($SEQ % 64))
12584
12585         do_facet $SINGLEMDS sync
12586         # Make sure journal flushed.
12587         sleep 6
12588         local blk1=$(do_facet $SINGLEMDS \
12589                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12590                      grep Blockcount | awk '{print $4}')
12591
12592         # Remove old files, some OI blocks will become idle.
12593         unlinkmany $myDIR/t- 10000
12594
12595         # stop the MDT
12596         stop $SINGLEMDS || error "Fail to stop MDT."
12597         # remount the MDT
12598         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
12599
12600         df $MOUNT || error "Fail to df."
12601         # Create new files, idle OI blocks should be reused.
12602         createmany -o $myDIR/t- 2000
12603         do_facet $SINGLEMDS sync
12604         # Make sure journal flushed.
12605         sleep 6
12606         local blk2=$(do_facet $SINGLEMDS \
12607                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12608                      grep Blockcount | awk '{print $4}')
12609
12610         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12611 }
12612 run_test 228b "idle OI blocks can be reused after MDT restart"
12613
12614 #LU-1881
12615 test_228c() {
12616         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12617         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12618         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12619                 skip "non-ldiskfs backend" && return
12620
12621         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12622         local myDIR=$DIR/$tdir
12623
12624         mkdir -p $myDIR
12625         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12626         $LCTL set_param fail_loc=0x80001002
12627         # 20000 files can guarantee there are index nodes in the OI file
12628         createmany -o $myDIR/t- 20000
12629         $LCTL set_param fail_loc=0
12630         # The guard is current the largest FID holder
12631         touch $myDIR/guard
12632         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12633                     tr -d '[')
12634         local IDX=$(($SEQ % 64))
12635
12636         do_facet $SINGLEMDS sync
12637         # Make sure journal flushed.
12638         sleep 6
12639         local blk1=$(do_facet $SINGLEMDS \
12640                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12641                      grep Blockcount | awk '{print $4}')
12642
12643         # Remove old files, some OI blocks will become idle.
12644         unlinkmany $myDIR/t- 20000
12645         rm -f $myDIR/guard
12646         # The OI file should become empty now
12647
12648         # Create new files, idle OI blocks should be reused.
12649         createmany -o $myDIR/t- 2000
12650         do_facet $SINGLEMDS sync
12651         # Make sure journal flushed.
12652         sleep 6
12653         local blk2=$(do_facet $SINGLEMDS \
12654                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12655                      grep Blockcount | awk '{print $4}')
12656
12657         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12658 }
12659 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
12660
12661 test_229() { # LU-2482, LU-3448
12662         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
12663                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
12664                 return
12665         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12666         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
12667
12668         rm -f $DIR/$tfile
12669
12670         # Create a file with a released layout and stripe count 2.
12671         $MULTIOP $DIR/$tfile H2c ||
12672                 error "failed to create file with released layout"
12673
12674         $GETSTRIPE -v $DIR/$tfile
12675
12676         local pattern=$($GETSTRIPE -L $DIR/$tfile)
12677         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
12678
12679         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
12680         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
12681         stat $DIR/$tfile || error "failed to stat released file"
12682
12683         chown $RUNAS_ID $DIR/$tfile ||
12684                 error "chown $RUNAS_ID $DIR/$tfile failed"
12685
12686         chgrp $RUNAS_ID $DIR/$tfile ||
12687                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12688
12689         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12690         rm $DIR/$tfile || error "failed to remove released file"
12691 }
12692 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12693
12694 test_230a() {
12695         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12696         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12697         local MDTIDX=1
12698
12699         test_mkdir $DIR/$tdir
12700         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
12701         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12702         [ $mdt_idx -ne 0 ] &&
12703                 error "create local directory on wrong MDT $mdt_idx"
12704
12705         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12706                         error "create remote directory failed"
12707         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12708         [ $mdt_idx -ne $MDTIDX ] &&
12709                 error "create remote directory on wrong MDT $mdt_idx"
12710
12711         createmany -o $DIR/$tdir/test_230/t- 10 ||
12712                 error "create files on remote directory failed"
12713         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12714         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12715         rm -r $DIR/$tdir || error "unlink remote directory failed"
12716 }
12717 run_test 230a "Create remote directory and files under the remote directory"
12718
12719 test_230b() {
12720         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12721         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12722         local MDTIDX=1
12723         local mdt_index
12724         local i
12725         local file
12726         local pid
12727         local stripe_count
12728         local migrate_dir=$DIR/$tdir/migrate_dir
12729         local other_dir=$DIR/$tdir/other_dir
12730
12731         test_mkdir $DIR/$tdir
12732         test_mkdir -i0 -c1 $migrate_dir
12733         test_mkdir -i0 -c1 $other_dir
12734         for ((i=0; i<10; i++)); do
12735                 mkdir -p $migrate_dir/dir_${i}
12736                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12737                         error "create files under remote dir failed $i"
12738         done
12739
12740         cp /etc/passwd $migrate_dir/$tfile
12741         cp /etc/passwd $other_dir/$tfile
12742         chattr +SAD $migrate_dir
12743         chattr +SAD $migrate_dir/$tfile
12744
12745         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12746         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12747         local old_dir_mode=$(stat -c%f $migrate_dir)
12748         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
12749
12750         mkdir -p $migrate_dir/dir_default_stripe2
12751         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12752         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12753
12754         mkdir -p $other_dir
12755         ln $migrate_dir/$tfile $other_dir/luna
12756         ln $migrate_dir/$tfile $migrate_dir/sofia
12757         ln $other_dir/$tfile $migrate_dir/david
12758         ln -s $migrate_dir/$tfile $other_dir/zachary
12759         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12760         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12761
12762         $LFS migrate -m $MDTIDX $migrate_dir ||
12763                 error "fails on migrating remote dir to MDT1"
12764
12765         echo "migratate to MDT1, then checking.."
12766         for ((i = 0; i < 10; i++)); do
12767                 for file in $(find $migrate_dir/dir_${i}); do
12768                         mdt_index=$($LFS getstripe -M $file)
12769                         [ $mdt_index == $MDTIDX ] ||
12770                                 error "$file is not on MDT${MDTIDX}"
12771                 done
12772         done
12773
12774         # the multiple link file should still in MDT0
12775         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12776         [ $mdt_index == 0 ] ||
12777                 error "$file is not on MDT${MDTIDX}"
12778
12779         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12780         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12781                 error " expect $old_dir_flag get $new_dir_flag"
12782
12783         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12784         [ "$old_file_flag" = "$new_file_flag" ] ||
12785                 error " expect $old_file_flag get $new_file_flag"
12786
12787         local new_dir_mode=$(stat -c%f $migrate_dir)
12788         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12789                 error "expect mode $old_dir_mode get $new_dir_mode"
12790
12791         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12792         [ "$old_file_mode" = "$new_file_mode" ] ||
12793                 error "expect mode $old_file_mode get $new_file_mode"
12794
12795         diff /etc/passwd $migrate_dir/$tfile ||
12796                 error "$tfile different after migration"
12797
12798         diff /etc/passwd $other_dir/luna ||
12799                 error "luna different after migration"
12800
12801         diff /etc/passwd $migrate_dir/sofia ||
12802                 error "sofia different after migration"
12803
12804         diff /etc/passwd $migrate_dir/david ||
12805                 error "david different after migration"
12806
12807         diff /etc/passwd $other_dir/zachary ||
12808                 error "zachary different after migration"
12809
12810         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12811                 error "${tfile}_ln different after migration"
12812
12813         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12814                 error "${tfile}_ln_other different after migration"
12815
12816         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12817         [ $stripe_count = 2 ] ||
12818                 error "dir strpe_count $d != 2 after migration."
12819
12820         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12821         [ $stripe_count = 2 ] ||
12822                 error "file strpe_count $d != 2 after migration."
12823
12824         #migrate back to MDT0
12825         MDTIDX=0
12826
12827         $LFS migrate -m $MDTIDX $migrate_dir ||
12828                 error "fails on migrating remote dir to MDT0"
12829
12830         echo "migrate back to MDT0, checking.."
12831         for file in $(find $migrate_dir); do
12832                 mdt_index=$($LFS getstripe -M $file)
12833                 [ $mdt_index == $MDTIDX ] ||
12834                         error "$file is not on MDT${MDTIDX}"
12835         done
12836
12837         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12838         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12839                 error " expect $old_dir_flag get $new_dir_flag"
12840
12841         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12842         [ "$old_file_flag" = "$new_file_flag" ] ||
12843                 error " expect $old_file_flag get $new_file_flag"
12844
12845         local new_dir_mode=$(stat -c%f $migrate_dir)
12846         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12847                 error "expect mode $old_dir_mode get $new_dir_mode"
12848
12849         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12850         [ "$old_file_mode" = "$new_file_mode" ] ||
12851                 error "expect mode $old_file_mode get $new_file_mode"
12852
12853         diff /etc/passwd ${migrate_dir}/$tfile ||
12854                 error "$tfile different after migration"
12855
12856         diff /etc/passwd ${other_dir}/luna ||
12857                 error "luna different after migration"
12858
12859         diff /etc/passwd ${migrate_dir}/sofia ||
12860                 error "sofia different after migration"
12861
12862         diff /etc/passwd ${other_dir}/zachary ||
12863                 error "zachary different after migration"
12864
12865         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12866                 error "${tfile}_ln different after migration"
12867
12868         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12869                 error "${tfile}_ln_other different after migration"
12870
12871         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12872         [ $stripe_count = 2 ] ||
12873                 error "dir strpe_count $d != 2 after migration."
12874
12875         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12876         [ $stripe_count = 2 ] ||
12877                 error "file strpe_count $d != 2 after migration."
12878
12879         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12880 }
12881 run_test 230b "migrate directory"
12882
12883 test_230c() {
12884         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12885         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12886         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12887         local MDTIDX=1
12888         local mdt_index
12889         local file
12890         local migrate_dir=$DIR/$tdir/migrate_dir
12891
12892         #If migrating directory fails in the middle, all entries of
12893         #the directory is still accessiable.
12894         test_mkdir $DIR/$tdir
12895         test_mkdir -i0 -c1 $migrate_dir
12896         stat $migrate_dir
12897         createmany -o $migrate_dir/f 10 ||
12898                 error "create files under ${migrate_dir} failed"
12899
12900         #failed after migrating 5 entries
12901         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12902         do_facet mds1 lctl set_param fail_loc=0x20001801
12903         do_facet mds1 lctl  set_param fail_val=5
12904         local t=$(ls $migrate_dir | wc -l)
12905         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
12906                 error "migrate should fail after 5 entries"
12907
12908         mkdir $migrate_dir/dir &&
12909                 error "mkdir succeeds under migrating directory"
12910         touch $migrate_dir/file &&
12911                 error "touch file succeeds under migrating directory"
12912
12913         local u=$(ls $migrate_dir | wc -l)
12914         [ "$u" == "$t" ] || error "$u != $t during migration"
12915
12916         for file in $(find $migrate_dir); do
12917                 stat $file || error "stat $file failed"
12918         done
12919
12920         do_facet mds1 lctl set_param fail_loc=0
12921         do_facet mds1 lctl set_param fail_val=0
12922
12923         $LFS migrate -m $MDTIDX $migrate_dir ||
12924                 error "migrate open files should failed with open files"
12925
12926         echo "Finish migration, then checking.."
12927         for file in $(find $migrate_dir); do
12928                 mdt_index=$($LFS getstripe -M $file)
12929                 [ $mdt_index == $MDTIDX ] ||
12930                         error "$file is not on MDT${MDTIDX}"
12931         done
12932
12933         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12934 }
12935 run_test 230c "check directory accessiblity if migration is failed"
12936
12937 test_230d() {
12938         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12939         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12940         local MDTIDX=1
12941         local mdt_index
12942         local migrate_dir=$DIR/$tdir/migrate_dir
12943         local i
12944         local j
12945
12946         test_mkdir $DIR/$tdir
12947         test_mkdir -i0 -c1 $migrate_dir
12948
12949         for ((i=0; i<100; i++)); do
12950                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
12951                 createmany -o $migrate_dir/dir_${i}/f 100 ||
12952                         error "create files under remote dir failed $i"
12953         done
12954
12955         $LFS migrate -m $MDTIDX $migrate_dir ||
12956                 error "migrate remote dir error"
12957
12958         echo "Finish migration, then checking.."
12959         for file in $(find $migrate_dir); do
12960                 mdt_index=$($LFS getstripe -M $file)
12961                 [ $mdt_index == $MDTIDX ] ||
12962                         error "$file is not on MDT${MDTIDX}"
12963         done
12964
12965         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12966 }
12967 run_test 230d "check migrate big directory"
12968
12969 test_230e() {
12970         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12971         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12972         local i
12973         local j
12974         local a_fid
12975         local b_fid
12976
12977         mkdir -p $DIR/$tdir
12978         mkdir $DIR/$tdir/migrate_dir
12979         mkdir $DIR/$tdir/other_dir
12980         touch $DIR/$tdir/migrate_dir/a
12981         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
12982         ls $DIR/$tdir/other_dir
12983
12984         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
12985                 error "migrate dir fails"
12986
12987         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
12988         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
12989
12990         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
12991         [ $mdt_index == 0 ] || error "a is not on MDT0"
12992
12993         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
12994                 error "migrate dir fails"
12995
12996         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir)
12997         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
12998
12999         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13000         [ $mdt_index == 1 ] || error "a is not on MDT1"
13001
13002         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir/b)
13003         [ $mdt_index == 1 ] || error "b is not on MDT1"
13004
13005         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13006         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
13007
13008         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
13009
13010         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13011 }
13012 run_test 230e "migrate mulitple local link files"
13013
13014 test_230f() {
13015         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13016         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13017         local a_fid
13018         local ln_fid
13019
13020         mkdir -p $DIR/$tdir
13021         mkdir $DIR/$tdir/migrate_dir
13022         $LFS mkdir -i1 $DIR/$tdir/other_dir
13023         touch $DIR/$tdir/migrate_dir/a
13024         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
13025         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
13026         ls $DIR/$tdir/other_dir
13027
13028         # a should be migrated to MDT1, since no other links on MDT0
13029         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13030                 error "migrate dir fails"
13031         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13032         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
13033         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13034         [ $mdt_index == 1 ] || error "a is not on MDT1"
13035
13036         # a should stay on MDT1, because it is a mulitple link file
13037         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13038                 error "migrate dir fails"
13039         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13040         [ $mdt_index == 1 ] || error "a is not on MDT1"
13041
13042         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13043                 error "migrate dir fails"
13044
13045         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13046         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
13047         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
13048
13049         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
13050         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
13051
13052         # a should be migrated to MDT0, since no other links on MDT1
13053         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13054                 error "migrate dir fails"
13055         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13056         [ $mdt_index == 0 ] || error "a is not on MDT0"
13057
13058         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13059 }
13060 run_test 230f "migrate mulitple remote link files"
13061
13062 test_230g() {
13063         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13064         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13065
13066         mkdir -p $DIR/$tdir/migrate_dir
13067
13068         $LFS migrate -m 1000 $DIR/$tdir/migrate_dir &&
13069                 error "migrating dir to non-exist MDT succeeds"
13070         true
13071 }
13072 run_test 230g "migrate dir to non-exist MDT"
13073
13074 test_230h() {
13075         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13076         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13077         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
13078                 skip "Need MDS version at least 2.7.64" && return
13079         local mdt_index
13080
13081         mkdir -p $DIR/$tdir/migrate_dir
13082
13083         $LFS migrate -m1 $DIR &&
13084                 error "migrating mountpoint1 should fail"
13085
13086         $LFS migrate -m1 $DIR/$tdir/.. &&
13087                 error "migrating mountpoint2 should fail"
13088
13089         $LFS migrate -m1 $DIR/$tdir/migrate_dir/.. ||
13090                 error "migrating $tdir fail"
13091
13092         mdt_index=$($LFS getstripe -M $DIR/$tdir)
13093         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13094
13095         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13096         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13097
13098 }
13099 run_test 230h "migrate .. and root"
13100
13101 test_231a()
13102 {
13103         # For simplicity this test assumes that max_pages_per_rpc
13104         # is the same across all OSCs
13105         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
13106         local bulk_size=$((max_pages * 4096))
13107
13108         mkdir -p $DIR/$tdir
13109
13110         # clear the OSC stats
13111         $LCTL set_param osc.*.stats=0 &>/dev/null
13112         stop_writeback
13113
13114         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
13115         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
13116                 oflag=direct &>/dev/null || error "dd failed"
13117
13118         sync; sleep 1; sync # just to be safe
13119         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
13120         if [ x$nrpcs != "x1" ]; then
13121                 $LCTL get_param osc.*.stats
13122                 error "found $nrpcs ost_write RPCs, not 1 as expected"
13123         fi
13124
13125         start_writeback
13126         # Drop the OSC cache, otherwise we will read from it
13127         cancel_lru_locks osc
13128
13129         # clear the OSC stats
13130         $LCTL set_param osc.*.stats=0 &>/dev/null
13131
13132         # Client reads $bulk_size.
13133         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
13134                 iflag=direct &>/dev/null || error "dd failed"
13135
13136         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
13137         if [ x$nrpcs != "x1" ]; then
13138                 $LCTL get_param osc.*.stats
13139                 error "found $nrpcs ost_read RPCs, not 1 as expected"
13140         fi
13141 }
13142 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
13143
13144 test_231b() {
13145         mkdir -p $DIR/$tdir
13146         local i
13147         for i in {0..1023}; do
13148                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
13149                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
13150                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
13151         done
13152         sync
13153 }
13154 run_test 231b "must not assert on fully utilized OST request buffer"
13155
13156 test_232() {
13157         mkdir -p $DIR/$tdir
13158         #define OBD_FAIL_LDLM_OST_LVB            0x31c
13159         $LCTL set_param fail_loc=0x31c
13160
13161         # ignore dd failure
13162         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
13163
13164         $LCTL set_param fail_loc=0
13165         umount_client $MOUNT || error "umount failed"
13166         mount_client $MOUNT || error "mount failed"
13167 }
13168 run_test 232 "failed lock should not block umount"
13169
13170 test_233a() {
13171         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
13172         { skip "Need MDS version at least 2.3.64"; return; }
13173
13174         local fid=$($LFS path2fid $MOUNT)
13175         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13176                 error "cannot access $MOUNT using its FID '$fid'"
13177 }
13178 run_test 233a "checking that OBF of the FS root succeeds"
13179
13180 test_233b() {
13181         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
13182         { skip "Need MDS version at least 2.5.90"; return; }
13183
13184         local fid=$($LFS path2fid $MOUNT/.lustre)
13185         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13186                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
13187
13188         fid=$($LFS path2fid $MOUNT/.lustre/fid)
13189         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13190                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
13191 }
13192 run_test 233b "checking that OBF of the FS .lustre succeeds"
13193
13194 test_234() {
13195         local p="$TMP/sanityN-$TESTNAME.parameters"
13196         save_lustre_params client "llite.*.xattr_cache" > $p
13197         lctl set_param llite.*.xattr_cache 1 ||
13198                 { skip "xattr cache is not supported"; return 0; }
13199
13200         mkdir -p $DIR/$tdir || error "mkdir failed"
13201         touch $DIR/$tdir/$tfile || error "touch failed"
13202         # OBD_FAIL_LLITE_XATTR_ENOMEM
13203         $LCTL set_param fail_loc=0x1405
13204         # output of the form: attr 2 4 44 3 fc13 x86_64
13205         V=($(IFS=".-" rpm -q attr))
13206         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
13207               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
13208                 # attr pre-2.4.44-7 had a bug with rc
13209                 # LU-3703 - SLES 11 and FC13 clients have older attr
13210                 getfattr -n user.attr $DIR/$tdir/$tfile &&
13211                         error "getfattr should have failed with ENOMEM"
13212         else
13213                 skip "LU-3703: attr version $(getfattr --version) too old"
13214         fi
13215         $LCTL set_param fail_loc=0x0
13216         rm -rf $DIR/$tdir
13217
13218         restore_lustre_params < $p
13219         rm -f $p
13220 }
13221 run_test 234 "xattr cache should not crash on ENOMEM"
13222
13223 test_235() {
13224         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
13225                 skip "Need MDS version at least 2.4.52" && return
13226         flock_deadlock $DIR/$tfile
13227         local RC=$?
13228         case $RC in
13229                 0)
13230                 ;;
13231                 124) error "process hangs on a deadlock"
13232                 ;;
13233                 *) error "error executing flock_deadlock $DIR/$tfile"
13234                 ;;
13235         esac
13236 }
13237 run_test 235 "LU-1715: flock deadlock detection does not work properly"
13238
13239 #LU-2935
13240 test_236() {
13241         check_swap_layouts_support && return 0
13242         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
13243
13244         local ref1=/etc/passwd
13245         local ref2=/etc/group
13246         local file1=$DIR/$tdir/f1
13247         local file2=$DIR/$tdir/f2
13248
13249         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
13250         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
13251         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
13252         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
13253         local fd=$(free_fd)
13254         local cmd="exec $fd<>$file2"
13255         eval $cmd
13256         rm $file2
13257         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
13258                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
13259         cmd="exec $fd>&-"
13260         eval $cmd
13261         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
13262
13263         #cleanup
13264         rm -rf $DIR/$tdir
13265 }
13266 run_test 236 "Layout swap on open unlinked file"
13267
13268 # test to verify file handle related system calls
13269 # (name_to_handle_at/open_by_handle_at)
13270 # The new system calls are supported in glibc >= 2.14.
13271
13272 test_237() {
13273         echo "Test file_handle syscalls" > $DIR/$tfile ||
13274                 error "write failed"
13275         check_fhandle_syscalls $DIR/$tfile ||
13276                 error "check_fhandle_syscalls failed"
13277 }
13278 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
13279
13280 # LU-4659 linkea consistency
13281 test_238() {
13282         local server_version=$(lustre_version_code $SINGLEMDS)
13283
13284         [[ $server_version -gt $(version_code 2.5.57) ]] ||
13285                 [[ $server_version -gt $(version_code 2.5.1) &&
13286                    $server_version -lt $(version_code 2.5.50) ]] ||
13287                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
13288
13289         touch $DIR/$tfile
13290         ln $DIR/$tfile $DIR/$tfile.lnk
13291         touch $DIR/$tfile.new
13292         mv $DIR/$tfile.new $DIR/$tfile
13293         local fid1=$($LFS path2fid $DIR/$tfile)
13294         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
13295         local path1=$($LFS fid2path $FSNAME "$fid1")
13296         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
13297         local path2=$($LFS fid2path $FSNAME "$fid2")
13298         [ $tfile.lnk == $path2 ] ||
13299                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
13300         rm -f $DIR/$tfile*
13301 }
13302 run_test 238 "Verify linkea consistency"
13303
13304 test_239() {
13305         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
13306                 skip "Need MDS version at least 2.5.60" && return
13307         local list=$(comma_list $(mdts_nodes))
13308
13309         mkdir -p $DIR/$tdir
13310         createmany -o $DIR/$tdir/f- 5000
13311         unlinkmany $DIR/$tdir/f- 5000
13312         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
13313         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
13314                         osc.*MDT*.sync_in_flight" | calc_sum)
13315         [ "$changes" -eq 0 ] || error "$changes not synced"
13316 }
13317 run_test 239 "osp_sync test"
13318
13319 test_239a() { #LU-5297
13320         touch $DIR/$tfile
13321         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
13322         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
13323         chgrp $RUNAS_GID $DIR/$tfile
13324         wait_delete_completed
13325 }
13326 run_test 239a "process invalid osp sync record correctly"
13327
13328 test_239b() { #LU-5297
13329         touch $DIR/$tfile1
13330         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
13331         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
13332         chgrp $RUNAS_GID $DIR/$tfile1
13333         wait_delete_completed
13334         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
13335         touch $DIR/$tfile2
13336         chgrp $RUNAS_GID $DIR/$tfile2
13337         wait_delete_completed
13338 }
13339 run_test 239b "process osp sync record with ENOMEM error correctly"
13340
13341 test_240() {
13342         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13343
13344         mkdir -p $DIR/$tdir
13345
13346         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
13347                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
13348         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
13349                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
13350
13351         umount_client $MOUNT || error "umount failed"
13352         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
13353         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
13354         mount_client $MOUNT || error "failed to mount client"
13355
13356         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
13357         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
13358 }
13359 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
13360
13361 test_241_bio() {
13362         for LOOP in $(seq $1); do
13363                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
13364                 cancel_lru_locks osc || true
13365         done
13366 }
13367
13368 test_241_dio() {
13369         for LOOP in $(seq $1); do
13370                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
13371                                                 iflag=direct 2>/dev/null
13372         done
13373 }
13374
13375 test_241() {
13376         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
13377         ls -la $DIR/$tfile
13378         cancel_lru_locks osc
13379         test_241_bio 1000 &
13380         PID=$!
13381         test_241_dio 1000
13382         wait $PID
13383 }
13384 run_test 241 "bio vs dio"
13385
13386 test_241b() {
13387         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
13388         ls -la $DIR/$tfile
13389         test_241_dio 1000 &
13390         PID=$!
13391         test_241_dio 1000
13392         wait $PID
13393 }
13394 run_test 241b "dio vs dio"
13395
13396 test_242() {
13397         mkdir -p $DIR/$tdir
13398         touch $DIR/$tdir/$tfile
13399
13400         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
13401         do_facet mds1 lctl set_param fail_loc=0x105
13402         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
13403
13404         do_facet mds1 lctl set_param fail_loc=0
13405         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
13406 }
13407 run_test 242 "mdt_readpage failure should not cause directory unreadable"
13408
13409 test_243()
13410 {
13411         test_mkdir -p $DIR/$tdir
13412         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
13413 }
13414 run_test 243 "various group lock tests"
13415
13416 test_244()
13417 {
13418         test_mkdir -p $DIR/$tdir
13419         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
13420         sendfile_grouplock $DIR/$tdir/$tfile || \
13421                 error "sendfile+grouplock failed"
13422         rm -rf $DIR/$tdir
13423 }
13424 run_test 244 "sendfile with group lock tests"
13425
13426 test_245() {
13427         local flagname="multi_mod_rpcs"
13428         local connect_data_name="max_mod_rpcs"
13429         local out
13430
13431         # check if multiple modify RPCs flag is set
13432         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
13433                 grep "connect_flags:")
13434         echo "$out"
13435
13436         echo "$out" | grep -qw $flagname
13437         if [ $? -ne 0 ]; then
13438                 echo "connect flag $flagname is not set"
13439                 return
13440         fi
13441
13442         # check if multiple modify RPCs data is set
13443         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
13444         echo "$out"
13445
13446         echo "$out" | grep -qw $connect_data_name ||
13447                 error "import should have connect data $connect_data_name"
13448 }
13449 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
13450
13451 test_246() { # LU-7371
13452         [ $(lustre_version_code ost1) -lt $(version_code 2.7.62) ] &&
13453                 skip "Need OST version >= 2.7.62" && return 0
13454         do_facet ost1 $LCTL set_param fail_val=4095
13455 #define OBD_FAIL_OST_READ_SIZE          0x234
13456         do_facet ost1 $LCTL set_param fail_loc=0x234
13457         $LFS setstripe $DIR/$tfile -i 0 -c 1
13458         dd if=/dev/zero of=$DIR/$tfile bs=4095 count=1 > /dev/null 2>&1
13459         cancel_lru_locks $FSNAME-OST0000
13460         dd if=$DIR/$tfile of=/dev/null bs=1048576 || error "Read failed"
13461 }
13462 run_test 246 "Read file of size 4095 should return right length"
13463
13464 test_250() {
13465         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
13466          && skip "no 16TB file size limit on ZFS" && return
13467
13468         $SETSTRIPE -c 1 $DIR/$tfile
13469         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
13470         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
13471         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
13472         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
13473                 conv=notrunc,fsync && error "append succeeded"
13474         return 0
13475 }
13476 run_test 250 "Write above 16T limit"
13477
13478 test_251() {
13479         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
13480
13481         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
13482         #Skip once - writing the first stripe will succeed
13483         $LCTL set_param fail_loc=0xa0001407 fail_val=1
13484         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
13485                 error "short write happened"
13486
13487         $LCTL set_param fail_loc=0xa0001407 fail_val=1
13488         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
13489                 error "short read happened"
13490
13491         rm -f $DIR/$tfile
13492 }
13493 run_test 251 "Handling short read and write correctly"
13494
13495 test_252() {
13496         local tgt
13497         local dev
13498         local out
13499         local uuid
13500         local num
13501         local gen
13502
13503         if [ "$(facet_fstype ost1)" != "ldiskfs" -o \
13504              "$(facet_fstype mds1)" != "ldiskfs" ]; then
13505                 skip "can only run lr_reader on ldiskfs target"
13506                 return
13507         fi
13508
13509         # check lr_reader on OST0000
13510         tgt=ost1
13511         dev=$(facet_device $tgt)
13512         out=$(do_facet $tgt $LR_READER $dev)
13513         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
13514         echo "$out"
13515         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
13516         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
13517                 error "Invalid uuid returned by $LR_READER on target $tgt"
13518         echo -e "uuid returned by $LR_READER is '$uuid'\n"
13519
13520         # check lr_reader -c on MDT0000
13521         tgt=mds1
13522         dev=$(facet_device $tgt)
13523         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
13524                 echo "$LR_READER does not support additional options"
13525                 return 0
13526         fi
13527         out=$(do_facet $tgt $LR_READER -c $dev)
13528         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
13529         echo "$out"
13530         num=$(echo "$out" | grep -c "mdtlov")
13531         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
13532                 error "Invalid number of mdtlov clients returned by $LR_READER"
13533         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
13534
13535         # check lr_reader -cr on MDT0000
13536         out=$(do_facet $tgt $LR_READER -cr $dev)
13537         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
13538         echo "$out"
13539         echo "$out" | grep -q "^reply_data:$" ||
13540                 error "$LR_READER should have returned 'reply_data' section"
13541         num=$(echo "$out" | grep -c "client_generation")
13542         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
13543 }
13544 run_test 252 "check lr_reader tool"
13545
13546
13547 cleanup_test_300() {
13548         trap 0
13549         umask $SAVE_UMASK
13550 }
13551 test_striped_dir() {
13552         local mdt_index=$1
13553         local stripe_count
13554         local stripe_index
13555
13556         mkdir -p $DIR/$tdir
13557
13558         SAVE_UMASK=$(umask)
13559         trap cleanup_test_300 RETURN EXIT
13560
13561         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
13562                                                 $DIR/$tdir/striped_dir ||
13563                 error "set striped dir error"
13564
13565         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
13566         [ "$mode" = "755" ] || error "expect 755 got $mode"
13567
13568         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
13569                 error "getdirstripe failed"
13570         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
13571         if [ "$stripe_count" != "2" ]; then
13572                 error "stripe_count is $stripe_count, expect 2"
13573         fi
13574
13575         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
13576         if [ "$stripe_index" != "$mdt_index" ]; then
13577                 error "stripe_index is $stripe_index, expect $mdt_index"
13578         fi
13579
13580         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13581                 error "nlink error after create striped dir"
13582
13583         mkdir $DIR/$tdir/striped_dir/a
13584         mkdir $DIR/$tdir/striped_dir/b
13585
13586         stat $DIR/$tdir/striped_dir/a ||
13587                 error "create dir under striped dir failed"
13588         stat $DIR/$tdir/striped_dir/b ||
13589                 error "create dir under striped dir failed"
13590
13591         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
13592                 error "nlink error after mkdir"
13593
13594         rmdir $DIR/$tdir/striped_dir/a
13595         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
13596                 error "nlink error after rmdir"
13597
13598         rmdir $DIR/$tdir/striped_dir/b
13599         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13600                 error "nlink error after rmdir"
13601
13602         chattr +i $DIR/$tdir/striped_dir
13603         createmany -o $DIR/$tdir/striped_dir/f 10 &&
13604                 error "immutable flags not working under striped dir!"
13605         chattr -i $DIR/$tdir/striped_dir
13606
13607         rmdir $DIR/$tdir/striped_dir ||
13608                 error "rmdir striped dir error"
13609
13610         cleanup_test_300
13611
13612         true
13613 }
13614
13615 test_300a() {
13616         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13617         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13618
13619         test_striped_dir 0 || error "failed on striped dir on MDT0"
13620         test_striped_dir 1 || error "failed on striped dir on MDT0"
13621 }
13622 run_test 300a "basic striped dir sanity test"
13623
13624 test_300b() {
13625         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13626         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13627         local i
13628         local mtime1
13629         local mtime2
13630         local mtime3
13631
13632         test_mkdir $DIR/$tdir || error "mkdir fail"
13633         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13634                 error "set striped dir error"
13635         for ((i=0; i<10; i++)); do
13636                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
13637                 sleep 1
13638                 touch $DIR/$tdir/striped_dir/file_$i ||
13639                                         error "touch error $i"
13640                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
13641                 [ $mtime1 -eq $mtime2 ] &&
13642                         error "mtime not change after create"
13643                 sleep 1
13644                 rm -f $DIR/$tdir/striped_dir/file_$i ||
13645                                         error "unlink error $i"
13646                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
13647                 [ $mtime2 -eq $mtime3 ] &&
13648                         error "mtime did not change after unlink"
13649         done
13650         true
13651 }
13652 run_test 300b "check ctime/mtime for striped dir"
13653
13654 test_300c() {
13655         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13656         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13657         local file_count
13658
13659         mkdir -p $DIR/$tdir
13660         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
13661                 error "set striped dir error"
13662
13663         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
13664                 error "chown striped dir failed"
13665
13666         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
13667                 error "create 5k files failed"
13668
13669         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
13670
13671         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
13672
13673         rm -rf $DIR/$tdir
13674 }
13675 run_test 300c "chown && check ls under striped directory"
13676
13677 test_300d() {
13678         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13679         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13680         local stripe_count
13681         local file
13682
13683         mkdir -p $DIR/$tdir
13684         $SETSTRIPE -c 2 $DIR/$tdir
13685
13686         #local striped directory
13687         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13688                 error "set striped dir error"
13689         createmany -o $DIR/$tdir/striped_dir/f 10 ||
13690                 error "create 10 files failed"
13691
13692         #remote striped directory
13693         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
13694                 error "set striped dir error"
13695         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
13696                 error "create 10 files failed"
13697
13698         for file in $(find $DIR/$tdir); do
13699                 stripe_count=$($GETSTRIPE -c $file)
13700                 [ $stripe_count -eq 2 ] ||
13701                         error "wrong stripe $stripe_count for $file"
13702         done
13703
13704         rm -rf $DIR/$tdir
13705 }
13706 run_test 300d "check default stripe under striped directory"
13707
13708 test_300e() {
13709         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13710                 skip "Need MDS version at least 2.7.55" && return
13711         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13712         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13713         local stripe_count
13714         local file
13715
13716         mkdir -p $DIR/$tdir
13717
13718         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13719                 error "set striped dir error"
13720
13721         touch $DIR/$tdir/striped_dir/a
13722         touch $DIR/$tdir/striped_dir/b
13723         touch $DIR/$tdir/striped_dir/c
13724
13725         mkdir $DIR/$tdir/striped_dir/dir_a
13726         mkdir $DIR/$tdir/striped_dir/dir_b
13727         mkdir $DIR/$tdir/striped_dir/dir_c
13728
13729         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
13730                 error "set striped dir under striped dir error"
13731
13732         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
13733                 error "set striped dir under striped dir error"
13734
13735         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
13736                 error "set striped dir under striped dir error"
13737
13738         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
13739                 error "rename dir under striped dir fails"
13740
13741         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
13742                 error "rename dir under different stripes fails"
13743
13744         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
13745                 error "rename file under striped dir should succeed"
13746
13747         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
13748                 error "rename dir under striped dir should succeed"
13749
13750         rm -rf $DIR/$tdir
13751 }
13752 run_test 300e "check rename under striped directory"
13753
13754 test_300f() {
13755         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13756                 skip "Need MDS version at least 2.7.55" && return
13757         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13758         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13759         local stripe_count
13760         local file
13761
13762         rm -rf $DIR/$tdir
13763         mkdir -p $DIR/$tdir
13764
13765         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13766                 error "set striped dir error"
13767
13768         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
13769                 error "set striped dir error"
13770
13771         touch $DIR/$tdir/striped_dir/a
13772         mkdir $DIR/$tdir/striped_dir/dir_a
13773         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
13774                 error "create striped dir under striped dir fails"
13775
13776         touch $DIR/$tdir/striped_dir1/b
13777         mkdir $DIR/$tdir/striped_dir1/dir_b
13778         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
13779                 error "create striped dir under striped dir fails"
13780
13781         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
13782                 error "rename dir under different striped dir should fail"
13783
13784         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
13785                 error "rename striped dir under diff striped dir should fail"
13786
13787         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
13788                 error "rename file under diff striped dirs fails"
13789
13790         rm -rf $DIR/$tdir
13791 }
13792 run_test 300f "check rename cross striped directory"
13793
13794 test_300_check_default_striped_dir()
13795 {
13796         local dirname=$1
13797         local default_count=$2
13798         local default_index=$3
13799         local stripe_count
13800         local stripe_index
13801         local dir_stripe_index
13802         local dir
13803
13804         echo "checking $dirname $default_count $default_index"
13805         $LFS setdirstripe -D -c $default_count -i $default_index \
13806                                 -t all_char $DIR/$tdir/$dirname ||
13807                 error "set default stripe on striped dir error"
13808         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
13809         [ $stripe_count -eq $default_count ] ||
13810                 error "expect $default_count get $stripe_count for $dirname"
13811
13812         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
13813         [ $stripe_index -eq $default_index ] ||
13814                 error "expect $default_index get $stripe_index for $dirname"
13815
13816         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
13817                                                 error "create dirs failed"
13818
13819         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
13820         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
13821         for dir in $(find $DIR/$tdir/$dirname/*); do
13822                 stripe_count=$($LFS getdirstripe -c $dir)
13823                 [ $stripe_count -eq $default_count ] ||
13824                 [ $stripe_count -eq 0 -o $default_count -eq 1 ] ||
13825                 error "stripe count $default_count != $stripe_count for $dir"
13826
13827                 stripe_index=$($LFS getdirstripe -i $dir)
13828                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
13829                         error "$stripe_index != $default_index for $dir"
13830
13831                 #check default stripe
13832                 stripe_count=$($LFS getdirstripe -D -c $dir)
13833                 [ $stripe_count -eq $default_count ] ||
13834                 error "default count $default_count != $stripe_count for $dir"
13835
13836                 stripe_index=$($LFS getdirstripe -D -i $dir)
13837                 [ $stripe_index -eq $default_index ] ||
13838                 error "default index $default_index != $stripe_index for $dir"
13839         done
13840         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
13841 }
13842
13843 test_300g() {
13844         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13845                 skip "Need MDS version at least 2.7.55" && return
13846         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13847         local dir
13848         local stripe_count
13849         local stripe_index
13850
13851         mkdir $DIR/$tdir
13852         mkdir $DIR/$tdir/normal_dir
13853
13854         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
13855         test_300_check_default_striped_dir normal_dir 1 0
13856         test_300_check_default_striped_dir normal_dir 2 1
13857         test_300_check_default_striped_dir normal_dir 2 -1
13858
13859         #delete default stripe information
13860         echo "delete default stripeEA"
13861         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
13862                 error "set default stripe on striped dir error"
13863
13864         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
13865         for dir in $(find $DIR/$tdir/normal_dir/*); do
13866                 stripe_count=$($LFS getdirstripe -c $dir)
13867                 [ $stripe_count -eq 0 ] ||
13868                         error "expect 1 get $stripe_count for $dir"
13869                 stripe_index=$($LFS getdirstripe -i $dir)
13870                 [ $stripe_index -eq 0 ] ||
13871                         error "expect 0 get $stripe_index for $dir"
13872         done
13873 }
13874 run_test 300g "check default striped directory for normal directory"
13875
13876 test_300h() {
13877         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13878                 skip "Need MDS version at least 2.7.55" && return
13879         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13880         local dir
13881         local stripe_count
13882
13883         mkdir $DIR/$tdir
13884         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
13885                                         $DIR/$tdir/striped_dir ||
13886                 error "set striped dir error"
13887
13888         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
13889         test_300_check_default_striped_dir striped_dir 1 0
13890         test_300_check_default_striped_dir striped_dir 2 1
13891         test_300_check_default_striped_dir striped_dir 2 -1
13892
13893         #delete default stripe information
13894         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
13895                 error "set default stripe on striped dir error"
13896
13897         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
13898         for dir in $(find $DIR/$tdir/striped_dir/*); do
13899                 stripe_count=$($LFS getdirstripe -c $dir)
13900                 [ $stripe_count -eq 0 ] ||
13901                         error "expect 1 get $stripe_count for $dir"
13902         done
13903 }
13904 run_test 300h "check default striped directory for striped directory"
13905
13906 test_300i() {
13907         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13908                 skip "Need MDS version at least 2.7.55" && return
13909         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13910         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13911         local stripe_count
13912         local file
13913
13914         mkdir $DIR/$tdir
13915
13916         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
13917                 error "set striped dir error"
13918
13919         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
13920                 error "create files under striped dir failed"
13921
13922         # unfortunately, we need to umount to clear dir layout cache for now
13923         # once we fully implement dir layout, we can drop this
13924         umount_client $MOUNT || error "umount failed"
13925         mount_client $MOUNT || error "mount failed"
13926
13927         #set the stripe to be unknown hash type
13928         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
13929         $LCTL set_param fail_loc=0x1901
13930         for ((i = 0; i < 10; i++)); do
13931                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
13932                         error "stat f-$i failed"
13933                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
13934         done
13935
13936         touch $DIR/$tdir/striped_dir/f0 &&
13937                 error "create under striped dir with unknown hash should fail"
13938
13939         $LCTL set_param fail_loc=0
13940
13941         umount_client $MOUNT || error "umount failed"
13942         mount_client $MOUNT || error "mount failed"
13943
13944         return 0
13945 }
13946 run_test 300i "client handle unknown hash type striped directory"
13947
13948 test_300j() {
13949         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13950         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13951                 skip "Need MDS version at least 2.7.55" && return
13952         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13953         local stripe_count
13954         local file
13955
13956         mkdir $DIR/$tdir
13957
13958         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
13959         $LCTL set_param fail_loc=0x1702
13960         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
13961                 error "set striped dir error"
13962
13963         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
13964                 error "create files under striped dir failed"
13965
13966         $LCTL set_param fail_loc=0
13967
13968         rm -rf $DIR/$tdir || error "unlink striped dir fails"
13969
13970         return 0
13971 }
13972 run_test 300j "test large update record"
13973
13974 test_300k() {
13975         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13976                 skip "Need MDS version at least 2.7.55" && return
13977         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13978         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13979         local stripe_count
13980         local file
13981
13982         mkdir $DIR/$tdir
13983
13984         #define OBD_FAIL_LARGE_STRIPE   0x1703
13985         $LCTL set_param fail_loc=0x1703
13986         $LFS setdirstripe -i 0 -c512 $DIR/$tdir/striped_dir ||
13987                 error "set striped dir error"
13988         $LCTL set_param fail_loc=0
13989
13990         $LFS getdirstripe $DIR/$tdir/striped_dir ||
13991                 error "getstripeddir fails"
13992         rm -rf $DIR/$tdir/striped_dir ||
13993                 error "unlink striped dir fails"
13994
13995         return 0
13996 }
13997 run_test 300k "test large striped directory"
13998
13999 test_300l() {
14000         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14001                 skip "Need MDS version at least 2.7.55" && return
14002         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14003         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14004         local stripe_index
14005
14006         test_mkdir -p $DIR/$tdir/striped_dir
14007         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
14008                         error "chown $RUNAS_ID failed"
14009         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
14010                 error "set default striped dir failed"
14011
14012         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
14013         $LCTL set_param fail_loc=0x80000158
14014         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
14015
14016         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
14017         [ $stripe_index -eq 1 ] ||
14018                 error "expect 1 get $stripe_index for $dir"
14019 }
14020 run_test 300l "non-root user to create dir under striped dir with stale layout"
14021
14022 test_300m() {
14023         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14024                 skip "Need MDS version at least 2.7.55" && return
14025         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14026         [ $MDSCOUNT -ge 2 ] && skip "Only for single MDT" && return
14027
14028         mkdir -p $DIR/$tdir/striped_dir
14029         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
14030                 error "set default stripes dir error"
14031
14032         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
14033
14034         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
14035         [ $stripe_count -eq 0 ] ||
14036                         error "expect 0 get $stripe_count for a"
14037
14038         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
14039                 error "set default stripes dir error"
14040
14041         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
14042
14043         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
14044         [ $stripe_count -eq 0 ] ||
14045                         error "expect 0 get $stripe_count for b"
14046
14047         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
14048                 error "set default stripes dir error"
14049
14050         mkdir $DIR/$tdir/striped_dir/c &&
14051                 error "default stripe_index is invalid, mkdir c should fails"
14052
14053         rm -rf $DIR/$tdir || error "rmdir fails"
14054 }
14055 run_test 300m "setstriped directory on single MDT FS"
14056
14057 cleanup_300n() {
14058         local list=$(comma_list $(mdts_nodes))
14059
14060         trap 0
14061         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
14062 }
14063
14064 test_300n() {
14065         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14066                 skip "Need MDS version at least 2.7.55" && return
14067         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14068         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14069         local stripe_index
14070         local list=$(comma_list $(mdts_nodes))
14071
14072         trap cleanup_300n RETURN EXIT
14073         mkdir -p $DIR/$tdir
14074         chmod 777 $DIR/$tdir
14075         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
14076                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
14077                 error "create striped dir succeeds with gid=0"
14078
14079         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
14080         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
14081                 error "create striped dir fails with gid=-1"
14082
14083         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
14084         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
14085                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
14086                 error "set default striped dir succeeds with gid=0"
14087
14088
14089         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
14090         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
14091                 error "set default striped dir fails with gid=-1"
14092
14093
14094         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
14095         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
14096                                         error "create test_dir fails"
14097         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
14098                                         error "create test_dir1 fails"
14099         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
14100                                         error "create test_dir2 fails"
14101         cleanup_300n
14102 }
14103 run_test 300n "non-root user to create dir under striped dir with default EA"
14104
14105 test_300o() {
14106         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14107                 skip "Need MDS version at least 2.7.55" && return
14108         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14109         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14110         local numfree1
14111         local numfree2
14112
14113         mkdir -p $DIR/$tdir
14114
14115         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
14116         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
14117         if [ $numfree1 -lt 66000 -o $numfree2 -lt 66000 ]; then
14118                 skip "not enough free inodes $numfree1 $numfree2"
14119                 return
14120         fi
14121
14122         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
14123         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
14124         if [ $numfree1 -lt 300000 -o $numfree2 -lt 300000 ]; then
14125                 skip "not enough free space $numfree1 $numfree2"
14126                 return
14127         fi
14128
14129         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
14130                 error "setdirstripe fails"
14131
14132         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
14133                 error "create dirs fails"
14134
14135         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
14136         ls $DIR/$tdir/striped_dir > /dev/null ||
14137                 error "ls striped dir fails"
14138         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
14139                 error "unlink big striped dir fails"
14140 }
14141 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
14142
14143 test_300p() {
14144         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14145         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14146
14147         mkdir -p $DIR/$tdir
14148
14149         #define OBD_FAIL_OUT_ENOSPC     0x1704
14150         do_facet mds2 lctl set_param fail_loc=0x80001704
14151         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 &&
14152                         error "create striped directory should fail"
14153
14154         [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
14155
14156         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir
14157         true
14158 }
14159 run_test 300p "create striped directory without space"
14160
14161 prepare_remote_file() {
14162         mkdir $DIR/$tdir/src_dir ||
14163                 error "create remote source failed"
14164
14165         cp /etc/hosts $DIR/$tdir/src_dir/a || error
14166         touch $DIR/$tdir/src_dir/a
14167
14168         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
14169                 error "create remote target dir failed"
14170
14171         touch $DIR/$tdir/tgt_dir/b
14172
14173         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
14174                 error "rename dir cross MDT failed!"
14175
14176         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
14177                 error "src_child still exists after rename"
14178
14179         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
14180                 error "missing file(a) after rename"
14181
14182         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
14183                 error "diff after rename"
14184 }
14185
14186 test_310a() {
14187         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
14188         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14189         local remote_file=$DIR/$tdir/tgt_dir/b
14190
14191         mkdir -p $DIR/$tdir
14192
14193         prepare_remote_file || error "prepare remote file failed"
14194
14195         #open-unlink file
14196         $OPENUNLINK $remote_file $remote_file || error
14197         $CHECKSTAT -a $remote_file || error
14198 }
14199 run_test 310a "open unlink remote file"
14200
14201 test_310b() {
14202         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
14203         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14204         local remote_file=$DIR/$tdir/tgt_dir/b
14205
14206         mkdir -p $DIR/$tdir
14207
14208         prepare_remote_file || error "prepare remote file failed"
14209
14210         ln $remote_file $DIR/$tfile || error "link failed for remote file"
14211         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
14212         $CHECKSTAT -t file $remote_file || error "check file failed"
14213 }
14214 run_test 310b "unlink remote file with multiple links while open"
14215
14216 test_310c() {
14217         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
14218         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14219         local remote_file=$DIR/$tdir/tgt_dir/b
14220
14221         mkdir -p $DIR/$tdir
14222
14223         prepare_remote_file || error "prepare remote file failed"
14224
14225         ln $remote_file $DIR/$tfile || error "link failed for remote file"
14226         multiop_bg_pause $remote_file O_uc ||
14227                         error "mulitop failed for remote file"
14228         MULTIPID=$!
14229         $MULTIOP $DIR/$tfile Ouc
14230         kill -USR1 $MULTIPID
14231         wait $MULTIPID
14232 }
14233 run_test 310c "open-unlink remote file with multiple links"
14234
14235 test_400a() { # LU-1606, was conf-sanity test_74
14236         local extra_flags=''
14237         local out=$TMP/$tfile
14238         local prefix=/usr/include/lustre
14239         local prog
14240
14241         if ! which $CC > /dev/null 2>&1; then
14242                 skip_env "$CC is not installed"
14243                 return 0
14244         fi
14245
14246         if ! [[ -d $prefix ]]; then
14247                 # Assume we're running in tree and fixup the include path.
14248                 extra_flags+=" -I$LUSTRE/../libcfs/include"
14249                 extra_flags+=" -I$LUSTRE/include"
14250                 extra_flags+=" -L$LUSTRE/utils"
14251         fi
14252
14253         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
14254                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
14255                         error "client api broken"
14256         done
14257 }
14258 run_test 400a "Lustre client api program can compile and link"
14259
14260 test_400b() { # LU-1606, LU-5011
14261         local header
14262         local out=$TMP/$tfile
14263         local prefix=/usr/include/lustre
14264
14265         # We use a hard coded prefix so that this test will not fail
14266         # when run in tree. There are headers in lustre/include/lustre/
14267         # that are not packaged (like lustre_idl.h) and have more
14268         # complicated include dependencies (like config.h and lnet/types.h).
14269         # Since this test about correct packaging we just skip them when
14270         # they don't exist (see below) rather than try to fixup cppflags.
14271
14272         if ! which $CC > /dev/null 2>&1; then
14273                 skip_env "$CC is not installed"
14274                 return 0
14275         fi
14276
14277         for header in $prefix/*.h; do
14278                 if ! [[ -f "$header" ]]; then
14279                         continue
14280                 fi
14281
14282                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
14283                         continue # liblustreapi.h is deprecated.
14284                 fi
14285
14286                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
14287                         error "cannot compile '$header'"
14288         done
14289 }
14290 run_test 400b "packaged headers can be compiled"
14291
14292 test_401() { #LU-7437
14293         #count the number of parameters by "list_param -R"
14294         local params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
14295         #count the number of parameters by listing proc files
14296         local procs=$(find -L $proc_dirs -mindepth 1 2>/dev/null | wc -l)
14297
14298         [ $params -eq $procs ] ||
14299                 error "found $params parameters vs. $procs proc files"
14300 }
14301 run_test 401 "Verify if 'lctl list_param -R' can list parameters recursively"
14302
14303 test_402() {
14304         $LFS setdirstripe -i 0 $DIR/$tdir || error "setdirstripe -i 0 failed"
14305 #define OBD_FAIL_MDS_FLD_LOOKUP 0x15c
14306         do_facet mds1 "lctl set_param fail_loc=0x8000015c"
14307         touch $DIR/$tdir/$tfile && error "touch should fail with ENOENT" ||
14308                 echo "Touch failed - OK"
14309 }
14310 run_test 402 "Return ENOENT to lod_generate_and_set_lovea"
14311
14312 #
14313 # tests that do cleanup/setup should be run at the end
14314 #
14315
14316 test_900() {
14317         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14318         local ls
14319         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
14320         $LCTL set_param fail_loc=0x903
14321
14322         cancel_lru_locks MGC
14323
14324         FAIL_ON_ERROR=true cleanup
14325         FAIL_ON_ERROR=true setup
14326 }
14327 run_test 900 "umount should not race with any mgc requeue thread"
14328
14329 complete $SECONDS
14330 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
14331 check_and_cleanup_lustre
14332 if [ "$I_MOUNTED" != "yes" ]; then
14333         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
14334 fi
14335 exit_status