Whamcloud - gitweb
144e5e73556467c930810de3dd8aa30f12d646c4
[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-4351
20 {
21         if [ -r /etc/SuSE-release ]
22         then
23                 local vers=`grep VERSION /etc/SuSE-release | awk '{print $3}'`
24                 if [ $vers -eq 11 ]
25                 then
26                         return 0
27                 fi
28         fi
29         return 1
30 }
31
32 if is_sles11; then                                      # LU-4351
33         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 54c"
34 fi
35
36 SRCDIR=$(cd $(dirname $0); echo $PWD)
37 export PATH=$PATH:/sbin
38
39 TMP=${TMP:-/tmp}
40
41 CC=${CC:-cc}
42 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
43 CREATETEST=${CREATETEST:-createtest}
44 LFS=${LFS:-lfs}
45 LFIND=${LFIND:-"$LFS find"}
46 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
47 LCTL=${LCTL:-lctl}
48 MCREATE=${MCREATE:-mcreate}
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 UMOUNT=${UMOUNT:-"umount -d"}
60 STRIPES_PER_OBJ=-1
61 CHECK_GRANT=${CHECK_GRANT:-"yes"}
62 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
63 export PARALLEL=${PARALLEL:-"no"}
64
65 export NAME=${NAME:-local}
66
67 SAVE_PWD=$PWD
68
69 CLEANUP=${CLEANUP:-:}
70 SETUP=${SETUP:-:}
71 TRACE=${TRACE:-""}
72 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
73 LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
74 . $LUSTRE/tests/test-framework.sh
75 init_test_env $@
76 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
77 init_logging
78
79 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 27m 64b 68 71 77f 78 115 124b 230d"
80
81 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
82 # bug number for skipped test:        LU-1593 LU-2610 LU-2833 LU-1957 LU-2805
83         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 34h     40      48a     180     184c"
84
85 FAIL_ON_ERROR=false
86
87 cleanup() {
88         echo -n "cln.."
89         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
90         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
91 }
92 setup() {
93         echo -n "mnt.."
94         load_modules
95         setupall || exit 10
96         echo "done"
97 }
98
99 check_kernel_version() {
100         WANT_VER=$1
101         GOT_VER=$(lctl get_param -n version | awk '/kernel:/ {print $2}')
102         case $GOT_VER in
103         patchless|patchless_client) return 0;;
104         *) [ $GOT_VER -ge $WANT_VER ] && return 0 ;;
105         esac
106         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
107         return 1
108 }
109
110 check_swap_layouts_support()
111 {
112         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
113                 { skip "Does not support layout lock."; return 0; }
114         return 1
115 }
116
117 if [ "$ONLY" == "cleanup" ]; then
118        sh llmountcleanup.sh
119        exit 0
120 fi
121
122 check_and_setup_lustre
123
124 DIR=${DIR:-$MOUNT}
125 assert_DIR
126
127 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
128         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
129 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
130 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
131 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
132 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
133 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
134 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
135
136 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
137 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
138 rm -rf $DIR/[Rdfs][0-9]*
139
140 # $RUNAS_ID may get set incorrectly somewhere else
141 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
142
143 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
144
145 build_test_filter
146
147 if [ "${ONLY}" = "MOUNT" ] ; then
148         echo "Lustre is up, please go on"
149         exit
150 fi
151
152 echo "preparing for tests involving mounts"
153 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
154 touch $EXT2_DEV
155 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
156 echo # add a newline after mke2fs.
157
158 umask 077
159
160 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
161 lctl set_param debug=-1 2> /dev/null || true
162 test_0a() {
163         touch $DIR/$tfile
164         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
165         rm $DIR/$tfile
166         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
167 }
168 run_test 0a "touch; rm ====================="
169
170 test_0b() {
171         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
172         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
173 }
174 run_test 0b "chmod 0755 $DIR ============================="
175
176 test_0c() {
177         $LCTL get_param mdc.*.import | grep "state: FULL" ||
178                 error "import not FULL"
179         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
180                 error "bad target"
181 }
182 run_test 0c "check import proc ============================="
183
184 test_1() {
185         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
186         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
187         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
188         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
189         rmdir $DIR/$tdir/d2
190         rmdir $DIR/$tdir
191         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
192 }
193 run_test 1 "mkdir; remkdir; rmdir =============================="
194
195 test_2() {
196         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
197         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
198         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
199         rm -r $DIR/$tdir
200         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
201 }
202 run_test 2 "mkdir; touch; rmdir; check file ===================="
203
204 test_3() {
205         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
206         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
207         touch $DIR/$tdir/$tfile
208         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
209         rm -r $DIR/$tdir
210         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
211 }
212 run_test 3 "mkdir; touch; rmdir; check dir ====================="
213
214 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
215 test_4() {
216         local MDTIDX=1
217         local remote_dir=remote_dir
218
219         test_mkdir $DIR/$remote_dir ||
220                 error "Create remote directory failed"
221
222         touch $DIR/$remote_dir/$tfile ||
223                 error "Create file under remote directory failed"
224
225         rmdir $DIR/$remote_dir &&
226                 error "Expect error removing in-use dir $DIR/$remote_dir"
227
228         test -d $DIR/$remote_dir || error "Remote directory disappeared"
229
230         rm -rf $DIR/$remote_dir || error "remove remote dir error"
231 }
232 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
233
234 test_5() {
235         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
236         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
237         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
238         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
239         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
240 }
241 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
242
243 test_6a() {
244         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
245         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
246         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
247                 error "$tfile does not have perm 0666 or UID $UID"
248         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
249         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
250                 error "$tfile should be 0666 and owned by UID $UID"
251 }
252 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
253
254 test_6c() {
255         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
256         touch $DIR/$tfile
257         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
258         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
259                 error "$tfile should be owned by UID $RUNAS_ID"
260         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
261         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
262                 error "$tfile should be owned by UID $RUNAS_ID"
263 }
264 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
265
266 test_6e() {
267         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
268         touch $DIR/$tfile
269         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
270         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
271                 error "$tfile should be owned by GID $UID"
272         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
273         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
274                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
275 }
276 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
277
278 test_6g() {
279         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
280         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
281         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
282         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
283         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
284         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
285         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
286                 error "$tdir/d/subdir should be GID $RUNAS_GID"
287 }
288 run_test 6g "Is new dir in sgid dir inheriting group?"
289
290 test_6h() { # bug 7331
291         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
292         touch $DIR/$tfile || error "touch failed"
293         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
294         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
295                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
296         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
297                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
298 }
299 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
300
301 test_7a() {
302         test_mkdir $DIR/$tdir
303         $MCREATE $DIR/$tdir/$tfile
304         chmod 0666 $DIR/$tdir/$tfile
305         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
306                 error "$tdir/$tfile should be mode 0666"
307 }
308 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
309
310 test_7b() {
311         if [ ! -d $DIR/$tdir ]; then
312                 mkdir $DIR/$tdir
313         fi
314         $MCREATE $DIR/$tdir/$tfile
315         echo -n foo > $DIR/$tdir/$tfile
316         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
317         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
318 }
319 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
320
321 test_8() {
322         test_mkdir $DIR/$tdir
323         touch $DIR/$tdir/$tfile
324         chmod 0666 $DIR/$tdir/$tfile
325         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
326                 error "$tfile mode not 0666"
327 }
328 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
329
330 test_9() {
331         test_mkdir $DIR/$tdir
332         test_mkdir $DIR/$tdir/d2
333         test_mkdir $DIR/$tdir/d2/d3
334         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
335 }
336 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
337
338 test_10() {
339         test_mkdir $DIR/$tdir
340         test_mkdir $DIR/$tdir/d2
341         touch $DIR/$tdir/d2/$tfile
342         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
343                 error "$tdir/d2/$tfile not a file"
344 }
345 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
346
347 test_11() {
348         test_mkdir $DIR/$tdir
349         test_mkdir $DIR/$tdir/d2
350         chmod 0666 $DIR/$tdir/d2
351         chmod 0705 $DIR/$tdir/d2
352         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
353                 error "$tdir/d2 mode not 0705"
354 }
355 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
356
357 test_12() {
358         test_mkdir $DIR/$tdir
359         touch $DIR/$tdir/$tfile
360         chmod 0666 $DIR/$tdir/$tfile
361         chmod 0654 $DIR/$tdir/$tfile
362         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
363                 error "$tdir/d2 mode not 0654"
364 }
365 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
366
367 test_13() {
368         test_mkdir $DIR/$tdir
369         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
370         >  $DIR/$tdir/$tfile
371         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
372                 error "$tdir/$tfile size not 0 after truncate"
373 }
374 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
375
376 test_14() {
377         test_mkdir $DIR/$tdir
378         touch $DIR/$tdir/$tfile
379         rm $DIR/$tdir/$tfile
380         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
381 }
382 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
383
384 test_15() {
385         test_mkdir $DIR/$tdir
386         touch $DIR/$tdir/$tfile
387         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
388         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
389                 error "$tdir/${tfile_2} not a file after rename"
390 }
391 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
392
393 test_16() {
394         test_mkdir $DIR/$tdir
395         touch $DIR/$tdir/$tfile
396         rm -rf $DIR/$tdir/$tfile
397         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
398 }
399 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
400
401 test_17a() {
402         test_mkdir -p $DIR/$tdir
403         touch $DIR/$tdir/$tfile
404         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
405         ls -l $DIR/$tdir
406         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
407                 error "$tdir/l-exist not a symlink"
408         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
409                 error "$tdir/l-exist not referencing a file"
410         rm -f $DIR/$tdir/l-exist
411         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
412 }
413 run_test 17a "symlinks: create, remove (real) =================="
414
415 test_17b() {
416         test_mkdir -p $DIR/$tdir
417         ln -s no-such-file $DIR/$tdir/l-dangle
418         ls -l $DIR/$tdir
419         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
420                 error "$tdir/l-dangle not referencing no-such-file"
421         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
422                 error "$tdir/l-dangle not referencing non-existent file"
423         rm -f $DIR/$tdir/l-dangle
424         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
425 }
426 run_test 17b "symlinks: create, remove (dangling) =============="
427
428 test_17c() { # bug 3440 - don't save failed open RPC for replay
429         test_mkdir -p $DIR/$tdir
430         ln -s foo $DIR/$tdir/$tfile
431         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
432 }
433 run_test 17c "symlinks: open dangling (should return error) ===="
434
435 test_17d() {
436         test_mkdir -p $DIR/$tdir
437         ln -s foo $DIR/$tdir/$tfile
438         touch $DIR/$tdir/$tfile || error "creating to new symlink"
439 }
440 run_test 17d "symlinks: create dangling ========================"
441
442 test_17e() {
443         test_mkdir -p $DIR/$tdir
444         local foo=$DIR/$tdir/$tfile
445         ln -s $foo $foo || error "create symlink failed"
446         ls -l $foo || error "ls -l failed"
447         ls $foo && error "ls not failed" || true
448 }
449 run_test 17e "symlinks: create recursive symlink (should return error) ===="
450
451 test_17f() {
452         test_mkdir -p $DIR/d17f
453         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/d17f/111
454         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/d17f/222
455         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/d17f/333
456         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/d17f/444
457         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/d17f/555
458         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890/aaaaaaaaaa/bbbbbbbbbb/cccccccccc/dddddddddd/eeeeeeeeee/ffffffffff/ $DIR/d17f/666
459         ls -l  $DIR/d17f
460 }
461 run_test 17f "symlinks: long and very long symlink name ========================"
462
463 # str_repeat(S, N) generate a string that is string S repeated N times
464 str_repeat() {
465         local s=$1
466         local n=$2
467         local ret=''
468         while [ $((n -= 1)) -ge 0 ]; do
469                 ret=$ret$s
470         done
471         echo $ret
472 }
473
474 # Long symlinks and LU-2241
475 test_17g() {
476         test_mkdir -p $DIR/$tdir
477         local TESTS="59 60 61 4094 4095"
478
479         # Fix for inode size boundary in 2.1.4
480         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
481                 TESTS="4094 4095"
482
483         # Patch not applied to 2.2 or 2.3 branches
484         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
485         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
486                 TESTS="4094 4095"
487
488         # skip long symlink name for rhel6.5.
489         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
490         grep -q '6.5' /etc/redhat-release &>/dev/null &&
491                 TESTS="59 60 61 4062 4063"
492
493         for i in $TESTS; do
494                 local SYMNAME=$(str_repeat 'x' $i)
495                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
496                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
497         done
498 }
499 run_test 17g "symlinks: really long symlink name and inode boundaries"
500
501 test_17h() { #bug 17378
502         remote_mds_nodsh && skip "remote MDS with nodsh" && return
503         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
504         local mdt_idx
505         test_mkdir -p $DIR/$tdir
506         if [[ $MDSCOUNT -gt 1 ]]; then
507                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
508         else
509                 mdt_idx=0
510         fi
511         $SETSTRIPE -c -1 $DIR/$tdir
512 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
513         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
514         touch $DIR/$tdir/$tfile || true
515 }
516 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
517
518 test_17i() { #bug 20018
519         remote_mds_nodsh && skip "remote MDS with nodsh" && return
520         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
521         test_mkdir -c1 $DIR/$tdir
522         local foo=$DIR/$tdir/$tfile
523         local mdt_idx
524         if [[ $MDSCOUNT -gt 1 ]]; then
525                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
526         else
527                 mdt_idx=0
528         fi
529         ln -s $foo $foo || error "create symlink failed"
530 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
531         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
532         ls -l $foo && error "error not detected"
533         return 0
534 }
535 run_test 17i "don't panic on short symlink"
536
537 test_17k() { #bug 22301
538         [[ -z "$(which rsync 2>/dev/null)" ]] &&
539                 skip "no rsync command" && return 0
540         rsync --help | grep -q xattr ||
541                 skip_env "$(rsync --version | head -n1) does not support xattrs"
542         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
543         test_mkdir -p $DIR/$tdir
544         test_mkdir -p $DIR/$tdir.new
545         touch $DIR/$tdir/$tfile
546         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
547         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
548                 error "rsync failed with xattrs enabled"
549 }
550 run_test 17k "symlinks: rsync with xattrs enabled ========================="
551
552 test_17l() { # LU-279
553         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
554                 skip "no getfattr command" && return 0
555         mkdir -p $DIR/$tdir
556         touch $DIR/$tdir/$tfile
557         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
558         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
559                 # -h to not follow symlinks. -m '' to list all the xattrs.
560                 # grep to remove first line: '# file: $path'.
561                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
562                 do
563                         lgetxattr_size_check $path $xattr ||
564                                 error "lgetxattr_size_check $path $xattr failed"
565                 done
566         done
567 }
568 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
569
570 # LU-1540
571 test_17m() {
572         local short_sym="0123456789"
573         local WDIR=$DIR/${tdir}m
574         local mds_index
575         local devname
576         local cmd
577         local i
578         local rc=0
579
580         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
581         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
582                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
583
584         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
585                 skip "only for ldiskfs MDT" && return 0
586
587         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
588
589         mkdir -p $WDIR
590         long_sym=$short_sym
591         # create a long symlink file
592         for ((i = 0; i < 4; ++i)); do
593                 long_sym=${long_sym}${long_sym}
594         done
595
596         echo "create 512 short and long symlink files under $WDIR"
597         for ((i = 0; i < 256; ++i)); do
598                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
599                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
600         done
601
602         echo "erase them"
603         rm -f $WDIR/*
604         sync
605         wait_delete_completed
606
607         echo "recreate the 512 symlink files with a shorter string"
608         for ((i = 0; i < 512; ++i)); do
609                 # rewrite the symlink file with a shorter string
610                 ln -sf ${long_sym} $WDIR/long-$i
611                 ln -sf ${short_sym} $WDIR/short-$i
612         done
613
614         mds_index=$($LFS getstripe -M $WDIR)
615         mds_index=$((mds_index+1))
616         devname=$(mdsdevname $mds_index)
617         cmd="$E2FSCK -fnvd $devname"
618
619         echo "stop and checking mds${mds_index}: $cmd"
620         # e2fsck should not return error
621         stop mds${mds_index}
622         do_facet mds${mds_index} $cmd || rc=$?
623
624         start mds${mds_index} $devname $MDS_MOUNT_OPTS
625         df $MOUNT > /dev/null 2>&1
626         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
627                 "short/long symlink MDT: rc=$rc"
628         return $rc
629 }
630 run_test 17m "run e2fsck against MDT which contains short/long symlink"
631
632 check_fs_consistency_17n() {
633         local mdt_index
634         local devname
635         local cmd
636         local rc=0
637
638         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
639         # so it only check MDT1/MDT2 instead of all of MDTs.
640         for mdt_index in $(seq 1 2); do
641                 devname=$(mdsdevname $mdt_index)
642                 cmd="$E2FSCK -fnvd $devname"
643
644                 echo "stop and checking mds${mdt_index}: $cmd"
645                 # e2fsck should not return error
646                 stop mds${mdt_index}
647                 do_facet mds${mdt_index} $cmd || rc=$?
648
649                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS
650                 df $MOUNT > /dev/null 2>&1
651                 [ $rc -ne 0 ] && break
652         done
653         return $rc
654 }
655
656 test_17n() {
657         local i
658
659         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
660         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
661                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
662
663         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
664                 skip "only for ldiskfs MDT" && return 0
665
666         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
667
668         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
669
670         mkdir $DIR/$tdir
671         for ((i=0; i<10; i++)); do
672                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
673                         error "create remote dir error $i"
674                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
675                         error "create files under remote dir failed $i"
676         done
677
678         check_fs_consistency_17n ||
679                 error "e2fsck report error after create files under remote dir"
680
681         for ((i=0;i<10;i++)); do
682                 rm -rf $DIR/$tdir/remote_dir_${i} ||
683                         error "destroy remote dir error $i"
684         done
685
686         check_fs_consistency_17n ||
687                 error "e2fsck report error after unlink files under remote dir"
688
689         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
690                 skip "lustre < 2.4.50 does not support migrate mv " && return
691
692         for ((i=0; i<10; i++)); do
693                 mkdir -p $DIR/$tdir/remote_dir_${i}
694                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
695                         error "create files under remote dir failed $i"
696                 $LFS mv -M 1 $DIR/$tdir/remote_dir_${i} ||
697                         error "migrate remote dir error $i"
698         done
699         check_fs_consistency_17n || error "e2fsck report error after migration"
700
701         for ((i=0;i<10;i++)); do
702                 rm -rf $DIR/$tdir/remote_dir_${i} ||
703                         error "destroy remote dir error $i"
704         done
705
706         check_fs_consistency_17n || error "e2fsck report error after unlink"
707 }
708 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
709
710 test_17o() {
711         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
712                 skip "Need MDS version at least 2.3.64" && return
713
714         local WDIR=$DIR/${tdir}o
715         local mdt_index
716         local mdtdevname
717         local rc=0
718
719         mkdir -p $WDIR
720         mdt_index=$($LFS getstripe -M $WDIR)
721         mdt_index=$((mdt_index+1))
722         mdtdevname=$(mdsdevname $mdt_index)
723
724         touch $WDIR/$tfile
725         stop mds${mdt_index}
726         start mds${mdt_index} $mdtdevname $MDS_MOUNT_OPTS
727
728         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
729         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
730         ls -l $WDIR/$tfile && rc=1
731         do_facet mds${mdt_index} lctl set_param fail_loc=0
732         [[ $rc -ne 0 ]] && error "stat file should fail"
733         true
734 }
735 run_test 17o "stat file with incompat LMA feature"
736
737 test_18() {
738         touch $DIR/f || error "Failed to touch $DIR/f: $?"
739         ls $DIR || error "Failed to ls $DIR: $?"
740 }
741 run_test 18 "touch .../f ; ls ... =============================="
742
743 test_19a() {
744         touch $DIR/$tfile
745         ls -l $DIR
746         rm $DIR/$tfile
747         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
748 }
749 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
750
751 test_19b() {
752         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
753 }
754 run_test 19b "ls -l .../f19 (should return error) =============="
755
756 test_19c() {
757         [ $RUNAS_ID -eq $UID ] &&
758                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
759         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
760 }
761 run_test 19c "$RUNAS touch .../f19 (should return error) =="
762
763 test_19d() {
764         cat $DIR/f19 && error || true
765 }
766 run_test 19d "cat .../f19 (should return error) =============="
767
768 test_20() {
769         touch $DIR/$tfile
770         rm $DIR/$tfile
771         log "1 done"
772         touch $DIR/$tfile
773         rm $DIR/$tfile
774         log "2 done"
775         touch $DIR/$tfile
776         rm $DIR/$tfile
777         log "3 done"
778         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
779 }
780 run_test 20 "touch .../f ; ls -l ... ==========================="
781
782 test_21() {
783         test_mkdir -p $DIR/$tdir
784         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
785         ln -s dangle $DIR/$tdir/link
786         echo foo >> $DIR/$tdir/link
787         cat $DIR/$tdir/dangle
788         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
789         $CHECKSTAT -f -t file $DIR/$tdir/link ||
790                 error "$tdir/link not linked to a file"
791 }
792 run_test 21 "write to dangling link ============================"
793
794 test_22() {
795         WDIR=$DIR/$tdir
796         test_mkdir -p $DIR/$tdir
797         chown $RUNAS_ID:$RUNAS_GID $WDIR
798         (cd $WDIR || error "cd $WDIR failed";
799         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
800         $RUNAS tar xf -)
801         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
802         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
803         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
804 }
805 run_test 22 "unpack tar archive as non-root user ==============="
806
807 # was test_23
808 test_23a() {
809         test_mkdir -p $DIR/$tdir
810         local file=$DIR/$tdir/$tfile
811
812         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
813         openfile -f O_CREAT:O_EXCL $file &&
814                 error "$file recreate succeeded" || true
815 }
816 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
817
818 test_23b() { # bug 18988
819         test_mkdir -p $DIR/$tdir
820         local file=$DIR/$tdir/$tfile
821
822         rm -f $file
823         echo foo > $file || error "write filed"
824         echo bar >> $file || error "append filed"
825         $CHECKSTAT -s 8 $file || error "wrong size"
826         rm $file
827 }
828 run_test 23b "O_APPEND check =========================="
829
830 # rename sanity
831 test_24a() {
832         echo '-- same directory rename'
833         test_mkdir $DIR/$tdir
834         touch $DIR/$tdir/$tfile.1
835         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
836         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
837 }
838 run_test 24a "rename file to non-existent target"
839
840 test_24b() {
841         test_mkdir $DIR/$tdir
842         touch $DIR/$tdir/$tfile.{1,2}
843         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
844         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
845         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
846 }
847 run_test 24b "rename file to existing target"
848
849 test_24c() {
850         test_mkdir $DIR/$tdir
851         test_mkdir $DIR/$tdir/d$testnum.1
852         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
853         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
854         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
855 }
856 run_test 24c "rename directory to non-existent target"
857
858 test_24d() {
859         test_mkdir -c1 $DIR/$tdir
860         test_mkdir -c1 $DIR/$tdir/d$testnum.1
861         test_mkdir -c1 $DIR/$tdir/d$testnum.2
862         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
863         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
864         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
865 }
866 run_test 24d "rename directory to existing target"
867
868 test_24e() {
869         echo '-- cross directory renames --'
870         test_mkdir $DIR/R5a
871         test_mkdir $DIR/R5b
872         touch $DIR/R5a/f
873         mv $DIR/R5a/f $DIR/R5b/g
874         $CHECKSTAT -a $DIR/R5a/f || error
875         $CHECKSTAT -t file $DIR/R5b/g || error
876 }
877 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
878
879 test_24f() {
880         test_mkdir $DIR/R6a
881         test_mkdir $DIR/R6b
882         touch $DIR/R6a/f $DIR/R6b/g
883         mv $DIR/R6a/f $DIR/R6b/g
884         $CHECKSTAT -a $DIR/R6a/f || error
885         $CHECKSTAT -t file $DIR/R6b/g || error
886 }
887 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
888
889 test_24g() {
890         test_mkdir $DIR/R7a
891         test_mkdir $DIR/R7b
892         test_mkdir $DIR/R7a/d
893         mv $DIR/R7a/d $DIR/R7b/e
894         $CHECKSTAT -a $DIR/R7a/d || error
895         $CHECKSTAT -t dir $DIR/R7b/e || error
896 }
897 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
898
899 test_24h() {
900         test_mkdir -c1 $DIR/R8a
901         test_mkdir -c1 $DIR/R8b
902         test_mkdir -c1 $DIR/R8a/d
903         test_mkdir -c1 $DIR/R8b/e
904         mrename $DIR/R8a/d $DIR/R8b/e
905         $CHECKSTAT -a $DIR/R8a/d || error
906         $CHECKSTAT -t dir $DIR/R8b/e || error
907 }
908 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
909
910 test_24i() {
911         echo "-- rename error cases"
912         test_mkdir $DIR/R9
913         test_mkdir $DIR/R9/a
914         touch $DIR/R9/f
915         mrename $DIR/R9/f $DIR/R9/a
916         $CHECKSTAT -t file $DIR/R9/f || error
917         $CHECKSTAT -t dir  $DIR/R9/a || error
918         $CHECKSTAT -a $DIR/R9/a/f || error
919 }
920 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
921
922 test_24j() {
923         test_mkdir $DIR/R10
924         mrename $DIR/R10/f $DIR/R10/g
925         $CHECKSTAT -t dir $DIR/R10 || error
926         $CHECKSTAT -a $DIR/R10/f || error
927         $CHECKSTAT -a $DIR/R10/g || error
928 }
929 run_test 24j "source does not exist ============================"
930
931 test_24k() {
932         test_mkdir $DIR/R11a
933         test_mkdir $DIR/R11a/d
934         touch $DIR/R11a/f
935         mv $DIR/R11a/f $DIR/R11a/d
936         $CHECKSTAT -a $DIR/R11a/f || error
937         $CHECKSTAT -t file $DIR/R11a/d/f || error
938 }
939 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
940
941 # bug 2429 - rename foo foo foo creates invalid file
942 test_24l() {
943         f="$DIR/f24l"
944         $MULTIOP $f OcNs || error
945 }
946 run_test 24l "Renaming a file to itself ========================"
947
948 test_24m() {
949         f="$DIR/f24m"
950         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
951         # on ext3 this does not remove either the source or target files
952         # though the "expected" operation would be to remove the source
953         $CHECKSTAT -t file ${f} || error "${f} missing"
954         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
955 }
956 run_test 24m "Renaming a file to a hard link to itself ========="
957
958 test_24n() {
959     f="$DIR/f24n"
960     # this stats the old file after it was renamed, so it should fail
961     touch ${f}
962     $CHECKSTAT ${f}
963     mv ${f} ${f}.rename
964     $CHECKSTAT ${f}.rename
965     $CHECKSTAT -a ${f}
966 }
967 run_test 24n "Statting the old file after renaming (Posix rename 2)"
968
969 test_24o() {
970         check_kernel_version 37 || return 0
971         test_mkdir -p $DIR/d24o
972         rename_many -s random -v -n 10 $DIR/d24o
973 }
974 run_test 24o "rename of files during htree split ==============="
975
976 test_24p() {
977         test_mkdir $DIR/R12a
978         test_mkdir $DIR/R12b
979         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
980         mrename $DIR/R12a $DIR/R12b
981         $CHECKSTAT -a $DIR/R12a || error
982         $CHECKSTAT -t dir $DIR/R12b || error
983         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
984         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
985 }
986 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
987
988 cleanup_multiop_pause() {
989         trap 0
990         kill -USR1 $MULTIPID
991 }
992
993 test_24q() {
994         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
995         test_mkdir $DIR/R13a
996         test_mkdir $DIR/R13b
997         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
998         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
999         MULTIPID=$!
1000
1001         trap cleanup_multiop_pause EXIT
1002         mrename $DIR/R13a $DIR/R13b
1003         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
1004         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
1005         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
1006         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
1007         cleanup_multiop_pause
1008         wait $MULTIPID || error "multiop close failed"
1009 }
1010 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
1011
1012 test_24r() { #bug 3789
1013         test_mkdir $DIR/R14a
1014         test_mkdir $DIR/R14a/b
1015         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1016         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1017         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1018 }
1019 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1020
1021 test_24s() {
1022         test_mkdir $DIR/R15a
1023         test_mkdir $DIR/R15a/b
1024         test_mkdir $DIR/R15a/b/c
1025         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1026         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1027         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1028 }
1029 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1030 test_24t() {
1031         test_mkdir $DIR/R16a
1032         test_mkdir $DIR/R16a/b
1033         test_mkdir $DIR/R16a/b/c
1034         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1035         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1036         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1037 }
1038 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1039
1040 test_24u() { # bug12192
1041         rm -rf $DIR/$tfile
1042         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1043         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1044 }
1045 run_test 24u "create stripe file"
1046
1047 page_size() {
1048         getconf PAGE_SIZE
1049 }
1050
1051 simple_cleanup_common() {
1052         trap 0
1053         rm -rf $DIR/$tdir
1054         wait_delete_completed
1055 }
1056
1057 max_pages_per_rpc() {
1058         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1059 }
1060
1061 test_24v() {
1062         local NRFILES=100000
1063         local FREE_INODES=$(mdt_free_inodes 0)
1064         [[ $FREE_INODES -lt $NRFILES ]] &&
1065                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1066                 return
1067
1068         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1069         trap simple_cleanup_common EXIT
1070
1071         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1072         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1073
1074         mkdir -p $DIR/$tdir
1075         createmany -m $DIR/$tdir/$tfile $NRFILES
1076
1077         cancel_lru_locks mdc
1078         lctl set_param mdc.*.stats clear
1079
1080         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1081
1082         # LU-5 large readdir
1083         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1084         #               8 bytes for name(filename is mostly 5 in this test) +
1085         #               8 bytes for luda_type
1086         # take into account of overhead in lu_dirpage header and end mark in
1087         # each page, plus one in RPC_NUM calculation.
1088         DIRENT_SIZE=48
1089         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1090         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1091         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1092                                 awk '/^mds_readpage/ {print $2}')
1093         [[ $mds_readpage -gt $RPC_NUM ]] &&
1094                 error "large readdir doesn't take effect"
1095
1096         simple_cleanup_common
1097 }
1098 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1099
1100 test_24w() { # bug21506
1101         SZ1=234852
1102         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1103         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1104         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1105         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1106         [ "$SZ1" = "$SZ2" ] || \
1107                 error "Error reading at the end of the file $tfile"
1108 }
1109 run_test 24w "Reading a file larger than 4Gb"
1110
1111 test_24x() {
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         mkdir -p $DIR/$tdir
1118         $LFS mkdir -i $MDTIDX $remote_dir ||
1119                 error "create remote directory failed"
1120
1121         mkdir -p $DIR/$tdir/src_dir
1122         touch $DIR/$tdir/src_file
1123         mkdir -p $remote_dir/tgt_dir
1124         touch $remote_dir/tgt_file
1125
1126         mrename $remote_dir $DIR/ &&
1127                 error "rename dir cross MDT works!"
1128
1129         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir &&
1130                 error "rename dir cross MDT works!"
1131
1132         mrename $DIR/$tdir/src_file $remote_dir/tgt_file &&
1133                 error "rename file cross MDT works!"
1134
1135         ln $DIR/$tdir/src_file $remote_dir/tgt_file1 &&
1136                 error "ln file cross MDT should not work!"
1137
1138         rm -rf $DIR/$tdir || error "Can not delete directories"
1139 }
1140 run_test 24x "cross rename/link should be failed"
1141
1142 test_24y() {
1143         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1144         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1145         local MDTIDX=1
1146         local remote_dir=$DIR/$tdir/remote_dir
1147
1148         mkdir -p $DIR/$tdir
1149         $LFS mkdir -i $MDTIDX $remote_dir ||
1150                    error "create remote directory failed"
1151
1152         mkdir -p $remote_dir/src_dir
1153         touch $remote_dir/src_file
1154         mkdir -p $remote_dir/tgt_dir
1155         touch $remote_dir/tgt_file
1156
1157         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1158                 error "rename subdir in the same remote dir failed!"
1159
1160         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1161                 error "rename files in the same remote dir failed!"
1162
1163         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1164                 error "link files in the same remote dir failed!"
1165
1166         rm -rf $DIR/$tdir || error "Can not delete directories"
1167 }
1168 run_test 24y "rename/link on the same dir should succeed"
1169
1170 test_24z() {
1171         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1172         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1173         local MDTIDX=1
1174         local remote_src=$DIR/$tdir/remote_dir
1175         local remote_tgt=$DIR/$tdir/remote_tgt
1176
1177         mkdir -p $DIR/$tdir
1178         $LFS mkdir -i $MDTIDX $remote_src ||
1179                    error "create remote directory failed"
1180
1181         $LFS mkdir -i $MDTIDX $remote_tgt ||
1182                    error "create remote directory failed"
1183
1184         mrename $remote_src $remote_tgt &&
1185                 error "rename remote dirs should not work!"
1186
1187         # If target dir does not exists, it should succeed
1188         rm -rf $remote_tgt
1189         mrename $remote_src $remote_tgt ||
1190                 error "rename remote dirs(tgt dir does not exists) failed!"
1191
1192         rm -rf $DIR/$tdir || error "Can not delete directories"
1193 }
1194 run_test 24z "rename one remote dir to another remote dir should fail"
1195
1196 test_24A() { # LU-3182
1197         local NFILES=5000
1198
1199         rm -rf $DIR/$tdir
1200         mkdir -p $DIR/$tdir
1201         createmany -m $DIR/$tdir/$tfile $NFILES
1202         local t=$(ls $DIR/$tdir | wc -l)
1203         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1204         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1205         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1206                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1207         fi
1208
1209         rm -rf $DIR/$tdir || error "Can not delete directories"
1210 }
1211 run_test 24A "readdir() returns correct number of entries."
1212
1213 test_24B() { # LU-4805
1214         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1215         local count
1216
1217         mkdir $DIR/$tdir
1218         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1219                 error "create striped dir failed"
1220
1221         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1222         [ $count -eq 2 ] || error "Expected 2, got $count"
1223
1224         touch $DIR/$tdir/striped_dir/a
1225
1226         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1227         [ $count -eq 3 ] || error "Expected 3, got $count"
1228
1229         touch $DIR/$tdir/striped_dir/.f
1230
1231         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1232         [ $count -eq 4 ] || error "Expected 4, got $count"
1233
1234         rm -rf $DIR/$tdir || error "Can not delete directories"
1235 }
1236 run_test 24B "readdir for striped dir return correct number of entries"
1237
1238 test_24C() {
1239         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1240
1241         mkdir $DIR/$tdir
1242         mkdir $DIR/$tdir/d0
1243         mkdir $DIR/$tdir/d1
1244
1245         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1246                 error "create striped dir failed"
1247
1248         cd $DIR/$tdir/d0/striped_dir
1249
1250         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1251         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1252         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1253
1254         [ "$d0_ino" = "$parent_ino" ] ||
1255                 error ".. wrong, expect $d0_ino, get $parent_ino"
1256
1257         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1258                 error "mv striped dir failed"
1259
1260         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1261
1262         [ "$d1_ino" = "$parent_ino" ] ||
1263                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1264 }
1265 run_test 24C "check .. in striped dir"
1266
1267 test_25a() {
1268         echo '== symlink sanity ============================================='
1269
1270         test_mkdir $DIR/d25
1271         ln -s d25 $DIR/s25
1272         touch $DIR/s25/foo || error
1273 }
1274 run_test 25a "create file in symlinked directory ==============="
1275
1276 test_25b() {
1277         [ ! -d $DIR/d25 ] && test_25a
1278         $CHECKSTAT -t file $DIR/s25/foo || error
1279 }
1280 run_test 25b "lookup file in symlinked directory ==============="
1281
1282 test_26a() {
1283         test_mkdir $DIR/d26
1284         test_mkdir $DIR/d26/d26-2
1285         ln -s d26/d26-2 $DIR/s26
1286         touch $DIR/s26/foo || error
1287 }
1288 run_test 26a "multiple component symlink ======================="
1289
1290 test_26b() {
1291         test_mkdir -p $DIR/d26b/d26-2
1292         ln -s d26b/d26-2/foo $DIR/s26-2
1293         touch $DIR/s26-2 || error
1294 }
1295 run_test 26b "multiple component symlink at end of lookup ======"
1296
1297 test_26c() {
1298         test_mkdir $DIR/d26.2
1299         touch $DIR/d26.2/foo
1300         ln -s d26.2 $DIR/s26.2-1
1301         ln -s s26.2-1 $DIR/s26.2-2
1302         ln -s s26.2-2 $DIR/s26.2-3
1303         chmod 0666 $DIR/s26.2-3/foo
1304 }
1305 run_test 26c "chain of symlinks ================================"
1306
1307 # recursive symlinks (bug 439)
1308 test_26d() {
1309         ln -s d26-3/foo $DIR/d26-3
1310 }
1311 run_test 26d "create multiple component recursive symlink ======"
1312
1313 test_26e() {
1314         [ ! -h $DIR/d26-3 ] && test_26d
1315         rm $DIR/d26-3
1316 }
1317 run_test 26e "unlink multiple component recursive symlink ======"
1318
1319 # recursive symlinks (bug 7022)
1320 test_26f() {
1321         test_mkdir -p $DIR/$tdir
1322         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1323         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1324         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1325         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1326         cd $tfile                || error "cd $tfile failed"
1327         ln -s .. dotdot          || error "ln dotdot failed"
1328         ln -s dotdot/lndir lndir || error "ln lndir failed"
1329         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1330         output=`ls $tfile/$tfile/lndir/bar1`
1331         [ "$output" = bar1 ] && error "unexpected output"
1332         rm -r $tfile             || error "rm $tfile failed"
1333         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1334 }
1335 run_test 26f "rm -r of a directory which has recursive symlink ="
1336
1337 test_27a() {
1338         echo '== stripe sanity =============================================='
1339         test_mkdir -p $DIR/d27 || error "mkdir failed"
1340         $GETSTRIPE $DIR/d27
1341         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1342         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1343         log "== test_27a: write to one stripe file ========================="
1344         cp /etc/hosts $DIR/d27/f0 || error
1345 }
1346 run_test 27a "one stripe file =================================="
1347
1348 test_27b() {
1349         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1350         test_mkdir -p $DIR/d27
1351         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1352         $GETSTRIPE -c $DIR/d27/f01
1353         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1354                 error "two-stripe file doesn't have two stripes"
1355
1356         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1357 }
1358 run_test 27b "create and write to two stripe file"
1359
1360 test_27d() {
1361         test_mkdir -p $DIR/d27
1362         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1363         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1364         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1365 }
1366 run_test 27d "create file with default settings ================"
1367
1368 test_27e() {
1369         test_mkdir -p $DIR/d27
1370         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1371         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1372         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1373 }
1374 run_test 27e "setstripe existing file (should return error) ======"
1375
1376 test_27f() {
1377         test_mkdir -p $DIR/d27
1378         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/d27/fbad && error "setstripe failed"
1379         dd if=/dev/zero of=$DIR/d27/fbad bs=4k count=4 || error "dd failed"
1380         $GETSTRIPE $DIR/d27/fbad || error "$GETSTRIPE failed"
1381 }
1382 run_test 27f "setstripe with bad stripe size (should return error)"
1383
1384 test_27g() {
1385         test_mkdir -p $DIR/d27
1386         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1387         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1388                 error "$DIR/d27/fnone has object"
1389 }
1390 run_test 27g "$GETSTRIPE with no objects"
1391
1392 test_27i() {
1393         touch $DIR/d27/fsome || error "touch failed"
1394         [[ $($GETSTRIPE -c $DIR/d27/fsome) -gt 0 ]] || 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         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1430                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1431                 return
1432         fi
1433         trap simple_cleanup_common EXIT
1434         test_mkdir -p $DIR/$tdir
1435         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1436         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1437                 error "dd should fill OST0"
1438         i=2
1439         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1440                 i=$((i + 1))
1441                 [ $i -gt 256 ] && break
1442         done
1443         i=$((i + 1))
1444         touch $DIR/$tdir/f27m_$i
1445         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1446                 error "OST0 was full but new created file still use it"
1447         i=$((i + 1))
1448         touch $DIR/$tdir/f27m_$i
1449         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1450                 error "OST0 was full but new created file still use it"
1451         simple_cleanup_common
1452 }
1453 run_test 27m "create file while OST0 was full =================="
1454
1455 sleep_maxage() {
1456         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1457         sleep $DELAY
1458 }
1459
1460 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1461 # if the OST isn't full anymore.
1462 reset_enospc() {
1463         local OSTIDX=${1:-""}
1464
1465         local list=$(comma_list $(osts_nodes))
1466         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1467
1468         do_nodes $list lctl set_param fail_loc=0
1469         sync    # initiate all OST_DESTROYs from MDS to OST
1470         sleep_maxage
1471 }
1472
1473 exhaust_precreations() {
1474         local OSTIDX=$1
1475         local FAILLOC=$2
1476         local FAILIDX=${3:-$OSTIDX}
1477
1478         test_mkdir -p $DIR/$tdir
1479         local MDSIDX=$(get_mds_dir "$DIR/$tdir")
1480         echo OSTIDX=$OSTIDX MDSIDX=$MDSIDX
1481
1482         local OST=$(ostname_from_index $OSTIDX)
1483         local MDT_INDEX=$(lfs df | grep "\[MDT:$((MDSIDX - 1))\]" | awk '{print $1}' | \
1484                           sed -e 's/_UUID$//;s/^.*-//')
1485
1486         # on the mdt's osc
1487         local mdtosc_proc1=$(get_mdtosc_proc_path mds${MDSIDX} $OST)
1488         local last_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1489                         osc.$mdtosc_proc1.prealloc_last_id)
1490         local next_id=$(do_facet mds${MDSIDX} lctl get_param -n \
1491                         osc.$mdtosc_proc1.prealloc_next_id)
1492
1493         local mdtosc_proc2=$(get_mdtosc_proc_path mds${MDSIDX})
1494         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1495
1496         test_mkdir -p $DIR/$tdir/${OST}
1497         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1498 #define OBD_FAIL_OST_ENOSPC              0x215
1499         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=$FAILIDX
1500         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x215
1501         echo "Creating to objid $last_id on ost $OST..."
1502         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1503         do_facet mds${MDSIDX} lctl get_param osc.$mdtosc_proc2.prealloc*
1504         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=$FAILLOC
1505         sleep_maxage
1506 }
1507
1508 exhaust_all_precreations() {
1509         local i
1510         for (( i=0; i < OSTCOUNT; i++ )) ; do
1511                 exhaust_precreations $i $1 -1
1512         done
1513 }
1514
1515 test_27n() {
1516         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1517         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1518         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1519         remote_ost_nodsh && skip "remote OST with nodsh" && return
1520
1521         reset_enospc
1522         rm -f $DIR/$tdir/$tfile
1523         exhaust_precreations 0 0x80000215
1524         $SETSTRIPE -c -1 $DIR/$tdir
1525         touch $DIR/$tdir/$tfile || error
1526         $GETSTRIPE $DIR/$tdir/$tfile
1527         reset_enospc
1528 }
1529 run_test 27n "create file with some full OSTs =================="
1530
1531 test_27o() {
1532         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1533         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1534         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1535         remote_ost_nodsh && skip "remote OST with nodsh" && return
1536
1537         reset_enospc
1538         rm -f $DIR/$tdir/$tfile
1539         exhaust_all_precreations 0x215
1540
1541         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1542
1543         reset_enospc
1544         rm -rf $DIR/$tdir/*
1545 }
1546 run_test 27o "create file with all full OSTs (should error) ===="
1547
1548 test_27p() {
1549         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1550         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1551         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1552         remote_ost_nodsh && skip "remote OST with nodsh" && return
1553
1554         reset_enospc
1555         rm -f $DIR/$tdir/$tfile
1556         test_mkdir -p $DIR/$tdir
1557
1558         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1559         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1560         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1561
1562         exhaust_precreations 0 0x80000215
1563         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1564         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1565         $GETSTRIPE $DIR/$tdir/$tfile
1566
1567         reset_enospc
1568 }
1569 run_test 27p "append to a truncated file with some full OSTs ==="
1570
1571 test_27q() {
1572         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1573         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1574         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1575         remote_ost_nodsh && skip "remote OST with nodsh" && return
1576
1577         reset_enospc
1578         rm -f $DIR/$tdir/$tfile
1579
1580         test_mkdir -p $DIR/$tdir
1581         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1582         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1583         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1584
1585         exhaust_all_precreations 0x215
1586
1587         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1588         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1589
1590         reset_enospc
1591 }
1592 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1593
1594 test_27r() {
1595         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1596         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1597         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1598         remote_ost_nodsh && skip "remote OST with nodsh" && return
1599
1600         reset_enospc
1601         rm -f $DIR/$tdir/$tfile
1602         exhaust_precreations 0 0x80000215
1603
1604         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1605
1606         reset_enospc
1607 }
1608 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1609
1610 test_27s() { # bug 10725
1611         test_mkdir -p $DIR/$tdir
1612         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1613         local stripe_count=0
1614         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1615         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1616                 error "stripe width >= 2^32 succeeded" || true
1617
1618 }
1619 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1620
1621 test_27t() { # bug 10864
1622         WDIR=$(pwd)
1623         WLFS=$(which lfs)
1624         cd $DIR
1625         touch $tfile
1626         $WLFS getstripe $tfile
1627         cd $WDIR
1628 }
1629 run_test 27t "check that utils parse path correctly"
1630
1631 test_27u() { # bug 4900
1632         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1633         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1634         local index
1635         local list=$(comma_list $(mdts_nodes))
1636
1637 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1638         do_nodes $list $LCTL set_param fail_loc=0x139
1639         test_mkdir -p $DIR/$tdir
1640         rm -rf $DIR/$tdir/*
1641         createmany -o $DIR/$tdir/t- 1000
1642         do_nodes $list $LCTL set_param fail_loc=0
1643
1644         TLOG=$DIR/$tfile.getstripe
1645         $GETSTRIPE $DIR/$tdir > $TLOG
1646         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1647         unlinkmany $DIR/$tdir/t- 1000
1648         [[ $OBJS -gt 0 ]] &&
1649                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1650 }
1651 run_test 27u "skip object creation on OSC w/o objects =========="
1652
1653 test_27v() { # bug 4900
1654         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1655         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1656         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1657         remote_ost_nodsh && skip "remote OST with nodsh" && return
1658
1659         exhaust_all_precreations 0x215
1660         reset_enospc
1661
1662         test_mkdir -p $DIR/$tdir
1663         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1664
1665         touch $DIR/$tdir/$tfile
1666         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1667         # all except ost1
1668         for (( i=1; i < OSTCOUNT; i++ )); do
1669                 do_facet ost$i lctl set_param fail_loc=0x705
1670         done
1671         local START=`date +%s`
1672         createmany -o $DIR/$tdir/$tfile 32
1673
1674         local FINISH=`date +%s`
1675         local TIMEOUT=`lctl get_param -n timeout`
1676         local PROCESS=$((FINISH - START))
1677         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1678                error "$FINISH - $START >= $TIMEOUT / 2"
1679         sleep $((TIMEOUT / 2 - PROCESS))
1680         reset_enospc
1681 }
1682 run_test 27v "skip object creation on slow OST ================="
1683
1684 test_27w() { # bug 10997
1685         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1686         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1687         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1688                 error "stripe size $size != 65536" || true
1689         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1690                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1691 }
1692 run_test 27w "check $SETSTRIPE -S option"
1693
1694 test_27wa() {
1695         [[ $OSTCOUNT -lt 2 ]] &&
1696                 skip_env "skipping multiple stripe count/offset test" && return
1697
1698         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1699         for i in $(seq 1 $OSTCOUNT); do
1700                 offset=$((i - 1))
1701                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1702                         error "setstripe -c $i -i $offset failed"
1703                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1704                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1705                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1706                 [ $index -ne $offset ] &&
1707                         error "stripe offset $index != $offset" || true
1708         done
1709 }
1710 run_test 27wa "check $SETSTRIPE -c -i options"
1711
1712 test_27x() {
1713         remote_ost_nodsh && skip "remote OST with nodsh" && return
1714         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1715         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1716         OFFSET=$(($OSTCOUNT - 1))
1717         OSTIDX=0
1718         local OST=$(ostname_from_index $OSTIDX)
1719
1720         test_mkdir -p $DIR/$tdir
1721         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1722         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1723         sleep_maxage
1724         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1725         for i in `seq 0 $OFFSET`; do
1726                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1727                 error "OST0 was degraded but new created file still use it"
1728         done
1729         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1730 }
1731 run_test 27x "create files while OST0 is degraded"
1732
1733 test_27y() {
1734         [[ $OSTCOUNT -lt 2 ]] &&
1735                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1736         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1737         remote_ost_nodsh && skip "remote OST with nodsh" && return
1738         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1739
1740         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1741         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1742             osc.$mdtosc.prealloc_last_id)
1743         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1744             osc.$mdtosc.prealloc_next_id)
1745         local fcount=$((last_id - next_id))
1746         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1747         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1748
1749         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1750                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1751         local OST_DEACTIVE_IDX=-1
1752         local OSC
1753         local OSTIDX
1754         local OST
1755
1756         for OSC in $MDS_OSCS; do
1757                 OST=$(osc_to_ost $OSC)
1758                 OSTIDX=$(index_from_ostuuid $OST)
1759                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1760                         OST_DEACTIVE_IDX=$OSTIDX
1761                 fi
1762                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1763                         echo $OSC "is Deactivated:"
1764                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1765                 fi
1766         done
1767
1768         OSTIDX=$(index_from_ostuuid $OST)
1769         mkdir -p $DIR/$tdir
1770         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1771
1772         for OSC in $MDS_OSCS; do
1773                 OST=$(osc_to_ost $OSC)
1774                 OSTIDX=$(index_from_ostuuid $OST)
1775                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1776                         echo $OST "is degraded:"
1777                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1778                                                 obdfilter.$OST.degraded=1
1779                 fi
1780         done
1781
1782         sleep_maxage
1783         createmany -o $DIR/$tdir/$tfile $fcount
1784
1785         for OSC in $MDS_OSCS; do
1786                 OST=$(osc_to_ost $OSC)
1787                 OSTIDX=$(index_from_ostuuid $OST)
1788                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1789                         echo $OST "is recovered from degraded:"
1790                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1791                                                 obdfilter.$OST.degraded=0
1792                 else
1793                         do_facet $SINGLEMDS lctl --device %$OSC activate
1794                 fi
1795         done
1796
1797         # all osp devices get activated, hence -1 stripe count restored
1798         local stripecnt=0
1799
1800         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1801         # devices get activated.
1802         sleep_maxage
1803         $SETSTRIPE -c -1 $DIR/$tfile
1804         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1805         rm -f $DIR/$tfile
1806         [ $stripecnt -ne $OSTCOUNT ] &&
1807                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1808         return 0
1809 }
1810 run_test 27y "create files while OST0 is degraded and the rest inactive"
1811
1812 check_seq_oid()
1813 {
1814         log "check file $1"
1815
1816         lmm_count=$($GETSTRIPE -c $1)
1817         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1818         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1819
1820         local old_ifs="$IFS"
1821         IFS=$'[:]'
1822         fid=($($LFS path2fid $1))
1823         IFS="$old_ifs"
1824
1825         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1826         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1827
1828         # compare lmm_seq and lu_fid->f_seq
1829         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1830         # compare lmm_object_id and lu_fid->oid
1831         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1832
1833         # check the trusted.fid attribute of the OST objects of the file
1834         local have_obdidx=false
1835         local stripe_nr=0
1836         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1837                 # skip lines up to and including "obdidx"
1838                 [ -z "$obdidx" ] && break
1839                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1840                 $have_obdidx || continue
1841
1842                 local ost=$((obdidx + 1))
1843                 local dev=$(ostdevname $ost)
1844                 local oid_hex
1845
1846                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1847
1848                 seq=$(echo $seq | sed -e "s/^0x//g")
1849                 if [ $seq == 0 ]; then
1850                         oid_hex=$(echo $oid)
1851                 else
1852                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1853                 fi
1854                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1855
1856                 local ff
1857                 #
1858                 # Don't unmount/remount the OSTs if we don't need to do that.
1859                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1860                 # update too, until that use mount/ll_decode_filter_fid/mount.
1861                 # Re-enable when debugfs will understand new filter_fid.
1862                 #
1863                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1864                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1865                                 $dev 2>/dev/null" | grep "parent=")
1866                 else
1867                         stop ost$ost
1868                         mount_fstype ost$ost
1869                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1870                                 $(facet_mntpt ost$ost)/$obj_file)
1871                         unmount_fstype ost$ost
1872                         start ost$ost $dev $OST_MOUNT_OPTS
1873                 fi
1874
1875                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1876
1877                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1878
1879                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1880                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1881                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1882                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1883                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1884                 local ff_pstripe
1885                 if echo $ff_parent | grep -q 'stripe='; then
1886                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1887                 else
1888                         #
1889                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1890                         # into f_ver in this case.  See the comment on
1891                         # ff_parent.
1892                         #
1893                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1894                                 sed -e 's/\]//')
1895                 fi
1896
1897                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1898                 [ $ff_pseq = $lmm_seq ] ||
1899                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1900                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1901                 [ $ff_poid = $lmm_oid ] ||
1902                         error "FF parent OID $ff_poid != $lmm_oid"
1903                 (($ff_pstripe == $stripe_nr)) ||
1904                         error "FF stripe $ff_pstripe != $stripe_nr"
1905
1906                 stripe_nr=$((stripe_nr + 1))
1907         done
1908 }
1909
1910 test_27z() {
1911         remote_ost_nodsh && skip "remote OST with nodsh" && return
1912         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1913         test_mkdir -p $DIR/$tdir
1914
1915         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1916                 { error "setstripe -c -1 failed"; return 1; }
1917         # We need to send a write to every object to get parent FID info set.
1918         # This _should_ also work for setattr, but does not currently.
1919         # touch $DIR/$tdir/$tfile-1 ||
1920         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1921                 { error "dd $tfile-1 failed"; return 2; }
1922         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1923                 { error "setstripe -c -1 failed"; return 3; }
1924         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1925                 { error "dd $tfile-2 failed"; return 4; }
1926
1927         # make sure write RPCs have been sent to OSTs
1928         sync; sleep 5; sync
1929
1930         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1931         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1932 }
1933 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1934
1935 test_27A() { # b=19102
1936         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1937         local restore_size=$($GETSTRIPE -S $MOUNT)
1938         local restore_count=$($GETSTRIPE -c $MOUNT)
1939         local restore_offset=$($GETSTRIPE -i $MOUNT)
1940         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1941         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1942                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1943         local default_size=$($GETSTRIPE -S $MOUNT)
1944         local default_offset=$($GETSTRIPE -i $MOUNT)
1945         local dsize=$((1024 * 1024))
1946         [ $default_size -eq $dsize ] ||
1947                 error "stripe size $default_size != $dsize"
1948         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1949         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1950 }
1951 run_test 27A "check filesystem-wide default LOV EA values"
1952
1953 test_27B() { # LU-2523
1954         test_mkdir -p $DIR/$tdir
1955         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1956         touch $DIR/$tdir/f0
1957         # open f1 with O_LOV_DELAY_CREATE
1958         # rename f0 onto f1
1959         # call setstripe ioctl on open file descriptor for f1
1960         # close
1961         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1962                 $DIR/$tdir/f0
1963
1964         rm -f $DIR/$tdir/f1
1965         # open f1 with O_LOV_DELAY_CREATE
1966         # unlink f1
1967         # call setstripe ioctl on open file descriptor for f1
1968         # close
1969         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1970
1971         # Allow multiop to fail in imitation of NFS's busted semantics.
1972         true
1973 }
1974 run_test 27B "call setstripe on open unlinked file/rename victim"
1975
1976 test_27C() { #LU-2871
1977         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1978
1979         declare -a ost_idx
1980         local index
1981         local found
1982         local i
1983         local j
1984
1985         test_mkdir -p $DIR/$tdir
1986         cd $DIR/$tdir
1987         for i in $(seq 0 $((OSTCOUNT - 1))); do
1988                 # set stripe across all OSTs starting from OST$i
1989                 $SETSTRIPE -i $i -c -1 $tfile$i
1990                 # get striping information
1991                 ost_idx=($($GETSTRIPE $tfile$i |
1992                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1993                 echo ${ost_idx[@]}
1994
1995                 # check the layout
1996                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
1997                         error "${#ost_idx[@]} != $OSTCOUNT"
1998
1999                 for index in $(seq 0 $((OSTCOUNT - 1))); do
2000                         found=0
2001                         for j in $(echo ${ost_idx[@]}); do
2002                                 if [ $index -eq $j ]; then
2003                                         found=1
2004                                         break
2005                                 fi
2006                         done
2007                         [ $found = 1 ] ||
2008                                 error "Can not find $index in ${ost_idx[@]}"
2009                 done
2010         done
2011 }
2012 run_test 27C "check full striping across all OSTs"
2013
2014 # createtest also checks that device nodes are created and
2015 # then visible correctly (#2091)
2016 test_28() { # bug 2091
2017         test_mkdir $DIR/d28
2018         $CREATETEST $DIR/d28/ct || error
2019 }
2020 run_test 28 "create/mknod/mkdir with bad file types ============"
2021
2022 test_29() {
2023         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2024         cancel_lru_locks mdc
2025         test_mkdir $DIR/d29
2026         touch $DIR/d29/foo
2027         log 'first d29'
2028         ls -l $DIR/d29
2029
2030         declare -i LOCKCOUNTORIG=0
2031         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2032                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2033         done
2034         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
2035
2036         declare -i LOCKUNUSEDCOUNTORIG=0
2037         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2038                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2039         done
2040
2041         log 'second d29'
2042         ls -l $DIR/d29
2043         log 'done'
2044
2045         declare -i LOCKCOUNTCURRENT=0
2046         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2047                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2048         done
2049
2050         declare -i LOCKUNUSEDCOUNTCURRENT=0
2051         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2052                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2053         done
2054
2055         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2056                 $LCTL set_param -n ldlm.dump_namespaces ""
2057                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2058                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2059                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2060                 return 2
2061         fi
2062         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2063                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2064                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2065                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2066                 return 3
2067         fi
2068 }
2069 run_test 29 "IT_GETATTR regression  ============================"
2070
2071 test_30a() { # was test_30
2072         cp $(which ls) $DIR || cp /bin/ls $DIR
2073         $DIR/ls / || error
2074         rm $DIR/ls
2075 }
2076 run_test 30a "execute binary from Lustre (execve) =============="
2077
2078 test_30b() {
2079         cp `which ls` $DIR || cp /bin/ls $DIR
2080         chmod go+rx $DIR/ls
2081         $RUNAS $DIR/ls / || error
2082         rm $DIR/ls
2083 }
2084 run_test 30b "execute binary from Lustre as non-root ==========="
2085
2086 test_30c() { # b=22376
2087         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2088         cp `which ls` $DIR || cp /bin/ls $DIR
2089         chmod a-rw $DIR/ls
2090         cancel_lru_locks mdc
2091         cancel_lru_locks osc
2092         $RUNAS $DIR/ls / || error
2093         rm -f $DIR/ls
2094 }
2095 run_test 30c "execute binary from Lustre without read perms ===="
2096
2097 test_31a() {
2098         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2099         $CHECKSTAT -a $DIR/f31 || error
2100 }
2101 run_test 31a "open-unlink file =================================="
2102
2103 test_31b() {
2104         touch $DIR/f31 || error
2105         ln $DIR/f31 $DIR/f31b || error
2106         $MULTIOP $DIR/f31b Ouc || error
2107         $CHECKSTAT -t file $DIR/f31 || error
2108 }
2109 run_test 31b "unlink file with multiple links while open ======="
2110
2111 test_31c() {
2112         touch $DIR/f31 || error
2113         ln $DIR/f31 $DIR/f31c || error
2114         multiop_bg_pause $DIR/f31 O_uc || return 1
2115         MULTIPID=$!
2116         $MULTIOP $DIR/f31c Ouc
2117         kill -USR1 $MULTIPID
2118         wait $MULTIPID
2119 }
2120 run_test 31c "open-unlink file with multiple links ============="
2121
2122 test_31d() {
2123         opendirunlink $DIR/d31d $DIR/d31d || error
2124         $CHECKSTAT -a $DIR/d31d || error
2125 }
2126 run_test 31d "remove of open directory ========================="
2127
2128 test_31e() { # bug 2904
2129         check_kernel_version 34 || return 0
2130         openfilleddirunlink $DIR/d31e || error
2131 }
2132 run_test 31e "remove of open non-empty directory ==============="
2133
2134 test_31f() { # bug 4554
2135         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2136         set -vx
2137         test_mkdir $DIR/d31f
2138         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2139         cp /etc/hosts $DIR/d31f
2140         ls -l $DIR/d31f
2141         $GETSTRIPE $DIR/d31f/hosts
2142         multiop_bg_pause $DIR/d31f D_c || return 1
2143         MULTIPID=$!
2144
2145         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2146         test_mkdir $DIR/d31f
2147         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2148         cp /etc/hosts $DIR/d31f
2149         ls -l $DIR/d31f
2150         $GETSTRIPE $DIR/d31f/hosts
2151         multiop_bg_pause $DIR/d31f D_c || return 1
2152         MULTIPID2=$!
2153
2154         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2155         wait $MULTIPID || error "first opendir $MULTIPID failed"
2156
2157         sleep 6
2158
2159         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2160         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2161         set +vx
2162 }
2163 run_test 31f "remove of open directory with open-unlink file ==="
2164
2165 test_31g() {
2166         echo "-- cross directory link --"
2167         test_mkdir -c1 $DIR/${tdir}ga
2168         test_mkdir -c1 $DIR/${tdir}gb
2169         touch $DIR/${tdir}ga/f
2170         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2171         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2172         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2173         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2174         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2175 }
2176 run_test 31g "cross directory link==============="
2177
2178 test_31h() {
2179         echo "-- cross directory link --"
2180         test_mkdir -c1 $DIR/${tdir}
2181         test_mkdir -c1 $DIR/${tdir}/dir
2182         touch $DIR/${tdir}/f
2183         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2184         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2185         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2186         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2187         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2188 }
2189 run_test 31h "cross directory link under child==============="
2190
2191 test_31i() {
2192         echo "-- cross directory link --"
2193         test_mkdir -c1 $DIR/$tdir
2194         test_mkdir -c1 $DIR/$tdir/dir
2195         touch $DIR/$tdir/dir/f
2196         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2197         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2198         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2199         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2200         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2201 }
2202 run_test 31i "cross directory link under parent==============="
2203
2204 test_31j() {
2205         test_mkdir -c1 -p $DIR/$tdir
2206         test_mkdir -c1 -p $DIR/$tdir/dir1
2207         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2208         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2209         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2210         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2211         return 0
2212 }
2213 run_test 31j "link for directory==============="
2214
2215 test_31k() {
2216         test_mkdir -c1 -p $DIR/$tdir
2217         touch $DIR/$tdir/s
2218         touch $DIR/$tdir/exist
2219         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2220         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2221         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2222         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2223         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2224         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2225         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2226         return 0
2227 }
2228 run_test 31k "link to file: the same, non-existing, dir==============="
2229
2230 test_31m() {
2231         mkdir $DIR/d31m
2232         touch $DIR/d31m/s
2233         mkdir $DIR/d31m2
2234         touch $DIR/d31m2/exist
2235         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2236         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2237         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2238         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2239         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2240         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2241         return 0
2242 }
2243 run_test 31m "link to file: the same, non-existing, dir==============="
2244
2245 test_31n() {
2246         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2247         nlink=$(stat --format=%h $DIR/$tfile)
2248         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2249         local fd=$(free_fd)
2250         local cmd="exec $fd<$DIR/$tfile"
2251         eval $cmd
2252         cmd="exec $fd<&-"
2253         trap "eval $cmd" EXIT
2254         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2255         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2256         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2257         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2258         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2259         eval $cmd
2260 }
2261 run_test 31n "check link count of unlinked file"
2262
2263 link_one() {
2264         local TEMPNAME=$(mktemp $1_XXXXXX)
2265         mlink $TEMPNAME $1 2> /dev/null &&
2266                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2267         munlink $TEMPNAME
2268 }
2269
2270 test_31o() { # LU-2901
2271         mkdir -p $DIR/$tdir
2272         for LOOP in $(seq 100); do
2273                 rm -f $DIR/$tdir/$tfile*
2274                 for THREAD in $(seq 8); do
2275                         link_one $DIR/$tdir/$tfile.$LOOP &
2276                 done
2277                 wait
2278                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2279                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2280                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2281                         break || true
2282         done
2283 }
2284 run_test 31o "duplicate hard links with same filename"
2285
2286 test_31p() {
2287         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2288
2289         mkdir $DIR/$tdir
2290         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2291         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2292
2293         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2294                 error "open unlink test1 failed"
2295         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2296                 error "open unlink test2 failed"
2297
2298         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2299                 error "test1 still exists"
2300         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2301                 error "test2 still exists"
2302 }
2303 run_test 31p "remove of open striped directory"
2304
2305 cleanup_test32_mount() {
2306         trap 0
2307         $UMOUNT -d $DIR/$tdir/ext2-mountpoint
2308 }
2309
2310 test_32a() {
2311         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2312         echo "== more mountpoints and symlinks ================="
2313         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2314         trap cleanup_test32_mount EXIT
2315         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2316         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2317         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2318         cleanup_test32_mount
2319 }
2320 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2321
2322 test_32b() {
2323         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2324         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2325         trap cleanup_test32_mount EXIT
2326         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2327         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2328         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2329         cleanup_test32_mount
2330 }
2331 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2332
2333 test_32c() {
2334         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2335         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2336         trap cleanup_test32_mount EXIT
2337         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2338         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2339         test_mkdir -p $DIR/$tdir/d2/test_dir
2340         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2341         cleanup_test32_mount
2342 }
2343 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2344
2345 test_32d() {
2346         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2347         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2348         trap cleanup_test32_mount EXIT
2349         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2350         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2351         test_mkdir -p $DIR/$tdir/d2/test_dir
2352         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2353         cleanup_test32_mount
2354 }
2355 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2356
2357 test_32e() {
2358         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2359         test_mkdir -p $DIR/d32e/tmp
2360         TMP_DIR=$DIR/d32e/tmp
2361         ln -s $DIR/d32e $TMP_DIR/symlink11
2362         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2363         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2364         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2365 }
2366 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2367
2368 test_32f() {
2369         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2370         test_mkdir -p $DIR/d32f/tmp
2371         TMP_DIR=$DIR/d32f/tmp
2372         ln -s $DIR/d32f $TMP_DIR/symlink11
2373         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2374         ls $DIR/d32f/tmp/symlink11  || error
2375         ls $DIR/d32f/symlink01 || error
2376 }
2377 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2378
2379 test_32g() {
2380         TMP_DIR=$DIR/$tdir/tmp
2381         test_mkdir -p $DIR/$tdir/tmp
2382         test_mkdir $DIR/${tdir}2
2383         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2384         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2385         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2386         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2387         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2388         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2389 }
2390 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2391
2392 test_32h() {
2393         rm -fr $DIR/$tdir $DIR/${tdir}2
2394         TMP_DIR=$DIR/$tdir/tmp
2395         test_mkdir -p $DIR/$tdir/tmp
2396         test_mkdir $DIR/${tdir}2
2397         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2398         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2399         ls $TMP_DIR/symlink12 || error
2400         ls $DIR/$tdir/symlink02  || error
2401 }
2402 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2403
2404 test_32i() {
2405         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2406         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2407         trap cleanup_test32_mount EXIT
2408         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2409         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2410         touch $DIR/$tdir/test_file
2411         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2412         cleanup_test32_mount
2413 }
2414 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2415
2416 test_32j() {
2417         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2418         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2419         trap cleanup_test32_mount EXIT
2420         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2421         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2422         touch $DIR/$tdir/test_file
2423         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2424         cleanup_test32_mount
2425 }
2426 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2427
2428 test_32k() {
2429         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2430         rm -fr $DIR/$tdir
2431         trap cleanup_test32_mount EXIT
2432         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2433         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2434         test_mkdir -p $DIR/$tdir/d2
2435         touch $DIR/$tdir/d2/test_file || error
2436         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2437         cleanup_test32_mount
2438 }
2439 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2440
2441 test_32l() {
2442         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2443         rm -fr $DIR/$tdir
2444         trap cleanup_test32_mount EXIT
2445         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2446         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2447         test_mkdir -p $DIR/$tdir/d2
2448         touch $DIR/$tdir/d2/test_file
2449         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2450         cleanup_test32_mount
2451 }
2452 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2453
2454 test_32m() {
2455         rm -fr $DIR/d32m
2456         test_mkdir -p $DIR/d32m/tmp
2457         TMP_DIR=$DIR/d32m/tmp
2458         ln -s $DIR $TMP_DIR/symlink11
2459         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2460         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2461         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2462 }
2463 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2464
2465 test_32n() {
2466         rm -fr $DIR/d32n
2467         test_mkdir -p $DIR/d32n/tmp
2468         TMP_DIR=$DIR/d32n/tmp
2469         ln -s $DIR $TMP_DIR/symlink11
2470         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2471         ls -l $DIR/d32n/tmp/symlink11  || error
2472         ls -l $DIR/d32n/symlink01 || error
2473 }
2474 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2475
2476 test_32o() {
2477         rm -fr $DIR/d32o $DIR/$tfile
2478         touch $DIR/$tfile
2479         test_mkdir -p $DIR/d32o/tmp
2480         TMP_DIR=$DIR/d32o/tmp
2481         ln -s $DIR/$tfile $TMP_DIR/symlink12
2482         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2483         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2484         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2485         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2486         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2487 }
2488 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2489
2490 test_32p() {
2491     log 32p_1
2492         rm -fr $DIR/d32p
2493     log 32p_2
2494         rm -f $DIR/$tfile
2495     log 32p_3
2496         touch $DIR/$tfile
2497     log 32p_4
2498         test_mkdir -p $DIR/d32p/tmp
2499     log 32p_5
2500         TMP_DIR=$DIR/d32p/tmp
2501     log 32p_6
2502         ln -s $DIR/$tfile $TMP_DIR/symlink12
2503     log 32p_7
2504         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2505     log 32p_8
2506         cat $DIR/d32p/tmp/symlink12 || error
2507     log 32p_9
2508         cat $DIR/d32p/symlink02 || error
2509     log 32p_10
2510 }
2511 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2512
2513 cleanup_testdir_mount() {
2514         trap 0
2515         $UMOUNT -d $DIR/$tdir
2516 }
2517
2518 test_32q() {
2519         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2520         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2521         trap cleanup_testdir_mount EXIT
2522         test_mkdir -p $DIR/$tdir
2523         touch $DIR/$tdir/under_the_mount
2524         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2525         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2526         cleanup_testdir_mount
2527 }
2528 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2529
2530 test_32r() {
2531         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2532         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2533         trap cleanup_testdir_mount EXIT
2534         test_mkdir -p $DIR/$tdir
2535         touch $DIR/$tdir/under_the_mount
2536         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2537         ls $DIR/$tdir | grep -q under_the_mount && error || true
2538         cleanup_testdir_mount
2539 }
2540 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2541
2542 test_33aa() {
2543         rm -f $DIR/$tfile
2544         touch $DIR/$tfile
2545         chmod 444 $DIR/$tfile
2546         chown $RUNAS_ID $DIR/$tfile
2547         log 33_1
2548         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2549         log 33_2
2550 }
2551 run_test 33aa "write file with mode 444 (should return error) ===="
2552
2553 test_33a() {
2554         rm -fr $DIR/d33
2555         test_mkdir -p $DIR/d33
2556         chown $RUNAS_ID $DIR/d33
2557         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2558         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2559                 error "open RDWR" || true
2560 }
2561 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2562
2563 test_33b() {
2564         rm -fr $DIR/d33
2565         test_mkdir -p $DIR/d33
2566         chown $RUNAS_ID $DIR/d33
2567         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 && error "create" || true
2568 }
2569 run_test 33b "test open file with malformed flags (No panic and return error)"
2570
2571 test_33c() {
2572         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2573         local ostnum
2574         local ostname
2575         local write_bytes
2576         local all_zeros
2577
2578         remote_ost_nodsh && skip "remote OST with nodsh" && return
2579         all_zeros=:
2580         rm -fr $DIR/d33
2581         test_mkdir -p $DIR/d33
2582         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2583
2584         sync
2585         for ostnum in $(seq $OSTCOUNT); do
2586                 # test-framework's OST numbering is one-based, while Lustre's
2587                 # is zero-based
2588                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2589                 # Parsing llobdstat's output sucks; we could grep the /proc
2590                 # path, but that's likely to not be as portable as using the
2591                 # llobdstat utility.  So we parse lctl output instead.
2592                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2593                         obdfilter/$ostname/stats |
2594                         awk '/^write_bytes/ {print $7}' )
2595                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2596                 if (( ${write_bytes:-0} > 0 ))
2597                 then
2598                         all_zeros=false
2599                         break;
2600                 fi
2601         done
2602
2603         $all_zeros || return 0
2604
2605         # Write four bytes
2606         echo foo > $DIR/d33/bar
2607         # Really write them
2608         sync
2609
2610         # Total up write_bytes after writing.  We'd better find non-zeros.
2611         for ostnum in $(seq $OSTCOUNT); do
2612                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2613                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2614                         obdfilter/$ostname/stats |
2615                         awk '/^write_bytes/ {print $7}' )
2616                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2617                 if (( ${write_bytes:-0} > 0 ))
2618                 then
2619                         all_zeros=false
2620                         break;
2621                 fi
2622         done
2623
2624         if $all_zeros
2625         then
2626                 for ostnum in $(seq $OSTCOUNT); do
2627                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2628                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2629                         do_facet ost$ostnum lctl get_param -n \
2630                                 obdfilter/$ostname/stats
2631                 done
2632                 error "OST not keeping write_bytes stats (b22312)"
2633         fi
2634 }
2635 run_test 33c "test llobdstat and write_bytes"
2636
2637 test_33d() {
2638         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2639         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2640         local MDTIDX=1
2641         local remote_dir=$DIR/$tdir/remote_dir
2642
2643         mkdir -p $DIR/$tdir
2644         $LFS mkdir -i $MDTIDX $remote_dir ||
2645                 error "create remote directory failed"
2646
2647         touch $remote_dir/$tfile
2648         chmod 444 $remote_dir/$tfile
2649         chown $RUNAS_ID $remote_dir/$tfile
2650
2651         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2652
2653         chown $RUNAS_ID $remote_dir
2654         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2655                                         error "create" || true
2656         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2657                                     error "open RDWR" || true
2658         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 &&
2659                                     error "create" || true
2660 }
2661 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2662
2663 test_33e() {
2664         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2665
2666         mkdir $DIR/$tdir
2667
2668         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2669         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2670         mkdir $DIR/$tdir/local_dir
2671
2672         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2673         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2674         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2675
2676         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2677                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2678
2679         rmdir $DIR/$tdir/* || error "rmdir failed"
2680
2681         umask 777
2682         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2683         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2684         mkdir $DIR/$tdir/local_dir
2685
2686         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2687         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2688         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2689
2690         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2691                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2692
2693         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2694
2695         umask 000
2696         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2697         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2698         mkdir $DIR/$tdir/local_dir
2699
2700         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2701         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2702         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2703
2704         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2705                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2706 }
2707 run_test 33e "mkdir and striped directory should have same mode"
2708
2709 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2710 test_34a() {
2711         rm -f $DIR/f34
2712         $MCREATE $DIR/f34 || error
2713         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2714         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2715         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2716         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2717 }
2718 run_test 34a "truncate file that has not been opened ==========="
2719
2720 test_34b() {
2721         [ ! -f $DIR/f34 ] && test_34a
2722         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2723         $OPENFILE -f O_RDONLY $DIR/f34
2724         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2725         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2726 }
2727 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2728
2729 test_34c() {
2730         [ ! -f $DIR/f34 ] && test_34a
2731         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2732         $OPENFILE -f O_RDWR $DIR/f34
2733         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2734         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2735 }
2736 run_test 34c "O_RDWR opening file-with-size works =============="
2737
2738 test_34d() {
2739         [ ! -f $DIR/f34 ] && test_34a
2740         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2741         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2742         rm $DIR/f34
2743 }
2744 run_test 34d "write to sparse file ============================="
2745
2746 test_34e() {
2747         rm -f $DIR/f34e
2748         $MCREATE $DIR/f34e || error
2749         $TRUNCATE $DIR/f34e 1000 || error
2750         $CHECKSTAT -s 1000 $DIR/f34e || error
2751         $OPENFILE -f O_RDWR $DIR/f34e
2752         $CHECKSTAT -s 1000 $DIR/f34e || error
2753 }
2754 run_test 34e "create objects, some with size and some without =="
2755
2756 test_34f() { # bug 6242, 6243
2757         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2758         SIZE34F=48000
2759         rm -f $DIR/f34f
2760         $MCREATE $DIR/f34f || error
2761         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2762         dd if=$DIR/f34f of=$TMP/f34f
2763         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2764         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2765         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2766         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2767         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2768 }
2769 run_test 34f "read from a file with no objects until EOF ======="
2770
2771 test_34g() {
2772         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2773         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2774         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2775         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2776         cancel_lru_locks osc
2777         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2778                 error "wrong size after lock cancel"
2779
2780         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2781         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2782                 error "expanding truncate failed"
2783         cancel_lru_locks osc
2784         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2785                 error "wrong expanded size after lock cancel"
2786 }
2787 run_test 34g "truncate long file ==============================="
2788
2789 test_34h() {
2790         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2791         local gid=10
2792         local sz=1000
2793
2794         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2795         sync # Flush the cache so that multiop below does not block on cache
2796              # flush when getting the group lock
2797         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2798         MULTIPID=$!
2799
2800         # Since just timed wait is not good enough, let's do a sync write
2801         # that way we are sure enough time for a roundtrip + processing
2802         # passed + 2 seconds of extra margin.
2803         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2804         rm $DIR/${tfile}-1
2805         sleep 2
2806
2807         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2808                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2809                 kill -9 $MULTIPID
2810         fi
2811         wait $MULTIPID
2812         local nsz=`stat -c %s $DIR/$tfile`
2813         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2814 }
2815 run_test 34h "ftruncate file under grouplock should not block"
2816
2817 test_35a() {
2818         cp /bin/sh $DIR/f35a
2819         chmod 444 $DIR/f35a
2820         chown $RUNAS_ID $DIR/f35a
2821         $RUNAS $DIR/f35a && error || true
2822         rm $DIR/f35a
2823 }
2824 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2825
2826 test_36a() {
2827         rm -f $DIR/f36
2828         utime $DIR/f36 || error
2829 }
2830 run_test 36a "MDS utime check (mknod, utime) ==================="
2831
2832 test_36b() {
2833         echo "" > $DIR/f36
2834         utime $DIR/f36 || error
2835 }
2836 run_test 36b "OST utime check (open, utime) ===================="
2837
2838 test_36c() {
2839         rm -f $DIR/d36/f36
2840         test_mkdir $DIR/d36
2841         chown $RUNAS_ID $DIR/d36
2842         $RUNAS utime $DIR/d36/f36 || error
2843 }
2844 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2845
2846 test_36d() {
2847         [ ! -d $DIR/d36 ] && test_36c
2848         echo "" > $DIR/d36/f36
2849         $RUNAS utime $DIR/d36/f36 || error
2850 }
2851 run_test 36d "non-root OST utime check (open, utime) ==========="
2852
2853 test_36e() {
2854         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2855         test_mkdir -p $DIR/$tdir
2856         touch $DIR/$tdir/$tfile
2857         $RUNAS utime $DIR/$tdir/$tfile && \
2858                 error "utime worked, expected failure" || true
2859 }
2860 run_test 36e "utime on non-owned file (should return error) ===="
2861
2862 subr_36fh() {
2863         local fl="$1"
2864         local LANG_SAVE=$LANG
2865         local LC_LANG_SAVE=$LC_LANG
2866         export LANG=C LC_LANG=C # for date language
2867
2868         DATESTR="Dec 20  2000"
2869         test_mkdir -p $DIR/$tdir
2870         lctl set_param fail_loc=$fl
2871         date; date +%s
2872         cp /etc/hosts $DIR/$tdir/$tfile
2873         sync & # write RPC generated with "current" inode timestamp, but delayed
2874         sleep 1
2875         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2876         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2877         cancel_lru_locks osc
2878         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2879         date; date +%s
2880         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2881                 echo "BEFORE: $LS_BEFORE" && \
2882                 echo "AFTER : $LS_AFTER" && \
2883                 echo "WANT  : $DATESTR" && \
2884                 error "$DIR/$tdir/$tfile timestamps changed" || true
2885
2886         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2887 }
2888
2889 test_36f() {
2890         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2891         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2892         subr_36fh "0x80000214"
2893 }
2894 run_test 36f "utime on file racing with OST BRW write =========="
2895
2896 test_36g() {
2897         remote_ost_nodsh && skip "remote OST with nodsh" && return
2898         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2899         local fmd_max_age
2900         local fmd_before
2901         local fmd_after
2902
2903         test_mkdir -p $DIR/$tdir
2904         fmd_max_age=$(do_facet ost1 \
2905                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2906                 head -n 1")
2907
2908         fmd_before=$(do_facet ost1 \
2909                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2910         touch $DIR/$tdir/$tfile
2911         sleep $((fmd_max_age + 12))
2912         fmd_after=$(do_facet ost1 \
2913                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2914
2915         echo "fmd_before: $fmd_before"
2916         echo "fmd_after: $fmd_after"
2917         [[ $fmd_after -gt $fmd_before ]] &&
2918                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
2919                 error "fmd didn't expire after ping" || true
2920 }
2921 run_test 36g "filter mod data cache expiry ====================="
2922
2923 test_36h() {
2924         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2925         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
2926         subr_36fh "0x80000227"
2927 }
2928 run_test 36h "utime on file racing with OST BRW write =========="
2929
2930 test_36i() {
2931         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2932
2933         mkdir $DIR/$tdir
2934         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
2935
2936         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
2937         local new_mtime=$((mtime + 200))
2938
2939         #change Modify time of striped dir
2940         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
2941                         error "change mtime failed"
2942
2943         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
2944
2945         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
2946 }
2947 run_test 36i "change mtime on striped directory"
2948
2949 # test_37 - duplicate with tests 32q 32r
2950
2951 test_38() {
2952         local file=$DIR/$tfile
2953         touch $file
2954         openfile -f O_DIRECTORY $file
2955         local RC=$?
2956         local ENOTDIR=20
2957         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
2958         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
2959 }
2960 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
2961
2962 test_39() {
2963         touch $DIR/$tfile
2964         touch $DIR/${tfile}2
2965 #       ls -l  $DIR/$tfile $DIR/${tfile}2
2966 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
2967 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
2968         sleep 2
2969         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
2970         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
2971                 echo "mtime"
2972                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
2973                 echo "atime"
2974                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
2975                 echo "ctime"
2976                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
2977                 error "O_TRUNC didn't change timestamps"
2978         fi
2979 }
2980 run_test 39 "mtime changed on create ==========================="
2981
2982 test_39b() {
2983         test_mkdir -p -c1 $DIR/$tdir
2984         cp -p /etc/passwd $DIR/$tdir/fopen
2985         cp -p /etc/passwd $DIR/$tdir/flink
2986         cp -p /etc/passwd $DIR/$tdir/funlink
2987         cp -p /etc/passwd $DIR/$tdir/frename
2988         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
2989
2990         sleep 1
2991         echo "aaaaaa" >> $DIR/$tdir/fopen
2992         echo "aaaaaa" >> $DIR/$tdir/flink
2993         echo "aaaaaa" >> $DIR/$tdir/funlink
2994         echo "aaaaaa" >> $DIR/$tdir/frename
2995
2996         local open_new=`stat -c %Y $DIR/$tdir/fopen`
2997         local link_new=`stat -c %Y $DIR/$tdir/flink`
2998         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
2999         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3000
3001         cat $DIR/$tdir/fopen > /dev/null
3002         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3003         rm -f $DIR/$tdir/funlink2
3004         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3005
3006         for (( i=0; i < 2; i++ )) ; do
3007                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3008                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3009                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3010                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3011
3012                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3013                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3014                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3015                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3016
3017                 cancel_lru_locks osc
3018                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3019         done
3020 }
3021 run_test 39b "mtime change on open, link, unlink, rename  ======"
3022
3023 # this should be set to past
3024 TEST_39_MTIME=`date -d "1 year ago" +%s`
3025
3026 # bug 11063
3027 test_39c() {
3028         touch $DIR1/$tfile
3029         sleep 2
3030         local mtime0=`stat -c %Y $DIR1/$tfile`
3031
3032         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3033         local mtime1=`stat -c %Y $DIR1/$tfile`
3034         [ "$mtime1" = $TEST_39_MTIME ] || \
3035                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3036
3037         local d1=`date +%s`
3038         echo hello >> $DIR1/$tfile
3039         local d2=`date +%s`
3040         local mtime2=`stat -c %Y $DIR1/$tfile`
3041         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3042                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3043
3044         mv $DIR1/$tfile $DIR1/$tfile-1
3045
3046         for (( i=0; i < 2; i++ )) ; do
3047                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3048                 [ "$mtime2" = "$mtime3" ] || \
3049                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3050
3051                 cancel_lru_locks osc
3052                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3053         done
3054 }
3055 run_test 39c "mtime change on rename ==========================="
3056
3057 # bug 21114
3058 test_39d() {
3059         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3060         touch $DIR1/$tfile
3061
3062         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3063
3064         for (( i=0; i < 2; i++ )) ; do
3065                 local mtime=`stat -c %Y $DIR1/$tfile`
3066                 [ $mtime = $TEST_39_MTIME ] || \
3067                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3068
3069                 cancel_lru_locks osc
3070                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3071         done
3072 }
3073 run_test 39d "create, utime, stat =============================="
3074
3075 # bug 21114
3076 test_39e() {
3077         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3078         touch $DIR1/$tfile
3079         local mtime1=`stat -c %Y $DIR1/$tfile`
3080
3081         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3082
3083         for (( i=0; i < 2; i++ )) ; do
3084                 local mtime2=`stat -c %Y $DIR1/$tfile`
3085                 [ $mtime2 = $TEST_39_MTIME ] || \
3086                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3087
3088                 cancel_lru_locks osc
3089                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3090         done
3091 }
3092 run_test 39e "create, stat, utime, stat ========================"
3093
3094 # bug 21114
3095 test_39f() {
3096         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3097         touch $DIR1/$tfile
3098         mtime1=`stat -c %Y $DIR1/$tfile`
3099
3100         sleep 2
3101         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3102
3103         for (( i=0; i < 2; i++ )) ; do
3104                 local mtime2=`stat -c %Y $DIR1/$tfile`
3105                 [ $mtime2 = $TEST_39_MTIME ] || \
3106                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3107
3108                 cancel_lru_locks osc
3109                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3110         done
3111 }
3112 run_test 39f "create, stat, sleep, utime, stat ================="
3113
3114 # bug 11063
3115 test_39g() {
3116         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3117         echo hello >> $DIR1/$tfile
3118         local mtime1=`stat -c %Y $DIR1/$tfile`
3119
3120         sleep 2
3121         chmod o+r $DIR1/$tfile
3122
3123         for (( i=0; i < 2; i++ )) ; do
3124                 local mtime2=`stat -c %Y $DIR1/$tfile`
3125                 [ "$mtime1" = "$mtime2" ] || \
3126                         error "lost mtime: $mtime2, should be $mtime1"
3127
3128                 cancel_lru_locks osc
3129                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3130         done
3131 }
3132 run_test 39g "write, chmod, stat ==============================="
3133
3134 # bug 11063
3135 test_39h() {
3136         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3137         touch $DIR1/$tfile
3138         sleep 1
3139
3140         local d1=`date`
3141         echo hello >> $DIR1/$tfile
3142         local mtime1=`stat -c %Y $DIR1/$tfile`
3143
3144         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3145         local d2=`date`
3146         if [ "$d1" != "$d2" ]; then
3147                 echo "write and touch not within one second"
3148         else
3149                 for (( i=0; i < 2; i++ )) ; do
3150                         local mtime2=`stat -c %Y $DIR1/$tfile`
3151                         [ "$mtime2" = $TEST_39_MTIME ] || \
3152                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3153
3154                         cancel_lru_locks osc
3155                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3156                 done
3157         fi
3158 }
3159 run_test 39h "write, utime within one second, stat ============="
3160
3161 test_39i() {
3162         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3163         touch $DIR1/$tfile
3164         sleep 1
3165
3166         echo hello >> $DIR1/$tfile
3167         local mtime1=`stat -c %Y $DIR1/$tfile`
3168
3169         mv $DIR1/$tfile $DIR1/$tfile-1
3170
3171         for (( i=0; i < 2; i++ )) ; do
3172                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3173
3174                 [ "$mtime1" = "$mtime2" ] || \
3175                         error "lost mtime: $mtime2, should be $mtime1"
3176
3177                 cancel_lru_locks osc
3178                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3179         done
3180 }
3181 run_test 39i "write, rename, stat =============================="
3182
3183 test_39j() {
3184         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3185         start_full_debug_logging
3186         touch $DIR1/$tfile
3187         sleep 1
3188
3189         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3190         lctl set_param fail_loc=0x80000412
3191         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3192                 error "multiop failed"
3193         local multipid=$!
3194         local mtime1=`stat -c %Y $DIR1/$tfile`
3195
3196         mv $DIR1/$tfile $DIR1/$tfile-1
3197
3198         kill -USR1 $multipid
3199         wait $multipid || error "multiop close failed"
3200
3201         for (( i=0; i < 2; i++ )) ; do
3202                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3203                 [ "$mtime1" = "$mtime2" ] ||
3204                         error "mtime is lost on close: $mtime2, " \
3205                               "should be $mtime1"
3206
3207                 cancel_lru_locks osc
3208                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3209         done
3210         lctl set_param fail_loc=0
3211         stop_full_debug_logging
3212 }
3213 run_test 39j "write, rename, close, stat ======================="
3214
3215 test_39k() {
3216         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3217         touch $DIR1/$tfile
3218         sleep 1
3219
3220         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3221         local multipid=$!
3222         local mtime1=`stat -c %Y $DIR1/$tfile`
3223
3224         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3225
3226         kill -USR1 $multipid
3227         wait $multipid || error "multiop close failed"
3228
3229         for (( i=0; i < 2; i++ )) ; do
3230                 local mtime2=`stat -c %Y $DIR1/$tfile`
3231
3232                 [ "$mtime2" = $TEST_39_MTIME ] || \
3233                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3234
3235                 cancel_lru_locks osc
3236                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3237         done
3238 }
3239 run_test 39k "write, utime, close, stat ========================"
3240
3241 # this should be set to future
3242 TEST_39_ATIME=`date -d "1 year" +%s`
3243
3244 test_39l() {
3245         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3246         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3247         local atime_diff=$(do_facet $SINGLEMDS \
3248                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3249         rm -rf $DIR/$tdir
3250         mkdir -p $DIR/$tdir
3251
3252         # test setting directory atime to future
3253         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3254         local atime=$(stat -c %X $DIR/$tdir)
3255         [ "$atime" = $TEST_39_ATIME ] || \
3256                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3257
3258         # test setting directory atime from future to now
3259         local d1=$(date +%s)
3260         ls $DIR/$tdir
3261         local d2=$(date +%s)
3262
3263         cancel_lru_locks mdc
3264         atime=$(stat -c %X $DIR/$tdir)
3265         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3266                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3267
3268         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3269         sleep 3
3270
3271         # test setting directory atime when now > dir atime + atime_diff
3272         d1=$(date +%s)
3273         ls $DIR/$tdir
3274         d2=$(date +%s)
3275         cancel_lru_locks mdc
3276         atime=$(stat -c %X $DIR/$tdir)
3277         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3278                 error "atime is not updated  : $atime, should be $d2"
3279
3280         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3281         sleep 3
3282
3283         # test not setting directory atime when now < dir atime + atime_diff
3284         ls $DIR/$tdir
3285         cancel_lru_locks mdc
3286         atime=$(stat -c %X $DIR/$tdir)
3287         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3288                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3289
3290         do_facet $SINGLEMDS \
3291                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3292 }
3293 run_test 39l "directory atime update ==========================="
3294
3295 test_39m() {
3296         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3297         touch $DIR1/$tfile
3298         sleep 2
3299         local far_past_mtime=$(date -d "May 29 1953" +%s)
3300         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3301
3302         touch -m -d @$far_past_mtime $DIR1/$tfile
3303         touch -a -d @$far_past_atime $DIR1/$tfile
3304
3305         for (( i=0; i < 2; i++ )) ; do
3306                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3307                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3308                         error "atime or mtime set incorrectly"
3309
3310                 cancel_lru_locks osc
3311                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3312         done
3313 }
3314 run_test 39m "test atime and mtime before 1970"
3315
3316 test_39n() { # LU-3832
3317         local atime_diff=$(do_facet $SINGLEMDS \
3318                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3319         local atime0
3320         local atime1
3321         local atime2
3322
3323         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3324
3325         rm -rf $DIR/$tfile
3326         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3327         atime0=$(stat -c %X $DIR/$tfile)
3328
3329         sleep 5
3330         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3331         atime1=$(stat -c %X $DIR/$tfile)
3332
3333         sleep 5
3334         cancel_lru_locks mdc
3335         cancel_lru_locks osc
3336         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3337         atime2=$(stat -c %X $DIR/$tfile)
3338
3339         do_facet $SINGLEMDS \
3340                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3341
3342         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3343         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3344 }
3345 run_test 39n "check that O_NOATIME is honored"
3346
3347 test_39o() {
3348         TESTDIR=$DIR/$tdir/$tfile
3349         [ -e $TESTDIR ] && rm -rf $TESTDIR
3350         test_mkdir -p $TESTDIR
3351         cd $TESTDIR
3352         links1=2
3353         ls
3354         mkdir a b
3355         ls
3356         links2=$(stat -c %h .)
3357         [ $(($links1 + 2)) != $links2 ] &&
3358                 error "wrong links count $(($links1 + 2)) != $links2"
3359         rmdir b
3360         links3=$(stat -c %h .)
3361         [ $(($links1 + 1)) != $links3 ] &&
3362                 error "wrong links count $links1 != $links3"
3363         return 0
3364 }
3365 run_test 39o "directory cached attributes updated after create ========"
3366
3367 test_39p() {
3368         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3369         local MDTIDX=1
3370         TESTDIR=$DIR/$tdir/$tfile
3371         [ -e $TESTDIR ] && rm -rf $TESTDIR
3372         mkdir -p $TESTDIR
3373         cd $TESTDIR
3374         links1=2
3375         ls
3376         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3377         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3378         ls
3379         links2=$(stat -c %h .)
3380         [ $(($links1 + 2)) != $links2 ] &&
3381                 error "wrong links count $(($links1 + 2)) != $links2"
3382         rmdir remote_dir2
3383         links3=$(stat -c %h .)
3384         [ $(($links1 + 1)) != $links3 ] &&
3385                 error "wrong links count $links1 != $links3"
3386         return 0
3387 }
3388 run_test 39p "remote directory cached attributes updated after create ========"
3389
3390
3391 test_40() {
3392         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3393         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3394                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3395         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3396                 error "$tfile is not 4096 bytes in size"
3397 }
3398 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3399
3400 test_41() {
3401         # bug 1553
3402         small_write $DIR/f41 18
3403 }
3404 run_test 41 "test small file write + fstat ====================="
3405
3406 count_ost_writes() {
3407         lctl get_param -n osc.*.stats |
3408                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3409                         END { printf("%0.0f", writes) }'
3410 }
3411
3412 # decent default
3413 WRITEBACK_SAVE=500
3414 DIRTY_RATIO_SAVE=40
3415 MAX_DIRTY_RATIO=50
3416 BG_DIRTY_RATIO_SAVE=10
3417 MAX_BG_DIRTY_RATIO=25
3418
3419 start_writeback() {
3420         trap 0
3421         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3422         # dirty_ratio, dirty_background_ratio
3423         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3424                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3425                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3426                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3427         else
3428                 # if file not here, we are a 2.4 kernel
3429                 kill -CONT `pidof kupdated`
3430         fi
3431 }
3432
3433 stop_writeback() {
3434         # setup the trap first, so someone cannot exit the test at the
3435         # exact wrong time and mess up a machine
3436         trap start_writeback EXIT
3437         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3438         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3439                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3440                 sysctl -w vm.dirty_writeback_centisecs=0
3441                 sysctl -w vm.dirty_writeback_centisecs=0
3442                 # save and increase /proc/sys/vm/dirty_ratio
3443                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3444                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3445                 # save and increase /proc/sys/vm/dirty_background_ratio
3446                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3447                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3448         else
3449                 # if file not here, we are a 2.4 kernel
3450                 kill -STOP `pidof kupdated`
3451         fi
3452 }
3453
3454 # ensure that all stripes have some grant before we test client-side cache
3455 setup_test42() {
3456         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3457                 dd if=/dev/zero of=$i bs=4k count=1
3458                 rm $i
3459         done
3460 }
3461
3462 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3463 # file truncation, and file removal.
3464 test_42a() {
3465         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3466         setup_test42
3467         cancel_lru_locks osc
3468         stop_writeback
3469         sync; sleep 1; sync # just to be safe
3470         BEFOREWRITES=`count_ost_writes`
3471         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3472         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3473         AFTERWRITES=`count_ost_writes`
3474         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3475                 error "$BEFOREWRITES < $AFTERWRITES"
3476         start_writeback
3477 }
3478 run_test 42a "ensure that we don't flush on close =============="
3479
3480 test_42b() {
3481         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3482         setup_test42
3483         cancel_lru_locks osc
3484         stop_writeback
3485         sync
3486         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3487         BEFOREWRITES=$(count_ost_writes)
3488         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3489         AFTERWRITES=$(count_ost_writes)
3490         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3491                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3492         fi
3493         BEFOREWRITES=$(count_ost_writes)
3494         sync || error "sync: $?"
3495         AFTERWRITES=$(count_ost_writes)
3496         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3497                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3498         fi
3499         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3500         start_writeback
3501         return 0
3502 }
3503 run_test 42b "test destroy of file with cached dirty data ======"
3504
3505 # if these tests just want to test the effect of truncation,
3506 # they have to be very careful.  consider:
3507 # - the first open gets a {0,EOF}PR lock
3508 # - the first write conflicts and gets a {0, count-1}PW
3509 # - the rest of the writes are under {count,EOF}PW
3510 # - the open for truncate tries to match a {0,EOF}PR
3511 #   for the filesize and cancels the PWs.
3512 # any number of fixes (don't get {0,EOF} on open, match
3513 # composite locks, do smarter file size management) fix
3514 # this, but for now we want these tests to verify that
3515 # the cancellation with truncate intent works, so we
3516 # start the file with a full-file pw lock to match against
3517 # until the truncate.
3518 trunc_test() {
3519         test=$1
3520         file=$DIR/$test
3521         offset=$2
3522         cancel_lru_locks osc
3523         stop_writeback
3524         # prime the file with 0,EOF PW to match
3525         touch $file
3526         $TRUNCATE $file 0
3527         sync; sync
3528         # now the real test..
3529         dd if=/dev/zero of=$file bs=1024 count=100
3530         BEFOREWRITES=`count_ost_writes`
3531         $TRUNCATE $file $offset
3532         cancel_lru_locks osc
3533         AFTERWRITES=`count_ost_writes`
3534         start_writeback
3535 }
3536
3537 test_42c() {
3538         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3539         trunc_test 42c 1024
3540         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3541             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3542         rm $file
3543 }
3544 run_test 42c "test partial truncate of file with cached dirty data"
3545
3546 test_42d() {
3547         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3548         trunc_test 42d 0
3549         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3550             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3551         rm $file
3552 }
3553 run_test 42d "test complete truncate of file with cached dirty data"
3554
3555 test_42e() { # bug22074
3556         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3557         local TDIR=$DIR/${tdir}e
3558         local pagesz=$(page_size)
3559         local pages=16 # hardcoded 16 pages, don't change it.
3560         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3561         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3562         local max_dirty_mb
3563         local warmup_files
3564
3565         test_mkdir -p $DIR/${tdir}e
3566         $SETSTRIPE -c 1 $TDIR
3567         createmany -o $TDIR/f $files
3568
3569         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3570
3571         # we assume that with $OSTCOUNT files, at least one of them will
3572         # be allocated on OST0.
3573         warmup_files=$((OSTCOUNT * max_dirty_mb))
3574         createmany -o $TDIR/w $warmup_files
3575
3576         # write a large amount of data into one file and sync, to get good
3577         # avail_grant number from OST.
3578         for ((i=0; i<$warmup_files; i++)); do
3579                 idx=$($GETSTRIPE -i $TDIR/w$i)
3580                 [ $idx -ne 0 ] && continue
3581                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3582                 break
3583         done
3584         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3585         sync
3586         $LCTL get_param $proc_osc0/cur_dirty_bytes
3587         $LCTL get_param $proc_osc0/cur_grant_bytes
3588
3589         # create as much dirty pages as we can while not to trigger the actual
3590         # RPCs directly. but depends on the env, VFS may trigger flush during this
3591         # period, hopefully we are good.
3592         for ((i=0; i<$warmup_files; i++)); do
3593                 idx=$($GETSTRIPE -i $TDIR/w$i)
3594                 [ $idx -ne 0 ] && continue
3595                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3596         done
3597         $LCTL get_param $proc_osc0/cur_dirty_bytes
3598         $LCTL get_param $proc_osc0/cur_grant_bytes
3599
3600         # perform the real test
3601         $LCTL set_param $proc_osc0/rpc_stats 0
3602         for ((;i<$files; i++)); do
3603                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3604                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3605         done
3606         sync
3607         $LCTL get_param $proc_osc0/rpc_stats
3608
3609         local percent=0
3610         local have_ppr=false
3611         $LCTL get_param $proc_osc0/rpc_stats |
3612                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3613                         # skip lines until we are at the RPC histogram data
3614                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3615                         $have_ppr || continue
3616
3617                         # we only want the percent stat for < 16 pages
3618                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3619
3620                         percent=$((percent + WPCT))
3621                         if [[ $percent -gt 15 ]]; then
3622                                 error "less than 16-pages write RPCs" \
3623                                       "$percent% > 15%"
3624                                 break
3625                         fi
3626                 done
3627         rm -rf $TDIR
3628 }
3629 run_test 42e "verify sub-RPC writes are not done synchronously"
3630
3631 test_43() {
3632         test_mkdir -p $DIR/$tdir
3633         cp -p /bin/ls $DIR/$tdir/$tfile
3634         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3635         pid=$!
3636         # give multiop a chance to open
3637         sleep 1
3638
3639         $DIR/$tdir/$tfile && error || true
3640         kill -USR1 $pid
3641 }
3642 run_test 43 "execution of file opened for write should return -ETXTBSY"
3643
3644 test_43a() {
3645         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3646         test_mkdir -p $DIR/$tdir
3647         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3648                         cp -p multiop $DIR/$tdir/multiop
3649         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3650                         return 1
3651         MULTIOP_PID=$!
3652         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3653         kill -USR1 $MULTIOP_PID || return 2
3654         wait $MULTIOP_PID || return 3
3655         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3656 }
3657 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3658
3659 test_43b() {
3660         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3661         test_mkdir -p $DIR/$tdir
3662         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3663                         cp -p multiop $DIR/$tdir/multiop
3664         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3665                         return 1
3666         MULTIOP_PID=$!
3667         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3668         kill -USR1 $MULTIOP_PID || return 2
3669         wait $MULTIOP_PID || return 3
3670         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3671 }
3672 run_test 43b "truncate of file being executed should return -ETXTBSY"
3673
3674 test_43c() {
3675         local testdir="$DIR/$tdir"
3676         test_mkdir -p $DIR/$tdir
3677         cp $SHELL $testdir/
3678         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3679                 ( cd $testdir && md5sum -c)
3680 }
3681 run_test 43c "md5sum of copy into lustre========================"
3682
3683 test_44() {
3684         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3685         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3686         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3687 }
3688 run_test 44 "zero length read from a sparse stripe ============="
3689
3690 test_44a() {
3691         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3692                 awk '{ print $2 }')
3693         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3694         [[ $nstripe -gt $OSTCOUNT ]] &&
3695             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3696             return
3697         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3698                 awk '{ print $2 }')
3699         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3700                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3701                         awk '{ print $2 }')
3702         fi
3703
3704         OFFSETS="0 $((stride/2)) $((stride-1))"
3705         for offset in $OFFSETS; do
3706                 for i in $(seq 0 $((nstripe-1))); do
3707                         local GLOBALOFFSETS=""
3708                         # size in Bytes
3709                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3710                         local myfn=$DIR/d44a-$size
3711                         echo "--------writing $myfn at $size"
3712                         ll_sparseness_write $myfn $size ||
3713                                 error "ll_sparseness_write"
3714                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3715                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3716                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3717
3718                         for j in $(seq 0 $((nstripe-1))); do
3719                                 # size in Bytes
3720                                 size=$((((j + $nstripe )*$stride + $offset)))
3721                                 ll_sparseness_write $myfn $size ||
3722                                         error "ll_sparseness_write"
3723                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3724                         done
3725                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3726                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3727                         rm -f $myfn
3728                 done
3729         done
3730 }
3731 run_test 44a "test sparse pwrite ==============================="
3732
3733 dirty_osc_total() {
3734         tot=0
3735         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3736                 tot=$(($tot + $d))
3737         done
3738         echo $tot
3739 }
3740 do_dirty_record() {
3741         before=`dirty_osc_total`
3742         echo executing "\"$*\""
3743         eval $*
3744         after=`dirty_osc_total`
3745         echo before $before, after $after
3746 }
3747 test_45() {
3748         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3749         f="$DIR/f45"
3750         # Obtain grants from OST if it supports it
3751         echo blah > ${f}_grant
3752         stop_writeback
3753         sync
3754         do_dirty_record "echo blah > $f"
3755         [[ $before -eq $after ]] && error "write wasn't cached"
3756         do_dirty_record "> $f"
3757         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3758         do_dirty_record "echo blah > $f"
3759         [[ $before -eq $after ]] && error "write wasn't cached"
3760         do_dirty_record "sync"
3761         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3762         do_dirty_record "echo blah > $f"
3763         [[ $before -eq $after ]] && error "write wasn't cached"
3764         do_dirty_record "cancel_lru_locks osc"
3765         [[ $before -gt $after ]] ||
3766                 error "lock cancellation didn't lower dirty count"
3767         start_writeback
3768 }
3769 run_test 45 "osc io page accounting ============================"
3770
3771 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3772 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3773 # objects offset and an assert hit when an rpc was built with 1023's mapped
3774 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3775 test_46() {
3776         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3777         f="$DIR/f46"
3778         stop_writeback
3779         sync
3780         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3781         sync
3782         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3783         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3784         sync
3785         start_writeback
3786 }
3787 run_test 46 "dirtying a previously written page ================"
3788
3789 # test_47 is removed "Device nodes check" is moved to test_28
3790
3791 test_48a() { # bug 2399
3792         check_kernel_version 34 || return 0
3793         test_mkdir -p $DIR/$tdir
3794         cd $DIR/$tdir
3795         mv $DIR/$tdir $DIR/d48.new || error "move directory failed"
3796         test_mkdir $DIR/$tdir || error "recreate directory failed"
3797         touch foo || error "'touch foo' failed after recreating cwd"
3798         test_mkdir $DIR/$tdir/bar ||
3799                      error "'mkdir foo' failed after recreating cwd"
3800         if check_kernel_version 44; then
3801                 touch .foo || error "'touch .foo' failed after recreating cwd"
3802                 test_mkdir $DIR/$tdir/.bar ||
3803                               error "'mkdir .foo' failed after recreating cwd"
3804         fi
3805         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3806         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3807         cd . || error "'cd .' failed after recreating cwd"
3808         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3809         rmdir . && error "'rmdir .' worked after recreating cwd"
3810         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3811         cd .. || error "'cd ..' failed after recreating cwd"
3812 }
3813 run_test 48a "Access renamed working dir (should return errors)="
3814
3815 test_48b() { # bug 2399
3816         check_kernel_version 34 || return 0
3817         rm -rf $DIR/$tdir
3818         test_mkdir -p $DIR/$tdir
3819         cd $DIR/$tdir
3820         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3821         touch foo && error "'touch foo' worked after removing cwd"
3822         test_mkdir $DIR/$tdir/foo &&
3823                      error "'mkdir foo' worked after removing cwd"
3824         if check_kernel_version 44; then
3825                 touch .foo && error "'touch .foo' worked after removing cwd"
3826                 test_mkdir $DIR/$tdir/.foo &&
3827                               error "'mkdir .foo' worked after removing cwd"
3828         fi
3829         ls . > /dev/null && error "'ls .' worked after removing cwd"
3830         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3831         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3832         test_mkdir $DIR/$tdir/. && error "'mkdir .' worked after removing cwd"
3833         rmdir . && error "'rmdir .' worked after removing cwd"
3834         ln -s . foo && error "'ln -s .' worked after removing cwd"
3835         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3836 }
3837 run_test 48b "Access removed working dir (should return errors)="
3838
3839 test_48c() { # bug 2350
3840         check_kernel_version 36 || return 0
3841         #lctl set_param debug=-1
3842         #set -vx
3843         rm -rf $DIR/$tdir
3844         test_mkdir -p $DIR/$tdir/dir
3845         cd $DIR/$tdir/dir
3846         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3847         $TRACE touch foo && error "touch foo worked after removing cwd"
3848         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3849         if check_kernel_version 44; then
3850                 touch .foo && error "touch .foo worked after removing cwd"
3851                 test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3852         fi
3853         $TRACE ls . && error "'ls .' worked after removing cwd"
3854         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3855         is_patchless || ( $TRACE cd . &&
3856                         error "'cd .' worked after removing cwd" )
3857         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3858         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3859         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3860         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3861 }
3862 run_test 48c "Access removed working subdir (should return errors)"
3863
3864 test_48d() { # bug 2350
3865         check_kernel_version 36 || return 0
3866         #lctl set_param debug=-1
3867         #set -vx
3868         rm -rf $DIR/$tdir
3869         test_mkdir -p $DIR/$tdir/dir
3870         cd $DIR/$tdir/dir
3871         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3872         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3873         $TRACE touch foo && error "'touch foo' worked after removing parent"
3874         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3875         if check_kernel_version 44; then
3876                 touch .foo && error "'touch .foo' worked after removing parent"
3877                 test_mkdir .foo &&
3878                               error "mkdir .foo worked after removing parent"
3879         fi
3880         $TRACE ls . && error "'ls .' worked after removing parent"
3881         $TRACE ls .. && error "'ls ..' worked after removing parent"
3882         is_patchless || ( $TRACE cd . &&
3883                         error "'cd .' worked after recreate parent" )
3884         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3885         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3886         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3887         is_patchless || ( $TRACE cd .. &&
3888                         error "'cd ..' worked after removing parent" || true )
3889 }
3890 run_test 48d "Access removed parent subdir (should return errors)"
3891
3892 test_48e() { # bug 4134
3893         check_kernel_version 41 || return 0
3894         #lctl set_param debug=-1
3895         #set -vx
3896         rm -rf $DIR/$tdir
3897         test_mkdir -p $DIR/$tdir/dir
3898         cd $DIR/$tdir/dir
3899         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3900         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3901         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3902         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3903         # On a buggy kernel addition of "touch foo" after cd .. will
3904         # produce kernel oops in lookup_hash_it
3905         touch ../foo && error "'cd ..' worked after recreate parent"
3906         cd $DIR
3907         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3908 }
3909 run_test 48e "Access to recreated parent subdir (should return errors)"
3910
3911 test_49() { # LU-1030
3912         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3913         # get ost1 size - lustre-OST0000
3914         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3915                 awk '{ print $4 }')
3916         # write 800M at maximum
3917         [[ $ost1_size -lt 2 ]] && ost1_size=2
3918         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3919
3920         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3921         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3922         local dd_pid=$!
3923
3924         # change max_pages_per_rpc while writing the file
3925         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3926         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3927         # loop until dd process exits
3928         while ps ax -opid | grep -wq $dd_pid; do
3929                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3930                 sleep $((RANDOM % 5 + 1))
3931         done
3932         # restore original max_pages_per_rpc
3933         $LCTL set_param $osc1_mppc=$orig_mppc
3934         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3935 }
3936 run_test 49 "Change max_pages_per_rpc won't break osc extent"
3937
3938 test_50() {
3939         # bug 1485
3940         test_mkdir $DIR/$tdir
3941         cd $DIR/$tdir
3942         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
3943 }
3944 run_test 50 "special situations: /proc symlinks  ==============="
3945
3946 test_51a() {    # was test_51
3947         # bug 1516 - create an empty entry right after ".." then split dir
3948         test_mkdir -c1 $DIR/$tdir
3949         touch $DIR/$tdir/foo
3950         $MCREATE $DIR/$tdir/bar
3951         rm $DIR/$tdir/foo
3952         createmany -m $DIR/$tdir/longfile 201
3953         FNUM=202
3954         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
3955                 $MCREATE $DIR/$tdir/longfile$FNUM
3956                 FNUM=$(($FNUM + 1))
3957                 echo -n "+"
3958         done
3959         echo
3960         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
3961 }
3962 run_test 51a "special situations: split htree with empty entry =="
3963
3964 export NUMTEST=70000
3965 test_51b() {
3966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3967         local BASE=$DIR/d${base}.${TESTSUITE}
3968
3969         # cleanup the directory
3970         rm -fr $BASE
3971
3972         test_mkdir -p -c1 $BASE
3973
3974         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
3975         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
3976         [[ $numfree -lt 21000 ]] && skip "not enough free inodes ($numfree)" &&
3977                 return
3978
3979         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3980                 echo "reduced count to $NUMTEST due to inodes"
3981
3982         # need to check free space for the directories as well
3983         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
3984         numfree=$((blkfree / 4))
3985         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
3986                 echo "reduced count to $NUMTEST due to blocks"
3987
3988         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
3989                 echo "failed" > $BASE/fnum
3990 }
3991 run_test 51b "exceed 64k subdirectory nlink limit"
3992
3993 test_51ba() { # LU-993
3994         local BASE=$DIR/d${base}.${TESTSUITE}
3995         # unlink all but 100 subdirectories, then check it still works
3996         local LEFT=100
3997         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
3998
3999         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
4000         local DELETE=$((NUMTEST - LEFT))
4001
4002         # continue on to run this test even if 51b didn't finish,
4003         # just to delete the many subdirectories created.
4004         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
4005
4006         # for ldiskfs the nlink count should be 1, but this is OSD specific
4007         # and so this is listed for informational purposes only
4008         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
4009         unlinkmany -d $BASE/d $DELETE
4010         RC=$?
4011
4012         if [ $RC -ne 0 ]; then
4013                 if [ "$NUMPREV" == "failed" ]; then
4014                         skip "previous setup failed"
4015                         return 0
4016                 else
4017                         error "unlink of first $DELETE subdirs failed"
4018                         return $RC
4019                 fi
4020         fi
4021
4022         echo "nlink between: $(stat -c %h $BASE)"
4023         # trim the first line of ls output
4024         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
4025         [ $FOUND -ne $LEFT ] &&
4026                 error "can't find subdirs: found only $FOUND/$LEFT"
4027
4028         unlinkmany -d $BASE/d $DELETE $LEFT ||
4029                 error "unlink of second $LEFT subdirs failed"
4030         # regardless of whether the backing filesystem tracks nlink accurately
4031         # or not, the nlink count shouldn't be more than "." and ".." here
4032         local AFTER=$(stat -c %h $BASE)
4033         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
4034                 echo "nlink after: $AFTER"
4035 }
4036 run_test 51ba "verify nlink for many subdirectory cleanup"
4037
4038 test_51d() {
4039         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4040         [[ $OSTCOUNT -lt 3 ]] &&
4041                 skip_env "skipping test with few OSTs" && return
4042         test_mkdir -p $DIR/$tdir
4043         createmany -o $DIR/$tdir/t- 1000
4044         $GETSTRIPE $DIR/$tdir > $TMP/files
4045         for N in $(seq 0 $((OSTCOUNT - 1))); do
4046                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4047                         END { printf("%0.0f", objs) }' $TMP/files)
4048                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
4049                         '($1 == '$N') { objs += 1 } \
4050                         END { printf("%0.0f", objs) }')
4051                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4052         done
4053         unlinkmany $DIR/$tdir/t- 1000
4054
4055         NLAST=0
4056         for N in $(seq 1 $((OSTCOUNT - 1))); do
4057                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4058                         error "OST $N has less objects vs OST $NLAST" \
4059                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4060                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4061                         error "OST $N has less objects vs OST $NLAST" \
4062                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4063
4064                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4065                         error "OST $N has less #0 objects vs OST $NLAST" \
4066                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4067                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4068                         error "OST $N has less #0 objects vs OST $NLAST" \
4069                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4070                 NLAST=$N
4071         done
4072 }
4073 run_test 51d "check object distribution ===================="
4074
4075 test_52a() {
4076         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4077         test_mkdir -p $DIR/$tdir
4078         touch $DIR/$tdir/foo
4079         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4080         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4081         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4082         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4083         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4084                                         error "link worked"
4085         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4086         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4087         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4088                                                      error "lsattr"
4089         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4090         cp -r $DIR/$tdir /tmp/
4091         rm -fr $DIR/$tdir || error "cleanup rm failed"
4092 }
4093 run_test 52a "append-only flag test (should return errors) ====="
4094
4095 test_52b() {
4096         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4097         test_mkdir -p $DIR/$tdir
4098         touch $DIR/$tdir/foo
4099         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4100         cat test > $DIR/$tdir/foo && error "cat test worked"
4101         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4102         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4103         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4104                                         error "link worked"
4105         echo foo >> $DIR/$tdir/foo && error "echo worked"
4106         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4107         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4108         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4109         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4110                                                         error "lsattr"
4111         chattr -i $DIR/$tdir/foo || error "chattr failed"
4112
4113         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4114 }
4115 run_test 52b "immutable flag test (should return errors) ======="
4116
4117 test_53() {
4118         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4119         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4120         remote_ost_nodsh && skip "remote OST with nodsh" && return
4121
4122         local param
4123         local param_seq
4124         local ostname
4125         local mds_last
4126         local mds_last_seq
4127         local ost_last
4128         local ost_last_seq
4129         local ost_last_id
4130         local ostnum
4131         local node
4132         local found=false
4133         local support_last_seq=true
4134
4135         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4136                 support_last_seq=false
4137
4138         # only test MDT0000
4139         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4140         local value
4141         for value in $(do_facet $SINGLEMDS \
4142                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4143                 param=$(echo ${value[0]} | cut -d "=" -f1)
4144                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4145
4146                 if $support_last_seq; then
4147                         param_seq=$(echo $param |
4148                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4149                         mds_last_seq=$(do_facet $SINGLEMDS \
4150                                        $LCTL get_param -n $param_seq)
4151                 fi
4152                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4153
4154                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4155                 node=$(facet_active_host ost$((ostnum+1)))
4156                 param="obdfilter.$ostname.last_id"
4157                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4158                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4159                         ost_last_id=$ost_last
4160
4161                         if $support_last_seq; then
4162                                 ost_last_id=$(echo $ost_last |
4163                                               awk -F':' '{print $2}' |
4164                                               sed -e "s/^0x//g")
4165                                 ost_last_seq=$(echo $ost_last |
4166                                                awk -F':' '{print $1}')
4167                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4168                         fi
4169
4170                         if [[ $ost_last_id != $mds_last ]]; then
4171                                 error "$ost_last_id != $mds_last"
4172                         else
4173                                 found=true
4174                                 break
4175                         fi
4176                 done
4177         done
4178         $found || error "can not match last_seq/last_id for $mdtosc"
4179         return 0
4180 }
4181 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4182
4183 test_54a() {
4184         $SOCKETSERVER $DIR/socket ||
4185                 error "$SOCKETSERVER $DIR/socket failed: $?"
4186         $SOCKETCLIENT $DIR/socket ||
4187                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4188         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4189 }
4190 run_test 54a "unix domain socket test =========================="
4191
4192 test_54b() {
4193         f="$DIR/f54b"
4194         mknod $f c 1 3
4195         chmod 0666 $f
4196         dd if=/dev/zero of=$f bs=$(page_size) count=1
4197 }
4198 run_test 54b "char device works in lustre ======================"
4199
4200 find_loop_dev() {
4201         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4202         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4203         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4204
4205         for i in $(seq 3 7); do
4206                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4207                 LOOPDEV=$LOOPBASE$i
4208                 LOOPNUM=$i
4209                 break
4210         done
4211 }
4212
4213 cleanup_54c() {
4214         loopdev="$DIR/loop54c"
4215
4216         trap 0
4217         $UMOUNT -d $tdir || rc=$?
4218         losetup -d $loopdev || true
4219         rm $loopdev
4220         return $rc
4221 }
4222
4223 test_54c() {
4224         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4225         tfile="$DIR/f54c"
4226         tdir="$DIR/d54c"
4227         loopdev="$DIR/loop54c"
4228
4229         find_loop_dev
4230         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4231         mknod $loopdev b 7 $LOOPNUM
4232         echo "make a loop file system with $tfile on $loopdev ($LOOPNUM)..."
4233         dd if=/dev/zero of=$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4234         losetup $loopdev $tfile || error "can't set up $loopdev for $tfile"
4235         trap cleanup_54c EXIT
4236         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4237         test_mkdir -p $tdir
4238         mount -t ext2 $loopdev $tdir || error "error mounting $loopdev on $tdir"
4239         dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
4240         df $tdir
4241         dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
4242         cleanup_54c
4243 }
4244 run_test 54c "block device works in lustre ====================="
4245
4246 test_54d() {
4247         f="$DIR/f54d"
4248         string="aaaaaa"
4249         mknod $f p
4250         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4251 }
4252 run_test 54d "fifo device works in lustre ======================"
4253
4254 test_54e() {
4255         check_kernel_version 46 || return 0
4256         f="$DIR/f54e"
4257         string="aaaaaa"
4258         cp -aL /dev/console $f
4259         echo $string > $f || error "echo $string to $f failed"
4260 }
4261 run_test 54e "console/tty device works in lustre ======================"
4262
4263 #The test_55 used to be iopen test and it was removed by bz#24037.
4264 #run_test 55 "check iopen_connect_dentry() ======================"
4265
4266 test_56a() {    # was test_56
4267         rm -rf $DIR/$tdir
4268         $SETSTRIPE -d $DIR
4269         test_mkdir -p $DIR/$tdir/dir
4270         NUMFILES=3
4271         NUMFILESx2=$(($NUMFILES * 2))
4272         for i in $(seq 1 $NUMFILES); do
4273                 touch $DIR/$tdir/file$i
4274                 touch $DIR/$tdir/dir/file$i
4275         done
4276
4277         # test lfs getstripe with --recursive
4278         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4279         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4280                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4281         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4282         [[ $FILENUM -eq $NUMFILES ]] ||
4283                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4284         echo "$GETSTRIPE --recursive passed."
4285
4286         # test lfs getstripe with file instead of dir
4287         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4288         [[ $FILENUM -eq 1 ]] ||
4289                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4290         echo "$GETSTRIPE file1 passed."
4291
4292         #test lfs getstripe with --verbose
4293         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4294                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4295                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4296         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4297                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4298         echo "$GETSTRIPE --verbose passed."
4299
4300         #test lfs getstripe with --obd
4301         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4302                 grep -q "unknown obduuid" ||
4303                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4304
4305         [[ $OSTCOUNT -lt 2 ]] &&
4306                 skip_env "skipping other $GETSTRIPE --obd test" && return
4307
4308         OSTIDX=1
4309         OBDUUID=$(ostuuid_from_index $OSTIDX)
4310         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4311         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4312         [[ $FOUND -eq $FILENUM ]] ||
4313                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4314         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4315                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4316                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4317                 error "$GETSTRIPE --obd: should not show file on other obd"
4318         echo "$GETSTRIPE --obd passed"
4319 }
4320 run_test 56a "check $GETSTRIPE"
4321
4322 NUMFILES=3
4323 NUMDIRS=3
4324 setup_56() {
4325         local LOCAL_NUMFILES="$1"
4326         local LOCAL_NUMDIRS="$2"
4327         local MKDIR_PARAMS="$3"
4328         local DIR_STRIPE_PARAMS="$4"
4329
4330         if [ ! -d "$TDIR" ] ; then
4331                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4332                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4333                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4334                         touch $TDIR/file$i
4335                 done
4336                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4337                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4338                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4339                                 touch $TDIR/dir$i/file$j
4340                         done
4341                 done
4342         fi
4343 }
4344
4345 setup_56_special() {
4346         LOCAL_NUMFILES=$1
4347         LOCAL_NUMDIRS=$2
4348         setup_56 $1 $2
4349         if [ ! -e "$TDIR/loop1b" ] ; then
4350                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4351                         mknod $TDIR/loop${i}b b 7 $i
4352                         mknod $TDIR/null${i}c c 1 3
4353                         ln -s $TDIR/file1 $TDIR/link${i}l
4354                 done
4355                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4356                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4357                         mknod $TDIR/dir$i/null${i}c c 1 3
4358                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4359                 done
4360         fi
4361 }
4362
4363 test_56g() {
4364         $SETSTRIPE -d $DIR
4365
4366         TDIR=$DIR/${tdir}g
4367         setup_56 $NUMFILES $NUMDIRS
4368
4369         EXPECTED=$(($NUMDIRS + 2))
4370         # test lfs find with -name
4371         for i in $(seq 1 $NUMFILES) ; do
4372                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4373                 [ $NUMS -eq $EXPECTED ] ||
4374                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4375                               "found $NUMS, expected $EXPECTED"
4376         done
4377 }
4378 run_test 56g "check lfs find -name ============================="
4379
4380 test_56h() {
4381         $SETSTRIPE -d $DIR
4382
4383         TDIR=$DIR/${tdir}g
4384         setup_56 $NUMFILES $NUMDIRS
4385
4386         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4387         # test lfs find with ! -name
4388         for i in $(seq 1 $NUMFILES) ; do
4389                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4390                 [ $NUMS -eq $EXPECTED ] ||
4391                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4392                               "found $NUMS, expected $EXPECTED"
4393         done
4394 }
4395 run_test 56h "check lfs find ! -name ============================="
4396
4397 test_56i() {
4398        tdir=${tdir}i
4399        test_mkdir -p $DIR/$tdir
4400        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4401        CMD="$LFIND -ost $UUID $DIR/$tdir"
4402        OUT=$($CMD)
4403        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4404 }
4405 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4406
4407 test_56j() {
4408         TDIR=$DIR/${tdir}g
4409         setup_56_special $NUMFILES $NUMDIRS
4410
4411         EXPECTED=$((NUMDIRS + 1))
4412         CMD="$LFIND -type d $TDIR"
4413         NUMS=$($CMD | wc -l)
4414         [ $NUMS -eq $EXPECTED ] ||
4415                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4416 }
4417 run_test 56j "check lfs find -type d ============================="
4418
4419 test_56k() {
4420         TDIR=$DIR/${tdir}g
4421         setup_56_special $NUMFILES $NUMDIRS
4422
4423         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4424         CMD="$LFIND -type f $TDIR"
4425         NUMS=$($CMD | wc -l)
4426         [ $NUMS -eq $EXPECTED ] ||
4427                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4428 }
4429 run_test 56k "check lfs find -type f ============================="
4430
4431 test_56l() {
4432         TDIR=$DIR/${tdir}g
4433         setup_56_special $NUMFILES $NUMDIRS
4434
4435         EXPECTED=$((NUMDIRS + NUMFILES))
4436         CMD="$LFIND -type b $TDIR"
4437         NUMS=$($CMD | wc -l)
4438         [ $NUMS -eq $EXPECTED ] ||
4439                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4440 }
4441 run_test 56l "check lfs find -type b ============================="
4442
4443 test_56m() {
4444         TDIR=$DIR/${tdir}g
4445         setup_56_special $NUMFILES $NUMDIRS
4446
4447         EXPECTED=$((NUMDIRS + NUMFILES))
4448         CMD="$LFIND -type c $TDIR"
4449         NUMS=$($CMD | wc -l)
4450         [ $NUMS -eq $EXPECTED ] ||
4451                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4452 }
4453 run_test 56m "check lfs find -type c ============================="
4454
4455 test_56n() {
4456         TDIR=$DIR/${tdir}g
4457         setup_56_special $NUMFILES $NUMDIRS
4458
4459         EXPECTED=$((NUMDIRS + NUMFILES))
4460         CMD="$LFIND -type l $TDIR"
4461         NUMS=$($CMD | wc -l)
4462         [ $NUMS -eq $EXPECTED ] ||
4463                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4464 }
4465 run_test 56n "check lfs find -type l ============================="
4466
4467 test_56o() {
4468         TDIR=$DIR/${tdir}o
4469         setup_56 $NUMFILES $NUMDIRS
4470         utime $TDIR/file1 > /dev/null || error "utime (1)"
4471         utime $TDIR/file2 > /dev/null || error "utime (2)"
4472         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4473         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4474         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4475         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4476
4477         EXPECTED=4
4478         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4479         [ $NUMS -eq $EXPECTED ] || \
4480                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4481
4482         EXPECTED=12
4483         CMD="$LFIND -mtime 0 $TDIR"
4484         NUMS=$($CMD | wc -l)
4485         [ $NUMS -eq $EXPECTED ] ||
4486                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4487 }
4488 run_test 56o "check lfs find -mtime for old files =========================="
4489
4490 test_56p() {
4491         [ $RUNAS_ID -eq $UID ] &&
4492                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4493
4494         TDIR=$DIR/${tdir}p
4495         setup_56 $NUMFILES $NUMDIRS
4496
4497         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4498         EXPECTED=$NUMFILES
4499         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4500         NUMS=$($CMD | wc -l)
4501         [ $NUMS -eq $EXPECTED ] || \
4502                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4503
4504         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4505         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4506         NUMS=$($CMD | wc -l)
4507         [ $NUMS -eq $EXPECTED ] || \
4508                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4509 }
4510 run_test 56p "check lfs find -uid and ! -uid ==============================="
4511
4512 test_56q() {
4513         [ $RUNAS_ID -eq $UID ] &&
4514                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4515
4516         TDIR=$DIR/${tdir}q
4517         setup_56 $NUMFILES $NUMDIRS
4518
4519         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4520
4521         EXPECTED=$NUMFILES
4522         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4523         NUMS=$($CMD | wc -l)
4524         [ $NUMS -eq $EXPECTED ] ||
4525                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4526
4527         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4528         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4529         NUMS=$($CMD | wc -l)
4530         [ $NUMS -eq $EXPECTED ] ||
4531                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4532 }
4533 run_test 56q "check lfs find -gid and ! -gid ==============================="
4534
4535 test_56r() {
4536         TDIR=$DIR/${tdir}r
4537         setup_56 $NUMFILES $NUMDIRS
4538
4539         EXPECTED=12
4540         CMD="$LFIND -size 0 -type f $TDIR"
4541         NUMS=$($CMD | wc -l)
4542         [ $NUMS -eq $EXPECTED ] ||
4543                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4544         EXPECTED=0
4545         CMD="$LFIND ! -size 0 -type f $TDIR"
4546         NUMS=$($CMD | wc -l)
4547         [ $NUMS -eq $EXPECTED ] ||
4548                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4549         echo "test" > $TDIR/$tfile
4550         echo "test2" > $TDIR/$tfile.2 && sync
4551         EXPECTED=1
4552         CMD="$LFIND -size 5 -type f $TDIR"
4553         NUMS=$($CMD | wc -l)
4554         [ $NUMS -eq $EXPECTED ] ||
4555                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4556         EXPECTED=1
4557         CMD="$LFIND -size +5 -type f $TDIR"
4558         NUMS=$($CMD | wc -l)
4559         [ $NUMS -eq $EXPECTED ] ||
4560                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4561         EXPECTED=2
4562         CMD="$LFIND -size +0 -type f $TDIR"
4563         NUMS=$($CMD | wc -l)
4564         [ $NUMS -eq $EXPECTED ] ||
4565                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4566         EXPECTED=2
4567         CMD="$LFIND ! -size -5 -type f $TDIR"
4568         NUMS=$($CMD | wc -l)
4569         [ $NUMS -eq $EXPECTED ] ||
4570                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4571         EXPECTED=12
4572         CMD="$LFIND -size -5 -type f $TDIR"
4573         NUMS=$($CMD | wc -l)
4574         [ $NUMS -eq $EXPECTED ] ||
4575                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4576 }
4577 run_test 56r "check lfs find -size works =========================="
4578
4579 test_56s() { # LU-611
4580         TDIR=$DIR/${tdir}s
4581         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4582
4583         if [[ $OSTCOUNT -gt 1 ]]; then
4584                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4585                 ONESTRIPE=4
4586                 EXTRA=4
4587         else
4588                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4589                 EXTRA=0
4590         fi
4591
4592         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4593         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4594         NUMS=$($CMD | wc -l)
4595         [ $NUMS -eq $EXPECTED ] || {
4596                 $GETSTRIPE -R $TDIR
4597                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4598         }
4599
4600         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4601         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4602         NUMS=$($CMD | wc -l)
4603         [ $NUMS -eq $EXPECTED ] || {
4604                 $GETSTRIPE -R $TDIR
4605                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4606         }
4607
4608         EXPECTED=$ONESTRIPE
4609         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4610         NUMS=$($CMD | wc -l)
4611         [ $NUMS -eq $EXPECTED ] || {
4612                 $GETSTRIPE -R $TDIR
4613                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4614         }
4615
4616         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4617         NUMS=$($CMD | wc -l)
4618         [ $NUMS -eq $EXPECTED ] || {
4619                 $GETSTRIPE -R $TDIR
4620                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4621         }
4622
4623         EXPECTED=0
4624         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4625         NUMS=$($CMD | wc -l)
4626         [ $NUMS -eq $EXPECTED ] || {
4627                 $GETSTRIPE -R $TDIR
4628                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4629         }
4630 }
4631 run_test 56s "check lfs find -stripe-count works"
4632
4633 test_56t() { # LU-611
4634         TDIR=$DIR/${tdir}t
4635         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4636
4637         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4638
4639         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4640         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4641         NUMS=$($CMD | wc -l)
4642         [ $NUMS -eq $EXPECTED ] ||
4643                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4644
4645         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4646         NUMS=$($CMD | wc -l)
4647         [ $NUMS -eq $EXPECTED ] ||
4648                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4649
4650         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4651         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4652         NUMS=$($CMD | wc -l)
4653         [ $NUMS -eq $EXPECTED ] ||
4654                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4655
4656         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4657         NUMS=$($CMD | wc -l)
4658         [ $NUMS -eq $EXPECTED ] ||
4659                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4660
4661         EXPECTED=4
4662         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4663         NUMS=$($CMD | wc -l)
4664         [ $NUMS -eq $EXPECTED ] ||
4665                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4666
4667         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4668         NUMS=$($CMD | wc -l)
4669         [ $NUMS -eq $EXPECTED ] ||
4670                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4671
4672         EXPECTED=0
4673         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4674         NUMS=$($CMD | wc -l)
4675         [ $NUMS -eq $EXPECTED ] ||
4676                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4677 }
4678 run_test 56t "check lfs find -stripe-size works"
4679
4680 test_56u() { # LU-611
4681         TDIR=$DIR/${tdir}u
4682         setup_56 $NUMFILES $NUMDIRS "-i 0"
4683
4684         if [[ $OSTCOUNT -gt 1 ]]; then
4685                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4686                 ONESTRIPE=4
4687         else
4688                 ONESTRIPE=0
4689         fi
4690
4691         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4692         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4693         NUMS=$($CMD | wc -l)
4694         [ $NUMS -eq $EXPECTED ] ||
4695                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4696
4697         EXPECTED=$ONESTRIPE
4698         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4699         NUMS=$($CMD | wc -l)
4700         [ $NUMS -eq $EXPECTED ] ||
4701                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4702
4703         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4704         NUMS=$($CMD | wc -l)
4705         [ $NUMS -eq $EXPECTED ] ||
4706                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4707
4708         EXPECTED=0
4709         # This should produce an error and not return any files
4710         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4711         NUMS=$($CMD 2>/dev/null | wc -l)
4712         [ $NUMS -eq $EXPECTED ] ||
4713                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4714
4715         if [[ $OSTCOUNT -gt 1 ]]; then
4716                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4717                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4718                 NUMS=$($CMD | wc -l)
4719                 [ $NUMS -eq $EXPECTED ] ||
4720                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4721         fi
4722 }
4723 run_test 56u "check lfs find -stripe-index works"
4724
4725 test_56v() {
4726     local MDT_IDX=0
4727
4728     TDIR=$DIR/${tdir}v
4729     rm -rf $TDIR
4730     setup_56 $NUMFILES $NUMDIRS
4731
4732     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4733     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4734
4735     for file in $($LFIND -mdt $UUID $TDIR); do
4736         file_mdt_idx=$($GETSTRIPE -M $file)
4737         [ $file_mdt_idx -eq $MDT_IDX ] ||
4738             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4739     done
4740 }
4741 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4742
4743 # Get and check the actual stripe count of one file.
4744 # Usage: check_stripe_count <file> <expected_stripe_count>
4745 check_stripe_count() {
4746     local file=$1
4747     local expected=$2
4748     local actual
4749
4750     [[ -z "$file" || -z "$expected" ]] &&
4751         error "check_stripe_count: invalid argument!"
4752
4753     local cmd="$GETSTRIPE -c $file"
4754     actual=$($cmd) || error "$cmd failed"
4755     actual=${actual%% *}
4756
4757     if [[ $actual -ne $expected ]]; then
4758         [[ $expected -eq -1 ]] ||
4759             error "$cmd wrong: found $actual, expected $expected"
4760         [[ $actual -eq $OSTCOUNT ]] ||
4761             error "$cmd wrong: found $actual, expected $OSTCOUNT"
4762     fi
4763 }
4764
4765 test_56w() {
4766         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4767         TDIR=$DIR/${tdir}w
4768
4769     rm -rf $TDIR || error "remove $TDIR failed"
4770     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4771
4772     local stripe_size
4773     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4774         error "$GETSTRIPE -S -d $TDIR failed"
4775     stripe_size=${stripe_size%% *}
4776
4777     local file_size=$((stripe_size * OSTCOUNT))
4778     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4779     local required_space=$((file_num * file_size))
4780     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4781     [[ $free_space -le $((required_space / 1024)) ]] &&
4782         skip_env "need at least $required_space bytes free space," \
4783                  "have $free_space kbytes" && return
4784
4785     local dd_bs=65536
4786     local dd_count=$((file_size / dd_bs))
4787
4788     # write data into the files
4789     local i
4790     local j
4791     local file
4792     for i in $(seq 1 $NUMFILES); do
4793         file=$TDIR/file$i
4794         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4795             error "write data into $file failed"
4796     done
4797     for i in $(seq 1 $NUMDIRS); do
4798         for j in $(seq 1 $NUMFILES); do
4799             file=$TDIR/dir$i/file$j
4800             yes | dd bs=$dd_bs count=$dd_count of=$file \
4801                 >/dev/null 2>&1 ||
4802                 error "write data into $file failed"
4803         done
4804     done
4805
4806     local expected=-1
4807     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4808
4809     # lfs_migrate file
4810     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4811     echo "$cmd"
4812     eval $cmd || error "$cmd failed"
4813
4814     check_stripe_count $TDIR/file1 $expected
4815
4816     # lfs_migrate dir
4817     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4818     echo "$cmd"
4819     eval $cmd || error "$cmd failed"
4820
4821     for j in $(seq 1 $NUMFILES); do
4822         check_stripe_count $TDIR/dir1/file$j $expected
4823     done
4824
4825     # lfs_migrate works with lfs find
4826     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4827          $LFS_MIGRATE -y -c $expected"
4828     echo "$cmd"
4829     eval $cmd || error "$cmd failed"
4830
4831     for i in $(seq 2 $NUMFILES); do
4832         check_stripe_count $TDIR/file$i $expected
4833     done
4834     for i in $(seq 2 $NUMDIRS); do
4835         for j in $(seq 1 $NUMFILES); do
4836             check_stripe_count $TDIR/dir$i/file$j $expected
4837         done
4838     done
4839 }
4840 run_test 56w "check lfs_migrate -c stripe_count works"
4841
4842 test_56x() {
4843         check_swap_layouts_support && return 0
4844         [[ $OSTCOUNT -lt 2 ]] &&
4845                 skip_env "need 2 OST, skipping test" && return
4846
4847         local dir0=$DIR/$tdir/$testnum
4848         mkdir -p $dir0 || error "creating dir $dir0"
4849
4850         local ref1=/etc/passwd
4851         local file1=$dir0/file1
4852
4853         $SETSTRIPE -c 2 $file1
4854         cp $ref1 $file1
4855         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4856         stripe=$($GETSTRIPE -c $file1)
4857         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4858         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4859
4860         # clean up
4861         rm -f $file1
4862 }
4863 run_test 56x "lfs migration support"
4864
4865 test_56y() {
4866         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4867                 skip "No HSM support on MDS of $(get_lustre_version)," \
4868                          "need 2.4.53 at least" && return
4869         local res=""
4870
4871         local dir0=$DIR/$tdir/$testnum
4872         mkdir -p $dir0 || error "creating dir $dir0"
4873         local f1=$dir0/file1
4874         local f2=$dir0/file2
4875
4876         touch $f1 || error "creating std file $f1"
4877         $MULTIOP $f2 H2c || error "creating released file $f2"
4878
4879         # a directory can be raid0, so ask only for files
4880         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4881         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4882
4883         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4884         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4885
4886         # only files can be released, so no need to force file search
4887         res=$($LFIND $dir0 -L released)
4888         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4889
4890         res=$($LFIND $dir0 \! -L released)
4891         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4892
4893 }
4894 run_test 56y "lfs find -L raid0|released"
4895
4896 test_57a() {
4897         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4898         # note test will not do anything if MDS is not local
4899         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4900                 skip "Only applicable to ldiskfs-based MDTs"
4901                 return
4902         fi
4903
4904         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4905         local MNTDEV="osd*.*MDT*.mntdev"
4906         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
4907         [ -z "$DEV" ] && error "can't access $MNTDEV"
4908         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
4909                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
4910                         error "can't access $DEV"
4911                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
4912                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
4913                 rm $TMP/t57a.dump
4914         done
4915 }
4916 run_test 57a "verify MDS filesystem created with large inodes =="
4917
4918 test_57b() {
4919         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4920         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4921                 skip "Only applicable to ldiskfs-based MDTs"
4922                 return
4923         fi
4924
4925         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4926         local dir=$DIR/d57b
4927
4928         local FILECOUNT=100
4929         local FILE1=$dir/f1
4930         local FILEN=$dir/f$FILECOUNT
4931
4932         rm -rf $dir || error "removing $dir"
4933         test_mkdir -p $dir || error "creating $dir"
4934         local num=$(get_mds_dir $dir)
4935         local mymds=mds$num
4936
4937         echo "mcreating $FILECOUNT files"
4938         createmany -m $dir/f 1 $FILECOUNT || \
4939                 error "creating files in $dir"
4940
4941         # verify that files do not have EAs yet
4942         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
4943         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
4944
4945         sync
4946         sleep 1
4947         df $dir  #make sure we get new statfs data
4948         local MDSFREE=$(do_facet $mymds \
4949                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4950         local MDCFREE=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4951         echo "opening files to create objects/EAs"
4952         local FILE
4953         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
4954                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
4955         done
4956
4957         # verify that files have EAs now
4958         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
4959         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
4960
4961         sleep 1  #make sure we get new statfs data
4962         df $dir
4963         local MDSFREE2=$(do_facet $mymds \
4964                 lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
4965         local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
4966         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
4967                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
4968                         error "MDC before $MDCFREE != after $MDCFREE2"
4969                 else
4970                         echo "MDC before $MDCFREE != after $MDCFREE2"
4971                         echo "unable to confirm if MDS has large inodes"
4972                 fi
4973         fi
4974         rm -rf $dir
4975 }
4976 run_test 57b "default LOV EAs are stored inside large inodes ==="
4977
4978 test_58() {
4979         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4980         [ -z "$(which wiretest 2>/dev/null)" ] &&
4981                         skip_env "could not find wiretest" && return
4982         wiretest
4983 }
4984 run_test 58 "verify cross-platform wire constants =============="
4985
4986 test_59() {
4987         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4988         echo "touch 130 files"
4989         createmany -o $DIR/f59- 130
4990         echo "rm 130 files"
4991         unlinkmany $DIR/f59- 130
4992         sync
4993         # wait for commitment of removal
4994         wait_delete_completed
4995 }
4996 run_test 59 "verify cancellation of llog records async ========="
4997
4998 TEST60_HEAD="test_60 run $RANDOM"
4999 test_60a() {
5000         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5001         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5002         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5003                 skip_env "missing subtest run-llog.sh" && return
5004         log "$TEST60_HEAD - from kernel mode"
5005         do_facet mgs sh run-llog.sh
5006 }
5007 run_test 60a "llog sanity tests run from kernel module =========="
5008
5009 test_60b() { # bug 6411
5010         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5011         dmesg > $DIR/$tfile
5012         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
5013                                  /llog.test/ {
5014                                          if (marker)
5015                                                  from_marker++
5016                                          from_begin++
5017                                  }
5018                                  END {
5019                                          if (marker)
5020                                                  print from_marker
5021                                          else
5022                                                  print from_begin
5023                                  }"`
5024         [[ $LLOG_COUNT -gt 50 ]] &&
5025                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5026 }
5027 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5028
5029 test_60c() {
5030         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5031         echo "create 5000 files"
5032         createmany -o $DIR/f60c- 5000
5033 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5034         lctl set_param fail_loc=0x80000137
5035         unlinkmany $DIR/f60c- 5000
5036         lctl set_param fail_loc=0
5037 }
5038 run_test 60c "unlink file when mds full"
5039
5040 test_60d() {
5041         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5042         SAVEPRINTK=$(lctl get_param -n printk)
5043
5044         # verify "lctl mark" is even working"
5045         MESSAGE="test message ID $RANDOM $$"
5046         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5047         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5048
5049         lctl set_param printk=0 || error "set lnet.printk failed"
5050         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5051         MESSAGE="new test message ID $RANDOM $$"
5052         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5053         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5054         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5055
5056         lctl set_param -n printk="$SAVEPRINTK"
5057 }
5058 run_test 60d "test printk console message masking"
5059
5060 test_61() {
5061         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5062         f="$DIR/f61"
5063         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5064         cancel_lru_locks osc
5065         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5066         sync
5067 }
5068 run_test 61 "mmap() writes don't make sync hang ================"
5069
5070 # bug 2330 - insufficient obd_match error checking causes LBUG
5071 test_62() {
5072         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5073         f="$DIR/f62"
5074         echo foo > $f
5075         cancel_lru_locks osc
5076         lctl set_param fail_loc=0x405
5077         cat $f && error "cat succeeded, expect -EIO"
5078         lctl set_param fail_loc=0
5079 }
5080 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5081 # match every page all of the time.
5082 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5083
5084 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5085 # Though this test is irrelevant anymore, it helped to reveal some
5086 # other grant bugs (LU-4482), let's keep it.
5087 test_63a() {   # was test_63
5088         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5089         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5090         for i in `seq 10` ; do
5091                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5092                 sleep 5
5093                 kill $!
5094                 sleep 1
5095         done
5096
5097         rm -f $DIR/f63 || true
5098 }
5099 run_test 63a "Verify oig_wait interruption does not crash ======="
5100
5101 # bug 2248 - async write errors didn't return to application on sync
5102 # bug 3677 - async write errors left page locked
5103 test_63b() {
5104         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5105         debugsave
5106         lctl set_param debug=-1
5107
5108         # ensure we have a grant to do async writes
5109         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5110         rm $DIR/$tfile
5111
5112         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5113         lctl set_param fail_loc=0x80000406
5114         $MULTIOP $DIR/$tfile Owy && \
5115                 error "sync didn't return ENOMEM"
5116         sync; sleep 2; sync     # do a real sync this time to flush page
5117         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5118                 error "locked page left in cache after async error" || true
5119         debugrestore
5120 }
5121 run_test 63b "async write errors should be returned to fsync ==="
5122
5123 test_64a () {
5124         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5125         df $DIR
5126         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5127 }
5128 run_test 64a "verify filter grant calculations (in kernel) ====="
5129
5130 test_64b () {
5131         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5132         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5133 }
5134 run_test 64b "check out-of-space detection on client ==========="
5135
5136 test_64c() {
5137         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5138 }
5139 run_test 64c "verify grant shrink ========================------"
5140
5141 # bug 1414 - set/get directories' stripe info
5142 test_65a() {
5143         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5144         test_mkdir -p $DIR/$tdir
5145         touch $DIR/$tdir/f1
5146         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5147 }
5148 run_test 65a "directory with no stripe info ===================="
5149
5150 test_65b() {
5151         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5152         test_mkdir -p $DIR/$tdir
5153         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5154                                                 error "setstripe"
5155         touch $DIR/$tdir/f2
5156         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5157 }
5158 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
5159
5160 test_65c() {
5161         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5162         if [[ $OSTCOUNT -gt 1 ]]; then
5163                 test_mkdir -p $DIR/$tdir
5164                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5165                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5166                 touch $DIR/$tdir/f3
5167                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5168         fi
5169 }
5170 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
5171
5172 test_65d() {
5173         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5174         test_mkdir -p $DIR/$tdir
5175         if [[ $STRIPECOUNT -le 0 ]]; then
5176                 sc=1
5177         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5178 #LOV_MAX_STRIPE_COUNT is 2000
5179                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5180         else
5181                 sc=$(($STRIPECOUNT - 1))
5182         fi
5183         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5184         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5185         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5186                 error "lverify failed"
5187 }
5188 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
5189
5190 test_65e() {
5191         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5192         test_mkdir -p $DIR/$tdir
5193
5194         $SETSTRIPE $DIR/$tdir || error "setstripe"
5195         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5196                                         error "no stripe info failed"
5197         touch $DIR/$tdir/f6
5198         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5199 }
5200 run_test 65e "directory setstripe defaults ======================="
5201
5202 test_65f() {
5203         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5204         test_mkdir -p $DIR/${tdir}f
5205         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5206 }
5207 run_test 65f "dir setstripe permission (should return error) ==="
5208
5209 test_65g() {
5210         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5211         test_mkdir -p $DIR/$tdir
5212         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5213                                                         error "setstripe"
5214         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5215         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5216                 error "delete default stripe failed"
5217 }
5218 run_test 65g "directory setstripe -d ==========================="
5219
5220 test_65h() {
5221         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5222         test_mkdir -p $DIR/$tdir
5223         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5224                                                         error "setstripe"
5225         test_mkdir -p $DIR/$tdir/dd1
5226         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5227                 error "stripe info inherit failed"
5228 }
5229 run_test 65h "directory stripe info inherit ===================="
5230
5231 test_65i() { # bug6367
5232         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5233         $SETSTRIPE -S 65536 -c -1 $MOUNT
5234 }
5235 run_test 65i "set non-default striping on root directory (bug 6367)="
5236
5237 test_65ia() { # bug12836
5238         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5239         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5240 }
5241 run_test 65ia "getstripe on -1 default directory striping"
5242
5243 test_65ib() { # bug12836
5244         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5245         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5246 }
5247 run_test 65ib "getstripe -v on -1 default directory striping"
5248
5249 test_65ic() { # bug12836
5250         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5251         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5252 }
5253 run_test 65ic "new find on -1 default directory striping"
5254
5255 test_65j() { # bug6367
5256         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5257         sync; sleep 1
5258         # if we aren't already remounting for each test, do so for this test
5259         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5260                 cleanup || error "failed to unmount"
5261                 setup
5262         fi
5263         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5264 }
5265 run_test 65j "set default striping on root directory (bug 6367)="
5266
5267 test_65k() { # bug11679
5268         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5269         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5270         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5271
5272     echo "Check OST status: "
5273     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5274               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5275
5276     for OSC in $MDS_OSCS; do
5277         echo $OSC "is activate"
5278         do_facet $SINGLEMDS lctl --device %$OSC activate
5279     done
5280
5281     mkdir -p $DIR/$tdir
5282     for INACTIVE_OSC in $MDS_OSCS; do
5283         echo "Deactivate: " $INACTIVE_OSC
5284         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5285         for STRIPE_OSC in $MDS_OSCS; do
5286             OST=`osc_to_ost $STRIPE_OSC`
5287             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5288                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5289
5290             [ -f $DIR/$tdir/$IDX ] && continue
5291             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5292             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5293             RC=$?
5294             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5295         done
5296         rm -f $DIR/$tdir/*
5297         echo $INACTIVE_OSC "is Activate."
5298         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5299     done
5300 }
5301 run_test 65k "validate manual striping works properly with deactivated OSCs"
5302
5303 test_65l() { # bug 12836
5304         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5305         test_mkdir -p $DIR/$tdir/test_dir
5306         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5307         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5308 }
5309 run_test 65l "lfs find on -1 stripe dir ========================"
5310
5311 # bug 2543 - update blocks count on client
5312 test_66() {
5313         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5314         COUNT=${COUNT:-8}
5315         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5316         sync; sync_all_data; sync; sync_all_data
5317         cancel_lru_locks osc
5318         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5319         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5320 }
5321 run_test 66 "update inode blocks count on client ==============="
5322
5323 LLOOP=
5324 LLITELOOPLOAD=
5325 cleanup_68() {
5326         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5327         trap 0
5328         if [ ! -z "$LLOOP" ]; then
5329                 if swapon -s | grep -q $LLOOP; then
5330                         swapoff $LLOOP || error "swapoff failed"
5331                 fi
5332
5333                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5334                 rm -f $LLOOP
5335                 unset LLOOP
5336         fi
5337         if [ ! -z "$LLITELOOPLOAD" ]; then
5338                 rmmod llite_lloop
5339                 unset LLITELOOPLOAD
5340         fi
5341         rm -f $DIR/f68*
5342 }
5343
5344 meminfo() {
5345         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5346 }
5347
5348 swap_used() {
5349         swapon -s | awk '($1 == "'$1'") { print $4 }'
5350 }
5351
5352 # test case for lloop driver, basic function
5353 test_68a() {
5354         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5355         [ "$UID" != 0 ] && skip_env "must run as root" && return
5356         llite_lloop_enabled || \
5357                 { skip_env "llite_lloop module disabled" && return; }
5358
5359         trap cleanup_68 EXIT
5360
5361         if ! module_loaded llite_lloop; then
5362                 if load_module llite/llite_lloop; then
5363                         LLITELOOPLOAD=yes
5364                 else
5365                         skip_env "can't find module llite_lloop"
5366                         return
5367                 fi
5368         fi
5369
5370         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5371         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5372         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5373
5374         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5375         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5376
5377         cleanup_68
5378 }
5379 run_test 68a "lloop driver - basic test ========================"
5380
5381 # excercise swapping to lustre by adding a high priority swapfile entry
5382 # and then consuming memory until it is used.
5383 test_68b() {  # was test_68
5384         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5385         [ "$UID" != 0 ] && skip_env "must run as root" && return
5386         lctl get_param -n devices | grep -q obdfilter && \
5387                 skip "local OST" && return
5388
5389         grep -q llite_lloop /proc/modules
5390         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5391
5392         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5393                 skip "can't reliably test swap with TCP" && return
5394
5395         MEMTOTAL=`meminfo MemTotal`
5396         NR_BLOCKS=$((MEMTOTAL>>8))
5397         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5398
5399         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5400         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5401         mkswap $DIR/f68b
5402
5403         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5404
5405         trap cleanup_68 EXIT
5406
5407         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5408
5409         echo "before: `swapon -s | grep $LLOOP`"
5410         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5411         echo "after: `swapon -s | grep $LLOOP`"
5412         SWAPUSED=`swap_used $LLOOP`
5413
5414         cleanup_68
5415
5416         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5417 }
5418 run_test 68b "support swapping to Lustre ========================"
5419
5420 # bug5265, obdfilter oa2dentry return -ENOENT
5421 # #define OBD_FAIL_OST_ENOENT 0x217
5422 test_69() {
5423         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5424         remote_ost_nodsh && skip "remote OST with nodsh" && return
5425
5426         f="$DIR/$tfile"
5427         $SETSTRIPE -c 1 -i 0 $f
5428
5429         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5430
5431         do_facet ost1 lctl set_param fail_loc=0x217
5432         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5433         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5434
5435         do_facet ost1 lctl set_param fail_loc=0
5436         $DIRECTIO write $f 0 2 || error "write error"
5437
5438         cancel_lru_locks osc
5439         $DIRECTIO read $f 0 1 || error "read error"
5440
5441         do_facet ost1 lctl set_param fail_loc=0x217
5442         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5443
5444         do_facet ost1 lctl set_param fail_loc=0
5445         rm -f $f
5446 }
5447 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5448
5449 test_71() {
5450     test_mkdir -p $DIR/$tdir
5451     sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5452 }
5453 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5454
5455 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5456         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5457         [ "$RUNAS_ID" = "$UID" ] &&
5458                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5459
5460         # Check that testing environment is properly set up. Skip if not
5461         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5462                 skip_env "User $RUNAS_ID does not exist - skipping"
5463                 return 0
5464         }
5465         # We had better clear the $DIR to get enough space for dd
5466         rm -rf $DIR/*
5467         touch $DIR/$tfile
5468         chmod 777 $DIR/$tfile
5469         chmod ug+s $DIR/$tfile
5470         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5471                 error "$RUNAS dd $DIR/$tfile failed"
5472         # See if we are still setuid/sgid
5473         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5474                 error "S/gid is not dropped on write"
5475         # Now test that MDS is updated too
5476         cancel_lru_locks mdc
5477         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5478                 error "S/gid is not dropped on MDS"
5479         rm -f $DIR/$tfile
5480 }
5481 run_test 72a "Test that remove suid works properly (bug5695) ===="
5482
5483 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5484         local perm
5485
5486         [ "$RUNAS_ID" = "$UID" ] && \
5487                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5488         [ "$RUNAS_ID" -eq 0 ] && \
5489                 skip_env "RUNAS_ID = 0 -- skipping" && return
5490
5491         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5492         # Check that testing environment is properly set up. Skip if not
5493         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5494                 skip_env "User $RUNAS_ID does not exist - skipping"
5495                 return 0
5496         }
5497         touch $DIR/${tfile}-f{g,u}
5498         test_mkdir $DIR/${tfile}-dg
5499         test_mkdir $DIR/${tfile}-du
5500         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5501         chmod g+s $DIR/${tfile}-{f,d}g
5502         chmod u+s $DIR/${tfile}-{f,d}u
5503         for perm in 777 2777 4777; do
5504                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5505                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5506                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5507                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5508         done
5509         true
5510 }
5511 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5512
5513 # bug 3462 - multiple simultaneous MDC requests
5514 test_73() {
5515         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5516         test_mkdir $DIR/d73-1
5517         test_mkdir $DIR/d73-2
5518         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5519         pid1=$!
5520
5521         lctl set_param fail_loc=0x80000129
5522         $MULTIOP $DIR/d73-1/f73-2 Oc &
5523         sleep 1
5524         lctl set_param fail_loc=0
5525
5526         $MULTIOP $DIR/d73-2/f73-3 Oc &
5527         pid3=$!
5528
5529         kill -USR1 $pid1
5530         wait $pid1 || return 1
5531
5532         sleep 25
5533
5534         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5535         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5536         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5537
5538         rm -rf $DIR/d73-*
5539 }
5540 run_test 73 "multiple MDC requests (should not deadlock)"
5541
5542 test_74a() { # bug 6149, 6184
5543         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5544         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5545         #
5546         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5547         # will spin in a tight reconnection loop
5548         touch $DIR/f74a
5549         $LCTL set_param fail_loc=0x8000030e
5550         # get any lock that won't be difficult - lookup works.
5551         ls $DIR/f74a
5552         $LCTL set_param fail_loc=0
5553         rm -f $DIR/f74a
5554         true
5555 }
5556 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5557
5558 test_74b() { # bug 13310
5559         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5560         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5561         #
5562         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5563         # will spin in a tight reconnection loop
5564         $LCTL set_param fail_loc=0x8000030e
5565         # get a "difficult" lock
5566         touch $DIR/f74b
5567         $LCTL set_param fail_loc=0
5568         rm -f $DIR/f74b
5569         true
5570 }
5571 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5572
5573 test_74c() {
5574         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5575         #define OBD_FAIL_LDLM_NEW_LOCK
5576         $LCTL set_param fail_loc=0x319
5577         touch $DIR/$tfile && error "touch successful"
5578         $LCTL set_param fail_loc=0
5579         true
5580 }
5581 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5582
5583 num_inodes() {
5584         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5585 }
5586
5587 get_inode_slab_tunables() {
5588         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5589 }
5590
5591 set_inode_slab_tunables() {
5592         echo "lustre_inode_cache $1" > /proc/slabinfo
5593 }
5594
5595 test_76() { # Now for bug 20433, added originally in bug 1443
5596         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5597         local SLAB_SETTINGS=`get_inode_slab_tunables`
5598         local CPUS=`getconf _NPROCESSORS_ONLN`
5599         # we cannot set limit below 1 which means 1 inode in each
5600         # per-cpu cache is still allowed
5601         set_inode_slab_tunables "1 1 0"
5602         cancel_lru_locks osc
5603         BEFORE_INODES=$(num_inodes)
5604         echo "before inodes: $BEFORE_INODES"
5605         local COUNT=1000
5606         [ "$SLOW" = "no" ] && COUNT=100
5607         for i in $(seq $COUNT); do
5608                 touch $DIR/$tfile
5609                 rm -f $DIR/$tfile
5610         done
5611         cancel_lru_locks osc
5612         AFTER_INODES=$(num_inodes)
5613         echo "after inodes: $AFTER_INODES"
5614         local wait=0
5615         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5616                 sleep 2
5617                 AFTER_INODES=$(num_inodes)
5618                 wait=$((wait+2))
5619                 echo "wait $wait seconds inodes: $AFTER_INODES"
5620                 if [ $wait -gt 30 ]; then
5621                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5622                 fi
5623         done
5624         set_inode_slab_tunables "$SLAB_SETTINGS"
5625 }
5626 run_test 76 "confirm clients recycle inodes properly ===="
5627
5628
5629 export ORIG_CSUM=""
5630 set_checksums()
5631 {
5632         # Note: in sptlrpc modes which enable its own bulk checksum, the
5633         # original crc32_le bulk checksum will be automatically disabled,
5634         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5635         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5636         # In this case set_checksums() will not be no-op, because sptlrpc
5637         # bulk checksum will be enabled all through the test.
5638
5639         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5640         lctl set_param -n osc.*.checksums $1
5641         return 0
5642 }
5643
5644 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5645                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5646 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5647 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5648 set_checksum_type()
5649 {
5650         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5651         log "set checksum type to $1"
5652         return 0
5653 }
5654 F77_TMP=$TMP/f77-temp
5655 F77SZ=8
5656 setup_f77() {
5657         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5658                 error "error writing to $F77_TMP"
5659 }
5660
5661 test_77a() { # bug 10889
5662         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5663         $GSS && skip "could not run with gss" && return
5664         [ ! -f $F77_TMP ] && setup_f77
5665         set_checksums 1
5666         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5667         set_checksums 0
5668         rm -f $DIR/$tfile
5669 }
5670 run_test 77a "normal checksum read/write operation"
5671
5672 test_77b() { # bug 10889
5673         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5674         $GSS && skip "could not run with gss" && return
5675         [ ! -f $F77_TMP ] && setup_f77
5676         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5677         $LCTL set_param fail_loc=0x80000409
5678         set_checksums 1
5679
5680         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5681                 error "dd error: $?"
5682         $LCTL set_param fail_loc=0
5683
5684         for algo in $CKSUM_TYPES; do
5685                 cancel_lru_locks osc
5686                 set_checksum_type $algo
5687                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5688                 $LCTL set_param fail_loc=0x80000408
5689                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5690                 $LCTL set_param fail_loc=0
5691         done
5692         set_checksums 0
5693         set_checksum_type $ORIG_CSUM_TYPE
5694         rm -f $DIR/$tfile
5695 }
5696 run_test 77b "checksum error on client write, read"
5697
5698 test_77d() { # bug 10889
5699         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5700         $GSS && skip "could not run with gss" && return
5701         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5702         $LCTL set_param fail_loc=0x80000409
5703         set_checksums 1
5704         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5705                 error "direct write: rc=$?"
5706         $LCTL set_param fail_loc=0
5707         set_checksums 0
5708
5709         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5710         $LCTL set_param fail_loc=0x80000408
5711         set_checksums 1
5712         cancel_lru_locks osc
5713         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5714                 error "direct read: rc=$?"
5715         $LCTL set_param fail_loc=0
5716         set_checksums 0
5717 }
5718 run_test 77d "checksum error on OST direct write, read"
5719
5720 test_77f() { # bug 10889
5721         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5722         $GSS && skip "could not run with gss" && return
5723         set_checksums 1
5724         for algo in $CKSUM_TYPES; do
5725                 cancel_lru_locks osc
5726                 set_checksum_type $algo
5727                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5728                 $LCTL set_param fail_loc=0x409
5729                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5730                         error "direct write succeeded"
5731                 $LCTL set_param fail_loc=0
5732         done
5733         set_checksum_type $ORIG_CSUM_TYPE
5734         set_checksums 0
5735 }
5736 run_test 77f "repeat checksum error on write (expect error)"
5737
5738 test_77g() { # bug 10889
5739         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5740         $GSS && skip "could not run with gss" && return
5741         remote_ost_nodsh && skip "remote OST with nodsh" && return
5742
5743         [ ! -f $F77_TMP ] && setup_f77
5744
5745         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5746         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5747         do_facet ost1 lctl set_param fail_loc=0x8000021a
5748         set_checksums 1
5749         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5750                 error "write error: rc=$?"
5751         do_facet ost1 lctl set_param fail_loc=0
5752         set_checksums 0
5753
5754         cancel_lru_locks osc
5755         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5756         do_facet ost1 lctl set_param fail_loc=0x8000021b
5757         set_checksums 1
5758         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5759         do_facet ost1 lctl set_param fail_loc=0
5760         set_checksums 0
5761 }
5762 run_test 77g "checksum error on OST write, read"
5763
5764 test_77i() { # bug 13805
5765         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5766         $GSS && skip "could not run with gss" && return
5767         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5768         lctl set_param fail_loc=0x40b
5769         remount_client $MOUNT
5770         lctl set_param fail_loc=0
5771         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5772                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5773                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5774                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5775         done
5776         remount_client $MOUNT
5777 }
5778 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5779
5780 test_77j() { # bug 13805
5781         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5782         $GSS && skip "could not run with gss" && return
5783         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
5784         lctl set_param fail_loc=0x40c
5785         remount_client $MOUNT
5786         lctl set_param fail_loc=0
5787         sleep 2 # wait async osc connect to finish
5788         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5789                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5790                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5791                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5792         done
5793         remount_client $MOUNT
5794 }
5795 run_test 77j "client only supporting ADLER32"
5796
5797 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
5798 rm -f $F77_TMP
5799 unset F77_TMP
5800
5801 test_78() { # bug 10901
5802         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5803         remote_ost || { skip_env "local OST" && return; }
5804
5805         NSEQ=5
5806         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
5807         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
5808         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
5809         echo "MemTotal: $MEMTOTAL"
5810
5811         # reserve 256MB of memory for the kernel and other running processes,
5812         # and then take 1/2 of the remaining memory for the read/write buffers.
5813         if [ $MEMTOTAL -gt 512 ] ;then
5814                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
5815         else
5816                 # for those poor memory-starved high-end clusters...
5817                 MEMTOTAL=$((MEMTOTAL / 2))
5818         fi
5819         echo "Mem to use for directio: $MEMTOTAL"
5820
5821         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
5822         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
5823         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
5824         SMALLESTOST=$(lfs df $DIR | grep OST | awk '{ print $4 }' | sort -n |
5825                 head -n1)
5826         echo "Smallest OST: $SMALLESTOST"
5827         [[ $SMALLESTOST -lt 10240 ]] &&
5828                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
5829
5830         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
5831                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
5832
5833         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
5834         echo "File size: $F78SIZE"
5835         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
5836         for i in $(seq 1 $NSEQ); do
5837                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
5838                 echo directIO rdwr round $i of $NSEQ
5839                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
5840         done
5841
5842         rm -f $DIR/$tfile
5843 }
5844 run_test 78 "handle large O_DIRECT writes correctly ============"
5845
5846 test_79() { # bug 12743
5847         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5848         wait_delete_completed
5849
5850         BKTOTAL=$(calc_osc_kbytes kbytestotal)
5851         BKFREE=$(calc_osc_kbytes kbytesfree)
5852         BKAVAIL=$(calc_osc_kbytes kbytesavail)
5853
5854         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
5855         DFTOTAL=`echo $STRING | cut -d, -f1`
5856         DFUSED=`echo $STRING  | cut -d, -f2`
5857         DFAVAIL=`echo $STRING | cut -d, -f3`
5858         DFFREE=$(($DFTOTAL - $DFUSED))
5859
5860         ALLOWANCE=$((64 * $OSTCOUNT))
5861
5862         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
5863            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
5864                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
5865         fi
5866         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
5867            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
5868                 error "df free($DFFREE) mismatch OST free($BKFREE)"
5869         fi
5870         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
5871            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
5872                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
5873         fi
5874 }
5875 run_test 79 "df report consistency check ======================="
5876
5877 test_80() { # bug 10718
5878         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5879         # relax strong synchronous semantics for slow backends like ZFS
5880         local soc="obdfilter.*.sync_on_lock_cancel"
5881         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
5882         local hosts=
5883         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
5884                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
5885                           facet_active_host $host; done | sort -u)
5886                 do_nodes $hosts lctl set_param $soc=never
5887         fi
5888
5889         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
5890         sync; sleep 1; sync
5891         local BEFORE=`date +%s`
5892         cancel_lru_locks osc
5893         local AFTER=`date +%s`
5894         local DIFF=$((AFTER-BEFORE))
5895         if [ $DIFF -gt 1 ] ; then
5896                 error "elapsed for 1M@1T = $DIFF"
5897         fi
5898
5899         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
5900
5901         rm -f $DIR/$tfile
5902 }
5903 run_test 80 "Page eviction is equally fast at high offsets too  ===="
5904
5905 test_81a() { # LU-456
5906         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5907         remote_ost_nodsh && skip "remote OST with nodsh" && return
5908         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5909         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
5910         do_facet ost1 lctl set_param fail_loc=0x80000228
5911
5912         # write should trigger a retry and success
5913         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5914         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5915         RC=$?
5916         if [ $RC -ne 0 ] ; then
5917                 error "write should success, but failed for $RC"
5918         fi
5919 }
5920 run_test 81a "OST should retry write when get -ENOSPC ==============="
5921
5922 test_81b() { # LU-456
5923         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5924         remote_ost_nodsh && skip "remote OST with nodsh" && return
5925         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
5926         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
5927         do_facet ost1 lctl set_param fail_loc=0x228
5928
5929         # write should retry several times and return -ENOSPC finally
5930         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
5931         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
5932         RC=$?
5933         ENOSPC=28
5934         if [ $RC -ne $ENOSPC ] ; then
5935                 error "dd should fail for -ENOSPC, but succeed."
5936         fi
5937 }
5938 run_test 81b "OST should return -ENOSPC when retry still fails ======="
5939
5940 test_82() { # LU-1031
5941         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
5942         local gid1=14091995
5943         local gid2=16022000
5944
5945         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
5946         local MULTIPID1=$!
5947         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
5948         local MULTIPID2=$!
5949         kill -USR1 $MULTIPID2
5950         sleep 2
5951         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
5952                 error "First grouplock does not block second one"
5953         else
5954                 echo "Second grouplock blocks first one"
5955         fi
5956         kill -USR1 $MULTIPID1
5957         wait $MULTIPID1
5958         wait $MULTIPID2
5959 }
5960 run_test 82 "Basic grouplock test ==============================="
5961
5962 test_99a() {
5963         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
5964                 return
5965         test_mkdir -p $DIR/d99cvsroot
5966         chown $RUNAS_ID $DIR/d99cvsroot
5967         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
5968         cd $TMP
5969
5970         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
5971         cd $oldPWD
5972 }
5973 run_test 99a "cvs init ========================================="
5974
5975 test_99b() {
5976         [ -z "$(which cvs 2>/dev/null)" ] &&
5977                 skip_env "could not find cvs" && return
5978         [ ! -d $DIR/d99cvsroot ] && test_99a
5979         cd /etc/init.d
5980         # some versions of cvs import exit(1) when asked to import links or
5981         # files they can't read.  ignore those files.
5982         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
5983                         ! -perm +4 -printf '-I %f\n')
5984         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
5985                 d99reposname vtag rtag
5986 }
5987 run_test 99b "cvs import ======================================="
5988
5989 test_99c() {
5990         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
5991         [ ! -d $DIR/d99cvsroot ] && test_99b
5992         cd $DIR
5993         test_mkdir -p $DIR/d99reposname
5994         chown $RUNAS_ID $DIR/d99reposname
5995         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
5996 }
5997 run_test 99c "cvs checkout ====================================="
5998
5999 test_99d() {
6000         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6001         [ ! -d $DIR/d99cvsroot ] && test_99c
6002         cd $DIR/d99reposname
6003         $RUNAS touch foo99
6004         $RUNAS cvs add -m 'addmsg' foo99
6005 }
6006 run_test 99d "cvs add =========================================="
6007
6008 test_99e() {
6009         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6010         [ ! -d $DIR/d99cvsroot ] && test_99c
6011         cd $DIR/d99reposname
6012         $RUNAS cvs update
6013 }
6014 run_test 99e "cvs update ======================================="
6015
6016 test_99f() {
6017         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6018         [ ! -d $DIR/d99cvsroot ] && test_99d
6019         cd $DIR/d99reposname
6020         $RUNAS cvs commit -m 'nomsg' foo99
6021     rm -fr $DIR/d99cvsroot
6022 }
6023 run_test 99f "cvs commit ======================================="
6024
6025 test_100() {
6026         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6027         [ "$NETTYPE" = tcp ] || \
6028                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
6029                         return ; }
6030
6031         remote_ost_nodsh && skip "remote OST with nodsh" && return
6032         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6033         remote_servers || \
6034                 { skip "useless for local single node setup" && return; }
6035
6036         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6037                 [ "$PROT" != "tcp" ] && continue
6038                 RPORT=$(echo $REMOTE | cut -d: -f2)
6039                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6040
6041                 rc=0
6042                 LPORT=`echo $LOCAL | cut -d: -f2`
6043                 if [ $LPORT -ge 1024 ]; then
6044                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6045                         netstat -tna
6046                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6047                 fi
6048         done
6049         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6050 }
6051 run_test 100 "check local port using privileged port ==========="
6052
6053 function get_named_value()
6054 {
6055     local tag
6056
6057     tag=$1
6058     while read ;do
6059         line=$REPLY
6060         case $line in
6061         $tag*)
6062             echo $line | sed "s/^$tag[ ]*//"
6063             break
6064             ;;
6065         esac
6066     done
6067 }
6068
6069 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6070                    awk '/^max_cached_mb/ { print $2 }')
6071
6072 cleanup_101a() {
6073         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6074         trap 0
6075 }
6076
6077 test_101a() {
6078         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6079         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
6080         local s
6081         local discard
6082         local nreads=10000
6083         local cache_limit=32
6084
6085         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6086         trap cleanup_101a EXIT
6087         $LCTL set_param -n llite.*.read_ahead_stats 0
6088         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6089
6090         #
6091         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6092         #
6093         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6094         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6095
6096         discard=0
6097         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6098                 get_named_value 'read but discarded' | cut -d" " -f1); do
6099                         discard=$(($discard + $s))
6100         done
6101         cleanup_101a
6102
6103         if [[ $(($discard * 10)) -gt $nreads ]]; then
6104                 $LCTL get_param osc.*-osc*.rpc_stats
6105                 $LCTL get_param llite.*.read_ahead_stats
6106                 error "too many ($discard) discarded pages"
6107         fi
6108         rm -f $DIR/$tfile || true
6109 }
6110 run_test 101a "check read-ahead for random reads ================"
6111
6112 setup_test101bc() {
6113         test_mkdir -p $DIR/$tdir
6114         local STRIPE_SIZE=$1
6115         local FILE_LENGTH=$2
6116         STRIPE_OFFSET=0
6117
6118         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6119
6120         local list=$(comma_list $(osts_nodes))
6121         set_osd_param $list '' read_cache_enable 0
6122         set_osd_param $list '' writethrough_cache_enable 0
6123
6124         trap cleanup_test101bc EXIT
6125         # prepare the read-ahead file
6126         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6127
6128         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6129                                 count=$FILE_SIZE_MB 2> /dev/null
6130
6131 }
6132
6133 cleanup_test101bc() {
6134         trap 0
6135         rm -rf $DIR/$tdir
6136         rm -f $DIR/$tfile
6137
6138         local list=$(comma_list $(osts_nodes))
6139         set_osd_param $list '' read_cache_enable 1
6140         set_osd_param $list '' writethrough_cache_enable 1
6141 }
6142
6143 calc_total() {
6144         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6145 }
6146
6147 ra_check_101() {
6148         local READ_SIZE=$1
6149         local STRIPE_SIZE=$2
6150         local FILE_LENGTH=$3
6151         local RA_INC=1048576
6152         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6153         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6154                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6155         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6156                         get_named_value 'read but discarded' |
6157                         cut -d" " -f1 | calc_total)
6158         if [[ $DISCARD -gt $discard_limit ]]; then
6159                 $LCTL get_param llite.*.read_ahead_stats
6160                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6161         else
6162                 echo "Read-ahead success for size ${READ_SIZE}"
6163         fi
6164 }
6165
6166 test_101b() {
6167         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6168         [[ $OSTCOUNT -lt 2 ]] &&
6169                 skip_env "skipping stride IO stride-ahead test" && return
6170         local STRIPE_SIZE=1048576
6171         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6172         if [ $SLOW == "yes" ]; then
6173                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6174         else
6175                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6176         fi
6177
6178         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6179
6180         # prepare the read-ahead file
6181         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6182         cancel_lru_locks osc
6183         for BIDX in 2 4 8 16 32 64 128 256
6184         do
6185                 local BSIZE=$((BIDX*4096))
6186                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6187                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6188                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6189                 $LCTL set_param -n llite.*.read_ahead_stats 0
6190                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6191                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6192                 cancel_lru_locks osc
6193                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6194         done
6195         cleanup_test101bc
6196         true
6197 }
6198 run_test 101b "check stride-io mode read-ahead ================="
6199
6200 test_101c() {
6201         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6202         local STRIPE_SIZE=1048576
6203         local FILE_LENGTH=$((STRIPE_SIZE*100))
6204         local nreads=10000
6205         local osc_rpc_stats
6206
6207         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6208
6209         cancel_lru_locks osc
6210         $LCTL set_param osc.*.rpc_stats 0
6211         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6212         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6213                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6214                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6215                 local size
6216
6217                 if [ $lines -le 20 ]; then
6218                         continue
6219                 fi
6220                 for size in 1 2 4 8; do
6221                         local rpc=$(echo "$stats" |
6222                                     awk '($1 == "'$size':") {print $2; exit; }')
6223                         [ $rpc != 0 ] &&
6224                                 error "Small $((size*4))k read IO $rpc !"
6225                 done
6226                 echo "$osc_rpc_stats check passed!"
6227         done
6228         cleanup_test101bc
6229         true
6230 }
6231 run_test 101c "check stripe_size aligned read-ahead ================="
6232
6233 set_read_ahead() {
6234         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6235         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6236 }
6237
6238 test_101d() {
6239         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6240         local file=$DIR/$tfile
6241         local sz_MB=${FILESIZE_101d:-500}
6242         local ra_MB=${READAHEAD_MB:-40}
6243
6244         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6245         [ $free_MB -lt $sz_MB ] &&
6246                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6247
6248         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6249         $SETSTRIPE -c -1 $file || error "setstripe failed"
6250
6251         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6252         echo Cancel LRU locks on lustre client to flush the client cache
6253         cancel_lru_locks osc
6254
6255         echo Disable read-ahead
6256         local old_READAHEAD=$(set_read_ahead 0)
6257
6258         echo Reading the test file $file with read-ahead disabled
6259         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6260
6261         echo Cancel LRU locks on lustre client to flush the client cache
6262         cancel_lru_locks osc
6263         echo Enable read-ahead with ${ra_MB}MB
6264         set_read_ahead $ra_MB
6265
6266         echo Reading the test file $file with read-ahead enabled
6267         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6268
6269         echo "read-ahead disabled time read $raOFF"
6270         echo "read-ahead enabled  time read $raON"
6271
6272         set_read_ahead $old_READAHEAD
6273         rm -f $file
6274         wait_delete_completed
6275
6276         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6277                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6278 }
6279 run_test 101d "file read with and without read-ahead enabled"
6280
6281 test_101e() {
6282         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6283         local file=$DIR/$tfile
6284         local size_KB=500  #KB
6285         local count=100
6286         local bsize=1024
6287
6288         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6289         local need_KB=$((count * size_KB))
6290         [[ $free_KB -le $need_KB ]] &&
6291                 skip_env "Need free space $need_KB, have $free_KB" && return
6292
6293         echo "Creating $count ${size_KB}K test files"
6294         for ((i = 0; i < $count; i++)); do
6295                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6296         done
6297
6298         echo "Cancel LRU locks on lustre client to flush the client cache"
6299         cancel_lru_locks osc
6300
6301         echo "Reset readahead stats"
6302         $LCTL set_param -n llite.*.read_ahead_stats 0
6303
6304         for ((i = 0; i < $count; i++)); do
6305                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6306         done
6307
6308         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6309                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6310
6311         for ((i = 0; i < $count; i++)); do
6312                 rm -rf $file.$i 2>/dev/null
6313         done
6314
6315         #10000 means 20% reads are missing in readahead
6316         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6317 }
6318 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6319
6320 cleanup_test101f() {
6321     trap 0
6322     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6323     rm -rf $DIR/$tfile 2>/dev/null
6324 }
6325
6326 test_101f() {
6327         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6328     local file=$DIR/$tfile
6329     local nreads=1000
6330
6331     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6332     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6333     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6334     trap cleanup_test101f EXIT
6335
6336     echo Cancel LRU locks on lustre client to flush the client cache
6337     cancel_lru_locks osc
6338
6339     echo Reset readahead stats
6340     $LCTL set_param -n llite.*.read_ahead_stats 0
6341     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6342     # readahead should read in 2M file on second read, so only miss
6343     # 2 pages.
6344     echo Random 4K reads on 2M file for 1000 times
6345     $READS -f $file -s 2097152 -b 4096 -n $nreads
6346
6347     echo checking missing pages
6348     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6349           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6350
6351     [ $miss -lt 3 ] || error "misses too much pages!"
6352     cleanup_test101f
6353 }
6354 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6355
6356 setup_test102() {
6357         test_mkdir -p $DIR/$tdir
6358         chown $RUNAS_ID $DIR/$tdir
6359         STRIPE_SIZE=65536
6360         STRIPE_OFFSET=1
6361         STRIPE_COUNT=$OSTCOUNT
6362         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6363
6364         trap cleanup_test102 EXIT
6365         cd $DIR
6366         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6367         cd $DIR/$tdir
6368         for num in 1 2 3 4; do
6369                 for count in $(seq 1 $STRIPE_COUNT); do
6370                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6371                                 local size=`expr $STRIPE_SIZE \* $num`
6372                                 local file=file"$num-$idx-$count"
6373                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6374                         done
6375                 done
6376         done
6377
6378         cd $DIR
6379         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6380 }
6381
6382 cleanup_test102() {
6383         trap 0
6384         rm -f $TMP/f102.tar
6385         rm -rf $DIR/d0.sanity/d102
6386 }
6387
6388 test_102a() {
6389         local testfile=$DIR/xattr_testfile
6390
6391         touch $testfile
6392
6393         [ "$UID" != 0 ] && skip_env "must run as root" && return
6394         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6395                 skip_env "must have user_xattr" && return
6396
6397         [ -z "$(which setfattr 2>/dev/null)" ] &&
6398                 skip_env "could not find setfattr" && return
6399
6400         echo "set/get xattr..."
6401         setfattr -n trusted.name1 -v value1 $testfile ||
6402                 error "setfattr -n trusted.name1=value1 $testfile failed"
6403         getfattr -n trusted.name1 $testfile 2> /dev/null |
6404           grep "trusted.name1=.value1" ||
6405                 error "$testfile missing trusted.name1=value1"
6406
6407         setfattr -n user.author1 -v author1 $testfile ||
6408                 error "setfattr -n user.author1=author1 $testfile failed"
6409         getfattr -n user.author1 $testfile 2> /dev/null |
6410           grep "user.author1=.author1" ||
6411                 error "$testfile missing trusted.author1=author1"
6412
6413         echo "listxattr..."
6414         setfattr -n trusted.name2 -v value2 $testfile ||
6415                 error "$testfile unable to set trusted.name2"
6416         setfattr -n trusted.name3 -v value3 $testfile ||
6417                 error "$testfile unable to set trusted.name3"
6418         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6419             grep "trusted.name" | wc -l) -eq 3 ] ||
6420                 error "$testfile missing 3 trusted.name xattrs"
6421
6422         setfattr -n user.author2 -v author2 $testfile ||
6423                 error "$testfile unable to set user.author2"
6424         setfattr -n user.author3 -v author3 $testfile ||
6425                 error "$testfile unable to set user.author3"
6426         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6427             grep "user.author" | wc -l) -eq 3 ] ||
6428                 error "$testfile missing 3 user.author xattrs"
6429
6430         echo "remove xattr..."
6431         setfattr -x trusted.name1 $testfile ||
6432                 error "$testfile error deleting trusted.name1"
6433         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6434                 error "$testfile did not delete trusted.name1 xattr"
6435
6436         setfattr -x user.author1 $testfile ||
6437                 error "$testfile error deleting user.author1"
6438         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6439                 error "$testfile did not delete trusted.name1 xattr"
6440
6441         # b10667: setting lustre special xattr be silently discarded
6442         echo "set lustre special xattr ..."
6443         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6444                 error "$testfile allowed setting trusted.lov"
6445 }
6446 run_test 102a "user xattr test =================================="
6447
6448 test_102b() {
6449         [ -z "$(which setfattr 2>/dev/null)" ] &&
6450                 skip_env "could not find setfattr" && return
6451
6452         # b10930: get/set/list trusted.lov xattr
6453         echo "get/set/list trusted.lov xattr ..."
6454         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6455         local testfile=$DIR/$tfile
6456         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6457                 error "setstripe failed"
6458         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6459                 error "getstripe failed"
6460         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6461                 error "can't get trusted.lov from $testfile"
6462
6463         local testfile2=${testfile}2
6464         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6465                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6466
6467         $MCREATE $testfile2
6468         setfattr -n trusted.lov -v $value $testfile2
6469         local stripe_size=$($GETSTRIPE -S $testfile2)
6470         local stripe_count=$($GETSTRIPE -c $testfile2)
6471         [[ $stripe_size -eq 65536 ]] ||
6472                 error "stripe size $stripe_size != 65536"
6473         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6474                 error "stripe count $stripe_count != $STRIPECOUNT"
6475         rm -f $DIR/$tfile
6476 }
6477 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6478
6479 test_102c() {
6480         [ -z "$(which setfattr 2>/dev/null)" ] &&
6481                 skip_env "could not find setfattr" && return
6482
6483         # b10930: get/set/list lustre.lov xattr
6484         echo "get/set/list lustre.lov xattr ..."
6485         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6486         test_mkdir -p $DIR/$tdir
6487         chown $RUNAS_ID $DIR/$tdir
6488         local testfile=$DIR/$tdir/$tfile
6489         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6490                 error "setstripe failed"
6491         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6492                 error "getstripe failed"
6493         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6494         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6495
6496         local testfile2=${testfile}2
6497         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6498                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6499
6500         $RUNAS $MCREATE $testfile2
6501         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6502         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6503         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6504         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6505         [ $stripe_count -eq $STRIPECOUNT ] ||
6506                 error "stripe count $stripe_count != $STRIPECOUNT"
6507 }
6508 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6509
6510 compare_stripe_info1() {
6511         local stripe_index_all_zero=true
6512
6513         for num in 1 2 3 4; do
6514                 for count in $(seq 1 $STRIPE_COUNT); do
6515                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6516                                 local size=$((STRIPE_SIZE * num))
6517                                 local file=file"$num-$offset-$count"
6518                                 stripe_size=$(lfs getstripe -S $PWD/$file)
6519                                 [[ $stripe_size -ne $size ]] &&
6520                                     error "$file: size $stripe_size != $size"
6521                                 stripe_count=$(lfs getstripe -c $PWD/$file)
6522                                 # allow fewer stripes to be created, ORI-601
6523                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6524                                     error "$file: count $stripe_count != $count"
6525                                 stripe_index=$(lfs getstripe -i $PWD/$file)
6526                                 [[ $stripe_index -ne 0 ]] &&
6527                                         stripe_index_all_zero=false
6528                         done
6529                 done
6530         done
6531         $stripe_index_all_zero &&
6532                 error "all files are being extracted starting from OST index 0"
6533         return 0
6534 }
6535
6536 find_lustre_tar() {
6537         [ -n "$(which tar 2>/dev/null)" ] &&
6538                 strings $(which tar) | grep -q "lustre" && echo tar
6539 }
6540
6541 test_102d() {
6542         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6543         # b10930: tar test for trusted.lov xattr
6544         TAR=$(find_lustre_tar)
6545         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6546         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6547         setup_test102
6548         test_mkdir -p $DIR/d102d
6549         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6550         cd $DIR/d102d/$tdir
6551         compare_stripe_info1
6552 }
6553 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6554
6555 test_102f() {
6556         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6557         # b10930: tar test for trusted.lov xattr
6558         TAR=$(find_lustre_tar)
6559         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6560         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6561         setup_test102
6562         test_mkdir -p $DIR/d102f
6563         cd $DIR
6564         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6565         cd $DIR/d102f/$tdir
6566         compare_stripe_info1
6567 }
6568 run_test 102f "tar copy files, not keep osts ==========="
6569
6570 grow_xattr() {
6571         local xsize=${1:-1024}  # in bytes
6572         local file=$DIR/$tfile
6573
6574         [ -z $(lctl get_param -n mdc.*.connect_flags | grep xattr) ] &&
6575                 skip "must have user_xattr" && return 0
6576         [ -z "$(which setfattr 2>/dev/null)" ] &&
6577                 skip_env "could not find setfattr" && return 0
6578         [ -z "$(which getfattr 2>/dev/null)" ] &&
6579                 skip_env "could not find getfattr" && return 0
6580
6581         touch $file
6582
6583         local value="$(generate_string $xsize)"
6584
6585         local xbig=trusted.big
6586         log "save $xbig on $file"
6587         setfattr -n $xbig -v $value $file ||
6588                 error "saving $xbig on $file failed"
6589
6590         local orig=$(get_xattr_value $xbig $file)
6591         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6592
6593         local xsml=trusted.sml
6594         log "save $xsml on $file"
6595         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6596
6597         local new=$(get_xattr_value $xbig $file)
6598         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6599
6600         log "grow $xsml on $file"
6601         setfattr -n $xsml -v "$value" $file ||
6602                 error "growing $xsml on $file failed"
6603
6604         new=$(get_xattr_value $xbig $file)
6605         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6606         log "$xbig still valid after growing $xsml"
6607
6608         rm -f $file
6609 }
6610
6611 test_102h() { # bug 15777
6612         grow_xattr 1024
6613 }
6614 run_test 102h "grow xattr from inside inode to external block"
6615
6616 test_102ha() {
6617         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6618         grow_xattr $(max_xattr_size)
6619 }
6620 run_test 102ha "grow xattr from inside inode to external inode"
6621
6622 test_102i() { # bug 17038
6623         [ -z "$(which getfattr 2>/dev/null)" ] &&
6624                 skip "could not find getfattr" && return
6625         touch $DIR/$tfile
6626         ln -s $DIR/$tfile $DIR/${tfile}link
6627         getfattr -n trusted.lov $DIR/$tfile ||
6628                 error "lgetxattr on $DIR/$tfile failed"
6629         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6630                 grep -i "no such attr" ||
6631                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6632         rm -f $DIR/$tfile $DIR/${tfile}link
6633 }
6634 run_test 102i "lgetxattr test on symbolic link ============"
6635
6636 test_102j() {
6637         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6638         TAR=$(find_lustre_tar)
6639         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6640         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6641         setup_test102 "$RUNAS"
6642         test_mkdir -p $DIR/d102j
6643         chown $RUNAS_ID $DIR/d102j
6644         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6645         cd $DIR/d102j/$tdir
6646         compare_stripe_info1 "$RUNAS"
6647 }
6648 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6649
6650 test_102k() {
6651         [ -z "$(which setfattr 2>/dev/null)" ] &&
6652                 skip "could not find setfattr" && return
6653         touch $DIR/$tfile
6654         # b22187 just check that does not crash for regular file.
6655         setfattr -n trusted.lov $DIR/$tfile
6656         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6657         local test_kdir=$DIR/d102k
6658         test_mkdir $test_kdir
6659         local default_size=`$GETSTRIPE -S $test_kdir`
6660         local default_count=`$GETSTRIPE -c $test_kdir`
6661         local default_offset=`$GETSTRIPE -i $test_kdir`
6662         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6663                 error 'dir setstripe failed'
6664         setfattr -n trusted.lov $test_kdir
6665         local stripe_size=`$GETSTRIPE -S $test_kdir`
6666         local stripe_count=`$GETSTRIPE -c $test_kdir`
6667         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6668         [ $stripe_size -eq $default_size ] ||
6669                 error "stripe size $stripe_size != $default_size"
6670         [ $stripe_count -eq $default_count ] ||
6671                 error "stripe count $stripe_count != $default_count"
6672         [ $stripe_offset -eq $default_offset ] ||
6673                 error "stripe offset $stripe_offset != $default_offset"
6674         rm -rf $DIR/$tfile $test_kdir
6675 }
6676 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6677
6678 test_102l() {
6679         [ -z "$(which getfattr 2>/dev/null)" ] &&
6680                 skip "could not find getfattr" && return
6681
6682         # LU-532 trusted. xattr is invisible to non-root
6683         local testfile=$DIR/$tfile
6684
6685         touch $testfile
6686
6687         echo "listxattr as user..."
6688         chown $RUNAS_ID $testfile
6689         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6690             grep -q "trusted" &&
6691                 error "$testfile trusted xattrs are user visible"
6692
6693         return 0;
6694 }
6695 run_test 102l "listxattr size test =================================="
6696
6697 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6698         local path=$DIR/$tfile
6699         touch $path
6700
6701         listxattr_size_check $path || error "listattr_size_check $path failed"
6702 }
6703 run_test 102m "Ensure listxattr fails on small bufffer ========"
6704
6705 cleanup_test102
6706
6707 getxattr() { # getxattr path name
6708         # Return the base64 encoding of the value of xattr name on path.
6709         local path=$1
6710         local name=$2
6711
6712         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6713         # file: $path
6714         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6715         #
6716         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6717
6718         getfattr --absolute-names --encoding=base64 --name=$name $path |
6719                 awk -F= -v name=$name '$1 == name {
6720                         print substr($0, index($0, "=") + 1);
6721         }'
6722 }
6723
6724 test_102n() { # LU-4101 mdt: protect internal xattrs
6725         local file0=$DIR/$tfile.0
6726         local file1=$DIR/$tfile.1
6727         local xattr0=$TMP/$tfile.0
6728         local xattr1=$TMP/$tfile.1
6729         local name
6730         local value
6731
6732         [ -z "$(which setfattr 2>/dev/null)" ] &&
6733                 skip "could not find setfattr" && return
6734
6735         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6736         then
6737                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6738                 return
6739         fi
6740
6741         rm -rf $file0 $file1 $xattr0 $xattr1
6742         touch $file0 $file1
6743
6744         # Get 'before' xattrs of $file1.
6745         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6746
6747         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6748                 # Try to copy xattr from $file0 to $file1.
6749                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6750
6751                 setfattr --name=trusted.$name --value="$value" $file1 ||
6752                         error "setxattr 'trusted.$name' failed"
6753
6754                 # Try to set a garbage xattr.
6755                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6756
6757                 setfattr --name=trusted.$name --value="$value" $file1 ||
6758                         error "setxattr 'trusted.$name' failed"
6759
6760                 # Try to remove the xattr from $file1. We don't care if this
6761                 # appears to succeed or fail, we just don't want there to be
6762                 # any changes or crashes.
6763                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6764         done
6765
6766         # Get 'after' xattrs of file1.
6767         getfattr --absolute-names --dump --match=- $file1 > $xattr1
6768
6769         if ! diff $xattr0 $xattr1; then
6770                 error "before and after xattrs of '$file1' differ"
6771         fi
6772
6773         rm -rf $file0 $file1 $xattr0 $xattr1
6774
6775         return 0
6776 }
6777 run_test 102n "silently ignore setxattr on internal trusted xattrs"
6778
6779 test_102p() { # LU-4703 setxattr did not check ownership
6780         local testfile=$DIR/$tfile
6781
6782         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
6783                 skip "MDS needs to be at least 2.5.56" && return
6784
6785         touch $testfile
6786
6787         echo "setfacl as user..."
6788         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
6789         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
6790
6791         echo "setfattr as user..."
6792         setfacl -m "u:$RUNAS_ID:---" $testfile
6793         $RUNAS setfattr -x system.posix_acl_access $testfile
6794         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
6795 }
6796 run_test 102p "check setxattr(2) correctly fails without permission"
6797
6798 run_acl_subtest()
6799 {
6800     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
6801     return $?
6802 }
6803
6804 test_103 () {
6805         [ "$UID" != 0 ] && skip_env "must run as root" && return
6806         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
6807                 skip "must have acl enabled" && return
6808         [ -z "$(which setfacl 2>/dev/null)" ] &&
6809                 skip_env "could not find setfacl" && return
6810         $GSS && skip "could not run under gss" && return
6811
6812         declare -a identity_old
6813
6814         for num in $(seq $MDSCOUNT); do
6815                 switch_identity $num true || identity_old[$num]=$?
6816         done
6817
6818         SAVE_UMASK=$(umask)
6819         umask 0022
6820         cd $DIR
6821
6822         echo "performing cp ..."
6823         run_acl_subtest cp || error "run_acl_subtest cp failed"
6824         echo "performing getfacl-noacl..."
6825         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
6826         echo "performing misc..."
6827         run_acl_subtest misc || error  "misc test failed"
6828         echo "performing permissions..."
6829         run_acl_subtest permissions || error "permissions failed"
6830         echo "performing setfacl..."
6831         run_acl_subtest setfacl || error  "setfacl test failed"
6832
6833         # inheritance test got from HP
6834         echo "performing inheritance..."
6835         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
6836         chmod +x make-tree || error "chmod +x failed"
6837         run_acl_subtest inheritance || error "inheritance test failed"
6838         rm -f make-tree
6839
6840         echo "LU-974 ignore umask when acl is enabled..."
6841         run_acl_subtest 974 || error "LU-974 umask test failed"
6842         if [ $MDSCOUNT -ge 2 ]; then
6843                 run_acl_subtest 974_remote ||
6844                         error "LU-974 umask test failed under remote dir"
6845         fi
6846
6847         echo "LU-2561 newly created file is same size as directory..."
6848         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
6849                 run_acl_subtest 2561 || error "LU-2561 test failed"
6850         else
6851                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
6852         fi
6853
6854         run_acl_subtest 4924 || error "LU-4924 test failed"
6855
6856         cd $SAVE_PWD
6857         umask $SAVE_UMASK
6858
6859         for num in $(seq $MDSCOUNT); do
6860                 if [ "${identity_old[$num]}" = 1 ]; then
6861                         switch_identity $num false || identity_old[$num]=$?
6862                 fi
6863         done
6864 }
6865 run_test 103 "acl test ========================================="
6866
6867 test_104a() {
6868         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6869         touch $DIR/$tfile
6870         lfs df || error "lfs df failed"
6871         lfs df -ih || error "lfs df -ih failed"
6872         lfs df -h $DIR || error "lfs df -h $DIR failed"
6873         lfs df -i $DIR || error "lfs df -i $DIR failed"
6874         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
6875         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
6876
6877         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
6878         lctl --device %$OSC deactivate
6879         lfs df || error "lfs df with deactivated OSC failed"
6880         lctl --device %$OSC activate
6881         # wait the osc back to normal
6882         wait_osc_import_state client ost FULL
6883
6884         lfs df || error "lfs df with reactivated OSC failed"
6885         rm -f $DIR/$tfile
6886 }
6887 run_test 104a "lfs df [-ih] [path] test ========================="
6888
6889 test_104b() {
6890         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6891         [ $RUNAS_ID -eq $UID ] &&
6892                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
6893         chmod 666 /dev/obd
6894         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
6895                         grep "Permission denied" | wc -l)))
6896         if [ $denied_cnt -ne 0 ]; then
6897                 error "lfs check servers test failed"
6898         fi
6899 }
6900 run_test 104b "$RUNAS lfs check servers test ===================="
6901
6902 test_105a() {
6903         # doesn't work on 2.4 kernels
6904         touch $DIR/$tfile
6905         if $(flock_is_enabled); then
6906                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
6907         else
6908                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
6909         fi
6910         rm -f $DIR/$tfile
6911 }
6912 run_test 105a "flock when mounted without -o flock test ========"
6913
6914 test_105b() {
6915         touch $DIR/$tfile
6916         if $(flock_is_enabled); then
6917                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
6918         else
6919                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
6920         fi
6921         rm -f $DIR/$tfile
6922 }
6923 run_test 105b "fcntl when mounted without -o flock test ========"
6924
6925 test_105c() {
6926         touch $DIR/$tfile
6927         if $(flock_is_enabled); then
6928                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
6929         else
6930                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
6931         fi
6932         rm -f $DIR/$tfile
6933 }
6934 run_test 105c "lockf when mounted without -o flock test ========"
6935
6936 test_105d() { # bug 15924
6937         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6938         test_mkdir -p $DIR/$tdir
6939         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
6940         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
6941         $LCTL set_param fail_loc=0x80000315
6942         flocks_test 2 $DIR/$tdir
6943 }
6944 run_test 105d "flock race (should not freeze) ========"
6945
6946 test_105e() { # bug 22660 && 22040
6947         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
6948         touch $DIR/$tfile
6949         flocks_test 3 $DIR/$tfile
6950 }
6951 run_test 105e "Two conflicting flocks from same process ======="
6952
6953 test_106() { #bug 10921
6954         test_mkdir -p $DIR/$tdir
6955         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
6956         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
6957 }
6958 run_test 106 "attempt exec of dir followed by chown of that dir"
6959
6960 test_107() {
6961         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6962         CDIR=`pwd`
6963         cd $DIR
6964
6965         local file=core
6966         rm -f $file
6967
6968         local save_pattern=$(sysctl -n kernel.core_pattern)
6969         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
6970         sysctl -w kernel.core_pattern=$file
6971         sysctl -w kernel.core_uses_pid=0
6972
6973         ulimit -c unlimited
6974         sleep 60 &
6975         SLEEPPID=$!
6976
6977         sleep 1
6978
6979         kill -s 11 $SLEEPPID
6980         wait $SLEEPPID
6981         if [ -e $file ]; then
6982                 size=`stat -c%s $file`
6983                 [ $size -eq 0 ] && error "Fail to create core file $file"
6984         else
6985                 error "Fail to create core file $file"
6986         fi
6987         rm -f $file
6988         sysctl -w kernel.core_pattern=$save_pattern
6989         sysctl -w kernel.core_uses_pid=$save_uses_pid
6990         cd $CDIR
6991 }
6992 run_test 107 "Coredump on SIG"
6993
6994 test_110() {
6995         test_mkdir -p $DIR/$tdir
6996         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
6997                 error "mkdir with 255 char failed"
6998         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
6999                 error "mkdir with 256 char should fail, but did not"
7000         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7001                 error "create with 255 char failed"
7002         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7003                 error "create with 256 char should fail, but did not"
7004
7005         ls -l $DIR/$tdir
7006         rm -rf $DIR/$tdir
7007 }
7008 run_test 110 "filename length checking"
7009
7010 test_115() {
7011         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7012         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
7013                 tail -1 | cut -c11-20)
7014         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
7015         echo "Starting with $OSTIO_pre threads"
7016
7017         NUMTEST=20000
7018         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7019         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
7020         echo "$NUMTEST creates/unlinks"
7021         test_mkdir -p $DIR/$tdir
7022         createmany -o $DIR/$tdir/$tfile $NUMTEST
7023         unlinkmany $DIR/$tdir/$tfile $NUMTEST
7024
7025         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
7026                 tail -1 | cut -c11-20)
7027
7028         # don't return an error
7029         [ $OSTIO_post == $OSTIO_pre ] && echo \
7030             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
7031             echo "This may be fine, depending on what ran before this test" &&
7032             echo "and how fast this system is." && return
7033
7034         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
7035 }
7036 run_test 115 "verify dynamic thread creation===================="
7037
7038 free_min_max () {
7039         wait_delete_completed
7040         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7041         echo OST kbytes available: ${AVAIL[@]}
7042         MAXI=0; MAXV=${AVAIL[0]}
7043         MINI=0; MINV=${AVAIL[0]}
7044         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7045                 #echo OST $i: ${AVAIL[i]}kb
7046                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7047                         MAXV=${AVAIL[i]}; MAXI=$i
7048                 fi
7049                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7050                         MINV=${AVAIL[i]}; MINI=$i
7051                 fi
7052         done
7053         echo Min free space: OST $MINI: $MINV
7054         echo Max free space: OST $MAXI: $MAXV
7055 }
7056
7057 test_116a() { # was previously test_116()
7058         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7059         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
7060
7061         echo -n "Free space priority "
7062         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7063                 head -n1
7064         declare -a AVAIL
7065         free_min_max
7066
7067         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7068         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7069                 && return
7070         trap simple_cleanup_common EXIT
7071
7072
7073         # Check if we need to generate uneven OSTs
7074         test_mkdir -p $DIR/$tdir/OST${MINI}
7075         local FILL=$(($MINV / 4))
7076         local DIFF=$(($MAXV - $MINV))
7077         local DIFF2=$(($DIFF * 100 / $MINV))
7078
7079         local threshold=$(do_facet $SINGLEMDS \
7080                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7081         threshold=${threshold%%%}
7082         echo -n "Check for uneven OSTs: "
7083         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7084
7085         if [[ $DIFF2 -gt $threshold ]]; then
7086                 echo "ok"
7087                 echo "Don't need to fill OST$MINI"
7088         else
7089                 # generate uneven OSTs. Write 2% over the QOS threshold value
7090                 echo "no"
7091                 DIFF=$(($threshold - $DIFF2 + 2))
7092                 DIFF2=$(( ($MINV * $DIFF)/100 ))
7093                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
7094                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7095                         error "setstripe failed"
7096                 DIFF=$(($DIFF2 / 2048))
7097                 i=0
7098                 while [ $i -lt $DIFF ]; do
7099                         i=$(($i + 1))
7100                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7101                                 bs=2M count=1 2>/dev/null
7102                         echo -n .
7103                 done
7104                 echo .
7105                 sync
7106                 sleep_maxage
7107                 free_min_max
7108         fi
7109
7110         DIFF=$(($MAXV - $MINV))
7111         DIFF2=$(($DIFF * 100 / $MINV))
7112         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
7113         if [[ $DIFF2 -gt $threshold ]]; then
7114                 echo "ok"
7115         else
7116                 echo "failed - QOS mode won't be used"
7117                 skip "QOS imbalance criteria not met"
7118                 simple_cleanup_common
7119                 return
7120         fi
7121
7122         MINI1=$MINI; MINV1=$MINV
7123         MAXI1=$MAXI; MAXV1=$MAXV
7124
7125         # now fill using QOS
7126         $SETSTRIPE -c 1 $DIR/$tdir
7127         FILL=$(($FILL / 200))
7128         if [ $FILL -gt 600 ]; then
7129                 FILL=600
7130         fi
7131         echo "writing $FILL files to QOS-assigned OSTs"
7132         i=0
7133         while [ $i -lt $FILL ]; do
7134                 i=$((i + 1))
7135                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7136                         count=1 2>/dev/null
7137                 echo -n .
7138         done
7139         echo "wrote $i 200k files"
7140         sync
7141         sleep_maxage
7142
7143         echo "Note: free space may not be updated, so measurements might be off"
7144         free_min_max
7145         DIFF2=$(($MAXV - $MINV))
7146         echo "free space delta: orig $DIFF final $DIFF2"
7147         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7148         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
7149         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7150         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
7151         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7152         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7153         [ $DIFF -gt 0 ] &&
7154                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7155
7156         # Figure out which files were written where
7157         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7158                   awk '/'$MINI1': / {print $2; exit}')
7159         echo $UUID
7160         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7161         echo "$MINC files created on smaller OST $MINI1"
7162         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7163                   awk '/'$MAXI1': / {print $2; exit}')
7164         echo $UUID
7165         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7166         echo "$MAXC files created on larger OST $MAXI1"
7167         FILL=$(($MAXC * 100 / $MINC - 100))
7168         [[ $MINC -gt 0 ]] &&
7169                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7170         [[ $MAXC -gt $MINC ]] ||
7171                 error_ignore LU-9 "stripe QOS didn't balance free space"
7172         simple_cleanup_common
7173 }
7174 run_test 116a "stripe QOS: free space balance ==================="
7175
7176 test_116b() { # LU-2093
7177         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7178         [ -z "$($LCTL get_param -n lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr |
7179                 head -1 2>/dev/null)" ] && skip "no QOS" && return
7180 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7181         local old_rr
7182         old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7183                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7184         do_facet $SINGLEMDS lctl set_param \
7185                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7186         mkdir -p $DIR/$tdir
7187         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7188         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7189         do_facet $SINGLEMDS lctl set_param fail_loc=0
7190         rm -rf $DIR/$tdir
7191         do_facet $SINGLEMDS lctl set_param \
7192                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7193 }
7194 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7195
7196 test_117() # bug 10891
7197 {
7198         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7199         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7200         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7201         lctl set_param fail_loc=0x21e
7202         > $DIR/$tfile || error "truncate failed"
7203         lctl set_param fail_loc=0
7204         echo "Truncate succeeded."
7205         rm -f $DIR/$tfile
7206 }
7207 run_test 117 "verify osd extend =========="
7208
7209 NO_SLOW_RESENDCOUNT=4
7210 export OLD_RESENDCOUNT=""
7211 set_resend_count () {
7212         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7213         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7214         lctl set_param -n $PROC_RESENDCOUNT $1
7215         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7216 }
7217
7218 # for reduce test_118* time (b=14842)
7219 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7220
7221 # Reset async IO behavior after error case
7222 reset_async() {
7223         FILE=$DIR/reset_async
7224
7225         # Ensure all OSCs are cleared
7226         $SETSTRIPE -c -1 $FILE
7227         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7228         sync
7229         rm $FILE
7230 }
7231
7232 test_118a() #bug 11710
7233 {
7234         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7235         reset_async
7236
7237         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7238         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7239         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7240
7241         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7242                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7243                 return 1;
7244         fi
7245         rm -f $DIR/$tfile
7246 }
7247 run_test 118a "verify O_SYNC works =========="
7248
7249 test_118b()
7250 {
7251         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7252         remote_ost_nodsh && skip "remote OST with nodsh" && return
7253
7254         reset_async
7255
7256         #define OBD_FAIL_OST_ENOENT 0x217
7257         set_nodes_failloc "$(osts_nodes)" 0x217
7258         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7259         RC=$?
7260         set_nodes_failloc "$(osts_nodes)" 0
7261         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7262         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7263                     grep -c writeback)
7264
7265         if [[ $RC -eq 0 ]]; then
7266                 error "Must return error due to dropped pages, rc=$RC"
7267                 return 1;
7268         fi
7269
7270         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7271                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7272                 return 1;
7273         fi
7274
7275         echo "Dirty pages not leaked on ENOENT"
7276
7277         # Due to the above error the OSC will issue all RPCs syncronously
7278         # until a subsequent RPC completes successfully without error.
7279         $MULTIOP $DIR/$tfile Ow4096yc
7280         rm -f $DIR/$tfile
7281
7282         return 0
7283 }
7284 run_test 118b "Reclaim dirty pages on fatal error =========="
7285
7286 test_118c()
7287 {
7288         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7289
7290         # for 118c, restore the original resend count, LU-1940
7291         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7292                                 set_resend_count $OLD_RESENDCOUNT
7293         remote_ost_nodsh && skip "remote OST with nodsh" && return
7294
7295         reset_async
7296
7297         #define OBD_FAIL_OST_EROFS               0x216
7298         set_nodes_failloc "$(osts_nodes)" 0x216
7299
7300         # multiop should block due to fsync until pages are written
7301         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7302         MULTIPID=$!
7303         sleep 1
7304
7305         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7306                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7307         fi
7308
7309         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7310                     grep -c writeback)
7311         if [[ $WRITEBACK -eq 0 ]]; then
7312                 error "No page in writeback, writeback=$WRITEBACK"
7313         fi
7314
7315         set_nodes_failloc "$(osts_nodes)" 0
7316         wait $MULTIPID
7317         RC=$?
7318         if [[ $RC -ne 0 ]]; then
7319                 error "Multiop fsync failed, rc=$RC"
7320         fi
7321
7322         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7323         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7324                     grep -c writeback)
7325         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7326                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7327         fi
7328
7329         rm -f $DIR/$tfile
7330         echo "Dirty pages flushed via fsync on EROFS"
7331         return 0
7332 }
7333 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7334
7335 # continue to use small resend count to reduce test_118* time (b=14842)
7336 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7337
7338 test_118d()
7339 {
7340         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7341         remote_ost_nodsh && skip "remote OST with nodsh" && return
7342
7343         reset_async
7344
7345         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7346         set_nodes_failloc "$(osts_nodes)" 0x214
7347         # multiop should block due to fsync until pages are written
7348         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7349         MULTIPID=$!
7350         sleep 1
7351
7352         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7353                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7354         fi
7355
7356         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7357                     grep -c writeback)
7358         if [[ $WRITEBACK -eq 0 ]]; then
7359                 error "No page in writeback, writeback=$WRITEBACK"
7360         fi
7361
7362         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7363         set_nodes_failloc "$(osts_nodes)" 0
7364
7365         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7366         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7367                     grep -c writeback)
7368         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7369                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7370         fi
7371
7372         rm -f $DIR/$tfile
7373         echo "Dirty pages gaurenteed flushed via fsync"
7374         return 0
7375 }
7376 run_test 118d "Fsync validation inject a delay of the bulk =========="
7377
7378 test_118f() {
7379         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7380         reset_async
7381
7382         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7383         lctl set_param fail_loc=0x8000040a
7384
7385         # Should simulate EINVAL error which is fatal
7386         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7387         RC=$?
7388         if [[ $RC -eq 0 ]]; then
7389                 error "Must return error due to dropped pages, rc=$RC"
7390         fi
7391
7392         lctl set_param fail_loc=0x0
7393
7394         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7395         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7396         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7397                     grep -c writeback)
7398         if [[ $LOCKED -ne 0 ]]; then
7399                 error "Locked pages remain in cache, locked=$LOCKED"
7400         fi
7401
7402         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7403                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7404         fi
7405
7406         rm -f $DIR/$tfile
7407         echo "No pages locked after fsync"
7408
7409         reset_async
7410         return 0
7411 }
7412 run_test 118f "Simulate unrecoverable OSC side error =========="
7413
7414 test_118g() {
7415         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7416         reset_async
7417
7418         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7419         lctl set_param fail_loc=0x406
7420
7421         # simulate local -ENOMEM
7422         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7423         RC=$?
7424
7425         lctl set_param fail_loc=0
7426         if [[ $RC -eq 0 ]]; then
7427                 error "Must return error due to dropped pages, rc=$RC"
7428         fi
7429
7430         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7431         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7432         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7433                         grep -c writeback)
7434         if [[ $LOCKED -ne 0 ]]; then
7435                 error "Locked pages remain in cache, locked=$LOCKED"
7436         fi
7437
7438         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7439                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7440         fi
7441
7442         rm -f $DIR/$tfile
7443         echo "No pages locked after fsync"
7444
7445         reset_async
7446         return 0
7447 }
7448 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7449
7450 test_118h() {
7451         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7452         remote_ost_nodsh && skip "remote OST with nodsh" && return
7453
7454         reset_async
7455
7456         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7457         set_nodes_failloc "$(osts_nodes)" 0x20e
7458         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7459         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7460         RC=$?
7461
7462         set_nodes_failloc "$(osts_nodes)" 0
7463         if [[ $RC -eq 0 ]]; then
7464                 error "Must return error due to dropped pages, rc=$RC"
7465         fi
7466
7467         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7468         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7469         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7470                     grep -c writeback)
7471         if [[ $LOCKED -ne 0 ]]; then
7472                 error "Locked pages remain in cache, locked=$LOCKED"
7473         fi
7474
7475         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7476                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7477         fi
7478
7479         rm -f $DIR/$tfile
7480         echo "No pages locked after fsync"
7481
7482         return 0
7483 }
7484 run_test 118h "Verify timeout in handling recoverables errors  =========="
7485
7486 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7487
7488 test_118i() {
7489         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7490         remote_ost_nodsh && skip "remote OST with nodsh" && return
7491
7492         reset_async
7493
7494         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7495         set_nodes_failloc "$(osts_nodes)" 0x20e
7496
7497         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7498         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7499         PID=$!
7500         sleep 5
7501         set_nodes_failloc "$(osts_nodes)" 0
7502
7503         wait $PID
7504         RC=$?
7505         if [[ $RC -ne 0 ]]; then
7506                 error "got error, but should be not, rc=$RC"
7507         fi
7508
7509         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7510         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7511         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7512         if [[ $LOCKED -ne 0 ]]; then
7513                 error "Locked pages remain in cache, locked=$LOCKED"
7514         fi
7515
7516         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7517                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7518         fi
7519
7520         rm -f $DIR/$tfile
7521         echo "No pages locked after fsync"
7522
7523         return 0
7524 }
7525 run_test 118i "Fix error before timeout in recoverable error  =========="
7526
7527 [ "$SLOW" = "no" ] && set_resend_count 4
7528
7529 test_118j() {
7530         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7531         remote_ost_nodsh && skip "remote OST with nodsh" && return
7532
7533         reset_async
7534
7535         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7536         set_nodes_failloc "$(osts_nodes)" 0x220
7537
7538         # return -EIO from OST
7539         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7540         RC=$?
7541         set_nodes_failloc "$(osts_nodes)" 0x0
7542         if [[ $RC -eq 0 ]]; then
7543                 error "Must return error due to dropped pages, rc=$RC"
7544         fi
7545
7546         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7547         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7548         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7549         if [[ $LOCKED -ne 0 ]]; then
7550                 error "Locked pages remain in cache, locked=$LOCKED"
7551         fi
7552
7553         # in recoverable error on OST we want resend and stay until it finished
7554         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7555                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7556         fi
7557
7558         rm -f $DIR/$tfile
7559         echo "No pages locked after fsync"
7560
7561         return 0
7562 }
7563 run_test 118j "Simulate unrecoverable OST side error =========="
7564
7565 test_118k()
7566 {
7567         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7568         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7569
7570         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7571         set_nodes_failloc "$(osts_nodes)" 0x20e
7572         test_mkdir -p $DIR/$tdir
7573
7574         for ((i=0;i<10;i++)); do
7575                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7576                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7577                 SLEEPPID=$!
7578                 sleep 0.500s
7579                 kill $SLEEPPID
7580                 wait $SLEEPPID
7581         done
7582
7583         set_nodes_failloc "$(osts_nodes)" 0
7584         rm -rf $DIR/$tdir
7585 }
7586 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7587
7588 test_118l()
7589 {
7590         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7591         # LU-646
7592         test_mkdir -p $DIR/$tdir
7593         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7594         rm -rf $DIR/$tdir
7595 }
7596 run_test 118l "fsync dir ========="
7597
7598 test_118m() # LU-3066
7599 {
7600         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7601         test_mkdir -p $DIR/$tdir
7602         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7603         rm -rf $DIR/$tdir
7604 }
7605 run_test 118m "fdatasync dir ========="
7606
7607 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7608
7609 test_119a() # bug 11737
7610 {
7611         BSIZE=$((512 * 1024))
7612         directio write $DIR/$tfile 0 1 $BSIZE
7613         # We ask to read two blocks, which is more than a file size.
7614         # directio will indicate an error when requested and actual
7615         # sizes aren't equeal (a normal situation in this case) and
7616         # print actual read amount.
7617         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7618         if [ "$NOB" != "$BSIZE" ]; then
7619                 error "read $NOB bytes instead of $BSIZE"
7620         fi
7621         rm -f $DIR/$tfile
7622 }
7623 run_test 119a "Short directIO read must return actual read amount"
7624
7625 test_119b() # bug 11737
7626 {
7627         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7628
7629         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7630         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7631         sync
7632         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7633                 error "direct read failed"
7634         rm -f $DIR/$tfile
7635 }
7636 run_test 119b "Sparse directIO read must return actual read amount"
7637
7638 test_119c() # bug 13099
7639 {
7640         BSIZE=1048576
7641         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7642         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7643         rm -f $DIR/$tfile
7644 }
7645 run_test 119c "Testing for direct read hitting hole"
7646
7647 test_119d() # bug 15950
7648 {
7649         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7650         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7651         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7652         BSIZE=1048576
7653         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7654         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7655         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7656         lctl set_param fail_loc=0x40d
7657         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7658         pid_dio=$!
7659         sleep 1
7660         cat $DIR/$tfile > /dev/null &
7661         lctl set_param fail_loc=0
7662         pid_reads=$!
7663         wait $pid_dio
7664         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7665         sleep 2
7666         [ -n "`ps h -p $pid_reads -o comm`" ] && \
7667         error "the read rpcs have not completed in 2s"
7668         rm -f $DIR/$tfile
7669         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
7670 }
7671 run_test 119d "The DIO path should try to send a new rpc once one is completed"
7672
7673 test_120a() {
7674         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7675         test_mkdir -p $DIR/$tdir
7676         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7677                skip "no early lock cancel on server" && return 0
7678
7679         lru_resize_disable mdc
7680         lru_resize_disable osc
7681         cancel_lru_locks mdc
7682         # asynchronous object destroy at MDT could cause bl ast to client
7683         cancel_lru_locks osc
7684
7685         stat $DIR/$tdir > /dev/null
7686         can1=$(do_facet $SINGLEMDS \
7687                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7688                awk '/ldlm_cancel/ {print $2}')
7689         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7690                awk '/ldlm_bl_callback/ {print $2}')
7691         test_mkdir -c1 $DIR/$tdir/d1
7692         can2=$(do_facet $SINGLEMDS \
7693                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7694                awk '/ldlm_cancel/ {print $2}')
7695         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7696                awk '/ldlm_bl_callback/ {print $2}')
7697         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7698         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7699         lru_resize_enable mdc
7700         lru_resize_enable osc
7701 }
7702 run_test 120a "Early Lock Cancel: mkdir test"
7703
7704 test_120b() {
7705         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7706         test_mkdir $DIR/$tdir
7707         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7708                skip "no early lock cancel on server" && return 0
7709         lru_resize_disable mdc
7710         lru_resize_disable osc
7711         cancel_lru_locks mdc
7712         stat $DIR/$tdir > /dev/null
7713         can1=$(do_facet $SINGLEMDS \
7714                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7715                awk '/ldlm_cancel/ {print $2}')
7716         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7717                awk '/ldlm_bl_callback/ {print $2}')
7718         touch $DIR/$tdir/f1
7719         can2=$(do_facet $SINGLEMDS \
7720                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7721                awk '/ldlm_cancel/ {print $2}')
7722         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7723                awk '/ldlm_bl_callback/ {print $2}')
7724         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7725         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7726         lru_resize_enable mdc
7727         lru_resize_enable osc
7728 }
7729 run_test 120b "Early Lock Cancel: create test"
7730
7731 test_120c() {
7732         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7733         test_mkdir -c1 $DIR/$tdir
7734         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7735                skip "no early lock cancel on server" && return 0
7736         lru_resize_disable mdc
7737         lru_resize_disable osc
7738         test_mkdir -p -c1 $DIR/$tdir/d1
7739         test_mkdir -p -c1 $DIR/$tdir/d2
7740         touch $DIR/$tdir/d1/f1
7741         cancel_lru_locks mdc
7742         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
7743         can1=$(do_facet $SINGLEMDS \
7744                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7745                awk '/ldlm_cancel/ {print $2}')
7746         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7747                awk '/ldlm_bl_callback/ {print $2}')
7748         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7749         can2=$(do_facet $SINGLEMDS \
7750                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7751                awk '/ldlm_cancel/ {print $2}')
7752         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7753                awk '/ldlm_bl_callback/ {print $2}')
7754         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7755         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7756         lru_resize_enable mdc
7757         lru_resize_enable osc
7758 }
7759 run_test 120c "Early Lock Cancel: link test"
7760
7761 test_120d() {
7762         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7763         test_mkdir -p -c1 $DIR/$tdir
7764         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
7765                skip "no early lock cancel on server" && return 0
7766         lru_resize_disable mdc
7767         lru_resize_disable osc
7768         touch $DIR/$tdir
7769         cancel_lru_locks mdc
7770         stat $DIR/$tdir > /dev/null
7771         can1=$(do_facet $SINGLEMDS \
7772                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7773                awk '/ldlm_cancel/ {print $2}')
7774         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7775                awk '/ldlm_bl_callback/ {print $2}')
7776         chmod a+x $DIR/$tdir
7777         can2=$(do_facet $SINGLEMDS \
7778                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7779                awk '/ldlm_cancel/ {print $2}')
7780         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7781                awk '/ldlm_bl_callback/ {print $2}')
7782         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7783         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7784         lru_resize_enable mdc
7785         lru_resize_enable osc
7786 }
7787 run_test 120d "Early Lock Cancel: setattr test"
7788
7789 test_120e() {
7790         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7791         test_mkdir -p -c1 $DIR/$tdir
7792         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7793                skip "no early lock cancel on server" && return 0
7794         lru_resize_disable mdc
7795         lru_resize_disable osc
7796         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
7797         cancel_lru_locks mdc
7798         cancel_lru_locks osc
7799         dd if=$DIR/$tdir/f1 of=/dev/null
7800         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
7801         # XXX client can not do early lock cancel of OST lock
7802         # during unlink (LU-4206), so cancel osc lock now.
7803         cancel_lru_locks osc
7804         can1=$(do_facet $SINGLEMDS \
7805                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7806                awk '/ldlm_cancel/ {print $2}')
7807         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7808                awk '/ldlm_bl_callback/ {print $2}')
7809         unlink $DIR/$tdir/f1
7810         sleep 5
7811         can2=$(do_facet $SINGLEMDS \
7812                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7813                awk '/ldlm_cancel/ {print $2}')
7814         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7815                awk '/ldlm_bl_callback/ {print $2}')
7816         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7817         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7818         lru_resize_enable mdc
7819         lru_resize_enable osc
7820 }
7821 run_test 120e "Early Lock Cancel: unlink test"
7822
7823 test_120f() {
7824         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7825         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7826                skip "no early lock cancel on server" && return 0
7827         test_mkdir -p -c1 $DIR/$tdir
7828         lru_resize_disable mdc
7829         lru_resize_disable osc
7830         test_mkdir -p -c1 $DIR/$tdir/d1
7831         test_mkdir -p -c1 $DIR/$tdir/d2
7832         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
7833         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
7834         cancel_lru_locks mdc
7835         cancel_lru_locks osc
7836         dd if=$DIR/$tdir/d1/f1 of=/dev/null
7837         dd if=$DIR/$tdir/d2/f2 of=/dev/null
7838         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
7839         # XXX client can not do early lock cancel of OST lock
7840         # during rename (LU-4206), so cancel osc lock now.
7841         cancel_lru_locks osc
7842         can1=$(do_facet $SINGLEMDS \
7843                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7844                awk '/ldlm_cancel/ {print $2}')
7845         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7846                awk '/ldlm_bl_callback/ {print $2}')
7847         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
7848         sleep 5
7849         can2=$(do_facet $SINGLEMDS \
7850                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7851                awk '/ldlm_cancel/ {print $2}')
7852         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7853                awk '/ldlm_bl_callback/ {print $2}')
7854         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
7855         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
7856         lru_resize_enable mdc
7857         lru_resize_enable osc
7858 }
7859 run_test 120f "Early Lock Cancel: rename test"
7860
7861 test_120g() {
7862         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7863         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
7864                skip "no early lock cancel on server" && return 0
7865         lru_resize_disable mdc
7866         lru_resize_disable osc
7867         count=10000
7868         echo create $count files
7869         test_mkdir -p $DIR/$tdir
7870         cancel_lru_locks mdc
7871         cancel_lru_locks osc
7872         t0=`date +%s`
7873
7874         can0=$(do_facet $SINGLEMDS \
7875                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7876                awk '/ldlm_cancel/ {print $2}')
7877         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7878                awk '/ldlm_bl_callback/ {print $2}')
7879         createmany -o $DIR/$tdir/f $count
7880         sync
7881         can1=$(do_facet $SINGLEMDS \
7882                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7883                awk '/ldlm_cancel/ {print $2}')
7884         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7885                awk '/ldlm_bl_callback/ {print $2}')
7886         t1=$(date +%s)
7887         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
7888         echo rm $count files
7889         rm -r $DIR/$tdir
7890         sync
7891         can2=$(do_facet $SINGLEMDS \
7892                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
7893                awk '/ldlm_cancel/ {print $2}')
7894         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
7895                awk '/ldlm_bl_callback/ {print $2}')
7896         t2=$(date +%s)
7897         echo total: $count removes in $((t2-t1))
7898         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
7899         sleep 2
7900         # wait for commitment of removal
7901         lru_resize_enable mdc
7902         lru_resize_enable osc
7903 }
7904 run_test 120g "Early Lock Cancel: performance test"
7905
7906 test_121() { #bug #10589
7907         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7908         rm -rf $DIR/$tfile
7909         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
7910 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
7911         lctl set_param fail_loc=0x310
7912         cancel_lru_locks osc > /dev/null
7913         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
7914         lctl set_param fail_loc=0
7915         [[ $reads -eq $writes ]] ||
7916                 error "read $reads blocks, must be $writes blocks"
7917 }
7918 run_test 121 "read cancel race ========="
7919
7920 test_123a() { # was test 123, statahead(bug 11401)
7921         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7922         SLOWOK=0
7923         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
7924             log "testing on UP system. Performance may be not as good as expected."
7925                         SLOWOK=1
7926         fi
7927
7928         rm -rf $DIR/$tdir
7929         test_mkdir -p $DIR/$tdir
7930         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7931         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
7932         MULT=10
7933         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
7934                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
7935
7936                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7937                 lctl set_param -n llite.*.statahead_max 0
7938                 lctl get_param llite.*.statahead_max
7939                 cancel_lru_locks mdc
7940                 cancel_lru_locks osc
7941                 stime=`date +%s`
7942                 time ls -l $DIR/$tdir | wc -l
7943                 etime=`date +%s`
7944                 delta=$((etime - stime))
7945                 log "ls $i files without statahead: $delta sec"
7946                 lctl set_param llite.*.statahead_max=$max
7947
7948                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7949                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
7950                 cancel_lru_locks mdc
7951                 cancel_lru_locks osc
7952                 stime=`date +%s`
7953                 time ls -l $DIR/$tdir | wc -l
7954                 etime=`date +%s`
7955                 delta_sa=$((etime - stime))
7956                 log "ls $i files with statahead: $delta_sa sec"
7957                 lctl get_param -n llite.*.statahead_stats
7958                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
7959
7960                 [[ $swrong -lt $ewrong ]] &&
7961                         log "statahead was stopped, maybe too many locks held!"
7962                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
7963
7964                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7965                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
7966                     lctl set_param -n llite.*.statahead_max 0
7967                     lctl get_param llite.*.statahead_max
7968                     cancel_lru_locks mdc
7969                     cancel_lru_locks osc
7970                     stime=`date +%s`
7971                     time ls -l $DIR/$tdir | wc -l
7972                     etime=`date +%s`
7973                     delta=$((etime - stime))
7974                     log "ls $i files again without statahead: $delta sec"
7975                     lctl set_param llite.*.statahead_max=$max
7976                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
7977                         if [  $SLOWOK -eq 0 ]; then
7978                                 error "ls $i files is slower with statahead!"
7979                         else
7980                                 log "ls $i files is slower with statahead!"
7981                         fi
7982                         break
7983                     fi
7984                 fi
7985
7986                 [ $delta -gt 20 ] && break
7987                 [ $delta -gt 8 ] && MULT=$((50 / delta))
7988                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
7989         done
7990         log "ls done"
7991
7992         stime=`date +%s`
7993         rm -r $DIR/$tdir
7994         sync
7995         etime=`date +%s`
7996         delta=$((etime - stime))
7997         log "rm -r $DIR/$tdir/: $delta seconds"
7998         log "rm done"
7999         lctl get_param -n llite.*.statahead_stats
8000 }
8001 run_test 123a "verify statahead work"
8002
8003 test_123b () { # statahead(bug 15027)
8004         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8005         test_mkdir -p $DIR/$tdir
8006         createmany -o $DIR/$tdir/$tfile-%d 1000
8007
8008         cancel_lru_locks mdc
8009         cancel_lru_locks osc
8010
8011 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8012         lctl set_param fail_loc=0x80000803
8013         ls -lR $DIR/$tdir > /dev/null
8014         log "ls done"
8015         lctl set_param fail_loc=0x0
8016         lctl get_param -n llite.*.statahead_stats
8017         rm -r $DIR/$tdir
8018         sync
8019
8020 }
8021 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8022
8023 test_124a() {
8024         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8025         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8026                 skip "no lru resize on server" && return 0
8027         local NR=2000
8028         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8029
8030         log "create $NR files at $DIR/$tdir"
8031         createmany -o $DIR/$tdir/f $NR ||
8032                 error "failed to create $NR files in $DIR/$tdir"
8033
8034         cancel_lru_locks mdc
8035         ls -l $DIR/$tdir > /dev/null
8036
8037         local NSDIR=""
8038         local LRU_SIZE=0
8039         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8040                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8041                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8042                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8043                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8044                         log "NSDIR=$NSDIR"
8045                         log "NS=$(basename $NSDIR)"
8046                         break
8047                 fi
8048         done
8049
8050         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8051                 skip "Not enough cached locks created!"
8052                 return 0
8053         fi
8054         log "LRU=$LRU_SIZE"
8055
8056         local SLEEP=30
8057
8058         # We know that lru resize allows one client to hold $LIMIT locks
8059         # for 10h. After that locks begin to be killed by client.
8060         local MAX_HRS=10
8061         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8062         log "LIMIT=$LIMIT"
8063
8064         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8065         # killing locks. Some time was spent for creating locks. This means
8066         # that up to the moment of sleep finish we must have killed some of
8067         # them (10-100 locks). This depends on how fast ther were created.
8068         # Many of them were touched in almost the same moment and thus will
8069         # be killed in groups.
8070         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8071
8072         # Use $LRU_SIZE_B here to take into account real number of locks
8073         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8074         local LRU_SIZE_B=$LRU_SIZE
8075         log "LVF=$LVF"
8076         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8077         log "OLD_LVF=$OLD_LVF"
8078         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8079
8080         # Let's make sure that we really have some margin. Client checks
8081         # cached locks every 10 sec.
8082         SLEEP=$((SLEEP+20))
8083         log "Sleep ${SLEEP} sec"
8084         local SEC=0
8085         while ((SEC<$SLEEP)); do
8086                 echo -n "..."
8087                 sleep 5
8088                 SEC=$((SEC+5))
8089                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8090                 echo -n "$LRU_SIZE"
8091         done
8092         echo ""
8093         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8094         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8095
8096         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8097                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8098                 unlinkmany $DIR/$tdir/f $NR
8099                 return
8100         }
8101
8102         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8103         log "unlink $NR files at $DIR/$tdir"
8104         unlinkmany $DIR/$tdir/f $NR
8105 }
8106 run_test 124a "lru resize ======================================="
8107
8108 get_max_pool_limit()
8109 {
8110         local limit=$($LCTL get_param \
8111                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8112         local max=0
8113         for l in $limit; do
8114                 if [[ $l -gt $max ]]; then
8115                         max=$l
8116                 fi
8117         done
8118         echo $max
8119 }
8120
8121 test_124b() {
8122         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8123         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8124                 skip "no lru resize on server" && return 0
8125
8126         LIMIT=$(get_max_pool_limit)
8127
8128         NR=$(($(default_lru_size)*20))
8129         if [[ $NR -gt $LIMIT ]]; then
8130                 log "Limit lock number by $LIMIT locks"
8131                 NR=$LIMIT
8132         fi
8133         lru_resize_disable mdc
8134         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8135                 error "failed to create $DIR/$tdir/disable_lru_resize"
8136
8137         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8138         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8139         cancel_lru_locks mdc
8140         stime=`date +%s`
8141         PID=""
8142         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8143         PID="$PID $!"
8144         sleep 2
8145         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8146         PID="$PID $!"
8147         sleep 2
8148         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8149         PID="$PID $!"
8150         wait $PID
8151         etime=`date +%s`
8152         nolruresize_delta=$((etime-stime))
8153         log "ls -la time: $nolruresize_delta seconds"
8154         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8155         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8156
8157         lru_resize_enable mdc
8158         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8159                 error "failed to create $DIR/$tdir/enable_lru_resize"
8160
8161         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8162         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8163         cancel_lru_locks mdc
8164         stime=`date +%s`
8165         PID=""
8166         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8167         PID="$PID $!"
8168         sleep 2
8169         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8170         PID="$PID $!"
8171         sleep 2
8172         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8173         PID="$PID $!"
8174         wait $PID
8175         etime=`date +%s`
8176         lruresize_delta=$((etime-stime))
8177         log "ls -la time: $lruresize_delta seconds"
8178         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8179
8180         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8181                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8182         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8183                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8184         else
8185                 log "lru resize performs the same with no lru resize"
8186         fi
8187         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8188 }
8189 run_test 124b "lru resize (performance test) ======================="
8190
8191 test_125() { # 13358
8192         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8193         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8194         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8195         test_mkdir -p $DIR/d125 || error "mkdir failed"
8196         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8197         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8198         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8199 }
8200 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8201
8202 test_126() { # bug 12829/13455
8203         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8204         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8205         $GSS && skip "must run as gss disabled" && return
8206
8207         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8208         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8209         rm -f $DIR/$tfile
8210         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8211 }
8212 run_test 126 "check that the fsgid provided by the client is taken into account"
8213
8214 test_127a() { # bug 15521
8215         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8216         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8217         $LCTL set_param osc.*.stats=0
8218         FSIZE=$((2048 * 1024))
8219         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8220         cancel_lru_locks osc
8221         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8222
8223         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8224         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8225                 echo "got $COUNT $NAME"
8226                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8227                 eval $NAME=$COUNT || error "Wrong proc format"
8228
8229                 case $NAME in
8230                         read_bytes|write_bytes)
8231                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8232                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8233                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8234                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8235                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8236                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8237                                 error "sumsquare is too small: $SUMSQ"
8238                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8239                                 error "sumsquare is too big: $SUMSQ"
8240                         ;;
8241                         *) ;;
8242                 esac
8243         done < $DIR/${tfile}.tmp
8244
8245         #check that we actually got some stats
8246         [ "$read_bytes" ] || error "Missing read_bytes stats"
8247         [ "$write_bytes" ] || error "Missing write_bytes stats"
8248         [ "$read_bytes" != 0 ] || error "no read done"
8249         [ "$write_bytes" != 0 ] || error "no write done"
8250 }
8251 run_test 127a "verify the client stats are sane"
8252
8253 test_127b() { # bug LU-333
8254         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8255         $LCTL set_param llite.*.stats=0
8256         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8257         # perform 2 reads and writes so MAX is different from SUM.
8258         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8259         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8260         cancel_lru_locks osc
8261         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8262         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8263
8264         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8265         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8266                 echo "got $COUNT $NAME"
8267                 eval $NAME=$COUNT || error "Wrong proc format"
8268
8269         case $NAME in
8270                 read_bytes)
8271                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8272                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8273                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8274                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8275                         ;;
8276                 write_bytes)
8277                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8278                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8279                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8280                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8281                         ;;
8282                         *) ;;
8283                 esac
8284         done < $TMP/${tfile}.tmp
8285
8286         #check that we actually got some stats
8287         [ "$read_bytes" ] || error "Missing read_bytes stats"
8288         [ "$write_bytes" ] || error "Missing write_bytes stats"
8289         [ "$read_bytes" != 0 ] || error "no read done"
8290         [ "$write_bytes" != 0 ] || error "no write done"
8291 }
8292 run_test 127b "verify the llite client stats are sane"
8293
8294 test_128() { # bug 15212
8295         touch $DIR/$tfile
8296         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8297                 find $DIR/$tfile
8298                 find $DIR/$tfile
8299         EOF
8300
8301         result=$(grep error $TMP/$tfile.log)
8302         rm -f $DIR/$tfile
8303         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8304 }
8305 run_test 128 "interactive lfs for 2 consecutive find's"
8306
8307 set_dir_limits () {
8308         local mntdev
8309         local canondev
8310         local node
8311
8312         local LDPROC=/proc/fs/ldiskfs
8313         local facets=$(get_facets MDS)
8314
8315         for facet in ${facets//,/ }; do
8316                 canondev=$(ldiskfs_canon \
8317                            *.$(convert_facet2label $facet).mntdev $facet)
8318                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8319                                                 LDPROC=/sys/fs/ldiskfs
8320                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8321         done
8322 }
8323
8324 test_129() {
8325         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8326         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8327                 skip "Only applicable to ldiskfs-based MDTs"
8328                 return
8329         fi
8330         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8331         ENOSPC=28
8332         EFBIG=27
8333
8334         rm -rf $DIR/$tdir
8335         test_mkdir -p $DIR/$tdir
8336
8337         # block size of mds1
8338         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8339         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8340         local MAX=$((MDSBLOCKSIZE * 3))
8341         set_dir_limits $MAX
8342         local I=$(stat -c%s "$DIR/$tdir")
8343         local J=0
8344         local STRIPE_COUNT=1
8345         [[ $MDSCOUNT -ge 2 ]] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8346         MAX=$((MAX*STRIPE_COUNT))
8347         while [[ $I -le $MAX ]]; do
8348                 $MULTIOP $DIR/$tdir/$J Oc
8349                 rc=$?
8350                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8351                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8352                 #and EFBIG for previous versions
8353                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8354                         set_dir_limits 0
8355                         echo "return code $rc received as expected"
8356                         multiop $DIR/$tdir/$J Oc ||
8357                                 error_exit "multiop failed w/o dir size limit"
8358
8359                         I=$(stat -c%s "$DIR/$tdir")
8360
8361                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8362                                         $(version_code 2.4.51) ]
8363                         then
8364                                 [[ $I -eq $MAX ]] && return 0
8365                         else
8366                                 [[ $I -gt $MAX ]] && return 0
8367                         fi
8368                         error_exit "current dir size $I, previous limit $MAX"
8369                 elif [ $rc -ne 0 ]; then
8370                         set_dir_limits 0
8371                         error_exit "return code $rc received instead of expected " \
8372                                    "$EFBIG or $ENOSPC, files in dir $I"
8373                 fi
8374                 J=$((J+1))
8375                 I=$(stat -c%s "$DIR/$tdir")
8376         done
8377
8378         set_dir_limits 0
8379         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8380 }
8381 run_test 129 "test directory size limit ========================"
8382
8383 OLDIFS="$IFS"
8384 cleanup_130() {
8385         trap 0
8386         IFS="$OLDIFS"
8387 }
8388
8389 test_130a() {
8390         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8391         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8392                 return
8393
8394         trap cleanup_130 EXIT RETURN
8395
8396         local fm_file=$DIR/$tfile
8397         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8398         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8399                 error "dd failed for $fm_file"
8400
8401         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8402         filefrag -ves $fm_file
8403         RC=$?
8404         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8405                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8406         [ $RC != 0 ] && error "filefrag $fm_file failed"
8407
8408         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8409                       grep -v "ext:" | grep -v "found")
8410         lun=$($GETSTRIPE -i $fm_file)
8411
8412         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8413         IFS=$'\n'
8414         tot_len=0
8415         for line in $filefrag_op
8416         do
8417                 frag_lun=`echo $line | cut -d: -f5`
8418                 ext_len=`echo $line | cut -d: -f4`
8419                 if (( $frag_lun != $lun )); then
8420                         cleanup_130
8421                         error "FIEMAP on 1-stripe file($fm_file) failed"
8422                         return
8423                 fi
8424                 (( tot_len += ext_len ))
8425         done
8426
8427         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8428                 cleanup_130
8429                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8430                 return
8431         fi
8432
8433         cleanup_130
8434
8435         echo "FIEMAP on single striped file succeeded"
8436 }
8437 run_test 130a "FIEMAP (1-stripe file)"
8438
8439 test_130b() {
8440         [ "$OSTCOUNT" -lt "2" ] &&
8441                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8442
8443         [ "$OSTCOUNT" -ge "10" ] &&
8444                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8445
8446         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8447         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8448                 return
8449
8450         trap cleanup_130 EXIT RETURN
8451
8452         local fm_file=$DIR/$tfile
8453         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8454         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8455                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8456
8457         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8458                 error "dd failed on $fm_file"
8459
8460         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8461         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8462                       grep -v "ext:" | grep -v "found")
8463
8464         last_lun=$(echo $filefrag_op | cut -d: -f5)
8465
8466         IFS=$'\n'
8467         tot_len=0
8468         num_luns=1
8469         for line in $filefrag_op
8470         do
8471                 frag_lun=`echo $line | cut -d: -f5`
8472                 ext_len=`echo $line | cut -d: -f4`
8473                 if (( $frag_lun != $last_lun )); then
8474                         if (( tot_len != 1024 )); then
8475                                 cleanup_130
8476                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8477                                 return
8478                         else
8479                                 (( num_luns += 1 ))
8480                                 tot_len=0
8481                         fi
8482                 fi
8483                 (( tot_len += ext_len ))
8484                 last_lun=$frag_lun
8485         done
8486         if (( num_luns != 2 || tot_len != 1024 )); then
8487                 cleanup_130
8488                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8489                 return
8490         fi
8491
8492         cleanup_130
8493
8494         echo "FIEMAP on 2-stripe file succeeded"
8495 }
8496 run_test 130b "FIEMAP (2-stripe file)"
8497
8498 test_130c() {
8499         [ "$OSTCOUNT" -lt "2" ] &&
8500                 skip_env "skipping FIEMAP on 2-stripe file" && return
8501
8502         [ "$OSTCOUNT" -ge "10" ] &&
8503                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8504
8505         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8506         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8507                 return
8508
8509         trap cleanup_130 EXIT RETURN
8510
8511         local fm_file=$DIR/$tfile
8512         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8513         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8514                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8515
8516         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8517
8518         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8519         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8520
8521         last_lun=`echo $filefrag_op | cut -d: -f5`
8522
8523         IFS=$'\n'
8524         tot_len=0
8525         num_luns=1
8526         for line in $filefrag_op
8527         do
8528                 frag_lun=`echo $line | cut -d: -f5`
8529                 ext_len=`echo $line | cut -d: -f4`
8530                 if (( $frag_lun != $last_lun )); then
8531                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8532                         if (( logical != 512 )); then
8533                                 cleanup_130
8534                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8535                                 return
8536                         fi
8537                         if (( tot_len != 512 )); then
8538                                 cleanup_130
8539                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8540                                 return
8541                         else
8542                                 (( num_luns += 1 ))
8543                                 tot_len=0
8544                         fi
8545                 fi
8546                 (( tot_len += ext_len ))
8547                 last_lun=$frag_lun
8548         done
8549         if (( num_luns != 2 || tot_len != 512 )); then
8550                 cleanup_130
8551                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8552                 return
8553         fi
8554
8555         cleanup_130
8556
8557         echo "FIEMAP on 2-stripe file with hole succeeded"
8558 }
8559 run_test 130c "FIEMAP (2-stripe file with hole)"
8560
8561 test_130d() {
8562         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8563
8564         [ "$OSTCOUNT" -ge "10" ] &&
8565                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8566
8567         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8568         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8569
8570         trap cleanup_130 EXIT RETURN
8571
8572         local fm_file=$DIR/$tfile
8573         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8574         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8575                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8576
8577         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8578         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8579                 error "dd failed on $fm_file"
8580
8581         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8582         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8583                 grep -v "ext:" | grep -v "found"`
8584
8585         last_lun=`echo $filefrag_op | cut -d: -f5`
8586
8587         IFS=$'\n'
8588         tot_len=0
8589         num_luns=1
8590         for line in $filefrag_op
8591         do
8592                 frag_lun=`echo $line | cut -d: -f5`
8593                 ext_len=`echo $line | cut -d: -f4`
8594                 if (( $frag_lun != $last_lun )); then
8595                         if (( tot_len != 1024 )); then
8596                                 cleanup_130
8597                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8598                                 return
8599                         else
8600                                 (( num_luns += 1 ))
8601                                 tot_len=0
8602                         fi
8603                 fi
8604                 (( tot_len += ext_len ))
8605                 last_lun=$frag_lun
8606         done
8607         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8608                 cleanup_130
8609                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8610                 return
8611         fi
8612
8613         cleanup_130
8614
8615         echo "FIEMAP on N-stripe file succeeded"
8616 }
8617 run_test 130d "FIEMAP (N-stripe file)"
8618
8619 test_130e() {
8620         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
8621
8622         [ "$OSTCOUNT" -ge "10" ] &&
8623                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8624
8625         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8626         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8627
8628         trap cleanup_130 EXIT RETURN
8629
8630         local fm_file=$DIR/$tfile
8631         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
8632         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8633                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8634
8635         NUM_BLKS=512
8636         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
8637         for ((i = 0; i < $NUM_BLKS; i++))
8638         do
8639                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
8640         done
8641
8642         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8643         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
8644
8645         last_lun=`echo $filefrag_op | cut -d: -f5`
8646
8647         IFS=$'\n'
8648         tot_len=0
8649         num_luns=1
8650         for line in $filefrag_op
8651         do
8652                 frag_lun=`echo $line | cut -d: -f5`
8653                 ext_len=`echo $line | cut -d: -f4`
8654                 if (( $frag_lun != $last_lun )); then
8655                         if (( tot_len != $EXPECTED_LEN )); then
8656                                 cleanup_130
8657                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
8658                                 return
8659                         else
8660                                 (( num_luns += 1 ))
8661                                 tot_len=0
8662                         fi
8663                 fi
8664                 (( tot_len += ext_len ))
8665                 last_lun=$frag_lun
8666         done
8667         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
8668                 cleanup_130
8669                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8670                 return
8671         fi
8672
8673         cleanup_130
8674
8675         echo "FIEMAP with continuation calls succeeded"
8676 }
8677 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
8678
8679 # Test for writev/readv
8680 test_131a() {
8681         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
8682         error "writev test failed"
8683         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
8684         error "readv failed"
8685         rm -f $DIR/$tfile
8686 }
8687 run_test 131a "test iov's crossing stripe boundary for writev/readv"
8688
8689 test_131b() {
8690         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
8691         error "append writev test failed"
8692         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
8693         error "append writev test failed"
8694         rm -f $DIR/$tfile
8695 }
8696 run_test 131b "test append writev"
8697
8698 test_131c() {
8699         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
8700         error "NOT PASS"
8701 }
8702 run_test 131c "test read/write on file w/o objects"
8703
8704 test_131d() {
8705         rwv -f $DIR/$tfile -w -n 1 1572864
8706         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
8707         if [ "$NOB" != 1572864 ]; then
8708                 error "Short read filed: read $NOB bytes instead of 1572864"
8709         fi
8710         rm -f $DIR/$tfile
8711 }
8712 run_test 131d "test short read"
8713
8714 test_131e() {
8715         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
8716         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
8717         error "read hitting hole failed"
8718         rm -f $DIR/$tfile
8719 }
8720 run_test 131e "test read hitting hole"
8721
8722 get_ost_param() {
8723         local token=$1
8724         local gl_sum=0
8725         for node in $(osts_nodes); do
8726                 gl=$(do_node $node "$LCTL get_param -n ost.OSS.ost.stats" | awk '/'$token'/ {print $2}' | head -n 1)
8727                 [ x$gl = x"" ] && gl=0
8728                 gl_sum=$((gl_sum + gl))
8729         done
8730         echo $gl_sum
8731 }
8732
8733 som_mode_switch() {
8734         local som=$1
8735         local gl1=$2
8736         local gl2=$3
8737
8738         if [ x$som = x"enabled" ]; then
8739                 [ $((gl2 - gl1)) -gt 0 ] && error "no glimpse RPC is expected"
8740                 MOUNTOPT=`echo $MOUNTOPT | sed 's/som_preview//g'`
8741                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=disabled"
8742         else
8743                 [ $((gl2 - gl1)) -gt 0 ] || error "some glimpse RPC is expected"
8744                 MOUNTOPT="$MOUNTOPT,som_preview"
8745                 do_facet mgs "$LCTL conf_param $FSNAME.mdt.som=enabled"
8746         fi
8747
8748         # do remount to make new mount-conf parameters actual
8749         echo remounting...
8750         sync
8751         stopall
8752         setupall
8753 }
8754
8755 test_132() { #1028, SOM
8756         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8757         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8758         local num=$(get_mds_dir $DIR)
8759         local mymds=mds${num}
8760         local MOUNTOPT_SAVE=$MOUNTOPT
8761
8762         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8763         cancel_lru_locks osc
8764
8765         som1=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8766
8767         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8768         stat $DIR/$tfile >/dev/null
8769         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8770         echo "====> SOM is "$som1", "$((gl2 - gl1))" glimpse RPC occured"
8771         rm $DIR/$tfile
8772         som_mode_switch $som1 $gl1 $gl2
8773
8774         dd if=/dev/zero of=$DIR/$tfile count=1 2>/dev/null
8775         cancel_lru_locks osc
8776
8777         som2=$(do_facet $mymds "$LCTL get_param mdt.*.som" |  awk -F= ' {print $2}' | head -n 1)
8778         if [ $som1 == $som2 ]; then
8779             error "som is still "$som2
8780             if [ x$som2 = x"enabled" ]; then
8781                 som2="disabled"
8782             else
8783                 som2="enabled"
8784             fi
8785         fi
8786
8787         gl1=$(get_ost_param "ldlm_glimpse_enqueue")
8788         stat $DIR/$tfile >/dev/null
8789         gl2=$(get_ost_param "ldlm_glimpse_enqueue")
8790         echo "====> SOM is "$som2", "$((gl2 - gl1))" glimpse RPC occured"
8791         som_mode_switch $som2 $gl1 $gl2
8792         MOUNTOPT=$MOUNTOPT_SAVE
8793 }
8794 run_test 132 "som avoids glimpse rpc"
8795
8796 check_stats() {
8797         local res
8798         local count
8799         case $1 in
8800         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
8801                  ;;
8802         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
8803                  ;;
8804         *) error "Wrong argument $1" ;;
8805         esac
8806         echo $res
8807         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
8808         # if the argument $3 is zero, it means any stat increment is ok.
8809         if [[ $3 -gt 0 ]]; then
8810                 count=$(echo $res | awk '{ print $2 }')
8811                 [[ $count -ne $3 ]] &&
8812                         error "The $2 counter on $1 is wrong - expected $3"
8813         fi
8814 }
8815
8816 test_133a() {
8817         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8818         remote_ost_nodsh && skip "remote OST with nodsh" && return
8819         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8820
8821         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8822                 { skip "MDS doesn't support rename stats"; return; }
8823         local testdir=$DIR/${tdir}/stats_testdir
8824         mkdir -p $DIR/${tdir}
8825
8826         # clear stats.
8827         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8828         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8829
8830         # verify mdt stats first.
8831         mkdir ${testdir} || error "mkdir failed"
8832         check_stats $SINGLEMDS "mkdir" 1
8833         touch ${testdir}/${tfile} || "touch failed"
8834         check_stats $SINGLEMDS "open" 1
8835         check_stats $SINGLEMDS "close" 1
8836         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
8837         check_stats $SINGLEMDS "mknod" 1
8838         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
8839         check_stats $SINGLEMDS "unlink" 1
8840         rm -f ${testdir}/${tfile} || error "file remove failed"
8841         check_stats $SINGLEMDS "unlink" 2
8842
8843         # remove working dir and check mdt stats again.
8844         rmdir ${testdir} || error "rmdir failed"
8845         check_stats $SINGLEMDS "rmdir" 1
8846
8847         local testdir1=$DIR/${tdir}/stats_testdir1
8848         mkdir -p ${testdir}
8849         mkdir -p ${testdir1}
8850         touch ${testdir1}/test1
8851         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
8852         check_stats $SINGLEMDS "crossdir_rename" 1
8853
8854         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
8855         check_stats $SINGLEMDS "samedir_rename" 1
8856
8857         rm -rf $DIR/${tdir}
8858 }
8859 run_test 133a "Verifying MDT stats ========================================"
8860
8861 test_133b() {
8862         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8863         remote_ost_nodsh && skip "remote OST with nodsh" && return
8864         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8865         local testdir=$DIR/${tdir}/stats_testdir
8866         mkdir -p ${testdir} || error "mkdir failed"
8867         touch ${testdir}/${tfile} || "touch failed"
8868         cancel_lru_locks mdc
8869
8870         # clear stats.
8871         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8872         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8873
8874         # extra mdt stats verification.
8875         chmod 444 ${testdir}/${tfile} || error "chmod failed"
8876         check_stats $SINGLEMDS "setattr" 1
8877         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8878         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
8879         then            # LU-1740
8880                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
8881                 check_stats $SINGLEMDS "getattr" 1
8882         fi
8883         $LFS df || error "lfs failed"
8884         check_stats $SINGLEMDS "statfs" 1
8885
8886         rm -rf $DIR/${tdir}
8887 }
8888 run_test 133b "Verifying extra MDT stats =================================="
8889
8890 test_133c() {
8891         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8892         remote_ost_nodsh && skip "remote OST with nodsh" && return
8893         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8894         local testdir=$DIR/${tdir}/stats_testdir
8895         test_mkdir -p ${testdir} || error "mkdir failed"
8896
8897         # verify obdfilter stats.
8898         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
8899         sync
8900         cancel_lru_locks osc
8901         wait_delete_completed
8902
8903         # clear stats.
8904         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
8905         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
8906
8907         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
8908         sync
8909         cancel_lru_locks osc
8910         check_stats ost "write" 1
8911
8912         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
8913         check_stats ost "read" 1
8914
8915         > ${testdir}/${tfile} || error "truncate failed"
8916         check_stats ost "punch" 1
8917
8918         rm -f ${testdir}/${tfile} || error "file remove failed"
8919         wait_delete_completed
8920         check_stats ost "destroy" 1
8921
8922         rm -rf $DIR/${tdir}
8923 }
8924 run_test 133c "Verifying OST stats ========================================"
8925
8926 order_2() {
8927         local value=$1
8928         local orig=$value
8929         local order=1
8930
8931         while [ $value -ge 2 ]; do
8932                 order=$((order*2))
8933                 value=$((value/2))
8934         done
8935
8936         if [ $orig -gt $order ]; then
8937                 order=$((order*2))
8938         fi
8939         echo $order
8940 }
8941
8942 size_in_KMGT() {
8943     local value=$1
8944     local size=('K' 'M' 'G' 'T');
8945     local i=0
8946     local size_string=$value
8947
8948     while [ $value -ge 1024 ]; do
8949         if [ $i -gt 3 ]; then
8950             #T is the biggest unit we get here, if that is bigger,
8951             #just return XXXT
8952             size_string=${value}T
8953             break
8954         fi
8955         value=$((value >> 10))
8956         if [ $value -lt 1024 ]; then
8957             size_string=${value}${size[$i]}
8958             break
8959         fi
8960         i=$((i + 1))
8961     done
8962
8963     echo $size_string
8964 }
8965
8966 get_rename_size() {
8967     local size=$1
8968     local context=${2:-.}
8969     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
8970                 grep -A1 $context |
8971                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
8972     echo $sample
8973 }
8974
8975 test_133d() {
8976         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8977         remote_ost_nodsh && skip "remote OST with nodsh" && return
8978         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8979         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
8980         { skip "MDS doesn't support rename stats"; return; }
8981
8982         local testdir1=$DIR/${tdir}/stats_testdir1
8983         local testdir2=$DIR/${tdir}/stats_testdir2
8984
8985         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
8986
8987         mkdir -p ${testdir1} || error "mkdir failed"
8988         mkdir -p ${testdir2} || error "mkdir failed"
8989
8990         createmany -o $testdir1/test 512 || error "createmany failed"
8991
8992         # check samedir rename size
8993         mv ${testdir1}/test0 ${testdir1}/test_0
8994
8995         local testdir1_size=$(ls -l $DIR/${tdir} |
8996                 awk '/stats_testdir1/ {print $5}')
8997         local testdir2_size=$(ls -l $DIR/${tdir} |
8998                 awk '/stats_testdir2/ {print $5}')
8999
9000         testdir1_size=$(order_2 $testdir1_size)
9001         testdir2_size=$(order_2 $testdir2_size)
9002
9003         testdir1_size=$(size_in_KMGT $testdir1_size)
9004         testdir2_size=$(size_in_KMGT $testdir2_size)
9005
9006         echo "source rename dir size: ${testdir1_size}"
9007         echo "target rename dir size: ${testdir2_size}"
9008
9009         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9010         eval $cmd || error "$cmd failed"
9011         local samedir=$($cmd | grep 'same_dir')
9012         local same_sample=$(get_rename_size $testdir1_size)
9013         [ -z "$samedir" ] && error "samedir_rename_size count error"
9014         [[ $same_sample -eq 1 ]] ||
9015                 error "samedir_rename_size error $same_sample"
9016         echo "Check same dir rename stats success"
9017
9018         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9019
9020         # check crossdir rename size
9021         mv ${testdir1}/test_0 ${testdir2}/test_0
9022
9023         testdir1_size=$(ls -l $DIR/${tdir} |
9024                 awk '/stats_testdir1/ {print $5}')
9025         testdir2_size=$(ls -l $DIR/${tdir} |
9026                 awk '/stats_testdir2/ {print $5}')
9027
9028         testdir1_size=$(order_2 $testdir1_size)
9029         testdir2_size=$(order_2 $testdir2_size)
9030
9031         testdir1_size=$(size_in_KMGT $testdir1_size)
9032         testdir2_size=$(size_in_KMGT $testdir2_size)
9033
9034         echo "source rename dir size: ${testdir1_size}"
9035         echo "target rename dir size: ${testdir2_size}"
9036
9037         eval $cmd || error "$cmd failed"
9038         local crossdir=$($cmd | grep 'crossdir')
9039         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9040         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9041         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9042         [[ $src_sample -eq 1 ]] ||
9043                 error "crossdir_rename_size error $src_sample"
9044         [[ $tgt_sample -eq 1 ]] ||
9045                 error "crossdir_rename_size error $tgt_sample"
9046         echo "Check cross dir rename stats success"
9047         rm -rf $DIR/${tdir}
9048 }
9049 run_test 133d "Verifying rename_stats ========================================"
9050
9051 test_133e() {
9052         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9053         local testdir=$DIR/${tdir}/stats_testdir
9054         local ctr f0 f1 bs=32768 count=42 sum
9055
9056         remote_ost_nodsh && skip "remote OST with nodsh" && return
9057         mkdir -p ${testdir} || error "mkdir failed"
9058
9059         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9060
9061         for ctr in {write,read}_bytes; do
9062                 sync
9063                 cancel_lru_locks osc
9064
9065                 do_facet ost1 $LCTL set_param -n \
9066                         "obdfilter.*.exports.clear=clear"
9067
9068                 if [ $ctr = write_bytes ]; then
9069                         f0=/dev/zero
9070                         f1=${testdir}/${tfile}
9071                 else
9072                         f0=${testdir}/${tfile}
9073                         f1=/dev/null
9074                 fi
9075
9076                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9077                         error "dd failed"
9078                 sync
9079                 cancel_lru_locks osc
9080
9081                 sum=$(do_facet ost1 $LCTL get_param \
9082                         "obdfilter.*.exports.*.stats" |
9083                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9084                                 $1 == ctr { sum += $7 }
9085                                 END { printf("%0.0f", sum) }')
9086
9087                 if ((sum != bs * count)); then
9088                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9089                 fi
9090         done
9091
9092         rm -rf $DIR/${tdir}
9093 }
9094 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9095
9096 test_133f() {
9097         local proc_dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/"
9098         local facet
9099
9100         # First without trusting modes.
9101         find $proc_dirs -exec cat '{}' \; &> /dev/null
9102
9103         # Second verifying readability.
9104         find $proc_dirs \
9105                 -type f \
9106                 -exec cat '{}' \; &> /dev/null ||
9107                         error "proc file read failed"
9108
9109         for facet in $SINGLEMDS ost1; do
9110                 do_facet $facet find $proc_dirs \
9111                         ! -name req_history \
9112                         -exec cat '{}' \\\; &> /dev/null
9113
9114                 do_facet $facet find $proc_dirs \
9115                         ! -name req_history \
9116                         -type f \
9117                         -exec cat '{}' \\\; &> /dev/null ||
9118                                 error "proc file read failed"
9119         done
9120 }
9121 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9122
9123 test_133g() {
9124         local proc_dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/"
9125         local facet
9126
9127         # Second verifying readability.
9128         find $proc_dirs \
9129                 -type f \
9130                 -not -name force_lbug \
9131                 -not -name changelog_mask \
9132                 -exec badarea_io '{}' \; &> /dev/null ||
9133                 error "find $proc_dirs failed"
9134
9135         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
9136                 skip "Too old lustre on MDS"
9137
9138         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
9139                 skip "Too old lustre on ost1"
9140
9141         for facet in $SINGLEMDS ost1; do
9142                 do_facet $facet find $proc_dirs \
9143                         -type f \
9144                         -not -name force_lbug \
9145                         -not -name changelog_mask \
9146                         -exec badarea_io '{}' \\\; &> /dev/null ||
9147                 error "$facet find $proc_dirs failed"
9148
9149         done
9150
9151         # remount the FS in case writes/reads /proc break the FS
9152         cleanup || error "failed to unmount"
9153         setup || error "failed to setup"
9154         true
9155 }
9156 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9157
9158 test_140() { #bug-17379
9159         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9160         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
9161         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
9162         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
9163
9164         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9165         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9166         local i=0
9167         while i=`expr $i + 1`; do
9168                 test_mkdir -p $i || error "Creating dir $i"
9169                 cd $i || error "Changing to $i"
9170                 ln -s ../stat stat || error "Creating stat symlink"
9171                 # Read the symlink until ELOOP present,
9172                 # not LBUGing the system is considered success,
9173                 # we didn't overrun the stack.
9174                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9175                 [ $ret -ne 0 ] && {
9176                         if [ $ret -eq 40 ]; then
9177                                 break  # -ELOOP
9178                         else
9179                                 error "Open stat symlink"
9180                                 return
9181                         fi
9182                 }
9183         done
9184         i=`expr $i - 1`
9185         echo "The symlink depth = $i"
9186         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9187                                         error "Invalid symlink depth"
9188
9189         # Test recursive symlink
9190         ln -s symlink_self symlink_self
9191         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9192         echo "open symlink_self returns $ret"
9193         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9194 }
9195 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9196
9197 test_150() {
9198         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9199         local TF="$TMP/$tfile"
9200
9201         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9202         cp $TF $DIR/$tfile
9203         cancel_lru_locks osc
9204         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9205         remount_client $MOUNT
9206         df -P $MOUNT
9207         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9208
9209         $TRUNCATE $TF 6000
9210         $TRUNCATE $DIR/$tfile 6000
9211         cancel_lru_locks osc
9212         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9213
9214         echo "12345" >>$TF
9215         echo "12345" >>$DIR/$tfile
9216         cancel_lru_locks osc
9217         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9218
9219         echo "12345" >>$TF
9220         echo "12345" >>$DIR/$tfile
9221         cancel_lru_locks osc
9222         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9223
9224         rm -f $TF
9225         true
9226 }
9227 run_test 150 "truncate/append tests"
9228
9229 #LU-2902 roc_hit was not able to read all values from lproc
9230 function roc_hit_init() {
9231         local list=$(comma_list $(osts_nodes))
9232         local dir=$DIR/$tdir-check
9233         local file=$dir/file
9234         local BEFORE
9235         local AFTER
9236         local idx
9237
9238         test_mkdir -p $dir
9239         #use setstripe to do a write to every ost
9240         for i in $(seq 0 $((OSTCOUNT-1))); do
9241                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9242                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9243                 idx=$(printf %04x $i)
9244                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9245                         awk '$1 == "cache_access" {sum += $2}
9246                                 END { printf("%0.0f", sum) }')
9247
9248                 cancel_lru_locks osc
9249                 cat $file >/dev/null
9250
9251                 AFTER=$(get_osd_param $list *OST*$idx stats |
9252                         awk '$1 == "cache_access" {sum += $2}
9253                                 END { printf("%0.0f", sum) }')
9254
9255                 echo BEFORE:$BEFORE AFTER:$AFTER
9256                 if ! let "AFTER - BEFORE == 4"; then
9257                         rm -rf $dir
9258                         error "roc_hit is not safe to use"
9259                 fi
9260                 rm $file
9261         done
9262
9263         rm -rf $dir
9264 }
9265
9266 function roc_hit() {
9267         local list=$(comma_list $(osts_nodes))
9268         echo $(get_osd_param $list '' stats |
9269                 awk '$1 == "cache_hit" {sum += $2}
9270                         END { printf("%0.0f", sum) }')
9271 }
9272
9273 function set_cache() {
9274         local on=1
9275
9276         if [ "$2" == "off" ]; then
9277                 on=0;
9278         fi
9279         local list=$(comma_list $(osts_nodes))
9280         set_osd_param $list '' $1_cache_enable $on
9281
9282         cancel_lru_locks osc
9283 }
9284
9285 test_151() {
9286         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9287         remote_ost_nodsh && skip "remote OST with nodsh" && return
9288
9289         local CPAGES=3
9290         local list=$(comma_list $(osts_nodes))
9291
9292         # check whether obdfilter is cache capable at all
9293         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9294                 echo "not cache-capable obdfilter"
9295                 return 0
9296         fi
9297
9298         # check cache is enabled on all obdfilters
9299         if get_osd_param $list '' read_cache_enable | grep 0; then
9300                 echo "oss cache is disabled"
9301                 return 0
9302         fi
9303
9304         set_osd_param $list '' writethrough_cache_enable 1
9305
9306         # check write cache is enabled on all obdfilters
9307         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9308                 echo "oss write cache is NOT enabled"
9309                 return 0
9310         fi
9311
9312         roc_hit_init
9313
9314         #define OBD_FAIL_OBD_NO_LRU  0x609
9315         do_nodes $list $LCTL set_param fail_loc=0x609
9316
9317         # pages should be in the case right after write
9318         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9319                 error "dd failed"
9320
9321         local BEFORE=$(roc_hit)
9322         cancel_lru_locks osc
9323         cat $DIR/$tfile >/dev/null
9324         local AFTER=$(roc_hit)
9325
9326         do_nodes $list $LCTL set_param fail_loc=0
9327
9328         if ! let "AFTER - BEFORE == CPAGES"; then
9329                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9330         fi
9331
9332         # the following read invalidates the cache
9333         cancel_lru_locks osc
9334         set_osd_param $list '' read_cache_enable 0
9335         cat $DIR/$tfile >/dev/null
9336
9337         # now data shouldn't be found in the cache
9338         BEFORE=$(roc_hit)
9339         cancel_lru_locks osc
9340         cat $DIR/$tfile >/dev/null
9341         AFTER=$(roc_hit)
9342         if let "AFTER - BEFORE != 0"; then
9343                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9344         fi
9345
9346         set_osd_param $list '' read_cache_enable 1
9347         rm -f $DIR/$tfile
9348 }
9349 run_test 151 "test cache on oss and controls ==============================="
9350
9351 test_152() {
9352         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9353         local TF="$TMP/$tfile"
9354
9355         # simulate ENOMEM during write
9356 #define OBD_FAIL_OST_NOMEM      0x226
9357         lctl set_param fail_loc=0x80000226
9358         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9359         cp $TF $DIR/$tfile
9360         sync || error "sync failed"
9361         lctl set_param fail_loc=0
9362
9363         # discard client's cache
9364         cancel_lru_locks osc
9365
9366         # simulate ENOMEM during read
9367         lctl set_param fail_loc=0x80000226
9368         cmp $TF $DIR/$tfile || error "cmp failed"
9369         lctl set_param fail_loc=0
9370
9371         rm -f $TF
9372 }
9373 run_test 152 "test read/write with enomem ============================"
9374
9375 test_153() {
9376         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9377 }
9378 run_test 153 "test if fdatasync does not crash ======================="
9379
9380 dot_lustre_fid_permission_check() {
9381         local fid=$1
9382         local ffid=$MOUNT/.lustre/fid/$fid
9383         local test_dir=$2
9384
9385         echo "stat fid $fid"
9386         stat $ffid > /dev/null || error "stat $ffid failed."
9387         echo "touch fid $fid"
9388         touch $ffid || error "touch $ffid failed."
9389         echo "write to fid $fid"
9390         cat /etc/hosts > $ffid || error "write $ffid failed."
9391         echo "read fid $fid"
9392         diff /etc/hosts $ffid || error "read $ffid failed."
9393         echo "append write to fid $fid"
9394         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9395         echo "rename fid $fid"
9396         mv $ffid $test_dir/$tfile.1 &&
9397                 error "rename $ffid to $tfile.1 should fail."
9398         touch $test_dir/$tfile.1
9399         mv $test_dir/$tfile.1 $ffid &&
9400                 error "rename $tfile.1 to $ffid should fail."
9401         rm -f $test_dir/$tfile.1
9402         echo "truncate fid $fid"
9403         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9404         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9405                 echo "link fid $fid"
9406                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9407         fi
9408         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9409                 echo "setfacl fid $fid"
9410                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9411                 echo "getfacl fid $fid"
9412                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9413         fi
9414         echo "unlink fid $fid"
9415         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9416         echo "mknod fid $fid"
9417         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9418
9419         fid=[0xf00000400:0x1:0x0]
9420         ffid=$MOUNT/.lustre/fid/$fid
9421
9422         echo "stat non-exist fid $fid"
9423         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9424         echo "write to non-exist fid $fid"
9425         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9426         echo "link new fid $fid"
9427         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9428
9429         mkdir -p $test_dir/$tdir
9430         touch $test_dir/$tdir/$tfile
9431         fid=$($LFS path2fid $test_dir/$tdir)
9432         rc=$?
9433         [ $rc -ne 0 ] &&
9434                 error "error: could not get fid for $test_dir/$dir/$tfile."
9435
9436         ffid=$MOUNT/.lustre/fid/$fid
9437
9438         echo "ls $fid"
9439         ls $ffid > /dev/null || error "ls $ffid failed."
9440         echo "touch $fid/$tfile.1"
9441         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9442
9443         echo "touch $MOUNT/.lustre/fid/$tfile"
9444         touch $MOUNT/.lustre/fid/$tfile && \
9445                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9446
9447         echo "setxattr to $MOUNT/.lustre/fid"
9448         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9449
9450         echo "listxattr for $MOUNT/.lustre/fid"
9451         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9452
9453         echo "delxattr from $MOUNT/.lustre/fid"
9454         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9455
9456         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9457         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9458                 error "touch invalid fid should fail."
9459
9460         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9461         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9462                 error "touch non-normal fid should fail."
9463
9464         echo "rename $tdir to $MOUNT/.lustre/fid"
9465         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9466                 error "rename to $MOUNT/.lustre/fid should fail."
9467
9468         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9469         then            # LU-3547
9470                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9471                 local new_obf_mode=777
9472
9473                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9474                 chmod $new_obf_mode $DIR/.lustre/fid ||
9475                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9476
9477                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9478                 [ $obf_mode -eq $new_obf_mode ] ||
9479                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9480
9481                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9482                 chmod $old_obf_mode $DIR/.lustre/fid ||
9483                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9484         fi
9485
9486         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9487         fid=$($LFS path2fid $test_dir/$tfile-2)
9488         echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9489         cp /etc/passwd $MOUNT/.lustre/fid/$fid &&
9490                 error "create lov data thru .lustre should fail."
9491         echo "cp /etc/passwd $test_dir/$tfile-2"
9492         cp /etc/passwd $test_dir/$tfile-2 ||
9493                 error "copy to $test_dir/$tfile-2 failed."
9494         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9495         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9496                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9497
9498         rm -rf $test_dir/tfile.lnk
9499         rm -rf $test_dir/$tfile-2
9500 }
9501
9502 test_154A() {
9503         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9504                 skip "Need MDS version at least 2.4.1" && return
9505
9506         touch $DIR/$tfile
9507         local FID=$($LFS path2fid $DIR/$tfile)
9508         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9509
9510         # check that we get the same pathname back
9511         local FOUND=$($LFS fid2path $MOUNT $FID)
9512         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9513         [ "$FOUND" != "$DIR/$tfile" ] &&
9514                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9515
9516         rm -rf $DIR/$tfile
9517 }
9518 run_test 154A "lfs path2fid and fid2path basic checks"
9519
9520 test_154a() {
9521         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9522         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9523                 { skip "Need MDS version at least 2.2.51"; return 0; }
9524         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9525
9526         cp /etc/hosts $DIR/$tfile
9527
9528         fid=$($LFS path2fid $DIR/$tfile)
9529         rc=$?
9530         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9531
9532         dot_lustre_fid_permission_check "$fid" $DIR ||
9533                 error "dot lustre permission check $fid failed"
9534
9535         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9536
9537         touch $MOUNT/.lustre/file &&
9538                 error "creation is not allowed under .lustre"
9539
9540         mkdir $MOUNT/.lustre/dir &&
9541                 error "mkdir is not allowed under .lustre"
9542
9543         rm -rf $DIR/$tfile
9544 }
9545 run_test 154a "Open-by-FID"
9546
9547 test_154b() {
9548         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9549         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9550                 { skip "Need MDS version at least 2.2.51"; return 0; }
9551
9552         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9553
9554         local remote_dir=$DIR/$tdir/remote_dir
9555         local MDTIDX=1
9556         local rc=0
9557
9558         mkdir -p $DIR/$tdir
9559         $LFS mkdir -i $MDTIDX -c $MDSCOUNT $remote_dir ||
9560                 error "create remote directory failed"
9561
9562         cp /etc/hosts $remote_dir/$tfile
9563
9564         fid=$($LFS path2fid $remote_dir/$tfile)
9565         rc=$?
9566         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9567
9568         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9569                 error "dot lustre permission check $fid failed"
9570         rm -rf $DIR/$tdir
9571 }
9572 run_test 154b "Open-by-FID for remote directory"
9573
9574 test_154c() {
9575         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9576                 skip "Need MDS version at least 2.4.1" && return
9577
9578         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9579         local FID1=$($LFS path2fid $DIR/$tfile.1)
9580         local FID2=$($LFS path2fid $DIR/$tfile.2)
9581         local FID3=$($LFS path2fid $DIR/$tfile.3)
9582
9583         local N=1
9584         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9585                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9586                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9587                 local want=FID$N
9588                 [ "$FID" = "${!want}" ] ||
9589                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9590                 N=$((N + 1))
9591         done
9592
9593         $LFS fid2path $MOUNT $FID1 $FID2 $FID3 | while read PATHNAME; do
9594                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
9595                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
9596                 N=$((N + 1))
9597         done
9598 }
9599 run_test 154c "lfs path2fid and fid2path multiple arguments"
9600
9601 test_154d() {
9602         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
9603                 skip "Need MDS version at least 2.5.53" && return
9604
9605         if remote_mds; then
9606                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
9607         else
9608                 nid="0@lo"
9609         fi
9610         local proc_ofile="mdt.*.exports.'$nid'.open_files"
9611         local fd
9612         local cmd
9613
9614         rm -f $DIR/$tfile
9615         touch $DIR/$tfile
9616
9617         fid=$($LFS path2fid $DIR/$tfile)
9618         # Open the file
9619         fd=$(free_fd)
9620         cmd="exec $fd<$DIR/$tfile"
9621         eval $cmd
9622         fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
9623         echo $fid_list | grep $fid
9624         rc=$?
9625
9626         cmd="exec $fd>/dev/null"
9627         eval $cmd
9628         if [ $rc -ne 0 ]; then
9629                 error "FID $fid not found in open files list $fid_list"
9630         fi
9631 }
9632 run_test 154d "Verify open file fid"
9633
9634 test_155_small_load() {
9635     local temp=$TMP/$tfile
9636     local file=$DIR/$tfile
9637
9638     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
9639         error "dd of=$temp bs=6096 count=1 failed"
9640     cp $temp $file
9641     cancel_lru_locks osc
9642     cmp $temp $file || error "$temp $file differ"
9643
9644     $TRUNCATE $temp 6000
9645     $TRUNCATE $file 6000
9646     cmp $temp $file || error "$temp $file differ (truncate1)"
9647
9648     echo "12345" >>$temp
9649     echo "12345" >>$file
9650     cmp $temp $file || error "$temp $file differ (append1)"
9651
9652     echo "12345" >>$temp
9653     echo "12345" >>$file
9654     cmp $temp $file || error "$temp $file differ (append2)"
9655
9656     rm -f $temp $file
9657     true
9658 }
9659
9660 test_155_big_load() {
9661     remote_ost_nodsh && skip "remote OST with nodsh" && return
9662     local temp=$TMP/$tfile
9663     local file=$DIR/$tfile
9664
9665     free_min_max
9666     local cache_size=$(do_facet ost$((MAXI+1)) \
9667         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
9668     local large_file_size=$((cache_size * 2))
9669
9670     echo "OSS cache size: $cache_size KB"
9671     echo "Large file size: $large_file_size KB"
9672
9673     [ $MAXV -le $large_file_size ] && \
9674         skip_env "max available OST size needs > $large_file_size KB" && \
9675         return 0
9676
9677     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
9678
9679     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
9680         error "dd of=$temp bs=$large_file_size count=1k failed"
9681     cp $temp $file
9682     ls -lh $temp $file
9683     cancel_lru_locks osc
9684     cmp $temp $file || error "$temp $file differ"
9685
9686     rm -f $temp $file
9687     true
9688 }
9689
9690 test_155a() {
9691         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9692         set_cache read on
9693         set_cache writethrough on
9694         test_155_small_load
9695 }
9696 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
9697
9698 test_155b() {
9699         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9700         set_cache read on
9701         set_cache writethrough off
9702         test_155_small_load
9703 }
9704 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
9705
9706 test_155c() {
9707         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9708         set_cache read off
9709         set_cache writethrough on
9710         test_155_small_load
9711 }
9712 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
9713
9714 test_155d() {
9715         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9716         set_cache read off
9717         set_cache writethrough off
9718         test_155_small_load
9719 }
9720 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
9721
9722 test_155e() {
9723         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9724         set_cache read on
9725         set_cache writethrough on
9726         test_155_big_load
9727 }
9728 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
9729
9730 test_155f() {
9731         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9732         set_cache read on
9733         set_cache writethrough off
9734         test_155_big_load
9735 }
9736 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
9737
9738 test_155g() {
9739         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9740         set_cache read off
9741         set_cache writethrough on
9742         test_155_big_load
9743 }
9744 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
9745
9746 test_155h() {
9747         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9748         set_cache read off
9749         set_cache writethrough off
9750         test_155_big_load
9751 }
9752 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
9753
9754 test_156() {
9755         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9756         local CPAGES=3
9757         local BEFORE
9758         local AFTER
9759         local file="$DIR/$tfile"
9760
9761         [ "$(facet_fstype ost1)" = "zfs" ] &&
9762                 skip "LU-1956/LU-2261: stats unimplemented on OSD ZFS" &&
9763                 return
9764
9765         roc_hit_init
9766
9767     log "Turn on read and write cache"
9768     set_cache read on
9769     set_cache writethrough on
9770
9771     log "Write data and read it back."
9772     log "Read should be satisfied from the cache."
9773     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9774     BEFORE=`roc_hit`
9775     cancel_lru_locks osc
9776     cat $file >/dev/null
9777     AFTER=`roc_hit`
9778     if ! let "AFTER - BEFORE == CPAGES"; then
9779         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9780     else
9781         log "cache hits:: before: $BEFORE, after: $AFTER"
9782     fi
9783
9784     log "Read again; it should be satisfied from the cache."
9785     BEFORE=$AFTER
9786     cancel_lru_locks osc
9787     cat $file >/dev/null
9788     AFTER=`roc_hit`
9789     if ! let "AFTER - BEFORE == CPAGES"; then
9790         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9791     else
9792         log "cache hits:: before: $BEFORE, after: $AFTER"
9793     fi
9794
9795
9796     log "Turn off the read cache and turn on the write cache"
9797     set_cache read off
9798     set_cache writethrough on
9799
9800     log "Read again; it should be satisfied from the cache."
9801     BEFORE=`roc_hit`
9802     cancel_lru_locks osc
9803     cat $file >/dev/null
9804     AFTER=`roc_hit`
9805     if ! let "AFTER - BEFORE == CPAGES"; then
9806         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9807     else
9808         log "cache hits:: before: $BEFORE, after: $AFTER"
9809     fi
9810
9811     log "Read again; it should not be satisfied from the cache."
9812     BEFORE=$AFTER
9813     cancel_lru_locks osc
9814     cat $file >/dev/null
9815     AFTER=`roc_hit`
9816     if ! let "AFTER - BEFORE == 0"; then
9817         error "IN CACHE: before: $BEFORE, after: $AFTER"
9818     else
9819         log "cache hits:: before: $BEFORE, after: $AFTER"
9820     fi
9821
9822     log "Write data and read it back."
9823     log "Read should be satisfied from the cache."
9824     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9825     BEFORE=`roc_hit`
9826     cancel_lru_locks osc
9827     cat $file >/dev/null
9828     AFTER=`roc_hit`
9829     if ! let "AFTER - BEFORE == CPAGES"; then
9830         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9831     else
9832         log "cache hits:: before: $BEFORE, after: $AFTER"
9833     fi
9834
9835     log "Read again; it should not be satisfied from the cache."
9836     BEFORE=$AFTER
9837     cancel_lru_locks osc
9838     cat $file >/dev/null
9839     AFTER=`roc_hit`
9840     if ! let "AFTER - BEFORE == 0"; then
9841         error "IN CACHE: before: $BEFORE, after: $AFTER"
9842     else
9843         log "cache hits:: before: $BEFORE, after: $AFTER"
9844     fi
9845
9846
9847     log "Turn off read and write cache"
9848     set_cache read off
9849     set_cache writethrough off
9850
9851     log "Write data and read it back"
9852     log "It should not be satisfied from the cache."
9853     rm -f $file
9854     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9855     cancel_lru_locks osc
9856     BEFORE=`roc_hit`
9857     cat $file >/dev/null
9858     AFTER=`roc_hit`
9859         if ! let "AFTER - BEFORE == 0"; then
9860                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9861         else
9862                 log "cache hits:: before: $BEFORE, after: $AFTER"
9863         fi
9864
9865     log "Turn on the read cache and turn off the write cache"
9866     set_cache read on
9867     set_cache writethrough off
9868
9869     log "Write data and read it back"
9870     log "It should not be satisfied from the cache."
9871     rm -f $file
9872     dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
9873     BEFORE=`roc_hit`
9874     cancel_lru_locks osc
9875     cat $file >/dev/null
9876     AFTER=`roc_hit`
9877         if ! let "AFTER - BEFORE == 0"; then
9878                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
9879         else
9880                 log "cache hits:: before: $BEFORE, after: $AFTER"
9881         fi
9882
9883     log "Read again; it should be satisfied from the cache."
9884     BEFORE=`roc_hit`
9885     cancel_lru_locks osc
9886     cat $file >/dev/null
9887     AFTER=`roc_hit`
9888     if ! let "AFTER - BEFORE == CPAGES"; then
9889         error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9890     else
9891         log "cache hits:: before: $BEFORE, after: $AFTER"
9892     fi
9893
9894     rm -f $file
9895 }
9896 run_test 156 "Verification of tunables ============================"
9897
9898 #Changelogs
9899 err17935 () {
9900         if [[ $MDSCOUNT -gt 1 ]]; then
9901                 error_ignore bz17935 $*
9902         else
9903                 error $*
9904         fi
9905 }
9906
9907 changelog_chmask()
9908 {
9909         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
9910
9911         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
9912
9913         if [ $MASK -eq 1 ]; then
9914                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
9915         else
9916                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
9917         fi
9918 }
9919
9920 changelog_extract_field() {
9921         local mdt=$1
9922         local cltype=$2
9923         local file=$3
9924         local identifier=$4
9925
9926         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
9927                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
9928                 tail -1
9929 }
9930
9931 test_160a() {
9932         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9933         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9934         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
9935                 { skip "Need MDS version at least 2.2.0"; return; }
9936
9937         local CL_USERS="mdd.$MDT0.changelog_users"
9938         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
9939         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
9940         echo "Registered as changelog user $USER"
9941         $GET_CL_USERS | grep -q $USER ||
9942                 error "User $USER not found in changelog_users"
9943
9944         # change something
9945         test_mkdir -p $DIR/$tdir/pics/2008/zachy
9946         touch $DIR/$tdir/pics/2008/zachy/timestamp
9947         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
9948         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
9949         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
9950         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
9951         rm $DIR/$tdir/pics/desktop.jpg
9952
9953         $LFS changelog $MDT0 | tail -5
9954
9955         echo "verifying changelog mask"
9956         changelog_chmask "MKDIR"
9957         changelog_chmask "CLOSE"
9958
9959         test_mkdir -p $DIR/$tdir/pics/zach/sofia
9960         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9961
9962         changelog_chmask "MKDIR"
9963         changelog_chmask "CLOSE"
9964
9965         test_mkdir -p $DIR/$tdir/pics/2008/sofia
9966         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
9967
9968         $LFS changelog $MDT0
9969         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
9970         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
9971         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
9972         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
9973
9974         # verify contents
9975         echo "verifying target fid"
9976         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
9977         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
9978         [ "$fidc" == "$fidf" ] ||
9979                 err17935 "fid in changelog $fidc != file fid $fidf"
9980         echo "verifying parent fid"
9981         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
9982         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
9983         [ "$fidc" == "$fidf" ] ||
9984                 err17935 "pfid in changelog $fidc != dir fid $fidf"
9985
9986         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
9987         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
9988         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
9989         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
9990         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
9991                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
9992
9993         MIN_REC=$($GET_CL_USERS |
9994                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
9995         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
9996         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
9997         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
9998                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
9999
10000         # LU-3446 changelog index reset on MDT restart
10001         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10002         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10003         $LFS changelog_clear $MDT0 $USER 0
10004         stop $SINGLEMDS || error "Fail to stop MDT."
10005         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10006         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10007         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
10008         [ $CUR_REC1 == $CUR_REC2 ] ||
10009                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
10010
10011         echo "verifying user deregister"
10012         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10013         $GET_CL_USERS | grep -q $USER &&
10014                 error "User $USER still in changelog_users"
10015
10016         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
10017         if [ $USERS -eq 0 ]; then
10018                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10019                 touch $DIR/$tdir/chloe
10020                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10021                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
10022                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
10023         else
10024                 echo "$USERS other changelog users; can't verify off"
10025         fi
10026 }
10027 run_test 160a "changelog sanity"
10028
10029 test_160b() { # LU-3587
10030         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10031         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10032         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10033                 { skip "Need MDS version at least 2.2.0"; return; }
10034
10035         local CL_USERS="mdd.$MDT0.changelog_users"
10036         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10037         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10038         echo "Registered as changelog user $USER"
10039         $GET_CL_USERS | grep -q $USER ||
10040                 error "User $USER not found in changelog_users"
10041
10042         local LONGNAME1=$(str_repeat a 255)
10043         local LONGNAME2=$(str_repeat b 255)
10044
10045         cd $DIR
10046         echo "creating very long named file"
10047         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
10048         echo "moving very long named file"
10049         mv $LONGNAME1 $LONGNAME2
10050
10051         $LFS changelog $MDT0 | grep RENME
10052
10053         echo "deregistering $USER"
10054         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10055
10056         rm -f $LONGNAME2
10057 }
10058 run_test 160b "Verify that very long rename doesn't crash in changelog"
10059
10060 test_160c() {
10061         local rc=0
10062         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10063
10064         # Registration step
10065         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10066                 changelog_register -n)
10067
10068         rm -rf $DIR/$tdir
10069         mkdir -p $DIR/$tdir
10070         $MCREATE $DIR/$tdir/foo_160c
10071         changelog_chmask "TRUNC"
10072         $TRUNCATE $DIR/$tdir/foo_160c 200
10073         changelog_chmask "TRUNC"
10074         $TRUNCATE $DIR/$tdir/foo_160c 199
10075         $LFS changelog $MDT0
10076         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
10077         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
10078         $LFS changelog_clear $MDT0 $USER 0
10079
10080         # Deregistration step
10081         echo "deregistering $USER"
10082         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10083 }
10084 run_test 160c "verify that changelog log catch the truncate event"
10085
10086 test_161a() {
10087         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10088         test_mkdir -p -c1 $DIR/$tdir
10089         cp /etc/hosts $DIR/$tdir/$tfile
10090         test_mkdir -c1 $DIR/$tdir/foo1
10091         test_mkdir -c1 $DIR/$tdir/foo2
10092         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
10093         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
10094         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
10095         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
10096         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
10097         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10098                 $LFS fid2path $DIR $FID
10099                 err17935 "bad link ea"
10100         fi
10101     # middle
10102     rm $DIR/$tdir/foo2/zachary
10103     # last
10104     rm $DIR/$tdir/foo2/thor
10105     # first
10106     rm $DIR/$tdir/$tfile
10107     # rename
10108     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
10109     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
10110         then
10111         $LFS fid2path $DIR $FID
10112         err17935 "bad link rename"
10113     fi
10114     rm $DIR/$tdir/foo2/maggie
10115
10116         # overflow the EA
10117         local longname=filename_avg_len_is_thirty_two_
10118         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
10119                 error "failed to hardlink many files"
10120         links=$($LFS fid2path $DIR $FID | wc -l)
10121         echo -n "${links}/1000 links in link EA"
10122         [[ $links -gt 60 ]] ||
10123                 err17935 "expected at least 60 links in link EA"
10124         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
10125                 error "failed to unlink many hardlinks"
10126 }
10127 run_test 161a "link ea sanity"
10128
10129 test_161b() {
10130         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10131         [ $MDSCOUNT -lt 2 ] &&
10132                 skip "skipping remote directory test" && return
10133         local MDTIDX=1
10134         local remote_dir=$DIR/$tdir/remote_dir
10135
10136         mkdir -p $DIR/$tdir
10137         $LFS mkdir -i $MDTIDX $remote_dir ||
10138                 error "create remote directory failed"
10139
10140         cp /etc/hosts $remote_dir/$tfile
10141         mkdir -p $remote_dir/foo1
10142         mkdir -p $remote_dir/foo2
10143         ln $remote_dir/$tfile $remote_dir/foo1/sofia
10144         ln $remote_dir/$tfile $remote_dir/foo2/zachary
10145         ln $remote_dir/$tfile $remote_dir/foo1/luna
10146         ln $remote_dir/$tfile $remote_dir/foo2/thor
10147
10148         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
10149                      tr -d ']')
10150         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10151                 $LFS fid2path $DIR $FID
10152                 err17935 "bad link ea"
10153         fi
10154         # middle
10155         rm $remote_dir/foo2/zachary
10156         # last
10157         rm $remote_dir/foo2/thor
10158         # first
10159         rm $remote_dir/$tfile
10160         # rename
10161         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
10162         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
10163         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
10164                 $LFS fid2path $DIR $FID
10165                 err17935 "bad link rename"
10166         fi
10167         rm $remote_dir/foo2/maggie
10168
10169         # overflow the EA
10170         local longname=filename_avg_len_is_thirty_two_
10171         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10172                 error "failed to hardlink many files"
10173         links=$($LFS fid2path $DIR $FID | wc -l)
10174         echo -n "${links}/1000 links in link EA"
10175         [[ ${links} -gt 60 ]] ||
10176                 err17935 "expected at least 60 links in link EA"
10177         unlinkmany $remote_dir/foo2/$longname 1000 ||
10178         error "failed to unlink many hardlinks"
10179 }
10180 run_test 161b "link ea sanity under remote directory"
10181
10182 test_161c() {
10183         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10184         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10185                 skip "Need MDS version at least 2.1.5" && return
10186
10187         # define CLF_RENAME_LAST 0x0001
10188         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10189         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10190                 changelog_register -n)
10191         rm -rf $DIR/$tdir
10192         mkdir -p $DIR/$tdir
10193         touch $DIR/$tdir/foo_161c
10194         touch $DIR/$tdir/bar_161c
10195         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10196         $LFS changelog $MDT0 | grep RENME
10197         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10198                 cut -f5 -d' ')
10199         $LFS changelog_clear $MDT0 $USER 0
10200         if [ x$flags != "x0x1" ]; then
10201                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10202                         $USER
10203                 error "flag $flags is not 0x1"
10204         fi
10205         echo "rename overwrite a target having nlink = 1," \
10206                 "changelog record has flags of $flags"
10207
10208         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10209         touch $DIR/$tdir/foo_161c
10210         touch $DIR/$tdir/bar_161c
10211         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10212         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10213         $LFS changelog $MDT0 | grep RENME
10214         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10215         $LFS changelog_clear $MDT0 $USER 0
10216         if [ x$flags != "x0x0" ]; then
10217                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10218                         $USER
10219                 error "flag $flags is not 0x0"
10220         fi
10221         echo "rename overwrite a target having nlink > 1," \
10222                 "changelog record has flags of $flags"
10223
10224         # rename doesn't overwrite a target (changelog flag 0x0)
10225         touch $DIR/$tdir/foo_161c
10226         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10227         $LFS changelog $MDT0 | grep RENME
10228         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10229         $LFS changelog_clear $MDT0 $USER 0
10230         if [ x$flags != "x0x0" ]; then
10231                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10232                         $USER
10233                 error "flag $flags is not 0x0"
10234         fi
10235         echo "rename doesn't overwrite a target," \
10236                 "changelog record has flags of $flags"
10237
10238         # define CLF_UNLINK_LAST 0x0001
10239         # unlink a file having nlink = 1 (changelog flag 0x1)
10240         rm -f $DIR/$tdir/foo2_161c
10241         $LFS changelog $MDT0 | grep UNLNK
10242         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10243         $LFS changelog_clear $MDT0 $USER 0
10244         if [ x$flags != "x0x1" ]; then
10245                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10246                         $USER
10247                 error "flag $flags is not 0x1"
10248         fi
10249         echo "unlink a file having nlink = 1," \
10250                 "changelog record has flags of $flags"
10251
10252         # unlink a file having nlink > 1 (changelog flag 0x0)
10253         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10254         rm -f $DIR/$tdir/foobar_161c
10255         $LFS changelog $MDT0 | grep UNLNK
10256         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10257         $LFS changelog_clear $MDT0 $USER 0
10258         if [ x$flags != "x0x0" ]; then
10259                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10260                         $USER
10261                 error "flag $flags is not 0x0"
10262         fi
10263         echo "unlink a file having nlink > 1," \
10264                 "changelog record has flags of $flags"
10265         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10266 }
10267 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10268
10269 check_path() {
10270     local expected=$1
10271     shift
10272     local fid=$2
10273
10274     local path=$(${LFS} fid2path $*)
10275     RC=$?
10276
10277     if [ $RC -ne 0 ]; then
10278         err17935 "path looked up of $expected failed. Error $RC"
10279         return $RC
10280     elif [ "${path}" != "${expected}" ]; then
10281         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10282         return 2
10283     fi
10284     echo "fid $fid resolves to path $path (expected $expected)"
10285 }
10286
10287 test_162() {
10288         # Make changes to filesystem
10289         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10290         test_mkdir -p -c1 $DIR/$tdir/d2
10291         touch $DIR/$tdir/d2/$tfile
10292         touch $DIR/$tdir/d2/x1
10293         touch $DIR/$tdir/d2/x2
10294         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
10295         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
10296         # regular file
10297         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10298         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0
10299
10300         # softlink
10301         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10302         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10303         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0
10304
10305         # softlink to wrong file
10306         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10307         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10308         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0
10309
10310         # hardlink
10311         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10312         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10313         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10314         # fid2path dir/fsname should both work
10315         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1
10316         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0
10317
10318         # hardlink count: check that there are 2 links
10319         # Doesnt work with CMD yet: 17935
10320         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10321                 err17935 "expected 2 links"
10322
10323         # hardlink indexing: remove the first link
10324         rm $DIR/$tdir/d2/p/q/r/hlink
10325         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0
10326
10327         return 0
10328 }
10329 run_test 162 "path lookup sanity"
10330
10331 test_162b() {
10332         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10333         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10334
10335         mkdir $DIR/$tdir
10336         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
10337                                 error "create striped dir failed"
10338
10339         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
10340                                         tail -n 1 | awk '{print $2}')
10341         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
10342
10343         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
10344         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
10345
10346         # regular file
10347         for ((i=0;i<5;i++)); do
10348                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
10349                         error "get fid for f$i failed"
10350                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0
10351
10352                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
10353                         error "get fid for d$i failed"
10354                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0
10355         done
10356
10357         return 0
10358 }
10359 run_test 162b "striped directory path lookup sanity"
10360
10361 test_169() {
10362         # do directio so as not to populate the page cache
10363         log "creating a 10 Mb file"
10364         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10365         log "starting reads"
10366         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10367         log "truncating the file"
10368         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10369         log "killing dd"
10370         kill %+ || true # reads might have finished
10371         echo "wait until dd is finished"
10372         wait
10373         log "removing the temporary file"
10374         rm -rf $DIR/$tfile || error "tmp file removal failed"
10375 }
10376 run_test 169 "parallel read and truncate should not deadlock"
10377
10378 test_170() {
10379         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10380         $LCTL clear     # bug 18514
10381         $LCTL debug_daemon start $TMP/${tfile}_log_good
10382         touch $DIR/$tfile
10383         $LCTL debug_daemon stop
10384         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10385                error "sed failed to read log_good"
10386
10387         $LCTL debug_daemon start $TMP/${tfile}_log_good
10388         rm -rf $DIR/$tfile
10389         $LCTL debug_daemon stop
10390
10391         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10392                error "lctl df log_bad failed"
10393
10394         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10395         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10396
10397         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10398         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10399
10400         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10401                 error "bad_line good_line1 good_line2 are empty"
10402
10403         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10404         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10405         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10406
10407         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10408         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10409         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10410
10411         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
10412                 error "bad_line_new good_line_new are empty"
10413
10414         local expected_good=$((good_line1 + good_line2*2))
10415
10416         rm -f $TMP/${tfile}*
10417         # LU-231, short malformed line may not be counted into bad lines
10418         if [ $bad_line -ne $bad_line_new ] &&
10419                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
10420                 error "expected $bad_line bad lines, but got $bad_line_new"
10421                 return 1
10422         fi
10423
10424         if [ $expected_good -ne $good_line_new ]; then
10425                 error "expected $expected_good good lines, but got $good_line_new"
10426                 return 2
10427         fi
10428         true
10429 }
10430 run_test 170 "test lctl df to handle corrupted log ====================="
10431
10432 test_171() { # bug20592
10433         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10434 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
10435         $LCTL set_param fail_loc=0x50e
10436         $LCTL set_param fail_val=3000
10437         multiop_bg_pause $DIR/$tfile O_s || true
10438         local MULTIPID=$!
10439         kill -USR1 $MULTIPID
10440         # cause log dump
10441         sleep 3
10442         wait $MULTIPID
10443         if dmesg | grep "recursive fault"; then
10444                 error "caught a recursive fault"
10445         fi
10446         $LCTL set_param fail_loc=0
10447         true
10448 }
10449 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
10450
10451 # it would be good to share it with obdfilter-survey/libecho code
10452 setup_obdecho_osc () {
10453         local rc=0
10454         local ost_nid=$1
10455         local obdfilter_name=$2
10456         echo "Creating new osc for $obdfilter_name on $ost_nid"
10457         # make sure we can find loopback nid
10458         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
10459
10460         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
10461                            ${obdfilter_name}_osc_UUID || rc=2; }
10462         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
10463                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
10464         return $rc
10465 }
10466
10467 cleanup_obdecho_osc () {
10468         local obdfilter_name=$1
10469         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
10470         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
10471         return 0
10472 }
10473
10474 obdecho_test() {
10475         local OBD=$1
10476         local node=$2
10477         local pages=${3:-64}
10478         local rc=0
10479         local id
10480
10481         local count=10
10482         local obd_size=$(get_obd_size $node $OBD)
10483         local page_size=$(get_page_size $node)
10484         if [[ -n "$obd_size" ]]; then
10485                 local new_count=$((obd_size / (pages * page_size / 1024)))
10486                 [[ $new_count -ge $count ]] || count=$new_count
10487         fi
10488
10489         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
10490         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
10491                            rc=2; }
10492         if [ $rc -eq 0 ]; then
10493             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
10494             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
10495         fi
10496         echo "New object id is $id"
10497         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
10498                            rc=4; }
10499         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
10500                            "test_brw $count w v $pages $id" || rc=4; }
10501         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
10502                            rc=4; }
10503         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
10504                                         "cleanup" || rc=5; }
10505         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
10506                                         "detach" || rc=6; }
10507         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
10508         return $rc
10509 }
10510
10511 test_180a() {
10512         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10513         remote_ost_nodsh && skip "remote OST with nodsh" && return
10514         local rc=0
10515         local rmmod_local=0
10516
10517         if ! module_loaded obdecho; then
10518             load_module obdecho/obdecho
10519             rmmod_local=1
10520         fi
10521
10522         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
10523         local host=$(lctl get_param -n osc.$osc.import |
10524                              awk '/current_connection:/ {print $2}' )
10525         local target=$(lctl get_param -n osc.$osc.import |
10526                              awk '/target:/ {print $2}' )
10527         target=${target%_UUID}
10528
10529         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
10530         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
10531         [[ -n $target ]] && cleanup_obdecho_osc $target
10532         [ $rmmod_local -eq 1 ] && rmmod obdecho
10533         return $rc
10534 }
10535 run_test 180a "test obdecho on osc"
10536
10537 test_180b() {
10538         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10539         remote_ost_nodsh && skip "remote OST with nodsh" && return
10540         local rc=0
10541         local rmmod_remote=0
10542
10543         do_facet ost1 "lsmod | grep -q obdecho || "                      \
10544                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
10545                       "modprobe obdecho; }" && rmmod_remote=1
10546         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
10547         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
10548         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
10549         return $rc
10550 }
10551 run_test 180b "test obdecho directly on obdfilter"
10552
10553 test_180c() { # LU-2598
10554         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10555         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
10556                 skip "Need MDS version at least 2.4.0" && return
10557
10558         local rc=0
10559         local rmmod_remote=false
10560         local pages=16384 # 64MB bulk I/O RPC size
10561         local target
10562
10563         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
10564                 rmmod_remote=true || error "failed to load module obdecho"
10565
10566         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
10567                 head -n1)
10568         if [ -n "$target" ]; then
10569                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
10570         else
10571                 echo "there is no obdfilter target on ost1"
10572                 rc=2
10573         fi
10574         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
10575         return $rc
10576 }
10577 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
10578
10579 test_181() { # bug 22177
10580         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10581         # create enough files to index the directory
10582         createmany -o $DIR/$tdir/foobar 4000
10583         # print attributes for debug purpose
10584         lsattr -d .
10585         # open dir
10586         multiop_bg_pause $DIR/$tdir D_Sc || return 1
10587         MULTIPID=$!
10588         # remove the files & current working dir
10589         unlinkmany $DIR/$tdir/foobar 4000
10590         rmdir $DIR/$tdir
10591         kill -USR1 $MULTIPID
10592         wait $MULTIPID
10593         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
10594         return 0
10595 }
10596 run_test 181 "Test open-unlinked dir ========================"
10597
10598 test_182() {
10599         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10600         # disable MDC RPC lock wouldn't crash client
10601         local fcount=1000
10602         local tcount=4
10603
10604         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10605 #define OBD_FAIL_MDC_RPCS_SEM           0x804
10606         $LCTL set_param fail_loc=0x804
10607
10608         for (( i=0; i < $tcount; i++ )) ; do
10609                 mkdir $DIR/$tdir/$i
10610                 createmany -o $DIR/$tdir/$i/f- $fcount &
10611         done
10612         wait
10613
10614         for (( i=0; i < $tcount; i++ )) ; do
10615                 unlinkmany $DIR/$tdir/$i/f- $fcount &
10616         done
10617         wait
10618
10619         rm -rf $DIR/$tdir
10620
10621         $LCTL set_param fail_loc=0
10622 }
10623 run_test 182 "Disable MDC RPCs semaphore wouldn't crash client ================"
10624
10625 test_183() { # LU-2275
10626         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
10627                 skip "Need MDS version at least 2.3.56" && return
10628
10629         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10630         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10631         echo aaa > $DIR/$tdir/$tfile
10632
10633 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
10634         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
10635
10636         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
10637         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
10638
10639         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
10640
10641         # Flush negative dentry cache
10642         touch $DIR/$tdir/$tfile
10643
10644         # We are not checking for any leaked references here, they'll
10645         # become evident next time we do cleanup with module unload.
10646         rm -rf $DIR/$tdir
10647 }
10648 run_test 183 "No crash or request leak in case of strange dispositions ========"
10649
10650 # test suite 184 is for LU-2016, LU-2017
10651 test_184a() {
10652         check_swap_layouts_support && return 0
10653
10654         dir0=$DIR/$tdir/$testnum
10655         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
10656         ref1=/etc/passwd
10657         ref2=/etc/group
10658         file1=$dir0/f1
10659         file2=$dir0/f2
10660         $SETSTRIPE -c1 $file1
10661         cp $ref1 $file1
10662         $SETSTRIPE -c2 $file2
10663         cp $ref2 $file2
10664         gen1=$($GETSTRIPE -g $file1)
10665         gen2=$($GETSTRIPE -g $file2)
10666
10667         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
10668         gen=$($GETSTRIPE -g $file1)
10669         [[ $gen1 != $gen ]] ||
10670                 "Layout generation on $file1 does not change"
10671         gen=$($GETSTRIPE -g $file2)
10672         [[ $gen2 != $gen ]] ||
10673                 "Layout generation on $file2 does not change"
10674
10675         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
10676         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
10677 }
10678 run_test 184a "Basic layout swap"
10679
10680 test_184b() {
10681         check_swap_layouts_support && return 0
10682
10683         dir0=$DIR/$tdir/$testnum
10684         mkdir -p $dir0 || error "creating dir $dir0"
10685         file1=$dir0/f1
10686         file2=$dir0/f2
10687         file3=$dir0/f3
10688         dir1=$dir0/d1
10689         dir2=$dir0/d2
10690         mkdir $dir1 $dir2
10691         $SETSTRIPE -c1 $file1
10692         $SETSTRIPE -c2 $file2
10693         $SETSTRIPE -c1 $file3
10694         chown $RUNAS_ID $file3
10695         gen1=$($GETSTRIPE -g $file1)
10696         gen2=$($GETSTRIPE -g $file2)
10697
10698         $LFS swap_layouts $dir1 $dir2 &&
10699                 error "swap of directories layouts should fail"
10700         $LFS swap_layouts $dir1 $file1 &&
10701                 error "swap of directory and file layouts should fail"
10702         $RUNAS $LFS swap_layouts $file1 $file2 &&
10703                 error "swap of file we cannot write should fail"
10704         $LFS swap_layouts $file1 $file3 &&
10705                 error "swap of file with different owner should fail"
10706         /bin/true # to clear error code
10707 }
10708 run_test 184b "Forbidden layout swap (will generate errors)"
10709
10710 test_184c() {
10711         check_swap_layouts_support && return 0
10712
10713         local dir0=$DIR/$tdir/$testnum
10714         mkdir -p $dir0 || error "creating dir $dir0"
10715
10716         local ref1=$dir0/ref1
10717         local ref2=$dir0/ref2
10718         local file1=$dir0/file1
10719         local file2=$dir0/file2
10720         # create a file large enough for the concurent test
10721         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
10722         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
10723         echo "ref file size: ref1($(stat -c %s $ref1))," \
10724              "ref2($(stat -c %s $ref2))"
10725
10726         cp $ref2 $file2
10727         dd if=$ref1 of=$file1 bs=16k &
10728         local DD_PID=$!
10729
10730         # Make sure dd starts to copy file
10731         while [ ! -f $file1 ]; do sleep 0.1; done
10732
10733         $LFS swap_layouts $file1 $file2
10734         local rc=$?
10735         wait $DD_PID
10736         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
10737         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
10738
10739         # how many bytes copied before swapping layout
10740         local copied=$(stat -c %s $file2)
10741         local remaining=$(stat -c %s $ref1)
10742         remaining=$((remaining - copied))
10743         echo "Copied $copied bytes before swapping layout..."
10744
10745         cmp -n $copied $file1 $ref2 | grep differ &&
10746                 error "Content mismatch [0, $copied) of ref2 and file1"
10747         cmp -n $copied $file2 $ref1 ||
10748                 error "Content mismatch [0, $copied) of ref1 and file2"
10749         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
10750                 error "Content mismatch [$copied, EOF) of ref1 and file1"
10751
10752         # clean up
10753         rm -f $ref1 $ref2 $file1 $file2
10754 }
10755 run_test 184c "Concurrent write and layout swap"
10756
10757 test_184d() {
10758         check_swap_layouts_support && return 0
10759         [ -z "$(which getfattr 2>/dev/null)" ] &&
10760                 skip "no getfattr command" && return 0
10761
10762         local file1=$DIR/$tdir/$tfile-1
10763         local file2=$DIR/$tdir/$tfile-2
10764         local file3=$DIR/$tdir/$tfile-3
10765         local lovea1
10766         local lovea2
10767
10768         mkdir -p $DIR/$tdir
10769         touch $file1 || error "create $file1 failed"
10770         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
10771                 error "create $file2 failed"
10772         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
10773                 error "create $file3 failed"
10774         lovea1=$($LFS getstripe $file1 | sed 1d)
10775
10776         $LFS swap_layouts $file2 $file3 ||
10777                 error "swap $file2 $file3 layouts failed"
10778         $LFS swap_layouts $file1 $file2 ||
10779                 error "swap $file1 $file2 layouts failed"
10780
10781         lovea2=$($LFS getstripe $file2 | sed 1d)
10782         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
10783
10784         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
10785         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
10786 }
10787 run_test 184d "allow stripeless layouts swap"
10788
10789
10790 test_185() { # LU-2441
10791         # LU-3553 - no volatile file support in old servers
10792         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
10793                 { skip "Need MDS version at least 2.3.60"; return 0; }
10794
10795         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
10796         touch $DIR/$tdir/spoo
10797         local mtime1=$(stat -c "%Y" $DIR/$tdir)
10798         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
10799                 error "cannot create/write a volatile file"
10800         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
10801                 error "FID is still valid after close"
10802
10803         multiop_bg_pause $DIR/$tdir vVw4096_c
10804         local multi_pid=$!
10805
10806         local OLD_IFS=$IFS
10807         IFS=":"
10808         local fidv=($fid)
10809         IFS=$OLD_IFS
10810         # assume that the next FID for this client is sequential, since stdout
10811         # is unfortunately eaten by multiop_bg_pause
10812         local n=$((${fidv[1]} + 1))
10813         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
10814         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
10815                 error "FID is missing before close"
10816         kill -USR1 $multi_pid
10817         # 1 second delay, so if mtime change we will see it
10818         sleep 1
10819         local mtime2=$(stat -c "%Y" $DIR/$tdir)
10820         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
10821 }
10822 run_test 185 "Volatile file support"
10823
10824 test_187a() {
10825         local dir0=$DIR/$tdir/$testnum
10826         mkdir -p $dir0 || error "creating dir $dir0"
10827
10828         local file=$dir0/file1
10829         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
10830         local dv1=$($LFS data_version $file)
10831         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
10832         local dv2=$($LFS data_version $file)
10833         [[ $dv1 != $dv2 ]] ||
10834                 error "data version did not change on write $dv1 == $dv2"
10835
10836         # clean up
10837         rm -f $file1
10838 }
10839 run_test 187a "Test data version change"
10840
10841 test_187b() {
10842         local dir0=$DIR/$tdir/$testnum
10843         mkdir -p $dir0 || error "creating dir $dir0"
10844
10845         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
10846         [[ ${DV[0]} != ${DV[1]} ]] ||
10847                 error "data version did not change on write"\
10848                       " ${DV[0]} == ${DV[1]}"
10849
10850         # clean up
10851         rm -f $file1
10852 }
10853 run_test 187b "Test data version change on volatile file"
10854
10855 # OST pools tests
10856 check_file_in_pool()
10857 {
10858         local file=$1
10859         local pool=$2
10860         local tlist="$3"
10861         local res=$($GETSTRIPE $file | grep 0x | cut -f2)
10862         for i in $res
10863         do
10864                 for t in $tlist ; do
10865                         [ "$i" -eq "$t" ] && continue 2
10866                 done
10867
10868                 echo "pool list: $tlist"
10869                 echo "striping: $res"
10870                 error_noexit "$file not allocated in $pool"
10871                 return 1
10872         done
10873         return 0
10874 }
10875
10876 pool_add() {
10877         echo "Creating new pool"
10878         local pool=$1
10879
10880         create_pool $FSNAME.$pool ||
10881                 { error_noexit "No pool created, result code $?"; return 1; }
10882         [ $($LFS pool_list $FSNAME | grep -c $pool) -eq 1 ] ||
10883                 { error_noexit "$pool not in lfs pool_list"; return 2; }
10884 }
10885
10886 pool_add_targets() {
10887         echo "Adding targets to pool"
10888         local pool=$1
10889         local first=$2
10890         local last=$3
10891         local step=${4:-1}
10892
10893         local list=$(seq $first $step $last)
10894
10895         local t=$(for i in $list; do printf "$FSNAME-OST%04x_UUID " $i; done)
10896         do_facet mgs $LCTL pool_add \
10897                         $FSNAME.$pool $FSNAME-OST[$first-$last/$step]
10898         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool \
10899                         | sort -u | tr '\n' ' ' " "$t" || { 
10900                 error_noexit "Add to pool failed"
10901                 return 1
10902         }
10903         local lfscount=$($LFS pool_list $FSNAME.$pool | grep -c "\-OST")
10904         local addcount=$(((last - first) / step + 1))
10905         [ $lfscount -eq $addcount ] || {
10906                 error_noexit "lfs pool_list bad ost count" \
10907                                                 "$lfscount != $addcount"
10908                 return 2
10909         }
10910 }
10911
10912 pool_set_dir() {
10913         local pool=$1
10914         local tdir=$2
10915         echo "Setting pool on directory $tdir"
10916
10917         $SETSTRIPE -c 2 -p $pool $tdir && return 0
10918
10919         error_noexit "Cannot set pool $pool to $tdir"
10920         return 1
10921 }
10922
10923 pool_check_dir() {
10924         local pool=$1
10925         local tdir=$2
10926         echo "Checking pool on directory $tdir"
10927
10928         local res=$($GETSTRIPE --pool $tdir | sed "s/\s*$//")
10929         [ "$res" = "$pool" ] && return 0
10930
10931         error_noexit "Pool on '$tdir' is '$res', not '$pool'"
10932         return 1
10933 }
10934
10935 pool_dir_rel_path() {
10936         echo "Testing relative path works well"
10937         local pool=$1
10938         local tdir=$2
10939         local root=$3
10940
10941         mkdir -p $root/$tdir/$tdir
10942         cd $root/$tdir
10943         pool_set_dir $pool $tdir          || return 1
10944         pool_set_dir $pool ./$tdir        || return 2
10945         pool_set_dir $pool ../$tdir       || return 3
10946         pool_set_dir $pool ../$tdir/$tdir || return 4
10947         rm -rf $tdir; cd - > /dev/null
10948 }
10949
10950 pool_alloc_files() {
10951         echo "Checking files allocation from directory pool"
10952         local pool=$1
10953         local tdir=$2
10954         local count=$3
10955         local tlist="$4"
10956
10957         local failed=0
10958         for i in $(seq -w 1 $count)
10959         do
10960                 local file=$tdir/file-$i
10961                 touch $file
10962                 check_file_in_pool $file $pool "$tlist" || \
10963                         failed=$((failed + 1))
10964         done
10965         [ "$failed" = 0 ] && return 0
10966
10967         error_noexit "$failed files not allocated in $pool"
10968         return 1
10969 }
10970
10971 pool_create_files() {
10972         echo "Creating files in pool"
10973         local pool=$1
10974         local tdir=$2
10975         local count=$3
10976         local tlist="$4"
10977
10978         mkdir -p $tdir
10979         local failed=0
10980         for i in $(seq -w 1 $count)
10981         do
10982                 local file=$tdir/spoo-$i
10983                 $SETSTRIPE -p $pool $file
10984                 check_file_in_pool $file $pool "$tlist" || \
10985                         failed=$((failed + 1))
10986         done
10987         [ "$failed" = 0 ] && return 0
10988
10989         error_noexit "$failed files not allocated in $pool"
10990         return 1
10991 }
10992
10993 pool_lfs_df() {
10994         echo "Checking 'lfs df' output"
10995         local pool=$1
10996
10997         local t=$($LCTL get_param -n lov.$FSNAME-clilov-*.pools.$pool |
10998                         tr '\n' ' ')
10999         local res=$($LFS df --pool $FSNAME.$pool |
11000                         awk '{print $1}' |
11001                         grep "$FSNAME-OST" |
11002                         tr '\n' ' ')
11003         [ "$res" = "$t" ] && return 0
11004
11005         error_noexit "Pools OSTs '$t' is not '$res' that lfs df reports"
11006         return 1
11007 }
11008
11009 pool_file_rel_path() {
11010         echo "Creating files in a pool with relative pathname"
11011         local pool=$1
11012         local tdir=$2
11013
11014         mkdir -p $tdir ||
11015                 { error_noexit "unable to create $tdir"; return 1 ; }
11016         local file="/..$tdir/$tfile-1"
11017         $SETSTRIPE -p $pool $file ||
11018                 { error_noexit "unable to create $file" ; return 2 ; }
11019
11020         cd $tdir
11021         $SETSTRIPE -p $pool $tfile-2 || {
11022                 error_noexit "unable to create $tfile-2 in $tdir"
11023                 return 3
11024         }
11025 }
11026
11027 pool_remove_first_target() {
11028         echo "Removing first target from a pool"
11029         local pool=$1
11030
11031         local pname="lov.$FSNAME-*.pools.$pool"
11032         local t=$($LCTL get_param -n $pname | head -n1)
11033         do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
11034         wait_update $HOSTNAME "lctl get_param -n $pname | grep $t" "" || {
11035                 error_noexit "$t not removed from $FSNAME.$pool"
11036                 return 1
11037         }
11038 }
11039
11040 pool_remove_all_targets() {
11041         echo "Removing all targets from pool"
11042         local pool=$1
11043         local file=$2
11044         local pname="lov.$FSNAME-*.pools.$pool"
11045         for t in $($LCTL get_param -n $pname | sort -u)
11046         do
11047                 do_facet mgs $LCTL pool_remove $FSNAME.$pool $t
11048         done
11049         wait_update $HOSTNAME "lctl get_param -n $pname" "" || {
11050                 error_noexit "Pool $FSNAME.$pool cannot be drained"
11051                 return 1
11052         }
11053         # striping on an empty/nonexistant pool should fall back
11054         # to "pool of everything"
11055         touch $file || {
11056                 error_noexit "failed to use fallback striping for empty pool"
11057                 return 2
11058         }
11059         # setstripe on an empty pool should fail
11060         $SETSTRIPE -p $pool $file 2>/dev/null && {
11061                 error_noexit "expected failure when creating file" \
11062                                                         "with empty pool"
11063                 return 3
11064         }
11065         return 0
11066 }
11067
11068 pool_remove() {
11069         echo "Destroying pool"
11070         local pool=$1
11071         local file=$2
11072
11073         do_facet mgs $LCTL pool_destroy $FSNAME.$pool
11074
11075         sleep 2
11076         # striping on an empty/nonexistant pool should fall back 
11077         # to "pool of everything"
11078         touch $file || {
11079                 error_noexit "failed to use fallback striping for missing pool"
11080                 return 1
11081         }
11082         # setstripe on an empty pool should fail
11083         $SETSTRIPE -p $pool $file 2>/dev/null && {
11084                 error_noexit "expected failure when creating file" \
11085                                                         "with missing pool"
11086                 return 2
11087         }
11088
11089         # get param should return err once pool is gone
11090         if wait_update $HOSTNAME "lctl get_param -n \
11091                 lov.$FSNAME-*.pools.$pool 2>/dev/null || echo foo" "foo"
11092         then
11093                 remove_pool_from_list $FSNAME.$pool
11094                 return 0
11095         fi
11096         error_noexit "Pool $FSNAME.$pool is not destroyed"
11097         return 3
11098 }
11099
11100 test_200() {
11101         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11102         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11103
11104         local POOL=${POOL:-cea1}
11105         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
11106         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
11107         # Pool OST targets
11108         local first_ost=0
11109         local last_ost=$(($OSTCOUNT - 1))
11110         local ost_step=2
11111         local ost_list=$(seq $first_ost $ost_step $last_ost)
11112         local ost_range="$first_ost $last_ost $ost_step"
11113         local test_path=$POOL_ROOT/$POOL_DIR_NAME
11114         local file_dir=$POOL_ROOT/file_tst
11115
11116         local rc=0
11117         while : ; do
11118                 # former test_200a test_200b
11119                 pool_add $POOL                          || { rc=$? ; break; }
11120                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
11121                 # former test_200c test_200d
11122                 mkdir -p $test_path
11123                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
11124                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
11125                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
11126                                                         || { rc=$? ; break; }
11127                 # former test_200e test_200f
11128                 local files=$((OSTCOUNT*3))
11129                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
11130                                                         || { rc=$? ; break; }
11131                 pool_create_files $POOL $file_dir $files "$ost_list" \
11132                                                         || { rc=$? ; break; }
11133                 # former test_200g test_200h
11134                 pool_lfs_df $POOL                       || { rc=$? ; break; }
11135                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
11136
11137                 # former test_201a test_201b test_201c
11138                 pool_remove_first_target $POOL          || { rc=$? ; break; }
11139
11140                 local f=$test_path/$tfile
11141                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
11142                 pool_remove $POOL $f                    || { rc=$? ; break; }
11143                 break
11144         done
11145
11146         cleanup_pools
11147         return $rc
11148 }
11149 run_test 200 "OST pools"
11150
11151 # usage: default_attr <count | size | offset>
11152 default_attr() {
11153         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
11154 }
11155
11156 # usage: check_default_stripe_attr
11157 check_default_stripe_attr() {
11158         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
11159         case $1 in
11160         --stripe-count|--count)
11161                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
11162         --stripe-size|--size)
11163                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
11164         --stripe-index|--index)
11165                 EXPECTED=-1;;
11166         *)
11167                 error "unknown getstripe attr '$1'"
11168         esac
11169
11170         [ $ACTUAL != $EXPECTED ] &&
11171                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
11172 }
11173
11174 test_204a() {
11175         test_mkdir -p $DIR/$tdir
11176         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
11177
11178         check_default_stripe_attr --stripe-count
11179         check_default_stripe_attr --stripe-size
11180         check_default_stripe_attr --stripe-index
11181
11182         return 0
11183 }
11184 run_test 204a "Print default stripe attributes ================="
11185
11186 test_204b() {
11187         test_mkdir -p $DIR/$tdir
11188         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11189
11190         check_default_stripe_attr --stripe-size
11191         check_default_stripe_attr --stripe-index
11192
11193         return 0
11194 }
11195 run_test 204b "Print default stripe size and offset  ==========="
11196
11197 test_204c() {
11198         test_mkdir -p $DIR/$tdir
11199         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11200
11201         check_default_stripe_attr --stripe-count
11202         check_default_stripe_attr --stripe-index
11203
11204         return 0
11205 }
11206 run_test 204c "Print default stripe count and offset ==========="
11207
11208 test_204d() {
11209         test_mkdir -p $DIR/$tdir
11210         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11211
11212         check_default_stripe_attr --stripe-count
11213         check_default_stripe_attr --stripe-size
11214
11215         return 0
11216 }
11217 run_test 204d "Print default stripe count and size ============="
11218
11219 test_204e() {
11220         test_mkdir -p $DIR/$tdir
11221         $SETSTRIPE -d $DIR/$tdir
11222
11223         check_default_stripe_attr --stripe-count --raw
11224         check_default_stripe_attr --stripe-size --raw
11225         check_default_stripe_attr --stripe-index --raw
11226
11227         return 0
11228 }
11229 run_test 204e "Print raw stripe attributes ================="
11230
11231 test_204f() {
11232         test_mkdir -p $DIR/$tdir
11233         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11234
11235         check_default_stripe_attr --stripe-size --raw
11236         check_default_stripe_attr --stripe-index --raw
11237
11238         return 0
11239 }
11240 run_test 204f "Print raw stripe size and offset  ==========="
11241
11242 test_204g() {
11243         test_mkdir -p $DIR/$tdir
11244         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11245
11246         check_default_stripe_attr --stripe-count --raw
11247         check_default_stripe_attr --stripe-index --raw
11248
11249         return 0
11250 }
11251 run_test 204g "Print raw stripe count and offset ==========="
11252
11253 test_204h() {
11254         test_mkdir -p $DIR/$tdir
11255         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11256
11257         check_default_stripe_attr --stripe-count --raw
11258         check_default_stripe_attr --stripe-size --raw
11259
11260         return 0
11261 }
11262 run_test 204h "Print raw stripe count and size ============="
11263
11264 # Figure out which job scheduler is being used, if any,
11265 # or use a fake one
11266 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11267         JOBENV=SLURM_JOB_ID
11268 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11269         JOBENV=LSB_JOBID
11270 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11271         JOBENV=PBS_JOBID
11272 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11273         JOBENV=LOADL_STEP_ID
11274 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11275         JOBENV=JOB_ID
11276 else
11277         JOBENV=FAKE_JOBID
11278 fi
11279
11280 verify_jobstats() {
11281         local cmd=$1
11282         local target=$2
11283
11284         # clear old jobstats
11285         do_facet $SINGLEMDS lctl set_param mdt.*.job_stats="clear"
11286         do_facet ost1 lctl set_param obdfilter.*.job_stats="clear"
11287
11288         # use a new JobID for this test, or we might see an old one
11289         [ "$JOBENV" = "FAKE_JOBID" ] && FAKE_JOBID=test_id.$testnum.$RANDOM
11290
11291         JOBVAL=${!JOBENV}
11292         log "Test: $cmd"
11293         log "Using JobID environment variable $JOBENV=$JOBVAL"
11294
11295         if [ $JOBENV = "FAKE_JOBID" ]; then
11296                 FAKE_JOBID=$JOBVAL $cmd
11297         else
11298                 $cmd
11299         fi
11300
11301         if [ "$target" = "mdt" -o "$target" = "both" ]; then
11302                 FACET="$SINGLEMDS" # will need to get MDS number for DNE
11303                 do_facet $FACET lctl get_param mdt.*.job_stats |
11304                         grep $JOBVAL || error "No job stats found on MDT $FACET"
11305         fi
11306         if [ "$target" = "ost" -o "$target" = "both" ]; then
11307                 FACET=ost1
11308                 do_facet $FACET lctl get_param obdfilter.*.job_stats |
11309                         grep $JOBVAL || error "No job stats found on OST $FACET"
11310         fi
11311 }
11312
11313 jobstats_set() {
11314         trap 0
11315         NEW_JOBENV=${1:-$OLD_JOBENV}
11316         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11317         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11318 }
11319
11320 test_205() { # Job stats
11321         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11322         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11323                 skip "Server doesn't support jobstats" && return 0
11324         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11325
11326         local cmd
11327         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11328         if [ $OLD_JOBENV != $JOBENV ]; then
11329                 jobstats_set $JOBENV
11330                 trap jobstats_set EXIT
11331         fi
11332
11333         # mkdir
11334         cmd="mkdir $DIR/$tfile"
11335         verify_jobstats "$cmd" "mdt"
11336         # rmdir
11337         cmd="rm -fr $DIR/$tfile"
11338         verify_jobstats "$cmd" "mdt"
11339         # mknod
11340         cmd="mknod $DIR/$tfile c 1 3"
11341         verify_jobstats "$cmd" "mdt"
11342         # unlink
11343         cmd="rm -f $DIR/$tfile"
11344         verify_jobstats "$cmd" "mdt"
11345         # open & close
11346         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11347         verify_jobstats "$cmd" "mdt"
11348         # setattr
11349         cmd="touch $DIR/$tfile"
11350         verify_jobstats "$cmd" "both"
11351         # write
11352         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11353         verify_jobstats "$cmd" "ost"
11354         # read
11355         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11356         verify_jobstats "$cmd" "ost"
11357         # truncate
11358         cmd="$TRUNCATE $DIR/$tfile 0"
11359         verify_jobstats "$cmd" "both"
11360         # rename
11361         cmd="mv -f $DIR/$tfile $DIR/jobstats_test_rename"
11362         verify_jobstats "$cmd" "mdt"
11363
11364         # cleanup
11365         rm -f $DIR/jobstats_test_rename
11366
11367         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11368 }
11369 run_test 205 "Verify job stats"
11370
11371 # LU-1480, LU-1773 and LU-1657
11372 test_206() {
11373         mkdir -p $DIR/$tdir
11374         $SETSTRIPE -c -1 $DIR/$tdir
11375 #define OBD_FAIL_LOV_INIT 0x1403
11376         $LCTL set_param fail_loc=0xa0001403
11377         $LCTL set_param fail_val=1
11378         touch $DIR/$tdir/$tfile || true
11379 }
11380 run_test 206 "fail lov_init_raid0() doesn't lbug"
11381
11382 test_207a() {
11383         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11384         local fsz=`stat -c %s $DIR/$tfile`
11385         cancel_lru_locks mdc
11386
11387         # do not return layout in getattr intent
11388 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11389         $LCTL set_param fail_loc=0x170
11390         local sz=`stat -c %s $DIR/$tfile`
11391
11392         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11393
11394         rm -rf $DIR/$tfile
11395 }
11396 run_test 207a "can refresh layout at glimpse"
11397
11398 test_207b() {
11399         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11400         local cksum=`md5sum $DIR/$tfile`
11401         local fsz=`stat -c %s $DIR/$tfile`
11402         cancel_lru_locks mdc
11403         cancel_lru_locks osc
11404
11405         # do not return layout in getattr intent
11406 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11407         $LCTL set_param fail_loc=0x171
11408
11409         # it will refresh layout after the file is opened but before read issues
11410         echo checksum is "$cksum"
11411         echo "$cksum" |md5sum -c --quiet || error "file differs"
11412
11413         rm -rf $DIR/$tfile
11414 }
11415 run_test 207b "can refresh layout at open"
11416
11417 test_208() {
11418         # FIXME: in this test suite, only RD lease is used. This is okay
11419         # for now as only exclusive open is supported. After generic lease
11420         # is done, this test suite should be revised. - Jinshan
11421
11422         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11423                 { skip "Need MDS version at least 2.4.52"; return 0; }
11424
11425         echo "==== test 1: verify get lease work"
11426         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11427
11428         echo "==== test 2: verify lease can be broken by upcoming open"
11429         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11430         local PID=$!
11431         sleep 1
11432
11433         $MULTIOP $DIR/$tfile oO_RDONLY:c
11434         kill -USR1 $PID && wait $PID || error "break lease error"
11435
11436         echo "==== test 3: verify lease can't be granted if an open already exists"
11437         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11438         local PID=$!
11439         sleep 1
11440
11441         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11442         kill -USR1 $PID && wait $PID || error "open file error"
11443
11444         echo "==== test 4: lease can sustain over recovery"
11445         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11446         PID=$!
11447         sleep 1
11448
11449         fail mds1
11450
11451         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11452
11453         echo "==== test 5: lease broken can't be regained by replay"
11454         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11455         PID=$!
11456         sleep 1
11457
11458         # open file to break lease and then recovery
11459         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11460         fail mds1
11461
11462         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11463
11464         rm -f $DIR/$tfile
11465 }
11466 run_test 208 "Exclusive open"
11467
11468 test_209() {
11469         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11470                 skip_env "must have disp_stripe" && return
11471
11472         touch $DIR/$tfile
11473         sync; sleep 5; sync;
11474
11475         echo 3 > /proc/sys/vm/drop_caches
11476         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11477
11478         # open/close 500 times
11479         for i in $(seq 500); do
11480                 cat $DIR/$tfile
11481         done
11482
11483         echo 3 > /proc/sys/vm/drop_caches
11484         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11485
11486         echo "before: $req_before, after: $req_after"
11487         [ $((req_after - req_before)) -ge 300 ] &&
11488                 error "open/close requests are not freed"
11489         return 0
11490 }
11491 run_test 209 "read-only open/close requests should be freed promptly"
11492
11493 test_212() {
11494         size=`date +%s`
11495         size=$((size % 8192 + 1))
11496         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11497         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11498         rm -f $DIR/f212 $DIR/f212.xyz
11499 }
11500 run_test 212 "Sendfile test ============================================"
11501
11502 test_213() {
11503         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11504         cancel_lru_locks osc
11505         lctl set_param fail_loc=0x8000040f
11506         # generate a read lock
11507         cat $DIR/$tfile > /dev/null
11508         # write to the file, it will try to cancel the above read lock.
11509         cat /etc/hosts >> $DIR/$tfile
11510 }
11511 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11512
11513 test_214() { # for bug 20133
11514         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11515         for (( i=0; i < 340; i++ )) ; do
11516                 touch $DIR/$tdir/d214c/a$i
11517         done
11518
11519         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11520         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11521         ls $DIR/d214c || error "ls $DIR/d214c failed"
11522         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11523         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11524 }
11525 run_test 214 "hash-indexed directory test - bug 20133"
11526
11527 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11528 create_lnet_proc_files() {
11529         cat /proc/sys/lnet/$1 >$TMP/lnet_$1.out || error "cannot read /proc/sys/lnet/$1"
11530         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11531
11532         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11533         rm -f "$TMP/lnet_$1.sys_tmp"
11534 }
11535
11536 # counterpart of create_lnet_proc_files
11537 remove_lnet_proc_files() {
11538         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11539 }
11540
11541 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11542 # 3rd arg as regexp for body
11543 check_lnet_proc_stats() {
11544         local l=$(cat "$TMP/lnet_$1" |wc -l)
11545         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
11546
11547         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
11548 }
11549
11550 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11551 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
11552 # optional and can be regexp for 2nd line (lnet.routes case)
11553 check_lnet_proc_entry() {
11554         local blp=2          # blp stands for 'position of 1st line of body'
11555         [ -z "$5" ] || blp=3 # lnet.routes case
11556
11557         local l=$(cat "$TMP/lnet_$1" |wc -l)
11558         # subtracting one from $blp because the body can be empty
11559         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
11560
11561         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
11562                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
11563
11564         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
11565                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
11566
11567         # bail out if any unexpected line happened
11568         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
11569         [ "$?" != 0 ] || error "$2 misformatted"
11570 }
11571
11572 test_215() { # for bugs 18102, 21079, 21517
11573         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11574         local N='(0|[1-9][0-9]*)'       # non-negative numeric
11575         local P='[1-9][0-9]*'           # positive numeric
11576         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
11577         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
11578         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
11579         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
11580
11581         local L1 # regexp for 1st line
11582         local L2 # regexp for 2nd line (optional)
11583         local BR # regexp for the rest (body)
11584
11585         # /proc/sys/lnet/stats should look as 11 space-separated non-negative numerics
11586         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
11587         create_lnet_proc_files "stats"
11588         check_lnet_proc_stats "stats.out" "/proc/sys/lnet/stats" "$BR"
11589         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
11590         remove_lnet_proc_files "stats"
11591
11592         # /proc/sys/lnet/routes should look like this:
11593         # Routing disabled/enabled
11594         # net hops priority state router
11595         # where net is a string like tcp0, hops > 0, priority >= 0,
11596         # state is up/down,
11597         # router is a string like 192.168.1.1@tcp2
11598         L1="^Routing (disabled|enabled)$"
11599         L2="^net +hops +priority +state +router$"
11600         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
11601         create_lnet_proc_files "routes"
11602         check_lnet_proc_entry "routes.out" "/proc/sys/lnet/routes" "$BR" "$L1" "$L2"
11603         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
11604         remove_lnet_proc_files "routes"
11605
11606         # /proc/sys/lnet/routers should look like this:
11607         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
11608         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
11609         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
11610         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
11611         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
11612         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
11613         create_lnet_proc_files "routers"
11614         check_lnet_proc_entry "routers.out" "/proc/sys/lnet/routers" "$BR" "$L1"
11615         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
11616         remove_lnet_proc_files "routers"
11617
11618         # /proc/sys/lnet/peers should look like this:
11619         # nid refs state last max rtr min tx min queue
11620         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
11621         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
11622         # numeric (0 or >0 or <0), queue >= 0.
11623         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
11624         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
11625         create_lnet_proc_files "peers"
11626         check_lnet_proc_entry "peers.out" "/proc/sys/lnet/peers" "$BR" "$L1"
11627         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
11628         remove_lnet_proc_files "peers"
11629
11630         # /proc/sys/lnet/buffers  should look like this:
11631         # pages count credits min
11632         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
11633         L1="^pages +count +credits +min$"
11634         BR="^ +$N +$N +$I +$I$"
11635         create_lnet_proc_files "buffers"
11636         check_lnet_proc_entry "buffers.out" "/proc/sys/lnet/buffers" "$BR" "$L1"
11637         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
11638         remove_lnet_proc_files "buffers"
11639
11640         # /proc/sys/lnet/nis should look like this:
11641         # nid status alive refs peer rtr max tx min
11642         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
11643         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
11644         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
11645         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
11646         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
11647         create_lnet_proc_files "nis"
11648         check_lnet_proc_entry "nis.out" "/proc/sys/lnet/nis" "$BR" "$L1"
11649         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
11650         remove_lnet_proc_files "nis"
11651
11652         # can we successfully write to /proc/sys/lnet/stats?
11653         echo "0" >/proc/sys/lnet/stats || error "cannot write to /proc/sys/lnet/stats"
11654         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
11655 }
11656 run_test 215 "/proc/sys/lnet exists and has proper content - bugs 18102, 21079, 21517"
11657
11658 test_216() { # bug 20317
11659         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11660         remote_ost_nodsh && skip "remote OST with nodsh" && return
11661
11662         local node
11663         local facets=$(get_facets OST)
11664         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
11665
11666         save_lustre_params client "osc.*.contention_seconds" > $p
11667         save_lustre_params $facets \
11668                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
11669         save_lustre_params $facets \
11670                 "ldlm.namespaces.filter-*.contended_locks" >> $p
11671         save_lustre_params $facets \
11672                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
11673         clear_osc_stats
11674
11675         # agressive lockless i/o settings
11676         for node in $(osts_nodes); do
11677                 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'
11678         done
11679         lctl set_param -n osc.*.contention_seconds 60
11680
11681         $DIRECTIO write $DIR/$tfile 0 10 4096
11682         $CHECKSTAT -s 40960 $DIR/$tfile
11683
11684         # disable lockless i/o
11685         for node in $(osts_nodes); do
11686                 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'
11687         done
11688         lctl set_param -n osc.*.contention_seconds 0
11689         clear_osc_stats
11690
11691         dd if=/dev/zero of=$DIR/$tfile count=0
11692         $CHECKSTAT -s 0 $DIR/$tfile
11693
11694         restore_lustre_params <$p
11695         rm -f $p
11696         rm $DIR/$tfile
11697 }
11698 run_test 216 "check lockless direct write works and updates file size and kms correctly"
11699
11700 test_217() { # bug 22430
11701         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11702         local node
11703         local nid
11704
11705         for node in $(nodes_list); do
11706                 nid=$(host_nids_address $node $NETTYPE)
11707                 if [[ $nid = *-* ]] ; then
11708                         echo "lctl ping $nid@$NETTYPE"
11709                         lctl ping $nid@$NETTYPE
11710                 else
11711                         echo "skipping $node (no hyphen detected)"
11712                 fi
11713         done
11714 }
11715 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
11716
11717 test_218() {
11718        # do directio so as not to populate the page cache
11719        log "creating a 10 Mb file"
11720        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
11721        log "starting reads"
11722        dd if=$DIR/$tfile of=/dev/null bs=4096 &
11723        log "truncating the file"
11724        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
11725        log "killing dd"
11726        kill %+ || true # reads might have finished
11727        echo "wait until dd is finished"
11728        wait
11729        log "removing the temporary file"
11730        rm -rf $DIR/$tfile || error "tmp file removal failed"
11731 }
11732 run_test 218 "parallel read and truncate should not deadlock ======================="
11733
11734 test_219() {
11735         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11736         # write one partial page
11737         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
11738         # set no grant so vvp_io_commit_write will do sync write
11739         $LCTL set_param fail_loc=0x411
11740         # write a full page at the end of file
11741         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
11742
11743         $LCTL set_param fail_loc=0
11744         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
11745         $LCTL set_param fail_loc=0x411
11746         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
11747
11748         # LU-4201
11749         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
11750         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
11751 }
11752 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
11753
11754 test_220() { #LU-325
11755         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11756         remote_ost_nodsh && skip "remote OST with nodsh" && return
11757         local OSTIDX=0
11758
11759         test_mkdir -p $DIR/$tdir
11760         local OST=$(lfs osts | grep ${OSTIDX}": " | \
11761                 awk '{print $2}' | sed -e 's/_UUID$//')
11762
11763         # on the mdt's osc
11764         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
11765         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
11766                         osc.$mdtosc_proc1.prealloc_last_id)
11767         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
11768                         osc.$mdtosc_proc1.prealloc_next_id)
11769
11770         $LFS df -i
11771
11772         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
11773         #define OBD_FAIL_OST_ENOINO              0x229
11774         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
11775         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
11776         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
11777
11778         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
11779
11780         MDSOBJS=$((last_id - next_id))
11781         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
11782
11783         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
11784         echo "OST still has $count kbytes free"
11785
11786         echo "create $MDSOBJS files @next_id..."
11787         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
11788
11789         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11790                         osc.$mdtosc_proc1.prealloc_last_id)
11791         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
11792                         osc.$mdtosc_proc1.prealloc_next_id)
11793
11794         echo "after creation, last_id=$last_id2, next_id=$next_id2"
11795         $LFS df -i
11796
11797         echo "cleanup..."
11798
11799         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
11800         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
11801
11802         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
11803         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
11804         echo "unlink $MDSOBJS files @$next_id..."
11805         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
11806 }
11807 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
11808
11809 test_221() {
11810         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11811         dd if=`which date` of=$MOUNT/date oflag=sync
11812         chmod +x $MOUNT/date
11813
11814         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
11815         $LCTL set_param fail_loc=0x80001401
11816
11817         $MOUNT/date > /dev/null
11818         rm -f $MOUNT/date
11819 }
11820 run_test 221 "make sure fault and truncate race to not cause OOM"
11821
11822 test_222a () {
11823         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11824        rm -rf $DIR/$tdir
11825        test_mkdir -p $DIR/$tdir
11826        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11827        createmany -o $DIR/$tdir/$tfile 10
11828        cancel_lru_locks mdc
11829        cancel_lru_locks osc
11830        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11831        $LCTL set_param fail_loc=0x31a
11832        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
11833        $LCTL set_param fail_loc=0
11834        rm -r $DIR/$tdir
11835 }
11836 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
11837
11838 test_222b () {
11839         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11840        rm -rf $DIR/$tdir
11841        test_mkdir -p $DIR/$tdir
11842        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11843        createmany -o $DIR/$tdir/$tfile 10
11844        cancel_lru_locks mdc
11845        cancel_lru_locks osc
11846        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
11847        $LCTL set_param fail_loc=0x31a
11848        rm -r $DIR/$tdir || "AGL for rmdir failed"
11849        $LCTL set_param fail_loc=0
11850 }
11851 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
11852
11853 test_223 () {
11854         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11855        rm -rf $DIR/$tdir
11856        test_mkdir -p $DIR/$tdir
11857        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
11858        createmany -o $DIR/$tdir/$tfile 10
11859        cancel_lru_locks mdc
11860        cancel_lru_locks osc
11861        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
11862        $LCTL set_param fail_loc=0x31b
11863        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
11864        $LCTL set_param fail_loc=0
11865        rm -r $DIR/$tdir
11866 }
11867 run_test 223 "osc reenqueue if without AGL lock granted ======================="
11868
11869 test_224a() { # LU-1039, MRP-303
11870         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11871         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
11872         $LCTL set_param fail_loc=0x508
11873         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
11874         $LCTL set_param fail_loc=0
11875         df $DIR
11876 }
11877 run_test 224a "Don't panic on bulk IO failure"
11878
11879 test_224b() { # LU-1039, MRP-303
11880         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11881         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
11882         cancel_lru_locks osc
11883         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
11884         $LCTL set_param fail_loc=0x515
11885         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
11886         $LCTL set_param fail_loc=0
11887         df $DIR
11888 }
11889 run_test 224b "Don't panic on bulk IO failure"
11890
11891 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
11892 test_225a () {
11893         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11894         if [ -z ${MDSSURVEY} ]; then
11895               skip_env "mds-survey not found" && return
11896         fi
11897
11898         [ $MDSCOUNT -ge 2 ] &&
11899                 skip "skipping now for more than one MDT" && return
11900
11901        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11902             { skip "Need MDS version at least 2.2.51"; return; }
11903
11904        local mds=$(facet_host $SINGLEMDS)
11905        local target=$(do_nodes $mds 'lctl dl' | \
11906                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11907
11908        local cmd1="file_count=1000 thrhi=4"
11909        local cmd2="dir_count=2 layer=mdd stripe_count=0"
11910        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11911        local cmd="$cmd1 $cmd2 $cmd3"
11912
11913        rm -f ${TMP}/mds_survey*
11914        echo + $cmd
11915        eval $cmd || error "mds-survey with zero-stripe failed"
11916        cat ${TMP}/mds_survey*
11917        rm -f ${TMP}/mds_survey*
11918 }
11919 run_test 225a "Metadata survey sanity with zero-stripe"
11920
11921 test_225b () {
11922         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11923
11924         if [ -z ${MDSSURVEY} ]; then
11925               skip_env "mds-survey not found" && return
11926         fi
11927         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
11928             { skip "Need MDS version at least 2.2.51"; return; }
11929
11930         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
11931               skip_env "Need to mount OST to test" && return
11932         fi
11933
11934         [ $MDSCOUNT -ge 2 ] &&
11935                 skip "skipping now for more than one MDT" && return
11936        local mds=$(facet_host $SINGLEMDS)
11937        local target=$(do_nodes $mds 'lctl dl' | \
11938                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
11939
11940        local cmd1="file_count=1000 thrhi=4"
11941        local cmd2="dir_count=2 layer=mdd stripe_count=1"
11942        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
11943        local cmd="$cmd1 $cmd2 $cmd3"
11944
11945        rm -f ${TMP}/mds_survey*
11946        echo + $cmd
11947        eval $cmd || error "mds-survey with stripe_count failed"
11948        cat ${TMP}/mds_survey*
11949        rm -f ${TMP}/mds_survey*
11950 }
11951 run_test 225b "Metadata survey sanity with stripe_count = 1"
11952
11953 mcreate_path2fid () {
11954         local mode=$1
11955         local major=$2
11956         local minor=$3
11957         local name=$4
11958         local desc=$5
11959         local path=$DIR/$tdir/$name
11960         local fid
11961         local rc
11962         local fid_path
11963
11964         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
11965                 error "cannot create $desc"
11966
11967         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
11968         rc=$?
11969         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
11970
11971         fid_path=$($LFS fid2path $MOUNT $fid)
11972         rc=$?
11973         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
11974
11975         [ "$path" == "$fid_path" ] ||
11976                 error "fid2path returned $fid_path, expected $path"
11977
11978         echo "pass with $path and $fid"
11979 }
11980
11981 test_226a () {
11982         rm -rf $DIR/$tdir
11983         mkdir -p $DIR/$tdir
11984
11985         mcreate_path2fid 0010666 0 0 fifo "FIFO"
11986         mcreate_path2fid 0020666 1 3 null "character special file (null)"
11987         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
11988         mcreate_path2fid 0040666 0 0 dir "directory"
11989         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
11990         mcreate_path2fid 0100666 0 0 file "regular file"
11991         mcreate_path2fid 0120666 0 0 link "symbolic link"
11992         mcreate_path2fid 0140666 0 0 sock "socket"
11993 }
11994 run_test 226a "call path2fid and fid2path on files of all type"
11995
11996 test_226b () {
11997         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
11998         rm -rf $DIR/$tdir
11999         local MDTIDX=1
12000
12001         mkdir -p $DIR/$tdir
12002         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
12003                 error "create remote directory failed"
12004         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
12005         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
12006                                 "character special file (null)"
12007         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
12008                                 "character special file (no device)"
12009         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
12010         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
12011                                 "block special file (loop)"
12012         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
12013         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
12014         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
12015 }
12016 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
12017
12018 # LU-1299 Executing or running ldd on a truncated executable does not
12019 # cause an out-of-memory condition.
12020 test_227() {
12021         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12022         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
12023         dd if=$(which date) of=$MOUNT/date bs=1k count=1
12024         chmod +x $MOUNT/date
12025
12026         $MOUNT/date > /dev/null
12027         ldd $MOUNT/date > /dev/null
12028         rm -f $MOUNT/date
12029 }
12030 run_test 227 "running truncated executable does not cause OOM"
12031
12032 # LU-1512 try to reuse idle OI blocks
12033 test_228a() {
12034         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12035         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12036                 skip "non-ldiskfs backend" && return
12037
12038         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12039         local myDIR=$DIR/$tdir
12040
12041         mkdir -p $myDIR
12042         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12043         $LCTL set_param fail_loc=0x80001002
12044         createmany -o $myDIR/t- 10000
12045         $LCTL set_param fail_loc=0
12046         # The guard is current the largest FID holder
12047         touch $myDIR/guard
12048         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12049                     tr -d '[')
12050         local IDX=$(($SEQ % 64))
12051
12052         do_facet $SINGLEMDS sync
12053         # Make sure journal flushed.
12054         sleep 6
12055         local blk1=$(do_facet $SINGLEMDS \
12056                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12057                      grep Blockcount | awk '{print $4}')
12058
12059         # Remove old files, some OI blocks will become idle.
12060         unlinkmany $myDIR/t- 10000
12061         # Create new files, idle OI blocks should be reused.
12062         createmany -o $myDIR/t- 2000
12063         do_facet $SINGLEMDS sync
12064         # Make sure journal flushed.
12065         sleep 6
12066         local blk2=$(do_facet $SINGLEMDS \
12067                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12068                      grep Blockcount | awk '{print $4}')
12069
12070         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12071 }
12072 run_test 228a "try to reuse idle OI blocks"
12073
12074 test_228b() {
12075         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12076         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12077                 skip "non-ldiskfs backend" && return
12078
12079         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12080         local myDIR=$DIR/$tdir
12081
12082         mkdir -p $myDIR
12083         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12084         $LCTL set_param fail_loc=0x80001002
12085         createmany -o $myDIR/t- 10000
12086         $LCTL set_param fail_loc=0
12087         # The guard is current the largest FID holder
12088         touch $myDIR/guard
12089         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12090                     tr -d '[')
12091         local IDX=$(($SEQ % 64))
12092
12093         do_facet $SINGLEMDS sync
12094         # Make sure journal flushed.
12095         sleep 6
12096         local blk1=$(do_facet $SINGLEMDS \
12097                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12098                      grep Blockcount | awk '{print $4}')
12099
12100         # Remove old files, some OI blocks will become idle.
12101         unlinkmany $myDIR/t- 10000
12102
12103         # stop the MDT
12104         stop $SINGLEMDS || error "Fail to stop MDT."
12105         # remount the MDT
12106         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
12107
12108         df $MOUNT || error "Fail to df."
12109         # Create new files, idle OI blocks should be reused.
12110         createmany -o $myDIR/t- 2000
12111         do_facet $SINGLEMDS sync
12112         # Make sure journal flushed.
12113         sleep 6
12114         local blk2=$(do_facet $SINGLEMDS \
12115                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12116                      grep Blockcount | awk '{print $4}')
12117
12118         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12119 }
12120 run_test 228b "idle OI blocks can be reused after MDT restart"
12121
12122 #LU-1881
12123 test_228c() {
12124         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12125         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12126                 skip "non-ldiskfs backend" && return
12127
12128         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12129         local myDIR=$DIR/$tdir
12130
12131         mkdir -p $myDIR
12132         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12133         $LCTL set_param fail_loc=0x80001002
12134         # 20000 files can guarantee there are index nodes in the OI file
12135         createmany -o $myDIR/t- 20000
12136         $LCTL set_param fail_loc=0
12137         # The guard is current the largest FID holder
12138         touch $myDIR/guard
12139         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12140                     tr -d '[')
12141         local IDX=$(($SEQ % 64))
12142
12143         do_facet $SINGLEMDS sync
12144         # Make sure journal flushed.
12145         sleep 6
12146         local blk1=$(do_facet $SINGLEMDS \
12147                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12148                      grep Blockcount | awk '{print $4}')
12149
12150         # Remove old files, some OI blocks will become idle.
12151         unlinkmany $myDIR/t- 20000
12152         rm -f $myDIR/guard
12153         # The OI file should become empty now
12154
12155         # Create new files, idle OI blocks should be reused.
12156         createmany -o $myDIR/t- 2000
12157         do_facet $SINGLEMDS sync
12158         # Make sure journal flushed.
12159         sleep 6
12160         local blk2=$(do_facet $SINGLEMDS \
12161                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12162                      grep Blockcount | awk '{print $4}')
12163
12164         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12165 }
12166 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
12167
12168 test_229() { # LU-2482, LU-3448
12169         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
12170                 skip "No HSM support on MDS of $(get_lustre_version)," \
12171                          "need 2.4.53 at least" && return
12172         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12173         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
12174
12175         rm -f $DIR/$tfile
12176
12177         # Create a file with a released layout and stripe count 2.
12178         $MULTIOP $DIR/$tfile H2c ||
12179                 error "failed to create file with released layout"
12180
12181         $GETSTRIPE -v $DIR/$tfile
12182
12183         local pattern=$($GETSTRIPE -L $DIR/$tfile)
12184         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
12185
12186         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
12187         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
12188         stat $DIR/$tfile || error "failed to stat released file"
12189
12190         chown $RUNAS_ID $DIR/$tfile ||
12191                 error "chown $RUNAS_ID $DIR/$tfile failed"
12192
12193         chgrp $RUNAS_ID $DIR/$tfile ||
12194                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12195
12196         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12197         rm $DIR/$tfile || error "failed to remove released file"
12198 }
12199 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12200
12201 test_230a() {
12202         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12203         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12204         local MDTIDX=1
12205
12206         mkdir -p $DIR/$tdir/test_230_local
12207         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12208         [ $mdt_idx -ne 0 ] &&
12209                 error "create local directory on wrong MDT $mdt_idx"
12210
12211         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12212                         error "create remote directory failed"
12213         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12214         [ $mdt_idx -ne $MDTIDX ] &&
12215                 error "create remote directory on wrong MDT $mdt_idx"
12216
12217         createmany -o $DIR/$tdir/test_230/t- 10 ||
12218                 error "create files on remote directory failed"
12219         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12220         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12221         rm -r $DIR/$tdir || error "unlink remote directory failed"
12222 }
12223 run_test 230a "Create remote directory and files under the remote directory"
12224
12225 test_230b() {
12226         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12227         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12228         local MDTIDX=1
12229         local mdt_index
12230         local i
12231         local file
12232         local pid
12233         local stripe_count
12234         local migrate_dir=$DIR/$tdir/migrate_dir
12235         local other_dir=$DIR/$tdir/other_dir
12236
12237         mkdir -p $migrate_dir
12238         mkdir -p $other_dir
12239         for ((i=0; i<10; i++)); do
12240                 mkdir -p $migrate_dir/dir_${i}
12241                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12242                         error "create files under remote dir failed $i"
12243         done
12244
12245         cp /etc/passwd $migrate_dir/$tfile
12246         cp /etc/passwd $other_dir/$tfile
12247         chattr +SAD $migrate_dir
12248         chattr +SAD $migrate_dir/$tfile
12249
12250         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12251         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12252         local old_dir_mode=$(stat -c%f $migrate_dir)
12253         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
12254
12255         mkdir -p $migrate_dir/dir_default_stripe2
12256         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12257         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12258
12259         mkdir -p $other_dir
12260         ln $migrate_dir/$tfile $other_dir/luna
12261         ln $migrate_dir/$tfile $migrate_dir/sofia
12262         ln $other_dir/$tfile $migrate_dir/david
12263         ln -s $migrate_dir/$tfile $other_dir/zachary
12264         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12265         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12266
12267         $LFS mv -v -M $MDTIDX $migrate_dir ||
12268                         error "migrate remote dir error"
12269
12270         echo "migratate to MDT1, then checking.."
12271         for ((i=0; i<10; i++)); do
12272                 for file in $(find $migrate_dir/dir_${i}); do
12273                         mdt_index=$($LFS getstripe -M $file)
12274                         [ $mdt_index == $MDTIDX ] ||
12275                                 error "$file is not on MDT${MDTIDX}"
12276                 done
12277         done
12278
12279         # the multiple link file should still in MDT0
12280         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12281         [ $mdt_index == 0 ] ||
12282                 error "$file is not on MDT${MDTIDX}"
12283
12284         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12285         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12286                 error " expect $old_dir_flag get $new_dir_flag"
12287
12288         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12289         [ "$old_file_flag" = "$new_file_flag" ] ||
12290                 error " expect $old_file_flag get $new_file_flag"
12291
12292         local new_dir_mode=$(stat -c%f $migrate_dir)
12293         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12294                 error "expect mode $old_dir_mode get $new_dir_mode"
12295
12296         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12297         [ "$old_file_mode" = "$new_file_mode" ] ||
12298                 error "expect mode $old_file_mode get $new_file_mode"
12299
12300         diff /etc/passwd $migrate_dir/$tfile ||
12301                 error "$tfile different after migration"
12302
12303         diff /etc/passwd $other_dir/luna ||
12304                 error "luna different after migration"
12305
12306         diff /etc/passwd $migrate_dir/sofia ||
12307                 error "sofia different after migration"
12308
12309         diff /etc/passwd $migrate_dir/david ||
12310                 error "david different after migration"
12311
12312         diff /etc/passwd $other_dir/zachary ||
12313                 error "zachary different after migration"
12314
12315         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12316                 error "${tfile}_ln different after migration"
12317
12318         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12319                 error "${tfile}_ln_other different after migration"
12320
12321         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12322         [ $stripe_count = 2 ] ||
12323                         error "dir strpe_count $d != 2 after migration."
12324
12325         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12326         [ $stripe_count = 2 ] ||
12327                         error "file strpe_count $d != 2 after migration."
12328
12329         #migrate back to MDT0
12330         MDTIDX=0
12331         $LFS mv -v -M $MDTIDX $migrate_dir ||
12332                         error "migrate remote dir error"
12333
12334         echo "migrate back to MDT0, checking.."
12335         for file in $(find $migrate_dir); do
12336                 mdt_index=$($LFS getstripe -M $file)
12337                 [ $mdt_index == $MDTIDX ] ||
12338                         error "$file is not on MDT${MDTIDX}"
12339         done
12340
12341         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12342         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12343                 error " expect $old_dir_flag get $new_dir_flag"
12344
12345         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12346         [ "$old_file_flag" = "$new_file_flag" ] ||
12347                 error " expect $old_file_flag get $new_file_flag"
12348
12349         local new_dir_mode=$(stat -c%f $migrate_dir)
12350         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12351                 error "expect mode $old_dir_mode get $new_dir_mode"
12352
12353         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12354         [ "$old_file_mode" = "$new_file_mode" ] ||
12355                 error "expect mode $old_file_mode get $new_file_mode"
12356
12357         diff /etc/passwd ${migrate_dir}/$tfile ||
12358                 error "$tfile different after migration"
12359
12360         diff /etc/passwd ${other_dir}/luna ||
12361                 error "luna different after migration"
12362
12363         diff /etc/passwd ${migrate_dir}/sofia ||
12364                 error "sofia different after migration"
12365
12366         diff /etc/passwd ${other_dir}/zachary ||
12367                 error "zachary different after migration"
12368
12369         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12370                 error "${tfile}_ln different after migration"
12371
12372         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12373                 error "${tfile}_ln_other different after migration"
12374
12375         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12376         [ $stripe_count = 2 ] ||
12377                 error "dir strpe_count $d != 2 after migration."
12378
12379         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12380         [ $stripe_count = 2 ] ||
12381                 error "file strpe_count $d != 2 after migration."
12382
12383         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12384 }
12385 run_test 230b "migrate directory"
12386
12387 test_230c() {
12388         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12389         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12390         local MDTIDX=1
12391         local mdt_index
12392         local file
12393
12394         #If migrating directory fails in the middle, all entries of
12395         #the directory is still accessiable.
12396         mkdir -p $DIR/$tdir
12397         stat $DIR/$tdir
12398         createmany -o $DIR/$tdir/f 10 ||
12399                 error "create files under ${tdir} failed"
12400
12401         #failed after migrating 5 entries
12402         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12403         do_facet mds1 lctl set_param fail_loc=0x20001801
12404         do_facet mds1 lctl  set_param fail_val=5
12405         local t=`ls $DIR/$tdir | wc -l`
12406         $LFS mv -M $MDTIDX $DIR/$tdir &&
12407                 error "migrate should failed after 5 entries"
12408         local u=`ls $DIR/$tdir | wc -l`
12409         [ "$u" == "$t" ] || error "$u != $t during migration"
12410
12411         for file in $(find $DIR/$tdir); do
12412                 stat $file || error "stat $file failed"
12413         done
12414
12415         do_facet mds1 lctl set_param fail_loc=0
12416         do_facet mds1 lctl set_param fail_val=0
12417
12418         $LFS mv -M $MDTIDX $DIR/$tdir ||
12419                 error "migrate open files should failed with open files"
12420
12421         echo "Finish migration, then checking.."
12422         for file in $(find $DIR/$tdir); do
12423                 mdt_index=$($LFS getstripe -M $file)
12424                 [ $mdt_index == $MDTIDX ] ||
12425                         error "$file is not on MDT${MDTIDX}"
12426         done
12427
12428         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12429 }
12430 run_test 230c "check directory accessiblity if migration is failed"
12431
12432 test_230d() {
12433         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12434         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12435         local MDTIDX=1
12436         local mdt_index
12437         local i
12438         local j
12439
12440         mkdir -p $DIR/$tdir
12441
12442         for ((i=0; i<100; i++)); do
12443                 mkdir -p $DIR/$tdir/dir_${i}
12444                 createmany -o $DIR/$tdir/dir_${i}/f 100 ||
12445                         error "create files under remote dir failed $i"
12446         done
12447
12448         $LFS mv -M $MDTIDX -v $DIR/$tdir || error "migrate remote dir error"
12449
12450         echo "Finish migration, then checking.."
12451         for file in $(find $DIR/$tdir); do
12452                 mdt_index=$($LFS getstripe -M $file)
12453                 [ $mdt_index == $MDTIDX ] ||
12454                         error "$file is not on MDT${MDTIDX}"
12455         done
12456
12457         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12458 }
12459 run_test 230d "check migrate big directory"
12460
12461 test_231a()
12462 {
12463         # For simplicity this test assumes that max_pages_per_rpc
12464         # is the same across all OSCs
12465         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
12466         local bulk_size=$((max_pages * 4096))
12467
12468         mkdir -p $DIR/$tdir
12469
12470         # clear the OSC stats
12471         $LCTL set_param osc.*.stats=0 &>/dev/null
12472
12473         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
12474         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
12475                 oflag=direct &>/dev/null || error "dd failed"
12476
12477         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
12478         if [ x$nrpcs != "x1" ]; then
12479                 error "found $nrpc ost_write RPCs, not 1 as expected"
12480         fi
12481
12482         # Drop the OSC cache, otherwise we will read from it
12483         cancel_lru_locks osc
12484
12485         # clear the OSC stats
12486         $LCTL set_param osc.*.stats=0 &>/dev/null
12487
12488         # Client reads $bulk_size.
12489         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
12490                 iflag=direct &>/dev/null || error "dd failed"
12491
12492         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
12493         if [ x$nrpcs != "x1" ]; then
12494                 error "found $nrpc ost_read RPCs, not 1 as expected"
12495         fi
12496 }
12497 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
12498
12499 test_231b() {
12500         mkdir -p $DIR/$tdir
12501         local i
12502         for i in {0..1023}; do
12503                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
12504                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
12505                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
12506         done
12507         sync
12508 }
12509 run_test 231b "must not assert on fully utilized OST request buffer"
12510
12511 test_232() {
12512         mkdir -p $DIR/$tdir
12513         #define OBD_FAIL_LDLM_OST_LVB            0x31c
12514         $LCTL set_param fail_loc=0x31c
12515
12516         # ignore dd failure
12517         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
12518
12519         $LCTL set_param fail_loc=0
12520         umount_client $MOUNT || error "umount failed"
12521         mount_client $MOUNT || error "mount failed"
12522 }
12523 run_test 232 "failed lock should not block umount"
12524
12525 test_233a() {
12526         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
12527         { skip "Need MDS version at least 2.3.64"; return; }
12528
12529         local fid=$($LFS path2fid $MOUNT)
12530         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12531                 error "cannot access $MOUNT using its FID '$fid'"
12532 }
12533 run_test 233a "checking that OBF of the FS root succeeds"
12534
12535 test_233b() {
12536         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
12537         { skip "Need MDS version at least 2.5.90"; return; }
12538
12539         local fid=$($LFS path2fid $MOUNT/.lustre)
12540         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12541                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
12542
12543         fid=$($LFS path2fid $MOUNT/.lustre/fid)
12544         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
12545                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
12546 }
12547 run_test 233b "checking that OBF of the FS .lustre succeeds"
12548
12549 test_234() {
12550         local p="$TMP/sanityN-$TESTNAME.parameters"
12551         save_lustre_params client "llite.*.xattr_cache" > $p
12552         lctl set_param llite.*.xattr_cache 1 ||
12553                 { skip "xattr cache is not supported"; return 0; }
12554
12555         mkdir -p $DIR/$tdir || error "mkdir failed"
12556         touch $DIR/$tdir/$tfile || error "touch failed"
12557         # OBD_FAIL_LLITE_XATTR_ENOMEM
12558         $LCTL set_param fail_loc=0x1405
12559         if [ ! -f /etc/SuSE-release ]; then
12560                 # attr pre-2.4.44-7 had a bug with rc
12561                 # LU-3703 - SLES clients have older attr
12562                 getfattr -n user.attr $DIR/$tdir/$tfile &&
12563                         error "getfattr should have failed with ENOMEM"
12564         fi
12565         $LCTL set_param fail_loc=0x0
12566         rm -rf $DIR/$tdir
12567
12568         restore_lustre_params < $p
12569         rm -f $p
12570 }
12571 run_test 234 "xattr cache should not crash on ENOMEM"
12572
12573 test_235() {
12574         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
12575                 skip "Need MDS version at least 2.4.52" && return
12576         flock_deadlock $DIR/$tfile
12577         local RC=$?
12578         case $RC in
12579                 0)
12580                 ;;
12581                 124) error "process hangs on a deadlock"
12582                 ;;
12583                 *) error "error executing flock_deadlock $DIR/$tfile"
12584                 ;;
12585         esac
12586 }
12587 run_test 235 "LU-1715: flock deadlock detection does not work properly"
12588
12589 #LU-2935
12590 test_236() {
12591         check_swap_layouts_support && return 0
12592         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
12593
12594         local ref1=/etc/passwd
12595         local ref2=/etc/group
12596         local file1=$DIR/$tdir/f1
12597         local file2=$DIR/$tdir/f2
12598
12599         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
12600         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
12601         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
12602         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
12603         local fd=$(free_fd)
12604         local cmd="exec $fd<>$file2"
12605         eval $cmd
12606         rm $file2
12607         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
12608                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
12609         cmd="exec $fd>&-"
12610         eval $cmd
12611         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
12612
12613         #cleanup
12614         rm -rf $DIR/$tdir
12615 }
12616 run_test 236 "Layout swap on open unlinked file"
12617
12618 # test to verify file handle related system calls
12619 # (name_to_handle_at/open_by_handle_at)
12620 # The new system calls are supported in glibc >= 2.14.
12621
12622 test_237() {
12623         echo "Test file_handle syscalls" > $DIR/$tfile
12624         check_fhandle_syscalls $DIR/$tfile ||
12625                 error "check_fhandle_syscalls failed"
12626 }
12627 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
12628
12629 # LU-4659 linkea consistency
12630 test_238() {
12631         touch $DIR/$tfile
12632         ln $DIR/$tfile $DIR/$tfile.lnk
12633         touch $DIR/$tfile.new
12634         mv $DIR/$tfile.new $DIR/$tfile
12635         local fid1=$(lfs path2fid $DIR/$tfile)
12636         local fid2=$(lfs path2fid $DIR/$tfile.lnk)
12637         local path1=$(lfs fid2path $FSNAME $fid1)
12638         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
12639         local path2=$(lfs fid2path $FSNAME $fid2)
12640         [ $tfile.lnk == $path2 ] ||
12641                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
12642         rm -f $DIR/$tfile*
12643 }
12644 run_test 238 "Verify linkea consistency"
12645
12646 cleanup_test_300() {
12647         trap 0
12648         umask $SAVE_UMASK
12649 }
12650 test_striped_dir() {
12651         local mdt_index=$1
12652         local stripe_count
12653         local stripe_index
12654
12655         mkdir -p $DIR/$tdir
12656
12657         SAVE_UMASK=$(umask)
12658         trap cleanup_test_300 RETURN EXIT
12659
12660         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
12661                                                 $DIR/$tdir/striped_dir ||
12662                 error "set striped dir error"
12663
12664         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
12665         [ "$mode" = "755" ] || error "expect 755 got $mode"
12666
12667         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
12668         if [ "$stripe_count" != "2" ]; then
12669                 error "stripe_count is $stripe_count, expect 2"
12670         fi
12671
12672         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
12673         if [ "$stripe_index" != "$mdt_index" ]; then
12674                 error "stripe_index is $stripe_index, expect $mdt_index"
12675         fi
12676
12677         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12678                 error "nlink error after create striped dir"
12679
12680         mkdir $DIR/$tdir/striped_dir/a
12681         mkdir $DIR/$tdir/striped_dir/b
12682
12683         stat $DIR/$tdir/striped_dir/a ||
12684                 error "create dir under striped dir failed"
12685         stat $DIR/$tdir/striped_dir/b ||
12686                 error "create dir under striped dir failed"
12687
12688         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
12689                 error "nlink error after mkdir"
12690
12691         rmdir $DIR/$tdir/striped_dir/a
12692         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
12693                 error "nlink error after rmdir"
12694
12695         rmdir $DIR/$tdir/striped_dir/b
12696         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
12697                 error "nlink error after rmdir"
12698
12699         rmdir $DIR/$tdir/striped_dir ||
12700                 error "rmdir striped dir error"
12701
12702         cleanup_test_300
12703
12704         true
12705 }
12706
12707 test_300a() {
12708         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12709         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12710
12711         test_striped_dir 0 || error "failed on striped dir on MDT0"
12712         test_striped_dir 1 || error "failed on striped dir on MDT0"
12713 }
12714 run_test 300a "basic striped dir sanity test"
12715
12716 test_300b() {
12717         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12718         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12719         local i
12720         local mtime1
12721         local mtime2
12722         local mtime3
12723
12724         test_mkdir $DIR/$tdir || error "mkdir fail"
12725         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12726                 error "set striped dir error"
12727         for ((i=0; i<10; i++)); do
12728                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
12729                 sleep 1
12730                 touch $DIR/$tdir/striped_dir/file_$i ||
12731                                         error "touch error $i"
12732                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
12733                 [ $mtime1 -eq $mtime2 ] &&
12734                         error "mtime not change after create"
12735                 sleep 1
12736                 rm -f $DIR/$tdir/striped_dir/file_$i ||
12737                                         error "unlink error $i"
12738                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
12739                 [ $mtime2 -eq $mtime3 ] &&
12740                         error "mtime did not change after unlink"
12741         done
12742         true
12743 }
12744 run_test 300b "check ctime/mtime for striped dir"
12745
12746 test_300c() {
12747         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12748         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12749         local file_count
12750
12751         mkdir -p $DIR/$tdir
12752         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
12753                 error "set striped dir error"
12754
12755         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
12756                 error "chown striped dir failed"
12757
12758         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
12759                 error "create 5k files failed"
12760
12761         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
12762
12763         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
12764
12765         rm -rf $DIR/$tdir
12766 }
12767 run_test 300c "chown && check ls under striped directory"
12768
12769 test_300d() {
12770         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12771         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12772         local stripe_count
12773         local file
12774
12775         mkdir -p $DIR/$tdir
12776         $SETSTRIPE -c 2 $DIR/$tdir
12777
12778         #local striped directory
12779         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12780                 error "set striped dir error"
12781         createmany -o $DIR/$tdir/striped_dir/f 10 ||
12782                 error "create 10 files failed"
12783
12784         #remote striped directory
12785         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
12786                 error "set striped dir error"
12787         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
12788                 error "create 10 files failed"
12789
12790         for file in $(find $DIR/$tdir); do
12791                 stripe_count=$($GETSTRIPE -c $file)
12792                 [ $stripe_count -eq 2 ] ||
12793                         error "wrong stripe $stripe_count for $file"
12794         done
12795
12796         rm -rf $DIR/$tdir
12797 }
12798 run_test 300d "check default stripe under striped directory"
12799
12800 test_300e() {
12801         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12802         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12803         local stripe_count
12804         local file
12805
12806         mkdir -p $DIR/$tdir
12807
12808         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12809                 error "set striped dir error"
12810
12811         touch $DIR/$tdir/striped_dir/a
12812         touch $DIR/$tdir/striped_dir/b
12813         touch $DIR/$tdir/striped_dir/c
12814
12815         mkdir $DIR/$tdir/striped_dir/dir_a
12816         mkdir $DIR/$tdir/striped_dir/dir_b
12817         mkdir $DIR/$tdir/striped_dir/dir_c
12818
12819         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
12820                 error "set striped dir under striped dir error"
12821
12822         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
12823                 error "set striped dir under striped dir error"
12824
12825         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
12826                 error "set striped dir under striped dir error"
12827
12828         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/b &&
12829                 error "rename file under striped dir should fail"
12830
12831         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b &&
12832                 error "rename dir under striped dir should fail"
12833
12834         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b &&
12835                 error "rename dir under different stripes should fail"
12836
12837         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
12838                 error "rename file under striped dir should succeed"
12839
12840         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_c ||
12841                 error "rename dir under striped dir should succeed"
12842
12843         rm -rf $DIR/$tdir
12844 }
12845 run_test 300e "check rename under striped directory"
12846
12847 test_300f() {
12848         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12849         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12850         local stripe_count
12851         local file
12852
12853         rm -rf $DIR/$tdir
12854         mkdir -p $DIR/$tdir
12855
12856         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
12857                 error "set striped dir error"
12858
12859         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
12860                 error "set striped dir error"
12861
12862         touch $DIR/$tdir/striped_dir/a
12863         mkdir $DIR/$tdir/striped_dir/dir_a
12864         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
12865                 error "create striped dir under striped dir fails"
12866
12867         touch $DIR/$tdir/striped_dir1/b
12868         mkdir $DIR/$tdir/striped_dir1/dir_b
12869         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
12870                 error "create striped dir under striped dir fails"
12871
12872         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/b &&
12873                 error "rename file under different striped dir should fail"
12874
12875         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b &&
12876                 error "rename dir under different striped dir should fail"
12877
12878         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b &&
12879                 error "rename striped dir under diff striped dir should fail"
12880
12881         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
12882                 error "rename file under diff striped dirs fails"
12883
12884         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_a ||
12885                 error "rename dir under diff striped dirs fails"
12886
12887         rm -rf $DIR/$tdir
12888 }
12889 run_test 300f "check rename cross striped directory"
12890
12891 test_300g() {
12892         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12893         local stripe_count
12894         local dir
12895
12896         mkdir $DIR/$tdir
12897         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
12898                                         $DIR/$tdir/striped_dir ||
12899                 error "set striped dir error"
12900
12901         $LFS setdirstripe -D -c $MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
12902                 error "set default stripe on striped dir error"
12903
12904         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/striped_dir)
12905         [ $stripe_count -eq $MDSCOUNT ] ||
12906                 error "default stripe wrong expect $MDSCOUNT get $stripe_count"
12907
12908         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12909
12910         for dir in $(find $DIR/$tdir/striped_dir/*); do
12911                 stripe_count=$($LFS getdirstripe -c $dir)
12912                 [ $stripe_count -eq $MDSCOUNT ] ||
12913                         error "expect $MDSCOUNT get $stripe_count for $dir"
12914         done
12915
12916         rmdir $DIR/$tdir/striped_dir/* || error "rmdir1 failed"
12917         #change default stripe count to 2
12918         $LFS setdirstripe -D -c 2 -t all_char $DIR/$tdir/striped_dir ||
12919                 error "set default stripe on striped dir error"
12920
12921         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12922
12923         rmdir $DIR/$tdir/striped_dir/* || error "rmdir2 failed"
12924
12925         #change default stripe count to 1
12926         $LFS setdirstripe -D -c 1 -t all_char $DIR/$tdir/striped_dir ||
12927                 error "set default stripe on striped dir error"
12928
12929         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
12930         for dir in $(find $DIR/$tdir/striped_dir/*); do
12931                 stripe_count=$($LFS getdirstripe -c $dir)
12932                 [ $stripe_count -eq 1 ] ||
12933                         error "expect 1 get $stripe_count for $dir"
12934         done
12935         rmdir $DIR/$tdir/striped_dir/* || error "rmdir3 failed"
12936 }
12937 run_test 300g "check default striped directory for striped directory"
12938
12939 test_400a() { # LU-1606, was conf-sanity test_74
12940         local extra_flags=''
12941         local out=$TMP/$tfile
12942         local prefix=/usr/include/lustre
12943         local prog
12944
12945         if ! which $CC > /dev/null 2>&1; then
12946                 skip_env "$CC is not installed"
12947                 return 0
12948         fi
12949
12950         if ! [[ -d $prefix ]]; then
12951                 # Assume we're running in tree and fixup the include path.
12952                 extra_flags+=" -I$LUSTRE/../libcfs/include"
12953                 extra_flags+=" -I$LUSTRE/include"
12954                 extra_flags+=" -L$LUSTRE/utils"
12955         fi
12956
12957         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
12958                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
12959                         error "client api broken"
12960         done
12961 }
12962 run_test 400a "Lustre client api program can compile and link"
12963
12964 test_400b() { # LU-1606, LU-5011
12965         local header
12966         local out=$TMP/$tfile
12967         local prefix=/usr/include/lustre
12968
12969         # We use a hard coded prefix so that this test will not fail
12970         # when run in tree. There are headers in lustre/include/lustre/
12971         # that are not packaged (like lustre_idl.h) and have more
12972         # complicated include dependencies (like config.h and lnet/types.h).
12973         # Since this test about correct packaging we just skip them when
12974         # they don't exist (see below) rather than try to fixup cppflags.
12975
12976         if ! which $CC > /dev/null 2>&1; then
12977                 skip_env "$CC is not installed"
12978                 return 0
12979         fi
12980
12981         for header in $prefix/*.h; do
12982                 if ! [[ -f "$header" ]]; then
12983                         continue
12984                 fi
12985
12986                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
12987                         continue # liblustreapi.h is deprecated.
12988                 fi
12989
12990                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
12991                         error "cannot compile '$header'"
12992         done
12993 }
12994 run_test 400b "packaged headers can be compiled"
12995
12996 #
12997 # tests that do cleanup/setup should be run at the end
12998 #
12999
13000 test_900() {
13001         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13002         local ls
13003         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
13004         $LCTL set_param fail_loc=0x903
13005         # cancel_lru_locks mgc - does not work due to lctl set_param syntax
13006         for ls in /proc/fs/lustre/ldlm/namespaces/MGC*/lru_size; do
13007                 echo "clear" > $ls
13008         done
13009         FAIL_ON_ERROR=true cleanup
13010         FAIL_ON_ERROR=true setup
13011 }
13012 run_test 900 "umount should not race with any mgc requeue thread"
13013
13014 complete $SECONDS
13015 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
13016 check_and_cleanup_lustre
13017 if [ "$I_MOUNTED" != "yes" ]; then
13018         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
13019 fi
13020 exit_status