Whamcloud - gitweb
LU-7577 mdt: root inode checking for migration
[fs/lustre-release.git] / lustre / tests / sanity.sh
1 #!/bin/bash
2 # -*- tab-width: 8; indent-tabs-mode: t; -*-
3 #
4 # Run select tests by setting ONLY, or as arguments to the script.
5 # Skip specific tests by setting EXCEPT.
6 #
7 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11 # bug number for skipped test: 13297 2108 9789 3637 9789 3561 12622 5188
12 ALWAYS_EXCEPT="                42a  42b  42c  42d  45   51d   68b   $SANITY_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 # with LOD/OSP landing
16 # bug number for skipped tests: LU-2036
17 ALWAYS_EXCEPT="                 76     $ALWAYS_EXCEPT"
18
19 is_sles11()                                             # LU-4341
20 {
21         if [ -r /etc/SuSE-release ]
22         then
23                 local vers=$(grep VERSION /etc/SuSE-release | awk '{print $3}')
24                 local patchlev=$(grep PATCHLEVEL /etc/SuSE-release |
25                         awk '{ print $3 }')
26                 if [ $vers -eq 11 ] && [ $patchlev -ge 3 ]; then
27                         return 0
28                 fi
29         fi
30         return 1
31 }
32
33 if is_sles11; then                                      # LU-4341
34         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 170"
35 fi
36
37 SRCDIR=$(cd $(dirname $0); echo $PWD)
38 export PATH=$PATH:/sbin
39
40 TMP=${TMP:-/tmp}
41
42 CC=${CC:-cc}
43 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
44 CREATETEST=${CREATETEST:-createtest}
45 LFS=${LFS:-lfs}
46 LFIND=${LFIND:-"$LFS find"}
47 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
48 LCTL=${LCTL:-lctl}
49 OPENFILE=${OPENFILE:-openfile}
50 OPENUNLINK=${OPENUNLINK:-openunlink}
51 export MULTIOP=${MULTIOP:-multiop}
52 READS=${READS:-"reads"}
53 MUNLINK=${MUNLINK:-munlink}
54 SOCKETSERVER=${SOCKETSERVER:-socketserver}
55 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
56 MEMHOG=${MEMHOG:-memhog}
57 DIRECTIO=${DIRECTIO:-directio}
58 ACCEPTOR_PORT=${ACCEPTOR_PORT:-988}
59 STRIPES_PER_OBJ=-1
60 CHECK_GRANT=${CHECK_GRANT:-"yes"}
61 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
62 export PARALLEL=${PARALLEL:-"no"}
63
64 export NAME=${NAME:-local}
65
66 SAVE_PWD=$PWD
67
68 CLEANUP=${CLEANUP:-:}
69 SETUP=${SETUP:-:}
70 TRACE=${TRACE:-""}
71 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
72 LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
73 . $LUSTRE/tests/test-framework.sh
74 init_test_env $@
75 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
76 init_logging
77
78 [ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 24D 27m 64b 68 71 77f 78 115 124b 300o"
79
80 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
81         # bug number for skipped test: LU-4536 LU-1957 LU-2805
82         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  65ic    180     184c"
83         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b 51ba"
84 fi
85
86 FAIL_ON_ERROR=false
87
88 cleanup() {
89         echo -n "cln.."
90         pgrep ll_sa > /dev/null && { echo "There are ll_sa thread not exit!"; exit 20; }
91         cleanupall ${FORCE} $* || { echo "FAILed to clean up"; exit 20; }
92 }
93 setup() {
94         echo -n "mnt.."
95         load_modules
96         setupall || exit 10
97         echo "done"
98 }
99
100 check_swap_layouts_support()
101 {
102         $LCTL get_param -n llite.*.sbi_flags | grep -q layout ||
103                 { skip "Does not support layout lock."; return 0; }
104         return 1
105 }
106
107 check_and_setup_lustre
108
109 DIR=${DIR:-$MOUNT}
110 assert_DIR
111
112 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
113         awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
114 LOVNAME=$($LCTL get_param -n llite.*.lov.common_name | tail -n 1)
115 OSTCOUNT=$($LCTL get_param -n lov.$LOVNAME.numobd)
116 STRIPECOUNT=$($LCTL get_param -n lov.$LOVNAME.stripecount)
117 STRIPESIZE=$($LCTL get_param -n lov.$LOVNAME.stripesize)
118 ORIGFREE=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
119 MAXFREE=${MAXFREE:-$((200000 * $OSTCOUNT))}
120
121 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
122 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
123 rm -rf $DIR/[Rdfs][0-9]*
124
125 # $RUNAS_ID may get set incorrectly somewhere else
126 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] && error "\$RUNAS_ID set to 0, but \$UID is also 0!"
127
128 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
129
130 build_test_filter
131
132 if [ "${ONLY}" = "MOUNT" ] ; then
133         echo "Lustre is up, please go on"
134         exit
135 fi
136
137 echo "preparing for tests involving mounts"
138 EXT2_DEV=${EXT2_DEV:-$TMP/SANITY.LOOP}
139 touch $EXT2_DEV
140 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
141 echo # add a newline after mke2fs.
142
143 umask 077
144
145 OLDDEBUG=$(lctl get_param -n debug 2> /dev/null)
146 lctl set_param debug=-1 2> /dev/null || true
147 test_0a() {
148         touch $DIR/$tfile
149         $CHECKSTAT -t file $DIR/$tfile || error "$tfile is not a file"
150         rm $DIR/$tfile
151         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
152 }
153 run_test 0a "touch; rm ====================="
154
155 test_0b() {
156         chmod 0755 $DIR || error "chmod 0755 $DIR failed"
157         $CHECKSTAT -p 0755 $DIR || error "$DIR permission is not 0755"
158 }
159 run_test 0b "chmod 0755 $DIR ============================="
160
161 test_0c() {
162         $LCTL get_param mdc.*.import | grep "state: FULL" ||
163                 error "import not FULL"
164         $LCTL get_param mdc.*.import | grep "target: $FSNAME-MDT" ||
165                 error "bad target"
166 }
167 run_test 0c "check import proc ============================="
168
169 test_1() {
170         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
171         test_mkdir -p $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
172         test_mkdir $DIR/$tdir/d2 && error "we expect EEXIST, but not returned"
173         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a dir"
174         rmdir $DIR/$tdir/d2
175         rmdir $DIR/$tdir
176         $CHECKSTAT -a $DIR/$tdir || error "$tdir was not removed"
177 }
178 run_test 1 "mkdir; remkdir; rmdir =============================="
179
180 test_2() {
181         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
182         touch $DIR/$tdir/$tfile || error "touch $tdir/$tfile failed"
183         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
184         rm -r $DIR/$tdir
185         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$file is not removed"
186 }
187 run_test 2 "mkdir; touch; rmdir; check file ===================="
188
189 test_3() {
190         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
191         $CHECKSTAT -t dir $DIR/$tdir || error "$tdir is not a directory"
192         touch $DIR/$tdir/$tfile
193         $CHECKSTAT -t file $DIR/$tdir/$tfile || error "$tdir/$tfile not a file"
194         rm -r $DIR/$tdir
195         $CHECKSTAT -a $DIR/$tdir || error "$tdir is not removed"
196 }
197 run_test 3 "mkdir; touch; rmdir; check dir ====================="
198
199 # LU-4471 - failed rmdir on remote directories still removes directory on MDT0
200 test_4() {
201         local MDTIDX=1
202
203         test_mkdir $DIR/$tdir ||
204                 error "Create remote directory failed"
205
206         touch $DIR/$tdir/$tfile ||
207                 error "Create file under remote directory failed"
208
209         rmdir $DIR/$tdir &&
210                 error "Expect error removing in-use dir $DIR/$tdir"
211
212         test -d $DIR/$tdir || error "Remote directory disappeared"
213
214         rm -rf $DIR/$tdir || error "remove remote dir error"
215 }
216 run_test 4 "mkdir; touch dir/file; rmdir; checkdir (expect error)"
217
218 test_5() {
219         test_mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
220         test_mkdir $DIR/$tdir/d2 || error "mkdir $tdir/d2 failed"
221         chmod 0707 $DIR/$tdir/d2 || error "chmod 0707 $tdir/d2 failed"
222         $CHECKSTAT -t dir -p 0707 $DIR/$tdir/d2 || error "$tdir/d2 not mode 707"
223         $CHECKSTAT -t dir $DIR/$tdir/d2 || error "$tdir/d2 is not a directory"
224 }
225 run_test 5 "mkdir .../d5 .../d5/d2; chmod .../d5/d2 ============"
226
227 test_6a() {
228         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
229         chmod 0666 $DIR/$tfile || error "chmod 0666 $tfile failed"
230         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
231                 error "$tfile does not have perm 0666 or UID $UID"
232         $RUNAS chmod 0444 $DIR/$tfile && error "chmod $tfile worked on UID $UID"
233         $CHECKSTAT -t file -p 0666 -u \#$UID $DIR/$tfile ||
234                 error "$tfile should be 0666 and owned by UID $UID"
235 }
236 run_test 6a "touch f6a; chmod f6a; $RUNAS chmod f6a (should return error) =="
237
238 test_6c() {
239         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
240         touch $DIR/$tfile
241         chown $RUNAS_ID $DIR/$tfile || error "chown $RUNAS_ID $file failed"
242         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
243                 error "$tfile should be owned by UID $RUNAS_ID"
244         $RUNAS chown $UID $DIR/$tfile && error "chown $UID $file succeeded"
245         $CHECKSTAT -t file -u \#$RUNAS_ID $DIR/$tfile ||
246                 error "$tfile should be owned by UID $RUNAS_ID"
247 }
248 run_test 6c "touch f6c; chown f6c; $RUNAS chown f6c (should return error) =="
249
250 test_6e() {
251         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
252         touch $DIR/$tfile
253         chgrp $RUNAS_ID $DIR/$tfile || error "chgrp $RUNAS_ID $file failed"
254         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
255                 error "$tfile should be owned by GID $UID"
256         $RUNAS chgrp $UID $DIR/$tfile && error "chgrp $UID $file succeeded"
257         $CHECKSTAT -t file -u \#$UID -g \#$RUNAS_ID $DIR/$tfile ||
258                 error "$tfile should be owned by UID $UID and GID $RUNAS_ID"
259 }
260 run_test 6e "touch f6e; chgrp f6e; $RUNAS chgrp f6e (should return error) =="
261
262 test_6g() {
263         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
264         test_mkdir $DIR/$tdir || error "mkdir $tfile failed"
265         chmod 777 $DIR/$tdir || error "chmod 0777 $tdir failed"
266         $RUNAS mkdir $DIR/$tdir/d || error "mkdir $tdir/d failed"
267         chmod g+s $DIR/$tdir/d || error "chmod g+s $tdir/d failed"
268         test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
269         $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
270                 error "$tdir/d/subdir should be GID $RUNAS_GID"
271 }
272 run_test 6g "Is new dir in sgid dir inheriting group?"
273
274 test_6h() { # bug 7331
275         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID" && return
276         touch $DIR/$tfile || error "touch failed"
277         chown $RUNAS_ID:$RUNAS_GID $DIR/$tfile || error "initial chown failed"
278         $RUNAS -G$RUNAS_GID chown $RUNAS_ID:0 $DIR/$tfile &&
279                 error "chown $RUNAS_ID:0 $tfile worked as GID $RUNAS_GID"
280         $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_GID $DIR/$tfile ||
281                 error "$tdir/$tfile should be UID $RUNAS_UID GID $RUNAS_GID"
282 }
283 run_test 6h "$RUNAS chown RUNAS_ID.0 .../f6h (should return error)"
284
285 test_7a() {
286         test_mkdir $DIR/$tdir
287         $MCREATE $DIR/$tdir/$tfile
288         chmod 0666 $DIR/$tdir/$tfile
289         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
290                 error "$tdir/$tfile should be mode 0666"
291 }
292 run_test 7a "mkdir .../d7; mcreate .../d7/f; chmod .../d7/f ===="
293
294 test_7b() {
295         if [ ! -d $DIR/$tdir ]; then
296                 test_mkdir $DIR/$tdir
297         fi
298         $MCREATE $DIR/$tdir/$tfile
299         echo -n foo > $DIR/$tdir/$tfile
300         [ "$(cat $DIR/$tdir/$tfile)" = "foo" ] || error "$tdir/$tfile not 'foo'"
301         $CHECKSTAT -t file -s 3 $DIR/$tdir/$tfile || error "$tfile size not 3"
302 }
303 run_test 7b "mkdir .../d7; mcreate d7/f2; echo foo > d7/f2 ====="
304
305 test_8() {
306         test_mkdir $DIR/$tdir
307         touch $DIR/$tdir/$tfile
308         chmod 0666 $DIR/$tdir/$tfile
309         $CHECKSTAT -t file -p 0666 $DIR/$tdir/$tfile ||
310                 error "$tfile mode not 0666"
311 }
312 run_test 8 "mkdir .../d8; touch .../d8/f; chmod .../d8/f ======="
313
314 test_9() {
315         test_mkdir $DIR/$tdir
316         test_mkdir $DIR/$tdir/d2
317         test_mkdir $DIR/$tdir/d2/d3
318         $CHECKSTAT -t dir $DIR/$tdir/d2/d3 || error "$tdir/d2/d3 not a dir"
319 }
320 run_test 9 "mkdir .../d9 .../d9/d2 .../d9/d2/d3 ================"
321
322 test_10() {
323         test_mkdir $DIR/$tdir
324         test_mkdir $DIR/$tdir/d2
325         touch $DIR/$tdir/d2/$tfile
326         $CHECKSTAT -t file $DIR/$tdir/d2/$tfile ||
327                 error "$tdir/d2/$tfile not a file"
328 }
329 run_test 10 "mkdir .../d10 .../d10/d2; touch .../d10/d2/f ======"
330
331 test_11() {
332         test_mkdir $DIR/$tdir
333         test_mkdir $DIR/$tdir/d2
334         chmod 0666 $DIR/$tdir/d2
335         chmod 0705 $DIR/$tdir/d2
336         $CHECKSTAT -t dir -p 0705 $DIR/$tdir/d2 ||
337                 error "$tdir/d2 mode not 0705"
338 }
339 run_test 11 "mkdir .../d11 d11/d2; chmod .../d11/d2 ============"
340
341 test_12() {
342         test_mkdir $DIR/$tdir
343         touch $DIR/$tdir/$tfile
344         chmod 0666 $DIR/$tdir/$tfile
345         chmod 0654 $DIR/$tdir/$tfile
346         $CHECKSTAT -t file -p 0654 $DIR/$tdir/$tfile ||
347                 error "$tdir/d2 mode not 0654"
348 }
349 run_test 12 "touch .../d12/f; chmod .../d12/f .../d12/f ========"
350
351 test_13() {
352         test_mkdir $DIR/$tdir
353         dd if=/dev/zero of=$DIR/$tdir/$tfile count=10
354         >  $DIR/$tdir/$tfile
355         $CHECKSTAT -t file -s 0 $DIR/$tdir/$tfile ||
356                 error "$tdir/$tfile size not 0 after truncate"
357 }
358 run_test 13 "creat .../d13/f; dd .../d13/f; > .../d13/f ========"
359
360 test_14() {
361         test_mkdir $DIR/$tdir
362         touch $DIR/$tdir/$tfile
363         rm $DIR/$tdir/$tfile
364         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
365 }
366 run_test 14 "touch .../d14/f; rm .../d14/f; rm .../d14/f ======="
367
368 test_15() {
369         test_mkdir $DIR/$tdir
370         touch $DIR/$tdir/$tfile
371         mv $DIR/$tdir/$tfile $DIR/$tdir/${tfile}_2
372         $CHECKSTAT -t file $DIR/$tdir/${tfile}_2 ||
373                 error "$tdir/${tfile_2} not a file after rename"
374         rm $DIR/$tdir/${tfile}_2 || error "unlink failed after rename"
375 }
376 run_test 15 "touch .../d15/f; mv .../d15/f .../d15/f2 =========="
377
378 test_16() {
379         test_mkdir $DIR/$tdir
380         touch $DIR/$tdir/$tfile
381         rm -rf $DIR/$tdir/$tfile
382         $CHECKSTAT -a $DIR/$tdir/$tfile || error "$tdir/$tfile not removed"
383 }
384 run_test 16 "touch .../d16/f; rm -rf .../d16/f ================="
385
386 test_17a() {
387         test_mkdir -p $DIR/$tdir
388         touch $DIR/$tdir/$tfile
389         ln -s $DIR/$tdir/$tfile $DIR/$tdir/l-exist
390         ls -l $DIR/$tdir
391         $CHECKSTAT -l $DIR/$tdir/$tfile $DIR/$tdir/l-exist ||
392                 error "$tdir/l-exist not a symlink"
393         $CHECKSTAT -f -t f $DIR/$tdir/l-exist ||
394                 error "$tdir/l-exist not referencing a file"
395         rm -f $DIR/$tdir/l-exist
396         $CHECKSTAT -a $DIR/$tdir/l-exist || error "$tdir/l-exist not removed"
397 }
398 run_test 17a "symlinks: create, remove (real) =================="
399
400 test_17b() {
401         test_mkdir -p $DIR/$tdir
402         ln -s no-such-file $DIR/$tdir/l-dangle
403         ls -l $DIR/$tdir
404         $CHECKSTAT -l no-such-file $DIR/$tdir/l-dangle ||
405                 error "$tdir/l-dangle not referencing no-such-file"
406         $CHECKSTAT -fa $DIR/$tdir/l-dangle ||
407                 error "$tdir/l-dangle not referencing non-existent file"
408         rm -f $DIR/$tdir/l-dangle
409         $CHECKSTAT -a $DIR/$tdir/l-dangle || error "$tdir/l-dangle not removed"
410 }
411 run_test 17b "symlinks: create, remove (dangling) =============="
412
413 test_17c() { # bug 3440 - don't save failed open RPC for replay
414         test_mkdir -p $DIR/$tdir
415         ln -s foo $DIR/$tdir/$tfile
416         cat $DIR/$tdir/$tfile && error "opened non-existent symlink" || true
417 }
418 run_test 17c "symlinks: open dangling (should return error) ===="
419
420 test_17d() {
421         test_mkdir -p $DIR/$tdir
422         ln -s foo $DIR/$tdir/$tfile
423         touch $DIR/$tdir/$tfile || error "creating to new symlink"
424 }
425 run_test 17d "symlinks: create dangling ========================"
426
427 test_17e() {
428         test_mkdir -p $DIR/$tdir
429         local foo=$DIR/$tdir/$tfile
430         ln -s $foo $foo || error "create symlink failed"
431         ls -l $foo || error "ls -l failed"
432         ls $foo && error "ls not failed" || true
433 }
434 run_test 17e "symlinks: create recursive symlink (should return error) ===="
435
436 test_17f() {
437         test_mkdir -p $DIR/$tdir
438         ln -s 1234567890/2234567890/3234567890/4234567890 $DIR/$tdir/111
439         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890 $DIR/$tdir/222
440         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890 $DIR/$tdir/333
441         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890 $DIR/$tdir/444
442         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890 $DIR/$tdir/555
443         ln -s 1234567890/2234567890/3234567890/4234567890/5234567890/6234567890/7234567890/8234567890/9234567890/a234567890/b234567890/c234567890/d234567890/f234567890/aaaaaaaaaa/bbbbbbbbbb/cccccccccc/dddddddddd/eeeeeeeeee/ffffffffff/ $DIR/$tdir/666
444         ls -l  $DIR/$tdir
445 }
446 run_test 17f "symlinks: long and very long symlink name ========================"
447
448 # str_repeat(S, N) generate a string that is string S repeated N times
449 str_repeat() {
450         local s=$1
451         local n=$2
452         local ret=''
453         while [ $((n -= 1)) -ge 0 ]; do
454                 ret=$ret$s
455         done
456         echo $ret
457 }
458
459 # Long symlinks and LU-2241
460 test_17g() {
461         test_mkdir -p $DIR/$tdir
462         local TESTS="59 60 61 4094 4095"
463
464         # Fix for inode size boundary in 2.1.4
465         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.4) ] &&
466                 TESTS="4094 4095"
467
468         # Patch not applied to 2.2 or 2.3 branches
469         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
470         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.3.55) ] &&
471                 TESTS="4094 4095"
472
473         # skip long symlink name for rhel6.5.
474         # rhel6.5 has a limit (PATH_MAX - sizeof(struct filename))
475         grep -q '6.5' /etc/redhat-release &>/dev/null &&
476                 TESTS="59 60 61 4062 4063"
477
478         for i in $TESTS; do
479                 local SYMNAME=$(str_repeat 'x' $i)
480                 ln -s $SYMNAME $DIR/$tdir/f$i || error "failed $i-char symlink"
481                 readlink $DIR/$tdir/f$i || error "failed $i-char readlink"
482         done
483 }
484 run_test 17g "symlinks: really long symlink name and inode boundaries"
485
486 test_17h() { #bug 17378
487         remote_mds_nodsh && skip "remote MDS with nodsh" && return
488         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
489         local mdt_idx
490         test_mkdir -p $DIR/$tdir
491         if [[ $MDSCOUNT -gt 1 ]]; then
492                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
493         else
494                 mdt_idx=0
495         fi
496         $SETSTRIPE -c -1 $DIR/$tdir
497 #define OBD_FAIL_MDS_LOV_PREP_CREATE 0x141
498         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000141
499         touch $DIR/$tdir/$tfile || true
500 }
501 run_test 17h "create objects: lov_free_memmd() doesn't lbug"
502
503 test_17i() { #bug 20018
504         remote_mds_nodsh && skip "remote MDS with nodsh" && return
505         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
506         test_mkdir -c1 $DIR/$tdir
507         local foo=$DIR/$tdir/$tfile
508         local mdt_idx
509         if [[ $MDSCOUNT -gt 1 ]]; then
510                 mdt_idx=$($LFS getdirstripe -i $DIR/$tdir)
511         else
512                 mdt_idx=0
513         fi
514         ln -s $foo $foo || error "create symlink failed"
515 #define OBD_FAIL_MDS_READLINK_EPROTO     0x143
516         do_facet mds$((mdt_idx + 1)) lctl set_param fail_loc=0x80000143
517         ls -l $foo && error "error not detected"
518         return 0
519 }
520 run_test 17i "don't panic on short symlink"
521
522 test_17k() { #bug 22301
523         [[ -z "$(which rsync 2>/dev/null)" ]] &&
524                 skip "no rsync command" && return 0
525         rsync --help | grep -q xattr ||
526                 skip_env "$(rsync --version | head -n1) does not support xattrs"
527         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
528         test_mkdir -p $DIR/$tdir
529         test_mkdir -p $DIR/$tdir.new
530         touch $DIR/$tdir/$tfile
531         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
532         rsync -av -X $DIR/$tdir/ $DIR/$tdir.new ||
533                 error "rsync failed with xattrs enabled"
534 }
535 run_test 17k "symlinks: rsync with xattrs enabled ========================="
536
537 test_17l() { # LU-279
538         [[ -z "$(which getfattr 2>/dev/null)" ]] &&
539                 skip "no getfattr command" && return 0
540         test_mkdir -p $DIR/$tdir
541         touch $DIR/$tdir/$tfile
542         ln -s $DIR/$tdir/$tfile $DIR/$tdir/$tfile.lnk
543         for path in "$DIR/$tdir" "$DIR/$tdir/$tfile" "$DIR/$tdir/$tfile.lnk"; do
544                 # -h to not follow symlinks. -m '' to list all the xattrs.
545                 # grep to remove first line: '# file: $path'.
546                 for xattr in `getfattr -hm '' $path 2>/dev/null | grep -v '^#'`;
547                 do
548                         lgetxattr_size_check $path $xattr ||
549                                 error "lgetxattr_size_check $path $xattr failed"
550                 done
551         done
552 }
553 run_test 17l "Ensure lgetxattr's returned xattr size is consistent ========"
554
555 # LU-1540
556 test_17m() {
557         local short_sym="0123456789"
558         local WDIR=$DIR/${tdir}m
559         local i
560
561         remote_mds_nodsh && skip "remote MDS with nodsh" && return
562         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
563         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
564                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
565
566         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
567                 skip "only for ldiskfs MDT" && return 0
568
569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
570
571         test_mkdir -p $WDIR
572         long_sym=$short_sym
573         # create a long symlink file
574         for ((i = 0; i < 4; ++i)); do
575                 long_sym=${long_sym}${long_sym}
576         done
577
578         echo "create 512 short and long symlink files under $WDIR"
579         for ((i = 0; i < 256; ++i)); do
580                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
581                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
582         done
583
584         echo "erase them"
585         rm -f $WDIR/*
586         sync
587         wait_delete_completed
588
589         echo "recreate the 512 symlink files with a shorter string"
590         for ((i = 0; i < 512; ++i)); do
591                 # rewrite the symlink file with a shorter string
592                 ln -sf ${long_sym} $WDIR/long-$i || error "long_sym failed"
593                 ln -sf ${short_sym} $WDIR/short-$i || error "short_sym failed"
594         done
595
596         local mds_index=$(($($LFS getstripe -M $WDIR) + 1))
597         local devname=$(mdsdevname $mds_index)
598
599         echo "stop and checking mds${mds_index}:"
600         # e2fsck should not return error
601         stop mds${mds_index}
602         run_e2fsck $(facet_active_host mds${mds_index}) $devname -n
603         rc=$?
604
605         start mds${mds_index} $devname $MDS_MOUNT_OPTS || error "start failed"
606         df $MOUNT > /dev/null 2>&1
607         [ $rc -eq 0 ] ||
608                 error "e2fsck detected error for short/long symlink: rc=$rc"
609 }
610 run_test 17m "run e2fsck against MDT which contains short/long symlink"
611
612 check_fs_consistency_17n() {
613         local mdt_index
614         local rc=0
615
616         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
617         # so it only check MDT1/MDT2 instead of all of MDTs.
618         for mdt_index in 1 2; do
619                 local devname=$(mdsdevname $mdt_index)
620                 # e2fsck should not return error
621                 stop mds${mdt_index}
622                 run_e2fsck $(facet_active_host mds$mdt_index) $devname -n ||
623                         rc=$((rc + $?))
624
625                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
626                         error "mount mds$mdt_index failed"
627                 df $MOUNT > /dev/null 2>&1
628         done
629         return $rc
630 }
631
632 test_17n() {
633         local i
634
635         remote_mds_nodsh && skip "remote MDS with nodsh" && return
636         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
637         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
638                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
639
640         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
641                 skip "only for ldiskfs MDT" && return 0
642
643         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
644
645         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
646
647         test_mkdir $DIR/$tdir
648         for ((i=0; i<10; i++)); do
649                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
650                         error "create remote dir error $i"
651                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
652                         error "create files under remote dir failed $i"
653         done
654
655         check_fs_consistency_17n ||
656                 error "e2fsck report error after create files under remote dir"
657
658         for ((i = 0; i < 10; i++)); do
659                 rm -rf $DIR/$tdir/remote_dir_${i} ||
660                         error "destroy remote dir error $i"
661         done
662
663         check_fs_consistency_17n ||
664                 error "e2fsck report error after unlink files under remote dir"
665
666         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
667                 skip "lustre < 2.4.50 does not support migrate mv " && return
668
669         for ((i = 0; i < 10; i++)); do
670                 mkdir -p $DIR/$tdir/remote_dir_${i}
671                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
672                         error "create files under remote dir failed $i"
673                 $LFS migrate --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
674                         error "migrate remote dir error $i"
675         done
676         check_fs_consistency_17n || error "e2fsck report error after migration"
677
678         for ((i = 0; i < 10; i++)); do
679                 rm -rf $DIR/$tdir/remote_dir_${i} ||
680                         error "destroy remote dir error $i"
681         done
682
683         check_fs_consistency_17n || error "e2fsck report error after unlink"
684 }
685 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
686
687 test_17o() {
688         remote_mds_nodsh && skip "remote MDS with nodsh" && return
689         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
690                 skip "Need MDS version at least 2.3.64" && return
691
692         local WDIR=$DIR/${tdir}o
693         local mdt_index
694         local rc=0
695
696         test_mkdir -p $WDIR
697         mdt_index=$($LFS getstripe -M $WDIR)
698         mdt_index=$((mdt_index+1))
699
700         touch $WDIR/$tfile
701
702         #fail mds will wait the failover finish then set
703         #following fail_loc to avoid interfer the recovery process.
704         fail mds${mdt_index}
705
706         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
707         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
708         ls -l $WDIR/$tfile && rc=1
709         do_facet mds${mdt_index} lctl set_param fail_loc=0
710         [[ $rc -ne 0 ]] && error "stat file should fail"
711         true
712 }
713 run_test 17o "stat file with incompat LMA feature"
714
715 test_18() {
716         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
717         ls $DIR || error "Failed to ls $DIR: $?"
718 }
719 run_test 18 "touch .../f ; ls ... =============================="
720
721 test_19a() {
722         touch $DIR/$tfile
723         ls -l $DIR
724         rm $DIR/$tfile
725         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
726 }
727 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
728
729 test_19b() {
730         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
731 }
732 run_test 19b "ls -l .../f19 (should return error) =============="
733
734 test_19c() {
735         [ $RUNAS_ID -eq $UID ] &&
736                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
737         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
738 }
739 run_test 19c "$RUNAS touch .../f19 (should return error) =="
740
741 test_19d() {
742         cat $DIR/f19 && error || true
743 }
744 run_test 19d "cat .../f19 (should return error) =============="
745
746 test_20() {
747         touch $DIR/$tfile
748         rm $DIR/$tfile
749         log "1 done"
750         touch $DIR/$tfile
751         rm $DIR/$tfile
752         log "2 done"
753         touch $DIR/$tfile
754         rm $DIR/$tfile
755         log "3 done"
756         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
757 }
758 run_test 20 "touch .../f ; ls -l ... ==========================="
759
760 test_21() {
761         test_mkdir -p $DIR/$tdir
762         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
763         ln -s dangle $DIR/$tdir/link
764         echo foo >> $DIR/$tdir/link
765         cat $DIR/$tdir/dangle
766         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
767         $CHECKSTAT -f -t file $DIR/$tdir/link ||
768                 error "$tdir/link not linked to a file"
769 }
770 run_test 21 "write to dangling link ============================"
771
772 test_22() {
773         WDIR=$DIR/$tdir
774         test_mkdir -p $DIR/$tdir
775         chown $RUNAS_ID:$RUNAS_GID $WDIR
776         (cd $WDIR || error "cd $WDIR failed";
777         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
778         $RUNAS tar xf -)
779         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
780         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
781         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
782 }
783 run_test 22 "unpack tar archive as non-root user ==============="
784
785 # was test_23
786 test_23a() {
787         test_mkdir -p $DIR/$tdir
788         local file=$DIR/$tdir/$tfile
789
790         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
791         openfile -f O_CREAT:O_EXCL $file &&
792                 error "$file recreate succeeded" || true
793 }
794 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
795
796 test_23b() { # bug 18988
797         test_mkdir -p $DIR/$tdir
798         local file=$DIR/$tdir/$tfile
799
800         rm -f $file
801         echo foo > $file || error "write filed"
802         echo bar >> $file || error "append filed"
803         $CHECKSTAT -s 8 $file || error "wrong size"
804         rm $file
805 }
806 run_test 23b "O_APPEND check =========================="
807
808 # rename sanity
809 test_24a() {
810         echo '-- same directory rename'
811         test_mkdir $DIR/$tdir
812         touch $DIR/$tdir/$tfile.1
813         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
814         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
815 }
816 run_test 24a "rename file to non-existent target"
817
818 test_24b() {
819         test_mkdir $DIR/$tdir
820         touch $DIR/$tdir/$tfile.{1,2}
821         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
822         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
823         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
824 }
825 run_test 24b "rename file to existing target"
826
827 test_24c() {
828         test_mkdir $DIR/$tdir
829         test_mkdir $DIR/$tdir/d$testnum.1
830         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
831         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
832         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
833 }
834 run_test 24c "rename directory to non-existent target"
835
836 test_24d() {
837         test_mkdir -c1 $DIR/$tdir
838         test_mkdir -c1 $DIR/$tdir/d$testnum.1
839         test_mkdir -c1 $DIR/$tdir/d$testnum.2
840         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
841         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
842         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
843 }
844 run_test 24d "rename directory to existing target"
845
846 test_24e() {
847         echo '-- cross directory renames --'
848         test_mkdir $DIR/R5a
849         test_mkdir $DIR/R5b
850         touch $DIR/R5a/f
851         mv $DIR/R5a/f $DIR/R5b/g
852         $CHECKSTAT -a $DIR/R5a/f || error
853         $CHECKSTAT -t file $DIR/R5b/g || error
854 }
855 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
856
857 test_24f() {
858         test_mkdir $DIR/R6a
859         test_mkdir $DIR/R6b
860         touch $DIR/R6a/f $DIR/R6b/g
861         mv $DIR/R6a/f $DIR/R6b/g
862         $CHECKSTAT -a $DIR/R6a/f || error
863         $CHECKSTAT -t file $DIR/R6b/g || error
864 }
865 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
866
867 test_24g() {
868         test_mkdir $DIR/R7a
869         test_mkdir $DIR/R7b
870         test_mkdir $DIR/R7a/d
871         mv $DIR/R7a/d $DIR/R7b/e
872         $CHECKSTAT -a $DIR/R7a/d || error
873         $CHECKSTAT -t dir $DIR/R7b/e || error
874 }
875 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
876
877 test_24h() {
878         test_mkdir -c1 $DIR/R8a
879         test_mkdir -c1 $DIR/R8b
880         test_mkdir -c1 $DIR/R8a/d
881         test_mkdir -c1 $DIR/R8b/e
882         mrename $DIR/R8a/d $DIR/R8b/e
883         $CHECKSTAT -a $DIR/R8a/d || error
884         $CHECKSTAT -t dir $DIR/R8b/e || error
885 }
886 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
887
888 test_24i() {
889         echo "-- rename error cases"
890         test_mkdir $DIR/R9
891         test_mkdir $DIR/R9/a
892         touch $DIR/R9/f
893         mrename $DIR/R9/f $DIR/R9/a
894         $CHECKSTAT -t file $DIR/R9/f || error
895         $CHECKSTAT -t dir  $DIR/R9/a || error
896         $CHECKSTAT -a $DIR/R9/a/f || error
897 }
898 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
899
900 test_24j() {
901         test_mkdir $DIR/R10
902         mrename $DIR/R10/f $DIR/R10/g
903         $CHECKSTAT -t dir $DIR/R10 || error
904         $CHECKSTAT -a $DIR/R10/f || error
905         $CHECKSTAT -a $DIR/R10/g || error
906 }
907 run_test 24j "source does not exist ============================"
908
909 test_24k() {
910         test_mkdir $DIR/R11a
911         test_mkdir $DIR/R11a/d
912         touch $DIR/R11a/f
913         mv $DIR/R11a/f $DIR/R11a/d
914         $CHECKSTAT -a $DIR/R11a/f || error
915         $CHECKSTAT -t file $DIR/R11a/d/f || error
916 }
917 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
918
919 # bug 2429 - rename foo foo foo creates invalid file
920 test_24l() {
921         f="$DIR/f24l"
922         $MULTIOP $f OcNs || error
923 }
924 run_test 24l "Renaming a file to itself ========================"
925
926 test_24m() {
927         f="$DIR/f24m"
928         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
929         # on ext3 this does not remove either the source or target files
930         # though the "expected" operation would be to remove the source
931         $CHECKSTAT -t file ${f} || error "${f} missing"
932         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
933 }
934 run_test 24m "Renaming a file to a hard link to itself ========="
935
936 test_24n() {
937     f="$DIR/f24n"
938     # this stats the old file after it was renamed, so it should fail
939     touch ${f}
940     $CHECKSTAT ${f}
941     mv ${f} ${f}.rename
942     $CHECKSTAT ${f}.rename
943     $CHECKSTAT -a ${f}
944 }
945 run_test 24n "Statting the old file after renaming (Posix rename 2)"
946
947 test_24o() {
948         test_mkdir -p $DIR/d24o
949         rename_many -s random -v -n 10 $DIR/d24o
950 }
951 run_test 24o "rename of files during htree split ==============="
952
953 test_24p() {
954         test_mkdir $DIR/R12a
955         test_mkdir $DIR/R12b
956         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
957         mrename $DIR/R12a $DIR/R12b
958         $CHECKSTAT -a $DIR/R12a || error
959         $CHECKSTAT -t dir $DIR/R12b || error
960         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
961         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
962 }
963 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
964
965 cleanup_multiop_pause() {
966         trap 0
967         kill -USR1 $MULTIPID
968 }
969
970 test_24q() {
971         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
972         test_mkdir $DIR/R13a
973         test_mkdir $DIR/R13b
974         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
975         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
976         MULTIPID=$!
977
978         trap cleanup_multiop_pause EXIT
979         mrename $DIR/R13a $DIR/R13b
980         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
981         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
982         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
983         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
984         cleanup_multiop_pause
985         wait $MULTIPID || error "multiop close failed"
986 }
987 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
988
989 test_24r() { #bug 3789
990         test_mkdir $DIR/R14a
991         test_mkdir $DIR/R14a/b
992         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
993         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
994         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
995 }
996 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
997
998 test_24s() {
999         test_mkdir $DIR/R15a
1000         test_mkdir $DIR/R15a/b
1001         test_mkdir $DIR/R15a/b/c
1002         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1003         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1004         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1005 }
1006 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1007 test_24t() {
1008         test_mkdir $DIR/R16a
1009         test_mkdir $DIR/R16a/b
1010         test_mkdir $DIR/R16a/b/c
1011         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1012         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1013         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1014 }
1015 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1016
1017 test_24u() { # bug12192
1018         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1019         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1020 }
1021 run_test 24u "create stripe file"
1022
1023 page_size() {
1024         getconf PAGE_SIZE
1025 }
1026
1027 simple_cleanup_common() {
1028         trap 0
1029         rm -rf $DIR/$tdir
1030         wait_delete_completed
1031 }
1032
1033 max_pages_per_rpc() {
1034         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1035 }
1036
1037 test_24v() {
1038         local NRFILES=100000
1039         local FREE_INODES=$(mdt_free_inodes 0)
1040         [[ $FREE_INODES -lt $NRFILES ]] &&
1041                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1042                 return
1043
1044         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1045         trap simple_cleanup_common EXIT
1046
1047         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1048         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1049
1050         test_mkdir -p $DIR/$tdir
1051         createmany -m $DIR/$tdir/$tfile $NRFILES
1052
1053         cancel_lru_locks mdc
1054         lctl set_param mdc.*.stats clear
1055
1056         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1057
1058         # LU-5 large readdir
1059         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1060         #               8 bytes for name(filename is mostly 5 in this test) +
1061         #               8 bytes for luda_type
1062         # take into account of overhead in lu_dirpage header and end mark in
1063         # each page, plus one in RPC_NUM calculation.
1064         DIRENT_SIZE=48
1065         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1066         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1067         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1068                                 awk '/^mds_readpage/ {print $2}')
1069         [[ $mds_readpage -gt $RPC_NUM ]] &&
1070                 error "large readdir doesn't take effect"
1071
1072         simple_cleanup_common
1073 }
1074 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1075
1076 test_24w() { # bug21506
1077         SZ1=234852
1078         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1079         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1080         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1081         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1082         [[ "$SZ1" -eq "$SZ2" ]] ||
1083                 error "Error reading at the end of the file $tfile"
1084 }
1085 run_test 24w "Reading a file larger than 4Gb"
1086
1087 test_24x() {
1088         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1089         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1090         local MDTIDX=1
1091         local remote_dir=$DIR/$tdir/remote_dir
1092
1093         test_mkdir -p $DIR/$tdir
1094         $LFS mkdir -i $MDTIDX $remote_dir ||
1095                 error "create remote directory failed"
1096
1097         test_mkdir -p $DIR/$tdir/src_dir
1098         touch $DIR/$tdir/src_file
1099         test_mkdir -p $remote_dir/tgt_dir
1100         touch $remote_dir/tgt_file
1101
1102         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir ||
1103                 error "rename dir cross MDT failed!"
1104
1105         mrename $DIR/$tdir/src_file $remote_dir/tgt_file ||
1106                 error "rename file cross MDT failed!"
1107
1108         touch $DIR/$tdir/ln_file
1109         ln $DIR/$tdir/ln_file $remote_dir/ln_name ||
1110                 error "ln file cross MDT failed"
1111
1112         rm -rf $DIR/$tdir || error "Can not delete directories"
1113 }
1114 run_test 24x "cross MDT rename/link"
1115
1116 test_24y() {
1117         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1118         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1119         local MDTIDX=1
1120         local remote_dir=$DIR/$tdir/remote_dir
1121
1122         test_mkdir -p $DIR/$tdir
1123         $LFS mkdir -i $MDTIDX $remote_dir ||
1124                    error "create remote directory failed"
1125
1126         test_mkdir -p $remote_dir/src_dir
1127         touch $remote_dir/src_file
1128         test_mkdir -p $remote_dir/tgt_dir
1129         touch $remote_dir/tgt_file
1130
1131         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1132                 error "rename subdir in the same remote dir failed!"
1133
1134         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1135                 error "rename files in the same remote dir failed!"
1136
1137         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1138                 error "link files in the same remote dir failed!"
1139
1140         rm -rf $DIR/$tdir || error "Can not delete directories"
1141 }
1142 run_test 24y "rename/link on the same dir should succeed"
1143
1144 test_24A() { # LU-3182
1145         local NFILES=5000
1146
1147         rm -rf $DIR/$tdir
1148         test_mkdir -p $DIR/$tdir
1149         createmany -m $DIR/$tdir/$tfile $NFILES
1150         local t=$(ls $DIR/$tdir | wc -l)
1151         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1152         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1153         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1154                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1155         fi
1156
1157         rm -rf $DIR/$tdir || error "Can not delete directories"
1158 }
1159 run_test 24A "readdir() returns correct number of entries."
1160
1161 test_24B() { # LU-4805
1162         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1163         local count
1164
1165         test_mkdir $DIR/$tdir
1166         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1167                 error "create striped dir failed"
1168
1169         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1170         [ $count -eq 2 ] || error "Expected 2, got $count"
1171
1172         touch $DIR/$tdir/striped_dir/a
1173
1174         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1175         [ $count -eq 3 ] || error "Expected 3, got $count"
1176
1177         touch $DIR/$tdir/striped_dir/.f
1178
1179         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1180         [ $count -eq 4 ] || error "Expected 4, got $count"
1181
1182         rm -rf $DIR/$tdir || error "Can not delete directories"
1183 }
1184 run_test 24B "readdir for striped dir return correct number of entries"
1185
1186 test_24C() {
1187         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1188
1189         mkdir $DIR/$tdir
1190         mkdir $DIR/$tdir/d0
1191         mkdir $DIR/$tdir/d1
1192
1193         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1194                 error "create striped dir failed"
1195
1196         cd $DIR/$tdir/d0/striped_dir
1197
1198         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1199         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1200         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1201
1202         [ "$d0_ino" = "$parent_ino" ] ||
1203                 error ".. wrong, expect $d0_ino, get $parent_ino"
1204
1205         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1206                 error "mv striped dir failed"
1207
1208         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1209
1210         [ "$d1_ino" = "$parent_ino" ] ||
1211                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1212 }
1213 run_test 24C "check .. in striped dir"
1214
1215 test_24D() { # LU-6101
1216         local NFILES=50000
1217
1218         rm -rf $DIR/$tdir
1219         mkdir -p $DIR/$tdir
1220         createmany -m $DIR/$tdir/$tfile $NFILES
1221         local t=$(ls $DIR/$tdir | wc -l)
1222         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1223         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1224         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1225                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1226         fi
1227
1228         rm -rf $DIR/$tdir || error "Can not delete directories"
1229 }
1230 run_test 24D "readdir() returns correct number of entries after cursor reload"
1231
1232 test_24E() {
1233         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
1234         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1235
1236         mkdir -p $DIR/$tdir
1237         mkdir $DIR/$tdir/src_dir
1238         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
1239                 error "create remote source failed"
1240
1241         touch $DIR/$tdir/src_dir/src_child/a
1242
1243         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
1244                 error "create remote target dir failed"
1245
1246         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
1247                 error "create remote target child failed"
1248
1249         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
1250                 error "rename dir cross MDT failed!"
1251
1252         find $DIR/$tdir
1253
1254         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
1255                 error "src_child still exists after rename"
1256
1257         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
1258                 error "missing file(a) after rename"
1259
1260         rm -rf $DIR/$tdir || error "Can not delete directories"
1261 }
1262 run_test 24E "cross MDT rename/link"
1263
1264 test_25a() {
1265         echo '== symlink sanity ============================================='
1266
1267         test_mkdir $DIR/d25
1268         ln -s d25 $DIR/s25
1269         touch $DIR/s25/foo || error
1270 }
1271 run_test 25a "create file in symlinked directory ==============="
1272
1273 test_25b() {
1274         [ ! -d $DIR/d25 ] && test_25a
1275         $CHECKSTAT -t file $DIR/s25/foo || error
1276 }
1277 run_test 25b "lookup file in symlinked directory ==============="
1278
1279 test_26a() {
1280         test_mkdir $DIR/d26
1281         test_mkdir $DIR/d26/d26-2
1282         ln -s d26/d26-2 $DIR/s26
1283         touch $DIR/s26/foo || error
1284 }
1285 run_test 26a "multiple component symlink ======================="
1286
1287 test_26b() {
1288         test_mkdir -p $DIR/d26b/d26-2
1289         ln -s d26b/d26-2/foo $DIR/s26-2
1290         touch $DIR/s26-2 || error
1291 }
1292 run_test 26b "multiple component symlink at end of lookup ======"
1293
1294 test_26c() {
1295         test_mkdir $DIR/d26.2
1296         touch $DIR/d26.2/foo
1297         ln -s d26.2 $DIR/s26.2-1
1298         ln -s s26.2-1 $DIR/s26.2-2
1299         ln -s s26.2-2 $DIR/s26.2-3
1300         chmod 0666 $DIR/s26.2-3/foo
1301 }
1302 run_test 26c "chain of symlinks ================================"
1303
1304 # recursive symlinks (bug 439)
1305 test_26d() {
1306         ln -s d26-3/foo $DIR/d26-3
1307 }
1308 run_test 26d "create multiple component recursive symlink ======"
1309
1310 test_26e() {
1311         [ ! -h $DIR/d26-3 ] && test_26d
1312         rm $DIR/d26-3
1313 }
1314 run_test 26e "unlink multiple component recursive symlink ======"
1315
1316 # recursive symlinks (bug 7022)
1317 test_26f() {
1318         test_mkdir -p $DIR/$tdir
1319         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1320         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1321         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1322         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1323         cd $tfile                || error "cd $tfile failed"
1324         ln -s .. dotdot          || error "ln dotdot failed"
1325         ln -s dotdot/lndir lndir || error "ln lndir failed"
1326         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1327         output=`ls $tfile/$tfile/lndir/bar1`
1328         [ "$output" = bar1 ] && error "unexpected output"
1329         rm -r $tfile             || error "rm $tfile failed"
1330         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1331 }
1332 run_test 26f "rm -r of a directory which has recursive symlink ="
1333
1334 test_27a() {
1335         echo '== stripe sanity =============================================='
1336         test_mkdir -p $DIR/d27 || error "mkdir failed"
1337         $GETSTRIPE $DIR/d27
1338         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1339         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1340         log "== test_27a: write to one stripe file ========================="
1341         cp /etc/hosts $DIR/d27/f0 || error
1342 }
1343 run_test 27a "one stripe file =================================="
1344
1345 test_27b() {
1346         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1347         test_mkdir -p $DIR/d27
1348         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1349         $GETSTRIPE -c $DIR/d27/f01
1350         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1351                 error "two-stripe file doesn't have two stripes"
1352
1353         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1354 }
1355 run_test 27b "create and write to two stripe file"
1356
1357 test_27d() {
1358         test_mkdir -p $DIR/d27
1359         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1360         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1361         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1362 }
1363 run_test 27d "create file with default settings ================"
1364
1365 test_27e() {
1366         # LU-5839 adds check for existed layout before setting it
1367         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1368                 skip "Need MDS version at least 2.7.56" && return
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 $DIR/$tdir
1378         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1379                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1380         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1381                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1382         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1383         $GETSTRIPE $DIR/$tdir/$tfile || error "$GETSTRIPE failed"
1384 }
1385 run_test 27f "setstripe with bad stripe size (should return error)"
1386
1387 test_27g() {
1388         test_mkdir -p $DIR/d27
1389         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1390         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1391                 error "$DIR/d27/fnone has object"
1392 }
1393 run_test 27g "$GETSTRIPE with no objects"
1394
1395 test_27i() {
1396         test_mkdir $DIR/$tdir
1397         touch $DIR/$tdir/$tfile || error "touch failed"
1398         [[ $($GETSTRIPE -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1399                 error "missing objects"
1400 }
1401 run_test 27i "$GETSTRIPE with some objects"
1402
1403 test_27j() {
1404         test_mkdir -p $DIR/d27
1405         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1406 }
1407 run_test 27j "setstripe with bad stripe offset (should return error)"
1408
1409 test_27k() { # bug 2844
1410         test_mkdir -p $DIR/d27
1411         FILE=$DIR/d27/f27k
1412         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1413         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1414         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1415         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1416         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1417         dd if=/dev/zero of=$FILE bs=4k count=1
1418         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1419         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1420 }
1421 run_test 27k "limit i_blksize for broken user apps ============="
1422
1423 test_27l() {
1424         test_mkdir -p $DIR/d27
1425         mcreate $DIR/f27l || error "creating file"
1426         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1427                 error "setstripe should have failed" || true
1428 }
1429 run_test 27l "check setstripe permissions (should return error)"
1430
1431 test_27m() {
1432         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1433                 return
1434         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1435                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1436                 return
1437         fi
1438         trap simple_cleanup_common EXIT
1439         test_mkdir -p $DIR/$tdir
1440         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1441         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1442                 error "dd should fill OST0"
1443         i=2
1444         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1445                 i=$((i + 1))
1446                 [ $i -gt 256 ] && break
1447         done
1448         i=$((i + 1))
1449         touch $DIR/$tdir/f27m_$i
1450         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1451                 error "OST0 was full but new created file still use it"
1452         i=$((i + 1))
1453         touch $DIR/$tdir/f27m_$i
1454         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1455                 error "OST0 was full but new created file still use it"
1456         simple_cleanup_common
1457 }
1458 run_test 27m "create file while OST0 was full =================="
1459
1460 sleep_maxage() {
1461         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1462         sleep $DELAY
1463 }
1464
1465 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1466 # if the OST isn't full anymore.
1467 reset_enospc() {
1468         local OSTIDX=${1:-""}
1469
1470         local list=$(comma_list $(osts_nodes))
1471         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1472
1473         do_nodes $list lctl set_param fail_loc=0
1474         sync    # initiate all OST_DESTROYs from MDS to OST
1475         sleep_maxage
1476 }
1477
1478 exhaust_precreations() {
1479         local OSTIDX=$1
1480         local FAILLOC=$2
1481         local FAILIDX=${3:-$OSTIDX}
1482         local ofacet=ost$((OSTIDX + 1))
1483
1484         test_mkdir -p -c1 $DIR/$tdir
1485         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
1486         local mfacet=mds$((mdtidx + 1))
1487         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1488
1489         local OST=$(ostname_from_index $OSTIDX)
1490
1491         # on the mdt's osc
1492         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1493         local last_id=$(do_facet $mfacet lctl get_param -n \
1494                         osc.$mdtosc_proc1.prealloc_last_id)
1495         local next_id=$(do_facet $mfacet lctl get_param -n \
1496                         osc.$mdtosc_proc1.prealloc_next_id)
1497
1498         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1499         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1500
1501         test_mkdir -p $DIR/$tdir/${OST}
1502         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1503 #define OBD_FAIL_OST_ENOSPC              0x215
1504         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1505         echo "Creating to objid $last_id on ost $OST..."
1506         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1507         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1508         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1509         sleep_maxage
1510 }
1511
1512 exhaust_all_precreations() {
1513         local i
1514         for (( i=0; i < OSTCOUNT; i++ )) ; do
1515                 exhaust_precreations $i $1 -1
1516         done
1517 }
1518
1519 test_27n() {
1520         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1521         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1522         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1523         remote_ost_nodsh && skip "remote OST with nodsh" && return
1524
1525         reset_enospc
1526         rm -f $DIR/$tdir/$tfile
1527         exhaust_precreations 0 0x80000215
1528         $SETSTRIPE -c -1 $DIR/$tdir
1529         touch $DIR/$tdir/$tfile || error
1530         $GETSTRIPE $DIR/$tdir/$tfile
1531         reset_enospc
1532 }
1533 run_test 27n "create file with some full OSTs =================="
1534
1535 test_27o() {
1536         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1537         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1538         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1539         remote_ost_nodsh && skip "remote OST with nodsh" && return
1540
1541         reset_enospc
1542         rm -f $DIR/$tdir/$tfile
1543         exhaust_all_precreations 0x215
1544
1545         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1546
1547         reset_enospc
1548         rm -rf $DIR/$tdir/*
1549 }
1550 run_test 27o "create file with all full OSTs (should error) ===="
1551
1552 test_27p() {
1553         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1554         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1555         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1556         remote_ost_nodsh && skip "remote OST with nodsh" && return
1557
1558         reset_enospc
1559         rm -f $DIR/$tdir/$tfile
1560         test_mkdir -p $DIR/$tdir
1561
1562         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1563         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1564         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1565
1566         exhaust_precreations 0 0x80000215
1567         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1568         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1569         $GETSTRIPE $DIR/$tdir/$tfile
1570
1571         reset_enospc
1572 }
1573 run_test 27p "append to a truncated file with some full OSTs ==="
1574
1575 test_27q() {
1576         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1577         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1578         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1579         remote_ost_nodsh && skip "remote OST with nodsh" && return
1580
1581         reset_enospc
1582         rm -f $DIR/$tdir/$tfile
1583
1584         test_mkdir -p $DIR/$tdir
1585         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1586         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1587         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1588
1589         exhaust_all_precreations 0x215
1590
1591         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1592         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1593
1594         reset_enospc
1595 }
1596 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1597
1598 test_27r() {
1599         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1600         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1601         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1602         remote_ost_nodsh && skip "remote OST with nodsh" && return
1603
1604         reset_enospc
1605         rm -f $DIR/$tdir/$tfile
1606         exhaust_precreations 0 0x80000215
1607
1608         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1609
1610         reset_enospc
1611 }
1612 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1613
1614 test_27s() { # bug 10725
1615         test_mkdir -p $DIR/$tdir
1616         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1617         local stripe_count=0
1618         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1619         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1620                 error "stripe width >= 2^32 succeeded" || true
1621
1622 }
1623 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1624
1625 test_27t() { # bug 10864
1626         WDIR=$(pwd)
1627         WLFS=$(which lfs)
1628         cd $DIR
1629         touch $tfile
1630         $WLFS getstripe $tfile
1631         cd $WDIR
1632 }
1633 run_test 27t "check that utils parse path correctly"
1634
1635 test_27u() { # bug 4900
1636         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1637         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1638         local index
1639         local list=$(comma_list $(mdts_nodes))
1640
1641 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1642         do_nodes $list $LCTL set_param fail_loc=0x139
1643         test_mkdir -p $DIR/$tdir
1644         rm -rf $DIR/$tdir/*
1645         createmany -o $DIR/$tdir/t- 1000
1646         do_nodes $list $LCTL set_param fail_loc=0
1647
1648         TLOG=$DIR/$tfile.getstripe
1649         $GETSTRIPE $DIR/$tdir > $TLOG
1650         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1651         unlinkmany $DIR/$tdir/t- 1000
1652         [[ $OBJS -gt 0 ]] &&
1653                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1654 }
1655 run_test 27u "skip object creation on OSC w/o objects =========="
1656
1657 test_27v() { # bug 4900
1658         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1659         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1660         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1661         remote_ost_nodsh && skip "remote OST with nodsh" && return
1662
1663         exhaust_all_precreations 0x215
1664         reset_enospc
1665
1666         test_mkdir -p $DIR/$tdir
1667         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1668
1669         touch $DIR/$tdir/$tfile
1670         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1671         # all except ost1
1672         for (( i=1; i < OSTCOUNT; i++ )); do
1673                 do_facet ost$i lctl set_param fail_loc=0x705
1674         done
1675         local START=`date +%s`
1676         createmany -o $DIR/$tdir/$tfile 32
1677
1678         local FINISH=`date +%s`
1679         local TIMEOUT=`lctl get_param -n timeout`
1680         local PROCESS=$((FINISH - START))
1681         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1682                error "$FINISH - $START >= $TIMEOUT / 2"
1683         sleep $((TIMEOUT / 2 - PROCESS))
1684         reset_enospc
1685 }
1686 run_test 27v "skip object creation on slow OST ================="
1687
1688 test_27w() { # bug 10997
1689         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1690         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1691         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1692                 error "stripe size $size != 65536" || true
1693         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1694                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1695 }
1696 run_test 27w "check $SETSTRIPE -S option"
1697
1698 test_27wa() {
1699         [[ $OSTCOUNT -lt 2 ]] &&
1700                 skip_env "skipping multiple stripe count/offset test" && return
1701
1702         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1703         for i in $(seq 1 $OSTCOUNT); do
1704                 offset=$((i - 1))
1705                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1706                         error "setstripe -c $i -i $offset failed"
1707                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1708                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1709                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1710                 [ $index -ne $offset ] &&
1711                         error "stripe offset $index != $offset" || true
1712         done
1713 }
1714 run_test 27wa "check $SETSTRIPE -c -i options"
1715
1716 test_27x() {
1717         remote_ost_nodsh && skip "remote OST with nodsh" && return
1718         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1719         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1720         OFFSET=$(($OSTCOUNT - 1))
1721         OSTIDX=0
1722         local OST=$(ostname_from_index $OSTIDX)
1723
1724         test_mkdir -p $DIR/$tdir
1725         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1726         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1727         sleep_maxage
1728         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1729         for i in `seq 0 $OFFSET`; do
1730                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1731                 error "OST0 was degraded but new created file still use it"
1732         done
1733         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1734 }
1735 run_test 27x "create files while OST0 is degraded"
1736
1737 test_27y() {
1738         [[ $OSTCOUNT -lt 2 ]] &&
1739                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1740         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1741         remote_ost_nodsh && skip "remote OST with nodsh" && return
1742         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1743
1744         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1745         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1746             osc.$mdtosc.prealloc_last_id)
1747         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1748             osc.$mdtosc.prealloc_next_id)
1749         local fcount=$((last_id - next_id))
1750         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1751         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1752
1753         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1754                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1755         local OST_DEACTIVE_IDX=-1
1756         local OSC
1757         local OSTIDX
1758         local OST
1759
1760         for OSC in $MDS_OSCS; do
1761                 OST=$(osc_to_ost $OSC)
1762                 OSTIDX=$(index_from_ostuuid $OST)
1763                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1764                         OST_DEACTIVE_IDX=$OSTIDX
1765                 fi
1766                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1767                         echo $OSC "is Deactivated:"
1768                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1769                 fi
1770         done
1771
1772         OSTIDX=$(index_from_ostuuid $OST)
1773         test_mkdir -p $DIR/$tdir
1774         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1775
1776         for OSC in $MDS_OSCS; do
1777                 OST=$(osc_to_ost $OSC)
1778                 OSTIDX=$(index_from_ostuuid $OST)
1779                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1780                         echo $OST "is degraded:"
1781                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1782                                                 obdfilter.$OST.degraded=1
1783                 fi
1784         done
1785
1786         sleep_maxage
1787         createmany -o $DIR/$tdir/$tfile $fcount
1788
1789         for OSC in $MDS_OSCS; do
1790                 OST=$(osc_to_ost $OSC)
1791                 OSTIDX=$(index_from_ostuuid $OST)
1792                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1793                         echo $OST "is recovered from degraded:"
1794                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1795                                                 obdfilter.$OST.degraded=0
1796                 else
1797                         do_facet $SINGLEMDS lctl --device %$OSC activate
1798                 fi
1799         done
1800
1801         # all osp devices get activated, hence -1 stripe count restored
1802         local stripecnt=0
1803
1804         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1805         # devices get activated.
1806         sleep_maxage
1807         $SETSTRIPE -c -1 $DIR/$tfile
1808         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1809         rm -f $DIR/$tfile
1810         [ $stripecnt -ne $OSTCOUNT ] &&
1811                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1812         return 0
1813 }
1814 run_test 27y "create files while OST0 is degraded and the rest inactive"
1815
1816 check_seq_oid()
1817 {
1818         log "check file $1"
1819
1820         lmm_count=$($GETSTRIPE -c $1)
1821         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1822         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1823
1824         local old_ifs="$IFS"
1825         IFS=$'[:]'
1826         fid=($($LFS path2fid $1))
1827         IFS="$old_ifs"
1828
1829         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1830         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1831
1832         # compare lmm_seq and lu_fid->f_seq
1833         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1834         # compare lmm_object_id and lu_fid->oid
1835         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1836
1837         # check the trusted.fid attribute of the OST objects of the file
1838         local have_obdidx=false
1839         local stripe_nr=0
1840         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1841                 # skip lines up to and including "obdidx"
1842                 [ -z "$obdidx" ] && break
1843                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1844                 $have_obdidx || continue
1845
1846                 local ost=$((obdidx + 1))
1847                 local dev=$(ostdevname $ost)
1848                 local oid_hex
1849
1850                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1851
1852                 seq=$(echo $seq | sed -e "s/^0x//g")
1853                 if [ $seq == 0 ] || [ $(facet_fstype ost$ost) == zfs ]; then
1854                         oid_hex=$(echo $oid)
1855                 else
1856                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1857                 fi
1858                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1859
1860                 local ff
1861                 #
1862                 # Don't unmount/remount the OSTs if we don't need to do that.
1863                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1864                 # update too, until that use mount/ll_decode_filter_fid/mount.
1865                 # Re-enable when debugfs will understand new filter_fid.
1866                 #
1867                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1868                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1869                                 $dev 2>/dev/null" | grep "parent=")
1870                 else
1871                         stop ost$ost
1872                         mount_fstype ost$ost
1873                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1874                                 $(facet_mntpt ost$ost)/$obj_file)
1875                         unmount_fstype ost$ost
1876                         start ost$ost $dev $OST_MOUNT_OPTS
1877                         clients_up
1878                 fi
1879
1880                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1881
1882                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1883
1884                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1885                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1886                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1887                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1888                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1889                 local ff_pstripe
1890                 if echo $ff_parent | grep -q 'stripe='; then
1891                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1892                 else
1893                         #
1894                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1895                         # into f_ver in this case.  See the comment on
1896                         # ff_parent.
1897                         #
1898                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1899                                 sed -e 's/\]//')
1900                 fi
1901
1902                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1903                 [ $ff_pseq = $lmm_seq ] ||
1904                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1905                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1906                 [ $ff_poid = $lmm_oid ] ||
1907                         error "FF parent OID $ff_poid != $lmm_oid"
1908                 (($ff_pstripe == $stripe_nr)) ||
1909                         error "FF stripe $ff_pstripe != $stripe_nr"
1910
1911                 stripe_nr=$((stripe_nr + 1))
1912         done
1913 }
1914
1915 test_27z() {
1916         remote_ost_nodsh && skip "remote OST with nodsh" && return
1917         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1918         test_mkdir -p $DIR/$tdir
1919
1920         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1921                 { error "setstripe -c -1 failed"; return 1; }
1922         # We need to send a write to every object to get parent FID info set.
1923         # This _should_ also work for setattr, but does not currently.
1924         # touch $DIR/$tdir/$tfile-1 ||
1925         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1926                 { error "dd $tfile-1 failed"; return 2; }
1927         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1928                 { error "setstripe -c -1 failed"; return 3; }
1929         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1930                 { error "dd $tfile-2 failed"; return 4; }
1931
1932         # make sure write RPCs have been sent to OSTs
1933         sync; sleep 5; sync
1934
1935         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1936         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1937 }
1938 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1939
1940 test_27A() { # b=19102
1941         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1942         local restore_size=$($GETSTRIPE -S $MOUNT)
1943         local restore_count=$($GETSTRIPE -c $MOUNT)
1944         local restore_offset=$($GETSTRIPE -i $MOUNT)
1945         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1946         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1947                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1948         local default_size=$($GETSTRIPE -S $MOUNT)
1949         local default_offset=$($GETSTRIPE -i $MOUNT)
1950         local dsize=$((1024 * 1024))
1951         [ $default_size -eq $dsize ] ||
1952                 error "stripe size $default_size != $dsize"
1953         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1954         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1955 }
1956 run_test 27A "check filesystem-wide default LOV EA values"
1957
1958 test_27B() { # LU-2523
1959         test_mkdir -p $DIR/$tdir
1960         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1961         touch $DIR/$tdir/f0
1962         # open f1 with O_LOV_DELAY_CREATE
1963         # rename f0 onto f1
1964         # call setstripe ioctl on open file descriptor for f1
1965         # close
1966         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1967                 $DIR/$tdir/f0
1968
1969         rm -f $DIR/$tdir/f1
1970         # open f1 with O_LOV_DELAY_CREATE
1971         # unlink f1
1972         # call setstripe ioctl on open file descriptor for f1
1973         # close
1974         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1975
1976         # Allow multiop to fail in imitation of NFS's busted semantics.
1977         true
1978 }
1979 run_test 27B "call setstripe on open unlinked file/rename victim"
1980
1981 test_27C() { #LU-2871
1982         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1983
1984         declare -a ost_idx
1985         local index
1986         local found
1987         local i
1988         local j
1989
1990         test_mkdir -p $DIR/$tdir
1991         cd $DIR/$tdir
1992         for i in $(seq 0 $((OSTCOUNT - 1))); do
1993                 # set stripe across all OSTs starting from OST$i
1994                 $SETSTRIPE -i $i -c -1 $tfile$i
1995                 # get striping information
1996                 ost_idx=($($GETSTRIPE $tfile$i |
1997                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
1998                 echo ${ost_idx[@]}
1999
2000                 # check the layout
2001                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
2002                         error "${#ost_idx[@]} != $OSTCOUNT"
2003
2004                 for index in $(seq 0 $((OSTCOUNT - 1))); do
2005                         found=0
2006                         for j in $(echo ${ost_idx[@]}); do
2007                                 if [ $index -eq $j ]; then
2008                                         found=1
2009                                         break
2010                                 fi
2011                         done
2012                         [ $found = 1 ] ||
2013                                 error "Can not find $index in ${ost_idx[@]}"
2014                 done
2015         done
2016 }
2017 run_test 27C "check full striping across all OSTs"
2018
2019 test_27D() {
2020         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2021         local POOL=${POOL:-testpool}
2022         local first_ost=0
2023         local last_ost=$(($OSTCOUNT - 1))
2024         local ost_step=1
2025         local ost_list=$(seq $first_ost $ost_step $last_ost)
2026         local ost_range="$first_ost $last_ost $ost_step"
2027
2028         test_mkdir -p $DIR/$tdir
2029         pool_add $POOL || error "pool_add failed"
2030         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2031         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT ||
2032                 error "llapi_layout_test failed"
2033         cleanup_pools || error "cleanup_pools failed"
2034 }
2035 run_test 27D "validate llapi_layout API"
2036
2037 # Verify that default_easize is increased from its initial value after
2038 # accessing a widely striped file.
2039 test_27E() {
2040         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2041
2042         # 72 bytes is the minimum space required to store striping
2043         # information for a file striped across one OST:
2044         # (sizeof(struct lov_user_md_v3) +
2045         #  sizeof(struct lov_user_ost_data_v1))
2046         local min_easize=72
2047         $LCTL set_param -n llite.*.default_easize $min_easize ||
2048                 error "lctl set_param failed"
2049         local easize=$($LCTL get_param -n llite.*.default_easize)
2050
2051         [ $easize -eq $min_easize ] ||
2052                 error "failed to set default_easize"
2053
2054         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2055                 error "setstripe failed"
2056         cat $DIR/$tfile
2057         rm $DIR/$tfile
2058
2059         easize=$($LCTL get_param -n llite.*.default_easize)
2060
2061         [ $easize -gt $min_easize ] ||
2062                 error "default_easize not updated"
2063 }
2064 run_test 27E "check that default extended attribute size properly increases"
2065
2066 # createtest also checks that device nodes are created and
2067 # then visible correctly (#2091)
2068 test_28() { # bug 2091
2069         test_mkdir $DIR/d28
2070         $CREATETEST $DIR/d28/ct || error
2071 }
2072 run_test 28 "create/mknod/mkdir with bad file types ============"
2073
2074 test_29() {
2075         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2076         cancel_lru_locks mdc
2077         test_mkdir $DIR/d29
2078         touch $DIR/d29/foo
2079         log 'first d29'
2080         ls -l $DIR/d29
2081
2082         declare -i LOCKCOUNTORIG=0
2083         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2084                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2085         done
2086         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
2087
2088         declare -i LOCKUNUSEDCOUNTORIG=0
2089         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2090                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2091         done
2092
2093         log 'second d29'
2094         ls -l $DIR/d29
2095         log 'done'
2096
2097         declare -i LOCKCOUNTCURRENT=0
2098         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2099                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2100         done
2101
2102         declare -i LOCKUNUSEDCOUNTCURRENT=0
2103         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2104                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2105         done
2106
2107         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2108                 $LCTL set_param -n ldlm.dump_namespaces ""
2109                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2110                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2111                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2112                 return 2
2113         fi
2114         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2115                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2116                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2117                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2118                 return 3
2119         fi
2120 }
2121 run_test 29 "IT_GETATTR regression  ============================"
2122
2123 test_30a() { # was test_30
2124         cp $(which ls) $DIR || cp /bin/ls $DIR
2125         $DIR/ls / || error
2126         rm $DIR/ls
2127 }
2128 run_test 30a "execute binary from Lustre (execve) =============="
2129
2130 test_30b() {
2131         cp `which ls` $DIR || cp /bin/ls $DIR
2132         chmod go+rx $DIR/ls
2133         $RUNAS $DIR/ls / || error
2134         rm $DIR/ls
2135 }
2136 run_test 30b "execute binary from Lustre as non-root ==========="
2137
2138 test_30c() { # b=22376
2139         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2140         cp `which ls` $DIR || cp /bin/ls $DIR
2141         chmod a-rw $DIR/ls
2142         cancel_lru_locks mdc
2143         cancel_lru_locks osc
2144         $RUNAS $DIR/ls / || error
2145         rm -f $DIR/ls
2146 }
2147 run_test 30c "execute binary from Lustre without read perms ===="
2148
2149 test_31a() {
2150         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2151         $CHECKSTAT -a $DIR/f31 || error
2152 }
2153 run_test 31a "open-unlink file =================================="
2154
2155 test_31b() {
2156         touch $DIR/f31 || error
2157         ln $DIR/f31 $DIR/f31b || error
2158         $MULTIOP $DIR/f31b Ouc || error
2159         $CHECKSTAT -t file $DIR/f31 || error
2160 }
2161 run_test 31b "unlink file with multiple links while open ======="
2162
2163 test_31c() {
2164         touch $DIR/f31 || error
2165         ln $DIR/f31 $DIR/f31c || error
2166         multiop_bg_pause $DIR/f31 O_uc || return 1
2167         MULTIPID=$!
2168         $MULTIOP $DIR/f31c Ouc
2169         kill -USR1 $MULTIPID
2170         wait $MULTIPID
2171 }
2172 run_test 31c "open-unlink file with multiple links ============="
2173
2174 test_31d() {
2175         opendirunlink $DIR/d31d $DIR/d31d || error
2176         $CHECKSTAT -a $DIR/d31d || error
2177 }
2178 run_test 31d "remove of open directory ========================="
2179
2180 test_31e() { # bug 2904
2181         openfilleddirunlink $DIR/d31e || error
2182 }
2183 run_test 31e "remove of open non-empty directory ==============="
2184
2185 test_31f() { # bug 4554
2186         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2187         set -vx
2188         test_mkdir $DIR/d31f
2189         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2190         cp /etc/hosts $DIR/d31f
2191         ls -l $DIR/d31f
2192         $GETSTRIPE $DIR/d31f/hosts
2193         multiop_bg_pause $DIR/d31f D_c || return 1
2194         MULTIPID=$!
2195
2196         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2197         test_mkdir $DIR/d31f
2198         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2199         cp /etc/hosts $DIR/d31f
2200         ls -l $DIR/d31f
2201         $GETSTRIPE $DIR/d31f/hosts
2202         multiop_bg_pause $DIR/d31f D_c || return 1
2203         MULTIPID2=$!
2204
2205         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2206         wait $MULTIPID || error "first opendir $MULTIPID failed"
2207
2208         sleep 6
2209
2210         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2211         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2212         set +vx
2213 }
2214 run_test 31f "remove of open directory with open-unlink file ==="
2215
2216 test_31g() {
2217         echo "-- cross directory link --"
2218         test_mkdir -c1 $DIR/${tdir}ga
2219         test_mkdir -c1 $DIR/${tdir}gb
2220         touch $DIR/${tdir}ga/f
2221         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2222         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2223         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2224         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2225         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2226 }
2227 run_test 31g "cross directory link==============="
2228
2229 test_31h() {
2230         echo "-- cross directory link --"
2231         test_mkdir -c1 $DIR/${tdir}
2232         test_mkdir -c1 $DIR/${tdir}/dir
2233         touch $DIR/${tdir}/f
2234         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2235         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2236         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2237         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2238         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2239 }
2240 run_test 31h "cross directory link under child==============="
2241
2242 test_31i() {
2243         echo "-- cross directory link --"
2244         test_mkdir -c1 $DIR/$tdir
2245         test_mkdir -c1 $DIR/$tdir/dir
2246         touch $DIR/$tdir/dir/f
2247         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2248         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2249         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2250         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2251         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2252 }
2253 run_test 31i "cross directory link under parent==============="
2254
2255 test_31j() {
2256         test_mkdir -c1 -p $DIR/$tdir
2257         test_mkdir -c1 -p $DIR/$tdir/dir1
2258         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2259         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2260         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2261         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2262         return 0
2263 }
2264 run_test 31j "link for directory==============="
2265
2266 test_31k() {
2267         test_mkdir -c1 -p $DIR/$tdir
2268         touch $DIR/$tdir/s
2269         touch $DIR/$tdir/exist
2270         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2271         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2272         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2273         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2274         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2275         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2276         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2277         return 0
2278 }
2279 run_test 31k "link to file: the same, non-existing, dir==============="
2280
2281 test_31m() {
2282         mkdir $DIR/d31m
2283         touch $DIR/d31m/s
2284         mkdir $DIR/d31m2
2285         touch $DIR/d31m2/exist
2286         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2287         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2288         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2289         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2290         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2291         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2292         return 0
2293 }
2294 run_test 31m "link to file: the same, non-existing, dir==============="
2295
2296 test_31n() {
2297         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2298         nlink=$(stat --format=%h $DIR/$tfile)
2299         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2300         local fd=$(free_fd)
2301         local cmd="exec $fd<$DIR/$tfile"
2302         eval $cmd
2303         cmd="exec $fd<&-"
2304         trap "eval $cmd" EXIT
2305         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2306         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2307         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2308         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2309         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2310         eval $cmd
2311 }
2312 run_test 31n "check link count of unlinked file"
2313
2314 link_one() {
2315         local TEMPNAME=$(mktemp $1_XXXXXX)
2316         mlink $TEMPNAME $1 2> /dev/null &&
2317                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2318         munlink $TEMPNAME
2319 }
2320
2321 test_31o() { # LU-2901
2322         test_mkdir -p $DIR/$tdir
2323         for LOOP in $(seq 100); do
2324                 rm -f $DIR/$tdir/$tfile*
2325                 for THREAD in $(seq 8); do
2326                         link_one $DIR/$tdir/$tfile.$LOOP &
2327                 done
2328                 wait
2329                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2330                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2331                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2332                         break || true
2333         done
2334 }
2335 run_test 31o "duplicate hard links with same filename"
2336
2337 test_31p() {
2338         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2339
2340         test_mkdir $DIR/$tdir
2341         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2342         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2343
2344         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2345                 error "open unlink test1 failed"
2346         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2347                 error "open unlink test2 failed"
2348
2349         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2350                 error "test1 still exists"
2351         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2352                 error "test2 still exists"
2353 }
2354 run_test 31p "remove of open striped directory"
2355
2356 cleanup_test32_mount() {
2357         trap 0
2358         $UMOUNT $DIR/$tdir/ext2-mountpoint
2359 }
2360
2361 test_32a() {
2362         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2363         echo "== more mountpoints and symlinks ================="
2364         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2365         trap cleanup_test32_mount EXIT
2366         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2367         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2368         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2369         cleanup_test32_mount
2370 }
2371 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2372
2373 test_32b() {
2374         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2375         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2376         trap cleanup_test32_mount EXIT
2377         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2378         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2379         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2380         cleanup_test32_mount
2381 }
2382 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2383
2384 test_32c() {
2385         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2386         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2387         trap cleanup_test32_mount EXIT
2388         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2389         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2390         test_mkdir -p $DIR/$tdir/d2/test_dir
2391         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2392         cleanup_test32_mount
2393 }
2394 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2395
2396 test_32d() {
2397         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2398         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2399         trap cleanup_test32_mount EXIT
2400         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2401         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2402         test_mkdir -p $DIR/$tdir/d2/test_dir
2403         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2404         cleanup_test32_mount
2405 }
2406 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2407
2408 test_32e() {
2409         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2410         test_mkdir -p $DIR/d32e/tmp
2411         TMP_DIR=$DIR/d32e/tmp
2412         ln -s $DIR/d32e $TMP_DIR/symlink11
2413         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2414         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2415         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2416 }
2417 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2418
2419 test_32f() {
2420         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2421         test_mkdir -p $DIR/d32f/tmp
2422         TMP_DIR=$DIR/d32f/tmp
2423         ln -s $DIR/d32f $TMP_DIR/symlink11
2424         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2425         ls $DIR/d32f/tmp/symlink11  || error
2426         ls $DIR/d32f/symlink01 || error
2427 }
2428 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2429
2430 test_32g() {
2431         TMP_DIR=$DIR/$tdir/tmp
2432         test_mkdir -p $DIR/$tdir/tmp
2433         test_mkdir $DIR/${tdir}2
2434         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2435         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2436         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2437         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2438         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2439         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2440 }
2441 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2442
2443 test_32h() {
2444         rm -fr $DIR/$tdir $DIR/${tdir}2
2445         TMP_DIR=$DIR/$tdir/tmp
2446         test_mkdir -p $DIR/$tdir/tmp
2447         test_mkdir $DIR/${tdir}2
2448         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2449         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2450         ls $TMP_DIR/symlink12 || error
2451         ls $DIR/$tdir/symlink02  || error
2452 }
2453 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2454
2455 test_32i() {
2456         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2457         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2458         trap cleanup_test32_mount EXIT
2459         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2460         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2461         touch $DIR/$tdir/test_file
2462         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2463         cleanup_test32_mount
2464 }
2465 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2466
2467 test_32j() {
2468         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2469         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2470         trap cleanup_test32_mount EXIT
2471         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2472         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2473         touch $DIR/$tdir/test_file
2474         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2475         cleanup_test32_mount
2476 }
2477 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2478
2479 test_32k() {
2480         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2481         rm -fr $DIR/$tdir
2482         trap cleanup_test32_mount EXIT
2483         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2484         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2485         test_mkdir -p $DIR/$tdir/d2
2486         touch $DIR/$tdir/d2/test_file || error
2487         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2488         cleanup_test32_mount
2489 }
2490 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2491
2492 test_32l() {
2493         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2494         rm -fr $DIR/$tdir
2495         trap cleanup_test32_mount EXIT
2496         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2497         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2498         test_mkdir -p $DIR/$tdir/d2
2499         touch $DIR/$tdir/d2/test_file
2500         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2501         cleanup_test32_mount
2502 }
2503 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2504
2505 test_32m() {
2506         rm -fr $DIR/d32m
2507         test_mkdir -p $DIR/d32m/tmp
2508         TMP_DIR=$DIR/d32m/tmp
2509         ln -s $DIR $TMP_DIR/symlink11
2510         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2511         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2512         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2513 }
2514 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2515
2516 test_32n() {
2517         rm -fr $DIR/d32n
2518         test_mkdir -p $DIR/d32n/tmp
2519         TMP_DIR=$DIR/d32n/tmp
2520         ln -s $DIR $TMP_DIR/symlink11
2521         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2522         ls -l $DIR/d32n/tmp/symlink11  || error
2523         ls -l $DIR/d32n/symlink01 || error
2524 }
2525 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2526
2527 test_32o() {
2528         touch $DIR/$tfile
2529         test_mkdir -p $DIR/d32o/tmp
2530         TMP_DIR=$DIR/d32o/tmp
2531         ln -s $DIR/$tfile $TMP_DIR/symlink12
2532         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2533         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2534         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2535         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2536         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2537 }
2538 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2539
2540 test_32p() {
2541     log 32p_1
2542         rm -fr $DIR/d32p
2543     log 32p_2
2544         rm -f $DIR/$tfile
2545     log 32p_3
2546         touch $DIR/$tfile
2547     log 32p_4
2548         test_mkdir -p $DIR/d32p/tmp
2549     log 32p_5
2550         TMP_DIR=$DIR/d32p/tmp
2551     log 32p_6
2552         ln -s $DIR/$tfile $TMP_DIR/symlink12
2553     log 32p_7
2554         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2555     log 32p_8
2556         cat $DIR/d32p/tmp/symlink12 || error
2557     log 32p_9
2558         cat $DIR/d32p/symlink02 || error
2559     log 32p_10
2560 }
2561 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2562
2563 cleanup_testdir_mount() {
2564         trap 0
2565         $UMOUNT $DIR/$tdir
2566 }
2567
2568 test_32q() {
2569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2570         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2571         trap cleanup_testdir_mount EXIT
2572         test_mkdir -p $DIR/$tdir
2573         touch $DIR/$tdir/under_the_mount
2574         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2575         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2576         cleanup_testdir_mount
2577 }
2578 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2579
2580 test_32r() {
2581         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2582         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2583         trap cleanup_testdir_mount EXIT
2584         test_mkdir -p $DIR/$tdir
2585         touch $DIR/$tdir/under_the_mount
2586         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2587         ls $DIR/$tdir | grep -q under_the_mount && error || true
2588         cleanup_testdir_mount
2589 }
2590 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2591
2592 test_33aa() {
2593         rm -f $DIR/$tfile
2594         touch $DIR/$tfile
2595         chmod 444 $DIR/$tfile
2596         chown $RUNAS_ID $DIR/$tfile
2597         log 33_1
2598         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2599         log 33_2
2600 }
2601 run_test 33aa "write file with mode 444 (should return error) ===="
2602
2603 test_33a() {
2604         rm -fr $DIR/d33
2605         test_mkdir -p $DIR/d33
2606         chown $RUNAS_ID $DIR/d33
2607         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2608         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2609                 error "open RDWR" || true
2610 }
2611 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2612
2613 test_33b() {
2614         rm -fr $DIR/d33
2615         test_mkdir -p $DIR/d33
2616         chown $RUNAS_ID $DIR/d33
2617         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 || true
2618 }
2619 run_test 33b "test open file with malformed flags (No panic)"
2620
2621 test_33c() {
2622         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2623         local ostnum
2624         local ostname
2625         local write_bytes
2626         local all_zeros
2627
2628         remote_ost_nodsh && skip "remote OST with nodsh" && return
2629         all_zeros=:
2630         rm -fr $DIR/d33
2631         test_mkdir -p $DIR/d33
2632         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2633
2634         sync
2635         for ostnum in $(seq $OSTCOUNT); do
2636                 # test-framework's OST numbering is one-based, while Lustre's
2637                 # is zero-based
2638                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2639                 # Parsing llobdstat's output sucks; we could grep the /proc
2640                 # path, but that's likely to not be as portable as using the
2641                 # llobdstat utility.  So we parse lctl output instead.
2642                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2643                         obdfilter/$ostname/stats |
2644                         awk '/^write_bytes/ {print $7}' )
2645                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2646                 if (( ${write_bytes:-0} > 0 ))
2647                 then
2648                         all_zeros=false
2649                         break;
2650                 fi
2651         done
2652
2653         $all_zeros || return 0
2654
2655         # Write four bytes
2656         echo foo > $DIR/d33/bar
2657         # Really write them
2658         sync
2659
2660         # Total up write_bytes after writing.  We'd better find non-zeros.
2661         for ostnum in $(seq $OSTCOUNT); do
2662                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2663                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2664                         obdfilter/$ostname/stats |
2665                         awk '/^write_bytes/ {print $7}' )
2666                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2667                 if (( ${write_bytes:-0} > 0 ))
2668                 then
2669                         all_zeros=false
2670                         break;
2671                 fi
2672         done
2673
2674         if $all_zeros
2675         then
2676                 for ostnum in $(seq $OSTCOUNT); do
2677                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2678                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2679                         do_facet ost$ostnum lctl get_param -n \
2680                                 obdfilter/$ostname/stats
2681                 done
2682                 error "OST not keeping write_bytes stats (b22312)"
2683         fi
2684 }
2685 run_test 33c "test llobdstat and write_bytes"
2686
2687 test_33d() {
2688         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2689         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2690         local MDTIDX=1
2691         local remote_dir=$DIR/$tdir/remote_dir
2692
2693         test_mkdir -p $DIR/$tdir
2694         $LFS mkdir -i $MDTIDX $remote_dir ||
2695                 error "create remote directory failed"
2696
2697         touch $remote_dir/$tfile
2698         chmod 444 $remote_dir/$tfile
2699         chown $RUNAS_ID $remote_dir/$tfile
2700
2701         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2702
2703         chown $RUNAS_ID $remote_dir
2704         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2705                                         error "create" || true
2706         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2707                                     error "open RDWR" || true
2708         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 || true
2709 }
2710 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2711
2712 test_33e() {
2713         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2714
2715         mkdir $DIR/$tdir
2716
2717         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2718         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2719         mkdir $DIR/$tdir/local_dir
2720
2721         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2722         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2723         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2724
2725         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2726                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2727
2728         rmdir $DIR/$tdir/* || error "rmdir failed"
2729
2730         umask 777
2731         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2732         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2733         mkdir $DIR/$tdir/local_dir
2734
2735         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2736         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2737         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2738
2739         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2740                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2741
2742         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2743
2744         umask 000
2745         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2746         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2747         mkdir $DIR/$tdir/local_dir
2748
2749         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2750         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2751         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2752
2753         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2754                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2755 }
2756 run_test 33e "mkdir and striped directory should have same mode"
2757
2758 cleanup_33f() {
2759         trap 0
2760         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
2761 }
2762
2763 test_33f() {
2764         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2765
2766         mkdir $DIR/$tdir
2767         chmod go+rwx $DIR/$tdir
2768         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
2769         trap cleanup_33f EXIT
2770
2771         $RUNAS lfs mkdir -c$MDSCOUNT $DIR/$tdir/striped_dir ||
2772                 error "cannot create striped directory"
2773
2774         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
2775                 error "cannot create files in striped directory"
2776
2777         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
2778                 error "cannot remove files in striped directory"
2779
2780         $RUNAS rmdir $DIR/$tdir/striped_dir ||
2781                 error "cannot remove striped directory"
2782
2783         cleanup_33f
2784 }
2785 run_test 33f "nonroot user can create, access, and remove a striped directory"
2786
2787 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2788 test_34a() {
2789         rm -f $DIR/f34
2790         $MCREATE $DIR/f34 || error
2791         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2792         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2793         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2794         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2795 }
2796 run_test 34a "truncate file that has not been opened ==========="
2797
2798 test_34b() {
2799         [ ! -f $DIR/f34 ] && test_34a
2800         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2801         $OPENFILE -f O_RDONLY $DIR/f34
2802         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2803         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2804 }
2805 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2806
2807 test_34c() {
2808         [ ! -f $DIR/f34 ] && test_34a
2809         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2810         $OPENFILE -f O_RDWR $DIR/f34
2811         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2812         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2813 }
2814 run_test 34c "O_RDWR opening file-with-size works =============="
2815
2816 test_34d() {
2817         [ ! -f $DIR/f34 ] && test_34a
2818         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2819         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2820         rm $DIR/f34
2821 }
2822 run_test 34d "write to sparse file ============================="
2823
2824 test_34e() {
2825         rm -f $DIR/f34e
2826         $MCREATE $DIR/f34e || error
2827         $TRUNCATE $DIR/f34e 1000 || error
2828         $CHECKSTAT -s 1000 $DIR/f34e || error
2829         $OPENFILE -f O_RDWR $DIR/f34e
2830         $CHECKSTAT -s 1000 $DIR/f34e || error
2831 }
2832 run_test 34e "create objects, some with size and some without =="
2833
2834 test_34f() { # bug 6242, 6243
2835         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2836         SIZE34F=48000
2837         rm -f $DIR/f34f
2838         $MCREATE $DIR/f34f || error
2839         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2840         dd if=$DIR/f34f of=$TMP/f34f
2841         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2842         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2843         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2844         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2845         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2846 }
2847 run_test 34f "read from a file with no objects until EOF ======="
2848
2849 test_34g() {
2850         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2851         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2852         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2853         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2854         cancel_lru_locks osc
2855         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2856                 error "wrong size after lock cancel"
2857
2858         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2859         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2860                 error "expanding truncate failed"
2861         cancel_lru_locks osc
2862         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2863                 error "wrong expanded size after lock cancel"
2864 }
2865 run_test 34g "truncate long file ==============================="
2866
2867 test_34h() {
2868         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2869         local gid=10
2870         local sz=1000
2871
2872         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2873         sync # Flush the cache so that multiop below does not block on cache
2874              # flush when getting the group lock
2875         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2876         MULTIPID=$!
2877
2878         # Since just timed wait is not good enough, let's do a sync write
2879         # that way we are sure enough time for a roundtrip + processing
2880         # passed + 2 seconds of extra margin.
2881         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2882         rm $DIR/${tfile}-1
2883         sleep 2
2884
2885         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2886                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2887                 kill -9 $MULTIPID
2888         fi
2889         wait $MULTIPID
2890         local nsz=`stat -c %s $DIR/$tfile`
2891         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2892 }
2893 run_test 34h "ftruncate file under grouplock should not block"
2894
2895 test_35a() {
2896         cp /bin/sh $DIR/f35a
2897         chmod 444 $DIR/f35a
2898         chown $RUNAS_ID $DIR/f35a
2899         $RUNAS $DIR/f35a && error || true
2900         rm $DIR/f35a
2901 }
2902 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2903
2904 test_36a() {
2905         rm -f $DIR/f36
2906         utime $DIR/f36 || error
2907 }
2908 run_test 36a "MDS utime check (mknod, utime) ==================="
2909
2910 test_36b() {
2911         echo "" > $DIR/f36
2912         utime $DIR/f36 || error
2913 }
2914 run_test 36b "OST utime check (open, utime) ===================="
2915
2916 test_36c() {
2917         rm -f $DIR/d36/f36
2918         test_mkdir $DIR/d36
2919         chown $RUNAS_ID $DIR/d36
2920         $RUNAS utime $DIR/d36/f36 || error
2921 }
2922 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2923
2924 test_36d() {
2925         [ ! -d $DIR/d36 ] && test_36c
2926         echo "" > $DIR/d36/f36
2927         $RUNAS utime $DIR/d36/f36 || error
2928 }
2929 run_test 36d "non-root OST utime check (open, utime) ==========="
2930
2931 test_36e() {
2932         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2933         test_mkdir -p $DIR/$tdir
2934         touch $DIR/$tdir/$tfile
2935         $RUNAS utime $DIR/$tdir/$tfile && \
2936                 error "utime worked, expected failure" || true
2937 }
2938 run_test 36e "utime on non-owned file (should return error) ===="
2939
2940 subr_36fh() {
2941         local fl="$1"
2942         local LANG_SAVE=$LANG
2943         local LC_LANG_SAVE=$LC_LANG
2944         export LANG=C LC_LANG=C # for date language
2945
2946         DATESTR="Dec 20  2000"
2947         test_mkdir -p $DIR/$tdir
2948         lctl set_param fail_loc=$fl
2949         date; date +%s
2950         cp /etc/hosts $DIR/$tdir/$tfile
2951         sync & # write RPC generated with "current" inode timestamp, but delayed
2952         sleep 1
2953         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2954         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2955         cancel_lru_locks osc
2956         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2957         date; date +%s
2958         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2959                 echo "BEFORE: $LS_BEFORE" && \
2960                 echo "AFTER : $LS_AFTER" && \
2961                 echo "WANT  : $DATESTR" && \
2962                 error "$DIR/$tdir/$tfile timestamps changed" || true
2963
2964         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2965 }
2966
2967 test_36f() {
2968         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2969         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2970         subr_36fh "0x80000214"
2971 }
2972 run_test 36f "utime on file racing with OST BRW write =========="
2973
2974 test_36g() {
2975         remote_ost_nodsh && skip "remote OST with nodsh" && return
2976         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2977         local fmd_max_age
2978         local fmd_before
2979         local fmd_after
2980
2981         test_mkdir -p $DIR/$tdir
2982         fmd_max_age=$(do_facet ost1 \
2983                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2984                 head -n 1")
2985
2986         fmd_before=$(do_facet ost1 \
2987                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2988         touch $DIR/$tdir/$tfile
2989         sleep $((fmd_max_age + 12))
2990         fmd_after=$(do_facet ost1 \
2991                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2992
2993         echo "fmd_before: $fmd_before"
2994         echo "fmd_after: $fmd_after"
2995         [[ $fmd_after -gt $fmd_before ]] &&
2996                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
2997                 error "fmd didn't expire after ping" || true
2998 }
2999 run_test 36g "filter mod data cache expiry ====================="
3000
3001 test_36h() {
3002         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3003         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
3004         subr_36fh "0x80000227"
3005 }
3006 run_test 36h "utime on file racing with OST BRW write =========="
3007
3008 test_36i() {
3009         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3010
3011         test_mkdir $DIR/$tdir
3012         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
3013
3014         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3015         local new_mtime=$((mtime + 200))
3016
3017         #change Modify time of striped dir
3018         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3019                         error "change mtime failed"
3020
3021         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3022
3023         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3024 }
3025 run_test 36i "change mtime on striped directory"
3026
3027 # test_37 - duplicate with tests 32q 32r
3028
3029 test_38() {
3030         local file=$DIR/$tfile
3031         touch $file
3032         openfile -f O_DIRECTORY $file
3033         local RC=$?
3034         local ENOTDIR=20
3035         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3036         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3037 }
3038 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3039
3040 test_39() {
3041         touch $DIR/$tfile
3042         touch $DIR/${tfile}2
3043 #       ls -l  $DIR/$tfile $DIR/${tfile}2
3044 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
3045 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
3046         sleep 2
3047         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3048         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3049                 echo "mtime"
3050                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3051                 echo "atime"
3052                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3053                 echo "ctime"
3054                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3055                 error "O_TRUNC didn't change timestamps"
3056         fi
3057 }
3058 run_test 39 "mtime changed on create ==========================="
3059
3060 test_39b() {
3061         test_mkdir -p -c1 $DIR/$tdir
3062         cp -p /etc/passwd $DIR/$tdir/fopen
3063         cp -p /etc/passwd $DIR/$tdir/flink
3064         cp -p /etc/passwd $DIR/$tdir/funlink
3065         cp -p /etc/passwd $DIR/$tdir/frename
3066         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3067
3068         sleep 1
3069         echo "aaaaaa" >> $DIR/$tdir/fopen
3070         echo "aaaaaa" >> $DIR/$tdir/flink
3071         echo "aaaaaa" >> $DIR/$tdir/funlink
3072         echo "aaaaaa" >> $DIR/$tdir/frename
3073
3074         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3075         local link_new=`stat -c %Y $DIR/$tdir/flink`
3076         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3077         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3078
3079         cat $DIR/$tdir/fopen > /dev/null
3080         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3081         rm -f $DIR/$tdir/funlink2
3082         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3083
3084         for (( i=0; i < 2; i++ )) ; do
3085                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3086                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3087                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3088                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3089
3090                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3091                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3092                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3093                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3094
3095                 cancel_lru_locks osc
3096                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3097         done
3098 }
3099 run_test 39b "mtime change on open, link, unlink, rename  ======"
3100
3101 # this should be set to past
3102 TEST_39_MTIME=`date -d "1 year ago" +%s`
3103
3104 # bug 11063
3105 test_39c() {
3106         touch $DIR1/$tfile
3107         sleep 2
3108         local mtime0=`stat -c %Y $DIR1/$tfile`
3109
3110         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3111         local mtime1=`stat -c %Y $DIR1/$tfile`
3112         [ "$mtime1" = $TEST_39_MTIME ] || \
3113                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3114
3115         local d1=`date +%s`
3116         echo hello >> $DIR1/$tfile
3117         local d2=`date +%s`
3118         local mtime2=`stat -c %Y $DIR1/$tfile`
3119         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3120                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3121
3122         mv $DIR1/$tfile $DIR1/$tfile-1
3123
3124         for (( i=0; i < 2; i++ )) ; do
3125                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3126                 [ "$mtime2" = "$mtime3" ] || \
3127                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3128
3129                 cancel_lru_locks osc
3130                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3131         done
3132 }
3133 run_test 39c "mtime change on rename ==========================="
3134
3135 # bug 21114
3136 test_39d() {
3137         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3138         touch $DIR1/$tfile
3139
3140         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3141
3142         for (( i=0; i < 2; i++ )) ; do
3143                 local mtime=`stat -c %Y $DIR1/$tfile`
3144                 [ $mtime = $TEST_39_MTIME ] || \
3145                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3146
3147                 cancel_lru_locks osc
3148                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3149         done
3150 }
3151 run_test 39d "create, utime, stat =============================="
3152
3153 # bug 21114
3154 test_39e() {
3155         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3156         touch $DIR1/$tfile
3157         local mtime1=`stat -c %Y $DIR1/$tfile`
3158
3159         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3160
3161         for (( i=0; i < 2; i++ )) ; do
3162                 local mtime2=`stat -c %Y $DIR1/$tfile`
3163                 [ $mtime2 = $TEST_39_MTIME ] || \
3164                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3165
3166                 cancel_lru_locks osc
3167                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3168         done
3169 }
3170 run_test 39e "create, stat, utime, stat ========================"
3171
3172 # bug 21114
3173 test_39f() {
3174         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3175         touch $DIR1/$tfile
3176         mtime1=`stat -c %Y $DIR1/$tfile`
3177
3178         sleep 2
3179         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3180
3181         for (( i=0; i < 2; i++ )) ; do
3182                 local mtime2=`stat -c %Y $DIR1/$tfile`
3183                 [ $mtime2 = $TEST_39_MTIME ] || \
3184                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3185
3186                 cancel_lru_locks osc
3187                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3188         done
3189 }
3190 run_test 39f "create, stat, sleep, utime, stat ================="
3191
3192 # bug 11063
3193 test_39g() {
3194         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3195         echo hello >> $DIR1/$tfile
3196         local mtime1=`stat -c %Y $DIR1/$tfile`
3197
3198         sleep 2
3199         chmod o+r $DIR1/$tfile
3200
3201         for (( i=0; i < 2; i++ )) ; do
3202                 local mtime2=`stat -c %Y $DIR1/$tfile`
3203                 [ "$mtime1" = "$mtime2" ] || \
3204                         error "lost mtime: $mtime2, should be $mtime1"
3205
3206                 cancel_lru_locks osc
3207                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3208         done
3209 }
3210 run_test 39g "write, chmod, stat ==============================="
3211
3212 # bug 11063
3213 test_39h() {
3214         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3215         touch $DIR1/$tfile
3216         sleep 1
3217
3218         local d1=`date`
3219         echo hello >> $DIR1/$tfile
3220         local mtime1=`stat -c %Y $DIR1/$tfile`
3221
3222         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3223         local d2=`date`
3224         if [ "$d1" != "$d2" ]; then
3225                 echo "write and touch not within one second"
3226         else
3227                 for (( i=0; i < 2; i++ )) ; do
3228                         local mtime2=`stat -c %Y $DIR1/$tfile`
3229                         [ "$mtime2" = $TEST_39_MTIME ] || \
3230                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3231
3232                         cancel_lru_locks osc
3233                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3234                 done
3235         fi
3236 }
3237 run_test 39h "write, utime within one second, stat ============="
3238
3239 test_39i() {
3240         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3241         touch $DIR1/$tfile
3242         sleep 1
3243
3244         echo hello >> $DIR1/$tfile
3245         local mtime1=`stat -c %Y $DIR1/$tfile`
3246
3247         mv $DIR1/$tfile $DIR1/$tfile-1
3248
3249         for (( i=0; i < 2; i++ )) ; do
3250                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3251
3252                 [ "$mtime1" = "$mtime2" ] || \
3253                         error "lost mtime: $mtime2, should be $mtime1"
3254
3255                 cancel_lru_locks osc
3256                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3257         done
3258 }
3259 run_test 39i "write, rename, stat =============================="
3260
3261 test_39j() {
3262         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3263         start_full_debug_logging
3264         touch $DIR1/$tfile
3265         sleep 1
3266
3267         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3268         lctl set_param fail_loc=0x80000412
3269         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3270                 error "multiop failed"
3271         local multipid=$!
3272         local mtime1=`stat -c %Y $DIR1/$tfile`
3273
3274         mv $DIR1/$tfile $DIR1/$tfile-1
3275
3276         kill -USR1 $multipid
3277         wait $multipid || error "multiop close failed"
3278
3279         for (( i=0; i < 2; i++ )) ; do
3280                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3281                 [ "$mtime1" = "$mtime2" ] ||
3282                         error "mtime is lost on close: $mtime2, " \
3283                               "should be $mtime1"
3284
3285                 cancel_lru_locks osc
3286                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3287         done
3288         lctl set_param fail_loc=0
3289         stop_full_debug_logging
3290 }
3291 run_test 39j "write, rename, close, stat ======================="
3292
3293 test_39k() {
3294         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3295         touch $DIR1/$tfile
3296         sleep 1
3297
3298         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3299         local multipid=$!
3300         local mtime1=`stat -c %Y $DIR1/$tfile`
3301
3302         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3303
3304         kill -USR1 $multipid
3305         wait $multipid || error "multiop close failed"
3306
3307         for (( i=0; i < 2; i++ )) ; do
3308                 local mtime2=`stat -c %Y $DIR1/$tfile`
3309
3310                 [ "$mtime2" = $TEST_39_MTIME ] || \
3311                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3312
3313                 cancel_lru_locks osc
3314                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3315         done
3316 }
3317 run_test 39k "write, utime, close, stat ========================"
3318
3319 # this should be set to future
3320 TEST_39_ATIME=`date -d "1 year" +%s`
3321
3322 test_39l() {
3323         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3324         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3325         local atime_diff=$(do_facet $SINGLEMDS \
3326                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3327         rm -rf $DIR/$tdir
3328         mkdir -p $DIR/$tdir
3329
3330         # test setting directory atime to future
3331         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3332         local atime=$(stat -c %X $DIR/$tdir)
3333         [ "$atime" = $TEST_39_ATIME ] || \
3334                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3335
3336         # test setting directory atime from future to now
3337         local d1=$(date +%s)
3338         ls $DIR/$tdir
3339         local d2=$(date +%s)
3340
3341         cancel_lru_locks mdc
3342         atime=$(stat -c %X $DIR/$tdir)
3343         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3344                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3345
3346         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3347         sleep 3
3348
3349         # test setting directory atime when now > dir atime + atime_diff
3350         d1=$(date +%s)
3351         ls $DIR/$tdir
3352         d2=$(date +%s)
3353         cancel_lru_locks mdc
3354         atime=$(stat -c %X $DIR/$tdir)
3355         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3356                 error "atime is not updated  : $atime, should be $d2"
3357
3358         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3359         sleep 3
3360
3361         # test not setting directory atime when now < dir atime + atime_diff
3362         ls $DIR/$tdir
3363         cancel_lru_locks mdc
3364         atime=$(stat -c %X $DIR/$tdir)
3365         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3366                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3367
3368         do_facet $SINGLEMDS \
3369                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3370 }
3371 run_test 39l "directory atime update ==========================="
3372
3373 test_39m() {
3374         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3375         touch $DIR1/$tfile
3376         sleep 2
3377         local far_past_mtime=$(date -d "May 29 1953" +%s)
3378         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3379
3380         touch -m -d @$far_past_mtime $DIR1/$tfile
3381         touch -a -d @$far_past_atime $DIR1/$tfile
3382
3383         for (( i=0; i < 2; i++ )) ; do
3384                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3385                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3386                         error "atime or mtime set incorrectly"
3387
3388                 cancel_lru_locks osc
3389                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3390         done
3391 }
3392 run_test 39m "test atime and mtime before 1970"
3393
3394 test_39n() { # LU-3832
3395         local atime_diff=$(do_facet $SINGLEMDS \
3396                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3397         local atime0
3398         local atime1
3399         local atime2
3400
3401         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3402
3403         rm -rf $DIR/$tfile
3404         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3405         atime0=$(stat -c %X $DIR/$tfile)
3406
3407         sleep 5
3408         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3409         atime1=$(stat -c %X $DIR/$tfile)
3410
3411         sleep 5
3412         cancel_lru_locks mdc
3413         cancel_lru_locks osc
3414         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3415         atime2=$(stat -c %X $DIR/$tfile)
3416
3417         do_facet $SINGLEMDS \
3418                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3419
3420         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3421         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3422 }
3423 run_test 39n "check that O_NOATIME is honored"
3424
3425 test_39o() {
3426         TESTDIR=$DIR/$tdir/$tfile
3427         [ -e $TESTDIR ] && rm -rf $TESTDIR
3428         mkdir -p $TESTDIR
3429         cd $TESTDIR
3430         links1=2
3431         ls
3432         mkdir a b
3433         ls
3434         links2=$(stat -c %h .)
3435         [ $(($links1 + 2)) != $links2 ] &&
3436                 error "wrong links count $(($links1 + 2)) != $links2"
3437         rmdir b
3438         links3=$(stat -c %h .)
3439         [ $(($links1 + 1)) != $links3 ] &&
3440                 error "wrong links count $links1 != $links3"
3441         return 0
3442 }
3443 run_test 39o "directory cached attributes updated after create ========"
3444
3445 test_39p() {
3446         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3447         local MDTIDX=1
3448         TESTDIR=$DIR/$tdir/$tfile
3449         [ -e $TESTDIR ] && rm -rf $TESTDIR
3450         test_mkdir -p $TESTDIR
3451         cd $TESTDIR
3452         links1=2
3453         ls
3454         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3455         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3456         ls
3457         links2=$(stat -c %h .)
3458         [ $(($links1 + 2)) != $links2 ] &&
3459                 error "wrong links count $(($links1 + 2)) != $links2"
3460         rmdir remote_dir2
3461         links3=$(stat -c %h .)
3462         [ $(($links1 + 1)) != $links3 ] &&
3463                 error "wrong links count $links1 != $links3"
3464         return 0
3465 }
3466 run_test 39p "remote directory cached attributes updated after create ========"
3467
3468
3469 test_40() {
3470         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3471         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3472                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3473         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3474                 error "$tfile is not 4096 bytes in size"
3475 }
3476 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3477
3478 test_41() {
3479         # bug 1553
3480         small_write $DIR/f41 18
3481 }
3482 run_test 41 "test small file write + fstat ====================="
3483
3484 count_ost_writes() {
3485         lctl get_param -n osc.*.stats |
3486                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3487                         END { printf("%0.0f", writes) }'
3488 }
3489
3490 # decent default
3491 WRITEBACK_SAVE=500
3492 DIRTY_RATIO_SAVE=40
3493 MAX_DIRTY_RATIO=50
3494 BG_DIRTY_RATIO_SAVE=10
3495 MAX_BG_DIRTY_RATIO=25
3496
3497 start_writeback() {
3498         trap 0
3499         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3500         # dirty_ratio, dirty_background_ratio
3501         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3502                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3503                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3504                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3505         else
3506                 # if file not here, we are a 2.4 kernel
3507                 kill -CONT `pidof kupdated`
3508         fi
3509 }
3510
3511 stop_writeback() {
3512         # setup the trap first, so someone cannot exit the test at the
3513         # exact wrong time and mess up a machine
3514         trap start_writeback EXIT
3515         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3516         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3517                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3518                 sysctl -w vm.dirty_writeback_centisecs=0
3519                 sysctl -w vm.dirty_writeback_centisecs=0
3520                 # save and increase /proc/sys/vm/dirty_ratio
3521                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3522                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3523                 # save and increase /proc/sys/vm/dirty_background_ratio
3524                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3525                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3526         else
3527                 # if file not here, we are a 2.4 kernel
3528                 kill -STOP `pidof kupdated`
3529         fi
3530 }
3531
3532 # ensure that all stripes have some grant before we test client-side cache
3533 setup_test42() {
3534         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3535                 dd if=/dev/zero of=$i bs=4k count=1
3536                 rm $i
3537         done
3538 }
3539
3540 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3541 # file truncation, and file removal.
3542 test_42a() {
3543         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3544         setup_test42
3545         cancel_lru_locks osc
3546         stop_writeback
3547         sync; sleep 1; sync # just to be safe
3548         BEFOREWRITES=`count_ost_writes`
3549         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3550         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3551         AFTERWRITES=`count_ost_writes`
3552         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3553                 error "$BEFOREWRITES < $AFTERWRITES"
3554         start_writeback
3555 }
3556 run_test 42a "ensure that we don't flush on close =============="
3557
3558 test_42b() {
3559         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3560         setup_test42
3561         cancel_lru_locks osc
3562         stop_writeback
3563         sync
3564         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3565         BEFOREWRITES=$(count_ost_writes)
3566         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3567         AFTERWRITES=$(count_ost_writes)
3568         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3569                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3570         fi
3571         BEFOREWRITES=$(count_ost_writes)
3572         sync || error "sync: $?"
3573         AFTERWRITES=$(count_ost_writes)
3574         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3575                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3576         fi
3577         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3578         start_writeback
3579         return 0
3580 }
3581 run_test 42b "test destroy of file with cached dirty data ======"
3582
3583 # if these tests just want to test the effect of truncation,
3584 # they have to be very careful.  consider:
3585 # - the first open gets a {0,EOF}PR lock
3586 # - the first write conflicts and gets a {0, count-1}PW
3587 # - the rest of the writes are under {count,EOF}PW
3588 # - the open for truncate tries to match a {0,EOF}PR
3589 #   for the filesize and cancels the PWs.
3590 # any number of fixes (don't get {0,EOF} on open, match
3591 # composite locks, do smarter file size management) fix
3592 # this, but for now we want these tests to verify that
3593 # the cancellation with truncate intent works, so we
3594 # start the file with a full-file pw lock to match against
3595 # until the truncate.
3596 trunc_test() {
3597         test=$1
3598         file=$DIR/$test
3599         offset=$2
3600         cancel_lru_locks osc
3601         stop_writeback
3602         # prime the file with 0,EOF PW to match
3603         touch $file
3604         $TRUNCATE $file 0
3605         sync; sync
3606         # now the real test..
3607         dd if=/dev/zero of=$file bs=1024 count=100
3608         BEFOREWRITES=`count_ost_writes`
3609         $TRUNCATE $file $offset
3610         cancel_lru_locks osc
3611         AFTERWRITES=`count_ost_writes`
3612         start_writeback
3613 }
3614
3615 test_42c() {
3616         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3617         trunc_test 42c 1024
3618         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3619             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3620         rm $file
3621 }
3622 run_test 42c "test partial truncate of file with cached dirty data"
3623
3624 test_42d() {
3625         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3626         trunc_test 42d 0
3627         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3628             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3629         rm $file
3630 }
3631 run_test 42d "test complete truncate of file with cached dirty data"
3632
3633 test_42e() { # bug22074
3634         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3635         local TDIR=$DIR/${tdir}e
3636         local pagesz=$(page_size)
3637         local pages=16 # hardcoded 16 pages, don't change it.
3638         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3639         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3640         local max_dirty_mb
3641         local warmup_files
3642
3643         test_mkdir -p $DIR/${tdir}e
3644         $SETSTRIPE -c 1 $TDIR
3645         createmany -o $TDIR/f $files
3646
3647         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3648
3649         # we assume that with $OSTCOUNT files, at least one of them will
3650         # be allocated on OST0.
3651         warmup_files=$((OSTCOUNT * max_dirty_mb))
3652         createmany -o $TDIR/w $warmup_files
3653
3654         # write a large amount of data into one file and sync, to get good
3655         # avail_grant number from OST.
3656         for ((i=0; i<$warmup_files; i++)); do
3657                 idx=$($GETSTRIPE -i $TDIR/w$i)
3658                 [ $idx -ne 0 ] && continue
3659                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3660                 break
3661         done
3662         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3663         sync
3664         $LCTL get_param $proc_osc0/cur_dirty_bytes
3665         $LCTL get_param $proc_osc0/cur_grant_bytes
3666
3667         # create as much dirty pages as we can while not to trigger the actual
3668         # RPCs directly. but depends on the env, VFS may trigger flush during this
3669         # period, hopefully we are good.
3670         for ((i=0; i<$warmup_files; i++)); do
3671                 idx=$($GETSTRIPE -i $TDIR/w$i)
3672                 [ $idx -ne 0 ] && continue
3673                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3674         done
3675         $LCTL get_param $proc_osc0/cur_dirty_bytes
3676         $LCTL get_param $proc_osc0/cur_grant_bytes
3677
3678         # perform the real test
3679         $LCTL set_param $proc_osc0/rpc_stats 0
3680         for ((;i<$files; i++)); do
3681                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3682                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3683         done
3684         sync
3685         $LCTL get_param $proc_osc0/rpc_stats
3686
3687         local percent=0
3688         local have_ppr=false
3689         $LCTL get_param $proc_osc0/rpc_stats |
3690                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3691                         # skip lines until we are at the RPC histogram data
3692                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3693                         $have_ppr || continue
3694
3695                         # we only want the percent stat for < 16 pages
3696                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3697
3698                         percent=$((percent + WPCT))
3699                         if [[ $percent -gt 15 ]]; then
3700                                 error "less than 16-pages write RPCs" \
3701                                       "$percent% > 15%"
3702                                 break
3703                         fi
3704                 done
3705         rm -rf $TDIR
3706 }
3707 run_test 42e "verify sub-RPC writes are not done synchronously"
3708
3709 test_43() {
3710         test_mkdir -p $DIR/$tdir
3711         cp -p /bin/ls $DIR/$tdir/$tfile
3712         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3713         pid=$!
3714         # give multiop a chance to open
3715         sleep 1
3716
3717         $DIR/$tdir/$tfile && error || true
3718         kill -USR1 $pid
3719 }
3720 run_test 43 "execution of file opened for write should return -ETXTBSY"
3721
3722 test_43a() {
3723         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3724         test_mkdir -p $DIR/$tdir
3725         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3726                         cp -p multiop $DIR/$tdir/multiop
3727         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3728                         return 1
3729         MULTIOP_PID=$!
3730         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3731         kill -USR1 $MULTIOP_PID || return 2
3732         wait $MULTIOP_PID || return 3
3733         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3734 }
3735 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3736
3737 test_43b() {
3738         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3739         test_mkdir -p $DIR/$tdir
3740         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3741                         cp -p multiop $DIR/$tdir/multiop
3742         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3743                         return 1
3744         MULTIOP_PID=$!
3745         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3746         kill -USR1 $MULTIOP_PID || return 2
3747         wait $MULTIOP_PID || return 3
3748         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3749 }
3750 run_test 43b "truncate of file being executed should return -ETXTBSY"
3751
3752 test_43c() {
3753         local testdir="$DIR/$tdir"
3754         test_mkdir -p $DIR/$tdir
3755         cp $SHELL $testdir/
3756         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3757                 ( cd $testdir && md5sum -c)
3758 }
3759 run_test 43c "md5sum of copy into lustre========================"
3760
3761 test_44() {
3762         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3763         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3764         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3765 }
3766 run_test 44 "zero length read from a sparse stripe ============="
3767
3768 test_44a() {
3769         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3770                 awk '{ print $2 }')
3771         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3772         [[ $nstripe -gt $OSTCOUNT ]] &&
3773             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3774             return
3775         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3776                 awk '{ print $2 }')
3777         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3778                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3779                         awk '{ print $2 }')
3780         fi
3781
3782         OFFSETS="0 $((stride/2)) $((stride-1))"
3783         for offset in $OFFSETS; do
3784                 for i in $(seq 0 $((nstripe-1))); do
3785                         local GLOBALOFFSETS=""
3786                         # size in Bytes
3787                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3788                         local myfn=$DIR/d44a-$size
3789                         echo "--------writing $myfn at $size"
3790                         ll_sparseness_write $myfn $size ||
3791                                 error "ll_sparseness_write"
3792                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3793                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3794                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3795
3796                         for j in $(seq 0 $((nstripe-1))); do
3797                                 # size in Bytes
3798                                 size=$((((j + $nstripe )*$stride + $offset)))
3799                                 ll_sparseness_write $myfn $size ||
3800                                         error "ll_sparseness_write"
3801                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3802                         done
3803                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3804                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3805                         rm -f $myfn
3806                 done
3807         done
3808 }
3809 run_test 44a "test sparse pwrite ==============================="
3810
3811 dirty_osc_total() {
3812         tot=0
3813         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3814                 tot=$(($tot + $d))
3815         done
3816         echo $tot
3817 }
3818 do_dirty_record() {
3819         before=`dirty_osc_total`
3820         echo executing "\"$*\""
3821         eval $*
3822         after=`dirty_osc_total`
3823         echo before $before, after $after
3824 }
3825 test_45() {
3826         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3827         f="$DIR/f45"
3828         # Obtain grants from OST if it supports it
3829         echo blah > ${f}_grant
3830         stop_writeback
3831         sync
3832         do_dirty_record "echo blah > $f"
3833         [[ $before -eq $after ]] && error "write wasn't cached"
3834         do_dirty_record "> $f"
3835         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3836         do_dirty_record "echo blah > $f"
3837         [[ $before -eq $after ]] && error "write wasn't cached"
3838         do_dirty_record "sync"
3839         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3840         do_dirty_record "echo blah > $f"
3841         [[ $before -eq $after ]] && error "write wasn't cached"
3842         do_dirty_record "cancel_lru_locks osc"
3843         [[ $before -gt $after ]] ||
3844                 error "lock cancellation didn't lower dirty count"
3845         start_writeback
3846 }
3847 run_test 45 "osc io page accounting ============================"
3848
3849 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3850 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3851 # objects offset and an assert hit when an rpc was built with 1023's mapped
3852 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3853 test_46() {
3854         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3855         f="$DIR/f46"
3856         stop_writeback
3857         sync
3858         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3859         sync
3860         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3861         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3862         sync
3863         start_writeback
3864 }
3865 run_test 46 "dirtying a previously written page ================"
3866
3867 # test_47 is removed "Device nodes check" is moved to test_28
3868
3869 test_48a() { # bug 2399
3870         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
3871         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
3872                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly" &&
3873                 return
3874         test_mkdir $DIR/$tdir
3875         cd $DIR/$tdir
3876         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
3877         test_mkdir $DIR/$tdir || error "recreate directory failed"
3878         touch foo || error "'touch foo' failed after recreating cwd"
3879         test_mkdir bar || error "'mkdir foo' failed after recreating cwd"
3880         touch .foo || error "'touch .foo' failed after recreating cwd"
3881         test_mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
3882         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3883         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3884         cd . || error "'cd .' failed after recreating cwd"
3885         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3886         rmdir . && error "'rmdir .' worked after recreating cwd"
3887         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3888         cd .. || error "'cd ..' failed after recreating cwd"
3889 }
3890 run_test 48a "Access renamed working dir (should return errors)="
3891
3892 test_48b() { # bug 2399
3893         rm -rf $DIR/$tdir
3894         test_mkdir $DIR/$tdir
3895         cd $DIR/$tdir
3896         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3897         touch foo && error "'touch foo' worked after removing cwd"
3898         test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3899         touch .foo && error "'touch .foo' worked after removing cwd"
3900         test_mkdir .foo && error "'mkdir .foo' worked after removing cwd"
3901         ls . > /dev/null && error "'ls .' worked after removing cwd"
3902         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3903         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3904         test_mkdir . && error "'mkdir .' worked after removing cwd"
3905         rmdir . && error "'rmdir .' worked after removing cwd"
3906         ln -s . foo && error "'ln -s .' worked after removing cwd"
3907         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3908 }
3909 run_test 48b "Access removed working dir (should return errors)="
3910
3911 test_48c() { # bug 2350
3912         #lctl set_param debug=-1
3913         #set -vx
3914         rm -rf $DIR/$tdir
3915         test_mkdir -p $DIR/$tdir/dir
3916         cd $DIR/$tdir/dir
3917         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3918         $TRACE touch foo && error "touch foo worked after removing cwd"
3919         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3920         touch .foo && error "touch .foo worked after removing cwd"
3921         test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3922         $TRACE ls . && error "'ls .' worked after removing cwd"
3923         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3924         is_patchless || ( $TRACE cd . &&
3925                         error "'cd .' worked after removing cwd" )
3926         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3927         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3928         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3929         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3930 }
3931 run_test 48c "Access removed working subdir (should return errors)"
3932
3933 test_48d() { # bug 2350
3934         #lctl set_param debug=-1
3935         #set -vx
3936         rm -rf $DIR/$tdir
3937         test_mkdir -p $DIR/$tdir/dir
3938         cd $DIR/$tdir/dir
3939         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3940         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3941         $TRACE touch foo && error "'touch foo' worked after removing parent"
3942         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3943         touch .foo && error "'touch .foo' worked after removing parent"
3944         test_mkdir .foo && error "mkdir .foo worked after removing parent"
3945         $TRACE ls . && error "'ls .' worked after removing parent"
3946         $TRACE ls .. && error "'ls ..' worked after removing parent"
3947         is_patchless || ( $TRACE cd . &&
3948                         error "'cd .' worked after recreate parent" )
3949         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3950         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3951         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3952         is_patchless || ( $TRACE cd .. &&
3953                         error "'cd ..' worked after removing parent" || true )
3954 }
3955 run_test 48d "Access removed parent subdir (should return errors)"
3956
3957 test_48e() { # bug 4134
3958         #lctl set_param debug=-1
3959         #set -vx
3960         rm -rf $DIR/$tdir
3961         test_mkdir -p $DIR/$tdir/dir
3962         cd $DIR/$tdir/dir
3963         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3964         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3965         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3966         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3967         # On a buggy kernel addition of "touch foo" after cd .. will
3968         # produce kernel oops in lookup_hash_it
3969         touch ../foo && error "'cd ..' worked after recreate parent"
3970         cd $DIR
3971         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3972 }
3973 run_test 48e "Access to recreated parent subdir (should return errors)"
3974
3975 test_49() { # LU-1030
3976         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3977         # get ost1 size - lustre-OST0000
3978         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3979                 awk '{ print $4 }')
3980         # write 800M at maximum
3981         [[ $ost1_size -lt 2 ]] && ost1_size=2
3982         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3983
3984         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3985         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3986         local dd_pid=$!
3987
3988         # change max_pages_per_rpc while writing the file
3989         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
3990         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
3991         # loop until dd process exits
3992         while ps ax -opid | grep -wq $dd_pid; do
3993                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
3994                 sleep $((RANDOM % 5 + 1))
3995         done
3996         # restore original max_pages_per_rpc
3997         $LCTL set_param $osc1_mppc=$orig_mppc
3998         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
3999 }
4000 run_test 49 "Change max_pages_per_rpc won't break osc extent"
4001
4002 test_50() {
4003         # bug 1485
4004         test_mkdir $DIR/$tdir
4005         cd $DIR/$tdir
4006         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
4007 }
4008 run_test 50 "special situations: /proc symlinks  ==============="
4009
4010 test_51a() {    # was test_51
4011         # bug 1516 - create an empty entry right after ".." then split dir
4012         test_mkdir -c1 $DIR/$tdir
4013         touch $DIR/$tdir/foo
4014         $MCREATE $DIR/$tdir/bar
4015         rm $DIR/$tdir/foo
4016         createmany -m $DIR/$tdir/longfile 201
4017         FNUM=202
4018         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
4019                 $MCREATE $DIR/$tdir/longfile$FNUM
4020                 FNUM=$(($FNUM + 1))
4021                 echo -n "+"
4022         done
4023         echo
4024         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
4025 }
4026 run_test 51a "special situations: split htree with empty entry =="
4027
4028 export NUMTEST=70000
4029 test_51b() {
4030         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4031         local BASE=$DIR/d${base}.${TESTSUITE}
4032
4033         # cleanup the directory
4034         rm -fr $BASE
4035
4036         test_mkdir -p -c1 $BASE
4037
4038         $LFS df
4039         $LFS df -i
4040         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
4041         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
4042         [[ $numfree -lt 21000 ]] &&
4043                 skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
4044                 return
4045
4046         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
4047                 echo "reduced count to $NUMTEST due to inodes on MDT$mdtidx"
4048
4049         # need to check free space for the directories as well
4050         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
4051         numfree=$((blkfree / 4))
4052         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$((numfree - 50)) &&
4053                 echo "reduced count to $NUMTEST due to blocks on MDT$mdtidx"
4054
4055         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
4056         {
4057                 $LFS df
4058                 $LFS df -i
4059                 echo "failed" > $BASE/fnum
4060                 error "failed to create $NUMTEST subdirs in MDT$mdtidx:$BASE"
4061         }
4062 }
4063 run_test 51b "exceed 64k subdirectory nlink limit"
4064
4065 test_51ba() { # LU-993
4066         local BASE=$DIR/d${base}.${TESTSUITE}
4067         # unlink all but 100 subdirectories, then check it still works
4068         local LEFT=100
4069         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
4070
4071         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
4072         local DELETE=$((NUMTEST - LEFT))
4073
4074         # continue on to run this test even if 51b didn't finish,
4075         # just to delete the many subdirectories created.
4076         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
4077
4078         # for ldiskfs the nlink count should be 1, but this is OSD specific
4079         # and so this is listed for informational purposes only
4080         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
4081         unlinkmany -d $BASE/d $DELETE
4082         RC=$?
4083
4084         if [ $RC -ne 0 ]; then
4085                 if [ "$NUMPREV" == "failed" ]; then
4086                         skip "previous setup failed"
4087                         return 0
4088                 else
4089                         error "unlink of first $DELETE subdirs failed"
4090                         return $RC
4091                 fi
4092         fi
4093
4094         echo "nlink between: $(stat -c %h $BASE)"
4095         # trim the first line of ls output
4096         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
4097         [ $FOUND -ne $LEFT ] &&
4098                 error "can't find subdirs: found only $FOUND/$LEFT"
4099
4100         unlinkmany -d $BASE/d $DELETE $LEFT ||
4101                 error "unlink of second $LEFT subdirs failed"
4102         # regardless of whether the backing filesystem tracks nlink accurately
4103         # or not, the nlink count shouldn't be more than "." and ".." here
4104         local AFTER=$(stat -c %h $BASE)
4105         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
4106                 echo "nlink after: $AFTER"
4107 }
4108 run_test 51ba "verify nlink for many subdirectory cleanup"
4109
4110 test_51d() {
4111         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4112         [[ $OSTCOUNT -lt 3 ]] &&
4113                 skip_env "skipping test with few OSTs" && return
4114         test_mkdir -p $DIR/$tdir
4115         createmany -o $DIR/$tdir/t- 1000
4116         $GETSTRIPE $DIR/$tdir > $TMP/files
4117         for N in $(seq 0 $((OSTCOUNT - 1))); do
4118                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4119                         END { printf("%0.0f", objs) }' $TMP/files)
4120                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
4121                         '($1 == '$N') { objs += 1 } \
4122                         END { printf("%0.0f", objs) }')
4123                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4124         done
4125         unlinkmany $DIR/$tdir/t- 1000
4126
4127         NLAST=0
4128         for N in $(seq 1 $((OSTCOUNT - 1))); do
4129                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4130                         error "OST $N has less objects vs OST $NLAST" \
4131                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4132                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4133                         error "OST $N has less objects vs OST $NLAST" \
4134                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4135
4136                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4137                         error "OST $N has less #0 objects vs OST $NLAST" \
4138                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4139                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4140                         error "OST $N has less #0 objects vs OST $NLAST" \
4141                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4142                 NLAST=$N
4143         done
4144 }
4145 run_test 51d "check object distribution ===================="
4146
4147 test_51e() {
4148         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4149                 skip "Only applicable to ldiskfs-based MDTs"
4150                 return
4151         fi
4152
4153         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4154         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4155
4156         touch $DIR/$tdir/d0/foo
4157         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4158                 error "file exceed 65000 nlink limit!"
4159         unlinkmany $DIR/$tdir/d0/f- 65001
4160         return 0
4161 }
4162 run_test 51e "check file nlink limit"
4163
4164 test_52a() {
4165         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4166         test_mkdir -p $DIR/$tdir
4167         touch $DIR/$tdir/foo
4168         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4169         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4170         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4171         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4172         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4173                                         error "link worked"
4174         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4175         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4176         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4177                                                      error "lsattr"
4178         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4179         cp -r $DIR/$tdir /tmp/
4180         rm -fr $DIR/$tdir || error "cleanup rm failed"
4181 }
4182 run_test 52a "append-only flag test (should return errors) ====="
4183
4184 test_52b() {
4185         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4186         test_mkdir -p $DIR/$tdir
4187         touch $DIR/$tdir/foo
4188         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4189         cat test > $DIR/$tdir/foo && error "cat test worked"
4190         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4191         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4192         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4193                                         error "link worked"
4194         echo foo >> $DIR/$tdir/foo && error "echo worked"
4195         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4196         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4197         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4198         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4199                                                         error "lsattr"
4200         chattr -i $DIR/$tdir/foo || error "chattr failed"
4201
4202         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4203 }
4204 run_test 52b "immutable flag test (should return errors) ======="
4205
4206 test_53() {
4207         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4208         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4209         remote_ost_nodsh && skip "remote OST with nodsh" && return
4210
4211         local param
4212         local param_seq
4213         local ostname
4214         local mds_last
4215         local mds_last_seq
4216         local ost_last
4217         local ost_last_seq
4218         local ost_last_id
4219         local ostnum
4220         local node
4221         local found=false
4222         local support_last_seq=true
4223
4224         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4225                 support_last_seq=false
4226
4227         # only test MDT0000
4228         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4229         local value
4230         for value in $(do_facet $SINGLEMDS \
4231                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4232                 param=$(echo ${value[0]} | cut -d "=" -f1)
4233                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4234
4235                 if $support_last_seq; then
4236                         param_seq=$(echo $param |
4237                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4238                         mds_last_seq=$(do_facet $SINGLEMDS \
4239                                        $LCTL get_param -n $param_seq)
4240                 fi
4241                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4242
4243                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4244                 node=$(facet_active_host ost$((ostnum+1)))
4245                 param="obdfilter.$ostname.last_id"
4246                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4247                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4248                         ost_last_id=$ost_last
4249
4250                         if $support_last_seq; then
4251                                 ost_last_id=$(echo $ost_last |
4252                                               awk -F':' '{print $2}' |
4253                                               sed -e "s/^0x//g")
4254                                 ost_last_seq=$(echo $ost_last |
4255                                                awk -F':' '{print $1}')
4256                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4257                         fi
4258
4259                         if [[ $ost_last_id != $mds_last ]]; then
4260                                 error "$ost_last_id != $mds_last"
4261                         else
4262                                 found=true
4263                                 break
4264                         fi
4265                 done
4266         done
4267         $found || error "can not match last_seq/last_id for $mdtosc"
4268         return 0
4269 }
4270 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4271
4272 test_54a() {
4273         $SOCKETSERVER $DIR/socket ||
4274                 error "$SOCKETSERVER $DIR/socket failed: $?"
4275         $SOCKETCLIENT $DIR/socket ||
4276                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4277         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4278 }
4279 run_test 54a "unix domain socket test =========================="
4280
4281 test_54b() {
4282         f="$DIR/f54b"
4283         mknod $f c 1 3
4284         chmod 0666 $f
4285         dd if=/dev/zero of=$f bs=$(page_size) count=1
4286 }
4287 run_test 54b "char device works in lustre ======================"
4288
4289 find_loop_dev() {
4290         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4291         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4292         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4293
4294         for i in $(seq 3 7); do
4295                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4296                 LOOPDEV=$LOOPBASE$i
4297                 LOOPNUM=$i
4298                 break
4299         done
4300 }
4301
4302 cleanup_54c() {
4303         loopdev="$DIR/loop54c"
4304
4305         trap 0
4306         $UMOUNT $DIR/$tdir || rc=$?
4307         losetup -d $loopdev || true
4308         losetup -d $LOOPDEV || true
4309         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4310         return $rc
4311 }
4312
4313 test_54c() {
4314         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4315         loopdev="$DIR/loop54c"
4316
4317         find_loop_dev
4318         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4319         trap cleanup_54c EXIT
4320         mknod $loopdev b 7 $LOOPNUM
4321         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4322         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4323         losetup $loopdev $DIR/$tfile ||
4324                 error "can't set up $loopdev for $DIR/$tfile"
4325         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4326         test_mkdir -p $DIR/$tdir
4327         mount -t ext2 $loopdev $DIR/$tdir ||
4328                 error "error mounting $loopdev on $DIR/$tdir"
4329         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4330                 error "dd write"
4331         df $DIR/$tdir
4332         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4333                 error "dd read"
4334         cleanup_54c
4335 }
4336 run_test 54c "block device works in lustre ====================="
4337
4338 test_54d() {
4339         f="$DIR/f54d"
4340         string="aaaaaa"
4341         mknod $f p
4342         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4343 }
4344 run_test 54d "fifo device works in lustre ======================"
4345
4346 test_54e() {
4347         f="$DIR/f54e"
4348         string="aaaaaa"
4349         cp -aL /dev/console $f
4350         echo $string > $f || error "echo $string to $f failed"
4351 }
4352 run_test 54e "console/tty device works in lustre ======================"
4353
4354 #The test_55 used to be iopen test and it was removed by bz#24037.
4355 #run_test 55 "check iopen_connect_dentry() ======================"
4356
4357 test_56a() {    # was test_56
4358         rm -rf $DIR/$tdir
4359         $SETSTRIPE -d $DIR
4360         test_mkdir -p $DIR/$tdir/dir
4361         NUMFILES=3
4362         NUMFILESx2=$(($NUMFILES * 2))
4363         for i in $(seq 1 $NUMFILES); do
4364                 touch $DIR/$tdir/file$i
4365                 touch $DIR/$tdir/dir/file$i
4366         done
4367
4368         # test lfs getstripe with --recursive
4369         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4370         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4371                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4372         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4373         [[ $FILENUM -eq $NUMFILES ]] ||
4374                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4375         echo "$GETSTRIPE --recursive passed."
4376
4377         # test lfs getstripe with file instead of dir
4378         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4379         [[ $FILENUM -eq 1 ]] ||
4380                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4381         echo "$GETSTRIPE file1 passed."
4382
4383         #test lfs getstripe with --verbose
4384         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4385                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4386                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4387         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4388                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4389         echo "$GETSTRIPE --verbose passed."
4390
4391         #test lfs getstripe with --obd
4392         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4393                 grep -q "unknown obduuid" ||
4394                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4395
4396         [[ $OSTCOUNT -lt 2 ]] &&
4397                 skip_env "skipping other $GETSTRIPE --obd test" && return
4398
4399         OSTIDX=1
4400         OBDUUID=$(ostuuid_from_index $OSTIDX)
4401         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4402         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4403         [[ $FOUND -eq $FILENUM ]] ||
4404                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4405         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4406                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4407                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4408                 error "$GETSTRIPE --obd: should not show file on other obd"
4409         echo "$GETSTRIPE --obd passed"
4410 }
4411 run_test 56a "check $GETSTRIPE"
4412
4413 NUMFILES=3
4414 NUMDIRS=3
4415 setup_56() {
4416         local LOCAL_NUMFILES="$1"
4417         local LOCAL_NUMDIRS="$2"
4418         local MKDIR_PARAMS="$3"
4419         local DIR_STRIPE_PARAMS="$4"
4420
4421         if [ ! -d "$TDIR" ] ; then
4422                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4423                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4424                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4425                         touch $TDIR/file$i
4426                 done
4427                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4428                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4429                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4430                                 touch $TDIR/dir$i/file$j
4431                         done
4432                 done
4433         fi
4434 }
4435
4436 setup_56_special() {
4437         LOCAL_NUMFILES=$1
4438         LOCAL_NUMDIRS=$2
4439         setup_56 $1 $2
4440         if [ ! -e "$TDIR/loop1b" ] ; then
4441                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4442                         mknod $TDIR/loop${i}b b 7 $i
4443                         mknod $TDIR/null${i}c c 1 3
4444                         ln -s $TDIR/file1 $TDIR/link${i}l
4445                 done
4446                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4447                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4448                         mknod $TDIR/dir$i/null${i}c c 1 3
4449                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4450                 done
4451         fi
4452 }
4453
4454 test_56g() {
4455         $SETSTRIPE -d $DIR
4456
4457         TDIR=$DIR/${tdir}g
4458         setup_56 $NUMFILES $NUMDIRS
4459
4460         EXPECTED=$(($NUMDIRS + 2))
4461         # test lfs find with -name
4462         for i in $(seq 1 $NUMFILES) ; do
4463                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4464                 [ $NUMS -eq $EXPECTED ] ||
4465                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4466                               "found $NUMS, expected $EXPECTED"
4467         done
4468 }
4469 run_test 56g "check lfs find -name ============================="
4470
4471 test_56h() {
4472         $SETSTRIPE -d $DIR
4473
4474         TDIR=$DIR/${tdir}g
4475         setup_56 $NUMFILES $NUMDIRS
4476
4477         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4478         # test lfs find with ! -name
4479         for i in $(seq 1 $NUMFILES) ; do
4480                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4481                 [ $NUMS -eq $EXPECTED ] ||
4482                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4483                               "found $NUMS, expected $EXPECTED"
4484         done
4485 }
4486 run_test 56h "check lfs find ! -name ============================="
4487
4488 test_56i() {
4489        tdir=${tdir}i
4490        test_mkdir -p $DIR/$tdir
4491        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4492        CMD="$LFIND -ost $UUID $DIR/$tdir"
4493        OUT=$($CMD)
4494        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4495 }
4496 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4497
4498 test_56j() {
4499         TDIR=$DIR/${tdir}g
4500         setup_56_special $NUMFILES $NUMDIRS
4501
4502         EXPECTED=$((NUMDIRS + 1))
4503         CMD="$LFIND -type d $TDIR"
4504         NUMS=$($CMD | wc -l)
4505         [ $NUMS -eq $EXPECTED ] ||
4506                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4507 }
4508 run_test 56j "check lfs find -type d ============================="
4509
4510 test_56k() {
4511         TDIR=$DIR/${tdir}g
4512         setup_56_special $NUMFILES $NUMDIRS
4513
4514         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4515         CMD="$LFIND -type f $TDIR"
4516         NUMS=$($CMD | wc -l)
4517         [ $NUMS -eq $EXPECTED ] ||
4518                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4519 }
4520 run_test 56k "check lfs find -type f ============================="
4521
4522 test_56l() {
4523         TDIR=$DIR/${tdir}g
4524         setup_56_special $NUMFILES $NUMDIRS
4525
4526         EXPECTED=$((NUMDIRS + NUMFILES))
4527         CMD="$LFIND -type b $TDIR"
4528         NUMS=$($CMD | wc -l)
4529         [ $NUMS -eq $EXPECTED ] ||
4530                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4531 }
4532 run_test 56l "check lfs find -type b ============================="
4533
4534 test_56m() {
4535         TDIR=$DIR/${tdir}g
4536         setup_56_special $NUMFILES $NUMDIRS
4537
4538         EXPECTED=$((NUMDIRS + NUMFILES))
4539         CMD="$LFIND -type c $TDIR"
4540         NUMS=$($CMD | wc -l)
4541         [ $NUMS -eq $EXPECTED ] ||
4542                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4543 }
4544 run_test 56m "check lfs find -type c ============================="
4545
4546 test_56n() {
4547         TDIR=$DIR/${tdir}g
4548         setup_56_special $NUMFILES $NUMDIRS
4549
4550         EXPECTED=$((NUMDIRS + NUMFILES))
4551         CMD="$LFIND -type l $TDIR"
4552         NUMS=$($CMD | wc -l)
4553         [ $NUMS -eq $EXPECTED ] ||
4554                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4555 }
4556 run_test 56n "check lfs find -type l ============================="
4557
4558 test_56o() {
4559         TDIR=$DIR/${tdir}o
4560         setup_56 $NUMFILES $NUMDIRS
4561         utime $TDIR/file1 > /dev/null || error "utime (1)"
4562         utime $TDIR/file2 > /dev/null || error "utime (2)"
4563         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4564         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4565         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4566         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4567
4568         EXPECTED=4
4569         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4570         [ $NUMS -eq $EXPECTED ] || \
4571                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4572
4573         EXPECTED=12
4574         CMD="$LFIND -mtime 0 $TDIR"
4575         NUMS=$($CMD | wc -l)
4576         [ $NUMS -eq $EXPECTED ] ||
4577                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4578 }
4579 run_test 56o "check lfs find -mtime for old files =========================="
4580
4581 test_56p() {
4582         [ $RUNAS_ID -eq $UID ] &&
4583                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4584
4585         TDIR=$DIR/${tdir}p
4586         setup_56 $NUMFILES $NUMDIRS
4587
4588         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4589         EXPECTED=$NUMFILES
4590         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4591         NUMS=$($CMD | wc -l)
4592         [ $NUMS -eq $EXPECTED ] || \
4593                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4594
4595         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4596         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4597         NUMS=$($CMD | wc -l)
4598         [ $NUMS -eq $EXPECTED ] || \
4599                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4600 }
4601 run_test 56p "check lfs find -uid and ! -uid ==============================="
4602
4603 test_56q() {
4604         [ $RUNAS_ID -eq $UID ] &&
4605                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4606
4607         TDIR=$DIR/${tdir}q
4608         setup_56 $NUMFILES $NUMDIRS
4609
4610         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4611
4612         EXPECTED=$NUMFILES
4613         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4614         NUMS=$($CMD | wc -l)
4615         [ $NUMS -eq $EXPECTED ] ||
4616                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4617
4618         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4619         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4620         NUMS=$($CMD | wc -l)
4621         [ $NUMS -eq $EXPECTED ] ||
4622                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4623 }
4624 run_test 56q "check lfs find -gid and ! -gid ==============================="
4625
4626 test_56r() {
4627         TDIR=$DIR/${tdir}r
4628         setup_56 $NUMFILES $NUMDIRS
4629
4630         EXPECTED=12
4631         CMD="$LFIND -size 0 -type f $TDIR"
4632         NUMS=$($CMD | wc -l)
4633         [ $NUMS -eq $EXPECTED ] ||
4634                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4635         EXPECTED=0
4636         CMD="$LFIND ! -size 0 -type f $TDIR"
4637         NUMS=$($CMD | wc -l)
4638         [ $NUMS -eq $EXPECTED ] ||
4639                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4640         echo "test" > $TDIR/$tfile
4641         echo "test2" > $TDIR/$tfile.2 && sync
4642         EXPECTED=1
4643         CMD="$LFIND -size 5 -type f $TDIR"
4644         NUMS=$($CMD | wc -l)
4645         [ $NUMS -eq $EXPECTED ] ||
4646                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4647         EXPECTED=1
4648         CMD="$LFIND -size +5 -type f $TDIR"
4649         NUMS=$($CMD | wc -l)
4650         [ $NUMS -eq $EXPECTED ] ||
4651                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4652         EXPECTED=2
4653         CMD="$LFIND -size +0 -type f $TDIR"
4654         NUMS=$($CMD | wc -l)
4655         [ $NUMS -eq $EXPECTED ] ||
4656                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4657         EXPECTED=2
4658         CMD="$LFIND ! -size -5 -type f $TDIR"
4659         NUMS=$($CMD | wc -l)
4660         [ $NUMS -eq $EXPECTED ] ||
4661                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4662         EXPECTED=12
4663         CMD="$LFIND -size -5 -type f $TDIR"
4664         NUMS=$($CMD | wc -l)
4665         [ $NUMS -eq $EXPECTED ] ||
4666                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4667 }
4668 run_test 56r "check lfs find -size works =========================="
4669
4670 test_56s() { # LU-611
4671         TDIR=$DIR/${tdir}s
4672         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4673
4674         if [[ $OSTCOUNT -gt 1 ]]; then
4675                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4676                 ONESTRIPE=4
4677                 EXTRA=4
4678         else
4679                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4680                 EXTRA=0
4681         fi
4682
4683         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4684         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4685         NUMS=$($CMD | wc -l)
4686         [ $NUMS -eq $EXPECTED ] || {
4687                 $GETSTRIPE -R $TDIR
4688                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4689         }
4690
4691         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4692         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4693         NUMS=$($CMD | wc -l)
4694         [ $NUMS -eq $EXPECTED ] || {
4695                 $GETSTRIPE -R $TDIR
4696                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4697         }
4698
4699         EXPECTED=$ONESTRIPE
4700         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4701         NUMS=$($CMD | wc -l)
4702         [ $NUMS -eq $EXPECTED ] || {
4703                 $GETSTRIPE -R $TDIR
4704                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4705         }
4706
4707         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4708         NUMS=$($CMD | wc -l)
4709         [ $NUMS -eq $EXPECTED ] || {
4710                 $GETSTRIPE -R $TDIR
4711                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4712         }
4713
4714         EXPECTED=0
4715         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4716         NUMS=$($CMD | wc -l)
4717         [ $NUMS -eq $EXPECTED ] || {
4718                 $GETSTRIPE -R $TDIR
4719                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4720         }
4721 }
4722 run_test 56s "check lfs find -stripe-count works"
4723
4724 test_56t() { # LU-611
4725         TDIR=$DIR/${tdir}t
4726         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4727
4728         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4729
4730         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4731         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4732         NUMS=$($CMD | wc -l)
4733         [ $NUMS -eq $EXPECTED ] ||
4734                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4735
4736         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4737         NUMS=$($CMD | wc -l)
4738         [ $NUMS -eq $EXPECTED ] ||
4739                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4740
4741         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4742         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4743         NUMS=$($CMD | wc -l)
4744         [ $NUMS -eq $EXPECTED ] ||
4745                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4746
4747         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4748         NUMS=$($CMD | wc -l)
4749         [ $NUMS -eq $EXPECTED ] ||
4750                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4751
4752         EXPECTED=4
4753         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4754         NUMS=$($CMD | wc -l)
4755         [ $NUMS -eq $EXPECTED ] ||
4756                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4757
4758         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4759         NUMS=$($CMD | wc -l)
4760         [ $NUMS -eq $EXPECTED ] ||
4761                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4762
4763         EXPECTED=0
4764         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4765         NUMS=$($CMD | wc -l)
4766         [ $NUMS -eq $EXPECTED ] ||
4767                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4768 }
4769 run_test 56t "check lfs find -stripe-size works"
4770
4771 test_56u() { # LU-611
4772         TDIR=$DIR/${tdir}u
4773         setup_56 $NUMFILES $NUMDIRS "-i 0"
4774
4775         if [[ $OSTCOUNT -gt 1 ]]; then
4776                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4777                 ONESTRIPE=4
4778         else
4779                 ONESTRIPE=0
4780         fi
4781
4782         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4783         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4784         NUMS=$($CMD | wc -l)
4785         [ $NUMS -eq $EXPECTED ] ||
4786                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4787
4788         EXPECTED=$ONESTRIPE
4789         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4790         NUMS=$($CMD | wc -l)
4791         [ $NUMS -eq $EXPECTED ] ||
4792                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4793
4794         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4795         NUMS=$($CMD | wc -l)
4796         [ $NUMS -eq $EXPECTED ] ||
4797                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4798
4799         EXPECTED=0
4800         # This should produce an error and not return any files
4801         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4802         NUMS=$($CMD 2>/dev/null | wc -l)
4803         [ $NUMS -eq $EXPECTED ] ||
4804                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4805
4806         if [[ $OSTCOUNT -gt 1 ]]; then
4807                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4808                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4809                 NUMS=$($CMD | wc -l)
4810                 [ $NUMS -eq $EXPECTED ] ||
4811                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4812         fi
4813 }
4814 run_test 56u "check lfs find -stripe-index works"
4815
4816 test_56v() {
4817     local MDT_IDX=0
4818
4819     TDIR=$DIR/${tdir}v
4820     rm -rf $TDIR
4821     setup_56 $NUMFILES $NUMDIRS
4822
4823     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4824     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4825
4826     for file in $($LFIND -mdt $UUID $TDIR); do
4827         file_mdt_idx=$($GETSTRIPE -M $file)
4828         [ $file_mdt_idx -eq $MDT_IDX ] ||
4829             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4830     done
4831 }
4832 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4833
4834 test_56w() {
4835         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
4836                 return
4837         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4838         TDIR=$DIR/${tdir}w
4839
4840     rm -rf $TDIR || error "remove $TDIR failed"
4841     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4842
4843     local stripe_size
4844     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4845         error "$GETSTRIPE -S -d $TDIR failed"
4846     stripe_size=${stripe_size%% *}
4847
4848     local file_size=$((stripe_size * OSTCOUNT))
4849     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4850     local required_space=$((file_num * file_size))
4851     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4852     [[ $free_space -le $((required_space / 1024)) ]] &&
4853         skip_env "need at least $required_space bytes free space," \
4854                  "have $free_space kbytes" && return
4855
4856     local dd_bs=65536
4857     local dd_count=$((file_size / dd_bs))
4858
4859     # write data into the files
4860     local i
4861     local j
4862     local file
4863     for i in $(seq 1 $NUMFILES); do
4864         file=$TDIR/file$i
4865         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4866             error "write data into $file failed"
4867     done
4868     for i in $(seq 1 $NUMDIRS); do
4869         for j in $(seq 1 $NUMFILES); do
4870             file=$TDIR/dir$i/file$j
4871             yes | dd bs=$dd_bs count=$dd_count of=$file \
4872                 >/dev/null 2>&1 ||
4873                 error "write data into $file failed"
4874         done
4875     done
4876
4877     local expected=-1
4878     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4879
4880     # lfs_migrate file
4881     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4882     echo "$cmd"
4883     eval $cmd || error "$cmd failed"
4884
4885     check_stripe_count $TDIR/file1 $expected
4886
4887         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
4888         then
4889                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
4890                 # OST 1 if it is on OST 0. This file is small enough to
4891                 # be on only one stripe.
4892                 file=$TDIR/migr_1_ost
4893                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
4894                         error "write data into $file failed"
4895                 local obdidx=$($LFS getstripe -i $file)
4896                 local oldmd5=$(md5sum $file)
4897                 local newobdidx=0
4898                 [[ $obdidx -eq 0 ]] && newobdidx=1
4899                 cmd="$LFS migrate -i $newobdidx $file"
4900                 echo $cmd
4901                 eval $cmd || error "$cmd failed"
4902                 local realobdix=$($LFS getstripe -i $file)
4903                 local newmd5=$(md5sum $file)
4904                 [[ $newobdidx -ne $realobdix ]] &&
4905                         error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
4906                 [[ "$oldmd5" != "$newmd5" ]] &&
4907                         error "md5sum differ: $oldmd5, $newmd5"
4908         fi
4909
4910     # lfs_migrate dir
4911     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4912     echo "$cmd"
4913     eval $cmd || error "$cmd failed"
4914
4915     for j in $(seq 1 $NUMFILES); do
4916         check_stripe_count $TDIR/dir1/file$j $expected
4917     done
4918
4919     # lfs_migrate works with lfs find
4920     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4921          $LFS_MIGRATE -y -c $expected"
4922     echo "$cmd"
4923     eval $cmd || error "$cmd failed"
4924
4925     for i in $(seq 2 $NUMFILES); do
4926         check_stripe_count $TDIR/file$i $expected
4927     done
4928     for i in $(seq 2 $NUMDIRS); do
4929         for j in $(seq 1 $NUMFILES); do
4930             check_stripe_count $TDIR/dir$i/file$j $expected
4931         done
4932     done
4933 }
4934 run_test 56w "check lfs_migrate -c stripe_count works"
4935
4936 test_56x() {
4937         check_swap_layouts_support && return 0
4938         [[ $OSTCOUNT -lt 2 ]] &&
4939                 skip_env "need 2 OST, skipping test" && return
4940
4941         local dir0=$DIR/$tdir/$testnum
4942         test_mkdir -p $dir0 || error "creating dir $dir0"
4943
4944         local ref1=/etc/passwd
4945         local file1=$dir0/file1
4946
4947         $SETSTRIPE -c 2 $file1
4948         cp $ref1 $file1
4949         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4950         stripe=$($GETSTRIPE -c $file1)
4951         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4952         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4953
4954         # clean up
4955         rm -f $file1
4956 }
4957 run_test 56x "lfs migration support"
4958
4959 test_56y() {
4960         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4961                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
4962                 return
4963
4964         local res=""
4965         local dir0=$DIR/$tdir/$testnum
4966         test_mkdir -p $dir0 || error "creating dir $dir0"
4967         local f1=$dir0/file1
4968         local f2=$dir0/file2
4969
4970         touch $f1 || error "creating std file $f1"
4971         $MULTIOP $f2 H2c || error "creating released file $f2"
4972
4973         # a directory can be raid0, so ask only for files
4974         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4975         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4976
4977         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4978         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4979
4980         # only files can be released, so no need to force file search
4981         res=$($LFIND $dir0 -L released)
4982         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4983
4984         res=$($LFIND $dir0 \! -L released)
4985         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4986
4987 }
4988 run_test 56y "lfs find -L raid0|released"
4989
4990 test_56z() { # LU-4824
4991         # This checks to make sure 'lfs find' continues after errors
4992         # There are two classes of errors that should be caught:
4993         # - If multiple paths are provided, all should be searched even if one
4994         #   errors out
4995         # - If errors are encountered during the search, it should not terminate
4996         #   early
4997         local i
4998         test_mkdir $DIR/$tdir
4999         for i in d{0..9}; do
5000                 test_mkdir $DIR/$tdir/$i
5001         done
5002         touch $DIR/$tdir/d{0..9}/$tfile
5003         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
5004                 error "$LFS find did not return an error"
5005         # Make a directory unsearchable. This should NOT be the last entry in
5006         # directory order.  Arbitrarily pick the 6th entry
5007         chmod 700 $($LFS find $DIR/$tdir -type d | sed '6!d')
5008         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
5009         # The user should be able to see 10 directories and 9 files
5010         [ $count == 19 ] || error "$LFS find did not continue after error"
5011 }
5012 run_test 56z "lfs find should continue after an error"
5013
5014 test_56aa() { # LU-5937
5015         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5016
5017         mkdir $DIR/$tdir
5018         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
5019
5020         createmany -o $DIR/$tdir/striped_dir/${tfile}- 1024
5021         local dirs=$(lfs find --size +8k $DIR/$tdir/)
5022
5023         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5024 }
5025 run_test 56aa "lfs find --size under striped dir"
5026
5027 test_57a() {
5028         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5029         # note test will not do anything if MDS is not local
5030         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5031                 skip "Only applicable to ldiskfs-based MDTs"
5032                 return
5033         fi
5034
5035         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5036         local MNTDEV="osd*.*MDT*.mntdev"
5037         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
5038         [ -z "$DEV" ] && error "can't access $MNTDEV"
5039         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
5040                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
5041                         error "can't access $DEV"
5042                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
5043                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
5044                 rm $TMP/t57a.dump
5045         done
5046 }
5047 run_test 57a "verify MDS filesystem created with large inodes =="
5048
5049 test_57b() {
5050         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5051         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5052                 skip "Only applicable to ldiskfs-based MDTs"
5053                 return
5054         fi
5055
5056         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5057         local dir=$DIR/$tdir
5058
5059         local FILECOUNT=100
5060         local FILE1=$dir/f1
5061         local FILEN=$dir/f$FILECOUNT
5062
5063         rm -rf $dir || error "removing $dir"
5064         test_mkdir -p -c1 $dir || error "creating $dir"
5065         local mdtidx=$($LFS getstripe -M $dir)
5066         local mdtname=MDT$(printf %04x $mdtidx)
5067         local facet=mds$((mdtidx + 1))
5068
5069         echo "mcreating $FILECOUNT files"
5070         createmany -m $dir/f 1 $FILECOUNT || \
5071                 error "creating files in $dir"
5072
5073         # verify that files do not have EAs yet
5074         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5075         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5076
5077         sync
5078         sleep 1
5079         df $dir  #make sure we get new statfs data
5080         local MDSFREE=$(do_facet $facet \
5081                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5082         local MDCFREE=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5083         echo "opening files to create objects/EAs"
5084         local FILE
5085         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5086                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5087         done
5088
5089         # verify that files have EAs now
5090         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5091         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5092
5093         sleep 1  #make sure we get new statfs data
5094         df $dir
5095         local MDSFREE2=$(do_facet $facet \
5096                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5097         local MDCFREE2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5098         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5099                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5100                         error "MDC before $MDCFREE != after $MDCFREE2"
5101                 else
5102                         echo "MDC before $MDCFREE != after $MDCFREE2"
5103                         echo "unable to confirm if MDS has large inodes"
5104                 fi
5105         fi
5106         rm -rf $dir
5107 }
5108 run_test 57b "default LOV EAs are stored inside large inodes ==="
5109
5110 test_58() {
5111         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5112         [ -z "$(which wiretest 2>/dev/null)" ] &&
5113                         skip_env "could not find wiretest" && return
5114         wiretest
5115 }
5116 run_test 58 "verify cross-platform wire constants =============="
5117
5118 test_59() {
5119         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5120         echo "touch 130 files"
5121         createmany -o $DIR/f59- 130
5122         echo "rm 130 files"
5123         unlinkmany $DIR/f59- 130
5124         sync
5125         # wait for commitment of removal
5126         wait_delete_completed
5127 }
5128 run_test 59 "verify cancellation of llog records async ========="
5129
5130 TEST60_HEAD="test_60 run $RANDOM"
5131 test_60a() {
5132         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5133         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5134         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5135                 do_facet mgs "! ls run-llog.sh &> /dev/null" &&
5136                         skip_env "missing subtest run-llog.sh" && return
5137
5138         log "$TEST60_HEAD - from kernel mode"
5139         do_facet mgs "$LCTL set_param debug=warning; $LCTL dk > /dev/null"
5140         do_facet mgs sh run-llog.sh
5141         do_facet mgs $LCTL dk > $TMP/$tfile
5142
5143         # LU-6388: test llog_reader
5144         local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5145         llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5146         [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5147                         skip_env "missing llog_reader" && return
5148         local fstype=$(facet_fstype mgs)
5149         [ $fstype != ldiskfs -a $fstype != zfs ] &&
5150                 skip_env "Only for ldiskfs or zfs type mgs" && return
5151
5152         local mntpt=$(facet_mntpt mgs)
5153         local mgsdev=$(mgsdevname 1)
5154         local fid_list
5155         local fid
5156         local rec_list
5157         local rec
5158         local rec_type
5159         local obj_file
5160         local path
5161         local seq
5162         local oid
5163         local pass=true
5164
5165         #get fid and record list
5166         fid_list=($(awk '/9_sub.*record/ { print $NF }' /$TMP/$tfile |
5167                 tail -n 4))
5168         rec_list=($(awk '/9_sub.*record/ { print $((NF-3)) }' /$TMP/$tfile |
5169                 tail -n 4))
5170         #remount mgs as ldiskfs or zfs type
5171         stop mgs || error "stop mgs failed"
5172         mount_fstype mgs || error "remount mgs failed"
5173         for ((i = 0; i < ${#fid_list[@]}; i++)); do
5174                 fid=${fid_list[i]}
5175                 rec=${rec_list[i]}
5176                 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
5177                 oid=$(echo $fid | awk -F ':' '{ print $2 }' | sed -e "s/^0x//g")
5178                 oid=$((16#$oid))
5179
5180                 case $fstype in
5181                         ldiskfs )
5182                                 obj_file=$mntpt/O/$seq/d$((oid%32))/$oid ;;
5183                         zfs )
5184                                 obj_file=$mntpt/oi.$(($((16#$seq))&127))/$fid ;;
5185                 esac
5186                 echo "obj_file is $obj_file"
5187                 do_facet mgs $llog_reader $obj_file
5188
5189                 rec_type=$(do_facet mgs $llog_reader $obj_file | grep "type=" |
5190                         awk '{ print $3 }' | sed -e "s/^type=//g")
5191                 if [ $rec_type != $rec ]; then
5192                         echo "FAILED test_60a wrong record type $rec_type," \
5193                               "should be $rec"
5194                         pass=false
5195                         break
5196                 fi
5197
5198                 #check obj path if record type is LLOG_LOGID_MAGIC
5199                 if [ "$rec" == "1064553b" ]; then
5200                         path=$(do_facet mgs $llog_reader $obj_file |
5201                                 grep "path=" | awk '{ print $NF }' |
5202                                 sed -e "s/^path=//g")
5203                         if [ $obj_file != $mntpt/$path ]; then
5204                                 echo "FAILED test_60a wrong obj path" \
5205                                       "$montpt/$path, should be $obj_file"
5206                                 pass=false
5207                                 break
5208                         fi
5209                 fi
5210         done
5211         rm -f $TMP/$tfile
5212         #restart mgs before "error", otherwise it will block the next test
5213         stop mgs || error "stop mgs failed"
5214         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
5215         $pass || error "test failed, see FAILED test_60a messages for specifics"
5216 }
5217 run_test 60a "llog_test run from kernel module and test llog_reader =========="
5218
5219 test_60b() { # bug 6411
5220         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5221         dmesg > $DIR/$tfile
5222         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
5223                                  /llog.test/ {
5224                                          if (marker)
5225                                                  from_marker++
5226                                          from_begin++
5227                                  }
5228                                  END {
5229                                          if (marker)
5230                                                  print from_marker
5231                                          else
5232                                                  print from_begin
5233                                  }"`
5234         [[ $LLOG_COUNT -gt 50 ]] &&
5235                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5236 }
5237 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5238
5239 test_60c() {
5240         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5241         echo "create 5000 files"
5242         createmany -o $DIR/f60c- 5000
5243 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5244         lctl set_param fail_loc=0x80000137
5245         unlinkmany $DIR/f60c- 5000
5246         lctl set_param fail_loc=0
5247 }
5248 run_test 60c "unlink file when mds full"
5249
5250 test_60d() {
5251         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5252         SAVEPRINTK=$(lctl get_param -n printk)
5253
5254         # verify "lctl mark" is even working"
5255         MESSAGE="test message ID $RANDOM $$"
5256         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5257         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5258
5259         lctl set_param printk=0 || error "set lnet.printk failed"
5260         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5261         MESSAGE="new test message ID $RANDOM $$"
5262         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5263         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5264         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5265
5266         lctl set_param -n printk="$SAVEPRINTK"
5267 }
5268 run_test 60d "test printk console message masking"
5269
5270 test_60e() {
5271         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5272         touch $DIR/$tfile
5273 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED2  0x15b
5274         do_facet mds1 lctl set_param fail_loc=0x15b
5275         rm $DIR/$tfile
5276 }
5277 run_test 60e "no space while new llog is being created"
5278
5279 test_61() {
5280         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5281         f="$DIR/f61"
5282         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5283         cancel_lru_locks osc
5284         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5285         sync
5286 }
5287 run_test 61 "mmap() writes don't make sync hang ================"
5288
5289 # bug 2330 - insufficient obd_match error checking causes LBUG
5290 test_62() {
5291         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5292         f="$DIR/f62"
5293         echo foo > $f
5294         cancel_lru_locks osc
5295         lctl set_param fail_loc=0x405
5296         cat $f && error "cat succeeded, expect -EIO"
5297         lctl set_param fail_loc=0
5298 }
5299 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5300 # match every page all of the time.
5301 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5302
5303 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5304 # Though this test is irrelevant anymore, it helped to reveal some
5305 # other grant bugs (LU-4482), let's keep it.
5306 test_63a() {   # was test_63
5307         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5308         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5309         for i in `seq 10` ; do
5310                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5311                 sleep 5
5312                 kill $!
5313                 sleep 1
5314         done
5315
5316         rm -f $DIR/f63 || true
5317 }
5318 run_test 63a "Verify oig_wait interruption does not crash ======="
5319
5320 # bug 2248 - async write errors didn't return to application on sync
5321 # bug 3677 - async write errors left page locked
5322 test_63b() {
5323         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5324         debugsave
5325         lctl set_param debug=-1
5326
5327         # ensure we have a grant to do async writes
5328         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5329         rm $DIR/$tfile
5330
5331         sync    # sync lest earlier test intercept the fail_loc
5332
5333         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5334         lctl set_param fail_loc=0x80000406
5335         $MULTIOP $DIR/$tfile Owy && \
5336                 error "sync didn't return ENOMEM"
5337         sync; sleep 2; sync     # do a real sync this time to flush page
5338         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5339                 error "locked page left in cache after async error" || true
5340         debugrestore
5341 }
5342 run_test 63b "async write errors should be returned to fsync ==="
5343
5344 test_64a () {
5345         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5346         df $DIR
5347         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5348 }
5349 run_test 64a "verify filter grant calculations (in kernel) ====="
5350
5351 test_64b () {
5352         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5353         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5354 }
5355 run_test 64b "check out-of-space detection on client ==========="
5356
5357 test_64c() {
5358         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5359 }
5360 run_test 64c "verify grant shrink ========================------"
5361
5362 # bug 1414 - set/get directories' stripe info
5363 test_65a() {
5364         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5365         test_mkdir -p $DIR/$tdir
5366         touch $DIR/$tdir/f1
5367         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5368 }
5369 run_test 65a "directory with no stripe info ===================="
5370
5371 test_65b() {
5372         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5373         test_mkdir -p $DIR/$tdir
5374         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5375                                                 error "setstripe"
5376         touch $DIR/$tdir/f2
5377         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5378 }
5379 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
5380
5381 test_65c() {
5382         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5383         if [[ $OSTCOUNT -gt 1 ]]; then
5384                 test_mkdir -p $DIR/$tdir
5385                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5386                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5387                 touch $DIR/$tdir/f3
5388                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5389         fi
5390 }
5391 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
5392
5393 test_65d() {
5394         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5395         test_mkdir -p $DIR/$tdir
5396         if [[ $STRIPECOUNT -le 0 ]]; then
5397                 sc=1
5398         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5399 #LOV_MAX_STRIPE_COUNT is 2000
5400                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5401         else
5402                 sc=$(($STRIPECOUNT - 1))
5403         fi
5404         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5405         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5406         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5407                 error "lverify failed"
5408 }
5409 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
5410
5411 test_65e() {
5412         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5413         test_mkdir -p $DIR/$tdir
5414
5415         $SETSTRIPE $DIR/$tdir || error "setstripe"
5416         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5417                                         error "no stripe info failed"
5418         touch $DIR/$tdir/f6
5419         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5420 }
5421 run_test 65e "directory setstripe defaults ======================="
5422
5423 test_65f() {
5424         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5425         test_mkdir -p $DIR/${tdir}f
5426         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5427 }
5428 run_test 65f "dir setstripe permission (should return error) ==="
5429
5430 test_65g() {
5431         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5432         test_mkdir -p $DIR/$tdir
5433         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5434                                                         error "setstripe"
5435         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5436         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5437                 error "delete default stripe failed"
5438 }
5439 run_test 65g "directory setstripe -d ==========================="
5440
5441 test_65h() {
5442         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5443         test_mkdir -p $DIR/$tdir
5444         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5445                                                         error "setstripe"
5446         test_mkdir -p $DIR/$tdir/dd1
5447         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5448                 error "stripe info inherit failed"
5449 }
5450 run_test 65h "directory stripe info inherit ===================="
5451
5452 test_65i() { # bug6367
5453         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5454         $SETSTRIPE -S 65536 -c -1 $MOUNT
5455 }
5456 run_test 65i "set non-default striping on root directory (bug 6367)="
5457
5458 test_65ia() { # bug12836
5459         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5460         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5461 }
5462 run_test 65ia "getstripe on -1 default directory striping"
5463
5464 test_65ib() { # bug12836
5465         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5466         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5467 }
5468 run_test 65ib "getstripe -v on -1 default directory striping"
5469
5470 test_65ic() { # bug12836
5471         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5472         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5473 }
5474 run_test 65ic "new find on -1 default directory striping"
5475
5476 test_65j() { # bug6367
5477         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5478         sync; sleep 1
5479         # if we aren't already remounting for each test, do so for this test
5480         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5481                 cleanup || error "failed to unmount"
5482                 setup
5483         fi
5484         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5485 }
5486 run_test 65j "set default striping on root directory (bug 6367)="
5487
5488 test_65k() { # bug11679
5489         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5490         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5491         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5492
5493     echo "Check OST status: "
5494     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5495               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5496
5497     for OSC in $MDS_OSCS; do
5498         echo $OSC "is activate"
5499         do_facet $SINGLEMDS lctl --device %$OSC activate
5500     done
5501
5502     mkdir -p $DIR/$tdir
5503     for INACTIVE_OSC in $MDS_OSCS; do
5504         echo "Deactivate: " $INACTIVE_OSC
5505         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5506         for STRIPE_OSC in $MDS_OSCS; do
5507             OST=`osc_to_ost $STRIPE_OSC`
5508             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5509                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5510
5511             [ -f $DIR/$tdir/$IDX ] && continue
5512             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5513             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5514             RC=$?
5515             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5516         done
5517         rm -f $DIR/$tdir/*
5518         echo $INACTIVE_OSC "is Activate."
5519         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5520     done
5521 }
5522 run_test 65k "validate manual striping works properly with deactivated OSCs"
5523
5524 test_65l() { # bug 12836
5525         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5526         test_mkdir -p $DIR/$tdir/test_dir
5527         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5528         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5529 }
5530 run_test 65l "lfs find on -1 stripe dir ========================"
5531
5532 # bug 2543 - update blocks count on client
5533 test_66() {
5534         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5535         COUNT=${COUNT:-8}
5536         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5537         sync; sync_all_data; sync; sync_all_data
5538         cancel_lru_locks osc
5539         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5540         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5541 }
5542 run_test 66 "update inode blocks count on client ==============="
5543
5544 LLOOP=
5545 LLITELOOPLOAD=
5546 cleanup_68() {
5547         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5548         trap 0
5549         if [ ! -z "$LLOOP" ]; then
5550                 if swapon -s | grep -q $LLOOP; then
5551                         swapoff $LLOOP || error "swapoff failed"
5552                 fi
5553
5554                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5555                 rm -f $LLOOP
5556                 unset LLOOP
5557         fi
5558         if [ ! -z "$LLITELOOPLOAD" ]; then
5559                 rmmod llite_lloop
5560                 unset LLITELOOPLOAD
5561         fi
5562         rm -f $DIR/f68*
5563 }
5564
5565 meminfo() {
5566         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5567 }
5568
5569 swap_used() {
5570         swapon -s | awk '($1 == "'$1'") { print $4 }'
5571 }
5572
5573 # test case for lloop driver, basic function
5574 test_68a() {
5575         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5576         [ "$UID" != 0 ] && skip_env "must run as root" && return
5577         llite_lloop_enabled || \
5578                 { skip_env "llite_lloop module disabled" && return; }
5579
5580         trap cleanup_68 EXIT
5581
5582         if ! module_loaded llite_lloop; then
5583                 if load_module llite/llite_lloop; then
5584                         LLITELOOPLOAD=yes
5585                 else
5586                         skip_env "can't find module llite_lloop"
5587                         return
5588                 fi
5589         fi
5590
5591         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5592         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5593         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5594
5595         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5596         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5597
5598         cleanup_68
5599 }
5600 run_test 68a "lloop driver - basic test ========================"
5601
5602 # excercise swapping to lustre by adding a high priority swapfile entry
5603 # and then consuming memory until it is used.
5604 test_68b() {  # was test_68
5605         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5606         [ "$UID" != 0 ] && skip_env "must run as root" && return
5607         lctl get_param -n devices | grep -q obdfilter && \
5608                 skip "local OST" && return
5609
5610         grep -q llite_lloop /proc/modules
5611         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5612
5613         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5614                 skip "can't reliably test swap with TCP" && return
5615
5616         MEMTOTAL=`meminfo MemTotal`
5617         NR_BLOCKS=$((MEMTOTAL>>8))
5618         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5619
5620         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5621         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5622         mkswap $DIR/f68b
5623
5624         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5625
5626         trap cleanup_68 EXIT
5627
5628         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5629
5630         echo "before: `swapon -s | grep $LLOOP`"
5631         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5632         echo "after: `swapon -s | grep $LLOOP`"
5633         SWAPUSED=`swap_used $LLOOP`
5634
5635         cleanup_68
5636
5637         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5638 }
5639 run_test 68b "support swapping to Lustre ========================"
5640
5641 # bug5265, obdfilter oa2dentry return -ENOENT
5642 # #define OBD_FAIL_SRV_ENOENT 0x217
5643 test_69() {
5644         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5645         remote_ost_nodsh && skip "remote OST with nodsh" && return
5646
5647         f="$DIR/$tfile"
5648         $SETSTRIPE -c 1 -i 0 $f
5649
5650         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5651
5652         do_facet ost1 lctl set_param fail_loc=0x217
5653         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5654         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5655
5656         do_facet ost1 lctl set_param fail_loc=0
5657         $DIRECTIO write $f 0 2 || error "write error"
5658
5659         cancel_lru_locks osc
5660         $DIRECTIO read $f 0 1 || error "read error"
5661
5662         do_facet ost1 lctl set_param fail_loc=0x217
5663         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5664
5665         do_facet ost1 lctl set_param fail_loc=0
5666         rm -f $f
5667 }
5668 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5669
5670 test_71() {
5671         test_mkdir -p $DIR/$tdir
5672         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
5673         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5674 }
5675 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5676
5677 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5678         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5679         [ "$RUNAS_ID" = "$UID" ] &&
5680                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5681
5682         # Check that testing environment is properly set up. Skip if not
5683         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5684                 skip_env "User $RUNAS_ID does not exist - skipping"
5685                 return 0
5686         }
5687         touch $DIR/$tfile
5688         chmod 777 $DIR/$tfile
5689         chmod ug+s $DIR/$tfile
5690         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5691                 error "$RUNAS dd $DIR/$tfile failed"
5692         # See if we are still setuid/sgid
5693         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5694                 error "S/gid is not dropped on write"
5695         # Now test that MDS is updated too
5696         cancel_lru_locks mdc
5697         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5698                 error "S/gid is not dropped on MDS"
5699         rm -f $DIR/$tfile
5700 }
5701 run_test 72a "Test that remove suid works properly (bug5695) ===="
5702
5703 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5704         local perm
5705
5706         [ "$RUNAS_ID" = "$UID" ] && \
5707                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5708         [ "$RUNAS_ID" -eq 0 ] && \
5709                 skip_env "RUNAS_ID = 0 -- skipping" && return
5710
5711         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5712         # Check that testing environment is properly set up. Skip if not
5713         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5714                 skip_env "User $RUNAS_ID does not exist - skipping"
5715                 return 0
5716         }
5717         touch $DIR/${tfile}-f{g,u}
5718         test_mkdir $DIR/${tfile}-dg
5719         test_mkdir $DIR/${tfile}-du
5720         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5721         chmod g+s $DIR/${tfile}-{f,d}g
5722         chmod u+s $DIR/${tfile}-{f,d}u
5723         for perm in 777 2777 4777; do
5724                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5725                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5726                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5727                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5728         done
5729         true
5730 }
5731 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5732
5733 # bug 3462 - multiple simultaneous MDC requests
5734 test_73() {
5735         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5736         test_mkdir $DIR/d73-1
5737         test_mkdir $DIR/d73-2
5738         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5739         pid1=$!
5740
5741         lctl set_param fail_loc=0x80000129
5742         $MULTIOP $DIR/d73-1/f73-2 Oc &
5743         sleep 1
5744         lctl set_param fail_loc=0
5745
5746         $MULTIOP $DIR/d73-2/f73-3 Oc &
5747         pid3=$!
5748
5749         kill -USR1 $pid1
5750         wait $pid1 || return 1
5751
5752         sleep 25
5753
5754         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5755         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5756         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5757
5758         rm -rf $DIR/d73-*
5759 }
5760 run_test 73 "multiple MDC requests (should not deadlock)"
5761
5762 test_74a() { # bug 6149, 6184
5763         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5764         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5765         #
5766         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5767         # will spin in a tight reconnection loop
5768         touch $DIR/f74a
5769         $LCTL set_param fail_loc=0x8000030e
5770         # get any lock that won't be difficult - lookup works.
5771         ls $DIR/f74a
5772         $LCTL set_param fail_loc=0
5773         rm -f $DIR/f74a
5774         true
5775 }
5776 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5777
5778 test_74b() { # bug 13310
5779         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5780         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5781         #
5782         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5783         # will spin in a tight reconnection loop
5784         $LCTL set_param fail_loc=0x8000030e
5785         # get a "difficult" lock
5786         touch $DIR/f74b
5787         $LCTL set_param fail_loc=0
5788         rm -f $DIR/f74b
5789         true
5790 }
5791 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5792
5793 test_74c() {
5794         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5795         #define OBD_FAIL_LDLM_NEW_LOCK
5796         $LCTL set_param fail_loc=0x319
5797         touch $DIR/$tfile && error "touch successful"
5798         $LCTL set_param fail_loc=0
5799         true
5800 }
5801 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5802
5803 num_inodes() {
5804         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5805 }
5806
5807 get_inode_slab_tunables() {
5808         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5809 }
5810
5811 set_inode_slab_tunables() {
5812         echo "lustre_inode_cache $1" > /proc/slabinfo
5813 }
5814
5815 test_76() { # Now for bug 20433, added originally in bug 1443
5816         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5817         local SLAB_SETTINGS=`get_inode_slab_tunables`
5818         local CPUS=`getconf _NPROCESSORS_ONLN`
5819         # we cannot set limit below 1 which means 1 inode in each
5820         # per-cpu cache is still allowed
5821         set_inode_slab_tunables "1 1 0"
5822         cancel_lru_locks osc
5823         BEFORE_INODES=$(num_inodes)
5824         echo "before inodes: $BEFORE_INODES"
5825         local COUNT=1000
5826         [ "$SLOW" = "no" ] && COUNT=100
5827         for i in $(seq $COUNT); do
5828                 touch $DIR/$tfile
5829                 rm -f $DIR/$tfile
5830         done
5831         cancel_lru_locks osc
5832         AFTER_INODES=$(num_inodes)
5833         echo "after inodes: $AFTER_INODES"
5834         local wait=0
5835         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5836                 sleep 2
5837                 AFTER_INODES=$(num_inodes)
5838                 wait=$((wait+2))
5839                 echo "wait $wait seconds inodes: $AFTER_INODES"
5840                 if [ $wait -gt 30 ]; then
5841                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5842                 fi
5843         done
5844         set_inode_slab_tunables "$SLAB_SETTINGS"
5845 }
5846 run_test 76 "confirm clients recycle inodes properly ===="
5847
5848
5849 export ORIG_CSUM=""
5850 set_checksums()
5851 {
5852         # Note: in sptlrpc modes which enable its own bulk checksum, the
5853         # original crc32_le bulk checksum will be automatically disabled,
5854         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5855         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5856         # In this case set_checksums() will not be no-op, because sptlrpc
5857         # bulk checksum will be enabled all through the test.
5858
5859         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5860         lctl set_param -n osc.*.checksums $1
5861         return 0
5862 }
5863
5864 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5865                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5866 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5867 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5868 set_checksum_type()
5869 {
5870         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5871         log "set checksum type to $1"
5872         return 0
5873 }
5874 F77_TMP=$TMP/f77-temp
5875 F77SZ=8
5876 setup_f77() {
5877         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5878                 error "error writing to $F77_TMP"
5879 }
5880
5881 test_77a() { # bug 10889
5882         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5883         $GSS && skip "could not run with gss" && return
5884         [ ! -f $F77_TMP ] && setup_f77
5885         set_checksums 1
5886         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5887         set_checksums 0
5888         rm -f $DIR/$tfile
5889 }
5890 run_test 77a "normal checksum read/write operation"
5891
5892 test_77b() { # bug 10889
5893         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5894         $GSS && skip "could not run with gss" && return
5895         [ ! -f $F77_TMP ] && setup_f77
5896         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5897         $LCTL set_param fail_loc=0x80000409
5898         set_checksums 1
5899
5900         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5901                 error "dd error: $?"
5902         $LCTL set_param fail_loc=0
5903
5904         for algo in $CKSUM_TYPES; do
5905                 cancel_lru_locks osc
5906                 set_checksum_type $algo
5907                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5908                 $LCTL set_param fail_loc=0x80000408
5909                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5910                 $LCTL set_param fail_loc=0
5911         done
5912         set_checksums 0
5913         set_checksum_type $ORIG_CSUM_TYPE
5914         rm -f $DIR/$tfile
5915 }
5916 run_test 77b "checksum error on client write, read"
5917
5918 test_77d() { # bug 10889
5919         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5920         $GSS && skip "could not run with gss" && return
5921         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5922         $LCTL set_param fail_loc=0x80000409
5923         set_checksums 1
5924         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5925                 error "direct write: rc=$?"
5926         $LCTL set_param fail_loc=0
5927         set_checksums 0
5928
5929         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5930         $LCTL set_param fail_loc=0x80000408
5931         set_checksums 1
5932         cancel_lru_locks osc
5933         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5934                 error "direct read: rc=$?"
5935         $LCTL set_param fail_loc=0
5936         set_checksums 0
5937 }
5938 run_test 77d "checksum error on OST direct write, read"
5939
5940 test_77f() { # bug 10889
5941         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5942         $GSS && skip "could not run with gss" && return
5943         set_checksums 1
5944         for algo in $CKSUM_TYPES; do
5945                 cancel_lru_locks osc
5946                 set_checksum_type $algo
5947                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5948                 $LCTL set_param fail_loc=0x409
5949                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5950                         error "direct write succeeded"
5951                 $LCTL set_param fail_loc=0
5952         done
5953         set_checksum_type $ORIG_CSUM_TYPE
5954         set_checksums 0
5955 }
5956 run_test 77f "repeat checksum error on write (expect error)"
5957
5958 test_77g() { # bug 10889
5959         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5960         $GSS && skip "could not run with gss" && return
5961         remote_ost_nodsh && skip "remote OST with nodsh" && return
5962
5963         [ ! -f $F77_TMP ] && setup_f77
5964
5965         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5966         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5967         do_facet ost1 lctl set_param fail_loc=0x8000021a
5968         set_checksums 1
5969         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5970                 error "write error: rc=$?"
5971         do_facet ost1 lctl set_param fail_loc=0
5972         set_checksums 0
5973
5974         cancel_lru_locks osc
5975         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5976         do_facet ost1 lctl set_param fail_loc=0x8000021b
5977         set_checksums 1
5978         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5979         do_facet ost1 lctl set_param fail_loc=0
5980         set_checksums 0
5981 }
5982 run_test 77g "checksum error on OST write, read"
5983
5984 test_77i() { # bug 13805
5985         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5986         $GSS && skip "could not run with gss" && return
5987         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5988         lctl set_param fail_loc=0x40b
5989         remount_client $MOUNT
5990         lctl set_param fail_loc=0
5991         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
5992                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
5993                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
5994                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
5995         done
5996         remount_client $MOUNT
5997 }
5998 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
5999
6000 test_77j() { # bug 13805
6001         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6002         $GSS && skip "could not run with gss" && return
6003         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
6004         lctl set_param fail_loc=0x40c
6005         remount_client $MOUNT
6006         lctl set_param fail_loc=0
6007         sleep 2 # wait async osc connect to finish
6008         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
6009                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
6010                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
6011                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
6012         done
6013         remount_client $MOUNT
6014 }
6015 run_test 77j "client only supporting ADLER32"
6016
6017 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
6018 rm -f $F77_TMP
6019 unset F77_TMP
6020
6021 test_78() { # bug 10901
6022         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6023         remote_ost || { skip_env "local OST" && return; }
6024
6025         NSEQ=5
6026         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
6027         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
6028         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
6029         echo "MemTotal: $MEMTOTAL"
6030
6031         # reserve 256MB of memory for the kernel and other running processes,
6032         # and then take 1/2 of the remaining memory for the read/write buffers.
6033         if [ $MEMTOTAL -gt 512 ] ;then
6034                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
6035         else
6036                 # for those poor memory-starved high-end clusters...
6037                 MEMTOTAL=$((MEMTOTAL / 2))
6038         fi
6039         echo "Mem to use for directio: $MEMTOTAL"
6040
6041         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
6042         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
6043         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
6044         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
6045                 head -n1)
6046         echo "Smallest OST: $SMALLESTOST"
6047         [[ $SMALLESTOST -lt 10240 ]] &&
6048                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
6049
6050         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
6051                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
6052
6053         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
6054         echo "File size: $F78SIZE"
6055         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
6056         for i in $(seq 1 $NSEQ); do
6057                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
6058                 echo directIO rdwr round $i of $NSEQ
6059                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
6060         done
6061
6062         rm -f $DIR/$tfile
6063 }
6064 run_test 78 "handle large O_DIRECT writes correctly ============"
6065
6066 test_79() { # bug 12743
6067         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6068         wait_delete_completed
6069
6070         BKTOTAL=$(calc_osc_kbytes kbytestotal)
6071         BKFREE=$(calc_osc_kbytes kbytesfree)
6072         BKAVAIL=$(calc_osc_kbytes kbytesavail)
6073
6074         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
6075         DFTOTAL=`echo $STRING | cut -d, -f1`
6076         DFUSED=`echo $STRING  | cut -d, -f2`
6077         DFAVAIL=`echo $STRING | cut -d, -f3`
6078         DFFREE=$(($DFTOTAL - $DFUSED))
6079
6080         ALLOWANCE=$((64 * $OSTCOUNT))
6081
6082         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
6083            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
6084                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
6085         fi
6086         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
6087            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
6088                 error "df free($DFFREE) mismatch OST free($BKFREE)"
6089         fi
6090         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
6091            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
6092                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
6093         fi
6094 }
6095 run_test 79 "df report consistency check ======================="
6096
6097 test_80() { # bug 10718
6098         remote_ost_nodsh && skip "remote OST with nodsh" && return
6099         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6100         # relax strong synchronous semantics for slow backends like ZFS
6101         local soc="obdfilter.*.sync_on_lock_cancel"
6102         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
6103         local hosts=
6104         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
6105                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
6106                           facet_active_host $host; done | sort -u)
6107                 do_nodes $hosts lctl set_param $soc=never
6108         fi
6109
6110         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
6111         sync; sleep 1; sync
6112         local BEFORE=`date +%s`
6113         cancel_lru_locks osc
6114         local AFTER=`date +%s`
6115         local DIFF=$((AFTER-BEFORE))
6116         if [ $DIFF -gt 1 ] ; then
6117                 error "elapsed for 1M@1T = $DIFF"
6118         fi
6119
6120         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
6121
6122         rm -f $DIR/$tfile
6123 }
6124 run_test 80 "Page eviction is equally fast at high offsets too  ===="
6125
6126 test_81a() { # LU-456
6127         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6128         remote_ost_nodsh && skip "remote OST with nodsh" && return
6129         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6130         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
6131         do_facet ost1 lctl set_param fail_loc=0x80000228
6132
6133         # write should trigger a retry and success
6134         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6135         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6136         RC=$?
6137         if [ $RC -ne 0 ] ; then
6138                 error "write should success, but failed for $RC"
6139         fi
6140 }
6141 run_test 81a "OST should retry write when get -ENOSPC ==============="
6142
6143 test_81b() { # LU-456
6144         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6145         remote_ost_nodsh && skip "remote OST with nodsh" && return
6146         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6147         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
6148         do_facet ost1 lctl set_param fail_loc=0x228
6149
6150         # write should retry several times and return -ENOSPC finally
6151         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6152         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6153         RC=$?
6154         ENOSPC=28
6155         if [ $RC -ne $ENOSPC ] ; then
6156                 error "dd should fail for -ENOSPC, but succeed."
6157         fi
6158 }
6159 run_test 81b "OST should return -ENOSPC when retry still fails ======="
6160
6161 test_82() { # LU-1031
6162         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
6163         local gid1=14091995
6164         local gid2=16022000
6165
6166         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
6167         local MULTIPID1=$!
6168         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
6169         local MULTIPID2=$!
6170         kill -USR1 $MULTIPID2
6171         sleep 2
6172         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6173                 error "First grouplock does not block second one"
6174         else
6175                 echo "Second grouplock blocks first one"
6176         fi
6177         kill -USR1 $MULTIPID1
6178         wait $MULTIPID1
6179         wait $MULTIPID2
6180 }
6181 run_test 82 "Basic grouplock test ==============================="
6182
6183 test_99a() {
6184         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6185                 return
6186         test_mkdir -p $DIR/d99cvsroot
6187         chown $RUNAS_ID $DIR/d99cvsroot
6188         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6189         cd $TMP
6190
6191         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6192         cd $oldPWD
6193 }
6194 run_test 99a "cvs init ========================================="
6195
6196 test_99b() {
6197         [ -z "$(which cvs 2>/dev/null)" ] &&
6198                 skip_env "could not find cvs" && return
6199         [ ! -d $DIR/d99cvsroot ] && test_99a
6200         cd /etc/init.d
6201         # some versions of cvs import exit(1) when asked to import links or
6202         # files they can't read.  ignore those files.
6203         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6204                         ! -perm +4 -printf '-I %f\n')
6205         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6206                 d99reposname vtag rtag
6207 }
6208 run_test 99b "cvs import ======================================="
6209
6210 test_99c() {
6211         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6212         [ ! -d $DIR/d99cvsroot ] && test_99b
6213         cd $DIR
6214         test_mkdir -p $DIR/d99reposname
6215         chown $RUNAS_ID $DIR/d99reposname
6216         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6217 }
6218 run_test 99c "cvs checkout ====================================="
6219
6220 test_99d() {
6221         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6222         [ ! -d $DIR/d99cvsroot ] && test_99c
6223         cd $DIR/d99reposname
6224         $RUNAS touch foo99
6225         $RUNAS cvs add -m 'addmsg' foo99
6226 }
6227 run_test 99d "cvs add =========================================="
6228
6229 test_99e() {
6230         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6231         [ ! -d $DIR/d99cvsroot ] && test_99c
6232         cd $DIR/d99reposname
6233         $RUNAS cvs update
6234 }
6235 run_test 99e "cvs update ======================================="
6236
6237 test_99f() {
6238         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6239         [ ! -d $DIR/d99cvsroot ] && test_99d
6240         cd $DIR/d99reposname
6241         $RUNAS cvs commit -m 'nomsg' foo99
6242     rm -fr $DIR/d99cvsroot
6243 }
6244 run_test 99f "cvs commit ======================================="
6245
6246 test_100() {
6247         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6248         [ "$NETTYPE" = tcp ] || \
6249                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
6250                         return ; }
6251
6252         remote_ost_nodsh && skip "remote OST with nodsh" && return
6253         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6254         remote_servers || \
6255                 { skip "useless for local single node setup" && return; }
6256
6257         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6258                 [ "$PROT" != "tcp" ] && continue
6259                 RPORT=$(echo $REMOTE | cut -d: -f2)
6260                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6261
6262                 rc=0
6263                 LPORT=`echo $LOCAL | cut -d: -f2`
6264                 if [ $LPORT -ge 1024 ]; then
6265                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6266                         netstat -tna
6267                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6268                 fi
6269         done
6270         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6271 }
6272 run_test 100 "check local port using privileged port ==========="
6273
6274 function get_named_value()
6275 {
6276     local tag
6277
6278     tag=$1
6279     while read ;do
6280         line=$REPLY
6281         case $line in
6282         $tag*)
6283             echo $line | sed "s/^$tag[ ]*//"
6284             break
6285             ;;
6286         esac
6287     done
6288 }
6289
6290 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6291                    awk '/^max_cached_mb/ { print $2 }')
6292
6293 cleanup_101a() {
6294         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6295         trap 0
6296 }
6297
6298 test_101a() {
6299         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6300         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
6301         local s
6302         local discard
6303         local nreads=10000
6304         local cache_limit=32
6305
6306         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6307         trap cleanup_101a EXIT
6308         $LCTL set_param -n llite.*.read_ahead_stats 0
6309         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6310
6311         #
6312         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6313         #
6314         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6315         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6316
6317         discard=0
6318         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6319                 get_named_value 'read but discarded' | cut -d" " -f1); do
6320                         discard=$(($discard + $s))
6321         done
6322         cleanup_101a
6323
6324         if [[ $(($discard * 10)) -gt $nreads ]]; then
6325                 $LCTL get_param osc.*-osc*.rpc_stats
6326                 $LCTL get_param llite.*.read_ahead_stats
6327                 error "too many ($discard) discarded pages"
6328         fi
6329         rm -f $DIR/$tfile || true
6330 }
6331 run_test 101a "check read-ahead for random reads ================"
6332
6333 setup_test101bc() {
6334         test_mkdir -p $DIR/$tdir
6335         local STRIPE_SIZE=$1
6336         local FILE_LENGTH=$2
6337         STRIPE_OFFSET=0
6338
6339         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6340
6341         local list=$(comma_list $(osts_nodes))
6342         set_osd_param $list '' read_cache_enable 0
6343         set_osd_param $list '' writethrough_cache_enable 0
6344
6345         trap cleanup_test101bc EXIT
6346         # prepare the read-ahead file
6347         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6348
6349         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6350                                 count=$FILE_SIZE_MB 2> /dev/null
6351
6352 }
6353
6354 cleanup_test101bc() {
6355         trap 0
6356         rm -rf $DIR/$tdir
6357         rm -f $DIR/$tfile
6358
6359         local list=$(comma_list $(osts_nodes))
6360         set_osd_param $list '' read_cache_enable 1
6361         set_osd_param $list '' writethrough_cache_enable 1
6362 }
6363
6364 calc_total() {
6365         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6366 }
6367
6368 ra_check_101() {
6369         local READ_SIZE=$1
6370         local STRIPE_SIZE=$2
6371         local FILE_LENGTH=$3
6372         local RA_INC=1048576
6373         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6374         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6375                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6376         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6377                         get_named_value 'read but discarded' |
6378                         cut -d" " -f1 | calc_total)
6379         if [[ $DISCARD -gt $discard_limit ]]; then
6380                 $LCTL get_param llite.*.read_ahead_stats
6381                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6382         else
6383                 echo "Read-ahead success for size ${READ_SIZE}"
6384         fi
6385 }
6386
6387 test_101b() {
6388         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6389         [[ $OSTCOUNT -lt 2 ]] &&
6390                 skip_env "skipping stride IO stride-ahead test" && return
6391         local STRIPE_SIZE=1048576
6392         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6393         if [ $SLOW == "yes" ]; then
6394                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6395         else
6396                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6397         fi
6398
6399         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6400
6401         # prepare the read-ahead file
6402         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6403         cancel_lru_locks osc
6404         for BIDX in 2 4 8 16 32 64 128 256
6405         do
6406                 local BSIZE=$((BIDX*4096))
6407                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6408                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6409                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6410                 $LCTL set_param -n llite.*.read_ahead_stats 0
6411                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6412                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6413                 cancel_lru_locks osc
6414                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6415         done
6416         cleanup_test101bc
6417         true
6418 }
6419 run_test 101b "check stride-io mode read-ahead ================="
6420
6421 test_101c() {
6422         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6423         local STRIPE_SIZE=1048576
6424         local FILE_LENGTH=$((STRIPE_SIZE*100))
6425         local nreads=10000
6426         local osc_rpc_stats
6427
6428         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6429
6430         cancel_lru_locks osc
6431         $LCTL set_param osc.*.rpc_stats 0
6432         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6433         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6434                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6435                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6436                 local size
6437
6438                 if [ $lines -le 20 ]; then
6439                         continue
6440                 fi
6441                 for size in 1 2 4 8; do
6442                         local rpc=$(echo "$stats" |
6443                                     awk '($1 == "'$size':") {print $2; exit; }')
6444                         [ $rpc != 0 ] &&
6445                                 error "Small $((size*4))k read IO $rpc !"
6446                 done
6447                 echo "$osc_rpc_stats check passed!"
6448         done
6449         cleanup_test101bc
6450         true
6451 }
6452 run_test 101c "check stripe_size aligned read-ahead ================="
6453
6454 set_read_ahead() {
6455         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6456         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6457 }
6458
6459 test_101d() {
6460         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6461         local file=$DIR/$tfile
6462         local sz_MB=${FILESIZE_101d:-500}
6463         local ra_MB=${READAHEAD_MB:-40}
6464
6465         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6466         [ $free_MB -lt $sz_MB ] &&
6467                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6468
6469         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6470         $SETSTRIPE -c -1 $file || error "setstripe failed"
6471
6472         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6473         echo Cancel LRU locks on lustre client to flush the client cache
6474         cancel_lru_locks osc
6475
6476         echo Disable read-ahead
6477         local old_READAHEAD=$(set_read_ahead 0)
6478
6479         echo Reading the test file $file with read-ahead disabled
6480         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6481
6482         echo Cancel LRU locks on lustre client to flush the client cache
6483         cancel_lru_locks osc
6484         echo Enable read-ahead with ${ra_MB}MB
6485         set_read_ahead $ra_MB
6486
6487         echo Reading the test file $file with read-ahead enabled
6488         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6489
6490         echo "read-ahead disabled time read $raOFF"
6491         echo "read-ahead enabled  time read $raON"
6492
6493         set_read_ahead $old_READAHEAD
6494         rm -f $file
6495         wait_delete_completed
6496
6497         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6498                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6499 }
6500 run_test 101d "file read with and without read-ahead enabled"
6501
6502 test_101e() {
6503         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6504         local file=$DIR/$tfile
6505         local size_KB=500  #KB
6506         local count=100
6507         local bsize=1024
6508
6509         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6510         local need_KB=$((count * size_KB))
6511         [[ $free_KB -le $need_KB ]] &&
6512                 skip_env "Need free space $need_KB, have $free_KB" && return
6513
6514         echo "Creating $count ${size_KB}K test files"
6515         for ((i = 0; i < $count; i++)); do
6516                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6517         done
6518
6519         echo "Cancel LRU locks on lustre client to flush the client cache"
6520         cancel_lru_locks osc
6521
6522         echo "Reset readahead stats"
6523         $LCTL set_param -n llite.*.read_ahead_stats 0
6524
6525         for ((i = 0; i < $count; i++)); do
6526                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6527         done
6528
6529         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6530                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6531
6532         for ((i = 0; i < $count; i++)); do
6533                 rm -rf $file.$i 2>/dev/null
6534         done
6535
6536         #10000 means 20% reads are missing in readahead
6537         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6538 }
6539 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6540
6541 cleanup_test101f() {
6542     trap 0
6543     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6544     rm -rf $DIR/$tfile 2>/dev/null
6545 }
6546
6547 test_101f() {
6548         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6549     local file=$DIR/$tfile
6550     local nreads=1000
6551
6552     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6553     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6554     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6555     trap cleanup_test101f EXIT
6556
6557     echo Cancel LRU locks on lustre client to flush the client cache
6558     cancel_lru_locks osc
6559
6560     echo Reset readahead stats
6561     $LCTL set_param -n llite.*.read_ahead_stats 0
6562     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6563     # readahead should read in 2M file on second read, so only miss
6564     # 2 pages.
6565     echo Random 4K reads on 2M file for 1000 times
6566     $READS -f $file -s 2097152 -b 4096 -n $nreads
6567
6568     echo checking missing pages
6569     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6570           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6571
6572     [ $miss -lt 3 ] || error "misses too much pages!"
6573     cleanup_test101f
6574 }
6575 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6576
6577 setup_test102() {
6578         test_mkdir -p $DIR/$tdir
6579         chown $RUNAS_ID $DIR/$tdir
6580         STRIPE_SIZE=65536
6581         STRIPE_OFFSET=1
6582         STRIPE_COUNT=$OSTCOUNT
6583         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6584
6585         trap cleanup_test102 EXIT
6586         cd $DIR
6587         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6588         cd $DIR/$tdir
6589         for num in 1 2 3 4; do
6590                 for count in $(seq 1 $STRIPE_COUNT); do
6591                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6592                                 local size=`expr $STRIPE_SIZE \* $num`
6593                                 local file=file"$num-$idx-$count"
6594                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6595                         done
6596                 done
6597         done
6598
6599         cd $DIR
6600         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6601 }
6602
6603 cleanup_test102() {
6604         trap 0
6605         rm -f $TMP/f102.tar
6606         rm -rf $DIR/d0.sanity/d102
6607 }
6608
6609 test_102a() {
6610         local testfile=$DIR/$tfile
6611
6612         touch $testfile
6613
6614         [ "$UID" != 0 ] && skip_env "must run as root" && return
6615         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6616                 skip_env "must have user_xattr" && return
6617
6618         [ -z "$(which setfattr 2>/dev/null)" ] &&
6619                 skip_env "could not find setfattr" && return
6620
6621         echo "set/get xattr..."
6622         setfattr -n trusted.name1 -v value1 $testfile ||
6623                 error "setfattr -n trusted.name1=value1 $testfile failed"
6624         getfattr -n trusted.name1 $testfile 2> /dev/null |
6625           grep "trusted.name1=.value1" ||
6626                 error "$testfile missing trusted.name1=value1"
6627
6628         setfattr -n user.author1 -v author1 $testfile ||
6629                 error "setfattr -n user.author1=author1 $testfile failed"
6630         getfattr -n user.author1 $testfile 2> /dev/null |
6631           grep "user.author1=.author1" ||
6632                 error "$testfile missing trusted.author1=author1"
6633
6634         echo "listxattr..."
6635         setfattr -n trusted.name2 -v value2 $testfile ||
6636                 error "$testfile unable to set trusted.name2"
6637         setfattr -n trusted.name3 -v value3 $testfile ||
6638                 error "$testfile unable to set trusted.name3"
6639         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6640             grep "trusted.name" | wc -l) -eq 3 ] ||
6641                 error "$testfile missing 3 trusted.name xattrs"
6642
6643         setfattr -n user.author2 -v author2 $testfile ||
6644                 error "$testfile unable to set user.author2"
6645         setfattr -n user.author3 -v author3 $testfile ||
6646                 error "$testfile unable to set user.author3"
6647         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6648             grep "user.author" | wc -l) -eq 3 ] ||
6649                 error "$testfile missing 3 user.author xattrs"
6650
6651         echo "remove xattr..."
6652         setfattr -x trusted.name1 $testfile ||
6653                 error "$testfile error deleting trusted.name1"
6654         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6655                 error "$testfile did not delete trusted.name1 xattr"
6656
6657         setfattr -x user.author1 $testfile ||
6658                 error "$testfile error deleting user.author1"
6659         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6660                 error "$testfile did not delete trusted.name1 xattr"
6661
6662         # b10667: setting lustre special xattr be silently discarded
6663         echo "set lustre special xattr ..."
6664         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6665                 error "$testfile allowed setting trusted.lov"
6666 }
6667 run_test 102a "user xattr test =================================="
6668
6669 test_102b() {
6670         [ -z "$(which setfattr 2>/dev/null)" ] &&
6671                 skip_env "could not find setfattr" && return
6672
6673         # b10930: get/set/list trusted.lov xattr
6674         echo "get/set/list trusted.lov xattr ..."
6675         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6676         local testfile=$DIR/$tfile
6677         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6678                 error "setstripe failed"
6679         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6680                 error "getstripe failed"
6681         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6682                 error "can't get trusted.lov from $testfile"
6683
6684         local testfile2=${testfile}2
6685         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6686                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6687
6688         $MCREATE $testfile2
6689         setfattr -n trusted.lov -v $value $testfile2
6690         local stripe_size=$($GETSTRIPE -S $testfile2)
6691         local stripe_count=$($GETSTRIPE -c $testfile2)
6692         [[ $stripe_size -eq 65536 ]] ||
6693                 error "stripe size $stripe_size != 65536"
6694         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6695                 error "stripe count $stripe_count != $STRIPECOUNT"
6696         rm -f $DIR/$tfile
6697 }
6698 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6699
6700 test_102c() {
6701         [ -z "$(which setfattr 2>/dev/null)" ] &&
6702                 skip_env "could not find setfattr" && return
6703
6704         # b10930: get/set/list lustre.lov xattr
6705         echo "get/set/list lustre.lov xattr ..."
6706         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6707         test_mkdir -p $DIR/$tdir
6708         chown $RUNAS_ID $DIR/$tdir
6709         local testfile=$DIR/$tdir/$tfile
6710         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6711                 error "setstripe failed"
6712         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6713                 error "getstripe failed"
6714         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6715         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6716
6717         local testfile2=${testfile}2
6718         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6719                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6720
6721         $RUNAS $MCREATE $testfile2
6722         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6723         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6724         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6725         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6726         [ $stripe_count -eq $STRIPECOUNT ] ||
6727                 error "stripe count $stripe_count != $STRIPECOUNT"
6728 }
6729 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6730
6731 compare_stripe_info1() {
6732         local stripe_index_all_zero=true
6733
6734         for num in 1 2 3 4; do
6735                 for count in $(seq 1 $STRIPE_COUNT); do
6736                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6737                                 local size=$((STRIPE_SIZE * num))
6738                                 local file=file"$num-$offset-$count"
6739                                 stripe_size=$($LFS getstripe -S $PWD/$file)
6740                                 [[ $stripe_size -ne $size ]] &&
6741                                     error "$file: size $stripe_size != $size"
6742                                 stripe_count=$($LFS getstripe -c $PWD/$file)
6743                                 # allow fewer stripes to be created, ORI-601
6744                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6745                                     error "$file: count $stripe_count != $count"
6746                                 stripe_index=$($LFS getstripe -i $PWD/$file)
6747                                 [[ $stripe_index -ne 0 ]] &&
6748                                         stripe_index_all_zero=false
6749                         done
6750                 done
6751         done
6752         $stripe_index_all_zero &&
6753                 error "all files are being extracted starting from OST index 0"
6754         return 0
6755 }
6756
6757 find_lustre_tar() {
6758         [ -n "$(which tar 2>/dev/null)" ] &&
6759                 strings $(which tar) | grep -q "lustre" && echo tar
6760 }
6761
6762 test_102d() {
6763         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6764         # b10930: tar test for trusted.lov xattr
6765         TAR=$(find_lustre_tar)
6766         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6767         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6768         setup_test102
6769         test_mkdir -p $DIR/d102d
6770         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6771         cd $DIR/d102d/$tdir
6772         compare_stripe_info1
6773 }
6774 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6775
6776 test_102f() {
6777         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6778         # b10930: tar test for trusted.lov xattr
6779         TAR=$(find_lustre_tar)
6780         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6781         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6782         setup_test102
6783         test_mkdir -p $DIR/d102f
6784         cd $DIR
6785         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6786         cd $DIR/d102f/$tdir
6787         compare_stripe_info1
6788 }
6789 run_test 102f "tar copy files, not keep osts ==========="
6790
6791 grow_xattr() {
6792         local xsize=${1:-1024}  # in bytes
6793         local file=$DIR/$tfile
6794
6795         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep xattr)" ] &&
6796                 skip "must have user_xattr" && return 0
6797         [ -z "$(which setfattr 2>/dev/null)" ] &&
6798                 skip_env "could not find setfattr" && return 0
6799         [ -z "$(which getfattr 2>/dev/null)" ] &&
6800                 skip_env "could not find getfattr" && return 0
6801
6802         touch $file
6803
6804         local value="$(generate_string $xsize)"
6805
6806         local xbig=trusted.big
6807         log "save $xbig on $file"
6808         setfattr -n $xbig -v $value $file ||
6809                 error "saving $xbig on $file failed"
6810
6811         local orig=$(get_xattr_value $xbig $file)
6812         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6813
6814         local xsml=trusted.sml
6815         log "save $xsml on $file"
6816         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6817
6818         local new=$(get_xattr_value $xbig $file)
6819         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6820
6821         log "grow $xsml on $file"
6822         setfattr -n $xsml -v "$value" $file ||
6823                 error "growing $xsml on $file failed"
6824
6825         new=$(get_xattr_value $xbig $file)
6826         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6827         log "$xbig still valid after growing $xsml"
6828
6829         rm -f $file
6830 }
6831
6832 test_102h() { # bug 15777
6833         grow_xattr 1024
6834 }
6835 run_test 102h "grow xattr from inside inode to external block"
6836
6837 test_102ha() {
6838         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6839         grow_xattr $(max_xattr_size)
6840 }
6841 run_test 102ha "grow xattr from inside inode to external inode"
6842
6843 test_102i() { # bug 17038
6844         [ -z "$(which getfattr 2>/dev/null)" ] &&
6845                 skip "could not find getfattr" && return
6846         touch $DIR/$tfile
6847         ln -s $DIR/$tfile $DIR/${tfile}link
6848         getfattr -n trusted.lov $DIR/$tfile ||
6849                 error "lgetxattr on $DIR/$tfile failed"
6850         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6851                 grep -i "no such attr" ||
6852                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6853         rm -f $DIR/$tfile $DIR/${tfile}link
6854 }
6855 run_test 102i "lgetxattr test on symbolic link ============"
6856
6857 test_102j() {
6858         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6859         TAR=$(find_lustre_tar)
6860         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6861         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6862         setup_test102 "$RUNAS"
6863         test_mkdir -p $DIR/d102j
6864         chown $RUNAS_ID $DIR/d102j
6865         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6866         cd $DIR/d102j/$tdir
6867         compare_stripe_info1 "$RUNAS"
6868 }
6869 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6870
6871 test_102k() {
6872         [ -z "$(which setfattr 2>/dev/null)" ] &&
6873                 skip "could not find setfattr" && return
6874         touch $DIR/$tfile
6875         # b22187 just check that does not crash for regular file.
6876         setfattr -n trusted.lov $DIR/$tfile
6877         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6878         local test_kdir=$DIR/d102k
6879         test_mkdir $test_kdir
6880         local default_size=`$GETSTRIPE -S $test_kdir`
6881         local default_count=`$GETSTRIPE -c $test_kdir`
6882         local default_offset=`$GETSTRIPE -i $test_kdir`
6883         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6884                 error 'dir setstripe failed'
6885         setfattr -n trusted.lov $test_kdir
6886         local stripe_size=`$GETSTRIPE -S $test_kdir`
6887         local stripe_count=`$GETSTRIPE -c $test_kdir`
6888         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6889         [ $stripe_size -eq $default_size ] ||
6890                 error "stripe size $stripe_size != $default_size"
6891         [ $stripe_count -eq $default_count ] ||
6892                 error "stripe count $stripe_count != $default_count"
6893         [ $stripe_offset -eq $default_offset ] ||
6894                 error "stripe offset $stripe_offset != $default_offset"
6895         rm -rf $DIR/$tfile $test_kdir
6896 }
6897 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6898
6899 test_102l() {
6900         [ -z "$(which getfattr 2>/dev/null)" ] &&
6901                 skip "could not find getfattr" && return
6902
6903         # LU-532 trusted. xattr is invisible to non-root
6904         local testfile=$DIR/$tfile
6905
6906         touch $testfile
6907
6908         echo "listxattr as user..."
6909         chown $RUNAS_ID $testfile
6910         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6911             grep -q "trusted" &&
6912                 error "$testfile trusted xattrs are user visible"
6913
6914         return 0;
6915 }
6916 run_test 102l "listxattr size test =================================="
6917
6918 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6919         local path=$DIR/$tfile
6920         touch $path
6921
6922         listxattr_size_check $path || error "listattr_size_check $path failed"
6923 }
6924 run_test 102m "Ensure listxattr fails on small bufffer ========"
6925
6926 cleanup_test102
6927
6928 getxattr() { # getxattr path name
6929         # Return the base64 encoding of the value of xattr name on path.
6930         local path=$1
6931         local name=$2
6932
6933         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6934         # file: $path
6935         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6936         #
6937         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6938
6939         getfattr --absolute-names --encoding=base64 --name=$name $path |
6940                 awk -F= -v name=$name '$1 == name {
6941                         print substr($0, index($0, "=") + 1);
6942         }'
6943 }
6944
6945 test_102n() { # LU-4101 mdt: protect internal xattrs
6946         local file0=$DIR/$tfile.0
6947         local file1=$DIR/$tfile.1
6948         local xattr0=$TMP/$tfile.0
6949         local xattr1=$TMP/$tfile.1
6950         local name
6951         local value
6952
6953         [ -z "$(which setfattr 2>/dev/null)" ] &&
6954                 skip "could not find setfattr" && return
6955
6956         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6957         then
6958                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6959                 return
6960         fi
6961
6962         rm -rf $file0 $file1 $xattr0 $xattr1
6963         touch $file0 $file1
6964
6965         # Get 'before' xattrs of $file1.
6966         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6967
6968         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6969                 # Try to copy xattr from $file0 to $file1.
6970                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6971
6972                 setfattr --name=trusted.$name --value="$value" $file1 ||
6973                         error "setxattr 'trusted.$name' failed"
6974
6975                 # Try to set a garbage xattr.
6976                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6977
6978                 setfattr --name=trusted.$name --value="$value" $file1 ||
6979                         error "setxattr 'trusted.$name' failed"
6980
6981                 # Try to remove the xattr from $file1. We don't care if this
6982                 # appears to succeed or fail, we just don't want there to be
6983                 # any changes or crashes.
6984                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6985         done
6986
6987         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
6988         then
6989                 name="lfsck_ns"
6990                 # Try to copy xattr from $file0 to $file1.
6991                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6992
6993                 setfattr --name=trusted.$name --value="$value" $file1 ||
6994                         error "setxattr 'trusted.$name' failed"
6995
6996                 # Try to set a garbage xattr.
6997                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6998
6999                 setfattr --name=trusted.$name --value="$value" $file1 ||
7000                         error "setxattr 'trusted.$name' failed"
7001
7002                 # Try to remove the xattr from $file1. We don't care if this
7003                 # appears to succeed or fail, we just don't want there to be
7004                 # any changes or crashes.
7005                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7006         fi
7007
7008         # Get 'after' xattrs of file1.
7009         getfattr --absolute-names --dump --match=- $file1 > $xattr1
7010
7011         if ! diff $xattr0 $xattr1; then
7012                 error "before and after xattrs of '$file1' differ"
7013         fi
7014
7015         rm -rf $file0 $file1 $xattr0 $xattr1
7016
7017         return 0
7018 }
7019 run_test 102n "silently ignore setxattr on internal trusted xattrs"
7020
7021 test_102p() { # LU-4703 setxattr did not check ownership
7022         local testfile=$DIR/$tfile
7023
7024         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
7025                 skip "MDS needs to be at least 2.5.56" && return
7026
7027         touch $testfile
7028
7029         echo "setfacl as user..."
7030         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
7031         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
7032
7033         echo "setfattr as user..."
7034         setfacl -m "u:$RUNAS_ID:---" $testfile
7035         $RUNAS setfattr -x system.posix_acl_access $testfile
7036         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
7037 }
7038 run_test 102p "check setxattr(2) correctly fails without permission"
7039
7040 test_102q() {
7041         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
7042                 skip "MDS needs to be at least 2.6.92" && return
7043         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
7044 }
7045 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
7046
7047 test_102r() {
7048         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
7049                 skip "MDS needs to be at least 2.6.93" && return
7050         touch $DIR/$tfile || error "touch"
7051         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
7052         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
7053         rm $DIR/$tfile || error "rm"
7054
7055         #normal directory
7056         mkdir -p $DIR/$tdir || error "mkdir"
7057         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7058         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7059         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7060                 error "$testfile error deleting user.author1"
7061         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7062                 grep "user.$(basename $tdir)" &&
7063                 error "$tdir did not delete user.$(basename $tdir)"
7064         rmdir $DIR/$tdir || error "rmdir"
7065
7066         #striped directory
7067         test_mkdir -p $DIR/$tdir || error "make striped dir"
7068         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7069         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7070         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7071                 error "$testfile error deleting user.author1"
7072         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7073                 grep "user.$(basename $tdir)" &&
7074                 error "$tdir did not delete user.$(basename $tdir)"
7075         rmdir $DIR/$tdir || error "rm striped dir"
7076 }
7077 run_test 102r "set EAs with empty values"
7078
7079 run_acl_subtest()
7080 {
7081     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
7082     return $?
7083 }
7084
7085 test_103a() {
7086         [ "$UID" != 0 ] && skip_env "must run as root" && return
7087         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
7088                 skip "must have acl enabled" && return
7089         [ -z "$(which setfacl 2>/dev/null)" ] &&
7090                 skip_env "could not find setfacl" && return
7091         $GSS && skip "could not run under gss" && return
7092
7093         gpasswd -a daemon bin                           # LU-5641
7094         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
7095
7096         declare -a identity_old
7097
7098         for num in $(seq $MDSCOUNT); do
7099                 switch_identity $num true || identity_old[$num]=$?
7100         done
7101
7102         SAVE_UMASK=$(umask)
7103         umask 0022
7104         cd $DIR
7105
7106         echo "performing cp ..."
7107         run_acl_subtest cp || error "run_acl_subtest cp failed"
7108         echo "performing getfacl-noacl..."
7109         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
7110         echo "performing misc..."
7111         run_acl_subtest misc || error  "misc test failed"
7112         echo "performing permissions..."
7113         run_acl_subtest permissions || error "permissions failed"
7114         echo "performing setfacl..."
7115         run_acl_subtest setfacl || error  "setfacl test failed"
7116
7117         # inheritance test got from HP
7118         echo "performing inheritance..."
7119         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
7120         chmod +x make-tree || error "chmod +x failed"
7121         run_acl_subtest inheritance || error "inheritance test failed"
7122         rm -f make-tree
7123
7124         echo "LU-974 ignore umask when acl is enabled..."
7125         run_acl_subtest 974 || error "LU-974 umask test failed"
7126         if [ $MDSCOUNT -ge 2 ]; then
7127                 run_acl_subtest 974_remote ||
7128                         error "LU-974 umask test failed under remote dir"
7129         fi
7130
7131         echo "LU-2561 newly created file is same size as directory..."
7132         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
7133                 run_acl_subtest 2561 || error "LU-2561 test failed"
7134         else
7135                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
7136         fi
7137
7138         run_acl_subtest 4924 || error "LU-4924 test failed"
7139
7140         cd $SAVE_PWD
7141         umask $SAVE_UMASK
7142
7143         for num in $(seq $MDSCOUNT); do
7144                 if [ "${identity_old[$num]}" = 1 ]; then
7145                         switch_identity $num false || identity_old[$num]=$?
7146                 fi
7147         done
7148 }
7149 run_test 103a "acl test ========================================="
7150
7151 test_103b() {
7152         local noacl=false
7153         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
7154         local mountopts=$MDS_MOUNT_OPTS
7155
7156         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
7157                 noacl=true
7158         else
7159                 # stop the MDT
7160                 stop $SINGLEMDS || error "failed to stop MDT."
7161                 # remount the MDT
7162                 if [ -z "$MDS_MOUNT_OPTS" ]; then
7163                         MDS_MOUNT_OPTS="-o noacl"
7164                 else
7165                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
7166                 fi
7167                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7168                         error "failed to start MDT."
7169                 MDS_MOUNT_OPTS=$mountopts
7170         fi
7171
7172         touch $DIR/$tfile
7173         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
7174
7175         if ! $noacl; then
7176                 # stop the MDT
7177                 stop $SINGLEMDS || error "failed to stop MDT."
7178                 # remount the MDT
7179                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7180                         error "failed to start MDT."
7181         fi
7182
7183         true
7184 }
7185 run_test 103b "MDS mount option 'noacl'"
7186
7187 test_103c() {
7188         mkdir -p $DIR/$tdir
7189         cp -rp $DIR/$tdir $DIR/$tdir.bak
7190
7191         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
7192                 error "$DIR/$tdir shouldn't contain default ACL"
7193         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
7194                 error "$DIR/$tdir.bak shouldn't contain default ACL"
7195         true
7196 }
7197 run_test 103c "'cp -rp' won't set empty acl"
7198
7199 test_104a() {
7200         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7201         touch $DIR/$tfile
7202         lfs df || error "lfs df failed"
7203         lfs df -ih || error "lfs df -ih failed"
7204         lfs df -h $DIR || error "lfs df -h $DIR failed"
7205         lfs df -i $DIR || error "lfs df -i $DIR failed"
7206         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
7207         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
7208
7209         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
7210         lctl --device %$OSC deactivate
7211         lfs df || error "lfs df with deactivated OSC failed"
7212         lctl --device %$OSC activate
7213         # wait the osc back to normal
7214         wait_osc_import_state client ost FULL
7215
7216         lfs df || error "lfs df with reactivated OSC failed"
7217         rm -f $DIR/$tfile
7218 }
7219 run_test 104a "lfs df [-ih] [path] test ========================="
7220
7221 test_104b() {
7222         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7223         [ $RUNAS_ID -eq $UID ] &&
7224                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
7225         chmod 666 /dev/obd
7226         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
7227                         grep "Permission denied" | wc -l)))
7228         if [ $denied_cnt -ne 0 ]; then
7229                 error "lfs check servers test failed"
7230         fi
7231 }
7232 run_test 104b "$RUNAS lfs check servers test ===================="
7233
7234 test_105a() {
7235         # doesn't work on 2.4 kernels
7236         touch $DIR/$tfile
7237         if $(flock_is_enabled); then
7238                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7239         else
7240                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7241         fi
7242         rm -f $DIR/$tfile
7243 }
7244 run_test 105a "flock when mounted without -o flock test ========"
7245
7246 test_105b() {
7247         touch $DIR/$tfile
7248         if $(flock_is_enabled); then
7249                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7250         else
7251                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7252         fi
7253         rm -f $DIR/$tfile
7254 }
7255 run_test 105b "fcntl when mounted without -o flock test ========"
7256
7257 test_105c() {
7258         touch $DIR/$tfile
7259         if $(flock_is_enabled); then
7260                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7261         else
7262                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7263         fi
7264         rm -f $DIR/$tfile
7265 }
7266 run_test 105c "lockf when mounted without -o flock test ========"
7267
7268 test_105d() { # bug 15924
7269         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7270         test_mkdir -p $DIR/$tdir
7271         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7272         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7273         $LCTL set_param fail_loc=0x80000315
7274         flocks_test 2 $DIR/$tdir
7275 }
7276 run_test 105d "flock race (should not freeze) ========"
7277
7278 test_105e() { # bug 22660 && 22040
7279         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7280         touch $DIR/$tfile
7281         flocks_test 3 $DIR/$tfile
7282 }
7283 run_test 105e "Two conflicting flocks from same process ======="
7284
7285 test_106() { #bug 10921
7286         test_mkdir -p $DIR/$tdir
7287         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7288         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7289 }
7290 run_test 106 "attempt exec of dir followed by chown of that dir"
7291
7292 test_107() {
7293         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7294         CDIR=`pwd`
7295         cd $DIR
7296
7297         local file=core
7298         rm -f $file
7299
7300         local save_pattern=$(sysctl -n kernel.core_pattern)
7301         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7302         sysctl -w kernel.core_pattern=$file
7303         sysctl -w kernel.core_uses_pid=0
7304
7305         ulimit -c unlimited
7306         sleep 60 &
7307         SLEEPPID=$!
7308
7309         sleep 1
7310
7311         kill -s 11 $SLEEPPID
7312         wait $SLEEPPID
7313         if [ -e $file ]; then
7314                 size=`stat -c%s $file`
7315                 [ $size -eq 0 ] && error "Fail to create core file $file"
7316         else
7317                 error "Fail to create core file $file"
7318         fi
7319         rm -f $file
7320         sysctl -w kernel.core_pattern=$save_pattern
7321         sysctl -w kernel.core_uses_pid=$save_uses_pid
7322         cd $CDIR
7323 }
7324 run_test 107 "Coredump on SIG"
7325
7326 test_110() {
7327         test_mkdir -p $DIR/$tdir
7328         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7329                 error "mkdir with 255 char failed"
7330         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7331                 error "mkdir with 256 char should fail, but did not"
7332         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7333                 error "create with 255 char failed"
7334         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7335                 error "create with 256 char should fail, but did not"
7336
7337         ls -l $DIR/$tdir
7338         rm -rf $DIR/$tdir
7339 }
7340 run_test 110 "filename length checking"
7341
7342 test_115() {
7343         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7344         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
7345                 tail -1 | cut -c11-20)
7346         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
7347         echo "Starting with $OSTIO_pre threads"
7348
7349         NUMTEST=20000
7350         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7351         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
7352         echo "$NUMTEST creates/unlinks"
7353         test_mkdir -p $DIR/$tdir
7354         createmany -o $DIR/$tdir/$tfile $NUMTEST
7355         unlinkmany $DIR/$tdir/$tfile $NUMTEST
7356
7357         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
7358                 tail -1 | cut -c11-20)
7359
7360         # don't return an error
7361         [ $OSTIO_post == $OSTIO_pre ] && echo \
7362             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
7363             echo "This may be fine, depending on what ran before this test" &&
7364             echo "and how fast this system is." && return
7365
7366         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
7367 }
7368 run_test 115 "verify dynamic thread creation===================="
7369
7370 free_min_max () {
7371         wait_delete_completed
7372         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7373         echo OST kbytes available: ${AVAIL[@]}
7374         MAXI=0; MAXV=${AVAIL[0]}
7375         MINI=0; MINV=${AVAIL[0]}
7376         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7377                 #echo OST $i: ${AVAIL[i]}kb
7378                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7379                         MAXV=${AVAIL[i]}; MAXI=$i
7380                 fi
7381                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7382                         MINV=${AVAIL[i]}; MINI=$i
7383                 fi
7384         done
7385         echo Min free space: OST $MINI: $MINV
7386         echo Max free space: OST $MAXI: $MAXV
7387 }
7388
7389 test_116a() { # was previously test_116()
7390         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7391         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7392
7393         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
7394
7395         echo -n "Free space priority "
7396         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7397                 head -n1
7398         declare -a AVAIL
7399         free_min_max
7400
7401         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7402         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7403                 && return
7404         trap simple_cleanup_common EXIT
7405
7406
7407         # Check if we need to generate uneven OSTs
7408         test_mkdir -p $DIR/$tdir/OST${MINI}
7409         local FILL=$(($MINV / 4))
7410         local DIFF=$(($MAXV - $MINV))
7411         local DIFF2=$(($DIFF * 100 / $MINV))
7412
7413         local threshold=$(do_facet $SINGLEMDS \
7414                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7415         threshold=${threshold%%%}
7416         echo -n "Check for uneven OSTs: "
7417         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7418
7419         if [[ $DIFF2 -gt $threshold ]]; then
7420                 echo "ok"
7421                 echo "Don't need to fill OST$MINI"
7422         else
7423                 # generate uneven OSTs. Write 2% over the QOS threshold value
7424                 echo "no"
7425                 DIFF=$(($threshold - $DIFF2 + 2))
7426                 DIFF2=$(( ($MINV * $DIFF)/100 ))
7427                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
7428                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7429                         error "setstripe failed"
7430                 DIFF=$(($DIFF2 / 2048))
7431                 i=0
7432                 while [ $i -lt $DIFF ]; do
7433                         i=$(($i + 1))
7434                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7435                                 bs=2M count=1 2>/dev/null
7436                         echo -n .
7437                 done
7438                 echo .
7439                 sync
7440                 sleep_maxage
7441                 free_min_max
7442         fi
7443
7444         DIFF=$(($MAXV - $MINV))
7445         DIFF2=$(($DIFF * 100 / $MINV))
7446         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
7447         if [[ $DIFF2 -gt $threshold ]]; then
7448                 echo "ok"
7449         else
7450                 echo "failed - QOS mode won't be used"
7451                 skip "QOS imbalance criteria not met"
7452                 simple_cleanup_common
7453                 return
7454         fi
7455
7456         MINI1=$MINI; MINV1=$MINV
7457         MAXI1=$MAXI; MAXV1=$MAXV
7458
7459         # now fill using QOS
7460         $SETSTRIPE -c 1 $DIR/$tdir
7461         FILL=$(($FILL / 200))
7462         if [ $FILL -gt 600 ]; then
7463                 FILL=600
7464         fi
7465         echo "writing $FILL files to QOS-assigned OSTs"
7466         i=0
7467         while [ $i -lt $FILL ]; do
7468                 i=$((i + 1))
7469                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7470                         count=1 2>/dev/null
7471                 echo -n .
7472         done
7473         echo "wrote $i 200k files"
7474         sync
7475         sleep_maxage
7476
7477         echo "Note: free space may not be updated, so measurements might be off"
7478         free_min_max
7479         DIFF2=$(($MAXV - $MINV))
7480         echo "free space delta: orig $DIFF final $DIFF2"
7481         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7482         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
7483         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7484         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
7485         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7486         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7487         [ $DIFF -gt 0 ] &&
7488                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7489
7490         # Figure out which files were written where
7491         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7492                   awk '/'$MINI1': / {print $2; exit}')
7493         echo $UUID
7494         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7495         echo "$MINC files created on smaller OST $MINI1"
7496         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7497                   awk '/'$MAXI1': / {print $2; exit}')
7498         echo $UUID
7499         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7500         echo "$MAXC files created on larger OST $MAXI1"
7501         FILL=$(($MAXC * 100 / $MINC - 100))
7502         [[ $MINC -gt 0 ]] &&
7503                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7504         [[ $MAXC -gt $MINC ]] ||
7505                 error_ignore LU-9 "stripe QOS didn't balance free space"
7506         simple_cleanup_common
7507 }
7508 run_test 116a "stripe QOS: free space balance ==================="
7509
7510 test_116b() { # LU-2093
7511         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7512         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7513
7514 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7515         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7516                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7517         [ -z "$old_rr" ] && skip "no QOS" && return 0
7518         do_facet $SINGLEMDS lctl set_param \
7519                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7520         mkdir -p $DIR/$tdir
7521         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7522         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7523         do_facet $SINGLEMDS lctl set_param fail_loc=0
7524         rm -rf $DIR/$tdir
7525         do_facet $SINGLEMDS lctl set_param \
7526                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7527 }
7528 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7529
7530 test_117() # bug 10891
7531 {
7532         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7533         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7534         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7535         lctl set_param fail_loc=0x21e
7536         > $DIR/$tfile || error "truncate failed"
7537         lctl set_param fail_loc=0
7538         echo "Truncate succeeded."
7539         rm -f $DIR/$tfile
7540 }
7541 run_test 117 "verify osd extend =========="
7542
7543 NO_SLOW_RESENDCOUNT=4
7544 export OLD_RESENDCOUNT=""
7545 set_resend_count () {
7546         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7547         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7548         lctl set_param -n $PROC_RESENDCOUNT $1
7549         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7550 }
7551
7552 # for reduce test_118* time (b=14842)
7553 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7554
7555 # Reset async IO behavior after error case
7556 reset_async() {
7557         FILE=$DIR/reset_async
7558
7559         # Ensure all OSCs are cleared
7560         $SETSTRIPE -c -1 $FILE
7561         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7562         sync
7563         rm $FILE
7564 }
7565
7566 test_118a() #bug 11710
7567 {
7568         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7569         reset_async
7570
7571         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7572         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7573         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7574
7575         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7576                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7577                 return 1;
7578         fi
7579         rm -f $DIR/$tfile
7580 }
7581 run_test 118a "verify O_SYNC works =========="
7582
7583 test_118b()
7584 {
7585         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7586         remote_ost_nodsh && skip "remote OST with nodsh" && return
7587
7588         reset_async
7589
7590         #define OBD_FAIL_SRV_ENOENT 0x217
7591         set_nodes_failloc "$(osts_nodes)" 0x217
7592         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7593         RC=$?
7594         set_nodes_failloc "$(osts_nodes)" 0
7595         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7596         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7597                     grep -c writeback)
7598
7599         if [[ $RC -eq 0 ]]; then
7600                 error "Must return error due to dropped pages, rc=$RC"
7601                 return 1;
7602         fi
7603
7604         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7605                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7606                 return 1;
7607         fi
7608
7609         echo "Dirty pages not leaked on ENOENT"
7610
7611         # Due to the above error the OSC will issue all RPCs syncronously
7612         # until a subsequent RPC completes successfully without error.
7613         $MULTIOP $DIR/$tfile Ow4096yc
7614         rm -f $DIR/$tfile
7615
7616         return 0
7617 }
7618 run_test 118b "Reclaim dirty pages on fatal error =========="
7619
7620 test_118c()
7621 {
7622         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7623
7624         # for 118c, restore the original resend count, LU-1940
7625         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7626                                 set_resend_count $OLD_RESENDCOUNT
7627         remote_ost_nodsh && skip "remote OST with nodsh" && return
7628
7629         reset_async
7630
7631         #define OBD_FAIL_OST_EROFS               0x216
7632         set_nodes_failloc "$(osts_nodes)" 0x216
7633
7634         # multiop should block due to fsync until pages are written
7635         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7636         MULTIPID=$!
7637         sleep 1
7638
7639         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7640                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7641         fi
7642
7643         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7644                     grep -c writeback)
7645         if [[ $WRITEBACK -eq 0 ]]; then
7646                 error "No page in writeback, writeback=$WRITEBACK"
7647         fi
7648
7649         set_nodes_failloc "$(osts_nodes)" 0
7650         wait $MULTIPID
7651         RC=$?
7652         if [[ $RC -ne 0 ]]; then
7653                 error "Multiop fsync failed, rc=$RC"
7654         fi
7655
7656         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7657         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7658                     grep -c writeback)
7659         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7660                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7661         fi
7662
7663         rm -f $DIR/$tfile
7664         echo "Dirty pages flushed via fsync on EROFS"
7665         return 0
7666 }
7667 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7668
7669 # continue to use small resend count to reduce test_118* time (b=14842)
7670 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7671
7672 test_118d()
7673 {
7674         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7675         remote_ost_nodsh && skip "remote OST with nodsh" && return
7676
7677         reset_async
7678
7679         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7680         set_nodes_failloc "$(osts_nodes)" 0x214
7681         # multiop should block due to fsync until pages are written
7682         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7683         MULTIPID=$!
7684         sleep 1
7685
7686         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7687                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7688         fi
7689
7690         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7691                     grep -c writeback)
7692         if [[ $WRITEBACK -eq 0 ]]; then
7693                 error "No page in writeback, writeback=$WRITEBACK"
7694         fi
7695
7696         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7697         set_nodes_failloc "$(osts_nodes)" 0
7698
7699         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7700         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7701                     grep -c writeback)
7702         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7703                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7704         fi
7705
7706         rm -f $DIR/$tfile
7707         echo "Dirty pages gaurenteed flushed via fsync"
7708         return 0
7709 }
7710 run_test 118d "Fsync validation inject a delay of the bulk =========="
7711
7712 test_118f() {
7713         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7714         reset_async
7715
7716         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7717         lctl set_param fail_loc=0x8000040a
7718
7719         # Should simulate EINVAL error which is fatal
7720         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7721         RC=$?
7722         if [[ $RC -eq 0 ]]; then
7723                 error "Must return error due to dropped pages, rc=$RC"
7724         fi
7725
7726         lctl set_param fail_loc=0x0
7727
7728         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7729         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7730         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7731                     grep -c writeback)
7732         if [[ $LOCKED -ne 0 ]]; then
7733                 error "Locked pages remain in cache, locked=$LOCKED"
7734         fi
7735
7736         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7737                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7738         fi
7739
7740         rm -f $DIR/$tfile
7741         echo "No pages locked after fsync"
7742
7743         reset_async
7744         return 0
7745 }
7746 run_test 118f "Simulate unrecoverable OSC side error =========="
7747
7748 test_118g() {
7749         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7750         reset_async
7751
7752         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7753         lctl set_param fail_loc=0x406
7754
7755         # simulate local -ENOMEM
7756         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7757         RC=$?
7758
7759         lctl set_param fail_loc=0
7760         if [[ $RC -eq 0 ]]; then
7761                 error "Must return error due to dropped pages, rc=$RC"
7762         fi
7763
7764         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7765         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7766         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7767                         grep -c writeback)
7768         if [[ $LOCKED -ne 0 ]]; then
7769                 error "Locked pages remain in cache, locked=$LOCKED"
7770         fi
7771
7772         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7773                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7774         fi
7775
7776         rm -f $DIR/$tfile
7777         echo "No pages locked after fsync"
7778
7779         reset_async
7780         return 0
7781 }
7782 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7783
7784 test_118h() {
7785         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7786         remote_ost_nodsh && skip "remote OST with nodsh" && return
7787
7788         reset_async
7789
7790         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7791         set_nodes_failloc "$(osts_nodes)" 0x20e
7792         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7793         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7794         RC=$?
7795
7796         set_nodes_failloc "$(osts_nodes)" 0
7797         if [[ $RC -eq 0 ]]; then
7798                 error "Must return error due to dropped pages, rc=$RC"
7799         fi
7800
7801         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7802         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7803         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7804                     grep -c writeback)
7805         if [[ $LOCKED -ne 0 ]]; then
7806                 error "Locked pages remain in cache, locked=$LOCKED"
7807         fi
7808
7809         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7810                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7811         fi
7812
7813         rm -f $DIR/$tfile
7814         echo "No pages locked after fsync"
7815
7816         return 0
7817 }
7818 run_test 118h "Verify timeout in handling recoverables errors  =========="
7819
7820 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7821
7822 test_118i() {
7823         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7824         remote_ost_nodsh && skip "remote OST with nodsh" && return
7825
7826         reset_async
7827
7828         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7829         set_nodes_failloc "$(osts_nodes)" 0x20e
7830
7831         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7832         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7833         PID=$!
7834         sleep 5
7835         set_nodes_failloc "$(osts_nodes)" 0
7836
7837         wait $PID
7838         RC=$?
7839         if [[ $RC -ne 0 ]]; then
7840                 error "got error, but should be not, rc=$RC"
7841         fi
7842
7843         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7844         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7845         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7846         if [[ $LOCKED -ne 0 ]]; then
7847                 error "Locked pages remain in cache, locked=$LOCKED"
7848         fi
7849
7850         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7851                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7852         fi
7853
7854         rm -f $DIR/$tfile
7855         echo "No pages locked after fsync"
7856
7857         return 0
7858 }
7859 run_test 118i "Fix error before timeout in recoverable error  =========="
7860
7861 [ "$SLOW" = "no" ] && set_resend_count 4
7862
7863 test_118j() {
7864         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7865         remote_ost_nodsh && skip "remote OST with nodsh" && return
7866
7867         reset_async
7868
7869         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7870         set_nodes_failloc "$(osts_nodes)" 0x220
7871
7872         # return -EIO from OST
7873         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7874         RC=$?
7875         set_nodes_failloc "$(osts_nodes)" 0x0
7876         if [[ $RC -eq 0 ]]; then
7877                 error "Must return error due to dropped pages, rc=$RC"
7878         fi
7879
7880         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7881         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7882         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7883         if [[ $LOCKED -ne 0 ]]; then
7884                 error "Locked pages remain in cache, locked=$LOCKED"
7885         fi
7886
7887         # in recoverable error on OST we want resend and stay until it finished
7888         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7889                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7890         fi
7891
7892         rm -f $DIR/$tfile
7893         echo "No pages locked after fsync"
7894
7895         return 0
7896 }
7897 run_test 118j "Simulate unrecoverable OST side error =========="
7898
7899 test_118k()
7900 {
7901         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7902         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7903
7904         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7905         set_nodes_failloc "$(osts_nodes)" 0x20e
7906         test_mkdir -p $DIR/$tdir
7907
7908         for ((i=0;i<10;i++)); do
7909                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7910                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7911                 SLEEPPID=$!
7912                 sleep 0.500s
7913                 kill $SLEEPPID
7914                 wait $SLEEPPID
7915         done
7916
7917         set_nodes_failloc "$(osts_nodes)" 0
7918         rm -rf $DIR/$tdir
7919 }
7920 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7921
7922 test_118l()
7923 {
7924         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7925         # LU-646
7926         test_mkdir -p $DIR/$tdir
7927         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7928         rm -rf $DIR/$tdir
7929 }
7930 run_test 118l "fsync dir ========="
7931
7932 test_118m() # LU-3066
7933 {
7934         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7935         test_mkdir -p $DIR/$tdir
7936         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7937         rm -rf $DIR/$tdir
7938 }
7939 run_test 118m "fdatasync dir ========="
7940
7941 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7942
7943 test_119a() # bug 11737
7944 {
7945         BSIZE=$((512 * 1024))
7946         directio write $DIR/$tfile 0 1 $BSIZE
7947         # We ask to read two blocks, which is more than a file size.
7948         # directio will indicate an error when requested and actual
7949         # sizes aren't equeal (a normal situation in this case) and
7950         # print actual read amount.
7951         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7952         if [ "$NOB" != "$BSIZE" ]; then
7953                 error "read $NOB bytes instead of $BSIZE"
7954         fi
7955         rm -f $DIR/$tfile
7956 }
7957 run_test 119a "Short directIO read must return actual read amount"
7958
7959 test_119b() # bug 11737
7960 {
7961         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7962
7963         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7964         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7965         sync
7966         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7967                 error "direct read failed"
7968         rm -f $DIR/$tfile
7969 }
7970 run_test 119b "Sparse directIO read must return actual read amount"
7971
7972 test_119c() # bug 13099
7973 {
7974         BSIZE=1048576
7975         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7976         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7977         rm -f $DIR/$tfile
7978 }
7979 run_test 119c "Testing for direct read hitting hole"
7980
7981 test_119d() # bug 15950
7982 {
7983         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7984         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7985         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7986         BSIZE=1048576
7987         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7988         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7989         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
7990         lctl set_param fail_loc=0x40d
7991         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
7992         pid_dio=$!
7993         sleep 1
7994         cat $DIR/$tfile > /dev/null &
7995         lctl set_param fail_loc=0
7996         pid_reads=$!
7997         wait $pid_dio
7998         log "the DIO writes have completed, now wait for the reads (should not block very long)"
7999         sleep 2
8000         [ -n "`ps h -p $pid_reads -o comm`" ] && \
8001         error "the read rpcs have not completed in 2s"
8002         rm -f $DIR/$tfile
8003         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
8004 }
8005 run_test 119d "The DIO path should try to send a new rpc once one is completed"
8006
8007 test_120a() {
8008         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8009         test_mkdir -p $DIR/$tdir
8010         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8011                skip "no early lock cancel on server" && return 0
8012
8013         lru_resize_disable mdc
8014         lru_resize_disable osc
8015         cancel_lru_locks mdc
8016         # asynchronous object destroy at MDT could cause bl ast to client
8017         cancel_lru_locks osc
8018
8019         stat $DIR/$tdir > /dev/null
8020         can1=$(do_facet $SINGLEMDS \
8021                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8022                awk '/ldlm_cancel/ {print $2}')
8023         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8024                awk '/ldlm_bl_callback/ {print $2}')
8025         test_mkdir -c1 $DIR/$tdir/d1
8026         can2=$(do_facet $SINGLEMDS \
8027                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8028                awk '/ldlm_cancel/ {print $2}')
8029         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8030                awk '/ldlm_bl_callback/ {print $2}')
8031         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8032         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8033         lru_resize_enable mdc
8034         lru_resize_enable osc
8035 }
8036 run_test 120a "Early Lock Cancel: mkdir test"
8037
8038 test_120b() {
8039         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8040         test_mkdir $DIR/$tdir
8041         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8042                skip "no early lock cancel on server" && return 0
8043         lru_resize_disable mdc
8044         lru_resize_disable osc
8045         cancel_lru_locks mdc
8046         stat $DIR/$tdir > /dev/null
8047         can1=$(do_facet $SINGLEMDS \
8048                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8049                awk '/ldlm_cancel/ {print $2}')
8050         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8051                awk '/ldlm_bl_callback/ {print $2}')
8052         touch $DIR/$tdir/f1
8053         can2=$(do_facet $SINGLEMDS \
8054                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8055                awk '/ldlm_cancel/ {print $2}')
8056         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8057                awk '/ldlm_bl_callback/ {print $2}')
8058         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8059         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8060         lru_resize_enable mdc
8061         lru_resize_enable osc
8062 }
8063 run_test 120b "Early Lock Cancel: create test"
8064
8065 test_120c() {
8066         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8067         test_mkdir -c1 $DIR/$tdir
8068         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8069                skip "no early lock cancel on server" && return 0
8070         lru_resize_disable mdc
8071         lru_resize_disable osc
8072         test_mkdir -p -c1 $DIR/$tdir/d1
8073         test_mkdir -p -c1 $DIR/$tdir/d2
8074         touch $DIR/$tdir/d1/f1
8075         cancel_lru_locks mdc
8076         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
8077         can1=$(do_facet $SINGLEMDS \
8078                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8079                awk '/ldlm_cancel/ {print $2}')
8080         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8081                awk '/ldlm_bl_callback/ {print $2}')
8082         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8083         can2=$(do_facet $SINGLEMDS \
8084                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8085                awk '/ldlm_cancel/ {print $2}')
8086         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8087                awk '/ldlm_bl_callback/ {print $2}')
8088         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8089         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8090         lru_resize_enable mdc
8091         lru_resize_enable osc
8092 }
8093 run_test 120c "Early Lock Cancel: link test"
8094
8095 test_120d() {
8096         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8097         test_mkdir -p -c1 $DIR/$tdir
8098         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8099                skip "no early lock cancel on server" && return 0
8100         lru_resize_disable mdc
8101         lru_resize_disable osc
8102         touch $DIR/$tdir
8103         cancel_lru_locks mdc
8104         stat $DIR/$tdir > /dev/null
8105         can1=$(do_facet $SINGLEMDS \
8106                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8107                awk '/ldlm_cancel/ {print $2}')
8108         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8109                awk '/ldlm_bl_callback/ {print $2}')
8110         chmod a+x $DIR/$tdir
8111         can2=$(do_facet $SINGLEMDS \
8112                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8113                awk '/ldlm_cancel/ {print $2}')
8114         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8115                awk '/ldlm_bl_callback/ {print $2}')
8116         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8117         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8118         lru_resize_enable mdc
8119         lru_resize_enable osc
8120 }
8121 run_test 120d "Early Lock Cancel: setattr test"
8122
8123 test_120e() {
8124         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8125         test_mkdir -p -c1 $DIR/$tdir
8126         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8127                skip "no early lock cancel on server" && return 0
8128         lru_resize_disable mdc
8129         lru_resize_disable osc
8130         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
8131         cancel_lru_locks mdc
8132         cancel_lru_locks osc
8133         dd if=$DIR/$tdir/f1 of=/dev/null
8134         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
8135         # XXX client can not do early lock cancel of OST lock
8136         # during unlink (LU-4206), so cancel osc lock now.
8137         cancel_lru_locks osc
8138         can1=$(do_facet $SINGLEMDS \
8139                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8140                awk '/ldlm_cancel/ {print $2}')
8141         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8142                awk '/ldlm_bl_callback/ {print $2}')
8143         unlink $DIR/$tdir/f1
8144         sleep 5
8145         can2=$(do_facet $SINGLEMDS \
8146                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8147                awk '/ldlm_cancel/ {print $2}')
8148         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8149                awk '/ldlm_bl_callback/ {print $2}')
8150         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8151         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8152         lru_resize_enable mdc
8153         lru_resize_enable osc
8154 }
8155 run_test 120e "Early Lock Cancel: unlink test"
8156
8157 test_120f() {
8158         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8159         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8160                skip "no early lock cancel on server" && return 0
8161         test_mkdir -p -c1 $DIR/$tdir
8162         lru_resize_disable mdc
8163         lru_resize_disable osc
8164         test_mkdir -p -c1 $DIR/$tdir/d1
8165         test_mkdir -p -c1 $DIR/$tdir/d2
8166         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
8167         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
8168         cancel_lru_locks mdc
8169         cancel_lru_locks osc
8170         dd if=$DIR/$tdir/d1/f1 of=/dev/null
8171         dd if=$DIR/$tdir/d2/f2 of=/dev/null
8172         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
8173         # XXX client can not do early lock cancel of OST lock
8174         # during rename (LU-4206), so cancel osc lock now.
8175         cancel_lru_locks osc
8176         can1=$(do_facet $SINGLEMDS \
8177                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8178                awk '/ldlm_cancel/ {print $2}')
8179         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8180                awk '/ldlm_bl_callback/ {print $2}')
8181         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8182         sleep 5
8183         can2=$(do_facet $SINGLEMDS \
8184                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8185                awk '/ldlm_cancel/ {print $2}')
8186         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8187                awk '/ldlm_bl_callback/ {print $2}')
8188         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8189         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8190         lru_resize_enable mdc
8191         lru_resize_enable osc
8192 }
8193 run_test 120f "Early Lock Cancel: rename test"
8194
8195 test_120g() {
8196         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8197         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8198                skip "no early lock cancel on server" && return 0
8199         lru_resize_disable mdc
8200         lru_resize_disable osc
8201         count=10000
8202         echo create $count files
8203         test_mkdir -p $DIR/$tdir
8204         cancel_lru_locks mdc
8205         cancel_lru_locks osc
8206         t0=`date +%s`
8207
8208         can0=$(do_facet $SINGLEMDS \
8209                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8210                awk '/ldlm_cancel/ {print $2}')
8211         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8212                awk '/ldlm_bl_callback/ {print $2}')
8213         createmany -o $DIR/$tdir/f $count
8214         sync
8215         can1=$(do_facet $SINGLEMDS \
8216                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8217                awk '/ldlm_cancel/ {print $2}')
8218         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8219                awk '/ldlm_bl_callback/ {print $2}')
8220         t1=$(date +%s)
8221         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
8222         echo rm $count files
8223         rm -r $DIR/$tdir
8224         sync
8225         can2=$(do_facet $SINGLEMDS \
8226                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8227                awk '/ldlm_cancel/ {print $2}')
8228         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8229                awk '/ldlm_bl_callback/ {print $2}')
8230         t2=$(date +%s)
8231         echo total: $count removes in $((t2-t1))
8232         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
8233         sleep 2
8234         # wait for commitment of removal
8235         lru_resize_enable mdc
8236         lru_resize_enable osc
8237 }
8238 run_test 120g "Early Lock Cancel: performance test"
8239
8240 test_121() { #bug #10589
8241         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8242         rm -rf $DIR/$tfile
8243         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8244 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8245         lctl set_param fail_loc=0x310
8246         cancel_lru_locks osc > /dev/null
8247         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8248         lctl set_param fail_loc=0
8249         [[ $reads -eq $writes ]] ||
8250                 error "read $reads blocks, must be $writes blocks"
8251 }
8252 run_test 121 "read cancel race ========="
8253
8254 test_123a() { # was test 123, statahead(bug 11401)
8255         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8256         SLOWOK=0
8257         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8258             log "testing on UP system. Performance may be not as good as expected."
8259                         SLOWOK=1
8260         fi
8261
8262         rm -rf $DIR/$tdir
8263         test_mkdir -p $DIR/$tdir
8264         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8265         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8266         MULT=10
8267         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8268                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8269
8270                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8271                 lctl set_param -n llite.*.statahead_max 0
8272                 lctl get_param llite.*.statahead_max
8273                 cancel_lru_locks mdc
8274                 cancel_lru_locks osc
8275                 stime=`date +%s`
8276                 time ls -l $DIR/$tdir | wc -l
8277                 etime=`date +%s`
8278                 delta=$((etime - stime))
8279                 log "ls $i files without statahead: $delta sec"
8280                 lctl set_param llite.*.statahead_max=$max
8281
8282                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8283                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8284                 cancel_lru_locks mdc
8285                 cancel_lru_locks osc
8286                 stime=`date +%s`
8287                 time ls -l $DIR/$tdir | wc -l
8288                 etime=`date +%s`
8289                 delta_sa=$((etime - stime))
8290                 log "ls $i files with statahead: $delta_sa sec"
8291                 lctl get_param -n llite.*.statahead_stats
8292                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8293
8294                 [[ $swrong -lt $ewrong ]] &&
8295                         log "statahead was stopped, maybe too many locks held!"
8296                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8297
8298                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8299                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8300                     lctl set_param -n llite.*.statahead_max 0
8301                     lctl get_param llite.*.statahead_max
8302                     cancel_lru_locks mdc
8303                     cancel_lru_locks osc
8304                     stime=`date +%s`
8305                     time ls -l $DIR/$tdir | wc -l
8306                     etime=`date +%s`
8307                     delta=$((etime - stime))
8308                     log "ls $i files again without statahead: $delta sec"
8309                     lctl set_param llite.*.statahead_max=$max
8310                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8311                         if [  $SLOWOK -eq 0 ]; then
8312                                 error "ls $i files is slower with statahead!"
8313                         else
8314                                 log "ls $i files is slower with statahead!"
8315                         fi
8316                         break
8317                     fi
8318                 fi
8319
8320                 [ $delta -gt 20 ] && break
8321                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8322                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8323         done
8324         log "ls done"
8325
8326         stime=`date +%s`
8327         rm -r $DIR/$tdir
8328         sync
8329         etime=`date +%s`
8330         delta=$((etime - stime))
8331         log "rm -r $DIR/$tdir/: $delta seconds"
8332         log "rm done"
8333         lctl get_param -n llite.*.statahead_stats
8334 }
8335 run_test 123a "verify statahead work"
8336
8337 test_123b () { # statahead(bug 15027)
8338         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8339         test_mkdir -p $DIR/$tdir
8340         createmany -o $DIR/$tdir/$tfile-%d 1000
8341
8342         cancel_lru_locks mdc
8343         cancel_lru_locks osc
8344
8345 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8346         lctl set_param fail_loc=0x80000803
8347         ls -lR $DIR/$tdir > /dev/null
8348         log "ls done"
8349         lctl set_param fail_loc=0x0
8350         lctl get_param -n llite.*.statahead_stats
8351         rm -r $DIR/$tdir
8352         sync
8353
8354 }
8355 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8356
8357 test_124a() {
8358         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8359         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8360                 skip "no lru resize on server" && return 0
8361         local NR=2000
8362         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8363
8364         log "create $NR files at $DIR/$tdir"
8365         createmany -o $DIR/$tdir/f $NR ||
8366                 error "failed to create $NR files in $DIR/$tdir"
8367
8368         cancel_lru_locks mdc
8369         ls -l $DIR/$tdir > /dev/null
8370
8371         local NSDIR=""
8372         local LRU_SIZE=0
8373         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8374                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8375                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8376                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8377                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8378                         log "NSDIR=$NSDIR"
8379                         log "NS=$(basename $NSDIR)"
8380                         break
8381                 fi
8382         done
8383
8384         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8385                 skip "Not enough cached locks created!"
8386                 return 0
8387         fi
8388         log "LRU=$LRU_SIZE"
8389
8390         local SLEEP=30
8391
8392         # We know that lru resize allows one client to hold $LIMIT locks
8393         # for 10h. After that locks begin to be killed by client.
8394         local MAX_HRS=10
8395         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8396         log "LIMIT=$LIMIT"
8397         if [ $LIMIT -lt $LRU_SIZE ]; then
8398             skip "Limit is too small $LIMIT"
8399             return 0
8400         fi
8401
8402         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8403         # killing locks. Some time was spent for creating locks. This means
8404         # that up to the moment of sleep finish we must have killed some of
8405         # them (10-100 locks). This depends on how fast ther were created.
8406         # Many of them were touched in almost the same moment and thus will
8407         # be killed in groups.
8408         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8409
8410         # Use $LRU_SIZE_B here to take into account real number of locks
8411         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8412         local LRU_SIZE_B=$LRU_SIZE
8413         log "LVF=$LVF"
8414         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8415         log "OLD_LVF=$OLD_LVF"
8416         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8417
8418         # Let's make sure that we really have some margin. Client checks
8419         # cached locks every 10 sec.
8420         SLEEP=$((SLEEP+20))
8421         log "Sleep ${SLEEP} sec"
8422         local SEC=0
8423         while ((SEC<$SLEEP)); do
8424                 echo -n "..."
8425                 sleep 5
8426                 SEC=$((SEC+5))
8427                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8428                 echo -n "$LRU_SIZE"
8429         done
8430         echo ""
8431         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8432         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8433
8434         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8435                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8436                 unlinkmany $DIR/$tdir/f $NR
8437                 return
8438         }
8439
8440         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8441         log "unlink $NR files at $DIR/$tdir"
8442         unlinkmany $DIR/$tdir/f $NR
8443 }
8444 run_test 124a "lru resize ======================================="
8445
8446 get_max_pool_limit()
8447 {
8448         local limit=$($LCTL get_param \
8449                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8450         local max=0
8451         for l in $limit; do
8452                 if [[ $l -gt $max ]]; then
8453                         max=$l
8454                 fi
8455         done
8456         echo $max
8457 }
8458
8459 test_124b() {
8460         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8461         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8462                 skip "no lru resize on server" && return 0
8463
8464         LIMIT=$(get_max_pool_limit)
8465
8466         NR=$(($(default_lru_size)*20))
8467         if [[ $NR -gt $LIMIT ]]; then
8468                 log "Limit lock number by $LIMIT locks"
8469                 NR=$LIMIT
8470         fi
8471         lru_resize_disable mdc
8472         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8473                 error "failed to create $DIR/$tdir/disable_lru_resize"
8474
8475         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8476         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8477         cancel_lru_locks mdc
8478         stime=`date +%s`
8479         PID=""
8480         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8481         PID="$PID $!"
8482         sleep 2
8483         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8484         PID="$PID $!"
8485         sleep 2
8486         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8487         PID="$PID $!"
8488         wait $PID
8489         etime=`date +%s`
8490         nolruresize_delta=$((etime-stime))
8491         log "ls -la time: $nolruresize_delta seconds"
8492         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8493         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8494
8495         lru_resize_enable mdc
8496         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8497                 error "failed to create $DIR/$tdir/enable_lru_resize"
8498
8499         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8500         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8501         cancel_lru_locks mdc
8502         stime=`date +%s`
8503         PID=""
8504         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8505         PID="$PID $!"
8506         sleep 2
8507         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8508         PID="$PID $!"
8509         sleep 2
8510         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8511         PID="$PID $!"
8512         wait $PID
8513         etime=`date +%s`
8514         lruresize_delta=$((etime-stime))
8515         log "ls -la time: $lruresize_delta seconds"
8516         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8517
8518         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8519                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8520         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8521                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8522         else
8523                 log "lru resize performs the same with no lru resize"
8524         fi
8525         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8526 }
8527 run_test 124b "lru resize (performance test) ======================="
8528
8529 test_124c() {
8530         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8531         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8532                 skip "no lru resize on server" && return 0
8533
8534         # cache ununsed locks on client
8535         local nr=100
8536         cancel_lru_locks mdc
8537         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8538         createmany -o $DIR/$tdir/f $nr ||
8539                 error "failed to create $nr files in $DIR/$tdir"
8540         ls -l $DIR/$tdir > /dev/null
8541
8542         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
8543         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
8544         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
8545         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
8546         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
8547
8548         # set lru_max_age to 1 sec
8549         $LCTL set_param $nsdir.lru_max_age=1000 # jiffies
8550         echo "sleep $((recalc_p * 2)) seconds..."
8551         sleep $((recalc_p * 2))
8552
8553         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
8554         # restore lru_max_age
8555         $LCTL set_param -n $nsdir.lru_max_age $max_age
8556         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
8557         unlinkmany $DIR/$tdir/f $nr
8558 }
8559 run_test 124c "LRUR cancel very aged locks"
8560
8561 test_125() { # 13358
8562         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8563         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8564         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8565         test_mkdir -p $DIR/d125 || error "mkdir failed"
8566         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8567         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8568         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8569 }
8570 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8571
8572 test_126() { # bug 12829/13455
8573         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8574         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8575         $GSS && skip "must run as gss disabled" && return
8576
8577         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8578         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8579         rm -f $DIR/$tfile
8580         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8581 }
8582 run_test 126 "check that the fsgid provided by the client is taken into account"
8583
8584 test_127a() { # bug 15521
8585         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8586         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8587         $LCTL set_param osc.*.stats=0
8588         FSIZE=$((2048 * 1024))
8589         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8590         cancel_lru_locks osc
8591         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8592
8593         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8594         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8595                 echo "got $COUNT $NAME"
8596                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8597                 eval $NAME=$COUNT || error "Wrong proc format"
8598
8599                 case $NAME in
8600                         read_bytes|write_bytes)
8601                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8602                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8603                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8604                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8605                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8606                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8607                                 error "sumsquare is too small: $SUMSQ"
8608                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8609                                 error "sumsquare is too big: $SUMSQ"
8610                         ;;
8611                         *) ;;
8612                 esac
8613         done < $DIR/${tfile}.tmp
8614
8615         #check that we actually got some stats
8616         [ "$read_bytes" ] || error "Missing read_bytes stats"
8617         [ "$write_bytes" ] || error "Missing write_bytes stats"
8618         [ "$read_bytes" != 0 ] || error "no read done"
8619         [ "$write_bytes" != 0 ] || error "no write done"
8620 }
8621 run_test 127a "verify the client stats are sane"
8622
8623 test_127b() { # bug LU-333
8624         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8625         $LCTL set_param llite.*.stats=0
8626         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8627         # perform 2 reads and writes so MAX is different from SUM.
8628         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8629         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8630         cancel_lru_locks osc
8631         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8632         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8633
8634         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8635         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8636                 echo "got $COUNT $NAME"
8637                 eval $NAME=$COUNT || error "Wrong proc format"
8638
8639         case $NAME in
8640                 read_bytes)
8641                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8642                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8643                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8644                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8645                         ;;
8646                 write_bytes)
8647                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8648                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8649                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8650                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8651                         ;;
8652                         *) ;;
8653                 esac
8654         done < $TMP/${tfile}.tmp
8655
8656         #check that we actually got some stats
8657         [ "$read_bytes" ] || error "Missing read_bytes stats"
8658         [ "$write_bytes" ] || error "Missing write_bytes stats"
8659         [ "$read_bytes" != 0 ] || error "no read done"
8660         [ "$write_bytes" != 0 ] || error "no write done"
8661 }
8662 run_test 127b "verify the llite client stats are sane"
8663
8664 test_128() { # bug 15212
8665         touch $DIR/$tfile
8666         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8667                 find $DIR/$tfile
8668                 find $DIR/$tfile
8669         EOF
8670
8671         result=$(grep error $TMP/$tfile.log)
8672         rm -f $DIR/$tfile
8673         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8674 }
8675 run_test 128 "interactive lfs for 2 consecutive find's"
8676
8677 set_dir_limits () {
8678         local mntdev
8679         local canondev
8680         local node
8681
8682         local LDPROC=/proc/fs/ldiskfs
8683         local facets=$(get_facets MDS)
8684
8685         for facet in ${facets//,/ }; do
8686                 canondev=$(ldiskfs_canon \
8687                            *.$(convert_facet2label $facet).mntdev $facet)
8688                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8689                                                 LDPROC=/sys/fs/ldiskfs
8690                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8691                 do_facet $facet "test -e $LDPROC/$canondev/warning_dir_size" ||
8692                                                 LDPROC=/sys/fs/ldiskfs
8693                 do_facet $facet "echo $2 >$LDPROC/$canondev/warning_dir_size"
8694         done
8695 }
8696
8697 check_mds_dmesg() {
8698         local facets=$(get_facets MDS)
8699         for facet in ${facets//,/ }; do
8700                 do_facet $facet "dmesg | tail -3 | grep -q $1" && return 0
8701         done
8702         return 1
8703 }
8704
8705 test_129() {
8706         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8707         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8708                 skip "Only applicable to ldiskfs-based MDTs"
8709                 return
8710         fi
8711         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8712         ENOSPC=28
8713         EFBIG=27
8714         has_warning=0
8715
8716         rm -rf $DIR/$tdir
8717         test_mkdir -p $DIR/$tdir
8718
8719         # block size of mds1
8720         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8721         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8722         local MAX=$((MDSBLOCKSIZE * 5))
8723         set_dir_limits $MAX $MAX
8724         local I=$(stat -c%s "$DIR/$tdir")
8725         local J=0
8726         local STRIPE_COUNT=1
8727         [[ $MDSCOUNT -ge 2 ]] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8728         MAX=$((MAX*STRIPE_COUNT))
8729         while [[ $I -le $MAX ]]; do
8730                 $MULTIOP $DIR/$tdir/$J Oc
8731                 rc=$?
8732                 if [ $has_warning -eq 0 ]; then
8733                         check_mds_dmesg '"is approaching"' &&
8734                                 has_warning=1
8735                 fi
8736                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8737                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8738                 #and EFBIG for previous versions
8739                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8740                         set_dir_limits 0 0
8741                         echo "return code $rc received as expected"
8742                         multiop $DIR/$tdir/$J Oc ||
8743                                 error_exit "multiop failed w/o dir size limit"
8744
8745                         check_mds_dmesg '"has reached"' ||
8746                                 error_exit "has reached message should be output"
8747
8748                         [ $has_warning ] ||
8749                                 error_exit "warning message should be output"
8750
8751                         I=$(stat -c%s "$DIR/$tdir")
8752
8753                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8754                                         $(version_code 2.4.51) ]
8755                         then
8756                                 [[ $I -eq $MAX ]] && return 0
8757                         else
8758                                 [[ $I -gt $MAX ]] && return 0
8759                         fi
8760                         error_exit "current dir size $I, previous limit $MAX"
8761                 elif [ $rc -ne 0 ]; then
8762                         set_dir_limits 0 0
8763                         error_exit "return code $rc received instead of expected " \
8764                                    "$EFBIG or $ENOSPC, files in dir $I"
8765                 fi
8766                 J=$((J+1))
8767                 I=$(stat -c%s "$DIR/$tdir")
8768         done
8769
8770         set_dir_limits 0 0
8771         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8772 }
8773 run_test 129 "test directory size limit ========================"
8774
8775 OLDIFS="$IFS"
8776 cleanup_130() {
8777         trap 0
8778         IFS="$OLDIFS"
8779 }
8780
8781 test_130a() {
8782         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8783         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8784                 return
8785
8786         trap cleanup_130 EXIT RETURN
8787
8788         local fm_file=$DIR/$tfile
8789         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8790         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8791                 error "dd failed for $fm_file"
8792
8793         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8794         filefrag -ves $fm_file
8795         RC=$?
8796         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8797                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8798         [ $RC != 0 ] && error "filefrag $fm_file failed"
8799
8800         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8801                       grep -v "ext:" | grep -v "found")
8802         lun=$($GETSTRIPE -i $fm_file)
8803
8804         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8805         IFS=$'\n'
8806         tot_len=0
8807         for line in $filefrag_op
8808         do
8809                 frag_lun=`echo $line | cut -d: -f5`
8810                 ext_len=`echo $line | cut -d: -f4`
8811                 if (( $frag_lun != $lun )); then
8812                         cleanup_130
8813                         error "FIEMAP on 1-stripe file($fm_file) failed"
8814                         return
8815                 fi
8816                 (( tot_len += ext_len ))
8817         done
8818
8819         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8820                 cleanup_130
8821                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8822                 return
8823         fi
8824
8825         cleanup_130
8826
8827         echo "FIEMAP on single striped file succeeded"
8828 }
8829 run_test 130a "FIEMAP (1-stripe file)"
8830
8831 test_130b() {
8832         [ "$OSTCOUNT" -lt "2" ] &&
8833                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8834
8835         [ "$OSTCOUNT" -ge "10" ] &&
8836                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8837
8838         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8839         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8840                 return
8841
8842         trap cleanup_130 EXIT RETURN
8843
8844         local fm_file=$DIR/$tfile
8845         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8846         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8847                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8848
8849         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8850                 error "dd failed on $fm_file"
8851
8852         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8853         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8854                       grep -v "ext:" | grep -v "found")
8855
8856         last_lun=$(echo $filefrag_op | cut -d: -f5)
8857
8858         IFS=$'\n'
8859         tot_len=0
8860         num_luns=1
8861         for line in $filefrag_op
8862         do
8863                 frag_lun=`echo $line | cut -d: -f5`
8864                 ext_len=`echo $line | cut -d: -f4`
8865                 if (( $frag_lun != $last_lun )); then
8866                         if (( tot_len != 1024 )); then
8867                                 cleanup_130
8868                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8869                                 return
8870                         else
8871                                 (( num_luns += 1 ))
8872                                 tot_len=0
8873                         fi
8874                 fi
8875                 (( tot_len += ext_len ))
8876                 last_lun=$frag_lun
8877         done
8878         if (( num_luns != 2 || tot_len != 1024 )); then
8879                 cleanup_130
8880                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8881                 return
8882         fi
8883
8884         cleanup_130
8885
8886         echo "FIEMAP on 2-stripe file succeeded"
8887 }
8888 run_test 130b "FIEMAP (2-stripe file)"
8889
8890 test_130c() {
8891         [ "$OSTCOUNT" -lt "2" ] &&
8892                 skip_env "skipping FIEMAP on 2-stripe file" && return
8893
8894         [ "$OSTCOUNT" -ge "10" ] &&
8895                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8896
8897         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8898         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8899                 return
8900
8901         trap cleanup_130 EXIT RETURN
8902
8903         local fm_file=$DIR/$tfile
8904         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8905         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8906                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8907
8908         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8909
8910         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8911         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8912
8913         last_lun=`echo $filefrag_op | cut -d: -f5`
8914
8915         IFS=$'\n'
8916         tot_len=0
8917         num_luns=1
8918         for line in $filefrag_op
8919         do
8920                 frag_lun=`echo $line | cut -d: -f5`
8921                 ext_len=`echo $line | cut -d: -f4`
8922                 if (( $frag_lun != $last_lun )); then
8923                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8924                         if (( logical != 512 )); then
8925                                 cleanup_130
8926                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8927                                 return
8928                         fi
8929                         if (( tot_len != 512 )); then
8930                                 cleanup_130
8931                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8932                                 return
8933                         else
8934                                 (( num_luns += 1 ))
8935                                 tot_len=0
8936                         fi
8937                 fi
8938                 (( tot_len += ext_len ))
8939                 last_lun=$frag_lun
8940         done
8941         if (( num_luns != 2 || tot_len != 512 )); then
8942                 cleanup_130
8943                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8944                 return
8945         fi
8946
8947         cleanup_130
8948
8949         echo "FIEMAP on 2-stripe file with hole succeeded"
8950 }
8951 run_test 130c "FIEMAP (2-stripe file with hole)"
8952
8953 test_130d() {
8954         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8955
8956         [ "$OSTCOUNT" -ge "10" ] &&
8957                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8958
8959         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8960         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8961
8962         trap cleanup_130 EXIT RETURN
8963
8964         local fm_file=$DIR/$tfile
8965         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8966         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8967                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8968
8969         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8970         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8971                 error "dd failed on $fm_file"
8972
8973         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8974         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8975                 grep -v "ext:" | grep -v "found"`
8976
8977         last_lun=`echo $filefrag_op | cut -d: -f5`
8978
8979         IFS=$'\n'
8980         tot_len=0
8981         num_luns=1
8982         for line in $filefrag_op
8983         do
8984                 frag_lun=`echo $line | cut -d: -f5`
8985                 ext_len=`echo $line | cut -d: -f4`
8986                 if (( $frag_lun != $last_lun )); then
8987                         if (( tot_len != 1024 )); then
8988                                 cleanup_130
8989                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8990                                 return
8991                         else
8992                                 (( num_luns += 1 ))
8993                                 tot_len=0
8994                         fi
8995                 fi
8996                 (( tot_len += ext_len ))
8997                 last_lun=$frag_lun
8998         done
8999         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
9000                 cleanup_130
9001                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
9002                 return
9003         fi
9004
9005         cleanup_130
9006
9007         echo "FIEMAP on N-stripe file succeeded"
9008 }
9009 run_test 130d "FIEMAP (N-stripe file)"
9010
9011 test_130e() {
9012         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
9013
9014         [ "$OSTCOUNT" -ge "10" ] &&
9015                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
9016
9017         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9018         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
9019
9020         trap cleanup_130 EXIT RETURN
9021
9022         local fm_file=$DIR/$tfile
9023         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
9024         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9025                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9026
9027         NUM_BLKS=512
9028         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
9029         for ((i = 0; i < $NUM_BLKS; i++))
9030         do
9031                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
9032         done
9033
9034         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9035         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
9036
9037         last_lun=`echo $filefrag_op | cut -d: -f5`
9038
9039         IFS=$'\n'
9040         tot_len=0
9041         num_luns=1
9042         for line in $filefrag_op
9043         do
9044                 frag_lun=`echo $line | cut -d: -f5`
9045                 ext_len=`echo $line | cut -d: -f4`
9046                 if (( $frag_lun != $last_lun )); then
9047                         if (( tot_len != $EXPECTED_LEN )); then
9048                                 cleanup_130
9049                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
9050                                 return
9051                         else
9052                                 (( num_luns += 1 ))
9053                                 tot_len=0
9054                         fi
9055                 fi
9056                 (( tot_len += ext_len ))
9057                 last_lun=$frag_lun
9058         done
9059         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
9060                 cleanup_130
9061                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
9062                 return
9063         fi
9064
9065         cleanup_130
9066
9067         echo "FIEMAP with continuation calls succeeded"
9068 }
9069 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
9070
9071 # Test for writev/readv
9072 test_131a() {
9073         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
9074         error "writev test failed"
9075         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
9076         error "readv failed"
9077         rm -f $DIR/$tfile
9078 }
9079 run_test 131a "test iov's crossing stripe boundary for writev/readv"
9080
9081 test_131b() {
9082         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
9083         error "append writev test failed"
9084         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
9085         error "append writev test failed"
9086         rm -f $DIR/$tfile
9087 }
9088 run_test 131b "test append writev"
9089
9090 test_131c() {
9091         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
9092         error "NOT PASS"
9093 }
9094 run_test 131c "test read/write on file w/o objects"
9095
9096 test_131d() {
9097         rwv -f $DIR/$tfile -w -n 1 1572864
9098         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
9099         if [ "$NOB" != 1572864 ]; then
9100                 error "Short read filed: read $NOB bytes instead of 1572864"
9101         fi
9102         rm -f $DIR/$tfile
9103 }
9104 run_test 131d "test short read"
9105
9106 test_131e() {
9107         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
9108         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
9109         error "read hitting hole failed"
9110         rm -f $DIR/$tfile
9111 }
9112 run_test 131e "test read hitting hole"
9113
9114 check_stats() {
9115         local res
9116         local count
9117         case $1 in
9118         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
9119                  ;;
9120         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
9121                  ;;
9122         *) error "Wrong argument $1" ;;
9123         esac
9124         echo $res
9125         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
9126         # if the argument $3 is zero, it means any stat increment is ok.
9127         if [[ $3 -gt 0 ]]; then
9128                 count=$(echo $res | awk '{ print $2 }')
9129                 [[ $count -ne $3 ]] &&
9130                         error "The $2 counter on $1 is wrong - expected $3"
9131         fi
9132 }
9133
9134 test_133a() {
9135         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9136         remote_ost_nodsh && skip "remote OST with nodsh" && return
9137         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9138
9139         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9140                 { skip "MDS doesn't support rename stats"; return; }
9141         local testdir=$DIR/${tdir}/stats_testdir
9142         mkdir -p $DIR/${tdir}
9143
9144         # clear stats.
9145         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9146         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9147
9148         # verify mdt stats first.
9149         mkdir ${testdir} || error "mkdir failed"
9150         check_stats $SINGLEMDS "mkdir" 1
9151         touch ${testdir}/${tfile} || "touch failed"
9152         check_stats $SINGLEMDS "open" 1
9153         check_stats $SINGLEMDS "close" 1
9154         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
9155         check_stats $SINGLEMDS "mknod" 1
9156         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
9157         check_stats $SINGLEMDS "unlink" 1
9158         rm -f ${testdir}/${tfile} || error "file remove failed"
9159         check_stats $SINGLEMDS "unlink" 2
9160
9161         # remove working dir and check mdt stats again.
9162         rmdir ${testdir} || error "rmdir failed"
9163         check_stats $SINGLEMDS "rmdir" 1
9164
9165         local testdir1=$DIR/${tdir}/stats_testdir1
9166         mkdir -p ${testdir}
9167         mkdir -p ${testdir1}
9168         touch ${testdir1}/test1
9169         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
9170         check_stats $SINGLEMDS "crossdir_rename" 1
9171
9172         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
9173         check_stats $SINGLEMDS "samedir_rename" 1
9174
9175         rm -rf $DIR/${tdir}
9176 }
9177 run_test 133a "Verifying MDT stats ========================================"
9178
9179 test_133b() {
9180         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9181         remote_ost_nodsh && skip "remote OST with nodsh" && return
9182         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9183         local testdir=$DIR/${tdir}/stats_testdir
9184         mkdir -p ${testdir} || error "mkdir failed"
9185         touch ${testdir}/${tfile} || "touch failed"
9186         cancel_lru_locks mdc
9187
9188         # clear stats.
9189         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9190         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9191
9192         # extra mdt stats verification.
9193         chmod 444 ${testdir}/${tfile} || error "chmod failed"
9194         check_stats $SINGLEMDS "setattr" 1
9195         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9196         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
9197         then            # LU-1740
9198                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
9199                 check_stats $SINGLEMDS "getattr" 1
9200         fi
9201         $LFS df || error "lfs failed"
9202         check_stats $SINGLEMDS "statfs" 1
9203
9204         rm -rf $DIR/${tdir}
9205 }
9206 run_test 133b "Verifying extra MDT stats =================================="
9207
9208 test_133c() {
9209         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9210         remote_ost_nodsh && skip "remote OST with nodsh" && return
9211         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9212         local testdir=$DIR/${tdir}/stats_testdir
9213         test_mkdir -p ${testdir} || error "mkdir failed"
9214
9215         # verify obdfilter stats.
9216         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9217         sync
9218         cancel_lru_locks osc
9219         wait_delete_completed
9220
9221         # clear stats.
9222         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9223         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9224
9225         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
9226         sync
9227         cancel_lru_locks osc
9228         check_stats ost "write" 1
9229
9230         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9231         check_stats ost "read" 1
9232
9233         > ${testdir}/${tfile} || error "truncate failed"
9234         check_stats ost "punch" 1
9235
9236         rm -f ${testdir}/${tfile} || error "file remove failed"
9237         wait_delete_completed
9238         check_stats ost "destroy" 1
9239
9240         rm -rf $DIR/${tdir}
9241 }
9242 run_test 133c "Verifying OST stats ========================================"
9243
9244 order_2() {
9245         local value=$1
9246         local orig=$value
9247         local order=1
9248
9249         while [ $value -ge 2 ]; do
9250                 order=$((order*2))
9251                 value=$((value/2))
9252         done
9253
9254         if [ $orig -gt $order ]; then
9255                 order=$((order*2))
9256         fi
9257         echo $order
9258 }
9259
9260 size_in_KMGT() {
9261     local value=$1
9262     local size=('K' 'M' 'G' 'T');
9263     local i=0
9264     local size_string=$value
9265
9266     while [ $value -ge 1024 ]; do
9267         if [ $i -gt 3 ]; then
9268             #T is the biggest unit we get here, if that is bigger,
9269             #just return XXXT
9270             size_string=${value}T
9271             break
9272         fi
9273         value=$((value >> 10))
9274         if [ $value -lt 1024 ]; then
9275             size_string=${value}${size[$i]}
9276             break
9277         fi
9278         i=$((i + 1))
9279     done
9280
9281     echo $size_string
9282 }
9283
9284 get_rename_size() {
9285     local size=$1
9286     local context=${2:-.}
9287     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9288                 grep -A1 $context |
9289                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9290     echo $sample
9291 }
9292
9293 test_133d() {
9294         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9295         remote_ost_nodsh && skip "remote OST with nodsh" && return
9296         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9297         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9298         { skip "MDS doesn't support rename stats"; return; }
9299
9300         local testdir1=$DIR/${tdir}/stats_testdir1
9301         local testdir2=$DIR/${tdir}/stats_testdir2
9302
9303         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9304
9305         mkdir -p ${testdir1} || error "mkdir failed"
9306         mkdir -p ${testdir2} || error "mkdir failed"
9307
9308         createmany -o $testdir1/test 512 || error "createmany failed"
9309
9310         # check samedir rename size
9311         mv ${testdir1}/test0 ${testdir1}/test_0
9312
9313         local testdir1_size=$(ls -l $DIR/${tdir} |
9314                 awk '/stats_testdir1/ {print $5}')
9315         local testdir2_size=$(ls -l $DIR/${tdir} |
9316                 awk '/stats_testdir2/ {print $5}')
9317
9318         testdir1_size=$(order_2 $testdir1_size)
9319         testdir2_size=$(order_2 $testdir2_size)
9320
9321         testdir1_size=$(size_in_KMGT $testdir1_size)
9322         testdir2_size=$(size_in_KMGT $testdir2_size)
9323
9324         echo "source rename dir size: ${testdir1_size}"
9325         echo "target rename dir size: ${testdir2_size}"
9326
9327         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9328         eval $cmd || error "$cmd failed"
9329         local samedir=$($cmd | grep 'same_dir')
9330         local same_sample=$(get_rename_size $testdir1_size)
9331         [ -z "$samedir" ] && error "samedir_rename_size count error"
9332         [[ $same_sample -eq 1 ]] ||
9333                 error "samedir_rename_size error $same_sample"
9334         echo "Check same dir rename stats success"
9335
9336         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9337
9338         # check crossdir rename size
9339         mv ${testdir1}/test_0 ${testdir2}/test_0
9340
9341         testdir1_size=$(ls -l $DIR/${tdir} |
9342                 awk '/stats_testdir1/ {print $5}')
9343         testdir2_size=$(ls -l $DIR/${tdir} |
9344                 awk '/stats_testdir2/ {print $5}')
9345
9346         testdir1_size=$(order_2 $testdir1_size)
9347         testdir2_size=$(order_2 $testdir2_size)
9348
9349         testdir1_size=$(size_in_KMGT $testdir1_size)
9350         testdir2_size=$(size_in_KMGT $testdir2_size)
9351
9352         echo "source rename dir size: ${testdir1_size}"
9353         echo "target rename dir size: ${testdir2_size}"
9354
9355         eval $cmd || error "$cmd failed"
9356         local crossdir=$($cmd | grep 'crossdir')
9357         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9358         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9359         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9360         [[ $src_sample -eq 1 ]] ||
9361                 error "crossdir_rename_size error $src_sample"
9362         [[ $tgt_sample -eq 1 ]] ||
9363                 error "crossdir_rename_size error $tgt_sample"
9364         echo "Check cross dir rename stats success"
9365         rm -rf $DIR/${tdir}
9366 }
9367 run_test 133d "Verifying rename_stats ========================================"
9368
9369 test_133e() {
9370         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9371         remote_ost_nodsh && skip "remote OST with nodsh" && return
9372         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9373         local testdir=$DIR/${tdir}/stats_testdir
9374         local ctr f0 f1 bs=32768 count=42 sum
9375
9376         mkdir -p ${testdir} || error "mkdir failed"
9377
9378         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9379
9380         for ctr in {write,read}_bytes; do
9381                 sync
9382                 cancel_lru_locks osc
9383
9384                 do_facet ost1 $LCTL set_param -n \
9385                         "obdfilter.*.exports.clear=clear"
9386
9387                 if [ $ctr = write_bytes ]; then
9388                         f0=/dev/zero
9389                         f1=${testdir}/${tfile}
9390                 else
9391                         f0=${testdir}/${tfile}
9392                         f1=/dev/null
9393                 fi
9394
9395                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9396                         error "dd failed"
9397                 sync
9398                 cancel_lru_locks osc
9399
9400                 sum=$(do_facet ost1 $LCTL get_param \
9401                         "obdfilter.*.exports.*.stats" |
9402                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9403                                 $1 == ctr { sum += $7 }
9404                                 END { printf("%0.0f", sum) }')
9405
9406                 if ((sum != bs * count)); then
9407                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9408                 fi
9409         done
9410
9411         rm -rf $DIR/${tdir}
9412 }
9413 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9414
9415 test_133f() {
9416         local proc_dirs
9417
9418         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9419 /sys/fs/lustre/ /sys/fs/lnet/"
9420         local dir
9421         for dir in $dirs; do
9422                 if [ -d $dir ]; then
9423                         proc_dirs="$proc_dirs $dir"
9424                 fi
9425         done
9426
9427         local facet
9428
9429         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9430         remote_ost_nodsh && skip "remote OST with nodsh" && return
9431         # First without trusting modes.
9432         find $proc_dirs -exec cat '{}' \; &> /dev/null
9433
9434         # Second verifying readability.
9435         find $proc_dirs \
9436                 -type f \
9437                 -exec cat '{}' \; &> /dev/null ||
9438                         error "proc file read failed"
9439
9440         for facet in $SINGLEMDS ost1; do
9441                 do_facet $facet find $proc_dirs \
9442                         ! -name req_history \
9443                         -exec cat '{}' \\\; &> /dev/null
9444
9445                 do_facet $facet find $proc_dirs \
9446                         ! -name req_history \
9447                         -type f \
9448                         -exec cat '{}' \\\; &> /dev/null ||
9449                                 error "proc file read failed"
9450         done
9451 }
9452 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9453
9454 test_133g() {
9455         local proc_dirs
9456
9457         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9458 /sys/fs/lustre/ /sys/fs/lnet/"
9459         local dir
9460         for dir in $dirs; do
9461                 if [ -d $dir ]; then
9462                         proc_dirs="$proc_dirs $dir"
9463                 fi
9464         done
9465
9466         local facet
9467
9468         # Second verifying readability.
9469         find $proc_dirs \
9470                 -type f \
9471                 -not -name force_lbug \
9472                 -not -name changelog_mask \
9473                 -exec badarea_io '{}' \; &> /dev/null ||
9474                 error "find $proc_dirs failed"
9475
9476         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
9477                 skip "Too old lustre on MDS" && return
9478
9479         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
9480                 skip "Too old lustre on ost1" && return
9481
9482         for facet in $SINGLEMDS ost1; do
9483                 do_facet $facet find $proc_dirs \
9484                         -type f \
9485                         -not -name force_lbug \
9486                         -not -name changelog_mask \
9487                         -exec badarea_io '{}' \\\; &> /dev/null ||
9488                 error "$facet find $proc_dirs failed"
9489
9490         done
9491
9492         # remount the FS in case writes/reads /proc break the FS
9493         cleanup || error "failed to unmount"
9494         setup || error "failed to setup"
9495         true
9496 }
9497 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9498
9499 test_134a() {
9500         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
9501                 skip "Need MDS version at least 2.7.54" && return
9502
9503         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9504         cancel_lru_locks mdc
9505
9506         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
9507         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9508         [ $unused -eq 0 ] || "$unused locks are not cleared"
9509
9510         local nr=1000
9511         createmany -o $DIR/$tdir/f $nr ||
9512                 error "failed to create $nr files in $DIR/$tdir"
9513         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9514
9515         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
9516         do_facet mds1 $LCTL set_param fail_loc=0x327
9517         do_facet mds1 $LCTL set_param fail_val=500
9518         touch $DIR/$tdir/m
9519
9520         echo "sleep 10 seconds ..."
9521         sleep 10
9522         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
9523
9524         do_facet mds1 $LCTL set_param fail_loc=0
9525         do_facet mds1 $LCTL set_param fail_val=0
9526         [ $lck_cnt -lt $unused ] ||
9527                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
9528
9529         rm $DIR/$tdir/m
9530         unlinkmany $DIR/$tdir/f $nr
9531 }
9532 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
9533
9534 test_134b() {
9535         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
9536                 skip "Need MDS version at least 2.7.54" && return
9537
9538         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9539         cancel_lru_locks mdc
9540
9541         local low_wm=$(do_facet mds1 $LCTL get_param -n \
9542                         ldlm.lock_reclaim_threshold_mb)
9543         # disable reclaim temporarily
9544         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
9545
9546         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
9547         do_facet mds1 $LCTL set_param fail_loc=0x328
9548         do_facet mds1 $LCTL set_param fail_val=500
9549
9550         $LCTL set_param debug=+trace
9551
9552         local nr=600
9553         createmany -o $DIR/$tdir/f $nr &
9554         local create_pid=$!
9555
9556         echo "Sleep $TIMEOUT seconds ..."
9557         sleep $TIMEOUT
9558         if ! ps -p $create_pid  > /dev/null 2>&1; then
9559                 do_facet mds1 $LCTL set_param fail_loc=0
9560                 do_facet mds1 $LCTL set_param fail_val=0
9561                 do_facet mds1 $LCTL set_param \
9562                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
9563                 error "createmany finished incorrectly!"
9564         fi
9565         do_facet mds1 $LCTL set_param fail_loc=0
9566         do_facet mds1 $LCTL set_param fail_val=0
9567         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
9568         wait $create_pid || return 1
9569
9570         unlinkmany $DIR/$tdir/f $nr
9571 }
9572 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
9573
9574 test_140() { #bug-17379
9575         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9576         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
9577         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
9578         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
9579
9580         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9581         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9582         local i=0
9583         while i=`expr $i + 1`; do
9584                 test_mkdir -p $i || error "Creating dir $i"
9585                 cd $i || error "Changing to $i"
9586                 ln -s ../stat stat || error "Creating stat symlink"
9587                 # Read the symlink until ELOOP present,
9588                 # not LBUGing the system is considered success,
9589                 # we didn't overrun the stack.
9590                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9591                 [ $ret -ne 0 ] && {
9592                         if [ $ret -eq 40 ]; then
9593                                 break  # -ELOOP
9594                         else
9595                                 error "Open stat symlink"
9596                                 return
9597                         fi
9598                 }
9599         done
9600         i=`expr $i - 1`
9601         echo "The symlink depth = $i"
9602         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9603                                         error "Invalid symlink depth"
9604
9605         # Test recursive symlink
9606         ln -s symlink_self symlink_self
9607         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9608         echo "open symlink_self returns $ret"
9609         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9610 }
9611 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9612
9613 test_150() {
9614         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9615         local TF="$TMP/$tfile"
9616
9617         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9618         cp $TF $DIR/$tfile
9619         cancel_lru_locks osc
9620         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9621         remount_client $MOUNT
9622         df -P $MOUNT
9623         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9624
9625         $TRUNCATE $TF 6000
9626         $TRUNCATE $DIR/$tfile 6000
9627         cancel_lru_locks osc
9628         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9629
9630         echo "12345" >>$TF
9631         echo "12345" >>$DIR/$tfile
9632         cancel_lru_locks osc
9633         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9634
9635         echo "12345" >>$TF
9636         echo "12345" >>$DIR/$tfile
9637         cancel_lru_locks osc
9638         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9639
9640         rm -f $TF
9641         true
9642 }
9643 run_test 150 "truncate/append tests"
9644
9645 #LU-2902 roc_hit was not able to read all values from lproc
9646 function roc_hit_init() {
9647         local list=$(comma_list $(osts_nodes))
9648         local dir=$DIR/$tdir-check
9649         local file=$dir/file
9650         local BEFORE
9651         local AFTER
9652         local idx
9653
9654         test_mkdir -p $dir
9655         #use setstripe to do a write to every ost
9656         for i in $(seq 0 $((OSTCOUNT-1))); do
9657                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9658                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9659                 idx=$(printf %04x $i)
9660                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9661                         awk '$1 == "cache_access" {sum += $7}
9662                                 END { printf("%0.0f", sum) }')
9663
9664                 cancel_lru_locks osc
9665                 cat $file >/dev/null
9666
9667                 AFTER=$(get_osd_param $list *OST*$idx stats |
9668                         awk '$1 == "cache_access" {sum += $7}
9669                                 END { printf("%0.0f", sum) }')
9670
9671                 echo BEFORE:$BEFORE AFTER:$AFTER
9672                 if ! let "AFTER - BEFORE == 4"; then
9673                         rm -rf $dir
9674                         error "roc_hit is not safe to use"
9675                 fi
9676                 rm $file
9677         done
9678
9679         rm -rf $dir
9680 }
9681
9682 function roc_hit() {
9683         local list=$(comma_list $(osts_nodes))
9684         echo $(get_osd_param $list '' stats |
9685                 awk '$1 == "cache_hit" {sum += $7}
9686                         END { printf("%0.0f", sum) }')
9687 }
9688
9689 function set_cache() {
9690         local on=1
9691
9692         if [ "$2" == "off" ]; then
9693                 on=0;
9694         fi
9695         local list=$(comma_list $(osts_nodes))
9696         set_osd_param $list '' $1_cache_enable $on
9697
9698         cancel_lru_locks osc
9699 }
9700
9701 test_151() {
9702         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9703         remote_ost_nodsh && skip "remote OST with nodsh" && return
9704
9705         local CPAGES=3
9706         local list=$(comma_list $(osts_nodes))
9707
9708         # check whether obdfilter is cache capable at all
9709         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9710                 echo "not cache-capable obdfilter"
9711                 return 0
9712         fi
9713
9714         # check cache is enabled on all obdfilters
9715         if get_osd_param $list '' read_cache_enable | grep 0; then
9716                 echo "oss cache is disabled"
9717                 return 0
9718         fi
9719
9720         set_osd_param $list '' writethrough_cache_enable 1
9721
9722         # check write cache is enabled on all obdfilters
9723         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9724                 echo "oss write cache is NOT enabled"
9725                 return 0
9726         fi
9727
9728         roc_hit_init
9729
9730         #define OBD_FAIL_OBD_NO_LRU  0x609
9731         do_nodes $list $LCTL set_param fail_loc=0x609
9732
9733         # pages should be in the case right after write
9734         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9735                 error "dd failed"
9736
9737         local BEFORE=$(roc_hit)
9738         cancel_lru_locks osc
9739         cat $DIR/$tfile >/dev/null
9740         local AFTER=$(roc_hit)
9741
9742         do_nodes $list $LCTL set_param fail_loc=0
9743
9744         if ! let "AFTER - BEFORE == CPAGES"; then
9745                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9746         fi
9747
9748         # the following read invalidates the cache
9749         cancel_lru_locks osc
9750         set_osd_param $list '' read_cache_enable 0
9751         cat $DIR/$tfile >/dev/null
9752
9753         # now data shouldn't be found in the cache
9754         BEFORE=$(roc_hit)
9755         cancel_lru_locks osc
9756         cat $DIR/$tfile >/dev/null
9757         AFTER=$(roc_hit)
9758         if let "AFTER - BEFORE != 0"; then
9759                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9760         fi
9761
9762         set_osd_param $list '' read_cache_enable 1
9763         rm -f $DIR/$tfile
9764 }
9765 run_test 151 "test cache on oss and controls ==============================="
9766
9767 test_152() {
9768         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9769         local TF="$TMP/$tfile"
9770
9771         # simulate ENOMEM during write
9772 #define OBD_FAIL_OST_NOMEM      0x226
9773         lctl set_param fail_loc=0x80000226
9774         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9775         cp $TF $DIR/$tfile
9776         sync || error "sync failed"
9777         lctl set_param fail_loc=0
9778
9779         # discard client's cache
9780         cancel_lru_locks osc
9781
9782         # simulate ENOMEM during read
9783         lctl set_param fail_loc=0x80000226
9784         cmp $TF $DIR/$tfile || error "cmp failed"
9785         lctl set_param fail_loc=0
9786
9787         rm -f $TF
9788 }
9789 run_test 152 "test read/write with enomem ============================"
9790
9791 test_153() {
9792         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9793 }
9794 run_test 153 "test if fdatasync does not crash ======================="
9795
9796 dot_lustre_fid_permission_check() {
9797         local fid=$1
9798         local ffid=$MOUNT/.lustre/fid/$fid
9799         local test_dir=$2
9800
9801         echo "stat fid $fid"
9802         stat $ffid > /dev/null || error "stat $ffid failed."
9803         echo "touch fid $fid"
9804         touch $ffid || error "touch $ffid failed."
9805         echo "write to fid $fid"
9806         cat /etc/hosts > $ffid || error "write $ffid failed."
9807         echo "read fid $fid"
9808         diff /etc/hosts $ffid || error "read $ffid failed."
9809         echo "append write to fid $fid"
9810         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9811         echo "rename fid $fid"
9812         mv $ffid $test_dir/$tfile.1 &&
9813                 error "rename $ffid to $tfile.1 should fail."
9814         touch $test_dir/$tfile.1
9815         mv $test_dir/$tfile.1 $ffid &&
9816                 error "rename $tfile.1 to $ffid should fail."
9817         rm -f $test_dir/$tfile.1
9818         echo "truncate fid $fid"
9819         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9820         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9821                 echo "link fid $fid"
9822                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9823         fi
9824         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9825                 echo "setfacl fid $fid"
9826                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9827                 echo "getfacl fid $fid"
9828                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9829         fi
9830         echo "unlink fid $fid"
9831         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9832         echo "mknod fid $fid"
9833         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9834
9835         fid=[0xf00000400:0x1:0x0]
9836         ffid=$MOUNT/.lustre/fid/$fid
9837
9838         echo "stat non-exist fid $fid"
9839         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9840         echo "write to non-exist fid $fid"
9841         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9842         echo "link new fid $fid"
9843         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9844
9845         mkdir -p $test_dir/$tdir
9846         touch $test_dir/$tdir/$tfile
9847         fid=$($LFS path2fid $test_dir/$tdir)
9848         rc=$?
9849         [ $rc -ne 0 ] &&
9850                 error "error: could not get fid for $test_dir/$dir/$tfile."
9851
9852         ffid=$MOUNT/.lustre/fid/$fid
9853
9854         echo "ls $fid"
9855         ls $ffid > /dev/null || error "ls $ffid failed."
9856         echo "touch $fid/$tfile.1"
9857         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9858
9859         echo "touch $MOUNT/.lustre/fid/$tfile"
9860         touch $MOUNT/.lustre/fid/$tfile && \
9861                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9862
9863         echo "setxattr to $MOUNT/.lustre/fid"
9864         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9865
9866         echo "listxattr for $MOUNT/.lustre/fid"
9867         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9868
9869         echo "delxattr from $MOUNT/.lustre/fid"
9870         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9871
9872         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9873         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9874                 error "touch invalid fid should fail."
9875
9876         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9877         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9878                 error "touch non-normal fid should fail."
9879
9880         echo "rename $tdir to $MOUNT/.lustre/fid"
9881         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9882                 error "rename to $MOUNT/.lustre/fid should fail."
9883
9884         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9885         then            # LU-3547
9886                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9887                 local new_obf_mode=777
9888
9889                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9890                 chmod $new_obf_mode $DIR/.lustre/fid ||
9891                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9892
9893                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9894                 [ $obf_mode -eq $new_obf_mode ] ||
9895                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9896
9897                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9898                 chmod $old_obf_mode $DIR/.lustre/fid ||
9899                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9900         fi
9901
9902         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9903         fid=$($LFS path2fid $test_dir/$tfile-2)
9904
9905         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
9906         then # LU-5424
9907                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9908                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
9909                         error "create lov data thru .lustre failed"
9910         fi
9911         echo "cp /etc/passwd $test_dir/$tfile-2"
9912         cp /etc/passwd $test_dir/$tfile-2 ||
9913                 error "copy to $test_dir/$tfile-2 failed."
9914         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9915         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9916                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9917
9918         rm -rf $test_dir/tfile.lnk
9919         rm -rf $test_dir/$tfile-2
9920 }
9921
9922 test_154A() {
9923         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9924                 skip "Need MDS version at least 2.4.1" && return
9925
9926         touch $DIR/$tfile
9927         local FID=$($LFS path2fid $DIR/$tfile)
9928         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9929
9930         # check that we get the same pathname back
9931         local FOUND=$($LFS fid2path $MOUNT "$FID")
9932         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9933         [ "$FOUND" != "$DIR/$tfile" ] &&
9934                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9935
9936         rm -rf $DIR/$tfile
9937 }
9938 run_test 154A "lfs path2fid and fid2path basic checks"
9939
9940 test_154a() {
9941         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9942         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9943                 { skip "Need MDS version at least 2.2.51"; return 0; }
9944         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9945
9946         cp /etc/hosts $DIR/$tfile
9947
9948         fid=$($LFS path2fid $DIR/$tfile)
9949         rc=$?
9950         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9951
9952         dot_lustre_fid_permission_check "$fid" $DIR ||
9953                 error "dot lustre permission check $fid failed"
9954
9955         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9956
9957         touch $MOUNT/.lustre/file &&
9958                 error "creation is not allowed under .lustre"
9959
9960         mkdir $MOUNT/.lustre/dir &&
9961                 error "mkdir is not allowed under .lustre"
9962
9963         rm -rf $DIR/$tfile
9964 }
9965 run_test 154a "Open-by-FID"
9966
9967 test_154b() {
9968         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9969         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9970                 { skip "Need MDS version at least 2.2.51"; return 0; }
9971
9972         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9973
9974         local remote_dir=$DIR/$tdir/remote_dir
9975         local MDTIDX=1
9976         local rc=0
9977
9978         mkdir -p $DIR/$tdir
9979         $LFS mkdir -i $MDTIDX $remote_dir ||
9980                 error "create remote directory failed"
9981
9982         cp /etc/hosts $remote_dir/$tfile
9983
9984         fid=$($LFS path2fid $remote_dir/$tfile)
9985         rc=$?
9986         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9987
9988         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9989                 error "dot lustre permission check $fid failed"
9990         rm -rf $DIR/$tdir
9991 }
9992 run_test 154b "Open-by-FID for remote directory"
9993
9994 test_154c() {
9995         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9996                 skip "Need MDS version at least 2.4.1" && return
9997
9998         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9999         local FID1=$($LFS path2fid $DIR/$tfile.1)
10000         local FID2=$($LFS path2fid $DIR/$tfile.2)
10001         local FID3=$($LFS path2fid $DIR/$tfile.3)
10002
10003         local N=1
10004         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
10005                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
10006                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
10007                 local want=FID$N
10008                 [ "$FID" = "${!want}" ] ||
10009                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
10010                 N=$((N + 1))
10011         done
10012
10013         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
10014         do
10015                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
10016                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
10017                 N=$((N + 1))
10018         done
10019 }
10020 run_test 154c "lfs path2fid and fid2path multiple arguments"
10021
10022 test_154d() {
10023         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
10024                 skip "Need MDS version at least 2.5.53" && return
10025
10026         if remote_mds; then
10027                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
10028         else
10029                 nid="0@lo"
10030         fi
10031         local proc_ofile="mdt.*.exports.'$nid'.open_files"
10032         local fd
10033         local cmd
10034
10035         rm -f $DIR/$tfile
10036         touch $DIR/$tfile
10037
10038         local fid=$($LFS path2fid $DIR/$tfile)
10039         # Open the file
10040         fd=$(free_fd)
10041         cmd="exec $fd<$DIR/$tfile"
10042         eval $cmd
10043         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
10044         echo "$fid_list" | grep "$fid"
10045         rc=$?
10046
10047         cmd="exec $fd>/dev/null"
10048         eval $cmd
10049         if [ $rc -ne 0 ]; then
10050                 error "FID $fid not found in open files list $fid_list"
10051         fi
10052 }
10053 run_test 154d "Verify open file fid"
10054
10055 test_154e()
10056 {
10057         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
10058                 skip "Need MDS version at least 2.6.50" && return
10059
10060         if ls -a $MOUNT | grep -q '^\.lustre$'; then
10061                 error ".lustre returned by readdir"
10062         fi
10063 }
10064 run_test 154e ".lustre is not returned by readdir"
10065
10066 test_154f() {
10067         # create parent directory on a single MDT to avoid cross-MDT hardlinks
10068         test_mkdir -p -c1 $DIR/$tdir/d
10069         # test dirs inherit from its stripe
10070         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
10071         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
10072         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
10073         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
10074         touch $DIR/f
10075
10076         # get fid of parents
10077         local FID0=$($LFS path2fid $DIR/$tdir/d)
10078         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
10079         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
10080         local FID3=$($LFS path2fid $DIR)
10081
10082         # check that path2fid --parents returns expected <parent_fid>/name
10083         # 1) test for a directory (single parent)
10084         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
10085         [ "$parent" == "$FID0/foo1" ] ||
10086                 error "expected parent: $FID0/foo1, got: $parent"
10087
10088         # 2) test for a file with nlink > 1 (multiple parents)
10089         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
10090         echo "$parent" | grep -F "$FID1/$tfile" ||
10091                 error "$FID1/$tfile not returned in parent list"
10092         echo "$parent" | grep -F "$FID2/link" ||
10093                 error "$FID2/link not returned in parent list"
10094
10095         # 3) get parent by fid
10096         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
10097         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10098         echo "$parent" | grep -F "$FID1/$tfile" ||
10099                 error "$FID1/$tfile not returned in parent list (by fid)"
10100         echo "$parent" | grep -F "$FID2/link" ||
10101                 error "$FID2/link not returned in parent list (by fid)"
10102
10103         # 4) test for entry in root directory
10104         parent=$($LFS path2fid --parents $DIR/f)
10105         echo "$parent" | grep -F "$FID3/f" ||
10106                 error "$FID3/f not returned in parent list"
10107
10108         # 5) test it on root directory
10109         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
10110                 error "$MOUNT should not have parents"
10111
10112         # enable xattr caching and check that linkea is correctly updated
10113         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
10114         save_lustre_params client "llite.*.xattr_cache" > $save
10115         lctl set_param llite.*.xattr_cache 1
10116
10117         # 6.1) linkea update on rename
10118         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
10119
10120         # get parents by fid
10121         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10122         # foo1 should no longer be returned in parent list
10123         echo "$parent" | grep -F "$FID1" &&
10124                 error "$FID1 should no longer be in parent list"
10125         # the new path should appear
10126         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
10127                 error "$FID2/$tfile.moved is not in parent list"
10128
10129         # 6.2) linkea update on unlink
10130         rm -f $DIR/$tdir/d/foo2/link
10131         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10132         # foo2/link should no longer be returned in parent list
10133         echo "$parent" | grep -F "$FID2/link" &&
10134                 error "$FID2/link should no longer be in parent list"
10135         true
10136
10137         rm -f $DIR/f
10138         restore_lustre_params < $save
10139 }
10140 run_test 154f "get parent fids by reading link ea"
10141
10142 test_154g()
10143 {
10144         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) ]] ||
10145                 { skip "Need MDS version at least 2.6.92"; return 0; }
10146
10147         mkdir -p $DIR/$tdir
10148         llapi_fid_test -d $DIR/$tdir
10149 }
10150 run_test 154g "various llapi FID tests"
10151
10152 test_155_small_load() {
10153     local temp=$TMP/$tfile
10154     local file=$DIR/$tfile
10155
10156     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
10157         error "dd of=$temp bs=6096 count=1 failed"
10158     cp $temp $file
10159     cancel_lru_locks osc
10160     cmp $temp $file || error "$temp $file differ"
10161
10162     $TRUNCATE $temp 6000
10163     $TRUNCATE $file 6000
10164     cmp $temp $file || error "$temp $file differ (truncate1)"
10165
10166     echo "12345" >>$temp
10167     echo "12345" >>$file
10168     cmp $temp $file || error "$temp $file differ (append1)"
10169
10170     echo "12345" >>$temp
10171     echo "12345" >>$file
10172     cmp $temp $file || error "$temp $file differ (append2)"
10173
10174     rm -f $temp $file
10175     true
10176 }
10177
10178 test_155_big_load() {
10179     remote_ost_nodsh && skip "remote OST with nodsh" && return
10180     local temp=$TMP/$tfile
10181     local file=$DIR/$tfile
10182
10183     free_min_max
10184     local cache_size=$(do_facet ost$((MAXI+1)) \
10185         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
10186     local large_file_size=$((cache_size * 2))
10187
10188     echo "OSS cache size: $cache_size KB"
10189     echo "Large file size: $large_file_size KB"
10190
10191     [ $MAXV -le $large_file_size ] && \
10192         skip_env "max available OST size needs > $large_file_size KB" && \
10193         return 0
10194
10195     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
10196
10197     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
10198         error "dd of=$temp bs=$large_file_size count=1k failed"
10199     cp $temp $file
10200     ls -lh $temp $file
10201     cancel_lru_locks osc
10202     cmp $temp $file || error "$temp $file differ"
10203
10204     rm -f $temp $file
10205     true
10206 }
10207
10208 test_155a() {
10209         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10210         set_cache read on
10211         set_cache writethrough on
10212         test_155_small_load
10213 }
10214 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
10215
10216 test_155b() {
10217         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10218         set_cache read on
10219         set_cache writethrough off
10220         test_155_small_load
10221 }
10222 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
10223
10224 test_155c() {
10225         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10226         set_cache read off
10227         set_cache writethrough on
10228         test_155_small_load
10229 }
10230 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
10231
10232 test_155d() {
10233         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10234         set_cache read off
10235         set_cache writethrough off
10236         test_155_small_load
10237 }
10238 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
10239
10240 test_155e() {
10241         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10242         set_cache read on
10243         set_cache writethrough on
10244         test_155_big_load
10245 }
10246 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
10247
10248 test_155f() {
10249         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10250         set_cache read on
10251         set_cache writethrough off
10252         test_155_big_load
10253 }
10254 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
10255
10256 test_155g() {
10257         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10258         set_cache read off
10259         set_cache writethrough on
10260         test_155_big_load
10261 }
10262 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
10263
10264 test_155h() {
10265         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10266         set_cache read off
10267         set_cache writethrough off
10268         test_155_big_load
10269 }
10270 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
10271
10272 test_156() {
10273         remote_ost_nodsh && skip "remote OST with nodsh" && return
10274         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10275         local CPAGES=3
10276         local BEFORE
10277         local AFTER
10278         local file="$DIR/$tfile"
10279
10280         [ "$(facet_fstype ost1)" = "zfs" -a \
10281            $(lustre_version_code ost1 -lt $(version_code 2.6.93)) ] &&
10282                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS" &&
10283                 return
10284
10285         roc_hit_init
10286
10287         log "Turn on read and write cache"
10288         set_cache read on
10289         set_cache writethrough on
10290
10291         log "Write data and read it back."
10292         log "Read should be satisfied from the cache."
10293         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10294         BEFORE=$(roc_hit)
10295         cancel_lru_locks osc
10296         cat $file >/dev/null
10297         AFTER=$(roc_hit)
10298         if ! let "AFTER - BEFORE == CPAGES"; then
10299                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10300         else
10301                 log "cache hits:: before: $BEFORE, after: $AFTER"
10302         fi
10303
10304         log "Read again; it should be satisfied from the cache."
10305         BEFORE=$AFTER
10306         cancel_lru_locks osc
10307         cat $file >/dev/null
10308         AFTER=$(roc_hit)
10309         if ! let "AFTER - BEFORE == CPAGES"; then
10310                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10311         else
10312                 log "cache hits:: before: $BEFORE, after: $AFTER"
10313         fi
10314
10315         log "Turn off the read cache and turn on the write cache"
10316         set_cache read off
10317         set_cache writethrough on
10318
10319         log "Read again; it should be satisfied from the cache."
10320         BEFORE=$(roc_hit)
10321         cancel_lru_locks osc
10322         cat $file >/dev/null
10323         AFTER=$(roc_hit)
10324         if ! let "AFTER - BEFORE == CPAGES"; then
10325                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10326         else
10327                 log "cache hits:: before: $BEFORE, after: $AFTER"
10328         fi
10329
10330         log "Read again; it should not be satisfied from the cache."
10331         BEFORE=$AFTER
10332         cancel_lru_locks osc
10333         cat $file >/dev/null
10334         AFTER=$(roc_hit)
10335         if ! let "AFTER - BEFORE == 0"; then
10336                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10337         else
10338                 log "cache hits:: before: $BEFORE, after: $AFTER"
10339         fi
10340
10341         log "Write data and read it back."
10342         log "Read should be satisfied from the cache."
10343         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10344         BEFORE=$(roc_hit)
10345         cancel_lru_locks osc
10346         cat $file >/dev/null
10347         AFTER=$(roc_hit)
10348         if ! let "AFTER - BEFORE == CPAGES"; then
10349                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10350         else
10351                 log "cache hits:: before: $BEFORE, after: $AFTER"
10352         fi
10353
10354         log "Read again; it should not be satisfied from the cache."
10355         BEFORE=$AFTER
10356         cancel_lru_locks osc
10357         cat $file >/dev/null
10358         AFTER=$(roc_hit)
10359         if ! let "AFTER - BEFORE == 0"; then
10360                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10361         else
10362                 log "cache hits:: before: $BEFORE, after: $AFTER"
10363         fi
10364
10365         log "Turn off read and write cache"
10366         set_cache read off
10367         set_cache writethrough off
10368
10369         log "Write data and read it back"
10370         log "It should not be satisfied from the cache."
10371         rm -f $file
10372         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10373         cancel_lru_locks osc
10374         BEFORE=$(roc_hit)
10375         cat $file >/dev/null
10376         AFTER=$(roc_hit)
10377         if ! let "AFTER - BEFORE == 0"; then
10378                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10379         else
10380                 log "cache hits:: before: $BEFORE, after: $AFTER"
10381         fi
10382
10383         log "Turn on the read cache and turn off the write cache"
10384         set_cache read on
10385         set_cache writethrough off
10386
10387         log "Write data and read it back"
10388         log "It should not be satisfied from the cache."
10389         rm -f $file
10390         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10391         BEFORE=$(roc_hit)
10392         cancel_lru_locks osc
10393         cat $file >/dev/null
10394         AFTER=$(roc_hit)
10395         if ! let "AFTER - BEFORE == 0"; then
10396                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10397         else
10398                 log "cache hits:: before: $BEFORE, after: $AFTER"
10399         fi
10400
10401         log "Read again; it should be satisfied from the cache."
10402         BEFORE=$(roc_hit)
10403         cancel_lru_locks osc
10404         cat $file >/dev/null
10405         AFTER=$(roc_hit)
10406         if ! let "AFTER - BEFORE == CPAGES"; then
10407                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10408         else
10409                 log "cache hits:: before: $BEFORE, after: $AFTER"
10410         fi
10411
10412         rm -f $file
10413 }
10414 run_test 156 "Verification of tunables"
10415
10416 #Changelogs
10417 err17935 () {
10418         if [[ $MDSCOUNT -gt 1 ]]; then
10419                 error_ignore bz17935 $*
10420         else
10421                 error $*
10422         fi
10423 }
10424
10425 changelog_chmask()
10426 {
10427         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10428
10429         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
10430
10431         if [ $MASK -eq 1 ]; then
10432                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
10433         else
10434                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
10435         fi
10436 }
10437
10438 changelog_extract_field() {
10439         local mdt=$1
10440         local cltype=$2
10441         local file=$3
10442         local identifier=$4
10443
10444         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
10445                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10446                 tail -1
10447 }
10448
10449 test_160a() {
10450         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10451         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10452         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10453                 { skip "Need MDS version at least 2.2.0"; return; }
10454
10455         local CL_USERS="mdd.$MDT0.changelog_users"
10456         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10457         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10458         echo "Registered as changelog user $USER"
10459         $GET_CL_USERS | grep -q $USER ||
10460                 error "User $USER not found in changelog_users"
10461
10462         # change something
10463         test_mkdir -p $DIR/$tdir/pics/2008/zachy
10464         touch $DIR/$tdir/pics/2008/zachy/timestamp
10465         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
10466         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
10467         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
10468         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
10469         rm $DIR/$tdir/pics/desktop.jpg
10470
10471         $LFS changelog $MDT0 | tail -5
10472
10473         echo "verifying changelog mask"
10474         changelog_chmask "MKDIR"
10475         changelog_chmask "CLOSE"
10476
10477         test_mkdir -p $DIR/$tdir/pics/zach/sofia
10478         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10479
10480         changelog_chmask "MKDIR"
10481         changelog_chmask "CLOSE"
10482
10483         test_mkdir -p $DIR/$tdir/pics/2008/sofia
10484         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10485
10486         $LFS changelog $MDT0
10487         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
10488         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
10489         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
10490         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
10491
10492         # verify contents
10493         echo "verifying target fid"
10494         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
10495         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
10496         [ "$fidc" == "$fidf" ] ||
10497                 err17935 "fid in changelog $fidc != file fid $fidf"
10498         echo "verifying parent fid"
10499         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
10500         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
10501         [ "$fidc" == "$fidf" ] ||
10502                 err17935 "pfid in changelog $fidc != dir fid $fidf"
10503
10504         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10505         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
10506         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10507         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
10508         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
10509                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
10510
10511         MIN_REC=$($GET_CL_USERS |
10512                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
10513         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
10514         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
10515         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
10516                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
10517
10518         # LU-3446 changelog index reset on MDT restart
10519         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10520         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10521         $LFS changelog_clear $MDT0 $USER 0
10522         stop $SINGLEMDS || error "Fail to stop MDT."
10523         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10524         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10525         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
10526         [ $CUR_REC1 == $CUR_REC2 ] ||
10527                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
10528
10529         echo "verifying user deregister"
10530         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10531         $GET_CL_USERS | grep -q $USER &&
10532                 error "User $USER still in changelog_users"
10533
10534         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
10535         if [ $USERS -eq 0 ]; then
10536                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10537                 touch $DIR/$tdir/chloe
10538                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10539                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
10540                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
10541         else
10542                 echo "$USERS other changelog users; can't verify off"
10543         fi
10544 }
10545 run_test 160a "changelog sanity"
10546
10547 test_160b() { # LU-3587
10548         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10549         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10550         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10551                 { skip "Need MDS version at least 2.2.0"; return; }
10552
10553         local CL_USERS="mdd.$MDT0.changelog_users"
10554         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10555         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10556         echo "Registered as changelog user $USER"
10557         $GET_CL_USERS | grep -q $USER ||
10558                 error "User $USER not found in changelog_users"
10559
10560         local LONGNAME1=$(str_repeat a 255)
10561         local LONGNAME2=$(str_repeat b 255)
10562
10563         cd $DIR
10564         echo "creating very long named file"
10565         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
10566         echo "moving very long named file"
10567         mv $LONGNAME1 $LONGNAME2
10568
10569         $LFS changelog $MDT0 | grep RENME
10570
10571         echo "deregistering $USER"
10572         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10573
10574         rm -f $LONGNAME2
10575 }
10576 run_test 160b "Verify that very long rename doesn't crash in changelog"
10577
10578 test_160c() {
10579         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10580
10581         local rc=0
10582         local server_version=$(lustre_version_code $SINGLEMDS)
10583
10584         [[ $server_version -gt $(version_code 2.5.57) ]] ||
10585                 [[ $server_version -gt $(version_code 2.5.1) &&
10586                    $server_version -lt $(version_code 2.5.50) ]] ||
10587                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
10588         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10589
10590         # Registration step
10591         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10592                 changelog_register -n)
10593
10594         rm -rf $DIR/$tdir
10595         mkdir -p $DIR/$tdir
10596         $MCREATE $DIR/$tdir/foo_160c
10597         changelog_chmask "TRUNC"
10598         $TRUNCATE $DIR/$tdir/foo_160c 200
10599         changelog_chmask "TRUNC"
10600         $TRUNCATE $DIR/$tdir/foo_160c 199
10601         $LFS changelog $MDT0
10602         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
10603         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
10604         $LFS changelog_clear $MDT0 $USER 0
10605
10606         # Deregistration step
10607         echo "deregistering $USER"
10608         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10609 }
10610 run_test 160c "verify that changelog log catch the truncate event"
10611
10612 test_160d() {
10613         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10614         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10615
10616         local server_version=$(lustre_version_code mds1)
10617         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10618
10619         [[ $server_version -ge $(version_code 2.7.60) ]] ||
10620                 { skip "Need MDS version at least 2.7.60+"; return; }
10621         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10622
10623         # Registration step
10624         local USER=$(do_facet mds1 $LCTL --device $MDT0 \
10625                 changelog_register -n)
10626
10627         mkdir -p $DIR/$tdir/migrate_dir
10628         $LFS changelog_clear $MDT0 $USER 0
10629
10630         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
10631         $LFS changelog $MDT0
10632         MIGRATES=$($LFS changelog $MDT0 | tail -5 | grep -c "MIGRT")
10633         $LFS changelog_clear $MDT0 $USER 0
10634         [ $MIGRATES -eq 1 ] ||
10635                 error "MIGRATE changelog mask count $MIGRATES != 1"
10636
10637         # Deregistration step
10638         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $USER
10639 }
10640 run_test 160d "verify that changelog log catch the migrate event"
10641
10642 test_161a() {
10643         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10644         test_mkdir -p -c1 $DIR/$tdir
10645         cp /etc/hosts $DIR/$tdir/$tfile
10646         test_mkdir -c1 $DIR/$tdir/foo1
10647         test_mkdir -c1 $DIR/$tdir/foo2
10648         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
10649         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
10650         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
10651         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
10652         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
10653         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10654                 $LFS fid2path $DIR $FID
10655                 err17935 "bad link ea"
10656         fi
10657     # middle
10658     rm $DIR/$tdir/foo2/zachary
10659     # last
10660     rm $DIR/$tdir/foo2/thor
10661     # first
10662     rm $DIR/$tdir/$tfile
10663     # rename
10664     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
10665     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
10666         then
10667         $LFS fid2path $DIR $FID
10668         err17935 "bad link rename"
10669     fi
10670     rm $DIR/$tdir/foo2/maggie
10671
10672         # overflow the EA
10673         local longname=filename_avg_len_is_thirty_two_
10674         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
10675                 error "failed to hardlink many files"
10676         links=$($LFS fid2path $DIR $FID | wc -l)
10677         echo -n "${links}/1000 links in link EA"
10678         [[ $links -gt 60 ]] ||
10679                 err17935 "expected at least 60 links in link EA"
10680         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
10681                 error "failed to unlink many hardlinks"
10682 }
10683 run_test 161a "link ea sanity"
10684
10685 test_161b() {
10686         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10687         [ $MDSCOUNT -lt 2 ] &&
10688                 skip "skipping remote directory test" && return
10689         local MDTIDX=1
10690         local remote_dir=$DIR/$tdir/remote_dir
10691
10692         mkdir -p $DIR/$tdir
10693         $LFS mkdir -i $MDTIDX $remote_dir ||
10694                 error "create remote directory failed"
10695
10696         cp /etc/hosts $remote_dir/$tfile
10697         mkdir -p $remote_dir/foo1
10698         mkdir -p $remote_dir/foo2
10699         ln $remote_dir/$tfile $remote_dir/foo1/sofia
10700         ln $remote_dir/$tfile $remote_dir/foo2/zachary
10701         ln $remote_dir/$tfile $remote_dir/foo1/luna
10702         ln $remote_dir/$tfile $remote_dir/foo2/thor
10703
10704         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
10705                      tr -d ']')
10706         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10707                 $LFS fid2path $DIR $FID
10708                 err17935 "bad link ea"
10709         fi
10710         # middle
10711         rm $remote_dir/foo2/zachary
10712         # last
10713         rm $remote_dir/foo2/thor
10714         # first
10715         rm $remote_dir/$tfile
10716         # rename
10717         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
10718         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
10719         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
10720                 $LFS fid2path $DIR $FID
10721                 err17935 "bad link rename"
10722         fi
10723         rm $remote_dir/foo2/maggie
10724
10725         # overflow the EA
10726         local longname=filename_avg_len_is_thirty_two_
10727         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10728                 error "failed to hardlink many files"
10729         links=$($LFS fid2path $DIR $FID | wc -l)
10730         echo -n "${links}/1000 links in link EA"
10731         [[ ${links} -gt 60 ]] ||
10732                 err17935 "expected at least 60 links in link EA"
10733         unlinkmany $remote_dir/foo2/$longname 1000 ||
10734         error "failed to unlink many hardlinks"
10735 }
10736 run_test 161b "link ea sanity under remote directory"
10737
10738 test_161c() {
10739         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10740         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10741         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10742                 skip "Need MDS version at least 2.1.5" && return
10743
10744         # define CLF_RENAME_LAST 0x0001
10745         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10746         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10747                 changelog_register -n)
10748         rm -rf $DIR/$tdir
10749         mkdir -p $DIR/$tdir
10750         touch $DIR/$tdir/foo_161c
10751         touch $DIR/$tdir/bar_161c
10752         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10753         $LFS changelog $MDT0 | grep RENME
10754         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10755                 cut -f5 -d' ')
10756         $LFS changelog_clear $MDT0 $USER 0
10757         if [ x$flags != "x0x1" ]; then
10758                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10759                         $USER
10760                 error "flag $flags is not 0x1"
10761         fi
10762         echo "rename overwrite a target having nlink = 1," \
10763                 "changelog record has flags of $flags"
10764
10765         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10766         touch $DIR/$tdir/foo_161c
10767         touch $DIR/$tdir/bar_161c
10768         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10769         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10770         $LFS changelog $MDT0 | grep RENME
10771         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10772         $LFS changelog_clear $MDT0 $USER 0
10773         if [ x$flags != "x0x0" ]; then
10774                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10775                         $USER
10776                 error "flag $flags is not 0x0"
10777         fi
10778         echo "rename overwrite a target having nlink > 1," \
10779                 "changelog record has flags of $flags"
10780
10781         # rename doesn't overwrite a target (changelog flag 0x0)
10782         touch $DIR/$tdir/foo_161c
10783         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10784         $LFS changelog $MDT0 | grep RENME
10785         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10786         $LFS changelog_clear $MDT0 $USER 0
10787         if [ x$flags != "x0x0" ]; then
10788                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10789                         $USER
10790                 error "flag $flags is not 0x0"
10791         fi
10792         echo "rename doesn't overwrite a target," \
10793                 "changelog record has flags of $flags"
10794
10795         # define CLF_UNLINK_LAST 0x0001
10796         # unlink a file having nlink = 1 (changelog flag 0x1)
10797         rm -f $DIR/$tdir/foo2_161c
10798         $LFS changelog $MDT0 | grep UNLNK
10799         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10800         $LFS changelog_clear $MDT0 $USER 0
10801         if [ x$flags != "x0x1" ]; then
10802                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10803                         $USER
10804                 error "flag $flags is not 0x1"
10805         fi
10806         echo "unlink a file having nlink = 1," \
10807                 "changelog record has flags of $flags"
10808
10809         # unlink a file having nlink > 1 (changelog flag 0x0)
10810         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10811         rm -f $DIR/$tdir/foobar_161c
10812         $LFS changelog $MDT0 | grep UNLNK
10813         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10814         $LFS changelog_clear $MDT0 $USER 0
10815         if [ x$flags != "x0x0" ]; then
10816                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10817                         $USER
10818                 error "flag $flags is not 0x0"
10819         fi
10820         echo "unlink a file having nlink > 1," \
10821                 "changelog record has flags of $flags"
10822         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10823 }
10824 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10825
10826 check_path() {
10827     local expected=$1
10828     shift
10829     local fid=$2
10830
10831     local path=$(${LFS} fid2path $*)
10832     # Remove the '//' indicating a remote directory
10833     path=$(echo $path | sed 's#//#/#g')
10834     RC=$?
10835
10836     if [ $RC -ne 0 ]; then
10837         err17935 "path looked up of $expected failed. Error $RC"
10838         return $RC
10839     elif [ "${path}" != "${expected}" ]; then
10840         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10841         return 2
10842     fi
10843     echo "fid $fid resolves to path $path (expected $expected)"
10844 }
10845
10846 test_162a() { # was test_162
10847         # Make changes to filesystem
10848         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10849         test_mkdir -p -c1 $DIR/$tdir/d2
10850         touch $DIR/$tdir/d2/$tfile
10851         touch $DIR/$tdir/d2/x1
10852         touch $DIR/$tdir/d2/x2
10853         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
10854         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
10855         # regular file
10856         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10857         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
10858                 error "check path $tdir/d2/$tfile failed"
10859
10860         # softlink
10861         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10862         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10863         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
10864                 error "check path $tdir/d2/p/q/r/slink failed"
10865
10866         # softlink to wrong file
10867         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10868         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10869         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
10870                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
10871
10872         # hardlink
10873         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10874         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10875         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10876         # fid2path dir/fsname should both work
10877         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
10878                 error "check path $tdir/d2/a/b/c/new_file failed"
10879         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
10880                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
10881
10882         # hardlink count: check that there are 2 links
10883         # Doesnt work with CMD yet: 17935
10884         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10885                 err17935 "expected 2 links"
10886
10887         # hardlink indexing: remove the first link
10888         rm $DIR/$tdir/d2/p/q/r/hlink
10889         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
10890                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
10891
10892         return 0
10893 }
10894 run_test 162a "path lookup sanity"
10895
10896 test_162b() {
10897         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10898         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10899
10900         mkdir $DIR/$tdir
10901         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
10902                                 error "create striped dir failed"
10903
10904         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
10905                                         tail -n 1 | awk '{print $2}')
10906         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
10907
10908         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
10909         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
10910
10911         # regular file
10912         for ((i=0;i<5;i++)); do
10913                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
10914                         error "get fid for f$i failed"
10915                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
10916                         error "check path $tdir/striped_dir/f$i failed"
10917
10918                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
10919                         error "get fid for d$i failed"
10920                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
10921                         error "check path $tdir/striped_dir/d$i failed"
10922         done
10923
10924         return 0
10925 }
10926 run_test 162b "striped directory path lookup sanity"
10927
10928 # LU-4239: Verify fid2path works with paths 100 or more directories deep
10929 test_162c() {
10930         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.51) ]] &&
10931                 skip "Need MDS version at least 2.7.51" && return
10932         test_mkdir $DIR/$tdir.local
10933         test_mkdir $DIR/$tdir.remote
10934         local lpath=$tdir.local
10935         local rpath=$tdir.remote
10936
10937         for ((i = 0; i <= 101; i++)); do
10938                 lpath="$lpath/$i"
10939                 mkdir $DIR/$lpath
10940                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
10941                         error "get fid for local directory $DIR/$lpath failed"
10942                 check_path "$DIR/$lpath" $MOUNT $FID --link 0 ||
10943                         error "check path for local directory $DIR/$lpath failed"
10944
10945                 rpath="$rpath/$i"
10946                 test_mkdir $DIR/$rpath
10947                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
10948                         error "get fid for remote directory $DIR/$rpath failed"
10949                 check_path "$DIR/$rpath" $MOUNT $FID --link 0 ||
10950                         error "check path for remote directory $DIR/$rpath failed"
10951         done
10952
10953         return 0
10954 }
10955 run_test 162c "fid2path works with paths 100 or more directories deep"
10956
10957 test_169() {
10958         # do directio so as not to populate the page cache
10959         log "creating a 10 Mb file"
10960         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10961         log "starting reads"
10962         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10963         log "truncating the file"
10964         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10965         log "killing dd"
10966         kill %+ || true # reads might have finished
10967         echo "wait until dd is finished"
10968         wait
10969         log "removing the temporary file"
10970         rm -rf $DIR/$tfile || error "tmp file removal failed"
10971 }
10972 run_test 169 "parallel read and truncate should not deadlock"
10973
10974 test_170() {
10975         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10976         $LCTL clear     # bug 18514
10977         $LCTL debug_daemon start $TMP/${tfile}_log_good
10978         touch $DIR/$tfile
10979         $LCTL debug_daemon stop
10980         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10981                error "sed failed to read log_good"
10982
10983         $LCTL debug_daemon start $TMP/${tfile}_log_good
10984         rm -rf $DIR/$tfile
10985         $LCTL debug_daemon stop
10986
10987         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10988                error "lctl df log_bad failed"
10989
10990         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10991         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10992
10993         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10994         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10995
10996         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10997                 error "bad_line good_line1 good_line2 are empty"
10998
10999         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11000         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
11001         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
11002
11003         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
11004         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
11005         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
11006
11007         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
11008                 error "bad_line_new good_line_new are empty"
11009
11010         local expected_good=$((good_line1 + good_line2*2))
11011
11012         rm -f $TMP/${tfile}*
11013         # LU-231, short malformed line may not be counted into bad lines
11014         if [ $bad_line -ne $bad_line_new ] &&
11015                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
11016                 error "expected $bad_line bad lines, but got $bad_line_new"
11017                 return 1
11018         fi
11019
11020         if [ $expected_good -ne $good_line_new ]; then
11021                 error "expected $expected_good good lines, but got $good_line_new"
11022                 return 2
11023         fi
11024         true
11025 }
11026 run_test 170 "test lctl df to handle corrupted log ====================="
11027
11028 test_171() { # bug20592
11029         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11030 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
11031         $LCTL set_param fail_loc=0x50e
11032         $LCTL set_param fail_val=3000
11033         multiop_bg_pause $DIR/$tfile O_s || true
11034         local MULTIPID=$!
11035         kill -USR1 $MULTIPID
11036         # cause log dump
11037         sleep 3
11038         wait $MULTIPID
11039         if dmesg | grep "recursive fault"; then
11040                 error "caught a recursive fault"
11041         fi
11042         $LCTL set_param fail_loc=0
11043         true
11044 }
11045 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
11046
11047 # it would be good to share it with obdfilter-survey/iokit-libecho code
11048 setup_obdecho_osc () {
11049         local rc=0
11050         local ost_nid=$1
11051         local obdfilter_name=$2
11052         echo "Creating new osc for $obdfilter_name on $ost_nid"
11053         # make sure we can find loopback nid
11054         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
11055
11056         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
11057                            ${obdfilter_name}_osc_UUID || rc=2; }
11058         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
11059                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
11060         return $rc
11061 }
11062
11063 cleanup_obdecho_osc () {
11064         local obdfilter_name=$1
11065         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
11066         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
11067         return 0
11068 }
11069
11070 obdecho_test() {
11071         local OBD=$1
11072         local node=$2
11073         local pages=${3:-64}
11074         local rc=0
11075         local id
11076
11077         local count=10
11078         local obd_size=$(get_obd_size $node $OBD)
11079         local page_size=$(get_page_size $node)
11080         if [[ -n "$obd_size" ]]; then
11081                 local new_count=$((obd_size / (pages * page_size / 1024)))
11082                 [[ $new_count -ge $count ]] || count=$new_count
11083         fi
11084
11085         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
11086         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
11087                            rc=2; }
11088         if [ $rc -eq 0 ]; then
11089             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
11090             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
11091         fi
11092         echo "New object id is $id"
11093         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
11094                            rc=4; }
11095         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
11096                            "test_brw $count w v $pages $id" || rc=4; }
11097         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
11098                            rc=4; }
11099         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
11100                                         "cleanup" || rc=5; }
11101         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
11102                                         "detach" || rc=6; }
11103         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
11104         return $rc
11105 }
11106
11107 test_180a() {
11108         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11109         remote_ost_nodsh && skip "remote OST with nodsh" && return
11110         local rc=0
11111         local rmmod_local=0
11112
11113         if ! module_loaded obdecho; then
11114             load_module obdecho/obdecho
11115             rmmod_local=1
11116         fi
11117
11118         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
11119         local host=$(lctl get_param -n osc.$osc.import |
11120                              awk '/current_connection:/ {print $2}' )
11121         local target=$(lctl get_param -n osc.$osc.import |
11122                              awk '/target:/ {print $2}' )
11123         target=${target%_UUID}
11124
11125         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
11126         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
11127         [[ -n $target ]] && cleanup_obdecho_osc $target
11128         [ $rmmod_local -eq 1 ] && rmmod obdecho
11129         return $rc
11130 }
11131 run_test 180a "test obdecho on osc"
11132
11133 test_180b() {
11134         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11135         remote_ost_nodsh && skip "remote OST with nodsh" && return
11136         local rc=0
11137         local rmmod_remote=0
11138
11139         do_facet ost1 "lsmod | grep -q obdecho || "                      \
11140                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
11141                       "modprobe obdecho; }" && rmmod_remote=1
11142         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
11143         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
11144         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
11145         return $rc
11146 }
11147 run_test 180b "test obdecho directly on obdfilter"
11148
11149 test_180c() { # LU-2598
11150         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11151         remote_ost_nodsh && skip "remote OST with nodsh" && return
11152         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
11153                 skip "Need MDS version at least 2.4.0" && return
11154
11155         local rc=0
11156         local rmmod_remote=false
11157         local pages=16384 # 64MB bulk I/O RPC size
11158         local target
11159
11160         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
11161                 rmmod_remote=true || error "failed to load module obdecho"
11162
11163         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
11164                 head -n1)
11165         if [ -n "$target" ]; then
11166                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
11167         else
11168                 echo "there is no obdfilter target on ost1"
11169                 rc=2
11170         fi
11171         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
11172         return $rc
11173 }
11174 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
11175
11176 test_181() { # bug 22177
11177         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11178         # create enough files to index the directory
11179         createmany -o $DIR/$tdir/foobar 4000
11180         # print attributes for debug purpose
11181         lsattr -d .
11182         # open dir
11183         multiop_bg_pause $DIR/$tdir D_Sc || return 1
11184         MULTIPID=$!
11185         # remove the files & current working dir
11186         unlinkmany $DIR/$tdir/foobar 4000
11187         rmdir $DIR/$tdir
11188         kill -USR1 $MULTIPID
11189         wait $MULTIPID
11190         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
11191         return 0
11192 }
11193 run_test 181 "Test open-unlinked dir ========================"
11194
11195 test_182() {
11196         local fcount=1000
11197         local tcount=10
11198
11199         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11200
11201         $LCTL set_param mdc.*.rpc_stats=clear
11202
11203         for (( i = 0; i < $tcount; i++ )) ; do
11204                 mkdir $DIR/$tdir/$i
11205         done
11206
11207         for (( i = 0; i < $tcount; i++ )) ; do
11208                 createmany -o $DIR/$tdir/$i/f- $fcount &
11209         done
11210         wait
11211
11212         for (( i = 0; i < $tcount; i++ )) ; do
11213                 unlinkmany $DIR/$tdir/$i/f- $fcount &
11214         done
11215         wait
11216
11217         $LCTL get_param mdc.*.rpc_stats
11218
11219         rm -rf $DIR/$tdir
11220 }
11221 run_test 182 "Test parallel modify metadata operations ================"
11222
11223 test_183() { # LU-2275
11224         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11225         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
11226                 skip "Need MDS version at least 2.3.56" && return
11227
11228         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11229         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11230         echo aaa > $DIR/$tdir/$tfile
11231
11232 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
11233         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
11234
11235         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
11236         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
11237
11238         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
11239
11240         # Flush negative dentry cache
11241         touch $DIR/$tdir/$tfile
11242
11243         # We are not checking for any leaked references here, they'll
11244         # become evident next time we do cleanup with module unload.
11245         rm -rf $DIR/$tdir
11246 }
11247 run_test 183 "No crash or request leak in case of strange dispositions ========"
11248
11249 # test suite 184 is for LU-2016, LU-2017
11250 test_184a() {
11251         check_swap_layouts_support && return 0
11252
11253         dir0=$DIR/$tdir/$testnum
11254         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
11255         ref1=/etc/passwd
11256         ref2=/etc/group
11257         file1=$dir0/f1
11258         file2=$dir0/f2
11259         $SETSTRIPE -c1 $file1
11260         cp $ref1 $file1
11261         $SETSTRIPE -c2 $file2
11262         cp $ref2 $file2
11263         gen1=$($GETSTRIPE -g $file1)
11264         gen2=$($GETSTRIPE -g $file2)
11265
11266         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
11267         gen=$($GETSTRIPE -g $file1)
11268         [[ $gen1 != $gen ]] ||
11269                 "Layout generation on $file1 does not change"
11270         gen=$($GETSTRIPE -g $file2)
11271         [[ $gen2 != $gen ]] ||
11272                 "Layout generation on $file2 does not change"
11273
11274         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
11275         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
11276 }
11277 run_test 184a "Basic layout swap"
11278
11279 test_184b() {
11280         check_swap_layouts_support && return 0
11281
11282         dir0=$DIR/$tdir/$testnum
11283         mkdir -p $dir0 || error "creating dir $dir0"
11284         file1=$dir0/f1
11285         file2=$dir0/f2
11286         file3=$dir0/f3
11287         dir1=$dir0/d1
11288         dir2=$dir0/d2
11289         mkdir $dir1 $dir2
11290         $SETSTRIPE -c1 $file1
11291         $SETSTRIPE -c2 $file2
11292         $SETSTRIPE -c1 $file3
11293         chown $RUNAS_ID $file3
11294         gen1=$($GETSTRIPE -g $file1)
11295         gen2=$($GETSTRIPE -g $file2)
11296
11297         $LFS swap_layouts $dir1 $dir2 &&
11298                 error "swap of directories layouts should fail"
11299         $LFS swap_layouts $dir1 $file1 &&
11300                 error "swap of directory and file layouts should fail"
11301         $RUNAS $LFS swap_layouts $file1 $file2 &&
11302                 error "swap of file we cannot write should fail"
11303         $LFS swap_layouts $file1 $file3 &&
11304                 error "swap of file with different owner should fail"
11305         /bin/true # to clear error code
11306 }
11307 run_test 184b "Forbidden layout swap (will generate errors)"
11308
11309 test_184c() {
11310         check_swap_layouts_support && return 0
11311
11312         local dir0=$DIR/$tdir/$testnum
11313         mkdir -p $dir0 || error "creating dir $dir0"
11314
11315         local ref1=$dir0/ref1
11316         local ref2=$dir0/ref2
11317         local file1=$dir0/file1
11318         local file2=$dir0/file2
11319         # create a file large enough for the concurrent test
11320         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
11321         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
11322         echo "ref file size: ref1($(stat -c %s $ref1))," \
11323              "ref2($(stat -c %s $ref2))"
11324
11325         cp $ref2 $file2
11326         dd if=$ref1 of=$file1 bs=16k &
11327         local DD_PID=$!
11328
11329         # Make sure dd starts to copy file
11330         while [ ! -f $file1 ]; do sleep 0.1; done
11331
11332         $LFS swap_layouts $file1 $file2
11333         local rc=$?
11334         wait $DD_PID
11335         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
11336         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
11337
11338         # how many bytes copied before swapping layout
11339         local copied=$(stat -c %s $file2)
11340         local remaining=$(stat -c %s $ref1)
11341         remaining=$((remaining - copied))
11342         echo "Copied $copied bytes before swapping layout..."
11343
11344         cmp -n $copied $file1 $ref2 | grep differ &&
11345                 error "Content mismatch [0, $copied) of ref2 and file1"
11346         cmp -n $copied $file2 $ref1 ||
11347                 error "Content mismatch [0, $copied) of ref1 and file2"
11348         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
11349                 error "Content mismatch [$copied, EOF) of ref1 and file1"
11350
11351         # clean up
11352         rm -f $ref1 $ref2 $file1 $file2
11353 }
11354 run_test 184c "Concurrent write and layout swap"
11355
11356 test_184d() {
11357         check_swap_layouts_support && return 0
11358         [ -z "$(which getfattr 2>/dev/null)" ] &&
11359                 skip "no getfattr command" && return 0
11360
11361         local file1=$DIR/$tdir/$tfile-1
11362         local file2=$DIR/$tdir/$tfile-2
11363         local file3=$DIR/$tdir/$tfile-3
11364         local lovea1
11365         local lovea2
11366
11367         mkdir -p $DIR/$tdir
11368         touch $file1 || error "create $file1 failed"
11369         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11370                 error "create $file2 failed"
11371         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11372                 error "create $file3 failed"
11373         lovea1=$($LFS getstripe $file1 | sed 1d)
11374
11375         $LFS swap_layouts $file2 $file3 ||
11376                 error "swap $file2 $file3 layouts failed"
11377         $LFS swap_layouts $file1 $file2 ||
11378                 error "swap $file1 $file2 layouts failed"
11379
11380         lovea2=$($LFS getstripe $file2 | sed 1d)
11381         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
11382
11383         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11384         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
11385 }
11386 run_test 184d "allow stripeless layouts swap"
11387
11388 test_184e() {
11389         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
11390                 { skip "Need MDS version at least 2.6.94"; return 0; }
11391         check_swap_layouts_support && return 0
11392         [ -z "$(which getfattr 2>/dev/null)" ] &&
11393                 skip "no getfattr command" && return 0
11394
11395         local file1=$DIR/$tdir/$tfile-1
11396         local file2=$DIR/$tdir/$tfile-2
11397         local file3=$DIR/$tdir/$tfile-3
11398         local lovea
11399
11400         mkdir -p $DIR/$tdir
11401         touch $file1 || error "create $file1 failed"
11402         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11403                 error "create $file2 failed"
11404         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11405                 error "create $file3 failed"
11406
11407         $LFS swap_layouts $file1 $file2 ||
11408                 error "swap $file1 $file2 layouts failed"
11409
11410         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11411         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
11412
11413         echo 123 > $file1 || error "Should be able to write into $file1"
11414
11415         $LFS swap_layouts $file1 $file3 ||
11416                 error "swap $file1 $file3 layouts failed"
11417
11418         echo 123 > $file1 || error "Should be able to write into $file1"
11419
11420         rm -rf $file1 $file2 $file3
11421 }
11422 run_test 184e "Recreate layout after stripeless layout swaps"
11423
11424 test_185() { # LU-2441
11425         # LU-3553 - no volatile file support in old servers
11426         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
11427                 { skip "Need MDS version at least 2.3.60"; return 0; }
11428
11429         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11430         touch $DIR/$tdir/spoo
11431         local mtime1=$(stat -c "%Y" $DIR/$tdir)
11432         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
11433                 error "cannot create/write a volatile file"
11434         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
11435                 error "FID is still valid after close"
11436
11437         multiop_bg_pause $DIR/$tdir vVw4096_c
11438         local multi_pid=$!
11439
11440         local OLD_IFS=$IFS
11441         IFS=":"
11442         local fidv=($fid)
11443         IFS=$OLD_IFS
11444         # assume that the next FID for this client is sequential, since stdout
11445         # is unfortunately eaten by multiop_bg_pause
11446         local n=$((${fidv[1]} + 1))
11447         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
11448         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
11449                 error "FID is missing before close"
11450         kill -USR1 $multi_pid
11451         # 1 second delay, so if mtime change we will see it
11452         sleep 1
11453         local mtime2=$(stat -c "%Y" $DIR/$tdir)
11454         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
11455 }
11456 run_test 185 "Volatile file support"
11457
11458 test_187a() {
11459         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11460         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
11461                 skip "Need MDS version at least 2.3.0" && return
11462
11463         local dir0=$DIR/$tdir/$testnum
11464         mkdir -p $dir0 || error "creating dir $dir0"
11465
11466         local file=$dir0/file1
11467         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
11468         local dv1=$($LFS data_version $file)
11469         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
11470         local dv2=$($LFS data_version $file)
11471         [[ $dv1 != $dv2 ]] ||
11472                 error "data version did not change on write $dv1 == $dv2"
11473
11474         # clean up
11475         rm -f $file1
11476 }
11477 run_test 187a "Test data version change"
11478
11479 test_187b() {
11480         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11481         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
11482                 skip "Need MDS version at least 2.3.0" && return
11483
11484         local dir0=$DIR/$tdir/$testnum
11485         mkdir -p $dir0 || error "creating dir $dir0"
11486
11487         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
11488         [[ ${DV[0]} != ${DV[1]} ]] ||
11489                 error "data version did not change on write"\
11490                       " ${DV[0]} == ${DV[1]}"
11491
11492         # clean up
11493         rm -f $file1
11494 }
11495 run_test 187b "Test data version change on volatile file"
11496
11497 test_200() {
11498         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11499         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11500
11501         local POOL=${POOL:-cea1}
11502         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
11503         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
11504         # Pool OST targets
11505         local first_ost=0
11506         local last_ost=$(($OSTCOUNT - 1))
11507         local ost_step=2
11508         local ost_list=$(seq $first_ost $ost_step $last_ost)
11509         local ost_range="$first_ost $last_ost $ost_step"
11510         local test_path=$POOL_ROOT/$POOL_DIR_NAME
11511         local file_dir=$POOL_ROOT/file_tst
11512         local subdir=$test_path/subdir
11513
11514         local rc=0
11515         while : ; do
11516                 # former test_200a test_200b
11517                 pool_add $POOL                          || { rc=$? ; break; }
11518                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
11519                 # former test_200c test_200d
11520                 mkdir -p $test_path
11521                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
11522                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
11523                 mkdir -p $subdir
11524                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
11525                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
11526                                                         || { rc=$? ; break; }
11527                 # former test_200e test_200f
11528                 local files=$((OSTCOUNT*3))
11529                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
11530                                                         || { rc=$? ; break; }
11531                 pool_create_files $POOL $file_dir $files "$ost_list" \
11532                                                         || { rc=$? ; break; }
11533                 # former test_200g test_200h
11534                 pool_lfs_df $POOL                       || { rc=$? ; break; }
11535                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
11536
11537                 # former test_201a test_201b test_201c
11538                 pool_remove_first_target $POOL          || { rc=$? ; break; }
11539
11540                 local f=$test_path/$tfile
11541                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
11542                 pool_remove $POOL $f                    || { rc=$? ; break; }
11543                 break
11544         done
11545
11546         cleanup_pools
11547         return $rc
11548 }
11549 run_test 200 "OST pools"
11550
11551 # usage: default_attr <count | size | offset>
11552 default_attr() {
11553         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
11554 }
11555
11556 # usage: check_default_stripe_attr
11557 check_default_stripe_attr() {
11558         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
11559         case $1 in
11560         --stripe-count|--count)
11561                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
11562         --stripe-size|--size)
11563                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
11564         --stripe-index|--index)
11565                 EXPECTED=-1;;
11566         *)
11567                 error "unknown getstripe attr '$1'"
11568         esac
11569
11570         [ $ACTUAL != $EXPECTED ] &&
11571                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
11572 }
11573
11574 test_204a() {
11575         test_mkdir -p $DIR/$tdir
11576         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
11577
11578         check_default_stripe_attr --stripe-count
11579         check_default_stripe_attr --stripe-size
11580         check_default_stripe_attr --stripe-index
11581
11582         return 0
11583 }
11584 run_test 204a "Print default stripe attributes ================="
11585
11586 test_204b() {
11587         test_mkdir -p $DIR/$tdir
11588         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11589
11590         check_default_stripe_attr --stripe-size
11591         check_default_stripe_attr --stripe-index
11592
11593         return 0
11594 }
11595 run_test 204b "Print default stripe size and offset  ==========="
11596
11597 test_204c() {
11598         test_mkdir -p $DIR/$tdir
11599         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11600
11601         check_default_stripe_attr --stripe-count
11602         check_default_stripe_attr --stripe-index
11603
11604         return 0
11605 }
11606 run_test 204c "Print default stripe count and offset ==========="
11607
11608 test_204d() {
11609         test_mkdir -p $DIR/$tdir
11610         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11611
11612         check_default_stripe_attr --stripe-count
11613         check_default_stripe_attr --stripe-size
11614
11615         return 0
11616 }
11617 run_test 204d "Print default stripe count and size ============="
11618
11619 test_204e() {
11620         test_mkdir -p $DIR/$tdir
11621         $SETSTRIPE -d $DIR/$tdir
11622
11623         check_default_stripe_attr --stripe-count --raw
11624         check_default_stripe_attr --stripe-size --raw
11625         check_default_stripe_attr --stripe-index --raw
11626
11627         return 0
11628 }
11629 run_test 204e "Print raw stripe attributes ================="
11630
11631 test_204f() {
11632         test_mkdir -p $DIR/$tdir
11633         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11634
11635         check_default_stripe_attr --stripe-size --raw
11636         check_default_stripe_attr --stripe-index --raw
11637
11638         return 0
11639 }
11640 run_test 204f "Print raw stripe size and offset  ==========="
11641
11642 test_204g() {
11643         test_mkdir -p $DIR/$tdir
11644         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11645
11646         check_default_stripe_attr --stripe-count --raw
11647         check_default_stripe_attr --stripe-index --raw
11648
11649         return 0
11650 }
11651 run_test 204g "Print raw stripe count and offset ==========="
11652
11653 test_204h() {
11654         test_mkdir -p $DIR/$tdir
11655         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11656
11657         check_default_stripe_attr --stripe-count --raw
11658         check_default_stripe_attr --stripe-size --raw
11659
11660         return 0
11661 }
11662 run_test 204h "Print raw stripe count and size ============="
11663
11664 # Figure out which job scheduler is being used, if any,
11665 # or use a fake one
11666 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11667         JOBENV=SLURM_JOB_ID
11668 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11669         JOBENV=LSB_JOBID
11670 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11671         JOBENV=PBS_JOBID
11672 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11673         JOBENV=LOADL_STEP_ID
11674 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11675         JOBENV=JOB_ID
11676 else
11677         $LCTL list_param jobid_name > /dev/null 2>&1
11678         if [ $? -eq 0 ]; then
11679                 JOBENV=nodelocal
11680         else
11681                 JOBENV=FAKE_JOBID
11682         fi
11683 fi
11684
11685 verify_jobstats() {
11686         local cmd=($1)
11687         shift
11688         local facets="$@"
11689
11690 # we don't really need to clear the stats for this test to work, since each
11691 # command has a unique jobid, but it makes debugging easier if needed.
11692 #       for facet in $facets; do
11693 #               local dev=$(convert_facet2label $facet)
11694 #               # clear old jobstats
11695 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
11696 #       done
11697
11698         # use a new JobID for each test, or we might see an old one
11699         [ "$JOBENV" = "FAKE_JOBID" ] &&
11700                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
11701
11702         JOBVAL=${!JOBENV}
11703
11704         [ "$JOBENV" = "nodelocal" ] && {
11705                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
11706                 $LCTL set_param jobid_name=$FAKE_JOBID
11707                 JOBVAL=$FAKE_JOBID
11708         }
11709
11710         log "Test: ${cmd[*]}"
11711         log "Using JobID environment variable $JOBENV=$JOBVAL"
11712
11713         if [ $JOBENV = "FAKE_JOBID" ]; then
11714                 FAKE_JOBID=$JOBVAL ${cmd[*]}
11715         else
11716                 ${cmd[*]}
11717         fi
11718
11719         # all files are created on OST0000
11720         for facet in $facets; do
11721                 local stats="*.$(convert_facet2label $facet).job_stats"
11722                 if [ $(do_facet $facet lctl get_param $stats |
11723                        grep -c $JOBVAL) -ne 1 ]; then
11724                         do_facet $facet lctl get_param $stats
11725                         error "No jobstats for $JOBVAL found on $facet::$stats"
11726                 fi
11727         done
11728 }
11729
11730 jobstats_set() {
11731         trap 0
11732         NEW_JOBENV=${1:-$OLD_JOBENV}
11733         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11734         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11735 }
11736
11737 cleanup_205() {
11738         do_facet $SINGLEMDS \
11739                 $LCTL set_param mdt.*.job_cleanup_interval=$OLD_INTERVAL
11740         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11741         do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
11742 }
11743
11744 test_205() { # Job stats
11745         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11746         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11747         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11748         remote_ost_nodsh && skip "remote OST with nodsh" && return
11749
11750         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11751                 skip "Server doesn't support jobstats" && return 0
11752         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11753
11754         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11755         if [ $OLD_JOBENV != $JOBENV ]; then
11756                 jobstats_set $JOBENV
11757                 trap cleanup_205 EXIT
11758         fi
11759
11760         CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
11761         echo "Registered as changelog user $CL_USER"
11762
11763         OLD_INTERVAL=$(do_facet $SINGLEMDS \
11764                        lctl get_param -n mdt.*.job_cleanup_interval)
11765         local interval_new=5
11766         do_facet $SINGLEMDS \
11767                 $LCTL set_param mdt.*.job_cleanup_interval=$interval_new
11768         local start=$SECONDS
11769
11770         local cmd
11771         # mkdir
11772         cmd="mkdir $DIR/$tdir"
11773         verify_jobstats "$cmd" "$SINGLEMDS"
11774         # rmdir
11775         cmd="rmdir $DIR/$tdir"
11776         verify_jobstats "$cmd" "$SINGLEMDS"
11777         # mkdir on secondary MDT
11778         if [ $MDSCOUNT -gt 1 ]; then
11779                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
11780                 verify_jobstats "$cmd" "mds2"
11781         fi
11782         # mknod
11783         cmd="mknod $DIR/$tfile c 1 3"
11784         verify_jobstats "$cmd" "$SINGLEMDS"
11785         # unlink
11786         cmd="rm -f $DIR/$tfile"
11787         verify_jobstats "$cmd" "$SINGLEMDS"
11788         # create all files on OST0000 so verify_jobstats can find OST stats
11789         # open & close
11790         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11791         verify_jobstats "$cmd" "$SINGLEMDS"
11792         # setattr
11793         cmd="touch $DIR/$tfile"
11794         verify_jobstats "$cmd" "$SINGLEMDS ost1"
11795         # write
11796         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11797         verify_jobstats "$cmd" "ost1"
11798         # read
11799         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11800         verify_jobstats "$cmd" "ost1"
11801         # truncate
11802         cmd="$TRUNCATE $DIR/$tfile 0"
11803         verify_jobstats "$cmd" "$SINGLEMDS ost1"
11804         # rename
11805         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
11806         verify_jobstats "$cmd" "$SINGLEMDS"
11807         # jobstats expiry - sleep until old stats should be expired
11808         local left=$((interval_new + 2 - (SECONDS - start)))
11809         [ $left -ge 0 ] && echo "sleep $left for expiry" && sleep $((left + 1))
11810         cmd="mkdir $DIR/$tdir.expire"
11811         verify_jobstats "$cmd" "$SINGLEMDS"
11812         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
11813             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
11814
11815         # Ensure that jobid are present in changelog (if supported by MDS)
11816         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
11817         then
11818                 $LFS changelog $MDT0 | tail -9
11819                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
11820                 [ $jobids -eq 9 ] ||
11821                         error "Wrong changelog jobid count $jobids != 9"
11822
11823                 # LU-5862
11824                 JOBENV="disable"
11825                 jobstats_set $JOBENV
11826                 touch $DIR/$tfile
11827                 $LFS changelog $MDT0 | tail -1
11828                 jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
11829                 [ $jobids -eq 0 ] ||
11830                         error "Unexpected jobids when jobid_var=$JOBENV"
11831         fi
11832
11833         cleanup_205
11834 }
11835 run_test 205 "Verify job stats"
11836
11837 # LU-1480, LU-1773 and LU-1657
11838 test_206() {
11839         mkdir -p $DIR/$tdir
11840         $SETSTRIPE -c -1 $DIR/$tdir
11841 #define OBD_FAIL_LOV_INIT 0x1403
11842         $LCTL set_param fail_loc=0xa0001403
11843         $LCTL set_param fail_val=1
11844         touch $DIR/$tdir/$tfile || true
11845 }
11846 run_test 206 "fail lov_init_raid0() doesn't lbug"
11847
11848 test_207a() {
11849         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11850         local fsz=`stat -c %s $DIR/$tfile`
11851         cancel_lru_locks mdc
11852
11853         # do not return layout in getattr intent
11854 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11855         $LCTL set_param fail_loc=0x170
11856         local sz=`stat -c %s $DIR/$tfile`
11857
11858         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11859
11860         rm -rf $DIR/$tfile
11861 }
11862 run_test 207a "can refresh layout at glimpse"
11863
11864 test_207b() {
11865         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11866         local cksum=`md5sum $DIR/$tfile`
11867         local fsz=`stat -c %s $DIR/$tfile`
11868         cancel_lru_locks mdc
11869         cancel_lru_locks osc
11870
11871         # do not return layout in getattr intent
11872 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11873         $LCTL set_param fail_loc=0x171
11874
11875         # it will refresh layout after the file is opened but before read issues
11876         echo checksum is "$cksum"
11877         echo "$cksum" |md5sum -c --quiet || error "file differs"
11878
11879         rm -rf $DIR/$tfile
11880 }
11881 run_test 207b "can refresh layout at open"
11882
11883 test_208() {
11884         # FIXME: in this test suite, only RD lease is used. This is okay
11885         # for now as only exclusive open is supported. After generic lease
11886         # is done, this test suite should be revised. - Jinshan
11887
11888         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11889         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11890                 { skip "Need MDS version at least 2.4.52"; return 0; }
11891
11892         echo "==== test 1: verify get lease work"
11893         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11894
11895         echo "==== test 2: verify lease can be broken by upcoming open"
11896         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11897         local PID=$!
11898         sleep 1
11899
11900         $MULTIOP $DIR/$tfile oO_RDONLY:c
11901         kill -USR1 $PID && wait $PID || error "break lease error"
11902
11903         echo "==== test 3: verify lease can't be granted if an open already exists"
11904         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11905         local PID=$!
11906         sleep 1
11907
11908         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11909         kill -USR1 $PID && wait $PID || error "open file error"
11910
11911         echo "==== test 4: lease can sustain over recovery"
11912         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11913         PID=$!
11914         sleep 1
11915
11916         fail mds1
11917
11918         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11919
11920         echo "==== test 5: lease broken can't be regained by replay"
11921         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11922         PID=$!
11923         sleep 1
11924
11925         # open file to break lease and then recovery
11926         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11927         fail mds1
11928
11929         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11930
11931         rm -f $DIR/$tfile
11932 }
11933 run_test 208 "Exclusive open"
11934
11935 test_209() {
11936         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11937                 skip_env "must have disp_stripe" && return
11938
11939         touch $DIR/$tfile
11940         sync; sleep 5; sync;
11941
11942         echo 3 > /proc/sys/vm/drop_caches
11943         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11944
11945         # open/close 500 times
11946         for i in $(seq 500); do
11947                 cat $DIR/$tfile
11948         done
11949
11950         echo 3 > /proc/sys/vm/drop_caches
11951         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11952
11953         echo "before: $req_before, after: $req_after"
11954         [ $((req_after - req_before)) -ge 300 ] &&
11955                 error "open/close requests are not freed"
11956         return 0
11957 }
11958 run_test 209 "read-only open/close requests should be freed promptly"
11959
11960 test_212() {
11961         size=`date +%s`
11962         size=$((size % 8192 + 1))
11963         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11964         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11965         rm -f $DIR/f212 $DIR/f212.xyz
11966 }
11967 run_test 212 "Sendfile test ============================================"
11968
11969 test_213() {
11970         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11971         cancel_lru_locks osc
11972         lctl set_param fail_loc=0x8000040f
11973         # generate a read lock
11974         cat $DIR/$tfile > /dev/null
11975         # write to the file, it will try to cancel the above read lock.
11976         cat /etc/hosts >> $DIR/$tfile
11977 }
11978 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11979
11980 test_214() { # for bug 20133
11981         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11982         for (( i=0; i < 340; i++ )) ; do
11983                 touch $DIR/$tdir/d214c/a$i
11984         done
11985
11986         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11987         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11988         ls $DIR/d214c || error "ls $DIR/d214c failed"
11989         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11990         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11991 }
11992 run_test 214 "hash-indexed directory test - bug 20133"
11993
11994 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11995 create_lnet_proc_files() {
11996         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
11997         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11998
11999         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
12000         rm -f "$TMP/lnet_$1.sys_tmp"
12001 }
12002
12003 # counterpart of create_lnet_proc_files
12004 remove_lnet_proc_files() {
12005         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
12006 }
12007
12008 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12009 # 3rd arg as regexp for body
12010 check_lnet_proc_stats() {
12011         local l=$(cat "$TMP/lnet_$1" |wc -l)
12012         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
12013
12014         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
12015 }
12016
12017 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12018 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
12019 # optional and can be regexp for 2nd line (lnet.routes case)
12020 check_lnet_proc_entry() {
12021         local blp=2          # blp stands for 'position of 1st line of body'
12022         [ -z "$5" ] || blp=3 # lnet.routes case
12023
12024         local l=$(cat "$TMP/lnet_$1" |wc -l)
12025         # subtracting one from $blp because the body can be empty
12026         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
12027
12028         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
12029                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
12030
12031         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
12032                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
12033
12034         # bail out if any unexpected line happened
12035         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
12036         [ "$?" != 0 ] || error "$2 misformatted"
12037 }
12038
12039 test_215() { # for bugs 18102, 21079, 21517
12040         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12041         local N='(0|[1-9][0-9]*)'       # non-negative numeric
12042         local P='[1-9][0-9]*'           # positive numeric
12043         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
12044         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
12045         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
12046         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
12047
12048         local L1 # regexp for 1st line
12049         local L2 # regexp for 2nd line (optional)
12050         local BR # regexp for the rest (body)
12051
12052         # lnet.stats should look as 11 space-separated non-negative numerics
12053         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
12054         create_lnet_proc_files "stats"
12055         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
12056         remove_lnet_proc_files "stats"
12057
12058         # lnet.routes should look like this:
12059         # Routing disabled/enabled
12060         # net hops priority state router
12061         # where net is a string like tcp0, hops > 0, priority >= 0,
12062         # state is up/down,
12063         # router is a string like 192.168.1.1@tcp2
12064         L1="^Routing (disabled|enabled)$"
12065         L2="^net +hops +priority +state +router$"
12066         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
12067         create_lnet_proc_files "routes"
12068         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
12069         remove_lnet_proc_files "routes"
12070
12071         # lnet.routers should look like this:
12072         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
12073         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
12074         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
12075         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
12076         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
12077         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
12078         create_lnet_proc_files "routers"
12079         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
12080         remove_lnet_proc_files "routers"
12081
12082         # lnet.peers should look like this:
12083         # nid refs state last max rtr min tx min queue
12084         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
12085         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
12086         # numeric (0 or >0 or <0), queue >= 0.
12087         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
12088         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
12089         create_lnet_proc_files "peers"
12090         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
12091         remove_lnet_proc_files "peers"
12092
12093         # lnet.buffers  should look like this:
12094         # pages count credits min
12095         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
12096         L1="^pages +count +credits +min$"
12097         BR="^ +$N +$N +$I +$I$"
12098         create_lnet_proc_files "buffers"
12099         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
12100         remove_lnet_proc_files "buffers"
12101
12102         # lnet.nis should look like this:
12103         # nid status alive refs peer rtr max tx min
12104         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
12105         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
12106         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
12107         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
12108         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
12109         create_lnet_proc_files "nis"
12110         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
12111         remove_lnet_proc_files "nis"
12112
12113         # can we successfully write to lnet.stats?
12114         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
12115         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
12116 }
12117 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
12118
12119 test_216() { # bug 20317
12120         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12121         remote_ost_nodsh && skip "remote OST with nodsh" && return
12122
12123         local node
12124         local facets=$(get_facets OST)
12125         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
12126
12127         save_lustre_params client "osc.*.contention_seconds" > $p
12128         save_lustre_params $facets \
12129                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
12130         save_lustre_params $facets \
12131                 "ldlm.namespaces.filter-*.contended_locks" >> $p
12132         save_lustre_params $facets \
12133                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
12134         clear_osc_stats
12135
12136         # agressive lockless i/o settings
12137         for node in $(osts_nodes); do
12138                 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'
12139         done
12140         lctl set_param -n osc.*.contention_seconds 60
12141
12142         $DIRECTIO write $DIR/$tfile 0 10 4096
12143         $CHECKSTAT -s 40960 $DIR/$tfile
12144
12145         # disable lockless i/o
12146         for node in $(osts_nodes); do
12147                 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'
12148         done
12149         lctl set_param -n osc.*.contention_seconds 0
12150         clear_osc_stats
12151
12152         dd if=/dev/zero of=$DIR/$tfile count=0
12153         $CHECKSTAT -s 0 $DIR/$tfile
12154
12155         restore_lustre_params <$p
12156         rm -f $p
12157         rm $DIR/$tfile
12158 }
12159 run_test 216 "check lockless direct write works and updates file size and kms correctly"
12160
12161 test_217() { # bug 22430
12162         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12163         local node
12164         local nid
12165
12166         for node in $(nodes_list); do
12167                 nid=$(host_nids_address $node $NETTYPE)
12168                 if [[ $nid = *-* ]] ; then
12169                         echo "lctl ping $nid@$NETTYPE"
12170                         lctl ping $nid@$NETTYPE
12171                 else
12172                         echo "skipping $node (no hyphen detected)"
12173                 fi
12174         done
12175 }
12176 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
12177
12178 test_218() {
12179        # do directio so as not to populate the page cache
12180        log "creating a 10 Mb file"
12181        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
12182        log "starting reads"
12183        dd if=$DIR/$tfile of=/dev/null bs=4096 &
12184        log "truncating the file"
12185        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
12186        log "killing dd"
12187        kill %+ || true # reads might have finished
12188        echo "wait until dd is finished"
12189        wait
12190        log "removing the temporary file"
12191        rm -rf $DIR/$tfile || error "tmp file removal failed"
12192 }
12193 run_test 218 "parallel read and truncate should not deadlock ======================="
12194
12195 test_219() {
12196         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12197         # write one partial page
12198         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
12199         # set no grant so vvp_io_commit_write will do sync write
12200         $LCTL set_param fail_loc=0x411
12201         # write a full page at the end of file
12202         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
12203
12204         $LCTL set_param fail_loc=0
12205         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
12206         $LCTL set_param fail_loc=0x411
12207         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
12208
12209         # LU-4201
12210         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
12211         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
12212 }
12213 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
12214
12215 test_220() { #LU-325
12216         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12217         remote_ost_nodsh && skip "remote OST with nodsh" && return
12218         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12219         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12220         local OSTIDX=0
12221
12222         # create on MDT0000 so the last_id and next_id are correct
12223         mkdir $DIR/$tdir
12224         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
12225         OST=${OST%_UUID}
12226
12227         # on the mdt's osc
12228         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
12229         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
12230                         osc.$mdtosc_proc1.prealloc_last_id)
12231         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
12232                         osc.$mdtosc_proc1.prealloc_next_id)
12233
12234         $LFS df -i
12235
12236         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
12237         #define OBD_FAIL_OST_ENOINO              0x229
12238         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
12239         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
12240         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
12241
12242         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
12243
12244         MDSOBJS=$((last_id - next_id))
12245         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
12246
12247         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
12248         echo "OST still has $count kbytes free"
12249
12250         echo "create $MDSOBJS files @next_id..."
12251         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
12252
12253         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12254                         osc.$mdtosc_proc1.prealloc_last_id)
12255         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12256                         osc.$mdtosc_proc1.prealloc_next_id)
12257
12258         echo "after creation, last_id=$last_id2, next_id=$next_id2"
12259         $LFS df -i
12260
12261         echo "cleanup..."
12262
12263         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
12264         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
12265
12266         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
12267         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
12268         echo "unlink $MDSOBJS files @$next_id..."
12269         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
12270 }
12271 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
12272
12273 test_221() {
12274         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12275         dd if=`which date` of=$MOUNT/date oflag=sync
12276         chmod +x $MOUNT/date
12277
12278         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
12279         $LCTL set_param fail_loc=0x80001401
12280
12281         $MOUNT/date > /dev/null
12282         rm -f $MOUNT/date
12283 }
12284 run_test 221 "make sure fault and truncate race to not cause OOM"
12285
12286 test_222a () {
12287         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12288        rm -rf $DIR/$tdir
12289        test_mkdir -p $DIR/$tdir
12290        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12291        createmany -o $DIR/$tdir/$tfile 10
12292        cancel_lru_locks mdc
12293        cancel_lru_locks osc
12294        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12295        $LCTL set_param fail_loc=0x31a
12296        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
12297        $LCTL set_param fail_loc=0
12298        rm -r $DIR/$tdir
12299 }
12300 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
12301
12302 test_222b () {
12303         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12304        rm -rf $DIR/$tdir
12305        test_mkdir -p $DIR/$tdir
12306        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12307        createmany -o $DIR/$tdir/$tfile 10
12308        cancel_lru_locks mdc
12309        cancel_lru_locks osc
12310        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12311        $LCTL set_param fail_loc=0x31a
12312        rm -r $DIR/$tdir || "AGL for rmdir failed"
12313        $LCTL set_param fail_loc=0
12314 }
12315 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
12316
12317 test_223 () {
12318         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12319        rm -rf $DIR/$tdir
12320        test_mkdir -p $DIR/$tdir
12321        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12322        createmany -o $DIR/$tdir/$tfile 10
12323        cancel_lru_locks mdc
12324        cancel_lru_locks osc
12325        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
12326        $LCTL set_param fail_loc=0x31b
12327        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
12328        $LCTL set_param fail_loc=0
12329        rm -r $DIR/$tdir
12330 }
12331 run_test 223 "osc reenqueue if without AGL lock granted ======================="
12332
12333 test_224a() { # LU-1039, MRP-303
12334         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12335         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
12336         $LCTL set_param fail_loc=0x508
12337         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
12338         $LCTL set_param fail_loc=0
12339         df $DIR
12340 }
12341 run_test 224a "Don't panic on bulk IO failure"
12342
12343 test_224b() { # LU-1039, MRP-303
12344         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12345         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
12346         cancel_lru_locks osc
12347         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
12348         $LCTL set_param fail_loc=0x515
12349         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
12350         $LCTL set_param fail_loc=0
12351         df $DIR
12352 }
12353 run_test 224b "Don't panic on bulk IO failure"
12354
12355 test_224c() { # LU-6441
12356         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12357         local pages_per_rpc=$($LCTL get_param \
12358                                 osc.*.max_pages_per_rpc)
12359         local at_max=$($LCTL get_param -n at_max)
12360         local timeout=$($LCTL get_param -n timeout)
12361         local test_at="$LCTL get_param -n at_max"
12362         local param_at="$FSNAME.sys.at_max"
12363         local test_timeout="$LCTL get_param -n timeout"
12364         local param_timeout="$FSNAME.sys.timeout"
12365
12366         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
12367
12368         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
12369                 error "conf_param at_max=0 failed"
12370         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
12371                 error "conf_param timeout=5 failed"
12372
12373         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
12374         $LCTL set_param fail_loc=0x520
12375         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
12376         sync
12377         $LCTL set_param fail_loc=0
12378
12379         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
12380                 error "conf_param at_max=$at_max failed"
12381         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
12382                 $timeout || error "conf_param timeout=$timeout failed"
12383
12384         $LCTL set_param -n $pages_per_rpc
12385 }
12386 run_test 224c "Don't hang if one of md lost during large bulk RPC"
12387
12388 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
12389 test_225a () {
12390         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12391         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12392         if [ -z ${MDSSURVEY} ]; then
12393               skip_env "mds-survey not found" && return
12394         fi
12395
12396         [ $MDSCOUNT -ge 2 ] &&
12397                 skip "skipping now for more than one MDT" && return
12398
12399        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12400             { skip "Need MDS version at least 2.2.51"; return; }
12401
12402        local mds=$(facet_host $SINGLEMDS)
12403        local target=$(do_nodes $mds 'lctl dl' | \
12404                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12405
12406        local cmd1="file_count=1000 thrhi=4"
12407        local cmd2="dir_count=2 layer=mdd stripe_count=0"
12408        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12409        local cmd="$cmd1 $cmd2 $cmd3"
12410
12411        rm -f ${TMP}/mds_survey*
12412        echo + $cmd
12413        eval $cmd || error "mds-survey with zero-stripe failed"
12414        cat ${TMP}/mds_survey*
12415        rm -f ${TMP}/mds_survey*
12416 }
12417 run_test 225a "Metadata survey sanity with zero-stripe"
12418
12419 test_225b () {
12420         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12421         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12422         if [ -z ${MDSSURVEY} ]; then
12423               skip_env "mds-survey not found" && return
12424         fi
12425         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12426             { skip "Need MDS version at least 2.2.51"; return; }
12427
12428         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
12429               skip_env "Need to mount OST to test" && return
12430         fi
12431
12432         [ $MDSCOUNT -ge 2 ] &&
12433                 skip "skipping now for more than one MDT" && return
12434        local mds=$(facet_host $SINGLEMDS)
12435        local target=$(do_nodes $mds 'lctl dl' | \
12436                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12437
12438        local cmd1="file_count=1000 thrhi=4"
12439        local cmd2="dir_count=2 layer=mdd stripe_count=1"
12440        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12441        local cmd="$cmd1 $cmd2 $cmd3"
12442
12443        rm -f ${TMP}/mds_survey*
12444        echo + $cmd
12445        eval $cmd || error "mds-survey with stripe_count failed"
12446        cat ${TMP}/mds_survey*
12447        rm -f ${TMP}/mds_survey*
12448 }
12449 run_test 225b "Metadata survey sanity with stripe_count = 1"
12450
12451 mcreate_path2fid () {
12452         local mode=$1
12453         local major=$2
12454         local minor=$3
12455         local name=$4
12456         local desc=$5
12457         local path=$DIR/$tdir/$name
12458         local fid
12459         local rc
12460         local fid_path
12461
12462         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
12463                 error "cannot create $desc"
12464
12465         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
12466         rc=$?
12467         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
12468
12469         fid_path=$($LFS fid2path $MOUNT $fid)
12470         rc=$?
12471         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
12472
12473         [ "$path" == "$fid_path" ] ||
12474                 error "fid2path returned $fid_path, expected $path"
12475
12476         echo "pass with $path and $fid"
12477 }
12478
12479 test_226a () {
12480         rm -rf $DIR/$tdir
12481         mkdir -p $DIR/$tdir
12482
12483         mcreate_path2fid 0010666 0 0 fifo "FIFO"
12484         mcreate_path2fid 0020666 1 3 null "character special file (null)"
12485         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
12486         mcreate_path2fid 0040666 0 0 dir "directory"
12487         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
12488         mcreate_path2fid 0100666 0 0 file "regular file"
12489         mcreate_path2fid 0120666 0 0 link "symbolic link"
12490         mcreate_path2fid 0140666 0 0 sock "socket"
12491 }
12492 run_test 226a "call path2fid and fid2path on files of all type"
12493
12494 test_226b () {
12495         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12496         rm -rf $DIR/$tdir
12497         local MDTIDX=1
12498
12499         mkdir -p $DIR/$tdir
12500         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
12501                 error "create remote directory failed"
12502         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
12503         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
12504                                 "character special file (null)"
12505         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
12506                                 "character special file (no device)"
12507         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
12508         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
12509                                 "block special file (loop)"
12510         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
12511         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
12512         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
12513 }
12514 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
12515
12516 # LU-1299 Executing or running ldd on a truncated executable does not
12517 # cause an out-of-memory condition.
12518 test_227() {
12519         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12520         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
12521         dd if=$(which date) of=$MOUNT/date bs=1k count=1
12522         chmod +x $MOUNT/date
12523
12524         $MOUNT/date > /dev/null
12525         ldd $MOUNT/date > /dev/null
12526         rm -f $MOUNT/date
12527 }
12528 run_test 227 "running truncated executable does not cause OOM"
12529
12530 # LU-1512 try to reuse idle OI blocks
12531 test_228a() {
12532         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12533         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12534         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12535                 skip "non-ldiskfs backend" && return
12536
12537         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12538         local myDIR=$DIR/$tdir
12539
12540         mkdir -p $myDIR
12541         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12542         $LCTL set_param fail_loc=0x80001002
12543         createmany -o $myDIR/t- 10000
12544         $LCTL set_param fail_loc=0
12545         # The guard is current the largest FID holder
12546         touch $myDIR/guard
12547         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12548                     tr -d '[')
12549         local IDX=$(($SEQ % 64))
12550
12551         do_facet $SINGLEMDS sync
12552         # Make sure journal flushed.
12553         sleep 6
12554         local blk1=$(do_facet $SINGLEMDS \
12555                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12556                      grep Blockcount | awk '{print $4}')
12557
12558         # Remove old files, some OI blocks will become idle.
12559         unlinkmany $myDIR/t- 10000
12560         # Create new files, idle OI blocks should be reused.
12561         createmany -o $myDIR/t- 2000
12562         do_facet $SINGLEMDS sync
12563         # Make sure journal flushed.
12564         sleep 6
12565         local blk2=$(do_facet $SINGLEMDS \
12566                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12567                      grep Blockcount | awk '{print $4}')
12568
12569         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12570 }
12571 run_test 228a "try to reuse idle OI blocks"
12572
12573 test_228b() {
12574         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12575         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12576         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12577                 skip "non-ldiskfs backend" && return
12578
12579         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12580         local myDIR=$DIR/$tdir
12581
12582         mkdir -p $myDIR
12583         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12584         $LCTL set_param fail_loc=0x80001002
12585         createmany -o $myDIR/t- 10000
12586         $LCTL set_param fail_loc=0
12587         # The guard is current the largest FID holder
12588         touch $myDIR/guard
12589         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12590                     tr -d '[')
12591         local IDX=$(($SEQ % 64))
12592
12593         do_facet $SINGLEMDS sync
12594         # Make sure journal flushed.
12595         sleep 6
12596         local blk1=$(do_facet $SINGLEMDS \
12597                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12598                      grep Blockcount | awk '{print $4}')
12599
12600         # Remove old files, some OI blocks will become idle.
12601         unlinkmany $myDIR/t- 10000
12602
12603         # stop the MDT
12604         stop $SINGLEMDS || error "Fail to stop MDT."
12605         # remount the MDT
12606         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
12607
12608         df $MOUNT || error "Fail to df."
12609         # Create new files, idle OI blocks should be reused.
12610         createmany -o $myDIR/t- 2000
12611         do_facet $SINGLEMDS sync
12612         # Make sure journal flushed.
12613         sleep 6
12614         local blk2=$(do_facet $SINGLEMDS \
12615                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12616                      grep Blockcount | awk '{print $4}')
12617
12618         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12619 }
12620 run_test 228b "idle OI blocks can be reused after MDT restart"
12621
12622 #LU-1881
12623 test_228c() {
12624         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12625         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12626         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12627                 skip "non-ldiskfs backend" && return
12628
12629         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12630         local myDIR=$DIR/$tdir
12631
12632         mkdir -p $myDIR
12633         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12634         $LCTL set_param fail_loc=0x80001002
12635         # 20000 files can guarantee there are index nodes in the OI file
12636         createmany -o $myDIR/t- 20000
12637         $LCTL set_param fail_loc=0
12638         # The guard is current the largest FID holder
12639         touch $myDIR/guard
12640         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12641                     tr -d '[')
12642         local IDX=$(($SEQ % 64))
12643
12644         do_facet $SINGLEMDS sync
12645         # Make sure journal flushed.
12646         sleep 6
12647         local blk1=$(do_facet $SINGLEMDS \
12648                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12649                      grep Blockcount | awk '{print $4}')
12650
12651         # Remove old files, some OI blocks will become idle.
12652         unlinkmany $myDIR/t- 20000
12653         rm -f $myDIR/guard
12654         # The OI file should become empty now
12655
12656         # Create new files, idle OI blocks should be reused.
12657         createmany -o $myDIR/t- 2000
12658         do_facet $SINGLEMDS sync
12659         # Make sure journal flushed.
12660         sleep 6
12661         local blk2=$(do_facet $SINGLEMDS \
12662                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12663                      grep Blockcount | awk '{print $4}')
12664
12665         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12666 }
12667 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
12668
12669 test_229() { # LU-2482, LU-3448
12670         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
12671                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
12672                 return
12673         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12674         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
12675
12676         rm -f $DIR/$tfile
12677
12678         # Create a file with a released layout and stripe count 2.
12679         $MULTIOP $DIR/$tfile H2c ||
12680                 error "failed to create file with released layout"
12681
12682         $GETSTRIPE -v $DIR/$tfile
12683
12684         local pattern=$($GETSTRIPE -L $DIR/$tfile)
12685         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
12686
12687         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
12688         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
12689         stat $DIR/$tfile || error "failed to stat released file"
12690
12691         chown $RUNAS_ID $DIR/$tfile ||
12692                 error "chown $RUNAS_ID $DIR/$tfile failed"
12693
12694         chgrp $RUNAS_ID $DIR/$tfile ||
12695                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12696
12697         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12698         rm $DIR/$tfile || error "failed to remove released file"
12699 }
12700 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12701
12702 test_230a() {
12703         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12704         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12705         local MDTIDX=1
12706
12707         test_mkdir $DIR/$tdir
12708         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
12709         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12710         [ $mdt_idx -ne 0 ] &&
12711                 error "create local directory on wrong MDT $mdt_idx"
12712
12713         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12714                         error "create remote directory failed"
12715         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12716         [ $mdt_idx -ne $MDTIDX ] &&
12717                 error "create remote directory on wrong MDT $mdt_idx"
12718
12719         createmany -o $DIR/$tdir/test_230/t- 10 ||
12720                 error "create files on remote directory failed"
12721         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12722         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12723         rm -r $DIR/$tdir || error "unlink remote directory failed"
12724 }
12725 run_test 230a "Create remote directory and files under the remote directory"
12726
12727 test_230b() {
12728         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12729         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12730         local MDTIDX=1
12731         local mdt_index
12732         local i
12733         local file
12734         local pid
12735         local stripe_count
12736         local migrate_dir=$DIR/$tdir/migrate_dir
12737         local other_dir=$DIR/$tdir/other_dir
12738
12739         test_mkdir $DIR/$tdir
12740         test_mkdir -i0 -c1 $migrate_dir
12741         test_mkdir -i0 -c1 $other_dir
12742         for ((i=0; i<10; i++)); do
12743                 mkdir -p $migrate_dir/dir_${i}
12744                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12745                         error "create files under remote dir failed $i"
12746         done
12747
12748         cp /etc/passwd $migrate_dir/$tfile
12749         cp /etc/passwd $other_dir/$tfile
12750         chattr +SAD $migrate_dir
12751         chattr +SAD $migrate_dir/$tfile
12752
12753         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12754         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12755         local old_dir_mode=$(stat -c%f $migrate_dir)
12756         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
12757
12758         mkdir -p $migrate_dir/dir_default_stripe2
12759         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12760         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12761
12762         mkdir -p $other_dir
12763         ln $migrate_dir/$tfile $other_dir/luna
12764         ln $migrate_dir/$tfile $migrate_dir/sofia
12765         ln $other_dir/$tfile $migrate_dir/david
12766         ln -s $migrate_dir/$tfile $other_dir/zachary
12767         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12768         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12769
12770         $LFS migrate -m $MDTIDX $migrate_dir ||
12771                 error "fails on migrating remote dir to MDT1"
12772
12773         echo "migratate to MDT1, then checking.."
12774         for ((i = 0; i < 10; i++)); do
12775                 for file in $(find $migrate_dir/dir_${i}); do
12776                         mdt_index=$($LFS getstripe -M $file)
12777                         [ $mdt_index == $MDTIDX ] ||
12778                                 error "$file is not on MDT${MDTIDX}"
12779                 done
12780         done
12781
12782         # the multiple link file should still in MDT0
12783         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12784         [ $mdt_index == 0 ] ||
12785                 error "$file is not on MDT${MDTIDX}"
12786
12787         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12788         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12789                 error " expect $old_dir_flag get $new_dir_flag"
12790
12791         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12792         [ "$old_file_flag" = "$new_file_flag" ] ||
12793                 error " expect $old_file_flag get $new_file_flag"
12794
12795         local new_dir_mode=$(stat -c%f $migrate_dir)
12796         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12797                 error "expect mode $old_dir_mode get $new_dir_mode"
12798
12799         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12800         [ "$old_file_mode" = "$new_file_mode" ] ||
12801                 error "expect mode $old_file_mode get $new_file_mode"
12802
12803         diff /etc/passwd $migrate_dir/$tfile ||
12804                 error "$tfile different after migration"
12805
12806         diff /etc/passwd $other_dir/luna ||
12807                 error "luna different after migration"
12808
12809         diff /etc/passwd $migrate_dir/sofia ||
12810                 error "sofia different after migration"
12811
12812         diff /etc/passwd $migrate_dir/david ||
12813                 error "david different after migration"
12814
12815         diff /etc/passwd $other_dir/zachary ||
12816                 error "zachary different after migration"
12817
12818         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12819                 error "${tfile}_ln different after migration"
12820
12821         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12822                 error "${tfile}_ln_other different after migration"
12823
12824         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12825         [ $stripe_count = 2 ] ||
12826                 error "dir strpe_count $d != 2 after migration."
12827
12828         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12829         [ $stripe_count = 2 ] ||
12830                 error "file strpe_count $d != 2 after migration."
12831
12832         #migrate back to MDT0
12833         MDTIDX=0
12834
12835         $LFS migrate -m $MDTIDX $migrate_dir ||
12836                 error "fails on migrating remote dir to MDT0"
12837
12838         echo "migrate back to MDT0, checking.."
12839         for file in $(find $migrate_dir); do
12840                 mdt_index=$($LFS getstripe -M $file)
12841                 [ $mdt_index == $MDTIDX ] ||
12842                         error "$file is not on MDT${MDTIDX}"
12843         done
12844
12845         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12846         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12847                 error " expect $old_dir_flag get $new_dir_flag"
12848
12849         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12850         [ "$old_file_flag" = "$new_file_flag" ] ||
12851                 error " expect $old_file_flag get $new_file_flag"
12852
12853         local new_dir_mode=$(stat -c%f $migrate_dir)
12854         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12855                 error "expect mode $old_dir_mode get $new_dir_mode"
12856
12857         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12858         [ "$old_file_mode" = "$new_file_mode" ] ||
12859                 error "expect mode $old_file_mode get $new_file_mode"
12860
12861         diff /etc/passwd ${migrate_dir}/$tfile ||
12862                 error "$tfile different after migration"
12863
12864         diff /etc/passwd ${other_dir}/luna ||
12865                 error "luna different after migration"
12866
12867         diff /etc/passwd ${migrate_dir}/sofia ||
12868                 error "sofia different after migration"
12869
12870         diff /etc/passwd ${other_dir}/zachary ||
12871                 error "zachary different after migration"
12872
12873         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12874                 error "${tfile}_ln different after migration"
12875
12876         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12877                 error "${tfile}_ln_other different after migration"
12878
12879         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12880         [ $stripe_count = 2 ] ||
12881                 error "dir strpe_count $d != 2 after migration."
12882
12883         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12884         [ $stripe_count = 2 ] ||
12885                 error "file strpe_count $d != 2 after migration."
12886
12887         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12888 }
12889 run_test 230b "migrate directory"
12890
12891 test_230c() {
12892         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12893         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12894         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12895         local MDTIDX=1
12896         local mdt_index
12897         local file
12898         local migrate_dir=$DIR/$tdir/migrate_dir
12899
12900         #If migrating directory fails in the middle, all entries of
12901         #the directory is still accessiable.
12902         test_mkdir $DIR/$tdir
12903         test_mkdir -i0 -c1 $migrate_dir
12904         stat $migrate_dir
12905         createmany -o $migrate_dir/f 10 ||
12906                 error "create files under ${migrate_dir} failed"
12907
12908         #failed after migrating 5 entries
12909         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12910         do_facet mds1 lctl set_param fail_loc=0x20001801
12911         do_facet mds1 lctl  set_param fail_val=5
12912         local t=$(ls $migrate_dir | wc -l)
12913         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
12914                 error "migrate should fail after 5 entries"
12915
12916         mkdir $migrate_dir/dir &&
12917                 error "mkdir succeeds under migrating directory"
12918         touch $migrate_dir/file &&
12919                 error "touch file succeeds under migrating directory"
12920
12921         local u=$(ls $migrate_dir | wc -l)
12922         [ "$u" == "$t" ] || error "$u != $t during migration"
12923
12924         for file in $(find $migrate_dir); do
12925                 stat $file || error "stat $file failed"
12926         done
12927
12928         do_facet mds1 lctl set_param fail_loc=0
12929         do_facet mds1 lctl set_param fail_val=0
12930
12931         $LFS migrate -m $MDTIDX $migrate_dir ||
12932                 error "migrate open files should failed with open files"
12933
12934         echo "Finish migration, then checking.."
12935         for file in $(find $migrate_dir); do
12936                 mdt_index=$($LFS getstripe -M $file)
12937                 [ $mdt_index == $MDTIDX ] ||
12938                         error "$file is not on MDT${MDTIDX}"
12939         done
12940
12941         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12942 }
12943 run_test 230c "check directory accessiblity if migration is failed"
12944
12945 test_230d() {
12946         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12947         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12948         local MDTIDX=1
12949         local mdt_index
12950         local migrate_dir=$DIR/$tdir/migrate_dir
12951         local i
12952         local j
12953
12954         test_mkdir $DIR/$tdir
12955         test_mkdir -i0 -c1 $migrate_dir
12956
12957         for ((i=0; i<100; i++)); do
12958                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
12959                 createmany -o $migrate_dir/dir_${i}/f 100 ||
12960                         error "create files under remote dir failed $i"
12961         done
12962
12963         $LFS migrate -m $MDTIDX $migrate_dir ||
12964                 error "migrate remote dir error"
12965
12966         echo "Finish migration, then checking.."
12967         for file in $(find $migrate_dir); do
12968                 mdt_index=$($LFS getstripe -M $file)
12969                 [ $mdt_index == $MDTIDX ] ||
12970                         error "$file is not on MDT${MDTIDX}"
12971         done
12972
12973         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12974 }
12975 run_test 230d "check migrate big directory"
12976
12977 test_230e() {
12978         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12979         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12980         local i
12981         local j
12982         local a_fid
12983         local b_fid
12984
12985         mkdir -p $DIR/$tdir
12986         mkdir $DIR/$tdir/migrate_dir
12987         mkdir $DIR/$tdir/other_dir
12988         touch $DIR/$tdir/migrate_dir/a
12989         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
12990         ls $DIR/$tdir/other_dir
12991
12992         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
12993                 error "migrate dir fails"
12994
12995         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
12996         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
12997
12998         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
12999         [ $mdt_index == 0 ] || error "a is not on MDT0"
13000
13001         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
13002                 error "migrate dir fails"
13003
13004         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir)
13005         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
13006
13007         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13008         [ $mdt_index == 1 ] || error "a is not on MDT1"
13009
13010         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir/b)
13011         [ $mdt_index == 1 ] || error "b is not on MDT1"
13012
13013         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13014         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
13015
13016         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
13017
13018         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13019 }
13020 run_test 230e "migrate mulitple local link files"
13021
13022 test_230f() {
13023         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13024         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13025         local a_fid
13026         local ln_fid
13027
13028         mkdir -p $DIR/$tdir
13029         mkdir $DIR/$tdir/migrate_dir
13030         $LFS mkdir -i1 $DIR/$tdir/other_dir
13031         touch $DIR/$tdir/migrate_dir/a
13032         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
13033         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
13034         ls $DIR/$tdir/other_dir
13035
13036         # a should be migrated to MDT1, since no other links on MDT0
13037         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13038                 error "migrate dir fails"
13039         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13040         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
13041         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13042         [ $mdt_index == 1 ] || error "a is not on MDT1"
13043
13044         # a should stay on MDT1, because it is a mulitple link file
13045         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13046                 error "migrate dir fails"
13047         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13048         [ $mdt_index == 1 ] || error "a is not on MDT1"
13049
13050         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13051                 error "migrate dir fails"
13052
13053         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13054         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
13055         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
13056
13057         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
13058         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
13059
13060         # a should be migrated to MDT0, since no other links on MDT1
13061         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13062                 error "migrate dir fails"
13063         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13064         [ $mdt_index == 0 ] || error "a is not on MDT0"
13065
13066         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13067 }
13068 run_test 230f "migrate mulitple remote link files"
13069
13070 test_230g() {
13071         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13072         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13073
13074         mkdir -p $DIR/$tdir/migrate_dir
13075
13076         $LFS migrate -m 1000 $DIR/$tdir/migrate_dir &&
13077                 error "migrating dir to non-exist MDT succeeds"
13078         true
13079 }
13080 run_test 230g "migrate dir to non-exist MDT"
13081
13082 test_230h() {
13083         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13084         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13085         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
13086                 skip "Need MDS version at least 2.7.64" && return
13087         local mdt_index
13088
13089         mkdir -p $DIR/$tdir/migrate_dir
13090
13091         $LFS migrate -m1 $DIR &&
13092                 error "migrating mountpoint1 should fail"
13093
13094         $LFS migrate -m1 $DIR/$tdir/.. &&
13095                 error "migrating mountpoint2 should fail"
13096
13097         $LFS migrate -m1 $DIR/$tdir/migrate_dir/.. ||
13098                 error "migrating $tdir fail"
13099
13100         mdt_index=$($LFS getstripe -M $DIR/$tdir)
13101         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13102
13103         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13104         [ $mdt_index == 1 ] || error "$mdt_index != 1 after migration"
13105
13106 }
13107 run_test 230h "migrate .. and root"
13108
13109 test_231a()
13110 {
13111         # For simplicity this test assumes that max_pages_per_rpc
13112         # is the same across all OSCs
13113         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
13114         local bulk_size=$((max_pages * 4096))
13115
13116         mkdir -p $DIR/$tdir
13117
13118         # clear the OSC stats
13119         $LCTL set_param osc.*.stats=0 &>/dev/null
13120
13121         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
13122         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
13123                 oflag=direct &>/dev/null || error "dd failed"
13124
13125         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
13126         if [ x$nrpcs != "x1" ]; then
13127                 error "found $nrpc ost_write RPCs, not 1 as expected"
13128         fi
13129
13130         # Drop the OSC cache, otherwise we will read from it
13131         cancel_lru_locks osc
13132
13133         # clear the OSC stats
13134         $LCTL set_param osc.*.stats=0 &>/dev/null
13135
13136         # Client reads $bulk_size.
13137         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
13138                 iflag=direct &>/dev/null || error "dd failed"
13139
13140         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
13141         if [ x$nrpcs != "x1" ]; then
13142                 error "found $nrpc ost_read RPCs, not 1 as expected"
13143         fi
13144 }
13145 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
13146
13147 test_231b() {
13148         mkdir -p $DIR/$tdir
13149         local i
13150         for i in {0..1023}; do
13151                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
13152                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
13153                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
13154         done
13155         sync
13156 }
13157 run_test 231b "must not assert on fully utilized OST request buffer"
13158
13159 test_232() {
13160         mkdir -p $DIR/$tdir
13161         #define OBD_FAIL_LDLM_OST_LVB            0x31c
13162         $LCTL set_param fail_loc=0x31c
13163
13164         # ignore dd failure
13165         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
13166
13167         $LCTL set_param fail_loc=0
13168         umount_client $MOUNT || error "umount failed"
13169         mount_client $MOUNT || error "mount failed"
13170 }
13171 run_test 232 "failed lock should not block umount"
13172
13173 test_233a() {
13174         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
13175         { skip "Need MDS version at least 2.3.64"; return; }
13176
13177         local fid=$($LFS path2fid $MOUNT)
13178         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13179                 error "cannot access $MOUNT using its FID '$fid'"
13180 }
13181 run_test 233a "checking that OBF of the FS root succeeds"
13182
13183 test_233b() {
13184         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
13185         { skip "Need MDS version at least 2.5.90"; return; }
13186
13187         local fid=$($LFS path2fid $MOUNT/.lustre)
13188         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13189                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
13190
13191         fid=$($LFS path2fid $MOUNT/.lustre/fid)
13192         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13193                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
13194 }
13195 run_test 233b "checking that OBF of the FS .lustre succeeds"
13196
13197 test_234() {
13198         local p="$TMP/sanityN-$TESTNAME.parameters"
13199         save_lustre_params client "llite.*.xattr_cache" > $p
13200         lctl set_param llite.*.xattr_cache 1 ||
13201                 { skip "xattr cache is not supported"; return 0; }
13202
13203         mkdir -p $DIR/$tdir || error "mkdir failed"
13204         touch $DIR/$tdir/$tfile || error "touch failed"
13205         # OBD_FAIL_LLITE_XATTR_ENOMEM
13206         $LCTL set_param fail_loc=0x1405
13207         # output of the form: attr 2 4 44 3 fc13 x86_64
13208         V=($(IFS=".-" rpm -q attr))
13209         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
13210               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
13211                 # attr pre-2.4.44-7 had a bug with rc
13212                 # LU-3703 - SLES 11 and FC13 clients have older attr
13213                 getfattr -n user.attr $DIR/$tdir/$tfile &&
13214                         error "getfattr should have failed with ENOMEM"
13215         else
13216                 skip "LU-3703: attr version $(getfattr --version) too old"
13217         fi
13218         $LCTL set_param fail_loc=0x0
13219         rm -rf $DIR/$tdir
13220
13221         restore_lustre_params < $p
13222         rm -f $p
13223 }
13224 run_test 234 "xattr cache should not crash on ENOMEM"
13225
13226 test_235() {
13227         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
13228                 skip "Need MDS version at least 2.4.52" && return
13229         flock_deadlock $DIR/$tfile
13230         local RC=$?
13231         case $RC in
13232                 0)
13233                 ;;
13234                 124) error "process hangs on a deadlock"
13235                 ;;
13236                 *) error "error executing flock_deadlock $DIR/$tfile"
13237                 ;;
13238         esac
13239 }
13240 run_test 235 "LU-1715: flock deadlock detection does not work properly"
13241
13242 #LU-2935
13243 test_236() {
13244         check_swap_layouts_support && return 0
13245         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
13246
13247         local ref1=/etc/passwd
13248         local ref2=/etc/group
13249         local file1=$DIR/$tdir/f1
13250         local file2=$DIR/$tdir/f2
13251
13252         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
13253         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
13254         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
13255         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
13256         local fd=$(free_fd)
13257         local cmd="exec $fd<>$file2"
13258         eval $cmd
13259         rm $file2
13260         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
13261                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
13262         cmd="exec $fd>&-"
13263         eval $cmd
13264         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
13265
13266         #cleanup
13267         rm -rf $DIR/$tdir
13268 }
13269 run_test 236 "Layout swap on open unlinked file"
13270
13271 # test to verify file handle related system calls
13272 # (name_to_handle_at/open_by_handle_at)
13273 # The new system calls are supported in glibc >= 2.14.
13274
13275 test_237() {
13276         echo "Test file_handle syscalls" > $DIR/$tfile ||
13277                 error "write failed"
13278         check_fhandle_syscalls $DIR/$tfile ||
13279                 error "check_fhandle_syscalls failed"
13280 }
13281 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
13282
13283 # LU-4659 linkea consistency
13284 test_238() {
13285         local server_version=$(lustre_version_code $SINGLEMDS)
13286
13287         [[ $server_version -gt $(version_code 2.5.57) ]] ||
13288                 [[ $server_version -gt $(version_code 2.5.1) &&
13289                    $server_version -lt $(version_code 2.5.50) ]] ||
13290                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
13291
13292         touch $DIR/$tfile
13293         ln $DIR/$tfile $DIR/$tfile.lnk
13294         touch $DIR/$tfile.new
13295         mv $DIR/$tfile.new $DIR/$tfile
13296         local fid1=$($LFS path2fid $DIR/$tfile)
13297         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
13298         local path1=$($LFS fid2path $FSNAME "$fid1")
13299         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
13300         local path2=$($LFS fid2path $FSNAME "$fid2")
13301         [ $tfile.lnk == $path2 ] ||
13302                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
13303         rm -f $DIR/$tfile*
13304 }
13305 run_test 238 "Verify linkea consistency"
13306
13307 test_239() {
13308         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
13309                 skip "Need MDS version at least 2.5.60" && return
13310         local list=$(comma_list $(mdts_nodes))
13311
13312         mkdir -p $DIR/$tdir
13313         createmany -o $DIR/$tdir/f- 5000
13314         unlinkmany $DIR/$tdir/f- 5000
13315         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
13316         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
13317                         osc.*MDT*.sync_in_flight" | calc_sum)
13318         [ "$changes" -eq 0 ] || error "$changes not synced"
13319 }
13320 run_test 239 "osp_sync test"
13321
13322 test_239a() { #LU-5297
13323         touch $DIR/$tfile
13324         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
13325         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
13326         chgrp $RUNAS_GID $DIR/$tfile
13327         wait_delete_completed
13328 }
13329 run_test 239a "process invalid osp sync record correctly"
13330
13331 test_239b() { #LU-5297
13332         touch $DIR/$tfile1
13333         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
13334         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
13335         chgrp $RUNAS_GID $DIR/$tfile1
13336         wait_delete_completed
13337         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
13338         touch $DIR/$tfile2
13339         chgrp $RUNAS_GID $DIR/$tfile2
13340         wait_delete_completed
13341 }
13342 run_test 239b "process osp sync record with ENOMEM error correctly"
13343
13344 test_240() {
13345         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13346
13347         mkdir -p $DIR/$tdir
13348
13349         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
13350                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
13351         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
13352                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
13353
13354         umount_client $MOUNT || error "umount failed"
13355         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
13356         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
13357         mount_client $MOUNT || error "failed to mount client"
13358
13359         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
13360         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
13361 }
13362 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
13363
13364 test_241_bio() {
13365         for LOOP in $(seq $1); do
13366                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
13367                 cancel_lru_locks osc
13368         done
13369 }
13370
13371 test_241_dio() {
13372         for LOOP in $(seq $1); do
13373                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
13374                                                 iflag=direct 2>/dev/null
13375         done
13376 }
13377
13378 test_241() {
13379         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
13380         ls -la $DIR/$tfile
13381         cancel_lru_locks osc
13382         test_241_bio 1000 &
13383         PID=$!
13384         test_241_dio 1000
13385         wait $PID
13386 }
13387 run_test 241 "bio vs dio"
13388
13389 test_241b() {
13390         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
13391         ls -la $DIR/$tfile
13392         test_241_dio 1000 &
13393         PID=$!
13394         test_241_dio 1000
13395         wait $PID
13396 }
13397 run_test 241b "dio vs dio"
13398
13399 test_242() {
13400         mkdir -p $DIR/$tdir
13401         touch $DIR/$tdir/$tfile
13402
13403         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
13404         do_facet mds1 lctl set_param fail_loc=0x105
13405         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
13406
13407         do_facet mds1 lctl set_param fail_loc=0
13408         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
13409 }
13410 run_test 242 "mdt_readpage failure should not cause directory unreadable"
13411
13412 test_243()
13413 {
13414         test_mkdir -p $DIR/$tdir
13415         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
13416 }
13417 run_test 243 "various group lock tests"
13418
13419 test_244()
13420 {
13421         test_mkdir -p $DIR/$tdir
13422         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
13423         sendfile_grouplock $DIR/$tdir/$tfile || \
13424                 error "sendfile+grouplock failed"
13425         rm -rf $DIR/$tdir
13426 }
13427 run_test 244 "sendfile with group lock tests"
13428
13429 test_245() {
13430         local flagname="multi_mod_rpcs"
13431         local connect_data_name="max_mod_rpcs"
13432         local out
13433
13434         # check if multiple modify RPCs flag is set
13435         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
13436                 grep "connect_flags:")
13437         echo "$out"
13438
13439         echo "$out" | grep -qw $flagname
13440         if [ $? -ne 0 ]; then
13441                 echo "connect flag $flagname is not set"
13442                 return
13443         fi
13444
13445         # check if multiple modify RPCs data is set
13446         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
13447         echo "$out"
13448
13449         echo "$out" | grep -qw $connect_data_name ||
13450                 error "import should have connect data $connect_data_name"
13451 }
13452 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
13453
13454 test_246() { # LU-7371
13455         [ $(lustre_version_code ost1) -lt $(version_code 2.7.62) ] &&
13456                 skip "Need OST version >= 2.7.62" && return 0
13457         do_facet ost1 $LCTL set_param fail_val=4095
13458 #define OBD_FAIL_OST_READ_SIZE          0x234
13459         do_facet ost1 $LCTL set_param fail_loc=0x234
13460         $LFS setstripe $DIR/$tfile -i 0 -c 1
13461         dd if=/dev/zero of=$DIR/$tfile bs=4095 count=1 > /dev/null 2>&1
13462         cancel_lru_locks $FSNAME-OST0000
13463         dd if=$DIR/$tfile of=/dev/null bs=1048576 || error "Read failed"
13464 }
13465 run_test 246 "Read file of size 4095 should return right length"
13466
13467 test_250() {
13468         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
13469          && skip "no 16TB file size limit on ZFS" && return
13470
13471         $SETSTRIPE -c 1 $DIR/$tfile
13472         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
13473         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
13474         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
13475         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
13476                 conv=notrunc,fsync && error "append succeeded"
13477         return 0
13478 }
13479 run_test 250 "Write above 16T limit"
13480
13481 test_251() {
13482         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
13483
13484         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
13485         #Skip once - writing the first stripe will succeed
13486         $LCTL set_param fail_loc=0xa0001407 fail_val=1
13487         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
13488                 error "short write happened"
13489
13490         $LCTL set_param fail_loc=0xa0001407 fail_val=1
13491         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
13492                 error "short read happened"
13493
13494         rm -f $DIR/$tfile
13495 }
13496 run_test 251 "Handling short read and write correctly"
13497
13498 test_252() {
13499         local tgt
13500         local dev
13501         local out
13502         local uuid
13503         local num
13504         local gen
13505
13506         if [ "$(facet_fstype ost1)" != "ldiskfs" -o \
13507              "$(facet_fstype mds1)" != "ldiskfs" ]; then
13508                 skip "can only run lr_reader on ldiskfs target"
13509                 return
13510         fi
13511
13512         # check lr_reader on OST0000
13513         tgt=ost1
13514         dev=$(facet_device $tgt)
13515         out=$(do_facet $tgt $LR_READER $dev)
13516         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
13517         echo "$out"
13518         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
13519         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
13520                 error "Invalid uuid returned by $LR_READER on target $tgt"
13521         echo -e "uuid returned by $LR_READER is '$uuid'\n"
13522
13523         # check lr_reader -c on MDT0000
13524         tgt=mds1
13525         dev=$(facet_device $tgt)
13526         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
13527                 echo "$LR_READER does not support additional options"
13528                 return 0
13529         fi
13530         out=$(do_facet $tgt $LR_READER -c $dev)
13531         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
13532         echo "$out"
13533         num=$(echo "$out" | grep -c "mdtlov")
13534         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
13535                 error "Invalid number of mdtlov clients returned by $LR_READER"
13536         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
13537
13538         # check lr_reader -cr on MDT0000
13539         out=$(do_facet $tgt $LR_READER -cr $dev)
13540         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
13541         echo "$out"
13542         echo "$out" | grep -q "^reply_data:$" ||
13543                 error "$LR_READER should have returned 'reply_data' section"
13544         num=$(echo "$out" | grep -c "client_generation")
13545         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
13546 }
13547 run_test 252 "check lr_reader tool"
13548
13549
13550 cleanup_test_300() {
13551         trap 0
13552         umask $SAVE_UMASK
13553 }
13554 test_striped_dir() {
13555         local mdt_index=$1
13556         local stripe_count
13557         local stripe_index
13558
13559         mkdir -p $DIR/$tdir
13560
13561         SAVE_UMASK=$(umask)
13562         trap cleanup_test_300 RETURN EXIT
13563
13564         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
13565                                                 $DIR/$tdir/striped_dir ||
13566                 error "set striped dir error"
13567
13568         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
13569         [ "$mode" = "755" ] || error "expect 755 got $mode"
13570
13571         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
13572                 error "getdirstripe failed"
13573         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
13574         if [ "$stripe_count" != "2" ]; then
13575                 error "stripe_count is $stripe_count, expect 2"
13576         fi
13577
13578         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
13579         if [ "$stripe_index" != "$mdt_index" ]; then
13580                 error "stripe_index is $stripe_index, expect $mdt_index"
13581         fi
13582
13583         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13584                 error "nlink error after create striped dir"
13585
13586         mkdir $DIR/$tdir/striped_dir/a
13587         mkdir $DIR/$tdir/striped_dir/b
13588
13589         stat $DIR/$tdir/striped_dir/a ||
13590                 error "create dir under striped dir failed"
13591         stat $DIR/$tdir/striped_dir/b ||
13592                 error "create dir under striped dir failed"
13593
13594         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
13595                 error "nlink error after mkdir"
13596
13597         rmdir $DIR/$tdir/striped_dir/a
13598         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
13599                 error "nlink error after rmdir"
13600
13601         rmdir $DIR/$tdir/striped_dir/b
13602         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13603                 error "nlink error after rmdir"
13604
13605         chattr +i $DIR/$tdir/striped_dir
13606         createmany -o $DIR/$tdir/striped_dir/f 10 &&
13607                 error "immutable flags not working under striped dir!"
13608         chattr -i $DIR/$tdir/striped_dir
13609
13610         rmdir $DIR/$tdir/striped_dir ||
13611                 error "rmdir striped dir error"
13612
13613         cleanup_test_300
13614
13615         true
13616 }
13617
13618 test_300a() {
13619         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13620         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13621
13622         test_striped_dir 0 || error "failed on striped dir on MDT0"
13623         test_striped_dir 1 || error "failed on striped dir on MDT0"
13624 }
13625 run_test 300a "basic striped dir sanity test"
13626
13627 test_300b() {
13628         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13629         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13630         local i
13631         local mtime1
13632         local mtime2
13633         local mtime3
13634
13635         test_mkdir $DIR/$tdir || error "mkdir fail"
13636         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13637                 error "set striped dir error"
13638         for ((i=0; i<10; i++)); do
13639                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
13640                 sleep 1
13641                 touch $DIR/$tdir/striped_dir/file_$i ||
13642                                         error "touch error $i"
13643                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
13644                 [ $mtime1 -eq $mtime2 ] &&
13645                         error "mtime not change after create"
13646                 sleep 1
13647                 rm -f $DIR/$tdir/striped_dir/file_$i ||
13648                                         error "unlink error $i"
13649                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
13650                 [ $mtime2 -eq $mtime3 ] &&
13651                         error "mtime did not change after unlink"
13652         done
13653         true
13654 }
13655 run_test 300b "check ctime/mtime for striped dir"
13656
13657 test_300c() {
13658         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13659         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13660         local file_count
13661
13662         mkdir -p $DIR/$tdir
13663         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
13664                 error "set striped dir error"
13665
13666         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
13667                 error "chown striped dir failed"
13668
13669         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
13670                 error "create 5k files failed"
13671
13672         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
13673
13674         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
13675
13676         rm -rf $DIR/$tdir
13677 }
13678 run_test 300c "chown && check ls under striped directory"
13679
13680 test_300d() {
13681         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13682         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13683         local stripe_count
13684         local file
13685
13686         mkdir -p $DIR/$tdir
13687         $SETSTRIPE -c 2 $DIR/$tdir
13688
13689         #local striped directory
13690         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13691                 error "set striped dir error"
13692         createmany -o $DIR/$tdir/striped_dir/f 10 ||
13693                 error "create 10 files failed"
13694
13695         #remote striped directory
13696         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
13697                 error "set striped dir error"
13698         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
13699                 error "create 10 files failed"
13700
13701         for file in $(find $DIR/$tdir); do
13702                 stripe_count=$($GETSTRIPE -c $file)
13703                 [ $stripe_count -eq 2 ] ||
13704                         error "wrong stripe $stripe_count for $file"
13705         done
13706
13707         rm -rf $DIR/$tdir
13708 }
13709 run_test 300d "check default stripe under striped directory"
13710
13711 test_300e() {
13712         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13713                 skip "Need MDS version at least 2.7.55" && return
13714         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13715         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13716         local stripe_count
13717         local file
13718
13719         mkdir -p $DIR/$tdir
13720
13721         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13722                 error "set striped dir error"
13723
13724         touch $DIR/$tdir/striped_dir/a
13725         touch $DIR/$tdir/striped_dir/b
13726         touch $DIR/$tdir/striped_dir/c
13727
13728         mkdir $DIR/$tdir/striped_dir/dir_a
13729         mkdir $DIR/$tdir/striped_dir/dir_b
13730         mkdir $DIR/$tdir/striped_dir/dir_c
13731
13732         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
13733                 error "set striped dir under striped dir error"
13734
13735         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
13736                 error "set striped dir under striped dir error"
13737
13738         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
13739                 error "set striped dir under striped dir error"
13740
13741         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
13742                 error "rename dir under striped dir fails"
13743
13744         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
13745                 error "rename dir under different stripes fails"
13746
13747         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
13748                 error "rename file under striped dir should succeed"
13749
13750         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
13751                 error "rename dir under striped dir should succeed"
13752
13753         rm -rf $DIR/$tdir
13754 }
13755 run_test 300e "check rename under striped directory"
13756
13757 test_300f() {
13758         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13759                 skip "Need MDS version at least 2.7.55" && return
13760         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13761         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13762         local stripe_count
13763         local file
13764
13765         rm -rf $DIR/$tdir
13766         mkdir -p $DIR/$tdir
13767
13768         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13769                 error "set striped dir error"
13770
13771         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
13772                 error "set striped dir error"
13773
13774         touch $DIR/$tdir/striped_dir/a
13775         mkdir $DIR/$tdir/striped_dir/dir_a
13776         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
13777                 error "create striped dir under striped dir fails"
13778
13779         touch $DIR/$tdir/striped_dir1/b
13780         mkdir $DIR/$tdir/striped_dir1/dir_b
13781         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
13782                 error "create striped dir under striped dir fails"
13783
13784         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
13785                 error "rename dir under different striped dir should fail"
13786
13787         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
13788                 error "rename striped dir under diff striped dir should fail"
13789
13790         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
13791                 error "rename file under diff striped dirs fails"
13792
13793         rm -rf $DIR/$tdir
13794 }
13795 run_test 300f "check rename cross striped directory"
13796
13797 test_300_check_default_striped_dir()
13798 {
13799         local dirname=$1
13800         local default_count=$2
13801         local default_index=$3
13802         local stripe_count
13803         local stripe_index
13804         local dir_stripe_index
13805         local dir
13806
13807         echo "checking $dirname $default_count $default_index"
13808         $LFS setdirstripe -D -c $default_count -i $default_index \
13809                                 -t all_char $DIR/$tdir/$dirname ||
13810                 error "set default stripe on striped dir error"
13811         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
13812         [ $stripe_count -eq $default_count ] ||
13813                 error "expect $default_count get $stripe_count for $dirname"
13814
13815         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
13816         [ $stripe_index -eq $default_index ] ||
13817                 error "expect $default_index get $stripe_index for $dirname"
13818
13819         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
13820                                                 error "create dirs failed"
13821
13822         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
13823         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
13824         for dir in $(find $DIR/$tdir/$dirname/*); do
13825                 stripe_count=$($LFS getdirstripe -c $dir)
13826                 [ $stripe_count -eq $default_count ] ||
13827                 [ $stripe_count -eq 0 -o $default_count -eq 1 ] ||
13828                 error "stripe count $default_count != $stripe_count for $dir"
13829
13830                 stripe_index=$($LFS getdirstripe -i $dir)
13831                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
13832                         error "$stripe_index != $default_index for $dir"
13833
13834                 #check default stripe
13835                 stripe_count=$($LFS getdirstripe -D -c $dir)
13836                 [ $stripe_count -eq $default_count ] ||
13837                 error "default count $default_count != $stripe_count for $dir"
13838
13839                 stripe_index=$($LFS getdirstripe -D -i $dir)
13840                 [ $stripe_index -eq $default_index ] ||
13841                 error "default index $default_index != $stripe_index for $dir"
13842         done
13843         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
13844 }
13845
13846 test_300g() {
13847         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13848                 skip "Need MDS version at least 2.7.55" && return
13849         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13850         local dir
13851         local stripe_count
13852         local stripe_index
13853
13854         mkdir $DIR/$tdir
13855         mkdir $DIR/$tdir/normal_dir
13856
13857         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
13858         test_300_check_default_striped_dir normal_dir 1 0
13859         test_300_check_default_striped_dir normal_dir 2 1
13860         test_300_check_default_striped_dir normal_dir 2 -1
13861
13862         #delete default stripe information
13863         echo "delete default stripeEA"
13864         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
13865                 error "set default stripe on striped dir error"
13866
13867         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
13868         for dir in $(find $DIR/$tdir/normal_dir/*); do
13869                 stripe_count=$($LFS getdirstripe -c $dir)
13870                 [ $stripe_count -eq 0 ] ||
13871                         error "expect 1 get $stripe_count for $dir"
13872                 stripe_index=$($LFS getdirstripe -i $dir)
13873                 [ $stripe_index -eq 0 ] ||
13874                         error "expect 0 get $stripe_index for $dir"
13875         done
13876 }
13877 run_test 300g "check default striped directory for normal directory"
13878
13879 test_300h() {
13880         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13881                 skip "Need MDS version at least 2.7.55" && return
13882         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13883         local dir
13884         local stripe_count
13885
13886         mkdir $DIR/$tdir
13887         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
13888                                         $DIR/$tdir/striped_dir ||
13889                 error "set striped dir error"
13890
13891         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
13892         test_300_check_default_striped_dir striped_dir 1 0
13893         test_300_check_default_striped_dir striped_dir 2 1
13894         test_300_check_default_striped_dir striped_dir 2 -1
13895
13896         #delete default stripe information
13897         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
13898                 error "set default stripe on striped dir error"
13899
13900         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
13901         for dir in $(find $DIR/$tdir/striped_dir/*); do
13902                 stripe_count=$($LFS getdirstripe -c $dir)
13903                 [ $stripe_count -eq 0 ] ||
13904                         error "expect 1 get $stripe_count for $dir"
13905         done
13906 }
13907 run_test 300h "check default striped directory for striped directory"
13908
13909 test_300i() {
13910         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13911                 skip "Need MDS version at least 2.7.55" && return
13912         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13913         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13914         local stripe_count
13915         local file
13916
13917         mkdir $DIR/$tdir
13918
13919         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
13920                 error "set striped dir error"
13921
13922         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
13923                 error "create files under striped dir failed"
13924
13925         # unfortunately, we need to umount to clear dir layout cache for now
13926         # once we fully implement dir layout, we can drop this
13927         umount_client $MOUNT || error "umount failed"
13928         mount_client $MOUNT || error "mount failed"
13929
13930         #set the stripe to be unknown hash type
13931         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
13932         $LCTL set_param fail_loc=0x1901
13933         for ((i = 0; i < 10; i++)); do
13934                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
13935                         error "stat f-$i failed"
13936                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
13937         done
13938
13939         touch $DIR/$tdir/striped_dir/f0 &&
13940                 error "create under striped dir with unknown hash should fail"
13941
13942         $LCTL set_param fail_loc=0
13943
13944         umount_client $MOUNT || error "umount failed"
13945         mount_client $MOUNT || error "mount failed"
13946
13947         return 0
13948 }
13949 run_test 300i "client handle unknown hash type striped directory"
13950
13951 test_300j() {
13952         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13953         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13954                 skip "Need MDS version at least 2.7.55" && return
13955         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13956         local stripe_count
13957         local file
13958
13959         mkdir $DIR/$tdir
13960
13961         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
13962         $LCTL set_param fail_loc=0x1702
13963         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
13964                 error "set striped dir error"
13965
13966         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
13967                 error "create files under striped dir failed"
13968
13969         $LCTL set_param fail_loc=0
13970
13971         rm -rf $DIR/$tdir || error "unlink striped dir fails"
13972
13973         return 0
13974 }
13975 run_test 300j "test large update record"
13976
13977 test_300k() {
13978         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13979                 skip "Need MDS version at least 2.7.55" && return
13980         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13981         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13982         local stripe_count
13983         local file
13984
13985         mkdir $DIR/$tdir
13986
13987         #define OBD_FAIL_LARGE_STRIPE   0x1703
13988         $LCTL set_param fail_loc=0x1703
13989         $LFS setdirstripe -i 0 -c512 $DIR/$tdir/striped_dir ||
13990                 error "set striped dir error"
13991         $LCTL set_param fail_loc=0
13992
13993         $LFS getdirstripe $DIR/$tdir/striped_dir ||
13994                 error "getstripeddir fails"
13995         rm -rf $DIR/$tdir/striped_dir ||
13996                 error "unlink striped dir fails"
13997
13998         return 0
13999 }
14000 run_test 300k "test large striped directory"
14001
14002 test_300l() {
14003         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14004                 skip "Need MDS version at least 2.7.55" && return
14005         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14006         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14007         local stripe_index
14008
14009         test_mkdir -p $DIR/$tdir/striped_dir
14010         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
14011                         error "chown $RUNAS_ID failed"
14012         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
14013                 error "set default striped dir failed"
14014
14015         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
14016         $LCTL set_param fail_loc=0x80000158
14017         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
14018
14019         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
14020         [ $stripe_index -eq 1 ] ||
14021                 error "expect 1 get $stripe_index for $dir"
14022 }
14023 run_test 300l "non-root user to create dir under striped dir with stale layout"
14024
14025 test_300m() {
14026         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14027                 skip "Need MDS version at least 2.7.55" && return
14028         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14029         [ $MDSCOUNT -ge 2 ] && skip "Only for single MDT" && return
14030
14031         mkdir -p $DIR/$tdir/striped_dir
14032         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
14033                 error "set default stripes dir error"
14034
14035         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
14036
14037         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
14038         [ $stripe_count -eq 0 ] ||
14039                         error "expect 0 get $stripe_count for a"
14040
14041         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
14042                 error "set default stripes dir error"
14043
14044         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
14045
14046         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
14047         [ $stripe_count -eq 0 ] ||
14048                         error "expect 0 get $stripe_count for b"
14049
14050         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
14051                 error "set default stripes dir error"
14052
14053         mkdir $DIR/$tdir/striped_dir/c &&
14054                 error "default stripe_index is invalid, mkdir c should fails"
14055
14056         rm -rf $DIR/$tdir || error "rmdir fails"
14057 }
14058 run_test 300m "setstriped directory on single MDT FS"
14059
14060 cleanup_300n() {
14061         local list=$(comma_list $(mdts_nodes))
14062
14063         trap 0
14064         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
14065 }
14066
14067 test_300n() {
14068         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14069                 skip "Need MDS version at least 2.7.55" && return
14070         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14071         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14072         local stripe_index
14073         local list=$(comma_list $(mdts_nodes))
14074
14075         trap cleanup_300n RETURN EXIT
14076         mkdir -p $DIR/$tdir
14077         chmod 777 $DIR/$tdir
14078         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
14079                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
14080                 error "create striped dir succeeds with gid=0"
14081
14082         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
14083         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
14084                 error "create striped dir fails with gid=-1"
14085
14086         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
14087         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
14088                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
14089                 error "set default striped dir succeeds with gid=0"
14090
14091
14092         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
14093         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
14094                 error "set default striped dir fails with gid=-1"
14095
14096
14097         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
14098         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
14099                                         error "create test_dir fails"
14100         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
14101                                         error "create test_dir1 fails"
14102         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
14103                                         error "create test_dir2 fails"
14104         cleanup_300n
14105 }
14106 run_test 300n "non-root user to create dir under striped dir with default EA"
14107
14108 test_300o() {
14109         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14110                 skip "Need MDS version at least 2.7.55" && return
14111         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14112         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14113         local numfree1
14114         local numfree2
14115
14116         mkdir -p $DIR/$tdir
14117
14118         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
14119         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
14120         if [ $numfree1 -lt 66000 -o $numfree2 -lt 66000 ]; then
14121                 skip "not enough free inodes $numfree1 $numfree2"
14122                 return
14123         fi
14124
14125         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
14126         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
14127         if [ $numfree1 -lt 300000 -o $numfree2 -lt 300000 ]; then
14128                 skip "not enough free space $numfree1 $numfree2"
14129                 return
14130         fi
14131
14132         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
14133                 error "setdirstripe fails"
14134
14135         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
14136                 error "create dirs fails"
14137
14138         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
14139         ls $DIR/$tdir/striped_dir > /dev/null ||
14140                 error "ls striped dir fails"
14141         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
14142                 error "unlink big striped dir fails"
14143 }
14144 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
14145
14146 test_300p() {
14147         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14148         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14149
14150         mkdir -p $DIR/$tdir
14151
14152         #define OBD_FAIL_OUT_ENOSPC     0x1704
14153         do_facet mds2 lctl set_param fail_loc=0x80001704
14154         $LFS setdirstripe -c2 $DIR/$tdir/bad_striped_dir > /dev/null 2>&1 &&
14155                         error "create striped directory should fail"
14156
14157         [ -e $DIR/$tdir/bad_striped_dir ] && error "striped dir exists"
14158         true
14159 }
14160 run_test 300p "create striped directory without space"
14161
14162 prepare_remote_file() {
14163         mkdir $DIR/$tdir/src_dir ||
14164                 error "create remote source failed"
14165
14166         cp /etc/hosts $DIR/$tdir/src_dir/a || error
14167         touch $DIR/$tdir/src_dir/a
14168
14169         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
14170                 error "create remote target dir failed"
14171
14172         touch $DIR/$tdir/tgt_dir/b
14173
14174         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
14175                 error "rename dir cross MDT failed!"
14176
14177         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
14178                 error "src_child still exists after rename"
14179
14180         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
14181                 error "missing file(a) after rename"
14182
14183         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
14184                 error "diff after rename"
14185 }
14186
14187 test_310a() {
14188         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
14189         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14190         local remote_file=$DIR/$tdir/tgt_dir/b
14191
14192         mkdir -p $DIR/$tdir
14193
14194         prepare_remote_file || error "prepare remote file failed"
14195
14196         #open-unlink file
14197         $OPENUNLINK $remote_file $remote_file || error
14198         $CHECKSTAT -a $remote_file || error
14199 }
14200 run_test 310a "open unlink remote file"
14201
14202 test_310b() {
14203         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
14204         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14205         local remote_file=$DIR/$tdir/tgt_dir/b
14206
14207         mkdir -p $DIR/$tdir
14208
14209         prepare_remote_file || error "prepare remote file failed"
14210
14211         ln $remote_file $DIR/$tfile || error "link failed for remote file"
14212         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
14213         $CHECKSTAT -t file $remote_file || error "check file failed"
14214 }
14215 run_test 310b "unlink remote file with multiple links while open"
14216
14217 test_310c() {
14218         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
14219         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14220         local remote_file=$DIR/$tdir/tgt_dir/b
14221
14222         mkdir -p $DIR/$tdir
14223
14224         prepare_remote_file || error "prepare remote file failed"
14225
14226         ln $remote_file $DIR/$tfile || error "link failed for remote file"
14227         multiop_bg_pause $remote_file O_uc ||
14228                         error "mulitop failed for remote file"
14229         MULTIPID=$!
14230         $MULTIOP $DIR/$tfile Ouc
14231         kill -USR1 $MULTIPID
14232         wait $MULTIPID
14233 }
14234 run_test 310c "open-unlink remote file with multiple links"
14235
14236 test_400a() { # LU-1606, was conf-sanity test_74
14237         local extra_flags=''
14238         local out=$TMP/$tfile
14239         local prefix=/usr/include/lustre
14240         local prog
14241
14242         if ! which $CC > /dev/null 2>&1; then
14243                 skip_env "$CC is not installed"
14244                 return 0
14245         fi
14246
14247         if ! [[ -d $prefix ]]; then
14248                 # Assume we're running in tree and fixup the include path.
14249                 extra_flags+=" -I$LUSTRE/../libcfs/include"
14250                 extra_flags+=" -I$LUSTRE/include"
14251                 extra_flags+=" -L$LUSTRE/utils"
14252         fi
14253
14254         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
14255                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
14256                         error "client api broken"
14257         done
14258 }
14259 run_test 400a "Lustre client api program can compile and link"
14260
14261 test_400b() { # LU-1606, LU-5011
14262         local header
14263         local out=$TMP/$tfile
14264         local prefix=/usr/include/lustre
14265
14266         # We use a hard coded prefix so that this test will not fail
14267         # when run in tree. There are headers in lustre/include/lustre/
14268         # that are not packaged (like lustre_idl.h) and have more
14269         # complicated include dependencies (like config.h and lnet/types.h).
14270         # Since this test about correct packaging we just skip them when
14271         # they don't exist (see below) rather than try to fixup cppflags.
14272
14273         if ! which $CC > /dev/null 2>&1; then
14274                 skip_env "$CC is not installed"
14275                 return 0
14276         fi
14277
14278         for header in $prefix/*.h; do
14279                 if ! [[ -f "$header" ]]; then
14280                         continue
14281                 fi
14282
14283                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
14284                         continue # liblustreapi.h is deprecated.
14285                 fi
14286
14287                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
14288                         error "cannot compile '$header'"
14289         done
14290 }
14291 run_test 400b "packaged headers can be compiled"
14292
14293 test_401() { #LU-7437
14294         local params
14295         local procs
14296
14297         #count the number of parameters by "list_param -R"
14298         params=$($LCTL list_param -R '*' 2>/dev/null | wc -l)
14299         #count the number of parameters by listing proc files
14300         ls -lRL /proc/{fs,sys}/{lnet,lustre} 2>/dev/null |
14301                 grep -v "^t" | grep -v "^d" > $TMP/$tfile
14302         #Since there is no /proc/fs/lnet, we need to remove other
14303         #3 directories, /proc/{fs,sys}/lustre and /proc/sys/lnet.
14304         procs=$(($(sed /^$/d $TMP/$tfile | wc -l)-3))
14305
14306         [ $params -eq $procs ] ||
14307                 error "found $params parameters vs. $procs proc files"
14308
14309         rm -f $TMP/$tfile
14310 }
14311 run_test 401 "Verify if 'lctl list_param -R' can list parameters recursively"
14312
14313 #
14314 # tests that do cleanup/setup should be run at the end
14315 #
14316
14317 test_900() {
14318         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14319         local ls
14320         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
14321         $LCTL set_param fail_loc=0x903
14322
14323         cancel_lru_locks MGC
14324
14325         FAIL_ON_ERROR=true cleanup
14326         FAIL_ON_ERROR=true setup
14327 }
14328 run_test 900 "umount should not race with any mgc requeue thread"
14329
14330 complete $SECONDS
14331 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
14332 check_and_cleanup_lustre
14333 if [ "$I_MOUNTED" != "yes" ]; then
14334         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
14335 fi
14336 exit_status