Whamcloud - gitweb
LU-6634 llog: destroy plain llog if init fails
[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 mds_index
560         local devname
561         local cmd
562         local i
563         local rc=0
564
565         remote_mds_nodsh && skip "remote MDS with nodsh" && return
566         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
567         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
568                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
569
570         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
571                 skip "only for ldiskfs MDT" && return 0
572
573         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
574
575         test_mkdir -p $WDIR
576         long_sym=$short_sym
577         # create a long symlink file
578         for ((i = 0; i < 4; ++i)); do
579                 long_sym=${long_sym}${long_sym}
580         done
581
582         echo "create 512 short and long symlink files under $WDIR"
583         for ((i = 0; i < 256; ++i)); do
584                 ln -sf ${long_sym}"a5a5" $WDIR/long-$i
585                 ln -sf ${short_sym}"a5a5" $WDIR/short-$i
586         done
587
588         echo "erase them"
589         rm -f $WDIR/*
590         sync
591         wait_delete_completed
592
593         echo "recreate the 512 symlink files with a shorter string"
594         for ((i = 0; i < 512; ++i)); do
595                 # rewrite the symlink file with a shorter string
596                 ln -sf ${long_sym} $WDIR/long-$i
597                 ln -sf ${short_sym} $WDIR/short-$i
598         done
599
600         mds_index=$($LFS getstripe -M $WDIR)
601         mds_index=$((mds_index+1))
602         devname=$(mdsdevname $mds_index)
603         cmd="$E2FSCK -fnvd $devname"
604
605         echo "stop and checking mds${mds_index}: $cmd"
606         # e2fsck should not return error
607         stop mds${mds_index}
608         do_facet mds${mds_index} $cmd || rc=$?
609
610         start mds${mds_index} $devname $MDS_MOUNT_OPTS || error "start failed"
611         df $MOUNT > /dev/null 2>&1
612         [ $rc -ne 0 ] && error "e2fsck should not report error upon "\
613                 "short/long symlink MDT: rc=$rc"
614         return $rc
615 }
616 run_test 17m "run e2fsck against MDT which contains short/long symlink"
617
618 check_fs_consistency_17n() {
619         local mdt_index
620         local devname
621         local cmd
622         local rc=0
623
624         # create/unlink in 17n only change 2 MDTs(MDT1/MDT2),
625         # so it only check MDT1/MDT2 instead of all of MDTs.
626         for mdt_index in $(seq 1 2); do
627                 devname=$(mdsdevname $mdt_index)
628                 cmd="$E2FSCK -fnvd $devname"
629
630                 echo "stop and checking mds${mdt_index}: $cmd"
631                 # e2fsck should not return error
632                 stop mds${mdt_index}
633                 do_facet mds${mdt_index} $cmd || rc=$?
634
635                 start mds${mdt_index} $devname $MDS_MOUNT_OPTS ||
636                         error "mount mds${mdt_index} failed"
637                 df $MOUNT > /dev/null 2>&1
638                 [ $rc -ne 0 ] && break
639         done
640         return $rc
641 }
642
643 test_17n() {
644         local i
645
646         remote_mds_nodsh && skip "remote MDS with nodsh" && return
647         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] &&
648         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.2.93) ] &&
649                 skip "MDS 2.2.0-2.2.93 do not NUL-terminate symlinks" && return
650
651         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
652                 skip "only for ldiskfs MDT" && return 0
653
654         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
655
656         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
657
658         test_mkdir $DIR/$tdir
659         for ((i=0; i<10; i++)); do
660                 $LFS mkdir -i1 -c2 $DIR/$tdir/remote_dir_${i} ||
661                         error "create remote dir error $i"
662                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
663                         error "create files under remote dir failed $i"
664         done
665
666         check_fs_consistency_17n ||
667                 error "e2fsck report error after create files under remote dir"
668
669         for ((i = 0; i < 10; i++)); do
670                 rm -rf $DIR/$tdir/remote_dir_${i} ||
671                         error "destroy remote dir error $i"
672         done
673
674         check_fs_consistency_17n ||
675                 error "e2fsck report error after unlink files under remote dir"
676
677         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.50) ] &&
678                 skip "lustre < 2.4.50 does not support migrate mv " && return
679
680         for ((i = 0; i < 10; i++)); do
681                 mkdir -p $DIR/$tdir/remote_dir_${i}
682                 createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
683                         error "create files under remote dir failed $i"
684                 $LFS migrate --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
685                         error "migrate remote dir error $i"
686         done
687         check_fs_consistency_17n || error "e2fsck report error after migration"
688
689         for ((i = 0; i < 10; i++)); do
690                 rm -rf $DIR/$tdir/remote_dir_${i} ||
691                         error "destroy remote dir error $i"
692         done
693
694         check_fs_consistency_17n || error "e2fsck report error after unlink"
695 }
696 run_test 17n "run e2fsck against master/slave MDT which contains remote dir"
697
698 test_17o() {
699         remote_mds_nodsh && skip "remote MDS with nodsh" && return
700         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.64) ] &&
701                 skip "Need MDS version at least 2.3.64" && return
702
703         local WDIR=$DIR/${tdir}o
704         local mdt_index
705         local rc=0
706
707         test_mkdir -p $WDIR
708         mdt_index=$($LFS getstripe -M $WDIR)
709         mdt_index=$((mdt_index+1))
710
711         touch $WDIR/$tfile
712
713         #fail mds will wait the failover finish then set
714         #following fail_loc to avoid interfer the recovery process.
715         fail mds${mdt_index}
716
717         #define OBD_FAIL_OSD_LMA_INCOMPAT 0x194
718         do_facet mds${mdt_index} lctl set_param fail_loc=0x194
719         ls -l $WDIR/$tfile && rc=1
720         do_facet mds${mdt_index} lctl set_param fail_loc=0
721         [[ $rc -ne 0 ]] && error "stat file should fail"
722         true
723 }
724 run_test 17o "stat file with incompat LMA feature"
725
726 test_18() {
727         touch $DIR/$tfile || error "Failed to touch $DIR/$tfile: $?"
728         ls $DIR || error "Failed to ls $DIR: $?"
729 }
730 run_test 18 "touch .../f ; ls ... =============================="
731
732 test_19a() {
733         touch $DIR/$tfile
734         ls -l $DIR
735         rm $DIR/$tfile
736         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
737 }
738 run_test 19a "touch .../f19 ; ls -l ... ; rm .../f19 ==========="
739
740 test_19b() {
741         ls -l $DIR/$tfile && error "ls -l $tfile failed"|| true
742 }
743 run_test 19b "ls -l .../f19 (should return error) =============="
744
745 test_19c() {
746         [ $RUNAS_ID -eq $UID ] &&
747                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
748         $RUNAS touch $DIR/$tfile && error "create non-root file failed" || true
749 }
750 run_test 19c "$RUNAS touch .../f19 (should return error) =="
751
752 test_19d() {
753         cat $DIR/f19 && error || true
754 }
755 run_test 19d "cat .../f19 (should return error) =============="
756
757 test_20() {
758         touch $DIR/$tfile
759         rm $DIR/$tfile
760         log "1 done"
761         touch $DIR/$tfile
762         rm $DIR/$tfile
763         log "2 done"
764         touch $DIR/$tfile
765         rm $DIR/$tfile
766         log "3 done"
767         $CHECKSTAT -a $DIR/$tfile || error "$tfile was not removed"
768 }
769 run_test 20 "touch .../f ; ls -l ... ==========================="
770
771 test_21() {
772         test_mkdir -p $DIR/$tdir
773         [ -f $DIR/$tdir/dangle ] && rm -f $DIR/$tdir/dangle
774         ln -s dangle $DIR/$tdir/link
775         echo foo >> $DIR/$tdir/link
776         cat $DIR/$tdir/dangle
777         $CHECKSTAT -t link $DIR/$tdir/link || error "$tdir/link not a link"
778         $CHECKSTAT -f -t file $DIR/$tdir/link ||
779                 error "$tdir/link not linked to a file"
780 }
781 run_test 21 "write to dangling link ============================"
782
783 test_22() {
784         WDIR=$DIR/$tdir
785         test_mkdir -p $DIR/$tdir
786         chown $RUNAS_ID:$RUNAS_GID $WDIR
787         (cd $WDIR || error "cd $WDIR failed";
788         $RUNAS tar cf - /etc/hosts /etc/sysconfig/network | \
789         $RUNAS tar xf -)
790         ls -lR $WDIR/etc || error "ls -lR $WDIR/etc failed"
791         $CHECKSTAT -t dir $WDIR/etc || error "checkstat -t dir failed"
792         $CHECKSTAT -u \#$RUNAS_ID -g \#$RUNAS_GID $WDIR/etc || error "checkstat -u failed"
793 }
794 run_test 22 "unpack tar archive as non-root user ==============="
795
796 # was test_23
797 test_23a() {
798         test_mkdir -p $DIR/$tdir
799         local file=$DIR/$tdir/$tfile
800
801         openfile -f O_CREAT:O_EXCL $file || error "$file create failed"
802         openfile -f O_CREAT:O_EXCL $file &&
803                 error "$file recreate succeeded" || true
804 }
805 run_test 23a "O_CREAT|O_EXCL in subdir =========================="
806
807 test_23b() { # bug 18988
808         test_mkdir -p $DIR/$tdir
809         local file=$DIR/$tdir/$tfile
810
811         rm -f $file
812         echo foo > $file || error "write filed"
813         echo bar >> $file || error "append filed"
814         $CHECKSTAT -s 8 $file || error "wrong size"
815         rm $file
816 }
817 run_test 23b "O_APPEND check =========================="
818
819 # rename sanity
820 test_24a() {
821         echo '-- same directory rename'
822         test_mkdir $DIR/$tdir
823         touch $DIR/$tdir/$tfile.1
824         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
825         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
826 }
827 run_test 24a "rename file to non-existent target"
828
829 test_24b() {
830         test_mkdir $DIR/$tdir
831         touch $DIR/$tdir/$tfile.{1,2}
832         mv $DIR/$tdir/$tfile.1 $DIR/$tdir/$tfile.2
833         $CHECKSTAT -a $DIR/$tdir/$tfile.1 || error "$tfile.1 exists"
834         $CHECKSTAT -t file $DIR/$tdir/$tfile.2 || error "$tfile.2 not a file"
835 }
836 run_test 24b "rename file to existing target"
837
838 test_24c() {
839         test_mkdir $DIR/$tdir
840         test_mkdir $DIR/$tdir/d$testnum.1
841         mv $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
842         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
843         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
844 }
845 run_test 24c "rename directory to non-existent target"
846
847 test_24d() {
848         test_mkdir -c1 $DIR/$tdir
849         test_mkdir -c1 $DIR/$tdir/d$testnum.1
850         test_mkdir -c1 $DIR/$tdir/d$testnum.2
851         mrename $DIR/$tdir/d$testnum.1 $DIR/$tdir/d$testnum.2
852         $CHECKSTAT -a $DIR/$tdir/d$testnum.1 || error "d$testnum.1 exists"
853         $CHECKSTAT -t dir $DIR/$tdir/d$testnum.2 || error "d$testnum.2 not dir"
854 }
855 run_test 24d "rename directory to existing target"
856
857 test_24e() {
858         echo '-- cross directory renames --'
859         test_mkdir $DIR/R5a
860         test_mkdir $DIR/R5b
861         touch $DIR/R5a/f
862         mv $DIR/R5a/f $DIR/R5b/g
863         $CHECKSTAT -a $DIR/R5a/f || error
864         $CHECKSTAT -t file $DIR/R5b/g || error
865 }
866 run_test 24e "touch .../R5a/f; rename .../R5a/f .../R5b/g ======"
867
868 test_24f() {
869         test_mkdir $DIR/R6a
870         test_mkdir $DIR/R6b
871         touch $DIR/R6a/f $DIR/R6b/g
872         mv $DIR/R6a/f $DIR/R6b/g
873         $CHECKSTAT -a $DIR/R6a/f || error
874         $CHECKSTAT -t file $DIR/R6b/g || error
875 }
876 run_test 24f "touch .../R6a/f R6b/g; mv .../R6a/f .../R6b/g ===="
877
878 test_24g() {
879         test_mkdir $DIR/R7a
880         test_mkdir $DIR/R7b
881         test_mkdir $DIR/R7a/d
882         mv $DIR/R7a/d $DIR/R7b/e
883         $CHECKSTAT -a $DIR/R7a/d || error
884         $CHECKSTAT -t dir $DIR/R7b/e || error
885 }
886 run_test 24g "mkdir .../R7{a,b}/d; mv .../R7a/d .../R7b/e ======"
887
888 test_24h() {
889         test_mkdir -c1 $DIR/R8a
890         test_mkdir -c1 $DIR/R8b
891         test_mkdir -c1 $DIR/R8a/d
892         test_mkdir -c1 $DIR/R8b/e
893         mrename $DIR/R8a/d $DIR/R8b/e
894         $CHECKSTAT -a $DIR/R8a/d || error
895         $CHECKSTAT -t dir $DIR/R8b/e || error
896 }
897 run_test 24h "mkdir .../R8{a,b}/{d,e}; rename .../R8a/d .../R8b/e"
898
899 test_24i() {
900         echo "-- rename error cases"
901         test_mkdir $DIR/R9
902         test_mkdir $DIR/R9/a
903         touch $DIR/R9/f
904         mrename $DIR/R9/f $DIR/R9/a
905         $CHECKSTAT -t file $DIR/R9/f || error
906         $CHECKSTAT -t dir  $DIR/R9/a || error
907         $CHECKSTAT -a $DIR/R9/a/f || error
908 }
909 run_test 24i "rename file to dir error: touch f ; mkdir a ; rename f a"
910
911 test_24j() {
912         test_mkdir $DIR/R10
913         mrename $DIR/R10/f $DIR/R10/g
914         $CHECKSTAT -t dir $DIR/R10 || error
915         $CHECKSTAT -a $DIR/R10/f || error
916         $CHECKSTAT -a $DIR/R10/g || error
917 }
918 run_test 24j "source does not exist ============================"
919
920 test_24k() {
921         test_mkdir $DIR/R11a
922         test_mkdir $DIR/R11a/d
923         touch $DIR/R11a/f
924         mv $DIR/R11a/f $DIR/R11a/d
925         $CHECKSTAT -a $DIR/R11a/f || error
926         $CHECKSTAT -t file $DIR/R11a/d/f || error
927 }
928 run_test 24k "touch .../R11a/f; mv .../R11a/f .../R11a/d ======="
929
930 # bug 2429 - rename foo foo foo creates invalid file
931 test_24l() {
932         f="$DIR/f24l"
933         $MULTIOP $f OcNs || error
934 }
935 run_test 24l "Renaming a file to itself ========================"
936
937 test_24m() {
938         f="$DIR/f24m"
939         $MULTIOP $f OcLN ${f}2 ${f}2 || error "link ${f}2 ${f}2 failed"
940         # on ext3 this does not remove either the source or target files
941         # though the "expected" operation would be to remove the source
942         $CHECKSTAT -t file ${f} || error "${f} missing"
943         $CHECKSTAT -t file ${f}2 || error "${f}2 missing"
944 }
945 run_test 24m "Renaming a file to a hard link to itself ========="
946
947 test_24n() {
948     f="$DIR/f24n"
949     # this stats the old file after it was renamed, so it should fail
950     touch ${f}
951     $CHECKSTAT ${f}
952     mv ${f} ${f}.rename
953     $CHECKSTAT ${f}.rename
954     $CHECKSTAT -a ${f}
955 }
956 run_test 24n "Statting the old file after renaming (Posix rename 2)"
957
958 test_24o() {
959         test_mkdir -p $DIR/d24o
960         rename_many -s random -v -n 10 $DIR/d24o
961 }
962 run_test 24o "rename of files during htree split ==============="
963
964 test_24p() {
965         test_mkdir $DIR/R12a
966         test_mkdir $DIR/R12b
967         DIRINO=`ls -lid $DIR/R12a | awk '{ print $1 }'`
968         mrename $DIR/R12a $DIR/R12b
969         $CHECKSTAT -a $DIR/R12a || error
970         $CHECKSTAT -t dir $DIR/R12b || error
971         DIRINO2=`ls -lid $DIR/R12b | awk '{ print $1 }'`
972         [ "$DIRINO" = "$DIRINO2" ] || error "R12a $DIRINO != R12b $DIRINO2"
973 }
974 run_test 24p "mkdir .../R12{a,b}; rename .../R12a .../R12b"
975
976 cleanup_multiop_pause() {
977         trap 0
978         kill -USR1 $MULTIPID
979 }
980
981 test_24q() {
982         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
983         test_mkdir $DIR/R13a
984         test_mkdir $DIR/R13b
985         local DIRINO=$(ls -lid $DIR/R13a | awk '{ print $1 }')
986         multiop_bg_pause $DIR/R13b D_c || error "multiop failed to start"
987         MULTIPID=$!
988
989         trap cleanup_multiop_pause EXIT
990         mrename $DIR/R13a $DIR/R13b
991         $CHECKSTAT -a $DIR/R13a || error "R13a still exists"
992         $CHECKSTAT -t dir $DIR/R13b || error "R13b does not exist"
993         local DIRINO2=$(ls -lid $DIR/R13b | awk '{ print $1 }')
994         [ "$DIRINO" = "$DIRINO2" ] || error "R13a $DIRINO != R13b $DIRINO2"
995         cleanup_multiop_pause
996         wait $MULTIPID || error "multiop close failed"
997 }
998 run_test 24q "mkdir .../R13{a,b}; open R13b rename R13a R13b ==="
999
1000 test_24r() { #bug 3789
1001         test_mkdir $DIR/R14a
1002         test_mkdir $DIR/R14a/b
1003         mrename $DIR/R14a $DIR/R14a/b && error "rename to subdir worked!"
1004         $CHECKSTAT -t dir $DIR/R14a || error "$DIR/R14a missing"
1005         $CHECKSTAT -t dir $DIR/R14a/b || error "$DIR/R14a/b missing"
1006 }
1007 run_test 24r "mkdir .../R14a/b; rename .../R14a .../R14a/b ====="
1008
1009 test_24s() {
1010         test_mkdir $DIR/R15a
1011         test_mkdir $DIR/R15a/b
1012         test_mkdir $DIR/R15a/b/c
1013         mrename $DIR/R15a $DIR/R15a/b/c && error "rename to sub-subdir worked!"
1014         $CHECKSTAT -t dir $DIR/R15a || error "$DIR/R15a missing"
1015         $CHECKSTAT -t dir $DIR/R15a/b/c || error "$DIR/R15a/b/c missing"
1016 }
1017 run_test 24s "mkdir .../R15a/b/c; rename .../R15a .../R15a/b/c ="
1018 test_24t() {
1019         test_mkdir $DIR/R16a
1020         test_mkdir $DIR/R16a/b
1021         test_mkdir $DIR/R16a/b/c
1022         mrename $DIR/R16a/b/c $DIR/R16a && error "rename to sub-subdir worked!"
1023         $CHECKSTAT -t dir $DIR/R16a || error "$DIR/R16a missing"
1024         $CHECKSTAT -t dir $DIR/R16a/b/c || error "$DIR/R16a/b/c missing"
1025 }
1026 run_test 24t "mkdir .../R16a/b/c; rename .../R16a/b/c .../R16a ="
1027
1028 test_24u() { # bug12192
1029         $MULTIOP $DIR/$tfile C2w$((2048 * 1024))c || error
1030         $CHECKSTAT -s $((2048 * 1024)) $DIR/$tfile || error "wrong file size"
1031 }
1032 run_test 24u "create stripe file"
1033
1034 page_size() {
1035         getconf PAGE_SIZE
1036 }
1037
1038 simple_cleanup_common() {
1039         trap 0
1040         rm -rf $DIR/$tdir
1041         wait_delete_completed
1042 }
1043
1044 max_pages_per_rpc() {
1045         $LCTL get_param -n mdc.*.max_pages_per_rpc | head -n1
1046 }
1047
1048 test_24v() {
1049         local NRFILES=100000
1050         local FREE_INODES=$(mdt_free_inodes 0)
1051         [[ $FREE_INODES -lt $NRFILES ]] &&
1052                 skip "not enough free inodes $FREE_INODES required $NRFILES" &&
1053                 return
1054
1055         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1056         trap simple_cleanup_common EXIT
1057
1058         # Performance issue on ZFS see LU-4072 (c.f. LU-2887)
1059         [ $(facet_fstype $SINGLEMDS) = "zfs" ] && NRFILES=10000
1060
1061         test_mkdir -p $DIR/$tdir
1062         createmany -m $DIR/$tdir/$tfile $NRFILES
1063
1064         cancel_lru_locks mdc
1065         lctl set_param mdc.*.stats clear
1066
1067         ls $DIR/$tdir >/dev/null || error "error in listing large dir"
1068
1069         # LU-5 large readdir
1070         # DIRENT_SIZE = 32 bytes for sizeof(struct lu_dirent) +
1071         #               8 bytes for name(filename is mostly 5 in this test) +
1072         #               8 bytes for luda_type
1073         # take into account of overhead in lu_dirpage header and end mark in
1074         # each page, plus one in RPC_NUM calculation.
1075         DIRENT_SIZE=48
1076         RPC_SIZE=$(($(max_pages_per_rpc) * $(page_size)))
1077         RPC_NUM=$(((NRFILES * DIRENT_SIZE + RPC_SIZE - 1) / RPC_SIZE + 1))
1078         mds_readpage=$(lctl get_param mdc.*MDT0000*.stats |
1079                                 awk '/^mds_readpage/ {print $2}')
1080         [[ $mds_readpage -gt $RPC_NUM ]] &&
1081                 error "large readdir doesn't take effect"
1082
1083         simple_cleanup_common
1084 }
1085 run_test 24v "list directory with large files (handle hash collision, bug: 17560)"
1086
1087 test_24w() { # bug21506
1088         SZ1=234852
1089         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=4096 || return 1
1090         dd if=/dev/zero bs=$SZ1 count=1 >> $DIR/$tfile || return 2
1091         dd if=$DIR/$tfile of=$DIR/${tfile}_left bs=1M skip=4097 || return 3
1092         SZ2=`ls -l $DIR/${tfile}_left | awk '{print $5}'`
1093         [[ "$SZ1" -eq "$SZ2" ]] ||
1094                 error "Error reading at the end of the file $tfile"
1095 }
1096 run_test 24w "Reading a file larger than 4Gb"
1097
1098 test_24x() {
1099         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1100         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1101         local MDTIDX=1
1102         local remote_dir=$DIR/$tdir/remote_dir
1103
1104         test_mkdir -p $DIR/$tdir
1105         $LFS mkdir -i $MDTIDX $remote_dir ||
1106                 error "create remote directory failed"
1107
1108         test_mkdir -p $DIR/$tdir/src_dir
1109         touch $DIR/$tdir/src_file
1110         test_mkdir -p $remote_dir/tgt_dir
1111         touch $remote_dir/tgt_file
1112
1113         mrename $DIR/$tdir/src_dir $remote_dir/tgt_dir ||
1114                 error "rename dir cross MDT failed!"
1115
1116         mrename $DIR/$tdir/src_file $remote_dir/tgt_file ||
1117                 error "rename file cross MDT failed!"
1118
1119         touch $DIR/$tdir/ln_file
1120         ln $DIR/$tdir/ln_file $remote_dir/ln_name ||
1121                 error "ln file cross MDT failed"
1122
1123         rm -rf $DIR/$tdir || error "Can not delete directories"
1124 }
1125 run_test 24x "cross MDT rename/link"
1126
1127 test_24y() {
1128         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
1129         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1130         local MDTIDX=1
1131         local remote_dir=$DIR/$tdir/remote_dir
1132
1133         test_mkdir -p $DIR/$tdir
1134         $LFS mkdir -i $MDTIDX $remote_dir ||
1135                    error "create remote directory failed"
1136
1137         test_mkdir -p $remote_dir/src_dir
1138         touch $remote_dir/src_file
1139         test_mkdir -p $remote_dir/tgt_dir
1140         touch $remote_dir/tgt_file
1141
1142         mrename $remote_dir/src_dir $remote_dir/tgt_dir ||
1143                 error "rename subdir in the same remote dir failed!"
1144
1145         mrename $remote_dir/src_file $remote_dir/tgt_file ||
1146                 error "rename files in the same remote dir failed!"
1147
1148         ln $remote_dir/tgt_file $remote_dir/tgt_file1 ||
1149                 error "link files in the same remote dir failed!"
1150
1151         rm -rf $DIR/$tdir || error "Can not delete directories"
1152 }
1153 run_test 24y "rename/link on the same dir should succeed"
1154
1155 test_24A() { # LU-3182
1156         local NFILES=5000
1157
1158         rm -rf $DIR/$tdir
1159         test_mkdir -p $DIR/$tdir
1160         createmany -m $DIR/$tdir/$tfile $NFILES
1161         local t=$(ls $DIR/$tdir | wc -l)
1162         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1163         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1164         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1165                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1166         fi
1167
1168         rm -rf $DIR/$tdir || error "Can not delete directories"
1169 }
1170 run_test 24A "readdir() returns correct number of entries."
1171
1172 test_24B() { # LU-4805
1173         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1174         local count
1175
1176         test_mkdir $DIR/$tdir
1177         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
1178                 error "create striped dir failed"
1179
1180         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1181         [ $count -eq 2 ] || error "Expected 2, got $count"
1182
1183         touch $DIR/$tdir/striped_dir/a
1184
1185         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1186         [ $count -eq 3 ] || error "Expected 3, got $count"
1187
1188         touch $DIR/$tdir/striped_dir/.f
1189
1190         count=$(ls -ai $DIR/$tdir/striped_dir | wc -l)
1191         [ $count -eq 4 ] || error "Expected 4, got $count"
1192
1193         rm -rf $DIR/$tdir || error "Can not delete directories"
1194 }
1195 run_test 24B "readdir for striped dir return correct number of entries"
1196
1197 test_24C() {
1198         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1199
1200         mkdir $DIR/$tdir
1201         mkdir $DIR/$tdir/d0
1202         mkdir $DIR/$tdir/d1
1203
1204         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/d0/striped_dir ||
1205                 error "create striped dir failed"
1206
1207         cd $DIR/$tdir/d0/striped_dir
1208
1209         local d0_ino=$(ls -i -l -a $DIR/$tdir | grep "d0" | awk '{print $1}')
1210         local d1_ino=$(ls -i -l -a $DIR/$tdir | grep "d1" | awk '{print $1}')
1211         local parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1212
1213         [ "$d0_ino" = "$parent_ino" ] ||
1214                 error ".. wrong, expect $d0_ino, get $parent_ino"
1215
1216         mv $DIR/$tdir/d0/striped_dir $DIR/$tdir/d1/ ||
1217                 error "mv striped dir failed"
1218
1219         parent_ino=$(ls -i -l -a | grep "\.\." | awk '{print $1}')
1220
1221         [ "$d1_ino" = "$parent_ino" ] ||
1222                 error ".. wrong after mv, expect $d1_ino, get $parent_ino"
1223 }
1224 run_test 24C "check .. in striped dir"
1225
1226 test_24D() { # LU-6101
1227         local NFILES=50000
1228
1229         rm -rf $DIR/$tdir
1230         mkdir -p $DIR/$tdir
1231         createmany -m $DIR/$tdir/$tfile $NFILES
1232         local t=$(ls $DIR/$tdir | wc -l)
1233         local u=$(ls $DIR/$tdir | sort -u | wc -l)
1234         local v=$(ls -ai $DIR/$tdir | sort -u | wc -l)
1235         if [ $t -ne $NFILES -o $u -ne $NFILES -o $v -ne $((NFILES + 2)) ] ; then
1236                 error "Expected $NFILES files, got $t ($u unique $v .&..)"
1237         fi
1238
1239         rm -rf $DIR/$tdir || error "Can not delete directories"
1240 }
1241 run_test 24D "readdir() returns correct number of entries after cursor reload"
1242
1243 test_24E() {
1244         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
1245         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1246
1247         mkdir -p $DIR/$tdir
1248         mkdir $DIR/$tdir/src_dir
1249         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
1250                 error "create remote source failed"
1251
1252         touch $DIR/$tdir/src_dir/src_child/a
1253
1254         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
1255                 error "create remote target dir failed"
1256
1257         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
1258                 error "create remote target child failed"
1259
1260         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
1261                 error "rename dir cross MDT failed!"
1262
1263         find $DIR/$tdir
1264
1265         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
1266                 error "src_child still exists after rename"
1267
1268         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
1269                 error "missing file(a) after rename"
1270
1271         rm -rf $DIR/$tdir || error "Can not delete directories"
1272 }
1273 run_test 24E "cross MDT rename/link"
1274
1275 test_25a() {
1276         echo '== symlink sanity ============================================='
1277
1278         test_mkdir $DIR/d25
1279         ln -s d25 $DIR/s25
1280         touch $DIR/s25/foo || error
1281 }
1282 run_test 25a "create file in symlinked directory ==============="
1283
1284 test_25b() {
1285         [ ! -d $DIR/d25 ] && test_25a
1286         $CHECKSTAT -t file $DIR/s25/foo || error
1287 }
1288 run_test 25b "lookup file in symlinked directory ==============="
1289
1290 test_26a() {
1291         test_mkdir $DIR/d26
1292         test_mkdir $DIR/d26/d26-2
1293         ln -s d26/d26-2 $DIR/s26
1294         touch $DIR/s26/foo || error
1295 }
1296 run_test 26a "multiple component symlink ======================="
1297
1298 test_26b() {
1299         test_mkdir -p $DIR/d26b/d26-2
1300         ln -s d26b/d26-2/foo $DIR/s26-2
1301         touch $DIR/s26-2 || error
1302 }
1303 run_test 26b "multiple component symlink at end of lookup ======"
1304
1305 test_26c() {
1306         test_mkdir $DIR/d26.2
1307         touch $DIR/d26.2/foo
1308         ln -s d26.2 $DIR/s26.2-1
1309         ln -s s26.2-1 $DIR/s26.2-2
1310         ln -s s26.2-2 $DIR/s26.2-3
1311         chmod 0666 $DIR/s26.2-3/foo
1312 }
1313 run_test 26c "chain of symlinks ================================"
1314
1315 # recursive symlinks (bug 439)
1316 test_26d() {
1317         ln -s d26-3/foo $DIR/d26-3
1318 }
1319 run_test 26d "create multiple component recursive symlink ======"
1320
1321 test_26e() {
1322         [ ! -h $DIR/d26-3 ] && test_26d
1323         rm $DIR/d26-3
1324 }
1325 run_test 26e "unlink multiple component recursive symlink ======"
1326
1327 # recursive symlinks (bug 7022)
1328 test_26f() {
1329         test_mkdir -p $DIR/$tdir
1330         test_mkdir $DIR/$tdir/$tfile   || error "mkdir $DIR/$tdir/$tfile failed"
1331         cd $DIR/$tdir/$tfile           || error "cd $DIR/$tdir/$tfile failed"
1332         test_mkdir -p lndir/bar1      || error "mkdir lndir/bar1 failed"
1333         test_mkdir $DIR/$tdir/$tfile/$tfile   || error "mkdir $tfile failed"
1334         cd $tfile                || error "cd $tfile failed"
1335         ln -s .. dotdot          || error "ln dotdot failed"
1336         ln -s dotdot/lndir lndir || error "ln lndir failed"
1337         cd $DIR/$tdir                 || error "cd $DIR/$tdir failed"
1338         output=`ls $tfile/$tfile/lndir/bar1`
1339         [ "$output" = bar1 ] && error "unexpected output"
1340         rm -r $tfile             || error "rm $tfile failed"
1341         $CHECKSTAT -a $DIR/$tfile || error "$tfile not gone"
1342 }
1343 run_test 26f "rm -r of a directory which has recursive symlink ="
1344
1345 test_27a() {
1346         echo '== stripe sanity =============================================='
1347         test_mkdir -p $DIR/d27 || error "mkdir failed"
1348         $GETSTRIPE $DIR/d27
1349         $SETSTRIPE -c 1 $DIR/d27/f0 || error "setstripe failed"
1350         $CHECKSTAT -t file $DIR/d27/f0 || error "checkstat failed"
1351         log "== test_27a: write to one stripe file ========================="
1352         cp /etc/hosts $DIR/d27/f0 || error
1353 }
1354 run_test 27a "one stripe file =================================="
1355
1356 test_27b() {
1357         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
1358         test_mkdir -p $DIR/d27
1359         $SETSTRIPE -c 2 $DIR/d27/f01 || error "setstripe failed"
1360         $GETSTRIPE -c $DIR/d27/f01
1361         [ $($GETSTRIPE -c $DIR/d27/f01) -eq 2 ] ||
1362                 error "two-stripe file doesn't have two stripes"
1363
1364         dd if=/dev/zero of=$DIR/d27/f01 bs=4k count=4 || error "dd failed"
1365 }
1366 run_test 27b "create and write to two stripe file"
1367
1368 test_27d() {
1369         test_mkdir -p $DIR/d27
1370         $SETSTRIPE -c 0 -i -1 -S 0 $DIR/d27/fdef || error "setstripe failed"
1371         $CHECKSTAT -t file $DIR/d27/fdef || error "checkstat failed"
1372         dd if=/dev/zero of=$DIR/d27/fdef bs=4k count=4 || error
1373 }
1374 run_test 27d "create file with default settings ================"
1375
1376 test_27e() {
1377         # LU-5839 adds check for existed layout before setting it
1378         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.56) ]] &&
1379                 skip "Need MDS version at least 2.7.56" && return
1380         test_mkdir -p $DIR/d27
1381         $SETSTRIPE -c 2 $DIR/d27/f12 || error "setstripe failed"
1382         $SETSTRIPE -c 2 $DIR/d27/f12 && error "setstripe succeeded twice"
1383         $CHECKSTAT -t file $DIR/d27/f12 || error "checkstat failed"
1384 }
1385 run_test 27e "setstripe existing file (should return error) ======"
1386
1387 test_27f() {
1388         test_mkdir $DIR/$tdir
1389         $SETSTRIPE -S 100 -i 0 -c 1 $DIR/$tdir/$tfile &&
1390                 error "$SETSTRIPE $DIR/$tdir/$tfile failed"
1391         $CHECKSTAT -t file $DIR/$tdir/$tfile &&
1392                 error "$CHECKSTAT -t file $DIR/$tdir/$tfile should fail"
1393         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=4k count=4 || error "dd failed"
1394         $GETSTRIPE $DIR/$tdir/$tfile || error "$GETSTRIPE failed"
1395 }
1396 run_test 27f "setstripe with bad stripe size (should return error)"
1397
1398 test_27g() {
1399         test_mkdir -p $DIR/d27
1400         $MCREATE $DIR/d27/fnone || error "mcreate failed"
1401         $GETSTRIPE $DIR/d27/fnone 2>&1 | grep "no stripe info" ||
1402                 error "$DIR/d27/fnone has object"
1403 }
1404 run_test 27g "$GETSTRIPE with no objects"
1405
1406 test_27i() {
1407         test_mkdir $DIR/$tdir
1408         touch $DIR/$tdir/$tfile || error "touch failed"
1409         [[ $($GETSTRIPE -c $DIR/$tdir/$tfile) -gt 0 ]] ||
1410                 error "missing objects"
1411 }
1412 run_test 27i "$GETSTRIPE with some objects"
1413
1414 test_27j() {
1415         test_mkdir -p $DIR/d27
1416         $SETSTRIPE -i $OSTCOUNT $DIR/d27/f27j && error "setstripe failed"||true
1417 }
1418 run_test 27j "setstripe with bad stripe offset (should return error)"
1419
1420 test_27k() { # bug 2844
1421         test_mkdir -p $DIR/d27
1422         FILE=$DIR/d27/f27k
1423         LL_MAX_BLKSIZE=$((4 * 1024 * 1024))
1424         [ ! -d $DIR/d27 ] && test_mkdir -p $DIR d27
1425         $SETSTRIPE -S 67108864 $FILE || error "setstripe failed"
1426         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1427         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "1:$BLKSIZE > $LL_MAX_BLKSIZE"
1428         dd if=/dev/zero of=$FILE bs=4k count=1
1429         BLKSIZE=`stat $FILE | awk '/IO Block:/ { print $7 }'`
1430         [ $BLKSIZE -le $LL_MAX_BLKSIZE ] || error "2:$BLKSIZE > $LL_MAX_BLKSIZE"
1431 }
1432 run_test 27k "limit i_blksize for broken user apps ============="
1433
1434 test_27l() {
1435         test_mkdir -p $DIR/d27
1436         mcreate $DIR/f27l || error "creating file"
1437         $RUNAS $SETSTRIPE -c 1 $DIR/f27l && \
1438                 error "setstripe should have failed" || true
1439 }
1440 run_test 27l "check setstripe permissions (should return error)"
1441
1442 test_27m() {
1443         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
1444                 return
1445         if [[ $ORIGFREE -gt $MAXFREE ]]; then
1446                 skip "$ORIGFREE > $MAXFREE skipping out-of-space test on OST0"
1447                 return
1448         fi
1449         trap simple_cleanup_common EXIT
1450         test_mkdir -p $DIR/$tdir
1451         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_1
1452         dd if=/dev/zero of=$DIR/$tdir/f27m_1 bs=1024 count=$MAXFREE &&
1453                 error "dd should fill OST0"
1454         i=2
1455         while $SETSTRIPE -i 0 -c 1 $DIR/$tdir/f27m_$i; do
1456                 i=$((i + 1))
1457                 [ $i -gt 256 ] && break
1458         done
1459         i=$((i + 1))
1460         touch $DIR/$tdir/f27m_$i
1461         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1462                 error "OST0 was full but new created file still use it"
1463         i=$((i + 1))
1464         touch $DIR/$tdir/f27m_$i
1465         [ `$GETSTRIPE $DIR/$tdir/f27m_$i | grep -A 10 obdidx | awk '{print $1}'| grep -w "0"` ] &&
1466                 error "OST0 was full but new created file still use it"
1467         simple_cleanup_common
1468 }
1469 run_test 27m "create file while OST0 was full =================="
1470
1471 sleep_maxage() {
1472         local DELAY=$(do_facet $SINGLEMDS lctl get_param -n lov.*.qos_maxage | head -n 1 | awk '{print $1 * 2}')
1473         sleep $DELAY
1474 }
1475
1476 # OSCs keep a NOSPC flag that will be reset after ~5s (qos_maxage)
1477 # if the OST isn't full anymore.
1478 reset_enospc() {
1479         local OSTIDX=${1:-""}
1480
1481         local list=$(comma_list $(osts_nodes))
1482         [ "$OSTIDX" ] && list=$(facet_host ost$((OSTIDX + 1)))
1483
1484         do_nodes $list lctl set_param fail_loc=0
1485         sync    # initiate all OST_DESTROYs from MDS to OST
1486         sleep_maxage
1487 }
1488
1489 exhaust_precreations() {
1490         local OSTIDX=$1
1491         local FAILLOC=$2
1492         local FAILIDX=${3:-$OSTIDX}
1493         local ofacet=ost$((OSTIDX + 1))
1494
1495         test_mkdir -p -c1 $DIR/$tdir
1496         local mdtidx=$($LFS getstripe -M $DIR/$tdir)
1497         local mfacet=mds$((mdtidx + 1))
1498         echo OSTIDX=$OSTIDX MDTIDX=$mdtidx
1499
1500         local OST=$(ostname_from_index $OSTIDX)
1501
1502         # on the mdt's osc
1503         local mdtosc_proc1=$(get_mdtosc_proc_path $mfacet $OST)
1504         local last_id=$(do_facet $mfacet lctl get_param -n \
1505                         osc.$mdtosc_proc1.prealloc_last_id)
1506         local next_id=$(do_facet $mfacet lctl get_param -n \
1507                         osc.$mdtosc_proc1.prealloc_next_id)
1508
1509         local mdtosc_proc2=$(get_mdtosc_proc_path $mfacet)
1510         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1511
1512         test_mkdir -p $DIR/$tdir/${OST}
1513         $SETSTRIPE -i $OSTIDX -c 1 $DIR/$tdir/${OST}
1514 #define OBD_FAIL_OST_ENOSPC              0x215
1515         do_facet $ofacet lctl set_param fail_val=$FAILIDX fail_loc=0x215
1516         echo "Creating to objid $last_id on ost $OST..."
1517         createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1518         do_facet $mfacet lctl get_param osc.$mdtosc_proc2.prealloc*
1519         do_facet $ofacet lctl set_param fail_loc=$FAILLOC
1520         sleep_maxage
1521 }
1522
1523 exhaust_all_precreations() {
1524         local i
1525         for (( i=0; i < OSTCOUNT; i++ )) ; do
1526                 exhaust_precreations $i $1 -1
1527         done
1528 }
1529
1530 test_27n() {
1531         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1532         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1533         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1534         remote_ost_nodsh && skip "remote OST with nodsh" && return
1535
1536         reset_enospc
1537         rm -f $DIR/$tdir/$tfile
1538         exhaust_precreations 0 0x80000215
1539         $SETSTRIPE -c -1 $DIR/$tdir
1540         touch $DIR/$tdir/$tfile || error
1541         $GETSTRIPE $DIR/$tdir/$tfile
1542         reset_enospc
1543 }
1544 run_test 27n "create file with some full OSTs =================="
1545
1546 test_27o() {
1547         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1548         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1549         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1550         remote_ost_nodsh && skip "remote OST with nodsh" && return
1551
1552         reset_enospc
1553         rm -f $DIR/$tdir/$tfile
1554         exhaust_all_precreations 0x215
1555
1556         touch $DIR/$tdir/$tfile && error "able to create $DIR/$tdir/$tfile"
1557
1558         reset_enospc
1559         rm -rf $DIR/$tdir/*
1560 }
1561 run_test 27o "create file with all full OSTs (should error) ===="
1562
1563 test_27p() {
1564         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1565         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1566         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1567         remote_ost_nodsh && skip "remote OST with nodsh" && return
1568
1569         reset_enospc
1570         rm -f $DIR/$tdir/$tfile
1571         test_mkdir -p $DIR/$tdir
1572
1573         $MCREATE $DIR/$tdir/$tfile || error "mcreate failed"
1574         $TRUNCATE $DIR/$tdir/$tfile 80000000 || error "truncate failed"
1575         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1576
1577         exhaust_precreations 0 0x80000215
1578         echo foo >> $DIR/$tdir/$tfile || error "append failed"
1579         $CHECKSTAT -s 80000004 $DIR/$tdir/$tfile || error "checkstat failed"
1580         $GETSTRIPE $DIR/$tdir/$tfile
1581
1582         reset_enospc
1583 }
1584 run_test 27p "append to a truncated file with some full OSTs ==="
1585
1586 test_27q() {
1587         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1588         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1589         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1590         remote_ost_nodsh && skip "remote OST with nodsh" && return
1591
1592         reset_enospc
1593         rm -f $DIR/$tdir/$tfile
1594
1595         test_mkdir -p $DIR/$tdir
1596         $MCREATE $DIR/$tdir/$tfile || error "mcreate $DIR/$tdir/$tfile failed"
1597         $TRUNCATE $DIR/$tdir/$tfile 80000000 ||error "truncate $DIR/$tdir/$tfile failed"
1598         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat failed"
1599
1600         exhaust_all_precreations 0x215
1601
1602         echo foo >> $DIR/$tdir/$tfile && error "append succeeded"
1603         $CHECKSTAT -s 80000000 $DIR/$tdir/$tfile || error "checkstat 2 failed"
1604
1605         reset_enospc
1606 }
1607 run_test 27q "append to truncated file with all OSTs full (should error) ==="
1608
1609 test_27r() {
1610         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1611         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1612         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1613         remote_ost_nodsh && skip "remote OST with nodsh" && return
1614
1615         reset_enospc
1616         rm -f $DIR/$tdir/$tfile
1617         exhaust_precreations 0 0x80000215
1618
1619         $SETSTRIPE -i 0 -c 2 $DIR/$tdir/$tfile # && error
1620
1621         reset_enospc
1622 }
1623 run_test 27r "stripe file with some full OSTs (shouldn't LBUG) ="
1624
1625 test_27s() { # bug 10725
1626         test_mkdir -p $DIR/$tdir
1627         local stripe_size=$((4096 * 1024 * 1024))       # 2^32
1628         local stripe_count=0
1629         [ $OSTCOUNT -eq 1 ] || stripe_count=2
1630         $SETSTRIPE -S $stripe_size -c $stripe_count $DIR/$tdir &&
1631                 error "stripe width >= 2^32 succeeded" || true
1632
1633 }
1634 run_test 27s "lsm_xfersize overflow (should error) (bug 10725)"
1635
1636 test_27t() { # bug 10864
1637         WDIR=$(pwd)
1638         WLFS=$(which lfs)
1639         cd $DIR
1640         touch $tfile
1641         $WLFS getstripe $tfile
1642         cd $WDIR
1643 }
1644 run_test 27t "check that utils parse path correctly"
1645
1646 test_27u() { # bug 4900
1647         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1648         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1649         local index
1650         local list=$(comma_list $(mdts_nodes))
1651
1652 #define OBD_FAIL_MDS_OSC_PRECREATE      0x139
1653         do_nodes $list $LCTL set_param fail_loc=0x139
1654         test_mkdir -p $DIR/$tdir
1655         rm -rf $DIR/$tdir/*
1656         createmany -o $DIR/$tdir/t- 1000
1657         do_nodes $list $LCTL set_param fail_loc=0
1658
1659         TLOG=$DIR/$tfile.getstripe
1660         $GETSTRIPE $DIR/$tdir > $TLOG
1661         OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
1662         unlinkmany $DIR/$tdir/t- 1000
1663         [[ $OBJS -gt 0 ]] &&
1664                 error "$OBJS objects created on OST-0. See $TLOG" || pass
1665 }
1666 run_test 27u "skip object creation on OSC w/o objects =========="
1667
1668 test_27v() { # bug 4900
1669         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
1670         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1671         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1672         remote_ost_nodsh && skip "remote OST with nodsh" && return
1673
1674         exhaust_all_precreations 0x215
1675         reset_enospc
1676
1677         test_mkdir -p $DIR/$tdir
1678         $SETSTRIPE -c 1 $DIR/$tdir         # 1 stripe / file
1679
1680         touch $DIR/$tdir/$tfile
1681         #define OBD_FAIL_TGT_DELAY_PRECREATE     0x705
1682         # all except ost1
1683         for (( i=1; i < OSTCOUNT; i++ )); do
1684                 do_facet ost$i lctl set_param fail_loc=0x705
1685         done
1686         local START=`date +%s`
1687         createmany -o $DIR/$tdir/$tfile 32
1688
1689         local FINISH=`date +%s`
1690         local TIMEOUT=`lctl get_param -n timeout`
1691         local PROCESS=$((FINISH - START))
1692         [ $PROCESS -ge $((TIMEOUT / 2)) ] && \
1693                error "$FINISH - $START >= $TIMEOUT / 2"
1694         sleep $((TIMEOUT / 2 - PROCESS))
1695         reset_enospc
1696 }
1697 run_test 27v "skip object creation on slow OST ================="
1698
1699 test_27w() { # bug 10997
1700         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1701         $SETSTRIPE -S 65536 $DIR/$tdir/f0 || error "setstripe failed"
1702         [ $($GETSTRIPE -S $DIR/$tdir/f0) -ne 65536 ] &&
1703                 error "stripe size $size != 65536" || true
1704         [ $($GETSTRIPE -d $DIR/$tdir | grep -c "stripe_count") -ne 1 ] &&
1705                 error "$GETSTRIPE -d $DIR/$tdir failed" || true
1706 }
1707 run_test 27w "check $SETSTRIPE -S option"
1708
1709 test_27wa() {
1710         [[ $OSTCOUNT -lt 2 ]] &&
1711                 skip_env "skipping multiple stripe count/offset test" && return
1712
1713         test_mkdir -p $DIR/$tdir || error "mkdir failed"
1714         for i in $(seq 1 $OSTCOUNT); do
1715                 offset=$((i - 1))
1716                 $SETSTRIPE -c $i -i $offset $DIR/$tdir/f$i ||
1717                         error "setstripe -c $i -i $offset failed"
1718                 count=$($GETSTRIPE -c $DIR/$tdir/f$i)
1719                 index=$($GETSTRIPE -i $DIR/$tdir/f$i)
1720                 [ $count -ne $i ] && error "stripe count $count != $i" || true
1721                 [ $index -ne $offset ] &&
1722                         error "stripe offset $index != $offset" || true
1723         done
1724 }
1725 run_test 27wa "check $SETSTRIPE -c -i options"
1726
1727 test_27x() {
1728         remote_ost_nodsh && skip "remote OST with nodsh" && return
1729         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
1730         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1731         OFFSET=$(($OSTCOUNT - 1))
1732         OSTIDX=0
1733         local OST=$(ostname_from_index $OSTIDX)
1734
1735         test_mkdir -p $DIR/$tdir
1736         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe per file
1737         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 1
1738         sleep_maxage
1739         createmany -o $DIR/$tdir/$tfile $OSTCOUNT
1740         for i in `seq 0 $OFFSET`; do
1741                 [ `$GETSTRIPE $DIR/$tdir/$tfile$i | grep -A 10 obdidx | awk '{print $1}' | grep -w "$OSTIDX"` ] &&
1742                 error "OST0 was degraded but new created file still use it"
1743         done
1744         do_facet ost$((OSTIDX + 1)) lctl set_param -n obdfilter.$OST.degraded 0
1745 }
1746 run_test 27x "create files while OST0 is degraded"
1747
1748 test_27y() {
1749         [[ $OSTCOUNT -lt 2 ]] &&
1750                 skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1751         remote_mds_nodsh && skip "remote MDS with nodsh" && return
1752         remote_ost_nodsh && skip "remote OST with nodsh" && return
1753         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1754
1755         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1756         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1757             osc.$mdtosc.prealloc_last_id)
1758         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1759             osc.$mdtosc.prealloc_next_id)
1760         local fcount=$((last_id - next_id))
1761         [[ $fcount -eq 0 ]] && skip "not enough space on OST0" && return
1762         [[ $fcount -gt $OSTCOUNT ]] && fcount=$OSTCOUNT
1763
1764         local MDS_OSCS=$(do_facet $SINGLEMDS lctl dl |
1765                          awk '/[oO][sS][cC].*md[ts]/ { print $4 }')
1766         local OST_DEACTIVE_IDX=-1
1767         local OSC
1768         local OSTIDX
1769         local OST
1770
1771         for OSC in $MDS_OSCS; do
1772                 OST=$(osc_to_ost $OSC)
1773                 OSTIDX=$(index_from_ostuuid $OST)
1774                 if [ $OST_DEACTIVE_IDX == -1 ]; then
1775                         OST_DEACTIVE_IDX=$OSTIDX
1776                 fi
1777                 if [ $OSTIDX != $OST_DEACTIVE_IDX ]; then
1778                         echo $OSC "is Deactivated:"
1779                         do_facet $SINGLEMDS lctl --device  %$OSC deactivate
1780                 fi
1781         done
1782
1783         OSTIDX=$(index_from_ostuuid $OST)
1784         test_mkdir -p $DIR/$tdir
1785         $SETSTRIPE -c 1 $DIR/$tdir      # 1 stripe / file
1786
1787         for OSC in $MDS_OSCS; do
1788                 OST=$(osc_to_ost $OSC)
1789                 OSTIDX=$(index_from_ostuuid $OST)
1790                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1791                         echo $OST "is degraded:"
1792                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1793                                                 obdfilter.$OST.degraded=1
1794                 fi
1795         done
1796
1797         sleep_maxage
1798         createmany -o $DIR/$tdir/$tfile $fcount
1799
1800         for OSC in $MDS_OSCS; do
1801                 OST=$(osc_to_ost $OSC)
1802                 OSTIDX=$(index_from_ostuuid $OST)
1803                 if [ $OSTIDX == $OST_DEACTIVE_IDX ]; then
1804                         echo $OST "is recovered from degraded:"
1805                         do_facet ost$((OSTIDX+1)) lctl set_param -n \
1806                                                 obdfilter.$OST.degraded=0
1807                 else
1808                         do_facet $SINGLEMDS lctl --device %$OSC activate
1809                 fi
1810         done
1811
1812         # all osp devices get activated, hence -1 stripe count restored
1813         local stripecnt=0
1814
1815         # sleep 2*lod_qos_maxage seconds waiting for lod qos to notice osp
1816         # devices get activated.
1817         sleep_maxage
1818         $SETSTRIPE -c -1 $DIR/$tfile
1819         stripecnt=$($GETSTRIPE -c $DIR/$tfile)
1820         rm -f $DIR/$tfile
1821         [ $stripecnt -ne $OSTCOUNT ] &&
1822                 error "Of $OSTCOUNT OSTs, only $stripecnt is available"
1823         return 0
1824 }
1825 run_test 27y "create files while OST0 is degraded and the rest inactive"
1826
1827 check_seq_oid()
1828 {
1829         log "check file $1"
1830
1831         lmm_count=$($GETSTRIPE -c $1)
1832         lmm_seq=$($GETSTRIPE -v $1 | awk '/lmm_seq/ { print $2 }')
1833         lmm_oid=$($GETSTRIPE -v $1 | awk '/lmm_object_id/ { print $2 }')
1834
1835         local old_ifs="$IFS"
1836         IFS=$'[:]'
1837         fid=($($LFS path2fid $1))
1838         IFS="$old_ifs"
1839
1840         log "FID seq ${fid[1]}, oid ${fid[2]} ver ${fid[3]}"
1841         log "LOV seq $lmm_seq, oid $lmm_oid, count: $lmm_count"
1842
1843         # compare lmm_seq and lu_fid->f_seq
1844         [ $lmm_seq = ${fid[1]} ] || { error "SEQ mismatch"; return 1; }
1845         # compare lmm_object_id and lu_fid->oid
1846         [ $lmm_oid = ${fid[2]} ] || { error "OID mismatch"; return 2; }
1847
1848         # check the trusted.fid attribute of the OST objects of the file
1849         local have_obdidx=false
1850         local stripe_nr=0
1851         $GETSTRIPE $1 | while read obdidx oid hex seq; do
1852                 # skip lines up to and including "obdidx"
1853                 [ -z "$obdidx" ] && break
1854                 [ "$obdidx" = "obdidx" ] && have_obdidx=true && continue
1855                 $have_obdidx || continue
1856
1857                 local ost=$((obdidx + 1))
1858                 local dev=$(ostdevname $ost)
1859                 local oid_hex
1860
1861                 log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
1862
1863                 seq=$(echo $seq | sed -e "s/^0x//g")
1864                 if [ $seq == 0 ] || [ $(facet_fstype ost$ost) == zfs ]; then
1865                         oid_hex=$(echo $oid)
1866                 else
1867                         oid_hex=$(echo $hex | sed -e "s/^0x//g")
1868                 fi
1869                 local obj_file="O/$seq/d$((oid %32))/$oid_hex"
1870
1871                 local ff
1872                 #
1873                 # Don't unmount/remount the OSTs if we don't need to do that.
1874                 # LU-2577 changes filter_fid to be smaller, so debugfs needs
1875                 # update too, until that use mount/ll_decode_filter_fid/mount.
1876                 # Re-enable when debugfs will understand new filter_fid.
1877                 #
1878                 if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
1879                         ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
1880                                 $dev 2>/dev/null" | grep "parent=")
1881                 else
1882                         stop ost$ost
1883                         mount_fstype ost$ost
1884                         ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
1885                                 $(facet_mntpt ost$ost)/$obj_file)
1886                         unmount_fstype ost$ost
1887                         start ost$ost $dev $OST_MOUNT_OPTS
1888                 fi
1889
1890                 [ -z "$ff" ] && error "$obj_file: no filter_fid info"
1891
1892                 echo "$ff" | sed -e 's#.*objid=#got: objid=#'
1893
1894                 # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
1895                 # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
1896                 local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
1897                 local ff_pseq=$(echo $ff_parent | cut -d: -f1)
1898                 local ff_poid=$(echo $ff_parent | cut -d: -f2)
1899                 local ff_pstripe
1900                 if echo $ff_parent | grep -q 'stripe='; then
1901                         ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
1902                 else
1903                         #
1904                         # $LL_DECODE_FILTER_FID does not print "stripe="; look
1905                         # into f_ver in this case.  See the comment on
1906                         # ff_parent.
1907                         #
1908                         ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
1909                                 sed -e 's/\]//')
1910                 fi
1911
1912                 # compare lmm_seq and filter_fid->ff_parent.f_seq
1913                 [ $ff_pseq = $lmm_seq ] ||
1914                         error "FF parent SEQ $ff_pseq != $lmm_seq"
1915                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
1916                 [ $ff_poid = $lmm_oid ] ||
1917                         error "FF parent OID $ff_poid != $lmm_oid"
1918                 (($ff_pstripe == $stripe_nr)) ||
1919                         error "FF stripe $ff_pstripe != $stripe_nr"
1920
1921                 stripe_nr=$((stripe_nr + 1))
1922         done
1923 }
1924
1925 test_27z() {
1926         remote_ost_nodsh && skip "remote OST with nodsh" && return
1927         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1928         test_mkdir -p $DIR/$tdir
1929
1930         $SETSTRIPE -c 1 -i 0 -S 64k $DIR/$tdir/$tfile-1 ||
1931                 { error "setstripe -c -1 failed"; return 1; }
1932         # We need to send a write to every object to get parent FID info set.
1933         # This _should_ also work for setattr, but does not currently.
1934         # touch $DIR/$tdir/$tfile-1 ||
1935         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=1M count=1 ||
1936                 { error "dd $tfile-1 failed"; return 2; }
1937         $SETSTRIPE -c -1 -i $((OSTCOUNT - 1)) -S 1M $DIR/$tdir/$tfile-2 ||
1938                 { error "setstripe -c -1 failed"; return 3; }
1939         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=1M count=$OSTCOUNT ||
1940                 { error "dd $tfile-2 failed"; return 4; }
1941
1942         # make sure write RPCs have been sent to OSTs
1943         sync; sleep 5; sync
1944
1945         check_seq_oid $DIR/$tdir/$tfile-1 || return 5
1946         check_seq_oid $DIR/$tdir/$tfile-2 || return 6
1947 }
1948 run_test 27z "check SEQ/OID on the MDT and OST filesystems"
1949
1950 test_27A() { # b=19102
1951         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
1952         local restore_size=$($GETSTRIPE -S $MOUNT)
1953         local restore_count=$($GETSTRIPE -c $MOUNT)
1954         local restore_offset=$($GETSTRIPE -i $MOUNT)
1955         $SETSTRIPE -c 0 -i -1 -S 0 $MOUNT
1956         wait_update $HOSTNAME "$GETSTRIPE -c $MOUNT | sed 's/  *//g'" "1" 20 ||
1957                 error "stripe count $($GETSTRIPE -c $MOUNT) != 1"
1958         local default_size=$($GETSTRIPE -S $MOUNT)
1959         local default_offset=$($GETSTRIPE -i $MOUNT)
1960         local dsize=$((1024 * 1024))
1961         [ $default_size -eq $dsize ] ||
1962                 error "stripe size $default_size != $dsize"
1963         [ $default_offset -eq -1 ] ||error "stripe offset $default_offset != -1"
1964         $SETSTRIPE -c $restore_count -i $restore_offset -S $restore_size $MOUNT
1965 }
1966 run_test 27A "check filesystem-wide default LOV EA values"
1967
1968 test_27B() { # LU-2523
1969         test_mkdir -p $DIR/$tdir
1970         rm -f $DIR/$tdir/f0 $DIR/$tdir/f1
1971         touch $DIR/$tdir/f0
1972         # open f1 with O_LOV_DELAY_CREATE
1973         # rename f0 onto f1
1974         # call setstripe ioctl on open file descriptor for f1
1975         # close
1976         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:nB1c \
1977                 $DIR/$tdir/f0
1978
1979         rm -f $DIR/$tdir/f1
1980         # open f1 with O_LOV_DELAY_CREATE
1981         # unlink f1
1982         # call setstripe ioctl on open file descriptor for f1
1983         # close
1984         multiop $DIR/$tdir/f1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:uB1c
1985
1986         # Allow multiop to fail in imitation of NFS's busted semantics.
1987         true
1988 }
1989 run_test 27B "call setstripe on open unlinked file/rename victim"
1990
1991 test_27C() { #LU-2871
1992         [[ $OSTCOUNT -lt 2 ]] && skip "needs >= 2 OSTs" && return
1993
1994         declare -a ost_idx
1995         local index
1996         local found
1997         local i
1998         local j
1999
2000         test_mkdir -p $DIR/$tdir
2001         cd $DIR/$tdir
2002         for i in $(seq 0 $((OSTCOUNT - 1))); do
2003                 # set stripe across all OSTs starting from OST$i
2004                 $SETSTRIPE -i $i -c -1 $tfile$i
2005                 # get striping information
2006                 ost_idx=($($GETSTRIPE $tfile$i |
2007                          tail -n $((OSTCOUNT + 1)) | awk '{print $1}'))
2008                 echo ${ost_idx[@]}
2009
2010                 # check the layout
2011                 [ ${#ost_idx[@]} -eq $OSTCOUNT ] ||
2012                         error "${#ost_idx[@]} != $OSTCOUNT"
2013
2014                 for index in $(seq 0 $((OSTCOUNT - 1))); do
2015                         found=0
2016                         for j in $(echo ${ost_idx[@]}); do
2017                                 if [ $index -eq $j ]; then
2018                                         found=1
2019                                         break
2020                                 fi
2021                         done
2022                         [ $found = 1 ] ||
2023                                 error "Can not find $index in ${ost_idx[@]}"
2024                 done
2025         done
2026 }
2027 run_test 27C "check full striping across all OSTs"
2028
2029 test_27D() {
2030         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2031         local POOL=${POOL:-testpool}
2032         local first_ost=0
2033         local last_ost=$(($OSTCOUNT - 1))
2034         local ost_step=1
2035         local ost_list=$(seq $first_ost $ost_step $last_ost)
2036         local ost_range="$first_ost $last_ost $ost_step"
2037
2038         test_mkdir -p $DIR/$tdir
2039         pool_add $POOL || error "pool_add failed"
2040         pool_add_targets $POOL $ost_range || error "pool_add_targets failed"
2041         llapi_layout_test -d$DIR/$tdir -p$POOL -o$OSTCOUNT ||
2042                 error "llapi_layout_test failed"
2043         cleanup_pools || error "cleanup_pools failed"
2044 }
2045 run_test 27D "validate llapi_layout API"
2046
2047 # Verify that default_easize is increased from its initial value after
2048 # accessing a widely striped file.
2049 test_27E() {
2050         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
2051
2052         # 72 bytes is the minimum space required to store striping
2053         # information for a file striped across one OST:
2054         # (sizeof(struct lov_user_md_v3) +
2055         #  sizeof(struct lov_user_ost_data_v1))
2056         local min_easize=72
2057         $LCTL set_param -n llite.*.default_easize $min_easize ||
2058                 error "lctl set_param failed"
2059         local easize=$($LCTL get_param -n llite.*.default_easize)
2060
2061         [ $easize -eq $min_easize ] ||
2062                 error "failed to set default_easize"
2063
2064         $LFS setstripe -c $OSTCOUNT $DIR/$tfile ||
2065                 error "setstripe failed"
2066         cat $DIR/$tfile
2067         rm $DIR/$tfile
2068
2069         easize=$($LCTL get_param -n llite.*.default_easize)
2070
2071         [ $easize -gt $min_easize ] ||
2072                 error "default_easize not updated"
2073 }
2074 run_test 27E "check that default extended attribute size properly increases"
2075
2076 # createtest also checks that device nodes are created and
2077 # then visible correctly (#2091)
2078 test_28() { # bug 2091
2079         test_mkdir $DIR/d28
2080         $CREATETEST $DIR/d28/ct || error
2081 }
2082 run_test 28 "create/mknod/mkdir with bad file types ============"
2083
2084 test_29() {
2085         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2086         cancel_lru_locks mdc
2087         test_mkdir $DIR/d29
2088         touch $DIR/d29/foo
2089         log 'first d29'
2090         ls -l $DIR/d29
2091
2092         declare -i LOCKCOUNTORIG=0
2093         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2094                 let LOCKCOUNTORIG=$LOCKCOUNTORIG+$lock_count
2095         done
2096         [ $LOCKCOUNTORIG -eq 0 ] && echo "No mdc lock count" && return 1
2097
2098         declare -i LOCKUNUSEDCOUNTORIG=0
2099         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2100                 let LOCKUNUSEDCOUNTORIG=$LOCKUNUSEDCOUNTORIG+$unused_count
2101         done
2102
2103         log 'second d29'
2104         ls -l $DIR/d29
2105         log 'done'
2106
2107         declare -i LOCKCOUNTCURRENT=0
2108         for lock_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_count); do
2109                 let LOCKCOUNTCURRENT=$LOCKCOUNTCURRENT+$lock_count
2110         done
2111
2112         declare -i LOCKUNUSEDCOUNTCURRENT=0
2113         for unused_count in $(lctl get_param -n ldlm.namespaces.*mdc*.lock_unused_count); do
2114                 let LOCKUNUSEDCOUNTCURRENT=$LOCKUNUSEDCOUNTCURRENT+$unused_count
2115         done
2116
2117         if [[ $LOCKCOUNTCURRENT -gt $LOCKCOUNTORIG ]]; then
2118                 $LCTL set_param -n ldlm.dump_namespaces ""
2119                 error "CURRENT: $LOCKCOUNTCURRENT > $LOCKCOUNTORIG"
2120                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2121                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2122                 return 2
2123         fi
2124         if [[ $LOCKUNUSEDCOUNTCURRENT -gt $LOCKUNUSEDCOUNTORIG ]]; then
2125                 error "UNUSED: $LOCKUNUSEDCOUNTCURRENT > $LOCKUNUSEDCOUNTORIG"
2126                 $LCTL dk | sort -k4 -t: > $TMP/test_29.dk
2127                 log "dumped log to $TMP/test_29.dk (bug 5793)"
2128                 return 3
2129         fi
2130 }
2131 run_test 29 "IT_GETATTR regression  ============================"
2132
2133 test_30a() { # was test_30
2134         cp $(which ls) $DIR || cp /bin/ls $DIR
2135         $DIR/ls / || error
2136         rm $DIR/ls
2137 }
2138 run_test 30a "execute binary from Lustre (execve) =============="
2139
2140 test_30b() {
2141         cp `which ls` $DIR || cp /bin/ls $DIR
2142         chmod go+rx $DIR/ls
2143         $RUNAS $DIR/ls / || error
2144         rm $DIR/ls
2145 }
2146 run_test 30b "execute binary from Lustre as non-root ==========="
2147
2148 test_30c() { # b=22376
2149         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2150         cp `which ls` $DIR || cp /bin/ls $DIR
2151         chmod a-rw $DIR/ls
2152         cancel_lru_locks mdc
2153         cancel_lru_locks osc
2154         $RUNAS $DIR/ls / || error
2155         rm -f $DIR/ls
2156 }
2157 run_test 30c "execute binary from Lustre without read perms ===="
2158
2159 test_31a() {
2160         $OPENUNLINK $DIR/f31 $DIR/f31 || error
2161         $CHECKSTAT -a $DIR/f31 || error
2162 }
2163 run_test 31a "open-unlink file =================================="
2164
2165 test_31b() {
2166         touch $DIR/f31 || error
2167         ln $DIR/f31 $DIR/f31b || error
2168         $MULTIOP $DIR/f31b Ouc || error
2169         $CHECKSTAT -t file $DIR/f31 || error
2170 }
2171 run_test 31b "unlink file with multiple links while open ======="
2172
2173 test_31c() {
2174         touch $DIR/f31 || error
2175         ln $DIR/f31 $DIR/f31c || error
2176         multiop_bg_pause $DIR/f31 O_uc || return 1
2177         MULTIPID=$!
2178         $MULTIOP $DIR/f31c Ouc
2179         kill -USR1 $MULTIPID
2180         wait $MULTIPID
2181 }
2182 run_test 31c "open-unlink file with multiple links ============="
2183
2184 test_31d() {
2185         opendirunlink $DIR/d31d $DIR/d31d || error
2186         $CHECKSTAT -a $DIR/d31d || error
2187 }
2188 run_test 31d "remove of open directory ========================="
2189
2190 test_31e() { # bug 2904
2191         openfilleddirunlink $DIR/d31e || error
2192 }
2193 run_test 31e "remove of open non-empty directory ==============="
2194
2195 test_31f() { # bug 4554
2196         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2197         set -vx
2198         test_mkdir $DIR/d31f
2199         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2200         cp /etc/hosts $DIR/d31f
2201         ls -l $DIR/d31f
2202         $GETSTRIPE $DIR/d31f/hosts
2203         multiop_bg_pause $DIR/d31f D_c || return 1
2204         MULTIPID=$!
2205
2206         rm -rv $DIR/d31f || error "first of $DIR/d31f"
2207         test_mkdir $DIR/d31f
2208         $SETSTRIPE -S 1048576 -c 1 $DIR/d31f
2209         cp /etc/hosts $DIR/d31f
2210         ls -l $DIR/d31f
2211         $GETSTRIPE $DIR/d31f/hosts
2212         multiop_bg_pause $DIR/d31f D_c || return 1
2213         MULTIPID2=$!
2214
2215         kill -USR1 $MULTIPID || error "first opendir $MULTIPID not running"
2216         wait $MULTIPID || error "first opendir $MULTIPID failed"
2217
2218         sleep 6
2219
2220         kill -USR1 $MULTIPID2 || error "second opendir $MULTIPID not running"
2221         wait $MULTIPID2 || error "second opendir $MULTIPID2 failed"
2222         set +vx
2223 }
2224 run_test 31f "remove of open directory with open-unlink file ==="
2225
2226 test_31g() {
2227         echo "-- cross directory link --"
2228         test_mkdir -c1 $DIR/${tdir}ga
2229         test_mkdir -c1 $DIR/${tdir}gb
2230         touch $DIR/${tdir}ga/f
2231         ln $DIR/${tdir}ga/f $DIR/${tdir}gb/g
2232         $CHECKSTAT -t file $DIR/${tdir}ga/f || error "source"
2233         [ `stat -c%h $DIR/${tdir}ga/f` == '2' ] || error "source nlink"
2234         $CHECKSTAT -t file $DIR/${tdir}gb/g || error "target"
2235         [ `stat -c%h $DIR/${tdir}gb/g` == '2' ] || error "target nlink"
2236 }
2237 run_test 31g "cross directory link==============="
2238
2239 test_31h() {
2240         echo "-- cross directory link --"
2241         test_mkdir -c1 $DIR/${tdir}
2242         test_mkdir -c1 $DIR/${tdir}/dir
2243         touch $DIR/${tdir}/f
2244         ln $DIR/${tdir}/f $DIR/${tdir}/dir/g
2245         $CHECKSTAT -t file $DIR/${tdir}/f || error "source"
2246         [ `stat -c%h $DIR/${tdir}/f` == '2' ] || error "source nlink"
2247         $CHECKSTAT -t file $DIR/${tdir}/dir/g || error "target"
2248         [ `stat -c%h $DIR/${tdir}/dir/g` == '2' ] || error "target nlink"
2249 }
2250 run_test 31h "cross directory link under child==============="
2251
2252 test_31i() {
2253         echo "-- cross directory link --"
2254         test_mkdir -c1 $DIR/$tdir
2255         test_mkdir -c1 $DIR/$tdir/dir
2256         touch $DIR/$tdir/dir/f
2257         ln $DIR/$tdir/dir/f $DIR/$tdir/g
2258         $CHECKSTAT -t file $DIR/$tdir/dir/f || error "source"
2259         [ `stat -c%h $DIR/$tdir/dir/f` == '2' ] || error "source nlink"
2260         $CHECKSTAT -t file $DIR/$tdir/g || error "target"
2261         [ `stat -c%h $DIR/$tdir/g` == '2' ] || error "target nlink"
2262 }
2263 run_test 31i "cross directory link under parent==============="
2264
2265 test_31j() {
2266         test_mkdir -c1 -p $DIR/$tdir
2267         test_mkdir -c1 -p $DIR/$tdir/dir1
2268         ln $DIR/$tdir/dir1 $DIR/$tdir/dir2 && error "ln for dir"
2269         link $DIR/$tdir/dir1 $DIR/$tdir/dir3 && error "link for dir"
2270         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir4 && error "mlink for dir"
2271         mlink $DIR/$tdir/dir1 $DIR/$tdir/dir1 && error "mlink to the same dir"
2272         return 0
2273 }
2274 run_test 31j "link for directory==============="
2275
2276 test_31k() {
2277         test_mkdir -c1 -p $DIR/$tdir
2278         touch $DIR/$tdir/s
2279         touch $DIR/$tdir/exist
2280         mlink $DIR/$tdir/s $DIR/$tdir/t || error "mlink"
2281         mlink $DIR/$tdir/s $DIR/$tdir/exist && error "mlink to exist file"
2282         mlink $DIR/$tdir/s $DIR/$tdir/s && error "mlink to the same file"
2283         mlink $DIR/$tdir/s $DIR/$tdir && error "mlink to parent dir"
2284         mlink $DIR/$tdir $DIR/$tdir/s && error "mlink parent dir to target"
2285         mlink $DIR/$tdir/not-exist $DIR/$tdir/foo && error "mlink non-existing to new"
2286         mlink $DIR/$tdir/not-exist $DIR/$tdir/s && error "mlink non-existing to exist"
2287         return 0
2288 }
2289 run_test 31k "link to file: the same, non-existing, dir==============="
2290
2291 test_31m() {
2292         mkdir $DIR/d31m
2293         touch $DIR/d31m/s
2294         mkdir $DIR/d31m2
2295         touch $DIR/d31m2/exist
2296         mlink $DIR/d31m/s $DIR/d31m2/t || error "mlink"
2297         mlink $DIR/d31m/s $DIR/d31m2/exist && error "mlink to exist file"
2298         mlink $DIR/d31m/s $DIR/d31m2 && error "mlink to parent dir"
2299         mlink $DIR/d31m2 $DIR/d31m/s && error "mlink parent dir to target"
2300         mlink $DIR/d31m/not-exist $DIR/d31m2/foo && error "mlink non-existing to new"
2301         mlink $DIR/d31m/not-exist $DIR/d31m2/s && error "mlink non-existing to exist"
2302         return 0
2303 }
2304 run_test 31m "link to file: the same, non-existing, dir==============="
2305
2306 test_31n() {
2307         touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
2308         nlink=$(stat --format=%h $DIR/$tfile)
2309         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2310         local fd=$(free_fd)
2311         local cmd="exec $fd<$DIR/$tfile"
2312         eval $cmd
2313         cmd="exec $fd<&-"
2314         trap "eval $cmd" EXIT
2315         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2316         [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
2317         rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
2318         nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
2319         [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
2320         eval $cmd
2321 }
2322 run_test 31n "check link count of unlinked file"
2323
2324 link_one() {
2325         local TEMPNAME=$(mktemp $1_XXXXXX)
2326         mlink $TEMPNAME $1 2> /dev/null &&
2327                 echo "$BASHPID: link $TEMPNAME to $1 succeeded"
2328         munlink $TEMPNAME
2329 }
2330
2331 test_31o() { # LU-2901
2332         test_mkdir -p $DIR/$tdir
2333         for LOOP in $(seq 100); do
2334                 rm -f $DIR/$tdir/$tfile*
2335                 for THREAD in $(seq 8); do
2336                         link_one $DIR/$tdir/$tfile.$LOOP &
2337                 done
2338                 wait
2339                 local LINKS=$(ls -1 $DIR/$tdir | grep -c $tfile.$LOOP)
2340                 [[ $LINKS -gt 1 ]] && ls $DIR/$tdir &&
2341                         error "$LINKS duplicate links to $tfile.$LOOP" &&
2342                         break || true
2343         done
2344 }
2345 run_test 31o "duplicate hard links with same filename"
2346
2347 test_31p() {
2348         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2349
2350         test_mkdir $DIR/$tdir
2351         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2352         $LFS setdirstripe -D -c2 -t all_char $DIR/$tdir/striped_dir
2353
2354         opendirunlink $DIR/$tdir/striped_dir/test1 ||
2355                 error "open unlink test1 failed"
2356         opendirunlink $DIR/$tdir/striped_dir/test2 ||
2357                 error "open unlink test2 failed"
2358
2359         $CHECKSTAT -a $DIR/$tdir/striped_dir/test1 ||
2360                 error "test1 still exists"
2361         $CHECKSTAT -a $DIR/$tdir/striped_dir/test2 ||
2362                 error "test2 still exists"
2363 }
2364 run_test 31p "remove of open striped directory"
2365
2366 cleanup_test32_mount() {
2367         trap 0
2368         $UMOUNT $DIR/$tdir/ext2-mountpoint
2369 }
2370
2371 test_32a() {
2372         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2373         echo "== more mountpoints and symlinks ================="
2374         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2375         trap cleanup_test32_mount EXIT
2376         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2377         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2378         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/.. || error
2379         cleanup_test32_mount
2380 }
2381 run_test 32a "stat d32a/ext2-mountpoint/.. ====================="
2382
2383 test_32b() {
2384         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2385         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2386         trap cleanup_test32_mount EXIT
2387         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2388         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2389         ls -al $DIR/$tdir/ext2-mountpoint/.. || error
2390         cleanup_test32_mount
2391 }
2392 run_test 32b "open d32b/ext2-mountpoint/.. ====================="
2393
2394 test_32c() {
2395         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2396         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2397         trap cleanup_test32_mount EXIT
2398         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2399         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2400         test_mkdir -p $DIR/$tdir/d2/test_dir
2401         $CHECKSTAT -t dir $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2402         cleanup_test32_mount
2403 }
2404 run_test 32c "stat d32c/ext2-mountpoint/../d2/test_dir ========="
2405
2406 test_32d() {
2407         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2408         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2409         trap cleanup_test32_mount EXIT
2410         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2411         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2412         test_mkdir -p $DIR/$tdir/d2/test_dir
2413         ls -al $DIR/$tdir/ext2-mountpoint/../d2/test_dir || error
2414         cleanup_test32_mount
2415 }
2416 run_test 32d "open d32d/ext2-mountpoint/../d2/test_dir ========="
2417
2418 test_32e() {
2419         [ -e $DIR/d32e ] && rm -fr $DIR/d32e
2420         test_mkdir -p $DIR/d32e/tmp
2421         TMP_DIR=$DIR/d32e/tmp
2422         ln -s $DIR/d32e $TMP_DIR/symlink11
2423         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2424         $CHECKSTAT -t link $DIR/d32e/tmp/symlink11 || error
2425         $CHECKSTAT -t link $DIR/d32e/symlink01 || error
2426 }
2427 run_test 32e "stat d32e/symlink->tmp/symlink->lustre-subdir ===="
2428
2429 test_32f() {
2430         [ -e $DIR/d32f ] && rm -fr $DIR/d32f
2431         test_mkdir -p $DIR/d32f/tmp
2432         TMP_DIR=$DIR/d32f/tmp
2433         ln -s $DIR/d32f $TMP_DIR/symlink11
2434         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2435         ls $DIR/d32f/tmp/symlink11  || error
2436         ls $DIR/d32f/symlink01 || error
2437 }
2438 run_test 32f "open d32f/symlink->tmp/symlink->lustre-subdir ===="
2439
2440 test_32g() {
2441         TMP_DIR=$DIR/$tdir/tmp
2442         test_mkdir -p $DIR/$tdir/tmp
2443         test_mkdir $DIR/${tdir}2
2444         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2445         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2446         $CHECKSTAT -t link $TMP_DIR/symlink12 || error
2447         $CHECKSTAT -t link $DIR/$tdir/symlink02 || error
2448         $CHECKSTAT -t dir -f $TMP_DIR/symlink12 || error
2449         $CHECKSTAT -t dir -f $DIR/$tdir/symlink02 || error
2450 }
2451 run_test 32g "stat d32g/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2452
2453 test_32h() {
2454         rm -fr $DIR/$tdir $DIR/${tdir}2
2455         TMP_DIR=$DIR/$tdir/tmp
2456         test_mkdir -p $DIR/$tdir/tmp
2457         test_mkdir $DIR/${tdir}2
2458         ln -s $DIR/${tdir}2 $TMP_DIR/symlink12
2459         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2460         ls $TMP_DIR/symlink12 || error
2461         ls $DIR/$tdir/symlink02  || error
2462 }
2463 run_test 32h "open d32h/symlink->tmp/symlink->lustre-subdir/${tdir}2"
2464
2465 test_32i() {
2466         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2467         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2468         trap cleanup_test32_mount EXIT
2469         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2470         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2471         touch $DIR/$tdir/test_file
2472         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../test_file || error
2473         cleanup_test32_mount
2474 }
2475 run_test 32i "stat d32i/ext2-mountpoint/../test_file ==========="
2476
2477 test_32j() {
2478         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2479         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2480         trap cleanup_test32_mount EXIT
2481         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2482         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2483         touch $DIR/$tdir/test_file
2484         cat $DIR/$tdir/ext2-mountpoint/../test_file || error
2485         cleanup_test32_mount
2486 }
2487 run_test 32j "open d32j/ext2-mountpoint/../test_file ==========="
2488
2489 test_32k() {
2490         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2491         rm -fr $DIR/$tdir
2492         trap cleanup_test32_mount EXIT
2493         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2494         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint
2495         test_mkdir -p $DIR/$tdir/d2
2496         touch $DIR/$tdir/d2/test_file || error
2497         $CHECKSTAT -t file $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2498         cleanup_test32_mount
2499 }
2500 run_test 32k "stat d32k/ext2-mountpoint/../d2/test_file ========"
2501
2502 test_32l() {
2503         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2504         rm -fr $DIR/$tdir
2505         trap cleanup_test32_mount EXIT
2506         test_mkdir -p $DIR/$tdir/ext2-mountpoint
2507         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir/ext2-mountpoint || error
2508         test_mkdir -p $DIR/$tdir/d2
2509         touch $DIR/$tdir/d2/test_file
2510         cat  $DIR/$tdir/ext2-mountpoint/../d2/test_file || error
2511         cleanup_test32_mount
2512 }
2513 run_test 32l "open d32l/ext2-mountpoint/../d2/test_file ========"
2514
2515 test_32m() {
2516         rm -fr $DIR/d32m
2517         test_mkdir -p $DIR/d32m/tmp
2518         TMP_DIR=$DIR/d32m/tmp
2519         ln -s $DIR $TMP_DIR/symlink11
2520         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2521         $CHECKSTAT -t link $DIR/d32m/tmp/symlink11 || error
2522         $CHECKSTAT -t link $DIR/d32m/symlink01 || error
2523 }
2524 run_test 32m "stat d32m/symlink->tmp/symlink->lustre-root ======"
2525
2526 test_32n() {
2527         rm -fr $DIR/d32n
2528         test_mkdir -p $DIR/d32n/tmp
2529         TMP_DIR=$DIR/d32n/tmp
2530         ln -s $DIR $TMP_DIR/symlink11
2531         ln -s $TMP_DIR/symlink11 $TMP_DIR/../symlink01
2532         ls -l $DIR/d32n/tmp/symlink11  || error
2533         ls -l $DIR/d32n/symlink01 || error
2534 }
2535 run_test 32n "open d32n/symlink->tmp/symlink->lustre-root ======"
2536
2537 test_32o() {
2538         touch $DIR/$tfile
2539         test_mkdir -p $DIR/d32o/tmp
2540         TMP_DIR=$DIR/d32o/tmp
2541         ln -s $DIR/$tfile $TMP_DIR/symlink12
2542         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2543         $CHECKSTAT -t link $DIR/d32o/tmp/symlink12 || error
2544         $CHECKSTAT -t link $DIR/d32o/symlink02 || error
2545         $CHECKSTAT -t file -f $DIR/d32o/tmp/symlink12 || error
2546         $CHECKSTAT -t file -f $DIR/d32o/symlink02 || error
2547 }
2548 run_test 32o "stat d32o/symlink->tmp/symlink->lustre-root/$tfile"
2549
2550 test_32p() {
2551     log 32p_1
2552         rm -fr $DIR/d32p
2553     log 32p_2
2554         rm -f $DIR/$tfile
2555     log 32p_3
2556         touch $DIR/$tfile
2557     log 32p_4
2558         test_mkdir -p $DIR/d32p/tmp
2559     log 32p_5
2560         TMP_DIR=$DIR/d32p/tmp
2561     log 32p_6
2562         ln -s $DIR/$tfile $TMP_DIR/symlink12
2563     log 32p_7
2564         ln -s $TMP_DIR/symlink12 $TMP_DIR/../symlink02
2565     log 32p_8
2566         cat $DIR/d32p/tmp/symlink12 || error
2567     log 32p_9
2568         cat $DIR/d32p/symlink02 || error
2569     log 32p_10
2570 }
2571 run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
2572
2573 cleanup_testdir_mount() {
2574         trap 0
2575         $UMOUNT $DIR/$tdir
2576 }
2577
2578 test_32q() {
2579         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2580         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2581         trap cleanup_testdir_mount EXIT
2582         test_mkdir -p $DIR/$tdir
2583         touch $DIR/$tdir/under_the_mount
2584         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2585         ls $DIR/$tdir | grep "\<under_the_mount\>" && error
2586         cleanup_testdir_mount
2587 }
2588 run_test 32q "stat follows mountpoints in Lustre (should return error)"
2589
2590 test_32r() {
2591         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2592         [ -e $DIR/$tdir ] && rm -fr $DIR/$tdir
2593         trap cleanup_testdir_mount EXIT
2594         test_mkdir -p $DIR/$tdir
2595         touch $DIR/$tdir/under_the_mount
2596         mount -t ext2 -o loop $EXT2_DEV $DIR/$tdir
2597         ls $DIR/$tdir | grep -q under_the_mount && error || true
2598         cleanup_testdir_mount
2599 }
2600 run_test 32r "opendir follows mountpoints in Lustre (should return error)"
2601
2602 test_33aa() {
2603         rm -f $DIR/$tfile
2604         touch $DIR/$tfile
2605         chmod 444 $DIR/$tfile
2606         chown $RUNAS_ID $DIR/$tfile
2607         log 33_1
2608         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2609         log 33_2
2610 }
2611 run_test 33aa "write file with mode 444 (should return error) ===="
2612
2613 test_33a() {
2614         rm -fr $DIR/d33
2615         test_mkdir -p $DIR/d33
2616         chown $RUNAS_ID $DIR/d33
2617         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33|| error "create"
2618         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $DIR/d33/f33 && \
2619                 error "open RDWR" || true
2620 }
2621 run_test 33a "test open file(mode=0444) with O_RDWR (should return error)"
2622
2623 test_33b() {
2624         rm -fr $DIR/d33
2625         test_mkdir -p $DIR/d33
2626         chown $RUNAS_ID $DIR/d33
2627         $RUNAS $OPENFILE -f 1286739555 $DIR/d33/f33 || true
2628 }
2629 run_test 33b "test open file with malformed flags (No panic)"
2630
2631 test_33c() {
2632         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2633         local ostnum
2634         local ostname
2635         local write_bytes
2636         local all_zeros
2637
2638         remote_ost_nodsh && skip "remote OST with nodsh" && return
2639         all_zeros=:
2640         rm -fr $DIR/d33
2641         test_mkdir -p $DIR/d33
2642         # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
2643
2644         sync
2645         for ostnum in $(seq $OSTCOUNT); do
2646                 # test-framework's OST numbering is one-based, while Lustre's
2647                 # is zero-based
2648                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2649                 # Parsing llobdstat's output sucks; we could grep the /proc
2650                 # path, but that's likely to not be as portable as using the
2651                 # llobdstat utility.  So we parse lctl output instead.
2652                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2653                         obdfilter/$ostname/stats |
2654                         awk '/^write_bytes/ {print $7}' )
2655                 echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
2656                 if (( ${write_bytes:-0} > 0 ))
2657                 then
2658                         all_zeros=false
2659                         break;
2660                 fi
2661         done
2662
2663         $all_zeros || return 0
2664
2665         # Write four bytes
2666         echo foo > $DIR/d33/bar
2667         # Really write them
2668         sync
2669
2670         # Total up write_bytes after writing.  We'd better find non-zeros.
2671         for ostnum in $(seq $OSTCOUNT); do
2672                 ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2673                 write_bytes=$(do_facet ost$ostnum lctl get_param -n \
2674                         obdfilter/$ostname/stats |
2675                         awk '/^write_bytes/ {print $7}' )
2676                 echo "write_bytes@$OSTnum/$ostname=$write_bytes"
2677                 if (( ${write_bytes:-0} > 0 ))
2678                 then
2679                         all_zeros=false
2680                         break;
2681                 fi
2682         done
2683
2684         if $all_zeros
2685         then
2686                 for ostnum in $(seq $OSTCOUNT); do
2687                         ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
2688                         echo "Check that write_bytes is present in obdfilter/*/stats:"
2689                         do_facet ost$ostnum lctl get_param -n \
2690                                 obdfilter/$ostname/stats
2691                 done
2692                 error "OST not keeping write_bytes stats (b22312)"
2693         fi
2694 }
2695 run_test 33c "test llobdstat and write_bytes"
2696
2697 test_33d() {
2698         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
2699         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2700         local MDTIDX=1
2701         local remote_dir=$DIR/$tdir/remote_dir
2702
2703         test_mkdir -p $DIR/$tdir
2704         $LFS mkdir -i $MDTIDX $remote_dir ||
2705                 error "create remote directory failed"
2706
2707         touch $remote_dir/$tfile
2708         chmod 444 $remote_dir/$tfile
2709         chown $RUNAS_ID $remote_dir/$tfile
2710
2711         $RUNAS $OPENFILE -f O_RDWR $DIR/$tfile && error || true
2712
2713         chown $RUNAS_ID $remote_dir
2714         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 ||
2715                                         error "create" || true
2716         $RUNAS $OPENFILE -f O_RDWR:O_CREAT -m 0444 $remote_dir/f33 &&
2717                                     error "open RDWR" || true
2718         $RUNAS $OPENFILE -f 1286739555 $remote_dir/f33 || true
2719 }
2720 run_test 33d "openfile with 444 modes and malformed flags under remote dir"
2721
2722 test_33e() {
2723         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2724
2725         mkdir $DIR/$tdir
2726
2727         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2728         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2729         mkdir $DIR/$tdir/local_dir
2730
2731         local s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2732         local s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2733         local l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2734
2735         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2736                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode"
2737
2738         rmdir $DIR/$tdir/* || error "rmdir failed"
2739
2740         umask 777
2741         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2742         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2743         mkdir $DIR/$tdir/local_dir
2744
2745         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2746         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2747         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2748
2749         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2750                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 777"
2751
2752         rmdir $DIR/$tdir/* || error "rmdir(umask 777) failed"
2753
2754         umask 000
2755         $LFS setdirstripe -i0 -c2 $DIR/$tdir/striped_dir
2756         $LFS setdirstripe -i1 -c2 $DIR/$tdir/striped_dir1
2757         mkdir $DIR/$tdir/local_dir
2758
2759         s0_mode=$(stat -c%f $DIR/$tdir/striped_dir)
2760         s1_mode=$(stat -c%f $DIR/$tdir/striped_dir1)
2761         l_mode=$(stat -c%f $DIR/$tdir/local_dir)
2762
2763         [ "$l_mode" = "$s0_mode" -a "$l_mode" = "$s1_mode" ] ||
2764                 error "mkdir $l_mode striped0 $s0_mode striped1 $s1_mode 0"
2765 }
2766 run_test 33e "mkdir and striped directory should have same mode"
2767
2768 cleanup_33f() {
2769         trap 0
2770         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=0
2771 }
2772
2773 test_33f() {
2774         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2775
2776         mkdir $DIR/$tdir
2777         chmod go+rwx $DIR/$tdir
2778         do_facet $SINGLEMDS $LCTL set_param mdt.*.enable_remote_dir_gid=-1
2779         trap cleanup_33f EXIT
2780
2781         $RUNAS lfs mkdir -c$MDSCOUNT $DIR/$tdir/striped_dir ||
2782                 error "cannot create striped directory"
2783
2784         $RUNAS touch $DIR/$tdir/striped_dir/{0..16} ||
2785                 error "cannot create files in striped directory"
2786
2787         $RUNAS rm $DIR/$tdir/striped_dir/{0..16} ||
2788                 error "cannot remove files in striped directory"
2789
2790         $RUNAS rmdir $DIR/$tdir/striped_dir ||
2791                 error "cannot remove striped directory"
2792
2793         cleanup_33f
2794 }
2795 run_test 33f "nonroot user can create, access, and remove a striped directory"
2796
2797 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
2798 test_34a() {
2799         rm -f $DIR/f34
2800         $MCREATE $DIR/f34 || error
2801         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2802         $TRUNCATE $DIR/f34 $TEST_34_SIZE || error
2803         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2804         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2805 }
2806 run_test 34a "truncate file that has not been opened ==========="
2807
2808 test_34b() {
2809         [ ! -f $DIR/f34 ] && test_34a
2810         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2811         $OPENFILE -f O_RDONLY $DIR/f34
2812         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" || error
2813         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2814 }
2815 run_test 34b "O_RDONLY opening file doesn't create objects ====="
2816
2817 test_34c() {
2818         [ ! -f $DIR/f34 ] && test_34a
2819         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2820         $OPENFILE -f O_RDWR $DIR/f34
2821         $GETSTRIPE $DIR/f34 2>&1 | grep -q "no stripe info" && error
2822         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2823 }
2824 run_test 34c "O_RDWR opening file-with-size works =============="
2825
2826 test_34d() {
2827         [ ! -f $DIR/f34 ] && test_34a
2828         dd if=/dev/zero of=$DIR/f34 conv=notrunc bs=4k count=1 || error
2829         $CHECKSTAT -s $TEST_34_SIZE $DIR/f34 || error
2830         rm $DIR/f34
2831 }
2832 run_test 34d "write to sparse file ============================="
2833
2834 test_34e() {
2835         rm -f $DIR/f34e
2836         $MCREATE $DIR/f34e || error
2837         $TRUNCATE $DIR/f34e 1000 || error
2838         $CHECKSTAT -s 1000 $DIR/f34e || error
2839         $OPENFILE -f O_RDWR $DIR/f34e
2840         $CHECKSTAT -s 1000 $DIR/f34e || error
2841 }
2842 run_test 34e "create objects, some with size and some without =="
2843
2844 test_34f() { # bug 6242, 6243
2845         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2846         SIZE34F=48000
2847         rm -f $DIR/f34f
2848         $MCREATE $DIR/f34f || error
2849         $TRUNCATE $DIR/f34f $SIZE34F || error "truncating $DIR/f3f to $SIZE34F"
2850         dd if=$DIR/f34f of=$TMP/f34f
2851         $CHECKSTAT -s $SIZE34F $TMP/f34f || error "$TMP/f34f not $SIZE34F bytes"
2852         dd if=/dev/zero of=$TMP/f34fzero bs=$SIZE34F count=1
2853         cmp $DIR/f34f $TMP/f34fzero || error "$DIR/f34f not all zero"
2854         cmp $TMP/f34f $TMP/f34fzero || error "$TMP/f34f not all zero"
2855         rm $TMP/f34f $TMP/f34fzero $DIR/f34f
2856 }
2857 run_test 34f "read from a file with no objects until EOF ======="
2858
2859 test_34g() {
2860         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2861         dd if=/dev/zero of=$DIR/$tfile bs=1 count=100 seek=$TEST_34_SIZE || error
2862         $TRUNCATE $DIR/$tfile $((TEST_34_SIZE / 2))|| error
2863         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || error "truncate failed"
2864         cancel_lru_locks osc
2865         $CHECKSTAT -s $((TEST_34_SIZE / 2)) $DIR/$tfile || \
2866                 error "wrong size after lock cancel"
2867
2868         $TRUNCATE $DIR/$tfile $TEST_34_SIZE || error
2869         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2870                 error "expanding truncate failed"
2871         cancel_lru_locks osc
2872         $CHECKSTAT -s $TEST_34_SIZE $DIR/$tfile || \
2873                 error "wrong expanded size after lock cancel"
2874 }
2875 run_test 34g "truncate long file ==============================="
2876
2877 test_34h() {
2878         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2879         local gid=10
2880         local sz=1000
2881
2882         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10 || error
2883         sync # Flush the cache so that multiop below does not block on cache
2884              # flush when getting the group lock
2885         $MULTIOP $DIR/$tfile OG${gid}T${sz}g${gid}c &
2886         MULTIPID=$!
2887
2888         # Since just timed wait is not good enough, let's do a sync write
2889         # that way we are sure enough time for a roundtrip + processing
2890         # passed + 2 seconds of extra margin.
2891         dd if=/dev/zero of=$DIR/${tfile}-1 bs=4096 oflag=direct count=1
2892         rm $DIR/${tfile}-1
2893         sleep 2
2894
2895         if [[ `ps h -o comm -p $MULTIPID` == "multiop" ]]; then
2896                 error "Multiop blocked on ftruncate, pid=$MULTIPID"
2897                 kill -9 $MULTIPID
2898         fi
2899         wait $MULTIPID
2900         local nsz=`stat -c %s $DIR/$tfile`
2901         [[ $nsz == $sz ]] || error "New size wrong $nsz != $sz"
2902 }
2903 run_test 34h "ftruncate file under grouplock should not block"
2904
2905 test_35a() {
2906         cp /bin/sh $DIR/f35a
2907         chmod 444 $DIR/f35a
2908         chown $RUNAS_ID $DIR/f35a
2909         $RUNAS $DIR/f35a && error || true
2910         rm $DIR/f35a
2911 }
2912 run_test 35a "exec file with mode 444 (should return and not leak) ====="
2913
2914 test_36a() {
2915         rm -f $DIR/f36
2916         utime $DIR/f36 || error
2917 }
2918 run_test 36a "MDS utime check (mknod, utime) ==================="
2919
2920 test_36b() {
2921         echo "" > $DIR/f36
2922         utime $DIR/f36 || error
2923 }
2924 run_test 36b "OST utime check (open, utime) ===================="
2925
2926 test_36c() {
2927         rm -f $DIR/d36/f36
2928         test_mkdir $DIR/d36
2929         chown $RUNAS_ID $DIR/d36
2930         $RUNAS utime $DIR/d36/f36 || error
2931 }
2932 run_test 36c "non-root MDS utime check (mknod, utime) =========="
2933
2934 test_36d() {
2935         [ ! -d $DIR/d36 ] && test_36c
2936         echo "" > $DIR/d36/f36
2937         $RUNAS utime $DIR/d36/f36 || error
2938 }
2939 run_test 36d "non-root OST utime check (open, utime) ==========="
2940
2941 test_36e() {
2942         [ $RUNAS_ID -eq $UID ] && skip_env "RUNAS_ID = UID = $UID -- skipping" && return
2943         test_mkdir -p $DIR/$tdir
2944         touch $DIR/$tdir/$tfile
2945         $RUNAS utime $DIR/$tdir/$tfile && \
2946                 error "utime worked, expected failure" || true
2947 }
2948 run_test 36e "utime on non-owned file (should return error) ===="
2949
2950 subr_36fh() {
2951         local fl="$1"
2952         local LANG_SAVE=$LANG
2953         local LC_LANG_SAVE=$LC_LANG
2954         export LANG=C LC_LANG=C # for date language
2955
2956         DATESTR="Dec 20  2000"
2957         test_mkdir -p $DIR/$tdir
2958         lctl set_param fail_loc=$fl
2959         date; date +%s
2960         cp /etc/hosts $DIR/$tdir/$tfile
2961         sync & # write RPC generated with "current" inode timestamp, but delayed
2962         sleep 1
2963         touch --date="$DATESTR" $DIR/$tdir/$tfile # setattr timestamp in past
2964         LS_BEFORE="`ls -l $DIR/$tdir/$tfile`" # old timestamp from client cache
2965         cancel_lru_locks osc
2966         LS_AFTER="`ls -l $DIR/$tdir/$tfile`"  # timestamp from OST object
2967         date; date +%s
2968         [ "$LS_BEFORE" != "$LS_AFTER" ] && \
2969                 echo "BEFORE: $LS_BEFORE" && \
2970                 echo "AFTER : $LS_AFTER" && \
2971                 echo "WANT  : $DATESTR" && \
2972                 error "$DIR/$tdir/$tfile timestamps changed" || true
2973
2974         export LANG=$LANG_SAVE LC_LANG=$LC_LANG_SAVE
2975 }
2976
2977 test_36f() {
2978         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2979         #define OBD_FAIL_OST_BRW_PAUSE_BULK 0x214
2980         subr_36fh "0x80000214"
2981 }
2982 run_test 36f "utime on file racing with OST BRW write =========="
2983
2984 test_36g() {
2985         remote_ost_nodsh && skip "remote OST with nodsh" && return
2986         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
2987         local fmd_max_age
2988         local fmd_before
2989         local fmd_after
2990
2991         test_mkdir -p $DIR/$tdir
2992         fmd_max_age=$(do_facet ost1 \
2993                 "lctl get_param -n obdfilter.*.client_cache_seconds 2> /dev/null | \
2994                 head -n 1")
2995
2996         fmd_before=$(do_facet ost1 \
2997                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
2998         touch $DIR/$tdir/$tfile
2999         sleep $((fmd_max_age + 12))
3000         fmd_after=$(do_facet ost1 \
3001                 "awk '/ll_fmd_cache/ {print \\\$2}' /proc/slabinfo")
3002
3003         echo "fmd_before: $fmd_before"
3004         echo "fmd_after: $fmd_after"
3005         [[ $fmd_after -gt $fmd_before ]] &&
3006                 echo "AFTER: $fmd_after > BEFORE: $fmd_before" &&
3007                 error "fmd didn't expire after ping" || true
3008 }
3009 run_test 36g "filter mod data cache expiry ====================="
3010
3011 test_36h() {
3012         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3013         #define OBD_FAIL_OST_BRW_PAUSE_BULK2 0x227
3014         subr_36fh "0x80000227"
3015 }
3016 run_test 36h "utime on file racing with OST BRW write =========="
3017
3018 test_36i() {
3019         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3020
3021         test_mkdir $DIR/$tdir
3022         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
3023
3024         local mtime=$(stat -c%Y $DIR/$tdir/striped_dir)
3025         local new_mtime=$((mtime + 200))
3026
3027         #change Modify time of striped dir
3028         touch -m -d @$new_mtime $DIR/$tdir/striped_dir ||
3029                         error "change mtime failed"
3030
3031         local got=$(stat -c%Y $DIR/$tdir/striped_dir)
3032
3033         [ "$new_mtime" = "$got" ] || error "expect $new_mtime got $got"
3034 }
3035 run_test 36i "change mtime on striped directory"
3036
3037 # test_37 - duplicate with tests 32q 32r
3038
3039 test_38() {
3040         local file=$DIR/$tfile
3041         touch $file
3042         openfile -f O_DIRECTORY $file
3043         local RC=$?
3044         local ENOTDIR=20
3045         [ $RC -eq 0 ] && error "opened file $file with O_DIRECTORY" || true
3046         [ $RC -eq $ENOTDIR ] || error "error $RC should be ENOTDIR ($ENOTDIR)"
3047 }
3048 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
3049
3050 test_39() {
3051         touch $DIR/$tfile
3052         touch $DIR/${tfile}2
3053 #       ls -l  $DIR/$tfile $DIR/${tfile}2
3054 #       ls -lu  $DIR/$tfile $DIR/${tfile}2
3055 #       ls -lc  $DIR/$tfile $DIR/${tfile}2
3056         sleep 2
3057         $OPENFILE -f O_CREAT:O_TRUNC:O_WRONLY $DIR/${tfile}2
3058         if [ ! $DIR/${tfile}2 -nt $DIR/$tfile ]; then
3059                 echo "mtime"
3060                 ls -l --full-time $DIR/$tfile $DIR/${tfile}2
3061                 echo "atime"
3062                 ls -lu --full-time $DIR/$tfile $DIR/${tfile}2
3063                 echo "ctime"
3064                 ls -lc --full-time $DIR/$tfile $DIR/${tfile}2
3065                 error "O_TRUNC didn't change timestamps"
3066         fi
3067 }
3068 run_test 39 "mtime changed on create ==========================="
3069
3070 test_39b() {
3071         test_mkdir -p -c1 $DIR/$tdir
3072         cp -p /etc/passwd $DIR/$tdir/fopen
3073         cp -p /etc/passwd $DIR/$tdir/flink
3074         cp -p /etc/passwd $DIR/$tdir/funlink
3075         cp -p /etc/passwd $DIR/$tdir/frename
3076         ln $DIR/$tdir/funlink $DIR/$tdir/funlink2
3077
3078         sleep 1
3079         echo "aaaaaa" >> $DIR/$tdir/fopen
3080         echo "aaaaaa" >> $DIR/$tdir/flink
3081         echo "aaaaaa" >> $DIR/$tdir/funlink
3082         echo "aaaaaa" >> $DIR/$tdir/frename
3083
3084         local open_new=`stat -c %Y $DIR/$tdir/fopen`
3085         local link_new=`stat -c %Y $DIR/$tdir/flink`
3086         local unlink_new=`stat -c %Y $DIR/$tdir/funlink`
3087         local rename_new=`stat -c %Y $DIR/$tdir/frename`
3088
3089         cat $DIR/$tdir/fopen > /dev/null
3090         ln $DIR/$tdir/flink $DIR/$tdir/flink2
3091         rm -f $DIR/$tdir/funlink2
3092         mv -f $DIR/$tdir/frename $DIR/$tdir/frename2
3093
3094         for (( i=0; i < 2; i++ )) ; do
3095                 local open_new2=`stat -c %Y $DIR/$tdir/fopen`
3096                 local link_new2=`stat -c %Y $DIR/$tdir/flink`
3097                 local unlink_new2=`stat -c %Y $DIR/$tdir/funlink`
3098                 local rename_new2=`stat -c %Y $DIR/$tdir/frename2`
3099
3100                 [ $open_new2 -eq $open_new ] || error "open file reverses mtime"
3101                 [ $link_new2 -eq $link_new ] || error "link file reverses mtime"
3102                 [ $unlink_new2 -eq $unlink_new ] || error "unlink file reverses mtime"
3103                 [ $rename_new2 -eq $rename_new ] || error "rename file reverses mtime"
3104
3105                 cancel_lru_locks osc
3106                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3107         done
3108 }
3109 run_test 39b "mtime change on open, link, unlink, rename  ======"
3110
3111 # this should be set to past
3112 TEST_39_MTIME=`date -d "1 year ago" +%s`
3113
3114 # bug 11063
3115 test_39c() {
3116         touch $DIR1/$tfile
3117         sleep 2
3118         local mtime0=`stat -c %Y $DIR1/$tfile`
3119
3120         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3121         local mtime1=`stat -c %Y $DIR1/$tfile`
3122         [ "$mtime1" = $TEST_39_MTIME ] || \
3123                 error "mtime is not set to past: $mtime1, should be $TEST_39_MTIME"
3124
3125         local d1=`date +%s`
3126         echo hello >> $DIR1/$tfile
3127         local d2=`date +%s`
3128         local mtime2=`stat -c %Y $DIR1/$tfile`
3129         [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] || \
3130                 error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
3131
3132         mv $DIR1/$tfile $DIR1/$tfile-1
3133
3134         for (( i=0; i < 2; i++ )) ; do
3135                 local mtime3=`stat -c %Y $DIR1/$tfile-1`
3136                 [ "$mtime2" = "$mtime3" ] || \
3137                         error "mtime ($mtime2) changed (to $mtime3) on rename"
3138
3139                 cancel_lru_locks osc
3140                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3141         done
3142 }
3143 run_test 39c "mtime change on rename ==========================="
3144
3145 # bug 21114
3146 test_39d() {
3147         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3148         touch $DIR1/$tfile
3149
3150         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3151
3152         for (( i=0; i < 2; i++ )) ; do
3153                 local mtime=`stat -c %Y $DIR1/$tfile`
3154                 [ $mtime = $TEST_39_MTIME ] || \
3155                         error "mtime($mtime) is not set to $TEST_39_MTIME"
3156
3157                 cancel_lru_locks osc
3158                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3159         done
3160 }
3161 run_test 39d "create, utime, stat =============================="
3162
3163 # bug 21114
3164 test_39e() {
3165         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3166         touch $DIR1/$tfile
3167         local mtime1=`stat -c %Y $DIR1/$tfile`
3168
3169         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3170
3171         for (( i=0; i < 2; i++ )) ; do
3172                 local mtime2=`stat -c %Y $DIR1/$tfile`
3173                 [ $mtime2 = $TEST_39_MTIME ] || \
3174                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3175
3176                 cancel_lru_locks osc
3177                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3178         done
3179 }
3180 run_test 39e "create, stat, utime, stat ========================"
3181
3182 # bug 21114
3183 test_39f() {
3184         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3185         touch $DIR1/$tfile
3186         mtime1=`stat -c %Y $DIR1/$tfile`
3187
3188         sleep 2
3189         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3190
3191         for (( i=0; i < 2; i++ )) ; do
3192                 local mtime2=`stat -c %Y $DIR1/$tfile`
3193                 [ $mtime2 = $TEST_39_MTIME ] || \
3194                         error "mtime($mtime2) is not set to $TEST_39_MTIME"
3195
3196                 cancel_lru_locks osc
3197                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3198         done
3199 }
3200 run_test 39f "create, stat, sleep, utime, stat ================="
3201
3202 # bug 11063
3203 test_39g() {
3204         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3205         echo hello >> $DIR1/$tfile
3206         local mtime1=`stat -c %Y $DIR1/$tfile`
3207
3208         sleep 2
3209         chmod o+r $DIR1/$tfile
3210
3211         for (( i=0; i < 2; i++ )) ; do
3212                 local mtime2=`stat -c %Y $DIR1/$tfile`
3213                 [ "$mtime1" = "$mtime2" ] || \
3214                         error "lost mtime: $mtime2, should be $mtime1"
3215
3216                 cancel_lru_locks osc
3217                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3218         done
3219 }
3220 run_test 39g "write, chmod, stat ==============================="
3221
3222 # bug 11063
3223 test_39h() {
3224         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3225         touch $DIR1/$tfile
3226         sleep 1
3227
3228         local d1=`date`
3229         echo hello >> $DIR1/$tfile
3230         local mtime1=`stat -c %Y $DIR1/$tfile`
3231
3232         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3233         local d2=`date`
3234         if [ "$d1" != "$d2" ]; then
3235                 echo "write and touch not within one second"
3236         else
3237                 for (( i=0; i < 2; i++ )) ; do
3238                         local mtime2=`stat -c %Y $DIR1/$tfile`
3239                         [ "$mtime2" = $TEST_39_MTIME ] || \
3240                                 error "lost mtime: $mtime2, should be $TEST_39_MTIME"
3241
3242                         cancel_lru_locks osc
3243                         if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3244                 done
3245         fi
3246 }
3247 run_test 39h "write, utime within one second, stat ============="
3248
3249 test_39i() {
3250         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3251         touch $DIR1/$tfile
3252         sleep 1
3253
3254         echo hello >> $DIR1/$tfile
3255         local mtime1=`stat -c %Y $DIR1/$tfile`
3256
3257         mv $DIR1/$tfile $DIR1/$tfile-1
3258
3259         for (( i=0; i < 2; i++ )) ; do
3260                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3261
3262                 [ "$mtime1" = "$mtime2" ] || \
3263                         error "lost mtime: $mtime2, should be $mtime1"
3264
3265                 cancel_lru_locks osc
3266                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3267         done
3268 }
3269 run_test 39i "write, rename, stat =============================="
3270
3271 test_39j() {
3272         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3273         start_full_debug_logging
3274         touch $DIR1/$tfile
3275         sleep 1
3276
3277         #define OBD_FAIL_OSC_DELAY_SETTIME       0x412
3278         lctl set_param fail_loc=0x80000412
3279         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c ||
3280                 error "multiop failed"
3281         local multipid=$!
3282         local mtime1=`stat -c %Y $DIR1/$tfile`
3283
3284         mv $DIR1/$tfile $DIR1/$tfile-1
3285
3286         kill -USR1 $multipid
3287         wait $multipid || error "multiop close failed"
3288
3289         for (( i=0; i < 2; i++ )) ; do
3290                 local mtime2=`stat -c %Y $DIR1/$tfile-1`
3291                 [ "$mtime1" = "$mtime2" ] ||
3292                         error "mtime is lost on close: $mtime2, " \
3293                               "should be $mtime1"
3294
3295                 cancel_lru_locks osc
3296                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3297         done
3298         lctl set_param fail_loc=0
3299         stop_full_debug_logging
3300 }
3301 run_test 39j "write, rename, close, stat ======================="
3302
3303 test_39k() {
3304         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3305         touch $DIR1/$tfile
3306         sleep 1
3307
3308         multiop_bg_pause $DIR1/$tfile oO_RDWR:w2097152_c || error "multiop failed"
3309         local multipid=$!
3310         local mtime1=`stat -c %Y $DIR1/$tfile`
3311
3312         touch -m -d @$TEST_39_MTIME $DIR1/$tfile
3313
3314         kill -USR1 $multipid
3315         wait $multipid || error "multiop close failed"
3316
3317         for (( i=0; i < 2; i++ )) ; do
3318                 local mtime2=`stat -c %Y $DIR1/$tfile`
3319
3320                 [ "$mtime2" = $TEST_39_MTIME ] || \
3321                         error "mtime is lost on close: $mtime2, should be $TEST_39_MTIME"
3322
3323                 cancel_lru_locks osc
3324                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3325         done
3326 }
3327 run_test 39k "write, utime, close, stat ========================"
3328
3329 # this should be set to future
3330 TEST_39_ATIME=`date -d "1 year" +%s`
3331
3332 test_39l() {
3333         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3334         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3335         local atime_diff=$(do_facet $SINGLEMDS \
3336                                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3337         rm -rf $DIR/$tdir
3338         mkdir -p $DIR/$tdir
3339
3340         # test setting directory atime to future
3341         touch -a -d @$TEST_39_ATIME $DIR/$tdir
3342         local atime=$(stat -c %X $DIR/$tdir)
3343         [ "$atime" = $TEST_39_ATIME ] || \
3344                 error "atime is not set to future: $atime, $TEST_39_ATIME"
3345
3346         # test setting directory atime from future to now
3347         local d1=$(date +%s)
3348         ls $DIR/$tdir
3349         local d2=$(date +%s)
3350
3351         cancel_lru_locks mdc
3352         atime=$(stat -c %X $DIR/$tdir)
3353         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3354                 error "atime is not updated from future: $atime, $d1<atime<$d2"
3355
3356         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
3357         sleep 3
3358
3359         # test setting directory atime when now > dir atime + atime_diff
3360         d1=$(date +%s)
3361         ls $DIR/$tdir
3362         d2=$(date +%s)
3363         cancel_lru_locks mdc
3364         atime=$(stat -c %X $DIR/$tdir)
3365         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3366                 error "atime is not updated  : $atime, should be $d2"
3367
3368         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
3369         sleep 3
3370
3371         # test not setting directory atime when now < dir atime + atime_diff
3372         ls $DIR/$tdir
3373         cancel_lru_locks mdc
3374         atime=$(stat -c %X $DIR/$tdir)
3375         [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
3376                 error "atime is updated to $atime, should remain $d1<atime<$d2"
3377
3378         do_facet $SINGLEMDS \
3379                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3380 }
3381 run_test 39l "directory atime update ==========================="
3382
3383 test_39m() {
3384         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3385         touch $DIR1/$tfile
3386         sleep 2
3387         local far_past_mtime=$(date -d "May 29 1953" +%s)
3388         local far_past_atime=$(date -d "Dec 17 1903" +%s)
3389
3390         touch -m -d @$far_past_mtime $DIR1/$tfile
3391         touch -a -d @$far_past_atime $DIR1/$tfile
3392
3393         for (( i=0; i < 2; i++ )) ; do
3394                 local timestamps=$(stat -c "%X %Y" $DIR1/$tfile)
3395                 [ "$timestamps" = "$far_past_atime $far_past_mtime" ] || \
3396                         error "atime or mtime set incorrectly"
3397
3398                 cancel_lru_locks osc
3399                 if [ $i = 0 ] ; then echo "repeat after cancel_lru_locks"; fi
3400         done
3401 }
3402 run_test 39m "test atime and mtime before 1970"
3403
3404 test_39n() { # LU-3832
3405         local atime_diff=$(do_facet $SINGLEMDS \
3406                 lctl get_param -n mdd.*MDT0000*.atime_diff)
3407         local atime0
3408         local atime1
3409         local atime2
3410
3411         do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=1
3412
3413         rm -rf $DIR/$tfile
3414         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 status=noxfer
3415         atime0=$(stat -c %X $DIR/$tfile)
3416
3417         sleep 5
3418         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3419         atime1=$(stat -c %X $DIR/$tfile)
3420
3421         sleep 5
3422         cancel_lru_locks mdc
3423         cancel_lru_locks osc
3424         $MULTIOP $DIR/$tfile oO_RDONLY:O_NOATIME:r4096c
3425         atime2=$(stat -c %X $DIR/$tfile)
3426
3427         do_facet $SINGLEMDS \
3428                 lctl set_param -n mdd.*MDT0000*.atime_diff=$atime_diff
3429
3430         [ "$atime0" -eq "$atime1" ] || error "atime0 $atime0 != atime1 $atime1"
3431         [ "$atime1" -eq "$atime2" ] || error "atime0 $atime0 != atime1 $atime1"
3432 }
3433 run_test 39n "check that O_NOATIME is honored"
3434
3435 test_39o() {
3436         TESTDIR=$DIR/$tdir/$tfile
3437         [ -e $TESTDIR ] && rm -rf $TESTDIR
3438         mkdir -p $TESTDIR
3439         cd $TESTDIR
3440         links1=2
3441         ls
3442         mkdir a b
3443         ls
3444         links2=$(stat -c %h .)
3445         [ $(($links1 + 2)) != $links2 ] &&
3446                 error "wrong links count $(($links1 + 2)) != $links2"
3447         rmdir b
3448         links3=$(stat -c %h .)
3449         [ $(($links1 + 1)) != $links3 ] &&
3450                 error "wrong links count $links1 != $links3"
3451         return 0
3452 }
3453 run_test 39o "directory cached attributes updated after create ========"
3454
3455 test_39p() {
3456         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs" && return
3457         local MDTIDX=1
3458         TESTDIR=$DIR/$tdir/$tfile
3459         [ -e $TESTDIR ] && rm -rf $TESTDIR
3460         test_mkdir -p $TESTDIR
3461         cd $TESTDIR
3462         links1=2
3463         ls
3464         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
3465         $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
3466         ls
3467         links2=$(stat -c %h .)
3468         [ $(($links1 + 2)) != $links2 ] &&
3469                 error "wrong links count $(($links1 + 2)) != $links2"
3470         rmdir remote_dir2
3471         links3=$(stat -c %h .)
3472         [ $(($links1 + 1)) != $links3 ] &&
3473                 error "wrong links count $links1 != $links3"
3474         return 0
3475 }
3476 run_test 39p "remote directory cached attributes updated after create ========"
3477
3478
3479 test_40() {
3480         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
3481         $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
3482                 error "openfile O_WRONLY:O_TRUNC $tfile failed"
3483         $CHECKSTAT -t file -s 4096 $DIR/$tfile ||
3484                 error "$tfile is not 4096 bytes in size"
3485 }
3486 run_test 40 "failed open(O_TRUNC) doesn't truncate ============="
3487
3488 test_41() {
3489         # bug 1553
3490         small_write $DIR/f41 18
3491 }
3492 run_test 41 "test small file write + fstat ====================="
3493
3494 count_ost_writes() {
3495         lctl get_param -n osc.*.stats |
3496                 awk -vwrites=0 '/ost_write/ { writes += $2 } \
3497                         END { printf("%0.0f", writes) }'
3498 }
3499
3500 # decent default
3501 WRITEBACK_SAVE=500
3502 DIRTY_RATIO_SAVE=40
3503 MAX_DIRTY_RATIO=50
3504 BG_DIRTY_RATIO_SAVE=10
3505 MAX_BG_DIRTY_RATIO=25
3506
3507 start_writeback() {
3508         trap 0
3509         # in 2.6, restore /proc/sys/vm/dirty_writeback_centisecs,
3510         # dirty_ratio, dirty_background_ratio
3511         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3512                 sysctl -w vm.dirty_writeback_centisecs=$WRITEBACK_SAVE
3513                 sysctl -w vm.dirty_background_ratio=$BG_DIRTY_RATIO_SAVE
3514                 sysctl -w vm.dirty_ratio=$DIRTY_RATIO_SAVE
3515         else
3516                 # if file not here, we are a 2.4 kernel
3517                 kill -CONT `pidof kupdated`
3518         fi
3519 }
3520
3521 stop_writeback() {
3522         # setup the trap first, so someone cannot exit the test at the
3523         # exact wrong time and mess up a machine
3524         trap start_writeback EXIT
3525         # in 2.6, save and 0 /proc/sys/vm/dirty_writeback_centisecs
3526         if [ -f /proc/sys/vm/dirty_writeback_centisecs ]; then
3527                 WRITEBACK_SAVE=`sysctl -n vm.dirty_writeback_centisecs`
3528                 sysctl -w vm.dirty_writeback_centisecs=0
3529                 sysctl -w vm.dirty_writeback_centisecs=0
3530                 # save and increase /proc/sys/vm/dirty_ratio
3531                 DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_ratio`
3532                 sysctl -w vm.dirty_ratio=$MAX_DIRTY_RATIO
3533                 # save and increase /proc/sys/vm/dirty_background_ratio
3534                 BG_DIRTY_RATIO_SAVE=`sysctl -n vm.dirty_background_ratio`
3535                 sysctl -w vm.dirty_background_ratio=$MAX_BG_DIRTY_RATIO
3536         else
3537                 # if file not here, we are a 2.4 kernel
3538                 kill -STOP `pidof kupdated`
3539         fi
3540 }
3541
3542 # ensure that all stripes have some grant before we test client-side cache
3543 setup_test42() {
3544         for i in `seq -f $DIR/f42-%g 1 $OSTCOUNT`; do
3545                 dd if=/dev/zero of=$i bs=4k count=1
3546                 rm $i
3547         done
3548 }
3549
3550 # Tests 42* verify that our behaviour is correct WRT caching, file closure,
3551 # file truncation, and file removal.
3552 test_42a() {
3553         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3554         setup_test42
3555         cancel_lru_locks osc
3556         stop_writeback
3557         sync; sleep 1; sync # just to be safe
3558         BEFOREWRITES=`count_ost_writes`
3559         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur_grant_bytes | grep "[0-9]"
3560         dd if=/dev/zero of=$DIR/f42a bs=1024 count=100
3561         AFTERWRITES=`count_ost_writes`
3562         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3563                 error "$BEFOREWRITES < $AFTERWRITES"
3564         start_writeback
3565 }
3566 run_test 42a "ensure that we don't flush on close =============="
3567
3568 test_42b() {
3569         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3570         setup_test42
3571         cancel_lru_locks osc
3572         stop_writeback
3573         sync
3574         dd if=/dev/zero of=$DIR/f42b bs=1024 count=100
3575         BEFOREWRITES=$(count_ost_writes)
3576         $MUNLINK $DIR/f42b || error "$MUNLINK $DIR/f42b: $?"
3577         AFTERWRITES=$(count_ost_writes)
3578         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3579                 error "$BEFOREWRITES < $AFTERWRITES on unlink"
3580         fi
3581         BEFOREWRITES=$(count_ost_writes)
3582         sync || error "sync: $?"
3583         AFTERWRITES=$(count_ost_writes)
3584         if [[ $BEFOREWRITES -lt $AFTERWRITES ]]; then
3585                 error "$BEFOREWRITES < $AFTERWRITES on sync"
3586         fi
3587         dmesg | grep 'error from obd_brw_async' && error 'error writing back'
3588         start_writeback
3589         return 0
3590 }
3591 run_test 42b "test destroy of file with cached dirty data ======"
3592
3593 # if these tests just want to test the effect of truncation,
3594 # they have to be very careful.  consider:
3595 # - the first open gets a {0,EOF}PR lock
3596 # - the first write conflicts and gets a {0, count-1}PW
3597 # - the rest of the writes are under {count,EOF}PW
3598 # - the open for truncate tries to match a {0,EOF}PR
3599 #   for the filesize and cancels the PWs.
3600 # any number of fixes (don't get {0,EOF} on open, match
3601 # composite locks, do smarter file size management) fix
3602 # this, but for now we want these tests to verify that
3603 # the cancellation with truncate intent works, so we
3604 # start the file with a full-file pw lock to match against
3605 # until the truncate.
3606 trunc_test() {
3607         test=$1
3608         file=$DIR/$test
3609         offset=$2
3610         cancel_lru_locks osc
3611         stop_writeback
3612         # prime the file with 0,EOF PW to match
3613         touch $file
3614         $TRUNCATE $file 0
3615         sync; sync
3616         # now the real test..
3617         dd if=/dev/zero of=$file bs=1024 count=100
3618         BEFOREWRITES=`count_ost_writes`
3619         $TRUNCATE $file $offset
3620         cancel_lru_locks osc
3621         AFTERWRITES=`count_ost_writes`
3622         start_writeback
3623 }
3624
3625 test_42c() {
3626         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3627         trunc_test 42c 1024
3628         [ $BEFOREWRITES -eq $AFTERWRITES ] && \
3629             error "beforewrites $BEFOREWRITES == afterwrites $AFTERWRITES on truncate"
3630         rm $file
3631 }
3632 run_test 42c "test partial truncate of file with cached dirty data"
3633
3634 test_42d() {
3635         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3636         trunc_test 42d 0
3637         [ $BEFOREWRITES -eq $AFTERWRITES ] || \
3638             error "beforewrites $BEFOREWRITES != afterwrites $AFTERWRITES on truncate"
3639         rm $file
3640 }
3641 run_test 42d "test complete truncate of file with cached dirty data"
3642
3643 test_42e() { # bug22074
3644         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3645         local TDIR=$DIR/${tdir}e
3646         local pagesz=$(page_size)
3647         local pages=16 # hardcoded 16 pages, don't change it.
3648         local files=$((OSTCOUNT * 500)) # hopefully 500 files on each OST
3649         local proc_osc0="osc.${FSNAME}-OST0000-osc-[^MDT]*"
3650         local max_dirty_mb
3651         local warmup_files
3652
3653         test_mkdir -p $DIR/${tdir}e
3654         $SETSTRIPE -c 1 $TDIR
3655         createmany -o $TDIR/f $files
3656
3657         max_dirty_mb=$($LCTL get_param -n $proc_osc0/max_dirty_mb)
3658
3659         # we assume that with $OSTCOUNT files, at least one of them will
3660         # be allocated on OST0.
3661         warmup_files=$((OSTCOUNT * max_dirty_mb))
3662         createmany -o $TDIR/w $warmup_files
3663
3664         # write a large amount of data into one file and sync, to get good
3665         # avail_grant number from OST.
3666         for ((i=0; i<$warmup_files; i++)); do
3667                 idx=$($GETSTRIPE -i $TDIR/w$i)
3668                 [ $idx -ne 0 ] && continue
3669                 dd if=/dev/zero of=$TDIR/w$i bs="$max_dirty_mb"M count=1
3670                 break
3671         done
3672         [[ $i -gt $warmup_files ]] && error "OST0 is still cold"
3673         sync
3674         $LCTL get_param $proc_osc0/cur_dirty_bytes
3675         $LCTL get_param $proc_osc0/cur_grant_bytes
3676
3677         # create as much dirty pages as we can while not to trigger the actual
3678         # RPCs directly. but depends on the env, VFS may trigger flush during this
3679         # period, hopefully we are good.
3680         for ((i=0; i<$warmup_files; i++)); do
3681                 idx=$($GETSTRIPE -i $TDIR/w$i)
3682                 [ $idx -ne 0 ] && continue
3683                 dd if=/dev/zero of=$TDIR/w$i bs=1M count=1 2>/dev/null
3684         done
3685         $LCTL get_param $proc_osc0/cur_dirty_bytes
3686         $LCTL get_param $proc_osc0/cur_grant_bytes
3687
3688         # perform the real test
3689         $LCTL set_param $proc_osc0/rpc_stats 0
3690         for ((;i<$files; i++)); do
3691                 [ $($GETSTRIPE -i $TDIR/f$i) -eq 0 ] || continue
3692                 dd if=/dev/zero of=$TDIR/f$i bs=$pagesz count=$pages 2>/dev/null
3693         done
3694         sync
3695         $LCTL get_param $proc_osc0/rpc_stats
3696
3697         local percent=0
3698         local have_ppr=false
3699         $LCTL get_param $proc_osc0/rpc_stats |
3700                 while read PPR RRPC RPCT RCUM BAR WRPC WPCT WCUM; do
3701                         # skip lines until we are at the RPC histogram data
3702                         [ "$PPR" == "pages" ] && have_ppr=true && continue
3703                         $have_ppr || continue
3704
3705                         # we only want the percent stat for < 16 pages
3706                         [[ $(echo $PPR | tr -d ':') -ge $pages ]] && break
3707
3708                         percent=$((percent + WPCT))
3709                         if [[ $percent -gt 15 ]]; then
3710                                 error "less than 16-pages write RPCs" \
3711                                       "$percent% > 15%"
3712                                 break
3713                         fi
3714                 done
3715         rm -rf $TDIR
3716 }
3717 run_test 42e "verify sub-RPC writes are not done synchronously"
3718
3719 test_43() {
3720         test_mkdir -p $DIR/$tdir
3721         cp -p /bin/ls $DIR/$tdir/$tfile
3722         $MULTIOP $DIR/$tdir/$tfile Ow_c &
3723         pid=$!
3724         # give multiop a chance to open
3725         sleep 1
3726
3727         $DIR/$tdir/$tfile && error || true
3728         kill -USR1 $pid
3729 }
3730 run_test 43 "execution of file opened for write should return -ETXTBSY"
3731
3732 test_43a() {
3733         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3734         test_mkdir -p $DIR/$tdir
3735         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3736                         cp -p multiop $DIR/$tdir/multiop
3737         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3738                         return 1
3739         MULTIOP_PID=$!
3740         $MULTIOP $DIR/$tdir/multiop Oc && error "expected error, got success"
3741         kill -USR1 $MULTIOP_PID || return 2
3742         wait $MULTIOP_PID || return 3
3743         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3744 }
3745 run_test 43a "open(RDWR) of file being executed should return -ETXTBSY"
3746
3747 test_43b() {
3748         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3749         test_mkdir -p $DIR/$tdir
3750         cp -p `which $MULTIOP` $DIR/$tdir/multiop ||
3751                         cp -p multiop $DIR/$tdir/multiop
3752         MULTIOP_PROG=$DIR/$tdir/multiop multiop_bg_pause $TMP/$tfile.junk O_c ||
3753                         return 1
3754         MULTIOP_PID=$!
3755         $TRUNCATE $DIR/$tdir/multiop 0 && error "expected error, got success"
3756         kill -USR1 $MULTIOP_PID || return 2
3757         wait $MULTIOP_PID || return 3
3758         rm $TMP/$tfile.junk $DIR/$tdir/multiop
3759 }
3760 run_test 43b "truncate of file being executed should return -ETXTBSY"
3761
3762 test_43c() {
3763         local testdir="$DIR/$tdir"
3764         test_mkdir -p $DIR/$tdir
3765         cp $SHELL $testdir/
3766         ( cd $(dirname $SHELL) && md5sum $(basename $SHELL) ) | \
3767                 ( cd $testdir && md5sum -c)
3768 }
3769 run_test 43c "md5sum of copy into lustre========================"
3770
3771 test_44() {
3772         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
3773         dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
3774         dd if=$DIR/f1 bs=4k count=1 > /dev/null
3775 }
3776 run_test 44 "zero length read from a sparse stripe ============="
3777
3778 test_44a() {
3779         local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
3780                 awk '{ print $2 }')
3781         [ -z "$nstripe" ] && skip "can't get stripe info" && return
3782         [[ $nstripe -gt $OSTCOUNT ]] &&
3783             skip "Wrong default_stripe_count: $nstripe (OSTCOUNT: $OSTCOUNT)" &&
3784             return
3785         local stride=$($LCTL lov_getconfig $DIR | grep default_stripe_size: |
3786                 awk '{ print $2 }')
3787         if [[ $nstripe -eq 0 || $nstripe -eq -1 ]]; then
3788                 nstripe=$($LCTL lov_getconfig $DIR | grep obd_count: |
3789                         awk '{ print $2 }')
3790         fi
3791
3792         OFFSETS="0 $((stride/2)) $((stride-1))"
3793         for offset in $OFFSETS; do
3794                 for i in $(seq 0 $((nstripe-1))); do
3795                         local GLOBALOFFSETS=""
3796                         # size in Bytes
3797                         local size=$((((i + 2 * $nstripe )*$stride + $offset)))
3798                         local myfn=$DIR/d44a-$size
3799                         echo "--------writing $myfn at $size"
3800                         ll_sparseness_write $myfn $size ||
3801                                 error "ll_sparseness_write"
3802                         GLOBALOFFSETS="$GLOBALOFFSETS $size"
3803                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3804                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3805
3806                         for j in $(seq 0 $((nstripe-1))); do
3807                                 # size in Bytes
3808                                 size=$((((j + $nstripe )*$stride + $offset)))
3809                                 ll_sparseness_write $myfn $size ||
3810                                         error "ll_sparseness_write"
3811                                 GLOBALOFFSETS="$GLOBALOFFSETS $size"
3812                         done
3813                         ll_sparseness_verify $myfn $GLOBALOFFSETS ||
3814                                 error "ll_sparseness_verify $GLOBALOFFSETS"
3815                         rm -f $myfn
3816                 done
3817         done
3818 }
3819 run_test 44a "test sparse pwrite ==============================="
3820
3821 dirty_osc_total() {
3822         tot=0
3823         for d in `lctl get_param -n osc.*.cur_dirty_bytes`; do
3824                 tot=$(($tot + $d))
3825         done
3826         echo $tot
3827 }
3828 do_dirty_record() {
3829         before=`dirty_osc_total`
3830         echo executing "\"$*\""
3831         eval $*
3832         after=`dirty_osc_total`
3833         echo before $before, after $after
3834 }
3835 test_45() {
3836         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3837         f="$DIR/f45"
3838         # Obtain grants from OST if it supports it
3839         echo blah > ${f}_grant
3840         stop_writeback
3841         sync
3842         do_dirty_record "echo blah > $f"
3843         [[ $before -eq $after ]] && error "write wasn't cached"
3844         do_dirty_record "> $f"
3845         [[ $before -gt $after ]] || error "truncate didn't lower dirty count"
3846         do_dirty_record "echo blah > $f"
3847         [[ $before -eq $after ]] && error "write wasn't cached"
3848         do_dirty_record "sync"
3849         [[ $before -gt $after ]] || error "writeback didn't lower dirty count"
3850         do_dirty_record "echo blah > $f"
3851         [[ $before -eq $after ]] && error "write wasn't cached"
3852         do_dirty_record "cancel_lru_locks osc"
3853         [[ $before -gt $after ]] ||
3854                 error "lock cancellation didn't lower dirty count"
3855         start_writeback
3856 }
3857 run_test 45 "osc io page accounting ============================"
3858
3859 # in a 2 stripe file (lov.sh), page 1023 maps to page 511 in its object.  this
3860 # test tickles a bug where re-dirtying a page was failing to be mapped to the
3861 # objects offset and an assert hit when an rpc was built with 1023's mapped
3862 # offset 511 and 511's raw 511 offset. it also found general redirtying bugs.
3863 test_46() {
3864         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3865         f="$DIR/f46"
3866         stop_writeback
3867         sync
3868         dd if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3869         sync
3870         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=1023 count=1
3871         dd conv=notrunc if=/dev/zero of=$f bs=`page_size` seek=511 count=1
3872         sync
3873         start_writeback
3874 }
3875 run_test 46 "dirtying a previously written page ================"
3876
3877 # test_47 is removed "Device nodes check" is moved to test_28
3878
3879 test_48a() { # bug 2399
3880         [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
3881         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.63) ] &&
3882                 skip "MDS prior to 2.3.63 handle ZFS dir .. incorrectly" &&
3883                 return
3884         test_mkdir $DIR/$tdir
3885         cd $DIR/$tdir
3886         mv $DIR/$tdir $DIR/$tdir.new || error "move directory failed"
3887         test_mkdir $DIR/$tdir || error "recreate directory failed"
3888         touch foo || error "'touch foo' failed after recreating cwd"
3889         test_mkdir bar || error "'mkdir foo' failed after recreating cwd"
3890         touch .foo || error "'touch .foo' failed after recreating cwd"
3891         test_mkdir .bar || error "'mkdir .foo' failed after recreating cwd"
3892         ls . > /dev/null || error "'ls .' failed after recreating cwd"
3893         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3894         cd . || error "'cd .' failed after recreating cwd"
3895         test_mkdir . && error "'mkdir .' worked after recreating cwd"
3896         rmdir . && error "'rmdir .' worked after recreating cwd"
3897         ln -s . baz || error "'ln -s .' failed after recreating cwd"
3898         cd .. || error "'cd ..' failed after recreating cwd"
3899 }
3900 run_test 48a "Access renamed working dir (should return errors)="
3901
3902 test_48b() { # bug 2399
3903         rm -rf $DIR/$tdir
3904         test_mkdir $DIR/$tdir
3905         cd $DIR/$tdir
3906         rmdir $DIR/$tdir || error "remove cwd $DIR/$tdir failed"
3907         touch foo && error "'touch foo' worked after removing cwd"
3908         test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3909         touch .foo && error "'touch .foo' worked after removing cwd"
3910         test_mkdir .foo && error "'mkdir .foo' worked after removing cwd"
3911         ls . > /dev/null && error "'ls .' worked after removing cwd"
3912         ls .. > /dev/null || error "'ls ..' failed after removing cwd"
3913         is_patchless || ( cd . && error "'cd .' worked after removing cwd" )
3914         test_mkdir . && error "'mkdir .' worked after removing cwd"
3915         rmdir . && error "'rmdir .' worked after removing cwd"
3916         ln -s . foo && error "'ln -s .' worked after removing cwd"
3917         cd .. || echo "'cd ..' failed after removing cwd `pwd`"  #bug 3517
3918 }
3919 run_test 48b "Access removed working dir (should return errors)="
3920
3921 test_48c() { # bug 2350
3922         #lctl set_param debug=-1
3923         #set -vx
3924         rm -rf $DIR/$tdir
3925         test_mkdir -p $DIR/$tdir/dir
3926         cd $DIR/$tdir/dir
3927         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3928         $TRACE touch foo && error "touch foo worked after removing cwd"
3929         $TRACE test_mkdir foo && error "'mkdir foo' worked after removing cwd"
3930         touch .foo && error "touch .foo worked after removing cwd"
3931         test_mkdir .foo && error "mkdir .foo worked after removing cwd"
3932         $TRACE ls . && error "'ls .' worked after removing cwd"
3933         $TRACE ls .. || error "'ls ..' failed after removing cwd"
3934         is_patchless || ( $TRACE cd . &&
3935                         error "'cd .' worked after removing cwd" )
3936         $TRACE test_mkdir . && error "'mkdir .' worked after removing cwd"
3937         $TRACE rmdir . && error "'rmdir .' worked after removing cwd"
3938         $TRACE ln -s . foo && error "'ln -s .' worked after removing cwd"
3939         $TRACE cd .. || echo "'cd ..' failed after removing cwd `pwd`" #bug 3415
3940 }
3941 run_test 48c "Access removed working subdir (should return errors)"
3942
3943 test_48d() { # bug 2350
3944         #lctl set_param debug=-1
3945         #set -vx
3946         rm -rf $DIR/$tdir
3947         test_mkdir -p $DIR/$tdir/dir
3948         cd $DIR/$tdir/dir
3949         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3950         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3951         $TRACE touch foo && error "'touch foo' worked after removing parent"
3952         $TRACE test_mkdir foo && error "mkdir foo worked after removing parent"
3953         touch .foo && error "'touch .foo' worked after removing parent"
3954         test_mkdir .foo && error "mkdir .foo worked after removing parent"
3955         $TRACE ls . && error "'ls .' worked after removing parent"
3956         $TRACE ls .. && error "'ls ..' worked after removing parent"
3957         is_patchless || ( $TRACE cd . &&
3958                         error "'cd .' worked after recreate parent" )
3959         $TRACE test_mkdir . && error "'mkdir .' worked after removing parent"
3960         $TRACE rmdir . && error "'rmdir .' worked after removing parent"
3961         $TRACE ln -s . foo && error "'ln -s .' worked after removing parent"
3962         is_patchless || ( $TRACE cd .. &&
3963                         error "'cd ..' worked after removing parent" || true )
3964 }
3965 run_test 48d "Access removed parent subdir (should return errors)"
3966
3967 test_48e() { # bug 4134
3968         #lctl set_param debug=-1
3969         #set -vx
3970         rm -rf $DIR/$tdir
3971         test_mkdir -p $DIR/$tdir/dir
3972         cd $DIR/$tdir/dir
3973         $TRACE rmdir $DIR/$tdir/dir || error "remove cwd $DIR/$tdir/dir failed"
3974         $TRACE rmdir $DIR/$tdir || error "remove parent $DIR/$tdir failed"
3975         $TRACE touch $DIR/$tdir || error "'touch $DIR/$tdir' failed"
3976         $TRACE chmod +x $DIR/$tdir || error "'chmod +x $DIR/$tdir' failed"
3977         # On a buggy kernel addition of "touch foo" after cd .. will
3978         # produce kernel oops in lookup_hash_it
3979         touch ../foo && error "'cd ..' worked after recreate parent"
3980         cd $DIR
3981         $TRACE rm $DIR/$tdir || error "rm '$DIR/$tdir' failed"
3982 }
3983 run_test 48e "Access to recreated parent subdir (should return errors)"
3984
3985 test_49() { # LU-1030
3986         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
3987         # get ost1 size - lustre-OST0000
3988         ost1_size=$(do_facet ost1 $LFS df | grep ${ost1_svc} |
3989                 awk '{ print $4 }')
3990         # write 800M at maximum
3991         [[ $ost1_size -lt 2 ]] && ost1_size=2
3992         [[ $ost1_size -gt 819200 ]] && ost1_size=819200
3993
3994         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
3995         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((ost1_size >> 2)) &
3996         local dd_pid=$!
3997
3998         # change max_pages_per_rpc while writing the file
3999         local osc1_mppc=osc.$(get_osc_import_name client ost1).max_pages_per_rpc
4000         local orig_mppc=$($LCTL get_param -n $osc1_mppc)
4001         # loop until dd process exits
4002         while ps ax -opid | grep -wq $dd_pid; do
4003                 $LCTL set_param $osc1_mppc=$((RANDOM % 256 + 1))
4004                 sleep $((RANDOM % 5 + 1))
4005         done
4006         # restore original max_pages_per_rpc
4007         $LCTL set_param $osc1_mppc=$orig_mppc
4008         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
4009 }
4010 run_test 49 "Change max_pages_per_rpc won't break osc extent"
4011
4012 test_50() {
4013         # bug 1485
4014         test_mkdir $DIR/$tdir
4015         cd $DIR/$tdir
4016         ls /proc/$$/cwd || error "ls /proc/$$/cwd failed"
4017 }
4018 run_test 50 "special situations: /proc symlinks  ==============="
4019
4020 test_51a() {    # was test_51
4021         # bug 1516 - create an empty entry right after ".." then split dir
4022         test_mkdir -c1 $DIR/$tdir
4023         touch $DIR/$tdir/foo
4024         $MCREATE $DIR/$tdir/bar
4025         rm $DIR/$tdir/foo
4026         createmany -m $DIR/$tdir/longfile 201
4027         FNUM=202
4028         while [[ $(ls -sd $DIR/$tdir | awk '{ print $1 }') -eq 4 ]]; do
4029                 $MCREATE $DIR/$tdir/longfile$FNUM
4030                 FNUM=$(($FNUM + 1))
4031                 echo -n "+"
4032         done
4033         echo
4034         ls -l $DIR/$tdir > /dev/null || error "ls -l $DIR/$tdir failed"
4035 }
4036 run_test 51a "special situations: split htree with empty entry =="
4037
4038 export NUMTEST=70000
4039 test_51b() {
4040         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4041         local BASE=$DIR/d${base}.${TESTSUITE}
4042
4043         # cleanup the directory
4044         rm -fr $BASE
4045
4046         test_mkdir -p -c1 $BASE
4047
4048         $LFS df
4049         $LFS df -i
4050         local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
4051         local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
4052         [[ $numfree -lt 21000 ]] &&
4053                 skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
4054                 return
4055
4056         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
4057                 echo "reduced count to $NUMTEST due to inodes on MDT$mdtidx"
4058
4059         # need to check free space for the directories as well
4060         local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
4061         numfree=$((blkfree / 4))
4062         [[ $numfree -lt $NUMTEST ]] && NUMTEST=$((numfree - 50)) &&
4063                 echo "reduced count to $NUMTEST due to blocks on MDT$mdtidx"
4064
4065         createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
4066         {
4067                 $LFS df
4068                 $LFS df -i
4069                 echo "failed" > $BASE/fnum
4070                 error "failed to create $NUMTEST subdirs in MDT$mdtidx:$BASE"
4071         }
4072 }
4073 run_test 51b "exceed 64k subdirectory nlink limit"
4074
4075 test_51ba() { # LU-993
4076         local BASE=$DIR/d${base}.${TESTSUITE}
4077         # unlink all but 100 subdirectories, then check it still works
4078         local LEFT=100
4079         [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
4080
4081         [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
4082         local DELETE=$((NUMTEST - LEFT))
4083
4084         # continue on to run this test even if 51b didn't finish,
4085         # just to delete the many subdirectories created.
4086         [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
4087
4088         # for ldiskfs the nlink count should be 1, but this is OSD specific
4089         # and so this is listed for informational purposes only
4090         echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
4091         unlinkmany -d $BASE/d $DELETE
4092         RC=$?
4093
4094         if [ $RC -ne 0 ]; then
4095                 if [ "$NUMPREV" == "failed" ]; then
4096                         skip "previous setup failed"
4097                         return 0
4098                 else
4099                         error "unlink of first $DELETE subdirs failed"
4100                         return $RC
4101                 fi
4102         fi
4103
4104         echo "nlink between: $(stat -c %h $BASE)"
4105         # trim the first line of ls output
4106         local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
4107         [ $FOUND -ne $LEFT ] &&
4108                 error "can't find subdirs: found only $FOUND/$LEFT"
4109
4110         unlinkmany -d $BASE/d $DELETE $LEFT ||
4111                 error "unlink of second $LEFT subdirs failed"
4112         # regardless of whether the backing filesystem tracks nlink accurately
4113         # or not, the nlink count shouldn't be more than "." and ".." here
4114         local AFTER=$(stat -c %h $BASE)
4115         [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
4116                 echo "nlink after: $AFTER"
4117 }
4118 run_test 51ba "verify nlink for many subdirectory cleanup"
4119
4120 test_51d() {
4121         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4122         [[ $OSTCOUNT -lt 3 ]] &&
4123                 skip_env "skipping test with few OSTs" && return
4124         test_mkdir -p $DIR/$tdir
4125         createmany -o $DIR/$tdir/t- 1000
4126         $GETSTRIPE $DIR/$tdir > $TMP/files
4127         for N in $(seq 0 $((OSTCOUNT - 1))); do
4128                 OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
4129                         END { printf("%0.0f", objs) }' $TMP/files)
4130                 OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
4131                         '($1 == '$N') { objs += 1 } \
4132                         END { printf("%0.0f", objs) }')
4133                 log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
4134         done
4135         unlinkmany $DIR/$tdir/t- 1000
4136
4137         NLAST=0
4138         for N in $(seq 1 $((OSTCOUNT - 1))); do
4139                 [[ ${OBJS[$N]} -lt $((${OBJS[$NLAST]} - 20)) ]] &&
4140                         error "OST $N has less objects vs OST $NLAST" \
4141                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4142                 [[ ${OBJS[$N]} -gt $((${OBJS[$NLAST]} + 20)) ]] &&
4143                         error "OST $N has less objects vs OST $NLAST" \
4144                               " (${OBJS[$N]} < ${OBJS[$NLAST]}"
4145
4146                 [[ ${OBJS0[$N]} -lt $((${OBJS0[$NLAST]} - 20)) ]] &&
4147                         error "OST $N has less #0 objects vs OST $NLAST" \
4148                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4149                 [[ ${OBJS0[$N]} -gt $((${OBJS0[$NLAST]} + 20)) ]] &&
4150                         error "OST $N has less #0 objects vs OST $NLAST" \
4151                               " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
4152                 NLAST=$N
4153         done
4154 }
4155 run_test 51d "check object distribution ===================="
4156
4157 test_51e() {
4158         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
4159                 skip "Only applicable to ldiskfs-based MDTs"
4160                 return
4161         fi
4162
4163         test_mkdir -c1 $DIR/$tdir       || error "create $tdir failed"
4164         test_mkdir -c1 $DIR/$tdir/d0    || error "create d0 failed"
4165
4166         touch $DIR/$tdir/d0/foo
4167         createmany -l $DIR/$tdir/d0/foo $DIR/$tdir/d0/f- 65001 &&
4168                 error "file exceed 65000 nlink limit!"
4169         unlinkmany $DIR/$tdir/d0/f- 65001
4170         return 0
4171 }
4172 run_test 51e "check file nlink limit"
4173
4174 test_52a() {
4175         [ -f $DIR/$tdir/foo ] && chattr -a $DIR/$tdir/foo
4176         test_mkdir -p $DIR/$tdir
4177         touch $DIR/$tdir/foo
4178         chattr +a $DIR/$tdir/foo || error "chattr +a failed"
4179         echo bar >> $DIR/$tdir/foo || error "append bar failed"
4180         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4181         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4182         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4183                                         error "link worked"
4184         echo foo >> $DIR/$tdir/foo || error "append foo failed"
4185         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4186         lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
4187                                                      error "lsattr"
4188         chattr -a $DIR/$tdir/foo || error "chattr -a failed"
4189         cp -r $DIR/$tdir /tmp/
4190         rm -fr $DIR/$tdir || error "cleanup rm failed"
4191 }
4192 run_test 52a "append-only flag test (should return errors) ====="
4193
4194 test_52b() {
4195         [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
4196         test_mkdir -p $DIR/$tdir
4197         touch $DIR/$tdir/foo
4198         chattr +i $DIR/$tdir/foo || error "chattr +i failed"
4199         cat test > $DIR/$tdir/foo && error "cat test worked"
4200         cp /etc/hosts $DIR/$tdir/foo && error "cp worked"
4201         rm -f $DIR/$tdir/foo 2>/dev/null && error "rm worked"
4202         link $DIR/$tdir/foo $DIR/$tdir/foo_link 2>/dev/null &&
4203                                         error "link worked"
4204         echo foo >> $DIR/$tdir/foo && error "echo worked"
4205         mrename $DIR/$tdir/foo $DIR/$tdir/foo_ren && error "rename worked"
4206         [ -f $DIR/$tdir/foo ] || error "$tdir/foo is not a file"
4207         [ -f $DIR/$tdir/foo_ren ] && error "$tdir/foo_ren is not a file"
4208         lsattr $DIR/$tdir/foo | egrep -q "^-+i[-e]+ $DIR/$tdir/foo" ||
4209                                                         error "lsattr"
4210         chattr -i $DIR/$tdir/foo || error "chattr failed"
4211
4212         rm -fr $DIR/$tdir || error "unable to remove $DIR/$tdir"
4213 }
4214 run_test 52b "immutable flag test (should return errors) ======="
4215
4216 test_53() {
4217         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4218         remote_mds_nodsh && skip "remote MDS with nodsh" && return
4219         remote_ost_nodsh && skip "remote OST with nodsh" && return
4220
4221         local param
4222         local param_seq
4223         local ostname
4224         local mds_last
4225         local mds_last_seq
4226         local ost_last
4227         local ost_last_seq
4228         local ost_last_id
4229         local ostnum
4230         local node
4231         local found=false
4232         local support_last_seq=true
4233
4234         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
4235                 support_last_seq=false
4236
4237         # only test MDT0000
4238         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS)
4239         local value
4240         for value in $(do_facet $SINGLEMDS \
4241                        $LCTL get_param osc.$mdtosc.prealloc_last_id) ; do
4242                 param=$(echo ${value[0]} | cut -d "=" -f1)
4243                 ostname=$(echo $param | cut -d "." -f2 | cut -d - -f 1-2)
4244
4245                 if $support_last_seq; then
4246                         param_seq=$(echo $param |
4247                                 sed -e s/prealloc_last_id/prealloc_last_seq/g)
4248                         mds_last_seq=$(do_facet $SINGLEMDS \
4249                                        $LCTL get_param -n $param_seq)
4250                 fi
4251                 mds_last=$(do_facet $SINGLEMDS $LCTL get_param -n $param)
4252
4253                 ostnum=$(index_from_ostuuid ${ostname}_UUID)
4254                 node=$(facet_active_host ost$((ostnum+1)))
4255                 param="obdfilter.$ostname.last_id"
4256                 for ost_last in $(do_node $node $LCTL get_param -n $param) ; do
4257                         echo "$ostname.last_id=$ost_last; MDS.last_id=$mds_last"
4258                         ost_last_id=$ost_last
4259
4260                         if $support_last_seq; then
4261                                 ost_last_id=$(echo $ost_last |
4262                                               awk -F':' '{print $2}' |
4263                                               sed -e "s/^0x//g")
4264                                 ost_last_seq=$(echo $ost_last |
4265                                                awk -F':' '{print $1}')
4266                                 [[ $ost_last_seq = $mds_last_seq ]] || continue
4267                         fi
4268
4269                         if [[ $ost_last_id != $mds_last ]]; then
4270                                 error "$ost_last_id != $mds_last"
4271                         else
4272                                 found=true
4273                                 break
4274                         fi
4275                 done
4276         done
4277         $found || error "can not match last_seq/last_id for $mdtosc"
4278         return 0
4279 }
4280 run_test 53 "verify that MDS and OSTs agree on pre-creation ===="
4281
4282 test_54a() {
4283         $SOCKETSERVER $DIR/socket ||
4284                 error "$SOCKETSERVER $DIR/socket failed: $?"
4285         $SOCKETCLIENT $DIR/socket ||
4286                 error "$SOCKETCLIENT $DIR/socket failed: $?"
4287         $MUNLINK $DIR/socket || error "$MUNLINK $DIR/socket failed: $?"
4288 }
4289 run_test 54a "unix domain socket test =========================="
4290
4291 test_54b() {
4292         f="$DIR/f54b"
4293         mknod $f c 1 3
4294         chmod 0666 $f
4295         dd if=/dev/zero of=$f bs=$(page_size) count=1
4296 }
4297 run_test 54b "char device works in lustre ======================"
4298
4299 find_loop_dev() {
4300         [ -b /dev/loop/0 ] && LOOPBASE=/dev/loop/
4301         [ -b /dev/loop0 ] && LOOPBASE=/dev/loop
4302         [ -z "$LOOPBASE" ] && echo "/dev/loop/0 and /dev/loop0 gone?" && return
4303
4304         for i in $(seq 3 7); do
4305                 losetup $LOOPBASE$i > /dev/null 2>&1 && continue
4306                 LOOPDEV=$LOOPBASE$i
4307                 LOOPNUM=$i
4308                 break
4309         done
4310 }
4311
4312 cleanup_54c() {
4313         loopdev="$DIR/loop54c"
4314
4315         trap 0
4316         $UMOUNT $DIR/$tdir || rc=$?
4317         losetup -d $loopdev || true
4318         losetup -d $LOOPDEV || true
4319         rm -rf $loopdev $DIR/$tfile $DIR/$tdir
4320         return $rc
4321 }
4322
4323 test_54c() {
4324         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4325         loopdev="$DIR/loop54c"
4326
4327         find_loop_dev
4328         [ -z "$LOOPNUM" ] && echo "couldn't find empty loop device" && return
4329         trap cleanup_54c EXIT
4330         mknod $loopdev b 7 $LOOPNUM
4331         echo "make a loop file system with $DIR/$tfile on $loopdev ($LOOPNUM)."
4332         dd if=/dev/zero of=$DIR/$tfile bs=$(get_page_size client) seek=1024 count=1 > /dev/null
4333         losetup $loopdev $DIR/$tfile ||
4334                 error "can't set up $loopdev for $DIR/$tfile"
4335         mkfs.ext2 $loopdev || error "mke2fs on $loopdev"
4336         test_mkdir -p $DIR/$tdir
4337         mount -t ext2 $loopdev $DIR/$tdir ||
4338                 error "error mounting $loopdev on $DIR/$tdir"
4339         dd if=/dev/zero of=$DIR/$tdir/tmp bs=$(get_page_size client) count=30 ||
4340                 error "dd write"
4341         df $DIR/$tdir
4342         dd if=$DIR/$tdir/tmp of=/dev/zero bs=$(get_page_size client) count=30 ||
4343                 error "dd read"
4344         cleanup_54c
4345 }
4346 run_test 54c "block device works in lustre ====================="
4347
4348 test_54d() {
4349         f="$DIR/f54d"
4350         string="aaaaaa"
4351         mknod $f p
4352         [ "$string" = $(echo $string > $f | cat $f) ] || error "$f != $string"
4353 }
4354 run_test 54d "fifo device works in lustre ======================"
4355
4356 test_54e() {
4357         f="$DIR/f54e"
4358         string="aaaaaa"
4359         cp -aL /dev/console $f
4360         echo $string > $f || error "echo $string to $f failed"
4361 }
4362 run_test 54e "console/tty device works in lustre ======================"
4363
4364 #The test_55 used to be iopen test and it was removed by bz#24037.
4365 #run_test 55 "check iopen_connect_dentry() ======================"
4366
4367 test_56a() {    # was test_56
4368         rm -rf $DIR/$tdir
4369         $SETSTRIPE -d $DIR
4370         test_mkdir -p $DIR/$tdir/dir
4371         NUMFILES=3
4372         NUMFILESx2=$(($NUMFILES * 2))
4373         for i in $(seq 1 $NUMFILES); do
4374                 touch $DIR/$tdir/file$i
4375                 touch $DIR/$tdir/dir/file$i
4376         done
4377
4378         # test lfs getstripe with --recursive
4379         FILENUM=$($GETSTRIPE --recursive $DIR/$tdir | grep -c obdidx)
4380         [[ $FILENUM -eq $NUMFILESx2 ]] ||
4381                 error "$GETSTRIPE --recursive: found $FILENUM, not $NUMFILESx2"
4382         FILENUM=$($GETSTRIPE $DIR/$tdir | grep -c obdidx)
4383         [[ $FILENUM -eq $NUMFILES ]] ||
4384                 error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
4385         echo "$GETSTRIPE --recursive passed."
4386
4387         # test lfs getstripe with file instead of dir
4388         FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
4389         [[ $FILENUM -eq 1 ]] ||
4390                 error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
4391         echo "$GETSTRIPE file1 passed."
4392
4393         #test lfs getstripe with --verbose
4394         [[ $($GETSTRIPE --verbose $DIR/$tdir |
4395                 grep -c lmm_magic) -eq $NUMFILES ]] ||
4396                 error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
4397         [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
4398                 rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
4399         echo "$GETSTRIPE --verbose passed."
4400
4401         #test lfs getstripe with --obd
4402         $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
4403                 grep -q "unknown obduuid" ||
4404                 error "$GETSTRIPE --obd wrong_uuid should return error message"
4405
4406         [[ $OSTCOUNT -lt 2 ]] &&
4407                 skip_env "skipping other $GETSTRIPE --obd test" && return
4408
4409         OSTIDX=1
4410         OBDUUID=$(ostuuid_from_index $OSTIDX)
4411         FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
4412         FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
4413         [[ $FOUND -eq $FILENUM ]] ||
4414                 error "$GETSTRIPE --obd wrong: found $FOUND, expected $FILENUM"
4415         [[ $($GETSTRIPE -r -v --obd $OBDUUID $DIR/$tdir |
4416                 sed '/^[         ]*'${OSTIDX}'[  ]/d' |
4417                 sed -n '/^[      ]*[0-9][0-9]*[  ]/p' | wc -l) -eq 0 ]] ||
4418                 error "$GETSTRIPE --obd: should not show file on other obd"
4419         echo "$GETSTRIPE --obd passed"
4420 }
4421 run_test 56a "check $GETSTRIPE"
4422
4423 NUMFILES=3
4424 NUMDIRS=3
4425 setup_56() {
4426         local LOCAL_NUMFILES="$1"
4427         local LOCAL_NUMDIRS="$2"
4428         local MKDIR_PARAMS="$3"
4429         local DIR_STRIPE_PARAMS="$4"
4430
4431         if [ ! -d "$TDIR" ] ; then
4432                 test_mkdir -p $DIR_STRIPE_PARAMS $TDIR
4433                 [ "$MKDIR_PARAMS" ] && $SETSTRIPE $MKDIR_PARAMS $TDIR
4434                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4435                         touch $TDIR/file$i
4436                 done
4437                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4438                         test_mkdir $DIR_STRIPE_PARAMS $TDIR/dir$i
4439                         for j in `seq 1 $LOCAL_NUMFILES` ; do
4440                                 touch $TDIR/dir$i/file$j
4441                         done
4442                 done
4443         fi
4444 }
4445
4446 setup_56_special() {
4447         LOCAL_NUMFILES=$1
4448         LOCAL_NUMDIRS=$2
4449         setup_56 $1 $2
4450         if [ ! -e "$TDIR/loop1b" ] ; then
4451                 for i in `seq 1 $LOCAL_NUMFILES` ; do
4452                         mknod $TDIR/loop${i}b b 7 $i
4453                         mknod $TDIR/null${i}c c 1 3
4454                         ln -s $TDIR/file1 $TDIR/link${i}l
4455                 done
4456                 for i in `seq 1 $LOCAL_NUMDIRS` ; do
4457                         mknod $TDIR/dir$i/loop${i}b b 7 $i
4458                         mknod $TDIR/dir$i/null${i}c c 1 3
4459                         ln -s $TDIR/dir$i/file1 $TDIR/dir$i/link${i}l
4460                 done
4461         fi
4462 }
4463
4464 test_56g() {
4465         $SETSTRIPE -d $DIR
4466
4467         TDIR=$DIR/${tdir}g
4468         setup_56 $NUMFILES $NUMDIRS
4469
4470         EXPECTED=$(($NUMDIRS + 2))
4471         # test lfs find with -name
4472         for i in $(seq 1 $NUMFILES) ; do
4473                 NUMS=$($LFIND -name "*$i" $TDIR | wc -l)
4474                 [ $NUMS -eq $EXPECTED ] ||
4475                         error "lfs find -name \"*$i\" $TDIR wrong: "\
4476                               "found $NUMS, expected $EXPECTED"
4477         done
4478 }
4479 run_test 56g "check lfs find -name ============================="
4480
4481 test_56h() {
4482         $SETSTRIPE -d $DIR
4483
4484         TDIR=$DIR/${tdir}g
4485         setup_56 $NUMFILES $NUMDIRS
4486
4487         EXPECTED=$(((NUMDIRS + 1) * (NUMFILES - 1) + NUMFILES))
4488         # test lfs find with ! -name
4489         for i in $(seq 1 $NUMFILES) ; do
4490                 NUMS=$($LFIND ! -name "*$i" $TDIR | wc -l)
4491                 [ $NUMS -eq $EXPECTED ] ||
4492                         error "lfs find ! -name \"*$i\" $TDIR wrong: "\
4493                               "found $NUMS, expected $EXPECTED"
4494         done
4495 }
4496 run_test 56h "check lfs find ! -name ============================="
4497
4498 test_56i() {
4499        tdir=${tdir}i
4500        test_mkdir -p $DIR/$tdir
4501        UUID=$(ostuuid_from_index 0 $DIR/$tdir)
4502        CMD="$LFIND -ost $UUID $DIR/$tdir"
4503        OUT=$($CMD)
4504        [ -z "$OUT" ] || error "\"$CMD\" returned directory '$OUT'"
4505 }
4506 run_test 56i "check 'lfs find -ost UUID' skips directories ======="
4507
4508 test_56j() {
4509         TDIR=$DIR/${tdir}g
4510         setup_56_special $NUMFILES $NUMDIRS
4511
4512         EXPECTED=$((NUMDIRS + 1))
4513         CMD="$LFIND -type d $TDIR"
4514         NUMS=$($CMD | wc -l)
4515         [ $NUMS -eq $EXPECTED ] ||
4516                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4517 }
4518 run_test 56j "check lfs find -type d ============================="
4519
4520 test_56k() {
4521         TDIR=$DIR/${tdir}g
4522         setup_56_special $NUMFILES $NUMDIRS
4523
4524         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4525         CMD="$LFIND -type f $TDIR"
4526         NUMS=$($CMD | wc -l)
4527         [ $NUMS -eq $EXPECTED ] ||
4528                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4529 }
4530 run_test 56k "check lfs find -type f ============================="
4531
4532 test_56l() {
4533         TDIR=$DIR/${tdir}g
4534         setup_56_special $NUMFILES $NUMDIRS
4535
4536         EXPECTED=$((NUMDIRS + NUMFILES))
4537         CMD="$LFIND -type b $TDIR"
4538         NUMS=$($CMD | wc -l)
4539         [ $NUMS -eq $EXPECTED ] ||
4540                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4541 }
4542 run_test 56l "check lfs find -type b ============================="
4543
4544 test_56m() {
4545         TDIR=$DIR/${tdir}g
4546         setup_56_special $NUMFILES $NUMDIRS
4547
4548         EXPECTED=$((NUMDIRS + NUMFILES))
4549         CMD="$LFIND -type c $TDIR"
4550         NUMS=$($CMD | wc -l)
4551         [ $NUMS -eq $EXPECTED ] ||
4552                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4553 }
4554 run_test 56m "check lfs find -type c ============================="
4555
4556 test_56n() {
4557         TDIR=$DIR/${tdir}g
4558         setup_56_special $NUMFILES $NUMDIRS
4559
4560         EXPECTED=$((NUMDIRS + NUMFILES))
4561         CMD="$LFIND -type l $TDIR"
4562         NUMS=$($CMD | wc -l)
4563         [ $NUMS -eq $EXPECTED ] ||
4564                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4565 }
4566 run_test 56n "check lfs find -type l ============================="
4567
4568 test_56o() {
4569         TDIR=$DIR/${tdir}o
4570         setup_56 $NUMFILES $NUMDIRS
4571         utime $TDIR/file1 > /dev/null || error "utime (1)"
4572         utime $TDIR/file2 > /dev/null || error "utime (2)"
4573         utime $TDIR/dir1 > /dev/null || error "utime (3)"
4574         utime $TDIR/dir2 > /dev/null || error "utime (4)"
4575         utime $TDIR/dir1/file1 > /dev/null || error "utime (5)"
4576         dd if=/dev/zero count=1 >> $TDIR/dir1/file1 && sync
4577
4578         EXPECTED=4
4579         NUMS=`$LFIND -mtime +0 $TDIR | wc -l`
4580         [ $NUMS -eq $EXPECTED ] || \
4581                 error "lfs find -mtime +0 $TDIR wrong: found $NUMS, expected $EXPECTED"
4582
4583         EXPECTED=12
4584         CMD="$LFIND -mtime 0 $TDIR"
4585         NUMS=$($CMD | wc -l)
4586         [ $NUMS -eq $EXPECTED ] ||
4587                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4588 }
4589 run_test 56o "check lfs find -mtime for old files =========================="
4590
4591 test_56p() {
4592         [ $RUNAS_ID -eq $UID ] &&
4593                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4594
4595         TDIR=$DIR/${tdir}p
4596         setup_56 $NUMFILES $NUMDIRS
4597
4598         chown $RUNAS_ID $TDIR/file* || error "chown $DIR/${tdir}g/file$i failed"
4599         EXPECTED=$NUMFILES
4600         CMD="$LFIND -uid $RUNAS_ID $TDIR"
4601         NUMS=$($CMD | wc -l)
4602         [ $NUMS -eq $EXPECTED ] || \
4603                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4604
4605         EXPECTED=$(((NUMFILES + 1) * NUMDIRS + 1))
4606         CMD="$LFIND ! -uid $RUNAS_ID $TDIR"
4607         NUMS=$($CMD | wc -l)
4608         [ $NUMS -eq $EXPECTED ] || \
4609                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4610 }
4611 run_test 56p "check lfs find -uid and ! -uid ==============================="
4612
4613 test_56q() {
4614         [ $RUNAS_ID -eq $UID ] &&
4615                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
4616
4617         TDIR=$DIR/${tdir}q
4618         setup_56 $NUMFILES $NUMDIRS
4619
4620         chgrp $RUNAS_GID $TDIR/file* || error "chown $TDIR/file$i failed"
4621
4622         EXPECTED=$NUMFILES
4623         CMD="$LFIND -gid $RUNAS_GID $TDIR"
4624         NUMS=$($CMD | wc -l)
4625         [ $NUMS -eq $EXPECTED ] ||
4626                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4627
4628         EXPECTED=$(( ($NUMFILES+1) * $NUMDIRS + 1))
4629         CMD="$LFIND ! -gid $RUNAS_GID $TDIR"
4630         NUMS=$($CMD | wc -l)
4631         [ $NUMS -eq $EXPECTED ] ||
4632                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4633 }
4634 run_test 56q "check lfs find -gid and ! -gid ==============================="
4635
4636 test_56r() {
4637         TDIR=$DIR/${tdir}r
4638         setup_56 $NUMFILES $NUMDIRS
4639
4640         EXPECTED=12
4641         CMD="$LFIND -size 0 -type f $TDIR"
4642         NUMS=$($CMD | wc -l)
4643         [ $NUMS -eq $EXPECTED ] ||
4644                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4645         EXPECTED=0
4646         CMD="$LFIND ! -size 0 -type f $TDIR"
4647         NUMS=$($CMD | wc -l)
4648         [ $NUMS -eq $EXPECTED ] ||
4649                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4650         echo "test" > $TDIR/$tfile
4651         echo "test2" > $TDIR/$tfile.2 && sync
4652         EXPECTED=1
4653         CMD="$LFIND -size 5 -type f $TDIR"
4654         NUMS=$($CMD | wc -l)
4655         [ $NUMS -eq $EXPECTED ] ||
4656                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4657         EXPECTED=1
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=2
4663         CMD="$LFIND -size +0 -type f $TDIR"
4664         NUMS=$($CMD | wc -l)
4665         [ $NUMS -eq $EXPECTED ] ||
4666                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4667         EXPECTED=2
4668         CMD="$LFIND ! -size -5 -type f $TDIR"
4669         NUMS=$($CMD | wc -l)
4670         [ $NUMS -eq $EXPECTED ] ||
4671                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4672         EXPECTED=12
4673         CMD="$LFIND -size -5 -type f $TDIR"
4674         NUMS=$($CMD | wc -l)
4675         [ $NUMS -eq $EXPECTED ] ||
4676                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4677 }
4678 run_test 56r "check lfs find -size works =========================="
4679
4680 test_56s() { # LU-611
4681         TDIR=$DIR/${tdir}s
4682         setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT"
4683
4684         if [[ $OSTCOUNT -gt 1 ]]; then
4685                 $SETSTRIPE -c 1 $TDIR/$tfile.{0,1,2,3}
4686                 ONESTRIPE=4
4687                 EXTRA=4
4688         else
4689                 ONESTRIPE=$(((NUMDIRS + 1) * NUMFILES))
4690                 EXTRA=0
4691         fi
4692
4693         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4694         CMD="$LFIND -stripe-count $OSTCOUNT -type f $TDIR"
4695         NUMS=$($CMD | wc -l)
4696         [ $NUMS -eq $EXPECTED ] || {
4697                 $GETSTRIPE -R $TDIR
4698                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4699         }
4700
4701         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + EXTRA))
4702         CMD="$LFIND -stripe-count +0 -type f $TDIR"
4703         NUMS=$($CMD | wc -l)
4704         [ $NUMS -eq $EXPECTED ] || {
4705                 $GETSTRIPE -R $TDIR
4706                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4707         }
4708
4709         EXPECTED=$ONESTRIPE
4710         CMD="$LFIND -stripe-count 1 -type f $TDIR"
4711         NUMS=$($CMD | wc -l)
4712         [ $NUMS -eq $EXPECTED ] || {
4713                 $GETSTRIPE -R $TDIR
4714                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4715         }
4716
4717         CMD="$LFIND -stripe-count -2 -type f $TDIR"
4718         NUMS=$($CMD | wc -l)
4719         [ $NUMS -eq $EXPECTED ] || {
4720                 $GETSTRIPE -R $TDIR
4721                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4722         }
4723
4724         EXPECTED=0
4725         CMD="$LFIND -stripe-count $((OSTCOUNT + 1)) -type f $TDIR"
4726         NUMS=$($CMD | wc -l)
4727         [ $NUMS -eq $EXPECTED ] || {
4728                 $GETSTRIPE -R $TDIR
4729                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4730         }
4731 }
4732 run_test 56s "check lfs find -stripe-count works"
4733
4734 test_56t() { # LU-611
4735         TDIR=$DIR/${tdir}t
4736         setup_56 $NUMFILES $NUMDIRS "-s 512k"
4737
4738         $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
4739
4740         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4741         CMD="$LFIND -stripe-size 512k -type f $TDIR"
4742         NUMS=$($CMD | wc -l)
4743         [ $NUMS -eq $EXPECTED ] ||
4744                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4745
4746         CMD="$LFIND -stripe-size +320k -type f $TDIR"
4747         NUMS=$($CMD | wc -l)
4748         [ $NUMS -eq $EXPECTED ] ||
4749                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4750
4751         EXPECTED=$(((NUMDIRS + 1) * NUMFILES + 4))
4752         CMD="$LFIND -stripe-size +200k -type f $TDIR"
4753         NUMS=$($CMD | wc -l)
4754         [ $NUMS -eq $EXPECTED ] ||
4755                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4756
4757         CMD="$LFIND -stripe-size -640k -type f $TDIR"
4758         NUMS=$($CMD | wc -l)
4759         [ $NUMS -eq $EXPECTED ] ||
4760                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4761
4762         EXPECTED=4
4763         CMD="$LFIND -stripe-size 256k -type f $TDIR"
4764         NUMS=$($CMD | wc -l)
4765         [ $NUMS -eq $EXPECTED ] ||
4766                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4767
4768         CMD="$LFIND -stripe-size -320k -type f $TDIR"
4769         NUMS=$($CMD | wc -l)
4770         [ $NUMS -eq $EXPECTED ] ||
4771                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4772
4773         EXPECTED=0
4774         CMD="$LFIND -stripe-size 1024k -type f $TDIR"
4775         NUMS=$($CMD | wc -l)
4776         [ $NUMS -eq $EXPECTED ] ||
4777                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4778 }
4779 run_test 56t "check lfs find -stripe-size works"
4780
4781 test_56u() { # LU-611
4782         TDIR=$DIR/${tdir}u
4783         setup_56 $NUMFILES $NUMDIRS "-i 0"
4784
4785         if [[ $OSTCOUNT -gt 1 ]]; then
4786                 $SETSTRIPE -i 1 $TDIR/$tfile.{0,1,2,3}
4787                 ONESTRIPE=4
4788         else
4789                 ONESTRIPE=0
4790         fi
4791
4792         EXPECTED=$(((NUMDIRS + 1) * NUMFILES))
4793         CMD="$LFIND -stripe-index 0 -type f $TDIR"
4794         NUMS=$($CMD | wc -l)
4795         [ $NUMS -eq $EXPECTED ] ||
4796                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4797
4798         EXPECTED=$ONESTRIPE
4799         CMD="$LFIND -stripe-index 1 -type f $TDIR"
4800         NUMS=$($CMD | wc -l)
4801         [ $NUMS -eq $EXPECTED ] ||
4802                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4803
4804         CMD="$LFIND ! -stripe-index 0 -type f $TDIR"
4805         NUMS=$($CMD | wc -l)
4806         [ $NUMS -eq $EXPECTED ] ||
4807                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4808
4809         EXPECTED=0
4810         # This should produce an error and not return any files
4811         CMD="$LFIND -stripe-index $OSTCOUNT -type f $TDIR"
4812         NUMS=$($CMD 2>/dev/null | wc -l)
4813         [ $NUMS -eq $EXPECTED ] ||
4814                 error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4815
4816         if [[ $OSTCOUNT -gt 1 ]]; then
4817                 EXPECTED=$(((NUMDIRS + 1) * NUMFILES + ONESTRIPE))
4818                 CMD="$LFIND -stripe-index 0,1 -type f $TDIR"
4819                 NUMS=$($CMD | wc -l)
4820                 [ $NUMS -eq $EXPECTED ] ||
4821                         error "\"$CMD\" wrong: found $NUMS, expected $EXPECTED"
4822         fi
4823 }
4824 run_test 56u "check lfs find -stripe-index works"
4825
4826 test_56v() {
4827     local MDT_IDX=0
4828
4829     TDIR=$DIR/${tdir}v
4830     rm -rf $TDIR
4831     setup_56 $NUMFILES $NUMDIRS
4832
4833     UUID=$(mdtuuid_from_index $MDT_IDX $TDIR)
4834     [ -z "$UUID" ] && error "mdtuuid_from_index cannot find MDT index $MDT_IDX"
4835
4836     for file in $($LFIND -mdt $UUID $TDIR); do
4837         file_mdt_idx=$($GETSTRIPE -M $file)
4838         [ $file_mdt_idx -eq $MDT_IDX ] ||
4839             error "'lfind -mdt $UUID' != 'getstripe -M' ($file_mdt_idx)"
4840     done
4841 }
4842 run_test 56v "check 'lfs find -mdt match with lfs getstripe -M' ======="
4843
4844 test_56w() {
4845         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" &&
4846                 return
4847         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
4848         TDIR=$DIR/${tdir}w
4849
4850     rm -rf $TDIR || error "remove $TDIR failed"
4851     setup_56 $NUMFILES $NUMDIRS "-c $OSTCOUNT" "-c1"
4852
4853     local stripe_size
4854     stripe_size=$($GETSTRIPE -S -d $TDIR) ||
4855         error "$GETSTRIPE -S -d $TDIR failed"
4856     stripe_size=${stripe_size%% *}
4857
4858     local file_size=$((stripe_size * OSTCOUNT))
4859     local file_num=$((NUMDIRS * NUMFILES + NUMFILES))
4860     local required_space=$((file_num * file_size))
4861     local free_space=$($LCTL get_param -n lov.$LOVNAME.kbytesavail)
4862     [[ $free_space -le $((required_space / 1024)) ]] &&
4863         skip_env "need at least $required_space bytes free space," \
4864                  "have $free_space kbytes" && return
4865
4866     local dd_bs=65536
4867     local dd_count=$((file_size / dd_bs))
4868
4869     # write data into the files
4870     local i
4871     local j
4872     local file
4873     for i in $(seq 1 $NUMFILES); do
4874         file=$TDIR/file$i
4875         yes | dd bs=$dd_bs count=$dd_count of=$file >/dev/null 2>&1 ||
4876             error "write data into $file failed"
4877     done
4878     for i in $(seq 1 $NUMDIRS); do
4879         for j in $(seq 1 $NUMFILES); do
4880             file=$TDIR/dir$i/file$j
4881             yes | dd bs=$dd_bs count=$dd_count of=$file \
4882                 >/dev/null 2>&1 ||
4883                 error "write data into $file failed"
4884         done
4885     done
4886
4887     local expected=-1
4888     [[ $OSTCOUNT -gt 1 ]] && expected=$((OSTCOUNT - 1))
4889
4890     # lfs_migrate file
4891     local cmd="$LFS_MIGRATE -y -c $expected $TDIR/file1"
4892     echo "$cmd"
4893     eval $cmd || error "$cmd failed"
4894
4895     check_stripe_count $TDIR/file1 $expected
4896
4897         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.90) ];
4898         then
4899                 # lfs_migrate file onto OST 0 if it is on OST 1, or onto
4900                 # OST 1 if it is on OST 0. This file is small enough to
4901                 # be on only one stripe.
4902                 file=$TDIR/migr_1_ost
4903                 dd bs=$dd_bs count=1 if=/dev/urandom of=$file >/dev/null 2>&1 ||
4904                         error "write data into $file failed"
4905                 local obdidx=$($LFS getstripe -i $file)
4906                 local oldmd5=$(md5sum $file)
4907                 local newobdidx=0
4908                 [[ $obdidx -eq 0 ]] && newobdidx=1
4909                 cmd="$LFS migrate -i $newobdidx $file"
4910                 echo $cmd
4911                 eval $cmd || error "$cmd failed"
4912                 local realobdix=$($LFS getstripe -i $file)
4913                 local newmd5=$(md5sum $file)
4914                 [[ $newobdidx -ne $realobdix ]] &&
4915                         error "new OST is different (was=$obdidx, wanted=$newobdidx, got=$realobdix)"
4916                 [[ "$oldmd5" != "$newmd5" ]] &&
4917                         error "md5sum differ: $oldmd5, $newmd5"
4918         fi
4919
4920     # lfs_migrate dir
4921     cmd="$LFS_MIGRATE -y -c $expected $TDIR/dir1"
4922     echo "$cmd"
4923     eval $cmd || error "$cmd failed"
4924
4925     for j in $(seq 1 $NUMFILES); do
4926         check_stripe_count $TDIR/dir1/file$j $expected
4927     done
4928
4929     # lfs_migrate works with lfs find
4930     cmd="$LFIND -stripe_count $OSTCOUNT -type f $TDIR |
4931          $LFS_MIGRATE -y -c $expected"
4932     echo "$cmd"
4933     eval $cmd || error "$cmd failed"
4934
4935     for i in $(seq 2 $NUMFILES); do
4936         check_stripe_count $TDIR/file$i $expected
4937     done
4938     for i in $(seq 2 $NUMDIRS); do
4939         for j in $(seq 1 $NUMFILES); do
4940             check_stripe_count $TDIR/dir$i/file$j $expected
4941         done
4942     done
4943 }
4944 run_test 56w "check lfs_migrate -c stripe_count works"
4945
4946 test_56x() {
4947         check_swap_layouts_support && return 0
4948         [[ $OSTCOUNT -lt 2 ]] &&
4949                 skip_env "need 2 OST, skipping test" && return
4950
4951         local dir0=$DIR/$tdir/$testnum
4952         test_mkdir -p $dir0 || error "creating dir $dir0"
4953
4954         local ref1=/etc/passwd
4955         local file1=$dir0/file1
4956
4957         $SETSTRIPE -c 2 $file1
4958         cp $ref1 $file1
4959         $LFS migrate -c 1 $file1 || error "migrate failed rc = $?"
4960         stripe=$($GETSTRIPE -c $file1)
4961         [[ $stripe == 1 ]] || error "stripe of $file1 is $stripe != 1"
4962         cmp $file1 $ref1 || error "content mismatch $file1 differs from $ref1"
4963
4964         # clean up
4965         rm -f $file1
4966 }
4967 run_test 56x "lfs migration support"
4968
4969 test_56y() {
4970         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
4971                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
4972                 return
4973
4974         local res=""
4975         local dir0=$DIR/$tdir/$testnum
4976         test_mkdir -p $dir0 || error "creating dir $dir0"
4977         local f1=$dir0/file1
4978         local f2=$dir0/file2
4979
4980         touch $f1 || error "creating std file $f1"
4981         $MULTIOP $f2 H2c || error "creating released file $f2"
4982
4983         # a directory can be raid0, so ask only for files
4984         res=$($LFIND $dir0 -L raid0 -type f | wc -l)
4985         [[ $res == 2 ]] || error "search raid0: found $res files != 2"
4986
4987         res=$($LFIND $dir0 \! -L raid0 -type f | wc -l)
4988         [[ $res == 0 ]] || error "search !raid0: found $res files != 0"
4989
4990         # only files can be released, so no need to force file search
4991         res=$($LFIND $dir0 -L released)
4992         [[ $res == $f2 ]] || error "search released: found $res != $f2"
4993
4994         res=$($LFIND $dir0 \! -L released)
4995         [[ $res == $f1 ]] || error "search !released: found $res != $f1"
4996
4997 }
4998 run_test 56y "lfs find -L raid0|released"
4999
5000 test_56z() { # LU-4824
5001         # This checks to make sure 'lfs find' continues after errors
5002         # There are two classes of errors that should be caught:
5003         # - If multiple paths are provided, all should be searched even if one
5004         #   errors out
5005         # - If errors are encountered during the search, it should not terminate
5006         #   early
5007         local i
5008         test_mkdir $DIR/$tdir
5009         for i in d{0..9}; do
5010                 test_mkdir $DIR/$tdir/$i
5011         done
5012         touch $DIR/$tdir/d{0..9}/$tfile
5013         $LFS find $DIR/non_existent_dir $DIR/$tdir &&
5014                 error "$LFS find did not return an error"
5015         # Make a directory unsearchable. This should NOT be the last entry in
5016         # directory order.  Arbitrarily pick the 6th entry
5017         chmod 700 $($LFS find $DIR/$tdir -type d | sed '6!d')
5018         local count=$($RUNAS $LFS find $DIR/non_existent $DIR/$tdir | wc -l)
5019         # The user should be able to see 10 directories and 9 files
5020         [ $count == 19 ] || error "$LFS find did not continue after error"
5021 }
5022 run_test 56z "lfs find should continue after an error"
5023
5024 test_56aa() { # LU-5937
5025         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5026
5027         mkdir $DIR/$tdir
5028         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
5029
5030         createmany -o $DIR/$tdir/striped_dir/${tfile}- 1024
5031         local dirs=$(lfs find --size +8k $DIR/$tdir/)
5032
5033         [ -n "$dirs" ] || error "lfs find --size wrong under striped dir"
5034 }
5035 run_test 56aa "lfs find --size under striped dir"
5036
5037 test_57a() {
5038         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5039         # note test will not do anything if MDS is not local
5040         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5041                 skip "Only applicable to ldiskfs-based MDTs"
5042                 return
5043         fi
5044
5045         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5046         local MNTDEV="osd*.*MDT*.mntdev"
5047         DEV=$(do_facet $SINGLEMDS lctl get_param -n $MNTDEV)
5048         [ -z "$DEV" ] && error "can't access $MNTDEV"
5049         for DEV in $(do_facet $SINGLEMDS lctl get_param -n $MNTDEV); do
5050                 do_facet $SINGLEMDS $DUMPE2FS -h $DEV > $TMP/t57a.dump ||
5051                         error "can't access $DEV"
5052                 DEVISIZE=$(awk '/Inode size:/ { print $3 }' $TMP/t57a.dump)
5053                 [[ $DEVISIZE -gt 128 ]] || error "inode size $DEVISIZE"
5054                 rm $TMP/t57a.dump
5055         done
5056 }
5057 run_test 57a "verify MDS filesystem created with large inodes =="
5058
5059 test_57b() {
5060         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5061         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
5062                 skip "Only applicable to ldiskfs-based MDTs"
5063                 return
5064         fi
5065
5066         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5067         local dir=$DIR/$tdir
5068
5069         local FILECOUNT=100
5070         local FILE1=$dir/f1
5071         local FILEN=$dir/f$FILECOUNT
5072
5073         rm -rf $dir || error "removing $dir"
5074         test_mkdir -p -c1 $dir || error "creating $dir"
5075         local mdtidx=$($LFS getstripe -M $dir)
5076         local mdtname=MDT$(printf %04x $mdtidx)
5077         local facet=mds$((mdtidx + 1))
5078
5079         echo "mcreating $FILECOUNT files"
5080         createmany -m $dir/f 1 $FILECOUNT || \
5081                 error "creating files in $dir"
5082
5083         # verify that files do not have EAs yet
5084         $GETSTRIPE $FILE1 2>&1 | grep -q "no stripe" || error "$FILE1 has an EA"
5085         $GETSTRIPE $FILEN 2>&1 | grep -q "no stripe" || error "$FILEN has an EA"
5086
5087         sync
5088         sleep 1
5089         df $dir  #make sure we get new statfs data
5090         local MDSFREE=$(do_facet $facet \
5091                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5092         local MDCFREE=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5093         echo "opening files to create objects/EAs"
5094         local FILE
5095         for FILE in `seq -f $dir/f%g 1 $FILECOUNT`; do
5096                 $OPENFILE -f O_RDWR $FILE > /dev/null 2>&1 || error "opening $FILE"
5097         done
5098
5099         # verify that files have EAs now
5100         $GETSTRIPE $FILE1 | grep -q "obdidx" || error "$FILE1 missing EA"
5101         $GETSTRIPE $FILEN | grep -q "obdidx" || error "$FILEN missing EA"
5102
5103         sleep 1  #make sure we get new statfs data
5104         df $dir
5105         local MDSFREE2=$(do_facet $facet \
5106                 lctl get_param -n osd*.*$mdtname.kbytesfree)
5107         local MDCFREE2=$(lctl get_param -n mdc.*$mdtname-mdc-*.kbytesfree)
5108         if [[ $MDCFREE2 -lt $((MDCFREE - 16)) ]]; then
5109                 if [ "$MDSFREE" != "$MDSFREE2" ]; then
5110                         error "MDC before $MDCFREE != after $MDCFREE2"
5111                 else
5112                         echo "MDC before $MDCFREE != after $MDCFREE2"
5113                         echo "unable to confirm if MDS has large inodes"
5114                 fi
5115         fi
5116         rm -rf $dir
5117 }
5118 run_test 57b "default LOV EAs are stored inside large inodes ==="
5119
5120 test_58() {
5121         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5122         [ -z "$(which wiretest 2>/dev/null)" ] &&
5123                         skip_env "could not find wiretest" && return
5124         wiretest
5125 }
5126 run_test 58 "verify cross-platform wire constants =============="
5127
5128 test_59() {
5129         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5130         echo "touch 130 files"
5131         createmany -o $DIR/f59- 130
5132         echo "rm 130 files"
5133         unlinkmany $DIR/f59- 130
5134         sync
5135         # wait for commitment of removal
5136         wait_delete_completed
5137 }
5138 run_test 59 "verify cancellation of llog records async ========="
5139
5140 TEST60_HEAD="test_60 run $RANDOM"
5141 test_60a() {
5142         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5143         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
5144         do_facet mgs "! which run-llog.sh &> /dev/null" &&
5145                 do_facet mgs "! ls run-llog.sh &> /dev/null" &&
5146                         skip_env "missing subtest run-llog.sh" && return
5147
5148         log "$TEST60_HEAD - from kernel mode"
5149         do_facet mgs "$LCTL set_param debug=warning; $LCTL dk > /dev/null"
5150         do_facet mgs sh run-llog.sh
5151         do_facet mgs $LCTL dk > $TMP/$tfile
5152
5153         # LU-6388: test llog_reader
5154         local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5155         llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5156         [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5157                         skip_env "missing llog_reader" && return
5158         local fstype=$(facet_fstype mgs)
5159         [ $fstype != ldiskfs -a $fstype != zfs ] &&
5160                 skip_env "Only for ldiskfs or zfs type mgs" && return
5161
5162         local mntpt=$(facet_mntpt mgs)
5163         local mgsdev=$(mgsdevname 1)
5164         local fid_list
5165         local fid
5166         local rec_list
5167         local rec
5168         local rec_type
5169         local obj_file
5170         local path
5171         local seq
5172         local oid
5173         local pass=true
5174
5175         #get fid and record list
5176         fid_list=($(awk '/9_sub.*record/ { print $NF }' /$TMP/$tfile |
5177                 tail -n 4))
5178         rec_list=($(awk '/9_sub.*record/ { print $((NF-3)) }' /$TMP/$tfile |
5179                 tail -n 4))
5180         #remount mgs as ldiskfs or zfs type
5181         stop mgs || error "stop mgs failed"
5182         mount_fstype mgs || error "remount mgs failed"
5183         for ((i = 0; i < ${#fid_list[@]}; i++)); do
5184                 fid=${fid_list[i]}
5185                 rec=${rec_list[i]}
5186                 seq=$(echo $fid | awk -F ':' '{ print $1 }' | sed -e "s/^0x//g")
5187                 oid=$(echo $fid | awk -F ':' '{ print $2 }' | sed -e "s/^0x//g")
5188                 oid=$((16#$oid))
5189
5190                 case $fstype in
5191                         ldiskfs )
5192                                 obj_file=$mntpt/O/$seq/d$((oid%32))/$oid ;;
5193                         zfs )
5194                                 obj_file=$mntpt/oi.$(($((16#$seq))&127))/$fid ;;
5195                 esac
5196                 echo "obj_file is $obj_file"
5197                 do_facet mgs $llog_reader $obj_file
5198
5199                 rec_type=$(do_facet mgs $llog_reader $obj_file | grep "type=" |
5200                         awk '{ print $3 }' | sed -e "s/^type=//g")
5201                 if [ $rec_type != $rec ]; then
5202                         echo "FAILED test_60a wrong record type $rec_type," \
5203                               "should be $rec"
5204                         pass=false
5205                         break
5206                 fi
5207
5208                 #check obj path if record type is LLOG_LOGID_MAGIC
5209                 if [ "$rec" == "1064553b" ]; then
5210                         path=$(do_facet mgs $llog_reader $obj_file |
5211                                 grep "path=" | awk '{ print $NF }' |
5212                                 sed -e "s/^path=//g")
5213                         if [ $obj_file != $mntpt/$path ]; then
5214                                 echo "FAILED test_60a wrong obj path" \
5215                                       "$montpt/$path, should be $obj_file"
5216                                 pass=false
5217                                 break
5218                         fi
5219                 fi
5220         done
5221         rm -f $TMP/$tfile
5222         #restart mgs before "error", otherwise it will block the next test
5223         stop mgs || error "stop mgs failed"
5224         start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "start mgs failed"
5225         $pass || error "test failed, see FAILED test_60a messages for specifics"
5226 }
5227 run_test 60a "llog_test run from kernel module and test llog_reader =========="
5228
5229 test_60b() { # bug 6411
5230         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5231         dmesg > $DIR/$tfile
5232         LLOG_COUNT=`dmesg | awk "/$TEST60_HEAD/{marker = 1; from_marker = 0;}
5233                                  /llog.test/ {
5234                                          if (marker)
5235                                                  from_marker++
5236                                          from_begin++
5237                                  }
5238                                  END {
5239                                          if (marker)
5240                                                  print from_marker
5241                                          else
5242                                                  print from_begin
5243                                  }"`
5244         [[ $LLOG_COUNT -gt 50 ]] &&
5245                 error "CDEBUG_LIMIT not limiting messages ($LLOG_COUNT)" || true
5246 }
5247 run_test 60b "limit repeated messages from CERROR/CWARN ========"
5248
5249 test_60c() {
5250         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5251         echo "create 5000 files"
5252         createmany -o $DIR/f60c- 5000
5253 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED  0x137
5254         lctl set_param fail_loc=0x80000137
5255         unlinkmany $DIR/f60c- 5000
5256         lctl set_param fail_loc=0
5257 }
5258 run_test 60c "unlink file when mds full"
5259
5260 test_60d() {
5261         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5262         SAVEPRINTK=$(lctl get_param -n printk)
5263
5264         # verify "lctl mark" is even working"
5265         MESSAGE="test message ID $RANDOM $$"
5266         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5267         dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
5268
5269         lctl set_param printk=0 || error "set lnet.printk failed"
5270         lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
5271         MESSAGE="new test message ID $RANDOM $$"
5272         # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
5273         $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
5274         dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
5275
5276         lctl set_param -n printk="$SAVEPRINTK"
5277 }
5278 run_test 60d "test printk console message masking"
5279
5280 test_60e() {
5281         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5282         touch $DIR/$tfile
5283 #define OBD_FAIL_MDS_LLOG_CREATE_FAILED2  0x15b
5284         do_facet mds1 lctl set_param fail_loc=0x15b
5285         rm $DIR/$tfile
5286 }
5287 run_test 60e "no space while new llog is being created"
5288
5289 test_61() {
5290         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5291         f="$DIR/f61"
5292         dd if=/dev/zero of=$f bs=$(page_size) count=1 || error "dd $f failed"
5293         cancel_lru_locks osc
5294         $MULTIOP $f OSMWUc || error "$MULTIOP $f failed"
5295         sync
5296 }
5297 run_test 61 "mmap() writes don't make sync hang ================"
5298
5299 # bug 2330 - insufficient obd_match error checking causes LBUG
5300 test_62() {
5301         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5302         f="$DIR/f62"
5303         echo foo > $f
5304         cancel_lru_locks osc
5305         lctl set_param fail_loc=0x405
5306         cat $f && error "cat succeeded, expect -EIO"
5307         lctl set_param fail_loc=0
5308 }
5309 # This test is now irrelevant (as of bug 10718 inclusion), we no longer
5310 # match every page all of the time.
5311 #run_test 62 "verify obd_match failure doesn't LBUG (should -EIO)"
5312
5313 # bug 2319 - oig_wait() interrupted causes crash because of invalid waitq.
5314 # Though this test is irrelevant anymore, it helped to reveal some
5315 # other grant bugs (LU-4482), let's keep it.
5316 test_63a() {   # was test_63
5317         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5318         MAX_DIRTY_MB=`lctl get_param -n osc.*.max_dirty_mb | head -n 1`
5319         for i in `seq 10` ; do
5320                 dd if=/dev/zero of=$DIR/f63 bs=8k &
5321                 sleep 5
5322                 kill $!
5323                 sleep 1
5324         done
5325
5326         rm -f $DIR/f63 || true
5327 }
5328 run_test 63a "Verify oig_wait interruption does not crash ======="
5329
5330 # bug 2248 - async write errors didn't return to application on sync
5331 # bug 3677 - async write errors left page locked
5332 test_63b() {
5333         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5334         debugsave
5335         lctl set_param debug=-1
5336
5337         # ensure we have a grant to do async writes
5338         dd if=/dev/zero of=$DIR/$tfile bs=4k count=1
5339         rm $DIR/$tfile
5340
5341         sync    # sync lest earlier test intercept the fail_loc
5342
5343         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
5344         lctl set_param fail_loc=0x80000406
5345         $MULTIOP $DIR/$tfile Owy && \
5346                 error "sync didn't return ENOMEM"
5347         sync; sleep 2; sync     # do a real sync this time to flush page
5348         lctl get_param -n llite.*.dump_page_cache | grep locked && \
5349                 error "locked page left in cache after async error" || true
5350         debugrestore
5351 }
5352 run_test 63b "async write errors should be returned to fsync ==="
5353
5354 test_64a () {
5355         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5356         df $DIR
5357         lctl get_param -n osc.*[oO][sS][cC][_-]*.cur* | grep "[0-9]"
5358 }
5359 run_test 64a "verify filter grant calculations (in kernel) ====="
5360
5361 test_64b () {
5362         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5363         sh oos.sh $MOUNT || error "oos.sh failed: $?"
5364 }
5365 run_test 64b "check out-of-space detection on client ==========="
5366
5367 test_64c() {
5368         $LCTL set_param osc.*OST0000-osc-[^mM]*.cur_grant_bytes=0
5369 }
5370 run_test 64c "verify grant shrink ========================------"
5371
5372 # bug 1414 - set/get directories' stripe info
5373 test_65a() {
5374         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5375         test_mkdir -p $DIR/$tdir
5376         touch $DIR/$tdir/f1
5377         $LVERIFY $DIR/$tdir $DIR/$tdir/f1 || error "lverify failed"
5378 }
5379 run_test 65a "directory with no stripe info ===================="
5380
5381 test_65b() {
5382         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5383         test_mkdir -p $DIR/$tdir
5384         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5385                                                 error "setstripe"
5386         touch $DIR/$tdir/f2
5387         $LVERIFY $DIR/$tdir $DIR/$tdir/f2 || error "lverify failed"
5388 }
5389 run_test 65b "directory setstripe -S $((STRIPESIZE * 2)) -i 0 -c 1"
5390
5391 test_65c() {
5392         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5393         if [[ $OSTCOUNT -gt 1 ]]; then
5394                 test_mkdir -p $DIR/$tdir
5395                 $SETSTRIPE -S $(($STRIPESIZE * 4)) -i 1 \
5396                         -c $(($OSTCOUNT - 1)) $DIR/$tdir || error "setstripe"
5397                 touch $DIR/$tdir/f3
5398                 $LVERIFY $DIR/$tdir $DIR/$tdir/f3 || error "lverify failed"
5399         fi
5400 }
5401 run_test 65c "directory setstripe -S $((STRIPESIZE*4)) -i 1 -c $((OSTCOUNT-1))"
5402
5403 test_65d() {
5404         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5405         test_mkdir -p $DIR/$tdir
5406         if [[ $STRIPECOUNT -le 0 ]]; then
5407                 sc=1
5408         elif [[ $STRIPECOUNT -gt 2000 ]]; then
5409 #LOV_MAX_STRIPE_COUNT is 2000
5410                 [[ $OSTCOUNT -gt 2000 ]] && sc=2000 || sc=$(($OSTCOUNT - 1))
5411         else
5412                 sc=$(($STRIPECOUNT - 1))
5413         fi
5414         $SETSTRIPE -S $STRIPESIZE -c $sc $DIR/$tdir || error "setstripe"
5415         touch $DIR/$tdir/f4 $DIR/$tdir/f5
5416         $LVERIFY $DIR/$tdir $DIR/$tdir/f4 $DIR/$tdir/f5 ||
5417                 error "lverify failed"
5418 }
5419 run_test 65d "directory setstripe -S $STRIPESIZE -c stripe_count"
5420
5421 test_65e() {
5422         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5423         test_mkdir -p $DIR/$tdir
5424
5425         $SETSTRIPE $DIR/$tdir || error "setstripe"
5426         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5427                                         error "no stripe info failed"
5428         touch $DIR/$tdir/f6
5429         $LVERIFY $DIR/$tdir $DIR/$tdir/f6 || error "lverify failed"
5430 }
5431 run_test 65e "directory setstripe defaults ======================="
5432
5433 test_65f() {
5434         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5435         test_mkdir -p $DIR/${tdir}f
5436         $RUNAS $SETSTRIPE $DIR/${tdir}f && error "setstripe succeeded" || true
5437 }
5438 run_test 65f "dir setstripe permission (should return error) ==="
5439
5440 test_65g() {
5441         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5442         test_mkdir -p $DIR/$tdir
5443         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5444                                                         error "setstripe"
5445         $SETSTRIPE -d $DIR/$tdir || error "setstripe"
5446         $GETSTRIPE -v $DIR/$tdir | grep "Default" ||
5447                 error "delete default stripe failed"
5448 }
5449 run_test 65g "directory setstripe -d ==========================="
5450
5451 test_65h() {
5452         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5453         test_mkdir -p $DIR/$tdir
5454         $SETSTRIPE -S $((STRIPESIZE * 2)) -i 0 -c 1 $DIR/$tdir ||
5455                                                         error "setstripe"
5456         test_mkdir -p $DIR/$tdir/dd1
5457         [ $($GETSTRIPE -c $DIR/$tdir) == $($GETSTRIPE -c $DIR/$tdir/dd1) ] ||
5458                 error "stripe info inherit failed"
5459 }
5460 run_test 65h "directory stripe info inherit ===================="
5461
5462 test_65i() { # bug6367
5463         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5464         $SETSTRIPE -S 65536 -c -1 $MOUNT
5465 }
5466 run_test 65i "set non-default striping on root directory (bug 6367)="
5467
5468 test_65ia() { # bug12836
5469         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5470         $GETSTRIPE $MOUNT || error "getstripe $MOUNT failed"
5471 }
5472 run_test 65ia "getstripe on -1 default directory striping"
5473
5474 test_65ib() { # bug12836
5475         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5476         $GETSTRIPE -v $MOUNT || error "getstripe -v $MOUNT failed"
5477 }
5478 run_test 65ib "getstripe -v on -1 default directory striping"
5479
5480 test_65ic() { # bug12836
5481         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5482         $LFS find -mtime -1 $MOUNT > /dev/null || error "find $MOUNT failed"
5483 }
5484 run_test 65ic "new find on -1 default directory striping"
5485
5486 test_65j() { # bug6367
5487         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5488         sync; sleep 1
5489         # if we aren't already remounting for each test, do so for this test
5490         if [ "$CLEANUP" = ":" -a "$I_MOUNTED" = "yes" ]; then
5491                 cleanup || error "failed to unmount"
5492                 setup
5493         fi
5494         $SETSTRIPE -d $MOUNT || error "setstripe failed"
5495 }
5496 run_test 65j "set default striping on root directory (bug 6367)="
5497
5498 test_65k() { # bug11679
5499         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5500         [[ $OSTCOUNT -lt 2 ]] && skip_env "too few OSTs" && return
5501         remote_mds_nodsh && skip "remote MDS with nodsh" && return
5502
5503     echo "Check OST status: "
5504     local MDS_OSCS=`do_facet $SINGLEMDS lctl dl |
5505               awk '/[oO][sS][cC].*md[ts]/ { print $4 }'`
5506
5507     for OSC in $MDS_OSCS; do
5508         echo $OSC "is activate"
5509         do_facet $SINGLEMDS lctl --device %$OSC activate
5510     done
5511
5512     mkdir -p $DIR/$tdir
5513     for INACTIVE_OSC in $MDS_OSCS; do
5514         echo "Deactivate: " $INACTIVE_OSC
5515         do_facet $SINGLEMDS lctl --device %$INACTIVE_OSC deactivate
5516         for STRIPE_OSC in $MDS_OSCS; do
5517             OST=`osc_to_ost $STRIPE_OSC`
5518             IDX=`do_facet $SINGLEMDS lctl get_param -n lov.*md*.target_obd |
5519                  awk -F: /$OST/'{ print $1 }' | head -n 1`
5520
5521             [ -f $DIR/$tdir/$IDX ] && continue
5522             echo "$SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX"
5523             $SETSTRIPE -i $IDX -c 1 $DIR/$tdir/$IDX
5524             RC=$?
5525             [ $RC -ne 0 ] && error "setstripe should have succeeded"
5526         done
5527         rm -f $DIR/$tdir/*
5528         echo $INACTIVE_OSC "is Activate."
5529         do_facet $SINGLEMDS lctl --device  %$INACTIVE_OSC activate
5530     done
5531 }
5532 run_test 65k "validate manual striping works properly with deactivated OSCs"
5533
5534 test_65l() { # bug 12836
5535         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5536         test_mkdir -p $DIR/$tdir/test_dir
5537         $SETSTRIPE -c -1 $DIR/$tdir/test_dir
5538         $LFS find -mtime -1 $DIR/$tdir >/dev/null
5539 }
5540 run_test 65l "lfs find on -1 stripe dir ========================"
5541
5542 # bug 2543 - update blocks count on client
5543 test_66() {
5544         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5545         COUNT=${COUNT:-8}
5546         dd if=/dev/zero of=$DIR/f66 bs=1k count=$COUNT
5547         sync; sync_all_data; sync; sync_all_data
5548         cancel_lru_locks osc
5549         BLOCKS=`ls -s $DIR/f66 | awk '{ print $1 }'`
5550         [ $BLOCKS -ge $COUNT ] || error "$DIR/f66 blocks $BLOCKS < $COUNT"
5551 }
5552 run_test 66 "update inode blocks count on client ==============="
5553
5554 LLOOP=
5555 LLITELOOPLOAD=
5556 cleanup_68() {
5557         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5558         trap 0
5559         if [ ! -z "$LLOOP" ]; then
5560                 if swapon -s | grep -q $LLOOP; then
5561                         swapoff $LLOOP || error "swapoff failed"
5562                 fi
5563
5564                 $LCTL blockdev_detach $LLOOP || error "detach failed"
5565                 rm -f $LLOOP
5566                 unset LLOOP
5567         fi
5568         if [ ! -z "$LLITELOOPLOAD" ]; then
5569                 rmmod llite_lloop
5570                 unset LLITELOOPLOAD
5571         fi
5572         rm -f $DIR/f68*
5573 }
5574
5575 meminfo() {
5576         awk '($1 == "'$1':") { print $2 }' /proc/meminfo
5577 }
5578
5579 swap_used() {
5580         swapon -s | awk '($1 == "'$1'") { print $4 }'
5581 }
5582
5583 # test case for lloop driver, basic function
5584 test_68a() {
5585         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5586         [ "$UID" != 0 ] && skip_env "must run as root" && return
5587         llite_lloop_enabled || \
5588                 { skip_env "llite_lloop module disabled" && return; }
5589
5590         trap cleanup_68 EXIT
5591
5592         if ! module_loaded llite_lloop; then
5593                 if load_module llite/llite_lloop; then
5594                         LLITELOOPLOAD=yes
5595                 else
5596                         skip_env "can't find module llite_lloop"
5597                         return
5598                 fi
5599         fi
5600
5601         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5602         dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
5603         $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
5604
5605         directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
5606         directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
5607
5608         cleanup_68
5609 }
5610 run_test 68a "lloop driver - basic test ========================"
5611
5612 # excercise swapping to lustre by adding a high priority swapfile entry
5613 # and then consuming memory until it is used.
5614 test_68b() {  # was test_68
5615         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5616         [ "$UID" != 0 ] && skip_env "must run as root" && return
5617         lctl get_param -n devices | grep -q obdfilter && \
5618                 skip "local OST" && return
5619
5620         grep -q llite_lloop /proc/modules
5621         [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
5622
5623         [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
5624                 skip "can't reliably test swap with TCP" && return
5625
5626         MEMTOTAL=`meminfo MemTotal`
5627         NR_BLOCKS=$((MEMTOTAL>>8))
5628         [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
5629
5630         LLOOP=$TMP/lloop.`date +%s`.`date +%N`
5631         dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
5632         mkswap $DIR/f68b
5633
5634         $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
5635
5636         trap cleanup_68 EXIT
5637
5638         swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
5639
5640         echo "before: `swapon -s | grep $LLOOP`"
5641         $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
5642         echo "after: `swapon -s | grep $LLOOP`"
5643         SWAPUSED=`swap_used $LLOOP`
5644
5645         cleanup_68
5646
5647         [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
5648 }
5649 run_test 68b "support swapping to Lustre ========================"
5650
5651 # bug5265, obdfilter oa2dentry return -ENOENT
5652 # #define OBD_FAIL_OST_ENOENT 0x217
5653 test_69() {
5654         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5655         remote_ost_nodsh && skip "remote OST with nodsh" && return
5656
5657         f="$DIR/$tfile"
5658         $SETSTRIPE -c 1 -i 0 $f
5659
5660         $DIRECTIO write ${f}.2 0 1 || error "directio write error"
5661
5662         do_facet ost1 lctl set_param fail_loc=0x217
5663         $TRUNCATE $f 1 # vmtruncate() will ignore truncate() error.
5664         $DIRECTIO write $f 0 2 && error "write succeeded, expect -ENOENT"
5665
5666         do_facet ost1 lctl set_param fail_loc=0
5667         $DIRECTIO write $f 0 2 || error "write error"
5668
5669         cancel_lru_locks osc
5670         $DIRECTIO read $f 0 1 || error "read error"
5671
5672         do_facet ost1 lctl set_param fail_loc=0x217
5673         $DIRECTIO read $f 1 1 && error "read succeeded, expect -ENOENT"
5674
5675         do_facet ost1 lctl set_param fail_loc=0
5676         rm -f $f
5677 }
5678 run_test 69 "verify oa2dentry return -ENOENT doesn't LBUG ======"
5679
5680 test_71() {
5681         test_mkdir -p $DIR/$tdir
5682         $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
5683         sh rundbench -C -D $DIR/$tdir 2 || error "dbench failed!"
5684 }
5685 run_test 71 "Running dbench on lustre (don't segment fault) ===="
5686
5687 test_72a() { # bug 5695 - Test that on 2.6 remove_suid works properly
5688         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5689         [ "$RUNAS_ID" = "$UID" ] &&
5690                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5691
5692         # Check that testing environment is properly set up. Skip if not
5693         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_GID $RUNAS || {
5694                 skip_env "User $RUNAS_ID does not exist - skipping"
5695                 return 0
5696         }
5697         touch $DIR/$tfile
5698         chmod 777 $DIR/$tfile
5699         chmod ug+s $DIR/$tfile
5700         $RUNAS dd if=/dev/zero of=$DIR/$tfile bs=512 count=1 ||
5701                 error "$RUNAS dd $DIR/$tfile failed"
5702         # See if we are still setuid/sgid
5703         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5704                 error "S/gid is not dropped on write"
5705         # Now test that MDS is updated too
5706         cancel_lru_locks mdc
5707         test -u $DIR/$tfile -o -g $DIR/$tfile &&
5708                 error "S/gid is not dropped on MDS"
5709         rm -f $DIR/$tfile
5710 }
5711 run_test 72a "Test that remove suid works properly (bug5695) ===="
5712
5713 test_72b() { # bug 24226 -- keep mode setting when size is not changing
5714         local perm
5715
5716         [ "$RUNAS_ID" = "$UID" ] && \
5717                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
5718         [ "$RUNAS_ID" -eq 0 ] && \
5719                 skip_env "RUNAS_ID = 0 -- skipping" && return
5720
5721         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5722         # Check that testing environment is properly set up. Skip if not
5723         FAIL_ON_ERROR=false check_runas_id_ret $RUNAS_ID $RUNAS_ID $RUNAS || {
5724                 skip_env "User $RUNAS_ID does not exist - skipping"
5725                 return 0
5726         }
5727         touch $DIR/${tfile}-f{g,u}
5728         test_mkdir $DIR/${tfile}-dg
5729         test_mkdir $DIR/${tfile}-du
5730         chmod 770 $DIR/${tfile}-{f,d}{g,u}
5731         chmod g+s $DIR/${tfile}-{f,d}g
5732         chmod u+s $DIR/${tfile}-{f,d}u
5733         for perm in 777 2777 4777; do
5734                 $RUNAS chmod $perm $DIR/${tfile}-fg && error "S/gid file allowed improper chmod to $perm"
5735                 $RUNAS chmod $perm $DIR/${tfile}-fu && error "S/uid file allowed improper chmod to $perm"
5736                 $RUNAS chmod $perm $DIR/${tfile}-dg && error "S/gid dir allowed improper chmod to $perm"
5737                 $RUNAS chmod $perm $DIR/${tfile}-du && error "S/uid dir allowed improper chmod to $perm"
5738         done
5739         true
5740 }
5741 run_test 72b "Test that we keep mode setting if without file data changed (bug 24226)"
5742
5743 # bug 3462 - multiple simultaneous MDC requests
5744 test_73() {
5745         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5746         test_mkdir $DIR/d73-1
5747         test_mkdir $DIR/d73-2
5748         multiop_bg_pause $DIR/d73-1/f73-1 O_c || return 1
5749         pid1=$!
5750
5751         lctl set_param fail_loc=0x80000129
5752         $MULTIOP $DIR/d73-1/f73-2 Oc &
5753         sleep 1
5754         lctl set_param fail_loc=0
5755
5756         $MULTIOP $DIR/d73-2/f73-3 Oc &
5757         pid3=$!
5758
5759         kill -USR1 $pid1
5760         wait $pid1 || return 1
5761
5762         sleep 25
5763
5764         $CHECKSTAT -t file $DIR/d73-1/f73-1 || return 4
5765         $CHECKSTAT -t file $DIR/d73-1/f73-2 || return 5
5766         $CHECKSTAT -t file $DIR/d73-2/f73-3 || return 6
5767
5768         rm -rf $DIR/d73-*
5769 }
5770 run_test 73 "multiple MDC requests (should not deadlock)"
5771
5772 test_74a() { # bug 6149, 6184
5773         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5774         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5775         #
5776         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5777         # will spin in a tight reconnection loop
5778         touch $DIR/f74a
5779         $LCTL set_param fail_loc=0x8000030e
5780         # get any lock that won't be difficult - lookup works.
5781         ls $DIR/f74a
5782         $LCTL set_param fail_loc=0
5783         rm -f $DIR/f74a
5784         true
5785 }
5786 run_test 74a "ldlm_enqueue freed-export error path, ls (shouldn't LBUG)"
5787
5788 test_74b() { # bug 13310
5789         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5790         #define OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT 0x30e
5791         #
5792         # very important to OR with OBD_FAIL_ONCE (0x80000000) -- otherwise it
5793         # will spin in a tight reconnection loop
5794         $LCTL set_param fail_loc=0x8000030e
5795         # get a "difficult" lock
5796         touch $DIR/f74b
5797         $LCTL set_param fail_loc=0
5798         rm -f $DIR/f74b
5799         true
5800 }
5801 run_test 74b "ldlm_enqueue freed-export error path, touch (shouldn't LBUG)"
5802
5803 test_74c() {
5804         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5805         #define OBD_FAIL_LDLM_NEW_LOCK
5806         $LCTL set_param fail_loc=0x319
5807         touch $DIR/$tfile && error "touch successful"
5808         $LCTL set_param fail_loc=0
5809         true
5810 }
5811 run_test 74c "ldlm_lock_create error path, (shouldn't LBUG)"
5812
5813 num_inodes() {
5814         awk '/lustre_inode_cache/ {print $2; exit}' /proc/slabinfo
5815 }
5816
5817 get_inode_slab_tunables() {
5818         awk '/lustre_inode_cache/ {print $9," ",$10," ",$11; exit}' /proc/slabinfo
5819 }
5820
5821 set_inode_slab_tunables() {
5822         echo "lustre_inode_cache $1" > /proc/slabinfo
5823 }
5824
5825 test_76() { # Now for bug 20433, added originally in bug 1443
5826         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5827         local SLAB_SETTINGS=`get_inode_slab_tunables`
5828         local CPUS=`getconf _NPROCESSORS_ONLN`
5829         # we cannot set limit below 1 which means 1 inode in each
5830         # per-cpu cache is still allowed
5831         set_inode_slab_tunables "1 1 0"
5832         cancel_lru_locks osc
5833         BEFORE_INODES=$(num_inodes)
5834         echo "before inodes: $BEFORE_INODES"
5835         local COUNT=1000
5836         [ "$SLOW" = "no" ] && COUNT=100
5837         for i in $(seq $COUNT); do
5838                 touch $DIR/$tfile
5839                 rm -f $DIR/$tfile
5840         done
5841         cancel_lru_locks osc
5842         AFTER_INODES=$(num_inodes)
5843         echo "after inodes: $AFTER_INODES"
5844         local wait=0
5845         while [[ $((AFTER_INODES-1*CPUS)) -gt $BEFORE_INODES ]]; do
5846                 sleep 2
5847                 AFTER_INODES=$(num_inodes)
5848                 wait=$((wait+2))
5849                 echo "wait $wait seconds inodes: $AFTER_INODES"
5850                 if [ $wait -gt 30 ]; then
5851                         error "inode slab grew from $BEFORE_INODES to $AFTER_INODES"
5852                 fi
5853         done
5854         set_inode_slab_tunables "$SLAB_SETTINGS"
5855 }
5856 run_test 76 "confirm clients recycle inodes properly ===="
5857
5858
5859 export ORIG_CSUM=""
5860 set_checksums()
5861 {
5862         # Note: in sptlrpc modes which enable its own bulk checksum, the
5863         # original crc32_le bulk checksum will be automatically disabled,
5864         # and the OBD_FAIL_OSC_CHECKSUM_SEND/OBD_FAIL_OSC_CHECKSUM_RECEIVE
5865         # will be checked by sptlrpc code against sptlrpc bulk checksum.
5866         # In this case set_checksums() will not be no-op, because sptlrpc
5867         # bulk checksum will be enabled all through the test.
5868
5869         [ "$ORIG_CSUM" ] || ORIG_CSUM=`lctl get_param -n osc.*.checksums | head -n1`
5870         lctl set_param -n osc.*.checksums $1
5871         return 0
5872 }
5873
5874 export ORIG_CSUM_TYPE="`lctl get_param -n osc.*osc-[^mM]*.checksum_type |
5875                         sed 's/.*\[\(.*\)\].*/\1/g' | head -n1`"
5876 CKSUM_TYPES=${CKSUM_TYPES:-"crc32 adler"}
5877 [ "$ORIG_CSUM_TYPE" = "crc32c" ] && CKSUM_TYPES="$CKSUM_TYPES crc32c"
5878 set_checksum_type()
5879 {
5880         lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
5881         log "set checksum type to $1"
5882         return 0
5883 }
5884 F77_TMP=$TMP/f77-temp
5885 F77SZ=8
5886 setup_f77() {
5887         dd if=/dev/urandom of=$F77_TMP bs=1M count=$F77SZ || \
5888                 error "error writing to $F77_TMP"
5889 }
5890
5891 test_77a() { # bug 10889
5892         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5893         $GSS && skip "could not run with gss" && return
5894         [ ! -f $F77_TMP ] && setup_f77
5895         set_checksums 1
5896         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ || error "dd error"
5897         set_checksums 0
5898         rm -f $DIR/$tfile
5899 }
5900 run_test 77a "normal checksum read/write operation"
5901
5902 test_77b() { # bug 10889
5903         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5904         $GSS && skip "could not run with gss" && return
5905         [ ! -f $F77_TMP ] && setup_f77
5906         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5907         $LCTL set_param fail_loc=0x80000409
5908         set_checksums 1
5909
5910         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ conv=sync ||
5911                 error "dd error: $?"
5912         $LCTL set_param fail_loc=0
5913
5914         for algo in $CKSUM_TYPES; do
5915                 cancel_lru_locks osc
5916                 set_checksum_type $algo
5917                 #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5918                 $LCTL set_param fail_loc=0x80000408
5919                 cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5920                 $LCTL set_param fail_loc=0
5921         done
5922         set_checksums 0
5923         set_checksum_type $ORIG_CSUM_TYPE
5924         rm -f $DIR/$tfile
5925 }
5926 run_test 77b "checksum error on client write, read"
5927
5928 test_77d() { # bug 10889
5929         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5930         $GSS && skip "could not run with gss" && return
5931         #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5932         $LCTL set_param fail_loc=0x80000409
5933         set_checksums 1
5934         $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5935                 error "direct write: rc=$?"
5936         $LCTL set_param fail_loc=0
5937         set_checksums 0
5938
5939         #define OBD_FAIL_OSC_CHECKSUM_RECEIVE    0x408
5940         $LCTL set_param fail_loc=0x80000408
5941         set_checksums 1
5942         cancel_lru_locks osc
5943         $DIRECTIO read $DIR/$tfile 0 $F77SZ $((1024 * 1024)) ||
5944                 error "direct read: rc=$?"
5945         $LCTL set_param fail_loc=0
5946         set_checksums 0
5947 }
5948 run_test 77d "checksum error on OST direct write, read"
5949
5950 test_77f() { # bug 10889
5951         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5952         $GSS && skip "could not run with gss" && return
5953         set_checksums 1
5954         for algo in $CKSUM_TYPES; do
5955                 cancel_lru_locks osc
5956                 set_checksum_type $algo
5957                 #define OBD_FAIL_OSC_CHECKSUM_SEND       0x409
5958                 $LCTL set_param fail_loc=0x409
5959                 $DIRECTIO write $DIR/$tfile 0 $F77SZ $((1024 * 1024)) &&
5960                         error "direct write succeeded"
5961                 $LCTL set_param fail_loc=0
5962         done
5963         set_checksum_type $ORIG_CSUM_TYPE
5964         set_checksums 0
5965 }
5966 run_test 77f "repeat checksum error on write (expect error)"
5967
5968 test_77g() { # bug 10889
5969         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5970         $GSS && skip "could not run with gss" && return
5971         remote_ost_nodsh && skip "remote OST with nodsh" && return
5972
5973         [ ! -f $F77_TMP ] && setup_f77
5974
5975         $SETSTRIPE -c 1 -i 0 $DIR/$tfile
5976         #define OBD_FAIL_OST_CHECKSUM_RECEIVE       0x21a
5977         do_facet ost1 lctl set_param fail_loc=0x8000021a
5978         set_checksums 1
5979         dd if=$F77_TMP of=$DIR/$tfile bs=1M count=$F77SZ ||
5980                 error "write error: rc=$?"
5981         do_facet ost1 lctl set_param fail_loc=0
5982         set_checksums 0
5983
5984         cancel_lru_locks osc
5985         #define OBD_FAIL_OST_CHECKSUM_SEND          0x21b
5986         do_facet ost1 lctl set_param fail_loc=0x8000021b
5987         set_checksums 1
5988         cmp $F77_TMP $DIR/$tfile || error "file compare failed"
5989         do_facet ost1 lctl set_param fail_loc=0
5990         set_checksums 0
5991 }
5992 run_test 77g "checksum error on OST write, read"
5993
5994 test_77i() { # bug 13805
5995         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
5996         $GSS && skip "could not run with gss" && return
5997         #define OBD_FAIL_OSC_CONNECT_CKSUM       0x40b
5998         lctl set_param fail_loc=0x40b
5999         remount_client $MOUNT
6000         lctl set_param fail_loc=0
6001         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
6002                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
6003                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
6004                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
6005         done
6006         remount_client $MOUNT
6007 }
6008 run_test 77i "client not supporting OSD_CONNECT_CKSUM"
6009
6010 test_77j() { # bug 13805
6011         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6012         $GSS && skip "could not run with gss" && return
6013         #define OBD_FAIL_OSC_CKSUM_ADLER_ONLY    0x40c
6014         lctl set_param fail_loc=0x40c
6015         remount_client $MOUNT
6016         lctl set_param fail_loc=0
6017         sleep 2 # wait async osc connect to finish
6018         for VALUE in `lctl get_param osc.*osc-[^mM]*.checksum_type`; do
6019                 PARAM=`echo ${VALUE[0]} | cut -d "=" -f1`
6020                 algo=`lctl get_param -n $PARAM | sed 's/.*\[\(.*\)\].*/\1/g'`
6021                 [ "$algo" = "adler" ] || error "algo set to $algo instead of adler"
6022         done
6023         remount_client $MOUNT
6024 }
6025 run_test 77j "client only supporting ADLER32"
6026
6027 [ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
6028 rm -f $F77_TMP
6029 unset F77_TMP
6030
6031 test_78() { # bug 10901
6032         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6033         remote_ost || { skip_env "local OST" && return; }
6034
6035         NSEQ=5
6036         F78SIZE=$(($(awk '/MemFree:/ { print $2 }' /proc/meminfo) / 1024))
6037         echo "MemFree: $F78SIZE, Max file size: $MAXFREE"
6038         MEMTOTAL=$(($(awk '/MemTotal:/ { print $2 }' /proc/meminfo) / 1024))
6039         echo "MemTotal: $MEMTOTAL"
6040
6041         # reserve 256MB of memory for the kernel and other running processes,
6042         # and then take 1/2 of the remaining memory for the read/write buffers.
6043         if [ $MEMTOTAL -gt 512 ] ;then
6044                 MEMTOTAL=$(((MEMTOTAL - 256 ) / 2))
6045         else
6046                 # for those poor memory-starved high-end clusters...
6047                 MEMTOTAL=$((MEMTOTAL / 2))
6048         fi
6049         echo "Mem to use for directio: $MEMTOTAL"
6050
6051         [[ $F78SIZE -gt $MEMTOTAL ]] && F78SIZE=$MEMTOTAL
6052         [[ $F78SIZE -gt 512 ]] && F78SIZE=512
6053         [[ $F78SIZE -gt $((MAXFREE / 1024)) ]] && F78SIZE=$((MAXFREE / 1024))
6054         SMALLESTOST=$($LFS df $DIR | grep OST | awk '{ print $4 }' | sort -n |
6055                 head -n1)
6056         echo "Smallest OST: $SMALLESTOST"
6057         [[ $SMALLESTOST -lt 10240 ]] &&
6058                 skip "too small OSTSIZE, useless to run large O_DIRECT test" && return 0
6059
6060         [[ $F78SIZE -gt $((SMALLESTOST * $OSTCOUNT / 1024 - 80)) ]] &&
6061                 F78SIZE=$((SMALLESTOST * $OSTCOUNT / 1024 - 80))
6062
6063         [ "$SLOW" = "no" ] && NSEQ=1 && [ $F78SIZE -gt 32 ] && F78SIZE=32
6064         echo "File size: $F78SIZE"
6065         $SETSTRIPE -c $OSTCOUNT $DIR/$tfile || error "setstripe failed"
6066         for i in $(seq 1 $NSEQ); do
6067                 FSIZE=$(($F78SIZE / ($NSEQ - $i + 1)))
6068                 echo directIO rdwr round $i of $NSEQ
6069                 $DIRECTIO rdwr $DIR/$tfile 0 $FSIZE 1048576||error "rdwr failed"
6070         done
6071
6072         rm -f $DIR/$tfile
6073 }
6074 run_test 78 "handle large O_DIRECT writes correctly ============"
6075
6076 test_79() { # bug 12743
6077         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6078         wait_delete_completed
6079
6080         BKTOTAL=$(calc_osc_kbytes kbytestotal)
6081         BKFREE=$(calc_osc_kbytes kbytesfree)
6082         BKAVAIL=$(calc_osc_kbytes kbytesavail)
6083
6084         STRING=`df -P $MOUNT | tail -n 1 | awk '{print $2","$3","$4}'`
6085         DFTOTAL=`echo $STRING | cut -d, -f1`
6086         DFUSED=`echo $STRING  | cut -d, -f2`
6087         DFAVAIL=`echo $STRING | cut -d, -f3`
6088         DFFREE=$(($DFTOTAL - $DFUSED))
6089
6090         ALLOWANCE=$((64 * $OSTCOUNT))
6091
6092         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
6093            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
6094                 error "df total($DFTOTAL) mismatch OST total($BKTOTAL)"
6095         fi
6096         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
6097            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
6098                 error "df free($DFFREE) mismatch OST free($BKFREE)"
6099         fi
6100         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
6101            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
6102                 error "df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
6103         fi
6104 }
6105 run_test 79 "df report consistency check ======================="
6106
6107 test_80() { # bug 10718
6108         remote_ost_nodsh && skip "remote OST with nodsh" && return
6109         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6110         # relax strong synchronous semantics for slow backends like ZFS
6111         local soc="obdfilter.*.sync_on_lock_cancel"
6112         local soc_old=$(do_facet ost1 lctl get_param -n $soc | head -n1)
6113         local hosts=
6114         if [ "$soc_old" != "never" -a "$(facet_fstype ost1)" != "ldiskfs" ]; then
6115                 hosts=$(for host in $(seq -f "ost%g" 1 $OSTCOUNT); do
6116                           facet_active_host $host; done | sort -u)
6117                 do_nodes $hosts lctl set_param $soc=never
6118         fi
6119
6120         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1M
6121         sync; sleep 1; sync
6122         local BEFORE=`date +%s`
6123         cancel_lru_locks osc
6124         local AFTER=`date +%s`
6125         local DIFF=$((AFTER-BEFORE))
6126         if [ $DIFF -gt 1 ] ; then
6127                 error "elapsed for 1M@1T = $DIFF"
6128         fi
6129
6130         [ -n "$hosts" ] && do_nodes $hosts lctl set_param $soc=$soc_old
6131
6132         rm -f $DIR/$tfile
6133 }
6134 run_test 80 "Page eviction is equally fast at high offsets too  ===="
6135
6136 test_81a() { # LU-456
6137         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6138         remote_ost_nodsh && skip "remote OST with nodsh" && return
6139         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6140         # MUST OR with the OBD_FAIL_ONCE (0x80000000)
6141         do_facet ost1 lctl set_param fail_loc=0x80000228
6142
6143         # write should trigger a retry and success
6144         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6145         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6146         RC=$?
6147         if [ $RC -ne 0 ] ; then
6148                 error "write should success, but failed for $RC"
6149         fi
6150 }
6151 run_test 81a "OST should retry write when get -ENOSPC ==============="
6152
6153 test_81b() { # LU-456
6154         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6155         remote_ost_nodsh && skip "remote OST with nodsh" && return
6156         # define OBD_FAIL_OST_MAPBLK_ENOSPC    0x228
6157         # Don't OR with the OBD_FAIL_ONCE (0x80000000)
6158         do_facet ost1 lctl set_param fail_loc=0x228
6159
6160         # write should retry several times and return -ENOSPC finally
6161         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
6162         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
6163         RC=$?
6164         ENOSPC=28
6165         if [ $RC -ne $ENOSPC ] ; then
6166                 error "dd should fail for -ENOSPC, but succeed."
6167         fi
6168 }
6169 run_test 81b "OST should return -ENOSPC when retry still fails ======="
6170
6171 test_82() { # LU-1031
6172         dd if=/dev/zero of=$DIR/$tfile bs=1M count=10
6173         local gid1=14091995
6174         local gid2=16022000
6175
6176         multiop_bg_pause $DIR/$tfile OG${gid1}_g${gid1}c || return 1
6177         local MULTIPID1=$!
6178         multiop_bg_pause $DIR/$tfile O_G${gid2}r10g${gid2}c || return 2
6179         local MULTIPID2=$!
6180         kill -USR1 $MULTIPID2
6181         sleep 2
6182         if [[ `ps h -o comm -p $MULTIPID2` == "" ]]; then
6183                 error "First grouplock does not block second one"
6184         else
6185                 echo "Second grouplock blocks first one"
6186         fi
6187         kill -USR1 $MULTIPID1
6188         wait $MULTIPID1
6189         wait $MULTIPID2
6190 }
6191 run_test 82 "Basic grouplock test ==============================="
6192
6193 test_99a() {
6194         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" &&
6195                 return
6196         test_mkdir -p $DIR/d99cvsroot
6197         chown $RUNAS_ID $DIR/d99cvsroot
6198         local oldPWD=$PWD       # bug 13584, use $TMP as working dir
6199         cd $TMP
6200
6201         $RUNAS cvs -d $DIR/d99cvsroot init || error "cvs init failed"
6202         cd $oldPWD
6203 }
6204 run_test 99a "cvs init ========================================="
6205
6206 test_99b() {
6207         [ -z "$(which cvs 2>/dev/null)" ] &&
6208                 skip_env "could not find cvs" && return
6209         [ ! -d $DIR/d99cvsroot ] && test_99a
6210         cd /etc/init.d
6211         # some versions of cvs import exit(1) when asked to import links or
6212         # files they can't read.  ignore those files.
6213         TOIGNORE=$(find . -type l -printf '-I %f\n' -o \
6214                         ! -perm +4 -printf '-I %f\n')
6215         $RUNAS cvs -d $DIR/d99cvsroot import -m "nomesg" $TOIGNORE \
6216                 d99reposname vtag rtag
6217 }
6218 run_test 99b "cvs import ======================================="
6219
6220 test_99c() {
6221         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6222         [ ! -d $DIR/d99cvsroot ] && test_99b
6223         cd $DIR
6224         test_mkdir -p $DIR/d99reposname
6225         chown $RUNAS_ID $DIR/d99reposname
6226         $RUNAS cvs -d $DIR/d99cvsroot co d99reposname
6227 }
6228 run_test 99c "cvs checkout ====================================="
6229
6230 test_99d() {
6231         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6232         [ ! -d $DIR/d99cvsroot ] && test_99c
6233         cd $DIR/d99reposname
6234         $RUNAS touch foo99
6235         $RUNAS cvs add -m 'addmsg' foo99
6236 }
6237 run_test 99d "cvs add =========================================="
6238
6239 test_99e() {
6240         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6241         [ ! -d $DIR/d99cvsroot ] && test_99c
6242         cd $DIR/d99reposname
6243         $RUNAS cvs update
6244 }
6245 run_test 99e "cvs update ======================================="
6246
6247 test_99f() {
6248         [ -z "$(which cvs 2>/dev/null)" ] && skip_env "could not find cvs" && return
6249         [ ! -d $DIR/d99cvsroot ] && test_99d
6250         cd $DIR/d99reposname
6251         $RUNAS cvs commit -m 'nomsg' foo99
6252     rm -fr $DIR/d99cvsroot
6253 }
6254 run_test 99f "cvs commit ======================================="
6255
6256 test_100() {
6257         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6258         [ "$NETTYPE" = tcp ] || \
6259                 { skip "TCP secure port test, not useful for NETTYPE=$NETTYPE" && \
6260                         return ; }
6261
6262         remote_ost_nodsh && skip "remote OST with nodsh" && return
6263         remote_mds_nodsh && skip "remote MDS with nodsh" && return
6264         remote_servers || \
6265                 { skip "useless for local single node setup" && return; }
6266
6267         netstat -tna | ( rc=1; while read PROT SND RCV LOCAL REMOTE STAT; do
6268                 [ "$PROT" != "tcp" ] && continue
6269                 RPORT=$(echo $REMOTE | cut -d: -f2)
6270                 [ "$RPORT" != "$ACCEPTOR_PORT" ] && continue
6271
6272                 rc=0
6273                 LPORT=`echo $LOCAL | cut -d: -f2`
6274                 if [ $LPORT -ge 1024 ]; then
6275                         echo "bad: $PROT $SND $RCV $LOCAL $REMOTE $STAT"
6276                         netstat -tna
6277                         error_exit "local: $LPORT > 1024, remote: $RPORT"
6278                 fi
6279         done
6280         [ "$rc" = 0 ] || error_exit "privileged port not found" )
6281 }
6282 run_test 100 "check local port using privileged port ==========="
6283
6284 function get_named_value()
6285 {
6286     local tag
6287
6288     tag=$1
6289     while read ;do
6290         line=$REPLY
6291         case $line in
6292         $tag*)
6293             echo $line | sed "s/^$tag[ ]*//"
6294             break
6295             ;;
6296         esac
6297     done
6298 }
6299
6300 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
6301                    awk '/^max_cached_mb/ { print $2 }')
6302
6303 cleanup_101a() {
6304         $LCTL set_param -n llite.*.max_cached_mb $CACHE_MAX
6305         trap 0
6306 }
6307
6308 test_101a() {
6309         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6310         [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
6311         local s
6312         local discard
6313         local nreads=10000
6314         local cache_limit=32
6315
6316         $LCTL set_param -n osc.*-osc*.rpc_stats 0
6317         trap cleanup_101a EXIT
6318         $LCTL set_param -n llite.*.read_ahead_stats 0
6319         $LCTL set_param -n llite.*.max_cached_mb $cache_limit
6320
6321         #
6322         # randomly read 10000 of 64K chunks from file 3x 32MB in size
6323         #
6324         echo "nreads: $nreads file size: $((cache_limit * 3))MB"
6325         $READS -f $DIR/$tfile -s$((cache_limit * 3192 * 1024)) -b65536 -C -n$nreads -t 180
6326
6327         discard=0
6328         for s in $($LCTL get_param -n llite.*.read_ahead_stats |
6329                 get_named_value 'read but discarded' | cut -d" " -f1); do
6330                         discard=$(($discard + $s))
6331         done
6332         cleanup_101a
6333
6334         if [[ $(($discard * 10)) -gt $nreads ]]; then
6335                 $LCTL get_param osc.*-osc*.rpc_stats
6336                 $LCTL get_param llite.*.read_ahead_stats
6337                 error "too many ($discard) discarded pages"
6338         fi
6339         rm -f $DIR/$tfile || true
6340 }
6341 run_test 101a "check read-ahead for random reads ================"
6342
6343 setup_test101bc() {
6344         test_mkdir -p $DIR/$tdir
6345         local STRIPE_SIZE=$1
6346         local FILE_LENGTH=$2
6347         STRIPE_OFFSET=0
6348
6349         local FILE_SIZE_MB=$((FILE_LENGTH / STRIPE_SIZE))
6350
6351         local list=$(comma_list $(osts_nodes))
6352         set_osd_param $list '' read_cache_enable 0
6353         set_osd_param $list '' writethrough_cache_enable 0
6354
6355         trap cleanup_test101bc EXIT
6356         # prepare the read-ahead file
6357         $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $OSTCOUNT $DIR/$tfile
6358
6359         dd if=/dev/zero of=$DIR/$tfile bs=$STRIPE_SIZE \
6360                                 count=$FILE_SIZE_MB 2> /dev/null
6361
6362 }
6363
6364 cleanup_test101bc() {
6365         trap 0
6366         rm -rf $DIR/$tdir
6367         rm -f $DIR/$tfile
6368
6369         local list=$(comma_list $(osts_nodes))
6370         set_osd_param $list '' read_cache_enable 1
6371         set_osd_param $list '' writethrough_cache_enable 1
6372 }
6373
6374 calc_total() {
6375         awk 'BEGIN{total=0}; {total+=$1}; END{print total}'
6376 }
6377
6378 ra_check_101() {
6379         local READ_SIZE=$1
6380         local STRIPE_SIZE=$2
6381         local FILE_LENGTH=$3
6382         local RA_INC=1048576
6383         local STRIDE_LENGTH=$((STRIPE_SIZE/READ_SIZE))
6384         local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
6385                              (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
6386         DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
6387                         get_named_value 'read but discarded' |
6388                         cut -d" " -f1 | calc_total)
6389         if [[ $DISCARD -gt $discard_limit ]]; then
6390                 $LCTL get_param llite.*.read_ahead_stats
6391                 error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
6392         else
6393                 echo "Read-ahead success for size ${READ_SIZE}"
6394         fi
6395 }
6396
6397 test_101b() {
6398         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6399         [[ $OSTCOUNT -lt 2 ]] &&
6400                 skip_env "skipping stride IO stride-ahead test" && return
6401         local STRIPE_SIZE=1048576
6402         local STRIDE_SIZE=$((STRIPE_SIZE*OSTCOUNT))
6403         if [ $SLOW == "yes" ]; then
6404                 local FILE_LENGTH=$((STRIDE_SIZE * 64))
6405         else
6406                 local FILE_LENGTH=$((STRIDE_SIZE * 8))
6407         fi
6408
6409         local ITERATION=$((FILE_LENGTH / STRIDE_SIZE))
6410
6411         # prepare the read-ahead file
6412         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6413         cancel_lru_locks osc
6414         for BIDX in 2 4 8 16 32 64 128 256
6415         do
6416                 local BSIZE=$((BIDX*4096))
6417                 local READ_COUNT=$((STRIPE_SIZE/BSIZE))
6418                 local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
6419                 local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
6420                 $LCTL set_param -n llite.*.read_ahead_stats 0
6421                 $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
6422                               -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
6423                 cancel_lru_locks osc
6424                 ra_check_101 $BSIZE $STRIPE_SIZE $FILE_LENGTH
6425         done
6426         cleanup_test101bc
6427         true
6428 }
6429 run_test 101b "check stride-io mode read-ahead ================="
6430
6431 test_101c() {
6432         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6433         local STRIPE_SIZE=1048576
6434         local FILE_LENGTH=$((STRIPE_SIZE*100))
6435         local nreads=10000
6436         local osc_rpc_stats
6437
6438         setup_test101bc $STRIPE_SIZE $FILE_LENGTH
6439
6440         cancel_lru_locks osc
6441         $LCTL set_param osc.*.rpc_stats 0
6442         $READS -f $DIR/$tfile -s$FILE_LENGTH -b65536 -n$nreads -t 180
6443         for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
6444                 local stats=$($LCTL get_param -n $osc_rpc_stats)
6445                 local lines=$(echo "$stats" | awk 'END {print NR;}')
6446                 local size
6447
6448                 if [ $lines -le 20 ]; then
6449                         continue
6450                 fi
6451                 for size in 1 2 4 8; do
6452                         local rpc=$(echo "$stats" |
6453                                     awk '($1 == "'$size':") {print $2; exit; }')
6454                         [ $rpc != 0 ] &&
6455                                 error "Small $((size*4))k read IO $rpc !"
6456                 done
6457                 echo "$osc_rpc_stats check passed!"
6458         done
6459         cleanup_test101bc
6460         true
6461 }
6462 run_test 101c "check stripe_size aligned read-ahead ================="
6463
6464 set_read_ahead() {
6465         $LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1
6466         $LCTL set_param -n llite.*.max_read_ahead_mb $1 > /dev/null 2>&1
6467 }
6468
6469 test_101d() {
6470         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6471         local file=$DIR/$tfile
6472         local sz_MB=${FILESIZE_101d:-500}
6473         local ra_MB=${READAHEAD_MB:-40}
6474
6475         local free_MB=$(($(df -P $DIR | tail -n 1 | awk '{ print $4 }') / 1024))
6476         [ $free_MB -lt $sz_MB ] &&
6477                 skip "Need free space ${sz_MB}M, have ${free_MB}M" && return
6478
6479         echo "Create test file $file size ${sz_MB}M, ${free_MB}M free"
6480         $SETSTRIPE -c -1 $file || error "setstripe failed"
6481
6482         dd if=/dev/zero of=$file bs=1M count=$sz_MB || error "dd failed"
6483         echo Cancel LRU locks on lustre client to flush the client cache
6484         cancel_lru_locks osc
6485
6486         echo Disable read-ahead
6487         local old_READAHEAD=$(set_read_ahead 0)
6488
6489         echo Reading the test file $file with read-ahead disabled
6490         local raOFF=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6491
6492         echo Cancel LRU locks on lustre client to flush the client cache
6493         cancel_lru_locks osc
6494         echo Enable read-ahead with ${ra_MB}MB
6495         set_read_ahead $ra_MB
6496
6497         echo Reading the test file $file with read-ahead enabled
6498         local raON=$(do_and_time "dd if=$file of=/dev/null bs=1M count=$sz_MB")
6499
6500         echo "read-ahead disabled time read $raOFF"
6501         echo "read-ahead enabled  time read $raON"
6502
6503         set_read_ahead $old_READAHEAD
6504         rm -f $file
6505         wait_delete_completed
6506
6507         [ $raOFF -le 1 -o $raON -lt $raOFF ] ||
6508                 error "readahead ${raON}s > no-readahead ${raOFF}s ${sz_MB}M"
6509 }
6510 run_test 101d "file read with and without read-ahead enabled"
6511
6512 test_101e() {
6513         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6514         local file=$DIR/$tfile
6515         local size_KB=500  #KB
6516         local count=100
6517         local bsize=1024
6518
6519         local free_KB=$(df -P $DIR | tail -n 1 | awk '{ print $4 }')
6520         local need_KB=$((count * size_KB))
6521         [[ $free_KB -le $need_KB ]] &&
6522                 skip_env "Need free space $need_KB, have $free_KB" && return
6523
6524         echo "Creating $count ${size_KB}K test files"
6525         for ((i = 0; i < $count; i++)); do
6526                 dd if=/dev/zero of=$file.$i bs=$bsize count=$size_KB 2>/dev/null
6527         done
6528
6529         echo "Cancel LRU locks on lustre client to flush the client cache"
6530         cancel_lru_locks osc
6531
6532         echo "Reset readahead stats"
6533         $LCTL set_param -n llite.*.read_ahead_stats 0
6534
6535         for ((i = 0; i < $count; i++)); do
6536                 dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
6537         done
6538
6539         local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6540                      get_named_value 'misses' | cut -d" " -f1 | calc_total)
6541
6542         for ((i = 0; i < $count; i++)); do
6543                 rm -rf $file.$i 2>/dev/null
6544         done
6545
6546         #10000 means 20% reads are missing in readahead
6547         [[ $miss -lt 10000 ]] ||  error "misses too much for small reads"
6548 }
6549 run_test 101e "check read-ahead for small read(1k) for small files(500k)"
6550
6551 cleanup_test101f() {
6552     trap 0
6553     $LCTL set_param -n llite.*.max_read_ahead_whole_mb $MAX_WHOLE_MB
6554     rm -rf $DIR/$tfile 2>/dev/null
6555 }
6556
6557 test_101f() {
6558         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6559     local file=$DIR/$tfile
6560     local nreads=1000
6561
6562     MAX_WHOLE_MB=$($LCTL get_param -n llite.*.max_read_ahead_whole_mb)
6563     $LCTL set_param -n llite.*.max_read_ahead_whole_mb 2
6564     dd if=/dev/zero of=${file} bs=2097152 count=1 2>/dev/null
6565     trap cleanup_test101f EXIT
6566
6567     echo Cancel LRU locks on lustre client to flush the client cache
6568     cancel_lru_locks osc
6569
6570     echo Reset readahead stats
6571     $LCTL set_param -n llite.*.read_ahead_stats 0
6572     # Random read in a 2M file, because max_read_ahead_whole_mb = 2M,
6573     # readahead should read in 2M file on second read, so only miss
6574     # 2 pages.
6575     echo Random 4K reads on 2M file for 1000 times
6576     $READS -f $file -s 2097152 -b 4096 -n $nreads
6577
6578     echo checking missing pages
6579     local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
6580           get_named_value 'misses' | cut -d" " -f1 | calc_total)
6581
6582     [ $miss -lt 3 ] || error "misses too much pages!"
6583     cleanup_test101f
6584 }
6585 run_test 101f "check read-ahead for max_read_ahead_whole_mb"
6586
6587 setup_test102() {
6588         test_mkdir -p $DIR/$tdir
6589         chown $RUNAS_ID $DIR/$tdir
6590         STRIPE_SIZE=65536
6591         STRIPE_OFFSET=1
6592         STRIPE_COUNT=$OSTCOUNT
6593         [[ $OSTCOUNT -gt 4 ]] && STRIPE_COUNT=4
6594
6595         trap cleanup_test102 EXIT
6596         cd $DIR
6597         $1 $SETSTRIPE -S $STRIPE_SIZE -i $STRIPE_OFFSET -c $STRIPE_COUNT $tdir
6598         cd $DIR/$tdir
6599         for num in 1 2 3 4; do
6600                 for count in $(seq 1 $STRIPE_COUNT); do
6601                         for idx in $(seq 0 $[$STRIPE_COUNT - 1]); do
6602                                 local size=`expr $STRIPE_SIZE \* $num`
6603                                 local file=file"$num-$idx-$count"
6604                                 $1 $SETSTRIPE -S $size -i $idx -c $count $file
6605                         done
6606                 done
6607         done
6608
6609         cd $DIR
6610         $1 $TAR cf $TMP/f102.tar $tdir --xattrs
6611 }
6612
6613 cleanup_test102() {
6614         trap 0
6615         rm -f $TMP/f102.tar
6616         rm -rf $DIR/d0.sanity/d102
6617 }
6618
6619 test_102a() {
6620         local testfile=$DIR/$tfile
6621
6622         touch $testfile
6623
6624         [ "$UID" != 0 ] && skip_env "must run as root" && return
6625         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep xattr)" ] &&
6626                 skip_env "must have user_xattr" && return
6627
6628         [ -z "$(which setfattr 2>/dev/null)" ] &&
6629                 skip_env "could not find setfattr" && return
6630
6631         echo "set/get xattr..."
6632         setfattr -n trusted.name1 -v value1 $testfile ||
6633                 error "setfattr -n trusted.name1=value1 $testfile failed"
6634         getfattr -n trusted.name1 $testfile 2> /dev/null |
6635           grep "trusted.name1=.value1" ||
6636                 error "$testfile missing trusted.name1=value1"
6637
6638         setfattr -n user.author1 -v author1 $testfile ||
6639                 error "setfattr -n user.author1=author1 $testfile failed"
6640         getfattr -n user.author1 $testfile 2> /dev/null |
6641           grep "user.author1=.author1" ||
6642                 error "$testfile missing trusted.author1=author1"
6643
6644         echo "listxattr..."
6645         setfattr -n trusted.name2 -v value2 $testfile ||
6646                 error "$testfile unable to set trusted.name2"
6647         setfattr -n trusted.name3 -v value3 $testfile ||
6648                 error "$testfile unable to set trusted.name3"
6649         [ $(getfattr -d -m "^trusted" $testfile 2> /dev/null |
6650             grep "trusted.name" | wc -l) -eq 3 ] ||
6651                 error "$testfile missing 3 trusted.name xattrs"
6652
6653         setfattr -n user.author2 -v author2 $testfile ||
6654                 error "$testfile unable to set user.author2"
6655         setfattr -n user.author3 -v author3 $testfile ||
6656                 error "$testfile unable to set user.author3"
6657         [ $(getfattr -d -m "^user" $testfile 2> /dev/null |
6658             grep "user.author" | wc -l) -eq 3 ] ||
6659                 error "$testfile missing 3 user.author xattrs"
6660
6661         echo "remove xattr..."
6662         setfattr -x trusted.name1 $testfile ||
6663                 error "$testfile error deleting trusted.name1"
6664         getfattr -d -m trusted $testfile 2> /dev/null | grep "trusted.name1" &&
6665                 error "$testfile did not delete trusted.name1 xattr"
6666
6667         setfattr -x user.author1 $testfile ||
6668                 error "$testfile error deleting user.author1"
6669         getfattr -d -m user $testfile 2> /dev/null | grep "user.author1" &&
6670                 error "$testfile did not delete trusted.name1 xattr"
6671
6672         # b10667: setting lustre special xattr be silently discarded
6673         echo "set lustre special xattr ..."
6674         setfattr -n "trusted.lov" -v "invalid value" $testfile ||
6675                 error "$testfile allowed setting trusted.lov"
6676 }
6677 run_test 102a "user xattr test =================================="
6678
6679 test_102b() {
6680         [ -z "$(which setfattr 2>/dev/null)" ] &&
6681                 skip_env "could not find setfattr" && return
6682
6683         # b10930: get/set/list trusted.lov xattr
6684         echo "get/set/list trusted.lov xattr ..."
6685         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6686         local testfile=$DIR/$tfile
6687         $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6688                 error "setstripe failed"
6689         local STRIPECOUNT=$($GETSTRIPE -c $testfile) ||
6690                 error "getstripe failed"
6691         getfattr -d -m "^trusted" $testfile 2>/dev/null | grep "trusted.lov" ||
6692                 error "can't get trusted.lov from $testfile"
6693
6694         local testfile2=${testfile}2
6695         local value=$(getfattr -n trusted.lov $testfile 2>/dev/null |
6696                         grep "trusted.lov" | sed -e 's/[^=]\+=//')
6697
6698         $MCREATE $testfile2
6699         setfattr -n trusted.lov -v $value $testfile2
6700         local stripe_size=$($GETSTRIPE -S $testfile2)
6701         local stripe_count=$($GETSTRIPE -c $testfile2)
6702         [[ $stripe_size -eq 65536 ]] ||
6703                 error "stripe size $stripe_size != 65536"
6704         [[ $stripe_count -eq $STRIPECOUNT ]] ||
6705                 error "stripe count $stripe_count != $STRIPECOUNT"
6706         rm -f $DIR/$tfile
6707 }
6708 run_test 102b "getfattr/setfattr for trusted.lov EAs ============"
6709
6710 test_102c() {
6711         [ -z "$(which setfattr 2>/dev/null)" ] &&
6712                 skip_env "could not find setfattr" && return
6713
6714         # b10930: get/set/list lustre.lov xattr
6715         echo "get/set/list lustre.lov xattr ..."
6716         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
6717         test_mkdir -p $DIR/$tdir
6718         chown $RUNAS_ID $DIR/$tdir
6719         local testfile=$DIR/$tdir/$tfile
6720         $RUNAS $SETSTRIPE -S 65536 -i 1 -c $OSTCOUNT $testfile ||
6721                 error "setstripe failed"
6722         local STRIPECOUNT=$($RUNAS $GETSTRIPE -c $testfile) ||
6723                 error "getstripe failed"
6724         $RUNAS getfattr -d -m "^lustre" $testfile 2> /dev/null | \
6725         grep "lustre.lov" || error "can't get lustre.lov from $testfile"
6726
6727         local testfile2=${testfile}2
6728         local value=`getfattr -n lustre.lov $testfile 2> /dev/null | \
6729                      grep "lustre.lov" |sed -e 's/[^=]\+=//'  `
6730
6731         $RUNAS $MCREATE $testfile2
6732         $RUNAS setfattr -n lustre.lov -v $value $testfile2
6733         local stripe_size=$($RUNAS $GETSTRIPE -S $testfile2)
6734         local stripe_count=$($RUNAS $GETSTRIPE -c $testfile2)
6735         [ $stripe_size -eq 65536 ] || error "stripe size $stripe_size != 65536"
6736         [ $stripe_count -eq $STRIPECOUNT ] ||
6737                 error "stripe count $stripe_count != $STRIPECOUNT"
6738 }
6739 run_test 102c "non-root getfattr/setfattr for lustre.lov EAs ==========="
6740
6741 compare_stripe_info1() {
6742         local stripe_index_all_zero=true
6743
6744         for num in 1 2 3 4; do
6745                 for count in $(seq 1 $STRIPE_COUNT); do
6746                         for offset in $(seq 0 $[$STRIPE_COUNT - 1]); do
6747                                 local size=$((STRIPE_SIZE * num))
6748                                 local file=file"$num-$offset-$count"
6749                                 stripe_size=$($LFS getstripe -S $PWD/$file)
6750                                 [[ $stripe_size -ne $size ]] &&
6751                                     error "$file: size $stripe_size != $size"
6752                                 stripe_count=$($LFS getstripe -c $PWD/$file)
6753                                 # allow fewer stripes to be created, ORI-601
6754                                 [[ $stripe_count -lt $(((3 * count + 3) / 4)) ]] &&
6755                                     error "$file: count $stripe_count != $count"
6756                                 stripe_index=$($LFS getstripe -i $PWD/$file)
6757                                 [[ $stripe_index -ne 0 ]] &&
6758                                         stripe_index_all_zero=false
6759                         done
6760                 done
6761         done
6762         $stripe_index_all_zero &&
6763                 error "all files are being extracted starting from OST index 0"
6764         return 0
6765 }
6766
6767 find_lustre_tar() {
6768         [ -n "$(which tar 2>/dev/null)" ] &&
6769                 strings $(which tar) | grep -q "lustre" && echo tar
6770 }
6771
6772 test_102d() {
6773         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6774         # b10930: tar test for trusted.lov xattr
6775         TAR=$(find_lustre_tar)
6776         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6777         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6778         setup_test102
6779         test_mkdir -p $DIR/d102d
6780         $TAR xf $TMP/f102.tar -C $DIR/d102d --xattrs
6781         cd $DIR/d102d/$tdir
6782         compare_stripe_info1
6783 }
6784 run_test 102d "tar restore stripe info from tarfile,not keep osts ==========="
6785
6786 test_102f() {
6787         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6788         # b10930: tar test for trusted.lov xattr
6789         TAR=$(find_lustre_tar)
6790         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6791         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6792         setup_test102
6793         test_mkdir -p $DIR/d102f
6794         cd $DIR
6795         $TAR cf - --xattrs $tdir | $TAR xf - --xattrs -C $DIR/d102f
6796         cd $DIR/d102f/$tdir
6797         compare_stripe_info1
6798 }
6799 run_test 102f "tar copy files, not keep osts ==========="
6800
6801 grow_xattr() {
6802         local xsize=${1:-1024}  # in bytes
6803         local file=$DIR/$tfile
6804
6805         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep xattr)" ] &&
6806                 skip "must have user_xattr" && return 0
6807         [ -z "$(which setfattr 2>/dev/null)" ] &&
6808                 skip_env "could not find setfattr" && return 0
6809         [ -z "$(which getfattr 2>/dev/null)" ] &&
6810                 skip_env "could not find getfattr" && return 0
6811
6812         touch $file
6813
6814         local value="$(generate_string $xsize)"
6815
6816         local xbig=trusted.big
6817         log "save $xbig on $file"
6818         setfattr -n $xbig -v $value $file ||
6819                 error "saving $xbig on $file failed"
6820
6821         local orig=$(get_xattr_value $xbig $file)
6822         [[ "$orig" != "$value" ]] && error "$xbig different after saving $xbig"
6823
6824         local xsml=trusted.sml
6825         log "save $xsml on $file"
6826         setfattr -n $xsml -v val $file || error "saving $xsml on $file failed"
6827
6828         local new=$(get_xattr_value $xbig $file)
6829         [[ "$new" != "$orig" ]] && error "$xbig different after saving $xsml"
6830
6831         log "grow $xsml on $file"
6832         setfattr -n $xsml -v "$value" $file ||
6833                 error "growing $xsml on $file failed"
6834
6835         new=$(get_xattr_value $xbig $file)
6836         [[ "$new" != "$orig" ]] && error "$xbig different after growing $xsml"
6837         log "$xbig still valid after growing $xsml"
6838
6839         rm -f $file
6840 }
6841
6842 test_102h() { # bug 15777
6843         grow_xattr 1024
6844 }
6845 run_test 102h "grow xattr from inside inode to external block"
6846
6847 test_102ha() {
6848         large_xattr_enabled || { skip "large_xattr disabled" && return; }
6849         grow_xattr $(max_xattr_size)
6850 }
6851 run_test 102ha "grow xattr from inside inode to external inode"
6852
6853 test_102i() { # bug 17038
6854         [ -z "$(which getfattr 2>/dev/null)" ] &&
6855                 skip "could not find getfattr" && return
6856         touch $DIR/$tfile
6857         ln -s $DIR/$tfile $DIR/${tfile}link
6858         getfattr -n trusted.lov $DIR/$tfile ||
6859                 error "lgetxattr on $DIR/$tfile failed"
6860         getfattr -h -n trusted.lov $DIR/${tfile}link 2>&1 |
6861                 grep -i "no such attr" ||
6862                 error "error for lgetxattr on $DIR/${tfile}link is not ENODATA"
6863         rm -f $DIR/$tfile $DIR/${tfile}link
6864 }
6865 run_test 102i "lgetxattr test on symbolic link ============"
6866
6867 test_102j() {
6868         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
6869         TAR=$(find_lustre_tar)
6870         [ -z "$TAR" ] && skip_env "lustre-aware tar is not installed" && return
6871         [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping N-stripe test" && return
6872         setup_test102 "$RUNAS"
6873         test_mkdir -p $DIR/d102j
6874         chown $RUNAS_ID $DIR/d102j
6875         $RUNAS $TAR xf $TMP/f102.tar -C $DIR/d102j --xattrs
6876         cd $DIR/d102j/$tdir
6877         compare_stripe_info1 "$RUNAS"
6878 }
6879 run_test 102j "non-root tar restore stripe info from tarfile, not keep osts ==="
6880
6881 test_102k() {
6882         [ -z "$(which setfattr 2>/dev/null)" ] &&
6883                 skip "could not find setfattr" && return
6884         touch $DIR/$tfile
6885         # b22187 just check that does not crash for regular file.
6886         setfattr -n trusted.lov $DIR/$tfile
6887         # b22187 'setfattr -n trusted.lov' should work as remove LOV EA for directories
6888         local test_kdir=$DIR/d102k
6889         test_mkdir $test_kdir
6890         local default_size=`$GETSTRIPE -S $test_kdir`
6891         local default_count=`$GETSTRIPE -c $test_kdir`
6892         local default_offset=`$GETSTRIPE -i $test_kdir`
6893         $SETSTRIPE -S 65536 -i 0 -c $OSTCOUNT $test_kdir ||
6894                 error 'dir setstripe failed'
6895         setfattr -n trusted.lov $test_kdir
6896         local stripe_size=`$GETSTRIPE -S $test_kdir`
6897         local stripe_count=`$GETSTRIPE -c $test_kdir`
6898         local stripe_offset=`$GETSTRIPE -i $test_kdir`
6899         [ $stripe_size -eq $default_size ] ||
6900                 error "stripe size $stripe_size != $default_size"
6901         [ $stripe_count -eq $default_count ] ||
6902                 error "stripe count $stripe_count != $default_count"
6903         [ $stripe_offset -eq $default_offset ] ||
6904                 error "stripe offset $stripe_offset != $default_offset"
6905         rm -rf $DIR/$tfile $test_kdir
6906 }
6907 run_test 102k "setfattr without parameter of value shouldn't cause a crash"
6908
6909 test_102l() {
6910         [ -z "$(which getfattr 2>/dev/null)" ] &&
6911                 skip "could not find getfattr" && return
6912
6913         # LU-532 trusted. xattr is invisible to non-root
6914         local testfile=$DIR/$tfile
6915
6916         touch $testfile
6917
6918         echo "listxattr as user..."
6919         chown $RUNAS_ID $testfile
6920         $RUNAS getfattr -d -m '.*' $testfile 2>&1 |
6921             grep -q "trusted" &&
6922                 error "$testfile trusted xattrs are user visible"
6923
6924         return 0;
6925 }
6926 run_test 102l "listxattr size test =================================="
6927
6928 test_102m() { # LU-3403 llite: error of listxattr when buffer is small
6929         local path=$DIR/$tfile
6930         touch $path
6931
6932         listxattr_size_check $path || error "listattr_size_check $path failed"
6933 }
6934 run_test 102m "Ensure listxattr fails on small bufffer ========"
6935
6936 cleanup_test102
6937
6938 getxattr() { # getxattr path name
6939         # Return the base64 encoding of the value of xattr name on path.
6940         local path=$1
6941         local name=$2
6942
6943         # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
6944         # file: $path
6945         # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6946         #
6947         # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
6948
6949         getfattr --absolute-names --encoding=base64 --name=$name $path |
6950                 awk -F= -v name=$name '$1 == name {
6951                         print substr($0, index($0, "=") + 1);
6952         }'
6953 }
6954
6955 test_102n() { # LU-4101 mdt: protect internal xattrs
6956         local file0=$DIR/$tfile.0
6957         local file1=$DIR/$tfile.1
6958         local xattr0=$TMP/$tfile.0
6959         local xattr1=$TMP/$tfile.1
6960         local name
6961         local value
6962
6963         [ -z "$(which setfattr 2>/dev/null)" ] &&
6964                 skip "could not find setfattr" && return
6965
6966         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
6967         then
6968                 skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
6969                 return
6970         fi
6971
6972         rm -rf $file0 $file1 $xattr0 $xattr1
6973         touch $file0 $file1
6974
6975         # Get 'before' xattrs of $file1.
6976         getfattr --absolute-names --dump --match=- $file1 > $xattr0
6977
6978         for name in lov lma lmv link fid version som hsm lfsck_namespace; do
6979                 # Try to copy xattr from $file0 to $file1.
6980                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
6981
6982                 setfattr --name=trusted.$name --value="$value" $file1 ||
6983                         error "setxattr 'trusted.$name' failed"
6984
6985                 # Try to set a garbage xattr.
6986                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
6987
6988                 setfattr --name=trusted.$name --value="$value" $file1 ||
6989                         error "setxattr 'trusted.$name' failed"
6990
6991                 # Try to remove the xattr from $file1. We don't care if this
6992                 # appears to succeed or fail, we just don't want there to be
6993                 # any changes or crashes.
6994                 setfattr --remove=$trusted.$name $file1 2> /dev/null
6995         done
6996
6997         if [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.6.50) ]
6998         then
6999                 name="lfsck_ns"
7000                 # Try to copy xattr from $file0 to $file1.
7001                 value=$(getxattr $file0 trusted.$name 2> /dev/null)
7002
7003                 setfattr --name=trusted.$name --value="$value" $file1 ||
7004                         error "setxattr 'trusted.$name' failed"
7005
7006                 # Try to set a garbage xattr.
7007                 value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
7008
7009                 setfattr --name=trusted.$name --value="$value" $file1 ||
7010                         error "setxattr 'trusted.$name' failed"
7011
7012                 # Try to remove the xattr from $file1. We don't care if this
7013                 # appears to succeed or fail, we just don't want there to be
7014                 # any changes or crashes.
7015                 setfattr --remove=$trusted.$name $file1 2> /dev/null
7016         fi
7017
7018         # Get 'after' xattrs of file1.
7019         getfattr --absolute-names --dump --match=- $file1 > $xattr1
7020
7021         if ! diff $xattr0 $xattr1; then
7022                 error "before and after xattrs of '$file1' differ"
7023         fi
7024
7025         rm -rf $file0 $file1 $xattr0 $xattr1
7026
7027         return 0
7028 }
7029 run_test 102n "silently ignore setxattr on internal trusted xattrs"
7030
7031 test_102p() { # LU-4703 setxattr did not check ownership
7032         local testfile=$DIR/$tfile
7033
7034         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.56) ] &&
7035                 skip "MDS needs to be at least 2.5.56" && return
7036
7037         touch $testfile
7038
7039         echo "setfacl as user..."
7040         $RUNAS setfacl -m "u:$RUNAS_ID:rwx" $testfile
7041         [ $? -ne 0 ] || error "setfacl by $RUNAS_ID was allowed on $testfile"
7042
7043         echo "setfattr as user..."
7044         setfacl -m "u:$RUNAS_ID:---" $testfile
7045         $RUNAS setfattr -x system.posix_acl_access $testfile
7046         [ $? -ne 0 ] || error "setfattr by $RUNAS_ID was allowed on $testfile"
7047 }
7048 run_test 102p "check setxattr(2) correctly fails without permission"
7049
7050 test_102q() {
7051         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
7052                 skip "MDS needs to be at least 2.6.92" && return
7053         orphan_linkea_check $DIR/$tfile || error "orphan_linkea_check"
7054 }
7055 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
7056
7057 test_102r() {
7058         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
7059                 skip "MDS needs to be at least 2.6.93" && return
7060         touch $DIR/$tfile || error "touch"
7061         setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
7062         getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
7063         rm $DIR/$tfile || error "rm"
7064
7065         #normal directory
7066         mkdir -p $DIR/$tdir || error "mkdir"
7067         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7068         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7069         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7070                 error "$testfile error deleting user.author1"
7071         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7072                 grep "user.$(basename $tdir)" &&
7073                 error "$tdir did not delete user.$(basename $tdir)"
7074         rmdir $DIR/$tdir || error "rmdir"
7075
7076         #striped directory
7077         test_mkdir -p $DIR/$tdir || error "make striped dir"
7078         setfattr -n user.$(basename $tdir) $DIR/$tdir || error "setfattr dir"
7079         getfattr -n user.$(basename $tdir) $DIR/$tdir || error "getfattr dir"
7080         setfattr -x user.$(basename $tdir) $DIR/$tdir ||
7081                 error "$testfile error deleting user.author1"
7082         getfattr -d -m user.$(basename $tdir) 2> /dev/null |
7083                 grep "user.$(basename $tdir)" &&
7084                 error "$tdir did not delete user.$(basename $tdir)"
7085         rmdir $DIR/$tdir || error "rm striped dir"
7086 }
7087 run_test 102r "set EAs with empty values"
7088
7089 run_acl_subtest()
7090 {
7091     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
7092     return $?
7093 }
7094
7095 test_103a() {
7096         [ "$UID" != 0 ] && skip_env "must run as root" && return
7097         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] &&
7098                 skip "must have acl enabled" && return
7099         [ -z "$(which setfacl 2>/dev/null)" ] &&
7100                 skip_env "could not find setfacl" && return
7101         $GSS && skip "could not run under gss" && return
7102
7103         gpasswd -a daemon bin                           # LU-5641
7104         do_facet $SINGLEMDS gpasswd -a daemon bin       # LU-5641
7105
7106         declare -a identity_old
7107
7108         for num in $(seq $MDSCOUNT); do
7109                 switch_identity $num true || identity_old[$num]=$?
7110         done
7111
7112         SAVE_UMASK=$(umask)
7113         umask 0022
7114         cd $DIR
7115
7116         echo "performing cp ..."
7117         run_acl_subtest cp || error "run_acl_subtest cp failed"
7118         echo "performing getfacl-noacl..."
7119         run_acl_subtest getfacl-noacl || error "getfacl-noacl test failed"
7120         echo "performing misc..."
7121         run_acl_subtest misc || error  "misc test failed"
7122         echo "performing permissions..."
7123         run_acl_subtest permissions || error "permissions failed"
7124         echo "performing setfacl..."
7125         run_acl_subtest setfacl || error  "setfacl test failed"
7126
7127         # inheritance test got from HP
7128         echo "performing inheritance..."
7129         cp $LUSTRE/tests/acl/make-tree . || error "cannot copy make-tree"
7130         chmod +x make-tree || error "chmod +x failed"
7131         run_acl_subtest inheritance || error "inheritance test failed"
7132         rm -f make-tree
7133
7134         echo "LU-974 ignore umask when acl is enabled..."
7135         run_acl_subtest 974 || error "LU-974 umask test failed"
7136         if [ $MDSCOUNT -ge 2 ]; then
7137                 run_acl_subtest 974_remote ||
7138                         error "LU-974 umask test failed under remote dir"
7139         fi
7140
7141         echo "LU-2561 newly created file is same size as directory..."
7142         if [ $(facet_fstype $SINGLEMDS) != "zfs" ]; then
7143                 run_acl_subtest 2561 || error "LU-2561 test failed"
7144         else
7145                 run_acl_subtest 2561_zfs || error "LU-2561 zfs test failed"
7146         fi
7147
7148         run_acl_subtest 4924 || error "LU-4924 test failed"
7149
7150         cd $SAVE_PWD
7151         umask $SAVE_UMASK
7152
7153         for num in $(seq $MDSCOUNT); do
7154                 if [ "${identity_old[$num]}" = 1 ]; then
7155                         switch_identity $num false || identity_old[$num]=$?
7156                 fi
7157         done
7158 }
7159 run_test 103a "acl test ========================================="
7160
7161 test_103b() {
7162         local noacl=false
7163         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
7164         local mountopts=$MDS_MOUNT_OPTS
7165
7166         if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then
7167                 noacl=true
7168         else
7169                 # stop the MDT
7170                 stop $SINGLEMDS || error "failed to stop MDT."
7171                 # remount the MDT
7172                 if [ -z "$MDS_MOUNT_OPTS" ]; then
7173                         MDS_MOUNT_OPTS="-o noacl"
7174                 else
7175                         MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
7176                 fi
7177                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7178                         error "failed to start MDT."
7179                 MDS_MOUNT_OPTS=$mountopts
7180         fi
7181
7182         touch $DIR/$tfile
7183         setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail"
7184
7185         if ! $noacl; then
7186                 # stop the MDT
7187                 stop $SINGLEMDS || error "failed to stop MDT."
7188                 # remount the MDT
7189                 start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS ||
7190                         error "failed to start MDT."
7191         fi
7192
7193         true
7194 }
7195 run_test 103b "MDS mount option 'noacl'"
7196
7197 test_103c() {
7198         mkdir -p $DIR/$tdir
7199         cp -rp $DIR/$tdir $DIR/$tdir.bak
7200
7201         [ -n "$(getfattr -d -m. $DIR/$tdir | grep posix_acl_default)" ] &&
7202                 error "$DIR/$tdir shouldn't contain default ACL"
7203         [ -n "$(getfattr -d -m. $DIR/$tdir.bak | grep posix_acl_default)" ] &&
7204                 error "$DIR/$tdir.bak shouldn't contain default ACL"
7205         true
7206 }
7207 run_test 103c "'cp -rp' won't set empty acl"
7208
7209 test_104a() {
7210         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7211         touch $DIR/$tfile
7212         lfs df || error "lfs df failed"
7213         lfs df -ih || error "lfs df -ih failed"
7214         lfs df -h $DIR || error "lfs df -h $DIR failed"
7215         lfs df -i $DIR || error "lfs df -i $DIR failed"
7216         lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
7217         lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
7218
7219         local OSC=$(lctl dl | grep OST0000-osc-[^M] | awk '{ print $4 }')
7220         lctl --device %$OSC deactivate
7221         lfs df || error "lfs df with deactivated OSC failed"
7222         lctl --device %$OSC activate
7223         # wait the osc back to normal
7224         wait_osc_import_state client ost FULL
7225
7226         lfs df || error "lfs df with reactivated OSC failed"
7227         rm -f $DIR/$tfile
7228 }
7229 run_test 104a "lfs df [-ih] [path] test ========================="
7230
7231 test_104b() {
7232         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7233         [ $RUNAS_ID -eq $UID ] &&
7234                 skip_env "RUNAS_ID = UID = $UID -- skipping" && return
7235         chmod 666 /dev/obd
7236         denied_cnt=$(($($RUNAS $LFS check servers 2>&1 |
7237                         grep "Permission denied" | wc -l)))
7238         if [ $denied_cnt -ne 0 ]; then
7239                 error "lfs check servers test failed"
7240         fi
7241 }
7242 run_test 104b "$RUNAS lfs check servers test ===================="
7243
7244 test_105a() {
7245         # doesn't work on 2.4 kernels
7246         touch $DIR/$tfile
7247         if $(flock_is_enabled); then
7248                 flocks_test 1 on -f $DIR/$tfile || error "fail flock on"
7249         else
7250                 flocks_test 1 off -f $DIR/$tfile || error "fail flock off"
7251         fi
7252         rm -f $DIR/$tfile
7253 }
7254 run_test 105a "flock when mounted without -o flock test ========"
7255
7256 test_105b() {
7257         touch $DIR/$tfile
7258         if $(flock_is_enabled); then
7259                 flocks_test 1 on -c $DIR/$tfile || error "fail flock on"
7260         else
7261                 flocks_test 1 off -c $DIR/$tfile || error "fail flock off"
7262         fi
7263         rm -f $DIR/$tfile
7264 }
7265 run_test 105b "fcntl when mounted without -o flock test ========"
7266
7267 test_105c() {
7268         touch $DIR/$tfile
7269         if $(flock_is_enabled); then
7270                 flocks_test 1 on -l $DIR/$tfile || error "fail flock on"
7271         else
7272                 flocks_test 1 off -l $DIR/$tfile || error "fail flock off"
7273         fi
7274         rm -f $DIR/$tfile
7275 }
7276 run_test 105c "lockf when mounted without -o flock test ========"
7277
7278 test_105d() { # bug 15924
7279         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7280         test_mkdir -p $DIR/$tdir
7281         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7282         #define OBD_FAIL_LDLM_CP_CB_WAIT  0x315
7283         $LCTL set_param fail_loc=0x80000315
7284         flocks_test 2 $DIR/$tdir
7285 }
7286 run_test 105d "flock race (should not freeze) ========"
7287
7288 test_105e() { # bug 22660 && 22040
7289         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
7290         touch $DIR/$tfile
7291         flocks_test 3 $DIR/$tfile
7292 }
7293 run_test 105e "Two conflicting flocks from same process ======="
7294
7295 test_106() { #bug 10921
7296         test_mkdir -p $DIR/$tdir
7297         $DIR/$tdir && error "exec $DIR/$tdir succeeded"
7298         chmod 777 $DIR/$tdir || error "chmod $DIR/$tdir failed"
7299 }
7300 run_test 106 "attempt exec of dir followed by chown of that dir"
7301
7302 test_107() {
7303         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7304         CDIR=`pwd`
7305         cd $DIR
7306
7307         local file=core
7308         rm -f $file
7309
7310         local save_pattern=$(sysctl -n kernel.core_pattern)
7311         local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
7312         sysctl -w kernel.core_pattern=$file
7313         sysctl -w kernel.core_uses_pid=0
7314
7315         ulimit -c unlimited
7316         sleep 60 &
7317         SLEEPPID=$!
7318
7319         sleep 1
7320
7321         kill -s 11 $SLEEPPID
7322         wait $SLEEPPID
7323         if [ -e $file ]; then
7324                 size=`stat -c%s $file`
7325                 [ $size -eq 0 ] && error "Fail to create core file $file"
7326         else
7327                 error "Fail to create core file $file"
7328         fi
7329         rm -f $file
7330         sysctl -w kernel.core_pattern=$save_pattern
7331         sysctl -w kernel.core_uses_pid=$save_uses_pid
7332         cd $CDIR
7333 }
7334 run_test 107 "Coredump on SIG"
7335
7336 test_110() {
7337         test_mkdir -p $DIR/$tdir
7338         test_mkdir $DIR/$tdir/$(str_repeat 'a' 255) ||
7339                 error "mkdir with 255 char failed"
7340         test_mkdir $DIR/$tdir/$(str_repeat 'b' 256) &&
7341                 error "mkdir with 256 char should fail, but did not"
7342         touch $DIR/$tdir/$(str_repeat 'x' 255) ||
7343                 error "create with 255 char failed"
7344         touch $DIR/$tdir/$(str_repeat 'y' 256) &&
7345                 error "create with 256 char should fail, but did not"
7346
7347         ls -l $DIR/$tdir
7348         rm -rf $DIR/$tdir
7349 }
7350 run_test 110 "filename length checking"
7351
7352 test_115() {
7353         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7354         OSTIO_pre=$(ps -e | grep ll_ost_io | awk '{ print $4 }'| sort -n |
7355                 tail -1 | cut -c11-20)
7356         [ -z "$OSTIO_pre" ] && skip "no OSS threads" && return
7357         echo "Starting with $OSTIO_pre threads"
7358
7359         NUMTEST=20000
7360         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
7361         [[ $NUMFREE -lt $NUMTEST ]] && NUMTEST=$(($NUMFREE - 1000))
7362         echo "$NUMTEST creates/unlinks"
7363         test_mkdir -p $DIR/$tdir
7364         createmany -o $DIR/$tdir/$tfile $NUMTEST
7365         unlinkmany $DIR/$tdir/$tfile $NUMTEST
7366
7367         OSTIO_post=$(ps -e | grep ll_ost_io | awk '{ print $4 }' | sort -n |
7368                 tail -1 | cut -c11-20)
7369
7370         # don't return an error
7371         [ $OSTIO_post == $OSTIO_pre ] && echo \
7372             "WARNING: No new ll_ost_io threads were created ($OSTIO_pre)" &&
7373             echo "This may be fine, depending on what ran before this test" &&
7374             echo "and how fast this system is." && return
7375
7376         echo "Started with $OSTIO_pre threads, ended with $OSTIO_post"
7377 }
7378 run_test 115 "verify dynamic thread creation===================="
7379
7380 free_min_max () {
7381         wait_delete_completed
7382         AVAIL=($(lctl get_param -n osc.*[oO][sS][cC]-[^M]*.kbytesavail))
7383         echo OST kbytes available: ${AVAIL[@]}
7384         MAXI=0; MAXV=${AVAIL[0]}
7385         MINI=0; MINV=${AVAIL[0]}
7386         for ((i = 0; i < ${#AVAIL[@]}; i++)); do
7387                 #echo OST $i: ${AVAIL[i]}kb
7388                 if [[ ${AVAIL[i]} -gt $MAXV ]]; then
7389                         MAXV=${AVAIL[i]}; MAXI=$i
7390                 fi
7391                 if [[ ${AVAIL[i]} -lt $MINV ]]; then
7392                         MINV=${AVAIL[i]}; MINI=$i
7393                 fi
7394         done
7395         echo Min free space: OST $MINI: $MINV
7396         echo Max free space: OST $MAXI: $MAXV
7397 }
7398
7399 test_116a() { # was previously test_116()
7400         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7401         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7402
7403         [[ $OSTCOUNT -lt 2 ]] && skip_env "$OSTCOUNT < 2 OSTs" && return
7404
7405         echo -n "Free space priority "
7406         do_facet $SINGLEMDS lctl get_param -n lo*.*-mdtlov.qos_prio_free |
7407                 head -n1
7408         declare -a AVAIL
7409         free_min_max
7410
7411         [ $MINV -eq 0 ] && skip "no free space in OST$MINI, skip" && return
7412         [ $MINV -gt 10000000 ] && skip "too much free space in OST$MINI, skip" \
7413                 && return
7414         trap simple_cleanup_common EXIT
7415
7416
7417         # Check if we need to generate uneven OSTs
7418         test_mkdir -p $DIR/$tdir/OST${MINI}
7419         local FILL=$(($MINV / 4))
7420         local DIFF=$(($MAXV - $MINV))
7421         local DIFF2=$(($DIFF * 100 / $MINV))
7422
7423         local threshold=$(do_facet $SINGLEMDS \
7424                 lctl get_param -n *.*MDT0000-mdtlov.qos_threshold_rr | head -n1)
7425         threshold=${threshold%%%}
7426         echo -n "Check for uneven OSTs: "
7427         echo -n "diff=${DIFF}KB (${DIFF2}%) must be > ${threshold}% ..."
7428
7429         if [[ $DIFF2 -gt $threshold ]]; then
7430                 echo "ok"
7431                 echo "Don't need to fill OST$MINI"
7432         else
7433                 # generate uneven OSTs. Write 2% over the QOS threshold value
7434                 echo "no"
7435                 DIFF=$(($threshold - $DIFF2 + 2))
7436                 DIFF2=$(( ($MINV * $DIFF)/100 ))
7437                 echo "Fill ${DIFF}% remaining space in OST${MINI} with ${DIFF2}KB"
7438                 $SETSTRIPE -i $MINI -c 1 $DIR/$tdir/OST${MINI} ||
7439                         error "setstripe failed"
7440                 DIFF=$(($DIFF2 / 2048))
7441                 i=0
7442                 while [ $i -lt $DIFF ]; do
7443                         i=$(($i + 1))
7444                         dd if=/dev/zero of=$DIR/$tdir/OST${MINI}/$tfile-$i \
7445                                 bs=2M count=1 2>/dev/null
7446                         echo -n .
7447                 done
7448                 echo .
7449                 sync
7450                 sleep_maxage
7451                 free_min_max
7452         fi
7453
7454         DIFF=$(($MAXV - $MINV))
7455         DIFF2=$(($DIFF * 100 / $MINV))
7456         echo -n "diff=${DIFF}=${DIFF2}% must be > ${threshold}% for QOS mode..."
7457         if [[ $DIFF2 -gt $threshold ]]; then
7458                 echo "ok"
7459         else
7460                 echo "failed - QOS mode won't be used"
7461                 skip "QOS imbalance criteria not met"
7462                 simple_cleanup_common
7463                 return
7464         fi
7465
7466         MINI1=$MINI; MINV1=$MINV
7467         MAXI1=$MAXI; MAXV1=$MAXV
7468
7469         # now fill using QOS
7470         $SETSTRIPE -c 1 $DIR/$tdir
7471         FILL=$(($FILL / 200))
7472         if [ $FILL -gt 600 ]; then
7473                 FILL=600
7474         fi
7475         echo "writing $FILL files to QOS-assigned OSTs"
7476         i=0
7477         while [ $i -lt $FILL ]; do
7478                 i=$((i + 1))
7479                 dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=200k \
7480                         count=1 2>/dev/null
7481                 echo -n .
7482         done
7483         echo "wrote $i 200k files"
7484         sync
7485         sleep_maxage
7486
7487         echo "Note: free space may not be updated, so measurements might be off"
7488         free_min_max
7489         DIFF2=$(($MAXV - $MINV))
7490         echo "free space delta: orig $DIFF final $DIFF2"
7491         [ $DIFF2 -gt $DIFF ] && echo "delta got worse!"
7492         DIFF=$(($MINV1 - ${AVAIL[$MINI1]}))
7493         echo "Wrote ${DIFF}KB to smaller OST $MINI1"
7494         DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
7495         echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
7496         FILL=$(($DIFF2 * 100 / $DIFF - 100))
7497         [ $DIFF -gt 0 ] &&
7498                 echo "Wrote ${FILL}% more data to larger OST $MAXI1"
7499
7500         # Figure out which files were written where
7501         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7502                   awk '/'$MINI1': / {print $2; exit}')
7503         echo $UUID
7504         MINC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7505         echo "$MINC files created on smaller OST $MINI1"
7506         UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
7507                   awk '/'$MAXI1': / {print $2; exit}')
7508         echo $UUID
7509         MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
7510         echo "$MAXC files created on larger OST $MAXI1"
7511         FILL=$(($MAXC * 100 / $MINC - 100))
7512         [[ $MINC -gt 0 ]] &&
7513                 echo "Wrote ${FILL}% more files to larger OST $MAXI1"
7514         [[ $MAXC -gt $MINC ]] ||
7515                 error_ignore LU-9 "stripe QOS didn't balance free space"
7516         simple_cleanup_common
7517 }
7518 run_test 116a "stripe QOS: free space balance ==================="
7519
7520 test_116b() { # LU-2093
7521         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7522         remote_mds_nodsh && skip "remote MDS with nodsh" && return
7523
7524 #define OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
7525         local old_rr=$(do_facet $SINGLEMDS lctl get_param -n \
7526                        lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr | head -1)
7527         [ -z "$old_rr" ] && skip "no QOS" && return 0
7528         do_facet $SINGLEMDS lctl set_param \
7529                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=0
7530         mkdir -p $DIR/$tdir
7531         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
7532         createmany -o $DIR/$tdir/f- 20 || error "can't create"
7533         do_facet $SINGLEMDS lctl set_param fail_loc=0
7534         rm -rf $DIR/$tdir
7535         do_facet $SINGLEMDS lctl set_param \
7536                 lo*.$FSNAME-MDT0000-mdtlov.qos_threshold_rr=$old_rr
7537 }
7538 run_test 116b "QoS shouldn't LBUG if not enough OSTs found on the 2nd pass"
7539
7540 test_117() # bug 10891
7541 {
7542         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7543         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1
7544         #define OBD_FAIL_OST_SETATTR_CREDITS 0x21e
7545         lctl set_param fail_loc=0x21e
7546         > $DIR/$tfile || error "truncate failed"
7547         lctl set_param fail_loc=0
7548         echo "Truncate succeeded."
7549         rm -f $DIR/$tfile
7550 }
7551 run_test 117 "verify osd extend =========="
7552
7553 NO_SLOW_RESENDCOUNT=4
7554 export OLD_RESENDCOUNT=""
7555 set_resend_count () {
7556         local PROC_RESENDCOUNT="osc.${FSNAME}-OST*-osc-*.resend_count"
7557         OLD_RESENDCOUNT=$(lctl get_param -n $PROC_RESENDCOUNT | head -n1)
7558         lctl set_param -n $PROC_RESENDCOUNT $1
7559         echo resend_count is set to $(lctl get_param -n $PROC_RESENDCOUNT)
7560 }
7561
7562 # for reduce test_118* time (b=14842)
7563 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7564
7565 # Reset async IO behavior after error case
7566 reset_async() {
7567         FILE=$DIR/reset_async
7568
7569         # Ensure all OSCs are cleared
7570         $SETSTRIPE -c -1 $FILE
7571         dd if=/dev/zero of=$FILE bs=64k count=$OSTCOUNT
7572         sync
7573         rm $FILE
7574 }
7575
7576 test_118a() #bug 11710
7577 {
7578         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7579         reset_async
7580
7581         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7582         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7583         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7584
7585         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7586                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7587                 return 1;
7588         fi
7589         rm -f $DIR/$tfile
7590 }
7591 run_test 118a "verify O_SYNC works =========="
7592
7593 test_118b()
7594 {
7595         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7596         remote_ost_nodsh && skip "remote OST with nodsh" && return
7597
7598         reset_async
7599
7600         #define OBD_FAIL_OST_ENOENT 0x217
7601         set_nodes_failloc "$(osts_nodes)" 0x217
7602         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7603         RC=$?
7604         set_nodes_failloc "$(osts_nodes)" 0
7605         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7606         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7607                     grep -c writeback)
7608
7609         if [[ $RC -eq 0 ]]; then
7610                 error "Must return error due to dropped pages, rc=$RC"
7611                 return 1;
7612         fi
7613
7614         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7615                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7616                 return 1;
7617         fi
7618
7619         echo "Dirty pages not leaked on ENOENT"
7620
7621         # Due to the above error the OSC will issue all RPCs syncronously
7622         # until a subsequent RPC completes successfully without error.
7623         $MULTIOP $DIR/$tfile Ow4096yc
7624         rm -f $DIR/$tfile
7625
7626         return 0
7627 }
7628 run_test 118b "Reclaim dirty pages on fatal error =========="
7629
7630 test_118c()
7631 {
7632         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7633
7634         # for 118c, restore the original resend count, LU-1940
7635         [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] &&
7636                                 set_resend_count $OLD_RESENDCOUNT
7637         remote_ost_nodsh && skip "remote OST with nodsh" && return
7638
7639         reset_async
7640
7641         #define OBD_FAIL_OST_EROFS               0x216
7642         set_nodes_failloc "$(osts_nodes)" 0x216
7643
7644         # multiop should block due to fsync until pages are written
7645         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7646         MULTIPID=$!
7647         sleep 1
7648
7649         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7650                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7651         fi
7652
7653         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7654                     grep -c writeback)
7655         if [[ $WRITEBACK -eq 0 ]]; then
7656                 error "No page in writeback, writeback=$WRITEBACK"
7657         fi
7658
7659         set_nodes_failloc "$(osts_nodes)" 0
7660         wait $MULTIPID
7661         RC=$?
7662         if [[ $RC -ne 0 ]]; then
7663                 error "Multiop fsync failed, rc=$RC"
7664         fi
7665
7666         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7667         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7668                     grep -c writeback)
7669         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7670                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7671         fi
7672
7673         rm -f $DIR/$tfile
7674         echo "Dirty pages flushed via fsync on EROFS"
7675         return 0
7676 }
7677 run_test 118c "Fsync blocks on EROFS until dirty pages are flushed =========="
7678
7679 # continue to use small resend count to reduce test_118* time (b=14842)
7680 [ "$SLOW" = "no" ] && set_resend_count $NO_SLOW_RESENDCOUNT
7681
7682 test_118d()
7683 {
7684         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7685         remote_ost_nodsh && skip "remote OST with nodsh" && return
7686
7687         reset_async
7688
7689         #define OBD_FAIL_OST_BRW_PAUSE_BULK
7690         set_nodes_failloc "$(osts_nodes)" 0x214
7691         # multiop should block due to fsync until pages are written
7692         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7693         MULTIPID=$!
7694         sleep 1
7695
7696         if [[ `ps h -o comm -p $MULTIPID` != "multiop" ]]; then
7697                 error "Multiop failed to block on fsync, pid=$MULTIPID"
7698         fi
7699
7700         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7701                     grep -c writeback)
7702         if [[ $WRITEBACK -eq 0 ]]; then
7703                 error "No page in writeback, writeback=$WRITEBACK"
7704         fi
7705
7706         wait $MULTIPID || error "Multiop fsync failed, rc=$?"
7707         set_nodes_failloc "$(osts_nodes)" 0
7708
7709         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7710         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7711                     grep -c writeback)
7712         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7713                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7714         fi
7715
7716         rm -f $DIR/$tfile
7717         echo "Dirty pages gaurenteed flushed via fsync"
7718         return 0
7719 }
7720 run_test 118d "Fsync validation inject a delay of the bulk =========="
7721
7722 test_118f() {
7723         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7724         reset_async
7725
7726         #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
7727         lctl set_param fail_loc=0x8000040a
7728
7729         # Should simulate EINVAL error which is fatal
7730         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7731         RC=$?
7732         if [[ $RC -eq 0 ]]; then
7733                 error "Must return error due to dropped pages, rc=$RC"
7734         fi
7735
7736         lctl set_param fail_loc=0x0
7737
7738         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7739         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7740         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7741                     grep -c writeback)
7742         if [[ $LOCKED -ne 0 ]]; then
7743                 error "Locked pages remain in cache, locked=$LOCKED"
7744         fi
7745
7746         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7747                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7748         fi
7749
7750         rm -f $DIR/$tfile
7751         echo "No pages locked after fsync"
7752
7753         reset_async
7754         return 0
7755 }
7756 run_test 118f "Simulate unrecoverable OSC side error =========="
7757
7758 test_118g() {
7759         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7760         reset_async
7761
7762         #define OBD_FAIL_OSC_BRW_PREP_REQ        0x406
7763         lctl set_param fail_loc=0x406
7764
7765         # simulate local -ENOMEM
7766         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7767         RC=$?
7768
7769         lctl set_param fail_loc=0
7770         if [[ $RC -eq 0 ]]; then
7771                 error "Must return error due to dropped pages, rc=$RC"
7772         fi
7773
7774         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7775         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7776         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7777                         grep -c writeback)
7778         if [[ $LOCKED -ne 0 ]]; then
7779                 error "Locked pages remain in cache, locked=$LOCKED"
7780         fi
7781
7782         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7783                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7784         fi
7785
7786         rm -f $DIR/$tfile
7787         echo "No pages locked after fsync"
7788
7789         reset_async
7790         return 0
7791 }
7792 run_test 118g "Don't stay in wait if we got local -ENOMEM  =========="
7793
7794 test_118h() {
7795         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7796         remote_ost_nodsh && skip "remote OST with nodsh" && return
7797
7798         reset_async
7799
7800         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7801         set_nodes_failloc "$(osts_nodes)" 0x20e
7802         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7803         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7804         RC=$?
7805
7806         set_nodes_failloc "$(osts_nodes)" 0
7807         if [[ $RC -eq 0 ]]; then
7808                 error "Must return error due to dropped pages, rc=$RC"
7809         fi
7810
7811         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7812         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7813         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache |
7814                     grep -c writeback)
7815         if [[ $LOCKED -ne 0 ]]; then
7816                 error "Locked pages remain in cache, locked=$LOCKED"
7817         fi
7818
7819         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7820                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7821         fi
7822
7823         rm -f $DIR/$tfile
7824         echo "No pages locked after fsync"
7825
7826         return 0
7827 }
7828 run_test 118h "Verify timeout in handling recoverables errors  =========="
7829
7830 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7831
7832 test_118i() {
7833         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7834         remote_ost_nodsh && skip "remote OST with nodsh" && return
7835
7836         reset_async
7837
7838         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7839         set_nodes_failloc "$(osts_nodes)" 0x20e
7840
7841         # Should simulate ENOMEM error which is recoverable and should be handled by timeout
7842         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c &
7843         PID=$!
7844         sleep 5
7845         set_nodes_failloc "$(osts_nodes)" 0
7846
7847         wait $PID
7848         RC=$?
7849         if [[ $RC -ne 0 ]]; then
7850                 error "got error, but should be not, rc=$RC"
7851         fi
7852
7853         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7854         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7855         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7856         if [[ $LOCKED -ne 0 ]]; then
7857                 error "Locked pages remain in cache, locked=$LOCKED"
7858         fi
7859
7860         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7861                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7862         fi
7863
7864         rm -f $DIR/$tfile
7865         echo "No pages locked after fsync"
7866
7867         return 0
7868 }
7869 run_test 118i "Fix error before timeout in recoverable error  =========="
7870
7871 [ "$SLOW" = "no" ] && set_resend_count 4
7872
7873 test_118j() {
7874         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7875         remote_ost_nodsh && skip "remote OST with nodsh" && return
7876
7877         reset_async
7878
7879         #define OBD_FAIL_OST_BRW_WRITE_BULK2     0x220
7880         set_nodes_failloc "$(osts_nodes)" 0x220
7881
7882         # return -EIO from OST
7883         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
7884         RC=$?
7885         set_nodes_failloc "$(osts_nodes)" 0x0
7886         if [[ $RC -eq 0 ]]; then
7887                 error "Must return error due to dropped pages, rc=$RC"
7888         fi
7889
7890         LOCKED=$(lctl get_param -n llite.*.dump_page_cache | grep -c locked)
7891         DIRTY=$(lctl get_param -n llite.*.dump_page_cache | grep -c dirty)
7892         WRITEBACK=$(lctl get_param -n llite.*.dump_page_cache | grep -c writeback)
7893         if [[ $LOCKED -ne 0 ]]; then
7894                 error "Locked pages remain in cache, locked=$LOCKED"
7895         fi
7896
7897         # in recoverable error on OST we want resend and stay until it finished
7898         if [[ $DIRTY -ne 0 || $WRITEBACK -ne 0 ]]; then
7899                 error "Dirty pages not flushed to disk, dirty=$DIRTY, writeback=$WRITEBACK"
7900         fi
7901
7902         rm -f $DIR/$tfile
7903         echo "No pages locked after fsync"
7904
7905         return 0
7906 }
7907 run_test 118j "Simulate unrecoverable OST side error =========="
7908
7909 test_118k()
7910 {
7911         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7912         remote_ost_nodsh && skip "remote OSTs with nodsh" && return
7913
7914         #define OBD_FAIL_OST_BRW_WRITE_BULK      0x20e
7915         set_nodes_failloc "$(osts_nodes)" 0x20e
7916         test_mkdir -p $DIR/$tdir
7917
7918         for ((i=0;i<10;i++)); do
7919                 (dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=1M count=10 || \
7920                         error "dd to $DIR/$tdir/$tfile-$i failed" )&
7921                 SLEEPPID=$!
7922                 sleep 0.500s
7923                 kill $SLEEPPID
7924                 wait $SLEEPPID
7925         done
7926
7927         set_nodes_failloc "$(osts_nodes)" 0
7928         rm -rf $DIR/$tdir
7929 }
7930 run_test 118k "bio alloc -ENOMEM and IO TERM handling ========="
7931
7932 test_118l()
7933 {
7934         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7935         # LU-646
7936         test_mkdir -p $DIR/$tdir
7937         $MULTIOP $DIR/$tdir Dy || error "fsync dir failed"
7938         rm -rf $DIR/$tdir
7939 }
7940 run_test 118l "fsync dir ========="
7941
7942 test_118m() # LU-3066
7943 {
7944         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7945         test_mkdir -p $DIR/$tdir
7946         $MULTIOP $DIR/$tdir DY || error "fdatasync dir failed"
7947         rm -rf $DIR/$tdir
7948 }
7949 run_test 118m "fdatasync dir ========="
7950
7951 [ "$SLOW" = "no" ] && [ -n "$OLD_RESENDCOUNT" ] && set_resend_count $OLD_RESENDCOUNT
7952
7953 test_119a() # bug 11737
7954 {
7955         BSIZE=$((512 * 1024))
7956         directio write $DIR/$tfile 0 1 $BSIZE
7957         # We ask to read two blocks, which is more than a file size.
7958         # directio will indicate an error when requested and actual
7959         # sizes aren't equeal (a normal situation in this case) and
7960         # print actual read amount.
7961         NOB=`directio read $DIR/$tfile 0 2 $BSIZE | awk '/error/ {print $6}'`
7962         if [ "$NOB" != "$BSIZE" ]; then
7963                 error "read $NOB bytes instead of $BSIZE"
7964         fi
7965         rm -f $DIR/$tfile
7966 }
7967 run_test 119a "Short directIO read must return actual read amount"
7968
7969 test_119b() # bug 11737
7970 {
7971         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
7972
7973         $SETSTRIPE -c 2 $DIR/$tfile || error "setstripe failed"
7974         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 seek=1 || error "dd failed"
7975         sync
7976         $MULTIOP $DIR/$tfile oO_RDONLY:O_DIRECT:r$((2048 * 1024)) || \
7977                 error "direct read failed"
7978         rm -f $DIR/$tfile
7979 }
7980 run_test 119b "Sparse directIO read must return actual read amount"
7981
7982 test_119c() # bug 13099
7983 {
7984         BSIZE=1048576
7985         directio write $DIR/$tfile 3 1 $BSIZE || error "direct write failed"
7986         directio readhole $DIR/$tfile 0 2 $BSIZE || error "reading hole failed"
7987         rm -f $DIR/$tfile
7988 }
7989 run_test 119c "Testing for direct read hitting hole"
7990
7991 test_119d() # bug 15950
7992 {
7993         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
7994         MAX_RPCS_IN_FLIGHT=`$LCTL get_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight`
7995         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight 1
7996         BSIZE=1048576
7997         $SETSTRIPE $DIR/$tfile -i 0 -c 1 || error "setstripe failed"
7998         $DIRECTIO write $DIR/$tfile 0 1 $BSIZE || error "first directio failed"
7999         #define OBD_FAIL_OSC_DIO_PAUSE           0x40d
8000         lctl set_param fail_loc=0x40d
8001         $DIRECTIO write $DIR/$tfile 1 4 $BSIZE &
8002         pid_dio=$!
8003         sleep 1
8004         cat $DIR/$tfile > /dev/null &
8005         lctl set_param fail_loc=0
8006         pid_reads=$!
8007         wait $pid_dio
8008         log "the DIO writes have completed, now wait for the reads (should not block very long)"
8009         sleep 2
8010         [ -n "`ps h -p $pid_reads -o comm`" ] && \
8011         error "the read rpcs have not completed in 2s"
8012         rm -f $DIR/$tfile
8013         $LCTL set_param -n osc.*OST0000-osc-[^mM]*.max_rpcs_in_flight $MAX_RPCS_IN_FLIGHT
8014 }
8015 run_test 119d "The DIO path should try to send a new rpc once one is completed"
8016
8017 test_120a() {
8018         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8019         test_mkdir -p $DIR/$tdir
8020         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8021                skip "no early lock cancel on server" && return 0
8022
8023         lru_resize_disable mdc
8024         lru_resize_disable osc
8025         cancel_lru_locks mdc
8026         # asynchronous object destroy at MDT could cause bl ast to client
8027         cancel_lru_locks osc
8028
8029         stat $DIR/$tdir > /dev/null
8030         can1=$(do_facet $SINGLEMDS \
8031                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8032                awk '/ldlm_cancel/ {print $2}')
8033         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8034                awk '/ldlm_bl_callback/ {print $2}')
8035         test_mkdir -c1 $DIR/$tdir/d1
8036         can2=$(do_facet $SINGLEMDS \
8037                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8038                awk '/ldlm_cancel/ {print $2}')
8039         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8040                awk '/ldlm_bl_callback/ {print $2}')
8041         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8042         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8043         lru_resize_enable mdc
8044         lru_resize_enable osc
8045 }
8046 run_test 120a "Early Lock Cancel: mkdir test"
8047
8048 test_120b() {
8049         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8050         test_mkdir $DIR/$tdir
8051         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8052                skip "no early lock cancel on server" && return 0
8053         lru_resize_disable mdc
8054         lru_resize_disable osc
8055         cancel_lru_locks mdc
8056         stat $DIR/$tdir > /dev/null
8057         can1=$(do_facet $SINGLEMDS \
8058                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8059                awk '/ldlm_cancel/ {print $2}')
8060         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8061                awk '/ldlm_bl_callback/ {print $2}')
8062         touch $DIR/$tdir/f1
8063         can2=$(do_facet $SINGLEMDS \
8064                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8065                awk '/ldlm_cancel/ {print $2}')
8066         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8067                awk '/ldlm_bl_callback/ {print $2}')
8068         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8069         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8070         lru_resize_enable mdc
8071         lru_resize_enable osc
8072 }
8073 run_test 120b "Early Lock Cancel: create test"
8074
8075 test_120c() {
8076         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8077         test_mkdir -c1 $DIR/$tdir
8078         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8079                skip "no early lock cancel on server" && return 0
8080         lru_resize_disable mdc
8081         lru_resize_disable osc
8082         test_mkdir -p -c1 $DIR/$tdir/d1
8083         test_mkdir -p -c1 $DIR/$tdir/d2
8084         touch $DIR/$tdir/d1/f1
8085         cancel_lru_locks mdc
8086         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 > /dev/null
8087         can1=$(do_facet $SINGLEMDS \
8088                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8089                awk '/ldlm_cancel/ {print $2}')
8090         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8091                awk '/ldlm_bl_callback/ {print $2}')
8092         ln $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8093         can2=$(do_facet $SINGLEMDS \
8094                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8095                awk '/ldlm_cancel/ {print $2}')
8096         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8097                awk '/ldlm_bl_callback/ {print $2}')
8098         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8099         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8100         lru_resize_enable mdc
8101         lru_resize_enable osc
8102 }
8103 run_test 120c "Early Lock Cancel: link test"
8104
8105 test_120d() {
8106         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8107         test_mkdir -p -c1 $DIR/$tdir
8108         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel)" ] && \
8109                skip "no early lock cancel on server" && return 0
8110         lru_resize_disable mdc
8111         lru_resize_disable osc
8112         touch $DIR/$tdir
8113         cancel_lru_locks mdc
8114         stat $DIR/$tdir > /dev/null
8115         can1=$(do_facet $SINGLEMDS \
8116                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8117                awk '/ldlm_cancel/ {print $2}')
8118         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8119                awk '/ldlm_bl_callback/ {print $2}')
8120         chmod a+x $DIR/$tdir
8121         can2=$(do_facet $SINGLEMDS \
8122                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8123                awk '/ldlm_cancel/ {print $2}')
8124         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8125                awk '/ldlm_bl_callback/ {print $2}')
8126         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8127         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8128         lru_resize_enable mdc
8129         lru_resize_enable osc
8130 }
8131 run_test 120d "Early Lock Cancel: setattr test"
8132
8133 test_120e() {
8134         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8135         test_mkdir -p -c1 $DIR/$tdir
8136         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8137                skip "no early lock cancel on server" && return 0
8138         lru_resize_disable mdc
8139         lru_resize_disable osc
8140         dd if=/dev/zero of=$DIR/$tdir/f1 count=1
8141         cancel_lru_locks mdc
8142         cancel_lru_locks osc
8143         dd if=$DIR/$tdir/f1 of=/dev/null
8144         stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
8145         # XXX client can not do early lock cancel of OST lock
8146         # during unlink (LU-4206), so cancel osc lock now.
8147         cancel_lru_locks osc
8148         can1=$(do_facet $SINGLEMDS \
8149                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8150                awk '/ldlm_cancel/ {print $2}')
8151         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8152                awk '/ldlm_bl_callback/ {print $2}')
8153         unlink $DIR/$tdir/f1
8154         sleep 5
8155         can2=$(do_facet $SINGLEMDS \
8156                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8157                awk '/ldlm_cancel/ {print $2}')
8158         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8159                awk '/ldlm_bl_callback/ {print $2}')
8160         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8161         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8162         lru_resize_enable mdc
8163         lru_resize_enable osc
8164 }
8165 run_test 120e "Early Lock Cancel: unlink test"
8166
8167 test_120f() {
8168         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8169         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8170                skip "no early lock cancel on server" && return 0
8171         test_mkdir -p -c1 $DIR/$tdir
8172         lru_resize_disable mdc
8173         lru_resize_disable osc
8174         test_mkdir -p -c1 $DIR/$tdir/d1
8175         test_mkdir -p -c1 $DIR/$tdir/d2
8176         dd if=/dev/zero of=$DIR/$tdir/d1/f1 count=1
8177         dd if=/dev/zero of=$DIR/$tdir/d2/f2 count=1
8178         cancel_lru_locks mdc
8179         cancel_lru_locks osc
8180         dd if=$DIR/$tdir/d1/f1 of=/dev/null
8181         dd if=$DIR/$tdir/d2/f2 of=/dev/null
8182         stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
8183         # XXX client can not do early lock cancel of OST lock
8184         # during rename (LU-4206), so cancel osc lock now.
8185         cancel_lru_locks osc
8186         can1=$(do_facet $SINGLEMDS \
8187                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8188                awk '/ldlm_cancel/ {print $2}')
8189         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8190                awk '/ldlm_bl_callback/ {print $2}')
8191         mrename $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2
8192         sleep 5
8193         can2=$(do_facet $SINGLEMDS \
8194                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8195                awk '/ldlm_cancel/ {print $2}')
8196         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8197                awk '/ldlm_bl_callback/ {print $2}')
8198         [ $can1 -eq $can2 ] || error $((can2-can1)) "cancel RPC occured."
8199         [ $blk1 -eq $blk2 ] || error $((blk2-blk1)) "blocking RPC occured."
8200         lru_resize_enable mdc
8201         lru_resize_enable osc
8202 }
8203 run_test 120f "Early Lock Cancel: rename test"
8204
8205 test_120g() {
8206         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8207         [ -z "`lctl get_param -n mdc.*.connect_flags | grep early_lock_cancel`" ] && \
8208                skip "no early lock cancel on server" && return 0
8209         lru_resize_disable mdc
8210         lru_resize_disable osc
8211         count=10000
8212         echo create $count files
8213         test_mkdir -p $DIR/$tdir
8214         cancel_lru_locks mdc
8215         cancel_lru_locks osc
8216         t0=`date +%s`
8217
8218         can0=$(do_facet $SINGLEMDS \
8219                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8220                awk '/ldlm_cancel/ {print $2}')
8221         blk0=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8222                awk '/ldlm_bl_callback/ {print $2}')
8223         createmany -o $DIR/$tdir/f $count
8224         sync
8225         can1=$(do_facet $SINGLEMDS \
8226                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8227                awk '/ldlm_cancel/ {print $2}')
8228         blk1=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8229                awk '/ldlm_bl_callback/ {print $2}')
8230         t1=$(date +%s)
8231         echo total: $((can1-can0)) cancels, $((blk1-blk0)) blockings
8232         echo rm $count files
8233         rm -r $DIR/$tdir
8234         sync
8235         can2=$(do_facet $SINGLEMDS \
8236                "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
8237                awk '/ldlm_cancel/ {print $2}')
8238         blk2=$($LCTL get_param -n ldlm.services.ldlm_cbd.stats |
8239                awk '/ldlm_bl_callback/ {print $2}')
8240         t2=$(date +%s)
8241         echo total: $count removes in $((t2-t1))
8242         echo total: $((can2-can1)) cancels, $((blk2-blk1)) blockings
8243         sleep 2
8244         # wait for commitment of removal
8245         lru_resize_enable mdc
8246         lru_resize_enable osc
8247 }
8248 run_test 120g "Early Lock Cancel: performance test"
8249
8250 test_121() { #bug #10589
8251         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8252         rm -rf $DIR/$tfile
8253         writes=$(LANG=C dd if=/dev/zero of=$DIR/$tfile count=1 2>&1 | awk -F '+' '/out$/ {print $1}')
8254 #define OBD_FAIL_LDLM_CANCEL_RACE        0x310
8255         lctl set_param fail_loc=0x310
8256         cancel_lru_locks osc > /dev/null
8257         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in$/ {print $1}')
8258         lctl set_param fail_loc=0
8259         [[ $reads -eq $writes ]] ||
8260                 error "read $reads blocks, must be $writes blocks"
8261 }
8262 run_test 121 "read cancel race ========="
8263
8264 test_123a() { # was test 123, statahead(bug 11401)
8265         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8266         SLOWOK=0
8267         if [ -z "$(grep "processor.*: 1" /proc/cpuinfo)" ]; then
8268             log "testing on UP system. Performance may be not as good as expected."
8269                         SLOWOK=1
8270         fi
8271
8272         rm -rf $DIR/$tdir
8273         test_mkdir -p $DIR/$tdir
8274         NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }')
8275         [[ $NUMFREE -gt 100000 ]] && NUMFREE=100000 || NUMFREE=$((NUMFREE-1000))
8276         MULT=10
8277         for ((i=100, j=0; i<=$NUMFREE; j=$i, i=$((i * MULT)) )); do
8278                 createmany -o $DIR/$tdir/$tfile $j $((i - j))
8279
8280                 max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8281                 lctl set_param -n llite.*.statahead_max 0
8282                 lctl get_param llite.*.statahead_max
8283                 cancel_lru_locks mdc
8284                 cancel_lru_locks osc
8285                 stime=`date +%s`
8286                 time ls -l $DIR/$tdir | wc -l
8287                 etime=`date +%s`
8288                 delta=$((etime - stime))
8289                 log "ls $i files without statahead: $delta sec"
8290                 lctl set_param llite.*.statahead_max=$max
8291
8292                 swrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8293                 lctl get_param -n llite.*.statahead_max | grep '[0-9]'
8294                 cancel_lru_locks mdc
8295                 cancel_lru_locks osc
8296                 stime=`date +%s`
8297                 time ls -l $DIR/$tdir | wc -l
8298                 etime=`date +%s`
8299                 delta_sa=$((etime - stime))
8300                 log "ls $i files with statahead: $delta_sa sec"
8301                 lctl get_param -n llite.*.statahead_stats
8302                 ewrong=`lctl get_param -n llite.*.statahead_stats | grep "statahead wrong:" | awk '{print $3}'`
8303
8304                 [[ $swrong -lt $ewrong ]] &&
8305                         log "statahead was stopped, maybe too many locks held!"
8306                 [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue
8307
8308                 if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8309                     max=`lctl get_param -n llite.*.statahead_max | head -n 1`
8310                     lctl set_param -n llite.*.statahead_max 0
8311                     lctl get_param llite.*.statahead_max
8312                     cancel_lru_locks mdc
8313                     cancel_lru_locks osc
8314                     stime=`date +%s`
8315                     time ls -l $DIR/$tdir | wc -l
8316                     etime=`date +%s`
8317                     delta=$((etime - stime))
8318                     log "ls $i files again without statahead: $delta sec"
8319                     lctl set_param llite.*.statahead_max=$max
8320                     if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then
8321                         if [  $SLOWOK -eq 0 ]; then
8322                                 error "ls $i files is slower with statahead!"
8323                         else
8324                                 log "ls $i files is slower with statahead!"
8325                         fi
8326                         break
8327                     fi
8328                 fi
8329
8330                 [ $delta -gt 20 ] && break
8331                 [ $delta -gt 8 ] && MULT=$((50 / delta))
8332                 [ "$SLOW" = "no" -a $delta -gt 5 ] && break
8333         done
8334         log "ls done"
8335
8336         stime=`date +%s`
8337         rm -r $DIR/$tdir
8338         sync
8339         etime=`date +%s`
8340         delta=$((etime - stime))
8341         log "rm -r $DIR/$tdir/: $delta seconds"
8342         log "rm done"
8343         lctl get_param -n llite.*.statahead_stats
8344 }
8345 run_test 123a "verify statahead work"
8346
8347 test_123b () { # statahead(bug 15027)
8348         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8349         test_mkdir -p $DIR/$tdir
8350         createmany -o $DIR/$tdir/$tfile-%d 1000
8351
8352         cancel_lru_locks mdc
8353         cancel_lru_locks osc
8354
8355 #define OBD_FAIL_MDC_GETATTR_ENQUEUE     0x803
8356         lctl set_param fail_loc=0x80000803
8357         ls -lR $DIR/$tdir > /dev/null
8358         log "ls done"
8359         lctl set_param fail_loc=0x0
8360         lctl get_param -n llite.*.statahead_stats
8361         rm -r $DIR/$tdir
8362         sync
8363
8364 }
8365 run_test 123b "not panic with network error in statahead enqueue (bug 15027)"
8366
8367 test_124a() {
8368         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8369         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8370                 skip "no lru resize on server" && return 0
8371         local NR=2000
8372         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8373
8374         log "create $NR files at $DIR/$tdir"
8375         createmany -o $DIR/$tdir/f $NR ||
8376                 error "failed to create $NR files in $DIR/$tdir"
8377
8378         cancel_lru_locks mdc
8379         ls -l $DIR/$tdir > /dev/null
8380
8381         local NSDIR=""
8382         local LRU_SIZE=0
8383         for VALUE in $($LCTL get_param ldlm.namespaces.*mdc-*.lru_size); do
8384                 local PARAM=$(echo ${VALUE[0]} | cut -d "=" -f1)
8385                 LRU_SIZE=$($LCTL get_param -n $PARAM)
8386                 if [[ $LRU_SIZE -gt $(default_lru_size) ]]; then
8387                         NSDIR=$(echo $PARAM | cut -d "." -f1-3)
8388                         log "NSDIR=$NSDIR"
8389                         log "NS=$(basename $NSDIR)"
8390                         break
8391                 fi
8392         done
8393
8394         if [[ -z "$NSDIR" || $LRU_SIZE -lt $(default_lru_size) ]]; then
8395                 skip "Not enough cached locks created!"
8396                 return 0
8397         fi
8398         log "LRU=$LRU_SIZE"
8399
8400         local SLEEP=30
8401
8402         # We know that lru resize allows one client to hold $LIMIT locks
8403         # for 10h. After that locks begin to be killed by client.
8404         local MAX_HRS=10
8405         local LIMIT=$($LCTL get_param -n $NSDIR.pool.limit)
8406         log "LIMIT=$LIMIT"
8407         if [ $LIMIT -lt $LRU_SIZE ]; then
8408             skip "Limit is too small $LIMIT"
8409             return 0
8410         fi
8411
8412         # Make LVF so higher that sleeping for $SLEEP is enough to _start_
8413         # killing locks. Some time was spent for creating locks. This means
8414         # that up to the moment of sleep finish we must have killed some of
8415         # them (10-100 locks). This depends on how fast ther were created.
8416         # Many of them were touched in almost the same moment and thus will
8417         # be killed in groups.
8418         local LVF=$(($MAX_HRS * 60 * 60 / $SLEEP * $LIMIT / $LRU_SIZE))
8419
8420         # Use $LRU_SIZE_B here to take into account real number of locks
8421         # created in the case of CMD, LRU_SIZE_B != $NR in most of cases
8422         local LRU_SIZE_B=$LRU_SIZE
8423         log "LVF=$LVF"
8424         local OLD_LVF=$($LCTL get_param -n $NSDIR.pool.lock_volume_factor)
8425         log "OLD_LVF=$OLD_LVF"
8426         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $LVF
8427
8428         # Let's make sure that we really have some margin. Client checks
8429         # cached locks every 10 sec.
8430         SLEEP=$((SLEEP+20))
8431         log "Sleep ${SLEEP} sec"
8432         local SEC=0
8433         while ((SEC<$SLEEP)); do
8434                 echo -n "..."
8435                 sleep 5
8436                 SEC=$((SEC+5))
8437                 LRU_SIZE=$($LCTL get_param -n $NSDIR/lru_size)
8438                 echo -n "$LRU_SIZE"
8439         done
8440         echo ""
8441         $LCTL set_param -n $NSDIR.pool.lock_volume_factor $OLD_LVF
8442         local LRU_SIZE_A=$($LCTL get_param -n $NSDIR.lru_size)
8443
8444         [[ $LRU_SIZE_B -gt $LRU_SIZE_A ]] || {
8445                 error "No locks dropped in ${SLEEP}s. LRU size: $LRU_SIZE_A"
8446                 unlinkmany $DIR/$tdir/f $NR
8447                 return
8448         }
8449
8450         log "Dropped "$((LRU_SIZE_B-LRU_SIZE_A))" locks in ${SLEEP}s"
8451         log "unlink $NR files at $DIR/$tdir"
8452         unlinkmany $DIR/$tdir/f $NR
8453 }
8454 run_test 124a "lru resize ======================================="
8455
8456 get_max_pool_limit()
8457 {
8458         local limit=$($LCTL get_param \
8459                       -n ldlm.namespaces.*-MDT0000-mdc-*.pool.limit)
8460         local max=0
8461         for l in $limit; do
8462                 if [[ $l -gt $max ]]; then
8463                         max=$l
8464                 fi
8465         done
8466         echo $max
8467 }
8468
8469 test_124b() {
8470         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8471         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8472                 skip "no lru resize on server" && return 0
8473
8474         LIMIT=$(get_max_pool_limit)
8475
8476         NR=$(($(default_lru_size)*20))
8477         if [[ $NR -gt $LIMIT ]]; then
8478                 log "Limit lock number by $LIMIT locks"
8479                 NR=$LIMIT
8480         fi
8481         lru_resize_disable mdc
8482         test_mkdir -p $DIR/$tdir/disable_lru_resize ||
8483                 error "failed to create $DIR/$tdir/disable_lru_resize"
8484
8485         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
8486         log "doing ls -la $DIR/$tdir/disable_lru_resize 3 times"
8487         cancel_lru_locks mdc
8488         stime=`date +%s`
8489         PID=""
8490         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8491         PID="$PID $!"
8492         sleep 2
8493         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8494         PID="$PID $!"
8495         sleep 2
8496         ls -la $DIR/$tdir/disable_lru_resize > /dev/null &
8497         PID="$PID $!"
8498         wait $PID
8499         etime=`date +%s`
8500         nolruresize_delta=$((etime-stime))
8501         log "ls -la time: $nolruresize_delta seconds"
8502         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8503         unlinkmany $DIR/$tdir/disable_lru_resize/f $NR
8504
8505         lru_resize_enable mdc
8506         test_mkdir -p $DIR/$tdir/enable_lru_resize ||
8507                 error "failed to create $DIR/$tdir/enable_lru_resize"
8508
8509         createmany -o $DIR/$tdir/enable_lru_resize/f $NR
8510         log "doing ls -la $DIR/$tdir/enable_lru_resize 3 times"
8511         cancel_lru_locks mdc
8512         stime=`date +%s`
8513         PID=""
8514         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8515         PID="$PID $!"
8516         sleep 2
8517         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8518         PID="$PID $!"
8519         sleep 2
8520         ls -la $DIR/$tdir/enable_lru_resize > /dev/null &
8521         PID="$PID $!"
8522         wait $PID
8523         etime=`date +%s`
8524         lruresize_delta=$((etime-stime))
8525         log "ls -la time: $lruresize_delta seconds"
8526         log "lru_size = $(lctl get_param -n ldlm.namespaces.*mdc*.lru_size)"
8527
8528         if [ $lruresize_delta -gt $nolruresize_delta ]; then
8529                 log "ls -la is $(((lruresize_delta - $nolruresize_delta) * 100 / $nolruresize_delta))% slower with lru resize enabled"
8530         elif [ $nolruresize_delta -gt $lruresize_delta ]; then
8531                 log "ls -la is $(((nolruresize_delta - $lruresize_delta) * 100 / $nolruresize_delta))% faster with lru resize enabled"
8532         else
8533                 log "lru resize performs the same with no lru resize"
8534         fi
8535         unlinkmany $DIR/$tdir/enable_lru_resize/f $NR
8536 }
8537 run_test 124b "lru resize (performance test) ======================="
8538
8539 test_124c() {
8540         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8541         [ -z "$($LCTL get_param -n mdc.*.connect_flags | grep lru_resize)" ] &&
8542                 skip "no lru resize on server" && return 0
8543
8544         # cache ununsed locks on client
8545         local nr=100
8546         cancel_lru_locks mdc
8547         test_mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
8548         createmany -o $DIR/$tdir/f $nr ||
8549                 error "failed to create $nr files in $DIR/$tdir"
8550         ls -l $DIR/$tdir > /dev/null
8551
8552         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
8553         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
8554         local max_age=$($LCTL get_param -n $nsdir.lru_max_age)
8555         local recalc_p=$($LCTL get_param -n $nsdir.pool.recalc_period)
8556         echo "unused=$unused, max_age=$max_age, recalc_p=$recalc_p"
8557
8558         # set lru_max_age to 1 sec
8559         $LCTL set_param $nsdir.lru_max_age=1000 # jiffies
8560         echo "sleep $((recalc_p * 2)) seconds..."
8561         sleep $((recalc_p * 2))
8562
8563         local remaining=$($LCTL get_param -n $nsdir.lock_unused_count)
8564         # restore lru_max_age
8565         $LCTL set_param -n $nsdir.lru_max_age $max_age
8566         [ $remaining -eq 0 ] || error "$remaining locks are not canceled"
8567         unlinkmany $DIR/$tdir/f $nr
8568 }
8569 run_test 124c "LRUR cancel very aged locks"
8570
8571 test_125() { # 13358
8572         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8573         [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return
8574         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
8575         test_mkdir -p $DIR/d125 || error "mkdir failed"
8576         $SETSTRIPE -S 65536 -c -1 $DIR/d125 || error "setstripe failed"
8577         setfacl -R -m u:bin:rwx $DIR/d125 || error "setfacl $DIR/d125 failed"
8578         ls -ld $DIR/d125 || error "cannot access $DIR/d125"
8579 }
8580 run_test 125 "don't return EPROTO when a dir has a non-default striping and ACLs"
8581
8582 test_126() { # bug 12829/13455
8583         [ -z "$(lctl get_param -n llite.*.client_type | grep local)" ] && skip "must run as local client" && return
8584         [ "$UID" != 0 ] && skip_env "skipping $TESTNAME (must run as root)" && return
8585         $GSS && skip "must run as gss disabled" && return
8586
8587         $RUNAS -u 0 -g 1 touch $DIR/$tfile || error "touch failed"
8588         gid=`ls -n $DIR/$tfile | awk '{print $4}'`
8589         rm -f $DIR/$tfile
8590         [ $gid -eq "1" ] || error "gid is set to" $gid "instead of 1"
8591 }
8592 run_test 126 "check that the fsgid provided by the client is taken into account"
8593
8594 test_127a() { # bug 15521
8595         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8596         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
8597         $LCTL set_param osc.*.stats=0
8598         FSIZE=$((2048 * 1024))
8599         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8600         cancel_lru_locks osc
8601         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE
8602
8603         $LCTL get_param osc.*0000-osc-*.stats | grep samples > $DIR/${tfile}.tmp
8604         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8605                 echo "got $COUNT $NAME"
8606                 [ ! $MIN ] && error "Missing min value for $NAME proc entry"
8607                 eval $NAME=$COUNT || error "Wrong proc format"
8608
8609                 case $NAME in
8610                         read_bytes|write_bytes)
8611                         [ $MIN -lt 4096 ] && error "min is too small: $MIN"
8612                         [ $MIN -gt $FSIZE ] && error "min is too big: $MIN"
8613                         [ $MAX -lt 4096 ] && error "max is too small: $MAX"
8614                         [ $MAX -gt $FSIZE ] && error "max is too big: $MAX"
8615                         [ $SUM -ne $FSIZE ] && error "sum is wrong: $SUM"
8616                         [ $SUMSQ -lt $(((FSIZE /4096) * (4096 * 4096))) ] &&
8617                                 error "sumsquare is too small: $SUMSQ"
8618                         [ $SUMSQ -gt $((FSIZE * FSIZE)) ] &&
8619                                 error "sumsquare is too big: $SUMSQ"
8620                         ;;
8621                         *) ;;
8622                 esac
8623         done < $DIR/${tfile}.tmp
8624
8625         #check that we actually got some stats
8626         [ "$read_bytes" ] || error "Missing read_bytes stats"
8627         [ "$write_bytes" ] || error "Missing write_bytes stats"
8628         [ "$read_bytes" != 0 ] || error "no read done"
8629         [ "$write_bytes" != 0 ] || error "no write done"
8630 }
8631 run_test 127a "verify the client stats are sane"
8632
8633 test_127b() { # bug LU-333
8634         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8635         $LCTL set_param llite.*.stats=0
8636         FSIZE=65536 # sized fixed to match PAGE_SIZE for most clients
8637         # perform 2 reads and writes so MAX is different from SUM.
8638         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8639         dd if=/dev/zero of=$DIR/$tfile bs=$FSIZE count=1
8640         cancel_lru_locks osc
8641         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8642         dd if=$DIR/$tfile of=/dev/null bs=$FSIZE count=1
8643
8644         $LCTL get_param llite.*.stats | grep samples > $TMP/${tfile}.tmp
8645         while read NAME COUNT SAMP UNIT MIN MAX SUM SUMSQ; do
8646                 echo "got $COUNT $NAME"
8647                 eval $NAME=$COUNT || error "Wrong proc format"
8648
8649         case $NAME in
8650                 read_bytes)
8651                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8652                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8653                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8654                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8655                         ;;
8656                 write_bytes)
8657                         [ $COUNT -ne 2 ] && error "count is not 2: $COUNT"
8658                         [ $MIN -ne $FSIZE ] && error "min is not $FSIZE: $MIN"
8659                         [ $MAX -ne $FSIZE ] && error "max is incorrect: $MAX"
8660                         [ $SUM -ne $((FSIZE * 2)) ] && error "sum is wrong: $SUM"
8661                         ;;
8662                         *) ;;
8663                 esac
8664         done < $TMP/${tfile}.tmp
8665
8666         #check that we actually got some stats
8667         [ "$read_bytes" ] || error "Missing read_bytes stats"
8668         [ "$write_bytes" ] || error "Missing write_bytes stats"
8669         [ "$read_bytes" != 0 ] || error "no read done"
8670         [ "$write_bytes" != 0 ] || error "no write done"
8671 }
8672 run_test 127b "verify the llite client stats are sane"
8673
8674 test_128() { # bug 15212
8675         touch $DIR/$tfile
8676         $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
8677                 find $DIR/$tfile
8678                 find $DIR/$tfile
8679         EOF
8680
8681         result=$(grep error $TMP/$tfile.log)
8682         rm -f $DIR/$tfile
8683         [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
8684 }
8685 run_test 128 "interactive lfs for 2 consecutive find's"
8686
8687 set_dir_limits () {
8688         local mntdev
8689         local canondev
8690         local node
8691
8692         local LDPROC=/proc/fs/ldiskfs
8693         local facets=$(get_facets MDS)
8694
8695         for facet in ${facets//,/ }; do
8696                 canondev=$(ldiskfs_canon \
8697                            *.$(convert_facet2label $facet).mntdev $facet)
8698                 do_facet $facet "test -e $LDPROC/$canondev/max_dir_size" ||
8699                                                 LDPROC=/sys/fs/ldiskfs
8700                 do_facet $facet "echo $1 >$LDPROC/$canondev/max_dir_size"
8701         done
8702 }
8703
8704 test_129() {
8705         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
8706         if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
8707                 skip "Only applicable to ldiskfs-based MDTs"
8708                 return
8709         fi
8710         remote_mds_nodsh && skip "remote MDS with nodsh" && return
8711         ENOSPC=28
8712         EFBIG=27
8713
8714         rm -rf $DIR/$tdir
8715         test_mkdir -p $DIR/$tdir
8716
8717         # block size of mds1
8718         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
8719         local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
8720         local MAX=$((MDSBLOCKSIZE * 3))
8721         set_dir_limits $MAX
8722         local I=$(stat -c%s "$DIR/$tdir")
8723         local J=0
8724         local STRIPE_COUNT=1
8725         [[ $MDSCOUNT -ge 2 ]] && STRIPE_COUNT=$($LFS getdirstripe -c $DIR/$tdir)
8726         MAX=$((MAX*STRIPE_COUNT))
8727         while [[ $I -le $MAX ]]; do
8728                 $MULTIOP $DIR/$tdir/$J Oc
8729                 rc=$?
8730                 #check two errors ENOSPC for new version of ext4 max_dir_size patch
8731                 #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
8732                 #and EFBIG for previous versions
8733                 if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
8734                         set_dir_limits 0
8735                         echo "return code $rc received as expected"
8736                         multiop $DIR/$tdir/$J Oc ||
8737                                 error_exit "multiop failed w/o dir size limit"
8738
8739                         I=$(stat -c%s "$DIR/$tdir")
8740
8741                         if [ $(lustre_version_code $SINGLEMDS) -lt \
8742                                         $(version_code 2.4.51) ]
8743                         then
8744                                 [[ $I -eq $MAX ]] && return 0
8745                         else
8746                                 [[ $I -gt $MAX ]] && return 0
8747                         fi
8748                         error_exit "current dir size $I, previous limit $MAX"
8749                 elif [ $rc -ne 0 ]; then
8750                         set_dir_limits 0
8751                         error_exit "return code $rc received instead of expected " \
8752                                    "$EFBIG or $ENOSPC, files in dir $I"
8753                 fi
8754                 J=$((J+1))
8755                 I=$(stat -c%s "$DIR/$tdir")
8756         done
8757
8758         set_dir_limits 0
8759         error "exceeded dir size limit $MAX($MDSCOUNT) : $I bytes"
8760 }
8761 run_test 129 "test directory size limit ========================"
8762
8763 OLDIFS="$IFS"
8764 cleanup_130() {
8765         trap 0
8766         IFS="$OLDIFS"
8767 }
8768
8769 test_130a() {
8770         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8771         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8772                 return
8773
8774         trap cleanup_130 EXIT RETURN
8775
8776         local fm_file=$DIR/$tfile
8777         $SETSTRIPE -S 65536 -c 1 $fm_file || error "setstripe on $fm_file"
8778         dd if=/dev/zero of=$fm_file bs=65536 count=1 ||
8779                 error "dd failed for $fm_file"
8780
8781         # LU-1795: test filefrag/FIEMAP once, even if unsupported
8782         filefrag -ves $fm_file
8783         RC=$?
8784         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8785                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8786         [ $RC != 0 ] && error "filefrag $fm_file failed"
8787
8788         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8789                       grep -v "ext:" | grep -v "found")
8790         lun=$($GETSTRIPE -i $fm_file)
8791
8792         start_blk=`echo $filefrag_op | cut -d: -f2 | cut -d. -f1`
8793         IFS=$'\n'
8794         tot_len=0
8795         for line in $filefrag_op
8796         do
8797                 frag_lun=`echo $line | cut -d: -f5`
8798                 ext_len=`echo $line | cut -d: -f4`
8799                 if (( $frag_lun != $lun )); then
8800                         cleanup_130
8801                         error "FIEMAP on 1-stripe file($fm_file) failed"
8802                         return
8803                 fi
8804                 (( tot_len += ext_len ))
8805         done
8806
8807         if (( lun != frag_lun || start_blk != 0 || tot_len != 64 )); then
8808                 cleanup_130
8809                 error "FIEMAP on 1-stripe file($fm_file) failed;"
8810                 return
8811         fi
8812
8813         cleanup_130
8814
8815         echo "FIEMAP on single striped file succeeded"
8816 }
8817 run_test 130a "FIEMAP (1-stripe file)"
8818
8819 test_130b() {
8820         [ "$OSTCOUNT" -lt "2" ] &&
8821                 skip_env "skipping FIEMAP on 2-stripe file test" && return
8822
8823         [ "$OSTCOUNT" -ge "10" ] &&
8824                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8825
8826         local filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8827         [ -n "$filefrag_op" ] && skip_env "filefrag does not support FIEMAP" &&
8828                 return
8829
8830         trap cleanup_130 EXIT RETURN
8831
8832         local fm_file=$DIR/$tfile
8833         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8834         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8835                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8836
8837         dd if=/dev/zero of=$fm_file bs=1M count=2 ||
8838                 error "dd failed on $fm_file"
8839
8840         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8841         filefrag_op=$(filefrag -ve $fm_file | grep -A 100 "ext:" |
8842                       grep -v "ext:" | grep -v "found")
8843
8844         last_lun=$(echo $filefrag_op | cut -d: -f5)
8845
8846         IFS=$'\n'
8847         tot_len=0
8848         num_luns=1
8849         for line in $filefrag_op
8850         do
8851                 frag_lun=`echo $line | cut -d: -f5`
8852                 ext_len=`echo $line | cut -d: -f4`
8853                 if (( $frag_lun != $last_lun )); then
8854                         if (( tot_len != 1024 )); then
8855                                 cleanup_130
8856                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 256"
8857                                 return
8858                         else
8859                                 (( num_luns += 1 ))
8860                                 tot_len=0
8861                         fi
8862                 fi
8863                 (( tot_len += ext_len ))
8864                 last_lun=$frag_lun
8865         done
8866         if (( num_luns != 2 || tot_len != 1024 )); then
8867                 cleanup_130
8868                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8869                 return
8870         fi
8871
8872         cleanup_130
8873
8874         echo "FIEMAP on 2-stripe file succeeded"
8875 }
8876 run_test 130b "FIEMAP (2-stripe file)"
8877
8878 test_130c() {
8879         [ "$OSTCOUNT" -lt "2" ] &&
8880                 skip_env "skipping FIEMAP on 2-stripe file" && return
8881
8882         [ "$OSTCOUNT" -ge "10" ] &&
8883                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8884
8885         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8886         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" &&
8887                 return
8888
8889         trap cleanup_130 EXIT RETURN
8890
8891         local fm_file=$DIR/$tfile
8892         $SETSTRIPE -S 65536 -c 2 $fm_file || error "setstripe on $fm_file"
8893         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8894                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8895
8896         dd if=/dev/zero of=$fm_file seek=1 bs=1M count=1 || error "dd failed on $fm_file"
8897
8898         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8899         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" | grep -v "ext:" | grep -v "found"`
8900
8901         last_lun=`echo $filefrag_op | cut -d: -f5`
8902
8903         IFS=$'\n'
8904         tot_len=0
8905         num_luns=1
8906         for line in $filefrag_op
8907         do
8908                 frag_lun=`echo $line | cut -d: -f5`
8909                 ext_len=`echo $line | cut -d: -f4`
8910                 if (( $frag_lun != $last_lun )); then
8911                         logical=`echo $line | cut -d: -f2 | cut -d. -f1`
8912                         if (( logical != 512 )); then
8913                                 cleanup_130
8914                                 error "FIEMAP on $fm_file failed; returned logical start for lun $logical instead of 512"
8915                                 return
8916                         fi
8917                         if (( tot_len != 512 )); then
8918                                 cleanup_130
8919                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8920                                 return
8921                         else
8922                                 (( num_luns += 1 ))
8923                                 tot_len=0
8924                         fi
8925                 fi
8926                 (( tot_len += ext_len ))
8927                 last_lun=$frag_lun
8928         done
8929         if (( num_luns != 2 || tot_len != 512 )); then
8930                 cleanup_130
8931                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8932                 return
8933         fi
8934
8935         cleanup_130
8936
8937         echo "FIEMAP on 2-stripe file with hole succeeded"
8938 }
8939 run_test 130c "FIEMAP (2-stripe file with hole)"
8940
8941 test_130d() {
8942         [ "$OSTCOUNT" -lt "3" ] && skip_env "skipping FIEMAP on N-stripe file test" && return
8943
8944         [ "$OSTCOUNT" -ge "10" ] &&
8945                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
8946
8947         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
8948         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
8949
8950         trap cleanup_130 EXIT RETURN
8951
8952         local fm_file=$DIR/$tfile
8953         $SETSTRIPE -S 65536 -c $OSTCOUNT $fm_file||error "setstripe on $fm_file"
8954         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
8955                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
8956
8957         local actual_stripecnt=$($GETSTRIPE -c $fm_file)
8958         dd if=/dev/zero of=$fm_file bs=1M count=$actual_stripecnt ||
8959                 error "dd failed on $fm_file"
8960
8961         filefrag -ves $fm_file || error "filefrag $fm_file failed"
8962         filefrag_op=`filefrag -ve $fm_file | grep -A 100 "ext:" |
8963                 grep -v "ext:" | grep -v "found"`
8964
8965         last_lun=`echo $filefrag_op | cut -d: -f5`
8966
8967         IFS=$'\n'
8968         tot_len=0
8969         num_luns=1
8970         for line in $filefrag_op
8971         do
8972                 frag_lun=`echo $line | cut -d: -f5`
8973                 ext_len=`echo $line | cut -d: -f4`
8974                 if (( $frag_lun != $last_lun )); then
8975                         if (( tot_len != 1024 )); then
8976                                 cleanup_130
8977                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of 1024"
8978                                 return
8979                         else
8980                                 (( num_luns += 1 ))
8981                                 tot_len=0
8982                         fi
8983                 fi
8984                 (( tot_len += ext_len ))
8985                 last_lun=$frag_lun
8986         done
8987         if (( num_luns != actual_stripecnt || tot_len != 1024 )); then
8988                 cleanup_130
8989                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
8990                 return
8991         fi
8992
8993         cleanup_130
8994
8995         echo "FIEMAP on N-stripe file succeeded"
8996 }
8997 run_test 130d "FIEMAP (N-stripe file)"
8998
8999 test_130e() {
9000         [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping continuation FIEMAP test" && return
9001
9002         [ "$OSTCOUNT" -ge "10" ] &&
9003                 skip_env "skipping FIEMAP with >= 10 OSTs" && return
9004
9005         filefrag_op=$(filefrag -e 2>&1 | grep "invalid option")
9006         [ -n "$filefrag_op" ] && skip "filefrag does not support FIEMAP" && return
9007
9008         trap cleanup_130 EXIT RETURN
9009
9010         local fm_file=$DIR/$tfile
9011         $SETSTRIPE -S 131072 -c 2 $fm_file || error "setstripe on $fm_file"
9012         [ "$(facet_fstype ost$(($($GETSTRIPE -i $fm_file) + 1)))" = "zfs" ] &&
9013                 skip "ORI-366/LU-1941: FIEMAP unimplemented on ZFS" && return
9014
9015         NUM_BLKS=512
9016         EXPECTED_LEN=$(( (NUM_BLKS / 2) * 64 ))
9017         for ((i = 0; i < $NUM_BLKS; i++))
9018         do
9019                 dd if=/dev/zero of=$fm_file count=1 bs=64k seek=$((2*$i)) conv=notrunc > /dev/null 2>&1
9020         done
9021
9022         filefrag -ves $fm_file || error "filefrag $fm_file failed"
9023         filefrag_op=`filefrag -ve $fm_file | grep -A 12000 "ext:" | grep -v "ext:" | grep -v "found"`
9024
9025         last_lun=`echo $filefrag_op | cut -d: -f5`
9026
9027         IFS=$'\n'
9028         tot_len=0
9029         num_luns=1
9030         for line in $filefrag_op
9031         do
9032                 frag_lun=`echo $line | cut -d: -f5`
9033                 ext_len=`echo $line | cut -d: -f4`
9034                 if (( $frag_lun != $last_lun )); then
9035                         if (( tot_len != $EXPECTED_LEN )); then
9036                                 cleanup_130
9037                                 error "FIEMAP on $fm_file failed; returned len $tot_len for OST $last_lun instead of $EXPECTED_LEN"
9038                                 return
9039                         else
9040                                 (( num_luns += 1 ))
9041                                 tot_len=0
9042                         fi
9043                 fi
9044                 (( tot_len += ext_len ))
9045                 last_lun=$frag_lun
9046         done
9047         if (( num_luns != 2 || tot_len != $EXPECTED_LEN )); then
9048                 cleanup_130
9049                 error "FIEMAP on $fm_file failed; returned wrong number of luns or wrong len for OST $last_lun"
9050                 return
9051         fi
9052
9053         cleanup_130
9054
9055         echo "FIEMAP with continuation calls succeeded"
9056 }
9057 run_test 130e "FIEMAP (test continuation FIEMAP calls)"
9058
9059 # Test for writev/readv
9060 test_131a() {
9061         rwv -f $DIR/$tfile -w -n 3 524288 1048576 1572864 || \
9062         error "writev test failed"
9063         rwv -f $DIR/$tfile -r -v -n 2 1572864 1048576 || \
9064         error "readv failed"
9065         rm -f $DIR/$tfile
9066 }
9067 run_test 131a "test iov's crossing stripe boundary for writev/readv"
9068
9069 test_131b() {
9070         rwv -f $DIR/$tfile -w -a -n 3 524288 1048576 1572864 || \
9071         error "append writev test failed"
9072         rwv -f $DIR/$tfile -w -a -n 2 1572864 1048576 || \
9073         error "append writev test failed"
9074         rm -f $DIR/$tfile
9075 }
9076 run_test 131b "test append writev"
9077
9078 test_131c() {
9079         rwv -f $DIR/$tfile -w -d -n 1 1048576 || return 0
9080         error "NOT PASS"
9081 }
9082 run_test 131c "test read/write on file w/o objects"
9083
9084 test_131d() {
9085         rwv -f $DIR/$tfile -w -n 1 1572864
9086         NOB=`rwv -f $DIR/$tfile -r -n 3 524288 524288 1048576 | awk '/error/ {print $6}'`
9087         if [ "$NOB" != 1572864 ]; then
9088                 error "Short read filed: read $NOB bytes instead of 1572864"
9089         fi
9090         rm -f $DIR/$tfile
9091 }
9092 run_test 131d "test short read"
9093
9094 test_131e() {
9095         rwv -f $DIR/$tfile -w -s 1048576 -n 1 1048576
9096         rwv -f $DIR/$tfile -r -z -s 0 -n 1 524288 || \
9097         error "read hitting hole failed"
9098         rm -f $DIR/$tfile
9099 }
9100 run_test 131e "test read hitting hole"
9101
9102 check_stats() {
9103         local res
9104         local count
9105         case $1 in
9106         $SINGLEMDS) res=`do_facet $SINGLEMDS $LCTL get_param mdt.$FSNAME-MDT0000.md_stats | grep "$2"`
9107                  ;;
9108         ost) res=`do_facet ost1 $LCTL get_param obdfilter.$FSNAME-OST0000.stats | grep "$2"`
9109                  ;;
9110         *) error "Wrong argument $1" ;;
9111         esac
9112         echo $res
9113         [ -z "$res" ] && error "The counter for $2 on $1 was not incremented"
9114         # if the argument $3 is zero, it means any stat increment is ok.
9115         if [[ $3 -gt 0 ]]; then
9116                 count=$(echo $res | awk '{ print $2 }')
9117                 [[ $count -ne $3 ]] &&
9118                         error "The $2 counter on $1 is wrong - expected $3"
9119         fi
9120 }
9121
9122 test_133a() {
9123         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9124         remote_ost_nodsh && skip "remote OST with nodsh" && return
9125         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9126
9127         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9128                 { skip "MDS doesn't support rename stats"; return; }
9129         local testdir=$DIR/${tdir}/stats_testdir
9130         mkdir -p $DIR/${tdir}
9131
9132         # clear stats.
9133         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9134         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9135
9136         # verify mdt stats first.
9137         mkdir ${testdir} || error "mkdir failed"
9138         check_stats $SINGLEMDS "mkdir" 1
9139         touch ${testdir}/${tfile} || "touch failed"
9140         check_stats $SINGLEMDS "open" 1
9141         check_stats $SINGLEMDS "close" 1
9142         mknod ${testdir}/${tfile}-pipe p || "mknod failed"
9143         check_stats $SINGLEMDS "mknod" 1
9144         rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
9145         check_stats $SINGLEMDS "unlink" 1
9146         rm -f ${testdir}/${tfile} || error "file remove failed"
9147         check_stats $SINGLEMDS "unlink" 2
9148
9149         # remove working dir and check mdt stats again.
9150         rmdir ${testdir} || error "rmdir failed"
9151         check_stats $SINGLEMDS "rmdir" 1
9152
9153         local testdir1=$DIR/${tdir}/stats_testdir1
9154         mkdir -p ${testdir}
9155         mkdir -p ${testdir1}
9156         touch ${testdir1}/test1
9157         mv ${testdir1}/test1 ${testdir} || error "file crossdir rename"
9158         check_stats $SINGLEMDS "crossdir_rename" 1
9159
9160         mv ${testdir}/test1 ${testdir}/test0 || error "file samedir rename"
9161         check_stats $SINGLEMDS "samedir_rename" 1
9162
9163         rm -rf $DIR/${tdir}
9164 }
9165 run_test 133a "Verifying MDT stats ========================================"
9166
9167 test_133b() {
9168         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9169         remote_ost_nodsh && skip "remote OST with nodsh" && return
9170         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9171         local testdir=$DIR/${tdir}/stats_testdir
9172         mkdir -p ${testdir} || error "mkdir failed"
9173         touch ${testdir}/${tfile} || "touch failed"
9174         cancel_lru_locks mdc
9175
9176         # clear stats.
9177         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9178         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9179
9180         # extra mdt stats verification.
9181         chmod 444 ${testdir}/${tfile} || error "chmod failed"
9182         check_stats $SINGLEMDS "setattr" 1
9183         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9184         if [ $(lustre_version_code $SINGLEMDS) -ne $(version_code 2.2.0) ]
9185         then            # LU-1740
9186                 ls -l ${testdir}/${tfile} > /dev/null|| error "ls failed"
9187                 check_stats $SINGLEMDS "getattr" 1
9188         fi
9189         $LFS df || error "lfs failed"
9190         check_stats $SINGLEMDS "statfs" 1
9191
9192         rm -rf $DIR/${tdir}
9193 }
9194 run_test 133b "Verifying extra MDT stats =================================="
9195
9196 test_133c() {
9197         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9198         remote_ost_nodsh && skip "remote OST with nodsh" && return
9199         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9200         local testdir=$DIR/${tdir}/stats_testdir
9201         test_mkdir -p ${testdir} || error "mkdir failed"
9202
9203         # verify obdfilter stats.
9204         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9205         sync
9206         cancel_lru_locks osc
9207         wait_delete_completed
9208
9209         # clear stats.
9210         do_facet $SINGLEMDS $LCTL set_param mdt.*.md_stats=clear
9211         do_facet ost1 $LCTL set_param obdfilter.*.stats=clear
9212
9213         dd if=/dev/zero of=${testdir}/${tfile} conv=notrunc bs=512k count=1 || error "dd failed"
9214         sync
9215         cancel_lru_locks osc
9216         check_stats ost "write" 1
9217
9218         dd if=${testdir}/${tfile} of=/dev/null bs=1k count=1 || error "dd failed"
9219         check_stats ost "read" 1
9220
9221         > ${testdir}/${tfile} || error "truncate failed"
9222         check_stats ost "punch" 1
9223
9224         rm -f ${testdir}/${tfile} || error "file remove failed"
9225         wait_delete_completed
9226         check_stats ost "destroy" 1
9227
9228         rm -rf $DIR/${tdir}
9229 }
9230 run_test 133c "Verifying OST stats ========================================"
9231
9232 order_2() {
9233         local value=$1
9234         local orig=$value
9235         local order=1
9236
9237         while [ $value -ge 2 ]; do
9238                 order=$((order*2))
9239                 value=$((value/2))
9240         done
9241
9242         if [ $orig -gt $order ]; then
9243                 order=$((order*2))
9244         fi
9245         echo $order
9246 }
9247
9248 size_in_KMGT() {
9249     local value=$1
9250     local size=('K' 'M' 'G' 'T');
9251     local i=0
9252     local size_string=$value
9253
9254     while [ $value -ge 1024 ]; do
9255         if [ $i -gt 3 ]; then
9256             #T is the biggest unit we get here, if that is bigger,
9257             #just return XXXT
9258             size_string=${value}T
9259             break
9260         fi
9261         value=$((value >> 10))
9262         if [ $value -lt 1024 ]; then
9263             size_string=${value}${size[$i]}
9264             break
9265         fi
9266         i=$((i + 1))
9267     done
9268
9269     echo $size_string
9270 }
9271
9272 get_rename_size() {
9273     local size=$1
9274     local context=${2:-.}
9275     local sample=$(do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats |
9276                 grep -A1 $context |
9277                 awk '/ '${size}'/ {print $4}' | sed -e "s/,//g")
9278     echo $sample
9279 }
9280
9281 test_133d() {
9282         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9283         remote_ost_nodsh && skip "remote OST with nodsh" && return
9284         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9285         do_facet $SINGLEMDS $LCTL list_param mdt.*.rename_stats ||
9286         { skip "MDS doesn't support rename stats"; return; }
9287
9288         local testdir1=$DIR/${tdir}/stats_testdir1
9289         local testdir2=$DIR/${tdir}/stats_testdir2
9290
9291         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9292
9293         mkdir -p ${testdir1} || error "mkdir failed"
9294         mkdir -p ${testdir2} || error "mkdir failed"
9295
9296         createmany -o $testdir1/test 512 || error "createmany failed"
9297
9298         # check samedir rename size
9299         mv ${testdir1}/test0 ${testdir1}/test_0
9300
9301         local testdir1_size=$(ls -l $DIR/${tdir} |
9302                 awk '/stats_testdir1/ {print $5}')
9303         local testdir2_size=$(ls -l $DIR/${tdir} |
9304                 awk '/stats_testdir2/ {print $5}')
9305
9306         testdir1_size=$(order_2 $testdir1_size)
9307         testdir2_size=$(order_2 $testdir2_size)
9308
9309         testdir1_size=$(size_in_KMGT $testdir1_size)
9310         testdir2_size=$(size_in_KMGT $testdir2_size)
9311
9312         echo "source rename dir size: ${testdir1_size}"
9313         echo "target rename dir size: ${testdir2_size}"
9314
9315         local cmd="do_facet $SINGLEMDS $LCTL get_param mdt.*.rename_stats"
9316         eval $cmd || error "$cmd failed"
9317         local samedir=$($cmd | grep 'same_dir')
9318         local same_sample=$(get_rename_size $testdir1_size)
9319         [ -z "$samedir" ] && error "samedir_rename_size count error"
9320         [[ $same_sample -eq 1 ]] ||
9321                 error "samedir_rename_size error $same_sample"
9322         echo "Check same dir rename stats success"
9323
9324         do_facet $SINGLEMDS $LCTL set_param mdt.*.rename_stats=clear
9325
9326         # check crossdir rename size
9327         mv ${testdir1}/test_0 ${testdir2}/test_0
9328
9329         testdir1_size=$(ls -l $DIR/${tdir} |
9330                 awk '/stats_testdir1/ {print $5}')
9331         testdir2_size=$(ls -l $DIR/${tdir} |
9332                 awk '/stats_testdir2/ {print $5}')
9333
9334         testdir1_size=$(order_2 $testdir1_size)
9335         testdir2_size=$(order_2 $testdir2_size)
9336
9337         testdir1_size=$(size_in_KMGT $testdir1_size)
9338         testdir2_size=$(size_in_KMGT $testdir2_size)
9339
9340         echo "source rename dir size: ${testdir1_size}"
9341         echo "target rename dir size: ${testdir2_size}"
9342
9343         eval $cmd || error "$cmd failed"
9344         local crossdir=$($cmd | grep 'crossdir')
9345         local src_sample=$(get_rename_size $testdir1_size crossdir_src)
9346         local tgt_sample=$(get_rename_size $testdir2_size crossdir_tgt)
9347         [ -z "$crossdir" ] && error "crossdir_rename_size count error"
9348         [[ $src_sample -eq 1 ]] ||
9349                 error "crossdir_rename_size error $src_sample"
9350         [[ $tgt_sample -eq 1 ]] ||
9351                 error "crossdir_rename_size error $tgt_sample"
9352         echo "Check cross dir rename stats success"
9353         rm -rf $DIR/${tdir}
9354 }
9355 run_test 133d "Verifying rename_stats ========================================"
9356
9357 test_133e() {
9358         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9359         remote_ost_nodsh && skip "remote OST with nodsh" && return
9360         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9361         local testdir=$DIR/${tdir}/stats_testdir
9362         local ctr f0 f1 bs=32768 count=42 sum
9363
9364         mkdir -p ${testdir} || error "mkdir failed"
9365
9366         $SETSTRIPE -c 1 -i 0 ${testdir}/${tfile}
9367
9368         for ctr in {write,read}_bytes; do
9369                 sync
9370                 cancel_lru_locks osc
9371
9372                 do_facet ost1 $LCTL set_param -n \
9373                         "obdfilter.*.exports.clear=clear"
9374
9375                 if [ $ctr = write_bytes ]; then
9376                         f0=/dev/zero
9377                         f1=${testdir}/${tfile}
9378                 else
9379                         f0=${testdir}/${tfile}
9380                         f1=/dev/null
9381                 fi
9382
9383                 dd if=$f0 of=$f1 conv=notrunc bs=$bs count=$count || \
9384                         error "dd failed"
9385                 sync
9386                 cancel_lru_locks osc
9387
9388                 sum=$(do_facet ost1 $LCTL get_param \
9389                         "obdfilter.*.exports.*.stats" |
9390                         awk -v ctr=$ctr 'BEGIN { sum = 0 }
9391                                 $1 == ctr { sum += $7 }
9392                                 END { printf("%0.0f", sum) }')
9393
9394                 if ((sum != bs * count)); then
9395                         error "Bad $ctr sum, expected $((bs * count)), got $sum"
9396                 fi
9397         done
9398
9399         rm -rf $DIR/${tdir}
9400 }
9401 run_test 133e "Verifying OST {read,write}_bytes nid stats ================="
9402
9403 test_133f() {
9404         local proc_dirs
9405
9406         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9407 /sys/fs/lustre/ /sys/fs/lnet/"
9408         local dir
9409         for dir in $dirs; do
9410                 if [ -d $dir ]; then
9411                         proc_dirs="$proc_dirs $dir"
9412                 fi
9413         done
9414
9415         local facet
9416
9417         remote_mds_nodsh && skip "remote MDS with nodsh" && return
9418         remote_ost_nodsh && skip "remote OST with nodsh" && return
9419         # First without trusting modes.
9420         find $proc_dirs -exec cat '{}' \; &> /dev/null
9421
9422         # Second verifying readability.
9423         find $proc_dirs \
9424                 -type f \
9425                 -exec cat '{}' \; &> /dev/null ||
9426                         error "proc file read failed"
9427
9428         for facet in $SINGLEMDS ost1; do
9429                 do_facet $facet find $proc_dirs \
9430                         ! -name req_history \
9431                         -exec cat '{}' \\\; &> /dev/null
9432
9433                 do_facet $facet find $proc_dirs \
9434                         ! -name req_history \
9435                         -type f \
9436                         -exec cat '{}' \\\; &> /dev/null ||
9437                                 error "proc file read failed"
9438         done
9439 }
9440 run_test 133f "Check for LBUGs/Oopses/unreadable files in /proc"
9441
9442 test_133g() {
9443         local proc_dirs
9444
9445         local dirs="/proc/fs/lustre/ /proc/sys/lnet/ /proc/sys/lustre/ \
9446 /sys/fs/lustre/ /sys/fs/lnet/"
9447         local dir
9448         for dir in $dirs; do
9449                 if [ -d $dir ]; then
9450                         proc_dirs="$proc_dirs $dir"
9451                 fi
9452         done
9453
9454         local facet
9455
9456         # Second verifying readability.
9457         find $proc_dirs \
9458                 -type f \
9459                 -not -name force_lbug \
9460                 -not -name changelog_mask \
9461                 -exec badarea_io '{}' \; &> /dev/null ||
9462                 error "find $proc_dirs failed"
9463
9464         [ $(lustre_version_code $SINGLEMDS) -le $(version_code 2.5.54) ] &&
9465                 skip "Too old lustre on MDS" && return
9466
9467         [ $(lustre_version_code ost1) -le $(version_code 2.5.54) ] &&
9468                 skip "Too old lustre on ost1" && return
9469
9470         for facet in $SINGLEMDS ost1; do
9471                 do_facet $facet find $proc_dirs \
9472                         -type f \
9473                         -not -name force_lbug \
9474                         -not -name changelog_mask \
9475                         -exec badarea_io '{}' \\\; &> /dev/null ||
9476                 error "$facet find $proc_dirs failed"
9477
9478         done
9479
9480         # remount the FS in case writes/reads /proc break the FS
9481         cleanup || error "failed to unmount"
9482         setup || error "failed to setup"
9483         true
9484 }
9485 run_test 133g "Check for Oopses on bad io area writes/reads in /proc"
9486
9487 test_134a() {
9488         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
9489                 skip "Need MDS version at least 2.7.54" && return
9490
9491         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9492         cancel_lru_locks mdc
9493
9494         local nsdir="ldlm.namespaces.*-MDT0000-mdc-*"
9495         local unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9496         [ $unused -eq 0 ] || "$unused locks are not cleared"
9497
9498         local nr=1000
9499         createmany -o $DIR/$tdir/f $nr ||
9500                 error "failed to create $nr files in $DIR/$tdir"
9501         unused=$($LCTL get_param -n $nsdir.lock_unused_count)
9502
9503         #define OBD_FAIL_LDLM_WATERMARK_LOW     0x327
9504         do_facet mds1 $LCTL set_param fail_loc=0x327
9505         do_facet mds1 $LCTL set_param fail_val=500
9506         touch $DIR/$tdir/m
9507
9508         echo "sleep 10 seconds ..."
9509         sleep 10
9510         local lck_cnt=$($LCTL get_param -n $nsdir.lock_unused_count)
9511
9512         do_facet mds1 $LCTL set_param fail_loc=0
9513         do_facet mds1 $LCTL set_param fail_val=0
9514         [ $lck_cnt -lt $unused ] ||
9515                 error "No locks reclaimed, before:$unused, after:$lck_cnt"
9516
9517         rm $DIR/$tdir/m
9518         unlinkmany $DIR/$tdir/f $nr
9519 }
9520 run_test 134a "Server reclaims locks when reaching lock_reclaim_threshold"
9521
9522 test_134b() {
9523         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.54) ]] &&
9524                 skip "Need MDS version at least 2.7.54" && return
9525
9526         mkdir -p $DIR/$tdir || error "failed to create $DIR/$tdir"
9527         cancel_lru_locks mdc
9528
9529         local low_wm=$(do_facet mds1 $LCTL get_param -n \
9530                         ldlm.lock_reclaim_threshold_mb)
9531         # disable reclaim temporarily
9532         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=0
9533
9534         #define OBD_FAIL_LDLM_WATERMARK_HIGH     0x328
9535         do_facet mds1 $LCTL set_param fail_loc=0x328
9536         do_facet mds1 $LCTL set_param fail_val=500
9537
9538         $LCTL set_param debug=+trace
9539
9540         local nr=600
9541         createmany -o $DIR/$tdir/f $nr &
9542         local create_pid=$!
9543
9544         echo "Sleep $TIMEOUT seconds ..."
9545         sleep $TIMEOUT
9546         if ! ps -p $create_pid  > /dev/null 2>&1; then
9547                 do_facet mds1 $LCTL set_param fail_loc=0
9548                 do_facet mds1 $LCTL set_param fail_val=0
9549                 do_facet mds1 $LCTL set_param \
9550                         ldlm.lock_reclaim_threshold_mb=${low_wm}m
9551                 error "createmany finished incorrectly!"
9552         fi
9553         do_facet mds1 $LCTL set_param fail_loc=0
9554         do_facet mds1 $LCTL set_param fail_val=0
9555         do_facet mds1 $LCTL set_param ldlm.lock_reclaim_threshold_mb=${low_wm}m
9556         wait $create_pid || return 1
9557
9558         unlinkmany $DIR/$tdir/f $nr
9559 }
9560 run_test 134b "Server rejects lock request when reaching lock_limit_mb"
9561
9562 test_140() { #bug-17379
9563         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9564         test_mkdir -p $DIR/$tdir || error "Creating dir $DIR/$tdir"
9565         cd $DIR/$tdir || error "Changing to $DIR/$tdir"
9566         cp /usr/bin/stat . || error "Copying stat to $DIR/$tdir"
9567
9568         # VFS limits max symlink depth to 5(4KSTACK) or 7(8KSTACK) or 8
9569         # For kernel > 3.5, bellow only tests consecutive symlink (MAX 40)
9570         local i=0
9571         while i=`expr $i + 1`; do
9572                 test_mkdir -p $i || error "Creating dir $i"
9573                 cd $i || error "Changing to $i"
9574                 ln -s ../stat stat || error "Creating stat symlink"
9575                 # Read the symlink until ELOOP present,
9576                 # not LBUGing the system is considered success,
9577                 # we didn't overrun the stack.
9578                 $OPENFILE -f O_RDONLY stat >/dev/null 2>&1; ret=$?
9579                 [ $ret -ne 0 ] && {
9580                         if [ $ret -eq 40 ]; then
9581                                 break  # -ELOOP
9582                         else
9583                                 error "Open stat symlink"
9584                                 return
9585                         fi
9586                 }
9587         done
9588         i=`expr $i - 1`
9589         echo "The symlink depth = $i"
9590         [ $i -eq 5 -o $i -eq 7 -o $i -eq 8 -o $i -eq 40 ] ||
9591                                         error "Invalid symlink depth"
9592
9593         # Test recursive symlink
9594         ln -s symlink_self symlink_self
9595         $OPENFILE -f O_RDONLY symlink_self >/dev/null 2>&1; ret=$?
9596         echo "open symlink_self returns $ret"
9597         [ $ret -eq 40 ] || error "recursive symlink doesn't return -ELOOP"
9598 }
9599 run_test 140 "Check reasonable stack depth (shouldn't LBUG) ===="
9600
9601 test_150() {
9602         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9603         local TF="$TMP/$tfile"
9604
9605         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9606         cp $TF $DIR/$tfile
9607         cancel_lru_locks osc
9608         cmp $TF $DIR/$tfile || error "$TMP/$tfile $DIR/$tfile differ"
9609         remount_client $MOUNT
9610         df -P $MOUNT
9611         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (remount)"
9612
9613         $TRUNCATE $TF 6000
9614         $TRUNCATE $DIR/$tfile 6000
9615         cancel_lru_locks osc
9616         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (truncate1)"
9617
9618         echo "12345" >>$TF
9619         echo "12345" >>$DIR/$tfile
9620         cancel_lru_locks osc
9621         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append1)"
9622
9623         echo "12345" >>$TF
9624         echo "12345" >>$DIR/$tfile
9625         cancel_lru_locks osc
9626         cmp $TF $DIR/$tfile || error "$TF $DIR/$tfile differ (append2)"
9627
9628         rm -f $TF
9629         true
9630 }
9631 run_test 150 "truncate/append tests"
9632
9633 #LU-2902 roc_hit was not able to read all values from lproc
9634 function roc_hit_init() {
9635         local list=$(comma_list $(osts_nodes))
9636         local dir=$DIR/$tdir-check
9637         local file=$dir/file
9638         local BEFORE
9639         local AFTER
9640         local idx
9641
9642         test_mkdir -p $dir
9643         #use setstripe to do a write to every ost
9644         for i in $(seq 0 $((OSTCOUNT-1))); do
9645                 $SETSTRIPE -c 1 -i $i $dir || error "$SETSTRIPE $file failed"
9646                 dd if=/dev/urandom of=$file bs=4k count=4 2>&1 > /dev/null
9647                 idx=$(printf %04x $i)
9648                 BEFORE=$(get_osd_param $list *OST*$idx stats |
9649                         awk '$1 == "cache_access" {sum += $7}
9650                                 END { printf("%0.0f", sum) }')
9651
9652                 cancel_lru_locks osc
9653                 cat $file >/dev/null
9654
9655                 AFTER=$(get_osd_param $list *OST*$idx stats |
9656                         awk '$1 == "cache_access" {sum += $7}
9657                                 END { printf("%0.0f", sum) }')
9658
9659                 echo BEFORE:$BEFORE AFTER:$AFTER
9660                 if ! let "AFTER - BEFORE == 4"; then
9661                         rm -rf $dir
9662                         error "roc_hit is not safe to use"
9663                 fi
9664                 rm $file
9665         done
9666
9667         rm -rf $dir
9668 }
9669
9670 function roc_hit() {
9671         local list=$(comma_list $(osts_nodes))
9672         echo $(get_osd_param $list '' stats |
9673                 awk '$1 == "cache_hit" {sum += $7}
9674                         END { printf("%0.0f", sum) }')
9675 }
9676
9677 function set_cache() {
9678         local on=1
9679
9680         if [ "$2" == "off" ]; then
9681                 on=0;
9682         fi
9683         local list=$(comma_list $(osts_nodes))
9684         set_osd_param $list '' $1_cache_enable $on
9685
9686         cancel_lru_locks osc
9687 }
9688
9689 test_151() {
9690         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9691         remote_ost_nodsh && skip "remote OST with nodsh" && return
9692
9693         local CPAGES=3
9694         local list=$(comma_list $(osts_nodes))
9695
9696         # check whether obdfilter is cache capable at all
9697         if ! get_osd_param $list '' read_cache_enable >/dev/null; then
9698                 echo "not cache-capable obdfilter"
9699                 return 0
9700         fi
9701
9702         # check cache is enabled on all obdfilters
9703         if get_osd_param $list '' read_cache_enable | grep 0; then
9704                 echo "oss cache is disabled"
9705                 return 0
9706         fi
9707
9708         set_osd_param $list '' writethrough_cache_enable 1
9709
9710         # check write cache is enabled on all obdfilters
9711         if get_osd_param $list '' writethrough_cache_enable | grep 0; then
9712                 echo "oss write cache is NOT enabled"
9713                 return 0
9714         fi
9715
9716         roc_hit_init
9717
9718         #define OBD_FAIL_OBD_NO_LRU  0x609
9719         do_nodes $list $LCTL set_param fail_loc=0x609
9720
9721         # pages should be in the case right after write
9722         dd if=/dev/urandom of=$DIR/$tfile bs=4k count=$CPAGES ||
9723                 error "dd failed"
9724
9725         local BEFORE=$(roc_hit)
9726         cancel_lru_locks osc
9727         cat $DIR/$tfile >/dev/null
9728         local AFTER=$(roc_hit)
9729
9730         do_nodes $list $LCTL set_param fail_loc=0
9731
9732         if ! let "AFTER - BEFORE == CPAGES"; then
9733                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
9734         fi
9735
9736         # the following read invalidates the cache
9737         cancel_lru_locks osc
9738         set_osd_param $list '' read_cache_enable 0
9739         cat $DIR/$tfile >/dev/null
9740
9741         # now data shouldn't be found in the cache
9742         BEFORE=$(roc_hit)
9743         cancel_lru_locks osc
9744         cat $DIR/$tfile >/dev/null
9745         AFTER=$(roc_hit)
9746         if let "AFTER - BEFORE != 0"; then
9747                 error "IN CACHE: before: $BEFORE, after: $AFTER"
9748         fi
9749
9750         set_osd_param $list '' read_cache_enable 1
9751         rm -f $DIR/$tfile
9752 }
9753 run_test 151 "test cache on oss and controls ==============================="
9754
9755 test_152() {
9756         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9757         local TF="$TMP/$tfile"
9758
9759         # simulate ENOMEM during write
9760 #define OBD_FAIL_OST_NOMEM      0x226
9761         lctl set_param fail_loc=0x80000226
9762         dd if=/dev/urandom of=$TF bs=6096 count=1 || error "dd failed"
9763         cp $TF $DIR/$tfile
9764         sync || error "sync failed"
9765         lctl set_param fail_loc=0
9766
9767         # discard client's cache
9768         cancel_lru_locks osc
9769
9770         # simulate ENOMEM during read
9771         lctl set_param fail_loc=0x80000226
9772         cmp $TF $DIR/$tfile || error "cmp failed"
9773         lctl set_param fail_loc=0
9774
9775         rm -f $TF
9776 }
9777 run_test 152 "test read/write with enomem ============================"
9778
9779 test_153() {
9780         $MULTIOP $DIR/$tfile Ow4096Ycu || error "multiop failed"
9781 }
9782 run_test 153 "test if fdatasync does not crash ======================="
9783
9784 dot_lustre_fid_permission_check() {
9785         local fid=$1
9786         local ffid=$MOUNT/.lustre/fid/$fid
9787         local test_dir=$2
9788
9789         echo "stat fid $fid"
9790         stat $ffid > /dev/null || error "stat $ffid failed."
9791         echo "touch fid $fid"
9792         touch $ffid || error "touch $ffid failed."
9793         echo "write to fid $fid"
9794         cat /etc/hosts > $ffid || error "write $ffid failed."
9795         echo "read fid $fid"
9796         diff /etc/hosts $ffid || error "read $ffid failed."
9797         echo "append write to fid $fid"
9798         cat /etc/hosts >> $ffid || error "append write $ffid failed."
9799         echo "rename fid $fid"
9800         mv $ffid $test_dir/$tfile.1 &&
9801                 error "rename $ffid to $tfile.1 should fail."
9802         touch $test_dir/$tfile.1
9803         mv $test_dir/$tfile.1 $ffid &&
9804                 error "rename $tfile.1 to $ffid should fail."
9805         rm -f $test_dir/$tfile.1
9806         echo "truncate fid $fid"
9807         $TRUNCATE $ffid 777 || error "truncate $ffid failed."
9808         if [ $MDSCOUNT -lt 2 ]; then #FIXME when cross-MDT hard link is working
9809                 echo "link fid $fid"
9810                 ln -f $ffid $test_dir/tfile.lnk || error "link $ffid failed."
9811         fi
9812         if [ -n $(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl) ]; then
9813                 echo "setfacl fid $fid"
9814                 setfacl -R -m u:bin:rwx $ffid || error "setfacl $ffid failed."
9815                 echo "getfacl fid $fid"
9816                 getfacl $ffid >/dev/null || error "getfacl $ffid failed."
9817         fi
9818         echo "unlink fid $fid"
9819         unlink $MOUNT/.lustre/fid/$fid && error "unlink $ffid should fail."
9820         echo "mknod fid $fid"
9821         mknod $ffid c 1 3 && error "mknod $ffid should fail."
9822
9823         fid=[0xf00000400:0x1:0x0]
9824         ffid=$MOUNT/.lustre/fid/$fid
9825
9826         echo "stat non-exist fid $fid"
9827         stat $ffid > /dev/null && error "stat non-exist $ffid should fail."
9828         echo "write to non-exist fid $fid"
9829         cat /etc/hosts > $ffid && error "write non-exist $ffid should fail."
9830         echo "link new fid $fid"
9831         ln $test_dir/$tfile $ffid && error "link $ffid should fail."
9832
9833         mkdir -p $test_dir/$tdir
9834         touch $test_dir/$tdir/$tfile
9835         fid=$($LFS path2fid $test_dir/$tdir)
9836         rc=$?
9837         [ $rc -ne 0 ] &&
9838                 error "error: could not get fid for $test_dir/$dir/$tfile."
9839
9840         ffid=$MOUNT/.lustre/fid/$fid
9841
9842         echo "ls $fid"
9843         ls $ffid > /dev/null || error "ls $ffid failed."
9844         echo "touch $fid/$tfile.1"
9845         touch $ffid/$tfile.1 || error "touch $ffid/$tfile.1 failed."
9846
9847         echo "touch $MOUNT/.lustre/fid/$tfile"
9848         touch $MOUNT/.lustre/fid/$tfile && \
9849                 error "touch $MOUNT/.lustre/fid/$tfile should fail."
9850
9851         echo "setxattr to $MOUNT/.lustre/fid"
9852         setfattr -n trusted.name1 -v value1 $MOUNT/.lustre/fid
9853
9854         echo "listxattr for $MOUNT/.lustre/fid"
9855         getfattr -d -m "^trusted" $MOUNT/.lustre/fid
9856
9857         echo "delxattr from $MOUNT/.lustre/fid"
9858         setfattr -x trusted.name1 $MOUNT/.lustre/fid
9859
9860         echo "touch invalid fid: $MOUNT/.lustre/fid/[0x200000400:0x2:0x3]"
9861         touch $MOUNT/.lustre/fid/[0x200000400:0x2:0x3] &&
9862                 error "touch invalid fid should fail."
9863
9864         echo "touch non-normal fid: $MOUNT/.lustre/fid/[0x1:0x2:0x0]"
9865         touch $MOUNT/.lustre/fid/[0x1:0x2:0x0] &&
9866                 error "touch non-normal fid should fail."
9867
9868         echo "rename $tdir to $MOUNT/.lustre/fid"
9869         mrename $test_dir/$tdir $MOUNT/.lustre/fid &&
9870                 error "rename to $MOUNT/.lustre/fid should fail."
9871
9872         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.51) ]
9873         then            # LU-3547
9874                 local old_obf_mode=$(stat --format="%a" $DIR/.lustre/fid)
9875                 local new_obf_mode=777
9876
9877                 echo "change mode of $DIR/.lustre/fid to $new_obf_mode"
9878                 chmod $new_obf_mode $DIR/.lustre/fid ||
9879                         error "chmod $new_obf_mode $DIR/.lustre/fid failed"
9880
9881                 local obf_mode=$(stat --format=%a $DIR/.lustre/fid)
9882                 [ $obf_mode -eq $new_obf_mode ] ||
9883                         error "stat $DIR/.lustre/fid returned wrong mode $obf_mode"
9884
9885                 echo "restore mode of $DIR/.lustre/fid to $old_obf_mode"
9886                 chmod $old_obf_mode $DIR/.lustre/fid ||
9887                         error "chmod $old_obf_mode $DIR/.lustre/fid failed"
9888         fi
9889
9890         $OPENFILE -f O_LOV_DELAY_CREATE:O_CREAT $test_dir/$tfile-2
9891         fid=$($LFS path2fid $test_dir/$tfile-2)
9892
9893         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.50) ]
9894         then # LU-5424
9895                 echo "cp /etc/passwd $MOUNT/.lustre/fid/$fid"
9896                 cp /etc/passwd $MOUNT/.lustre/fid/$fid ||
9897                         error "create lov data thru .lustre failed"
9898         fi
9899         echo "cp /etc/passwd $test_dir/$tfile-2"
9900         cp /etc/passwd $test_dir/$tfile-2 ||
9901                 error "copy to $test_dir/$tfile-2 failed."
9902         echo "diff /etc/passwd $MOUNT/.lustre/fid/$fid"
9903         diff /etc/passwd $MOUNT/.lustre/fid/$fid ||
9904                 error "diff /etc/passwd $MOUNT/.lustre/fid/$fid failed."
9905
9906         rm -rf $test_dir/tfile.lnk
9907         rm -rf $test_dir/$tfile-2
9908 }
9909
9910 test_154A() {
9911         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9912                 skip "Need MDS version at least 2.4.1" && return
9913
9914         touch $DIR/$tfile
9915         local FID=$($LFS path2fid $DIR/$tfile)
9916         [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
9917
9918         # check that we get the same pathname back
9919         local FOUND=$($LFS fid2path $MOUNT "$FID")
9920         [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
9921         [ "$FOUND" != "$DIR/$tfile" ] &&
9922                 error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
9923
9924         rm -rf $DIR/$tfile
9925 }
9926 run_test 154A "lfs path2fid and fid2path basic checks"
9927
9928 test_154a() {
9929         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9930         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9931                 { skip "Need MDS version at least 2.2.51"; return 0; }
9932         [ -z "$(which setfacl)" ] && skip "must have setfacl tool" && return
9933
9934         cp /etc/hosts $DIR/$tfile
9935
9936         fid=$($LFS path2fid $DIR/$tfile)
9937         rc=$?
9938         [ $rc -ne 0 ] && error "error: could not get fid for $DIR/$tfile."
9939
9940         dot_lustre_fid_permission_check "$fid" $DIR ||
9941                 error "dot lustre permission check $fid failed"
9942
9943         rm -rf $MOUNT/.lustre && error ".lustre is not allowed to be unlinked"
9944
9945         touch $MOUNT/.lustre/file &&
9946                 error "creation is not allowed under .lustre"
9947
9948         mkdir $MOUNT/.lustre/dir &&
9949                 error "mkdir is not allowed under .lustre"
9950
9951         rm -rf $DIR/$tfile
9952 }
9953 run_test 154a "Open-by-FID"
9954
9955 test_154b() {
9956         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
9957         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
9958                 { skip "Need MDS version at least 2.2.51"; return 0; }
9959
9960         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
9961
9962         local remote_dir=$DIR/$tdir/remote_dir
9963         local MDTIDX=1
9964         local rc=0
9965
9966         mkdir -p $DIR/$tdir
9967         $LFS mkdir -i $MDTIDX $remote_dir ||
9968                 error "create remote directory failed"
9969
9970         cp /etc/hosts $remote_dir/$tfile
9971
9972         fid=$($LFS path2fid $remote_dir/$tfile)
9973         rc=$?
9974         [ $rc -ne 0 ] && error "error: could not get fid for $remote_dir/$tfile"
9975
9976         dot_lustre_fid_permission_check "$fid" $remote_dir ||
9977                 error "dot lustre permission check $fid failed"
9978         rm -rf $DIR/$tdir
9979 }
9980 run_test 154b "Open-by-FID for remote directory"
9981
9982 test_154c() {
9983         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
9984                 skip "Need MDS version at least 2.4.1" && return
9985
9986         touch $DIR/$tfile.1 $DIR/$tfile.2 $DIR/$tfile.3
9987         local FID1=$($LFS path2fid $DIR/$tfile.1)
9988         local FID2=$($LFS path2fid $DIR/$tfile.2)
9989         local FID3=$($LFS path2fid $DIR/$tfile.3)
9990
9991         local N=1
9992         $LFS path2fid $DIR/$tfile.[123] | while read PATHNAME FID; do
9993                 [ "$PATHNAME" = "$DIR/$tfile.$N:" ] ||
9994                         error "path2fid pathname $PATHNAME != $DIR/$tfile.$N:"
9995                 local want=FID$N
9996                 [ "$FID" = "${!want}" ] ||
9997                         error "path2fid $PATHNAME FID $FID != FID$N ${!want}"
9998                 N=$((N + 1))
9999         done
10000
10001         $LFS fid2path $MOUNT "$FID1" "$FID2" "$FID3" | while read PATHNAME;
10002         do
10003                 [ "$PATHNAME" = "$DIR/$tfile.$N" ] ||
10004                         error "fid2path pathname $PATHNAME != $DIR/$tfile.$N:"
10005                 N=$((N + 1))
10006         done
10007 }
10008 run_test 154c "lfs path2fid and fid2path multiple arguments"
10009
10010 test_154d() {
10011         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
10012                 skip "Need MDS version at least 2.5.53" && return
10013
10014         if remote_mds; then
10015                 nid=$($LCTL list_nids | sed  "s/\./\\\./g")
10016         else
10017                 nid="0@lo"
10018         fi
10019         local proc_ofile="mdt.*.exports.'$nid'.open_files"
10020         local fd
10021         local cmd
10022
10023         rm -f $DIR/$tfile
10024         touch $DIR/$tfile
10025
10026         local fid=$($LFS path2fid $DIR/$tfile)
10027         # Open the file
10028         fd=$(free_fd)
10029         cmd="exec $fd<$DIR/$tfile"
10030         eval $cmd
10031         local fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
10032         echo "$fid_list" | grep "$fid"
10033         rc=$?
10034
10035         cmd="exec $fd>/dev/null"
10036         eval $cmd
10037         if [ $rc -ne 0 ]; then
10038                 error "FID $fid not found in open files list $fid_list"
10039         fi
10040 }
10041 run_test 154d "Verify open file fid"
10042
10043 test_154e()
10044 {
10045         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.50) ]] &&
10046                 skip "Need MDS version at least 2.6.50" && return
10047
10048         if ls -a $MOUNT | grep -q '^\.lustre$'; then
10049                 error ".lustre returned by readdir"
10050         fi
10051 }
10052 run_test 154e ".lustre is not returned by readdir"
10053
10054 test_154f() {
10055         # create parent directory on a single MDT to avoid cross-MDT hardlinks
10056         test_mkdir -p -c1 $DIR/$tdir/d
10057         # test dirs inherit from its stripe
10058         mkdir -p $DIR/$tdir/d/foo1 || error "mkdir error"
10059         mkdir -p $DIR/$tdir/d/foo2 || error "mkdir error"
10060         cp /etc/hosts $DIR/$tdir/d/foo1/$tfile
10061         ln $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/link
10062         touch $DIR/f
10063
10064         # get fid of parents
10065         local FID0=$($LFS path2fid $DIR/$tdir/d)
10066         local FID1=$($LFS path2fid $DIR/$tdir/d/foo1)
10067         local FID2=$($LFS path2fid $DIR/$tdir/d/foo2)
10068         local FID3=$($LFS path2fid $DIR)
10069
10070         # check that path2fid --parents returns expected <parent_fid>/name
10071         # 1) test for a directory (single parent)
10072         local parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1)
10073         [ "$parent" == "$FID0/foo1" ] ||
10074                 error "expected parent: $FID0/foo1, got: $parent"
10075
10076         # 2) test for a file with nlink > 1 (multiple parents)
10077         parent=$($LFS path2fid --parents $DIR/$tdir/d/foo1/$tfile)
10078         echo "$parent" | grep -F "$FID1/$tfile" ||
10079                 error "$FID1/$tfile not returned in parent list"
10080         echo "$parent" | grep -F "$FID2/link" ||
10081                 error "$FID2/link not returned in parent list"
10082
10083         # 3) get parent by fid
10084         local file_fid=$($LFS path2fid $DIR/$tdir/d/foo1/$tfile)
10085         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10086         echo "$parent" | grep -F "$FID1/$tfile" ||
10087                 error "$FID1/$tfile not returned in parent list (by fid)"
10088         echo "$parent" | grep -F "$FID2/link" ||
10089                 error "$FID2/link not returned in parent list (by fid)"
10090
10091         # 4) test for entry in root directory
10092         parent=$($LFS path2fid --parents $DIR/f)
10093         echo "$parent" | grep -F "$FID3/f" ||
10094                 error "$FID3/f not returned in parent list"
10095
10096         # 5) test it on root directory
10097         [ -z "$($LFS path2fid --parents $MOUNT 2>/dev/null)" ] ||
10098                 error "$MOUNT should not have parents"
10099
10100         # enable xattr caching and check that linkea is correctly updated
10101         local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
10102         save_lustre_params client "llite.*.xattr_cache" > $save
10103         lctl set_param llite.*.xattr_cache 1
10104
10105         # 6.1) linkea update on rename
10106         mv $DIR/$tdir/d/foo1/$tfile $DIR/$tdir/d/foo2/$tfile.moved
10107
10108         # get parents by fid
10109         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10110         # foo1 should no longer be returned in parent list
10111         echo "$parent" | grep -F "$FID1" &&
10112                 error "$FID1 should no longer be in parent list"
10113         # the new path should appear
10114         echo "$parent" | grep -F "$FID2/$tfile.moved" ||
10115                 error "$FID2/$tfile.moved is not in parent list"
10116
10117         # 6.2) linkea update on unlink
10118         rm -f $DIR/$tdir/d/foo2/link
10119         parent=$($LFS path2fid --parents $MOUNT/.lustre/fid/$file_fid)
10120         # foo2/link should no longer be returned in parent list
10121         echo "$parent" | grep -F "$FID2/link" &&
10122                 error "$FID2/link should no longer be in parent list"
10123         true
10124
10125         rm -f $DIR/f
10126         restore_lustre_params < $save
10127 }
10128 run_test 154f "get parent fids by reading link ea"
10129
10130 test_154g()
10131 {
10132         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.92) ]] ||
10133                 { skip "Need MDS version at least 2.6.92"; return 0; }
10134
10135         mkdir -p $DIR/$tdir
10136         llapi_fid_test -d $DIR/$tdir
10137 }
10138 run_test 154g "various llapi FID tests"
10139
10140 test_155_small_load() {
10141     local temp=$TMP/$tfile
10142     local file=$DIR/$tfile
10143
10144     dd if=/dev/urandom of=$temp bs=6096 count=1 || \
10145         error "dd of=$temp bs=6096 count=1 failed"
10146     cp $temp $file
10147     cancel_lru_locks osc
10148     cmp $temp $file || error "$temp $file differ"
10149
10150     $TRUNCATE $temp 6000
10151     $TRUNCATE $file 6000
10152     cmp $temp $file || error "$temp $file differ (truncate1)"
10153
10154     echo "12345" >>$temp
10155     echo "12345" >>$file
10156     cmp $temp $file || error "$temp $file differ (append1)"
10157
10158     echo "12345" >>$temp
10159     echo "12345" >>$file
10160     cmp $temp $file || error "$temp $file differ (append2)"
10161
10162     rm -f $temp $file
10163     true
10164 }
10165
10166 test_155_big_load() {
10167     remote_ost_nodsh && skip "remote OST with nodsh" && return
10168     local temp=$TMP/$tfile
10169     local file=$DIR/$tfile
10170
10171     free_min_max
10172     local cache_size=$(do_facet ost$((MAXI+1)) \
10173         "awk '/cache/ {sum+=\\\$4} END {print sum}' /proc/cpuinfo")
10174     local large_file_size=$((cache_size * 2))
10175
10176     echo "OSS cache size: $cache_size KB"
10177     echo "Large file size: $large_file_size KB"
10178
10179     [ $MAXV -le $large_file_size ] && \
10180         skip_env "max available OST size needs > $large_file_size KB" && \
10181         return 0
10182
10183     $SETSTRIPE $file -c 1 -i $MAXI || error "$SETSTRIPE $file failed"
10184
10185     dd if=/dev/urandom of=$temp bs=$large_file_size count=1k || \
10186         error "dd of=$temp bs=$large_file_size count=1k failed"
10187     cp $temp $file
10188     ls -lh $temp $file
10189     cancel_lru_locks osc
10190     cmp $temp $file || error "$temp $file differ"
10191
10192     rm -f $temp $file
10193     true
10194 }
10195
10196 test_155a() {
10197         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10198         set_cache read on
10199         set_cache writethrough on
10200         test_155_small_load
10201 }
10202 run_test 155a "Verify small file correctness: read cache:on write_cache:on"
10203
10204 test_155b() {
10205         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10206         set_cache read on
10207         set_cache writethrough off
10208         test_155_small_load
10209 }
10210 run_test 155b "Verify small file correctness: read cache:on write_cache:off"
10211
10212 test_155c() {
10213         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10214         set_cache read off
10215         set_cache writethrough on
10216         test_155_small_load
10217 }
10218 run_test 155c "Verify small file correctness: read cache:off write_cache:on"
10219
10220 test_155d() {
10221         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10222         set_cache read off
10223         set_cache writethrough off
10224         test_155_small_load
10225 }
10226 run_test 155d "Verify small file correctness: read cache:off write_cache:off"
10227
10228 test_155e() {
10229         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10230         set_cache read on
10231         set_cache writethrough on
10232         test_155_big_load
10233 }
10234 run_test 155e "Verify big file correctness: read cache:on write_cache:on"
10235
10236 test_155f() {
10237         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10238         set_cache read on
10239         set_cache writethrough off
10240         test_155_big_load
10241 }
10242 run_test 155f "Verify big file correctness: read cache:on write_cache:off"
10243
10244 test_155g() {
10245         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10246         set_cache read off
10247         set_cache writethrough on
10248         test_155_big_load
10249 }
10250 run_test 155g "Verify big file correctness: read cache:off write_cache:on"
10251
10252 test_155h() {
10253         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10254         set_cache read off
10255         set_cache writethrough off
10256         test_155_big_load
10257 }
10258 run_test 155h "Verify big file correctness: read cache:off write_cache:off"
10259
10260 test_156() {
10261         remote_ost_nodsh && skip "remote OST with nodsh" && return
10262         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10263         local CPAGES=3
10264         local BEFORE
10265         local AFTER
10266         local file="$DIR/$tfile"
10267
10268         [ "$(facet_fstype ost1)" = "zfs" -a \
10269            $(lustre_version_code ost1 -lt $(version_code 2.6.93)) ] &&
10270                 skip "LU-1956/LU-2261: stats not implemented on OSD ZFS" &&
10271                 return
10272
10273         roc_hit_init
10274
10275         log "Turn on read and write cache"
10276         set_cache read on
10277         set_cache writethrough on
10278
10279         log "Write data and read it back."
10280         log "Read should be satisfied from the cache."
10281         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10282         BEFORE=$(roc_hit)
10283         cancel_lru_locks osc
10284         cat $file >/dev/null
10285         AFTER=$(roc_hit)
10286         if ! let "AFTER - BEFORE == CPAGES"; then
10287                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10288         else
10289                 log "cache hits:: before: $BEFORE, after: $AFTER"
10290         fi
10291
10292         log "Read again; it should be satisfied from the cache."
10293         BEFORE=$AFTER
10294         cancel_lru_locks osc
10295         cat $file >/dev/null
10296         AFTER=$(roc_hit)
10297         if ! let "AFTER - BEFORE == CPAGES"; then
10298                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10299         else
10300                 log "cache hits:: before: $BEFORE, after: $AFTER"
10301         fi
10302
10303         log "Turn off the read cache and turn on the write cache"
10304         set_cache read off
10305         set_cache writethrough on
10306
10307         log "Read again; it should be satisfied from the cache."
10308         BEFORE=$(roc_hit)
10309         cancel_lru_locks osc
10310         cat $file >/dev/null
10311         AFTER=$(roc_hit)
10312         if ! let "AFTER - BEFORE == CPAGES"; then
10313                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10314         else
10315                 log "cache hits:: before: $BEFORE, after: $AFTER"
10316         fi
10317
10318         log "Read again; it should not be satisfied from the cache."
10319         BEFORE=$AFTER
10320         cancel_lru_locks osc
10321         cat $file >/dev/null
10322         AFTER=$(roc_hit)
10323         if ! let "AFTER - BEFORE == 0"; then
10324                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10325         else
10326                 log "cache hits:: before: $BEFORE, after: $AFTER"
10327         fi
10328
10329         log "Write data and read it back."
10330         log "Read should be satisfied from the cache."
10331         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10332         BEFORE=$(roc_hit)
10333         cancel_lru_locks osc
10334         cat $file >/dev/null
10335         AFTER=$(roc_hit)
10336         if ! let "AFTER - BEFORE == CPAGES"; then
10337                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10338         else
10339                 log "cache hits:: before: $BEFORE, after: $AFTER"
10340         fi
10341
10342         log "Read again; it should not be satisfied from the cache."
10343         BEFORE=$AFTER
10344         cancel_lru_locks osc
10345         cat $file >/dev/null
10346         AFTER=$(roc_hit)
10347         if ! let "AFTER - BEFORE == 0"; then
10348                 error "IN CACHE: before: $BEFORE, after: $AFTER"
10349         else
10350                 log "cache hits:: before: $BEFORE, after: $AFTER"
10351         fi
10352
10353         log "Turn off read and write cache"
10354         set_cache read off
10355         set_cache writethrough off
10356
10357         log "Write data and read it back"
10358         log "It should not be satisfied from the cache."
10359         rm -f $file
10360         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10361         cancel_lru_locks osc
10362         BEFORE=$(roc_hit)
10363         cat $file >/dev/null
10364         AFTER=$(roc_hit)
10365         if ! let "AFTER - BEFORE == 0"; then
10366                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10367         else
10368                 log "cache hits:: before: $BEFORE, after: $AFTER"
10369         fi
10370
10371         log "Turn on the read cache and turn off the write cache"
10372         set_cache read on
10373         set_cache writethrough off
10374
10375         log "Write data and read it back"
10376         log "It should not be satisfied from the cache."
10377         rm -f $file
10378         dd if=/dev/urandom of=$file bs=4k count=$CPAGES || error "dd failed"
10379         BEFORE=$(roc_hit)
10380         cancel_lru_locks osc
10381         cat $file >/dev/null
10382         AFTER=$(roc_hit)
10383         if ! let "AFTER - BEFORE == 0"; then
10384                 error_ignore bz20762 "IN CACHE: before: $BEFORE, after: $AFTER"
10385         else
10386                 log "cache hits:: before: $BEFORE, after: $AFTER"
10387         fi
10388
10389         log "Read again; it should be satisfied from the cache."
10390         BEFORE=$(roc_hit)
10391         cancel_lru_locks osc
10392         cat $file >/dev/null
10393         AFTER=$(roc_hit)
10394         if ! let "AFTER - BEFORE == CPAGES"; then
10395                 error "NOT IN CACHE: before: $BEFORE, after: $AFTER"
10396         else
10397                 log "cache hits:: before: $BEFORE, after: $AFTER"
10398         fi
10399
10400         rm -f $file
10401 }
10402 run_test 156 "Verification of tunables"
10403
10404 #Changelogs
10405 err17935 () {
10406         if [[ $MDSCOUNT -gt 1 ]]; then
10407                 error_ignore bz17935 $*
10408         else
10409                 error $*
10410         fi
10411 }
10412
10413 changelog_chmask()
10414 {
10415         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10416
10417         MASK=$(do_facet $SINGLEMDS $LCTL get_param $CL_MASK_PARAM| grep -c "$1")
10418
10419         if [ $MASK -eq 1 ]; then
10420                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="-$1"
10421         else
10422                 do_facet $SINGLEMDS $LCTL set_param $CL_MASK_PARAM="+$1"
10423         fi
10424 }
10425
10426 changelog_extract_field() {
10427         local mdt=$1
10428         local cltype=$2
10429         local file=$3
10430         local identifier=$4
10431
10432         $LFS changelog $mdt | gawk "/$cltype.*$file$/ {
10433                 print gensub(/^.* "$identifier'(\[[^\]]*\]).*$/,"\\1",1)}' |
10434                 tail -1
10435 }
10436
10437 test_160a() {
10438         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10439         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10440         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10441                 { skip "Need MDS version at least 2.2.0"; return; }
10442
10443         local CL_USERS="mdd.$MDT0.changelog_users"
10444         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10445         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10446         echo "Registered as changelog user $USER"
10447         $GET_CL_USERS | grep -q $USER ||
10448                 error "User $USER not found in changelog_users"
10449
10450         # change something
10451         test_mkdir -p $DIR/$tdir/pics/2008/zachy
10452         touch $DIR/$tdir/pics/2008/zachy/timestamp
10453         cp /etc/hosts $DIR/$tdir/pics/2008/zachy/pic1.jpg
10454         mv $DIR/$tdir/pics/2008/zachy $DIR/$tdir/pics/zach
10455         ln $DIR/$tdir/pics/zach/pic1.jpg $DIR/$tdir/pics/2008/portland.jpg
10456         ln -s $DIR/$tdir/pics/2008/portland.jpg $DIR/$tdir/pics/desktop.jpg
10457         rm $DIR/$tdir/pics/desktop.jpg
10458
10459         $LFS changelog $MDT0 | tail -5
10460
10461         echo "verifying changelog mask"
10462         changelog_chmask "MKDIR"
10463         changelog_chmask "CLOSE"
10464
10465         test_mkdir -p $DIR/$tdir/pics/zach/sofia
10466         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10467
10468         changelog_chmask "MKDIR"
10469         changelog_chmask "CLOSE"
10470
10471         test_mkdir -p $DIR/$tdir/pics/2008/sofia
10472         echo "zzzzzz" > $DIR/$tdir/pics/zach/file
10473
10474         $LFS changelog $MDT0
10475         MKDIRS=$($LFS changelog $MDT0 | tail -5 | grep -c "MKDIR")
10476         CLOSES=$($LFS changelog $MDT0 | tail -5 | grep -c "CLOSE")
10477         [ $MKDIRS -eq 1 ] || err17935 "MKDIR changelog mask count $DIRS != 1"
10478         [ $CLOSES -eq 1 ] || err17935 "CLOSE changelog mask count $DIRS != 1"
10479
10480         # verify contents
10481         echo "verifying target fid"
10482         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "t=")
10483         fidf=$($LFS path2fid $DIR/$tdir/pics/zach/timestamp)
10484         [ "$fidc" == "$fidf" ] ||
10485                 err17935 "fid in changelog $fidc != file fid $fidf"
10486         echo "verifying parent fid"
10487         fidc=$(changelog_extract_field $MDT0 "CREAT" "timestamp" "p=")
10488         fidf=$($LFS path2fid $DIR/$tdir/pics/zach)
10489         [ "$fidc" == "$fidf" ] ||
10490                 err17935 "pfid in changelog $fidc != dir fid $fidf"
10491
10492         USER_REC1=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10493         $LFS changelog_clear $MDT0 $USER $(($USER_REC1 + 5))
10494         USER_REC2=$($GET_CL_USERS | awk "\$1 == \"$USER\" {print \$2}")
10495         echo "verifying user clear: $(( $USER_REC1 + 5 )) == $USER_REC2"
10496         [ $USER_REC2 == $(($USER_REC1 + 5)) ] ||
10497                 err17935 "user index expected $(($USER_REC1 + 5)) is $USER_REC2"
10498
10499         MIN_REC=$($GET_CL_USERS |
10500                 awk 'min == "" || $2 < min {min = $2}; END {print min}')
10501         FIRST_REC=$($LFS changelog $MDT0 | head -n1 | awk '{print $1}')
10502         echo "verifying min purge: $(( $MIN_REC + 1 )) == $FIRST_REC"
10503         [ $FIRST_REC == $(($MIN_REC + 1)) ] ||
10504                 err17935 "first index should be $(($MIN_REC + 1)) is $FIRST_REC"
10505
10506         # LU-3446 changelog index reset on MDT restart
10507         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
10508         CUR_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10509         $LFS changelog_clear $MDT0 $USER 0
10510         stop $SINGLEMDS || error "Fail to stop MDT."
10511         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
10512         CUR_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10513         echo "verifying index survives MDT restart: $CUR_REC1 == $CUR_REC2"
10514         [ $CUR_REC1 == $CUR_REC2 ] ||
10515                 err17935 "current index should be $CUR_REC1 is $CUR_REC2"
10516
10517         echo "verifying user deregister"
10518         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10519         $GET_CL_USERS | grep -q $USER &&
10520                 error "User $USER still in changelog_users"
10521
10522         USERS=$(( $($GET_CL_USERS | wc -l) - 2 ))
10523         if [ $USERS -eq 0 ]; then
10524                 LAST_REC1=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10525                 touch $DIR/$tdir/chloe
10526                 LAST_REC2=$($GET_CL_USERS | head -n1 | cut -f3 -d' ')
10527                 echo "verify changelogs are off: $LAST_REC1 == $LAST_REC2"
10528                 [ $LAST_REC1 == $LAST_REC2 ] || error "changelogs not off"
10529         else
10530                 echo "$USERS other changelog users; can't verify off"
10531         fi
10532 }
10533 run_test 160a "changelog sanity"
10534
10535 test_160b() { # LU-3587
10536         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10537         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10538         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.0) ] ||
10539                 { skip "Need MDS version at least 2.2.0"; return; }
10540
10541         local CL_USERS="mdd.$MDT0.changelog_users"
10542         local GET_CL_USERS="do_facet $SINGLEMDS $LCTL get_param -n $CL_USERS"
10543         USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_register -n)
10544         echo "Registered as changelog user $USER"
10545         $GET_CL_USERS | grep -q $USER ||
10546                 error "User $USER not found in changelog_users"
10547
10548         local LONGNAME1=$(str_repeat a 255)
10549         local LONGNAME2=$(str_repeat b 255)
10550
10551         cd $DIR
10552         echo "creating very long named file"
10553         touch $LONGNAME1 || error "create of $LONGNAME1 failed"
10554         echo "moving very long named file"
10555         mv $LONGNAME1 $LONGNAME2
10556
10557         $LFS changelog $MDT0 | grep RENME
10558
10559         echo "deregistering $USER"
10560         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10561
10562         rm -f $LONGNAME2
10563 }
10564 run_test 160b "Verify that very long rename doesn't crash in changelog"
10565
10566 test_160c() {
10567         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10568
10569         local rc=0
10570         local server_version=$(lustre_version_code $SINGLEMDS)
10571
10572         [[ $server_version -gt $(version_code 2.5.57) ]] ||
10573                 [[ $server_version -gt $(version_code 2.5.1) &&
10574                    $server_version -lt $(version_code 2.5.50) ]] ||
10575                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
10576         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10577
10578         # Registration step
10579         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10580                 changelog_register -n)
10581
10582         rm -rf $DIR/$tdir
10583         mkdir -p $DIR/$tdir
10584         $MCREATE $DIR/$tdir/foo_160c
10585         changelog_chmask "TRUNC"
10586         $TRUNCATE $DIR/$tdir/foo_160c 200
10587         changelog_chmask "TRUNC"
10588         $TRUNCATE $DIR/$tdir/foo_160c 199
10589         $LFS changelog $MDT0
10590         TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC")
10591         [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1"
10592         $LFS changelog_clear $MDT0 $USER 0
10593
10594         # Deregistration step
10595         echo "deregistering $USER"
10596         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10597 }
10598 run_test 160c "verify that changelog log catch the truncate event"
10599
10600 test_160d() {
10601         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10602         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10603
10604         local server_version=$(lustre_version_code mds1)
10605         local CL_MASK_PARAM="mdd.$MDT0.changelog_mask"
10606
10607         [[ $server_version -ge $(version_code 2.7.60) ]] ||
10608                 { skip "Need MDS version at least 2.7.60+"; return; }
10609         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10610
10611         # Registration step
10612         local USER=$(do_facet mds1 $LCTL --device $MDT0 \
10613                 changelog_register -n)
10614
10615         mkdir -p $DIR/$tdir/migrate_dir
10616         $LFS changelog_clear $MDT0 $USER 0
10617
10618         $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails"
10619         $LFS changelog $MDT0
10620         MIGRATES=$($LFS changelog $MDT0 | tail -5 | grep -c "MIGRT")
10621         $LFS changelog_clear $MDT0 $USER 0
10622         [ $MIGRATES -eq 1 ] ||
10623                 error "MIGRATE changelog mask count $MIGRATES != 1"
10624
10625         # Deregistration step
10626         do_facet mds1 $LCTL --device $MDT0 changelog_deregister $USER
10627 }
10628 run_test 160d "verify that changelog log catch the migrate event"
10629
10630 test_161a() {
10631         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10632         test_mkdir -p -c1 $DIR/$tdir
10633         cp /etc/hosts $DIR/$tdir/$tfile
10634         test_mkdir -c1 $DIR/$tdir/foo1
10635         test_mkdir -c1 $DIR/$tdir/foo2
10636         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/sofia
10637         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/zachary
10638         ln $DIR/$tdir/$tfile $DIR/$tdir/foo1/luna
10639         ln $DIR/$tdir/$tfile $DIR/$tdir/foo2/thor
10640         local FID=$($LFS path2fid $DIR/$tdir/$tfile | tr -d '[]')
10641         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10642                 $LFS fid2path $DIR $FID
10643                 err17935 "bad link ea"
10644         fi
10645     # middle
10646     rm $DIR/$tdir/foo2/zachary
10647     # last
10648     rm $DIR/$tdir/foo2/thor
10649     # first
10650     rm $DIR/$tdir/$tfile
10651     # rename
10652     mv $DIR/$tdir/foo1/sofia $DIR/$tdir/foo2/maggie
10653     if [ "$($LFS fid2path $FSNAME --link 1 $FID)" != "$tdir/foo2/maggie" ]
10654         then
10655         $LFS fid2path $DIR $FID
10656         err17935 "bad link rename"
10657     fi
10658     rm $DIR/$tdir/foo2/maggie
10659
10660         # overflow the EA
10661         local longname=filename_avg_len_is_thirty_two_
10662         createmany -l$DIR/$tdir/foo1/luna $DIR/$tdir/foo2/$longname 1000 ||
10663                 error "failed to hardlink many files"
10664         links=$($LFS fid2path $DIR $FID | wc -l)
10665         echo -n "${links}/1000 links in link EA"
10666         [[ $links -gt 60 ]] ||
10667                 err17935 "expected at least 60 links in link EA"
10668         unlinkmany $DIR/$tdir/foo2/$longname 1000 ||
10669                 error "failed to unlink many hardlinks"
10670 }
10671 run_test 161a "link ea sanity"
10672
10673 test_161b() {
10674         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10675         [ $MDSCOUNT -lt 2 ] &&
10676                 skip "skipping remote directory test" && return
10677         local MDTIDX=1
10678         local remote_dir=$DIR/$tdir/remote_dir
10679
10680         mkdir -p $DIR/$tdir
10681         $LFS mkdir -i $MDTIDX $remote_dir ||
10682                 error "create remote directory failed"
10683
10684         cp /etc/hosts $remote_dir/$tfile
10685         mkdir -p $remote_dir/foo1
10686         mkdir -p $remote_dir/foo2
10687         ln $remote_dir/$tfile $remote_dir/foo1/sofia
10688         ln $remote_dir/$tfile $remote_dir/foo2/zachary
10689         ln $remote_dir/$tfile $remote_dir/foo1/luna
10690         ln $remote_dir/$tfile $remote_dir/foo2/thor
10691
10692         local FID=$($LFS path2fid $remote_dir/$tfile | tr -d '[' |
10693                      tr -d ']')
10694         if [ "$($LFS fid2path $DIR $FID | wc -l)" != "5" ]; then
10695                 $LFS fid2path $DIR $FID
10696                 err17935 "bad link ea"
10697         fi
10698         # middle
10699         rm $remote_dir/foo2/zachary
10700         # last
10701         rm $remote_dir/foo2/thor
10702         # first
10703         rm $remote_dir/$tfile
10704         # rename
10705         mv $remote_dir/foo1/sofia $remote_dir/foo2/maggie
10706         local link_path=$($LFS fid2path $FSNAME --link 1 $FID)
10707         if [ "$DIR/$link_path" != "$remote_dir/foo2/maggie" ]; then
10708                 $LFS fid2path $DIR $FID
10709                 err17935 "bad link rename"
10710         fi
10711         rm $remote_dir/foo2/maggie
10712
10713         # overflow the EA
10714         local longname=filename_avg_len_is_thirty_two_
10715         createmany -l$remote_dir/foo1/luna $remote_dir/foo2/$longname 1000 ||
10716                 error "failed to hardlink many files"
10717         links=$($LFS fid2path $DIR $FID | wc -l)
10718         echo -n "${links}/1000 links in link EA"
10719         [[ ${links} -gt 60 ]] ||
10720                 err17935 "expected at least 60 links in link EA"
10721         unlinkmany $remote_dir/foo2/$longname 1000 ||
10722         error "failed to unlink many hardlinks"
10723 }
10724 run_test 161b "link ea sanity under remote directory"
10725
10726 test_161c() {
10727         remote_mds_nodsh && skip "remote MDS with nodsh" && return
10728         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10729         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.1.5) ]] &&
10730                 skip "Need MDS version at least 2.1.5" && return
10731
10732         # define CLF_RENAME_LAST 0x0001
10733         # rename overwrite a target having nlink = 1 (changelog flag 0x1)
10734         local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \
10735                 changelog_register -n)
10736         rm -rf $DIR/$tdir
10737         mkdir -p $DIR/$tdir
10738         touch $DIR/$tdir/foo_161c
10739         touch $DIR/$tdir/bar_161c
10740         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10741         $LFS changelog $MDT0 | grep RENME
10742         local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \
10743                 cut -f5 -d' ')
10744         $LFS changelog_clear $MDT0 $USER 0
10745         if [ x$flags != "x0x1" ]; then
10746                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10747                         $USER
10748                 error "flag $flags is not 0x1"
10749         fi
10750         echo "rename overwrite a target having nlink = 1," \
10751                 "changelog record has flags of $flags"
10752
10753         # rename overwrite a target having nlink > 1 (changelog flag 0x0)
10754         touch $DIR/$tdir/foo_161c
10755         touch $DIR/$tdir/bar_161c
10756         ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10757         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c
10758         $LFS changelog $MDT0 | grep RENME
10759         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10760         $LFS changelog_clear $MDT0 $USER 0
10761         if [ x$flags != "x0x0" ]; then
10762                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10763                         $USER
10764                 error "flag $flags is not 0x0"
10765         fi
10766         echo "rename overwrite a target having nlink > 1," \
10767                 "changelog record has flags of $flags"
10768
10769         # rename doesn't overwrite a target (changelog flag 0x0)
10770         touch $DIR/$tdir/foo_161c
10771         mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c
10772         $LFS changelog $MDT0 | grep RENME
10773         flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ')
10774         $LFS changelog_clear $MDT0 $USER 0
10775         if [ x$flags != "x0x0" ]; then
10776                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10777                         $USER
10778                 error "flag $flags is not 0x0"
10779         fi
10780         echo "rename doesn't overwrite a target," \
10781                 "changelog record has flags of $flags"
10782
10783         # define CLF_UNLINK_LAST 0x0001
10784         # unlink a file having nlink = 1 (changelog flag 0x1)
10785         rm -f $DIR/$tdir/foo2_161c
10786         $LFS changelog $MDT0 | grep UNLNK
10787         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10788         $LFS changelog_clear $MDT0 $USER 0
10789         if [ x$flags != "x0x1" ]; then
10790                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10791                         $USER
10792                 error "flag $flags is not 0x1"
10793         fi
10794         echo "unlink a file having nlink = 1," \
10795                 "changelog record has flags of $flags"
10796
10797         # unlink a file having nlink > 1 (changelog flag 0x0)
10798         ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c
10799         rm -f $DIR/$tdir/foobar_161c
10800         $LFS changelog $MDT0 | grep UNLNK
10801         flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ')
10802         $LFS changelog_clear $MDT0 $USER 0
10803         if [ x$flags != "x0x0" ]; then
10804                 do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \
10805                         $USER
10806                 error "flag $flags is not 0x0"
10807         fi
10808         echo "unlink a file having nlink > 1," \
10809                 "changelog record has flags of $flags"
10810         do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER
10811 }
10812 run_test 161c "check CL_RENME[UNLINK] changelog record flags"
10813
10814 check_path() {
10815     local expected=$1
10816     shift
10817     local fid=$2
10818
10819     local path=$(${LFS} fid2path $*)
10820     # Remove the '//' indicating a remote directory
10821     path=$(echo $path | sed 's#//#/#g')
10822     RC=$?
10823
10824     if [ $RC -ne 0 ]; then
10825         err17935 "path looked up of $expected failed. Error $RC"
10826         return $RC
10827     elif [ "${path}" != "${expected}" ]; then
10828         err17935 "path looked up \"${path}\" instead of \"${expected}\""
10829         return 2
10830     fi
10831     echo "fid $fid resolves to path $path (expected $expected)"
10832 }
10833
10834 test_162a() { # was test_162
10835         # Make changes to filesystem
10836         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10837         test_mkdir -p -c1 $DIR/$tdir/d2
10838         touch $DIR/$tdir/d2/$tfile
10839         touch $DIR/$tdir/d2/x1
10840         touch $DIR/$tdir/d2/x2
10841         test_mkdir -p -c1 $DIR/$tdir/d2/a/b/c
10842         test_mkdir -p -c1 $DIR/$tdir/d2/p/q/r
10843         # regular file
10844         FID=$($LFS path2fid $DIR/$tdir/d2/$tfile | tr -d '[]')
10845         check_path "$tdir/d2/$tfile" $FSNAME $FID --link 0 ||
10846                 error "check path $tdir/d2/$tfile failed"
10847
10848         # softlink
10849         ln -s $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/slink
10850         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink | tr -d '[]')
10851         check_path "$tdir/d2/p/q/r/slink" $FSNAME $FID --link 0 ||
10852                 error "check path $tdir/d2/p/q/r/slink failed"
10853
10854         # softlink to wrong file
10855         ln -s /this/is/garbage $DIR/$tdir/d2/p/q/r/slink.wrong
10856         FID=$($LFS path2fid $DIR/$tdir/d2/p/q/r/slink.wrong | tr -d '[]')
10857         check_path "$tdir/d2/p/q/r/slink.wrong" $FSNAME $FID --link 0 ||
10858                 error "check path $tdir/d2/p/q/r/slink.wrong failed"
10859
10860         # hardlink
10861         ln $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/p/q/r/hlink
10862         mv $DIR/$tdir/d2/$tfile $DIR/$tdir/d2/a/b/c/new_file
10863         FID=$($LFS path2fid $DIR/$tdir/d2/a/b/c/new_file | tr -d '[]')
10864         # fid2path dir/fsname should both work
10865         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 1 ||
10866                 error "check path $tdir/d2/a/b/c/new_file failed"
10867         check_path "$DIR/$tdir/d2/p/q/r/hlink" $DIR $FID --link 0 ||
10868                 error "check path $DIR/$tdir/d2/p/q/r/hlink failed"
10869
10870         # hardlink count: check that there are 2 links
10871         # Doesnt work with CMD yet: 17935
10872         ${LFS} fid2path $DIR $FID | wc -l | grep -q 2 || \
10873                 err17935 "expected 2 links"
10874
10875         # hardlink indexing: remove the first link
10876         rm $DIR/$tdir/d2/p/q/r/hlink
10877         check_path "$tdir/d2/a/b/c/new_file" $FSNAME $FID --link 0 ||
10878                 error "check path $DIR/$tdir/d2/a/b/c/new_file failed"
10879
10880         return 0
10881 }
10882 run_test 162a "path lookup sanity"
10883
10884 test_162b() {
10885         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10886         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
10887
10888         mkdir $DIR/$tdir
10889         $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
10890                                 error "create striped dir failed"
10891
10892         local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir |
10893                                         tail -n 1 | awk '{print $2}')
10894         stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed"
10895
10896         touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed"
10897         mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed"
10898
10899         # regular file
10900         for ((i=0;i<5;i++)); do
10901                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') ||
10902                         error "get fid for f$i failed"
10903                 check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 ||
10904                         error "check path $tdir/striped_dir/f$i failed"
10905
10906                 FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') ||
10907                         error "get fid for d$i failed"
10908                 check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 ||
10909                         error "check path $tdir/striped_dir/d$i failed"
10910         done
10911
10912         return 0
10913 }
10914 run_test 162b "striped directory path lookup sanity"
10915
10916 # LU-4239: Verify fid2path works with paths 100 or more directories deep
10917 test_162c() {
10918         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.51) ]] &&
10919                 skip "Need MDS version at least 2.7.51" && return
10920         test_mkdir $DIR/$tdir.local
10921         test_mkdir $DIR/$tdir.remote
10922         local lpath=$tdir.local
10923         local rpath=$tdir.remote
10924
10925         for ((i = 0; i <= 101; i++)); do
10926                 lpath="$lpath/$i"
10927                 mkdir $DIR/$lpath
10928                 FID=$($LFS path2fid $DIR/$lpath | tr -d '[]') ||
10929                         error "get fid for local directory $DIR/$lpath failed"
10930                 check_path "$DIR/$lpath" $MOUNT $FID --link 0 ||
10931                         error "check path for local directory $DIR/$lpath failed"
10932
10933                 rpath="$rpath/$i"
10934                 test_mkdir $DIR/$rpath
10935                 FID=$($LFS path2fid $DIR/$rpath | tr -d '[]') ||
10936                         error "get fid for remote directory $DIR/$rpath failed"
10937                 check_path "$DIR/$rpath" $MOUNT $FID --link 0 ||
10938                         error "check path for remote directory $DIR/$rpath failed"
10939         done
10940
10941         return 0
10942 }
10943 run_test 162c "fid2path works with paths 100 or more directories deep"
10944
10945 test_169() {
10946         # do directio so as not to populate the page cache
10947         log "creating a 10 Mb file"
10948         $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
10949         log "starting reads"
10950         dd if=$DIR/$tfile of=/dev/null bs=4096 &
10951         log "truncating the file"
10952         $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
10953         log "killing dd"
10954         kill %+ || true # reads might have finished
10955         echo "wait until dd is finished"
10956         wait
10957         log "removing the temporary file"
10958         rm -rf $DIR/$tfile || error "tmp file removal failed"
10959 }
10960 run_test 169 "parallel read and truncate should not deadlock"
10961
10962 test_170() {
10963         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
10964         $LCTL clear     # bug 18514
10965         $LCTL debug_daemon start $TMP/${tfile}_log_good
10966         touch $DIR/$tfile
10967         $LCTL debug_daemon stop
10968         sed -e "s/^...../a/g" $TMP/${tfile}_log_good > $TMP/${tfile}_log_bad ||
10969                error "sed failed to read log_good"
10970
10971         $LCTL debug_daemon start $TMP/${tfile}_log_good
10972         rm -rf $DIR/$tfile
10973         $LCTL debug_daemon stop
10974
10975         $LCTL df $TMP/${tfile}_log_bad > $TMP/${tfile}_log_bad.out 2>&1 ||
10976                error "lctl df log_bad failed"
10977
10978         local bad_line=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10979         local good_line1=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10980
10981         $LCTL df $TMP/${tfile}_log_good > $TMP/${tfile}_log_good.out 2>&1
10982         local good_line2=$(tail -n 1 $TMP/${tfile}_log_good.out | awk '{print $5}')
10983
10984         [ "$bad_line" ] && [ "$good_line1" ] && [ "$good_line2" ] ||
10985                 error "bad_line good_line1 good_line2 are empty"
10986
10987         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10988         cat $TMP/${tfile}_log_bad >> $TMP/${tfile}_logs_corrupt
10989         cat $TMP/${tfile}_log_good >> $TMP/${tfile}_logs_corrupt
10990
10991         $LCTL df $TMP/${tfile}_logs_corrupt > $TMP/${tfile}_log_bad.out 2>&1
10992         local bad_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $9}')
10993         local good_line_new=$(tail -n 1 $TMP/${tfile}_log_bad.out | awk '{print $5}')
10994
10995         [ "$bad_line_new" ] && [ "$good_line_new" ] ||
10996                 error "bad_line_new good_line_new are empty"
10997
10998         local expected_good=$((good_line1 + good_line2*2))
10999
11000         rm -f $TMP/${tfile}*
11001         # LU-231, short malformed line may not be counted into bad lines
11002         if [ $bad_line -ne $bad_line_new ] &&
11003                    [ $bad_line -ne $((bad_line_new - 1)) ]; then
11004                 error "expected $bad_line bad lines, but got $bad_line_new"
11005                 return 1
11006         fi
11007
11008         if [ $expected_good -ne $good_line_new ]; then
11009                 error "expected $expected_good good lines, but got $good_line_new"
11010                 return 2
11011         fi
11012         true
11013 }
11014 run_test 170 "test lctl df to handle corrupted log ====================="
11015
11016 test_171() { # bug20592
11017         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11018 #define OBD_FAIL_PTLRPC_DUMP_LOG         0x50e
11019         $LCTL set_param fail_loc=0x50e
11020         $LCTL set_param fail_val=3000
11021         multiop_bg_pause $DIR/$tfile O_s || true
11022         local MULTIPID=$!
11023         kill -USR1 $MULTIPID
11024         # cause log dump
11025         sleep 3
11026         wait $MULTIPID
11027         if dmesg | grep "recursive fault"; then
11028                 error "caught a recursive fault"
11029         fi
11030         $LCTL set_param fail_loc=0
11031         true
11032 }
11033 run_test 171 "test libcfs_debug_dumplog_thread stuck in do_exit() ======"
11034
11035 # it would be good to share it with obdfilter-survey/iokit-libecho code
11036 setup_obdecho_osc () {
11037         local rc=0
11038         local ost_nid=$1
11039         local obdfilter_name=$2
11040         echo "Creating new osc for $obdfilter_name on $ost_nid"
11041         # make sure we can find loopback nid
11042         $LCTL add_uuid $ost_nid $ost_nid >/dev/null 2>&1
11043
11044         [ $rc -eq 0 ] && { $LCTL attach osc ${obdfilter_name}_osc     \
11045                            ${obdfilter_name}_osc_UUID || rc=2; }
11046         [ $rc -eq 0 ] && { $LCTL --device ${obdfilter_name}_osc setup \
11047                            ${obdfilter_name}_UUID  $ost_nid || rc=3; }
11048         return $rc
11049 }
11050
11051 cleanup_obdecho_osc () {
11052         local obdfilter_name=$1
11053         $LCTL --device ${obdfilter_name}_osc cleanup >/dev/null
11054         $LCTL --device ${obdfilter_name}_osc detach  >/dev/null
11055         return 0
11056 }
11057
11058 obdecho_test() {
11059         local OBD=$1
11060         local node=$2
11061         local pages=${3:-64}
11062         local rc=0
11063         local id
11064
11065         local count=10
11066         local obd_size=$(get_obd_size $node $OBD)
11067         local page_size=$(get_page_size $node)
11068         if [[ -n "$obd_size" ]]; then
11069                 local new_count=$((obd_size / (pages * page_size / 1024)))
11070                 [[ $new_count -ge $count ]] || count=$new_count
11071         fi
11072
11073         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
11074         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
11075                            rc=2; }
11076         if [ $rc -eq 0 ]; then
11077             id=$(do_facet $node "$LCTL --device ec create 1"  | awk '/object id/ {print $6}')
11078             [ ${PIPESTATUS[0]} -eq 0 -a -n "$id" ] || rc=3
11079         fi
11080         echo "New object id is $id"
11081         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
11082                            rc=4; }
11083         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
11084                            "test_brw $count w v $pages $id" || rc=4; }
11085         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
11086                            rc=4; }
11087         [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
11088                                         "cleanup" || rc=5; }
11089         [ $rc -eq 0 -o $rc -gt 1 ] && { do_facet $node "$LCTL --device ec "    \
11090                                         "detach" || rc=6; }
11091         [ $rc -ne 0 ] && echo "obecho_create_test failed: $rc"
11092         return $rc
11093 }
11094
11095 test_180a() {
11096         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11097         remote_ost_nodsh && skip "remote OST with nodsh" && return
11098         local rc=0
11099         local rmmod_local=0
11100
11101         if ! module_loaded obdecho; then
11102             load_module obdecho/obdecho
11103             rmmod_local=1
11104         fi
11105
11106         local osc=$($LCTL dl | grep -v mdt | awk '$3 == "osc" {print $4; exit}')
11107         local host=$(lctl get_param -n osc.$osc.import |
11108                              awk '/current_connection:/ {print $2}' )
11109         local target=$(lctl get_param -n osc.$osc.import |
11110                              awk '/target:/ {print $2}' )
11111         target=${target%_UUID}
11112
11113         [[ -n $target ]]  && { setup_obdecho_osc $host $target || rc=1; } || rc=1
11114         [ $rc -eq 0 ] && { obdecho_test ${target}_osc client || rc=2; }
11115         [[ -n $target ]] && cleanup_obdecho_osc $target
11116         [ $rmmod_local -eq 1 ] && rmmod obdecho
11117         return $rc
11118 }
11119 run_test 180a "test obdecho on osc"
11120
11121 test_180b() {
11122         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11123         remote_ost_nodsh && skip "remote OST with nodsh" && return
11124         local rc=0
11125         local rmmod_remote=0
11126
11127         do_facet ost1 "lsmod | grep -q obdecho || "                      \
11128                       "{ insmod ${LUSTRE}/obdecho/obdecho.ko || "        \
11129                       "modprobe obdecho; }" && rmmod_remote=1
11130         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ {print $4;exit}')
11131         [[ -n $target ]] && { obdecho_test $target ost1 || rc=1; }
11132         [ $rmmod_remote -eq 1 ] && do_facet ost1 "rmmod obdecho"
11133         return $rc
11134 }
11135 run_test 180b "test obdecho directly on obdfilter"
11136
11137 test_180c() { # LU-2598
11138         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11139         remote_ost_nodsh && skip "remote OST with nodsh" && return
11140         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.0) ]] &&
11141                 skip "Need MDS version at least 2.4.0" && return
11142
11143         local rc=0
11144         local rmmod_remote=false
11145         local pages=16384 # 64MB bulk I/O RPC size
11146         local target
11147
11148         do_rpc_nodes $(facet_active_host ost1) load_module obdecho/obdecho &&
11149                 rmmod_remote=true || error "failed to load module obdecho"
11150
11151         target=$(do_facet ost1 $LCTL dl | awk '/obdfilter/ { print $4 }' |
11152                 head -n1)
11153         if [ -n "$target" ]; then
11154                 obdecho_test "$target" ost1 "$pages" || rc=${PIPESTATUS[0]}
11155         else
11156                 echo "there is no obdfilter target on ost1"
11157                 rc=2
11158         fi
11159         $rmmod_remote && do_facet ost1 "rmmod obdecho" || true
11160         return $rc
11161 }
11162 run_test 180c "test huge bulk I/O size on obdfilter, don't LASSERT"
11163
11164 test_181() { # bug 22177
11165         test_mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11166         # create enough files to index the directory
11167         createmany -o $DIR/$tdir/foobar 4000
11168         # print attributes for debug purpose
11169         lsattr -d .
11170         # open dir
11171         multiop_bg_pause $DIR/$tdir D_Sc || return 1
11172         MULTIPID=$!
11173         # remove the files & current working dir
11174         unlinkmany $DIR/$tdir/foobar 4000
11175         rmdir $DIR/$tdir
11176         kill -USR1 $MULTIPID
11177         wait $MULTIPID
11178         stat $DIR/$tdir && error "open-unlinked dir was not removed!"
11179         return 0
11180 }
11181 run_test 181 "Test open-unlinked dir ========================"
11182
11183 test_182() {
11184         local fcount=1000
11185         local tcount=10
11186
11187         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11188
11189         $LCTL set_param mdc.*.rpc_stats=clear
11190
11191         for (( i = 0; i < $tcount; i++ )) ; do
11192                 mkdir $DIR/$tdir/$i
11193         done
11194
11195         for (( i = 0; i < $tcount; i++ )) ; do
11196                 createmany -o $DIR/$tdir/$i/f- $fcount &
11197         done
11198         wait
11199
11200         for (( i = 0; i < $tcount; i++ )) ; do
11201                 unlinkmany $DIR/$tdir/$i/f- $fcount &
11202         done
11203         wait
11204
11205         $LCTL get_param mdc.*.rpc_stats
11206
11207         rm -rf $DIR/$tdir
11208 }
11209 run_test 182 "Test parallel modify metadata operations ================"
11210
11211 test_183() { # LU-2275
11212         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11213         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.56) ]] &&
11214                 skip "Need MDS version at least 2.3.56" && return
11215
11216         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11217         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11218         echo aaa > $DIR/$tdir/$tfile
11219
11220 #define OBD_FAIL_MDS_NEGATIVE_POSITIVE  0x148
11221         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x148
11222
11223         ls -l $DIR/$tdir && error "ls succeeded, should have failed"
11224         cat $DIR/$tdir/$tfile && error "cat succeeded, should have failed"
11225
11226         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
11227
11228         # Flush negative dentry cache
11229         touch $DIR/$tdir/$tfile
11230
11231         # We are not checking for any leaked references here, they'll
11232         # become evident next time we do cleanup with module unload.
11233         rm -rf $DIR/$tdir
11234 }
11235 run_test 183 "No crash or request leak in case of strange dispositions ========"
11236
11237 # test suite 184 is for LU-2016, LU-2017
11238 test_184a() {
11239         check_swap_layouts_support && return 0
11240
11241         dir0=$DIR/$tdir/$testnum
11242         test_mkdir -p -c1 $dir0 || error "creating dir $dir0"
11243         ref1=/etc/passwd
11244         ref2=/etc/group
11245         file1=$dir0/f1
11246         file2=$dir0/f2
11247         $SETSTRIPE -c1 $file1
11248         cp $ref1 $file1
11249         $SETSTRIPE -c2 $file2
11250         cp $ref2 $file2
11251         gen1=$($GETSTRIPE -g $file1)
11252         gen2=$($GETSTRIPE -g $file2)
11253
11254         $LFS swap_layouts $file1 $file2 || error "swap of file layout failed"
11255         gen=$($GETSTRIPE -g $file1)
11256         [[ $gen1 != $gen ]] ||
11257                 "Layout generation on $file1 does not change"
11258         gen=$($GETSTRIPE -g $file2)
11259         [[ $gen2 != $gen ]] ||
11260                 "Layout generation on $file2 does not change"
11261
11262         cmp $ref1 $file2 || error "content compare failed ($ref1 != $file2)"
11263         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
11264 }
11265 run_test 184a "Basic layout swap"
11266
11267 test_184b() {
11268         check_swap_layouts_support && return 0
11269
11270         dir0=$DIR/$tdir/$testnum
11271         mkdir -p $dir0 || error "creating dir $dir0"
11272         file1=$dir0/f1
11273         file2=$dir0/f2
11274         file3=$dir0/f3
11275         dir1=$dir0/d1
11276         dir2=$dir0/d2
11277         mkdir $dir1 $dir2
11278         $SETSTRIPE -c1 $file1
11279         $SETSTRIPE -c2 $file2
11280         $SETSTRIPE -c1 $file3
11281         chown $RUNAS_ID $file3
11282         gen1=$($GETSTRIPE -g $file1)
11283         gen2=$($GETSTRIPE -g $file2)
11284
11285         $LFS swap_layouts $dir1 $dir2 &&
11286                 error "swap of directories layouts should fail"
11287         $LFS swap_layouts $dir1 $file1 &&
11288                 error "swap of directory and file layouts should fail"
11289         $RUNAS $LFS swap_layouts $file1 $file2 &&
11290                 error "swap of file we cannot write should fail"
11291         $LFS swap_layouts $file1 $file3 &&
11292                 error "swap of file with different owner should fail"
11293         /bin/true # to clear error code
11294 }
11295 run_test 184b "Forbidden layout swap (will generate errors)"
11296
11297 test_184c() {
11298         check_swap_layouts_support && return 0
11299
11300         local dir0=$DIR/$tdir/$testnum
11301         mkdir -p $dir0 || error "creating dir $dir0"
11302
11303         local ref1=$dir0/ref1
11304         local ref2=$dir0/ref2
11305         local file1=$dir0/file1
11306         local file2=$dir0/file2
11307         # create a file large enough for the concurrent test
11308         dd if=/dev/urandom of=$ref1 bs=1M count=$((RANDOM % 50 + 20))
11309         dd if=/dev/urandom of=$ref2 bs=1M count=$((RANDOM % 50 + 20))
11310         echo "ref file size: ref1($(stat -c %s $ref1))," \
11311              "ref2($(stat -c %s $ref2))"
11312
11313         cp $ref2 $file2
11314         dd if=$ref1 of=$file1 bs=16k &
11315         local DD_PID=$!
11316
11317         # Make sure dd starts to copy file
11318         while [ ! -f $file1 ]; do sleep 0.1; done
11319
11320         $LFS swap_layouts $file1 $file2
11321         local rc=$?
11322         wait $DD_PID
11323         [[ $? == 0 ]] || error "concurrent write on $file1 failed"
11324         [[ $rc == 0 ]] || error "swap of $file1 and $file2 failed"
11325
11326         # how many bytes copied before swapping layout
11327         local copied=$(stat -c %s $file2)
11328         local remaining=$(stat -c %s $ref1)
11329         remaining=$((remaining - copied))
11330         echo "Copied $copied bytes before swapping layout..."
11331
11332         cmp -n $copied $file1 $ref2 | grep differ &&
11333                 error "Content mismatch [0, $copied) of ref2 and file1"
11334         cmp -n $copied $file2 $ref1 ||
11335                 error "Content mismatch [0, $copied) of ref1 and file2"
11336         cmp -i $copied:$copied -n $remaining $file1 $ref1 ||
11337                 error "Content mismatch [$copied, EOF) of ref1 and file1"
11338
11339         # clean up
11340         rm -f $ref1 $ref2 $file1 $file2
11341 }
11342 run_test 184c "Concurrent write and layout swap"
11343
11344 test_184d() {
11345         check_swap_layouts_support && return 0
11346         [ -z "$(which getfattr 2>/dev/null)" ] &&
11347                 skip "no getfattr command" && return 0
11348
11349         local file1=$DIR/$tdir/$tfile-1
11350         local file2=$DIR/$tdir/$tfile-2
11351         local file3=$DIR/$tdir/$tfile-3
11352         local lovea1
11353         local lovea2
11354
11355         mkdir -p $DIR/$tdir
11356         touch $file1 || error "create $file1 failed"
11357         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11358                 error "create $file2 failed"
11359         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11360                 error "create $file3 failed"
11361         lovea1=$($LFS getstripe $file1 | sed 1d)
11362
11363         $LFS swap_layouts $file2 $file3 ||
11364                 error "swap $file2 $file3 layouts failed"
11365         $LFS swap_layouts $file1 $file2 ||
11366                 error "swap $file1 $file2 layouts failed"
11367
11368         lovea2=$($LFS getstripe $file2 | sed 1d)
11369         [ "$lovea1" == "$lovea2" ] || error "lovea $lovea1 != $lovea2"
11370
11371         lovea1=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11372         [[ -z "$lovea1" ]] || error "$file1 shouldn't have lovea"
11373 }
11374 run_test 184d "allow stripeless layouts swap"
11375
11376 test_184e() {
11377         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.94) ]] ||
11378                 { skip "Need MDS version at least 2.6.94"; return 0; }
11379         check_swap_layouts_support && return 0
11380         [ -z "$(which getfattr 2>/dev/null)" ] &&
11381                 skip "no getfattr command" && return 0
11382
11383         local file1=$DIR/$tdir/$tfile-1
11384         local file2=$DIR/$tdir/$tfile-2
11385         local file3=$DIR/$tdir/$tfile-3
11386         local lovea
11387
11388         mkdir -p $DIR/$tdir
11389         touch $file1 || error "create $file1 failed"
11390         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 ||
11391                 error "create $file2 failed"
11392         $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 ||
11393                 error "create $file3 failed"
11394
11395         $LFS swap_layouts $file1 $file2 ||
11396                 error "swap $file1 $file2 layouts failed"
11397
11398         lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted)
11399         [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea"
11400
11401         echo 123 > $file1 || error "Should be able to write into $file1"
11402
11403         $LFS swap_layouts $file1 $file3 ||
11404                 error "swap $file1 $file3 layouts failed"
11405
11406         echo 123 > $file1 || error "Should be able to write into $file1"
11407
11408         rm -rf $file1 $file2 $file3
11409 }
11410 run_test 184e "Recreate layout after stripeless layout swaps"
11411
11412 test_185() { # LU-2441
11413         # LU-3553 - no volatile file support in old servers
11414         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.60) ]] ||
11415                 { skip "Need MDS version at least 2.3.60"; return 0; }
11416
11417         mkdir -p $DIR/$tdir || error "creating dir $DIR/$tdir"
11418         touch $DIR/$tdir/spoo
11419         local mtime1=$(stat -c "%Y" $DIR/$tdir)
11420         local fid=$($MULTIOP $DIR/$tdir VFw4096c) ||
11421                 error "cannot create/write a volatile file"
11422         $CHECKSTAT -t file $MOUNT/.lustre/fid/$fid 2>/dev/null &&
11423                 error "FID is still valid after close"
11424
11425         multiop_bg_pause $DIR/$tdir vVw4096_c
11426         local multi_pid=$!
11427
11428         local OLD_IFS=$IFS
11429         IFS=":"
11430         local fidv=($fid)
11431         IFS=$OLD_IFS
11432         # assume that the next FID for this client is sequential, since stdout
11433         # is unfortunately eaten by multiop_bg_pause
11434         local n=$((${fidv[1]} + 1))
11435         local next_fid="${fidv[0]}:$(printf "0x%x" $n):${fidv[2]}"
11436         $CHECKSTAT -t file $MOUNT/.lustre/fid/$next_fid ||
11437                 error "FID is missing before close"
11438         kill -USR1 $multi_pid
11439         # 1 second delay, so if mtime change we will see it
11440         sleep 1
11441         local mtime2=$(stat -c "%Y" $DIR/$tdir)
11442         [[ $mtime1 == $mtime2 ]] || error "mtime has changed"
11443 }
11444 run_test 185 "Volatile file support"
11445
11446 test_187a() {
11447         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11448         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
11449                 skip "Need MDS version at least 2.3.0" && return
11450
11451         local dir0=$DIR/$tdir/$testnum
11452         mkdir -p $dir0 || error "creating dir $dir0"
11453
11454         local file=$dir0/file1
11455         dd if=/dev/urandom of=$file count=10 bs=1M conv=fsync
11456         local dv1=$($LFS data_version $file)
11457         dd if=/dev/urandom of=$file seek=10 count=1 bs=1M conv=fsync
11458         local dv2=$($LFS data_version $file)
11459         [[ $dv1 != $dv2 ]] ||
11460                 error "data version did not change on write $dv1 == $dv2"
11461
11462         # clean up
11463         rm -f $file1
11464 }
11465 run_test 187a "Test data version change"
11466
11467 test_187b() {
11468         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11469         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.0) ] &&
11470                 skip "Need MDS version at least 2.3.0" && return
11471
11472         local dir0=$DIR/$tdir/$testnum
11473         mkdir -p $dir0 || error "creating dir $dir0"
11474
11475         declare -a DV=$($MULTIOP $dir0 Vw1000xYw1000xY | cut -f3 -d" ")
11476         [[ ${DV[0]} != ${DV[1]} ]] ||
11477                 error "data version did not change on write"\
11478                       " ${DV[0]} == ${DV[1]}"
11479
11480         # clean up
11481         rm -f $file1
11482 }
11483 run_test 187b "Test data version change on volatile file"
11484
11485 test_200() {
11486         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11487         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11488
11489         local POOL=${POOL:-cea1}
11490         local POOL_ROOT=${POOL_ROOT:-$DIR/d200.pools}
11491         local POOL_DIR_NAME=${POOL_DIR_NAME:-dir_tst}
11492         # Pool OST targets
11493         local first_ost=0
11494         local last_ost=$(($OSTCOUNT - 1))
11495         local ost_step=2
11496         local ost_list=$(seq $first_ost $ost_step $last_ost)
11497         local ost_range="$first_ost $last_ost $ost_step"
11498         local test_path=$POOL_ROOT/$POOL_DIR_NAME
11499         local file_dir=$POOL_ROOT/file_tst
11500         local subdir=$test_path/subdir
11501
11502         local rc=0
11503         while : ; do
11504                 # former test_200a test_200b
11505                 pool_add $POOL                          || { rc=$? ; break; }
11506                 pool_add_targets  $POOL $ost_range      || { rc=$? ; break; }
11507                 # former test_200c test_200d
11508                 mkdir -p $test_path
11509                 pool_set_dir      $POOL $test_path      || { rc=$? ; break; }
11510                 pool_check_dir    $POOL $test_path      || { rc=$? ; break; }
11511                 mkdir -p $subdir
11512                 pool_check_dir    $POOL $subdir         || { rc=$? ; break; }
11513                 pool_dir_rel_path $POOL $POOL_DIR_NAME $POOL_ROOT \
11514                                                         || { rc=$? ; break; }
11515                 # former test_200e test_200f
11516                 local files=$((OSTCOUNT*3))
11517                 pool_alloc_files  $POOL $test_path $files "$ost_list" \
11518                                                         || { rc=$? ; break; }
11519                 pool_create_files $POOL $file_dir $files "$ost_list" \
11520                                                         || { rc=$? ; break; }
11521                 # former test_200g test_200h
11522                 pool_lfs_df $POOL                       || { rc=$? ; break; }
11523                 pool_file_rel_path $POOL $test_path     || { rc=$? ; break; }
11524
11525                 # former test_201a test_201b test_201c
11526                 pool_remove_first_target $POOL          || { rc=$? ; break; }
11527
11528                 local f=$test_path/$tfile
11529                 pool_remove_all_targets $POOL $f        || { rc=$? ; break; }
11530                 pool_remove $POOL $f                    || { rc=$? ; break; }
11531                 break
11532         done
11533
11534         cleanup_pools
11535         return $rc
11536 }
11537 run_test 200 "OST pools"
11538
11539 # usage: default_attr <count | size | offset>
11540 default_attr() {
11541         $LCTL get_param -n lov.$FSNAME-clilov-\*.stripe${1}
11542 }
11543
11544 # usage: check_default_stripe_attr
11545 check_default_stripe_attr() {
11546         ACTUAL=$($GETSTRIPE $* $DIR/$tdir)
11547         case $1 in
11548         --stripe-count|--count)
11549                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr count);;
11550         --stripe-size|--size)
11551                 [ -n "$2" ] && EXPECTED=0 || EXPECTED=$(default_attr size);;
11552         --stripe-index|--index)
11553                 EXPECTED=-1;;
11554         *)
11555                 error "unknown getstripe attr '$1'"
11556         esac
11557
11558         [ $ACTUAL != $EXPECTED ] &&
11559                 error "$DIR/$tdir has $1 '$ACTUAL', not '$EXPECTED'"
11560 }
11561
11562 test_204a() {
11563         test_mkdir -p $DIR/$tdir
11564         $SETSTRIPE --stripe-count 0 --stripe-size 0 --stripe-index -1 $DIR/$tdir
11565
11566         check_default_stripe_attr --stripe-count
11567         check_default_stripe_attr --stripe-size
11568         check_default_stripe_attr --stripe-index
11569
11570         return 0
11571 }
11572 run_test 204a "Print default stripe attributes ================="
11573
11574 test_204b() {
11575         test_mkdir -p $DIR/$tdir
11576         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11577
11578         check_default_stripe_attr --stripe-size
11579         check_default_stripe_attr --stripe-index
11580
11581         return 0
11582 }
11583 run_test 204b "Print default stripe size and offset  ==========="
11584
11585 test_204c() {
11586         test_mkdir -p $DIR/$tdir
11587         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11588
11589         check_default_stripe_attr --stripe-count
11590         check_default_stripe_attr --stripe-index
11591
11592         return 0
11593 }
11594 run_test 204c "Print default stripe count and offset ==========="
11595
11596 test_204d() {
11597         test_mkdir -p $DIR/$tdir
11598         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11599
11600         check_default_stripe_attr --stripe-count
11601         check_default_stripe_attr --stripe-size
11602
11603         return 0
11604 }
11605 run_test 204d "Print default stripe count and size ============="
11606
11607 test_204e() {
11608         test_mkdir -p $DIR/$tdir
11609         $SETSTRIPE -d $DIR/$tdir
11610
11611         check_default_stripe_attr --stripe-count --raw
11612         check_default_stripe_attr --stripe-size --raw
11613         check_default_stripe_attr --stripe-index --raw
11614
11615         return 0
11616 }
11617 run_test 204e "Print raw stripe attributes ================="
11618
11619 test_204f() {
11620         test_mkdir -p $DIR/$tdir
11621         $SETSTRIPE --stripe-count 1 $DIR/$tdir
11622
11623         check_default_stripe_attr --stripe-size --raw
11624         check_default_stripe_attr --stripe-index --raw
11625
11626         return 0
11627 }
11628 run_test 204f "Print raw stripe size and offset  ==========="
11629
11630 test_204g() {
11631         test_mkdir -p $DIR/$tdir
11632         $SETSTRIPE --stripe-size 65536 $DIR/$tdir
11633
11634         check_default_stripe_attr --stripe-count --raw
11635         check_default_stripe_attr --stripe-index --raw
11636
11637         return 0
11638 }
11639 run_test 204g "Print raw stripe count and offset ==========="
11640
11641 test_204h() {
11642         test_mkdir -p $DIR/$tdir
11643         $SETSTRIPE --stripe-index 0 $DIR/$tdir
11644
11645         check_default_stripe_attr --stripe-count --raw
11646         check_default_stripe_attr --stripe-size --raw
11647
11648         return 0
11649 }
11650 run_test 204h "Print raw stripe count and size ============="
11651
11652 # Figure out which job scheduler is being used, if any,
11653 # or use a fake one
11654 if [ -n "$SLURM_JOB_ID" ]; then # SLURM
11655         JOBENV=SLURM_JOB_ID
11656 elif [ -n "$LSB_JOBID" ]; then # Load Sharing Facility
11657         JOBENV=LSB_JOBID
11658 elif [ -n "$PBS_JOBID" ]; then # PBS/Maui/Moab
11659         JOBENV=PBS_JOBID
11660 elif [ -n "$LOADL_STEPID" ]; then # LoadLeveller
11661         JOBENV=LOADL_STEP_ID
11662 elif [ -n "$JOB_ID" ]; then # Sun Grid Engine
11663         JOBENV=JOB_ID
11664 else
11665         $LCTL list_param jobid_name > /dev/null 2>&1
11666         if [ $? -eq 0 ]; then
11667                 JOBENV=nodelocal
11668         else
11669                 JOBENV=FAKE_JOBID
11670         fi
11671 fi
11672
11673 verify_jobstats() {
11674         local cmd=($1)
11675         shift
11676         local facets="$@"
11677
11678 # we don't really need to clear the stats for this test to work, since each
11679 # command has a unique jobid, but it makes debugging easier if needed.
11680 #       for facet in $facets; do
11681 #               local dev=$(convert_facet2label $facet)
11682 #               # clear old jobstats
11683 #               do_facet $facet lctl set_param *.$dev.job_stats="clear"
11684 #       done
11685
11686         # use a new JobID for each test, or we might see an old one
11687         [ "$JOBENV" = "FAKE_JOBID" ] &&
11688                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
11689
11690         JOBVAL=${!JOBENV}
11691
11692         [ "$JOBENV" = "nodelocal" ] && {
11693                 FAKE_JOBID=id.$testnum.$(basename ${cmd[0]}).$RANDOM
11694                 $LCTL set_param jobid_name=$FAKE_JOBID
11695                 JOBVAL=$FAKE_JOBID
11696         }
11697
11698         log "Test: ${cmd[*]}"
11699         log "Using JobID environment variable $JOBENV=$JOBVAL"
11700
11701         if [ $JOBENV = "FAKE_JOBID" ]; then
11702                 FAKE_JOBID=$JOBVAL ${cmd[*]}
11703         else
11704                 ${cmd[*]}
11705         fi
11706
11707         # all files are created on OST0000
11708         for facet in $facets; do
11709                 local stats="*.$(convert_facet2label $facet).job_stats"
11710                 if [ $(do_facet $facet lctl get_param $stats |
11711                        grep -c $JOBVAL) -ne 1 ]; then
11712                         do_facet $facet lctl get_param $stats
11713                         error "No jobstats for $JOBVAL found on $facet::$stats"
11714                 fi
11715         done
11716 }
11717
11718 jobstats_set() {
11719         trap 0
11720         NEW_JOBENV=${1:-$OLD_JOBENV}
11721         do_facet mgs $LCTL conf_param $FSNAME.sys.jobid_var=$NEW_JOBENV
11722         wait_update $HOSTNAME "$LCTL get_param -n jobid_var" $NEW_JOBENV
11723 }
11724
11725 cleanup_205() {
11726         do_facet $SINGLEMDS \
11727                 $LCTL set_param mdt.*.job_cleanup_interval=$OLD_INTERVAL
11728         [ $OLD_JOBENV != $JOBENV ] && jobstats_set $OLD_JOBENV
11729         do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
11730 }
11731
11732 test_205() { # Job stats
11733         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
11734         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
11735         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11736         remote_ost_nodsh && skip "remote OST with nodsh" && return
11737
11738         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep jobstats)" ] &&
11739                 skip "Server doesn't support jobstats" && return 0
11740         [[ $JOBID_VAR = disable ]] && skip "jobstats is disabled" && return
11741
11742         OLD_JOBENV=$($LCTL get_param -n jobid_var)
11743         if [ $OLD_JOBENV != $JOBENV ]; then
11744                 jobstats_set $JOBENV
11745                 trap cleanup_205 EXIT
11746         fi
11747
11748         CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
11749         echo "Registered as changelog user $CL_USER"
11750
11751         OLD_INTERVAL=$(do_facet $SINGLEMDS \
11752                        lctl get_param -n mdt.*.job_cleanup_interval)
11753         local interval_new=5
11754         do_facet $SINGLEMDS \
11755                 $LCTL set_param mdt.*.job_cleanup_interval=$interval_new
11756         local start=$SECONDS
11757
11758         local cmd
11759         # mkdir
11760         cmd="mkdir $DIR/$tdir"
11761         verify_jobstats "$cmd" "$SINGLEMDS"
11762         # rmdir
11763         cmd="rmdir $DIR/$tdir"
11764         verify_jobstats "$cmd" "$SINGLEMDS"
11765         # mkdir on secondary MDT
11766         if [ $MDSCOUNT -gt 1 ]; then
11767                 cmd="lfs mkdir -i 1 $DIR/$tdir.remote"
11768                 verify_jobstats "$cmd" "mds2"
11769         fi
11770         # mknod
11771         cmd="mknod $DIR/$tfile c 1 3"
11772         verify_jobstats "$cmd" "$SINGLEMDS"
11773         # unlink
11774         cmd="rm -f $DIR/$tfile"
11775         verify_jobstats "$cmd" "$SINGLEMDS"
11776         # create all files on OST0000 so verify_jobstats can find OST stats
11777         # open & close
11778         cmd="$SETSTRIPE -i 0 -c 1 $DIR/$tfile"
11779         verify_jobstats "$cmd" "$SINGLEMDS"
11780         # setattr
11781         cmd="touch $DIR/$tfile"
11782         verify_jobstats "$cmd" "$SINGLEMDS ost1"
11783         # write
11784         cmd="dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 oflag=sync"
11785         verify_jobstats "$cmd" "ost1"
11786         # read
11787         cmd="dd if=$DIR/$tfile of=/dev/null bs=1M count=1 iflag=direct"
11788         verify_jobstats "$cmd" "ost1"
11789         # truncate
11790         cmd="$TRUNCATE $DIR/$tfile 0"
11791         verify_jobstats "$cmd" "$SINGLEMDS ost1"
11792         # rename
11793         cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
11794         verify_jobstats "$cmd" "$SINGLEMDS"
11795         # jobstats expiry - sleep until old stats should be expired
11796         local left=$((interval_new + 2 - (SECONDS - start)))
11797         [ $left -ge 0 ] && echo "sleep $left for expiry" && sleep $((left + 1))
11798         cmd="mkdir $DIR/$tdir.expire"
11799         verify_jobstats "$cmd" "$SINGLEMDS"
11800         [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
11801             grep -c "job_id.*mkdir") -gt 1 ] && error "old jobstats not expired"
11802
11803         # Ensure that jobid are present in changelog (if supported by MDS)
11804         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.52) ]
11805         then
11806                 $LFS changelog $MDT0 | tail -9
11807                 jobids=$($LFS changelog $MDT0 | tail -9 | grep -c "j=")
11808                 [ $jobids -eq 9 ] ||
11809                         error "Wrong changelog jobid count $jobids != 9"
11810
11811                 # LU-5862
11812                 JOBENV="disable"
11813                 jobstats_set $JOBENV
11814                 touch $DIR/$tfile
11815                 $LFS changelog $MDT0 | tail -1
11816                 jobids=$($LFS changelog $MDT0 | tail -1 | grep -c "j=")
11817                 [ $jobids -eq 0 ] ||
11818                         error "Unexpected jobids when jobid_var=$JOBENV"
11819         fi
11820
11821         cleanup_205
11822 }
11823 run_test 205 "Verify job stats"
11824
11825 # LU-1480, LU-1773 and LU-1657
11826 test_206() {
11827         mkdir -p $DIR/$tdir
11828         $SETSTRIPE -c -1 $DIR/$tdir
11829 #define OBD_FAIL_LOV_INIT 0x1403
11830         $LCTL set_param fail_loc=0xa0001403
11831         $LCTL set_param fail_val=1
11832         touch $DIR/$tdir/$tfile || true
11833 }
11834 run_test 206 "fail lov_init_raid0() doesn't lbug"
11835
11836 test_207a() {
11837         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11838         local fsz=`stat -c %s $DIR/$tfile`
11839         cancel_lru_locks mdc
11840
11841         # do not return layout in getattr intent
11842 #define OBD_FAIL_MDS_NO_LL_GETATTR 0x170
11843         $LCTL set_param fail_loc=0x170
11844         local sz=`stat -c %s $DIR/$tfile`
11845
11846         [ $fsz -eq $sz ] || error "file size expected $fsz, actual $sz"
11847
11848         rm -rf $DIR/$tfile
11849 }
11850 run_test 207a "can refresh layout at glimpse"
11851
11852 test_207b() {
11853         dd if=/dev/zero of=$DIR/$tfile bs=4k count=$((RANDOM%10+1))
11854         local cksum=`md5sum $DIR/$tfile`
11855         local fsz=`stat -c %s $DIR/$tfile`
11856         cancel_lru_locks mdc
11857         cancel_lru_locks osc
11858
11859         # do not return layout in getattr intent
11860 #define OBD_FAIL_MDS_NO_LL_OPEN 0x171
11861         $LCTL set_param fail_loc=0x171
11862
11863         # it will refresh layout after the file is opened but before read issues
11864         echo checksum is "$cksum"
11865         echo "$cksum" |md5sum -c --quiet || error "file differs"
11866
11867         rm -rf $DIR/$tfile
11868 }
11869 run_test 207b "can refresh layout at open"
11870
11871 test_208() {
11872         # FIXME: in this test suite, only RD lease is used. This is okay
11873         # for now as only exclusive open is supported. After generic lease
11874         # is done, this test suite should be revised. - Jinshan
11875
11876         remote_mds_nodsh && skip "remote MDS with nodsh" && return
11877         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.52) ]] ||
11878                 { skip "Need MDS version at least 2.4.52"; return 0; }
11879
11880         echo "==== test 1: verify get lease work"
11881         $MULTIOP $DIR/$tfile oO_CREAT:O_RDWR:eRE+eU || error "get lease error"
11882
11883         echo "==== test 2: verify lease can be broken by upcoming open"
11884         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11885         local PID=$!
11886         sleep 1
11887
11888         $MULTIOP $DIR/$tfile oO_RDONLY:c
11889         kill -USR1 $PID && wait $PID || error "break lease error"
11890
11891         echo "==== test 3: verify lease can't be granted if an open already exists"
11892         $MULTIOP $DIR/$tfile oO_RDONLY:_c &
11893         local PID=$!
11894         sleep 1
11895
11896         $MULTIOP $DIR/$tfile oO_RDONLY:eReUc && error "apply lease should fail"
11897         kill -USR1 $PID && wait $PID || error "open file error"
11898
11899         echo "==== test 4: lease can sustain over recovery"
11900         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E+eUc &
11901         PID=$!
11902         sleep 1
11903
11904         fail mds1
11905
11906         kill -USR1 $PID && wait $PID || error "lease broken over recovery"
11907
11908         echo "==== test 5: lease broken can't be regained by replay"
11909         $MULTIOP $DIR/$tfile oO_RDONLY:eR_E-eUc &
11910         PID=$!
11911         sleep 1
11912
11913         # open file to break lease and then recovery
11914         $MULTIOP $DIR/$tfile oO_RDWR:c || error "open file error"
11915         fail mds1
11916
11917         kill -USR1 $PID && wait $PID || error "lease not broken over recovery"
11918
11919         rm -f $DIR/$tfile
11920 }
11921 run_test 208 "Exclusive open"
11922
11923 test_209() {
11924         [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
11925                 skip_env "must have disp_stripe" && return
11926
11927         touch $DIR/$tfile
11928         sync; sleep 5; sync;
11929
11930         echo 3 > /proc/sys/vm/drop_caches
11931         req_before=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11932
11933         # open/close 500 times
11934         for i in $(seq 500); do
11935                 cat $DIR/$tfile
11936         done
11937
11938         echo 3 > /proc/sys/vm/drop_caches
11939         req_after=$(awk '/ptlrpc_cache / { print $2 }' /proc/slabinfo)
11940
11941         echo "before: $req_before, after: $req_after"
11942         [ $((req_after - req_before)) -ge 300 ] &&
11943                 error "open/close requests are not freed"
11944         return 0
11945 }
11946 run_test 209 "read-only open/close requests should be freed promptly"
11947
11948 test_212() {
11949         size=`date +%s`
11950         size=$((size % 8192 + 1))
11951         dd if=/dev/urandom of=$DIR/f212 bs=1k count=$size
11952         sendfile $DIR/f212 $DIR/f212.xyz || error "sendfile wrong"
11953         rm -f $DIR/f212 $DIR/f212.xyz
11954 }
11955 run_test 212 "Sendfile test ============================================"
11956
11957 test_213() {
11958         dd if=/dev/zero of=$DIR/$tfile bs=4k count=4
11959         cancel_lru_locks osc
11960         lctl set_param fail_loc=0x8000040f
11961         # generate a read lock
11962         cat $DIR/$tfile > /dev/null
11963         # write to the file, it will try to cancel the above read lock.
11964         cat /etc/hosts >> $DIR/$tfile
11965 }
11966 run_test 213 "OSC lock completion and cancel race don't crash - bug 18829"
11967
11968 test_214() { # for bug 20133
11969         mkdir -p $DIR/$tdir/d214c || error "mkdir $DIR/$tdir/d214c failed"
11970         for (( i=0; i < 340; i++ )) ; do
11971                 touch $DIR/$tdir/d214c/a$i
11972         done
11973
11974         ls -l $DIR/$tdir || error "ls -l $DIR/d214p failed"
11975         mv $DIR/$tdir/d214c $DIR/ || error "mv $DIR/d214p/d214c $DIR/ failed"
11976         ls $DIR/d214c || error "ls $DIR/d214c failed"
11977         rm -rf $DIR/$tdir || error "rm -rf $DIR/d214* failed"
11978         rm -rf $DIR/d214* || error "rm -rf $DIR/d214* failed"
11979 }
11980 run_test 214 "hash-indexed directory test - bug 20133"
11981
11982 # having "abc" as 1st arg, creates $TMP/lnet_abc.out and $TMP/lnet_abc.sys
11983 create_lnet_proc_files() {
11984         lctl get_param -n $1 >$TMP/lnet_$1.out || error "cannot read lnet.$1"
11985         sysctl lnet.$1 >$TMP/lnet_$1.sys_tmp || error "cannot read lnet.$1"
11986
11987         sed "s/^lnet.$1\ =\ //g" "$TMP/lnet_$1.sys_tmp" >$TMP/lnet_$1.sys
11988         rm -f "$TMP/lnet_$1.sys_tmp"
11989 }
11990
11991 # counterpart of create_lnet_proc_files
11992 remove_lnet_proc_files() {
11993         rm -f $TMP/lnet_$1.out $TMP/lnet_$1.sys
11994 }
11995
11996 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
11997 # 3rd arg as regexp for body
11998 check_lnet_proc_stats() {
11999         local l=$(cat "$TMP/lnet_$1" |wc -l)
12000         [ $l = 1 ] || (cat "$TMP/lnet_$1" && error "$2 is not of 1 line: $l")
12001
12002         grep -E "$3" "$TMP/lnet_$1" || (cat "$TMP/lnet_$1" && error "$2 misformatted")
12003 }
12004
12005 # uses 1st arg as trailing part of filename, 2nd arg as description for reports,
12006 # 3rd arg as regexp for body, 4th arg as regexp for 1st line, 5th arg is
12007 # optional and can be regexp for 2nd line (lnet.routes case)
12008 check_lnet_proc_entry() {
12009         local blp=2          # blp stands for 'position of 1st line of body'
12010         [ -z "$5" ] || blp=3 # lnet.routes case
12011
12012         local l=$(cat "$TMP/lnet_$1" |wc -l)
12013         # subtracting one from $blp because the body can be empty
12014         [ "$l" -ge "$(($blp - 1))" ] || (cat "$TMP/lnet_$1" && error "$2 is too short: $l")
12015
12016         sed -n '1 p' "$TMP/lnet_$1" |grep -E "$4" >/dev/null ||
12017                 (cat "$TMP/lnet_$1" && error "1st line of $2 misformatted")
12018
12019         [ "$5" = "" ] || sed -n '2 p' "$TMP/lnet_$1" |grep -E "$5" >/dev/null ||
12020                 (cat "$TMP/lnet_$1" && error "2nd line of $2 misformatted")
12021
12022         # bail out if any unexpected line happened
12023         sed -n "$blp p" "$TMP/lnet_$1" | grep -Ev "$3"
12024         [ "$?" != 0 ] || error "$2 misformatted"
12025 }
12026
12027 test_215() { # for bugs 18102, 21079, 21517
12028         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12029         local N='(0|[1-9][0-9]*)'       # non-negative numeric
12030         local P='[1-9][0-9]*'           # positive numeric
12031         local I='(0|-?[1-9][0-9]*|NA)'  # any numeric (0 | >0 | <0) or NA if no value
12032         local NET='[a-z][a-z0-9]*'      # LNET net like o2ib2
12033         local ADDR='[0-9.]+'            # LNET addr like 10.0.0.1
12034         local NID="$ADDR@$NET"          # LNET nid like 10.0.0.1@o2ib2
12035
12036         local L1 # regexp for 1st line
12037         local L2 # regexp for 2nd line (optional)
12038         local BR # regexp for the rest (body)
12039
12040         # lnet.stats should look as 11 space-separated non-negative numerics
12041         BR="^$N $N $N $N $N $N $N $N $N $N $N$"
12042         create_lnet_proc_files "stats"
12043         check_lnet_proc_stats "stats.sys" "lnet.stats" "$BR"
12044         remove_lnet_proc_files "stats"
12045
12046         # lnet.routes should look like this:
12047         # Routing disabled/enabled
12048         # net hops priority state router
12049         # where net is a string like tcp0, hops > 0, priority >= 0,
12050         # state is up/down,
12051         # router is a string like 192.168.1.1@tcp2
12052         L1="^Routing (disabled|enabled)$"
12053         L2="^net +hops +priority +state +router$"
12054         BR="^$NET +$N +(0|1) +(up|down) +$NID$"
12055         create_lnet_proc_files "routes"
12056         check_lnet_proc_entry "routes.sys" "lnet.routes" "$BR" "$L1" "$L2"
12057         remove_lnet_proc_files "routes"
12058
12059         # lnet.routers should look like this:
12060         # ref rtr_ref alive_cnt state last_ping ping_sent deadline down_ni router
12061         # where ref > 0, rtr_ref > 0, alive_cnt >= 0, state is up/down,
12062         # last_ping >= 0, ping_sent is boolean (0/1), deadline and down_ni are
12063         # numeric (0 or >0 or <0), router is a string like 192.168.1.1@tcp2
12064         L1="^ref +rtr_ref +alive_cnt +state +last_ping +ping_sent +deadline +down_ni +router$"
12065         BR="^$P +$P +$N +(up|down) +$N +(0|1) +$I +$I +$NID$"
12066         create_lnet_proc_files "routers"
12067         check_lnet_proc_entry "routers.sys" "lnet.routers" "$BR" "$L1"
12068         remove_lnet_proc_files "routers"
12069
12070         # lnet.peers should look like this:
12071         # nid refs state last max rtr min tx min queue
12072         # where nid is a string like 192.168.1.1@tcp2, refs > 0,
12073         # state is up/down/NA, max >= 0. last, rtr, min, tx, min are
12074         # numeric (0 or >0 or <0), queue >= 0.
12075         L1="^nid +refs +state +last +max +rtr +min +tx +min +queue$"
12076         BR="^$NID +$P +(up|down|NA) +$I +$N +$I +$I +$I +$I +$N$"
12077         create_lnet_proc_files "peers"
12078         check_lnet_proc_entry "peers.sys" "lnet.peers" "$BR" "$L1"
12079         remove_lnet_proc_files "peers"
12080
12081         # lnet.buffers  should look like this:
12082         # pages count credits min
12083         # where pages >=0, count >=0, credits and min are numeric (0 or >0 or <0)
12084         L1="^pages +count +credits +min$"
12085         BR="^ +$N +$N +$I +$I$"
12086         create_lnet_proc_files "buffers"
12087         check_lnet_proc_entry "buffers.sys" "lnet.buffers" "$BR" "$L1"
12088         remove_lnet_proc_files "buffers"
12089
12090         # lnet.nis should look like this:
12091         # nid status alive refs peer rtr max tx min
12092         # where nid is a string like 192.168.1.1@tcp2, status is up/down,
12093         # alive is numeric (0 or >0 or <0), refs >= 0, peer >= 0,
12094         # rtr >= 0, max >=0, tx and min are numeric (0 or >0 or <0).
12095         L1="^nid +status +alive +refs +peer +rtr +max +tx +min$"
12096         BR="^$NID +(up|down) +$I +$N +$N +$N +$N +$I +$I$"
12097         create_lnet_proc_files "nis"
12098         check_lnet_proc_entry "nis.sys" "lnet.nis" "$BR" "$L1"
12099         remove_lnet_proc_files "nis"
12100
12101         # can we successfully write to lnet.stats?
12102         lctl set_param -n stats=0 || error "cannot write to lnet.stats"
12103         sysctl -w lnet.stats=0 || error "cannot write to lnet.stats"
12104 }
12105 run_test 215 "lnet exists and has proper content - bugs 18102, 21079, 21517"
12106
12107 test_216() { # bug 20317
12108         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12109         remote_ost_nodsh && skip "remote OST with nodsh" && return
12110
12111         local node
12112         local facets=$(get_facets OST)
12113         local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
12114
12115         save_lustre_params client "osc.*.contention_seconds" > $p
12116         save_lustre_params $facets \
12117                 "ldlm.namespaces.filter-*.max_nolock_bytes" >> $p
12118         save_lustre_params $facets \
12119                 "ldlm.namespaces.filter-*.contended_locks" >> $p
12120         save_lustre_params $facets \
12121                 "ldlm.namespaces.filter-*.contention_seconds" >> $p
12122         clear_osc_stats
12123
12124         # agressive lockless i/o settings
12125         for node in $(osts_nodes); do
12126                 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'
12127         done
12128         lctl set_param -n osc.*.contention_seconds 60
12129
12130         $DIRECTIO write $DIR/$tfile 0 10 4096
12131         $CHECKSTAT -s 40960 $DIR/$tfile
12132
12133         # disable lockless i/o
12134         for node in $(osts_nodes); do
12135                 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'
12136         done
12137         lctl set_param -n osc.*.contention_seconds 0
12138         clear_osc_stats
12139
12140         dd if=/dev/zero of=$DIR/$tfile count=0
12141         $CHECKSTAT -s 0 $DIR/$tfile
12142
12143         restore_lustre_params <$p
12144         rm -f $p
12145         rm $DIR/$tfile
12146 }
12147 run_test 216 "check lockless direct write works and updates file size and kms correctly"
12148
12149 test_217() { # bug 22430
12150         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12151         local node
12152         local nid
12153
12154         for node in $(nodes_list); do
12155                 nid=$(host_nids_address $node $NETTYPE)
12156                 if [[ $nid = *-* ]] ; then
12157                         echo "lctl ping $nid@$NETTYPE"
12158                         lctl ping $nid@$NETTYPE
12159                 else
12160                         echo "skipping $node (no hyphen detected)"
12161                 fi
12162         done
12163 }
12164 run_test 217 "check lctl ping for hostnames with hiphen ('-')"
12165
12166 test_218() {
12167        # do directio so as not to populate the page cache
12168        log "creating a 10 Mb file"
12169        $MULTIOP $DIR/$tfile oO_CREAT:O_DIRECT:O_RDWR:w$((10*1048576))c || error "multiop failed while creating a file"
12170        log "starting reads"
12171        dd if=$DIR/$tfile of=/dev/null bs=4096 &
12172        log "truncating the file"
12173        $MULTIOP $DIR/$tfile oO_TRUNC:c || error "multiop failed while truncating the file"
12174        log "killing dd"
12175        kill %+ || true # reads might have finished
12176        echo "wait until dd is finished"
12177        wait
12178        log "removing the temporary file"
12179        rm -rf $DIR/$tfile || error "tmp file removal failed"
12180 }
12181 run_test 218 "parallel read and truncate should not deadlock ======================="
12182
12183 test_219() {
12184         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12185         # write one partial page
12186         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1
12187         # set no grant so vvp_io_commit_write will do sync write
12188         $LCTL set_param fail_loc=0x411
12189         # write a full page at the end of file
12190         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=1 conv=notrunc
12191
12192         $LCTL set_param fail_loc=0
12193         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
12194         $LCTL set_param fail_loc=0x411
12195         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
12196
12197         # LU-4201
12198         dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
12199         $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
12200 }
12201 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
12202
12203 test_220() { #LU-325
12204         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12205         remote_ost_nodsh && skip "remote OST with nodsh" && return
12206         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12207         remote_mgs_nodsh && skip "remote MGS with nodsh" && return
12208         local OSTIDX=0
12209
12210         # create on MDT0000 so the last_id and next_id are correct
12211         mkdir $DIR/$tdir
12212         local OST=$($LFS df $DIR | awk '/OST:'$OSTIDX'/ { print $1 }')
12213         OST=${OST%_UUID}
12214
12215         # on the mdt's osc
12216         local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $OST)
12217         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
12218                         osc.$mdtosc_proc1.prealloc_last_id)
12219         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
12220                         osc.$mdtosc_proc1.prealloc_next_id)
12221
12222         $LFS df -i
12223
12224         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=-1
12225         #define OBD_FAIL_OST_ENOINO              0x229
12226         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0x229
12227         do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
12228         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $OST || return 2
12229
12230         $SETSTRIPE $DIR/$tdir -i $OSTIDX -c 1 -p $FSNAME.$TESTNAME
12231
12232         MDSOBJS=$((last_id - next_id))
12233         echo "preallocated objects on MDS is $MDSOBJS" "($last_id - $next_id)"
12234
12235         blocks=$($LFS df $MOUNT | awk '($1 == '$OSTIDX') { print $4 }')
12236         echo "OST still has $count kbytes free"
12237
12238         echo "create $MDSOBJS files @next_id..."
12239         createmany -o $DIR/$tdir/f $MDSOBJS || return 3
12240
12241         local last_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12242                         osc.$mdtosc_proc1.prealloc_last_id)
12243         local next_id2=$(do_facet mds${MDSIDX} lctl get_param -n \
12244                         osc.$mdtosc_proc1.prealloc_next_id)
12245
12246         echo "after creation, last_id=$last_id2, next_id=$next_id2"
12247         $LFS df -i
12248
12249         echo "cleanup..."
12250
12251         do_facet ost$((OSTIDX + 1)) lctl set_param fail_val=0
12252         do_facet ost$((OSTIDX + 1)) lctl set_param fail_loc=0
12253
12254         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $OST || return 4
12255         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
12256         echo "unlink $MDSOBJS files @$next_id..."
12257         unlinkmany $DIR/$tdir/f $MDSOBJS || return 6
12258 }
12259 run_test 220 "preallocated MDS objects still used if ENOSPC from OST"
12260
12261 test_221() {
12262         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12263         dd if=`which date` of=$MOUNT/date oflag=sync
12264         chmod +x $MOUNT/date
12265
12266         #define OBD_FAIL_LLITE_FAULT_TRUNC_RACE  0x1401
12267         $LCTL set_param fail_loc=0x80001401
12268
12269         $MOUNT/date > /dev/null
12270         rm -f $MOUNT/date
12271 }
12272 run_test 221 "make sure fault and truncate race to not cause OOM"
12273
12274 test_222a () {
12275         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12276        rm -rf $DIR/$tdir
12277        test_mkdir -p $DIR/$tdir
12278        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12279        createmany -o $DIR/$tdir/$tfile 10
12280        cancel_lru_locks mdc
12281        cancel_lru_locks osc
12282        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12283        $LCTL set_param fail_loc=0x31a
12284        ls -l $DIR/$tdir > /dev/null || error "AGL for ls failed"
12285        $LCTL set_param fail_loc=0
12286        rm -r $DIR/$tdir
12287 }
12288 run_test 222a "AGL for ls should not trigger CLIO lock failure ================"
12289
12290 test_222b () {
12291         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12292        rm -rf $DIR/$tdir
12293        test_mkdir -p $DIR/$tdir
12294        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12295        createmany -o $DIR/$tdir/$tfile 10
12296        cancel_lru_locks mdc
12297        cancel_lru_locks osc
12298        #define OBD_FAIL_LDLM_AGL_DELAY           0x31a
12299        $LCTL set_param fail_loc=0x31a
12300        rm -r $DIR/$tdir || "AGL for rmdir failed"
12301        $LCTL set_param fail_loc=0
12302 }
12303 run_test 222b "AGL for rmdir should not trigger CLIO lock failure ============="
12304
12305 test_223 () {
12306         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12307        rm -rf $DIR/$tdir
12308        test_mkdir -p $DIR/$tdir
12309        $SETSTRIPE -c 1 -i 0 $DIR/$tdir
12310        createmany -o $DIR/$tdir/$tfile 10
12311        cancel_lru_locks mdc
12312        cancel_lru_locks osc
12313        #define OBD_FAIL_LDLM_AGL_NOLOCK          0x31b
12314        $LCTL set_param fail_loc=0x31b
12315        ls -l $DIR/$tdir > /dev/null || error "reenqueue failed"
12316        $LCTL set_param fail_loc=0
12317        rm -r $DIR/$tdir
12318 }
12319 run_test 223 "osc reenqueue if without AGL lock granted ======================="
12320
12321 test_224a() { # LU-1039, MRP-303
12322         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12323         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB   0x508
12324         $LCTL set_param fail_loc=0x508
12325         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync
12326         $LCTL set_param fail_loc=0
12327         df $DIR
12328 }
12329 run_test 224a "Don't panic on bulk IO failure"
12330
12331 test_224b() { # LU-1039, MRP-303
12332         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12333         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
12334         cancel_lru_locks osc
12335         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB2   0x515
12336         $LCTL set_param fail_loc=0x515
12337         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1
12338         $LCTL set_param fail_loc=0
12339         df $DIR
12340 }
12341 run_test 224b "Don't panic on bulk IO failure"
12342
12343 test_224c() { # LU-6441
12344         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12345         local pages_per_rpc=$($LCTL get_param \
12346                                 osc.*.max_pages_per_rpc)
12347         local at_max=$($LCTL get_param -n at_max)
12348         local timeout=$($LCTL get_param -n timeout)
12349         local test_at="$LCTL get_param -n at_max"
12350         local param_at="$FSNAME.sys.at_max"
12351         local test_timeout="$LCTL get_param -n timeout"
12352         local param_timeout="$FSNAME.sys.timeout"
12353
12354         $LCTL set_param -n osc.*.max_pages_per_rpc=1024
12355
12356         set_conf_param_and_check client "$test_at" "$param_at" 0 ||
12357                 error "conf_param at_max=0 failed"
12358         set_conf_param_and_check client "$test_timeout" "$param_timeout" 5 ||
12359                 error "conf_param timeout=5 failed"
12360
12361         #define OBD_FAIL_PTLRPC_CLIENT_BULK_CB3   0x520
12362         $LCTL set_param fail_loc=0x520
12363         dd if=/dev/zero of=$DIR/$tfile bs=8MB count=1
12364         sync
12365         $LCTL set_param fail_loc=0
12366
12367         set_conf_param_and_check client "$test_at" "$param_at" $at_max ||
12368                 error "conf_param at_max=$at_max failed"
12369         set_conf_param_and_check client "$test_timeout" "$param_timeout" \
12370                 $timeout || error "conf_param timeout=$timeout failed"
12371
12372         $LCTL set_param -n $pages_per_rpc
12373 }
12374 run_test 224c "Don't hang if one of md lost during large bulk RPC"
12375
12376 MDSSURVEY=${MDSSURVEY:-$(which mds-survey 2>/dev/null || true)}
12377 test_225a () {
12378         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12379         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12380         if [ -z ${MDSSURVEY} ]; then
12381               skip_env "mds-survey not found" && return
12382         fi
12383
12384         [ $MDSCOUNT -ge 2 ] &&
12385                 skip "skipping now for more than one MDT" && return
12386
12387        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12388             { skip "Need MDS version at least 2.2.51"; return; }
12389
12390        local mds=$(facet_host $SINGLEMDS)
12391        local target=$(do_nodes $mds 'lctl dl' | \
12392                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12393
12394        local cmd1="file_count=1000 thrhi=4"
12395        local cmd2="dir_count=2 layer=mdd stripe_count=0"
12396        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12397        local cmd="$cmd1 $cmd2 $cmd3"
12398
12399        rm -f ${TMP}/mds_survey*
12400        echo + $cmd
12401        eval $cmd || error "mds-survey with zero-stripe failed"
12402        cat ${TMP}/mds_survey*
12403        rm -f ${TMP}/mds_survey*
12404 }
12405 run_test 225a "Metadata survey sanity with zero-stripe"
12406
12407 test_225b () {
12408         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12409         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12410         if [ -z ${MDSSURVEY} ]; then
12411               skip_env "mds-survey not found" && return
12412         fi
12413         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ] ||
12414             { skip "Need MDS version at least 2.2.51"; return; }
12415
12416         if [ $($LCTL dl | grep -c osc) -eq 0 ]; then
12417               skip_env "Need to mount OST to test" && return
12418         fi
12419
12420         [ $MDSCOUNT -ge 2 ] &&
12421                 skip "skipping now for more than one MDT" && return
12422        local mds=$(facet_host $SINGLEMDS)
12423        local target=$(do_nodes $mds 'lctl dl' | \
12424                       awk "{if (\$2 == \"UP\" && \$3 == \"mdt\") {print \$4}}")
12425
12426        local cmd1="file_count=1000 thrhi=4"
12427        local cmd2="dir_count=2 layer=mdd stripe_count=1"
12428        local cmd3="rslt_loc=${TMP} targets=\"$mds:$target\" $MDSSURVEY"
12429        local cmd="$cmd1 $cmd2 $cmd3"
12430
12431        rm -f ${TMP}/mds_survey*
12432        echo + $cmd
12433        eval $cmd || error "mds-survey with stripe_count failed"
12434        cat ${TMP}/mds_survey*
12435        rm -f ${TMP}/mds_survey*
12436 }
12437 run_test 225b "Metadata survey sanity with stripe_count = 1"
12438
12439 mcreate_path2fid () {
12440         local mode=$1
12441         local major=$2
12442         local minor=$3
12443         local name=$4
12444         local desc=$5
12445         local path=$DIR/$tdir/$name
12446         local fid
12447         local rc
12448         local fid_path
12449
12450         $MCREATE --mode=$1 --major=$2 --minor=$3 $path ||
12451                 error "cannot create $desc"
12452
12453         fid=$($LFS path2fid $path | tr -d '[' | tr -d ']')
12454         rc=$?
12455         [ $rc -ne 0 ] && error "cannot get fid of a $desc"
12456
12457         fid_path=$($LFS fid2path $MOUNT $fid)
12458         rc=$?
12459         [ $rc -ne 0 ] && error "cannot get path of $desc by $DIR $path $fid"
12460
12461         [ "$path" == "$fid_path" ] ||
12462                 error "fid2path returned $fid_path, expected $path"
12463
12464         echo "pass with $path and $fid"
12465 }
12466
12467 test_226a () {
12468         rm -rf $DIR/$tdir
12469         mkdir -p $DIR/$tdir
12470
12471         mcreate_path2fid 0010666 0 0 fifo "FIFO"
12472         mcreate_path2fid 0020666 1 3 null "character special file (null)"
12473         mcreate_path2fid 0020666 1 255 none "character special file (no device)"
12474         mcreate_path2fid 0040666 0 0 dir "directory"
12475         mcreate_path2fid 0060666 7 0 loop0 "block special file (loop)"
12476         mcreate_path2fid 0100666 0 0 file "regular file"
12477         mcreate_path2fid 0120666 0 0 link "symbolic link"
12478         mcreate_path2fid 0140666 0 0 sock "socket"
12479 }
12480 run_test 226a "call path2fid and fid2path on files of all type"
12481
12482 test_226b () {
12483         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12484         rm -rf $DIR/$tdir
12485         local MDTIDX=1
12486
12487         mkdir -p $DIR/$tdir
12488         $LFS setdirstripe -i $MDTIDX $DIR/$tdir/remote_dir ||
12489                 error "create remote directory failed"
12490         mcreate_path2fid 0010666 0 0 "remote_dir/fifo" "FIFO"
12491         mcreate_path2fid 0020666 1 3 "remote_dir/null" \
12492                                 "character special file (null)"
12493         mcreate_path2fid 0020666 1 255 "remote_dir/none" \
12494                                 "character special file (no device)"
12495         mcreate_path2fid 0040666 0 0 "remote_dir/dir" "directory"
12496         mcreate_path2fid 0060666 7 0 "remote_dir/loop0" \
12497                                 "block special file (loop)"
12498         mcreate_path2fid 0100666 0 0 "remote_dir/file" "regular file"
12499         mcreate_path2fid 0120666 0 0 "remote_dir/link" "symbolic link"
12500         mcreate_path2fid 0140666 0 0 "remote_dir/sock" "socket"
12501 }
12502 run_test 226b "call path2fid and fid2path on files of all type under remote dir"
12503
12504 # LU-1299 Executing or running ldd on a truncated executable does not
12505 # cause an out-of-memory condition.
12506 test_227() {
12507         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12508         [ -z "$(which ldd)" ] && skip "should have ldd tool" && return
12509         dd if=$(which date) of=$MOUNT/date bs=1k count=1
12510         chmod +x $MOUNT/date
12511
12512         $MOUNT/date > /dev/null
12513         ldd $MOUNT/date > /dev/null
12514         rm -f $MOUNT/date
12515 }
12516 run_test 227 "running truncated executable does not cause OOM"
12517
12518 # LU-1512 try to reuse idle OI blocks
12519 test_228a() {
12520         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12521         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12522         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12523                 skip "non-ldiskfs backend" && return
12524
12525         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12526         local myDIR=$DIR/$tdir
12527
12528         mkdir -p $myDIR
12529         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12530         $LCTL set_param fail_loc=0x80001002
12531         createmany -o $myDIR/t- 10000
12532         $LCTL set_param fail_loc=0
12533         # The guard is current the largest FID holder
12534         touch $myDIR/guard
12535         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12536                     tr -d '[')
12537         local IDX=$(($SEQ % 64))
12538
12539         do_facet $SINGLEMDS sync
12540         # Make sure journal flushed.
12541         sleep 6
12542         local blk1=$(do_facet $SINGLEMDS \
12543                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12544                      grep Blockcount | awk '{print $4}')
12545
12546         # Remove old files, some OI blocks will become idle.
12547         unlinkmany $myDIR/t- 10000
12548         # Create new files, idle OI blocks should be reused.
12549         createmany -o $myDIR/t- 2000
12550         do_facet $SINGLEMDS sync
12551         # Make sure journal flushed.
12552         sleep 6
12553         local blk2=$(do_facet $SINGLEMDS \
12554                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12555                      grep Blockcount | awk '{print $4}')
12556
12557         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12558 }
12559 run_test 228a "try to reuse idle OI blocks"
12560
12561 test_228b() {
12562         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12563         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12564         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12565                 skip "non-ldiskfs backend" && return
12566
12567         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12568         local myDIR=$DIR/$tdir
12569
12570         mkdir -p $myDIR
12571         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12572         $LCTL set_param fail_loc=0x80001002
12573         createmany -o $myDIR/t- 10000
12574         $LCTL set_param fail_loc=0
12575         # The guard is current the largest FID holder
12576         touch $myDIR/guard
12577         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12578                     tr -d '[')
12579         local IDX=$(($SEQ % 64))
12580
12581         do_facet $SINGLEMDS sync
12582         # Make sure journal flushed.
12583         sleep 6
12584         local blk1=$(do_facet $SINGLEMDS \
12585                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12586                      grep Blockcount | awk '{print $4}')
12587
12588         # Remove old files, some OI blocks will become idle.
12589         unlinkmany $myDIR/t- 10000
12590
12591         # stop the MDT
12592         stop $SINGLEMDS || error "Fail to stop MDT."
12593         # remount the MDT
12594         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
12595
12596         df $MOUNT || error "Fail to df."
12597         # Create new files, idle OI blocks should be reused.
12598         createmany -o $myDIR/t- 2000
12599         do_facet $SINGLEMDS sync
12600         # Make sure journal flushed.
12601         sleep 6
12602         local blk2=$(do_facet $SINGLEMDS \
12603                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12604                      grep Blockcount | awk '{print $4}')
12605
12606         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12607 }
12608 run_test 228b "idle OI blocks can be reused after MDT restart"
12609
12610 #LU-1881
12611 test_228c() {
12612         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12613         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12614         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
12615                 skip "non-ldiskfs backend" && return
12616
12617         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
12618         local myDIR=$DIR/$tdir
12619
12620         mkdir -p $myDIR
12621         #define OBD_FAIL_SEQ_EXHAUST             0x1002
12622         $LCTL set_param fail_loc=0x80001002
12623         # 20000 files can guarantee there are index nodes in the OI file
12624         createmany -o $myDIR/t- 20000
12625         $LCTL set_param fail_loc=0
12626         # The guard is current the largest FID holder
12627         touch $myDIR/guard
12628         local SEQ=$($LFS path2fid $myDIR/guard | awk -F ':' '{print $1}' |
12629                     tr -d '[')
12630         local IDX=$(($SEQ % 64))
12631
12632         do_facet $SINGLEMDS sync
12633         # Make sure journal flushed.
12634         sleep 6
12635         local blk1=$(do_facet $SINGLEMDS \
12636                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12637                      grep Blockcount | awk '{print $4}')
12638
12639         # Remove old files, some OI blocks will become idle.
12640         unlinkmany $myDIR/t- 20000
12641         rm -f $myDIR/guard
12642         # The OI file should become empty now
12643
12644         # Create new files, idle OI blocks should be reused.
12645         createmany -o $myDIR/t- 2000
12646         do_facet $SINGLEMDS sync
12647         # Make sure journal flushed.
12648         sleep 6
12649         local blk2=$(do_facet $SINGLEMDS \
12650                      "$DEBUGFS -c -R \\\"stat oi.16.${IDX}\\\" $MDT_DEV" |
12651                      grep Blockcount | awk '{print $4}')
12652
12653         [ $blk1 == $blk2 ] || error "old blk1=$blk1, new blk2=$blk2, unmatched!"
12654 }
12655 run_test 228c "NOT shrink the last entry in OI index node to recycle idle leaf"
12656
12657 test_229() { # LU-2482, LU-3448
12658         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ] &&
12659                 skip "No HSM $(lustre_build_version $SINGLEMDS) MDS < 2.4.53" &&
12660                 return
12661         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12662         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
12663
12664         rm -f $DIR/$tfile
12665
12666         # Create a file with a released layout and stripe count 2.
12667         $MULTIOP $DIR/$tfile H2c ||
12668                 error "failed to create file with released layout"
12669
12670         $GETSTRIPE -v $DIR/$tfile
12671
12672         local pattern=$($GETSTRIPE -L $DIR/$tfile)
12673         [ X"$pattern" = X"80000001" ] || error "pattern error ($pattern)"
12674
12675         local stripe_count=$($GETSTRIPE -c $DIR/$tfile) || error "getstripe"
12676         [ $stripe_count -eq 2 ] || error "stripe count not 2 ($stripe_count)"
12677         stat $DIR/$tfile || error "failed to stat released file"
12678
12679         chown $RUNAS_ID $DIR/$tfile ||
12680                 error "chown $RUNAS_ID $DIR/$tfile failed"
12681
12682         chgrp $RUNAS_ID $DIR/$tfile ||
12683                 error "chgrp $RUNAS_ID $DIR/$tfile failed"
12684
12685         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
12686         rm $DIR/$tfile || error "failed to remove released file"
12687 }
12688 run_test 229 "getstripe/stat/rm/attr changes work on released files"
12689
12690 test_230a() {
12691         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12692         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12693         local MDTIDX=1
12694
12695         test_mkdir $DIR/$tdir
12696         test_mkdir -i0 -c1 $DIR/$tdir/test_230_local
12697         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230_local)
12698         [ $mdt_idx -ne 0 ] &&
12699                 error "create local directory on wrong MDT $mdt_idx"
12700
12701         $LFS mkdir -i $MDTIDX $DIR/$tdir/test_230 ||
12702                         error "create remote directory failed"
12703         local mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230)
12704         [ $mdt_idx -ne $MDTIDX ] &&
12705                 error "create remote directory on wrong MDT $mdt_idx"
12706
12707         createmany -o $DIR/$tdir/test_230/t- 10 ||
12708                 error "create files on remote directory failed"
12709         mdt_idx=$($GETSTRIPE -M $DIR/$tdir/test_230/t-0)
12710         [ $mdt_idx -ne $MDTIDX ] && error "create files on wrong MDT $mdt_idx"
12711         rm -r $DIR/$tdir || error "unlink remote directory failed"
12712 }
12713 run_test 230a "Create remote directory and files under the remote directory"
12714
12715 test_230b() {
12716         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12717         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12718         local MDTIDX=1
12719         local mdt_index
12720         local i
12721         local file
12722         local pid
12723         local stripe_count
12724         local migrate_dir=$DIR/$tdir/migrate_dir
12725         local other_dir=$DIR/$tdir/other_dir
12726
12727         test_mkdir $DIR/$tdir
12728         test_mkdir -i0 -c1 $migrate_dir
12729         test_mkdir -i0 -c1 $other_dir
12730         for ((i=0; i<10; i++)); do
12731                 mkdir -p $migrate_dir/dir_${i}
12732                 createmany -o $migrate_dir/dir_${i}/f 10 ||
12733                         error "create files under remote dir failed $i"
12734         done
12735
12736         cp /etc/passwd $migrate_dir/$tfile
12737         cp /etc/passwd $other_dir/$tfile
12738         chattr +SAD $migrate_dir
12739         chattr +SAD $migrate_dir/$tfile
12740
12741         local old_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12742         local old_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12743         local old_dir_mode=$(stat -c%f $migrate_dir)
12744         local old_file_mode=$(stat -c%f $migrate_dir/$tfile)
12745
12746         mkdir -p $migrate_dir/dir_default_stripe2
12747         $SETSTRIPE -c 2 $migrate_dir/dir_default_stripe2
12748         $SETSTRIPE -c 2 $migrate_dir/${tfile}_stripe2
12749
12750         mkdir -p $other_dir
12751         ln $migrate_dir/$tfile $other_dir/luna
12752         ln $migrate_dir/$tfile $migrate_dir/sofia
12753         ln $other_dir/$tfile $migrate_dir/david
12754         ln -s $migrate_dir/$tfile $other_dir/zachary
12755         ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
12756         ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
12757
12758         $LFS migrate -m $MDTIDX $migrate_dir ||
12759                 error "fails on migrating remote dir to MDT1"
12760
12761         echo "migratate to MDT1, then checking.."
12762         for ((i = 0; i < 10; i++)); do
12763                 for file in $(find $migrate_dir/dir_${i}); do
12764                         mdt_index=$($LFS getstripe -M $file)
12765                         [ $mdt_index == $MDTIDX ] ||
12766                                 error "$file is not on MDT${MDTIDX}"
12767                 done
12768         done
12769
12770         # the multiple link file should still in MDT0
12771         mdt_index=$($LFS getstripe -M $migrate_dir/$tfile)
12772         [ $mdt_index == 0 ] ||
12773                 error "$file is not on MDT${MDTIDX}"
12774
12775         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12776         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12777                 error " expect $old_dir_flag get $new_dir_flag"
12778
12779         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12780         [ "$old_file_flag" = "$new_file_flag" ] ||
12781                 error " expect $old_file_flag get $new_file_flag"
12782
12783         local new_dir_mode=$(stat -c%f $migrate_dir)
12784         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12785                 error "expect mode $old_dir_mode get $new_dir_mode"
12786
12787         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12788         [ "$old_file_mode" = "$new_file_mode" ] ||
12789                 error "expect mode $old_file_mode get $new_file_mode"
12790
12791         diff /etc/passwd $migrate_dir/$tfile ||
12792                 error "$tfile different after migration"
12793
12794         diff /etc/passwd $other_dir/luna ||
12795                 error "luna different after migration"
12796
12797         diff /etc/passwd $migrate_dir/sofia ||
12798                 error "sofia different after migration"
12799
12800         diff /etc/passwd $migrate_dir/david ||
12801                 error "david different after migration"
12802
12803         diff /etc/passwd $other_dir/zachary ||
12804                 error "zachary different after migration"
12805
12806         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12807                 error "${tfile}_ln different after migration"
12808
12809         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12810                 error "${tfile}_ln_other different after migration"
12811
12812         stripe_count=$($LFS getstripe -c $migrate_dir/dir_default_stripe2)
12813         [ $stripe_count = 2 ] ||
12814                 error "dir strpe_count $d != 2 after migration."
12815
12816         stripe_count=$($LFS getstripe -c $migrate_dir/${tfile}_stripe2)
12817         [ $stripe_count = 2 ] ||
12818                 error "file strpe_count $d != 2 after migration."
12819
12820         #migrate back to MDT0
12821         MDTIDX=0
12822
12823         $LFS migrate -m $MDTIDX $migrate_dir ||
12824                 error "fails on migrating remote dir to MDT0"
12825
12826         echo "migrate back to MDT0, checking.."
12827         for file in $(find $migrate_dir); do
12828                 mdt_index=$($LFS getstripe -M $file)
12829                 [ $mdt_index == $MDTIDX ] ||
12830                         error "$file is not on MDT${MDTIDX}"
12831         done
12832
12833         local new_dir_flag=$(lsattr -a $migrate_dir | awk '/\/\.$/ {print $1}')
12834         [ "$old_dir_flag" = "$new_dir_flag" ] ||
12835                 error " expect $old_dir_flag get $new_dir_flag"
12836
12837         local new_file_flag=$(lsattr $migrate_dir/$tfile | awk '{print $1}')
12838         [ "$old_file_flag" = "$new_file_flag" ] ||
12839                 error " expect $old_file_flag get $new_file_flag"
12840
12841         local new_dir_mode=$(stat -c%f $migrate_dir)
12842         [ "$old_dir_mode" = "$new_dir_mode" ] ||
12843                 error "expect mode $old_dir_mode get $new_dir_mode"
12844
12845         local new_file_mode=$(stat -c%f $migrate_dir/$tfile)
12846         [ "$old_file_mode" = "$new_file_mode" ] ||
12847                 error "expect mode $old_file_mode get $new_file_mode"
12848
12849         diff /etc/passwd ${migrate_dir}/$tfile ||
12850                 error "$tfile different after migration"
12851
12852         diff /etc/passwd ${other_dir}/luna ||
12853                 error "luna different after migration"
12854
12855         diff /etc/passwd ${migrate_dir}/sofia ||
12856                 error "sofia different after migration"
12857
12858         diff /etc/passwd ${other_dir}/zachary ||
12859                 error "zachary different after migration"
12860
12861         diff /etc/passwd $migrate_dir/${tfile}_ln ||
12862                 error "${tfile}_ln different after migration"
12863
12864         diff /etc/passwd $migrate_dir/${tfile}_ln_other ||
12865                 error "${tfile}_ln_other different after migration"
12866
12867         stripe_count=$($LFS getstripe -c ${migrate_dir}/dir_default_stripe2)
12868         [ $stripe_count = 2 ] ||
12869                 error "dir strpe_count $d != 2 after migration."
12870
12871         stripe_count=$($LFS getstripe -c ${migrate_dir}/${tfile}_stripe2)
12872         [ $stripe_count = 2 ] ||
12873                 error "file strpe_count $d != 2 after migration."
12874
12875         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12876 }
12877 run_test 230b "migrate directory"
12878
12879 test_230c() {
12880         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12881         remote_mds_nodsh && skip "remote MDS with nodsh" && return
12882         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12883         local MDTIDX=1
12884         local mdt_index
12885         local file
12886         local migrate_dir=$DIR/$tdir/migrate_dir
12887
12888         #If migrating directory fails in the middle, all entries of
12889         #the directory is still accessiable.
12890         test_mkdir $DIR/$tdir
12891         test_mkdir -i0 -c1 $migrate_dir
12892         stat $migrate_dir
12893         createmany -o $migrate_dir/f 10 ||
12894                 error "create files under ${migrate_dir} failed"
12895
12896         #failed after migrating 5 entries
12897         #OBD_FAIL_MIGRATE_ENTRIES       0x1801
12898         do_facet mds1 lctl set_param fail_loc=0x20001801
12899         do_facet mds1 lctl  set_param fail_val=5
12900         local t=$(ls $migrate_dir | wc -l)
12901         $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
12902                 error "migrate should fail after 5 entries"
12903
12904         mkdir $migrate_dir/dir &&
12905                 error "mkdir succeeds under migrating directory"
12906         touch $migrate_dir/file &&
12907                 error "touch file succeeds under migrating directory"
12908
12909         local u=$(ls $migrate_dir | wc -l)
12910         [ "$u" == "$t" ] || error "$u != $t during migration"
12911
12912         for file in $(find $migrate_dir); do
12913                 stat $file || error "stat $file failed"
12914         done
12915
12916         do_facet mds1 lctl set_param fail_loc=0
12917         do_facet mds1 lctl set_param fail_val=0
12918
12919         $LFS migrate -m $MDTIDX $migrate_dir ||
12920                 error "migrate open files should failed with open files"
12921
12922         echo "Finish migration, then checking.."
12923         for file in $(find $migrate_dir); do
12924                 mdt_index=$($LFS getstripe -M $file)
12925                 [ $mdt_index == $MDTIDX ] ||
12926                         error "$file is not on MDT${MDTIDX}"
12927         done
12928
12929         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12930 }
12931 run_test 230c "check directory accessiblity if migration is failed"
12932
12933 test_230d() {
12934         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12935         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12936         local MDTIDX=1
12937         local mdt_index
12938         local migrate_dir=$DIR/$tdir/migrate_dir
12939         local i
12940         local j
12941
12942         test_mkdir $DIR/$tdir
12943         test_mkdir -i0 -c1 $migrate_dir
12944
12945         for ((i=0; i<100; i++)); do
12946                 test_mkdir -i0 -c1 $migrate_dir/dir_${i}
12947                 createmany -o $migrate_dir/dir_${i}/f 100 ||
12948                         error "create files under remote dir failed $i"
12949         done
12950
12951         $LFS migrate -m $MDTIDX $migrate_dir ||
12952                 error "migrate remote dir error"
12953
12954         echo "Finish migration, then checking.."
12955         for file in $(find $migrate_dir); do
12956                 mdt_index=$($LFS getstripe -M $file)
12957                 [ $mdt_index == $MDTIDX ] ||
12958                         error "$file is not on MDT${MDTIDX}"
12959         done
12960
12961         rm -rf $DIR/$tdir || error "rm dir failed after migration"
12962 }
12963 run_test 230d "check migrate big directory"
12964
12965 test_230e() {
12966         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
12967         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
12968         local i
12969         local j
12970         local a_fid
12971         local b_fid
12972
12973         mkdir -p $DIR/$tdir
12974         mkdir $DIR/$tdir/migrate_dir
12975         mkdir $DIR/$tdir/other_dir
12976         touch $DIR/$tdir/migrate_dir/a
12977         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/b
12978
12979         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
12980                 error "migrate dir fails"
12981
12982         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
12983         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
12984
12985         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
12986         [ $mdt_index == 0 ] || error "a is not on MDT0"
12987
12988         $LFS migrate -m 1 $DIR/$tdir/other_dir ||
12989                 error "migrate dir fails"
12990
12991         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir)
12992         [ $mdt_index == 1 ] || error "other_dir is not on MDT1"
12993
12994         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
12995         [ $mdt_index == 1 ] || error "a is not on MDT1"
12996
12997         mdt_index=$($LFS getstripe -M $DIR/$tdir/other_dir/b)
12998         [ $mdt_index == 1 ] || error "b is not on MDT1"
12999
13000         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13001         b_fid=$($LFS path2fid $DIR/$tdir/other_dir/b)
13002
13003         [ "$a_fid" = "$b_fid" ] || error "different fid after migration"
13004
13005         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13006 }
13007 run_test 230e "migrate mulitple local link files"
13008
13009 test_230f() {
13010         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13011         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13012         local a_fid
13013         local ln_fid
13014
13015         mkdir -p $DIR/$tdir
13016         mkdir $DIR/$tdir/migrate_dir
13017         $LFS mkdir -i1 $DIR/$tdir/other_dir
13018         touch $DIR/$tdir/migrate_dir/a
13019         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln1
13020         ln $DIR/$tdir/migrate_dir/a $DIR/$tdir/other_dir/ln2
13021
13022         # a should be migrated to MDT1, since no other links on MDT0
13023         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13024                 error "migrate dir fails"
13025         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir)
13026         [ $mdt_index == 1 ] || error "migrate_dir is not on MDT1"
13027         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13028         [ $mdt_index == 1 ] || error "a is not on MDT1"
13029
13030         # a should stay on MDT1, because it is a mulitple link file
13031         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13032                 error "migrate dir fails"
13033         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13034         [ $mdt_index == 1 ] || error "a is not on MDT1"
13035
13036         $LFS migrate -m 1 $DIR/$tdir/migrate_dir ||
13037                 error "migrate dir fails"
13038
13039         a_fid=$($LFS path2fid $DIR/$tdir/migrate_dir/a)
13040         ln_fid=$($LFS path2fid $DIR/$tdir/other_dir/ln1)
13041         [ "$a_fid" = "$ln_fid" ] || error "different fid after migrate to MDT1"
13042
13043         rm -rf $DIR/$tdir/other_dir/ln1 || error "unlink ln1 fails"
13044         rm -rf $DIR/$tdir/other_dir/ln2 || error "unlink ln2 fails"
13045
13046         # a should be migrated to MDT0, since no other links on MDT1
13047         $LFS migrate -m 0 $DIR/$tdir/migrate_dir ||
13048                 error "migrate dir fails"
13049         mdt_index=$($LFS getstripe -M $DIR/$tdir/migrate_dir/a)
13050         [ $mdt_index == 0 ] || error "a is not on MDT0"
13051
13052         rm -rf $DIR/$tdir || error "rm dir failed after migration"
13053 }
13054 run_test 230f "migrate mulitple remote link files"
13055
13056 test_231a()
13057 {
13058         # For simplicity this test assumes that max_pages_per_rpc
13059         # is the same across all OSCs
13060         local max_pages=$($LCTL get_param -n osc.*.max_pages_per_rpc | head -n1)
13061         local bulk_size=$((max_pages * 4096))
13062
13063         mkdir -p $DIR/$tdir
13064
13065         # clear the OSC stats
13066         $LCTL set_param osc.*.stats=0 &>/dev/null
13067
13068         # Client writes $bulk_size - there must be 1 rpc for $max_pages.
13069         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$bulk_size count=1 \
13070                 oflag=direct &>/dev/null || error "dd failed"
13071
13072         local nrpcs=$($LCTL get_param osc.*.stats |awk '/ost_write/ {print $2}')
13073         if [ x$nrpcs != "x1" ]; then
13074                 error "found $nrpc ost_write RPCs, not 1 as expected"
13075         fi
13076
13077         # Drop the OSC cache, otherwise we will read from it
13078         cancel_lru_locks osc
13079
13080         # clear the OSC stats
13081         $LCTL set_param osc.*.stats=0 &>/dev/null
13082
13083         # Client reads $bulk_size.
13084         dd if=$DIR/$tdir/$tfile of=/dev/null bs=$bulk_size count=1 \
13085                 iflag=direct &>/dev/null || error "dd failed"
13086
13087         nrpcs=$($LCTL get_param osc.*.stats | awk '/ost_read/ { print $2 }')
13088         if [ x$nrpcs != "x1" ]; then
13089                 error "found $nrpc ost_read RPCs, not 1 as expected"
13090         fi
13091 }
13092 run_test 231a "checking that reading/writing of BRW RPC size results in one RPC"
13093
13094 test_231b() {
13095         mkdir -p $DIR/$tdir
13096         local i
13097         for i in {0..1023}; do
13098                 dd if=/dev/zero of=$DIR/$tdir/$tfile conv=notrunc \
13099                         seek=$((2 * i)) bs=4096 count=1 &>/dev/null ||
13100                         error "dd of=$DIR/$tdir/$tfile seek=$((2 * i)) failed"
13101         done
13102         sync
13103 }
13104 run_test 231b "must not assert on fully utilized OST request buffer"
13105
13106 test_232() {
13107         mkdir -p $DIR/$tdir
13108         #define OBD_FAIL_LDLM_OST_LVB            0x31c
13109         $LCTL set_param fail_loc=0x31c
13110
13111         # ignore dd failure
13112         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 || true
13113
13114         $LCTL set_param fail_loc=0
13115         umount_client $MOUNT || error "umount failed"
13116         mount_client $MOUNT || error "mount failed"
13117 }
13118 run_test 232 "failed lock should not block umount"
13119
13120 test_233a() {
13121         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
13122         { skip "Need MDS version at least 2.3.64"; return; }
13123
13124         local fid=$($LFS path2fid $MOUNT)
13125         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13126                 error "cannot access $MOUNT using its FID '$fid'"
13127 }
13128 run_test 233a "checking that OBF of the FS root succeeds"
13129
13130 test_233b() {
13131         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
13132         { skip "Need MDS version at least 2.5.90"; return; }
13133
13134         local fid=$($LFS path2fid $MOUNT/.lustre)
13135         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13136                 error "cannot access $MOUNT/.lustre using its FID '$fid'"
13137
13138         fid=$($LFS path2fid $MOUNT/.lustre/fid)
13139         stat $MOUNT/.lustre/fid/$fid > /dev/null ||
13140                 error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
13141 }
13142 run_test 233b "checking that OBF of the FS .lustre succeeds"
13143
13144 test_234() {
13145         local p="$TMP/sanityN-$TESTNAME.parameters"
13146         save_lustre_params client "llite.*.xattr_cache" > $p
13147         lctl set_param llite.*.xattr_cache 1 ||
13148                 { skip "xattr cache is not supported"; return 0; }
13149
13150         mkdir -p $DIR/$tdir || error "mkdir failed"
13151         touch $DIR/$tdir/$tfile || error "touch failed"
13152         # OBD_FAIL_LLITE_XATTR_ENOMEM
13153         $LCTL set_param fail_loc=0x1405
13154         # output of the form: attr 2 4 44 3 fc13 x86_64
13155         V=($(IFS=".-" rpm -q attr))
13156         if [[ ${V[1]} > 2 || ${V[2]} > 4 || ${V[3]} > 44 ||
13157               ${V[1]} = 2 && ${V[2]} = 4 && ${V[3]} = 44 && ${V[4]} > 6 ]]; then
13158                 # attr pre-2.4.44-7 had a bug with rc
13159                 # LU-3703 - SLES 11 and FC13 clients have older attr
13160                 getfattr -n user.attr $DIR/$tdir/$tfile &&
13161                         error "getfattr should have failed with ENOMEM"
13162         else
13163                 skip "LU-3703: attr version $(getfattr --version) too old"
13164         fi
13165         $LCTL set_param fail_loc=0x0
13166         rm -rf $DIR/$tdir
13167
13168         restore_lustre_params < $p
13169         rm -f $p
13170 }
13171 run_test 234 "xattr cache should not crash on ENOMEM"
13172
13173 test_235() {
13174         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.52) ] &&
13175                 skip "Need MDS version at least 2.4.52" && return
13176         flock_deadlock $DIR/$tfile
13177         local RC=$?
13178         case $RC in
13179                 0)
13180                 ;;
13181                 124) error "process hangs on a deadlock"
13182                 ;;
13183                 *) error "error executing flock_deadlock $DIR/$tfile"
13184                 ;;
13185         esac
13186 }
13187 run_test 235 "LU-1715: flock deadlock detection does not work properly"
13188
13189 #LU-2935
13190 test_236() {
13191         check_swap_layouts_support && return 0
13192         test_mkdir -p -c1 $DIR/$tdir || error "mkdir $tdir failed"
13193
13194         local ref1=/etc/passwd
13195         local ref2=/etc/group
13196         local file1=$DIR/$tdir/f1
13197         local file2=$DIR/$tdir/f2
13198
13199         $SETSTRIPE -c 1 $file1 || error "cannot setstripe on '$file1': rc = $?"
13200         cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
13201         $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
13202         cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
13203         local fd=$(free_fd)
13204         local cmd="exec $fd<>$file2"
13205         eval $cmd
13206         rm $file2
13207         $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
13208                 error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
13209         cmd="exec $fd>&-"
13210         eval $cmd
13211         cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
13212
13213         #cleanup
13214         rm -rf $DIR/$tdir
13215 }
13216 run_test 236 "Layout swap on open unlinked file"
13217
13218 # test to verify file handle related system calls
13219 # (name_to_handle_at/open_by_handle_at)
13220 # The new system calls are supported in glibc >= 2.14.
13221
13222 test_237() {
13223         echo "Test file_handle syscalls" > $DIR/$tfile ||
13224                 error "write failed"
13225         check_fhandle_syscalls $DIR/$tfile ||
13226                 error "check_fhandle_syscalls failed"
13227 }
13228 run_test 237 "Verify name_to_handle_at/open_by_handle_at syscalls"
13229
13230 # LU-4659 linkea consistency
13231 test_238() {
13232         local server_version=$(lustre_version_code $SINGLEMDS)
13233
13234         [[ $server_version -gt $(version_code 2.5.57) ]] ||
13235                 [[ $server_version -gt $(version_code 2.5.1) &&
13236                    $server_version -lt $(version_code 2.5.50) ]] ||
13237                 { skip "Need MDS version at least 2.5.58 or 2.5.2+"; return; }
13238
13239         touch $DIR/$tfile
13240         ln $DIR/$tfile $DIR/$tfile.lnk
13241         touch $DIR/$tfile.new
13242         mv $DIR/$tfile.new $DIR/$tfile
13243         local fid1=$($LFS path2fid $DIR/$tfile)
13244         local fid2=$($LFS path2fid $DIR/$tfile.lnk)
13245         local path1=$($LFS fid2path $FSNAME "$fid1")
13246         [ $tfile == $path1 ] || error "linkea inconsistent: $tfile $fid1 $path1"
13247         local path2=$($LFS fid2path $FSNAME "$fid2")
13248         [ $tfile.lnk == $path2 ] ||
13249                 error "linkea inconsistent: $tfile.lnk $fid2 $path2!"
13250         rm -f $DIR/$tfile*
13251 }
13252 run_test 238 "Verify linkea consistency"
13253
13254 test_239() {
13255         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.60) ] &&
13256                 skip "Need MDS version at least 2.5.60" && return
13257         local list=$(comma_list $(mdts_nodes))
13258
13259         mkdir -p $DIR/$tdir
13260         createmany -o $DIR/$tdir/f- 5000
13261         unlinkmany $DIR/$tdir/f- 5000
13262         do_nodes $list "lctl set_param -n osp*.*.sync_changes 1"
13263         changes=$(do_nodes $list "lctl get_param -n osc.*MDT*.sync_changes \
13264                         osc.*MDT*.sync_in_flight" | calc_sum)
13265         [ "$changes" -eq 0 ] || error "$changes not synced"
13266 }
13267 run_test 239 "osp_sync test"
13268
13269 test_239a() { #LU-5297
13270         touch $DIR/$tfile
13271         #define OBD_FAIL_OSP_CHECK_INVALID_REC     0x2100
13272         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2100
13273         chgrp $RUNAS_GID $DIR/$tfile
13274         wait_delete_completed
13275 }
13276 run_test 239a "process invalid osp sync record correctly"
13277
13278 test_239b() { #LU-5297
13279         touch $DIR/$tfile1
13280         #define OBD_FAIL_OSP_CHECK_ENOMEM     0x2101
13281         do_facet $SINGLEMDS $LCTL set_param fail_loc=0x2101
13282         chgrp $RUNAS_GID $DIR/$tfile1
13283         wait_delete_completed
13284         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
13285         touch $DIR/$tfile2
13286         chgrp $RUNAS_GID $DIR/$tfile2
13287         wait_delete_completed
13288 }
13289 run_test 239b "process osp sync record with ENOMEM error correctly"
13290
13291 test_240() {
13292         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13293
13294         mkdir -p $DIR/$tdir
13295
13296         $LFS mkdir -i 0 $DIR/$tdir/d0 ||
13297                 error "failed to mkdir $DIR/$tdir/d0 on MDT0"
13298         $LFS mkdir -i 1 $DIR/$tdir/d0/d1 ||
13299                 error "failed to mkdir $DIR/$tdir/d0/d1 on MDT1"
13300
13301         umount_client $MOUNT || error "umount failed"
13302         #define OBD_FAIL_TGT_DELAY_CONDITIONAL   0x713
13303         do_facet mds2 lctl set_param fail_loc=0x713 fail_val=1
13304         mount_client $MOUNT || error "failed to mount client"
13305
13306         echo "stat $DIR/$tdir/d0/d1, should not fail/ASSERT"
13307         stat $DIR/$tdir/d0/d1 || error "fail to stat $DIR/$tdir/d0/d1"
13308 }
13309 run_test 240 "race between ldlm enqueue and the connection RPC (no ASSERT)"
13310
13311 test_241_bio() {
13312         for LOOP in $(seq $1); do
13313                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 2>/dev/null
13314                 cancel_lru_locks osc
13315         done
13316 }
13317
13318 test_241_dio() {
13319         for LOOP in $(seq $1); do
13320                 dd if=$DIR/$tfile of=/dev/null bs=40960 count=1 \
13321                                                 iflag=direct 2>/dev/null
13322         done
13323 }
13324
13325 test_241() {
13326         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
13327         ls -la $DIR/$tfile
13328         cancel_lru_locks osc
13329         test_241_bio 1000 &
13330         PID=$!
13331         test_241_dio 1000
13332         wait $PID
13333 }
13334 run_test 241 "bio vs dio"
13335
13336 test_241b() {
13337         dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
13338         ls -la $DIR/$tfile
13339         test_241_dio 1000 &
13340         PID=$!
13341         test_241_dio 1000
13342         wait $PID
13343 }
13344 run_test 241b "dio vs dio"
13345
13346 test_242() {
13347         mkdir -p $DIR/$tdir
13348         touch $DIR/$tdir/$tfile
13349
13350         #define OBD_FAIL_MDS_READPAGE_PACK      0x105
13351         do_facet mds1 lctl set_param fail_loc=0x105
13352         /bin/ls $DIR/$tdir && error "ls $DIR/$tdir should fail"
13353
13354         do_facet mds1 lctl set_param fail_loc=0
13355         /bin/ls $DIR/$tdir || error "ls $DIR/$tdir failed"
13356 }
13357 run_test 242 "mdt_readpage failure should not cause directory unreadable"
13358
13359 test_243()
13360 {
13361         test_mkdir -p $DIR/$tdir
13362         group_lock_test -d $DIR/$tdir || error "A group lock test failed"
13363 }
13364 run_test 243 "various group lock tests"
13365
13366 test_244()
13367 {
13368         test_mkdir -p $DIR/$tdir
13369         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=35
13370         sendfile_grouplock $DIR/$tdir/$tfile || \
13371                 error "sendfile+grouplock failed"
13372         rm -rf $DIR/$tdir
13373 }
13374 run_test 244 "sendfile with group lock tests"
13375
13376 test_245() {
13377         local flagname="multi_mod_rpcs"
13378         local connect_data_name="max_mod_rpcs"
13379         local out
13380
13381         # check if multiple modify RPCs flag is set
13382         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import |
13383                 grep "connect_flags:")
13384         echo "$out"
13385
13386         echo "$out" | grep -qw $flagname
13387         if [ $? -ne 0 ]; then
13388                 echo "connect flag $flagname is not set"
13389                 return
13390         fi
13391
13392         # check if multiple modify RPCs data is set
13393         out=$($LCTL get_param mdc.$FSNAME-MDT0000-*.import)
13394         echo "$out"
13395
13396         echo "$out" | grep -qw $connect_data_name ||
13397                 error "import should have connect data $connect_data_name"
13398 }
13399 run_test 245 "check mdc connection flag/data: multiple modify RPCs"
13400
13401 test_250() {
13402         [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
13403          && skip "no 16TB file size limit on ZFS" && return
13404
13405         $SETSTRIPE -c 1 $DIR/$tfile
13406         # ldiskfs extent file size limit is (16TB - 4KB - 1) bytes
13407         local size=$((16 * 1024 * 1024 * 1024 * 1024 - 4096 - 1))
13408         $TRUNCATE $DIR/$tfile $size || error "truncate $tfile to $size failed"
13409         dd if=/dev/zero of=$DIR/$tfile bs=10 count=1 oflag=append \
13410                 conv=notrunc,fsync && error "append succeeded"
13411         return 0
13412 }
13413 run_test 250 "Write above 16T limit"
13414
13415 test_251() {
13416         $SETSTRIPE -c -1 -S 1048576 $DIR/$tfile
13417
13418         #define OBD_FAIL_LLITE_LOST_LAYOUT 0x1407
13419         #Skip once - writing the first stripe will succeed
13420         $LCTL set_param fail_loc=0xa0001407 fail_val=1
13421         $MULTIOP $DIR/$tfile o:O_RDWR:w2097152c 2>&1 | grep -q "short write" &&
13422                 error "short write happened"
13423
13424         $LCTL set_param fail_loc=0xa0001407 fail_val=1
13425         $MULTIOP $DIR/$tfile or2097152c 2>&1 | grep -q "short read" &&
13426                 error "short read happened"
13427
13428         rm -f $DIR/$tfile
13429 }
13430 run_test 251 "Handling short read and write correctly"
13431
13432 test_252() {
13433         local tgt
13434         local dev
13435         local out
13436         local uuid
13437         local num
13438         local gen
13439
13440         if [ "$(facet_fstype ost1)" != "ldiskfs" -o \
13441              "$(facet_fstype mds1)" != "ldiskfs" ]; then
13442                 skip "can only run lr_reader on ldiskfs target"
13443                 return
13444         fi
13445
13446         # check lr_reader on OST0000
13447         tgt=ost1
13448         dev=$(facet_device $tgt)
13449         out=$(do_facet $tgt $LR_READER $dev)
13450         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
13451         echo "$out"
13452         uuid=$(echo "$out" | grep -i uuid | awk '{ print $2 }')
13453         [ "$uuid" == "$(ostuuid_from_index 0)" ] ||
13454                 error "Invalid uuid returned by $LR_READER on target $tgt"
13455         echo -e "uuid returned by $LR_READER is '$uuid'\n"
13456
13457         # check lr_reader -c on MDT0000
13458         tgt=mds1
13459         dev=$(facet_device $tgt)
13460         if ! do_facet $tgt $LR_READER -h | grep -q OPTIONS; then
13461                 echo "$LR_READER does not support additional options"
13462                 return 0
13463         fi
13464         out=$(do_facet $tgt $LR_READER -c $dev)
13465         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
13466         echo "$out"
13467         num=$(echo "$out" | grep -c "mdtlov")
13468         [ "$num" -eq $((MDSCOUNT - 1)) ] ||
13469                 error "Invalid number of mdtlov clients returned by $LR_READER"
13470         echo -e "Number of mdtlov clients returned by $LR_READER is '$num'\n"
13471
13472         # check lr_reader -cr on MDT0000
13473         out=$(do_facet $tgt $LR_READER -cr $dev)
13474         [ $? -eq 0 ] || error "$LR_READER failed on target $tgt device $dev"
13475         echo "$out"
13476         echo "$out" | grep -q "^reply_data:$" ||
13477                 error "$LR_READER should have returned 'reply_data' section"
13478         num=$(echo "$out" | grep -c "client_generation")
13479         echo -e "Number of reply data returned by $LR_READER is '$num'\n"
13480 }
13481 run_test 252 "check lr_reader tool"
13482
13483
13484 cleanup_test_300() {
13485         trap 0
13486         umask $SAVE_UMASK
13487 }
13488 test_striped_dir() {
13489         local mdt_index=$1
13490         local stripe_count
13491         local stripe_index
13492
13493         mkdir -p $DIR/$tdir
13494
13495         SAVE_UMASK=$(umask)
13496         trap cleanup_test_300 RETURN EXIT
13497
13498         $LFS setdirstripe -i $mdt_index -c 2 -t all_char -m 755 \
13499                                                 $DIR/$tdir/striped_dir ||
13500                 error "set striped dir error"
13501
13502         local mode=$(stat -c%a $DIR/$tdir/striped_dir)
13503         [ "$mode" = "755" ] || error "expect 755 got $mode"
13504
13505         $LFS getdirstripe $DIR/$tdir/striped_dir > /dev/null 2>&1 ||
13506                 error "getdirstripe failed"
13507         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
13508         if [ "$stripe_count" != "2" ]; then
13509                 error "stripe_count is $stripe_count, expect 2"
13510         fi
13511
13512         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir)
13513         if [ "$stripe_index" != "$mdt_index" ]; then
13514                 error "stripe_index is $stripe_index, expect $mdt_index"
13515         fi
13516
13517         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13518                 error "nlink error after create striped dir"
13519
13520         mkdir $DIR/$tdir/striped_dir/a
13521         mkdir $DIR/$tdir/striped_dir/b
13522
13523         stat $DIR/$tdir/striped_dir/a ||
13524                 error "create dir under striped dir failed"
13525         stat $DIR/$tdir/striped_dir/b ||
13526                 error "create dir under striped dir failed"
13527
13528         [ $(stat -c%h $DIR/$tdir/striped_dir) == '4' ] ||
13529                 error "nlink error after mkdir"
13530
13531         rmdir $DIR/$tdir/striped_dir/a
13532         [ $(stat -c%h $DIR/$tdir/striped_dir) == '3' ] ||
13533                 error "nlink error after rmdir"
13534
13535         rmdir $DIR/$tdir/striped_dir/b
13536         [ $(stat -c%h $DIR/$tdir/striped_dir) == '2' ] ||
13537                 error "nlink error after rmdir"
13538
13539         chattr +i $DIR/$tdir/striped_dir
13540         createmany -o $DIR/$tdir/striped_dir/f 10 &&
13541                 error "immutable flags not working under striped dir!"
13542         chattr -i $DIR/$tdir/striped_dir
13543
13544         rmdir $DIR/$tdir/striped_dir ||
13545                 error "rmdir striped dir error"
13546
13547         cleanup_test_300
13548
13549         true
13550 }
13551
13552 test_300a() {
13553         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13554         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13555
13556         test_striped_dir 0 || error "failed on striped dir on MDT0"
13557         test_striped_dir 1 || error "failed on striped dir on MDT0"
13558 }
13559 run_test 300a "basic striped dir sanity test"
13560
13561 test_300b() {
13562         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13563         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13564         local i
13565         local mtime1
13566         local mtime2
13567         local mtime3
13568
13569         test_mkdir $DIR/$tdir || error "mkdir fail"
13570         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13571                 error "set striped dir error"
13572         for ((i=0; i<10; i++)); do
13573                 mtime1=$(stat -c %Y $DIR/$tdir/striped_dir)
13574                 sleep 1
13575                 touch $DIR/$tdir/striped_dir/file_$i ||
13576                                         error "touch error $i"
13577                 mtime2=$(stat -c %Y $DIR/$tdir/striped_dir)
13578                 [ $mtime1 -eq $mtime2 ] &&
13579                         error "mtime not change after create"
13580                 sleep 1
13581                 rm -f $DIR/$tdir/striped_dir/file_$i ||
13582                                         error "unlink error $i"
13583                 mtime3=$(stat -c %Y $DIR/$tdir/striped_dir)
13584                 [ $mtime2 -eq $mtime3 ] &&
13585                         error "mtime did not change after unlink"
13586         done
13587         true
13588 }
13589 run_test 300b "check ctime/mtime for striped dir"
13590
13591 test_300c() {
13592         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13593         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13594         local file_count
13595
13596         mkdir -p $DIR/$tdir
13597         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir ||
13598                 error "set striped dir error"
13599
13600         chown $RUNAS_ID:$RUNAS_GID $DIR/$tdir/striped_dir ||
13601                 error "chown striped dir failed"
13602
13603         $RUNAS createmany -o $DIR/$tdir/striped_dir/f 5000 ||
13604                 error "create 5k files failed"
13605
13606         file_count=$(ls $DIR/$tdir/striped_dir | wc -l)
13607
13608         [ "$file_count" = 5000 ] || error "file count $file_count != 5000"
13609
13610         rm -rf $DIR/$tdir
13611 }
13612 run_test 300c "chown && check ls under striped directory"
13613
13614 test_300d() {
13615         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13616         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13617         local stripe_count
13618         local file
13619
13620         mkdir -p $DIR/$tdir
13621         $SETSTRIPE -c 2 $DIR/$tdir
13622
13623         #local striped directory
13624         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13625                 error "set striped dir error"
13626         createmany -o $DIR/$tdir/striped_dir/f 10 ||
13627                 error "create 10 files failed"
13628
13629         #remote striped directory
13630         $LFS setdirstripe -i 1 -c 2 $DIR/$tdir/remote_striped_dir ||
13631                 error "set striped dir error"
13632         createmany -o $DIR/$tdir/remote_striped_dir/f 10 ||
13633                 error "create 10 files failed"
13634
13635         for file in $(find $DIR/$tdir); do
13636                 stripe_count=$($GETSTRIPE -c $file)
13637                 [ $stripe_count -eq 2 ] ||
13638                         error "wrong stripe $stripe_count for $file"
13639         done
13640
13641         rm -rf $DIR/$tdir
13642 }
13643 run_test 300d "check default stripe under striped directory"
13644
13645 test_300e() {
13646         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13647                 skip "Need MDS version at least 2.7.55" && return
13648         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13649         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13650         local stripe_count
13651         local file
13652
13653         mkdir -p $DIR/$tdir
13654
13655         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13656                 error "set striped dir error"
13657
13658         touch $DIR/$tdir/striped_dir/a
13659         touch $DIR/$tdir/striped_dir/b
13660         touch $DIR/$tdir/striped_dir/c
13661
13662         mkdir $DIR/$tdir/striped_dir/dir_a
13663         mkdir $DIR/$tdir/striped_dir/dir_b
13664         mkdir $DIR/$tdir/striped_dir/dir_c
13665
13666         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_a ||
13667                 error "set striped dir under striped dir error"
13668
13669         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_b ||
13670                 error "set striped dir under striped dir error"
13671
13672         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir/stp_c ||
13673                 error "set striped dir under striped dir error"
13674
13675         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir/dir_b ||
13676                 error "rename dir under striped dir fails"
13677
13678         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir/stp_b ||
13679                 error "rename dir under different stripes fails"
13680
13681         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir/c ||
13682                 error "rename file under striped dir should succeed"
13683
13684         mrename $DIR/$tdir/striped_dir/dir_b $DIR/$tdir/striped_dir/dir_c ||
13685                 error "rename dir under striped dir should succeed"
13686
13687         rm -rf $DIR/$tdir
13688 }
13689 run_test 300e "check rename under striped directory"
13690
13691 test_300f() {
13692         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13693                 skip "Need MDS version at least 2.7.55" && return
13694         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13695         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13696         local stripe_count
13697         local file
13698
13699         rm -rf $DIR/$tdir
13700         mkdir -p $DIR/$tdir
13701
13702         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir ||
13703                 error "set striped dir error"
13704
13705         $LFS setdirstripe -i 0 -c 2 -t all_char $DIR/$tdir/striped_dir1 ||
13706                 error "set striped dir error"
13707
13708         touch $DIR/$tdir/striped_dir/a
13709         mkdir $DIR/$tdir/striped_dir/dir_a
13710         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_a ||
13711                 error "create striped dir under striped dir fails"
13712
13713         touch $DIR/$tdir/striped_dir1/b
13714         mkdir $DIR/$tdir/striped_dir1/dir_b
13715         $LFS setdirstripe -i 0 -c 2 $DIR/$tdir/striped_dir/stp_b ||
13716                 error "create striped dir under striped dir fails"
13717
13718         mrename $DIR/$tdir/striped_dir/dir_a $DIR/$tdir/striped_dir1/dir_b ||
13719                 error "rename dir under different striped dir should fail"
13720
13721         mrename $DIR/$tdir/striped_dir/stp_a $DIR/$tdir/striped_dir1/stp_b ||
13722                 error "rename striped dir under diff striped dir should fail"
13723
13724         mrename $DIR/$tdir/striped_dir/a $DIR/$tdir/striped_dir1/a ||
13725                 error "rename file under diff striped dirs fails"
13726
13727         rm -rf $DIR/$tdir
13728 }
13729 run_test 300f "check rename cross striped directory"
13730
13731 test_300_check_default_striped_dir()
13732 {
13733         local dirname=$1
13734         local default_count=$2
13735         local default_index=$3
13736         local stripe_count
13737         local stripe_index
13738         local dir_stripe_index
13739         local dir
13740
13741         echo "checking $dirname $default_count $default_index"
13742         $LFS setdirstripe -D -c $default_count -i $default_index \
13743                                 -t all_char $DIR/$tdir/$dirname ||
13744                 error "set default stripe on striped dir error"
13745         stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
13746         [ $stripe_count -eq $default_count ] ||
13747                 error "expect $default_count get $stripe_count for $dirname"
13748
13749         stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
13750         [ $stripe_index -eq $default_index ] ||
13751                 error "expect $default_index get $stripe_index for $dirname"
13752
13753         mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
13754                                                 error "create dirs failed"
13755
13756         createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
13757         unlinkmany $DIR/$tdir/$dirname/f- 10    || error "unlink files failed"
13758         for dir in $(find $DIR/$tdir/$dirname/*); do
13759                 stripe_count=$($LFS getdirstripe -c $dir)
13760                 [ $stripe_count -eq $default_count ] ||
13761                 [ $stripe_count -eq 0 -o $default_count -eq 1 ] ||
13762                 error "stripe count $default_count != $stripe_count for $dir"
13763
13764                 stripe_index=$($LFS getdirstripe -i $dir)
13765                 [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
13766                         error "$stripe_index != $default_index for $dir"
13767
13768                 #check default stripe
13769                 stripe_count=$($LFS getdirstripe -D -c $dir)
13770                 [ $stripe_count -eq $default_count ] ||
13771                 error "default count $default_count != $stripe_count for $dir"
13772
13773                 stripe_index=$($LFS getdirstripe -D -i $dir)
13774                 [ $stripe_index -eq $default_index ] ||
13775                 error "default index $default_index != $stripe_index for $dir"
13776         done
13777         rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
13778 }
13779
13780 test_300g() {
13781         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13782                 skip "Need MDS version at least 2.7.55" && return
13783         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13784         local dir
13785         local stripe_count
13786         local stripe_index
13787
13788         mkdir $DIR/$tdir
13789         mkdir $DIR/$tdir/normal_dir
13790
13791         test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
13792         test_300_check_default_striped_dir normal_dir 1 0
13793         test_300_check_default_striped_dir normal_dir 2 1
13794         test_300_check_default_striped_dir normal_dir 2 -1
13795
13796         #delete default stripe information
13797         echo "delete default stripeEA"
13798         $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
13799                 error "set default stripe on striped dir error"
13800
13801         mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
13802         for dir in $(find $DIR/$tdir/normal_dir/*); do
13803                 stripe_count=$($LFS getdirstripe -c $dir)
13804                 [ $stripe_count -eq 0 ] ||
13805                         error "expect 1 get $stripe_count for $dir"
13806                 stripe_index=$($LFS getdirstripe -i $dir)
13807                 [ $stripe_index -eq 0 ] ||
13808                         error "expect 0 get $stripe_index for $dir"
13809         done
13810 }
13811 run_test 300g "check default striped directory for normal directory"
13812
13813 test_300h() {
13814         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13815                 skip "Need MDS version at least 2.7.55" && return
13816         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13817         local dir
13818         local stripe_count
13819
13820         mkdir $DIR/$tdir
13821         $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
13822                                         $DIR/$tdir/striped_dir ||
13823                 error "set striped dir error"
13824
13825         test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
13826         test_300_check_default_striped_dir striped_dir 1 0
13827         test_300_check_default_striped_dir striped_dir 2 1
13828         test_300_check_default_striped_dir striped_dir 2 -1
13829
13830         #delete default stripe information
13831         $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
13832                 error "set default stripe on striped dir error"
13833
13834         mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
13835         for dir in $(find $DIR/$tdir/striped_dir/*); do
13836                 stripe_count=$($LFS getdirstripe -c $dir)
13837                 [ $stripe_count -eq 0 ] ||
13838                         error "expect 1 get $stripe_count for $dir"
13839         done
13840 }
13841 run_test 300h "check default striped directory for striped directory"
13842
13843 test_300i() {
13844         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13845                 skip "Need MDS version at least 2.7.55" && return
13846         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13847         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13848         local stripe_count
13849         local file
13850
13851         mkdir $DIR/$tdir
13852
13853         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
13854                 error "set striped dir error"
13855
13856         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
13857                 error "create files under striped dir failed"
13858
13859         # unfortunately, we need to umount to clear dir layout cache for now
13860         # once we fully implement dir layout, we can drop this
13861         umount_client $MOUNT || error "umount failed"
13862         mount_client $MOUNT || error "mount failed"
13863
13864         #set the stripe to be unknown hash type
13865         #define OBD_FAIL_UNKNOWN_LMV_STRIPE     0x1901
13866         $LCTL set_param fail_loc=0x1901
13867         for ((i = 0; i < 10; i++)); do
13868                 $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
13869                         error "stat f-$i failed"
13870                 rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
13871         done
13872
13873         touch $DIR/$tdir/striped_dir/f0 &&
13874                 error "create under striped dir with unknown hash should fail"
13875
13876         $LCTL set_param fail_loc=0
13877
13878         umount_client $MOUNT || error "umount failed"
13879         mount_client $MOUNT || error "mount failed"
13880
13881         return 0
13882 }
13883 run_test 300i "client handle unknown hash type striped directory"
13884
13885 test_300j() {
13886         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13887         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13888                 skip "Need MDS version at least 2.7.55" && return
13889         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13890         local stripe_count
13891         local file
13892
13893         mkdir $DIR/$tdir
13894
13895         #define OBD_FAIL_SPLIT_UPDATE_REC       0x1702
13896         $LCTL set_param fail_loc=0x1702
13897         $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
13898                 error "set striped dir error"
13899
13900         createmany -o $DIR/$tdir/striped_dir/f- 10 ||
13901                 error "create files under striped dir failed"
13902
13903         $LCTL set_param fail_loc=0
13904
13905         rm -rf $DIR/$tdir || error "unlink striped dir fails"
13906
13907         return 0
13908 }
13909 run_test 300j "test large update record"
13910
13911 test_300k() {
13912         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13913                 skip "Need MDS version at least 2.7.55" && return
13914         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13915         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13916         local stripe_count
13917         local file
13918
13919         mkdir $DIR/$tdir
13920
13921         #define OBD_FAIL_LARGE_STRIPE   0x1703
13922         $LCTL set_param fail_loc=0x1703
13923         $LFS setdirstripe -i 0 -c512 $DIR/$tdir/striped_dir ||
13924                 error "set striped dir error"
13925         $LCTL set_param fail_loc=0
13926
13927         $LFS getdirstripe $DIR/$tdir/striped_dir ||
13928                 error "getstripeddir fails"
13929         rm -rf $DIR/$tdir/striped_dir ||
13930                 error "unlink striped dir fails"
13931
13932         return 0
13933 }
13934 run_test 300k "test large striped directory"
13935
13936 test_300l() {
13937         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13938                 skip "Need MDS version at least 2.7.55" && return
13939         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13940         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
13941         local stripe_index
13942
13943         test_mkdir -p $DIR/$tdir/striped_dir
13944         chown $RUNAS_ID $DIR/$tdir/striped_dir ||
13945                         error "chown $RUNAS_ID failed"
13946         $LFS setdirstripe -i 1 -D $DIR/$tdir/striped_dir ||
13947                 error "set default striped dir failed"
13948
13949         #define OBD_FAIL_MDS_STALE_DIR_LAYOUT    0x158
13950         $LCTL set_param fail_loc=0x80000158
13951         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir || error "create dir fails"
13952
13953         stripe_index=$($LFS getdirstripe -i $DIR/$tdir/striped_dir/test_dir)
13954         [ $stripe_index -eq 1 ] ||
13955                 error "expect 1 get $stripe_index for $dir"
13956 }
13957 run_test 300l "non-root user to create dir under striped dir with stale layout"
13958
13959 test_300m() {
13960         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
13961                 skip "Need MDS version at least 2.7.55" && return
13962         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
13963         [ $MDSCOUNT -ge 2 ] && skip "Only for single MDT" && return
13964
13965         mkdir -p $DIR/$tdir/striped_dir
13966         $LFS setdirstripe -D -c 1 $DIR/$tdir/striped_dir ||
13967                 error "set default stripes dir error"
13968
13969         mkdir $DIR/$tdir/striped_dir/a || error "mkdir a fails"
13970
13971         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/a)
13972         [ $stripe_count -eq 0 ] ||
13973                         error "expect 0 get $stripe_count for a"
13974
13975         $LFS setdirstripe -D -c 2 $DIR/$tdir/striped_dir ||
13976                 error "set default stripes dir error"
13977
13978         mkdir $DIR/$tdir/striped_dir/b || error "mkdir b fails"
13979
13980         stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir/b)
13981         [ $stripe_count -eq 0 ] ||
13982                         error "expect 0 get $stripe_count for b"
13983
13984         $LFS setdirstripe -D -c1 -i2 $DIR/$tdir/striped_dir ||
13985                 error "set default stripes dir error"
13986
13987         mkdir $DIR/$tdir/striped_dir/c &&
13988                 error "default stripe_index is invalid, mkdir c should fails"
13989
13990         rm -rf $DIR/$tdir || error "rmdir fails"
13991 }
13992 run_test 300m "setstriped directory on single MDT FS"
13993
13994 cleanup_300n() {
13995         local list=$(comma_list $(mdts_nodes))
13996
13997         trap 0
13998         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
13999 }
14000
14001 test_300n() {
14002         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14003                 skip "Need MDS version at least 2.7.55" && return
14004         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14005         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14006         local stripe_index
14007         local list=$(comma_list $(mdts_nodes))
14008
14009         trap cleanup_300n RETURN EXIT
14010         mkdir -p $DIR/$tdir
14011         chmod 777 $DIR/$tdir
14012         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT \
14013                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
14014                 error "create striped dir succeeds with gid=0"
14015
14016         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
14017         $RUNAS $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
14018                 error "create striped dir fails with gid=-1"
14019
14020         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
14021         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D \
14022                                 $DIR/$tdir/striped_dir > /dev/null 2>&1 &&
14023                 error "set default striped dir succeeds with gid=0"
14024
14025
14026         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=-1
14027         $RUNAS $LFS setdirstripe -i 1 -c$MDSCOUNT -D $DIR/$tdir/striped_dir ||
14028                 error "set default striped dir fails with gid=-1"
14029
14030
14031         do_nodes $list $LCTL set_param -n mdt.*.enable_remote_dir_gid=0
14032         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir ||
14033                                         error "create test_dir fails"
14034         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir1 ||
14035                                         error "create test_dir1 fails"
14036         $RUNAS mkdir $DIR/$tdir/striped_dir/test_dir2 ||
14037                                         error "create test_dir2 fails"
14038         cleanup_300n
14039 }
14040 run_test 300n "non-root user to create dir under striped dir with default EA"
14041
14042 test_300o() {
14043         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
14044                 skip "Need MDS version at least 2.7.55" && return
14045         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14046         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
14047         local numfree1
14048         local numfree2
14049
14050         mkdir -p $DIR/$tdir
14051
14052         numfree1=$(lctl get_param -n mdc.*MDT0000*.filesfree)
14053         numfree2=$(lctl get_param -n mdc.*MDT0001*.filesfree)
14054         if [ $numfree1 -lt 66000 -o $numfree2 -lt 66000 ]; then
14055                 skip "not enough free inodes $numfree1 $numfree2"
14056                 return
14057         fi
14058
14059         numfree1=$(lctl get_param -n mdc.*MDT0000-mdc-*.kbytesfree)
14060         numfree2=$(lctl get_param -n mdc.*MDT0001-mdc-*.kbytesfree)
14061         if [ $numfree1 -lt 300000 -o $numfree2 -lt 300000 ]; then
14062                 skip "not enough free space $numfree1 $numfree2"
14063                 return
14064         fi
14065
14066         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
14067                 error "setdirstripe fails"
14068
14069         createmany -d $DIR/$tdir/striped_dir/d 131000 ||
14070                 error "create dirs fails"
14071
14072         $LCTL set_param ldlm.namespaces.*mdc-*.lru_size=0
14073         ls $DIR/$tdir/striped_dir > /dev/null ||
14074                 error "ls striped dir fails"
14075         unlinkmany -d $DIR/$tdir/striped_dir/d 131000 ||
14076                 error "unlink big striped dir fails"
14077 }
14078 run_test 300o "unlink big sub stripe(> 65000 subdirs)"
14079
14080 prepare_remote_file() {
14081         mkdir $DIR/$tdir/src_dir ||
14082                 error "create remote source failed"
14083
14084         cp /etc/hosts $DIR/$tdir/src_dir/a || error
14085         touch $DIR/$tdir/src_dir/a
14086
14087         $LFS mkdir -i 1 $DIR/$tdir/tgt_dir ||
14088                 error "create remote target dir failed"
14089
14090         touch $DIR/$tdir/tgt_dir/b
14091
14092         mrename $DIR/$tdir/src_dir/a $DIR/$tdir/tgt_dir/b ||
14093                 error "rename dir cross MDT failed!"
14094
14095         $CHECKSTAT -t file $DIR/$tdir/src_dir/a &&
14096                 error "src_child still exists after rename"
14097
14098         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/b ||
14099                 error "missing file(a) after rename"
14100
14101         diff /etc/hosts $DIR/$tdir/tgt_dir/b ||
14102                 error "diff after rename"
14103 }
14104
14105 test_310a() {
14106         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
14107         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14108         local remote_file=$DIR/$tdir/tgt_dir/b
14109
14110         mkdir -p $DIR/$tdir
14111
14112         prepare_remote_file || error "prepare remote file failed"
14113
14114         #open-unlink file
14115         $OPENUNLINK $remote_file $remote_file || error
14116         $CHECKSTAT -a $remote_file || error
14117 }
14118 run_test 310a "open unlink remote file"
14119
14120 test_310b() {
14121         [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 4 MDTs" && return
14122         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14123         local remote_file=$DIR/$tdir/tgt_dir/b
14124
14125         mkdir -p $DIR/$tdir
14126
14127         prepare_remote_file || error "prepare remote file failed"
14128
14129         ln $remote_file $DIR/$tfile || error "link failed for remote file"
14130         $MULTIOP $DIR/$tfile Ouc || error "mulitop failed"
14131         $CHECKSTAT -t file $remote_file || error "check file failed"
14132 }
14133 run_test 310b "unlink remote file with multiple links while open"
14134
14135 test_310c() {
14136         [[ $MDSCOUNT -lt 4 ]] && skip "needs >= 4 MDTs" && return
14137         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14138         local remote_file=$DIR/$tdir/tgt_dir/b
14139
14140         mkdir -p $DIR/$tdir
14141
14142         prepare_remote_file || error "prepare remote file failed"
14143
14144         ln $remote_file $DIR/$tfile || error "link failed for remote file"
14145         multiop_bg_pause $remote_file O_uc ||
14146                         error "mulitop failed for remote file"
14147         MULTIPID=$!
14148         $MULTIOP $DIR/$tfile Ouc
14149         kill -USR1 $MULTIPID
14150         wait $MULTIPID
14151 }
14152 run_test 310c "open-unlink remote file with multiple links"
14153
14154 test_400a() { # LU-1606, was conf-sanity test_74
14155         local extra_flags=''
14156         local out=$TMP/$tfile
14157         local prefix=/usr/include/lustre
14158         local prog
14159
14160         if ! which $CC > /dev/null 2>&1; then
14161                 skip_env "$CC is not installed"
14162                 return 0
14163         fi
14164
14165         if ! [[ -d $prefix ]]; then
14166                 # Assume we're running in tree and fixup the include path.
14167                 extra_flags+=" -I$LUSTRE/../libcfs/include"
14168                 extra_flags+=" -I$LUSTRE/include"
14169                 extra_flags+=" -L$LUSTRE/utils"
14170         fi
14171
14172         for prog in $LUSTRE_TESTS_API_DIR/*.c; do
14173                 $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
14174                         error "client api broken"
14175         done
14176 }
14177 run_test 400a "Lustre client api program can compile and link"
14178
14179 test_400b() { # LU-1606, LU-5011
14180         local header
14181         local out=$TMP/$tfile
14182         local prefix=/usr/include/lustre
14183
14184         # We use a hard coded prefix so that this test will not fail
14185         # when run in tree. There are headers in lustre/include/lustre/
14186         # that are not packaged (like lustre_idl.h) and have more
14187         # complicated include dependencies (like config.h and lnet/types.h).
14188         # Since this test about correct packaging we just skip them when
14189         # they don't exist (see below) rather than try to fixup cppflags.
14190
14191         if ! which $CC > /dev/null 2>&1; then
14192                 skip_env "$CC is not installed"
14193                 return 0
14194         fi
14195
14196         for header in $prefix/*.h; do
14197                 if ! [[ -f "$header" ]]; then
14198                         continue
14199                 fi
14200
14201                 if [[ "$(basename $header)" == liblustreapi.h ]]; then
14202                         continue # liblustreapi.h is deprecated.
14203                 fi
14204
14205                 $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
14206                         error "cannot compile '$header'"
14207         done
14208 }
14209 run_test 400b "packaged headers can be compiled"
14210
14211 #
14212 # tests that do cleanup/setup should be run at the end
14213 #
14214
14215 test_900() {
14216         [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
14217         local ls
14218         #define OBD_FAIL_MGC_PAUSE_PROCESS_LOG   0x903
14219         $LCTL set_param fail_loc=0x903
14220
14221         cancel_lru_locks MGC
14222
14223         FAIL_ON_ERROR=true cleanup
14224         FAIL_ON_ERROR=true setup
14225 }
14226 run_test 900 "umount should not race with any mgc requeue thread"
14227
14228 complete $SECONDS
14229 [ -f $EXT2_DEV ] && rm $EXT2_DEV || true
14230 check_and_cleanup_lustre
14231 if [ "$I_MOUNTED" != "yes" ]; then
14232         lctl set_param debug="$OLDDEBUG" 2> /dev/null || true
14233 fi
14234 exit_status